Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73820 - in trunk/libs/unordered/test: objects unordered
From: dnljms_at_[hidden]
Date: 2011-08-16 14:08:23


Author: danieljames
Date: 2011-08-16 14:08:23 EDT (Tue, 16 Aug 2011)
New Revision: 73820
URL: http://svn.boost.org/trac/boost/changeset/73820

Log:
Unordered: Test types that are only destructible.
Text files modified:
   trunk/libs/unordered/test/objects/minimal.hpp | 36 ++++++++++++++++++++----------
   trunk/libs/unordered/test/unordered/compile_map.cpp | 20 +++++++---------
   trunk/libs/unordered/test/unordered/compile_set.cpp | 45 +++++++++++++++++++++++++++++++-------
   trunk/libs/unordered/test/unordered/compile_tests.hpp | 46 +++++++++++++++++++++++++++++++++------
   4 files changed, 107 insertions(+), 40 deletions(-)

Modified: trunk/libs/unordered/test/objects/minimal.hpp
==============================================================================
--- trunk/libs/unordered/test/objects/minimal.hpp (original)
+++ trunk/libs/unordered/test/objects/minimal.hpp 2011-08-16 14:08:23 EDT (Tue, 16 Aug 2011)
@@ -21,6 +21,7 @@
 {
 namespace minimal
 {
+ class destructible;
     class copy_constructible;
     class copy_constructible_equality_comparable;
     class default_copy_constructible;
@@ -35,10 +36,25 @@
     template <class T> class allocator;
     template <class T> class cxx11_allocator;
 
+ struct constructor_param
+ {
+ operator int() const { return 0; }
+ };
+
+ class destructible
+ {
+ public:
+ destructible(constructor_param const&) {}
+ ~destructible() {}
+ private:
+ destructible(destructible const&);
+ destructible& operator=(destructible const&);
+ };
+
     class copy_constructible
     {
     public:
- static copy_constructible create() { return copy_constructible(); }
+ copy_constructible(constructor_param const&) {}
         copy_constructible(copy_constructible const&) {}
         ~copy_constructible() {}
     private:
@@ -49,9 +65,7 @@
     class copy_constructible_equality_comparable
     {
     public:
- static copy_constructible_equality_comparable create() {
- return copy_constructible_equality_comparable();
- }
+ copy_constructible_equality_comparable(constructor_param const&) {}
 
         copy_constructible_equality_comparable(
             copy_constructible_equality_comparable const&)
@@ -86,10 +100,7 @@
     class default_copy_constructible
     {
     public:
- static default_copy_constructible create()
- {
- return default_copy_constructible();
- }
+ default_copy_constructible(constructor_param const&) {}
 
         default_copy_constructible()
         {
@@ -106,13 +117,14 @@
     private:
         default_copy_constructible& operator=(
             default_copy_constructible const&);
- ampersand_operator_used operator&() const { return ampersand_operator_used(); }
+ ampersand_operator_used operator&() const {
+ return ampersand_operator_used(); }
     };
 
     class assignable
     {
     public:
- static assignable create() { return assignable(); }
+ assignable(constructor_param const&) {}
         assignable(assignable const&) {}
         assignable& operator=(assignable const&) { return *this; }
         ~assignable() {}
@@ -127,7 +139,7 @@
     class hash
     {
     public:
- static hash create() { return hash<T>(); }
+ hash(constructor_param const&) {}
         hash() {}
         hash(hash const&) {}
         hash& operator=(hash const&) { return *this; }
@@ -142,7 +154,7 @@
     class equal_to
     {
     public:
- static equal_to create() { return equal_to<T>(); }
+ equal_to(constructor_param const&) {}
         equal_to() {}
         equal_to(equal_to const&) {}
         equal_to& operator=(equal_to const&) { return *this; }

Modified: trunk/libs/unordered/test/unordered/compile_map.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/compile_map.cpp (original)
+++ trunk/libs/unordered/test/unordered/compile_map.cpp 2011-08-16 14:08:23 EDT (Tue, 16 Aug 2011)
@@ -45,11 +45,11 @@
 
 UNORDERED_AUTO_TEST(test0)
 {
+ test::minimal::constructor_param x;
+
     typedef std::pair<test::minimal::assignable const,
             test::minimal::copy_constructible> value_type;
- value_type value(
- test::minimal::assignable::create(),
- test::minimal::copy_constructible::create());
+ value_type value(x, x);
 
     std::cout<<"Test unordered_map.\n";
 
@@ -179,14 +179,12 @@
 
 UNORDERED_AUTO_TEST(test2)
 {
- test::minimal::assignable assignable
- = test::minimal::assignable::create();
- test::minimal::copy_constructible copy_constructible
- = test::minimal::copy_constructible::create();
- test::minimal::hash<test::minimal::assignable> hash
- = test::minimal::hash<test::minimal::assignable>::create();
- test::minimal::equal_to<test::minimal::assignable> equal_to
- = test::minimal::equal_to<test::minimal::assignable>::create();
+ test::minimal::constructor_param x;
+
+ test::minimal::assignable assignable(x);
+ test::minimal::copy_constructible copy_constructible(x);
+ test::minimal::hash<test::minimal::assignable> hash(x);
+ test::minimal::equal_to<test::minimal::assignable> equal_to(x);
 
     typedef std::pair<test::minimal::assignable const,
             test::minimal::copy_constructible> map_value_type;

Modified: trunk/libs/unordered/test/unordered/compile_set.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/compile_set.cpp (original)
+++ trunk/libs/unordered/test/unordered/compile_set.cpp 2011-08-16 14:08:23 EDT (Tue, 16 Aug 2011)
@@ -41,7 +41,9 @@
 
 UNORDERED_AUTO_TEST(test0)
 {
- test::minimal::assignable assignable = test::minimal::assignable::create();
+ test::minimal::constructor_param x;
+
+ test::minimal::assignable assignable(x);
 
     std::cout<<"Test unordered_set.\n";
 
@@ -163,14 +165,12 @@
 
 UNORDERED_AUTO_TEST(test2)
 {
- test::minimal::assignable assignable
- = test::minimal::assignable::create();
- test::minimal::copy_constructible copy_constructible
- = test::minimal::copy_constructible::create();
- test::minimal::hash<test::minimal::assignable> hash
- = test::minimal::hash<test::minimal::assignable>::create();
- test::minimal::equal_to<test::minimal::assignable> equal_to
- = test::minimal::equal_to<test::minimal::assignable>::create();
+ test::minimal::constructor_param x;
+
+ test::minimal::assignable assignable(x);
+ test::minimal::copy_constructible copy_constructible(x);
+ test::minimal::hash<test::minimal::assignable> hash(x);
+ test::minimal::equal_to<test::minimal::assignable> equal_to(x);
 
     std::cout<<"Test unordered_set.\n";
 
@@ -197,4 +197,31 @@
     unordered_test(multiset, assignable, assignable, hash, equal_to);
 }
 
+UNORDERED_AUTO_TEST(destructible_tests)
+{
+ test::minimal::constructor_param x;
+
+ test::minimal::destructible destructible(x);
+ test::minimal::hash<test::minimal::destructible> hash(x);
+ test::minimal::equal_to<test::minimal::destructible> equal_to(x);
+
+ std::cout<<"Test unordered_set.\n";
+
+ boost::unordered_set<
+ test::minimal::destructible,
+ test::minimal::hash<test::minimal::destructible>,
+ test::minimal::equal_to<test::minimal::destructible> > set;
+
+ unordered_destructible_test(set);
+
+ std::cout<<"Test unordered_multiset.\n";
+
+ boost::unordered_multiset<
+ test::minimal::destructible,
+ test::minimal::hash<test::minimal::destructible>,
+ test::minimal::equal_to<test::minimal::destructible> > multiset;
+
+ unordered_destructible_test(multiset);
+}
+
 RUN_TESTS()

Modified: trunk/libs/unordered/test/unordered/compile_tests.hpp
==============================================================================
--- trunk/libs/unordered/test/unordered/compile_tests.hpp (original)
+++ trunk/libs/unordered/test/unordered/compile_tests.hpp 2011-08-16 14:08:23 EDT (Tue, 16 Aug 2011)
@@ -28,6 +28,7 @@
 
 template <class T> void sink(T const&) {}
 template <class T> T rvalue(T const& v) { return v; }
+template <class T> T rvalue_default() { return T(); }
 
 template <class X, class T>
 void container_test(X& r, T const&)
@@ -109,15 +110,48 @@
     BOOST_TEST(X().size() == 0);
 
     X a,b;
+ X a_const;
 
     sink(X(a));
     X u2(a);
     X u3 = a;
 
+ a.swap(b);
+ boost::swap(a, b);
+ test::check_return_type<X>::equals_ref(r = a);
+
+ // Allocator
+
+ typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type;
+ test::check_return_type<allocator_type>::equals(a_const.get_allocator());
+
+ // Avoid unused variable warnings:
+
+ sink(u);
+ sink(u2);
+ sink(u3);
+}
+
+template <class X>
+void unordered_destructible_test(X&)
+{
+ typedef BOOST_DEDUCED_TYPENAME X::iterator iterator;
+ typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator;
+ typedef BOOST_DEDUCED_TYPENAME X::size_type size_type;
+
+ X x1;
+
+#if !defined(BOOST_NO_RVALUE_REFERENCES)
+ X x2(rvalue_default<X>());
+ X x3 = rvalue_default<X>();
+ x2 = rvalue_default<X>();
+#endif
+
     X* ptr = new X();
     X& a1 = *ptr;
     (&a1)->~X();
 
+ X a,b;
     X const a_const;
     test::check_return_type<iterator>::equals(a.begin());
     test::check_return_type<const_iterator>::equals(a_const.begin());
@@ -130,7 +164,7 @@
 
     a.swap(b);
     boost::swap(a, b);
- test::check_return_type<X>::equals_ref(r = a);
+
     test::check_return_type<size_type>::equals(a.size());
     test::check_return_type<size_type>::equals(a.max_size());
     test::check_return_type<bool>::convertible(a.empty());
@@ -139,12 +173,6 @@
 
     typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type;
     test::check_return_type<allocator_type>::equals(a_const.get_allocator());
-
- // Avoid unused variable warnings:
-
- sink(u);
- sink(u2);
- sink(u3);
 }
 
 template <class X, class Key>
@@ -215,8 +243,10 @@
 }
 
 template <class X, class Key, class T, class Hash, class Pred>
-void unordered_test(X&, Key& k, T& t, Hash& hf, Pred& eq)
+void unordered_test(X& x, Key& k, T& t, Hash& hf, Pred& eq)
 {
+ unordered_destructible_test(x);
+
     typedef BOOST_DEDUCED_TYPENAME X::key_type key_type;
     typedef BOOST_DEDUCED_TYPENAME X::hasher hasher;
     typedef BOOST_DEDUCED_TYPENAME X::key_equal key_equal;


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