diff options
Diffstat (limited to 'libs/optional/test/optional_test_tie.cpp')
-rw-r--r-- | libs/optional/test/optional_test_tie.cpp | 84 |
1 files changed, 47 insertions, 37 deletions
diff --git a/libs/optional/test/optional_test_tie.cpp b/libs/optional/test/optional_test_tie.cpp index c4fc4ed33..b5c5818f1 100644 --- a/libs/optional/test/optional_test_tie.cpp +++ b/libs/optional/test/optional_test_tie.cpp @@ -1,4 +1,5 @@ // Copyright (C) 2003, 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 @@ -8,57 +9,66 @@ // // You are welcome to contact the author at: // fernando_cacciola@hotmail.com -// -#include<iostream> -#include<stdexcept> -#include<string> - -#define BOOST_ENABLE_ASSERT_HANDLER -#include "boost/optional.hpp" -#include "boost/tuple/tuple.hpp" +#include "boost/optional/optional.hpp" #ifdef __BORLANDC__ #pragma hdrstop #endif -#include "boost/test/minimal.hpp" - -#include "optional_test_common.cpp" +#include "boost/core/lightweight_test.hpp" +#include "boost/none.hpp" +#include "boost/tuple/tuple.hpp" -// Test boost::tie() interoperabiliy. -int test_main( int, char* [] ) +struct counting_oracle { - typedef X T ; - - try - { - TRACE( std::endl << BOOST_CURRENT_FUNCTION ); + int val; + counting_oracle() : val() { ++default_ctor_count; } + counting_oracle(int v) : val(v) { ++val_ctor_count; } + counting_oracle(const counting_oracle& rhs) : val(rhs.val) { ++copy_ctor_count; } + counting_oracle& operator=(const counting_oracle& rhs) { val = rhs.val; ++copy_assign_count; return *this; } + ~counting_oracle() { ++dtor_count; } - T z(0); - T a(1); - T b(2); + static int dtor_count; + static int default_ctor_count; + static int val_ctor_count; + static int copy_ctor_count; + static int copy_assign_count; + static int equals_count; - optional<T> oa, ob ; + friend bool operator==(const counting_oracle& lhs, const counting_oracle& rhs) { ++equals_count; return lhs.val == rhs.val; } - // T::T( T const& x ) is used - set_pending_dtor( ARG(T) ) ; - set_pending_copy( ARG(T) ) ; - boost::tie(oa,ob) = std::make_pair(a,b) ; - check_is_not_pending_dtor( ARG(T) ) ; - check_is_not_pending_copy( ARG(T) ) ; - check_initialized(oa); - check_initialized(ob); - check_value(oa,a,z); - check_value(ob,b,z); - - } - catch ( ... ) + static void clear_count() { - BOOST_ERROR("Unexpected Exception caught!"); + dtor_count = default_ctor_count = val_ctor_count = copy_ctor_count = copy_assign_count = equals_count = 0; } +}; + +int counting_oracle::dtor_count = 0; +int counting_oracle::default_ctor_count = 0; +int counting_oracle::val_ctor_count = 0; +int counting_oracle::copy_ctor_count = 0; +int counting_oracle::copy_assign_count = 0; +int counting_oracle::equals_count = 0; + +// Test boost::tie() interoperability. +int main() +{ + const std::pair<counting_oracle, counting_oracle> pair(1, 2); + counting_oracle::clear_count(); + + boost::optional<counting_oracle> o1, o2; + boost::tie(o1, o2) = pair; + + BOOST_TEST(o1); + BOOST_TEST(o2); + BOOST_TEST(*o1 == counting_oracle(1)); + BOOST_TEST(*o2 == counting_oracle(2)); + BOOST_TEST_EQ(2, counting_oracle::copy_ctor_count); + BOOST_TEST_EQ(0, counting_oracle::copy_assign_count); + BOOST_TEST_EQ(0, counting_oracle::default_ctor_count); - return 0; + return boost::report_errors(); } |