diff --git a/test/unordered/Jamfile.v2 b/test/unordered/Jamfile.v2 index 005a7787..5e02e281 100644 --- a/test/unordered/Jamfile.v2 +++ b/test/unordered/Jamfile.v2 @@ -16,9 +16,8 @@ test-suite unordered-tests : [ run set_compile.cpp ] [ run map_compile.cpp ] - [ run simple_tests.cpp ] [ run link_test_1.cpp link_test_2.cpp ] - [ run compile_tests.cpp ] + [ run simple_tests.cpp ] [ run equivalent_keys_tests.cpp ] [ run constructor_tests.cpp ] [ run copy_tests.cpp ] diff --git a/test/unordered/compile_tests.cpp b/test/unordered/compile_tests.cpp deleted file mode 100644 index 331bdad8..00000000 --- a/test/unordered/compile_tests.cpp +++ /dev/null @@ -1,328 +0,0 @@ - -// Copyright 2006-2007 Daniel James. -// 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) - -#include -#include - -#if defined(BOOST_MSVC) -#pragma warning(push) -#pragma warning(disable:4100) // unreferenced formal parameter -#endif - -#include - -#if defined(BOOST_MSVC) -#pragma warning(pop) -#endif - -#include -#include -#include "../helpers/check_return_type.hpp" - -#include -#include -#include "../objects/minimal.hpp" - -template void sink(T const&) {} - -template -void unordered_set_test(X&, Key const&) -{ - typedef typename X::value_type value_type; - typedef typename X::key_type key_type; - - BOOST_MPL_ASSERT((boost::is_same)); -} - -template -void unordered_map_test(X&, Key const&, T const&) -{ - typedef typename X::value_type value_type; - typedef typename X::key_type key_type; - BOOST_MPL_ASSERT((boost::is_same >)); -} - -template -void unordered_unique_test(X& r, T const& t) -{ - typedef typename X::iterator iterator; - test::check_return_type >::equals(r.insert(t)); -} - -template -void unordered_equivalent_test(X& r, T const& t) -{ - typedef typename X::iterator iterator; - test::check_return_type::equals(r.insert(t)); -} - -template -void unordered_map_functions(X&, Key const& k, T const&) -{ - typedef typename X::mapped_type mapped_type; - - X a; - test::check_return_type::equals_ref(a[k]); - test::check_return_type::equals_ref(a.at(k)); - - X const b = a; - test::check_return_type::equals_ref(b.at(k)); -} - -template -void unordered_test(X&, Key& k, T& t, Hash& hf, Pred& eq) -{ - typedef typename X::key_type key_type; - typedef typename X::hasher hasher; - typedef typename X::key_equal key_equal; - typedef typename X::size_type size_type; - - typedef typename X::iterator iterator; - typedef typename X::const_iterator const_iterator; - typedef typename X::local_iterator local_iterator; - typedef typename X::const_local_iterator const_local_iterator; - - typedef typename boost::BOOST_ITERATOR_CATEGORY::type iterator_category; - typedef typename boost::iterator_difference::type iterator_difference; - typedef typename boost::iterator_pointer::type iterator_pointer; - typedef typename boost::iterator_reference::type iterator_reference; - - typedef typename boost::BOOST_ITERATOR_CATEGORY::type local_iterator_category; - typedef typename boost::iterator_difference::type local_iterator_difference; - typedef typename boost::iterator_pointer::type local_iterator_pointer; - typedef typename boost::iterator_reference::type local_iterator_reference; - - typedef typename boost::BOOST_ITERATOR_CATEGORY::type const_iterator_category; - typedef typename boost::iterator_difference::type const_iterator_difference; - typedef typename boost::iterator_pointer::type const_iterator_pointer; - typedef typename boost::iterator_reference::type const_iterator_reference; - - typedef typename boost::BOOST_ITERATOR_CATEGORY::type const_local_iterator_category; - typedef typename boost::iterator_difference::type const_local_iterator_difference; - typedef typename boost::iterator_pointer::type const_local_iterator_pointer; - typedef typename boost::iterator_reference::type const_local_iterator_reference; - - BOOST_MPL_ASSERT((boost::is_same)); - boost::function_requires >(); - boost::function_requires >(); - - BOOST_MPL_ASSERT((boost::is_same)); - test::check_return_type::equals(hf(k)); - - BOOST_MPL_ASSERT((boost::is_same)); - test::check_return_type::convertible(eq(k, k)); - - boost::function_requires >(); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - - boost::function_requires >(); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - BOOST_MPL_ASSERT((boost::is_same)); - - X(10, hf, eq); - X a(10, hf, eq); - X(10, hf); - X a2(10, hf); - X(10); - X a3(10); - X(); - X a4; - - typename X::value_type* i = 0; - typename X::value_type* j = 0; - - X(i, j, 10, hf, eq); - X a5(i, j, 10, hf, eq); - X(i, j, 10, hf); - X a6(i, j, 10, hf); - X(i, j, 10); - X a7(i, j, 10); - X(i, j); - X a8(i, j); - - X const b; - sink(X(b)); - X a9(b); - a = b; - - test::check_return_type::equals(b.hash_function()); - test::check_return_type::equals(b.key_eq()); - - const_iterator q = a.cbegin(); - test::check_return_type::equals(a.insert(q, t)); - - a.insert(i, j); - test::check_return_type::equals(a.erase(k)); - - BOOST_TEST(a.empty()); - if(a.empty()) { - a.insert(t); - q = a.cbegin(); - test::check_return_type::equals(a.erase(q)); - } - - const_iterator q1 = a.cbegin(), q2 = a.cend(); - test::check_return_type::equals(a.erase(q1, q2)); - - a.clear(); - - test::check_return_type::equals(a.find(k)); - test::check_return_type::equals(b.find(k)); - test::check_return_type::equals(b.count(k)); - test::check_return_type >::equals( - a.equal_range(k)); - test::check_return_type >::equals( - b.equal_range(k)); - test::check_return_type::equals(b.bucket_count()); - test::check_return_type::equals(b.max_bucket_count()); - test::check_return_type::equals(b.bucket(k)); - test::check_return_type::equals(b.bucket_size(0)); - - test::check_return_type::equals(a.begin(0)); - test::check_return_type::equals(b.begin(0)); - test::check_return_type::equals(a.end(0)); - test::check_return_type::equals(b.end(0)); - - test::check_return_type::equals(a.cbegin(0)); - test::check_return_type::equals(b.cbegin(0)); - test::check_return_type::equals(a.cend(0)); - test::check_return_type::equals(b.cend(0)); - - test::check_return_type::equals(b.load_factor()); - test::check_return_type::equals(b.max_load_factor()); - a.max_load_factor((float) 2.0); - a.rehash(100); -} - -void test1() -{ - boost::hash hash; - std::equal_to equal_to; - int value = 0; - std::pair map_value(0, 0); - - std::cout<<"Test unordered_set.\n"; - - boost::unordered_set set; - - unordered_unique_test(set, value); - unordered_set_test(set, value); - unordered_test(set, value, value, hash, equal_to); - - std::cout<<"Test unordered_multiset.\n"; - - boost::unordered_multiset multiset; - - unordered_equivalent_test(multiset, value); - unordered_set_test(multiset, value); - unordered_test(multiset, value, value, hash, equal_to); - - std::cout<<"Test unordered_map.\n"; - - boost::unordered_map map; - - unordered_unique_test(map, map_value); - unordered_map_test(map, value, value); - unordered_test(map, value, map_value, hash, equal_to); - unordered_map_functions(map, value, value); - - std::cout<<"Test unordered_multimap.\n"; - - boost::unordered_multimap multimap; - - unordered_equivalent_test(multimap, map_value); - unordered_map_test(multimap, value, value); - unordered_test(multimap, value, map_value, hash, equal_to); -} - -void test2() -{ - test::minimal::assignable assignable - = test::minimal::assignable::create(); - test::minimal::copy_constructible copy_constructible - = test::minimal::copy_constructible::create(); - test::minimal::hash hash - = test::minimal::hash::create(); - test::minimal::equal_to equal_to - = test::minimal::equal_to::create(); - - typedef std::pair map_value_type; - map_value_type map_value(assignable, copy_constructible); - - std::cout<<"Test unordered_set.\n"; - - boost::unordered_set< - test::minimal::assignable, - test::minimal::hash, - test::minimal::equal_to, - test::minimal::allocator > set; - - unordered_unique_test(set, assignable); - unordered_set_test(set, assignable); - unordered_test(set, assignable, assignable, hash, equal_to); - - std::cout<<"Test unordered_multiset.\n"; - - boost::unordered_multiset< - test::minimal::assignable, - test::minimal::hash, - test::minimal::equal_to, - test::minimal::allocator > multiset; - - unordered_equivalent_test(multiset, assignable); - unordered_set_test(multiset, assignable); - unordered_test(multiset, assignable, assignable, hash, equal_to); - - std::cout<<"Test unordered_map.\n"; - - boost::unordered_map< - test::minimal::assignable, - test::minimal::copy_constructible, - test::minimal::hash, - test::minimal::equal_to, - test::minimal::allocator > map; - - unordered_unique_test(map, map_value); - unordered_map_test(map, assignable, copy_constructible); - unordered_test(map, assignable, map_value, hash, equal_to); - - - boost::unordered_map< - test::minimal::assignable, - test::minimal::default_copy_constructible, - test::minimal::hash, - test::minimal::equal_to, - test::minimal::allocator > map2; - - test::minimal::default_copy_constructible default_copy_constructible; - - unordered_map_functions(map2, assignable, default_copy_constructible); - - std::cout<<"Test unordered_multimap.\n"; - - boost::unordered_multimap< - test::minimal::assignable, - test::minimal::copy_constructible, - test::minimal::hash, - test::minimal::equal_to, - test::minimal::allocator > multimap; - - unordered_equivalent_test(multimap, map_value); - unordered_map_test(multimap, assignable, copy_constructible); - unordered_test(multimap, assignable, map_value, hash, equal_to); -} - -int main() { - test1(); - test2(); - - return boost::report_errors(); -} diff --git a/test/unordered/compile_tests.hpp b/test/unordered/compile_tests.hpp index b5fe1ab3..caa5acc1 100644 --- a/test/unordered/compile_tests.hpp +++ b/test/unordered/compile_tests.hpp @@ -128,3 +128,177 @@ void container_test(X& r, T&) test::check_return_type::equals(a.max_size()); test::check_return_type::convertible(a.empty()); } + +template +void unordered_set_test(X&, Key const&) +{ + typedef typename X::value_type value_type; + typedef typename X::key_type key_type; + + BOOST_MPL_ASSERT((boost::is_same)); +} + +template +void unordered_map_test(X&, Key const&, T const&) +{ + typedef typename X::value_type value_type; + typedef typename X::key_type key_type; + BOOST_MPL_ASSERT((boost::is_same >)); +} + +template +void unordered_unique_test(X& r, T const& t) +{ + typedef typename X::iterator iterator; + test::check_return_type >::equals(r.insert(t)); +} + +template +void unordered_equivalent_test(X& r, T const& t) +{ + typedef typename X::iterator iterator; + test::check_return_type::equals(r.insert(t)); +} + +template +void unordered_map_functions(X&, Key const& k, T const&) +{ + typedef typename X::mapped_type mapped_type; + + X a; + test::check_return_type::equals_ref(a[k]); + test::check_return_type::equals_ref(a.at(k)); + + X const b = a; + test::check_return_type::equals_ref(b.at(k)); +} + +template +void unordered_test(X&, Key& k, T& t, Hash& hf, Pred& eq) +{ + typedef typename X::key_type key_type; + typedef typename X::hasher hasher; + typedef typename X::key_equal key_equal; + typedef typename X::size_type size_type; + + typedef typename X::iterator iterator; + typedef typename X::const_iterator const_iterator; + typedef typename X::local_iterator local_iterator; + typedef typename X::const_local_iterator const_local_iterator; + + typedef typename boost::BOOST_ITERATOR_CATEGORY::type iterator_category; + typedef typename boost::iterator_difference::type iterator_difference; + typedef typename boost::iterator_pointer::type iterator_pointer; + typedef typename boost::iterator_reference::type iterator_reference; + + typedef typename boost::BOOST_ITERATOR_CATEGORY::type local_iterator_category; + typedef typename boost::iterator_difference::type local_iterator_difference; + typedef typename boost::iterator_pointer::type local_iterator_pointer; + typedef typename boost::iterator_reference::type local_iterator_reference; + + typedef typename boost::BOOST_ITERATOR_CATEGORY::type const_iterator_category; + typedef typename boost::iterator_difference::type const_iterator_difference; + typedef typename boost::iterator_pointer::type const_iterator_pointer; + typedef typename boost::iterator_reference::type const_iterator_reference; + + typedef typename boost::BOOST_ITERATOR_CATEGORY::type const_local_iterator_category; + typedef typename boost::iterator_difference::type const_local_iterator_difference; + typedef typename boost::iterator_pointer::type const_local_iterator_pointer; + typedef typename boost::iterator_reference::type const_local_iterator_reference; + + BOOST_MPL_ASSERT((boost::is_same)); + boost::function_requires >(); + boost::function_requires >(); + + BOOST_MPL_ASSERT((boost::is_same)); + test::check_return_type::equals(hf(k)); + + BOOST_MPL_ASSERT((boost::is_same)); + test::check_return_type::convertible(eq(k, k)); + + boost::function_requires >(); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); + + boost::function_requires >(); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); + + X(10, hf, eq); + X a(10, hf, eq); + X(10, hf); + X a2(10, hf); + X(10); + X a3(10); + X(); + X a4; + + typename X::value_type* i = 0; + typename X::value_type* j = 0; + + X(i, j, 10, hf, eq); + X a5(i, j, 10, hf, eq); + X(i, j, 10, hf); + X a6(i, j, 10, hf); + X(i, j, 10); + X a7(i, j, 10); + X(i, j); + X a8(i, j); + + X const b; + sink(X(b)); + X a9(b); + a = b; + + test::check_return_type::equals(b.hash_function()); + test::check_return_type::equals(b.key_eq()); + + const_iterator q = a.cbegin(); + test::check_return_type::equals(a.insert(q, t)); + + a.insert(i, j); + test::check_return_type::equals(a.erase(k)); + + BOOST_TEST(a.empty()); + if(a.empty()) { + a.insert(t); + q = a.cbegin(); + test::check_return_type::equals(a.erase(q)); + } + + const_iterator q1 = a.cbegin(), q2 = a.cend(); + test::check_return_type::equals(a.erase(q1, q2)); + + a.clear(); + + test::check_return_type::equals(a.find(k)); + test::check_return_type::equals(b.find(k)); + test::check_return_type::equals(b.count(k)); + test::check_return_type >::equals( + a.equal_range(k)); + test::check_return_type >::equals( + b.equal_range(k)); + test::check_return_type::equals(b.bucket_count()); + test::check_return_type::equals(b.max_bucket_count()); + test::check_return_type::equals(b.bucket(k)); + test::check_return_type::equals(b.bucket_size(0)); + + test::check_return_type::equals(a.begin(0)); + test::check_return_type::equals(b.begin(0)); + test::check_return_type::equals(a.end(0)); + test::check_return_type::equals(b.end(0)); + + test::check_return_type::equals(a.cbegin(0)); + test::check_return_type::equals(b.cbegin(0)); + test::check_return_type::equals(a.cend(0)); + test::check_return_type::equals(b.cend(0)); + + test::check_return_type::equals(b.load_factor()); + test::check_return_type::equals(b.max_load_factor()); + a.max_load_factor((float) 2.0); + a.rehash(100); +} diff --git a/test/unordered/map_compile.cpp b/test/unordered/map_compile.cpp index e498a934..cdb785e9 100644 --- a/test/unordered/map_compile.cpp +++ b/test/unordered/map_compile.cpp @@ -13,7 +13,7 @@ #include "../objects/minimal.hpp" #include "./compile_tests.hpp" -int main() +void test0() { typedef std::pair value_type; @@ -40,6 +40,92 @@ int main() test::minimal::allocator > multimap; container_test(multimap, value); +} + +void test1() +{ + boost::hash hash; + std::equal_to equal_to; + int value = 0; + std::pair map_value(0, 0); + + std::cout<<"Test unordered_map.\n"; + + boost::unordered_map map; + + unordered_unique_test(map, map_value); + unordered_map_test(map, value, value); + unordered_test(map, value, map_value, hash, equal_to); + unordered_map_functions(map, value, value); + + std::cout<<"Test unordered_multimap.\n"; + + boost::unordered_multimap multimap; + + unordered_equivalent_test(multimap, map_value); + unordered_map_test(multimap, value, value); + unordered_test(multimap, value, map_value, hash, equal_to); +} + +void test2() +{ + test::minimal::assignable assignable + = test::minimal::assignable::create(); + test::minimal::copy_constructible copy_constructible + = test::minimal::copy_constructible::create(); + test::minimal::hash hash + = test::minimal::hash::create(); + test::minimal::equal_to equal_to + = test::minimal::equal_to::create(); + + typedef std::pair map_value_type; + map_value_type map_value(assignable, copy_constructible); + + std::cout<<"Test unordered_map.\n"; + + boost::unordered_map< + test::minimal::assignable, + test::minimal::copy_constructible, + test::minimal::hash, + test::minimal::equal_to, + test::minimal::allocator > map; + + unordered_unique_test(map, map_value); + unordered_map_test(map, assignable, copy_constructible); + unordered_test(map, assignable, map_value, hash, equal_to); + + + boost::unordered_map< + test::minimal::assignable, + test::minimal::default_copy_constructible, + test::minimal::hash, + test::minimal::equal_to, + test::minimal::allocator > map2; + + test::minimal::default_copy_constructible default_copy_constructible; + + unordered_map_functions(map2, assignable, default_copy_constructible); + + std::cout<<"Test unordered_multimap.\n"; + + boost::unordered_multimap< + test::minimal::assignable, + test::minimal::copy_constructible, + test::minimal::hash, + test::minimal::equal_to, + test::minimal::allocator > multimap; + + unordered_equivalent_test(multimap, map_value); + unordered_map_test(multimap, assignable, copy_constructible); + unordered_test(multimap, assignable, map_value, hash, equal_to); +} + +int main() +{ + test0(); + test1(); + test2(); return boost::report_errors(); } diff --git a/test/unordered/set_compile.cpp b/test/unordered/set_compile.cpp index f34de5d7..099b8030 100644 --- a/test/unordered/set_compile.cpp +++ b/test/unordered/set_compile.cpp @@ -13,7 +13,7 @@ #include "../objects/minimal.hpp" #include "./compile_tests.hpp" -int main() +void test0() { test::minimal::assignable assignable = test::minimal::assignable::create(); @@ -34,6 +34,71 @@ int main() test::minimal::allocator > multiset; container_test(multiset, assignable); +} + +void test1() +{ + boost::hash hash; + std::equal_to equal_to; + int value = 0; + + std::cout<<"Test unordered_set.\n"; + + boost::unordered_set set; + + unordered_unique_test(set, value); + unordered_set_test(set, value); + unordered_test(set, value, value, hash, equal_to); + + std::cout<<"Test unordered_multiset.\n"; + + boost::unordered_multiset multiset; + + unordered_equivalent_test(multiset, value); + unordered_set_test(multiset, value); + unordered_test(multiset, value, value, hash, equal_to); +} + +void test2() +{ + test::minimal::assignable assignable + = test::minimal::assignable::create(); + test::minimal::copy_constructible copy_constructible + = test::minimal::copy_constructible::create(); + test::minimal::hash hash + = test::minimal::hash::create(); + test::minimal::equal_to equal_to + = test::minimal::equal_to::create(); + + std::cout<<"Test unordered_set.\n"; + + boost::unordered_set< + test::minimal::assignable, + test::minimal::hash, + test::minimal::equal_to, + test::minimal::allocator > set; + + unordered_unique_test(set, assignable); + unordered_set_test(set, assignable); + unordered_test(set, assignable, assignable, hash, equal_to); + + std::cout<<"Test unordered_multiset.\n"; + + boost::unordered_multiset< + test::minimal::assignable, + test::minimal::hash, + test::minimal::equal_to, + test::minimal::allocator > multiset; + + unordered_equivalent_test(multiset, assignable); + unordered_set_test(multiset, assignable); + unordered_test(multiset, assignable, assignable, hash, equal_to); +} + +int main() { + test0(); + test1(); + test2(); return boost::report_errors(); }