From 2000b1aed886a9f995eb6388402d5602b01b1643 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 7 Apr 2005 21:57:22 +0000 Subject: [PATCH] Change tests so they can be used to test implementations of TR1 (maybe, eventually). [SVN r28052] --- hash/test/Jamfile | 2 +- hash/test/compile_time.hpp | 2 +- hash/test/config.hpp | 13 +++++++++ hash/test/hash_custom_test.cpp | 23 +++++++++++---- hash/test/hash_deque_test.cpp | 14 ++++++++- hash/test/hash_float_test.cpp | 10 +++++-- hash/test/hash_list_test.cpp | 13 ++++++++- hash/test/hash_map_test.cpp | 13 ++++++++- hash/test/hash_map_test.hpp | 2 +- hash/test/hash_number_test.cpp | 12 ++++++-- hash/test/hash_pointer_test.cpp | 13 +++++++-- hash/test/hash_range_test.cpp | 50 ++++++++++++++++++++------------ hash/test/hash_sequence_test.hpp | 2 +- hash/test/hash_set_test.cpp | 14 ++++++++- hash/test/hash_set_test.hpp | 2 +- hash/test/hash_string_test.cpp | 16 ++++++---- hash/test/hash_vector_test.cpp | 14 ++++++++- 17 files changed, 167 insertions(+), 48 deletions(-) create mode 100644 hash/test/config.hpp diff --git a/hash/test/Jamfile b/hash/test/Jamfile index c5ad132..ef69bf1 100644 --- a/hash/test/Jamfile +++ b/hash/test/Jamfile @@ -8,7 +8,7 @@ subproject libs/functional/hash/test ; import testing ; -DEPENDS all : functional/hash ; +DEPENDS all : test ; rule hash-test ( name ) { diff --git a/hash/test/compile_time.hpp b/hash/test/compile_time.hpp index c4b1720..646d42b 100644 --- a/hash/test/compile_time.hpp +++ b/hash/test/compile_time.hpp @@ -11,7 +11,7 @@ template struct compile_time_tests { BOOST_MPL_ASSERT((boost::is_base_and_derived< - std::unary_function, boost::hash >)); + std::unary_function, HASH_NAMESPACE::hash >)); BOOST_STATIC_CONSTANT(bool, success = true); }; diff --git a/hash/test/config.hpp b/hash/test/config.hpp new file mode 100644 index 0000000..433c327 --- /dev/null +++ b/hash/test/config.hpp @@ -0,0 +1,13 @@ + +// (C) Copyright Daniel James 2005. +// Use, modification and distribution are subject to 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) + +#if defined(TEST_STD) +# define TEST_STD_INCLUDES +# define HASH_NAMESPACE std::tr1 +#else +# define HASH_NAMESPACE boost +# define TEST_EXTENSIONS +#endif diff --git a/hash/test/hash_custom_test.cpp b/hash/test/hash_custom_test.cpp index 282b830..eab9948 100644 --- a/hash/test/hash_custom_test.cpp +++ b/hash/test/hash_custom_test.cpp @@ -4,11 +4,21 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include +#ifdef TEST_EXTENSIONS + #include #include #include @@ -38,7 +48,7 @@ namespace boost BOOST_AUTO_UNIT_TEST(custom_tests) { - boost::hash custom_hasher; + HASH_NAMESPACE::hash custom_hasher; BOOST_CHECK(custom_hasher(10) == 100u); test::custom x(55); BOOST_CHECK(custom_hasher(x) == 550u); @@ -49,11 +59,12 @@ BOOST_AUTO_UNIT_TEST(custom_tests) custom_vector.push_back(35); std::size_t seed = 0; - boost::hash_combine(seed, test::custom(5)); - boost::hash_combine(seed, test::custom(25)); - boost::hash_combine(seed, test::custom(35)); + HASH_NAMESPACE::hash_combine(seed, test::custom(5)); + HASH_NAMESPACE::hash_combine(seed, test::custom(25)); + HASH_NAMESPACE::hash_combine(seed, test::custom(35)); BOOST_CHECK(seed == - boost::hash_range(custom_vector.begin(), custom_vector.end())); + HASH_NAMESPACE::hash_range(custom_vector.begin(), custom_vector.end())); } +#endif // TEST_EXTENSIONS diff --git a/hash/test/hash_deque_test.cpp b/hash/test/hash_deque_test.cpp index ac8e0bd..1cd7fe8 100644 --- a/hash/test/hash_deque_test.cpp +++ b/hash/test/hash_deque_test.cpp @@ -4,13 +4,25 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include +#ifdef TEST_EXTENSIONS + #include using std::deque; #define CONTAINER_TYPE deque #include "./hash_sequence_test.hpp" + +#endif // TEST_EXTENSIONS diff --git a/hash/test/hash_float_test.cpp b/hash/test/hash_float_test.cpp index 5f88a8d..1e2f8e0 100644 --- a/hash/test/hash_float_test.cpp +++ b/hash/test/hash_float_test.cpp @@ -3,7 +3,13 @@ // subject to 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include +#else +# include +#endif #define BOOST_AUTO_TEST_MAIN #include @@ -14,7 +20,7 @@ template void float_tests(T* = 0) { - boost::hash x1; + HASH_NAMESPACE::hash x1; T zero = 0; T minus_zero = (T) -1 * zero; diff --git a/hash/test/hash_list_test.cpp b/hash/test/hash_list_test.cpp index ecba931..bfa962b 100644 --- a/hash/test/hash_list_test.cpp +++ b/hash/test/hash_list_test.cpp @@ -4,14 +4,25 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include +#ifdef TEST_EXTENSIONS + #include using std::list; #define CONTAINER_TYPE list #include "./hash_sequence_test.hpp" +#endif // TEST_EXTENSIONS diff --git a/hash/test/hash_map_test.cpp b/hash/test/hash_map_test.cpp index fb8add3..ffce08f 100644 --- a/hash/test/hash_map_test.cpp +++ b/hash/test/hash_map_test.cpp @@ -4,13 +4,23 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include #include +#ifdef TEST_EXTENSIONS + using std::map; #define CONTAINER_TYPE map #include "./hash_map_test.hpp" @@ -19,3 +29,4 @@ using std::multimap; #define CONTAINER_TYPE multimap #include "./hash_map_test.hpp" +#endif // TEST_EXTENSTIONS diff --git a/hash/test/hash_map_test.hpp b/hash/test/hash_map_test.hpp index a5c37ee..09454e5 100644 --- a/hash/test/hash_map_test.hpp +++ b/hash/test/hash_map_test.hpp @@ -31,7 +31,7 @@ namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests) containers[9].insert(pair(-1,3)); containers[9].insert(pair(-1,3)); - boost::hash hasher; + HASH_NAMESPACE::hash hasher; for(int i2 = 0; i2 < number_of_containers; ++i2) { BOOST_CHECK(hasher(containers[i2]) == hasher(containers[i2])); diff --git a/hash/test/hash_number_test.cpp b/hash/test/hash_number_test.cpp index b85a4b8..af1accb 100644 --- a/hash/test/hash_number_test.cpp +++ b/hash/test/hash_number_test.cpp @@ -3,7 +3,13 @@ // subject to 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include +#else +# include +#endif #define BOOST_AUTO_TEST_MAIN #include @@ -20,8 +26,8 @@ void numeric_test() { BOOST_CHECK(compile_time_tests::success); - boost::hash x1; - boost::hash x2; + HASH_NAMESPACE::hash x1; + HASH_NAMESPACE::hash x2; BOOST_CHECK(x1(T(0)) == x2(T(0))); diff --git a/hash/test/hash_pointer_test.cpp b/hash/test/hash_pointer_test.cpp index 833c3af..2d661b4 100644 --- a/hash/test/hash_pointer_test.cpp +++ b/hash/test/hash_pointer_test.cpp @@ -1,9 +1,16 @@ + // (C) Copyright Daniel James 2005. // Use, modification and distribution are subject to 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include +#else +# include +#endif #define BOOST_AUTO_TEST_MAIN #include @@ -19,8 +26,8 @@ BOOST_AUTO_UNIT_TEST(pointer_tests) BOOST_CHECK(compile_time_tests::success); BOOST_CHECK(compile_time_tests::success); - boost::hash x1; - boost::hash x2; + HASH_NAMESPACE::hash x1; + HASH_NAMESPACE::hash x2; int int1; int int2; diff --git a/hash/test/hash_range_test.cpp b/hash/test/hash_range_test.cpp index e264267..48105a9 100644 --- a/hash/test/hash_range_test.cpp +++ b/hash/test/hash_range_test.cpp @@ -3,11 +3,21 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include +#ifdef TEST_EXTENSIONS + #include #include #include @@ -29,27 +39,29 @@ BOOST_AUTO_UNIT_TEST(hash_range_tests) values5.push_back(20); std::vector x; - BOOST_CHECK(boost::hash_range(empty.begin(), empty.end()) - == boost::hash_range(x.begin(), x.end())); - BOOST_CHECK(boost::hash_range(empty.begin(), empty.end()) - != boost::hash_range(values1.begin(), values1.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end()) + == HASH_NAMESPACE::hash_range(x.begin(), x.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end()) + != HASH_NAMESPACE::hash_range(values1.begin(), values1.end())); x.push_back(10); - BOOST_CHECK(boost::hash_range(empty.begin(), empty.end()) - != boost::hash_range(x.begin(), x.end())); - BOOST_CHECK(boost::hash_range(values2.begin(), values2.end()) - == boost::hash_range(x.begin(), x.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end()) + != HASH_NAMESPACE::hash_range(x.begin(), x.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(values2.begin(), values2.end()) + == HASH_NAMESPACE::hash_range(x.begin(), x.end())); x.push_back(20); - BOOST_CHECK(boost::hash_range(empty.begin(), empty.end()) - != boost::hash_range(x.begin(), x.end())); - BOOST_CHECK(boost::hash_range(values2.begin(), values2.end()) - != boost::hash_range(x.begin(), x.end())); - BOOST_CHECK(boost::hash_range(values3.begin(), values3.end()) - == boost::hash_range(x.begin(), x.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(empty.begin(), empty.end()) + != HASH_NAMESPACE::hash_range(x.begin(), x.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(values2.begin(), values2.end()) + != HASH_NAMESPACE::hash_range(x.begin(), x.end())); + BOOST_CHECK(HASH_NAMESPACE::hash_range(values3.begin(), values3.end()) + == HASH_NAMESPACE::hash_range(x.begin(), x.end())); - std::size_t seed = boost::hash_range(values3.begin(), values3.end()); - boost::hash_range(seed, values4.begin(), values4.end()); - boost::hash_range(seed, x.begin(), x.end()); - BOOST_CHECK(seed == boost::hash_range(values5.begin(), values5.end())); + std::size_t seed = HASH_NAMESPACE::hash_range(values3.begin(), values3.end()); + HASH_NAMESPACE::hash_range(seed, values4.begin(), values4.end()); + HASH_NAMESPACE::hash_range(seed, x.begin(), x.end()); + BOOST_CHECK(seed == HASH_NAMESPACE::hash_range(values5.begin(), values5.end())); } + +#endif diff --git a/hash/test/hash_sequence_test.hpp b/hash/test/hash_sequence_test.hpp index fd156af..f6dbae7 100644 --- a/hash/test/hash_sequence_test.hpp +++ b/hash/test/hash_sequence_test.hpp @@ -34,7 +34,7 @@ namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests) containers[10].push_back(-1); containers[10].push_back(1); - boost::hash hasher; + HASH_NAMESPACE::hash hasher; for(int i2 = 0; i2 < number_of_containers; ++i2) { BOOST_CHECK(hasher(containers[i2]) == hasher(containers[i2])); diff --git a/hash/test/hash_set_test.cpp b/hash/test/hash_set_test.cpp index 3b12f54..df54894 100644 --- a/hash/test/hash_set_test.cpp +++ b/hash/test/hash_set_test.cpp @@ -4,11 +4,21 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include +#ifdef TEST_EXTENSIONS + #include using std::set; @@ -18,3 +28,5 @@ using std::set; using std::multiset; #define CONTAINER_TYPE multiset #include "./hash_set_test.hpp" + +#endif diff --git a/hash/test/hash_set_test.hpp b/hash/test/hash_set_test.hpp index 7f2577b..2681587 100644 --- a/hash/test/hash_set_test.hpp +++ b/hash/test/hash_set_test.hpp @@ -32,7 +32,7 @@ namespace BOOST_PP_CAT(CONTAINER_TYPE, _tests) containers[10].insert(-1); containers[10].insert(1); - boost::hash hasher; + HASH_NAMESPACE::hash hasher; for(int i2 = 0; i2 < number_of_containers; ++i2) { BOOST_CHECK(hasher(containers[i2]) == hasher(containers[i2])); diff --git a/hash/test/hash_string_test.cpp b/hash/test/hash_string_test.cpp index c08a8e1..ae55682 100644 --- a/hash/test/hash_string_test.cpp +++ b/hash/test/hash_string_test.cpp @@ -3,7 +3,13 @@ // 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include +#else +# include +#endif #define BOOST_AUTO_TEST_MAIN #include @@ -18,8 +24,8 @@ BOOST_AUTO_UNIT_TEST(string_tests) { BOOST_CHECK(compile_time_tests::success); - boost::hash x1; - boost::hash x2; + HASH_NAMESPACE::hash x1; + HASH_NAMESPACE::hash x2; BOOST_CHECK(x1("Hello") == x2(std::string("Hel") + "lo")); BOOST_CHECK(x1("") == x2(std::string())); @@ -30,8 +36,8 @@ BOOST_AUTO_UNIT_TEST(wstring_tests) { BOOST_CHECK(compile_time_tests::success); - boost::hash x1; - boost::hash x2; + HASH_NAMESPACE::hash x1; + HASH_NAMESPACE::hash x2; BOOST_CHECK(x1(L"Hello") == x2(std::wstring(L"Hel") + L"lo")); BOOST_CHECK(x1(L"") == x2(std::wstring())); diff --git a/hash/test/hash_vector_test.cpp b/hash/test/hash_vector_test.cpp index 6337439..9e275bc 100644 --- a/hash/test/hash_vector_test.cpp +++ b/hash/test/hash_vector_test.cpp @@ -4,13 +4,25 @@ // 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include +# else +# include +# endif +#endif #define BOOST_AUTO_TEST_MAIN #include +#ifdef TEST_EXTENSIONS + #include using std::vector; #define CONTAINER_TYPE vector #include "./hash_sequence_test.hpp" + +#endif // TEST_EXTENSIONS