diff --git a/test/optional_test_swap.cpp b/test/optional_test_swap.cpp index 53eebc2..b6802b1 100644 --- a/test/optional_test_swap.cpp +++ b/test/optional_test_swap.cpp @@ -1,4 +1,5 @@ // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal. +// Copyright (C) 2015 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -12,15 +13,6 @@ // Revisions: // 12 May 2008 (added more swap tests) // -#include -#include -#include - -#define BOOST_ENABLE_ASSERT_HANDLER - -#include "boost/bind/apply.hpp" // Included just to test proper interaction with boost::apply<> as reported by Daniel Wallin -#include "boost/mpl/bool.hpp" -#include "boost/mpl/bool_fwd.hpp" // For mpl::true_ and mpl::false_ #include "boost/optional/optional.hpp" @@ -28,13 +20,13 @@ #pragma hdrstop #endif -#include "boost/none.hpp" - -#include "boost/test/minimal.hpp" - -#include "optional_test_common.cpp" +#include "boost/core/lightweight_test.hpp" +using boost::optional; +using boost::none; + +#define ARG(T) (static_cast< T const* >(0)) namespace optional_swap_test { @@ -51,7 +43,7 @@ namespace optional_swap_test public: base_class_with_forbidden_assignment & operator=(const base_class_with_forbidden_assignment &) { - BOOST_CHECK(!"The assignment should not be used while swapping!"); + BOOST_TEST(!"The assignment should not be used while swapping!"); throw assignment_exception(); } @@ -79,7 +71,7 @@ namespace optional_swap_test class_whose_default_ctor_should_not_be_used() { - BOOST_CHECK(!"This default constructor should not be used while swapping!"); + BOOST_TEST(!"This default constructor should not be used while swapping!"); throw default_ctor_exception(); } }; @@ -98,7 +90,7 @@ namespace optional_swap_test class_whose_default_ctor_should_be_used(const class_whose_default_ctor_should_be_used &) { - BOOST_CHECK(!"This copy constructor should not be used while swapping!"); + BOOST_TEST(!"This copy constructor should not be used while swapping!"); throw copy_ctor_exception(); } }; @@ -118,7 +110,7 @@ namespace optional_swap_test template_whose_default_ctor_should_be_used(const template_whose_default_ctor_should_be_used &) { - BOOST_CHECK(!"This copy constructor should not be used while swapping!"); + BOOST_TEST(!"This copy constructor should not be used while swapping!"); throw copy_ctor_exception(); } }; @@ -135,13 +127,13 @@ namespace optional_swap_test class_whose_explicit_ctor_should_be_used() { - BOOST_CHECK(!"This default constructor should not be used while swapping!"); + BOOST_TEST(!"This default constructor should not be used while swapping!"); throw default_ctor_exception(); } class_whose_explicit_ctor_should_be_used(const class_whose_explicit_ctor_should_be_used &) { - BOOST_CHECK(!"This copy constructor should not be used while swapping!"); + BOOST_TEST(!"This copy constructor should not be used while swapping!"); throw copy_ctor_exception(); } }; @@ -279,27 +271,27 @@ void test_swap_function( T const* ) // Self-swap should not have any effect. swap(obj1, obj1); swap(obj2, obj2); - BOOST_CHECK(!obj1); - BOOST_CHECK(!!obj2 && obj2->data == 'a'); + BOOST_TEST(!obj1); + BOOST_TEST(!!obj2 && obj2->data == 'a'); // Call non-member swap. swap(obj1, obj2); // Test if obj1 and obj2 are really swapped. - BOOST_CHECK(!!obj1 && obj1->data == 'a'); - BOOST_CHECK(!obj2); + BOOST_TEST(!!obj1 && obj1->data == 'a'); + BOOST_TEST(!obj2); // Call non-member swap one more time. swap(obj1, obj2); // Test if obj1 and obj2 are swapped back. - BOOST_CHECK(!obj1); - BOOST_CHECK(!!obj2 && obj2->data == 'a'); + BOOST_TEST(!obj1); + BOOST_TEST(!!obj2 && obj2->data == 'a'); } catch(const std::exception &) { // The swap function should not throw, for our test cases. - BOOST_CHECK(!"throw in swap"); + BOOST_TEST(!"throw in swap"); } } @@ -319,26 +311,26 @@ void test_swap_member_function( T const* ) // Self-swap should not have any effect. obj1.swap(obj1); obj2.swap(obj2); - BOOST_CHECK(!obj1); - BOOST_CHECK(!!obj2 && obj2->data == 'a'); + BOOST_TEST(!obj1); + BOOST_TEST(!!obj2 && obj2->data == 'a'); // Call member swap. obj1.swap(obj2); // Test if obj1 and obj2 are really swapped. - BOOST_CHECK(!!obj1 && obj1->data == 'a'); - BOOST_CHECK(!obj2); + BOOST_TEST(!!obj1 && obj1->data == 'a'); + BOOST_TEST(!obj2); // Call member swap one more time. obj1.swap(obj2); // Test if obj1 and obj2 are swapped back. - BOOST_CHECK(!obj1); - BOOST_CHECK(!!obj2 && obj2->data == 'a'); + BOOST_TEST(!obj1); + BOOST_TEST(!!obj2 && obj2->data == 'a'); } catch(const std::exception &) { - BOOST_CHECK(!"throw in swap"); + BOOST_TEST(!"throw in swap"); } } @@ -361,16 +353,8 @@ void test_swap_tweaking() ( test_swap_member_function( ARG(optional_swap_test::template_whose_default_ctor_should_be_used) ) ); } -int test_main( int, char* [] ) +int main() { - try - { - test_swap_tweaking(); - } - catch ( ... ) - { - BOOST_ERROR("Unexpected Exception caught!"); - } - - return 0; + test_swap_tweaking(); + return boost::report_errors(); } diff --git a/test/optional_test_the_compiler.cpp b/test/optional_test_the_compiler.cpp deleted file mode 100644 index dea10cb..0000000 --- a/test/optional_test_the_compiler.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2014 Andrzej Krzemienski. -// -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/lib/optional for documentation. -// -// You are welcome to contact the author at: -// akrzemi1@gmail.com -// -// Revisions: -// -#include -#include -//#include - -#define BOOST_ENABLE_ASSERT_HANDLER - -//#include "boost/bind/apply.hpp" // Included just to test proper interaction with boost::apply<> as reported by Daniel Wallin -#include "boost/mpl/bool.hpp" -#include "boost/mpl/bool_fwd.hpp" // For mpl::true_ and mpl::false_ -#include "boost/static_assert.hpp" - -#include "boost/optional/optional.hpp" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#include "boost/test/minimal.hpp" -#include "optional_test_common.cpp" - - -const int global_i = 0; - -class TestingReferenceBinding -{ -public: - TestingReferenceBinding(const int& ii) - { - BOOST_CHECK(&ii == &global_i); - } - - void operator=(const int& ii) - { - BOOST_CHECK(&ii == &global_i); - } - #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - void operator=(int&&) - { - BOOST_CHECK(false); - } - #endif -}; - -class TestingReferenceBinding2 // same definition as above, I need a different type -{ -public: - TestingReferenceBinding2(const int& ii) - { - BOOST_CHECK(&ii == &global_i); - } - - void operator=(const int& ii) - { - BOOST_CHECK(&ii == &global_i); - } - #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - void operator=(int&&) - { - BOOST_CHECK(false); - } - #endif -}; - - -void test_broken_compiler() -{ -// we are not testing boost::optional here, but the c++ compiler -// if this test fails, optional references will obviously fail too - - const int& iref = global_i; - BOOST_CHECK(&iref == &global_i); - - TestingReferenceBinding ttt = global_i; - ttt = global_i; - - TestingReferenceBinding2 ttt2 = iref; - ttt2 = iref; -} - - -int test_main( int, char* [] ) -{ - try - { - test_broken_compiler(); - } - catch ( ... ) - { - BOOST_ERROR("Unexpected Exception caught!"); - } - - return 0; -} - -