All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
NegateTest.h
Go to the documentation of this file.
1 // Copyright 2015, 2016 Thomas Trapp
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEXT_NEGATE_TEST_H_INCLUDED
16 #define HEXT_NEGATE_TEST_H_INCLUDED
17 
18 /// @file
19 /// Declares hext::NegateTest
20 
21 #include "hext/Cloneable.h"
22 #include "hext/ValueTest.h"
23 
24 #include <memory>
25 
26 
27 namespace hext {
28 
29 
30 /// Negates the result of another ValueTest.
31 ///
32 /// @par Example:
33 /// ~~~~~~~~~~~~~
34 /// NegateTest not_foo(std::make_unique<EqualsTest>("foo"));
35 ///
36 /// assert( not_foo.test("bar"));
37 /// assert( not_foo.test("baz"));
38 /// assert(!not_foo.test("foo"));
39 /// ~~~~~~~~~~~~~
40 class NegateTest final : public Cloneable<NegateTest, ValueTest>
41 {
42 public:
43  /// Constructs a NegateTest.
44  ///
45  /// @param value_test: The ValueTest a subject has to fail.
46  explicit NegateTest(std::unique_ptr<ValueTest> value_test) noexcept;
47 
48  ~NegateTest() noexcept = default;
49  NegateTest(NegateTest&& other) noexcept = default;
50  NegateTest(const NegateTest& other);
51  NegateTest& operator=(NegateTest&& other) noexcept = default;
52  NegateTest& operator=(const NegateTest& other);
53 
54  /// Returns true if the given ValueTest fails for subject.
55  ///
56  /// @param subject: The string that is to be tested.
57  bool test(const char * subject) const override;
58 
59 private:
60  /// The ValueTest a subject has to fail.
61  std::unique_ptr<ValueTest> test_;
62 };
63 
64 
65 } // namespace hext
66 
67 
68 #endif // HEXT_NEGATE_TEST_H_INCLUDED
69 
~NegateTest() noexcept=default
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
Definition: Cloneable.h:34
Negates the result of another ValueTest.
Definition: NegateTest.h:40
NegateTest & operator=(NegateTest &&other) noexcept=default
Declares hext::ValueTest.
bool test(const char *subject) const override
Returns true if the given ValueTest fails for subject.
Defines template hext::Cloneable.
NegateTest(std::unique_ptr< ValueTest > value_test) noexcept
Constructs a NegateTest.