Merge pull request #1588 from gennadiycivil/master

mostly 193547722
This commit is contained in:
Gennadiy Civil 2018-04-25 13:28:20 -04:00 committed by GitHub
commit dc043e1ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 619 additions and 597 deletions

View File

@ -357,7 +357,7 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
// // error when trying to resolve between this and overload 4 in // // error when trying to resolve between this and overload 4 in
// // 'gmock_GetName(WithoutMatchers(), nullptr)'. // // 'gmock_GetName(WithoutMatchers(), nullptr)'.
// MockSpec<string&()> gmock_GetName( // MockSpec<string&()> gmock_GetName(
// const WithoutMatchers&, const Function<string&()>*) const { // const WithoutMatchers&, const Function<string&()>*) const {
// // Removes const from this, calls overload 1 // // Removes const from this, calls overload 1
// return AdjustConstness_(this)->gmock_GetName(); // return AdjustConstness_(this)->gmock_GetName();
// } // }
@ -366,7 +366,7 @@ class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
// const string& gmock_GetName() const { … } // const string& gmock_GetName() const { … }
// // Overload 4 // // Overload 4
// MockSpec<const string&()> gmock_GetName( // MockSpec<const string&()> gmock_GetName(
// const WithoutMatchers&, const Function<const string&()>*) const { // const WithoutMatchers&, const Function<const string&()>*) const {
// // Does not remove const, calls overload 3 // // Does not remove const, calls overload 3
// return AdjustConstness_const(this)->gmock_GetName(); // return AdjustConstness_const(this)->gmock_GetName();
// } // }
@ -418,82 +418,81 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD0_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) ct Method() constness { \
) constness { \ GTEST_COMPILE_ASSERT_( \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ (::testing::tuple_size<tn ::testing::internal::Function< \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ __VA_ARGS__>::ArgumentTuple>::value == 0), \
== 0), \
this_method_does_not_take_0_arguments); \ this_method_does_not_take_0_arguments); \
GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method() constness { \
gmock_##Method() constness { \
GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(0, constness, Method).With(); \ return GMOCK_MOCKER_(0, constness, Method).With(); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(); \ ->gmock_##Method(); \
} \ } \
mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(0, constness, \
Method) Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD1_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_( \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ (::testing::tuple_size<tn ::testing::internal::Function< \
== 1), \ __VA_ARGS__>::ArgumentTuple>::value == 1), \
this_method_does_not_take_1_argument); \ this_method_does_not_take_1_argument); \
GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(1, constness, \ return GMOCK_MOCKER_(1, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1)); \ gmock_a1)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1) constness { \
GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>()); \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>()); \
} \ } \
mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(1, constness, \
Method) Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2) constness { \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_( \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ (::testing::tuple_size<tn ::testing::internal::Function< \
== 2), \ __VA_ARGS__>::ArgumentTuple>::value == 2), \
this_method_does_not_take_2_arguments); \ this_method_does_not_take_2_arguments); \
GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(2, constness, \ return GMOCK_MOCKER_(2, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2)); \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
gmock_a2)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2) constness { \
GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>()); \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>()); \
} \ } \
mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \ mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_(2, constness, \
@ -501,34 +500,36 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD3_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
__VA_ARGS__) gmock_a3) constness { \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_( \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ (::testing::tuple_size<tn ::testing::internal::Function< \
== 3), \ __VA_ARGS__>::ArgumentTuple>::value == 3), \
this_method_does_not_take_3_arguments); \ this_method_does_not_take_3_arguments); \
GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(3, constness, \ return GMOCK_MOCKER_(3, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3)); \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
gmock_a3)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3) constness { \
GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(3, constness, Method) \
gmock_a3); \ .With(gmock_a1, gmock_a2, gmock_a3); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>()); \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>()); \
} \ } \
@ -537,36 +538,40 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD4_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_( \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ (::testing::tuple_size<tn ::testing::internal::Function< \
== 4), \ __VA_ARGS__>::ArgumentTuple>::value == 4), \
this_method_does_not_take_4_arguments); \ this_method_does_not_take_4_arguments); \
GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(4, constness, \ return GMOCK_MOCKER_(4, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4)); \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
gmock_a4)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4) constness { \
GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(4, constness, Method) \
gmock_a3, gmock_a4); \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>()); \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>()); \
@ -576,39 +581,44 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD5_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
__VA_ARGS__) gmock_a5) constness { \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ GTEST_COMPILE_ASSERT_( \
== 5), \ (::testing::tuple_size<tn ::testing::internal::Function< \
__VA_ARGS__>::ArgumentTuple>::value == 5), \
this_method_does_not_take_5_arguments); \ this_method_does_not_take_5_arguments); \
GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(5, constness, \ return GMOCK_MOCKER_(5, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5)); \ gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \
gmock_a5)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5) constness { \
GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(5, constness, Method) \
gmock_a3, gmock_a4, gmock_a5); \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
@ -619,42 +629,48 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD6_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
__VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
__VA_ARGS__) gmock_a6) constness { \ GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ GTEST_COMPILE_ASSERT_( \
== 6), \ (::testing::tuple_size<tn ::testing::internal::Function< \
__VA_ARGS__>::ArgumentTuple>::value == 6), \
this_method_does_not_take_6_arguments); \ this_method_does_not_take_6_arguments); \
GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(6, constness, \ return GMOCK_MOCKER_(6, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \ gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6)); \ ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \
gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \
gmock_a6)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \ GMOCK_MATCHER_(tn, 5, __VA_ARGS__) gmock_a5, \
GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6) constness { \
GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(6, constness, Method) \
gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
@ -666,29 +682,37 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD7_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
__VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_( \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ (::testing::tuple_size<tn ::testing::internal::Function< \
== 7), \ __VA_ARGS__>::ArgumentTuple>::value == 7), \
this_method_does_not_take_7_arguments); \ this_method_does_not_take_7_arguments); \
GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(7, constness, \ return GMOCK_MOCKER_(7, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \ gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \ ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7)); \ gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \
gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \
gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \
gmock_a7)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
@ -696,14 +720,15 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \ GMOCK_MATCHER_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7) constness { \
GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(7, constness, Method) \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \
gmock_a7); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
@ -716,31 +741,40 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD8_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
__VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
__VA_ARGS__) gmock_a8) constness { \ GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
== 8), \ GTEST_COMPILE_ASSERT_( \
(::testing::tuple_size<tn ::testing::internal::Function< \
__VA_ARGS__>::ArgumentTuple>::value == 8), \
this_method_does_not_take_8_arguments); \ this_method_does_not_take_8_arguments); \
GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(8, constness, \ return GMOCK_MOCKER_(8, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \ gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \ ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \ gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8)); \ ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \
gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \
gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \
gmock_a7), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>( \
gmock_a8)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
@ -749,14 +783,15 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \ GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8) constness { \
GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(8, constness, Method) \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \
gmock_a7, gmock_a8); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
@ -770,33 +805,43 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD9_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
__VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
__VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, \ GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
__VA_ARGS__) gmock_a9) constness { \ GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
== 9), \ GTEST_COMPILE_ASSERT_( \
(::testing::tuple_size<tn ::testing::internal::Function< \
__VA_ARGS__>::ArgumentTuple>::value == 9), \
this_method_does_not_take_9_arguments); \ this_method_does_not_take_9_arguments); \
GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(9, constness, \ return GMOCK_MOCKER_(9, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \ gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \ ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \ gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \ ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9)); \ gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \
gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \
gmock_a7), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>( \
gmock_a8), \
::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>( \
gmock_a9)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
@ -806,15 +851,15 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \ GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9) constness { \
GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(9, constness, Method) \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \
gmock_a9); \ gmock_a7, gmock_a8, gmock_a9); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \
@ -829,34 +874,46 @@ using internal::FunctionMocker;
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \ #define GMOCK_METHOD10_(tn, constness, ct, Method, ...) \
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \ GMOCK_RESULT_(tn, __VA_ARGS__) \
GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, GMOCK_ARG_(tn, 2, \ ct Method(GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
__VA_ARGS__) gmock_a2, GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, GMOCK_ARG_(tn, 5, \ GMOCK_ARG_(tn, 3, __VA_ARGS__) gmock_a3, \
__VA_ARGS__) gmock_a5, GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \ GMOCK_ARG_(tn, 4, __VA_ARGS__) gmock_a4, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, GMOCK_ARG_(tn, 8, \ GMOCK_ARG_(tn, 5, __VA_ARGS__) gmock_a5, \
__VA_ARGS__) gmock_a8, GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \ GMOCK_ARG_(tn, 6, __VA_ARGS__) gmock_a6, \
GMOCK_ARG_(tn, 7, __VA_ARGS__) gmock_a7, \
GMOCK_ARG_(tn, 8, __VA_ARGS__) gmock_a8, \
GMOCK_ARG_(tn, 9, __VA_ARGS__) gmock_a9, \
GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \ GMOCK_ARG_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
GTEST_COMPILE_ASSERT_((::testing::tuple_size< \ GTEST_COMPILE_ASSERT_( \
tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value \ (::testing::tuple_size<tn ::testing::internal::Function< \
== 10), \ __VA_ARGS__>::ArgumentTuple>::value == 10), \
this_method_does_not_take_10_arguments); \ this_method_does_not_take_10_arguments); \
GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(10, constness, \ return GMOCK_MOCKER_(10, constness, Method) \
Method).Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, \ .Invoke(::testing::internal::forward<GMOCK_ARG_(tn, 1, __VA_ARGS__)>( \
__VA_ARGS__)>(gmock_a1), \ gmock_a1), \
::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(gmock_a2), \ ::testing::internal::forward<GMOCK_ARG_(tn, 2, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(gmock_a3), \ gmock_a2), \
::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(gmock_a4), \ ::testing::internal::forward<GMOCK_ARG_(tn, 3, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>(gmock_a5), \ gmock_a3), \
::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>(gmock_a6), \ ::testing::internal::forward<GMOCK_ARG_(tn, 4, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>(gmock_a7), \ gmock_a4), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>(gmock_a8), \ ::testing::internal::forward<GMOCK_ARG_(tn, 5, __VA_ARGS__)>( \
::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>(gmock_a9), \ gmock_a5), \
::testing::internal::forward<GMOCK_ARG_(tn, 10, __VA_ARGS__)>(gmock_a10)); \ ::testing::internal::forward<GMOCK_ARG_(tn, 6, __VA_ARGS__)>( \
gmock_a6), \
::testing::internal::forward<GMOCK_ARG_(tn, 7, __VA_ARGS__)>( \
gmock_a7), \
::testing::internal::forward<GMOCK_ARG_(tn, 8, __VA_ARGS__)>( \
gmock_a8), \
::testing::internal::forward<GMOCK_ARG_(tn, 9, __VA_ARGS__)>( \
gmock_a9), \
::testing::internal::forward<GMOCK_ARG_(tn, 10, __VA_ARGS__)>( \
gmock_a10)); \
} \ } \
::testing::MockSpec<__VA_ARGS__> \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
gmock_##Method(GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \ GMOCK_MATCHER_(tn, 1, __VA_ARGS__) gmock_a1, \
GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \ GMOCK_MATCHER_(tn, 2, __VA_ARGS__) gmock_a2, \
GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \ GMOCK_MATCHER_(tn, 3, __VA_ARGS__) gmock_a3, \
GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \ GMOCK_MATCHER_(tn, 4, __VA_ARGS__) gmock_a4, \
@ -865,18 +922,17 @@ using internal::FunctionMocker;
GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \ GMOCK_MATCHER_(tn, 7, __VA_ARGS__) gmock_a7, \
GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \ GMOCK_MATCHER_(tn, 8, __VA_ARGS__) gmock_a8, \
GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \ GMOCK_MATCHER_(tn, 9, __VA_ARGS__) gmock_a9, \
GMOCK_MATCHER_(tn, 10, \ GMOCK_MATCHER_(tn, 10, __VA_ARGS__) gmock_a10) constness { \
__VA_ARGS__) gmock_a10) constness { \
GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(10, constness, Method) \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ .With(gmock_a1, gmock_a2, gmock_a3, gmock_a4, gmock_a5, gmock_a6, \
gmock_a10); \ gmock_a7, gmock_a8, gmock_a9, gmock_a10); \
} \ } \
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \ ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
const ::testing::internal::WithoutMatchers&, \ const ::testing::internal::WithoutMatchers&, \
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \ constness ::testing::internal::Function<__VA_ARGS__>*) const { \
return ::testing::internal::AdjustConstness_##constness(this)-> \ return ::testing::internal::AdjustConstness_##constness(this) \
gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \ ->gmock_##Method(::testing::A<GMOCK_ARG_(tn, 1, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 2, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 3, __VA_ARGS__)>(), \
::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \ ::testing::A<GMOCK_ARG_(tn, 4, __VA_ARGS__)>(), \

View File

@ -119,7 +119,7 @@ class FunctionMocker<R($As)> : public
// // error when trying to resolve between this and overload 4 in // // error when trying to resolve between this and overload 4 in
// // 'gmock_GetName(WithoutMatchers(), nullptr)'. // // 'gmock_GetName(WithoutMatchers(), nullptr)'.
// MockSpec<string&()> gmock_GetName( // MockSpec<string&()> gmock_GetName(
// const WithoutMatchers&, const Function<string&()>*) const { // const WithoutMatchers&, const Function<string&()>*) const {
// // Removes const from this, calls overload 1 // // Removes const from this, calls overload 1
// return AdjustConstness_(this)->gmock_GetName(); // return AdjustConstness_(this)->gmock_GetName();
// } // }
@ -128,7 +128,7 @@ class FunctionMocker<R($As)> : public
// const string& gmock_GetName() const { … } // const string& gmock_GetName() const { … }
// // Overload 4 // // Overload 4
// MockSpec<const string&()> gmock_GetName( // MockSpec<const string&()> gmock_GetName(
// const WithoutMatchers&, const Function<const string&()>*) const { // const WithoutMatchers&, const Function<const string&()>*) const {
// // Does not remove const, calls overload 3 // // Does not remove const, calls overload 3
// return AdjustConstness_const(this)->gmock_GetName(); // return AdjustConstness_const(this)->gmock_GetName();
// } // }

View File

@ -1718,25 +1718,27 @@ class NotMatcher {
// that will prevent different instantiations of BothOfMatcher from // that will prevent different instantiations of BothOfMatcher from
// sharing the same BothOfMatcherImpl<T> class. // sharing the same BothOfMatcherImpl<T> class.
template <typename T> template <typename T>
class BothOfMatcherImpl class AllOfMatcherImpl
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
public: public:
BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
: matcher1_(matcher1), matcher2_(matcher2) {} : matchers_(internal::move(matchers)) {}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "("; *os << "(";
matcher1_.DescribeTo(os); for (size_t i = 0; i < matchers_.size(); ++i) {
*os << ") and ("; if (i != 0) *os << ") and (";
matcher2_.DescribeTo(os); matchers_[i].DescribeTo(os);
}
*os << ")"; *os << ")";
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "("; *os << "(";
matcher1_.DescribeNegationTo(os); for (size_t i = 0; i < matchers_.size(); ++i) {
*os << ") or ("; if (i != 0) *os << ") or (";
matcher2_.DescribeNegationTo(os); matchers_[i].DescribeNegationTo(os);
}
*os << ")"; *os << ")";
} }
@ -1744,93 +1746,38 @@ class BothOfMatcherImpl
MatchResultListener* listener) const { MatchResultListener* listener) const {
// If either matcher1_ or matcher2_ doesn't match x, we only need // If either matcher1_ or matcher2_ doesn't match x, we only need
// to explain why one of them fails. // to explain why one of them fails.
StringMatchResultListener listener1; std::string all_match_result;
if (!matcher1_.MatchAndExplain(x, &listener1)) {
*listener << listener1.str(); for (size_t i = 0; i < matchers_.size(); ++i) {
StringMatchResultListener slistener;
if (matchers_[i].MatchAndExplain(x, &slistener)) {
if (all_match_result.empty()) {
all_match_result = slistener.str();
} else {
std::string result = slistener.str();
if (!result.empty()) {
all_match_result += ", and ";
all_match_result += result;
}
}
} else {
*listener << slistener.str();
return false; return false;
} }
StringMatchResultListener listener2;
if (!matcher2_.MatchAndExplain(x, &listener2)) {
*listener << listener2.str();
return false;
} }
// Otherwise we need to explain why *both* of them match. // Otherwise we need to explain why *both* of them match.
const std::string s1 = listener1.str(); *listener << all_match_result;
const std::string s2 = listener2.str();
if (s1 == "") {
*listener << s2;
} else {
*listener << s1;
if (s2 != "") {
*listener << ", and " << s2;
}
}
return true; return true;
} }
private: private:
const Matcher<T> matcher1_; const std::vector<Matcher<T> > matchers_;
const Matcher<T> matcher2_;
GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl);
}; };
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
// MatcherList provides mechanisms for storing a variable number of matchers in
// a list structure (ListType) and creating a combining matcher from such a
// list.
// The template is defined recursively using the following template parameters:
// * kSize is the length of the MatcherList.
// * Head is the type of the first matcher of the list.
// * Tail denotes the types of the remaining matchers of the list.
template <int kSize, typename Head, typename... Tail>
struct MatcherList {
typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
// BuildList stores variadic type values in a nested pair structure.
// Example:
// MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
// the corresponding result of type pair<int, pair<string, float>>.
static ListType BuildList(const Head& matcher, const Tail&... tail) {
return ListType(matcher, MatcherListTail::BuildList(tail...));
}
// CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
// by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
// list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
// constructor taking two Matcher<T>s as input.
template <typename T, template <typename /* T */> class CombiningMatcher>
static Matcher<T> CreateMatcher(const ListType& matchers) {
return Matcher<T>(new CombiningMatcher<T>(
SafeMatcherCast<T>(matchers.first),
MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
matchers.second)));
}
};
// The following defines the base case for the recursive definition of
// MatcherList.
template <typename Matcher1, typename Matcher2>
struct MatcherList<2, Matcher1, Matcher2> {
typedef ::std::pair<Matcher1, Matcher2> ListType;
static ListType BuildList(const Matcher1& matcher1,
const Matcher2& matcher2) {
return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
}
template <typename T, template <typename /* T */> class CombiningMatcher>
static Matcher<T> CreateMatcher(const ListType& matchers) {
return Matcher<T>(new CombiningMatcher<T>(
SafeMatcherCast<T>(matchers.first),
SafeMatcherCast<T>(matchers.second)));
}
};
// VariadicMatcher is used for the variadic implementation of // VariadicMatcher is used for the variadic implementation of
// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...). // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
// CombiningMatcher<T> is used to recursively combine the provided matchers // CombiningMatcher<T> is used to recursively combine the provided matchers
@ -1839,27 +1786,40 @@ template <template <typename T> class CombiningMatcher, typename... Args>
class VariadicMatcher { class VariadicMatcher {
public: public:
VariadicMatcher(const Args&... matchers) // NOLINT VariadicMatcher(const Args&... matchers) // NOLINT
: matchers_(MatcherListType::BuildList(matchers...)) {} : matchers_(matchers...) {
static_assert(sizeof...(Args) > 0, "Must have at least one matcher.");
}
// This template type conversion operator allows an // This template type conversion operator allows an
// VariadicMatcher<Matcher1, Matcher2...> object to match any type that // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
// all of the provided matchers (Matcher1, Matcher2, ...) can match. // all of the provided matchers (Matcher1, Matcher2, ...) can match.
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return MatcherListType::template CreateMatcher<T, CombiningMatcher>( std::vector<Matcher<T> > values;
matchers_); CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
return Matcher<T>(new CombiningMatcher<T>(internal::move(values)));
} }
private: private:
typedef MatcherList<sizeof...(Args), Args...> MatcherListType; template <typename T, size_t I>
void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
std::integral_constant<size_t, I>) const {
values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
}
const typename MatcherListType::ListType matchers_; template <typename T>
void CreateVariadicMatcher(
std::vector<Matcher<T> >*,
std::integral_constant<size_t, sizeof...(Args)>) const {}
tuple<Args...> matchers_;
GTEST_DISALLOW_ASSIGN_(VariadicMatcher); GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
}; };
template <typename... Args> template <typename... Args>
using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>; using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
#endif // GTEST_LANG_CXX11 #endif // GTEST_LANG_CXX11
@ -1876,8 +1836,10 @@ class BothOfMatcher {
// both Matcher1 and Matcher2 can match. // both Matcher1 and Matcher2 can match.
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_), std::vector<Matcher<T> > values;
SafeMatcherCast<T>(matcher2_))); values.push_back(SafeMatcherCast<T>(matcher1_));
values.push_back(SafeMatcherCast<T>(matcher2_));
return Matcher<T>(new AllOfMatcherImpl<T>(internal::move(values)));
} }
private: private:
@ -1892,70 +1854,69 @@ class BothOfMatcher {
// that will prevent different instantiations of AnyOfMatcher from // that will prevent different instantiations of AnyOfMatcher from
// sharing the same EitherOfMatcherImpl<T> class. // sharing the same EitherOfMatcherImpl<T> class.
template <typename T> template <typename T>
class EitherOfMatcherImpl class AnyOfMatcherImpl
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> { : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
public: public:
EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
: matcher1_(matcher1), matcher2_(matcher2) {} : matchers_(internal::move(matchers)) {}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "("; *os << "(";
matcher1_.DescribeTo(os); for (size_t i = 0; i < matchers_.size(); ++i) {
*os << ") or ("; if (i != 0) *os << ") or (";
matcher2_.DescribeTo(os); matchers_[i].DescribeTo(os);
}
*os << ")"; *os << ")";
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "("; *os << "(";
matcher1_.DescribeNegationTo(os); for (size_t i = 0; i < matchers_.size(); ++i) {
*os << ") and ("; if (i != 0) *os << ") and (";
matcher2_.DescribeNegationTo(os); matchers_[i].DescribeNegationTo(os);
}
*os << ")"; *os << ")";
} }
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x, virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
MatchResultListener* listener) const { MatchResultListener* listener) const {
std::string no_match_result;
// If either matcher1_ or matcher2_ matches x, we just need to // If either matcher1_ or matcher2_ matches x, we just need to
// explain why *one* of them matches. // explain why *one* of them matches.
StringMatchResultListener listener1; for (size_t i = 0; i < matchers_.size(); ++i) {
if (matcher1_.MatchAndExplain(x, &listener1)) { StringMatchResultListener slistener;
*listener << listener1.str(); if (matchers_[i].MatchAndExplain(x, &slistener)) {
*listener << slistener.str();
return true; return true;
} else {
if (no_match_result.empty()) {
no_match_result = slistener.str();
} else {
std::string result = slistener.str();
if (!result.empty()) {
no_match_result += ", and ";
no_match_result += result;
}
}
} }
StringMatchResultListener listener2;
if (matcher2_.MatchAndExplain(x, &listener2)) {
*listener << listener2.str();
return true;
} }
// Otherwise we need to explain why *both* of them fail. // Otherwise we need to explain why *both* of them fail.
const std::string s1 = listener1.str(); *listener << no_match_result;
const std::string s2 = listener2.str();
if (s1 == "") {
*listener << s2;
} else {
*listener << s1;
if (s2 != "") {
*listener << ", and " << s2;
}
}
return false; return false;
} }
private: private:
const Matcher<T> matcher1_; const std::vector<Matcher<T> > matchers_;
const Matcher<T> matcher2_;
GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl); GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
}; };
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...). // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
template <typename... Args> template <typename... Args>
using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>; using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
#endif // GTEST_LANG_CXX11 #endif // GTEST_LANG_CXX11
@ -1973,8 +1934,10 @@ class EitherOfMatcher {
// both Matcher1 and Matcher2 can match. // both Matcher1 and Matcher2 can match.
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new EitherOfMatcherImpl<T>( std::vector<Matcher<T> > values;
SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_))); values.push_back(SafeMatcherCast<T>(matcher1_));
values.push_back(SafeMatcherCast<T>(matcher2_));
return Matcher<T>(new AnyOfMatcherImpl<T>(internal::move(values)));
} }
private: private:

