iutest  1.17.99.14
iutest_assertion.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_ASSERTION_HPP_E6AF3476_DA81_46F7_A961_ACCEF7363932_
16 #define INCG_IRIS_IUTEST_ASSERTION_HPP_E6AF3476_DA81_46F7_A961_ACCEF7363932_
17 
18 //======================================================================
19 // include
20 // IWYU pragma: begin_exports
21 #include "iutest_result.hpp"
22 #include "iutest_printers.hpp"
23 #include "internal/iutest_list.hpp"
24 // IWYU pragma: end_exports
25 
26 namespace iutest
27 {
28 
29 //======================================================================
30 // typedef
32 typedef detail::iuStreamMessage Message;
33 
34 //======================================================================
35 // function
36 template<typename T>
37 inline ::std::string StreamableToString(const T& value)
38 {
39  return (Message() << value).GetString();
40 }
41 
42 //======================================================================
43 // declare
44 namespace detail
45 {
46 
48 void DefaultReportTestPartResult(const TestPartResult& test_part_result);
49 
50 class UncaughtScopedTrace
51 {
52 public:
53  static void Add(const detail::iuCodeMessage& msg);
54  static bool Has();
55  static ::std::string Get();
56 };
57 
58 } // end of namespace detail
59 
60 //======================================================================
61 // class
65 class AssertionResult
66 {
67 public:
72  AssertionResult(bool result) : m_result(result) {} // NOLINT
74  AssertionResult(const AssertionResult& rhs) : m_message(rhs.m_message), m_result(rhs.m_result) {}
75 
79  bool failed() const IUTEST_CXX_NOEXCEPT_SPEC { return !m_result; }
80 
84  bool passed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_result; }
85 
89  const char* message() const { return m_message.c_str(); }
90 
95  const char* failure_message() const { return message(); }
96 
98  IUTEST_CXX_EXPLICIT_CONVERSION operator bool() const { return m_result; }
99 
100 public:
104  template<typename T>
105  AssertionResult& operator << (const T& value)
106  {
107  Message msg;
108  msg << value;
109  m_message += msg.GetString();
110  return *this;
111  }
112 public:
113  AssertionResult operator ! () const
114  {
115  return AssertionResult(failed()) << message();
116  }
117  AssertionResult operator && (const AssertionResult& rhs) const
118  {
119  return AssertionResult(m_result && rhs.passed()) << message() << " && " << rhs.message();
120  }
121  AssertionResult operator || (const AssertionResult& rhs) const
122  {
123  return AssertionResult(m_result || rhs.passed()) << message() << " || " << rhs.message();
124  }
125 
126 public:
130  static AssertionResult Success() { return AssertionResult(true); }
134  static AssertionResult Failure() { return AssertionResult(false); }
138  template<typename T>
139  static AssertionResult Is(const T& b) { return AssertionResult(b ? true : false); }
141  static AssertionResult Is(const AssertionResult& ar) { return AssertionResult(ar); }
142 
143 private:
144  IUTEST_PP_DISALLOW_ASSIGN(AssertionResult);
145 
146  ::std::string m_message;
147  bool m_result;
148 };
149 
150 #if IUTEST_HAS_ASSERTION_RETURN
154 template<typename R>
155 struct AssertionReturnType
156 {
157  R value;
164  AssertionReturnType(const R& v) : value(v) {} // NOLINT
165 };
169 template<>
170 struct AssertionReturnType<void>
171 {
174 };
175 
179 template<typename T>
180 inline AssertionReturnType<T> AssertionReturn(const T& ret) { return AssertionReturnType<T>(ret); }
181 
184 
185 #endif
186 
191 class AssertionHelper
192 {
193 public:
201  AssertionHelper(const char* file, int line, const char* message, TestPartResult::Type type)
202  : m_part_result(file, line, message, type)
203  {}
211  AssertionHelper(const char* file, int line, const ::std::string& message, TestPartResult::Type type)
212  : m_part_result(file, line, message.c_str(), type)
213  {}
214 
215 public:
217  class ScopedMessage
218  : public detail::iuCodeMessage
219 #if IUTEST_USE_OWN_LIST
220  , public detail::iu_list_node<ScopedMessage>
221 #endif
222  {
223  public:
224  ScopedMessage(const detail::iuCodeMessage& msg) // NOLINT
225  : detail::iuCodeMessage(msg)
226  {
227  ScopedTrace::GetInstance().list.push_back(this);
228  }
229  ~ScopedMessage()
230  {
231  ScopedTrace::GetInstance().list.remove(this);
232  if( stl::uncaught_exception() )
233  {
234  detail::UncaughtScopedTrace::Add(*this);
235  }
236  }
237  };
238 private:
239  class ScopedTrace
240  {
241  public:
242 #if IUTEST_USE_OWN_LIST
243  typedef detail::iu_list<ScopedMessage> msg_list;
244 #else
245  typedef ::std::list<ScopedMessage*> msg_list;
246 #endif
247  msg_list list;
248 
249  static ScopedTrace& GetInstance() { static ScopedTrace inst; return inst; }
250  public:
251  void append_message(TestPartResult& part_result, bool isException)
252  {
253  if( !list.empty() || detail::UncaughtScopedTrace::Has() )
254  {
255  part_result.add_message("\niutest trace:");
256  // TODO : 追加メッセージとして保存するべき
257  // 現状はテスト結果のメッセージに追加している。
258  for( msg_list::iterator it = list.begin(), end=list.end(); it != end; ++it )
259  {
260  part_result.add_message("\n");
261  part_result.add_message((*it)->make_message().c_str());
262  }
263  if( isException )
264  {
265  part_result.add_message(detail::UncaughtScopedTrace::Get());
266  }
267  }
268  }
269  };
270 
271 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
272  friend class ScopedMessage;
273 #endif
274 
275 #if IUTEST_HAS_ASSERTION_RETURN
276 private:
277  template<typename R>struct ReturnTypedFixed;
278 #endif
279 
280 public:
282  class Fixed : public Message
283  {
284  public:
285  template<typename T>
286  Fixed& operator << (T val)
287  {
288  Message::operator << (val);
289  return *this;
290  }
291  template<typename T, size_t SIZE>
292  Fixed& operator << (const T(&val)[SIZE])
293  {
294  Message::operator << (val);
295  return *this;
296  }
297 #if IUTEST_HAS_IOMANIP
298  Fixed& operator << (iu_basic_iomanip val)
299  {
300  Message::operator << (val);
301  return *this;
302  }
303 #endif
304 #if IUTEST_HAS_ASSERTION_RETURN
305  Fixed& operator << (const AssertionReturnType<void>&)
306  {
307  return *this;
308  }
309  template<typename R>
310  ReturnTypedFixed<R> operator << (const AssertionReturnType<R>& ret)
311  {
312  return ReturnTypedFixed<R>(*this, ret);
313  }
314 #endif
315  };
316 
317 #if IUTEST_HAS_ASSERTION_RETURN
318 private:
319  template<typename R>
320  struct ReturnTypedFixed
321  {
322  Fixed fixed;
324  ReturnTypedFixed(const Fixed& f, const AssertionReturnType<R>& r) : fixed(f), ret(r) {}
325  };
326 #endif
327 
328 public:
330  void operator = (const Fixed& fixed)
331  {
332  OnFixed(fixed);
333 #if IUTEST_HAS_EXCEPTIONS && IUTEST_USE_THROW_ON_ASSERTION_FAILURE
334  {
335 IUTEST_PRAGMA_WARN_PUSH()
336 IUTEST_PRAGMA_WARN_DISABLE_SWITCH_ENUM()
337  switch( m_part_result.type() )
338  {
342  throw m_part_result.type();
343  default:
344  break;
345  }
346 IUTEST_PRAGMA_WARN_POP()
347  }
348 #endif
349  }
350 #if IUTEST_HAS_ASSERTION_RETURN
352  template<typename R>
353  R operator = (const ReturnTypedFixed<R>& fixed) // lgtm [cpp/assignment-does-not-return-this]
354  {
355  this->operator=(fixed.fixed);
356  return fixed.ret.value;
357  }
358 #endif
359 
360 private:
361  void OnFixed(const Fixed& fixed, bool isException = false)
362  {
363  // OnFixed で throw しないこと!テスト側の例外キャッチにかからなくなる
364  const ::std::string append_message = fixed.GetString();
365  if( !append_message.empty() )
366  {
367  m_part_result.add_message(" " + append_message);
368  }
369  ScopedTrace::GetInstance().append_message(m_part_result, isException);
370 
371  if( TestEnv::GetGlobalTestPartResultReporter() != IUTEST_NULLPTR )
372  {
373  TestEnv::GetGlobalTestPartResultReporter()->ReportTestPartResult(m_part_result);
374  }
375  else
376  {
377  detail::DefaultReportTestPartResult(m_part_result);
378  }
379 
380  if IUTEST_COND_UNLIKELY(m_part_result.failed()
382  {
383  IUTEST_BREAK();
384  }
385  }
386 
387 private:
388  friend class TestInfo;
389  TestPartResult m_part_result;
390 
391 private:
393 };
394 
395 } // end of namespace iutest
396 
397 namespace iutest
398 {
399 
400 //======================================================================
401 // function
405 inline AssertionResult AssertionSuccess() { return AssertionResult::Success(); }
409 inline AssertionResult AssertionFailure() { return AssertionResult::Failure(); }
410 
414 inline const char* GetAssertionResultMessage(const AssertionResult& ar)
415 {
416  return ar.message();
417 }
418 
419 namespace internal
420 {
421 
425 template<typename T1, typename T2>
426 inline ::std::string FormatForComparisonFailureMessage(const T1& value, const T2& /*other_operand*/)
427 {
428  return PrintToString(value);
429 }
430 
434 inline ::std::string GetBooleanAssertionFailureMessage(const AssertionResult& ar
435  , const char* expr, const char* actual, const char* expected)
436 {
437  ::std::string str = "error: Value of: ";
438  str += expr;
439  str += "\n Actual: ";
440  str += actual;
441  if( !detail::IsEmpty(ar.message()) )
442  {
443  str += " (";
444  str += ar.message();
445  str += ")";
446  }
447  str += "\nExpected: ";
448  str += expected;
449  return str;
450 }
451 
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)
457 {
458  iu_global_format_stringstream strm;
459  strm << "error: Value of " << actual_expression
460  << "\n Actual: " << actual
461  << "\nExpected: " << expected_expression;
462  if( ignoring_case )
463  {
464  strm << " (ignoring case)";
465  }
466  if( !detail::IsStringEqual(expected_expression, expected.c_str()) )
467  {
468  strm << "\nWhich is: " << expected;
469  }
470  return AssertionFailure() << strm.str();
471 }
472 
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)
476 {
477  return AssertionFailure() << "error: Expected: " << expr1 << " " << op << " " << expr2
478  << "\n Actual: " << FormatForComparisonFailureMessage(val1, val2)
479  << " vs " << FormatForComparisonFailureMessage(val2, val1);
480 }
481 
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() \
492  return v1 op v2; \
493  IUTEST_PRAGMA_WARN_POP() \
494  }
495 
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) { \
500  return v1 op v2; \
501  } \
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; \
506  } \
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; \
511  }
512 #else
513 #define IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT_(op_name, op)
514 #endif
515 
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)
519 
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); } \
525  }
526 
527 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
528 
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)
534 
535 #else
536 
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&)
541 
542 #endif
543 
544 template<typename T1, typename T2>
545 bool iuOperatorEQ(const T1& v1, const T2& v2)
546 {
547 IUTEST_PRAGMA_WARN_PUSH()
548 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
549 IUTEST_PRAGMA_WARN_DISABLE_IMPLICIT_INT_FLOAT_CONVERSION()
550  return v1 == v2;
551 IUTEST_PRAGMA_WARN_POP()
552 }
553 IIUT_DECL_COMPARE_HELPER_EXTEND_POINT_VARIANT_(EQ, ==)
554 
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, > )
560 
561 
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_
567 
576 template<bool IsNullLiteral>
577 class NullHelper
578 {
579 public:
580  template<typename T>
581  static AssertionResult CompareEq(const char* expr, const T* val)
582  {
583  if IUTEST_COND_LIKELY( IUTEST_NULLPTR == val )
584  {
585  return AssertionSuccess();
586  }
587 
588  return AssertionFailure() << "error: Value of " << expr
589  << "\n Actual: " << val
590  << "\nExpected: NULL";
591  }
592  template<typename T>
593  static AssertionResult CompareNe(const char* expr, const T* val)
594  {
595  if IUTEST_COND_LIKELY( IUTEST_NULLPTR != val )
596  {
597  return AssertionSuccess();
598  }
599 
600  return AssertionFailure() << "error: Value of " << expr
601  << "\n Actual: NULL\nExpected: not NULL";
602  }
603 };
604 
608 template<>
609 class NullHelper<true>
610 {
611 public:
612  static AssertionResult CompareEq(const char*, void*)
613  {
614  return AssertionSuccess();
615  }
616  static AssertionResult CompareNe(const char* expr, void*)
617  {
618  return AssertionFailure() << "error: Value of " << expr
619  << "\n Actual: NULL\nExpected: not NULL";
620  }
621 };
622 
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)
626 {
627  if IUTEST_COND_LIKELY( &expected == &actual )
628  {
629  return AssertionSuccess();
630  }
631 
632  return AssertionFailure() << "error: Expected: &(" << expected_str << ") == &(" << actual_str
633  << ")\n Actual: " << FormatForComparisonFailureMessage(&expected, &actual)
634  << " vs " << FormatForComparisonFailureMessage(&actual, &expected);
635 }
636 
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)
640 {
641  if IUTEST_COND_LIKELY( iuOperatorEQ(actual, expected) )
642  {
643  return AssertionSuccess();
644  }
645 
646  return EqFailure(expected_str, actual_str
647  , FormatForComparisonFailureMessage(expected, actual)
648  , FormatForComparisonFailureMessage(actual, expected)
649  );
650 }
651 
652 template<typename T>
653 inline AssertionResult CmpHelperMemCmpEQ(const char* expected_str, const char* actual_str
654  , const T& expected, const T& actual)
655 {
656 IUTEST_PRAGMA_WARN_PUSH()
657 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
658 
659  if IUTEST_COND_LIKELY( memcmp(&actual, &expected, sizeof(T)) == 0 )
660  {
661  return AssertionSuccess();
662  }
663 
664  return EqFailure(expected_str, actual_str
665  , FormatForComparisonFailureMessage(expected, actual)
666  , FormatForComparisonFailureMessage(actual, expected)
667  );
668 
669 IUTEST_PRAGMA_WARN_POP()
670 }
671 
672 template<typename T>
673 inline AssertionResult CmpHelperMemCmpNE(const char* expected_str, const char* actual_str
674  , const T& expected, const T& actual)
675 {
676 IUTEST_PRAGMA_WARN_PUSH()
677 IUTEST_PRAGMA_WARN_DISABLE_SIGN_COMPARE()
678 
679  if IUTEST_COND_LIKELY( memcmp(&actual, &expected, sizeof(T)) != 0 )
680  {
681  return AssertionSuccess();
682  }
683 
684  return AssertionFailure() << "error: Expected: " << expected_str << " != " << actual_str
685  << "\n Actual: " << FormatForComparisonFailureMessage(expected, actual);
686 
687 IUTEST_PRAGMA_WARN_POP()
688 }
689 
690 template<typename RawType>
691 inline AssertionResult CmpHelperFloatingPointEQ(const char* expr1, const char* expr2
692  , RawType val1, RawType val2)
693 {
694  floating_point<RawType> f1(val1), f2(val2);
695  if IUTEST_COND_LIKELY( f1.AlmostEquals(f2) )
696  {
697  return AssertionSuccess();
698  }
699  return EqFailure(expr1, expr2
700  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f1, f2))
701  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f2, f1)));
702 }
703 
704 template<typename RawType>
705 inline AssertionResult CmpHelperFloatingPointLE(const char* expr1, const char* expr2
706  , RawType val1, RawType val2)
707 {
708  if IUTEST_COND_LIKELY( val1 < val2 )
709  {
710  return AssertionSuccess();
711  }
712  floating_point<RawType> f1(val1), f2(val2);
713  if IUTEST_COND_LIKELY( f1.AlmostEquals(f2) )
714  {
715  return AssertionSuccess();
716  }
717  return EqFailure(expr1, expr2
718  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f1, f2))
719  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(f2, f1)));
720 }
721 
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)
725 {
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) )
729  {
730  return AssertionSuccess();
731  }
732  return EqFailure(expr1, expr2
733  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2))
734  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1)));
735 }
736 
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)
740 {
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));
743 }
744 
745 template<typename R1, typename R2>
746 inline AssertionResult CmpHelperFloatingPointComplexEQ(const char* expr1, const char* expr2
747  , R1 val1, const ::std::complex<R2>& val2)
748 {
749  return CmpHelperFloatingPointComplexEQ(expr1, expr2, ::std::complex<R2>(val1, R2()), val2);
750 }
751 template<typename R1, typename R2>
752 inline AssertionResult CmpHelperFloatingPointComplexEQ(const char* expr1, const char* expr2
753  , const ::std::complex<R1>& val1, R2 val2)
754 {
755  return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, ::std::complex<R1>(val2, R1()));
756 }
757 
758 
762 namespace backward
763 {
764 
769 template<bool IsNullLiteral>
770 class EqHelper
771 {
772 #if IUTEST_HAS_ASSERTION_NOEQUALTO_OBJECT
773  template<typename T, bool has_equal_to_operator>
774  struct CmpHelper
775  {
776  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const T& val2)
777  {
778  return CmpHelperEQ(expr1, expr2, val1, val2);
779  }
780  };
781  template<typename T>
782  struct CmpHelper<T, false>
783  {
784  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const T& val2)
785  {
786  return CmpHelperMemCmpEQ(expr1, expr2, val1, val2);
787  }
788  };
789 
790 public:
791  template<typename T>
792  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const T& val2)
793  {
794  return CmpHelper<T, detail::has_equal_to<T>::value>::Compare(expr1, expr2, val1, val2);
795  }
796 #endif
797 
798 public:
799  template<typename T1, typename T2>
800  static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
801  {
802  return CmpHelperEQ(expr1, expr2, val1, val2);
803  }
804 };
805 
809 template<>
810 class EqHelper<true>
811 {
812 public:
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)
817  {
818  return CmpHelperEQ(expr1, expr2, val1, val2);
819  }
820  template<typename T2>
821  static AssertionResult Compare(const char* expr1, const char* expr2
822  , detail::IsNullLiteralHelper::Object* val1, T2* val2)
823  {
824  IUTEST_UNUSED_VAR(val1);
825  return CmpHelperEQ(expr1, expr2, static_cast<T2*>(IUTEST_NULLPTR), val2);
826  }
827 #else
828  template<typename T1, typename T2>
829  static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
830  {
831  return CmpHelperEQ(expr1, expr2, (T2)(val1), val2); // NOLINT
832  }
833 #endif
834 };
835 
840 template<bool IsNullLiteral>
841 class AlmostEqHelper : public EqHelper<false>
842 {
843  struct CmpHelper
844  {
845  template<typename T1, typename T2>
846  static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
847  {
848  return EqHelper<false>::Compare(expr1, expr2, val1, static_cast<T1>(val2));
849  }
850  template<typename T>
851  static AssertionResult Compare(const char* expr1, const char* expr2, const float& val1, const T& val2)
852  {
853  return CmpHelperFloatingPointEQ<float>(expr1, expr2, val1, static_cast<float>(val2));
854  }
855  template<typename T>
856  static AssertionResult Compare(const char* expr1, const char* expr2, const double& val1, const T& val2)
857  {
858  return CmpHelperFloatingPointEQ<double>(expr1, expr2, val1, static_cast<double>(val2));
859  }
860  };
861 public:
862  template<typename T1, typename T2>
863  static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
864  {
865  return CmpHelper::Compare(expr1, expr2, val1, val2);
866  }
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)
869  {
870  return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, val2);
871  }
872  template<typename T, typename U>
873  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const ::std::complex<U>& val2)
874  {
875  return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, val2);
876  }
877  template<typename T, typename U>
878  static AssertionResult Compare(const char* expr1, const char* expr2, const ::std::complex<T>& val1, const U& val2)
879  {
880  return CmpHelperFloatingPointComplexEQ(expr1, expr2, val1, val2);
881  }
882 };
883 
887 template<>
888 class AlmostEqHelper<true> : public EqHelper<true>
889 {
890 };
891 
896 template<bool IsNullLiteral>
897 class NeHelper
898 {
899 #if IUTEST_HAS_ASSERTION_NOEQUALTO_OBJECT
900  template<typename T, bool has_not_equal_to_operator>
901  struct CmpHelper
902  {
903  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const T& val2)
904  {
905  return CmpHelperNE(expr1, expr2, val1, val2);
906  }
907  };
908  template<typename T>
909  struct CmpHelper<T, false>
910  {
911  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const T& val2)
912  {
913  return CmpHelperMemCmpNE(expr1, expr2, val1, val2);
914  }
915  };
916 
917 public:
918  template<typename T>
919  static AssertionResult Compare(const char* expr1, const char* expr2, const T& val1, const T& val2)
920  {
921  return CmpHelper<T, detail::has_not_equal_to<T>::value>::Compare(expr1, expr2, val1, val2);
922  }
923 
924 #endif
925 
926 public:
927  template<typename T1, typename T2>
928  static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
929  {
930  return CmpHelperNE(expr1, expr2, val1, val2);
931  }
932 };
933 
937 template<>
938 class NeHelper<true>
939 {
940 public:
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)
945  {
946  return CmpHelperNE(expr1, expr2, val1, val2);
947  }
948  template<typename T2>
949  static AssertionResult Compare(const char* expr1, const char* expr2
950  , detail::IsNullLiteralHelper::Object* val1, T2* val2)
951  {
952  IUTEST_UNUSED_VAR(val1);
953  return CmpHelperNE(expr1, expr2, static_cast<T2*>(IUTEST_NULLPTR), val2);
954  }
955 #else
956  template<typename T1, typename T2>
957  static AssertionResult Compare(const char* expr1, const char* expr2, const T1& val1, const T2& val2)
958  {
959  return CmpHelperNE(expr1, expr2, (T2)(val1), val2); // NOLINT
960  }
961 #endif
962 };
963 
964 } // end of namespace backward
965 
966 #if IUTEST_HAS_NULLPTR && IUTEST_HAS_CXX_HDR_TYPE_TARITS && 0
967 
971 class EqHelper
972 {
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)
976  {
977  return backward::EqHelper<false>::Compare(expr1, expr2, val1, val2);
978  }
979  template<typename T>
980  static AssertionResult Compare(const char* expr1, const char* expr2, ::std::nullptr_t, T* val2)
981  {
982  return CmpHelperEQ(expr1, expr2, static_cast<T*>(IUTEST_NULLPTR), val2);
983  }
984 };
985 
989 class NeHelper
990 {
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)
994  {
995  return backward::NeHelper<false>::Compare(expr1, expr2, val1, val2);
996  }
997  template<typename T>
998  static AssertionResult Compare(const char* expr1, const char* expr2, ::std::nullptr_t, T* val2)
999  {
1000  return CmpHelperNE(expr1, expr2, static_cast<T*>(IUTEST_NULLPTR), val2);
1001  }
1002 };
1003 
1004 #else
1005 
1006 using backward::EqHelper;
1007 using backward::AlmostEqHelper;
1008 using backward::NeHelper;
1009 
1010 #endif
1011 
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)
1016 {
1017  const RawType diff = val1 > val2 ? val1 - val2 : val2 - val1;
1018  if IUTEST_COND_LIKELY( diff < abs_v )
1019  {
1020  return AssertionSuccess();
1021  }
1022  floating_point<RawType> f1(diff), f2(abs_v);
1023  if IUTEST_COND_LIKELY( f1.AlmostEquals(f2) )
1024  {
1025  return AssertionSuccess();
1026  }
1027  return AssertionFailure() << "error: Value of: abs(" << expr1 << " - " << expr2 << ") <= " << absc
1028  << "\n Actual: abs(" << val1 << " - " << val2 << ") : " << diff
1029  << "\nExpected: " << FormatForComparisonFailureMessage(abs_v, diff);
1030 }
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)
1034 {
1035  return CmpHelperNearFloatingPoint(expr1, expr2, absc, val1, val2, abs_v);
1036 }
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)
1042 {
1043  const T diff = val1 > val2 ? val1 - val2 : val2 - val1;
1044  if IUTEST_COND_LIKELY( diff <= abs_v )
1045  {
1046  return AssertionSuccess();
1047  }
1048  return AssertionFailure() << "error: Value of: abs(" << expr1 << " - " << expr2 << ") <= " << absc
1049  << "\n Actual: abs(" << val1 << " - " << val2 << ") : " << diff
1050  << "\nExpected: " << FormatForComparisonFailureMessage(abs_v, diff);
1051 }
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)
1056 {
1057  return CmpHelperNearFloatingPoint<double>(expr1, expr2, absc, val1, val2, static_cast<double>(abs_v));
1058 }
1059 #endif
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)
1064 {
1065  return CmpHelperNearFloatingPoint<float>(expr1, expr2, absc, val1, val2, static_cast<float>(abs_v));
1066 }
1067 
1068 
1069 namespace StrEqHelper
1070 {
1071 
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; \
1076  }
1077 #else
1078 #define IIUT_DECL_STREQ_COMPARE_HELPER_NULL_(T)
1079 #endif
1080 
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; \
1085  } \
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)); \
1090  }
1091 
1092 #define IIUT_DECL_STREQ_COMPARE_HELPER_(T) \
1093  IIUT_DECL_STREQ_COMPARE_HELPER_SV_(T) \
1094  IIUT_DECL_STREQ_COMPARE_HELPER_NULL_(T)
1095 
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)
1100 #endif
1101 #if IUTEST_HAS_CHAR32_T
1102 IIUT_DECL_STREQ_COMPARE_HELPER_(char32_t)
1103 #endif
1104 
1105 #undef IIUT_DECL_STREQ_COMPARE_HELPER_
1106 #undef IIUT_DECL_STREQ_COMPARE_HELPER_SV_
1107 
1108 } // end of namespace StrEqHelper
1109 
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)
1115 {
1116  if IUTEST_COND_LIKELY( StrEqHelper::Compare(val1, val2) )
1117  {
1118  return AssertionSuccess();
1119  }
1120 
1121  return EqFailure(expr1, expr2
1122  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2))
1123  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1)));
1124 }
1125 
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)
1130 {
1131  if IUTEST_COND_LIKELY( StrEqHelper::Compare(IUTEST_NULLPTR, val2) )
1132  {
1133  return AssertionSuccess();
1134  }
1135 
1136  return EqFailure(expr1, expr2
1137  , detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(IUTEST_NULLPTR, val2))
1138  , detail::ShowStringQuoted(FormatForComparisonFailureMessage<T, T>(val2, IUTEST_NULLPTR)));
1139 }
1140 
1141 namespace StrNeHelper
1142 {
1143 
1144 template<typename T1, typename T2>
1145 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& val1, const T2& val2)
1146 {
1147  return !StrEqHelper::Compare(val1, val2);
1148 }
1149 
1150 } // end of namespace StrNeHelper
1151 
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)
1158 {
1159  if IUTEST_COND_LIKELY( StrNeHelper::Compare(val1, val2) )
1160  {
1161  return AssertionSuccess();
1162  }
1163 
1164  return AssertionFailure() << "error: Expected: " << expr1 << " != " << expr2
1165  << "\n Actual: " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1))
1166  << " vs " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2));
1167 }
1168 
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)
1173 {
1174  if IUTEST_COND_LIKELY( !StrEqHelper::Compare(IUTEST_NULLPTR, val2) )
1175  {
1176  return AssertionSuccess();
1177  }
1178 
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));
1182 }
1183 
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)
1188 {
1189  if IUTEST_COND_LIKELY( !StrEqHelper::Compare(val1, IUTEST_NULLPTR) )
1190  {
1191  return AssertionSuccess();
1192  }
1193 
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));
1197 }
1198 
1199 namespace StrCaseEqHelper
1200 {
1201 
1202 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const char* val1, const char* val2)
1203 {
1204  if( val1 == IUTEST_NULLPTR || val2 == IUTEST_NULLPTR )
1205  {
1206  return val1 == val2;
1207  }
1208  return detail::iu_stricmp(val1, val2) == 0;
1209 }
1210 
1211 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const wchar_t* val1, const wchar_t* val2)
1212 {
1213  if( val1 == IUTEST_NULLPTR || val2 == IUTEST_NULLPTR )
1214  {
1215  return val1 == val2;
1216  }
1217  return detail::iu_wcsicmp(val1, val2) == 0;
1218 }
1219 
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)
1224 {
1225  return Compare(val1.c_str(), val2.c_str());
1226 }
1227 template<typename Elem, typename Traits, typename Ax>
1228 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
1229  const Elem* val1
1230  , const ::std::basic_string<Elem, Traits, Ax>& val2)
1231 {
1232  return Compare(val1, val2.c_str());
1233 }
1234 template<typename Elem, typename Traits, typename Ax>
1235 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(
1236  const ::std::basic_string<Elem, Traits, Ax>& val1
1237  , const Elem* val2)
1238 {
1239  return Compare(val1.c_str(), val2);
1240 }
1241 
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)
1246 {
1247  if IUTEST_COND_LIKELY( Compare(val1, val2) )
1248  {
1249  return AssertionSuccess();
1250  }
1251 
1252  return EqFailure(expr1, expr2
1253  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2))
1254  , detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1))
1255  , true);
1256 }
1257 
1258 } // end of namespace StrCaseEqHelper
1259 
1260 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1261  const char* expr1, const char* expr2
1262  , const char* val1, const char* val2)
1263 {
1264  return StrCaseEqHelper::Assertion(expr1, expr2, val1, val2);
1265 }
1266 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASEEQ(
1267  const char* expr1, const char* expr2
1268  , const wchar_t* val1, const wchar_t* val2)
1269 {
1270  return StrCaseEqHelper::Assertion(expr1, expr2, val1, val2);
1271 }
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)
1277 {
1278  return CmpHelperSTRCASEEQ(expr1, expr2, val1.c_str(), val2.c_str());
1279 }
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)
1284 {
1285  return CmpHelperSTRCASEEQ(expr1, expr2, val1, val2.c_str());
1286 }
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)
1291 {
1292  return CmpHelperSTRCASEEQ(expr1, expr2, val1.c_str(), val2);
1293 }
1294 
1295 namespace StrCaseNeHelper
1296 {
1297 
1298 template<typename T1, typename T2>
1299 inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const T1& val1, const T2& val2)
1300 {
1301  return !StrCaseEqHelper::Compare(val1, val2);
1302 }
1303 
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)
1308 {
1309  if IUTEST_COND_LIKELY( Compare(val1, val2) )
1310  {
1311  return AssertionSuccess();
1312  }
1313 
1314  return AssertionFailure() << "error: Expected: " << expr1 << " != " << expr2 << " (ignoring case)"
1315  << "\n Actual: " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val2, val1))
1316  << " vs " << detail::ShowStringQuoted(FormatForComparisonFailureMessage(val1, val2));
1317 }
1318 
1319 } // end of namespace StrCaseNeHelper
1320 
1321 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1322  const char* expr1, const char* expr2
1323  , const char* val1, const char* val2)
1324 {
1325  return StrCaseNeHelper::Assertion(expr1, expr2, val1, val2);
1326 }
1327 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1328  const char* expr1, const char* expr2
1329  , const wchar_t* val1, const wchar_t* val2)
1330 {
1331  return StrCaseNeHelper::Assertion(expr1, expr2, val1, val2);
1332 }
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)
1338 {
1339  return CmpHelperSTRCASENE(expr1, expr2, val1.c_str(), val2.c_str());
1340 }
1341 template<typename Elem, typename Traits, typename Ax>
1342 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ CmpHelperSTRCASENE(
1343  const char* expr1, const char* expr2
1344  , const Elem* val1
1345  , const ::std::basic_string<Elem, Traits, Ax>& val2)
1346 {
1347  return CmpHelperSTRCASENE(expr1, expr2, val1, val2.c_str());
1348 }
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
1353  , const Elem* val2)
1354 {
1355  return CmpHelperSTRCASENE(expr1, expr2, val1.c_str(), val2);
1356 }
1357 
1358 #if defined(IUTEST_OS_WINDOWS)
1359 
1360 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ IsHRESULTSuccess(const char* expr, HRESULT hr)
1361 {
1362  if IUTEST_COND_LIKELY( SUCCEEDED(hr) )
1363  {
1364  return AssertionSuccess();
1365  }
1366  return AssertionFailure() << "error: Expected: SUCCEEDED(" << expr << ")"
1367  << "\n Actual: " << hr << ": " << detail::win::GetHResultString(hr);
1368 }
1369 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ IsHRESULTFailure(const char* expr, HRESULT hr)
1370 {
1371  if IUTEST_COND_LIKELY( FAILED(hr) )
1372  {
1373  return AssertionSuccess();
1374  }
1375  return AssertionFailure() << "error: Expected : FAILED(" << expr << ")"
1376  << "\n Actual: " << hr;
1377 }
1378 
1379 #endif
1380 
1381 } // end of namespace internal
1382 
1387 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ FloatLE(
1388  const char* expr1, const char* expr2
1389  , float val1, float val2)
1390 {
1391  return internal::CmpHelperFloatingPointLE<float>(expr1, expr2, val1, val2);
1392 }
1393 
1398 inline AssertionResult IUTEST_ATTRIBUTE_UNUSED_ DoubleLE(
1399  const char* expr1, const char* expr2
1400  , double val1, double val2)
1401 {
1402  return internal::CmpHelperFloatingPointLE<double>(expr1, expr2, val1, val2);
1403 }
1404 
1405 
1406 } // end of namespace iutest
1407 
1408 #endif // INCG_IRIS_IUTEST_ASSERTION_HPP_E6AF3476_DA81_46F7_A961_ACCEF7363932_
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 出力ヘルパー ファイル
iris unit test result
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