blob: eb78cc375a6cb36a08e3a5df57c43d0fe9a0e2a5 [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 "./compile_time.hpp"
16
17void void_func1() { static int x = 1; ++x; }
18void void_func2() { static int x = 2; --x; }
19int int_func1(int) { return 0; }
20int int_func2(int) { return 1; }
21
22void function_pointer_tests()
23{
24 compile_time_tests((void(**)()) 0);
25 compile_time_tests((int(**)(int)) 0);
26
27 BOOST_HASH_TEST_NAMESPACE::hash<void(*)()> hasher_void;
28 BOOST_HASH_TEST_NAMESPACE::hash<int(*)(int)> hasher_int;
29
30 BOOST_TEST(&void_func1 != &void_func2);
31 BOOST_TEST(&int_func1 != &int_func2);
32
33 BOOST_TEST(hasher_void(0) == hasher_void(0));
34 BOOST_TEST(hasher_void(&void_func1) == hasher_void(&void_func1));
35 BOOST_TEST(hasher_void(&void_func1) != hasher_void(&void_func2));
36 BOOST_TEST(hasher_void(&void_func1) != hasher_void(0));
37 BOOST_TEST(hasher_int(0) == hasher_int(0));
38 BOOST_TEST(hasher_int(&int_func1) == hasher_int(&int_func1));
39 BOOST_TEST(hasher_int(&int_func1) != hasher_int(&int_func2));
40 BOOST_TEST(hasher_int(&int_func1) != hasher_int(0));
41#if defined(BOOST_HASH_TEST_EXTENSIONS)
42 BOOST_TEST(hasher_void(&void_func1)
43 == BOOST_HASH_TEST_NAMESPACE::hash_value(&void_func1));
44 BOOST_TEST(hasher_int(&int_func1)
45 == BOOST_HASH_TEST_NAMESPACE::hash_value(&int_func1));
46
47 // This isn't specified in Peter's proposal:
48 BOOST_TEST(hasher_void(0) == 0);
49#endif
50}
51
52int main()
53{
54 function_pointer_tests();
55
56 return ndnboost::report_errors();
57}