Boost logo

Boost-Commit :

From: nielsdekker_at_[hidden]
Date: 2008-08-02 07:41:48


Author: niels_dekker
Date: 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
New Revision: 47943
URL: http://svn.boost.org/trac/boost/changeset/47943

Log:
Added swap tests for std types, as discussed at "Re: [boost] [swap] Workaround for ADL failures of MSVC 7.1 and Borland okay?", http://lists.boost.org/Archives/boost/2008/08/140589.php
Added:
   trunk/libs/utility/swap/test/std_bitset.cpp (contents, props changed)
   trunk/libs/utility/swap/test/std_dateorder.cpp (contents, props changed)
   trunk/libs/utility/swap/test/std_string.cpp (contents, props changed)
   trunk/libs/utility/swap/test/std_typeinfo_ptr.cpp (contents, props changed)
   trunk/libs/utility/swap/test/std_vector_of_boost.cpp (contents, props changed)
   trunk/libs/utility/swap/test/std_vector_of_global.cpp (contents, props changed)
   trunk/libs/utility/swap/test/std_vector_of_other.cpp (contents, props changed)
Text files modified:
   trunk/libs/utility/swap/test/Jamfile.v2 | 7 +++++++
   1 files changed, 7 insertions(+), 0 deletions(-)

Modified: trunk/libs/utility/swap/test/Jamfile.v2
==============================================================================
--- trunk/libs/utility/swap/test/Jamfile.v2 (original)
+++ trunk/libs/utility/swap/test/Jamfile.v2 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -21,6 +21,13 @@
     [ run specialized_in_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     [ run specialized_in_std.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     [ run specialized_in_boost_and_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_bitset.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_dateorder.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_string.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_typeinfo_ptr.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_vector_of_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
+ [ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     [ run test_adl_barrier.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     [ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
     ;

Added: trunk/libs/utility/swap/test/std_bitset.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_bitset.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,33 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::bitset<T> objects by means of boost::swap.
+// Unlike most other Standard C++ Library template classes,
+// std::bitset<T> does not have its own std::swap overload.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <bitset>
+
+int test_main(int, char*[])
+{
+ typedef std::bitset<8> bitset_type;
+ const bitset_type initial_value1 = 1ul;
+ const bitset_type initial_value2 = 2ul;
+
+ bitset_type object1 = initial_value1;
+ bitset_type object2 = initial_value2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,initial_value2);
+ BOOST_CHECK_EQUAL(object2,initial_value1);
+
+ return 0;
+}
+

Added: trunk/libs/utility/swap/test/std_dateorder.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_dateorder.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,32 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::time_base::dateorder objects by means of boost::swap.
+// std::time_base::dateorder is an enumerated type. It does not have an
+// std::swap overload or template specialization.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <locale>
+
+int test_main(int, char*[])
+{
+ const std::time_base::dateorder initial_value1 = std::time_base::dmy;
+ const std::time_base::dateorder initial_value2 = std::time_base::mdy;
+
+ std::time_base::dateorder object1 = initial_value1;
+ std::time_base::dateorder object2 = initial_value2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,initial_value2);
+ BOOST_CHECK_EQUAL(object2,initial_value1);
+
+ return 0;
+}
+

Added: trunk/libs/utility/swap/test/std_string.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_string.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,31 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::string objects by means of boost::swap.
+// std::string has its own std::swap overload.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <string>
+
+int test_main(int, char*[])
+{
+ const std::string initial_value1 = "one";
+ const std::string initial_value2 = "two";
+
+ std::string object1 = initial_value1;
+ std::string object2 = initial_value2;
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1,initial_value2);
+ BOOST_CHECK_EQUAL(object2,initial_value1);
+
+ return 0;
+}
+

Added: trunk/libs/utility/swap/test/std_typeinfo_ptr.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_typeinfo_ptr.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,32 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::type_info pointers by means of boost::swap.
+// There is no std::swap overload or template specialization
+// for std::type_info pointers.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <typeinfo>
+
+int test_main(int, char*[])
+{
+ const std::type_info * const initial_value1 = 0;
+ const std::type_info * const initial_value2 = &typeid(double);
+
+ const std::type_info * ptr1 = initial_value1;
+ const std::type_info * ptr2 = initial_value2;
+
+ boost::swap(ptr1,ptr2);
+
+ BOOST_CHECK_EQUAL(ptr1,initial_value2);
+ BOOST_CHECK_EQUAL(ptr2,initial_value1);
+
+ return 0;
+}
+

Added: trunk/libs/utility/swap/test/std_vector_of_boost.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_vector_of_boost.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,54 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::vector objects by means of boost::swap,
+// having boost::swap_test_class as vector element type.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <vector>
+
+//Put test class in namespace boost
+namespace boost
+{
+ #include "./swap_test_class.hpp"
+}
+
+//Provide swap function in namespace boost
+namespace boost
+{
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ typedef boost::swap_test_class swap_test_class_type;
+ typedef std::vector<swap_test_class_type> vector_type;
+
+ 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);
+
+ swap_test_class_type::reset();
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1.size(),initial_size2);
+ BOOST_CHECK_EQUAL(object2.size(),initial_size1);
+
+ BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
+ BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
+
+ return 0;
+}
+

Added: trunk/libs/utility/swap/test/std_vector_of_global.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_vector_of_global.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,47 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::vector objects by means of boost::swap,
+// having ::swap_test_class as vector element type.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <vector>
+
+//Put test class in the global namespace
+#include "./swap_test_class.hpp"
+
+//Provide swap function in the global namespace
+void swap(swap_test_class& left, swap_test_class& right)
+{
+ left.swap(right);
+}
+
+int test_main(int, char*[])
+{
+ typedef std::vector<swap_test_class> vector_type;
+
+ 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);
+
+ swap_test_class::reset();
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1.size(),initial_size2);
+ BOOST_CHECK_EQUAL(object2.size(),initial_size1);
+
+ BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0);
+ BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
+
+ return 0;
+}
+

Added: trunk/libs/utility/swap/test/std_vector_of_other.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/swap/test/std_vector_of_other.cpp 2008-08-02 07:41:47 EDT (Sat, 02 Aug 2008)
@@ -0,0 +1,54 @@
+// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
+//
+// Distributed under 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)
+
+// Tests swapping std::vector objects by means of boost::swap,
+// having other::swap_test_class as vector element type.
+
+#include <boost/utility/swap.hpp>
+#define BOOST_INCLUDE_MAIN
+#include <boost/test/test_tools.hpp>
+
+#include <vector>
+
+//Put test class in namespace other
+namespace other
+{
+ #include "./swap_test_class.hpp"
+}
+
+//Provide swap function in namespace other
+namespace other
+{
+ void swap(swap_test_class& left, swap_test_class& right)
+ {
+ left.swap(right);
+ }
+}
+
+int test_main(int, char*[])
+{
+ typedef other::swap_test_class swap_test_class_type;
+ typedef std::vector<swap_test_class_type> vector_type;
+
+ 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);
+
+ swap_test_class_type::reset();
+
+ boost::swap(object1,object2);
+
+ BOOST_CHECK_EQUAL(object1.size(),initial_size2);
+ BOOST_CHECK_EQUAL(object2.size(),initial_size1);
+
+ BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
+ BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
+
+ return 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