15 #ifndef INCG_IRIS_IUTEST_MATCHER_HPP_23746E00_1A4B_4778_91AD_45C6DEFEEFA7_
16 #define INCG_IRIS_IUTEST_MATCHER_HPP_23746E00_1A4B_4778_91AD_45C6DEFEEFA7_
18 #if IUTEST_HAS_MATCHERS
26 #define IUTEST_TEST_THAT(actual, matcher, on_failure) \
27 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
28 if( ::iutest::AssertionResult iutest_ar = matcher(actual) ) { \
30 on_failure(::iutest::detail::MatcherAssertionFailureMessage( \
31 ::iutest::PrintToString(actual).c_str(), #matcher, iutest_ar))
46 inline ::std::string MatcherAssertionFailureMessage(
const char* actual,
const char* matcher_str
47 ,
const AssertionResult& ar)
49 iu_global_format_stringstream strm;
50 strm <<
"error: Expected: " << matcher_str
51 <<
"\n Actual: " << actual
52 <<
"\nWhich is: " << ar.message();
59 IUTEST_PRAGMA_ASSIGNMENT_OPERATOR_COULD_NOT_GENERATE_WARN_DISABLE_BEGIN()
66 IMatcher& operator=(
const IMatcher&);
69 struct is_matcher :
public iutest_type_traits::is_base_of<IMatcher, T> {};
72 IMatcher(
const IMatcher&) {}
73 virtual ~IMatcher() {}
74 virtual ::std::string WhichIs()
const = 0;
77 #if !defined(IUTEST_NO_SFINAE)
79 inline typename detail::enable_if_t< IMatcher::is_matcher<T>, iu_ostream>::type& operator << (iu_ostream& os,
const T& m)
81 return os << m.WhichIs();
84 inline iu_ostream& operator << (iu_ostream& os,
const IMatcher& m)
86 return os << m.WhichIs();
95 #define IIUT_DECL_COMPARE_MATCHER(name, op) \
96 template<typename T> \
97 class IUTEST_PP_CAT(name, Matcher) IUTEST_CXX_FINAL : public IMatcher { \
98 public: explicit IUTEST_PP_CAT(name, Matcher)(const T& v) : m_expected(v) {}\
99 ::std::string WhichIs() const IUTEST_CXX_OVERRIDE { \
100 iu_global_format_stringstream strm; \
101 strm << #name ": " << m_expected; return strm.str(); \
103 template<typename U>AssertionResult operator ()(const U& actual) const { \
104 if IUTEST_COND_LIKELY( actual op m_expected ) return AssertionSuccess();\
105 return AssertionFailure() << WhichIs(); \
107 private: const T& m_expected; \
110 #define IIUT_DECL_COMPARE_MATCHER2(name, op) \
111 class IUTEST_PP_CAT(Twofold, IUTEST_PP_CAT(name, Matcher)) IUTEST_CXX_FINAL : public IMatcher{ \
112 public: ::std::string WhichIs() const IUTEST_CXX_OVERRIDE { return #name; } \
113 template<typename T, typename U>AssertionResult operator () \
114 (const T& actual, const U& expected) const { \
115 if IUTEST_COND_LIKELY( actual op expected ) return AssertionSuccess(); \
116 return AssertionFailure() << WhichIs() << ": " << actual << " vs " << expected; \
121 IUTEST_PRAGMA_WARN_PUSH()
122 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
124 IIUT_DECL_COMPARE_MATCHER(
Ne, !=);
125 IIUT_DECL_COMPARE_MATCHER(
Le, <=);
126 IIUT_DECL_COMPARE_MATCHER(
Lt, < );
127 IIUT_DECL_COMPARE_MATCHER(
Ge, >=);
128 IIUT_DECL_COMPARE_MATCHER(
Gt, > );
130 IIUT_DECL_COMPARE_MATCHER2(
Eq, ==);
131 IIUT_DECL_COMPARE_MATCHER2(
Ne, !=);
132 IIUT_DECL_COMPARE_MATCHER2(
Le, <=);
133 IIUT_DECL_COMPARE_MATCHER2(
Lt, < );
134 IIUT_DECL_COMPARE_MATCHER2(
Ge, >=);
135 IIUT_DECL_COMPARE_MATCHER2(
Gt, > );
137 IUTEST_PRAGMA_WARN_POP()
139 #undef IIUT_DECL_COMPARE_MATCHER
140 #undef IIUT_DECL_COMPARE_MATCHER2
142 #define IIUT_DECL_STR_COMPARE_MATCHER(name) \
143 template<typename T> \
144 class IUTEST_PP_CAT(name, Matcher) IUTEST_CXX_FINAL : public IMatcher { \
145 public: IUTEST_PP_CAT(name, Matcher)(const T& value) : m_expected(value) {} \
146 template<typename U>AssertionResult operator ()(const U& actual) const { \
147 if IUTEST_COND_LIKELY( internal::IUTEST_PP_CAT(name, Helper)::Compare( \
148 actual, m_expected) ) { return AssertionSuccess(); } \
149 return AssertionFailure() << WhichIs(); \
151 ::std::string WhichIs() const IUTEST_CXX_OVERRIDE { \
152 iu_global_format_stringstream strm; strm << #name ": " << m_expected; \
156 const T& m_expected; \
159 IIUT_DECL_STR_COMPARE_MATCHER(
StrEq);
160 IIUT_DECL_STR_COMPARE_MATCHER(
StrNe);
161 IIUT_DECL_STR_COMPARE_MATCHER(
StrCaseEq);
162 IIUT_DECL_STR_COMPARE_MATCHER(
StrCaseNe);
164 #undef IIUT_DECL_COMPARE_MATCHER
177 AssertionResult operator ()(
const U& actual)
const
179 if IUTEST_COND_LIKELY( actual == IUTEST_NULLPTR )
198 AssertionResult operator ()(
const U& actual)
const
200 if IUTEST_COND_LIKELY( actual != IUTEST_NULLPTR )
220 explicit FloatingPointEqMatcher(
const T& value) : m_expected(value) {}
224 AssertionResult operator ()(
const U& actual)
const
226 const floating_point<T> f2(actual);
227 if IUTEST_COND_LIKELY( m_expected.AlmostEquals(f2) )
236 iu_global_format_stringstream strm;
241 floating_point<T> m_expected;
251 explicit NanSensitiveFloatingPointEqMatcher(
const T& value) : m_expected(value) {}
255 AssertionResult operator ()(
const U& actual)
const
257 const floating_point<T> f2(actual);
258 if IUTEST_COND_LIKELY( m_expected.NanSensitiveAlmostEquals(f2) )
267 iu_global_format_stringstream strm;
272 floating_point<T> m_expected;
282 explicit FloatingPointNearMatcher(
const T& value,
const T& abs_error)
283 : m_expected(value), m_max_abs_error(abs_error) {}
287 AssertionResult operator ()(
const U& actual)
const
289 const floating_point<T> a(actual);
290 if IUTEST_COND_LIKELY( m_expected.AlmostNear(a, m_max_abs_error) )
299 iu_global_format_stringstream strm;
300 strm <<
"Near: " <<
PrintToString(m_expected) <<
"(abs error <= " << m_max_abs_error <<
")";
304 floating_point<T> m_expected;
312 class NanSensitiveFloatingPointNearMatcher
IUTEST_CXX_FINAL :
public IMatcher
315 explicit NanSensitiveFloatingPointNearMatcher(
const T& value,
const T& abs_error)
316 : m_expected(value), m_max_abs_error(abs_error) {}
320 AssertionResult operator ()(
const U& actual)
const
322 const floating_point<T> a(actual);
323 if IUTEST_COND_LIKELY( m_expected.NanSensitiveAlmostNear(a, m_max_abs_error) )
332 iu_global_format_stringstream strm;
333 strm <<
"NanSensitive Near: " <<
PrintToString(m_expected) <<
"(abs error <= " << m_max_abs_error <<
")";
337 floating_point<T> m_expected;
348 explicit StartsWithMatcher(T str) : m_expected(str) {}
352 AssertionResult operator ()(
const U& actual)
const
354 if IUTEST_COND_LIKELY(
StartsWith(actual, m_expected) )
364 iu_global_format_stringstream strm;
365 strm <<
"StartsWith: " << m_expected;
369 static bool StartsWith(
const char* actual,
const char* start)
371 return strstr(actual, start) == actual;
373 static bool StartsWith(const ::std::string& actual,
const char* start)
375 const char* p = actual.c_str();
378 static bool StartsWith(
const char* actual, const ::std::string& start)
380 const char* p = start.c_str();
383 static bool StartsWith(const ::std::string& actual, const ::std::string& start)
385 const char* p = start.c_str();
399 explicit HasSubstrMatcher(T expected) : m_expected(expected) {}
402 AssertionResult operator ()(
const U& actual)
const
404 if IUTEST_COND_LIKELY(
HasSubstr(actual, m_expected) )
414 iu_global_format_stringstream strm;
415 strm <<
"HasSubstr: " << m_expected;
419 static bool HasSubstr(
const char* actual,
const char* expected)
421 return strstr(actual, expected) != NULL;
423 static bool HasSubstr(const ::std::string& actual,
const char* expected)
425 const char* p = actual.c_str();
428 static bool HasSubstr(
const char* actual, const ::std::string& expected)
430 const char* p = expected.c_str();
433 static bool HasSubstr(const ::std::string& actual, const ::std::string& expected)
435 const char* p = expected.c_str();
450 explicit EndsWithMatcher(T str) : m_expected(str) {}
454 AssertionResult operator ()(
const U& actual)
const
456 if IUTEST_COND_LIKELY(
EndsWith(actual, m_expected) )
466 iu_global_format_stringstream strm;
467 strm <<
"EndsWith: " << m_expected;
471 static bool EndsWith(
const char* actual,
const char* end)
473 const size_t len = strlen(end);
474 const size_t actual_len = strlen(actual);
475 if( len > actual_len )
479 const char* p = actual + actual_len - 1;
480 const char* q = end + len - 1;
481 for(
size_t i=0; i < len; ++i, --p, --q )
490 static bool EndsWith(const ::std::string& actual,
const char* end)
492 const char* p = actual.c_str();
495 static bool EndsWith(
const char* actual, const ::std::string& end)
497 const char* p = end.c_str();
500 static bool EndsWith(const ::std::string& actual, const ::std::string& end)
502 const char* p = end.c_str();
513 class EqMatcher :
public IMatcher
516 explicit EqMatcher(
const T& expected) : m_expected(expected) {}
520 AssertionResult operator ()(
const U& actual)
const
522 if IUTEST_COND_LIKELY(
Equals(actual, m_expected) )
532 iu_global_format_stringstream strm;
537 template<
typename A,
typename B>
538 static bool Equals(
const A& actual,
const B& expected)
540 IUTEST_PRAGMA_WARN_PUSH()
541 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
542 return actual == expected;
543 IUTEST_PRAGMA_WARN_POP()
545 static
bool Equals(const
char* actual, const
char* expected)
547 return strcmp(actual, expected) == 0;
549 static bool Equals(const ::std::string& actual,
const char* expected)
551 const char* p = actual.c_str();
552 return Equals(p, expected);
554 static bool Equals(const ::std::string& actual, const ::std::string& expected)
556 const char* p = expected.c_str();
570 explicit TypedEqMatcher(T expected) : EqMatcher<T>(m_expected), m_expected(expected) {}
572 AssertionResult operator ()(
const T& actual)
574 return EqMatcher<T>::operator ()(actual);
577 AssertionResult operator ()(
const U&)
const;
586 #if !defined(IUTEST_NO_SFINAE)
589 T& CastToMatcher(T& matcher
590 ,
typename detail::enable_if_t< IMatcher::is_matcher<T> >::type*& = detail::enabler::value)
596 EqMatcher<T> CastToMatcher(
const T& value
597 ,
typename detail::disable_if_t< IMatcher::is_matcher<T> >::type*& = detail::enabler::value)
599 return EqMatcher<T>(value);
605 T& CastToMatcher(T& matcher)
620 explicit ContainsMatcher(
const T& expected) : m_expected(expected) {}
624 AssertionResult operator ()(
const U& actual)
627 if IUTEST_COND_LIKELY(
Contains(begin(actual), end(actual)) )
637 iu_global_format_stringstream strm;
638 strm <<
"Contains: " << m_expected;
642 template<
typename Ite>
645 for( Ite it = begin; it != end; ++it )
647 if( CastToMatcher(m_expected)(*it) )
659 #if IUTEST_HAS_MATCHER_EACH
668 explicit EachMatcher(
const T& expected) : m_expected(expected) {}
672 AssertionResult operator ()(
const U& actual)
675 if IUTEST_COND_LIKELY(
Each(begin(actual), end(actual)) )
685 iu_global_format_stringstream strm;
686 strm <<
"Each: " << m_expected;
690 template<
typename Ite>
691 bool Each(Ite begin, Ite end)
693 for( Ite it = begin; it != end; ++it )
695 if( !CastToMatcher(m_expected)(*it) )
716 explicit ContainerEqMatcher(
const T& expected) : m_expected(expected) {}
720 AssertionResult operator ()(
const U& actual)
723 if IUTEST_COND_LIKELY( Check(begin(m_expected), end(m_expected)
724 , begin(actual), end(actual)) )
734 iu_global_format_stringstream strm;
736 strm <<
" (" << m_whichIs <<
")";
740 template<
typename Ite1,
typename Ite2>
741 bool Check(Ite1 b1, Ite1 e1, Ite2 b2, Ite2 e2)
746 for( elem=0; b1 != e1 && b2 != e2; ++b1, ++b2, ++elem )
748 if( !internal::backward::EqHelper<false>::Compare(
"",
"", *b1, *b2) )
751 ar <<
"\nMismatch in a position " << elem <<
": "
752 << ::iutest::internal::FormatForComparisonFailureMessage(*b1, *b2)
753 <<
" vs " << ::iutest::internal::FormatForComparisonFailureMessage(*b2, *b1);
756 if( b1 != e1 || b2 != e2 )
758 const size_t elem1 = elem + ::std::distance(b1, e1);
759 const size_t elem2 = elem + ::std::distance(b2, e2);
761 ar <<
"\nMismatch element : " << elem1 <<
" vs " << elem2;
763 m_whichIs = ar.GetString();
769 ::std::string m_whichIs;
773 #if IUTEST_HAS_MATCHER_POINTWISE
778 template<
typename M,
typename T>
782 PointwiseMatcher(
const M& matcher,
const T& expected)
783 : m_matcher(matcher), m_expected(expected) {}
787 AssertionResult operator ()(
const U& actual)
790 if IUTEST_COND_LIKELY( Check(begin(m_expected), end(m_expected)
791 , begin(actual), end(actual)) )
801 iu_global_format_stringstream strm;
802 strm <<
"Pointwise: " << m_matcher <<
": " <<
PrintToString(m_expected);
803 strm <<
" (" << m_whichIs <<
")";
807 template<
typename Ite1,
typename Ite2>
808 bool Check(Ite1 b1, Ite1 e1, Ite2 b2, Ite2 e2)
813 for( elem=0; b1 != e1 && b2 != e2; ++b1, ++b2, ++elem )
815 const AssertionResult r = m_matcher(*b2, *b1);
819 ar <<
"\nMismatch in a position " << elem <<
": " << r.message();
822 if( b1 != e1 || b2 != e2 )
824 const size_t elem1 = elem + ::std::distance(b1, e1);
825 const size_t elem2 = elem + ::std::distance(b2, e2);
827 ar <<
"\nMismatch element : " << elem1 <<
" vs " << elem2;
829 m_whichIs = ar.GetString();
836 ::std::string m_whichIs;
841 #if IUTEST_HAS_MATCHER_OPTIONAL
850 explicit OptionalMatcher(
const T& expected)
851 : m_expected(expected) {}
855 AssertionResult operator ()(
const U& actual)
866 bool Check(
const U& actual)
873 ar <<
"which is not engaged";
875 else if( !CastToMatcher(m_expected)(*actual) )
880 m_whichIs = ar.GetString();
887 iu_global_format_stringstream strm;
889 strm <<
" (" << m_whichIs <<
")";
894 ::std::string m_whichIs;
907 AssertionResult operator ()(
const U& actual)
909 if IUTEST_COND_LIKELY( (actual).empty() )
931 explicit SizeIsMatcher(
const T& expected) : m_expected(expected) {}
935 AssertionResult operator ()(
const U& actual)
937 if IUTEST_COND_LIKELY( Check(actual) )
947 iu_global_format_stringstream strm;
948 strm <<
"Size is: " << m_expected;
952 template<
typename Container>
953 bool Check(
const Container& actual)
955 return static_cast<bool>(CastToMatcher(m_expected)(actual.size()));
957 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
958 template<
typename U,
size_t SIZE>
959 bool Check(
const U(&)[SIZE])
961 return static_cast<bool>(CastToMatcher(m_expected)(SIZE));
976 AtMatcher(
size_t index,
const T& expected) : m_index(index), m_expected(expected) {}
980 AssertionResult operator ()(
const U& actual)
982 if IUTEST_COND_LIKELY( CastToMatcher(m_expected)(actual[m_index]) )
992 iu_global_format_stringstream strm;
993 strm <<
"At " << m_index <<
": " << m_expected;
1005 template<
typename T>
1009 template<
typename It>
1010 ElementsAreArrayMatcher(It begin, It end,
bool expected_elem_count=
true)
1011 : m_expected_elem_count(expected_elem_count)
1013 m_expected.insert(m_expected.end(), begin, end);
1017 template<
typename U>
1018 AssertionResult operator ()(
const U& actual)
1021 return Check(begin(actual), end(actual));
1029 ::std::string WhichIs(const ::std::string& msg)
const
1031 iu_global_format_stringstream strm;
1032 if( m_expected_elem_count )
1034 strm <<
"ElementsAreArray: ";
1038 strm <<
"ElementsAreArrayForward: ";
1044 template<
typename Ite>
1045 AssertionResult Check(Ite actual_begin, Ite actual_end)
1047 const size_t actual_cnt = ::std::distance(actual_begin, actual_end);
1048 const size_t expected_cnt = m_expected.size();
1049 if IUTEST_COND_UNLIKELY( actual_cnt < expected_cnt )
1051 iu_global_format_stringstream stream;
1052 stream <<
"actual argument[" << actual_cnt <<
"] is less than " << expected_cnt;
1055 if IUTEST_COND_UNLIKELY( m_expected_elem_count && actual_cnt > expected_cnt )
1057 iu_global_format_stringstream stream;
1058 stream <<
"actual argument[" << actual_cnt <<
"] is greater than " << expected_cnt;
1062 Ite it_a=actual_begin;
1063 typename ::std::vector<T>::iterator it_e=m_expected.begin();
1064 for(
int i=0; it_a != actual_end && it_e != m_expected.end(); ++it_e, ++it_a, ++i )
1067 if IUTEST_COND_UNLIKELY( *it_a != *it_e )
1076 ::std::vector<T> m_expected;
1077 bool m_expected_elem_count;
1080 #if IUTEST_HAS_MATCHER_ELEMENTSARE
1085 class ElementsAreMatcherBase :
public IMatcher
1088 template<
typename T,
typename U>
1089 static AssertionResult Check(T& matchers,
const U& actual)
1092 return Check<0, tuples::tuple_size<T>::value - 1>(begin(actual), end(actual), matchers);
1094 template<
int N,
typename T>
1095 static ::std::string WhichIs(
const T& matchers)
1097 ::std::string str =
"ElementsAre: {";
1098 str += WhichIs_<T, N, tuples::tuple_size<T>::value-1>(matchers);
1103 template<
int N,
int LAST,
typename Ite,
typename M>
1104 static AssertionResult Check(Ite it, Ite end, M& matchers)
1106 const size_t cnt = ::std::distance(it, end);
1107 if IUTEST_COND_UNLIKELY( cnt < LAST+1 )
1109 return AssertionFailure() <<
"ElementsAre: argument[" << cnt <<
"] is less than " << LAST+1;
1111 return CheckElem<N, LAST>(it, end, matchers);
1114 template<
int N,
int LAST,
typename Ite,
typename M>
1115 static AssertionResult CheckElem(Ite it, Ite end, M& matchers
1116 ,
typename detail::enable_if<N == LAST, void>::type*& = detail::enabler::value)
1118 for(
int index=N; it != end; ++it, ++index )
1120 AssertionResult ar = CastToMatcher(tuples::get<N>(matchers))(*it);
1121 if IUTEST_COND_UNLIKELY( !ar )
1129 template<
int N,
int LAST,
typename Ite,
typename M>
1130 static AssertionResult CheckElem(Ite it, Ite end, M& matchers
1131 ,
typename detail::disable_if<N == LAST, void>::type*& = detail::enabler::value)
1133 AssertionResult ar = CastToMatcher(tuples::get<N>(matchers))(*it);
1134 if IUTEST_COND_LIKELY( ar )
1136 return CheckElem<N + 1, LAST>(++it, end, matchers);
1141 template<
int N,
typename T>
1142 static ::std::string WhichIsElem(
const T& matchers,
int index)
1144 iu_global_format_stringstream strm;
1145 strm <<
"ElementsAre(" << index <<
"): " << tuples::get<N>(matchers);
1149 template<
typename T,
int N,
int LAST>
1150 static ::std::string WhichIs_(
const T& matchers
1151 ,
typename detail::enable_if<N == LAST, void>::type*& = detail::enabler::value)
1153 return StreamableToString(tuples::get<N>(matchers));
1155 template<
typename T,
int N,
int LAST>
1156 static ::std::string WhichIs_(
const T& matchers
1157 ,
typename detail::disable_if<N == LAST, void>::type*& = detail::enabler::value)
1159 return StreamableToString(tuples::get<N>(matchers)) +
", " + WhichIs_<T, N + 1, LAST>(matchers);
1163 #if IUTEST_HAS_MATCHER_VARIADIC
1168 template<
typename ...T>
1172 explicit ElementsAreMatcher(T... t) : m_matchers(t...) {}
1175 template<
typename U>
1176 AssertionResult operator ()(
const U& actual)
1178 return Check(m_matchers, actual);
1182 return ElementsAreMatcherBase::WhichIs<0>(m_matchers);
1186 tuples::tuple<T...> m_matchers;
1213 #define IIUT_DECL_ELEMENTSARE_MATCHER(n) \
1214 template< IUTEST_PP_ENUM_PARAMS(n, typename T) > \
1215 class IUTEST_PP_CAT(ElementsAreMatcher, n) IUTEST_CXX_FINAL : public ElementsAreMatcherBase { \
1216 public: IUTEST_PP_CAT(ElementsAreMatcher, n)(IUTEST_PP_ENUM_BINARY_PARAMS(n, T, m)) \
1217 : m_matchers(IUTEST_PP_ENUM_PARAMS(n, m)) {} \
1218 template<typename U>AssertionResult operator ()(const U& actual) { \
1219 return Check(m_matchers, actual); } \
1220 ::std::string WhichIs() const IUTEST_CXX_OVERRIDE { \
1221 return ElementsAreMatcherBase::WhichIs<0>(m_matchers); } \
1223 tuples::tuple< IUTEST_PP_ENUM_PARAMS(n, T) > m_matchers; \
1226 IIUT_DECL_ELEMENTSARE_MATCHER(1);
1227 IIUT_DECL_ELEMENTSARE_MATCHER(2);
1228 IIUT_DECL_ELEMENTSARE_MATCHER(3);
1229 IIUT_DECL_ELEMENTSARE_MATCHER(4);
1230 IIUT_DECL_ELEMENTSARE_MATCHER(5);
1231 IIUT_DECL_ELEMENTSARE_MATCHER(6);
1232 IIUT_DECL_ELEMENTSARE_MATCHER(7);
1233 IIUT_DECL_ELEMENTSARE_MATCHER(8);
1234 IIUT_DECL_ELEMENTSARE_MATCHER(9);
1235 IIUT_DECL_ELEMENTSARE_MATCHER(10);
1237 #undef IIUT_DECL_ELEMENTSARE_MATCHER
1246 template<
typename F,
typename T>
1250 FieldMatcher(
const F& field,
const T& expected) : m_field(field), m_expected(expected) {}
1253 template<
typename U>
1254 AssertionResult operator ()(
const U& actual)
1256 if IUTEST_COND_LIKELY( Check(actual) )
1266 iu_global_format_stringstream strm;
1267 strm <<
"Field: " << m_expected;
1272 #if !defined(IUTEST_NO_SFINAE)
1273 template<
typename U>
1274 bool Check(
const U& actual
1275 ,
typename detail::disable_if_t< detail::is_pointer<U> >::type*& = detail::enabler::value)
1277 return static_cast<bool>(CastToMatcher(m_expected)(actual.*m_field));
1279 template<
typename U>
1280 bool Check(
const U& actual
1281 ,
typename detail::enable_if_t< detail::is_pointer<U> >::type*& = detail::enabler::value)
1283 return static_cast<bool>(CastToMatcher(m_expected)(actual->*m_field));
1286 template<
typename U>
1287 bool Check(
const U& actual)
1289 return static_cast<bool>(CastToMatcher(m_expected)(actual->*m_field));
1301 template<
typename F,
typename T>
1305 PropertyMatcher(
const F& prop,
const T& expected) : m_property(prop), m_expected(expected) {}
1308 template<
typename U>
1309 AssertionResult operator ()(
const U& actual)
1311 if IUTEST_COND_LIKELY( Check(actual) )
1321 iu_global_format_stringstream strm;
1322 strm <<
"Property: " << m_expected;
1327 #if !defined(IUTEST_NO_SFINAE)
1328 template<
typename U>
1329 bool Check(
const U& actual
1330 ,
typename detail::disable_if_t< detail::is_pointer<U> >::type*& = detail::enabler::value)
1332 return static_cast<bool>(CastToMatcher(m_expected)((actual.*m_property)()));
1334 template<
typename U>
1335 bool Check(
const U& actual
1336 ,
typename detail::enable_if_t< detail::is_pointer<U> >::type*& = detail::enabler::value)
1338 return static_cast<bool>(CastToMatcher(m_expected)((actual->*m_property)()));
1341 template<
typename U>
1342 bool Check(
const U& actual)
1344 return static_cast<bool>(CastToMatcher(m_expected)((actual->*m_property)()));
1349 const F& m_property;
1356 template<
typename T>
1360 explicit KeyMatcher(
const T& expected) : m_expected(expected) {}
1363 template<
typename U>
1364 AssertionResult operator ()(
const U& actual)
const
1366 if IUTEST_COND_LIKELY( CastToMatcher(m_expected)(actual.first) )
1376 iu_global_format_stringstream strm;
1377 strm <<
"Key: " << m_expected;
1382 const T& m_expected;
1388 template<
typename T1,
typename T2>
1392 PairMatcher(
const T1& m1,
const T2& m2) : m_m1(m1), m_m2(m2) {}
1395 template<
typename U>
1396 AssertionResult operator ()(
const U& actual)
1398 if IUTEST_COND_UNLIKELY( !CheckElem(actual.first, m_m1) )
1402 if IUTEST_COND_UNLIKELY( !CheckElem(actual.second, m_m2) )
1412 iu_global_format_stringstream strm;
1413 strm <<
"Pair: (" << m_m1 <<
", " << m_m2 <<
")";
1417 template<
typename T,
typename U>
1418 bool CheckElem(
const T& actual, U& matcher)
1420 return static_cast<bool>(CastToMatcher(matcher)(actual));
1431 template<
typename F,
typename T>
1435 ResultOfMatcher(F& func,
const T& expected) : m_func(func), m_expected(expected) {}
1438 template<
typename U>
1439 AssertionResult operator ()(
const U& actual)
1441 if IUTEST_COND_LIKELY( Check(actual) )
1451 iu_global_format_stringstream strm;
1452 strm <<
"Result of: " << m_expected;
1457 template<
typename U>
1458 bool Check(
const U& actual)
1460 return static_cast<bool>(CastToMatcher(m_expected)((*m_func)(actual)));
1470 template<
typename T>
1474 explicit PointeeMatcher(
const T& expected) : m_expected(expected) {}
1477 template<
typename U>
1478 AssertionResult operator ()(
const U& actual)
1480 if IUTEST_COND_LIKELY( Check(actual) )
1490 iu_global_format_stringstream strm;
1491 strm <<
"Points To: " << m_expected;
1495 template<
typename U>
1496 bool Check(
const U& actual)
1498 return static_cast<bool>(CastToMatcher(m_expected)(*actual));
1507 template<
typename T>
1511 explicit NotMatcher(
const T& unexpected) : m_unexpected(unexpected) {}
1514 template<
typename U>
1515 AssertionResult operator ()(
const U& actual)
1517 if IUTEST_COND_LIKELY( !CastToMatcher(m_unexpected)(actual) )
1527 iu_global_format_stringstream strm;
1528 strm <<
"Not: (" << m_unexpected <<
")";
1539 template<
typename T>
1543 AssertionResult operator ()(
const T&)
const
1547 template<
typename U>
1548 AssertionResult operator ()(
const U&)
const;
1553 iu_global_format_stringstream strm;
1554 strm <<
"A: " << detail::GetTypeNameProxy<T>::GetTypeName();
1565 AnythingMatcher() {}
1567 template<
typename U>
1568 AssertionResult operator ()(
const U&)
const
1580 #if IUTEST_HAS_MATCHER_REGEX
1588 RegexMatcher(
const detail::iuRegex& expected,
bool full_match) : m_expected(expected), m_full_match(full_match) {}
1591 template<
typename U>
1592 AssertionResult operator ()(
const U& actual)
const
1594 if IUTEST_COND_LIKELY( Regex(actual) )
1604 iu_global_format_stringstream strm;
1607 strm <<
"MatchesRegex: " << m_expected.pattern();
1611 strm <<
"ContainsRegex: " << m_expected.pattern();
1616 bool Regex(
const char* actual)
const
1618 return m_full_match ? m_expected.FullMatch(actual)
1619 : m_expected.PartialMatch(actual);
1621 bool Regex(const ::std::string& actual)
const
1623 return m_full_match ? m_expected.FullMatch(actual.c_str())
1624 : m_expected.PartialMatch(actual.c_str());
1628 detail::iuRegex m_expected;
1634 #if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF
1639 class AllOfMatcherBase :
public IMatcher
1642 template<
typename T,
typename U>
1643 static AssertionResult Check(T& matchers,
const U& actual)
1645 return Check_<T, U, 0, tuples::tuple_size<T>::value-1>(matchers, actual);
1647 template<
int N,
typename T>
1648 static ::std::string WhichIs(
const T& matchers)
1650 return WhichIs_<T, N, tuples::tuple_size<T>::value-1>(matchers);
1653 template<
typename T,
typename U,
int N,
int LAST>
1654 static AssertionResult Check_(T& matchers,
const U& actual,
typename detail::enable_if<N == LAST, void>::type*& = detail::enabler::value)
1656 AssertionResult ar = tuples::get<N>(matchers)(actual);
1657 if IUTEST_COND_LIKELY( ar )
1663 template<
typename T,
typename U,
int N,
int LAST>
1664 static AssertionResult Check_(T& matchers,
const U& actual,
typename detail::disable_if<N == LAST, void>::type*& = detail::enabler::value)
1666 AssertionResult ar = tuples::get<N>(matchers)(actual);
1667 if IUTEST_COND_LIKELY( ar )
1669 return Check_<T, U, N + 1, LAST>(matchers, actual);
1674 template<
typename T,
int N,
int LAST>
1675 static ::std::string WhichIs_(
const T& matchers,
typename detail::enable_if<N == LAST, void>::type*& = detail::enabler::value)
1677 return tuples::get<N>(matchers).WhichIs();
1679 template<
typename T,
int N,
int LAST>
1680 static ::std::string WhichIs_(
const T& matchers,
typename detail::disable_if<N == LAST, void>::type*& = detail::enabler::value)
1682 return tuples::get<N>(matchers).WhichIs() +
" and " + WhichIs_<T, N + 1, LAST>(matchers);
1686 #if IUTEST_HAS_MATCHER_VARIADIC
1691 template<
typename ...T>
1695 explicit AllOfMatcher(T... t) : m_matchers(t...) {}
1698 template<
typename U>
1699 AssertionResult operator ()(
const U& actual)
1701 return Check(m_matchers, actual);
1705 return AllOfMatcherBase::WhichIs<0>(m_matchers);
1709 tuples::tuple<T...> m_matchers;
1736 #define IIUT_DECL_ALLOF_MATCHER(n) \
1737 template< IUTEST_PP_ENUM_PARAMS(n, typename T) > \
1738 class IUTEST_PP_CAT(AllOfMatcher, n) IUTEST_CXX_FINAL : public AllOfMatcherBase { \
1739 public: IUTEST_PP_CAT(AllOfMatcher, n)(IUTEST_PP_ENUM_BINARY_PARAMS(n, T, m)) \
1740 : m_matchers(IUTEST_PP_ENUM_PARAMS(n, m)) {} \
1741 template<typename U>AssertionResult operator ()(const U& actual) { \
1742 return Check(m_matchers, actual); } \
1743 ::std::string WhichIs() const IUTEST_CXX_OVERRIDE { \
1744 return AllOfMatcherBase::WhichIs<0>(m_matchers); } \
1746 tuples::tuple< IUTEST_PP_ENUM_PARAMS(n, T) > m_matchers; \
1749 IIUT_DECL_ALLOF_MATCHER(2);
1750 IIUT_DECL_ALLOF_MATCHER(3);
1751 IIUT_DECL_ALLOF_MATCHER(4);
1752 IIUT_DECL_ALLOF_MATCHER(5);
1753 IIUT_DECL_ALLOF_MATCHER(6);
1754 IIUT_DECL_ALLOF_MATCHER(7);
1755 IIUT_DECL_ALLOF_MATCHER(8);
1756 IIUT_DECL_ALLOF_MATCHER(9);
1757 IIUT_DECL_ALLOF_MATCHER(10);
1759 #undef IIUT_DECL_ALLOF_MATCHER
1766 class AnyOfMatcherBase :
public IMatcher
1769 template<
typename T,
typename U>
1770 static AssertionResult Check(T& matchers,
const U& actual)
1772 return Check_<T, U, 0, tuples::tuple_size<T>::value-1>(matchers, actual);
1774 template<
int N,
typename T>
1775 static ::std::string WhichIs(
const T& matchers)
1777 return WhichIs_<T, N, tuples::tuple_size<T>::value-1>(matchers);
1780 template<
typename T,
typename U,
int N,
int LAST>
1781 static AssertionResult Check_(T& matchers,
const U& actual,
typename detail::enable_if<N == LAST, void>::type*& = detail::enabler::value)
1783 AssertionResult ar = tuples::get<N>(matchers)(actual);
1784 if IUTEST_COND_LIKELY( ar )
1790 template<
typename T,
typename U,
int N,
int LAST>
1791 static AssertionResult Check_(T& matchers,
const U& actual,
typename detail::disable_if<N == LAST, void>::type*& = detail::enabler::value)
1793 AssertionResult ar = tuples::get<N>(matchers)(actual);
1794 if IUTEST_COND_LIKELY( ar )
1798 return Check_<T, U, N + 1, LAST>(matchers, actual);
1801 template<
typename T,
int N,
int LAST>
1802 static ::std::string WhichIs_(
const T& matchers,
typename detail::enable_if<N == LAST, void>::type*& = detail::enabler::value)
1804 return tuples::get<N>(matchers).WhichIs();
1806 template<
typename T,
int N,
int LAST>
1807 static ::std::string WhichIs_(
const T& matchers,
typename detail::disable_if<N == LAST, void>::type*& = detail::enabler::value)
1809 return tuples::get<N>(matchers).WhichIs() +
" or " + WhichIs_<T, N + 1, LAST>(matchers);
1813 #if IUTEST_HAS_MATCHER_VARIADIC
1818 template<
typename ...T>
1822 explicit AnyOfMatcher(T... t) : m_matchers(t...) {}
1825 template<
typename U>
1826 AssertionResult operator ()(
const U& actual)
1828 return Check(m_matchers, actual);
1832 return AnyOfMatcherBase::WhichIs<0>(m_matchers);
1836 tuples::tuple<T...> m_matchers;
1863 #define IIUT_DECL_ANYOF_MATCHER(n) \
1864 template< IUTEST_PP_ENUM_PARAMS(n, typename T) > \
1865 class IUTEST_PP_CAT(AnyOfMatcher, n) IUTEST_CXX_FINAL : public AnyOfMatcherBase { \
1866 public: IUTEST_PP_CAT(AnyOfMatcher, n)(IUTEST_PP_ENUM_BINARY_PARAMS(n, T, m)) \
1867 : m_matchers(IUTEST_PP_ENUM_PARAMS(n, m)) {} \
1868 template<typename U>AssertionResult operator ()(const U& actual) { \
1869 return Check(m_matchers, actual); } \
1870 ::std::string WhichIs() const IUTEST_CXX_OVERRIDE { \
1871 return AnyOfMatcherBase::WhichIs<0>(m_matchers); } \
1873 tuples::tuple< IUTEST_PP_ENUM_PARAMS(n, T) > m_matchers; \
1876 IIUT_DECL_ANYOF_MATCHER(2);
1877 IIUT_DECL_ANYOF_MATCHER(3);
1878 IIUT_DECL_ANYOF_MATCHER(4);
1879 IIUT_DECL_ANYOF_MATCHER(5);
1880 IIUT_DECL_ANYOF_MATCHER(6);
1881 IIUT_DECL_ANYOF_MATCHER(7);
1882 IIUT_DECL_ANYOF_MATCHER(8);
1883 IIUT_DECL_ANYOF_MATCHER(9);
1884 IIUT_DECL_ANYOF_MATCHER(10);
1886 #undef IIUT_DECL_ANYOF_MATCHER
1892 IUTEST_PRAGMA_ASSIGNMENT_OPERATOR_COULD_NOT_GENERATE_WARN_DISABLE_END()
1912 template<
typename T>
1913 detail::EqMatcher<T>
Equals(
const T& expected)
1915 return detail::EqMatcher<T>(expected);
1922 template<
typename T>
1923 detail::EqMatcher<T>
Eq(
const T& expected)
1925 return detail::EqMatcher<T>(expected);
1932 template<
typename T>
1933 detail::NeMatcher<T>
Ne(
const T& expected)
1935 return detail::NeMatcher<T>(expected);
1942 template<
typename T>
1943 detail::LeMatcher<T>
Le(
const T& expected)
1945 return detail::LeMatcher<T>(expected);
1952 template<
typename T>
1953 detail::LtMatcher<T>
Lt(
const T& expected)
1955 return detail::LtMatcher<T>(expected);
1962 template<
typename T>
1963 detail::GeMatcher<T>
Ge(
const T& expected)
1965 return detail::GeMatcher<T>(expected);
1972 template<
typename T>
1973 detail::GtMatcher<T>
Gt(
const T& expected)
1975 return detail::GtMatcher<T>(expected);
1982 inline detail::TwofoldEqMatcher
Eq()
1984 return detail::TwofoldEqMatcher();
1991 inline detail::TwofoldNeMatcher
Ne()
1993 return detail::TwofoldNeMatcher();
2000 inline detail::TwofoldLeMatcher
Le()
2002 return detail::TwofoldLeMatcher();
2009 inline detail::TwofoldLtMatcher
Lt()
2011 return detail::TwofoldLtMatcher();
2018 inline detail::TwofoldGeMatcher
Ge()
2020 return detail::TwofoldGeMatcher();
2027 inline detail::TwofoldGtMatcher
Gt()
2029 return detail::TwofoldGtMatcher();
2036 inline detail::IsNullMatcher
IsNull()
2038 return detail::IsNullMatcher();
2045 inline detail::NotNullMatcher
NotNull()
2047 return detail::NotNullMatcher();
2054 template<
typename T,
typename U>
2055 detail::TypedEqMatcher<T>
TypedEq(
const U& expected)
2057 return detail::TypedEqMatcher<T>(
static_cast<T
>(expected));
2064 template<
typename T>
2067 return detail::FloatingPointEqMatcher<T>(expected);
2074 inline detail::FloatingPointEqMatcher<float>
FloatEq(
float expected)
2076 return detail::FloatingPointEqMatcher<float>(expected);
2083 inline detail::FloatingPointEqMatcher<double>
DoubleEq(
double expected)
2085 return detail::FloatingPointEqMatcher<double>(expected);
2088 #if IUTEST_HAS_LONG_DOUBLE
2094 inline detail::FloatingPointEqMatcher<long double> LongDoubleEq(
long double expected)
2096 return detail::FloatingPointEqMatcher<long double>(expected);
2105 template<
typename T>
2108 return detail::NanSensitiveFloatingPointEqMatcher<T>(expected);
2115 inline detail::NanSensitiveFloatingPointEqMatcher<float>
NanSensitiveFloatEq(
float expected)
2117 return detail::NanSensitiveFloatingPointEqMatcher<float>(expected);
2124 inline detail::NanSensitiveFloatingPointEqMatcher<double>
NanSensitiveDoubleEq(
double expected)
2126 return detail::NanSensitiveFloatingPointEqMatcher<double>(expected);
2129 #if IUTEST_HAS_LONG_DOUBLE
2135 inline detail::NanSensitiveFloatingPointEqMatcher<long double> NanSensitiveLongDoubleEq(
long double expected)
2137 return detail::NanSensitiveFloatingPointEqMatcher<long double>(expected);
2142 #if IUTEST_HAS_MATCHER_FLOATINGPOINT_NEAR
2148 template<
typename T>
2149 inline detail::FloatingPointNearMatcher<T>
FloatingPointNear(T expected, T max_abs_error)
2151 return detail::FloatingPointNearMatcher<T>(expected, max_abs_error);
2158 inline detail::FloatingPointNearMatcher<float>
FloatNear(
float expected,
float max_abs_error)
2160 return detail::FloatingPointNearMatcher<float>(expected, max_abs_error);
2167 inline detail::FloatingPointNearMatcher<double>
DoubleNear(
double expected,
double max_abs_error)
2169 return detail::FloatingPointNearMatcher<double>(expected, max_abs_error);
2172 #if IUTEST_HAS_LONG_DOUBLE
2178 inline detail::FloatingPointNearMatcher<long double> LongDoubleNear(
long double expected,
long double max_abs_error)
2180 return detail::FloatingPointNearMatcher<long double>(expected, max_abs_error);
2189 template<
typename T>
2192 return detail::NanSensitiveFloatingPointNearMatcher<T>(expected, max_abs_error);
2199 inline detail::NanSensitiveFloatingPointNearMatcher<float>
NanSensitiveFloatNear(
float expected,
float max_abs_error)
2201 return detail::NanSensitiveFloatingPointNearMatcher<float>(expected, max_abs_error);
2208 inline detail::NanSensitiveFloatingPointNearMatcher<double>
NanSensitiveDoubleNear(
double expected,
double max_abs_error)
2210 return detail::NanSensitiveFloatingPointNearMatcher<double>(expected, max_abs_error);
2213 #if IUTEST_HAS_LONG_DOUBLE
2219 inline detail::NanSensitiveFloatingPointNearMatcher<long double> NanSensitiveLongDoubleNear(
long double expected,
long double max_abs_error)
2221 return detail::NanSensitiveFloatingPointNearMatcher<long double>(expected, max_abs_error);
2232 template<
typename T>
2233 detail::StrEqMatcher<T>
StrEq(
const T& expected)
2235 return detail::StrEqMatcher<T>(expected);
2242 template<
typename T>
2243 detail::StrNeMatcher<T>
StrNe(
const T& expected)
2245 return detail::StrNeMatcher<T>(expected);
2252 template<
typename T>
2253 detail::StrCaseEqMatcher<T>
StrCaseEq(
const T& expected)
2255 return detail::StrCaseEqMatcher<T>(expected);
2262 template<
typename T>
2263 detail::StrCaseNeMatcher<T>
StrCaseNe(
const T& expected)
2265 return detail::StrCaseNeMatcher<T>(expected);
2272 template<
typename T>
2273 detail::StartsWithMatcher<const T&>
StartsWith(
const T& str)
2275 return detail::StartsWithMatcher<const T&>(str);
2282 template<
typename T>
2283 detail::HasSubstrMatcher<const T&>
HasSubstr(
const T& str)
2285 return detail::HasSubstrMatcher<const T&>(str);
2292 template<
typename T>
2293 detail::EndsWithMatcher<const T&>
EndsWith(
const T& str)
2295 return detail::EndsWithMatcher<const T&>(str);
2302 template<
typename T>
2303 detail::ContainsMatcher<T>
Contains(
const T& expected)
2305 return detail::ContainsMatcher<T>(expected);
2308 #if IUTEST_HAS_MATCHER_EACH
2314 template<
typename T>
2315 detail::EachMatcher<T>
Each(
const T& expected)
2317 return detail::EachMatcher<T>(expected);
2326 template<
typename T>
2327 detail::ContainerEqMatcher<T>
ContainerEq(
const T& expected)
2329 return detail::ContainerEqMatcher<T>(expected);
2332 #if IUTEST_HAS_MATCHER_POINTWISE
2338 template<
typename M,
typename T>
2339 detail::PointwiseMatcher<M, T>
Pointwise(
const M& matcher,
const T& expected)
2341 return detail::PointwiseMatcher<M, T>(matcher, expected);
2346 #if IUTEST_HAS_MATCHER_OPTIONAL
2352 template<
typename T>
2353 detail::OptionalMatcher<T>
Optional(
const T& expected)
2355 return detail::OptionalMatcher<T>(expected);
2364 inline detail::IsEmptyMatcher
IsEmpty()
2366 return detail::IsEmptyMatcher();
2373 template<
typename T>
2374 detail::SizeIsMatcher<T>
SizeIs(
const T& expected)
2376 return detail::SizeIsMatcher<T>(expected);
2383 template<
typename T>
2384 detail::AtMatcher<T>
At(
size_t index,
const T& expected)
2386 return detail::AtMatcher<T>(index, expected);
2393 template<
typename Container>
2394 detail::ElementsAreArrayMatcher< typename Container::value_type >
ElementsAreArray(
const Container& container)
2397 return detail::ElementsAreArrayMatcher<typename Container::value_type>(container.begin(), container.end());
2400 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
2402 template<
typename T,
size_t SIZE>
2405 return detail::ElementsAreArrayMatcher<T>(v, v + SIZE);
2408 #if !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
2410 template<
typename Ite>
2411 detail::ElementsAreArrayMatcher< typename detail::IteratorTraits<Ite>::type >
ElementsAreArray(Ite begin, Ite end)
2413 return detail::ElementsAreArrayMatcher< typename detail::IteratorTraits<Ite>::type >(begin, end);
2417 #if IUTEST_HAS_INITIALIZER_LIST
2419 template<
typename T>
2420 detail::ElementsAreArrayMatcher<T>
ElementsAreArray(::std::initializer_list<T> l)
2422 return detail::ElementsAreArrayMatcher<T>(l.begin(), l.end());
2432 template<
typename T>
2435 return detail::ElementsAreArrayMatcher<T>(a, a + count);
2438 #if IUTEST_HAS_MATCHER_ELEMENTSAREARRAYFORWARD
2444 template<
typename Container>
2445 detail::ElementsAreArrayMatcher< typename Container::value_type >
ElementsAreArrayForward(
const Container& container)
2447 return detail::ElementsAreArrayMatcher<typename Container::value_type>(container.begin(), container.end(),
false);
2450 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
2452 template<
typename T,
size_t SIZE>
2455 return detail::ElementsAreArrayMatcher<T>(v, v + SIZE,
false);
2458 #if !defined(IUTEST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
2460 template<
typename Ite>
2461 detail::ElementsAreArrayMatcher< typename detail::IteratorTraits<Ite>::type >
ElementsAreArrayForward(Ite begin, Ite end)
2463 return detail::ElementsAreArrayMatcher< typename detail::IteratorTraits<Ite>::type >(begin, end,
false);
2467 #if IUTEST_HAS_INITIALIZER_LIST
2469 template<
typename T>
2472 return detail::ElementsAreArrayMatcher<T>(l.begin(), l.end(),
false);
2482 template<
typename T>
2485 return detail::ElementsAreArrayMatcher<T>(a, a + count,
false);
2490 #if IUTEST_HAS_MATCHER_ELEMENTSARE
2492 #if IUTEST_HAS_MATCHER_VARIADIC
2497 template<
typename ...T>
2498 detail::ElementsAreMatcher<T...>
ElementsAre(
const T&... m)
2500 return detail::ElementsAreMatcher<T...>(m...);
2505 #define IIUT_ELEMENTSARE_MATCHER_NAME(n) IUTEST_PP_CAT(ElementsAreMatcher, n)
2506 #define IIUT_DECL_ELEMENTSARE(n) \
2507 template< IUTEST_PP_ENUM_PARAMS(n, typename T) > \
2508 detail:: IIUT_ELEMENTSARE_MATCHER_NAME(n)< IUTEST_PP_ENUM_PARAMS(n, T) > \
2509 ElementsAre( IUTEST_PP_ENUM_BINARY_PARAMS(n, const T, &m) ) { return \
2510 detail:: IIUT_ELEMENTSARE_MATCHER_NAME(n)< IUTEST_PP_ENUM_PARAMS(n, T) > \
2511 ( IUTEST_PP_ENUM_PARAMS(n, m) ); }
2514 IIUT_DECL_ELEMENTSARE(1)
2515 IIUT_DECL_ELEMENTSARE(2)
2516 IIUT_DECL_ELEMENTSARE(3)
2517 IIUT_DECL_ELEMENTSARE(4)
2518 IIUT_DECL_ELEMENTSARE(5)
2519 IIUT_DECL_ELEMENTSARE(6)
2520 IIUT_DECL_ELEMENTSARE(7)
2521 IIUT_DECL_ELEMENTSARE(8)
2522 IIUT_DECL_ELEMENTSARE(9)
2523 IIUT_DECL_ELEMENTSARE(10)
2525 #undef IIUT_ELEMENTSARE_MATCHER_NAME
2526 #undef IIUT_DECL_ELEMENTSARE
2535 template<
typename T>
2536 detail::KeyMatcher<T>
Key(
const T& expected)
2538 return detail::KeyMatcher<T>(expected);
2545 template<
typename T1,
typename T2>
2546 detail::PairMatcher<T1, T2>
Pair(
const T1& m1,
const T2& m2)
2548 return detail::PairMatcher<T1, T2>(m1, m2);
2555 template<
typename F,
typename T>
2556 detail::FieldMatcher<F, T>
Field(
const F& field,
const T& expected)
2558 return detail::FieldMatcher<F, T>(field, expected);
2565 template<
typename P,
typename T>
2566 detail::PropertyMatcher<P, T>
Property(
const P& prop,
const T& expected)
2568 return detail::PropertyMatcher<P, T>(prop, expected);
2575 template<
typename F,
typename T>
2576 detail::ResultOfMatcher<F, T>
ResultOf(
const F& func,
const T& expected)
2578 return detail::ResultOfMatcher<F, T>(func, expected);
2584 template<
typename T>
2585 detail::PointeeMatcher<T>
Pointee(
const T& expected)
2587 return detail::PointeeMatcher<T>(expected);
2593 template<
typename T>
2594 detail::NotMatcher<T>
Not(
const T& unexpected)
2596 return detail::NotMatcher<T>(unexpected);
2602 template<
typename T>
2603 detail::AnyMatcher<T>
A()
2605 return detail::AnyMatcher<T>();
2612 const detail::AnythingMatcher
_;
2614 #if IUTEST_HAS_MATCHER_REGEX
2619 inline detail::RegexMatcher MatchesRegex(const ::std::string& str)
2621 return detail::RegexMatcher(detail::iuRegex(str),
true);
2627 inline detail::RegexMatcher ContainsRegex(const ::std::string& str)
2629 return detail::RegexMatcher(detail::iuRegex(str),
false);
2634 #if IUTEST_HAS_MATCHER_ALLOF_AND_ANYOF
2636 #if IUTEST_HAS_MATCHER_VARIADIC
2642 template<
typename ...T>
2643 detail::AllOfMatcher<T...>
AllOf(
const T&... m)
2645 return detail::AllOfMatcher<T...>(m...);
2652 template<
typename ...T>
2653 detail::AnyOfMatcher<T...>
AnyOf(
const T&... m)
2655 return detail::AnyOfMatcher<T...>(m...);
2660 #define IIUT_ANYOF_AND_ALLOF_MATCHER_NAME(name, n) IUTEST_PP_CAT( IUTEST_PP_CAT(name, Matcher), n)
2661 #define IIUT_DECL_ANYOF_AND_ALLOF(name, n) \
2662 template< IUTEST_PP_ENUM_PARAMS(n, typename T) > \
2663 detail:: IIUT_ANYOF_AND_ALLOF_MATCHER_NAME(name, n)< IUTEST_PP_ENUM_PARAMS(n, T) > \
2664 name( IUTEST_PP_ENUM_BINARY_PARAMS(n, const T, &m) ) { return \
2665 detail:: IIUT_ANYOF_AND_ALLOF_MATCHER_NAME(name, n)< IUTEST_PP_ENUM_PARAMS(n, T) > \
2666 ( IUTEST_PP_ENUM_PARAMS(n, m) ); }
2669 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 2)
2670 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 3)
2671 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 4)
2672 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 5)
2673 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 6)
2674 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 7)
2675 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 8)
2676 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 9)
2677 IIUT_DECL_ANYOF_AND_ALLOF(
AllOf, 10)
2679 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 2)
2680 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 3)
2681 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 4)
2682 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 5)
2683 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 6)
2684 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 7)
2685 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 8)
2686 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 9)
2687 IIUT_DECL_ANYOF_AND_ALLOF(
AnyOf, 10)
2689 #undef IIUT_ANYOF_AND_ALLOF_MATCHER_NAME
2690 #undef IIUT_DECL_ANYOF_AND_ALLOF
2699 template<
typename T,
typename M>
2700 bool Value(
const T& value,
const M& expected)
2702 return static_cast<bool>(detail::CastToMatcher(expected)(value));
2711 using namespace matchers;
detail::TwofoldGtMatcher Gt()
Make Twofold Gt matcher
Definition: iutest_matcher.hpp:2028
detail::HasSubstrMatcher< const T & > HasSubstr(const T &str)
Make HasSubstr matcher
Definition: iutest_matcher.hpp:2284
detail::NanSensitiveFloatingPointNearMatcher< double > NanSensitiveDoubleNear(double expected, double max_abs_error)
Make NanSensitive Double Near matcher
Definition: iutest_matcher.hpp:2209
detail::EachMatcher< T > Each(const T &expected)
Make Each matcher
Definition: iutest_matcher.hpp:2316
detail::NotNullMatcher NotNull()
Make NotNull matcher
Definition: iutest_matcher.hpp:2046
detail::EndsWithMatcher< const T & > EndsWith(const T &str)
Make EndsWith matcher
Definition: iutest_matcher.hpp:2294
detail::AnyOfMatcher< T... > AnyOf(const T &... m)
Make AnyOf matcher
Definition: iutest_matcher.hpp:2654
detail::ElementsAreArrayMatcher< T > ElementsAreArray(const T *a, int count)
Make ElementsAreArray matcher
Definition: iutest_matcher.hpp:2434
detail::NanSensitiveFloatingPointEqMatcher< T > NanSensitiveFloatingPointEq(T expected)
Make FloatingPoint Eq matcher
Definition: iutest_matcher.hpp:2107
detail::StrEqMatcher< T > StrEq(const T &expected)
Make StrEq matcher
Definition: iutest_matcher.hpp:2234
detail::AllOfMatcher< T... > AllOf(const T &... m)
Make AllOf matcher
Definition: iutest_matcher.hpp:2644
detail::PairMatcher< T1, T2 > Pair(const T1 &m1, const T2 &m2)
Make Pair matcher
Definition: iutest_matcher.hpp:2547
detail::IsNullMatcher IsNull()
Make IsNull matcher
Definition: iutest_matcher.hpp:2037
detail::NotMatcher< T > Not(const T &unexpected)
Make Not matcher
Definition: iutest_matcher.hpp:2595
detail::StartsWithMatcher< const T & > StartsWith(const T &str)
Make StartsWith matcher
Definition: iutest_matcher.hpp:2274
detail::TypedEqMatcher< T > TypedEq(const U &expected)
Make TypedEq matcher
Definition: iutest_matcher.hpp:2056
detail::FloatingPointEqMatcher< T > FloatingPointEq(T expected)
Make FloatingPoint Eq matcher
Definition: iutest_matcher.hpp:2066
detail::AnyMatcher< T > A()
Make Any matcher
Definition: iutest_matcher.hpp:2604
detail::EqMatcher< T > Equals(const T &expected)
Make Equals matcher
Definition: iutest_matcher.hpp:1914
detail::FloatingPointEqMatcher< float > FloatEq(float expected)
Make Float Eq matcher
Definition: iutest_matcher.hpp:2075
detail::ContainerEqMatcher< T > ContainerEq(const T &expected)
Make ContainerEq matcher
Definition: iutest_matcher.hpp:2328
detail::AtMatcher< T > At(size_t index, const T &expected)
Make At matcher
Definition: iutest_matcher.hpp:2385
detail::SizeIsMatcher< T > SizeIs(const T &expected)
Make SizeIs matcher
Definition: iutest_matcher.hpp:2375
detail::NanSensitiveFloatingPointNearMatcher< float > NanSensitiveFloatNear(float expected, float max_abs_error)
Make NanSensitive Float Near matcher
Definition: iutest_matcher.hpp:2200
detail::NanSensitiveFloatingPointNearMatcher< T > NanSensitiveFloatingPointNear(T expected, T max_abs_error)
Make FloatingPoint Near matcher
Definition: iutest_matcher.hpp:2191
detail::FieldMatcher< F, T > Field(const F &field, const T &expected)
Make Field matcher
Definition: iutest_matcher.hpp:2557
detail::PropertyMatcher< P, T > Property(const P &prop, const T &expected)
Make Property matcher
Definition: iutest_matcher.hpp:2567
detail::TwofoldEqMatcher Eq()
Make Twofold Eq matcher
Definition: iutest_matcher.hpp:1983
detail::StrCaseNeMatcher< T > StrCaseNe(const T &expected)
Make StrCaseNe matcher
Definition: iutest_matcher.hpp:2264
detail::TwofoldLtMatcher Lt()
Make Twofold Lt matcher
Definition: iutest_matcher.hpp:2010
detail::NanSensitiveFloatingPointEqMatcher< float > NanSensitiveFloatEq(float expected)
Make NanSensitive Float Eq matcher
Definition: iutest_matcher.hpp:2116
bool Value(const T &value, const M &expected)
Value predicate
Definition: iutest_matcher.hpp:2701
detail::FloatingPointNearMatcher< double > DoubleNear(double expected, double max_abs_error)
Make Double Near matcher
Definition: iutest_matcher.hpp:2168
detail::PointeeMatcher< T > Pointee(const T &expected)
Make Pointee matcher
Definition: iutest_matcher.hpp:2586
detail::PointwiseMatcher< M, T > Pointwise(const M &matcher, const T &expected)
Make Pointwise matcher
Definition: iutest_matcher.hpp:2340
detail::NanSensitiveFloatingPointEqMatcher< double > NanSensitiveDoubleEq(double expected)
Make NanSensitive Double Eq matcher
Definition: iutest_matcher.hpp:2125
detail::ElementsAreMatcher< T... > ElementsAre(const T &... m)
Make ElementsAre matcher
Definition: iutest_matcher.hpp:2499
detail::TwofoldGeMatcher Ge()
Make Twofold Ge matcher
Definition: iutest_matcher.hpp:2019
detail::TwofoldNeMatcher Ne()
Make Twofold Ne matcher
Definition: iutest_matcher.hpp:1992
detail::ElementsAreArrayMatcher< T > ElementsAreArrayForward(const T *a, int count)
Make ElementsAreArrayForward matcher
Definition: iutest_matcher.hpp:2484
detail::StrNeMatcher< T > StrNe(const T &expected)
Make StrNe matcher
Definition: iutest_matcher.hpp:2244
detail::KeyMatcher< T > Key(const T &expected)
Make Key matcher
Definition: iutest_matcher.hpp:2537
detail::ResultOfMatcher< F, T > ResultOf(const F &func, const T &expected)
Make ResultOf matcher
Definition: iutest_matcher.hpp:2577
detail::FloatingPointNearMatcher< float > FloatNear(float expected, float max_abs_error)
Make Float Near matcher
Definition: iutest_matcher.hpp:2159
detail::IsEmptyMatcher IsEmpty()
Make IsEmpty matcher
Definition: iutest_matcher.hpp:2365
const detail::AnythingMatcher _
Anything matcher
Definition: iutest_matcher.hpp:2613
detail::TwofoldLeMatcher Le()
Make Twofold Le matcher
Definition: iutest_matcher.hpp:2001
detail::StrCaseEqMatcher< T > StrCaseEq(const T &expected)
Make StrCaseEq matcher
Definition: iutest_matcher.hpp:2254
detail::FloatingPointEqMatcher< double > DoubleEq(double expected)
Make Double Eq matcher
Definition: iutest_matcher.hpp:2084
detail::OptionalMatcher< T > Optional(const T &expected)
Make Optional matcher
Definition: iutest_matcher.hpp:2354
detail::ContainsMatcher< T > Contains(const T &expected)
Make Contains matcher
Definition: iutest_matcher.hpp:2304
detail::FloatingPointNearMatcher< T > FloatingPointNear(T expected, T max_abs_error)
Make FloatingPoint Near matcher
Definition: iutest_matcher.hpp:2150
#define IUTEST_CXX_FINAL
final definition
Definition: iutest_compiler.hpp:756
#define IUTEST_CXX_OVERRIDE
override definition
Definition: iutest_compiler.hpp:747
#define IUTEST_USING_BEGIN_END()
using begin,end
Definition: iutest_stdlib.hpp:34
iutest root namespace
Definition: iutest_charcode.hpp:33
AssertionResult AssertionSuccess()
テスト成功を示す AssertionResult オブジェクトの取得
Definition: iutest_assertion.hpp:406
std::string PrintToString(const T &v)
文字列化
Definition: iutest_printers.hpp:767
AssertionResult AssertionFailure()
テスト失敗を示す AssertionResult オブジェクトの取得
Definition: iutest_assertion.hpp:410
detail::iuStreamMessage Message
Message クラス
Definition: iutest_assertion.hpp:33