Migration to lightweight_test continues

This commit is contained in:
Andrzej Krzemienski
2015-01-15 22:46:34 +01:00
parent a8a6be013f
commit 67c7e21b4b
5 changed files with 167 additions and 173 deletions

View File

@ -24,7 +24,7 @@ import testing ;
[ run optional_test_ref_assign_const_int.cpp ] [ run optional_test_ref_assign_const_int.cpp ]
[ run optional_test_ref_converting_ctor.cpp ] [ run optional_test_ref_converting_ctor.cpp ]
[ run optional_test_ref_portable_minimum.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_io.cpp ]
[ run optional_test_move.cpp ] [ run optional_test_move.cpp ]
[ run optional_test_noexcept_move.cpp ] [ run optional_test_noexcept_move.cpp ]

View File

@ -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<iostream>
#include<stdexcept>
#include<string>
#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<A> opt1(a0);
boost::optional<A> opt2 ( boost::in_place(a00,a01) ) ;
boost::optional<A> opt3 ( boost::in_place<A>(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<A>(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

View File

@ -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<string>
#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<Guard> og0 ( boost::in_place() );
boost::optional<Guard> og1 ( boost::in_place(1.0, "one") );
boost::optional<Guard> og1_( boost::in_place(1.0, "one") );
boost::optional<Guard> og2 ( boost::in_place<Guard>(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<Guard> 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<Guard>(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();
}

View File

@ -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 // Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // 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: // You are welcome to contact the author at:
// akrzemi1@gmail.com // akrzemi1@gmail.com
//
// Revisions:
//
#include<iostream>
#include<stdexcept>
#include<string>
#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" #include "boost/optional/optional.hpp"
@ -28,12 +15,9 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
#include "boost/core/lightweight_test.hpp"
#include "boost/none.hpp" #include "boost/none.hpp"
#include "boost/test/minimal.hpp"
#include "optional_test_common.cpp"
class NonConstructible class NonConstructible
{ {
private: private:
@ -46,16 +30,10 @@ private:
void test_non_constructible() void test_non_constructible()
{ {
optional<NonConstructible> o; boost::optional<NonConstructible> o;
BOOST_CHECK(!o); BOOST_TEST(!o);
BOOST_CHECK(o == boost::none); BOOST_TEST(o == boost::none);
try { BOOST_TEST_THROWS(o.value(), boost::bad_optional_access);
o.value();
BOOST_CHECK(false);
}
catch(...) {
BOOST_CHECK(true);
}
} }
class Guard class Guard
@ -72,33 +50,26 @@ private:
void test_guard() void test_guard()
{ {
optional<Guard> o; boost::optional<Guard> o;
o.emplace(1); o.emplace(1);
BOOST_CHECK(o); BOOST_TEST(o);
BOOST_TEST(o != boost::none);
} }
void test_non_assignable() void test_non_assignable()
{ {
optional<const std::string> o; boost::optional<const std::string> o;
o.emplace("cat"); o.emplace("cat");
BOOST_CHECK(o); BOOST_TEST(o);
BOOST_CHECK(*o == "cat"); BOOST_TEST(o != boost::none);
BOOST_TEST_EQ(*o, std::string("cat"));
} }
int test_main( int, char* [] ) int main()
{ {
try
{
test_non_constructible(); test_non_constructible();
test_guard(); test_guard();
test_non_assignable(); test_non_assignable();
}
catch ( ... )
{
BOOST_ERROR("Unexpected Exception caught!");
}
return 0; return boost::report_errors();
} }

View File

@ -1,4 +1,5 @@
// Copyright (C) 2003, Fernando Luis Cacciola Carballal. // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
// Copyright (C) 2015 Andrzej Krzemienski.
// //
// Use, modification, and distribution is subject to the Boost Software // Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // 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: // You are welcome to contact the author at:
// fernando_cacciola@hotmail.com // fernando_cacciola@hotmail.com
//
#include<iostream>
#include<stdexcept>
#include<string>
#define BOOST_ENABLE_ASSERT_HANDLER #include "boost/optional/optional.hpp"
#include "boost/optional.hpp"
#include "boost/tuple/tuple.hpp"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #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" struct counting_oracle
// Test boost::tie() interoperabiliy.
int test_main( int, char* [] )
{ {
typedef X T ; 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; }
try static int dtor_count;
{ static int default_ctor_count;
TRACE( std::endl << BOOST_CURRENT_FUNCTION ); static int val_ctor_count;
static int copy_ctor_count;
static int copy_assign_count;
static int equals_count;
T z(0); friend bool operator==(const counting_oracle& lhs, const counting_oracle& rhs) { ++equals_count; return lhs.val == rhs.val; }
T a(1); };
T b(2);
optional<T> oa, ob ; 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;
// T::T( T const& x ) is used // Test boost::tie() interoperability.
set_pending_dtor( ARG(T) ) ; int main()
set_pending_copy( ARG(T) ) ; {
boost::tie(oa,ob) = std::make_pair(a,b) ; const std::pair<counting_oracle, counting_oracle> pair(1, 2);
check_is_not_pending_dtor( ARG(T) ) ; boost::optional<counting_oracle> o1, o2;
check_is_not_pending_copy( ARG(T) ) ; boost::tie(o1, o2) = pair;
check_initialized(oa);
check_initialized(ob);
check_value(oa,a,z);
check_value(ob,b,z);
} BOOST_TEST(o1);
catch ( ... ) BOOST_TEST(o2);
{ BOOST_TEST(*o1 == counting_oracle(1));
BOOST_ERROR("Unexpected Exception caught!"); 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();
} }