iutest  1.17.1.0
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
35 
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
46 
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
57 
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
80 
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
91 
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
102 
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
123 
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
132 
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
141 
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
160 
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
169 
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
178 
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
197 
203 #ifndef IUTEST_EXPECT_STRLNEQ
204 # define IUTEST_EXPECT_STRLNEQ(len, v2) IUTEST_TEST_STRLNEQ(len, v2, IUTEST_EXPECT_FAILURE)
205 #endif
206 
212 #ifndef IUTEST_INFORM_STRLNEQ
213 # define IUTEST_INFORM_STRLNEQ(len, v2) IUTEST_TEST_STRLNEQ(len, v2, IUTEST_INFORM_FAILURE)
214 #endif
215 
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
234 
240 #ifndef IUTEST_EXPECT_STRIN
241 # define IUTEST_EXPECT_STRIN(substr, actual) IUTEST_TEST_STRIN(substr, actual, IUTEST_EXPECT_FAILURE)
242 #endif
243 
249 #ifndef IUTEST_INFORM_STRIN
250 # define IUTEST_INFORM_STRIN(substr, actual) IUTEST_TEST_STRIN(substr, actual, IUTEST_INFORM_FAILURE)
251 #endif
252 
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
272 
278 #ifndef IUTEST_EXPECT_STRNOTIN
279 # define IUTEST_EXPECT_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_EXPECT_FAILURE)
280 #endif
281 
287 #ifndef IUTEST_INFORM_STRNOTIN
288 # define IUTEST_INFORM_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_INFORM_FAILURE)
289 #endif
290 
296 #ifndef IUTEST_ASSUME_STRNOTIN
297 # define IUTEST_ASSUME_STRNOTIN(substr, actual) IUTEST_TEST_STRNOTIN(substr, actual, IUTEST_ASSUME_FAILURE)
298 #endif
299 
300 #if IUTEST_HAS_REGEX
301 
308 #ifndef IUTEST_ASSERT_MATCHES_REGEXEQ
309 # define IUTEST_ASSERT_MATCHES_REGEXEQ(regex_str, actual) \
310  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_ASSERT_FAILURE)
311 #endif
312 
318 #ifndef IUTEST_EXPECT_MATCHES_REGEXEQ
319 # define IUTEST_EXPECT_MATCHES_REGEXEQ(regex_str, actual) \
320  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_EXPECT_FAILURE)
321 #endif
322 
328 #ifndef IUTEST_INFORM_MATCHES_REGEXEQ
329 # define IUTEST_INFORM_MATCHES_REGEXEQ(regex_str, actual) \
330  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_INFORM_FAILURE)
331 #endif
332 
338 #ifndef IUTEST_ASSUME_MATCHES_REGEXEQ
339 # define IUTEST_ASSUME_MATCHES_REGEXEQ(regex_str, actual) \
340  IUTEST_TEST_MATCHES_REGEXEQ(regex_str, actual, IUTEST_ASSUME_FAILURE)
341 #endif
342 
349 #ifndef IUTEST_ASSERT_MATCHES_REGEXNE
350 # define IUTEST_ASSERT_MATCHES_REGEXNE(regex_str, actual) \
351  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_ASSERT_FAILURE)
352 #endif
353 
359 #ifndef IUTEST_EXPECT_MATCHES_REGEXNE
360 # define IUTEST_EXPECT_MATCHES_REGEXNE(regex_str, actual) \
361  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_EXPECT_FAILURE)
362 #endif
363 
369 #ifndef IUTEST_INFORM_MATCHES_REGEXNE
370 # define IUTEST_INFORM_MATCHES_REGEXNE(regex_str, actual) \
371  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_INFORM_FAILURE)
372 #endif
373 
379 #ifndef IUTEST_ASSUME_MATCHES_REGEXNE
380 # define IUTEST_ASSUME_MATCHES_REGEXNE(regex_str, actual) \
381  IUTEST_TEST_MATCHES_REGEXNE(regex_str, actual, IUTEST_ASSUME_FAILURE)
382 #endif
383 
384 
385 
392 #ifndef IUTEST_ASSERT_CONTAINS_REGEXEQ
393 # define IUTEST_ASSERT_CONTAINS_REGEXEQ(regex_str, actual) \
394  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_ASSERT_FAILURE)
395 #endif
396 
402 #ifndef IUTEST_EXPECT_CONTAINS_REGEXEQ
403 # define IUTEST_EXPECT_CONTAINS_REGEXEQ(regex_str, actual) \
404  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_EXPECT_FAILURE)
405 #endif
406 
412 #ifndef IUTEST_INFORM_CONTAINS_REGEXEQ
413 # define IUTEST_INFORM_CONTAINS_REGEXEQ(regex_str, actual) \
414  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_INFORM_FAILURE)
415 #endif
416 
422 #ifndef IUTEST_ASSUME_CONTAINS_REGEXEQ
423 # define IUTEST_ASSUME_CONTAINS_REGEXEQ(regex_str, actual) \
424  IUTEST_TEST_CONTAINS_REGEXEQ(regex_str, actual, IUTEST_ASSUME_FAILURE)
425 #endif
426 
433 #ifndef IUTEST_ASSERT_CONTAINS_REGEXNE
434 # define IUTEST_ASSERT_CONTAINS_REGEXNE(regex_str, actual) \
435  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_ASSERT_FAILURE)
436 #endif
437 
443 #ifndef IUTEST_EXPECT_CONTAINS_REGEXNE
444 # define IUTEST_EXPECT_CONTAINS_REGEXNE(regex_str, actual) \
445  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_EXPECT_FAILURE)
446 #endif
447 
453 #ifndef IUTEST_INFORM_CONTAINS_REGEXNE
454 # define IUTEST_INFORM_CONTAINS_REGEXNE(regex_str, actual) \
455  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_INFORM_FAILURE)
456 #endif
457 
463 #ifndef IUTEST_ASSUME_CONTAINS_REGEXNE
464 # define IUTEST_ASSUME_CONTAINS_REGEXNE(regex_str, actual) \
465  IUTEST_TEST_CONTAINS_REGEXNE(regex_str, actual, IUTEST_ASSUME_FAILURE)
466 #endif
467 
468 #endif
469 
476 #ifndef IUTEST_NO_UTIL_ASSERTION_GTEST_COMPATIBLE
477 
478 #define ASSERT_EQ_COLLECTIONS IUTEST_ASSERT_EQ_COLLECTIONS
479 #define ASSERT_NE_COLLECTIONS IUTEST_ASSERT_NE_COLLECTIONS
480 #define ASSERT_EQ_RANGE IUTEST_ASSERT_EQ_RANGE
481 #define ASSERT_NE_RANGE IUTEST_ASSERT_NE_RANGE
482 #define ASSERT_STRLNEQ IUTEST_ASSERT_STRLNEQ
483 #define ASSERT_STRIN IUTEST_ASSERT_STRIN
484 #define ASSERT_STRNOTIN IUTEST_ASSERT_STRNOTIN
485 
486 #define EXPECT_EQ_COLLECTIONS IUTEST_EXPECT_EQ_COLLECTIONS
487 #define EXPECT_NE_COLLECTIONS IUTEST_EXPECT_NE_COLLECTIONS
488 #define EXPECT_EQ_RANGE IUTEST_EXPECT_EQ_RANGE
489 #define EXPECT_NE_RANGE IUTEST_EXPECT_NE_RANGE
490 #define EXPECT_STRLNEQ IUTEST_EXPECT_STRLNEQ
491 #define EXPECT_STRIN IUTEST_EXPECT_STRIN
492 #define EXPECT_STRNOTIN IUTEST_EXPECT_STRNOTIN
493 
494 #define INFORM_EQ_COLLECTIONS IUTEST_INFORM_EQ_COLLECTIONS
495 #define INFORM_NE_COLLECTIONS IUTEST_INFORM_NE_COLLECTIONS
496 #define INFORM_EQ_RANGE IUTEST_INFORM_EQ_RANGE
497 #define INFORM_NE_RANGE IUTEST_INFORM_NE_RANGE
498 #define INFORM_STRLNEQ IUTEST_INFORM_STRLNEQ
499 #define INFORM_STRIN IUTEST_INFORM_STRIN
500 #define INFORM_STRNOTIN IUTEST_INFORM_STRNOTIN
501 
502 #define ASSUME_EQ_COLLECTIONS IUTEST_ASSUME_EQ_COLLECTIONS
503 #define ASSUME_NE_COLLECTIONS IUTEST_ASSUME_NE_COLLECTIONS
504 #define ASSUME_EQ_RANGE IUTEST_ASSUME_EQ_RANGE
505 #define ASSUME_NE_RANGE IUTEST_ASSUME_NE_RANGE
506 #define ASSUME_STRLNEQ IUTEST_ASSUME_STRLNEQ
507 #define ASSUME_STRIN IUTEST_ASSUME_STRIN
508 #define ASSUME_STRNOTIN IUTEST_ASSUME_STRNOTIN
509 
510 #if IUTEST_HAS_REGEX
511 
512 #define ASSERT_MATCHES_REGEXEQ IUTEST_ASSERT_MATCHES_REGEXEQ
513 #define EXPECT_MATCHES_REGEXEQ IUTEST_EXPECT_MATCHES_REGEXEQ
514 #define INFORM_MATCHES_REGEXEQ IUTEST_INFORM_MATCHES_REGEXEQ
515 #define ASSUME_MATCHES_REGEXEQ IUTEST_ASSUME_MATCHES_REGEXEQ
516 
517 #define ASSERT_MATCHES_REGEXNE IUTEST_ASSERT_MATCHES_REGEXNE
518 #define EXPECT_MATCHES_REGEXNE IUTEST_EXPECT_MATCHES_REGEXNE
519 #define INFORM_MATCHES_REGEXNE IUTEST_INFORM_MATCHES_REGEXNE
520 #define ASSUME_MATCHES_REGEXNE IUTEST_ASSUME_MATCHES_REGEXNE
521 
522 #define ASSERT_CONTAINS_REGEXEQ IUTEST_ASSERT_CONTAINS_REGEXEQ
523 #define EXPECT_CONTAINS_REGEXEQ IUTEST_EXPECT_CONTAINS_REGEXEQ
524 #define INFORM_CONTAINS_REGEXEQ IUTEST_INFORM_CONTAINS_REGEXEQ
525 #define ASSUME_CONTAINS_REGEXEQ IUTEST_ASSUME_CONTAINS_REGEXEQ
526 
527 #define ASSERT_CONTAINS_REGEXNE IUTEST_ASSERT_CONTAINS_REGEXNE
528 #define EXPECT_CONTAINS_REGEXNE IUTEST_EXPECT_CONTAINS_REGEXNE
529 #define INFORM_CONTAINS_REGEXNE IUTEST_INFORM_CONTAINS_REGEXNE
530 #define ASSUME_CONTAINS_REGEXNE IUTEST_ASSUME_CONTAINS_REGEXNE
531 
532 #endif
533 
534 #endif
535 
544 #define IUTEST_TEST_EQ_COLLECTIONS(b1, e1, b2, e2, on_failure) IUTEST_PRED_FORMAT4_( ::iuutil::CmpHelperEqCollections, b1, e1, b2, e2, on_failure)
545 #define IUTEST_TEST_NE_COLLECTIONS(b1, e1, b2, e2, on_failure) IUTEST_PRED_FORMAT4_( ::iuutil::CmpHelperNeCollections, b1, e1, b2, e2, on_failure)
546 #define IUTEST_TEST_EQ_RANGE(expected, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperEqRange, expected, actual, on_failure)
547 #define IUTEST_TEST_NE_RANGE(expected, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperNeRange, expected, actual, on_failure)
548 
549 #define IUTEST_TEST_STRLNEQ(len, v2, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperSTRLNEQ, len, v2, on_failure )
550 #define IUTEST_TEST_STRIN(substr, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperSTRIN, substr, actual, on_failure )
551 #define IUTEST_TEST_STRNOTIN(substr, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperSTRNOTIN, substr, actual, on_failure )
552 
553 #if IUTEST_HAS_REGEX
554 
555 #define IUTEST_TEST_MATCHES_REGEXEQ(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperMatchesRegexEq, regex, actual, on_failure )
556 #define IUTEST_TEST_MATCHES_REGEXNE(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperMatchesRegexNe, regex, actual, on_failure )
557 
558 #define IUTEST_TEST_CONTAINS_REGEXEQ(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperContainsRegexEq, regex, actual, on_failure )
559 #define IUTEST_TEST_CONTAINS_REGEXNE(regex, actual, on_failure) IUTEST_PRED_FORMAT2_( ::iuutil::CmpHelperContainsRegexNe, regex, actual, on_failure )
560 
561 #endif
562 
567 namespace iuutil
568 {
569 
570 //======================================================================
571 // function
575 template<typename T1, typename T2>
576 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqIterator(T1 b1, T1 e1, T2 b2, T2 e2)
577 {
578  int elem=0;
579  bool result = true;
581  for(elem=0; b1 != e1 && b2 != e2; ++b1, ++b2, ++elem)
582  {
583  if(!::iutest::internal::backward::EqHelper<false>::Compare("", "", *b1, *b2))
584  {
585  result = false;
586  ar << "\nMismatch in a position " << elem << ": "
587  << ::iutest::internal::FormatForComparisonFailureMessage(*b1, *b2)
588  << " vs " << ::iutest::internal::FormatForComparisonFailureMessage(*b2, *b1);
589  }
590  }
591  if(b1 != e1)
592  {
593  int elem1 = elem;
594  for(; b1 != e1; ++b1, ++elem1) {}
595  result = false;
596  ar << "\nMismatch element : " << elem1 << " vs " << elem;
597  }
598  if(b2 != e2)
599  {
600  int elem2 = elem;
601  for(; b2 != e2; ++b2, ++elem2) {}
602  result = false;
603  ar << "\nMismatch element : " << elem << " vs " << elem2;
604  }
605  if( !result )
606  {
608  }
610 }
611 
612 template<typename T1, typename T2>
613 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeIterator(T1 b1, T1 e1, T2 b2, T2 e2)
614 {
615  int elem=0;
616  bool result = false;
618  for(elem=0; b1 != e1 && b2 != e2; ++b1, ++b2, ++elem)
619  {
620  if(!::iutest::internal::backward::NeHelper<false>::Compare("", "", *b1, *b2))
621  {
622  ar << ::iutest::internal::FormatForComparisonFailureMessage(*b1, *b2);
623  }
624  else
625  {
626  result = true;
627  }
628  }
629  if( (b1 != e1) || (b2 != e2) )
630  {
631  result = true;
632  }
633  if( !result )
634  {
636  }
638 }
639 
640 
644 template<typename T1, typename T2>
645 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqCollections(const char* expr1b, const char* expr1e
646  , const char* expr2b, const char* expr2e
647  , T1 b1, T1 e1, T2 b2, T2 e2)
648 {
649  if( ::iutest::AssertionResult ar = CmpHelperEqIterator(b1, e1, b2, e2) )
650  {
652  }
653  else
654  {
655  return ::iutest::AssertionFailure() << "error: Expected: { " << expr1b << ", " << expr1e << " } == { "
656  << expr2b << ", " << expr2e << " }\n Actual:" << GetAssertionResultMessage(ar);
657  }
658 }
659 
663 template<typename T1, typename T2>
664 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeCollections(const char* expr1b, const char* expr1e
665  , const char* expr2b, const char* expr2e
666  , T1 b1, T1 e1, T2 b2, T2 e2)
667 {
668  if( ::iutest::AssertionResult ar = CmpHelperNeIterator(b1, e1, b2, e2) )
669  {
671  }
672  else
673  {
674  return ::iutest::AssertionFailure() << "error: Expected: { " << expr1b << ", " << expr1e << " } != { "
675  << expr2b << ", " << expr2e << " }\n Actual:" << GetAssertionResultMessage(ar);
676  }
677 }
678 
679 namespace detail
680 {
681 
682 template<typename T1, typename T2>
683 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char* expected_expr, const char* actual_expr
684  , T1 b1, T1 e1, T2 b2, T2 e2)
685 {
686  if( ::iutest::AssertionResult ar = CmpHelperEqIterator(b1, e1, b2, e2) )
687  {
689  }
690  else
691  {
692  return ::iutest::AssertionFailure() << "error: Expected: " << expected_expr << " == " << actual_expr
693  << " \n Actual:" << GetAssertionResultMessage(ar);
694  }
695 }
696 
697 } // end of namespace detail
698 
702 template<typename T1, typename T2>
703 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqRange(const char* expected_expr, const char* actual_expr
704  , const T1& expected, const T2& actual)
705 {
707  return detail::CmpHelperEqRange(expected_expr, actual_expr, begin(expected), end(expected)
708  , begin(actual), end(actual));
709 }
710 
714 template<typename T1, typename T2>
715 ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNeRange(const char* expected_expr, const char* actual_expr
716  , const T1& expected, const T2& actual)
717 {
719  if( ::iutest::AssertionResult ar =
720  CmpHelperNeIterator(begin(expected), end(expected), begin(actual), end(actual)))
721  {
723  }
724  else
725  {
726  return ::iutest::AssertionFailure() << "error: Expected: " << expected_expr << " != " << actual_expr
727  << " \n Actual:" << ::iutest::internal::FormatForComparisonFailureMessage(expected, actual);
728  }
729 }
730 
734 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char* expr1, const char* expr2
735  , size_t len1, const char* val2)
736 {
737  const size_t len2 = strlen(val2);
738  if( len2 == len1 )
739  {
741  }
742  return ::iutest::AssertionFailure() << "error: Value of: " << expr1 << " == strlen(" << expr2 << ")"
743  << "\n Actual: " << val2 << " : " << len2 << "\nExpected: " << len1;
744 }
748 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char* expr1, const char* expr2
749  , size_t len1, const wchar_t* val2)
750 {
751  const size_t len2 = wcslen(val2);
752  if( len2 == len1 )
753  {
755  }
756  return ::iutest::AssertionFailure() << "error: Value of: " << expr1 << " == wcslen(" << expr2 << ")"
757  << "\n Actual: " << val2 << " : " << len2 << "\nExpected: " << len1;
758 }
759 
760 namespace StrInHelper
761 {
762 
763 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const char* substr, const char* actual)
764 {
765  if( substr == NULL || actual == NULL )
766  {
767  return substr == actual;
768  }
769  return strstr(actual, substr) != NULL;
770 }
771 
772 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const wchar_t* substr, const wchar_t* actual)
773 {
774  if( substr == NULL || actual == NULL )
775  {
776  return substr == actual;
777  }
778  return wcsstr(actual, substr) != NULL;
779 }
780 
781 template<typename Elem, typename Traits, typename Ax>
782 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const ::std::basic_string<Elem, Traits, Ax>& substr
783  , const ::std::basic_string<Elem, Traits, Ax>& actual)
784 {
785  return Compare(substr.c_str(), actual.c_str());
786 }
787 template<typename Elem, typename Traits, typename Ax>
788 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const Elem* substr
789  , const ::std::basic_string<Elem, Traits, Ax>& actual)
790 {
791  return Compare(substr, actual.c_str());
792 }
793 template<typename Elem, typename Traits, typename Ax>
794 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const ::std::basic_string<Elem, Traits, Ax>& substr
795  , const Elem* actual)
796 {
797  return Compare(substr.c_str(), actual);
798 }
799 
800 template<typename T1, typename T2>
801 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* substr_str, const char* actual_str
802  , const T1& substr, const T2& actual)
803 {
804  if( Compare(substr, actual) )
805  {
807  }
808 
809  return ::iutest::AssertionFailure() << "error: Expected: " << "strstr(" << actual_str << ", " << substr_str << ") != NULL"
810  << "\n Actual: " << "strstr(\"" << actual << "\", " << substr << ") == NULL";
811 }
812 
813 } // end of namespace StrInHelper
814 
818 template<typename T1, typename T2>
819 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRIN(const char* substr_str, const char* actual_str
820  , const T1& substr, const T2& actual)
821 {
822  return StrInHelper::Assertion(substr_str, actual_str, substr, actual);
823 }
824 
825 namespace StrNotInHelper
826 {
827 
828 template<typename T1, typename T2>
829 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& substr, const T2& actual)
830 {
831  return !StrInHelper::Compare(substr, actual);
832 }
833 
834 template<typename T1, typename T2>
835 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* substr_str, const char* actual_str
836  , const T1& substr, const T2& actual)
837 {
838  if( Compare(substr, actual) )
839  {
841  }
842 
843  return ::iutest::AssertionFailure() << "error: Expected: " << "strstr(" << actual_str << ", " << substr_str << ") == NULL"
844  << "\n Actual: " << "strstr(\"" << actual << "\", " << substr << ") != NULL";
845 }
846 
847 } // end of namespace StrNotInHelper
848 
852 template<typename T1, typename T2>
853 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNOTIN(const char* substr_str, const char* actual_str
854  , const T1& substr, const T2& actual)
855 {
856  return StrNotInHelper::Assertion(substr_str, actual_str, substr, actual);
857 }
858 
859 #if IUTEST_HAS_REGEX
860 
861 namespace RegexHelper
862 {
863 
864 inline bool FullMatch(const ::std::string& str, const ::iutest::internal::RE& re)
865 {
866  return ::iutest::internal::RE::FullMatch(str, re);
867 }
868 inline bool FullMatch(const char* str, const ::iutest::internal::RE& re)
869 {
870  if( str == NULL )
871  {
872  return false;
873  }
874  return ::iutest::internal::RE::FullMatch(str, re);
875 }
876 
877 inline bool PartialMatch(const ::std::string& str, const ::iutest::internal::RE& re)
878 {
879  return ::iutest::internal::RE::PartialMatch(str, re);
880 }
881 inline bool PartialMatch(const char* str, const ::iutest::internal::RE& re)
882 {
883  if( str == NULL )
884  {
885  return false;
886  }
887  return ::iutest::internal::RE::PartialMatch(str, re);
888 }
889 
890 } // end of namespace RegexHelper
891 
892 namespace MatchesRegexEqHelper
893 {
894 
895 template<typename T1, typename T2>
896 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& regex, const T2& actual)
897 {
898  ::iutest::internal::RE iure(regex);
899  return RegexHelper::FullMatch(actual, iure);
900 }
901 
902 template<typename T1, typename T2>
903 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
904  , const T1& regex, const T2& actual)
905 {
906  if( Compare(regex, actual) )
907  {
909  }
910  ::std::string expected_str = "Matches Regex (";
911  expected_str += regex_str;
912  expected_str += ")";
913 
914  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
915  , ::iutest::PrintToString(regex)
916  , ::iutest::PrintToString(actual)
917  , false);
918 }
919 
920 } // end of namespace MatchesRegexEqHelper
921 
925 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperMatchesRegexEq(const char* regex_str, const char* actual_str
926  , const char* regex, const char* actual)
927 {
928  return MatchesRegexEqHelper::Assertion(regex_str, actual_str, regex, actual);
929 }
930 
931 namespace MatchesRegexNeHelper
932 {
933 
934 template<typename T1, typename T2>
935 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
936  , const T1& regex, const T2& actual)
937 {
938  if( !MatchesRegexEqHelper::Compare(regex, actual) )
939  {
941  }
942  ::std::string expected_str = "Not Matches Regex (";
943  expected_str += regex_str;
944  expected_str += ")";
945 
946  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
947  , ::iutest::PrintToString(regex)
948  , ::iutest::PrintToString(actual)
949  , false);
950 }
951 
952 } // end of namespace MatchesRegexNeHelper
953 
957 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperMatchesRegexNe(const char* regex_str, const char* actual_str
958  , const char* regex, const char* actual)
959 {
960  return MatchesRegexNeHelper::Assertion(regex_str, actual_str, regex, actual);
961 }
962 
963 namespace ContainsRegexEqHelper
964 {
965 
966 template<typename T1, typename T2>
967 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& regex, const T2& actual)
968 {
969  ::iutest::internal::RE m(regex);
970  return RegexHelper::PartialMatch(actual, m);
971 }
972 
973 template<typename T1, typename T2>
974 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
975  , const T1& regex, const T2& actual)
976 {
977  if( Compare(regex, actual) )
978  {
980  }
981  ::std::string expected_str = "Contains Regex (";
982  expected_str += regex_str;
983  expected_str += ")";
984 
985  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
986  , ::iutest::PrintToString(regex)
987  , ::iutest::PrintToString(actual)
988  , false);
989 }
990 
991 } // end of namespace ContainsRegexEqHelper
992 
996 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperContainsRegexEq(const char* regex_str, const char* actual_str
997  , const char* regex, const char* actual)
998 {
999  return ContainsRegexEqHelper::Assertion(regex_str, actual_str, regex, actual);
1000 }
1001 
1002 namespace ContainsRegexNeHelper
1003 {
1004 
1005 template<typename T1, typename T2>
1006 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(const char* regex_str, const char* actual_str
1007  , const T1& regex, const T2& actual)
1008 {
1009  if( !ContainsRegexEqHelper::Compare(regex, actual) )
1010  {
1012  }
1013  ::std::string expected_str = "Not Contains Regex (";
1014  expected_str += regex_str;
1015  expected_str += ")";
1016 
1017  return ::iutest::internal::EqFailure(expected_str.c_str(), actual_str
1018  , ::iutest::PrintToString(regex)
1019  , ::iutest::PrintToString(actual)
1020  , false);
1021 }
1022 
1023 } // end of namespace ContainsRegexNeHelper
1024 
1028 inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperContainsRegexNe(const char* regex_str, const char* actual_str
1029  , const char* regex, const char* actual)
1030 {
1031  return ContainsRegexNeHelper::Assertion(regex_str, actual_str, regex, actual);
1032 }
1033 
1034 #endif
1035 
1036 } // end of namespace iuutil
1037 
1038 #endif // INCG_IRIS_IUTEST_UTIL_ASSERTION_HPP_A45F8265_40E0_44F2_91C6_090B1778657C_
iutest_config.hpp
iris unit test config
iutest::PrintToString
std::string PrintToString(const T &v)
文字列化
Definition: iutest_printers.hpp:678
iutest::Message
detail::iuStreamMessage Message
Message クラス
Definition: iutest_assertion.hpp:31
iuutil::CmpHelperNeCollections
::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:665
iuutil::CmpHelperSTRLNEQ
inline ::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRLNEQ(const char *expr1, const char *expr2, size_t len1, const char *val2)
文字列長アサーションフォーマッター
Definition: iutest_util_assertion.hpp:735
iuutil::CmpHelperNeRange
::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:716
iuutil::CmpHelperEqCollections
::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:646
iuutil::CmpHelperSTRNOTIN
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:854
iuutil::CmpHelperEqRange
::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:704
iuutil
iutest utility namespace
Definition: iutest_util.hpp:33
iutest::AssertionResult
Assertion Result
Definition: iutest_assertion.hpp:54
iutest::GetAssertionResultMessage
const char * GetAssertionResultMessage(const AssertionResult &ar)
テスト結果のメッセージを取得する(for compatible)
Definition: iutest_assertion.hpp:391
IUTEST_USING_BEGIN_END
#define IUTEST_USING_BEGIN_END()
using begin,end
Definition: iutest_stdlib.hpp:581
iutest::AssertionFailure
AssertionResult AssertionFailure()
テスト失敗を示す AssertionResult オブジェクトの取得
Definition: iutest_assertion.hpp:386
iuutil::CmpHelperSTRIN
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:820
iuutil::CmpHelperEqIterator
::iutest::AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperEqIterator(T1 b1, T1 e1, T2 b2, T2 e2)
Equal Collection Helper
Definition: iutest_util_assertion.hpp:577
iutest::AssertionSuccess
AssertionResult AssertionSuccess()
テスト成功を示す AssertionResult オブジェクトの取得
Definition: iutest_assertion.hpp:382