diff options
author | Abseil Team <absl-team@google.com> | 2018-11-16 18:03:03 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-11-20 18:29:40 (GMT) |
commit | 5dab7be70d628ad8079f915ab5bd3753dea1af2b (patch) | |
tree | 9ca927326d6357c7f5b9e9494bdf6d5ec29298c8 /googlemock/include | |
parent | 45d66d81bec9edd1256b6edb7e519602b1d0d6de (diff) | |
download | googletest-5dab7be70d628ad8079f915ab5bd3753dea1af2b.zip googletest-5dab7be70d628ad8079f915ab5bd3753dea1af2b.tar.gz googletest-5dab7be70d628ad8079f915ab5bd3753dea1af2b.tar.bz2 |
Googletest export
Validate spec modifiers.
PiperOrigin-RevId: 221810235
Diffstat (limited to 'googlemock/include')
-rw-r--r-- | googlemock/include/gmock/gmock-function-mocker.h | 23 | ||||
-rw-r--r-- | googlemock/include/gmock/internal/gmock-pp.h | 4 |
2 files changed, 20 insertions, 7 deletions
diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index 953d746..3d14204 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -45,9 +45,10 @@ "enclosed in parentheses. If _Ret is a type with unprotected commas, " \ "it must also be enclosed in parentheses.") -#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \ - static_assert(GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \ - "_Tuple should be enclosed in parentheses") +#define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \ + static_assert( \ + GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \ + GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.") #define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \ static_assert( \ @@ -60,8 +61,8 @@ "This method does not take " GMOCK_PP_STRINGIZE( \ _N) " arguments. Parenthesize all types with unproctected commas.") -// TODO(iserna): Verify each element in spec is one of the allowed. -#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) static_assert(true, ""); +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \ + GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec) #define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \ _Override, _Final, _Noexcept, \ @@ -100,6 +101,7 @@ #define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__ +// Five Valid modifiers. #define GMOCK_INTERNAL_HAS_CONST(_Tuple) \ GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple)) @@ -117,6 +119,17 @@ #define GMOCK_INTERNAL_GET_CALLTYPE(_Tuple) \ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_CALLTYPE_IMPL, ~, _Tuple) +#define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \ + static_assert( \ + (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \ + GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \ + GMOCK_INTERNAL_IS_CALLTYPE(_elem)) == 1, \ + GMOCK_PP_STRINGIZE( \ + _elem) " cannot be recognized as a valid specification modifier."); + +// Modifiers implementation. #define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \ GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem) diff --git a/googlemock/include/gmock/internal/gmock-pp.h b/googlemock/include/gmock/internal/gmock-pp.h index 5b46904..1ab80e1 100644 --- a/googlemock/include/gmock/internal/gmock-pp.h +++ b/googlemock/include/gmock/internal/gmock-pp.h @@ -18,7 +18,7 @@ static_assert( #define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2) // Expands and stringifies the only argument. -#define GMOCK_PP_STRINGIZE(_x) GMOCK_PP_INTERNAL_STRINGIZE(_x) +#define GMOCK_PP_STRINGIZE(...) GMOCK_PP_INTERNAL_STRINGIZE(__VA_ARGS__) // Returns empty. Given a variadic number of arguments. #define GMOCK_PP_EMPTY(...) @@ -178,7 +178,7 @@ static_assert( // file or we will break your code. #define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , ) #define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2 -#define GMOCK_PP_INTERNAL_STRINGIZE(_x) #_x +#define GMOCK_PP_INTERNAL_STRINGIZE(...) #__VA_ARGS__ #define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \ _10, _11, _12, _13, _14, _15, _16, \ ...) \ |