diff options
Diffstat (limited to 'libs/functional/hash/test')
-rw-r--r-- | libs/functional/hash/test/Jamfile.v2 | 80 | ||||
-rw-r--r-- | libs/functional/hash/test/deprecated_container_fwd.cpp | 14 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_complex_test.cpp | 4 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_float_test.hpp | 4 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_map_test.cpp | 2 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_number_test.cpp | 4 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_std_array_test.cpp | 103 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_std_smart_ptr_test.cpp | 80 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_std_tuple_test.cpp | 77 | ||||
-rw-r--r-- | libs/functional/hash/test/hash_type_index_test.cpp | 13 | ||||
-rw-r--r-- | libs/functional/hash/test/implicit_test.cpp (renamed from libs/functional/hash/test/implicit_fail_test.cpp) | 0 |
11 files changed, 331 insertions, 50 deletions
diff --git a/libs/functional/hash/test/Jamfile.v2 b/libs/functional/hash/test/Jamfile.v2 index 7b3ccd9cf2..fc731d26f6 100644 --- a/libs/functional/hash/test/Jamfile.v2 +++ b/libs/functional/hash/test/Jamfile.v2 @@ -10,8 +10,8 @@ project hash-tests <warnings>all <toolset>intel:<warnings>on <toolset>intel:<cxxflags>-strict-ansi - <toolset>gcc:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" - <toolset>darwin:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion" + <toolset>gcc:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" + <toolset>darwin:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" <toolset>msvc:<warnings-as-errors>on #<toolset>gcc:<warnings-as-errors>on #<toolset>darwin:<warnings-as-errors>on @@ -19,49 +19,39 @@ project hash-tests test-suite functional/hash : - [ run hash_fwd_test_1.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_fwd_test_2.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_number_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_pointer_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_function_pointer_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_float_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_long_double_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_string_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_range_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_custom_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_global_namespace_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_friend_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_built_in_array_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_value_array_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_vector_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_list_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_deque_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_set_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_map_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_complex_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_type_index_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run link_test.cpp link_test_2.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run link_ext_test.cpp link_no_ext_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run extensions_hpp_test.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail hash_no_ext_fail_test.cpp : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail namespace_fail_test.cpp : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ compile-fail implicit_fail_test.cpp : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_no_ext_macro_1.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - [ run hash_no_ext_macro_2.cpp : : : <define>BOOST_HASH_NO_IMPLICIT_CASTS ] - ; - -test-suite functional/hash_implicit_casts - : - [ run hash_number_test.cpp : : : : implicit_number ] - [ run hash_pointer_test.cpp : : : : implicit_pointer ] - [ run hash_function_pointer_test.cpp : : : : implicit_function_pointer ] - [ run hash_float_test.cpp : : : : implicit_float ] - [ run hash_string_test.cpp : : : : implicit_string ] - [ run hash_range_test.cpp : : : : implicit_range ] - [ run hash_custom_test.cpp : : : : implicit_custom ] - [ run hash_built_in_array_test.cpp : : : : implicit_built_in_array ] - [ run link_test.cpp link_test_2.cpp : : : : implicit_link ] - [ run implicit_fail_test.cpp : : : : implicit_test ] + [ run hash_fwd_test_1.cpp ] + [ run hash_fwd_test_2.cpp ] + [ run hash_number_test.cpp ] + [ run hash_pointer_test.cpp ] + [ run hash_function_pointer_test.cpp ] + [ run hash_float_test.cpp ] + [ run hash_long_double_test.cpp ] + [ run hash_string_test.cpp ] + [ run hash_range_test.cpp ] + [ run hash_custom_test.cpp ] + [ run hash_global_namespace_test.cpp ] + [ run hash_friend_test.cpp ] + [ run hash_built_in_array_test.cpp ] + [ run hash_value_array_test.cpp ] + [ run hash_vector_test.cpp ] + [ run hash_list_test.cpp ] + [ run hash_deque_test.cpp ] + [ run hash_set_test.cpp ] + [ run hash_map_test.cpp ] + [ run hash_complex_test.cpp ] + [ run hash_type_index_test.cpp ] + [ run hash_std_array_test.cpp ] + [ run hash_std_tuple_test.cpp ] + [ run hash_std_smart_ptr_test.cpp ] + [ run link_test.cpp link_test_2.cpp ] + [ run link_ext_test.cpp link_no_ext_test.cpp ] + [ run extensions_hpp_test.cpp ] + [ compile-fail hash_no_ext_fail_test.cpp ] + [ compile-fail namespace_fail_test.cpp ] + [ run implicit_test.cpp ] + [ run hash_no_ext_macro_1.cpp ] + [ run hash_no_ext_macro_2.cpp ] + [ compile deprecated_container_fwd.cpp ] ; test-suite functional/hash_no_ext diff --git a/libs/functional/hash/test/deprecated_container_fwd.cpp b/libs/functional/hash/test/deprecated_container_fwd.cpp new file mode 100644 index 0000000000..1c6e12b7da --- /dev/null +++ b/libs/functional/hash/test/deprecated_container_fwd.cpp @@ -0,0 +1,14 @@ + +// Copyright 2012 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 <boost/functional/detail/container_fwd.hpp> + +typedef std::vector<int, std::allocator<int> > int_vector; + +#include <vector> + +int main() { + int_vector x; +} diff --git a/libs/functional/hash/test/hash_complex_test.cpp b/libs/functional/hash/test/hash_complex_test.cpp index 67e2aff0b0..bb1592cffc 100644 --- a/libs/functional/hash/test/hash_complex_test.cpp +++ b/libs/functional/hash/test/hash_complex_test.cpp @@ -35,6 +35,10 @@ int main() {} #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + #include <complex> #include <sstream> #include <boost/limits.hpp> diff --git a/libs/functional/hash/test/hash_float_test.hpp b/libs/functional/hash/test/hash_float_test.hpp index dd1358e108..c608915103 100644 --- a/libs/functional/hash/test/hash_float_test.hpp +++ b/libs/functional/hash/test/hash_float_test.hpp @@ -30,6 +30,10 @@ #endif #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + char const* float_type(float*) { return "float"; } char const* float_type(double*) { return "double"; } char const* float_type(long double*) { return "long double"; } diff --git a/libs/functional/hash/test/hash_map_test.cpp b/libs/functional/hash/test/hash_map_test.cpp index 2f813c3af0..7e117c72a6 100644 --- a/libs/functional/hash/test/hash_map_test.cpp +++ b/libs/functional/hash/test/hash_map_test.cpp @@ -27,7 +27,7 @@ using std::multimap; #define CONTAINER_TYPE multimap #include "./hash_map_test.hpp" -#endif // TEST_EXTENSTIONS +#endif // TEST_EXTENSIONS int main() { diff --git a/libs/functional/hash/test/hash_number_test.cpp b/libs/functional/hash/test/hash_number_test.cpp index b989d22c30..b233c71b4d 100644 --- a/libs/functional/hash/test/hash_number_test.cpp +++ b/libs/functional/hash/test/hash_number_test.cpp @@ -28,6 +28,10 @@ #pragma warning(disable:4310) // cast truncates constant value #endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + template <class T> void numeric_test(T*) { diff --git a/libs/functional/hash/test/hash_std_array_test.cpp b/libs/functional/hash/test/hash_std_array_test.cpp new file mode 100644 index 0000000000..6f67a67e37 --- /dev/null +++ b/libs/functional/hash/test/hash_std_array_test.cpp @@ -0,0 +1,103 @@ + +// Copyright 2012 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include <functional> +# else +# include <boost/functional/hash.hpp> +# endif +#endif + +#include <boost/config.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_ARRAY) +#define TEST_ARRAY +#include <array> +#include <vector> +#endif + +#ifdef TEST_ARRAY + +template <typename T> +void array_tests(T const& v) { + boost::hash<typename T::value_type> hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_array_test() { +/* + boost::hash<std::array<int, 0> > empty_array_hash; + std::array<int, 0> empty_array; + BOOST_TEST(empty_array_hash(empty_array) == boost::hash_value(empty_array)); +*/ +} + +void int_1_array_test() +{ + std::vector<std::array<int, 1> > arrays; + std::array<int, 1> val; + val[0] = 0; + arrays.push_back(val); + val[0] = 1; + arrays.push_back(val); + val[0] = 2; + arrays.push_back(val); + array_tests(arrays); +} + +void string_1_array_test() +{ + std::vector<std::array<std::string, 1> > arrays; + std::array<std::string, 1> val; + arrays.push_back(val); + val[0] = "one"; + arrays.push_back(val); + val[0] = "two"; + arrays.push_back(val); + array_tests(arrays); +} + +void string_3_array_test() +{ + std::vector<std::array<std::string,3 > > arrays; + std::array<std::string, 3> val; + arrays.push_back(val); + val[0] = "one"; + arrays.push_back(val); + val[0] = ""; val[1] = "one"; val[2] = ""; + arrays.push_back(val); + val[0] = ""; val[1] = ""; val[2] = "one"; + arrays.push_back(val); + val[0] = "one"; val[1] = "one"; val[2] = "one"; + arrays.push_back(val); + val[0] = "one"; val[1] = "two"; val[2] = "three"; + arrays.push_back(val); + array_tests(arrays); +} + +#endif // TEST_ARRAY + +int main() +{ +#ifdef TEST_ARRAY + empty_array_test(); + int_1_array_test(); + string_1_array_test(); + string_3_array_test(); +#endif + + return boost::report_errors(); +} diff --git a/libs/functional/hash/test/hash_std_smart_ptr_test.cpp b/libs/functional/hash/test/hash_std_smart_ptr_test.cpp new file mode 100644 index 0000000000..74525854f8 --- /dev/null +++ b/libs/functional/hash/test/hash_std_smart_ptr_test.cpp @@ -0,0 +1,80 @@ + +// Copyright 2012 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 "./config.hpp" + +#ifdef TEST_STD_INCLUDES +# include <functional> +#else +# include <boost/functional/hash.hpp> +#endif + +#include <boost/detail/lightweight_test.hpp> +#include "./compile_time.hpp" + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_SMART_PTR) +#define TEST_SMART_PTRS +#include <memory> +#endif + +#ifdef TEST_SMART_PTRS + +void shared_ptr_tests() +{ + std::shared_ptr<int> x; + compile_time_tests(&x); + + HASH_NAMESPACE::hash<std::shared_ptr<int> > x1; + HASH_NAMESPACE::hash<std::shared_ptr<int> > x2; + + std::shared_ptr<int> ptr1(new int(10)); + std::shared_ptr<int> ptr2; + + BOOST_TEST(x1(x) == x2(ptr2)); + BOOST_TEST(x1(x) != x2(ptr1)); + ptr2.reset(new int(10)); + BOOST_TEST(x1(ptr1) == x2(ptr1)); + BOOST_TEST(x1(ptr1) != x2(ptr2)); + ptr2 = ptr1; + BOOST_TEST(x1(ptr1) == x2(ptr2)); +#if defined(TEST_EXTENSIONS) + BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x)); + BOOST_TEST(x1(ptr1) == HASH_NAMESPACE::hash_value(ptr2)); +#endif +} + +void unique_ptr_tests() +{ + std::unique_ptr<int> x; + compile_time_tests(&x); + + HASH_NAMESPACE::hash<std::unique_ptr<int> > x1; + HASH_NAMESPACE::hash<std::unique_ptr<int> > x2; + + std::unique_ptr<int> ptr1(new int(10)); + std::unique_ptr<int> ptr2; + + BOOST_TEST(x1(x) == x2(ptr2)); + BOOST_TEST(x1(x) != x2(ptr1)); + ptr2.reset(new int(10)); + BOOST_TEST(x1(ptr1) == x2(ptr1)); + BOOST_TEST(x1(ptr1) != x2(ptr2)); + +#if defined(TEST_EXTENSIONS) + BOOST_TEST(x1(x) == HASH_NAMESPACE::hash_value(x)); +#endif +} + +#endif + +int main() +{ +#ifdef TEST_SMART_PTRS + shared_ptr_tests(); + unique_ptr_tests(); +#endif + + return boost::report_errors(); +} diff --git a/libs/functional/hash/test/hash_std_tuple_test.cpp b/libs/functional/hash/test/hash_std_tuple_test.cpp new file mode 100644 index 0000000000..9314336af5 --- /dev/null +++ b/libs/functional/hash/test/hash_std_tuple_test.cpp @@ -0,0 +1,77 @@ + +// Copyright 2012 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 "./config.hpp" + +#ifdef TEST_EXTENSIONS +# ifdef TEST_STD_INCLUDES +# include <functional> +# else +# include <boost/functional/hash.hpp> +# endif +#endif + +#include <boost/config.hpp> +#include <boost/detail/lightweight_test.hpp> + +#if defined(TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_HDR_TUPLE) +#define TEST_TUPLE +#include <tuple> +#include <vector> +#endif + +#ifdef TEST_TUPLE + +template <typename T> +void tuple_tests(T const& v) { + boost::hash<typename T::value_type> hf; + for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) { + for(typename T::const_iterator j = v.begin(); j != v.end(); ++j) { + if (i != j) + BOOST_TEST(hf(*i) != hf(*j)); + else + BOOST_TEST(hf(*i) == hf(*j)); + } + } +} + +void empty_tuple_test() { + boost::hash<std::tuple<> > empty_tuple_hash; + std::tuple<> empty_tuple; + BOOST_TEST(empty_tuple_hash(empty_tuple) == boost::hash_value(empty_tuple)); +} + +void int_tuple_test() { + std::vector<std::tuple<int> > int_tuples; + int_tuples.push_back(std::make_tuple(0)); + int_tuples.push_back(std::make_tuple(1)); + int_tuples.push_back(std::make_tuple(2)); + tuple_tests(int_tuples); +} + +void int_string_tuple_test() { + std::vector<std::tuple<int, std::string> > int_string_tuples; + int_string_tuples.push_back(std::make_tuple(0, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(2, std::string("two"))); + int_string_tuples.push_back(std::make_tuple(0, std::string("one"))); + int_string_tuples.push_back(std::make_tuple(1, std::string("zero"))); + int_string_tuples.push_back(std::make_tuple(0, std::string(""))); + int_string_tuples.push_back(std::make_tuple(1, std::string(""))); + tuple_tests(int_string_tuples); +} + +#endif // TEST_TUPLE + +int main() +{ +#ifdef TEST_TUPLE + empty_tuple_test(); + int_tuple_test(); + int_string_tuple_test(); +#endif + + return boost::report_errors(); +} diff --git a/libs/functional/hash/test/hash_type_index_test.cpp b/libs/functional/hash/test/hash_type_index_test.cpp index 7892918c42..27fcfff18f 100644 --- a/libs/functional/hash/test/hash_type_index_test.cpp +++ b/libs/functional/hash/test/hash_type_index_test.cpp @@ -13,17 +13,21 @@ #include <boost/config.hpp> #include <boost/detail/lightweight_test.hpp> -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) #include <typeindex> void test_type_index() { + HASH_NAMESPACE::hash<std::type_index> hasher; + +#if defined(BOOST_NO_TYPEID) + std::cout<<"Unable to test std::type_index, as typeid isn't available" + <<std::endl; +#else std::type_index int_index = typeid(int); std::type_index int2_index = typeid(int); std::type_index char_index = typeid(char); - HASH_NAMESPACE::hash<std::type_index> hasher; - BOOST_TEST(hasher(int_index) == int_index.hash_code()); BOOST_TEST(hasher(int_index) == int2_index.hash_code()); BOOST_TEST(hasher(char_index) == char_index.hash_code()); @@ -33,12 +37,13 @@ void test_type_index() { BOOST_TEST(hasher(int_index) == hasher(int2_index)); BOOST_TEST(hasher(int_index) != hasher(char_index)); +#endif } #endif int main() { -#if !defined(BOOST_NO_0X_HDR_TYPEINDEX) +#if !defined(BOOST_NO_CXX11_HDR_TYPEINDEX) test_type_index(); #else std::cout<<"<type_index> not available."<<std::endl; diff --git a/libs/functional/hash/test/implicit_fail_test.cpp b/libs/functional/hash/test/implicit_test.cpp index e48bbcdd18..e48bbcdd18 100644 --- a/libs/functional/hash/test/implicit_fail_test.cpp +++ b/libs/functional/hash/test/implicit_test.cpp |