15 #ifndef INCG_IRIS_IUTEST_ASSERTION_HPP_E6AF3476_DA81_46F7_A961_ACCEF7363932_
16 #define INCG_IRIS_IUTEST_ASSERTION_HPP_E6AF3476_DA81_46F7_A961_ACCEF7363932_
32 typedef detail::iuStreamMessage
Message;
37 inline ::std::string StreamableToString(
const T& value)
39 return (
Message() << value).GetString();
48 void DefaultReportTestPartResult(
const TestPartResult& test_part_result);
50 class UncaughtScopedTrace
53 static void Add(
const detail::iuCodeMessage& msg);
55 static ::std::string Get();
89 const char*
message()
const {
return m_message.c_str(); }
109 m_message += msg.GetString();
146 ::std::string m_message;
150 #if IUTEST_HAS_ASSERTION_RETURN
191 class AssertionHelper
202 : m_part_result(file, line, message, type)
211 AssertionHelper(
const char* file,
int line, const ::std::string& message,
TestPartResult::Type type)
212 : m_part_result(file, line, message.c_str(), type)
218 :
public detail::iuCodeMessage
219 #if IUTEST_USE_OWN_LIST
220 ,
public detail::iu_list_node<ScopedMessage>
224 ScopedMessage(
const detail::iuCodeMessage& msg)
225 : detail::iuCodeMessage(msg)
227 ScopedTrace::GetInstance().list.push_back(
this);
231 ScopedTrace::GetInstance().list.remove(
this);
232 if( stl::uncaught_exception() )
234 detail::UncaughtScopedTrace::Add(*
this);
242 #if IUTEST_USE_OWN_LIST
243 typedef detail::iu_list<ScopedMessage> msg_list;
245 typedef ::std::list<ScopedMessage*> msg_list;
249 static ScopedTrace& GetInstance() {
static ScopedTrace inst;
return inst; }
251 void append_message(
TestPartResult& part_result,
bool isException)
253 if( !list.empty() || detail::UncaughtScopedTrace::Has() )
255 part_result.add_message(
"\niutest trace:");
258 for( msg_list::iterator it = list.begin(), end=list.end(); it != end; ++it )
260 part_result.add_message(
"\n");
261 part_result.add_message((*it)->make_message().c_str());
265 part_result.add_message(detail::UncaughtScopedTrace::Get());
271 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
272 friend class ScopedMessage;
275 #if IUTEST_HAS_ASSERTION_RETURN
277 template<
typename R>
struct ReturnTypedFixed;
286 Fixed& operator << (T val)
288 Message::operator << (val);
291 template<
typename T,
size_t SIZE>
292 Fixed& operator << (
const T(&val)[SIZE])
294 Message::operator << (val);
297 #if IUTEST_HAS_IOMANIP
298 Fixed& operator << (iu_basic_iomanip val)
300 Message::operator << (val);
304 #if IUTEST_HAS_ASSERTION_RETURN
312 return ReturnTypedFixed<R>(*
this, ret);
317 #if IUTEST_HAS_ASSERTION_RETURN
320 struct ReturnTypedFixed
330 void operator = (
const Fixed& fixed)
333 #if IUTEST_HAS_EXCEPTIONS && IUTEST_USE_THROW_ON_ASSERTION_FAILURE
335 IUTEST_PRAGMA_WARN_PUSH()
336 IUTEST_PRAGMA_WARN_DISABLE_SWITCH_ENUM()
337 switch( m_part_result.type() )
342 throw m_part_result.type();
346 IUTEST_PRAGMA_WARN_POP()
350 #if IUTEST_HAS_ASSERTION_RETURN
353 R operator = (
const ReturnTypedFixed<R>& fixed)
355 this->operator=(fixed.fixed);
356 return fixed.ret.value;
361 void OnFixed(
const Fixed& fixed,
bool isException =
false)
364 const ::std::string append_message = fixed.GetString();
365 if( !append_message.empty() )
367 m_part_result.add_message(
" " + append_message);
369 ScopedTrace::GetInstance().append_message(m_part_result, isException);
371 if( TestEnv::GetGlobalTestPartResultReporter() != IUTEST_NULLPTR )
373 TestEnv::GetGlobalTestPartResultReporter()->ReportTestPartResult(m_part_result);
377 detail::DefaultReportTestPartResult(m_part_result);
380 if IUTEST_COND_UNLIKELY(m_part_result.failed()
425 template<
typename T1,
typename T2>
426 inline ::std::string FormatForComparisonFailureMessage(
const T1& value,
const T2& )
434 inline ::std::string GetBooleanAssertionFailureMessage(
const AssertionResult& ar
435 ,
const char* expr,
const char* actual,
const char* expected)
437 ::std::string str =
"error: Value of: ";
439 str +=
"\n Actual: ";
441 if( !detail::IsEmpty(ar.message()) )
447 str +=
"\nExpected: ";
455 inline AssertionResult EqFailure(
const char* expected_expression,
const char* actual_expression
456 , const ::std::string& expected, const ::std::string& actual,
bool ignoring_case =
false)
458 iu_global_format_stringstream strm;
459 strm <<
"error: Value of " << actual_expression
460 <<
"\n Actual: " << actual
461 <<
"\nExpected: " << expected_expression;
464 strm <<
" (ignoring case)";
466 if( !detail::IsStringEqual(expected_expression, expected.c_str()) )
468 strm <<
"\nWhich is: " << expected;
473 template<
typename T1,
typename T2>
474 inline AssertionResult CmpHelperOpFailure(
const char* expr1,
const char* expr2,
const char* op
475 ,
const T1& val1,
const T2& val2)
477 return AssertionFailure() <<
"error: Expected: " << expr1 <<
" " << op <<
" " << expr2
478 <<
"\n Actual: " << FormatForComparisonFailureMessage(val1, val2)
479 <<
" vs " << FormatForComparisonFailureMessage(val2, val1);
487 #define IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_BASE_(op_name, op) \
488 template<typename T1, typename T2> \
489 bool iuOperator##op_name(const T1& v1, const T2& v2) { \
490 IUTEST_PRAGMA_WARN_PUSH() \
491 IUTEST_PRAGMA_WARN_DISABLE_IMPLICIT_INT_FLOAT_CONVERSION() \
493 IUTEST_PRAGMA_WARN_POP() \
496 #if IUTEST_HAS_CXX_HDR_VARIANT && IUTEST_HAS_VARIADIC_TEMPLATES
497 #define IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT_(op_name, op) \
498 template<typename ...V1, typename ...V2> \
499 bool iuOperator##op_name(const ::std::variant<V1...>&& v1, const ::std::variant<V2...>& v2) { \
502 template<typename T1, typename ...V> \
503 bool iuOperator##op_name(const T1& v1, const ::std::variant<V...>& v2 \
504 , typename detail::enable_if< !detail::is_variant<T1>::value, void>::type*& = detail::enabler::value ) { \
505 ::std::variant<V...> vv1(v1); return vv1 op v2; \
507 template<typename ...V, typename T2> \
508 bool iuOperator##op_name(const ::std::variant<V...>& v1, const T2& v2 \
509 , typename detail::enable_if< !detail::is_variant<T2>::value, void>::type*& = detail::enabler::value ) { \
510 ::std::variant<V...> vv2(v2); return v1 op vv2; \
513 #define IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT_(op_name, op)
516 #define IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_(op_name, op) \
517 IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_BASE_(op_name, op) \
518 IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT_(op_name, op)
520 #define IIUT_DECL_COMPARE_HELPER_I_(op_name, op, type1, type2) \
521 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelper##op_name( \
522 const char* expr1, const char* expr2, type1 val1, type2 val2) { \
523 if IUTEST_COND_LIKELY(iuOperator##op_name(val1, val2)) { return AssertionSuccess(); \
524 } else { return CmpHelperOpFailure(expr1, expr2, #op, val1, val2); } \
527 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
529 #define IIUT_DECL_COMPARE_HELPER_(op_name, op) \
530 IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_(op_name, op) \
531 template<typename T1, typename T2> \
532 IIUT_DECL_COMPARE_HELPER_I_(op_name, op, const T1&, const T2&) \
533 IIUT_DECL_COMPARE_HELPER_I_(op_name, op, BiggestInt, BiggestInt)
537 #define IIUT_DECL_COMPARE_HELPER_(op_name, op) \
538 IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_(op_name, op) \
539 template<typename T1, typename T2> \
540 IIUT_DECL_COMPARE_HELPER_I_(op_name, op, const T1&, const T2&)
544 template<
typename T1,
typename T2>
545 bool iuOperatorEQ(
const T1& v1,
const T2& v2)
547 IUTEST_PRAGMA_WARN_PUSH()
548 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
549 IUTEST_PRAGMA_WARN_DISABLE_IMPLICIT_INT_FLOAT_CONVERSION()
551 IUTEST_PRAGMA_WARN_POP()
553 IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT_(EQ, ==)
555 IIUT_DECL_COMPARE_HELPER_(NE, !=)
556 IIUT_DECL_COMPARE_HELPER_(LE, <=)
557 IIUT_DECL_COMPARE_HELPER_(LT, < )
558 IIUT_DECL_COMPARE_HELPER_(GE, >=)
559 IIUT_DECL_COMPARE_HELPER_(GT, > )
562 #undef IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_
563 #undef IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_BASE
564 #undef IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT
565 #undef IIUT_DECL_COMPARE_HELPER_I_
566 #undef IIUT_DECL_COMPARE_HELPER_
576 template<
bool IsNullLiteral>
581 static AssertionResult CompareEq(
const char* expr,
const T* val)
583 if IUTEST_COND_LIKELY( IUTEST_NULLPTR == val )
589 <<
"\n Actual: " << val
590 <<
"\nExpected: NULL";
593 static AssertionResult CompareNe(
const char* expr,
const T* val)
595 if IUTEST_COND_LIKELY( IUTEST_NULLPTR != val )
601 <<
"\n Actual: NULL\nExpected: not NULL";
609 class NullHelper<true>
612 static AssertionResult CompareEq(
const char*,
void*)
616 static AssertionResult CompareNe(
const char* expr,
void*)
619 <<
"\n Actual: NULL\nExpected: not NULL";
623 template<
typename T1,
typename T2>
624 inline AssertionResult CmpHelperSame(
const char* expected_str,
const char* actual_str
625 ,
const T1& expected,
const T2& actual)
627 if IUTEST_COND_LIKELY( &expected == &actual )
632 return AssertionFailure() <<
"error: Expected: &(" << expected_str <<
") == &(" << actual_str
633 <<
")\n Actual: " << FormatForComparisonFailureMessage(&expected, &actual)
634 <<
" vs " << FormatForComparisonFailureMessage(&actual, &expected);
637 template<
typename T1,
typename T2>
638 inline AssertionResult CmpHelperEQ(
const char* expected_str,
const char* actual_str
639 ,
const T1& expected,
const T2& actual)
641 if IUTEST_COND_LIKELY( iuOperatorEQ(actual, expected) )
646 return EqFailure(expected_str, actual_str
647 , FormatForComparisonFailureMessage(expected, actual)
648 , FormatForComparisonFailureMessage(actual, expected)
653 inline AssertionResult CmpHelperMemCmpEQ(
const char* expected_str,
const char* actual_str
654 ,
const T& expected,
const T& actual)
656 IUTEST_PRAGMA_WARN_PUSH()
657 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
659 if IUTEST_COND_LIKELY( memcmp(&actual, &expected, sizeof(T)) == 0 )
664 return EqFailure(expected_str, actual_str
665 , FormatForComparisonFailureMessage(expected, actual)
666 , FormatForComparisonFailureMessage(actual, expected)
669 IUTEST_PRAGMA_WARN_POP()
673 inline AssertionResult CmpHelperMemCmpNE(
const char* expected_str,
const char* actual_str
674 ,
const T& expected,
const T& actual)
676 IUTEST_PRAGMA_WARN_PUSH()
677 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
679 if IUTEST_COND_LIKELY( memcmp(&actual, &expected, sizeof(T)) != 0 )
684 return AssertionFailure() <<
"error: Expected: " << expected_str <<
" != " << actual_str
685 <<
"\n Actual: " << FormatForComparisonFailureMessage(expected, actual);
687 IUTEST_PRAGMA_WARN_POP()
690 template<
typename RawType>
691 inline AssertionResult CmpHelperFloatingPointEQ(
const char* expr1,
const char* expr2
692 , RawType val1, RawType val2)
694 floating_point<RawType> f1(val1), f2(val2);
695 if IUTEST_COND_LIKELY( f1.AlmostEquals(f2) )
699 return EqFailure(expr1, expr2
700 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f1, f2))
701 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f2, f1)));
704 template<
typename RawType>
705 inline AssertionResult CmpHelperFloatingPointLE(
const char* expr1,
const char* expr2
706 , RawType val1, RawType val2)
708 if IUTEST_COND_LIKELY( val1 < val2 )
712 floating_point<RawType> f1(val1), f2(val2);
713 if IUTEST_COND_LIKELY( f1.AlmostEquals(f2) )
717 return EqFailure(expr1, expr2
718 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f1, f2))
719 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f2, f1)));
722 template<
typename RawType>
723 inline AssertionResult CmpHelperFloatingPointComplexEQ(
const char* expr1,
const char* expr2
724 , const ::std::complex<RawType>& val1, const ::std::complex<RawType>& val2)
726 floating_point<RawType> real1(val1.real()), real2(val2.real());
727 floating_point<RawType> imag1(val1.imag()), imag2(val2.imag());
728 if IUTEST_COND_LIKELY( real1.AlmostEquals(real2) && imag1.AlmostEquals(imag2) )
732 return EqFailure(expr1, expr2
733 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2))
734 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1)));
737 template<
typename R1,
typename R2>
738 inline AssertionResult CmpHelperFloatingPointComplexEQ(
const char* expr1,
const char* expr2
739 , const ::std::complex<R1>& val1, const ::std::complex<R2>& val2)
741 typedef typename detail::conditional<(
sizeof(R1) >
sizeof(R2)), R1, R2>::type RawType;
742 return CmpHelperFloatingPointComplexEQ<RawType>(expr1, expr2, ::std::complex<RawType>(val1), ::std::complex<RawType>(val2));
745 template<
typename R1,
typename R2>
746 inline AssertionResult CmpHelperFloatingPointComplexEQ(
const char* expr1,
const char* expr2
747 , R1 val1, const ::std::complex<R2>& val2)
749 return CmpHelperFloatingPointComplexEQ(expr1, expr2, ::std::complex<R2>(val1, R2()), val2);
751 template<
typename R1,
typename R2>
752 inline AssertionResult CmpHelperFloatingPointComplexEQ(
const char* expr1,
const char* expr2
753 , const ::std::complex<R1>& val1, R2 val2)
755 return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, ::std::complex<R1>(val2, R1()));
769 template<
bool IsNullLiteral>
772 #if IUTEST_HAS_ASSERTION_NOEQUALTO_OBJECT
773 template<
typename T,
bool has_equal_to_operator>
776 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1,
const T& val2)
778 return CmpHelperEQ(expr1, expr2, val1, val2);
782 struct CmpHelper<T, false>
784 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1,
const T& val2)
786 return CmpHelperMemCmpEQ(expr1, expr2, val1, val2);
792 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1,
const T& val2)
794 return CmpHelper<T, detail::has_equal_to<T>::value>::Compare(expr1, expr2, val1, val2);
799 template<
typename T1,
typename T2>
800 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
802 return CmpHelperEQ(expr1, expr2, val1, val2);
813 #if !defined(IUTEST_NO_SFINAE)
814 template<
typename T1,
typename T2>
815 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2
816 ,
typename detail::enable_if< !detail::is_pointer<T2>::value,
void>::type*& = detail::enabler::value)
818 return CmpHelperEQ(expr1, expr2, val1, val2);
820 template<
typename T2>
821 static AssertionResult Compare(
const char* expr1,
const char* expr2
822 , detail::IsNullLiteralHelper::Object* val1, T2* val2)
824 IUTEST_UNUSED_VAR(val1);
825 return CmpHelperEQ(expr1, expr2,
static_cast<T2*
>(IUTEST_NULLPTR), val2);
828 template<
typename T1,
typename T2>
829 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
831 return CmpHelperEQ(expr1, expr2, (T2)(val1), val2);
840 template<
bool IsNullLiteral>
841 class AlmostEqHelper :
public EqHelper<false>
845 template<
typename T1,
typename T2>
846 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
848 return EqHelper<false>::Compare(expr1, expr2, val1,
static_cast<T1
>(val2));
851 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const float& val1,
const T& val2)
853 return CmpHelperFloatingPointEQ<float>(expr1, expr2, val1,
static_cast<float>(val2));
856 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const double& val1,
const T& val2)
858 return CmpHelperFloatingPointEQ<double>(expr1, expr2, val1,
static_cast<double>(val2));
862 template<
typename T1,
typename T2>
863 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
865 return CmpHelper::Compare(expr1, expr2, val1, val2);
867 template<
typename T,
typename U>
868 static AssertionResult Compare(
const char* expr1,
const char* expr2, const ::std::complex<T>& val1, const ::std::complex<U>& val2)
870 return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, val2);
872 template<
typename T,
typename U>
873 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1, const ::std::complex<U>& val2)
875 return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, val2);
877 template<
typename T,
typename U>
878 static AssertionResult Compare(
const char* expr1,
const char* expr2, const ::std::complex<T>& val1,
const U& val2)
880 return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, val2);
888 class AlmostEqHelper<true> :
public EqHelper<true>
896 template<
bool IsNullLiteral>
899 #if IUTEST_HAS_ASSERTION_NOEQUALTO_OBJECT
900 template<
typename T,
bool has_not_equal_to_operator>
903 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1,
const T& val2)
905 return CmpHelperNE(expr1, expr2, val1, val2);
909 struct CmpHelper<T, false>
911 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1,
const T& val2)
913 return CmpHelperMemCmpNE(expr1, expr2, val1, val2);
919 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T& val1,
const T& val2)
921 return CmpHelper<T, detail::has_not_equal_to<T>::value>::Compare(expr1, expr2, val1, val2);
927 template<
typename T1,
typename T2>
928 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
930 return CmpHelperNE(expr1, expr2, val1, val2);
941 #if !defined(IUTEST_NO_SFINAE)
942 template<
typename T1,
typename T2>
943 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2
944 ,
typename detail::enable_if< !detail::is_pointer<T2>::value,
void>::type*& = detail::enabler::value)
946 return CmpHelperNE(expr1, expr2, val1, val2);
948 template<
typename T2>
949 static AssertionResult Compare(
const char* expr1,
const char* expr2
950 , detail::IsNullLiteralHelper::Object* val1, T2* val2)
952 IUTEST_UNUSED_VAR(val1);
953 return CmpHelperNE(expr1, expr2,
static_cast<T2*
>(IUTEST_NULLPTR), val2);
956 template<
typename T1,
typename T2>
957 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
959 return CmpHelperNE(expr1, expr2, (T2)(val1), val2);
966 #if IUTEST_HAS_NULLPTR && IUTEST_HAS_CXX_HDR_TYPE_TARITS && 0
973 template<
typename T1,
typename T2,
typename detail::enable_if<
974 !detail::is_integral<T1>::value || !detail::is_pointer<T2>::value,
void>::type*& = detail::enabler::value>
975 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
977 return backward::EqHelper<false>::Compare(expr1, expr2, val1, val2);
980 static AssertionResult Compare(
const char* expr1,
const char* expr2, ::std::nullptr_t, T* val2)
982 return CmpHelperEQ(expr1, expr2,
static_cast<T*
>(IUTEST_NULLPTR), val2);
991 template<
typename T1,
typename T2,
typename detail::enable_if<
992 !detail::is_integral<T1>::value || !detail::is_pointer<T2>::value,
void>::type*& = detail::enabler::value>
993 static AssertionResult Compare(
const char* expr1,
const char* expr2,
const T1& val1,
const T2& val2)
995 return backward::NeHelper<false>::Compare(expr1, expr2, val1, val2);
998 static AssertionResult Compare(
const char* expr1,
const char* expr2, ::std::nullptr_t, T* val2)
1000 return CmpHelperNE(expr1, expr2,
static_cast<T*
>(IUTEST_NULLPTR), val2);
1006 using backward::EqHelper;
1007 using backward::AlmostEqHelper;
1008 using backward::NeHelper;
1012 template<
typename RawType>
1013 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNearFloatingPoint(
1014 const char* expr1,
const char* expr2,
const char* absc
1015 , RawType val1, RawType val2, RawType abs_v)
1017 const RawType diff = val1 > val2 ? val1 - val2 : val2 - val1;
1018 if IUTEST_COND_LIKELY( diff < abs_v )
1022 floating_point<RawType> f1(diff), f2(abs_v);
1023 if IUTEST_COND_LIKELY( f1.AlmostEquals(f2) )
1027 return AssertionFailure() <<
"error: Value of: abs(" << expr1 <<
" - " << expr2 <<
") <= " << absc
1028 <<
"\n Actual: abs(" << val1 <<
" - " << val2 <<
") : " << diff
1029 <<
"\nExpected: " << FormatForComparisonFailureMessage(abs_v, diff);
1031 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ DoubleNearPredFormat(
1032 const char* expr1,
const char* expr2,
const char* absc
1033 ,
double val1,
double val2,
double abs_v)
1035 return CmpHelperNearFloatingPoint(expr1, expr2, absc, val1, val2, abs_v);
1037 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
1038 template<
typename T,
typename A>
1039 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNear(
1040 const char* expr1,
const char* expr2,
const char* absc
1041 ,
const T& val1,
const T& val2,
const A& abs_v)
1043 const T diff = val1 > val2 ? val1 - val2 : val2 - val1;
1044 if IUTEST_COND_LIKELY( diff <= abs_v )
1048 return AssertionFailure() <<
"error: Value of: abs(" << expr1 <<
" - " << expr2 <<
") <= " << absc
1049 <<
"\n Actual: abs(" << val1 <<
" - " << val2 <<
") : " << diff
1050 <<
"\nExpected: " << FormatForComparisonFailureMessage(abs_v, diff);
1052 template<
typename A>
1053 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNear(
1054 const char* expr1,
const char* expr2,
const char* absc
1055 ,
double val1,
double val2,
const A& abs_v)
1057 return CmpHelperNearFloatingPoint<double>(expr1, expr2, absc, val1, val2,
static_cast<double>(abs_v));
1060 template<
typename A>
1061 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperNear(
1062 const char* expr1,
const char* expr2,
const char* absc
1063 ,
float val1,
float val2,
const A& abs_v)
1065 return CmpHelperNearFloatingPoint<float>(expr1, expr2, absc, val1, val2,
static_cast<float>(abs_v));
1069 namespace StrEqHelper
1072 #if IUTEST_HAS_NULLPTR && 0
1073 #define IIUT_DECL_STREQ_COMPARE_HELPER_NULL_(T) \
1074 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(::std::nullptr_t, const T* val2) { \
1075 return val2 == IUTEST_NULLPTR; \
1078 #define IIUT_DECL_STREQ_COMPARE_HELPER_NULL_(T)
1081 #define IIUT_DECL_STREQ_COMPARE_HELPER_SV_(T) \
1082 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(detail::iu_nullable_basic_string_view<T> val1 \
1083 , detail::iu_nullable_basic_string_view<T> val2) { \
1084 return val1 == val2; \
1086 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T* val1, const T* val2) { \
1087 if( val1 == IUTEST_NULLPTR || val2 == IUTEST_NULLPTR ) { return val1 == val2; } \
1088 return Compare(detail::iu_nullable_basic_string_view<T>(val1) \
1089 , detail::iu_nullable_basic_string_view<T>(val2)); \
1092 #define IIUT_DECL_STREQ_COMPARE_HELPER_(T) \
1093 IIUT_DECL_STREQ_COMPARE_HELPER_SV_(T) \
1094 IIUT_DECL_STREQ_COMPARE_HELPER_NULL_(T)
1096 IIUT_DECL_STREQ_COMPARE_HELPER_(
char)
1097 IIUT_DECL_STREQ_COMPARE_HELPER_(
wchar_t)
1098 #if IUTEST_HAS_CHAR16_T
1099 IIUT_DECL_STREQ_COMPARE_HELPER_(char16_t)
1101 #if IUTEST_HAS_CHAR32_T
1102 IIUT_DECL_STREQ_COMPARE_HELPER_(char32_t)
1105 #undef IIUT_DECL_STREQ_COMPARE_HELPER_
1106 #undef IIUT_DECL_STREQ_COMPARE_HELPER_SV_
1110 template<
typename T1,
typename T2>
1111 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTREQ(
1112 const char* expr1,
const char* expr2
1113 , T1 val1, T2 val2,
typename detail::enable_if<
1114 !detail::is_integral<T1>::value || !detail::is_pointer<T2>::value,
void>::type*& = detail::enabler::value)
1116 if IUTEST_COND_LIKELY( StrEqHelper::Compare(val1, val2) )
1121 return EqFailure(expr1, expr2
1122 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2))
1123 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1)));
1126 template<
typename T>
1127 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTREQ(
1128 const char* expr1,
const char* expr2
1129 , detail::iu_nullptr_convertible_t, T val2)
1131 if IUTEST_COND_LIKELY( StrEqHelper::Compare(IUTEST_NULLPTR, val2) )
1136 return EqFailure(expr1, expr2
1137 , detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(IUTEST_NULLPTR, val2))
1138 , detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(val2, IUTEST_NULLPTR)));
1141 namespace StrNeHelper
1144 template<
typename T1,
typename T2>
1145 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
const T1& val1,
const T2& val2)
1147 return !StrEqHelper::Compare(val1, val2);
1152 template<
typename T1,
typename T2>
1153 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNE(
1154 const char* expr1,
const char* expr2
1155 , T1 val1, T2 val2,
typename detail::enable_if<
1156 ((!detail::is_integral<T2>::value || !detail::is_pointer<T1>::value) &&
1157 (!detail::is_integral<T1>::value || !detail::is_pointer<T2>::value)),
void>::type*& = detail::enabler::value)
1159 if IUTEST_COND_LIKELY( StrNeHelper::Compare(val1, val2) )
1164 return AssertionFailure() <<
"error: Expected: " << expr1 <<
" != " << expr2
1165 <<
"\n Actual: " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1))
1166 <<
" vs " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2));
1169 template<
typename T>
1170 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNE(
1171 const char* expr1,
const char* expr2
1172 , detail::iu_nullptr_convertible_t, T val2)
1174 if IUTEST_COND_LIKELY( !StrEqHelper::Compare(IUTEST_NULLPTR, val2) )
1179 return AssertionFailure() <<
"error: Expected: " << expr1 <<
" != " << expr2
1180 <<
"\n Actual: " << detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(val2, IUTEST_NULLPTR))
1181 <<
" vs " << detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(IUTEST_NULLPTR, val2));
1184 template<
typename T>
1185 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRNE(
1186 const char* expr1,
const char* expr2
1187 , T val1, detail::iu_nullptr_convertible_t)
1189 if IUTEST_COND_LIKELY( !StrEqHelper::Compare(val1, IUTEST_NULLPTR) )
1194 return AssertionFailure() <<
"error: Expected: " << expr1 <<
" != " << expr2
1195 <<
"\n Actual: " << detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(IUTEST_NULLPTR, val1))
1196 <<
" vs " << detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(val1, IUTEST_NULLPTR));
1199 namespace StrCaseEqHelper
1202 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
const char* val1,
const char* val2)
1204 if( val1 == IUTEST_NULLPTR || val2 == IUTEST_NULLPTR )
1206 return val1 == val2;
1208 return detail::iu_stricmp(val1, val2) == 0;
1211 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
const wchar_t* val1,
const wchar_t* val2)
1213 if( val1 == IUTEST_NULLPTR || val2 == IUTEST_NULLPTR )
1215 return val1 == val2;
1217 return detail::iu_wcsicmp(val1, val2) == 0;
1220 template<
typename Elem,
typename Traits,
typename Ax>
1221 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
1222 const ::std::basic_string<Elem, Traits, Ax>& val1
1223 , const ::std::basic_string<Elem, Traits, Ax>& val2)
1225 return Compare(val1.c_str(), val2.c_str());
1227 template<
typename Elem,
typename Traits,
typename Ax>
1228 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
1230 , const ::std::basic_string<Elem, Traits, Ax>& val2)
1232 return Compare(val1, val2.c_str());
1234 template<
typename Elem,
typename Traits,
typename Ax>
1235 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
1236 const ::std::basic_string<Elem, Traits, Ax>& val1
1239 return Compare(val1.c_str(), val2);
1242 template<
typename T1,
typename T2>
1243 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(
1244 const char* expr1,
const char* expr2
1245 ,
const T1& val1,
const T2& val2)
1247 if IUTEST_COND_LIKELY( Compare(val1, val2) )
1252 return EqFailure(expr1, expr2
1253 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2))
1254 , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1))
1260 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1261 const char* expr1,
const char* expr2
1262 ,
const char* val1,
const char* val2)
1264 return StrCaseEqHelper::Assertion(expr1, expr2, val1, val2);
1266 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1267 const char* expr1,
const char* expr2
1268 ,
const wchar_t* val1,
const wchar_t* val2)
1270 return StrCaseEqHelper::Assertion(expr1, expr2, val1, val2);
1272 template<
typename Elem,
typename Traits,
typename Ax>
1273 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1274 const char* expr1,
const char* expr2
1275 , const ::std::basic_string<Elem, Traits, Ax>& val1
1276 , const ::std::basic_string<Elem, Traits, Ax>& val2)
1278 return CmpHelperSTRCASEEQ(expr1, expr2, val1.c_str(), val2.c_str());
1280 template<
typename Elem,
typename Traits,
typename Ax>
1281 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1282 const char* expr1,
const char* expr2
1283 ,
const Elem* val1, const ::std::basic_string<Elem, Traits, Ax>& val2)
1285 return CmpHelperSTRCASEEQ(expr1, expr2, val1, val2.c_str());
1287 template<
typename Elem,
typename Traits,
typename Ax>
1288 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1289 const char* expr1,
const char* expr2
1290 , const ::std::basic_string<Elem, Traits, Ax>& val1,
const Elem* val2)
1292 return CmpHelperSTRCASEEQ(expr1, expr2, val1.c_str(), val2);
1295 namespace StrCaseNeHelper
1298 template<
typename T1,
typename T2>
1299 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
const T1& val1,
const T2& val2)
1301 return !StrCaseEqHelper::Compare(val1, val2);
1304 template<
typename T1,
typename T2>
1305 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ Assertion(
1306 const char* expr1,
const char* expr2
1307 ,
const T1& val1,
const T2& val2)
1309 if IUTEST_COND_LIKELY( Compare(val1, val2) )
1314 return AssertionFailure() <<
"error: Expected: " << expr1 <<
" != " << expr2 <<
" (ignoring case)"
1315 <<
"\n Actual: " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1))
1316 <<
" vs " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2));
1321 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1322 const char* expr1,
const char* expr2
1323 ,
const char* val1,
const char* val2)
1325 return StrCaseNeHelper::Assertion(expr1, expr2, val1, val2);
1327 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1328 const char* expr1,
const char* expr2
1329 ,
const wchar_t* val1,
const wchar_t* val2)
1331 return StrCaseNeHelper::Assertion(expr1, expr2, val1, val2);
1333 template<
typename Elem,
typename Traits,
typename Ax>
1334 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1335 const char* expr1,
const char* expr2
1336 , const ::std::basic_string<Elem, Traits, Ax>& val1
1337 , const ::std::basic_string<Elem, Traits, Ax>& val2)
1339 return CmpHelperSTRCASENE(expr1, expr2, val1.c_str(), val2.c_str());
1341 template<
typename Elem,
typename Traits,
typename Ax>
1342 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1343 const char* expr1,
const char* expr2
1345 , const ::std::basic_string<Elem, Traits, Ax>& val2)
1347 return CmpHelperSTRCASENE(expr1, expr2, val1, val2.c_str());
1349 template<
typename Elem,
typename Traits,
typename Ax>
1350 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1351 const char* expr1,
const char* expr2
1352 , const ::std::basic_string<Elem, Traits, Ax>& val1
1355 return CmpHelperSTRCASENE(expr1, expr2, val1.c_str(), val2);
1358 #if defined(IUTEST_OS_WINDOWS)
1360 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ IsHRESULTSuccess(
const char* expr, HRESULT hr)
1362 if IUTEST_COND_LIKELY( SUCCEEDED(hr) )
1367 <<
"\n Actual: " << hr <<
": " << detail::win::GetHResultString(hr);
1369 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ IsHRESULTFailure(
const char* expr, HRESULT hr)
1371 if IUTEST_COND_LIKELY( FAILED(hr) )
1376 <<
"\n Actual: " << hr;
1387 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_
FloatLE(
1388 const char* expr1,
const char* expr2
1389 ,
float val1,
float val2)
1391 return internal::CmpHelperFloatingPointLE<float>(expr1, expr2, val1, val2);
1398 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_
DoubleLE(
1399 const char* expr1,
const char* expr2
1400 ,
double val1,
double val2)
1402 return internal::CmpHelperFloatingPointLE<double>(expr1, expr2, val1, val2);
Assertion Result
Definition: iutest_assertion.hpp:67
bool passed() const IUTEST_CXX_NOEXCEPT_SPEC
成否
Definition: iutest_assertion.hpp:85
static AssertionResult Success()
成功結果の作成
Definition: iutest_assertion.hpp:131
const char * failure_message() const
メッセージの取得
Definition: iutest_assertion.hpp:96
static AssertionResult Is(const T &b)
成否の取得
Definition: iutest_assertion.hpp:140
const char * message() const
メッセージの取得
Definition: iutest_assertion.hpp:90
bool failed() const IUTEST_CXX_NOEXCEPT_SPEC
成否
Definition: iutest_assertion.hpp:80
AssertionResult(bool result)
コンストラクタ
Definition: iutest_assertion.hpp:73
static AssertionResult Failure()
失敗結果の作成
Definition: iutest_assertion.hpp:135
AssertionResult & operator<<(const T &value)
メッセージ追加
Definition: iutest_assertion.hpp:106
@ BREAK_ON_FAILURE
テスト失敗時にブレーク
Definition: iutest_env.hpp:149
static bool IsEnableFlag(int flag)
フラグが立っているかどうか
Definition: iutest_env.hpp:210
テスト情報クラス
Definition: iutest_info.hpp:38
テスト結果を示すクラス
Definition: iutest_result.hpp:57
Type
結果のタイプ
Definition: iutest_result.hpp:63
@ kSkip
スキップ
Definition: iutest_result.hpp:65
@ kAssumeFailure
前提条件エラー
Definition: iutest_result.hpp:64
@ kFatalFailure
致命的な失敗
Definition: iutest_result.hpp:69
detail::AnyMatcher< T > A()
Make Any matcher
Definition: iutest_matcher.hpp:2604
#define IUTEST_CXX_EXPLICIT_CONVERSION
explicit conversion definition
Definition: iutest_compiler.hpp:713
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
iris unit test list 構造 ファイル
#define IUTEST_PP_DISALLOW_MOVE_AND_COPY_AND_ASSIGN(TypeName)
コピー/ムーブ禁止定義
Definition: iutest_pp.hpp:52
iris unit test print 出力ヘルパー ファイル
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 IUTEST_ATTRIBUTE_UNUSED_ FloatLE(const char *expr1, const char *expr2, float val1, float val2)
Float LE Formatter
Definition: iutest_assertion.hpp:1388
AssertionResult AssertionFailure()
テスト失敗を示す AssertionResult オブジェクトの取得
Definition: iutest_assertion.hpp:410
detail::iuStreamMessage Message
Message クラス
Definition: iutest_assertion.hpp:33
AssertionReturnType< T > AssertionReturn(const T &ret)
Assetion Return 設定
Definition: iutest_assertion.hpp:181
const char * GetAssertionResultMessage(const AssertionResult &ar)
テスト結果のメッセージを取得する(for compatible)
Definition: iutest_assertion.hpp:415
AssertionResult IUTEST_ATTRIBUTE_UNUSED_ DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
Double LE Formatter
Definition: iutest_assertion.hpp:1399
Assetion Return Type (void)
Definition: iutest_assertion.hpp:172
Assetion Return Type
Definition: iutest_assertion.hpp:157
AssertionReturnType()
コンストラクタ
Definition: iutest_assertion.hpp:160
R value
Definition: iutest_assertion.hpp:158