15 #ifndef INCG_IRIS_IUTEST_EXPRESSION_ASSERTION_HPP_B9783316_33CF_4CA7_81D0_0BF44B048A4A_
16 #define INCG_IRIS_IUTEST_EXPRESSION_ASSERTION_HPP_B9783316_33CF_4CA7_81D0_0BF44B048A4A_
24 #define IUTEST_OPERAND(op) op IIUT_EXPRESSION_DECOMPOSE()
30 #define IUTEST_EXPRESSION(expr) (IIUT_EXPRESSION_DECOMPOSE() expr).GetResult()
38 #if IUTEST_HAS_ARITHMETIC_EXPRESSION_DECOMPOSE
39 # define IIUT_EXPRESSION_DECOMPOSE() ::iutest::detail::ExpressionDecomposer()->*
41 # define IIUT_EXPRESSION_DECOMPOSE() ::iutest::detail::ExpressionDecomposer()>>
44 #ifndef IUTEST_NO_VARIADIC_MACROS
45 # define IIUT_TEST_EXPRESSION_UNPAREN_(...) __VA_ARGS__
46 # define IIUT_TEST_EXPRESSION_EXPAND_EXPRESSION(expr) IIUT_TEST_EXPRESSION_EXPAND_EXPRESSION_(UNPAREN_ expr)
47 # define IIUT_TEST_EXPRESSION_EXPAND_EXPRESSION_(expr) IIUT_TEST_EXPRESSION_##expr
48 # define IIUT_TEST_EXPRESSION_(expr, expected, on_failure) \
49 IUTEST_TEST_TRUE( ( IIUT_EXPRESSION_DECOMPOSE() expr ).GetResult(expected), #expr, on_failure )
50 # define IUTEST_TEST_EXPRESSION_(expr, expected, on_failure) \
51 IIUT_TEST_EXPRESSION_( IIUT_TEST_EXPRESSION_EXPAND_EXPRESSION(expr), expected, on_failure )
53 # define IUTEST_TEST_EXPRESSION_(expr, expected, on_failure) \
54 IUTEST_TEST_TRUE( ( IIUT_EXPRESSION_DECOMPOSE() expr ).GetResult(expected), #expr, on_failure )
58 #define IIUT_DECL_EXPRESSION_RESULT_OP(op) \
59 template<typename RHS>ExpressionResult operator op (const RHS& rhs) const { \
60 const bool b = result() op rhs ? true : false; \
61 return ExpressionResult(AssertionResult(b) \
62 << m_result.message() << " " #op " " << rhs); \
64 ExpressionResult operator op (const ExpressionResult& rhs) const { \
65 const bool b = result() op rhs.result() ? true : false; \
66 return ExpressionResult(AssertionResult(b) \
67 << m_result.message() << " " #op " " << rhs.message()); \
69 ExpressionResult operator op (const AssertionResult& rhs) const { \
70 const bool b = result() op rhs.passed() ? true : false; \
71 return ExpressionResult(AssertionResult(b) \
72 << m_result.message() << " " #op " " << rhs.message()); \
75 #define IIUT_DECL_EXPRESSION_OP(op) \
76 template<typename RHS>ExpressionResult operator op (const RHS& rhs) const { \
77 const bool b = (m_lhs op rhs) ? true : false; \
78 return ExpressionResult(AssertionResult(b) << m_message << " " #op " " << rhs); \
81 #if IUTEST_HAS_ARITHMETIC_EXPRESSION_DECOMPOSE || IUTEST_HAS_BITWISE_EXPRESSION_DECOMPOSE
83 #if IUTEST_HAS_DECLTYPE && IUTEST_HAS_STD_DECLVAL
85 #define IIUT_DECL_EXPRESSION_OP_LHS(op) \
86 template<typename RHS>auto operator op (const RHS& rhs) const \
87 -> ExpressionLHS< decltype( expression_op_helper::operand_result( \
88 ( ::std::declval<T>() op rhs ) ) )> { \
89 return OperandResult(m_lhs op rhs) << " " #op " " << rhs; \
94 #define IIUT_DECL_EXPRESSION_OP_LHS(op) \
95 template<typename RHS>ExpressionLHS<RHS> operator op (const RHS& rhs) const { \
96 return OperandResult(m_lhs op rhs) << " " #op " " << rhs; \
117 class ExpressionResult
120 explicit ExpressionResult(
const AssertionResult& ar)
124 IIUT_DECL_EXPRESSION_RESULT_OP(||)
125 IIUT_DECL_EXPRESSION_RESULT_OP(&&)
128 AssertionResult GetResult(
bool expected)
const
130 return AssertionResult(result() == expected) <<
"expansion: " << m_result.message();
132 AssertionResult GetResult()
const
134 return AssertionResult(result()) << m_result.message();
137 bool result()
const {
return m_result.passed(); }
138 const char* message()
const {
return m_result.message(); }
140 AssertionResult m_result;
143 namespace expression_op_helper
146 T operand_result(
const T&);
156 typedef ExpressionLHS<T> _Myt;
158 #if IUTEST_HAS_RVALUE_REFS
159 explicit ExpressionLHS(T&& lhs) : m_lhs( ::std::forward<T>(lhs) )
161 AppendMessage(m_lhs);
164 explicit ExpressionLHS(T lhs) : m_lhs(lhs)
169 ExpressionLHS(T lhs, const ::std::string& msg) : m_lhs(lhs), m_message(msg) {}
170 ExpressionLHS(
const ExpressionLHS& rhs) : m_lhs(rhs.m_lhs), m_message(rhs.m_message) {}
173 IIUT_DECL_EXPRESSION_OP(==)
174 IIUT_DECL_EXPRESSION_OP(!=)
175 IIUT_DECL_EXPRESSION_OP(<)
176 IIUT_DECL_EXPRESSION_OP(<=)
177 IIUT_DECL_EXPRESSION_OP(>)
178 IIUT_DECL_EXPRESSION_OP(>=)
179 IIUT_DECL_EXPRESSION_OP(&&)
180 IIUT_DECL_EXPRESSION_OP(||)
182 #if IUTEST_HAS_ARITHMETIC_EXPRESSION_DECOMPOSE
183 IIUT_DECL_EXPRESSION_OP_LHS(+)
184 IIUT_DECL_EXPRESSION_OP_LHS(-)
185 IIUT_DECL_EXPRESSION_OP_LHS(*)
186 IIUT_DECL_EXPRESSION_OP_LHS(/)
187 IIUT_DECL_EXPRESSION_OP_LHS(%)
190 #if IUTEST_HAS_BITWISE_EXPRESSION_DECOMPOSE
191 IIUT_DECL_EXPRESSION_OP_LHS(&)
192 IIUT_DECL_EXPRESSION_OP_LHS(|)
193 IIUT_DECL_EXPRESSION_OP_LHS(^)
194 IIUT_DECL_EXPRESSION_OP_LHS(<<)
195 IIUT_DECL_EXPRESSION_OP_LHS(>>)
200 ExpressionLHS<U> OperandResult(
const U& lhs)
const
202 return ExpressionLHS<U>(lhs, m_message);
210 _Myt& operator << (
const U& value)
212 AppendMessage(value);
218 AssertionResult GetResult(
bool expected)
const
220 const bool b = m_lhs ? true :
false;
221 return AssertionResult(b == expected) <<
"expansion: " << m_message;
223 AssertionResult GetResult()
const
225 const bool b = m_lhs ? true :
false;
226 return AssertionResult(b) << m_message;
231 void AppendMessage(
const U& value)
235 m_message += msg.GetString();
242 ::std::string m_message;
245 #undef IIUT_DECL_EXPRESSION_RESULT_OP
246 #undef IIUT_DECL_EXPRESSION_OP
247 #ifdef IIUT_DECL_EXPRESSION_OP_LHS
248 # undef IIUT_DECL_EXPRESSION_OP_LHS
254 class ExpressionDecomposer
257 #if IUTEST_HAS_ARITHMETIC_EXPRESSION_DECOMPOSE
258 #if IUTEST_HAS_RVALUE_REFS
260 ExpressionLHS<T> operator ->*(T&& expr)
262 return ExpressionLHS<T>(::std::forward<T>(expr));
266 ExpressionLHS<const T&> operator ->*(
const T& expr)
268 return ExpressionLHS<const T&>(expr);
273 ExpressionLHS<const T&> operator >>(
const T& expr)
275 return ExpressionLHS<const T&>(expr);
#define IUTEST_CXX_DELETED_FUNCTION
delete function
Definition: iutest_compiler.hpp:445
iutest root namespace
Definition: iutest_charcode.hpp:33
detail::iuStreamMessage Message
Message クラス
Definition: iutest_assertion.hpp:33