diff --git a/test/c_compiler_checks/posix_api_check.cpp b/test/c_compiler_checks/posix_api_check.cpp index 8daae8f2..d3ff326a 100644 --- a/test/c_compiler_checks/posix_api_check.cpp +++ b/test/c_compiler_checks/posix_api_check.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include "../test_macros.hpp" const char* expression = "^"; const char* text = "\n "; @@ -43,7 +43,7 @@ int main() printf("%s", buf); return result; } - BOOST_TEST(re.re_nsub == 0); + BOOST_CHECK(re.re_nsub == 0); matches[0].rm_so = 0; matches[0].rm_eo = strlen(text); result = regexecA(&re, text, 1, matches, REG_NOTBOL | REG_NOTEOL | REG_STARTEND); @@ -55,7 +55,7 @@ int main() regfreeA(&re); return result; } - BOOST_TEST(matches[0].rm_so == matches[0].rm_eo); + BOOST_CHECK(matches[0].rm_so == matches[0].rm_eo); regfreeA(&re); printf("no errors found\n"); return boost::report_errors(); diff --git a/test/c_compiler_checks/wide_posix_api_check.cpp b/test/c_compiler_checks/wide_posix_api_check.cpp index 30172619..5c14cb22 100644 --- a/test/c_compiler_checks/wide_posix_api_check.cpp +++ b/test/c_compiler_checks/wide_posix_api_check.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #ifndef BOOST_NO_WREGEX diff --git a/test/captures/captures_test.cpp b/test/captures/captures_test.cpp index fcfd51f3..e0e3257c 100644 --- a/test/captures/captures_test.cpp +++ b/test/captures/captures_test.cpp @@ -17,7 +17,8 @@ */ #include -#include +#include +#include "../test_macros.hpp" #include #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -50,7 +51,7 @@ void test_captures(const std::string& regx, const std::string& text, T& expected } } -int test_main(int , char* []) +int cpp_main(int , char* []) { typedef const char* pchar; pchar e1[4][5] = @@ -113,4 +114,3 @@ int test_main(int , char* []) return 0; } -#include diff --git a/test/collate_info/collate_info.cpp b/test/collate_info/collate_info.cpp index 021a5498..da96745c 100644 --- a/test/collate_info/collate_info.cpp +++ b/test/collate_info/collate_info.cpp @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #ifdef BOOST_INTEL #pragma warning(disable:1418 981 983 2259) @@ -250,4 +253,3 @@ int cpp_main(int /*argc*/, char * /*argv*/[]) return 0; } -#include diff --git a/test/named_subexpressions/named_subexpressions_test.cpp b/test/named_subexpressions/named_subexpressions_test.cpp index c4c238ae..a92c02b8 100644 --- a/test/named_subexpressions/named_subexpressions_test.cpp +++ b/test/named_subexpressions/named_subexpressions_test.cpp @@ -10,7 +10,8 @@ */ #include -#include +#include +#include "../test_macros.hpp" #ifdef BOOST_INTEL #pragma warning(disable:1418 981 983 383) @@ -102,11 +103,10 @@ void test_named_subexpressions(charT) } } -int test_main( int , char* [] ) +int cpp_main( int , char* [] ) { test_named_subexpressions(char(0)); test_named_subexpressions(wchar_t(0)); return 0; } -#include diff --git a/test/object_cache/object_cache_test.cpp b/test/object_cache/object_cache_test.cpp index 40f55db4..50d883be 100644 --- a/test/object_cache/object_cache_test.cpp +++ b/test/object_cache/object_cache_test.cpp @@ -16,7 +16,8 @@ * DESCRIPTION: Test code for a generic object cache. */ #include -#include +#include +#include "../test_macros.hpp" class test_object { @@ -43,7 +44,7 @@ int test_object::s_count = 0; static const int max_cache_size = 5; -int test_main(int /*argc*/, char * /*argv*/[]) +int cpp_main(int /*argc*/, char * /*argv*/[]) { int i; for(i = 0; i < 20; ++i) @@ -73,6 +74,4 @@ int test_main(int /*argc*/, char * /*argv*/[]) return 0; } -#include - diff --git a/test/pathology/bad_expression_test.cpp b/test/pathology/bad_expression_test.cpp index 7354d584..bba20cda 100644 --- a/test/pathology/bad_expression_test.cpp +++ b/test/pathology/bad_expression_test.cpp @@ -18,13 +18,14 @@ #include #include -#include +#include +#include "../test_macros.hpp" #ifdef BOOST_INTEL #pragma warning(disable:1418 981 983 383) #endif -int test_main( int , char* [] ) +int cpp_main( int , char* [] ) { std::string bad_text(1024, ' '); std::string good_text(200, ' '); @@ -57,5 +58,3 @@ int test_main( int , char* [] ) return 0; } -#include - diff --git a/test/pathology/recursion_test.cpp b/test/pathology/recursion_test.cpp index ec187338..46b86f41 100644 --- a/test/pathology/recursion_test.cpp +++ b/test/pathology/recursion_test.cpp @@ -18,13 +18,14 @@ #include #include -#include +#include +#include "../test_macros.hpp" #ifdef BOOST_INTEL #pragma warning(disable:1418 981 983 383) #endif -int test_main( int , char* [] ) +int cpp_main( int , char* [] ) { // this regex will recurse twice for each whitespace character matched: boost::regex e("([[:space:]]|.)+"); @@ -62,4 +63,3 @@ int test_main( int , char* [] ) return 0; } -#include diff --git a/test/regress/main.cpp b/test/regress/main.cpp index d71b9658..e3e3dd7f 100644 --- a/test/regress/main.cpp +++ b/test/regress/main.cpp @@ -19,6 +19,8 @@ #include "test.hpp" #include "test_locale.hpp" #include +#include +#include #ifdef BOOST_HAS_ICU #include @@ -232,6 +234,6 @@ int main(int argc, char * argv[]) #else -#include +#include #endif diff --git a/test/regress/test_locale.cpp b/test/regress/test_locale.cpp index 20fbc004..f1a6fa21 100644 --- a/test/regress/test_locale.cpp +++ b/test/regress/test_locale.cpp @@ -15,6 +15,8 @@ #include #include #endif +#include +#include #ifdef BOOST_MSVC #pragma warning(disable:4127) diff --git a/test/regress/test_operators.cpp b/test/regress/test_operators.cpp index e9a947c3..2f4a017b 100644 --- a/test/regress/test_operators.cpp +++ b/test/regress/test_operators.cpp @@ -10,6 +10,8 @@ */ #include "test.hpp" +#include +#include #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)\ && !BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))\ diff --git a/test/static_mutex/static_mutex_test.cpp b/test/static_mutex/static_mutex_test.cpp index b31eefac..871a1d90 100644 --- a/test/static_mutex/static_mutex_test.cpp +++ b/test/static_mutex/static_mutex_test.cpp @@ -17,16 +17,17 @@ */ #include +#include #include #include #include // // we cannot use the regular Boost.Test in here: it is not thread safe -// and calls to BOOST_TEST will eventually crash on some compilers +// and calls to BOOST_CHECK will eventually crash on some compilers // (Borland certainly) due to race conditions inside the Boost.Test lib. // -#define BOOST_TEST(pred) if(!(pred)) failed_test(__FILE__, __LINE__, BOOST_STRINGIZE(pred)); +#define BOOST_CHECK(pred) if(!(pred)) failed_test(__FILE__, __LINE__, BOOST_STRINGIZE(pred)); int total_failures = 0; void failed_test(const char* file, int line, const char* pred) @@ -62,11 +63,11 @@ bool t1() static int data = 10000; boost::static_mutex::scoped_lock guard(mut); - BOOST_TEST(++has_lock == 1); - BOOST_TEST(guard.locked()); - BOOST_TEST(guard); + BOOST_CHECK(++has_lock == 1); + BOOST_CHECK(guard.locked()); + BOOST_CHECK(guard); bool result = (--data > 0) ? true : false; - BOOST_TEST(--has_lock == 0); + BOOST_CHECK(--has_lock == 0); return result; } @@ -77,17 +78,17 @@ bool t2() static int data = 10000; boost::static_mutex::scoped_lock guard(mut, false); - BOOST_TEST(0 == guard.locked()); - BOOST_TEST(!guard); + BOOST_CHECK(0 == guard.locked()); + BOOST_CHECK(!guard); guard.lock(); - BOOST_TEST(++has_lock == 1); - BOOST_TEST(guard.locked()); - BOOST_TEST(guard); + BOOST_CHECK(++has_lock == 1); + BOOST_CHECK(guard.locked()); + BOOST_CHECK(guard); bool result = (--data > 0) ? true : false; - BOOST_TEST(--has_lock == 0); + BOOST_CHECK(--has_lock == 0); guard.unlock(); - BOOST_TEST(0 == guard.locked()); - BOOST_TEST(!guard); + BOOST_CHECK(0 == guard.locked()); + BOOST_CHECK(!guard); return result; } @@ -98,11 +99,11 @@ bool t3() static int data = 10000; boost::static_mutex::scoped_lock guard(mut); - BOOST_TEST(++has_lock == 1); - BOOST_TEST(guard.locked()); - BOOST_TEST(guard); + BOOST_CHECK(++has_lock == 1); + BOOST_CHECK(guard.locked()); + BOOST_CHECK(guard); bool result = (--data > 0) ? true : false; - BOOST_TEST(--has_lock == 0); + BOOST_CHECK(--has_lock == 0); return result; } diff --git a/test/test_macros.hpp b/test/test_macros.hpp new file mode 100644 index 00000000..a3ccacb7 --- /dev/null +++ b/test/test_macros.hpp @@ -0,0 +1,226 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 John Maddock. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_ +// + +#ifndef BOOST_MULTIPRECISION_TEST_HPP +#define BOOST_MULTIPRECISION_TEST_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +enum +{ + warn_on_fail, + error_on_fail, + abort_on_fail +}; + +template +inline int digits_of(const T&) +{ + return std::numeric_limits::is_specialized ? std::numeric_limits::digits : 18; +} + + +inline std::ostream& report_where(const char* file, int line, const char* function) +{ + if(function) + BOOST_LIGHTWEIGHT_TEST_OSTREAM << "In function: "<< function << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM << file << ":" << line; + return BOOST_LIGHTWEIGHT_TEST_OSTREAM; +} + +#define BOOST_MP_REPORT_WHERE report_where(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) + +inline void report_severity(int severity) +{ + if(severity == error_on_fail) + ++boost::detail::test_errors(); + else if(severity == abort_on_fail) + { + ++boost::detail::test_errors(); + abort(); + } +} + +#define BOOST_MP_REPORT_SEVERITY(severity) report_severity(severity) + +template +void report_unexpected_exception(const E& e, int severity, const char* file, int line, const char* function) +{ + report_where(file, line, function) << " Unexpected exception of type " << typeid(e).name() << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Errot message was: " << e.what() << std::endl; + BOOST_MP_REPORT_SEVERITY(severity); +} + +#define BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) \ + catch(const std::exception& e) \ + { report_unexpected_exception(e, severity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); }\ + catch(...)\ + { BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Exception of unknown type was thrown" << std::endl; report_severity(severity); } + + +#define BOOST_CHECK_IMP(x, severity)\ + try{ if(x){}else{\ + BOOST_MP_REPORT_WHERE << " Failed predicate: " << BOOST_STRINGIZE(x) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_CHECK(x) BOOST_CHECK_IMP(x, error_on_fail) +#define BOOST_WARN(x) BOOST_CHECK_IMP(x, warn_on_fail) +#define BOOST_REQUIRE(x) BOOST_CHECK_IMP(x, abort_on_fail) + +#define BOOST_EQUAL_IMP(x, y, severity)\ + try{ if(!((x) == (y))){\ + BOOST_MP_REPORT_WHERE << " Failed check for equality: \n" \ + << std::setprecision(digits_of(x)) << std::scientific\ + << "Value of LHS was: " << (x) << "\n"\ + << "Value of RHS was: " << (y) << "\n"\ + << std::setprecision(3) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_NE_IMP(x, y, severity)\ + try{ if(!(x != y)){\ + BOOST_MP_REPORT_WHERE << " Failed check for non-equality: \n" \ + << std::setprecision(digits_of(x)) << std::scientific\ + << "Value of LHS was: " << x << "\n"\ + << "Value of RHS was: " << y << "\n"\ + << std::setprecision(3) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_LT_IMP(x, y, severity)\ + try{ if(!(x < y)){\ + BOOST_MP_REPORT_WHERE << " Failed check for less than: \n" \ + << std::setprecision(digits_of(x)) << std::scientific\ + << "Value of LHS was: " << x << "\n"\ + << "Value of RHS was: " << y << "\n"\ + << std::setprecision(3) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_GT_IMP(x, y, severity)\ + try{ if(!(x > y)){\ + BOOST_MP_REPORT_WHERE << " Failed check for greater than: \n" \ + << std::setprecision(digits_of(x)) << std::scientific\ + << "Value of LHS was: " << x << "\n"\ + << "Value of RHS was: " << y << "\n"\ + << std::setprecision(3) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_LE_IMP(x, y, severity)\ + try{ if(!(x <= y)){\ + BOOST_MP_REPORT_WHERE << " Failed check for less-than-equal-to: \n" \ + << std::setprecision(digits_of(x)) << std::scientific\ + << "Value of LHS was: " << x << "\n"\ + << "Value of RHS was: " << y << "\n"\ + << std::setprecision(3) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_GE_IMP(x, y, severity)\ + try{ if(!(x >= y)){\ + BOOST_MP_REPORT_WHERE << " Failed check for greater-than-equal-to \n" \ + << std::setprecision(digits_of(x)) << std::scientific\ + << "Value of LHS was: " << x << "\n"\ + << "Value of RHS was: " << y << "\n"\ + << std::setprecision(3) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +#define BOOST_MT_CHECK_THROW_IMP(x, E, severity)\ + try{ \ + x;\ + BOOST_MP_REPORT_WHERE << " Expected exception not thrown in expression " << BOOST_STRINGIZE(x) << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + catch(const E&){}\ + BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + +template +bool check_equal_collections(I a, I b, J x, J y) +{ + int i = 0; + while(a != b) + { + if(x == y) + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM << " Unexpected end of second sequence" << std::endl; + return false; + } + if(*a != *x) + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Error occured in position " << i << " of the collection." << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM << "First value was " << std::setprecision(digits_of(x)) << std::scientific << *a << std::endl; + BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Second value was " << std::setprecision(digits_of(x)) << std::scientific << *x << std::endl; + return false; + } + ++a; + ++x; + } + return true; +} + +#define BOOST_MT_CHECK_EQ_COLLECTIONS(a, b, x, y, severity)\ + try{ \ + if(!check_equal_collections(a, b, x, y))\ + {\ + BOOST_MP_REPORT_WHERE << " Collections were not equal" << std::endl;\ + BOOST_MP_REPORT_SEVERITY(severity);\ + }\ + }\ + BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) + + +#define BOOST_CHECK_EQUAL(x, y) BOOST_EQUAL_IMP(x, y, error_on_fail) +#define BOOST_WARN_EQUAL(x, y) BOOST_EQUAL_IMP(x, y, warn_on_fail) +#define BOOST_REQUIRE_EQUAL(x, y) BOOST_EQUAL_IMP(x, y, abort_on_fail) + +#define BOOST_CHECK_NE(x, y) BOOST_NE_IMP(x, y, error_on_fail) +#define BOOST_WARN_NE(x, y) BOOST_NE_IMP(x, y, warn_on_fail) +#define BOOST_REQUIRE_NE(x, y) BOOST_NE_IMP(x, y, abort_on_fail) + +#define BOOST_CHECK_LT(x, y) BOOST_LT_IMP(x, y, error_on_fail) +#define BOOST_WARN_LT(x, y) BOOST_LT_IMP(x, y, warn_on_fail) +#define BOOST_REQUIRE_LT(x, y) BOOST_LT_IMP(x, y, abort_on_fail) + +#define BOOST_CHECK_GT(x, y) BOOST_GT_IMP(x, y, error_on_fail) +#define BOOST_WARN_GT(x, y) BOOST_GT_IMP(x, y, warn_on_fail) +#define BOOST_REQUIRE_GT(x, y) BOOST_GT_IMP(x, y, abort_on_fail) + +#define BOOST_CHECK_LE(x, y) BOOST_LE_IMP(x, y, error_on_fail) +#define BOOST_WARN_LE(x, y) BOOST_LE_IMP(x, y, warn_on_fail) +#define BOOST_REQUIRE_LE(x, y) BOOST_LE_IMP(x, y, abort_on_fail) + +#define BOOST_CHECK_GE(x, y) BOOST_GE_IMP(x, y, error_on_fail) +#define BOOST_WARN_GE(x, y) BOOST_GE_IMP(x, y, warn_on_fail) +#define BOOST_REQUIRE_GE(x, y) BOOST_GE_IMP(x, y, abort_on_fail) + +#define BOOST_CHECK_THROW(x, E) BOOST_MT_CHECK_THROW_IMP(x, E, error_on_fail) +#define BOOST_WARN_THROW(x, E) BOOST_MT_CHECK_THROW_IMP(x, E, warn_on_fail) +#define BOOST_REQUIRE_THROW(x, E) BOOST_MT_CHECK_THROW_IMP(x, E, abort_on_fail) + +#define BOOST_CHECK_EQUAL_COLLECTIONS(a, b, x, y) BOOST_MT_CHECK_EQ_COLLECTIONS(a, b, x, y, error_on_fail) +#define BOOST_WARN_EQUAL_COLLECTIONS(a, b, x, y) BOOST_MT_CHECK_EQ_COLLECTIONS(a, b, x, y, warn_on_fail) +#define BOOST_REQUIRE_EQUAL_COLLECTIONS(a, b, x, y) BOOST_MT_CHECK_EQ_COLLECTIONS(a, b, x, y, abort_on_fail) + +#endif diff --git a/test/unicode/unicode_iterator_test.cpp b/test/unicode/unicode_iterator_test.cpp index 206b748b..243ef742 100644 --- a/test/unicode/unicode_iterator_test.cpp +++ b/test/unicode/unicode_iterator_test.cpp @@ -17,10 +17,14 @@ */ #include -#include +#include +#include "../test_macros.hpp" #include #include #include +#include +#include +#include #if !defined(TEST_UTF8) && !defined(TEST_UTF16) # define TEST_UTF8 @@ -294,27 +298,12 @@ void test(const std::vector< ::boost::uint32_t>& v) #endif } -int test_main( int, char* [] ) +int cpp_main( int, char* [] ) { // test specific value points from the standard: spot_checks(); // now test a bunch of values for self-consistency and round-tripping: std::vector< ::boost::uint32_t> v; - // start with boundary conditions: - /* - v.push_back(0); - v.push_back(0xD7FF); - v.push_back(0xE000); - v.push_back(0xFFFF); - v.push_back(0x10000); - v.push_back(0x10FFFF); - v.push_back(0x80u); - v.push_back(0x80u - 1); - v.push_back(0x800u); - v.push_back(0x800u - 1); - v.push_back(0x10000u); - v.push_back(0x10000u - 1); - */ for(unsigned i = 0; i < 0xD800; ++i) v.push_back(i); for(unsigned i = 0xDFFF + 1; i < 0x10FFFF; ++i) @@ -323,4 +312,3 @@ int test_main( int, char* [] ) return 0; } -#include