Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame^] | 1 | |
| 2 | // Copyright 2006-2009 Daniel James. |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | // This checks that template code implemented using hash_fwd will work. |
| 7 | |
| 8 | #include "./config.hpp" |
| 9 | |
| 10 | #include "./hash_fwd_test.hpp" |
| 11 | |
| 12 | #include <boost/detail/lightweight_test.hpp> |
| 13 | |
| 14 | #if defined(BOOST_HASH_TEST_EXTENSIONS) && !defined(BOOST_HASH_TEST_STD_INCLUDES) |
| 15 | |
| 16 | #include <boost/functional/hash.hpp> |
| 17 | #include <string> |
| 18 | |
| 19 | void fwd_test1() |
| 20 | { |
| 21 | test::test_type1<int> x(5); |
| 22 | test::test_type1<std::string> y("Test"); |
| 23 | |
| 24 | BOOST_HASH_TEST_NAMESPACE::hash<int> hasher_int; |
| 25 | BOOST_HASH_TEST_NAMESPACE::hash<std::string> hasher_string; |
| 26 | BOOST_HASH_TEST_NAMESPACE::hash<test::test_type1<int> > hasher_test_int; |
| 27 | BOOST_HASH_TEST_NAMESPACE::hash<test::test_type1<std::string> > hasher_test_string; |
| 28 | |
| 29 | BOOST_TEST(hasher_int(5) == hasher_test_int(x)); |
| 30 | BOOST_TEST(hasher_string("Test") == hasher_test_string(y)); |
| 31 | } |
| 32 | |
| 33 | void fwd_test2() |
| 34 | { |
| 35 | test::test_type2<int> x(5, 10); |
| 36 | test::test_type2<std::string> y("Test1", "Test2"); |
| 37 | |
| 38 | std::size_t seed1 = 0; |
| 39 | BOOST_HASH_TEST_NAMESPACE::hash_combine(seed1, 5); |
| 40 | BOOST_HASH_TEST_NAMESPACE::hash_combine(seed1, 10); |
| 41 | |
| 42 | std::size_t seed2 = 0; |
| 43 | BOOST_HASH_TEST_NAMESPACE::hash_combine(seed2, std::string("Test1")); |
| 44 | BOOST_HASH_TEST_NAMESPACE::hash_combine(seed2, std::string("Test2")); |
| 45 | |
| 46 | BOOST_HASH_TEST_NAMESPACE::hash<test::test_type2<int> > hasher_test_int; |
| 47 | BOOST_HASH_TEST_NAMESPACE::hash<test::test_type2<std::string> > hasher_test_string; |
| 48 | |
| 49 | BOOST_TEST(seed1 == hasher_test_int(x)); |
| 50 | BOOST_TEST(seed2 == hasher_test_string(y)); |
| 51 | } |
| 52 | |
| 53 | void fwd_test3() |
| 54 | { |
| 55 | std::vector<int> values1; |
| 56 | values1.push_back(10); |
| 57 | values1.push_back(15); |
| 58 | values1.push_back(20); |
| 59 | values1.push_back(3); |
| 60 | |
| 61 | std::vector<std::string> values2; |
| 62 | values2.push_back("Chico"); |
| 63 | values2.push_back("Groucho"); |
| 64 | values2.push_back("Harpo"); |
| 65 | values2.push_back("Gummo"); |
| 66 | values2.push_back("Zeppo"); |
| 67 | |
| 68 | test::test_type3<int> x(values1.begin(), values1.end()); |
| 69 | test::test_type3<std::string> y(values2.begin(), values2.end()); |
| 70 | |
| 71 | std::size_t seed1 = |
| 72 | BOOST_HASH_TEST_NAMESPACE::hash_range(values1.begin(), values1.end()); |
| 73 | BOOST_HASH_TEST_NAMESPACE::hash_range(seed1, values1.begin(), values1.end()); |
| 74 | |
| 75 | std::size_t seed2 = |
| 76 | BOOST_HASH_TEST_NAMESPACE::hash_range(values2.begin(), values2.end()); |
| 77 | BOOST_HASH_TEST_NAMESPACE::hash_range(seed2, values2.begin(), values2.end()); |
| 78 | |
| 79 | BOOST_HASH_TEST_NAMESPACE::hash<test::test_type3<int> > hasher_test_int; |
| 80 | BOOST_HASH_TEST_NAMESPACE::hash<test::test_type3<std::string> > hasher_test_string; |
| 81 | |
| 82 | BOOST_TEST(seed1 == hasher_test_int(x)); |
| 83 | BOOST_TEST(seed2 == hasher_test_string(y)); |
| 84 | } |
| 85 | |
| 86 | #endif |
| 87 | |
| 88 | int main() |
| 89 | { |
| 90 | #ifdef BOOST_HASH_TEST_EXTENSIONS |
| 91 | fwd_test1(); |
| 92 | fwd_test2(); |
| 93 | fwd_test3(); |
| 94 | #endif |
| 95 | return ndnboost::report_errors(); |
| 96 | } |