View File

@ -59,13 +59,6 @@
# include <forward_list> // NOLINT # include <forward_list> // NOLINT
#endif #endif
// Disable MSVC2015 warning for std::pair:
// "decorated name length exceeded, name was truncated".
#if defined _MSC_VER
# pragma warning(push)
# pragma warning(disable:4503)
#endif
#if GTEST_LANG_CXX11 #if GTEST_LANG_CXX11
# include <type_traits> # include <type_traits>
#endif #endif
@ -749,6 +742,13 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) {
EXPECT_FALSE(m3.Matches(239)); EXPECT_FALSE(m3.Matches(239));
} }
// ConvertibleFromAny does not work with MSVC. resulting in
// error C2440: 'initializing': cannot convert from 'Eq' to 'M'
// No constructor could take the source type, or constructor overload
// resolution was ambiguous
#if !defined _MSC_VER
// The below ConvertibleFromAny struct is implicitly constructible from anything // The below ConvertibleFromAny struct is implicitly constructible from anything
// and when in the same namespace can interact with other tests. In particular, // and when in the same namespace can interact with other tests. In particular,
// if it is in the same namespace as other tests and one removes // if it is in the same namespace as other tests and one removes
@ -761,7 +761,7 @@ namespace convertible_from_any {
struct ConvertibleFromAny { struct ConvertibleFromAny {
ConvertibleFromAny(int a_value) : value(a_value) {} ConvertibleFromAny(int a_value) : value(a_value) {}
template <typename T> template <typename T>
explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ConvertibleFromAny(const T& /*a_value*/) : value(-1) {
ADD_FAILURE() << "Conversion constructor called"; ADD_FAILURE() << "Conversion constructor called";
} }
int value; int value;
@ -789,6 +789,8 @@ TEST(MatcherCastTest, FromConvertibleFromAny) {
} }
} // namespace convertible_from_any } // namespace convertible_from_any
#endif // !defined _MSC_VER
struct IntReferenceWrapper { struct IntReferenceWrapper {
IntReferenceWrapper(const int& a_value) : value(&a_value) {} IntReferenceWrapper(const int& a_value) : value(&a_value) {}
const int* value; const int* value;
@ -893,6 +895,8 @@ TEST(SafeMatcherCastTest, FromSameType) {
EXPECT_FALSE(m2.Matches(1)); EXPECT_FALSE(m2.Matches(1));
} }
#if !defined _MSC_VER
namespace convertible_from_any { namespace convertible_from_any {
TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) {
Matcher<ConvertibleFromAny> m = SafeMatcherCast<ConvertibleFromAny>(1); Matcher<ConvertibleFromAny> m = SafeMatcherCast<ConvertibleFromAny>(1);
@ -908,6 +912,8 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) {
} }
} // namespace convertible_from_any } // namespace convertible_from_any
#endif // !defined _MSC_VER
TEST(SafeMatcherCastTest, ValueIsNotCopied) { TEST(SafeMatcherCastTest, ValueIsNotCopied) {
int n = 42; int n = 42;
Matcher<IntReferenceWrapper> m = SafeMatcherCast<IntReferenceWrapper>(n); Matcher<IntReferenceWrapper> m = SafeMatcherCast<IntReferenceWrapper>(n);
@ -2539,7 +2545,7 @@ TEST(AllOfTest, VariadicMatchesWhenAllMatch) {
::testing::AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); ::testing::AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
Matcher<int> m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Matcher<int> m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8),
Ne(9), Ne(10), Ne(11)); Ne(9), Ne(10), Ne(11));
EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11))))))))))")); EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11)"));
AllOfMatches(11, m); AllOfMatches(11, m);
AllOfMatches(50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), AllOfMatches(50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8),
Ne(9), Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), Ne(9), Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15),
@ -2733,7 +2739,7 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) {
// on ADL. // on ADL.
Matcher<int> m = ::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); Matcher<int> m = ::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
EXPECT_THAT(Describe(m), EndsWith("or (is equal to 11))))))))))")); EXPECT_THAT(Describe(m), EndsWith("or (is equal to 11)"));
AnyOfMatches(11, m); AnyOfMatches(11, m);
AnyOfMatches(50, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, AnyOfMatches(50, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
@ -6761,6 +6767,3 @@ TEST(NotTest, WorksOnMoveOnlyType) {
} // namespace gmock_matchers_test } // namespace gmock_matchers_test
} // namespace testing } // namespace testing
#if defined_MSC_VER
# pragma warning(pop)
#endif