blob: 73e76af5c2175cc41a5ed361eb903d017a7b0218 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
2// Copyright 2005-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#include "./config.hpp"
7
8#ifdef BOOST_HASH_TEST_STD_INCLUDES
9# include <functional>
10#else
11# include <boost/functional/hash.hpp>
12#endif
13
14#include <boost/detail/lightweight_test.hpp>
15#include <string>
16#include "./compile_time.hpp"
17
18void string_tests()
19{
20 compile_time_tests((std::string*) 0);
21
22 BOOST_HASH_TEST_NAMESPACE::hash<std::string> x1;
23 BOOST_HASH_TEST_NAMESPACE::hash<std::string> x2;
24
25 BOOST_TEST(x1("Hello") == x2(std::string("Hel") + "lo"));
26 BOOST_TEST(x1("") == x2(std::string()));
27
28#if defined(BOOST_HASH_TEST_EXTENSIONS)
29 std::string value1;
30 std::string value2("Hello");
31
32 BOOST_TEST(x1(value1) == BOOST_HASH_TEST_NAMESPACE::hash_value(value1));
33 BOOST_TEST(x1(value2) == BOOST_HASH_TEST_NAMESPACE::hash_value(value2));
34 BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(value1) ==
35 BOOST_HASH_TEST_NAMESPACE::hash_range(value1.begin(), value1.end()));
36 BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(value2) ==
37 BOOST_HASH_TEST_NAMESPACE::hash_range(value2.begin(), value2.end()));
38#endif
39}
40
41#if !defined(BOOST_NO_STD_WSTRING)
42void wstring_tests()
43{
44 compile_time_tests((std::wstring*) 0);
45
46 BOOST_HASH_TEST_NAMESPACE::hash<std::wstring> x1;
47 BOOST_HASH_TEST_NAMESPACE::hash<std::wstring> x2;
48
49 BOOST_TEST(x1(L"Hello") == x2(std::wstring(L"Hel") + L"lo"));
50 BOOST_TEST(x1(L"") == x2(std::wstring()));
51
52#if defined(BOOST_HASH_TEST_EXTENSIONS)
53 std::wstring value1;
54 std::wstring value2(L"Hello");
55
56 BOOST_TEST(x1(value1) == BOOST_HASH_TEST_NAMESPACE::hash_value(value1));
57 BOOST_TEST(x1(value2) == BOOST_HASH_TEST_NAMESPACE::hash_value(value2));
58 BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(value1) ==
59 BOOST_HASH_TEST_NAMESPACE::hash_range(value1.begin(), value1.end()));
60 BOOST_TEST(BOOST_HASH_TEST_NAMESPACE::hash_value(value2) ==
61 BOOST_HASH_TEST_NAMESPACE::hash_range(value2.begin(), value2.end()));
62#endif
63}
64#endif
65
66int main()
67{
68 string_tests();
69#if !defined(BOOST_NO_STD_WSTRING)
70 wstring_tests();
71#endif
72 return ndnboost::report_errors();
73}