1 #include "gmock/internal/gmock-pp.h"
2 
3 // Used to test MSVC treating __VA_ARGS__ with a comma in it as one value
4 #define GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_comma ,
5 #define GMOCK_TEST_REPLACE_comma_WITH_COMMA(x) \
6   GMOCK_PP_CAT(GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_, x)
7 
8 // Static assertions.
9 namespace testing {
10 namespace internal {
11 namespace gmockpp {
12 
13 static_assert(GMOCK_PP_CAT(1, 4) == 14, "");
14 static_assert(GMOCK_PP_INTERNAL_INTERNAL_16TH(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
15                                               12, 13, 14, 15, 16, 17, 18) == 16,
16               "");
17 static_assert(GMOCK_PP_NARG() == 1, "");
18 static_assert(GMOCK_PP_NARG(x) == 1, "");
19 static_assert(GMOCK_PP_NARG(x, y) == 2, "");
20 static_assert(GMOCK_PP_NARG(x, y, z) == 3, "");
21 static_assert(GMOCK_PP_NARG(x, y, z, w) == 4, "");
22 static_assert(!GMOCK_PP_HAS_COMMA(), "");
23 static_assert(GMOCK_PP_HAS_COMMA(b, ), "");
24 static_assert(!GMOCK_PP_HAS_COMMA((, )), "");
25 static_assert(GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma)),
26               "");
27 static_assert(
28     GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma(unrelated))),
29     "");
30 static_assert(!GMOCK_PP_IS_EMPTY(, ), "");
31 static_assert(!GMOCK_PP_IS_EMPTY(a), "");
32 static_assert(!GMOCK_PP_IS_EMPTY(()), "");
33 static_assert(GMOCK_PP_IF(1, 1, 2) == 1, "");
34 static_assert(GMOCK_PP_IF(0, 1, 2) == 2, "");
35 static_assert(GMOCK_PP_NARG0(x) == 1, "");
36 static_assert(GMOCK_PP_NARG0(x, y) == 2, "");
37 static_assert(GMOCK_PP_HEAD(1) == 1, "");
38 static_assert(GMOCK_PP_HEAD(1, 2) == 1, "");
39 static_assert(GMOCK_PP_HEAD(1, 2, 3) == 1, "");
40 static_assert(GMOCK_PP_TAIL(1, 2) == 2, "");
41 static_assert(GMOCK_PP_HEAD(GMOCK_PP_TAIL(1, 2, 3)) == 2, "");
42 static_assert(!GMOCK_PP_IS_BEGIN_PARENS(sss), "");
43 static_assert(!GMOCK_PP_IS_BEGIN_PARENS(sss()), "");
44 static_assert(!GMOCK_PP_IS_BEGIN_PARENS(sss() sss), "");
45 static_assert(GMOCK_PP_IS_BEGIN_PARENS((sss)), "");
46 static_assert(GMOCK_PP_IS_BEGIN_PARENS((sss)ss), "");
47 static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS(sss), "");
48 static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS(sss()), "");
49 static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS(sss() sss), "");
50 static_assert(!GMOCK_PP_IS_ENCLOSED_PARENS((sss)ss), "");
51 static_assert(GMOCK_PP_REMOVE_PARENS((1 + 1)) * 2 == 3, "");
52 static_assert(GMOCK_PP_INC(4) == 5, "");
53 
54 template <class... Args>
55 struct Test {
56   static constexpr int kArgs = sizeof...(Args);
57 };
58 #define GMOCK_PP_INTERNAL_TYPE_TEST(_i, _Data, _element) \
59   GMOCK_PP_COMMA_IF(_i) _element
60 static_assert(Test<GMOCK_PP_FOR_EACH(GMOCK_PP_INTERNAL_TYPE_TEST, ~,
61                                      (int, float, double, char))>::kArgs == 4,
62               "");
63 #define GMOCK_PP_INTERNAL_VAR_TEST_1(_x) 1
64 #define GMOCK_PP_INTERNAL_VAR_TEST_2(_x, _y) 2
65 #define GMOCK_PP_INTERNAL_VAR_TEST_3(_x, _y, _z) 3
66 
67 #define GMOCK_PP_INTERNAL_VAR_TEST(...) \
68   GMOCK_PP_VARIADIC_CALL(GMOCK_PP_INTERNAL_VAR_TEST_, __VA_ARGS__)
69 static_assert(GMOCK_PP_INTERNAL_VAR_TEST(x, y) == 2, "");
70 static_assert(GMOCK_PP_INTERNAL_VAR_TEST(silly) == 1, "");
71 static_assert(GMOCK_PP_INTERNAL_VAR_TEST(x, y, z) == 3, "");
72 
73 // TODO(iserna): The following asserts fail in --config=lexan.
74 #define GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1
75 static_assert(GMOCK_PP_IS_EMPTY(GMOCK_PP_INTERNAL_IS_EMPTY_TEST_1), "");
76 static_assert(GMOCK_PP_IS_EMPTY(), "");
77 static_assert(GMOCK_PP_IS_ENCLOSED_PARENS((sss)), "");
78 static_assert(GMOCK_PP_IS_EMPTY(GMOCK_PP_TAIL(1)), "");
79 static_assert(GMOCK_PP_NARG0() == 0, "");
80 
81 }  // namespace gmockpp
82 }  // namespace internal
83 }  // namespace testing
84