iutest  1.17.99.14
iutest_util_assertion.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_UTIL_ASSERTION_HPP_A45F8265_40E0_44F2_91C6_090B1778657C_
16 #define INCG_IRIS_IUTEST_UTIL_ASSERTION_HPP_A45F8265_40E0_44F2_91C6_090B1778657C_
17 
18 //======================================================================
19 // include
20 #include "../internal/iutest_type_traits.hpp"
21 
22 //======================================================================
23 // define
32 #ifndef IUTEST_ASSERT_EQ_COLLECTIONS
33 # define IUTEST_ASSERT_EQ_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_EQ_COLLECTIONS(b1, e1, b2, e2, IUTEST_ASSERT_FAILURE)
34 #endif
43 #ifndef IUTEST_EXPECT_EQ_COLLECTIONS
44 # define IUTEST_EXPECT_EQ_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_EQ_COLLECTIONS(b1, e1, b2, e2, IUTEST_EXPECT_FAILURE)
45 #endif
54 #ifndef IUTEST_INFORM_EQ_COLLECTIONS
55 # define IUTEST_INFORM_EQ_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_EQ_COLLECTIONS(b1, e1, b2, e2, IUTEST_INFORM_FAILURE)
56 #endif
65 #ifndef IUTEST_ASSUME_EQ_COLLECTIONS
66 # define IUTEST_ASSUME_EQ_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_EQ_COLLECTIONS(b1, e1, b2, e2, IUTEST_ASSUME_FAILURE)
67 #endif
68 
77 #ifndef IUTEST_ASSERT_NE_COLLECTIONS
78 # define IUTEST_ASSERT_NE_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_NE_COLLECTIONS(b1, e1, b2, e2, IUTEST_ASSERT_FAILURE)
79 #endif
88 #ifndef IUTEST_EXPECT_NE_COLLECTIONS
89 # define IUTEST_EXPECT_NE_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_NE_COLLECTIONS(b1, e1, b2, e2, IUTEST_EXPECT_FAILURE)
90 #endif
99 #ifndef IUTEST_INFORM_NE_COLLECTIONS
100 # define IUTEST_INFORM_NE_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_NE_COLLECTIONS(b1, e1, b2, e2, IUTEST_INFORM_FAILURE)
101 #endif
110 #ifndef IUTEST_ASSUME_NE_COLLECTIONS
111 # define IUTEST_ASSUME_NE_COLLECTIONS(b1, e1, b2, e2) IUTEST_TEST_NE_COLLECTIONS(b1, e1, b2, e2, IUTEST_ASSUME_FAILURE)
112 #endif
113 
120 #ifndef IUTEST_ASSERT_EQ_RANGE
121 # define IUTEST_ASSERT_EQ_RANGE(expected, actual) IUTEST_TEST_EQ_RANGE(expected, actual, IUTEST_ASSERT_FAILURE)
122 #endif
129 #ifndef IUTEST_EXPECT_EQ_RANGE
130 # define IUTEST_EXPECT_EQ_RANGE(expected, actual) IUTEST_TEST_EQ_RANGE(expected, actual, IUTEST_EXPECT_FAILURE)
131 #endif
138 #ifndef IUTEST_INFORM_EQ_RANGE
139 # define IUTEST_INFORM_EQ_RANGE(expected, actual) IUTEST_TEST_EQ_RANGE(expected, actual, IUTEST_INFORM_FAILURE)
140 #endif
147 #ifndef IUTEST_ASSUME_EQ_RANGE
148 # define IUTEST_ASSUME_EQ_RANGE(expected, actual) IUTEST_TEST_EQ_RANGE(expected, actual, IUTEST_ASSUME_FAILURE)
149 #endif
150 
157 #ifndef IUTEST_ASSERT_NE_RANGE
158 # define IUTEST_ASSERT_NE_RANGE(expected, actual) IUTEST_TEST_NE_RANGE(expected, actual, IUTEST_ASSERT_FAILURE)
159 #endif
166 #ifndef IUTEST_EXPECT_NE_RANGE
167 # define IUTEST_EXPECT_NE_RANGE(expected, actual) IUTEST_TEST_NE_RANGE(expected, actual, IUTEST_EXPECT_FAILURE)
168 #endif
175 #ifndef IUTEST_INFORM_NE_RANGE
176 # define IUTEST_INFORM_NE_RANGE(expected, actual) IUTEST_TEST_NE_RANGE(expected, actual, IUTEST_INFORM_FAILURE)
177 #endif
184 #ifndef IUTEST_ASSUME_NE_RANGE
185 # define IUTEST_ASSUME_NE_RANGE(expected, actual) IUTEST_TEST_NE_RANGE(expected, actual, IUTEST_ASSUME_FAILURE)
186 #endif
187 
194 #ifndef IUTEST_ASSERT_STRLNEQ
195 # define IUTEST_ASSERT_STRLNEQ(len, v2) IUTEST_TEST_STRLNEQ(len, v2, IUTEST_ASSERT_FAILURE)
196 #endif
203 #ifndef IUTEST_EXPECT_STRLNEQ
204 # define IUTEST_EXPECT_STRLNEQ(len, v2) IUTEST_TEST_STRLNEQ(len, v2, IUTEST_EXPECT_FAILURE)
205 #endif
212 #ifndef IUTEST_INFORM_STRLNEQ
213 # define IUTEST_INFORM_STRLNEQ(len, v2) IUTEST_TEST_STRLNEQ(len, v2, IUTEST_INFORM_FAILURE)
214 #endif
221 #ifndef IUTEST_ASSUME_STRLNEQ
222 # define IUTEST_ASSUME_STRLNEQ(len, v2) IUTEST_TEST_STRLNEQ(len, v2, IUTEST_ASSUME_FAILURE)
223 #endif
224 
231 #ifndef IUTEST_ASSERT_STRIN
232 # define IUTEST_ASSERT_STRIN(substr, actual) IUTEST_TEST_STRIN(substr, actual, IUTEST_ASSERT_FAILURE)
233 #endif
240 #ifndef IUTEST_EXPECT_STRIN
241 # define IUTEST_EXPECT_STRIN(substr, actual) IUTEST_TEST_STRIN(substr, actual, IUTEST_EXPECT_FAILURE)
242 #endif
249 #ifndef IUTEST_INFORM_STRIN
250 # define IUTEST_INFORM_STRIN(substr, actual) IUTEST_TEST_STRIN(substr, actual, IUTEST_INFORM_FAILURE)
251 #endif
258 #ifndef IUTEST_ASSUME_STRIN
259 # define IUTEST_ASSUME_STRIN(substr, actual) IUTEST_TEST_STRIN(substr, actual, IUTEST_ASSUME_FAILURE)
260 #endif
261 
262 
269 #ifndef IUTEST_ASSERT_STRNOTIN
270 # define IUTEST_ASSERT_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_ASSERT_FAILURE)
271 #endif
278 #ifndef IUTEST_EXPECT_STRNOTIN
279 # define IUTEST_EXPECT_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_EXPECT_FAILURE)
280 #endif
287 #ifndef IUTEST_INFORM_STRNOTIN
288 # define IUTEST_INFORM_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_INFORM_FAILURE)
289 #endif
296 #ifndef IUTEST_ASSUME_STRNOTIN
297 # define IUTEST_ASSUME_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_ASSUME_FAILURE)
298 #endif
299 
300 
306 #ifndef IUTEST_ASSERT_NAN
307 # define IUTEST_ASSERT_NAN(actual) IUTEST_TEST_NAN(actual, IUTEST_ASSERT_FAILURE)
308 #endif
314 #ifndef IUTEST_EXPECT_NAN
315 # define IUTEST_EXPECT_NAN(actual) IUTEST_TEST_NAN(actual, IUTEST_EXPECT_FAILURE)
316 #endif
322 #ifndef IUTEST_INFORM_NAN
323 # define IUTEST_INFORM_NAN(actual) IUTEST_TEST_NAN(actual, IUTEST_INFORM_FAILURE)
324 #endif
330 #ifndef IUTEST_ASSUME_NAN
331 # define IUTEST_ASSUME_NAN(actual) IUTEST_TEST_NAN(actual, IUTEST_ASSUME_FAILURE)
332 #endif
333 
334 #if IUTEST_HAS_REGEX
335 
342 #ifndef IUTEST_ASSERT_MATCHES_REGEXEQ
343 # define IUTEST_ASSERT_MATCHES_REGEXEQ(regex_str, actual) \
344  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_ASSERT_FAILURE)
345 #endif
352 #ifndef IUTEST_EXPECT_MATCHES_REGEXEQ
353 # define IUTEST_EXPECT_MATCHES_REGEXEQ(regex_str, actual) \
354  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_EXPECT_FAILURE)
355 #endif
362 #ifndef IUTEST_INFORM_MATCHES_REGEXEQ
363 # define IUTEST_INFORM_MATCHES_REGEXEQ(regex_str, actual) \
364  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_INFORM_FAILURE)
365 #endif
372 #ifndef IUTEST_ASSUME_MATCHES_REGEXEQ
373 # define IUTEST_ASSUME_MATCHES_REGEXEQ(regex_str, actual) \
374  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_ASSUME_FAILURE)
375 #endif
376 
383 #ifndef IUTEST_ASSERT_MATCHES_REGEXNE
384 # define IUTEST_ASSERT_MATCHES_REGEXNE(regex_str, actual) \
385  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_ASSERT_FAILURE)
386 #endif
393 #ifndef IUTEST_EXPECT_MATCHES_REGEXNE
394 # define IUTEST_EXPECT_MATCHES_REGEXNE(regex_str, actual) \
395  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_EXPECT_FAILURE)
396 #endif
403 #ifndef IUTEST_INFORM_MATCHES_REGEXNE
404 # define IUTEST_INFORM_MATCHES_REGEXNE(regex_str, actual) \
405  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_INFORM_FAILURE)
406 #endif
413 #ifndef IUTEST_ASSUME_MATCHES_REGEXNE
414 # define IUTEST_ASSUME_MATCHES_REGEXNE(regex_str, actual) \
415  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_ASSUME_FAILURE)
416 #endif
417 
418 
419 
426 #ifndef IUTEST_ASSERT_CONTAINS_REGEXEQ
427 # define IUTEST_ASSERT_CONTAINS_REGEXEQ(regex_str, actual) \
428  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_ASSERT_FAILURE)
429 #endif
436 #ifndef IUTEST_EXPECT_CONTAINS_REGEXEQ
437 # define IUTEST_EXPECT_CONTAINS_REGEXEQ(regex_str, actual) \
438  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_EXPECT_FAILURE)
439 #endif
446 #ifndef IUTEST_INFORM_CONTAINS_REGEXEQ
447 # define IUTEST_INFORM_CONTAINS_REGEXEQ(regex_str, actual) \
448  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_INFORM_FAILURE)
449 #endif
456 #ifndef IUTEST_ASSUME_CONTAINS_REGEXEQ
457 # define IUTEST_ASSUME_CONTAINS_REGEXEQ(regex_str, actual) \
458  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_ASSUME_FAILURE)
459 #endif
460 
467 #ifndef IUTEST_ASSERT_CONTAINS_REGEXNE
468 # define IUTEST_ASSERT_CONTAINS_REGEXNE(regex_str, actual) \
469  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_ASSERT_FAILURE)
470 #endif
477 #ifndef IUTEST_EXPECT_CONTAINS_REGEXNE
478 # define IUTEST_EXPECT_CONTAINS_REGEXNE(regex_str, actual) \
479  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_EXPECT_FAILURE)
480 #endif
487 #ifndef IUTEST_INFORM_CONTAINS_REGEXNE
488 # define IUTEST_INFORM_CONTAINS_REGEXNE(regex_str, actual) \
489  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_INFORM_FAILURE)
490 #endif
497 #ifndef IUTEST_ASSUME_CONTAINS_REGEXNE
498 # define IUTEST_ASSUME_CONTAINS_REGEXNE(regex_str, actual) \
499  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_ASSUME_FAILURE)
500 #endif
501 
502 #endif
503 
510 #ifndef IUTEST_NO_UTIL_ASSERTION_GTEST_COMPATIBLE
511 
512 #define ASSERT_EQ_COLLECTIONS IUTEST_ASSERT_EQ_COLLECTIONS
513 #define ASSERT_NE_COLLECTIONS IUTEST_ASSERT_NE_COLLECTIONS
514 #define ASSERT_EQ_RANGE IUTEST_ASSERT_EQ_RANGE
515 #define ASSERT_NE_RANGE IUTEST_ASSERT_NE_RANGE
516 #define ASSERT_STRLNEQ IUTEST_ASSERT_STRLNEQ
517 #define ASSERT_STRIN IUTEST_ASSERT_STRIN
518 #define ASSERT_STRNOTIN IUTEST_ASSERT_STRNOTIN
519 #define ASSERT_BAB IUTEST_ASSERT_NAN
520 
521 #define EXPECT_EQ_COLLECTIONS IUTEST_EXPECT_EQ_COLLECTIONS
522 #define EXPECT_NE_COLLECTIONS IUTEST_EXPECT_NE_COLLECTIONS
523 #define EXPECT_EQ_RANGE IUTEST_EXPECT_EQ_RANGE
524 #define EXPECT_NE_RANGE IUTEST_EXPECT_NE_RANGE
525 #define EXPECT_STRLNEQ IUTEST_EXPECT_STRLNEQ
526 #define EXPECT_STRIN IUTEST_EXPECT_STRIN
527 #define EXPECT_STRNOTIN IUTEST_EXPECT_STRNOTIN
528 #define EXPECT_NAN IUTEST_EXPECT_NAN
529 
530 #define INFORM_EQ_COLLECTIONS IUTEST_INFORM_EQ_COLLECTIONS
531 #define INFORM_NE_COLLECTIONS IUTEST_INFORM_NE_COLLECTIONS
532 #define INFORM_EQ_RANGE IUTEST_INFORM_EQ_RANGE
533 #define INFORM_NE_RANGE IUTEST_INFORM_NE_RANGE
534 #define INFORM_STRLNEQ IUTEST_INFORM_STRLNEQ
535 #define INFORM_STRIN IUTEST_INFORM_STRIN
536 #define INFORM_STRNOTIN IUTEST_INFORM_STRNOTIN
537 #define INFORM_NAN IUTEST_INFORM_NAN
538 
539 #define ASSUME_EQ_COLLECTIONS IUTEST_ASSUME_EQ_COLLECTIONS
540 #define ASSUME_NE_COLLECTIONS IUTEST_ASSUME_NE_COLLECTIONS
541 #define ASSUME_EQ_RANGE IUTEST_ASSUME_EQ_RANGE
542 #define ASSUME_NE_RANGE IUTEST_ASSUME_NE_RANGE
543 #define ASSUME_STRLNEQ IUTEST_ASSUME_STRLNEQ
544 #define ASSUME_STRIN IUTEST_ASSUME_STRIN
545 #define ASSUME_STRNOTIN IUTEST_ASSUME_STRNOTIN
546 #define ASSUME_NAN IUTEST_ASSUME_NAN
547 
548 #if IUTEST_HAS_REGEX
549 
550 #define ASSERT_MATCHES_REGEXEQ IUTEST_ASSERT_MATCHES_REGEXEQ
551 #define EXPECT_MATCHES_REGEXEQ IUTEST_EXPECT_MATCHES_REGEXEQ
552 #define INFORM_MATCHES_REGEXEQ IUTEST_INFORM_MATCHES_REGEXEQ
553 #define ASSUME_MATCHES_REGEXEQ IUTEST_ASSUME_MATCHES_REGEXEQ
554 
555 #define ASSERT_MATCHES_REGEXNE IUTEST_ASSERT_MATCHES_REGEXNE
556 #define EXPECT_MATCHES_REGEXNE IUTEST_EXPECT_MATCHES_REGEXNE
557 #define INFORM_MATCHES_REGEXNE IUTEST_INFORM_MATCHES_REGEXNE
558 #define ASSUME_MATCHES_REGEXNE IUTEST_ASSUME_MATCHES_REGEXNE
559 
560 #define ASSERT_CONTAINS_REGEXEQ IUTEST_ASSERT_CONTAINS_REGEXEQ
561 #define EXPECT_CONTAINS_REGEXEQ IUTEST_EXPECT_CONTAINS_REGEXEQ
562 #define INFORM_CONTAINS_REGEXEQ IUTEST_INFORM_CONTAINS_REGEXEQ
563 #define ASSUME_CONTAINS_REGEXEQ IUTEST_ASSUME_CONTAINS_REGEXEQ
564 
565 #define ASSERT_CONTAINS_REGEXNE IUTEST_ASSERT_CONTAINS_REGEXNE
566 #define EXPECT_CONTAINS_REGEXNE IUTEST_EXPECT_CONTAINS_REGEXNE
567 #define INFORM_CONTAINS_REGEXNE IUTEST_INFORM_CONTAINS_REGEXNE
568 #define ASSUME_CONTAINS_REGEXNE IUTEST_ASSUME_CONTAINS_REGEXNE
569 
570 #endif
571 
572 #endif
573 
582 #define IUTEST_TEST_EQ_COLLECTIONS(b1, e1, b2, e2, on_failure) IUTEST_PRED_FORMAT4_( ::iuutil::CmpHelperEqCollections, b1, e1, b2, e2, on_failure)
583 #define IUTEST_TEST_NE_COLLECTIONS(b1, e1, b2, e2, on_failure) IUTEST_PRED_FORMAT4_( ::iuutil::CmpHelperNeCollections, b1, e1, b2, e2, on_failure)
584 #define IUTEST_TEST_EQ_RANGE(expected, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperEqRange, expected, actual, on_failure)
585 #define IUTEST_TEST_NE_RANGE(expected, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperNeRange, expected, actual, on_failure)
586 
587 #define IUTEST_TEST_STRLNEQ(len, v2, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperSTRLNEQ, len, v2, on_failure )
588 #define IUTEST_TEST_STRIN(substr, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperSTRIN, substr, actual, on_failure )
589 #define IUTEST_TEST_STRNOTIN(substr, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperSTRNOTIN, substr, actual, on_failure )
590 
591 #define IUTEST_TEST_NAN(actual, on_failure) IUTEST_PRED_FORMAT1_( ::iuutil::CmpHelperIsNan, actual, on_failure )
592 
593 #if IUTEST_HAS_REGEX
594 
595 #define IUTEST_TEST_MATCHES_REGEXEQ(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperMatchesRegexEq, regex, actual, on_failure )
596 #define IUTEST_TEST_MATCHES_REGEXNE(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperMatchesRegexNe, regex, actual, on_failure )
597 
598 #define IUTEST_TEST_CONTAINS_REGEXEQ(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperContainsRegexEq, regex, actual, on_failure )
599 #define IUTEST_TEST_CONTAINS_REGEXNE(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperContainsRegexNe, regex, actual, on_failure )
600 
601 #endif
602 
607 namespace iuutil
608 {
609 
610 //======================================================================
611 // function
615 template<typename T1, typename T2>
616 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqIterator(T1 b1, T1 e1, T2 b2, T2 e2)
617 {
618  int elem=0;
619  bool result = true;
621  for(elem=0; b1 != e1 && b2 != e2; ++b1, ++b2, ++elem)
622  {
623  if(!::iutest::internal::backward::EqHelper<false>::Compare("", "", *b1, *b2))
624  {
625  result = false;
626  ar << "\nMismatch in a position " << elem << ": "
627  << ::iutest::internal::FormatForComparisonFailureMessage(*b1, *b2)
628  << " vs " << ::iutest::internal::FormatForComparisonFailureMessage(*b2, *b1);
629  }
630  }
631  if(b1 != e1)
632  {
633  int elem1 = elem;
634  for(; b1 != e1; ++b1, ++elem1) {}
635  result = false;
636  ar << "\nMismatch element : " << elem1 << " vs " << elem;
637  }
638  if(b2 != e2)
639  {
640  int elem2 = elem;
641  for(; b2 != e2; ++b2, ++elem2) {}
642  result = false;
643  ar << "\nMismatch element : " << elem << " vs " << elem2;
644  }
645  if( !result )
646  {
648  }
650 }
651 
652 template<typename T1, typename T2>
653 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeIterator(T1 b1, T1 e1, T2 b2, T2 e2)
654 {
655  int elem=0;
656  bool result = false;
658  for(elem=0; b1 != e1 && b2 != e2; ++b1, ++b2, ++elem)
659  {
660  if(!::iutest::internal::backward::NeHelper<false>::Compare("", "", *b1, *b2))
661  {
662  ar << ::iutest::internal::FormatForComparisonFailureMessage(*b1, *b2);
663  }
664  else
665  {
666  result = true;
667  }
668  }
669  if( (b1 != e1) || (b2 != e2) )
670  {
671  result = true;
672  }
673  if( !result )
674  {
676  }
678 }
679 
680 
684 template<typename T1, typename T2>
685 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqCollections(const char* expr1b, const char* expr1e
686  , const char* expr2b, const char* expr2e
687  , T1 b1, T1 e1, T2 b2, T2 e2)
688 {
689  if( ::iutest::AssertionResult ar = CmpHelperEqIterator(b1, e1, b2, e2) )
690  {
692  }
693  else
694  {
695  return ::iutest::AssertionFailure() << "error: Expected: { " << expr1b << ", " << expr1e << " } == { "
696  << expr2b << ", " << expr2e << " }\n Actual:" << GetAssertionResultMessage(ar);
697  }
698 }
699 
703 template<typename T1, typename T2>
704 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeCollections(const char* expr1b, const char* expr1e
705  , const char* expr2b, const char* expr2e
706  , T1 b1, T1 e1, T2 b2, T2 e2)
707 {
708  if( ::iutest::AssertionResult ar = CmpHelperNeIterator(b1, e1, b2, e2) )
709  {
711  }
712  else
713  {
714  return ::iutest::AssertionFailure() << "error: Expected: { " << expr1b << ", " << expr1e << " } != { "
715  << expr2b << ", " << expr2e << " }\n Actual:" << GetAssertionResultMessage(ar);
716  }
717 }
718 
719 namespace detail
720 {
721 
722 template<typename T1, typename T2>
723 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char* expected_expr, const char* actual_expr
724  , T1 b1, T1 e1, T2 b2, T2 e2)
725 {
726  if( ::iutest::AssertionResult ar = CmpHelperEqIterator(b1, e1, b2, e2) )
727  {
729  }
730  else
731  {
732  return ::iutest::AssertionFailure() << "error: Expected: " << expected_expr << " == " << actual_expr
733  << " \n Actual:" << GetAssertionResultMessage(ar);
734  }
735 }
736 
737 } // end of namespace detail
738 
742 template<typename T1, typename T2>
743 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char* expected_expr, const char* actual_expr
744  , const T1& expected, const T2& actual)
745 {
747  return detail::CmpHelperEqRange(expected_expr, actual_expr, begin(expected), end(expected)
748  , begin(actual), end(actual));
749 }
750 
754 template<typename T1, typename T2>
755 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeRange(const char* expected_expr, const char* actual_expr
756  , const T1& expected, const T2& actual)
757 {
759  if( ::iutest::AssertionResult ar =
760  CmpHelperNeIterator(begin(expected), end(expected), begin(actual), end(actual)))
761  {
763  }
764  else
765  {
766  return ::iutest::AssertionFailure() << "error: Expected: " << expected_expr << " != " << actual_expr
767  << " \n Actual:" << ::iutest::internal::FormatForComparisonFailureMessage(expected, actual);
768  }
769 }
770 
774 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char* expr1, const char* expr2
775  , size_t len1, const char* val2)
776 {
777  const size_t len2 = strlen(val2);
778  if( len2 == len1 )
779  {
781  }
782  return ::iutest::AssertionFailure() << "error: Value of: " << expr1 << " == strlen(" << expr2 << ")"
783  << "\n Actual: " << val2 << " : " << len2 << "\nExpected: " << len1;
784 }
788 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char* expr1, const char* expr2
789  , size_t len1, const ::std::string& val2)
790 {
791  const size_t len2 = val2.length();
792  if( len2 == len1 )
793  {
795  }
796  return ::iutest::AssertionFailure() << "error: Value of: " << expr1 << " == strlen(" << expr2 << ")"
797  << "\n Actual: " << val2 << " : " << len2 << "\nExpected: " << len1;
798 }
802 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char* expr1, const char* expr2
803  , size_t len1, const wchar_t* val2)
804 {
805  const size_t len2 = wcslen(val2);
806  if( len2 == len1 )
807  {
809  }
810  return ::iutest::AssertionFailure() << "error: Value of: " << expr1 << " == wcslen(" << expr2 << ")"
811  << "\n Actual: " << val2 << " : " << len2 << "\nExpected: " << len1;
812 }
813 
814 namespace StrInHelper
815 {
816 
817 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const char* substr, const char* actual)
818 {
819  if( substr == NULL || actual == NULL )
820  {
821  return substr == actual;
822  }
823  return strstr(actual, substr) != NULL;
824 }
825 
826 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const wchar_t* substr, const wchar_t* actual)
827 {
828  if( substr == NULL || actual == NULL )
829  {
830  return substr == actual;
831  }
832  return wcsstr(actual, substr) != NULL;
833 }
834 
835 template<typename Elem, typename Traits, typename Ax>
836 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const ::std::basic_string<Elem, Traits, Ax>& substr
837  , const ::std::basic_string<Elem, Traits, Ax>& actual)
838 {
839  return Compare(substr.c_str(), actual.c_str());
840 }
841 template<typename Elem, typename Traits, typename Ax>
842 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const Elem* substr
843  , const ::std::basic_string<Elem, Traits, Ax>& actual)
844 {
845  return Compare(substr, actual.c_str());
846 }
847 template<typename Elem, typename Traits, typename Ax>
848 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const ::std::basic_string<Elem, Traits, Ax>& substr
849  , const Elem* actual)
850 {
851  return Compare(substr.c_str(), actual);
852 }
853 
854 template<typename T1, typename T2>
855 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* substr_str, const char* actual_str
856  , const T1& substr, const T2& actual)
857 {
858  if( Compare(substr, actual) )
859  {
861  }
862 
863  return ::iutest::AssertionFailure() << "error: Expected: " << "strstr(" << actual_str << ", " << substr_str << ") != NULL"
864  << "\n Actual: " << "strstr(\"" << actual << "\", " << substr << ") == NULL";
865 }
866 
867 } // end of namespace StrInHelper
868 
872 template<typename T1, typename T2>
873 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRIN(const char* substr_str, const char* actual_str
874  , const T1& substr, const T2& actual)
875 {
876  return StrInHelper::Assertion(substr_str, actual_str, substr, actual);
877 }
878 
879 namespace StrNotInHelper
880 {
881 
882 template<typename T1, typename T2>
883 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& substr, const T2& actual)
884 {
885  return !StrInHelper::Compare(substr, actual);
886 }
887 
888 template<typename T1, typename T2>
889 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* substr_str, const char* actual_str
890  , const T1& substr, const T2& actual)
891 {
892  if( Compare(substr, actual) )
893  {
895  }
896 
897  return ::iutest::AssertionFailure() << "error: Expected: " << "strstr(" << actual_str << ", " << substr_str << ") == NULL"
898  << "\n Actual: " << "strstr(\"" << actual << "\", " << substr << ") != NULL";
899 }
900 
901 } // end of namespace StrNotInHelper
902 
906 template<typename T1, typename T2>
907 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNOTIN(const char* substr_str, const char* actual_str
908  , const T1& substr, const T2& actual)
909 {
910  return StrNotInHelper::Assertion(substr_str, actual_str, substr, actual);
911 }
912 
913 namespace floationg_point_helper
914 {
915 
916 template<typename T>
917 ::iutest::internal::FloatingPoint<float> CastToFloatingPoint(const T& x)
918 {
919  return ::iutest::internal::FloatingPoint<float>(static_cast<float>(x));
920 }
921 inline ::iutest::internal::FloatingPoint<double> CastToFloatingPoint(const double& x)
922 {
923  return ::iutest::internal::FloatingPoint<double>(x);
924 }
925 
926 } // end of namespace floationg_point_helper
927 
931 template<typename T>
932 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperIsNan(const char* actual_str, const T& actual)
933 {
934  if( floationg_point_helper::CastToFloatingPoint(actual).is_nan() )
935  {
937  }
938  return ::iutest::AssertionFailure() << "error: Value of: " << actual_str
939  << "\n Actual: " << actual << "\nExpected: NaN";
940 }
941 
942 #if IUTEST_HAS_REGEX
943 
944 namespace RegexHelper
945 {
946 
947 inline bool FullMatch(const ::std::string& str, const ::iutest::internal::RE& re)
948 {
949  return ::iutest::internal::RE::FullMatch(str, re);
950 }
951 inline bool FullMatch(const char* str, const ::iutest::internal::RE& re)
952 {
953  if( str == NULL )
954  {
955  return false;
956  }
957  return ::iutest::internal::RE::FullMatch(str, re);
958 }
959 
960 inline bool PartialMatch(const ::std::string& str, const ::iutest::internal::RE& re)
961 {
962  return ::iutest::internal::RE::PartialMatch(str, re);
963 }
964 inline bool PartialMatch(const char* str, const ::iutest::internal::RE& re)
965 {
966  if( str == NULL )
967  {
968  return false;
969  }
970  return ::iutest::internal::RE::PartialMatch(str, re);
971 }
972 
973 } // end of namespace RegexHelper
974 
975 namespace MatchesRegexEqHelper
976 {
977 
978 template<typename T1, typename T2>
979 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& regex, const T2& actual)
980 {
981  ::iutest::internal::RE iure(regex);
982  return RegexHelper::FullMatch(actual, iure);
983 }
984 
985 template<typename T1, typename T2>
986 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
987  , const T1& regex, const T2& actual)
988 {
989  if( Compare(regex, actual) )
990  {
992  }
993  ::std::string expected_str = "Matches Regex (";
994  expected_str += regex_str;
995  expected_str += ")";
996 
997  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
998  , ::iutest::PrintToString(regex)
999  , ::iutest::PrintToString(actual)
1000  , false);
1001 }
1002 
1003 } // end of namespace MatchesRegexEqHelper
1004 
1008 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperMatchesRegexEq(const char* regex_str, const char* actual_str
1009  , const char* regex, const char* actual)
1010 {
1011  return MatchesRegexEqHelper::Assertion(regex_str, actual_str, regex, actual);
1012 }
1013 
1014 namespace MatchesRegexNeHelper
1015 {
1016 
1017 template<typename T1, typename T2>
1018 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
1019  , const T1& regex, const T2& actual)
1020 {
1021  if( !MatchesRegexEqHelper::Compare(regex, actual) )
1022  {
1024  }
1025  ::std::string expected_str = "Not Matches Regex (";
1026  expected_str += regex_str;
1027  expected_str += ")";
1028 
1029  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
1030  , ::iutest::PrintToString(regex)
1031  , ::iutest::PrintToString(actual)
1032  , false);
1033 }
1034 
1035 } // end of namespace MatchesRegexNeHelper
1036 
1040 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperMatchesRegexNe(const char* regex_str, const char* actual_str
1041  , const char* regex, const char* actual)
1042 {
1043  return MatchesRegexNeHelper::Assertion(regex_str, actual_str, regex, actual);
1044 }
1045 
1046 namespace ContainsRegexEqHelper
1047 {
1048 
1049 template<typename T1, typename T2>
1050 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& regex, const T2& actual)
1051 {
1052  ::iutest::internal::RE m(regex);
1053  return RegexHelper::PartialMatch(actual, m);
1054 }
1055 
1056 template<typename T1, typename T2>
1057 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
1058  , const T1& regex, const T2& actual)
1059 {
1060  if( Compare(regex, actual) )
1061  {
1063  }
1064  ::std::string expected_str = "Contains Regex (";
1065  expected_str += regex_str;
1066  expected_str += ")";
1067 
1068  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
1069  , ::iutest::PrintToString(regex)
1070  , ::iutest::PrintToString(actual)
1071  , false);
1072 }
1073 
1074 } // end of namespace ContainsRegexEqHelper
1075 
1079 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperContainsRegexEq(const char* regex_str, const char* actual_str
1080  , const char* regex, const char* actual)
1081 {
1082  return ContainsRegexEqHelper::Assertion(regex_str, actual_str, regex, actual);
1083 }
1084 
1085 namespace ContainsRegexNeHelper
1086 {
1087 
1088 template<typename T1, typename T2>
1089 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
1090  , const T1& regex, const T2& actual)
1091 {
1092  if( !ContainsRegexEqHelper::Compare(regex, actual) )
1093  {
1095  }
1096  ::std::string expected_str = "Not Contains Regex (";
1097  expected_str += regex_str;
1098  expected_str += ")";
1099 
1100  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
1101  , ::iutest::PrintToString(regex)
1102  , ::iutest::PrintToString(actual)
1103  , false);
1104 }
1105 
1106 } // end of namespace ContainsRegexNeHelper
1107 
1111 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperContainsRegexNe(const char* regex_str, const char* actual_str
1112  , const char* regex, const char* actual)
1113 {
1114  return ContainsRegexNeHelper::Assertion(regex_str, actual_str, regex, actual);
1115 }
1116 
1117 #endif
1118 
1119 } // end of namespace iuutil
1120 
1121 #endif // INCG_IRIS_IUTEST_UTIL_ASSERTION_HPP_A45F8265_40E0_44F2_91C6_090B1778657C_
Assertion Result
Definition: iutest_assertion.hpp:67
#define IUTEST_USING_BEGIN_END()
using begin,end
Definition: iutest_stdlib.hpp:34
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
const char * GetAssertionResultMessage(const AssertionResult &ar)
テスト結果のメッセージを取得する(for compatible)
Definition: iutest_assertion.hpp:415
iutest utility namespace
Definition: iutest_util.hpp:36
inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRIN(const char *substr_str, const char *actual_str, const T1 &substr, const T2 &actual)
文字列部分一致アサーションフォーマッター
Definition: iutest_util_assertion.hpp:874
inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char *expr1, const char *expr2, size_t len1, const char *val2)
文字列長アサーションフォーマッター
Definition: iutest_util_assertion.hpp:775
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char *expected_expr, const char *actual_expr, const T1 &expected, const T2 &actual)
Equal Range Helper
Definition: iutest_util_assertion.hpp:744
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeCollections(const char *expr1b, const char *expr1e, const char *expr2b, const char *expr2e, T1 b1, T1 e1, T2 b2, T2 e2)
Equal Collection Helper
Definition: iutest_util_assertion.hpp:705
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqCollections(const char *expr1b, const char *expr1e, const char *expr2b, const char *expr2e, T1 b1, T1 e1, T2 b2, T2 e2)
Equal Collection Helper
Definition: iutest_util_assertion.hpp:686
inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperIsNan(const char *actual_str, const T &actual)
NaN Assertion formatter
Definition: iutest_util_assertion.hpp:933
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeRange(const char *expected_expr, const char *actual_expr, const T1 &expected, const T2 &actual)
Not Equal Range Helper
Definition: iutest_util_assertion.hpp:756
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqIterator(T1 b1, T1 e1, T2 b2, T2 e2)
Equal Collection Helper
Definition: iutest_util_assertion.hpp:617
inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNOTIN(const char *substr_str, const char *actual_str, const T1 &substr, const T2 &actual)
文字列部分一致アサーションフォーマッター
Definition: iutest_util_assertion.hpp:908