Boost logo

Boost-Commit :

From: nielsdekker_at_[hidden]
Date: 2008-08-20 04:28:36


Author: niels_dekker
Date: 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
New Revision: 48246
URL: http://svn.boost.org/trac/boost/changeset/48246

Log:
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
Text files modified:
   trunk/libs/utility/swap/test/no_ambiguity_in_boost.cpp | 11 +++++++++--
   trunk/libs/utility/swap/test/specialized_in_boost.cpp | 12 ++++++++++--
   trunk/libs/utility/swap/test/specialized_in_boost_and_other.cpp | 12 ++++++++++--
   trunk/libs/utility/swap/test/specialized_in_global.cpp | 12 ++++++++++--
   trunk/libs/utility/swap/test/specialized_in_other.cpp | 12 ++++++++++--
   trunk/libs/utility/swap/test/specialized_in_std.cpp | 12 ++++++++++--
   trunk/libs/utility/swap/test/std_vector_of_boost.cpp | 10 ++++++++--
   trunk/libs/utility/swap/test/std_vector_of_global.cpp | 10 ++++++++--
   trunk/libs/utility/swap/test/std_vector_of_other.cpp | 10 ++++++++--
   9 files changed, 83 insertions(+), 18 deletions(-)

Modified: trunk/libs/utility/swap/test/no_ambiguity_in_boost.cpp
==============================================================================
--- trunk/libs/utility/swap/test/no_ambiguity_in_boost.cpp (original)
+++ trunk/libs/utility/swap/test/no_ambiguity_in_boost.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -25,10 +25,17 @@
 
 int test_main(int, char*[])
 {
- boost::swap_test_class object1;
- boost::swap_test_class object2;
+ const boost::swap_test_class initial_value1(1);
+ 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_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::copy_count(),3);
 

Modified: trunk/libs/utility/swap/test/specialized_in_boost.cpp
==============================================================================
--- trunk/libs/utility/swap/test/specialized_in_boost.cpp (original)
+++ trunk/libs/utility/swap/test/specialized_in_boost.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -25,10 +25,18 @@
 
 int test_main(int, char*[])
 {
- boost::swap_test_class object1;
- boost::swap_test_class object2;
+ const boost::swap_test_class initial_value1(1);
+ 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_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::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/specialized_in_boost_and_other.cpp
==============================================================================
--- trunk/libs/utility/swap/test/specialized_in_boost_and_other.cpp (original)
+++ trunk/libs/utility/swap/test/specialized_in_boost_and_other.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -44,10 +44,18 @@
 
 int test_main(int, char*[])
 {
- other::swap_test_class object1;
- other::swap_test_class object2;
+ const other::swap_test_class initial_value1(1);
+ 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_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::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/specialized_in_global.cpp
==============================================================================
--- trunk/libs/utility/swap/test/specialized_in_global.cpp (original)
+++ trunk/libs/utility/swap/test/specialized_in_global.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -19,10 +19,18 @@
 
 int test_main(int, char*[])
 {
- swap_test_class object1;
- swap_test_class object2;
+ const swap_test_class initial_value1(1);
+ 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_CHECK(object1 == initial_value2);
+ BOOST_CHECK(object2 == initial_value1);
+
   BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
   BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/specialized_in_other.cpp
==============================================================================
--- trunk/libs/utility/swap/test/specialized_in_other.cpp (original)
+++ trunk/libs/utility/swap/test/specialized_in_other.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -25,10 +25,18 @@
 
 int test_main(int, char*[])
 {
- other::swap_test_class object1;
- other::swap_test_class object2;
+ const other::swap_test_class initial_value1(1);
+ 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_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::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/specialized_in_std.cpp
==============================================================================
--- trunk/libs/utility/swap/test/specialized_in_std.cpp (original)
+++ trunk/libs/utility/swap/test/specialized_in_std.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -24,10 +24,18 @@
 
 int test_main(int, char*[])
 {
- swap_test_class object1;
- swap_test_class object2;
+ const swap_test_class initial_value1(1);
+ 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_CHECK(object1 == initial_value2);
+ BOOST_CHECK(object2 == initial_value1);
+
   BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
   BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/std_vector_of_boost.cpp
==============================================================================
--- trunk/libs/utility/swap/test/std_vector_of_boost.cpp (original)
+++ trunk/libs/utility/swap/test/std_vector_of_boost.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -36,8 +36,11 @@
   const vector_type::size_type initial_size1 = 1;
   const vector_type::size_type initial_size2 = 2;
 
- vector_type object1(initial_size1);
- vector_type object2(initial_size2);
+ const vector_type initial_value1(initial_size1, swap_test_class_type(1));
+ 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();
   
@@ -46,6 +49,9 @@
   BOOST_CHECK_EQUAL(object1.size(),initial_size2);
   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::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/std_vector_of_global.cpp
==============================================================================
--- trunk/libs/utility/swap/test/std_vector_of_global.cpp (original)
+++ trunk/libs/utility/swap/test/std_vector_of_global.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -29,8 +29,11 @@
   const vector_type::size_type initial_size1 = 1;
   const vector_type::size_type initial_size2 = 2;
 
- vector_type object1(initial_size1);
- vector_type object2(initial_size2);
+ const vector_type initial_value1(initial_size1, swap_test_class(1));
+ 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();
   
@@ -39,6 +42,9 @@
   BOOST_CHECK_EQUAL(object1.size(),initial_size2);
   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::copy_count(),0);
 

Modified: trunk/libs/utility/swap/test/std_vector_of_other.cpp
==============================================================================
--- trunk/libs/utility/swap/test/std_vector_of_other.cpp (original)
+++ trunk/libs/utility/swap/test/std_vector_of_other.cpp 2008-08-20 04:28:35 EDT (Wed, 20 Aug 2008)
@@ -36,8 +36,11 @@
   const vector_type::size_type initial_size1 = 1;
   const vector_type::size_type initial_size2 = 2;
 
- vector_type object1(initial_size1);
- vector_type object2(initial_size2);
+ const vector_type initial_value1(initial_size1, swap_test_class_type(1));
+ 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();
   
@@ -46,6 +49,9 @@
   BOOST_CHECK_EQUAL(object1.size(),initial_size2);
   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::copy_count(),0);
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk