mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Added extra checks, checking that boost::swap does correctly exchange the values of its arguments, as I mentioned at "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141027.php
[SVN r48246]
This commit is contained in:
parent
7bfb7c8a61
commit
2cde009bb1
@ -25,10 +25,17 @@ namespace boost
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
boost::swap_test_class object1;
|
const boost::swap_test_class initial_value1(1);
|
||||||
boost::swap_test_class object2;
|
const boost::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
boost::swap_test_class object1 = initial_value1;
|
||||||
|
boost::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
boost::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3);
|
||||||
|
|
||||||
|
@ -25,10 +25,18 @@ namespace boost
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
boost::swap_test_class object1;
|
const boost::swap_test_class initial_value1(1);
|
||||||
boost::swap_test_class object2;
|
const boost::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
boost::swap_test_class object1 = initial_value1;
|
||||||
|
boost::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
boost::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@ -44,10 +44,18 @@ namespace other
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
other::swap_test_class object1;
|
const other::swap_test_class initial_value1(1);
|
||||||
other::swap_test_class object2;
|
const other::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
other::swap_test_class object1 = initial_value1;
|
||||||
|
other::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
other::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@ -19,10 +19,18 @@ void swap(swap_test_class& left, swap_test_class& right)
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
swap_test_class object1;
|
const swap_test_class initial_value1(1);
|
||||||
swap_test_class object2;
|
const swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
swap_test_class object1 = initial_value1;
|
||||||
|
swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@ -25,10 +25,18 @@ namespace other
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
other::swap_test_class object1;
|
const other::swap_test_class initial_value1(1);
|
||||||
other::swap_test_class object2;
|
const other::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
other::swap_test_class object1 = initial_value1;
|
||||||
|
other::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
other::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@ -24,10 +24,18 @@ namespace std
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
swap_test_class object1;
|
const swap_test_class initial_value1(1);
|
||||||
swap_test_class object2;
|
const swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
swap_test_class object1 = initial_value1;
|
||||||
|
swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@ -36,8 +36,11 @@ int test_main(int, char*[])
|
|||||||
const vector_type::size_type initial_size1 = 1;
|
const vector_type::size_type initial_size1 = 1;
|
||||||
const vector_type::size_type initial_size2 = 2;
|
const vector_type::size_type initial_size2 = 2;
|
||||||
|
|
||||||
vector_type object1(initial_size1);
|
const vector_type initial_value1(initial_size1, swap_test_class_type(1));
|
||||||
vector_type object2(initial_size2);
|
const vector_type initial_value2(initial_size2, swap_test_class_type(2));
|
||||||
|
|
||||||
|
vector_type object1 = initial_value1;
|
||||||
|
vector_type object2 = initial_value2;
|
||||||
|
|
||||||
swap_test_class_type::reset();
|
swap_test_class_type::reset();
|
||||||
|
|
||||||
@ -46,6 +49,9 @@ int test_main(int, char*[])
|
|||||||
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
||||||
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
||||||
|
|
||||||
|
@ -29,8 +29,11 @@ int test_main(int, char*[])
|
|||||||
const vector_type::size_type initial_size1 = 1;
|
const vector_type::size_type initial_size1 = 1;
|
||||||
const vector_type::size_type initial_size2 = 2;
|
const vector_type::size_type initial_size2 = 2;
|
||||||
|
|
||||||
vector_type object1(initial_size1);
|
const vector_type initial_value1(initial_size1, swap_test_class(1));
|
||||||
vector_type object2(initial_size2);
|
const vector_type initial_value2(initial_size2, swap_test_class(2));
|
||||||
|
|
||||||
|
vector_type object1 = initial_value1;
|
||||||
|
vector_type object2 = initial_value2;
|
||||||
|
|
||||||
swap_test_class::reset();
|
swap_test_class::reset();
|
||||||
|
|
||||||
@ -39,6 +42,9 @@ int test_main(int, char*[])
|
|||||||
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
||||||
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@ -36,8 +36,11 @@ int test_main(int, char*[])
|
|||||||
const vector_type::size_type initial_size1 = 1;
|
const vector_type::size_type initial_size1 = 1;
|
||||||
const vector_type::size_type initial_size2 = 2;
|
const vector_type::size_type initial_size2 = 2;
|
||||||
|
|
||||||
vector_type object1(initial_size1);
|
const vector_type initial_value1(initial_size1, swap_test_class_type(1));
|
||||||
vector_type object2(initial_size2);
|
const vector_type initial_value2(initial_size2, swap_test_class_type(2));
|
||||||
|
|
||||||
|
vector_type object1 = initial_value1;
|
||||||
|
vector_type object2 = initial_value2;
|
||||||
|
|
||||||
swap_test_class_type::reset();
|
swap_test_class_type::reset();
|
||||||
|
|
||||||
@ -46,6 +49,9 @@ int test_main(int, char*[])
|
|||||||
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
||||||
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user