forked from boostorg/optional
more unit test for opt ref swap and abstract types
This commit is contained in:
@ -30,7 +30,6 @@ import testing ;
|
||||
[ run optional_test_ref_convert_assign_const_int.cpp ]
|
||||
[ run optional_test_ref_portable_minimum.cpp ]
|
||||
[ run optional_test_ref_move.cpp ]
|
||||
[ run optional_test_ref_swap.cpp ]
|
||||
[ run optional_test_inplace_factory.cpp ]
|
||||
[ run optional_test_io.cpp ]
|
||||
[ run optional_test_move.cpp ]
|
||||
|
@ -38,7 +38,7 @@ void test_optional_ref_assignment()
|
||||
int main()
|
||||
{
|
||||
test_optional_ref_assignment<ScopeGuard>();
|
||||
//test_optional_ref_assignment<Abstract>();
|
||||
test_optional_ref_assignment<Abstract>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ void test_all_const_cases()
|
||||
int main()
|
||||
{
|
||||
test_all_const_cases<ScopeGuard>();
|
||||
//test_all_const_cases<Abstract>();
|
||||
test_all_const_cases<Abstract>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ int main()
|
||||
{
|
||||
test_all_const_cases<int>();
|
||||
test_all_const_cases<ScopeGuard>();
|
||||
//test_all_const_cases<Abstract>();
|
||||
test_all_const_cases<Abstract>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -256,11 +256,11 @@ void test_equality()
|
||||
BOOST_TEST( (o2 != oN));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename T, typename U = T>
|
||||
void test_order()
|
||||
{
|
||||
typename concrete_type_of<T>::type v1(1), v2(2), v2_(2), v3(3);
|
||||
optional<T&> o1(v1), o2(v2), o2_(v2_), o3(v3), o3_(v3), oN, oN_;
|
||||
optional<U&> o1(v1), o2(v2), o2_(v2_), o3(v3), o3_(v3), oN, oN_;
|
||||
// o2 and o2_ point to different objects; o3 and o3_ point to the same object
|
||||
|
||||
BOOST_TEST(!(oN < oN));
|
||||
@ -399,13 +399,35 @@ void test_order()
|
||||
BOOST_TEST(!(o3_ < oN_));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename T, typename U = T>
|
||||
void test_swap()
|
||||
{
|
||||
typename concrete_type_of<T>::type v1(1), v2(2);
|
||||
optional<T&> o1(v1), o1_(v1), o2(v2), o2_(v2), oN, oN_;
|
||||
optional<U&> o1(v1), o1_(v1), o2(v2), o2_(v2), oN, oN_;
|
||||
|
||||
// swap(o1, o1); DOESN'T WORK
|
||||
swap(o1, o1);
|
||||
BOOST_TEST(o1);
|
||||
BOOST_TEST(boost::addressof(*o1) == boost::addressof(v1));
|
||||
|
||||
swap(oN, oN_);
|
||||
BOOST_TEST(!oN);
|
||||
BOOST_TEST(!oN_);
|
||||
|
||||
swap(o1, oN);
|
||||
BOOST_TEST(!o1);
|
||||
BOOST_TEST(oN);
|
||||
BOOST_TEST(boost::addressof(*oN) == boost::addressof(v1));
|
||||
|
||||
swap(oN, o1);
|
||||
BOOST_TEST(!oN);
|
||||
BOOST_TEST(o1);
|
||||
BOOST_TEST(boost::addressof(*o1) == boost::addressof(v1));
|
||||
|
||||
swap(o1_, o2_);
|
||||
BOOST_TEST(o1_);
|
||||
BOOST_TEST(o2_);
|
||||
BOOST_TEST(boost::addressof(*o1_) == boost::addressof(v2));
|
||||
BOOST_TEST(boost::addressof(*o2_) == boost::addressof(v1));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -431,18 +453,19 @@ void test_optional_const_ref()
|
||||
test_arrow_noconst_const<T>();
|
||||
test_equality<const T>();
|
||||
test_order<const T>();
|
||||
//test_swap<T>();
|
||||
test_swap<const T>();
|
||||
test_swap<T, const T>();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_optional_ref<int>();
|
||||
test_optional_ref<ScopeGuard>();
|
||||
//test_optional_ref<Abstract>();
|
||||
test_optional_ref<Abstract>();
|
||||
|
||||
test_optional_const_ref<int>();
|
||||
test_optional_const_ref<ScopeGuard>();
|
||||
//test_optional_const_ref<Abstract>();
|
||||
test_optional_const_ref<Abstract>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -1,106 +0,0 @@
|
||||
// Copyright (C) 2016 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 maintainer at: akrzemi1@gmail.com
|
||||
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include "boost/core/addressof.hpp"
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
|
||||
using boost::optional;
|
||||
|
||||
struct Iface
|
||||
{
|
||||
virtual void fun() = 0;
|
||||
protected: ~Iface() {}
|
||||
};
|
||||
|
||||
struct Impl : Iface
|
||||
{
|
||||
void fun() {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void test_swap_empty_with_empty()
|
||||
{
|
||||
boost::optional<T&> o1, o2;
|
||||
swap(o1, o2);
|
||||
|
||||
BOOST_TEST(!o1);
|
||||
BOOST_TEST(!o2);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void test_swap_value_with_empty(U v1)
|
||||
{
|
||||
boost::optional<T&> o1 (v1), o2;
|
||||
swap(o1, o2);
|
||||
|
||||
BOOST_TEST(!o1);
|
||||
BOOST_TEST(o2);
|
||||
BOOST_TEST(boost::addressof(*o2) == boost::addressof(v1));
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void test_swap_empty_with_value(U v2)
|
||||
{
|
||||
boost::optional<T&> o1, o2(v2);
|
||||
swap(o1, o2);
|
||||
|
||||
BOOST_TEST(o1);
|
||||
BOOST_TEST(boost::addressof(*o1) == boost::addressof(v2));
|
||||
BOOST_TEST(!o2);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void test_swap_value_with_value(U v1, U v2)
|
||||
{
|
||||
boost::optional<T&> o1(v1), o2(v2);
|
||||
swap(o1, o2);
|
||||
|
||||
BOOST_TEST(o1);
|
||||
BOOST_TEST(o2);
|
||||
BOOST_TEST(boost::addressof(*o1) == boost::addressof(v2));
|
||||
BOOST_TEST(boost::addressof(*o2) == boost::addressof(v1));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string s1 ("AAA"), s2 ("BB");
|
||||
int i1 = 1, i2 = 2;
|
||||
Impl p1, p2;
|
||||
|
||||
test_swap_empty_with_empty<std::string>( );
|
||||
test_swap_value_with_empty<std::string>(s1 );
|
||||
test_swap_empty_with_value<std::string>( s2);
|
||||
test_swap_value_with_value<std::string>(s1, s2);
|
||||
|
||||
test_swap_empty_with_empty<int>( );
|
||||
test_swap_value_with_empty<int>(i1 );
|
||||
test_swap_empty_with_value<int>( i2);
|
||||
test_swap_value_with_value<int>(i1, i2);
|
||||
|
||||
test_swap_empty_with_empty<Iface>( );
|
||||
test_swap_value_with_empty<Iface>(p1 );
|
||||
test_swap_empty_with_value<Iface>( p2);
|
||||
test_swap_value_with_value<Iface>(p1, p2);
|
||||
|
||||
test_swap_empty_with_empty<const Iface>( );
|
||||
test_swap_value_with_empty<const Iface>(p1 );
|
||||
test_swap_empty_with_value<const Iface>( p2);
|
||||
test_swap_value_with_value<const Iface>(p1, p2);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user