From 67c7e21b4bef4d884dca1214984e77160f3d0850 Mon Sep 17 00:00:00 2001 From: Andrzej Krzemienski Date: Thu, 15 Jan 2015 22:46:34 +0100 Subject: [PATCH] Migration to lightweight_test continues --- test/Jamfile.v2 | 2 +- test/optional_test_inplace.cpp | 84 ---------------- test/optional_test_inplace_factory.cpp | 104 ++++++++++++++++++++ test/optional_test_minimum_requirements.cpp | 67 ++++--------- test/optional_test_tie.cpp | 83 ++++++++-------- 5 files changed, 167 insertions(+), 173 deletions(-) delete mode 100644 test/optional_test_inplace.cpp create mode 100644 test/optional_test_inplace_factory.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 952c75d..63045c5 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -24,7 +24,7 @@ import testing ; [ run optional_test_ref_assign_const_int.cpp ] [ run optional_test_ref_converting_ctor.cpp ] [ run optional_test_ref_portable_minimum.cpp ] - [ run optional_test_inplace.cpp ] + [ run optional_test_inplace_factory.cpp ] [ run optional_test_io.cpp ] [ run optional_test_move.cpp ] [ run optional_test_noexcept_move.cpp ] diff --git a/test/optional_test_inplace.cpp b/test/optional_test_inplace.cpp deleted file mode 100644 index b0e8285..0000000 --- a/test/optional_test_inplace.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2003, Fernando Luis Cacciola Carballal. -// -// 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: -// fernando_cacciola@hotmail.com -// -#include -#include -#include - -#define BOOST_ENABLE_ASSERT_HANDLER - -#include "boost/optional/optional.hpp" - -#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT -#include "boost/utility/in_place_factory.hpp" -#include "boost/utility/typed_in_place_factory.hpp" -#endif - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#include "boost/test/minimal.hpp" - -#include "optional_test_common.cpp" - -#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT -struct A -{ - A ( double a0, std::string a1 ) : m_a0(a0), m_a1(a1) {} - - friend bool operator == ( A const& x, A const& y ) - { return x.m_a0 == y.m_a0 && x.m_a1 == y.m_a1 ; } - - double m_a0 ; - std::string m_a1 ; -} ; - -int test_main( int, char* [] ) -{ - double a00 = 3.14, a10 = 6.02e-23; - std::string a01("pi"), a11("mol"); - - A a0(a00,a01); - A a1(a10,a11); - - boost::optional opt1(a0); - - boost::optional opt2 ( boost::in_place(a00,a01) ) ; - - boost::optional opt3 ( boost::in_place(a00,a01) ) ; - - BOOST_CHECK( opt1 == opt2 ) ; - BOOST_CHECK( opt2 == opt2 ) ; - BOOST_CHECK( *opt2 == a0 ) ; - -#ifndef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION - - opt2 = boost::in_place(a10,a11); - BOOST_CHECK( *opt2 == a1 ) ; - - opt3 = boost::in_place(a10,a11); - BOOST_CHECK( *opt3 == a1 ) ; - -#endif - - return 0; -} -#else -int test_main( int, char* [] ) -{ - // If in-place factories are not supported there is nothing to test - return 0 ; -} -#endif - - - diff --git a/test/optional_test_inplace_factory.cpp b/test/optional_test_inplace_factory.cpp new file mode 100644 index 0000000..1e852f0 --- /dev/null +++ b/test/optional_test_inplace_factory.cpp @@ -0,0 +1,104 @@ +// 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 +// 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: +// fernando_cacciola@hotmail.com + +#include +#include "boost/optional/optional.hpp" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT +#include "boost/utility/in_place_factory.hpp" +#include "boost/utility/typed_in_place_factory.hpp" +#endif + +#include "boost/core/lightweight_test.hpp" +#include "boost/none.hpp" + +struct Guard +{ + double num; + std::string str; + Guard() : num() {} + Guard(double num_, std::string str_) : num(num_), str(str_) {} + + friend bool operator==(const Guard& lhs, const Guard& rhs) { return lhs.num == rhs.num && lhs.str == rhs.str; } + friend bool operator!=(const Guard& lhs, const Guard& rhs) { return !(lhs == rhs); } + +private: + Guard(const Guard&); + Guard& operator=(const Guard&); +}; + +void test_ctor() +{ +#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT + Guard g0, g1(1.0, "one"), g2(2.0, "two"); + + boost::optional og0 ( boost::in_place() ); + boost::optional og1 ( boost::in_place(1.0, "one") ); + boost::optional og1_( boost::in_place(1.0, "one") ); + boost::optional og2 ( boost::in_place(2.0, "two") ); + + BOOST_TEST(og0); + BOOST_TEST(og1); + BOOST_TEST(og1_); + BOOST_TEST(og2); + + BOOST_TEST(*og0 == g0); + BOOST_TEST(*og1 == g1); + BOOST_TEST(*og1_ == g1); + BOOST_TEST(*og2 == g2); + + BOOST_TEST(og1_ == og1); + BOOST_TEST(og1_ != og2); + BOOST_TEST(og1_ != og0); +#endif +} + +void test_assign() +{ +#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT +#ifndef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION + Guard g0, g1(1.0, "one"), g2(2.0, "two"); + + boost::optional og0, og1, og1_, og2; + + og0 = boost::in_place(); + og1 = boost::in_place(1.0, "one"); + og1_ = boost::in_place(1.0, "one"); + og2 = boost::in_place(2.0, "two"); + + BOOST_TEST(og0); + BOOST_TEST(og1); + BOOST_TEST(og1_); + BOOST_TEST(og2); + + BOOST_TEST(*og0 == g0); + BOOST_TEST(*og1 == g1); + BOOST_TEST(*og1_ == g1); + BOOST_TEST(*og2 == g2); + + BOOST_TEST(og1_ == og1); + BOOST_TEST(og1_ != og2); + BOOST_TEST(og1_ != og0); +#endif +#endif +} + +int main() +{ + test_ctor(); + test_assign(); + return boost::report_errors(); +} \ No newline at end of file diff --git a/test/optional_test_minimum_requirements.cpp b/test/optional_test_minimum_requirements.cpp index 5649d69..77ef1fc 100644 --- a/test/optional_test_minimum_requirements.cpp +++ b/test/optional_test_minimum_requirements.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Andrzej Krzemienski. +// Copyright (C) 2014-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,19 +8,6 @@ // // 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" @@ -28,12 +15,9 @@ #pragma hdrstop #endif +#include "boost/core/lightweight_test.hpp" #include "boost/none.hpp" -#include "boost/test/minimal.hpp" - -#include "optional_test_common.cpp" - class NonConstructible { private: @@ -46,16 +30,10 @@ private: void test_non_constructible() { - optional o; - BOOST_CHECK(!o); - BOOST_CHECK(o == boost::none); - try { - o.value(); - BOOST_CHECK(false); - } - catch(...) { - BOOST_CHECK(true); - } + boost::optional o; + BOOST_TEST(!o); + BOOST_TEST(o == boost::none); + BOOST_TEST_THROWS(o.value(), boost::bad_optional_access); } class Guard @@ -72,33 +50,26 @@ private: void test_guard() { - optional o; + boost::optional o; o.emplace(1); - BOOST_CHECK(o); + BOOST_TEST(o); + BOOST_TEST(o != boost::none); } void test_non_assignable() { - optional o; + boost::optional o; o.emplace("cat"); - BOOST_CHECK(o); - BOOST_CHECK(*o == "cat"); + BOOST_TEST(o); + BOOST_TEST(o != boost::none); + BOOST_TEST_EQ(*o, std::string("cat")); } -int test_main( int, char* [] ) +int main() { - try - { - test_non_constructible(); - test_guard(); - test_non_assignable(); - } - catch ( ... ) - { - BOOST_ERROR("Unexpected Exception caught!"); - } - - return 0; -} - + test_non_constructible(); + test_guard(); + test_non_assignable(); + return boost::report_errors(); +} \ No newline at end of file diff --git a/test/optional_test_tie.cpp b/test/optional_test_tie.cpp index c4fc4ed..f77e74b 100644 --- a/test/optional_test_tie.cpp +++ b/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,59 @@ // // You are welcome to contact the author at: // fernando_cacciola@hotmail.com -// -#include -#include -#include -#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 "boost/core/lightweight_test.hpp" +#include "boost/none.hpp" +#include "boost/tuple/tuple.hpp" -#include "optional_test_common.cpp" - -// 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 oa, ob ; - - // 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 ( ... ) - { - BOOST_ERROR("Unexpected Exception caught!"); - } + friend bool operator==(const counting_oracle& lhs, const counting_oracle& rhs) { ++equals_count; return lhs.val == rhs.val; } +}; - return 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 pair(1, 2); + boost::optional 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 boost::report_errors(); }