]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stacktrace/test/test_void_ptr_cast.cpp
1 // Copyright 2017 Antony Polukhin.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/stacktrace/detail/void_ptr_cast.hpp>
9 #include <boost/core/lightweight_test.hpp>
11 int foo1_func(int) { return 0; }
12 void foo2_func(int, int, ...) {}
15 int foo1_memb(int) const { return 0; }
16 void foo2_memb(int, int, ...) {}
19 template <class F1
, class F2
>
20 void test(F1 foo1
, F2 foo2
) {
21 using boost::stacktrace::detail::void_ptr_cast
;
23 typedef void(*void_f_ptr
)();
25 // Function/variable to void(*)()
26 void_f_ptr fp1
= void_ptr_cast
<void_f_ptr
>(foo1
);
27 void_f_ptr fp2
= void_ptr_cast
<void_f_ptr
>(foo2
);
30 BOOST_TEST(fp1
!= fp2
);
32 // Function/variable to void*
33 void* vp1
= void_ptr_cast
<void*>(foo1
);
34 void* vp2
= void_ptr_cast
<void*>(foo2
);
37 BOOST_TEST(vp1
!= vp2
);
40 void_f_ptr fp1_2
= void_ptr_cast
<void_f_ptr
>(vp1
);
41 void_f_ptr fp2_2
= void_ptr_cast
<void_f_ptr
>(vp2
);
44 BOOST_TEST(fp1_2
!= fp2_2
);
45 BOOST_TEST(fp1
== fp1_2
);
46 BOOST_TEST(fp2
== fp2_2
);
49 BOOST_TEST(void_ptr_cast
<void*>(fp1
) == vp1
);
50 BOOST_TEST(void_ptr_cast
<void*>(fp2
) == vp2
);
52 // void(*)() to function/variable
53 BOOST_TEST(void_ptr_cast
<F1
>(fp1
) == foo1
);
54 BOOST_TEST(void_ptr_cast
<F2
>(fp2
) == foo2
);
56 // void* to function/variable
57 BOOST_TEST(void_ptr_cast
<F1
>(vp1
) == foo1
);
58 BOOST_TEST(void_ptr_cast
<F2
>(vp2
) == foo2
);
62 // Testing for functions
63 test(foo1_func
, foo2_func
);
65 typedef void(func_t
)();
67 boost::stacktrace::detail::void_ptr_cast
<func_t
* const>(foo1_func
),
68 boost::stacktrace::detail::void_ptr_cast
<func_t
* const>(foo2_func
)
71 // Testing for variables (just in case...)
78 return boost::report_errors();