gmock-pp_test.cc 3.4 KB

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