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