Imported Upstream version 2.99.2
[platform/upstream/libsigc++.git] / tests / test_member_method_trait.cc
1 /* Copyright 2016, The libsigc++ Development Team
2  *  Assigned to public domain.  Use as you wish without restriction.
3  */
4
5 #include <cstdlib>
6 #include <sigc++/member_method_trait.h>
7 #include <type_traits>
8
9 namespace
10 {
11
12 class Something
13 {
14 public:
15   void some_func(int a);
16   void some_const_func(int a) const;
17   void some_volatile_func(int a) volatile;
18   void some_const_volatile_func(int a) const volatile;
19
20   int some_int_func();
21   bool some_bool_func();
22 };
23
24 } // end anonymous namespace
25
26 void test_member_method_is_const()
27 {
28   static_assert(!sigc::internal::member_method_is_const<decltype(&Something::some_func)>::value,
29     "member_method_is_const failed to identify a non-const member method.");
30
31   static_assert(!sigc::internal::member_method_is_const<decltype(&Something::some_volatile_func)>::value,
32     "member_method_is_const failed to identify a non-const member method.");
33
34   static_assert(sigc::internal::member_method_is_const<decltype(&Something::some_const_func)>::value,
35     "member_method_is_const failed to identify a const member method.");
36
37   static_assert(sigc::internal::member_method_is_const<decltype(&Something::some_const_volatile_func)>::value,
38     "member_method_is_const failed to identify a const member method.");
39 }
40
41 void test_member_method_is_volatile()
42 {
43   static_assert(!sigc::internal::member_method_is_volatile<decltype(&Something::some_func)>::value,
44     "member_method_is_const failed to identify a non-volatile member method.");
45
46   static_assert(!sigc::internal::member_method_is_volatile<decltype(&Something::some_const_func)>::value,
47     "member_method_is_const failed to identify a non-volatile member method.");
48
49   static_assert(sigc::internal::member_method_is_volatile<decltype(&Something::some_volatile_func)>::value,
50     "member_method_is_const failed to identify a volatile member method.");
51
52   static_assert(sigc::internal::member_method_is_volatile<decltype(&Something::some_const_volatile_func)>::value,
53     "member_method_is_const failed to identify a volatile member method.");
54 }
55
56 void test_member_method_class_type()
57 {
58   static_assert(std::is_same<
59     sigc::internal::member_method_class<decltype(&Something::some_func)>::type,
60     Something>::value,
61     "member_method_class_type failed to identify the class type.");
62 }
63
64 void test_member_method_result_type()
65 {
66   static_assert(std::is_same<
67     sigc::internal::member_method_result<decltype(&Something::some_int_func)>::type,
68     int>::value,
69     "member_method_result_type failed to identify the result type.");
70
71   static_assert(std::is_same<
72     sigc::internal::member_method_result<decltype(&Something::some_bool_func)>::type,
73     bool>::value,
74     "member_method_result_type failed to identify the result type.");
75 }
76
77 int main()
78 {
79   test_member_method_is_const();
80   test_member_method_is_volatile();
81
82   test_member_method_class_type();
83   test_member_method_result_type();
84
85   return EXIT_SUCCESS;
86 }