aboutsummaryrefslogtreecommitdiff
path: root/framework/Asserts.h
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Asserts.h')
-rw-r--r--framework/Asserts.h121
1 files changed, 58 insertions, 63 deletions
diff --git a/framework/Asserts.h b/framework/Asserts.h
index a1424372e9..fd745d10e0 100644
--- a/framework/Asserts.h
+++ b/framework/Asserts.h
@@ -32,6 +32,8 @@
namespace arm_compute
{
+namespace test
+{
namespace framework
{
namespace detail
@@ -53,85 +55,78 @@ inline T &&make_printable(T &&value)
{
return value;
}
-} // namespace detail
-} // namespace framework
-} // namespace arm_compute
-template <typename T>
-void ARM_COMPUTE_ASSERT_EQUAL(T &&x, T &&y)
-{
- if(x != y)
- {
- std::stringstream msg;
- msg << "Assertion "
- << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " == "
- << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed.";
- throw arm_compute::test::framework::TestError(msg.str());
+#define ARM_COMPUTE_TEST_INFO(INFO) \
+ { \
+ std::stringstream info; \
+ info << INFO; \
+ arm_compute::test::framework::Framework::get().add_test_info(info.str()); \
}
-}
-template <typename T>
-void ARM_COMPUTE_EXPECT_EQUAL(T &&x, T &&y)
-{
- if(x != y)
- {
- std::stringstream msg;
- msg << "Expectation "
- << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " == "
- << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed.";
- arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str());
+#define ARM_COMPUTE_TEST_COMP_FACTORY(SEVERITY, SEVERITY_NAME, COMP, COMP_NAME, ERROR_CALL) \
+ template <typename T, typename U> \
+ void ARM_COMPUTE_##SEVERITY##_##COMP_NAME##_IMPL(T &&x, U &&y, const std::string &x_str, const std::string &y_str) \
+ { \
+ if(!(x COMP y)) \
+ { \
+ std::stringstream msg; \
+ msg << #SEVERITY_NAME " '" << x_str << " " #COMP " " << y_str << "' failed. [" \
+ << std::boolalpha << arm_compute::test::framework::detail::make_printable(x) \
+ << " " #COMP " " \
+ << std::boolalpha << arm_compute::test::framework::detail::make_printable(y) \
+ << "]\n"; \
+ arm_compute::test::framework::Framework::get().print_test_info(msg); \
+ ERROR_CALL \
+ } \
+ arm_compute::test::framework::Framework::get().clear_test_info(); \
}
-}
-template <typename T>
-void ARM_COMPUTE_ASSERT_NOT_EQUAL(T &&x, T &&y)
-{
- if(x == y)
- {
- std::stringstream msg;
- msg << "Assertion "
- << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " != "
- << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed.";
- throw arm_compute::test::framework::TestError(msg.str());
- }
-}
+ARM_COMPUTE_TEST_COMP_FACTORY(EXPECT, Expectation, ==, EQUAL, arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str());)
+ARM_COMPUTE_TEST_COMP_FACTORY(EXPECT, Expectation, !=, NOT_EQUAL, arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str());)
+ARM_COMPUTE_TEST_COMP_FACTORY(ASSERT, Assertion, ==, EQUAL, throw arm_compute::test::framework::TestError(msg.str());)
+ARM_COMPUTE_TEST_COMP_FACTORY(ASSERT, Assertion, !=, NOT_EQUAL, throw arm_compute::test::framework::TestError(msg.str());)
-template <typename T>
-void ARM_COMPUTE_EXPECT_NOT_EQUAL(T &&x, T &&y)
-{
- if(x == y)
- {
- std::stringstream msg;
- msg << "Expectation "
- << std::boolalpha << arm_compute::framework::detail::make_printable(x) << " != "
- << std::boolalpha << arm_compute::framework::detail::make_printable(y) << " failed.";
- arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str());
- }
-}
+#define ARM_COMPUTE_ASSERT_NOT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_ASSERT_NOT_EQUAL_IMPL(X, Y, #X, #Y)
-#define ARM_COMPUTE_ASSERT(X, MSG) \
- do \
- { \
- const auto &x = X; \
- if(!x) \
- { \
- std::stringstream msg; \
- msg << "Failed assertion: " << #X << "\n" \
- << MSG; \
- throw arm_compute::test::framework::TestError(msg.str()); \
- } \
+#define ARM_COMPUTE_ASSERT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_ASSERT_EQUAL_IMPL(X, Y, #X, #Y)
+
+#define ARM_COMPUTE_EXPECT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_EXPECT_EQUAL_IMPL(X, Y, #X, #Y)
+
+#define ARM_COMPUTE_EXPECT_NOT_EQUAL(X, Y) \
+ arm_compute::test::framework::detail::ARM_COMPUTE_EXPECT_NOT_EQUAL_IMPL(X, Y, #X, #Y)
+
+#define ARM_COMPUTE_ASSERT(X) \
+ do \
+ { \
+ const auto &x = X; \
+ if(!x) \
+ { \
+ std::stringstream msg; \
+ msg << "Assertion '" #X "' failed.\n"; \
+ arm_compute::test::framework::Framework::get().print_test_info(msg); \
+ throw arm_compute::test::framework::TestError(msg.str()); \
+ } \
+ arm_compute::test::framework::Framework::get().clear_test_info(); \
} while(false)
-#define ARM_COMPUTE_EXPECT(X, MSG) \
+#define ARM_COMPUTE_EXPECT(X) \
do \
{ \
const auto &x = X; \
if(!x) \
{ \
std::stringstream msg; \
- msg << "Failed assertion: " << #X << "\n" \
- << MSG; \
+ msg << "Expectation '" #X "' failed.\n"; \
+ arm_compute::test::framework::Framework::get().print_test_info(msg); \
arm_compute::test::framework::Framework::get().log_failed_expectation(msg.str()); \
} \
+ arm_compute::test::framework::Framework::get().clear_test_info(); \
} while(false)
+} // namespace detail
+} // namespace framework
+} // namespace test
+} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_FRAMEWORK_ASSERTS */