1
2// Copyright 2012 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/container_hash/hash.hpp>
12#endif
13
14#include <boost/core/lightweight_test.hpp>
15#include "./compile_time.hpp"
16
17#if defined(BOOST_HASH_TEST_EXTENSIONS) && !defined(BOOST_NO_CXX11_SMART_PTR)
18#define TEST_SMART_PTRS
19#include <memory>
20#endif
21
22#ifdef TEST_SMART_PTRS
23
24void shared_ptr_tests()
25{
26 std::shared_ptr<int> x;
27 compile_time_tests(&x);
28
29 BOOST_HASH_TEST_NAMESPACE::hash<std::shared_ptr<int> > x1;
30 BOOST_HASH_TEST_NAMESPACE::hash<std::shared_ptr<int> > x2;
31
32 std::shared_ptr<int> ptr1(new int(10));
33 std::shared_ptr<int> ptr2;
34
35 BOOST_TEST(x1(x) == x2(ptr2));
36 BOOST_TEST(x1(x) != x2(ptr1));
37 ptr2.reset(p: new int(10));
38 BOOST_TEST(x1(ptr1) == x2(ptr1));
39 BOOST_TEST(x1(ptr1) != x2(ptr2));
40 ptr2 = ptr1;
41 BOOST_TEST(x1(ptr1) == x2(ptr2));
42#if defined(BOOST_HASH_TEST_EXTENSIONS)
43 BOOST_TEST(x1(x) == BOOST_HASH_TEST_NAMESPACE::hash_value(x));
44 BOOST_TEST(x1(ptr1) == BOOST_HASH_TEST_NAMESPACE::hash_value(ptr2));
45#endif
46}
47
48void unique_ptr_tests()
49{
50 std::unique_ptr<int> x;
51 compile_time_tests(&x);
52
53 BOOST_HASH_TEST_NAMESPACE::hash<std::unique_ptr<int> > x1;
54 BOOST_HASH_TEST_NAMESPACE::hash<std::unique_ptr<int> > x2;
55
56 std::unique_ptr<int> ptr1(new int(10));
57 std::unique_ptr<int> ptr2;
58
59 BOOST_TEST(x1(x) == x2(ptr2));
60 BOOST_TEST(x1(x) != x2(ptr1));
61 ptr2.reset(p: new int(10));
62 BOOST_TEST(x1(ptr1) == x2(ptr1));
63 BOOST_TEST(x1(ptr1) != x2(ptr2));
64
65#if defined(BOOST_HASH_TEST_EXTENSIONS)
66 BOOST_TEST(x1(x) == BOOST_HASH_TEST_NAMESPACE::hash_value(x));
67#endif
68}
69
70#endif
71
72int main()
73{
74#ifdef TEST_SMART_PTRS
75 shared_ptr_tests();
76 unique_ptr_tests();
77#endif
78
79 return boost::report_errors();
80}
81

source code of boost/libs/container_hash/test/hash_std_smart_ptr_test.cpp