Mir
validity_matchers.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 or 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_VALIDITY_MATCHERS_H_
20 #define MIR_TEST_VALIDITY_MATCHERS_H_
21 
22 #include <gmock/gmock.h>
23 
25 
26 using ::testing::MakePolymorphicMatcher;
27 using ::testing::MatchResultListener;
28 using ::testing::NotNull;
29 using ::testing::PolymorphicMatcher;
30 
32 public:
33  // To implement a polymorphic matcher, first define a COPYABLE class
34  // that has three members MatchAndExplain(), DescribeTo(), and
35  // DescribeNegationTo(), like the following.
36 
37  // In this example, we want to use NotNull() with any pointer, so
38  // MatchAndExplain() accepts a pointer of any type as its first argument.
39  // In general, you can define MatchAndExplain() as an ordinary method or
40  // a method template, or even overload it.
41  template <typename T>
42  bool MatchAndExplain(T* p, MatchResultListener* listener) const;
43 
44  // Describes the property of a value matching this matcher.
45  void DescribeTo(::std::ostream* os) const { *os << "is valid"; }
46 
47  // Describes the property of a value NOT matching this matcher.
48  void DescribeNegationTo(::std::ostream* os) const { *os << "is not valid"; }
49 };
50 
51 template<>
52 bool IsValidMatcher::MatchAndExplain(MirConnection* connection, MatchResultListener* listener) const;
53 
54 template<>
55 bool IsValidMatcher::MatchAndExplain(MirWindow* surface, MatchResultListener* listener) const;
56 
57 // To construct a polymorphic matcher, pass an instance of the class
58 // to MakePolymorphicMatcher(). Note the return type.
59 inline PolymorphicMatcher<IsValidMatcher> IsValid()
60 {
61  return MakePolymorphicMatcher(IsValidMatcher{});
62 }
63 
64 #endif // MIR_TEST_VALIDITY_MATCHERS_H_
struct MirSurface MirWindow
Definition: client_types.h:43
void DescribeTo(::std::ostream *os) const
Definition: validity_matchers.h:45
struct MirConnection MirConnection
Definition: client_types.h:41
PolymorphicMatcher< IsValidMatcher > IsValid()
Definition: validity_matchers.h:59
bool MatchAndExplain(T *p, MatchResultListener *listener) const
Definition: validity_matchers.h:31
void DescribeNegationTo(::std::ostream *os) const
Definition: validity_matchers.h:48

Copyright © 2012-2018 Canonical Ltd.
Generated on Thu Mar 15 13:06:27 UTC 2018