2 // Copyright (c) 2012 Artyom Beilis (Tonkikh)
3 // Copyright (c) 2019-2020 Alexander Grund
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_NOWIDE_LIB_TEST_H_INCLUDED
10 #define BOOST_NOWIDE_LIB_TEST_H_INCLUDED
17 #if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
27 #if defined(_MSC_VER) && (_MSC_VER > 1310)
28 // disable message boxes on assert(), abort()
29 ::_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
31 #if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
32 // disable message boxes on iterator debugging violations
33 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
34 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
41 inline boost::nowide::test_monitor& test_mon()
43 static boost::nowide::test_monitor instance;
47 /// Function called when a test failed to be able set a breakpoint for debugging
48 inline void test_failed(const char* expr, const char* file, const int line, const char* function)
50 std::ostringstream ss;
51 ss << "Error " << expr << " at " << file << ':' << line << " in " << function;
52 throw std::runtime_error(ss.str());
55 template<typename T, typename U>
56 inline void test_equal_impl(const T& lhs, const U& rhs, const char* file, const int line, const char* function)
60 std::ostringstream ss;
61 ss << "[" << lhs << "!=" << rhs << "]";
62 test_failed(ss.str().c_str(), file, line, function);
66 #define DISABLE_CONST_EXPR_DETECTED __pragma(warning(push)) __pragma(warning(disable : 4127))
67 #define DISABLE_CONST_EXPR_DETECTED_POP __pragma(warning(pop))
69 #define DISABLE_CONST_EXPR_DETECTED
70 #define DISABLE_CONST_EXPR_DETECTED_POP
79 test_failed(#x, __FILE__, __LINE__, __FUNCTION__); \
80 DISABLE_CONST_EXPR_DETECTED \
81 } while(0) DISABLE_CONST_EXPR_DETECTED_POP
82 #define TEST_EQ(lhs, rhs) \
86 test_equal_impl((lhs), (rhs), __FILE__, __LINE__, __FUNCTION__); \
88 DISABLE_CONST_EXPR_DETECTED \
89 } while(0) DISABLE_CONST_EXPR_DETECTED_POP
91 #ifndef BOOST_NOWIDE_TEST_NO_MAIN
92 // Tests should implement this
93 void test_main(int argc, char** argv, char** env);
95 int main(int argc, char** argv, char** env)
99 test_main(argc, argv, env);
100 } catch(const std::exception& e)
102 std::cerr << "Failed " << e.what() << std::endl;
109 #endif // #ifndef BOOST_NOWIDE_LIB_TEST_H_INCLUDED