Remove all uses of Boost.Test.

This commit is contained in:
jzmaddock
2015-10-08 10:06:34 +01:00
parent a307fd7077
commit 09e789b4c6
14 changed files with 281 additions and 58 deletions

View File

@ -21,7 +21,7 @@
#include <string.h>
#include <boost/assert.hpp>
#include <boost/regex.h>
#include <boost/detail/lightweight_test.hpp>
#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();

View File

@ -26,6 +26,8 @@
#include <stdlib.h>
#include <boost/regex.h>
#include <wchar.h>
#include <iostream>
#include <iomanip>
#ifndef BOOST_NO_WREGEX

View File

@ -17,7 +17,8 @@
*/
#include <boost/regex.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_main.hpp>
#include "../test_macros.hpp"
#include <boost/array.hpp>
#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 <boost/test/included/test_exec_monitor.hpp>

View File

@ -13,6 +13,9 @@
#include <boost/regex.hpp>
#include <boost/regex/v4/primary_transform.hpp>
#include <assert.h>
#include <boost/detail/lightweight_main.hpp>
#include <iostream>
#include <iomanip>
#ifdef BOOST_INTEL
#pragma warning(disable:1418 981 983 2259)
@ -250,4 +253,3 @@ int cpp_main(int /*argc*/, char * /*argv*/[])
return 0;
}
#include <boost/test/included/prg_exec_monitor.hpp>

View File

@ -10,7 +10,8 @@
*/
#include <boost/regex.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_main.hpp>
#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 <boost/test/included/test_exec_monitor.hpp>

View File

@ -16,7 +16,8 @@
* DESCRIPTION: Test code for a generic object cache.
*/
#include <boost/regex/pending/object_cache.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
#include <boost/detail/lightweight_main.hpp>
#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 <boost/test/included/test_exec_monitor.hpp>

View File

@ -18,13 +18,14 @@
#include <string>
#include <boost/regex.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_main.hpp>
#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 <boost/test/included/test_exec_monitor.hpp>

View File

@ -18,13 +18,14 @@
#include <string>
#include <boost/regex.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_main.hpp>
#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 <boost/test/included/test_exec_monitor.hpp>

View File

@ -19,6 +19,8 @@
#include "test.hpp"
#include "test_locale.hpp"
#include <stdarg.h>
#include <iostream>
#include <iomanip>
#ifdef BOOST_HAS_ICU
#include <unicode/uloc.h>
@ -232,6 +234,6 @@ int main(int argc, char * argv[])
#else
#include <boost/test/included/prg_exec_monitor.hpp>
#include <boost/detail/lightweight_main.hpp>
#endif

View File

@ -15,6 +15,8 @@
#include <boost/scoped_array.hpp>
#include <windows.h>
#endif
#include <iostream>
#include <iomanip>
#ifdef BOOST_MSVC
#pragma warning(disable:4127)

View File

@ -10,6 +10,8 @@
*/
#include "test.hpp"
#include <iostream>
#include <iomanip>
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)\
&& !BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))\

View File

@ -17,16 +17,17 @@
*/
#include <iostream>
#include <iomanip>
#include <boost/regex/pending/static_mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/timer.hpp>
//
// 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;
}

226
test/test_macros.hpp Normal file
View File

@ -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 <limits>
#include <cmath>
#include <typeinfo>
#include <iostream>
#include <iomanip>
#include <boost/detail/lightweight_test.hpp>
#include <boost/current_function.hpp>
#include <boost/static_assert.hpp>
#include <boost/utility/enable_if.hpp>
enum
{
warn_on_fail,
error_on_fail,
abort_on_fail
};
template <class T>
inline int digits_of(const T&)
{
return std::numeric_limits<T>::is_specialized ? std::numeric_limits<T>::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 <class E>
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 <class I, class J>
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

View File

@ -17,10 +17,14 @@
*/
#include <boost/regex/pending/unicode_iterator.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
#include <boost/detail/lightweight_main.hpp>
#include "../test_macros.hpp"
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#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 <boost/test/included/test_exec_monitor.hpp>