aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock')
-rw-r--r--googlemock/docs/cheat_sheet.md28
-rw-r--r--googlemock/include/gmock/gmock-actions.h47
-rw-r--r--googlemock/include/gmock/gmock-function-mocker.h29
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h24
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump4
-rw-r--r--googlemock/include/gmock/gmock-generated-matchers.h88
-rw-r--r--googlemock/include/gmock/gmock-generated-matchers.h.pump8
-rw-r--r--googlemock/include/gmock/gmock-matchers.h28
-rw-r--r--googlemock/include/gmock/internal/gmock-internal-utils.h92
-rw-r--r--googlemock/include/gmock/internal/gmock-pp.h108
-rw-r--r--googlemock/scripts/README.md5
-rwxr-xr-xgooglemock/scripts/generator/cpp/ast.py46
-rwxr-xr-xgooglemock/scripts/generator/cpp/gmock_class.py114
-rwxr-xr-xgooglemock/scripts/generator/cpp/gmock_class_test.py93
-rwxr-xr-xgooglemock/scripts/generator/cpp/keywords.py39
-rwxr-xr-xgooglemock/scripts/generator/cpp/tokenize.py39
-rwxr-xr-xgooglemock/scripts/generator/cpp/utils.py40
-rwxr-xr-xgooglemock/scripts/generator/gmock_gen.py36
-rwxr-xr-xgooglemock/scripts/gmock-config.in303
-rwxr-xr-xgooglemock/scripts/gmock_doctor.py640
-rwxr-xr-xgooglemock/scripts/upload.py35
-rw-r--r--googlemock/src/gmock_main.cc8
-rw-r--r--googlemock/test/gmock-actions_test.cc26
-rw-r--r--googlemock/test/gmock-function-mocker_test.cc7
-rw-r--r--googlemock/test/gmock-generated-matchers_test.cc53
-rw-r--r--googlemock/test/gmock-matchers_test.cc146
-rw-r--r--googlemock/test/gmock-pp_test.cc10
-rw-r--r--googlemock/test/gmock-spec-builders_test.cc2
28 files changed, 750 insertions, 1348 deletions
diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md
index 850963af..aafb3b3b 100644
--- a/googlemock/docs/cheat_sheet.md
+++ b/googlemock/docs/cheat_sheet.md
@@ -287,6 +287,7 @@ is not changed afterwards, or the meaning of your matcher will be changed.
| `FloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as unequal. |
| `NanSensitiveDoubleEq(a_double)` | `argument` is a `double` value approximately equal to `a_double`, treating two NaNs as equal. |
| `NanSensitiveFloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as equal. |
+| `IsNan()` | `argument` is any floating-point type with a NaN value. |
<!-- mdformat on -->
The above matchers use ULP-based comparison (the same as used in googletest).
@@ -325,9 +326,9 @@ The `argument` can be either a C string or a C++ string object:
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They
use the regular expression syntax defined
-[here](../../googletest/docs/advanced.md#regular-expression-syntax).
-`StrCaseEq()`, `StrCaseNe()`, `StrEq()`, and `StrNe()` work for wide strings as
-well.
+[here](../../googletest/docs/advanced.md#regular-expression-syntax). All of
+these matchers, except `ContainsRegex()` and `MatchesRegex()` work for wide
+strings as well.
#### Container Matchers
@@ -502,16 +503,17 @@ which must be a permanent callback.
#### Returning a Value
<!-- mdformat off(no multiline tables) -->
-| | |
-| :-------------------------- | :-------------------------------------------- |
-| `Return()` | Return from a `void` mock function. |
-| `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed. |
-| `ReturnArg<N>()` | Return the `N`-th (0-based) argument. |
-| `ReturnNew<T>(a1, ..., ak)` | Return `new T(a1, ..., ak)`; a different object is created each time. |
-| `ReturnNull()` | Return a null pointer. |
-| `ReturnPointee(ptr)` | Return the value pointed to by `ptr`. |
-| `ReturnRef(variable)` | Return a reference to `variable`. |
-| `ReturnRefOfCopy(value)` | Return a reference to a copy of `value`; the copy lives as long as the action. |
+| | |
+| :-------------------------------- | :-------------------------------------------- |
+| `Return()` | Return from a `void` mock function. |
+| `Return(value)` | Return `value`. If the type of `value` is different to the mock function's return type, `value` is converted to the latter type <i>at the time the expectation is set</i>, not when the action is executed. |
+| `ReturnArg<N>()` | Return the `N`-th (0-based) argument. |
+| `ReturnNew<T>(a1, ..., ak)` | Return `new T(a1, ..., ak)`; a different object is created each time. |
+| `ReturnNull()` | Return a null pointer. |
+| `ReturnPointee(ptr)` | Return the value pointed to by `ptr`. |
+| `ReturnRef(variable)` | Return a reference to `variable`. |
+| `ReturnRefOfCopy(value)` | Return a reference to a copy of `value`; the copy lives as long as the action. |
+| `ReturnRoundRobin({a1, ..., ak})` | Each call will return the next `ai` in the list, starting at the beginning when the end of the list is reached. |
<!-- mdformat on -->
#### Side Effects
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index f12d39be..91abcd35 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -716,6 +716,36 @@ class ReturnRefOfCopyAction {
GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
};
+// Implements the polymorphic ReturnRoundRobin(v) action, which can be
+// used in any function that returns the element_type of v.
+template <typename T>
+class ReturnRoundRobinAction {
+ public:
+ explicit ReturnRoundRobinAction(std::vector<T> values) {
+ GTEST_CHECK_(!values.empty())
+ << "ReturnRoundRobin requires at least one element.";
+ state_->values = std::move(values);
+ }
+
+ template <typename... Args>
+ T operator()(Args&&...) const {
+ return state_->Next();
+ }
+
+ private:
+ struct State {
+ T Next() {
+ T ret_val = values[i++];
+ if (i == values.size()) i = 0;
+ return ret_val;
+ }
+
+ std::vector<T> values;
+ size_t i = 0;
+ };
+ std::shared_ptr<State> state_ = std::make_shared<State>();
+};
+
// Implements the polymorphic DoDefault() action.
class DoDefaultAction {
public:
@@ -1039,6 +1069,23 @@ internal::ByMoveWrapper<R> ByMove(R x) {
return internal::ByMoveWrapper<R>(std::move(x));
}
+// Creates an action that returns an element of `vals`. Calling this action will
+// repeatedly return the next value from `vals` until it reaches the end and
+// will restart from the beginning.
+template <typename T>
+internal::ReturnRoundRobinAction<T> ReturnRoundRobin(std::vector<T> vals) {
+ return internal::ReturnRoundRobinAction<T>(std::move(vals));
+}
+
+// Creates an action that returns an element of `vals`. Calling this action will
+// repeatedly return the next value from `vals` until it reaches the end and
+// will restart from the beginning.
+template <typename T>
+internal::ReturnRoundRobinAction<T> ReturnRoundRobin(
+ std::initializer_list<T> vals) {
+ return internal::ReturnRoundRobinAction<T>(std::vector<T>(vals));
+}
+
// Creates an action that does the default action for the give mock function.
inline internal::DoDefaultAction DoDefault() {
return internal::DoDefaultAction();
diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h
index cc1535c8..684db139 100644
--- a/googlemock/include/gmock/gmock-function-mocker.h
+++ b/googlemock/include/gmock/gmock-function-mocker.h
@@ -39,6 +39,13 @@
#include "gmock/gmock-generated-function-mockers.h" // NOLINT
#include "gmock/internal/gmock-pp.h"
+namespace testing {
+namespace internal {
+template <typename T>
+using identity_t = T;
+} // namespace internal
+} // namespace testing
+
#define MOCK_METHOD(...) \
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
@@ -207,10 +214,24 @@
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
-#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
- GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
- GMOCK_PP_IDENTITY) \
- (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
+// Note: The use of `identity_t` here allows _Ret to represent return types that
+// would normally need to be specified in a different way. For example, a method
+// returning a function pointer must be written as
+//
+// fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...)
+//
+// But we only support placing the return type at the beginning. To handle this,
+// we wrap all calls in identity_t, so that a declaration will be expanded to
+//
+// identity_t<fn_ptr_return_t (*)(fn_ptr_args_t...)> method(method_args_t...)
+//
+// This allows us to work around the syntactic oddities of function/method
+// types.
+#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
+ ::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \
+ GMOCK_PP_REMOVE_PARENS, \
+ GMOCK_PP_IDENTITY)(_Ret)>( \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
GMOCK_PP_COMMA_IF(_i) \
diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h
index 981af78f..cee96dae 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h
+++ b/googlemock/include/gmock/gmock-generated-actions.h
@@ -663,7 +663,7 @@ class ActionHelper {
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -726,7 +726,7 @@ class ActionHelper {
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
gmock_Impl() {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -776,7 +776,7 @@ class ActionHelper {
args_type;\
explicit gmock_Impl(p0##_type gmock_p0) : \
p0(::std::forward<p0##_type>(gmock_p0)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -832,7 +832,7 @@ class ActionHelper {
gmock_Impl(p0##_type gmock_p0, \
p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
p1(::std::forward<p1##_type>(gmock_p1)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -893,7 +893,7 @@ class ActionHelper {
p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
p1(::std::forward<p1##_type>(gmock_p1)), \
p2(::std::forward<p2##_type>(gmock_p2)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -961,7 +961,7 @@ class ActionHelper {
p1(::std::forward<p1##_type>(gmock_p1)), \
p2(::std::forward<p2##_type>(gmock_p2)), \
p3(::std::forward<p3##_type>(gmock_p3)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1038,7 +1038,7 @@ class ActionHelper {
p2(::std::forward<p2##_type>(gmock_p2)), \
p3(::std::forward<p3##_type>(gmock_p3)), \
p4(::std::forward<p4##_type>(gmock_p4)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1119,7 +1119,7 @@ class ActionHelper {
p3(::std::forward<p3##_type>(gmock_p3)), \
p4(::std::forward<p4##_type>(gmock_p4)), \
p5(::std::forward<p5##_type>(gmock_p5)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1206,7 +1206,7 @@ class ActionHelper {
p4(::std::forward<p4##_type>(gmock_p4)), \
p5(::std::forward<p5##_type>(gmock_p5)), \
p6(::std::forward<p6##_type>(gmock_p6)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1302,7 +1302,7 @@ class ActionHelper {
p5(::std::forward<p5##_type>(gmock_p5)), \
p6(::std::forward<p6##_type>(gmock_p6)), \
p7(::std::forward<p7##_type>(gmock_p7)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1404,7 +1404,7 @@ class ActionHelper {
p6(::std::forward<p6##_type>(gmock_p6)), \
p7(::std::forward<p7##_type>(gmock_p7)), \
p8(::std::forward<p8##_type>(gmock_p8)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1513,7 +1513,7 @@ class ActionHelper {
p7(::std::forward<p7##_type>(gmock_p7)), \
p8(::std::forward<p8##_type>(gmock_p8)), \
p9(::std::forward<p9##_type>(gmock_p9)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 209603c5..283abcdc 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -395,7 +395,7 @@ $range k 0..n-1
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -482,7 +482,7 @@ $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
[[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h
index 690a57f1..61892380 100644
--- a/googlemock/include/gmock/gmock-generated-matchers.h
+++ b/googlemock/include/gmock/gmock-generated-matchers.h
@@ -269,13 +269,13 @@
public:\
gmock_Impl()\
{}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
private:\
@@ -318,13 +318,13 @@
public:\
explicit gmock_Impl(p0##_type gmock_p0)\
: p0(::std::move(gmock_p0)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -371,13 +371,13 @@
public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -431,13 +431,13 @@
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -495,13 +495,13 @@
p3##_type gmock_p3)\
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -568,13 +568,13 @@
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -644,13 +644,13 @@
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -726,13 +726,13 @@
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -814,13 +814,13 @@
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -909,13 +909,13 @@
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
p8(::std::move(gmock_p8)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -1009,13 +1009,13 @@
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
p8(::std::move(gmock_p8)), p9(::std::move(gmock_p9)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump
index ae90917c..69d2ae41 100644
--- a/googlemock/include/gmock/gmock-generated-matchers.h.pump
+++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump
@@ -302,13 +302,13 @@ $var param_field_decls2 = [[$for j
public:\
[[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
$impl_inits {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\$param_field_decls
private:\
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 4428ec14..bb047da9 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -42,8 +42,8 @@
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
-#include <math.h>
#include <algorithm>
+#include <cmath>
#include <initializer_list>
#include <iterator>
#include <limits>
@@ -54,6 +54,7 @@
#include <type_traits>
#include <utility>
#include <vector>
+
#include "gmock/internal/gmock-internal-utils.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
@@ -141,7 +142,7 @@ class MatcherCastImpl {
template <bool Ignore>
static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
std::true_type /* convertible_to_matcher */,
- bool_constant<Ignore>) {
+ std::integral_constant<bool, Ignore>) {
// M is implicitly convertible to Matcher<T>, which means that either
// M is a polymorphic matcher or Matcher<T> has an implicit constructor
// from M. In both cases using the implicit conversion will produce a
@@ -1349,6 +1350,22 @@ MakePredicateFormatterFromMatcher(M matcher) {
return PredicateFormatterFromMatcher<M>(std::move(matcher));
}
+// Implements the polymorphic IsNan() matcher, which matches any floating type
+// value that is Nan.
+class IsNanMatcher {
+ public:
+ template <typename FloatType>
+ bool MatchAndExplain(const FloatType& f,
+ MatchResultListener* /* listener */) const {
+ return (::std::isnan)(f);
+ }
+
+ void DescribeTo(::std::ostream* os) const { *os << "is NaN"; }
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "isn't NaN";
+ }
+};
+
// Implements the polymorphic floating point equality matcher, which matches
// two float values using ULP-based approximation or, optionally, a
// user-specified epsilon. The template is meant to be instantiated with
@@ -1409,7 +1426,7 @@ class FloatingEqMatcher {
}
const FloatType diff = value - expected_;
- if (fabs(diff) <= max_abs_error_) {
+ if (::std::fabs(diff) <= max_abs_error_) {
return true;
}
@@ -3626,6 +3643,11 @@ inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
return internal::RefMatcher<T&>(x);
}
+// Creates a polymorphic matcher that matches any NaN floating point.
+inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
+ return MakePolymorphicMatcher(internal::IsNanMatcher());
+}
+
// Creates a matcher that matches any double argument approximately
// equal to rhs, where two NANs are considered unequal.
inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index 584afa98..5fd169e9 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -157,9 +157,6 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
static_cast< ::testing::internal::TypeKind>( \
::testing::internal::KindOf<type>::value)
-// Evaluates to true if and only if integer type T is signed.
-#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
-
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
// is true if and only if arithmetic type From can be losslessly converted to
// arithmetic type To.
@@ -170,65 +167,30 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
// From, and kToKind is the kind of To; the value is
// implementation-defined when the above pre-condition is violated.
template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
-struct LosslessArithmeticConvertibleImpl : public std::false_type {};
-
-// Converting bool to bool is lossless.
-template <>
-struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
- : public std::true_type {};
-
-// Converting bool to any integer type is lossless.
-template <typename To>
-struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
- : public std::true_type {};
-
-// Converting bool to any floating-point type is lossless.
-template <typename To>
-struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
- : public std::true_type {};
-
-// Converting an integer to bool is lossy.
-template <typename From>
-struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
- : public std::false_type {};
-
-// Converting an integer to another non-bool integer is lossless
-// if and only if the target type's range encloses the source type's range.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
- : public bool_constant<
- // When converting from a smaller size to a larger size, we are
- // fine as long as we are not converting from signed to unsigned.
- ((sizeof(From) < sizeof(To)) &&
- (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
- // When converting between the same size, the signedness must match.
- ((sizeof(From) == sizeof(To)) &&
- (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
-
-#undef GMOCK_IS_SIGNED_
-
-// Converting an integer to a floating-point type may be lossy, since
-// the format of a floating-point number is implementation-defined.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
- : public std::false_type {};
-
-// Converting a floating-point to bool is lossy.
-template <typename From>
-struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
- : public std::false_type {};
-
-// Converting a floating-point to an integer is lossy.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
- : public std::false_type {};
-
-// Converting a floating-point to another floating-point is lossless
-// if and only if the target type is at least as big as the source type.
-template <typename From, typename To>
-struct LosslessArithmeticConvertibleImpl<
- kFloatingPoint, From, kFloatingPoint, To>
- : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
+using LosslessArithmeticConvertibleImpl = std::integral_constant<
+ bool,
+ // clang-format off
+ // Converting from bool is always lossless
+ (kFromKind == kBool) ? true
+ // Converting between any other type kinds will be lossy if the type
+ // kinds are not the same.
+ : (kFromKind != kToKind) ? false
+ : (kFromKind == kInteger &&
+ // Converting between integers of different widths is allowed so long
+ // as the conversion does not go from signed to unsigned.
+ (((sizeof(From) < sizeof(To)) &&
+ !(std::is_signed<From>::value && !std::is_signed<To>::value)) ||
+ // Converting between integers of the same width only requires the
+ // two types to have the same signedness.
+ ((sizeof(From) == sizeof(To)) &&
+ (std::is_signed<From>::value == std::is_signed<To>::value)))
+ ) ? true
+ // Floating point conversions are lossless if and only if `To` is at least
+ // as wide as `From`.
+ : (kFromKind == kFloatingPoint && (sizeof(From) <= sizeof(To))) ? true
+ : false
+ // clang-format on
+ >;
// LosslessArithmeticConvertible<From, To>::value is true if and only if
// arithmetic type From can be losslessly converted to arithmetic type To.
@@ -238,9 +200,9 @@ struct LosslessArithmeticConvertibleImpl<
// reference) built-in arithmetic types; the value is
// implementation-defined when the above pre-condition is violated.
template <typename From, typename To>
-struct LosslessArithmeticConvertible
- : public LosslessArithmeticConvertibleImpl<
- GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
+using LosslessArithmeticConvertible =
+ LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
+ GMOCK_KIND_OF_(To), To>;
// This interface knows how to report a Google Mock failure (either
// non-fatal or fatal).
diff --git a/googlemock/include/gmock/internal/gmock-pp.h b/googlemock/include/gmock/internal/gmock-pp.h
index 1ab80e1c..c3759f66 100644
--- a/googlemock/include/gmock/internal/gmock-pp.h
+++ b/googlemock/include/gmock/internal/gmock-pp.h
@@ -1,19 +1,6 @@
#ifndef THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
#define THIRD_PARTY_GOOGLETEST_GOOGLEMOCK_INCLUDE_GMOCK_PP_H_
-#undef GMOCK_PP_INTERNAL_USE_MSVC
-#if defined(__clang__)
-#define GMOCK_PP_INTERNAL_USE_MSVC 0
-#elif defined(_MSC_VER)
-// TODO(iserna): Also verify tradional versus comformant preprocessor.
-static_assert(
- _MSC_VER >= 1900,
- "MSVC version not supported. There is support for MSVC 14.0 and above.");
-#define GMOCK_PP_INTERNAL_USE_MSVC 1
-#else
-#define GMOCK_PP_INTERNAL_USE_MSVC 0
-#endif
-
// Expands and concatenates the arguments. Constructed macros reevaluate.
#define GMOCK_PP_CAT(_1, _2) GMOCK_PP_INTERNAL_CAT(_1, _2)
@@ -29,10 +16,6 @@ static_assert(
// Returns the only argument.
#define GMOCK_PP_IDENTITY(_1) _1
-// MSVC preprocessor collapses __VA_ARGS__ in a single argument, we use a
-// CAT-like directive to force correct evaluation. Each macro has its own.
-#if GMOCK_PP_INTERNAL_USE_MSVC
-
// Evaluates to the number of arguments after expansion.
//
// #define PAIR x, y
@@ -43,45 +26,27 @@ static_assert(
// GMOCK_PP_NARG(PAIR) => 2
//
// Requires: the number of arguments after expansion is at most 15.
-#define GMOCK_PP_NARG(...) \
- GMOCK_PP_INTERNAL_NARG_CAT( \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, \
- 8, 7, 6, 5, 4, 3, 2, 1), )
+#define GMOCK_PP_NARG(...) \
+ GMOCK_PP_INTERNAL_16TH( \
+ (__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
// Returns 1 if the expansion of arguments has an unprotected comma. Otherwise
// returns 0. Requires no more than 15 unprotected commas.
-#define GMOCK_PP_HAS_COMMA(...) \
- GMOCK_PP_INTERNAL_HAS_COMMA_CAT( \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
- 1, 1, 1, 1, 1, 0), )
+#define GMOCK_PP_HAS_COMMA(...) \
+ GMOCK_PP_INTERNAL_16TH( \
+ (__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0))
+
// Returns the first argument.
-#define GMOCK_PP_HEAD(...) \
- GMOCK_PP_INTERNAL_HEAD_CAT(GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__), )
+#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD((__VA_ARGS__))
// Returns the tail. A variadic list of all arguments minus the first. Requires
// at least one argument.
-#define GMOCK_PP_TAIL(...) \
- GMOCK_PP_INTERNAL_TAIL_CAT(GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__), )
+#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL((__VA_ARGS__))
// Calls CAT(_Macro, NARG(__VA_ARGS__))(__VA_ARGS__)
#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
- GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT( \
- GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__), )
-
-#else // GMOCK_PP_INTERNAL_USE_MSVC
-
-#define GMOCK_PP_NARG(...) \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, \
- 7, 6, 5, 4, 3, 2, 1)
-#define GMOCK_PP_HAS_COMMA(...) \
- GMOCK_PP_INTERNAL_INTERNAL_16TH(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
- 1, 1, 1, 1, 0)
-#define GMOCK_PP_HEAD(...) GMOCK_PP_INTERNAL_HEAD(__VA_ARGS__)
-#define GMOCK_PP_TAIL(...) GMOCK_PP_INTERNAL_TAIL(__VA_ARGS__)
-#define GMOCK_PP_VARIADIC_CALL(_Macro, ...) \
- GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__)
-
-#endif // GMOCK_PP_INTERNAL_USE_MSVC
+ GMOCK_PP_IDENTITY( \
+ GMOCK_PP_CAT(_Macro, GMOCK_PP_NARG(__VA_ARGS__))(__VA_ARGS__))
// If the arguments after expansion have no tokens, evaluates to `1`. Otherwise
// evaluates to `0`.
@@ -139,10 +104,9 @@ static_assert(
// Expands to 1 if the first argument starts with something in parentheses,
// otherwise to 0.
-#define GMOCK_PP_IS_BEGIN_PARENS(...) \
- GMOCK_PP_INTERNAL_ALTERNATE_HEAD( \
- GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
- GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
+#define GMOCK_PP_IS_BEGIN_PARENS(...) \
+ GMOCK_PP_HEAD(GMOCK_PP_CAT(GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_, \
+ GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C __VA_ARGS__))
// Expands to 1 is there is only one argument and it is enclosed in parentheses.
#define GMOCK_PP_IS_ENCLOSED_PARENS(...) \
@@ -179,10 +143,6 @@ static_assert(
#define GMOCK_PP_INTENRAL_EMPTY_TUPLE (, , , , , , , , , , , , , , , )
#define GMOCK_PP_INTERNAL_CAT(_1, _2) _1##_2
#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, \
- ...) \
- _16
#define GMOCK_PP_INTERNAL_CAT_5(_1, _2, _3, _4, _5) _1##_2##_3##_4##_5
#define GMOCK_PP_INTERNAL_IS_EMPTY(_1, _2, _3, _4) \
GMOCK_PP_HAS_COMMA(GMOCK_PP_INTERNAL_CAT_5(GMOCK_PP_INTERNAL_IS_EMPTY_CASE_, \
@@ -190,30 +150,24 @@ static_assert(
#define GMOCK_PP_INTERNAL_IS_EMPTY_CASE_0001 ,
#define GMOCK_PP_INTERNAL_IF_1(_Then, _Else) _Then
#define GMOCK_PP_INTERNAL_IF_0(_Then, _Else) _Else
-#define GMOCK_PP_INTERNAL_HEAD(_1, ...) _1
-#define GMOCK_PP_INTERNAL_TAIL(_1, ...) __VA_ARGS__
-#if GMOCK_PP_INTERNAL_USE_MSVC
-#define GMOCK_PP_INTERNAL_NARG_CAT(_1, _2) GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_HEAD_CAT(_1, _2) GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT(_1, _2) \
- GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_TAIL_CAT(_1, _2) GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT(_1, _2) \
- GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_NARG_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_HEAD_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_HAS_COMMA_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_TAIL_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_VARIADIC_CALL_CAT_I(_1, _2) _1##_2
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) \
- GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(GMOCK_PP_HEAD(__VA_ARGS__), )
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT(_1, _2) \
- GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2)
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD_CAT_I(_1, _2) _1##_2
-#else // GMOCK_PP_INTERNAL_USE_MSVC
-#define GMOCK_PP_INTERNAL_ALTERNATE_HEAD(...) GMOCK_PP_HEAD(__VA_ARGS__)
-#endif // GMOCK_PP_INTERNAL_USE_MSVC
+// Because of MSVC treating a token with a comma in it as a single token when
+// passed to another macro, we need to force it to evaluate it as multiple
+// tokens. We do that by using a "IDENTITY(MACRO PARENTHESIZED_ARGS)" macro. We
+// define one per possible macro that relies on this behavior. Note "_Args" must
+// be parenthesized.
+#define GMOCK_PP_INTERNAL_INTERNAL_16TH(_1, _2, _3, _4, _5, _6, _7, _8, _9, \
+ _10, _11, _12, _13, _14, _15, _16, \
+ ...) \
+ _16
+#define GMOCK_PP_INTERNAL_16TH(_Args) \
+ GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_16TH _Args)
+#define GMOCK_PP_INTERNAL_INTERNAL_HEAD(_1, ...) _1
+#define GMOCK_PP_INTERNAL_HEAD(_Args) \
+ GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_HEAD _Args)
+#define GMOCK_PP_INTERNAL_INTERNAL_TAIL(_1, ...) __VA_ARGS__
+#define GMOCK_PP_INTERNAL_TAIL(_Args) \
+ GMOCK_PP_IDENTITY(GMOCK_PP_INTERNAL_INTERNAL_TAIL _Args)
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_C(...) 1 _
#define GMOCK_PP_INTERNAL_IBP_IS_VARIADIC_R_1 1,
diff --git a/googlemock/scripts/README.md b/googlemock/scripts/README.md
new file mode 100644
index 00000000..fa359fed
--- /dev/null
+++ b/googlemock/scripts/README.md
@@ -0,0 +1,5 @@
+# Please Note:
+
+Files in this directory are no longer supported by the maintainers. They
+represent mosty historical artifacts and supported by the community only. There
+is no guarantee whatsoever that these scripts still work.
diff --git a/googlemock/scripts/generator/cpp/ast.py b/googlemock/scripts/generator/cpp/ast.py
index f14728b4..77bbec99 100755
--- a/googlemock/scripts/generator/cpp/ast.py
+++ b/googlemock/scripts/generator/cpp/ast.py
@@ -17,10 +17,7 @@
"""Generate an Abstract Syntax Tree (AST) for C++."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
-# TODO:
+# FIXME:
# * Tokens should never be exported, need to convert to Nodes
# (return types, parameters, etc.)
# * Handle static class data for templatized classes
@@ -338,7 +335,7 @@ class Class(_GenericDeclaration):
# TODO(nnorwitz): handle namespaces, etc.
if self.bases:
for token_list in self.bases:
- # TODO(nnorwitz): bases are tokens, do name comparison.
+ # TODO(nnorwitz): bases are tokens, do name comparision.
for token in token_list:
if token.name == node.name:
return True
@@ -381,7 +378,7 @@ class Function(_GenericDeclaration):
def Requires(self, node):
if self.parameters:
- # TODO(nnorwitz): parameters are tokens, do name comparison.
+ # TODO(nnorwitz): parameters are tokens, do name comparision.
for p in self.parameters:
if p.name == node.name:
return True
@@ -739,6 +736,14 @@ class AstBuilder(object):
if token.token_type == tokenize.NAME:
if (keywords.IsKeyword(token.name) and
not keywords.IsBuiltinType(token.name)):
+ if token.name == 'enum':
+ # Pop the next token and only put it back if it's not
+ # 'class'. This allows us to support the two-token
+ # 'enum class' keyword as if it were simply 'enum'.
+ next = self._GetNextToken()
+ if next.name != 'class':
+ self._AddBackToken(next)
+
method = getattr(self, 'handle_' + token.name)
return method()
elif token.name == self.in_class_name_only:
@@ -754,7 +759,8 @@ class AstBuilder(object):
# Handle data or function declaration/definition.
syntax = tokenize.SYNTAX
temp_tokens, last_token = \
- self._GetVarTokensUpTo(syntax, '(', ';', '{', '[')
+ self._GetVarTokensUpToIgnoringTemplates(syntax,
+ '(', ';', '{', '[')
temp_tokens.insert(0, token)
if last_token.name == '(':
# If there is an assignment before the paren,
@@ -858,7 +864,25 @@ class AstBuilder(object):
last_token = self._GetNextToken()
return tokens, last_token
- # TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necessary.
+ # Same as _GetVarTokensUpTo, but skips over '<...>' which could contain an
+ # expected token.
+ def _GetVarTokensUpToIgnoringTemplates(self, expected_token_type,
+ *expected_tokens):
+ last_token = self._GetNextToken()
+ tokens = []
+ nesting = 0
+ while (nesting > 0 or
+ last_token.token_type != expected_token_type or
+ last_token.name not in expected_tokens):
+ tokens.append(last_token)
+ last_token = self._GetNextToken()
+ if last_token.name == '<':
+ nesting += 1
+ elif last_token.name == '>':
+ nesting -= 1
+ return tokens, last_token
+
+ # TODO(nnorwitz): remove _IgnoreUpTo() it shouldn't be necesary.
def _IgnoreUpTo(self, token_type, token):
unused_tokens = self._GetTokensUpTo(token_type, token)
@@ -1264,9 +1288,6 @@ class AstBuilder(object):
return self._GetNestedType(Union)
def handle_enum(self):
- token = self._GetNextToken()
- if not (token.token_type == tokenize.NAME and token.name == 'class'):
- self._AddBackToken(token)
return self._GetNestedType(Enum)
def handle_auto(self):
@@ -1298,7 +1319,8 @@ class AstBuilder(object):
if token2.token_type == tokenize.SYNTAX and token2.name == '~':
return self.GetMethod(FUNCTION_VIRTUAL + FUNCTION_DTOR, None)
assert token.token_type == tokenize.NAME or token.name == '::', token
- return_type_and_name = self._GetTokensUpTo(tokenize.SYNTAX, '(') # )
+ return_type_and_name, _ = self._GetVarTokensUpToIgnoringTemplates(
+ tokenize.SYNTAX, '(') # )
return_type_and_name.insert(0, token)
if token2 is not token:
return_type_and_name.insert(1, token2)
diff --git a/googlemock/scripts/generator/cpp/gmock_class.py b/googlemock/scripts/generator/cpp/gmock_class.py
index f9966cbb..86dcedbf 100755
--- a/googlemock/scripts/generator/cpp/gmock_class.py
+++ b/googlemock/scripts/generator/cpp/gmock_class.py
@@ -1,18 +1,33 @@
#!/usr/bin/env python
#
-# Copyright 2008 Google Inc. All Rights Reserved.
+# Copyright 2008, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Generate Google Mock classes from base classes.
@@ -26,9 +41,6 @@ Usage:
Output is sent to stdout.
"""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
import os
import re
import sys
@@ -48,6 +60,50 @@ _VERSION = (1, 0, 1) # The version of this script.
_INDENT = 2
+def _RenderType(ast_type):
+ """Renders the potentially recursively templated type into a string.
+
+ Args:
+ ast_type: The AST of the type.
+
+ Returns:
+ Rendered string and a boolean to indicate whether we have multiple args
+ (which is not handled correctly).
+ """
+ has_multiarg_error = False
+ # Add modifiers like 'const'.
+ modifiers = ''
+ if ast_type.modifiers:
+ modifiers = ' '.join(ast_type.modifiers) + ' '
+ return_type = modifiers + ast_type.name
+ if ast_type.templated_types:
+ # Collect template args.
+ template_args = []
+ for arg in ast_type.templated_types:
+ rendered_arg, e = _RenderType(arg)
+ if e: has_multiarg_error = True
+ template_args.append(rendered_arg)
+ return_type += '<' + ', '.join(template_args) + '>'
+ # We are actually not handling multi-template-args correctly. So mark it.
+ if len(template_args) > 1:
+ has_multiarg_error = True
+ if ast_type.pointer:
+ return_type += '*'
+ if ast_type.reference:
+ return_type += '&'
+ return return_type, has_multiarg_error
+
+
+def _GetNumParameters(parameters, source):
+ num_parameters = len(parameters)
+ if num_parameters == 1:
+ first_param = parameters[0]
+ if source[first_param.start:first_param.end].strip() == 'void':
+ # We must treat T(void) as a function with no parameters.
+ return 0
+ return num_parameters
+
+
def _GenerateMethods(output_lines, source, class_node):
function_type = (ast.FUNCTION_VIRTUAL | ast.FUNCTION_PURE_VIRTUAL |
ast.FUNCTION_OVERRIDE)
@@ -63,32 +119,16 @@ def _GenerateMethods(output_lines, source, class_node):
const = ''
if node.modifiers & ast.FUNCTION_CONST:
const = 'CONST_'
+ num_parameters = _GetNumParameters(node.parameters, source)
return_type = 'void'
if node.return_type:
- # Add modifiers like 'const'.
- modifiers = ''
- if node.return_type.modifiers:
- modifiers = ' '.join(node.return_type.modifiers) + ' '
- return_type = modifiers + node.return_type.name
- template_args = [arg.name for arg in node.return_type.templated_types]
- if template_args:
- return_type += '<' + ', '.join(template_args) + '>'
- if len(template_args) > 1:
- for line in [
- '// The following line won\'t really compile, as the return',
- '// type has multiple template arguments. To fix it, use a',
- '// typedef for the return type.']:
- output_lines.append(indent + line)
- if node.return_type.pointer:
- return_type += '*'
- if node.return_type.reference:
- return_type += '&'
- num_parameters = len(node.parameters)
- if len(node.parameters) == 1:
- first_param = node.parameters[0]
- if source[first_param.start:first_param.end].strip() == 'void':
- # We must treat T(void) as a function with no parameters.
- num_parameters = 0
+ return_type, has_multiarg_error = _RenderType(node.return_type)
+ if has_multiarg_error:
+ for line in [
+ '// The following line won\'t really compile, as the return',
+ '// type has multiple template arguments. To fix it, use a',
+ '// typedef for the return type.']:
+ output_lines.append(indent + line)
tmpl = ''
if class_node.templated_types:
tmpl = '_T'
diff --git a/googlemock/scripts/generator/cpp/gmock_class_test.py b/googlemock/scripts/generator/cpp/gmock_class_test.py
index c53e6000..05051626 100755
--- a/googlemock/scripts/generator/cpp/gmock_class_test.py
+++ b/googlemock/scripts/generator/cpp/gmock_class_test.py
@@ -1,25 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2009 Neal Norwitz All Rights Reserved.
-# Portions Copyright 2009 Google Inc. All Rights Reserved.
+# Copyright 2009, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tests for gmock.scripts.generator.cpp.gmock_class."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
import os
import sys
import unittest
@@ -444,19 +455,63 @@ void(const FooType& test_arg));
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
- def testEnumClass(self):
+ def testEnumType(self):
source = """
class Test {
public:
- enum class Baz { BAZINGA };
- virtual void Bar(const FooType& test_arg);
+ enum Bar {
+ BAZ, QUX, QUUX, QUUUX
+ };
+ virtual void Foo();
};
"""
expected = """\
class MockTest : public Test {
public:
-MOCK_METHOD1(Bar,
-void(const FooType& test_arg));
+MOCK_METHOD0(Foo,
+void());
+};
+"""
+ self.assertEqualIgnoreLeadingWhitespace(
+ expected, self.GenerateMocks(source))
+
+ def testEnumClassType(self):
+ source = """
+class Test {
+ public:
+ enum class Bar {
+ BAZ, QUX, QUUX, QUUUX
+ };
+ virtual void Foo();
+};
+"""
+ expected = """\
+class MockTest : public Test {
+public:
+MOCK_METHOD0(Foo,
+void());
+};
+"""
+ self.assertEqualIgnoreLeadingWhitespace(
+ expected, self.GenerateMocks(source))
+
+ def testStdFunction(self):
+ source = """
+class Test {
+ public:
+ Test(std::function<int(std::string)> foo) : foo_(foo) {}
+
+ virtual std::function<int(std::string)> foo();
+
+ private:
+ std::function<int(std::string)> foo_;
+};
+"""
+ expected = """\
+class MockTest : public Test {
+public:
+MOCK_METHOD0(foo,
+std::function<int (std::string)>());
};
"""
self.assertEqualIgnoreLeadingWhitespace(
diff --git a/googlemock/scripts/generator/cpp/keywords.py b/googlemock/scripts/generator/cpp/keywords.py
index f694450e..8b75c2b4 100755
--- a/googlemock/scripts/generator/cpp/keywords.py
+++ b/googlemock/scripts/generator/cpp/keywords.py
@@ -1,25 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2007 Neal Norwitz
-# Portions Copyright 2007 Google Inc.
+# Copyright 2007, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""C++ keywords and helper utilities for determining keywords."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
try:
# Python 3.x
import builtins
diff --git a/googlemock/scripts/generator/cpp/tokenize.py b/googlemock/scripts/generator/cpp/tokenize.py
index 359d5562..c64dcdee 100755
--- a/googlemock/scripts/generator/cpp/tokenize.py
+++ b/googlemock/scripts/generator/cpp/tokenize.py
@@ -1,25 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2007 Neal Norwitz
-# Portions Copyright 2007 Google Inc.
+# Copyright 2007, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tokenize C++ source code."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
try:
# Python 3.x
import builtins
diff --git a/googlemock/scripts/generator/cpp/utils.py b/googlemock/scripts/generator/cpp/utils.py
index eab36eec..6945a78c 100755
--- a/googlemock/scripts/generator/cpp/utils.py
+++ b/googlemock/scripts/generator/cpp/utils.py
@@ -1,28 +1,38 @@
#!/usr/bin/env python
#
-# Copyright 2007 Neal Norwitz
-# Portions Copyright 2007 Google Inc.
+# Copyright 2007, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Generic utilities for C++ parsing."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
-
-
import sys
-
# Set to True to see the start/end token indices.
DEBUG = True
diff --git a/googlemock/scripts/generator/gmock_gen.py b/googlemock/scripts/generator/gmock_gen.py
index 8cc0d135..34a7f887 100755
--- a/googlemock/scripts/generator/gmock_gen.py
+++ b/googlemock/scripts/generator/gmock_gen.py
@@ -1,22 +1,36 @@
#!/usr/bin/env python
#
-# Copyright 2008 Google Inc. All Rights Reserved.
+# Copyright 2008, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Driver for starting up Google Mock class generator."""
-__author__ = 'nnorwitz@google.com (Neal Norwitz)'
import os
import sys
diff --git a/googlemock/scripts/gmock-config.in b/googlemock/scripts/gmock-config.in
deleted file mode 100755
index 2baefe94..00000000
--- a/googlemock/scripts/gmock-config.in
+++ /dev/null
@@ -1,303 +0,0 @@
-#!/bin/sh
-
-# These variables are automatically filled in by the configure script.
-name="@PACKAGE_TARNAME@"
-version="@PACKAGE_VERSION@"
-
-show_usage()
-{
- echo "Usage: gmock-config [OPTIONS...]"
-}
-
-show_help()
-{
- show_usage
- cat <<\EOF
-
-The `gmock-config' script provides access to the necessary compile and linking
-flags to connect with Google C++ Mocking Framework, both in a build prior to
-installation, and on the system proper after installation. The installation
-overrides may be issued in combination with any other queries, but will only
-affect installation queries if called on a built but not installed gmock. The
-installation queries may not be issued with any other types of queries, and
-only one installation query may be made at a time. The version queries and
-compiler flag queries may be combined as desired but not mixed. Different
-version queries are always combined with logical "and" semantics, and only the
-last of any particular query is used while all previous ones ignored. All
-versions must be specified as a sequence of numbers separated by periods.
-Compiler flag queries output the union of the sets of flags when combined.
-
- Examples:
- gmock-config --min-version=1.0 || echo "Insufficient Google Mock version."
-
- g++ $(gmock-config --cppflags --cxxflags) -o foo.o -c foo.cpp
- g++ $(gmock-config --ldflags --libs) -o foo foo.o
-
- # When using a built but not installed Google Mock:
- g++ $(../../my_gmock_build/scripts/gmock-config ...) ...
-
- # When using an installed Google Mock, but with installation overrides:
- export GMOCK_PREFIX="/opt"
- g++ $(gmock-config --libdir="/opt/lib64" ...) ...
-
- Help:
- --usage brief usage information
- --help display this help message
-
- Installation Overrides:
- --prefix=<dir> overrides the installation prefix
- --exec-prefix=<dir> overrides the executable installation prefix
- --libdir=<dir> overrides the library installation prefix
- --includedir=<dir> overrides the header file installation prefix
-
- Installation Queries:
- --prefix installation prefix
- --exec-prefix executable installation prefix
- --libdir library installation directory
- --includedir header file installation directory
- --version the version of the Google Mock installation
-
- Version Queries:
- --min-version=VERSION return 0 if the version is at least VERSION
- --exact-version=VERSION return 0 if the version is exactly VERSION
- --max-version=VERSION return 0 if the version is at most VERSION
-
- Compilation Flag Queries:
- --cppflags compile flags specific to the C-like preprocessors
- --cxxflags compile flags appropriate for C++ programs
- --ldflags linker flags
- --libs libraries for linking
-
-EOF
-}
-
-# This function bounds our version with a min and a max. It uses some clever
-# POSIX-compliant variable expansion to portably do all the work in the shell
-# and avoid any dependency on a particular "sed" or "awk" implementation.
-# Notable is that it will only ever compare the first 3 components of versions.
-# Further components will be cleanly stripped off. All versions must be
-# unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and
-# the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should
-# investigate expanding this via autom4te from AS_VERSION_COMPARE rather than
-# continuing to maintain our own shell version.
-check_versions()
-{
- major_version=${version%%.*}
- minor_version="0"
- point_version="0"
- if test "${version#*.}" != "${version}"; then
- minor_version=${version#*.}
- minor_version=${minor_version%%.*}
- fi
- if test "${version#*.*.}" != "${version}"; then
- point_version=${version#*.*.}
- point_version=${point_version%%.*}
- fi
-
- min_version="$1"
- min_major_version=${min_version%%.*}
- min_minor_version="0"
- min_point_version="0"
- if test "${min_version#*.}" != "${min_version}"; then
- min_minor_version=${min_version#*.}
- min_minor_version=${min_minor_version%%.*}
- fi
- if test "${min_version#*.*.}" != "${min_version}"; then
- min_point_version=${min_version#*.*.}
- min_point_version=${min_point_version%%.*}
- fi
-
- max_version="$2"
- max_major_version=${max_version%%.*}
- max_minor_version="0"
- max_point_version="0"
- if test "${max_version#*.}" != "${max_version}"; then
- max_minor_version=${max_version#*.}
- max_minor_version=${max_minor_version%%.*}
- fi
- if test "${max_version#*.*.}" != "${max_version}"; then
- max_point_version=${max_version#*.*.}
- max_point_version=${max_point_version%%.*}
- fi
-
- test $(($major_version)) -lt $(($min_major_version)) && exit 1
- if test $(($major_version)) -eq $(($min_major_version)); then
- test $(($minor_version)) -lt $(($min_minor_version)) && exit 1
- if test $(($minor_version)) -eq $(($min_minor_version)); then
- test $(($point_version)) -lt $(($min_point_version)) && exit 1
- fi
- fi
-
- test $(($major_version)) -gt $(($max_major_version)) && exit 1
- if test $(($major_version)) -eq $(($max_major_version)); then
- test $(($minor_version)) -gt $(($max_minor_version)) && exit 1
- if test $(($minor_version)) -eq $(($max_minor_version)); then
- test $(($point_version)) -gt $(($max_point_version)) && exit 1
- fi
- fi
-
- exit 0
-}
-
-# Show the usage line when no arguments are specified.
-if test $# -eq 0; then
- show_usage
- exit 1
-fi
-
-while test $# -gt 0; do
- case $1 in
- --usage) show_usage; exit 0;;
- --help) show_help; exit 0;;
-
- # Installation overrides
- --prefix=*) GMOCK_PREFIX=${1#--prefix=};;
- --exec-prefix=*) GMOCK_EXEC_PREFIX=${1#--exec-prefix=};;
- --libdir=*) GMOCK_LIBDIR=${1#--libdir=};;
- --includedir=*) GMOCK_INCLUDEDIR=${1#--includedir=};;
-
- # Installation queries
- --prefix|--exec-prefix|--libdir|--includedir|--version)
- if test -n "${do_query}"; then
- show_usage
- exit 1
- fi
- do_query=${1#--}
- ;;
-
- # Version checking
- --min-version=*)
- do_check_versions=yes
- min_version=${1#--min-version=}
- ;;
- --max-version=*)
- do_check_versions=yes
- max_version=${1#--max-version=}
- ;;
- --exact-version=*)
- do_check_versions=yes
- exact_version=${1#--exact-version=}
- ;;
-
- # Compiler flag output
- --cppflags) echo_cppflags=yes;;
- --cxxflags) echo_cxxflags=yes;;
- --ldflags) echo_ldflags=yes;;
- --libs) echo_libs=yes;;
-
- # Everything else is an error
- *) show_usage; exit 1;;
- esac
- shift
-done
-
-# These have defaults filled in by the configure script but can also be
-# overridden by environment variables or command line parameters.
-prefix="${GMOCK_PREFIX:-@prefix@}"
-exec_prefix="${GMOCK_EXEC_PREFIX:-@exec_prefix@}"
-libdir="${GMOCK_LIBDIR:-@libdir@}"
-includedir="${GMOCK_INCLUDEDIR:-@includedir@}"
-
-# We try and detect if our binary is not located at its installed location. If
-# it's not, we provide variables pointing to the source and build tree rather
-# than to the install tree. We also locate Google Test using the configured
-# gtest-config script rather than searching the PATH and our bindir for one.
-# This allows building against a just-built gmock rather than an installed
-# gmock.
-bindir="@bindir@"
-this_relative_bindir=`dirname $0`
-this_bindir=`cd ${this_relative_bindir}; pwd -P`
-if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
- # The path to the script doesn't end in the bindir sequence from Autoconf,
- # assume that we are in a build tree.
- build_dir=`dirname ${this_bindir}`
- src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P`
-
- # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we
- # should work to remove it, and/or remove libtool altogether, replacing it
- # with direct references to the library and a link path.
- gmock_libs="${build_dir}/lib/libgmock.la"
- gmock_ldflags=""
-
- # We provide hooks to include from either the source or build dir, where the
- # build dir is always preferred. This will potentially allow us to write
- # build rules for generated headers and have them automatically be preferred
- # over provided versions.
- gmock_cppflags="-I${build_dir}/include -I${src_dir}/include"
- gmock_cxxflags=""
-
- # Directly invoke the gtest-config script used during the build process.
- gtest_config="@GTEST_CONFIG@"
-else
- # We're using an installed gmock, although it may be staged under some
- # prefix. Assume (as our own libraries do) that we can resolve the prefix,
- # and are present in the dynamic link paths.
- gmock_ldflags="-L${libdir}"
- gmock_libs="-l${name}"
- gmock_cppflags="-I${includedir}"
- gmock_cxxflags=""
-
- # We also prefer any gtest-config script installed in our prefix. Lacking
- # one, we look in the PATH for one.
- gtest_config="${bindir}/gtest-config"
- if test ! -x "${gtest_config}"; then
- gtest_config=`which gtest-config`
- fi
-fi
-
-# Ensure that we have located a Google Test to link against.
-if ! test -x "${gtest_config}"; then
- echo "Unable to locate Google Test, check your Google Mock configuration" \
- "and installation" >&2
- exit 1
-elif ! "${gtest_config}" "--exact-version=@GTEST_VERSION@"; then
- echo "The Google Test found is not the same version as Google Mock was " \
- "built against" >&2
- exit 1
-fi
-
-# Add the necessary Google Test bits into the various flag variables
-gmock_cppflags="${gmock_cppflags} `${gtest_config} --cppflags`"
-gmock_cxxflags="${gmock_cxxflags} `${gtest_config} --cxxflags`"
-gmock_ldflags="${gmock_ldflags} `${gtest_config} --ldflags`"
-gmock_libs="${gmock_libs} `${gtest_config} --libs`"
-
-# Do an installation query if requested.
-if test -n "$do_query"; then
- case $do_query in
- prefix) echo $prefix; exit 0;;
- exec-prefix) echo $exec_prefix; exit 0;;
- libdir) echo $libdir; exit 0;;
- includedir) echo $includedir; exit 0;;
- version) echo $version; exit 0;;
- *) show_usage; exit 1;;
- esac
-fi
-
-# Do a version check if requested.
-if test "$do_check_versions" = "yes"; then
- # Make sure we didn't receive a bad combination of parameters.
- test "$echo_cppflags" = "yes" && show_usage && exit 1
- test "$echo_cxxflags" = "yes" && show_usage && exit 1
- test "$echo_ldflags" = "yes" && show_usage && exit 1
- test "$echo_libs" = "yes" && show_usage && exit 1
-
- if test "$exact_version" != ""; then
- check_versions $exact_version $exact_version
- # unreachable
- else
- check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999}
- # unreachable
- fi
-fi
-
-# Do the output in the correct order so that these can be used in-line of
-# a compiler invocation.
-output=""
-test "$echo_cppflags" = "yes" && output="$output $gmock_cppflags"
-test "$echo_cxxflags" = "yes" && output="$output $gmock_cxxflags"
-test "$echo_ldflags" = "yes" && output="$output $gmock_ldflags"
-test "$echo_libs" = "yes" && output="$output $gmock_libs"
-echo $output
-
-exit 0
diff --git a/googlemock/scripts/gmock_doctor.py b/googlemock/scripts/gmock_doctor.py
deleted file mode 100755
index 74992bc7..00000000
--- a/googlemock/scripts/gmock_doctor.py
+++ /dev/null
@@ -1,640 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2008, Google Inc.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-"""Converts compiler's errors in code using Google Mock to plain English."""
-
-__author__ = 'wan@google.com (Zhanyong Wan)'
-
-import re
-import sys
-
-_VERSION = '1.0.3'
-
-_EMAIL = 'googlemock@googlegroups.com'
-
-_COMMON_GMOCK_SYMBOLS = [
- # Matchers
- '_',
- 'A',
- 'AddressSatisfies',
- 'AllOf',
- 'An',
- 'AnyOf',
- 'ContainerEq',
- 'Contains',
- 'ContainsRegex',
- 'DoubleEq',
- 'ElementsAre',
- 'ElementsAreArray',
- 'EndsWith',
- 'Eq',
- 'Field',
- 'FloatEq',
- 'Ge',
- 'Gt',
- 'HasSubstr',
- 'IsInitializedProto',
- 'Le',
- 'Lt',
- 'MatcherCast',
- 'Matches',
- 'MatchesRegex',
- 'NanSensitiveDoubleEq',
- 'NanSensitiveFloatEq',
- 'Ne',
- 'Not',
- 'NotNull',
- 'Pointee',
- 'Property',
- 'Ref',
- 'ResultOf',
- 'SafeMatcherCast',
- 'StartsWith',
- 'StrCaseEq',
- 'StrCaseNe',
- 'StrEq',
- 'StrNe',
- 'Truly',
- 'TypedEq',
- 'Value',
-
- # Actions
- 'Assign',
- 'ByRef',
- 'DeleteArg',
- 'DoAll',
- 'DoDefault',
- 'IgnoreResult',
- 'Invoke',
- 'InvokeArgument',
- 'InvokeWithoutArgs',
- 'Return',
- 'ReturnNew',
- 'ReturnNull',
- 'ReturnRef',
- 'SaveArg',
- 'SetArgReferee',
- 'SetArgPointee',
- 'SetArgumentPointee',
- 'SetArrayArgument',
- 'SetErrnoAndReturn',
- 'Throw',
- 'WithArg',
- 'WithArgs',
- 'WithoutArgs',
-
- # Cardinalities
- 'AnyNumber',
- 'AtLeast',
- 'AtMost',
- 'Between',
- 'Exactly',
-
- # Sequences
- 'InSequence',
- 'Sequence',
-
- # Misc
- 'DefaultValue',
- 'Mock',
- ]
-
-# Regex for matching source file path and line number in the compiler's errors.
-_GCC_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):(\d+:)?\s+'
-_CLANG_FILE_LINE_RE = r'(?P<file>.*):(?P<line>\d+):(?P<column>\d+):\s+'
-_CLANG_NON_GMOCK_FILE_LINE_RE = (
- r'(?P<file>.*[/\\^](?!gmock-)[^/\\]+):(?P<line>\d+):(?P<column>\d+):\s+')
-
-
-def _FindAllMatches(regex, s):
- """Generates all matches of regex in string s."""
-
- r = re.compile(regex)
- return r.finditer(s)
-
-
-def _GenericDiagnoser(short_name, long_name, diagnoses, msg):
- """Diagnoses the given disease by pattern matching.
-
- Can provide different diagnoses for different patterns.
-
- Args:
- short_name: Short name of the disease.
- long_name: Long name of the disease.
- diagnoses: A list of pairs (regex, pattern for formatting the diagnosis
- for matching regex).
- msg: Compiler's error messages.
- Yields:
- Tuples of the form
- (short name of disease, long name of disease, diagnosis).
- """
- for regex, diagnosis in diagnoses:
- if re.search(regex, msg):
- diagnosis = '%(file)s:%(line)s:' + diagnosis
- for m in _FindAllMatches(regex, msg):
- yield (short_name, long_name, diagnosis % m.groupdict())
-
-
-def _NeedToReturnReferenceDiagnoser(msg):
- """Diagnoses the NRR disease, given the error messages by the compiler."""
-
- gcc_regex = (r'In member function \'testing::internal::ReturnAction<R>.*\n'
- + _GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*gmock-actions\.h.*error: creating array with negative size')
- clang_regex = (r'error:.*array.*negative.*\r?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE +
- r'note: in instantiation of function template specialization '
- r'\'testing::internal::ReturnAction<(?P<type>.*)>'
- r'::operator Action<.*>\' requested here')
- clang11_re = (r'use_ReturnRef_instead_of_Return_to_return_a_reference.*'
- r'(.*\n)*?' + _CLANG_NON_GMOCK_FILE_LINE_RE)
-
- diagnosis = """
-You are using a Return() action in a function that returns a reference to
-%(type)s. Please use ReturnRef() instead."""
- return _GenericDiagnoser('NRR', 'Need to Return Reference',
- [(clang_regex, diagnosis),
- (clang11_re, diagnosis % {'type': 'a type'}),
- (gcc_regex, diagnosis % {'type': 'a type'})],
- msg)
-
-
-def _NeedToReturnSomethingDiagnoser(msg):
- """Diagnoses the NRS disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'(instantiated from here\n.'
- r'*gmock.*actions\.h.*error: void value not ignored)'
- r'|(error: control reaches end of non-void function)')
- clang_regex1 = (_CLANG_FILE_LINE_RE +
- r'error: cannot initialize return object '
- r'of type \'Result\' \(aka \'(?P<return_type>.*)\'\) '
- r'with an rvalue of type \'void\'')
- clang_regex2 = (_CLANG_FILE_LINE_RE +
- r'error: cannot initialize return object '
- r'of type \'(?P<return_type>.*)\' '
- r'with an rvalue of type \'void\'')
- diagnosis = """
-You are using an action that returns void, but it needs to return
-%(return_type)s. Please tell it *what* to return. Perhaps you can use
-the pattern DoAll(some_action, Return(some_value))?"""
- return _GenericDiagnoser(
- 'NRS',
- 'Need to Return Something',
- [(gcc_regex, diagnosis % {'return_type': '*something*'}),
- (clang_regex1, diagnosis),
- (clang_regex2, diagnosis)],
- msg)
-
-
-def _NeedToReturnNothingDiagnoser(msg):
- """Diagnoses the NRN disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*gmock-actions\.h.*error: instantiation of '
- r'\'testing::internal::ReturnAction<R>::Impl<F>::value_\' '
- r'as type \'void\'')
- clang_regex1 = (r'error: field has incomplete type '
- r'\'Result\' \(aka \'void\'\)(\r)?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE + r'note: in instantiation '
- r'of function template specialization '
- r'\'testing::internal::ReturnAction<(?P<return_type>.*)>'
- r'::operator Action<void \(.*\)>\' requested here')
- clang_regex2 = (r'error: field has incomplete type '
- r'\'Result\' \(aka \'void\'\)(\r)?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE + r'note: in instantiation '
- r'of function template specialization '
- r'\'testing::internal::DoBothAction<.*>'
- r'::operator Action<(?P<return_type>.*) \(.*\)>\' '
- r'requested here')
- diagnosis = """
-You are using an action that returns %(return_type)s, but it needs to return
-void. Please use a void-returning action instead.
-
-All actions but the last in DoAll(...) must return void. Perhaps you need
-to re-arrange the order of actions in a DoAll(), if you are using one?"""
- return _GenericDiagnoser(
- 'NRN',
- 'Need to Return Nothing',
- [(gcc_regex, diagnosis % {'return_type': '*something*'}),
- (clang_regex1, diagnosis),
- (clang_regex2, diagnosis)],
- msg)
-
-
-def _IncompleteByReferenceArgumentDiagnoser(msg):
- """Diagnoses the IBRA disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*gtest-printers\.h.*error: invalid application of '
- r'\'sizeof\' to incomplete type \'(?P<type>.*)\'')
-
- clang_regex = (r'.*gtest-printers\.h.*error: invalid application of '
- r'\'sizeof\' to an incomplete type '
- r'\'(?P<type>.*)( const)?\'\r?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE +
- r'note: in instantiation of member function '
- r'\'testing::internal2::TypeWithoutFormatter<.*>::'
- r'PrintValue\' requested here')
- diagnosis = """
-In order to mock this function, Google Mock needs to see the definition
-of type "%(type)s" - declaration alone is not enough. Either #include
-the header that defines it, or change the argument to be passed
-by pointer."""
-
- return _GenericDiagnoser('IBRA', 'Incomplete By-Reference Argument Type',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _OverloadedFunctionMatcherDiagnoser(msg):
- """Diagnoses the OFM disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: no matching function for '
- r'call to \'Truly\(<unresolved overloaded function type>\)')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: no matching function for '
- r'call to \'Truly')
- diagnosis = """
-The argument you gave to Truly() is an overloaded function. Please tell
-your compiler which overloaded version you want to use.
-
-For example, if you want to use the version whose signature is
- bool Foo(int n);
-you should write
- Truly(static_cast<bool (*)(int n)>(Foo))"""
- return _GenericDiagnoser('OFM', 'Overloaded Function Matcher',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _OverloadedFunctionActionDiagnoser(msg):
- """Diagnoses the OFA disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: no matching function for call to '
- r'\'Invoke\(<unresolved overloaded function type>')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: no matching '
- r'function for call to \'Invoke\'\r?\n'
- r'(.*\n)*?'
- r'.*\bgmock-generated-actions\.h:\d+:\d+:\s+'
- r'note: candidate template ignored:\s+'
- r'couldn\'t infer template argument \'FunctionImpl\'')
- diagnosis = """
-Function you are passing to Invoke is overloaded. Please tell your compiler
-which overloaded version you want to use.
-
-For example, if you want to use the version whose signature is
- bool MyFunction(int n, double x);
-you should write something like
- Invoke(static_cast<bool (*)(int n, double x)>(MyFunction))"""
- return _GenericDiagnoser('OFA', 'Overloaded Function Action',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _OverloadedMethodActionDiagnoser(msg):
- """Diagnoses the OMA disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: no matching function for '
- r'call to \'Invoke\(.+, <unresolved overloaded function '
- r'type>\)')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: no matching function '
- r'for call to \'Invoke\'\r?\n'
- r'(.*\n)*?'
- r'.*\bgmock-generated-actions\.h:\d+:\d+: '
- r'note: candidate function template not viable: '
- r'requires .*, but 2 (arguments )?were provided')
- diagnosis = """
-The second argument you gave to Invoke() is an overloaded method. Please
-tell your compiler which overloaded version you want to use.
-
-For example, if you want to use the version whose signature is
- class Foo {
- ...
- bool Bar(int n, double x);
- };
-you should write something like
- Invoke(foo, static_cast<bool (Foo::*)(int n, double x)>(&Foo::Bar))"""
- return _GenericDiagnoser('OMA', 'Overloaded Method Action',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _MockObjectPointerDiagnoser(msg):
- """Diagnoses the MOP disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: request for member '
- r'\'gmock_(?P<method>.+)\' in \'(?P<mock_object>.+)\', '
- r'which is of non-class type \'(.*::)*(?P<class_name>.+)\*\'')
- clang_regex = (_CLANG_FILE_LINE_RE + r'error: member reference type '
- r'\'(?P<class_name>.*?) *\' is a pointer; '
- r'(did you mean|maybe you meant) to use \'->\'\?')
- diagnosis = """
-The first argument to ON_CALL() and EXPECT_CALL() must be a mock *object*,
-not a *pointer* to it. Please write '*(%(mock_object)s)' instead of
-'%(mock_object)s' as your first argument.
-
-For example, given the mock class:
-
- class %(class_name)s : public ... {
- ...
- MOCK_METHOD0(%(method)s, ...);
- };
-
-and the following mock instance:
-
- %(class_name)s* mock_ptr = ...
-
-you should use the EXPECT_CALL like this:
-
- EXPECT_CALL(*mock_ptr, %(method)s(...));"""
-
- return _GenericDiagnoser(
- 'MOP',
- 'Mock Object Pointer',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis % {'mock_object': 'mock_object',
- 'method': 'method',
- 'class_name': '%(class_name)s'})],
- msg)
-
-
-def _NeedToUseSymbolDiagnoser(msg):
- """Diagnoses the NUS disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE + r'error: \'(?P<symbol>.+)\' '
- r'(was not declared in this scope|has not been declared)')
- clang_regex = (_CLANG_FILE_LINE_RE +
- r'error: (use of undeclared identifier|unknown type name|'
- r'no template named) \'(?P<symbol>[^\']+)\'')
- diagnosis = """
-'%(symbol)s' is defined by Google Mock in the testing namespace.
-Did you forget to write
- using testing::%(symbol)s;
-?"""
- for m in (list(_FindAllMatches(gcc_regex, msg)) +
- list(_FindAllMatches(clang_regex, msg))):
- symbol = m.groupdict()['symbol']
- if symbol in _COMMON_GMOCK_SYMBOLS:
- yield ('NUS', 'Need to Use Symbol', diagnosis % m.groupdict())
-
-
-def _NeedToUseReturnNullDiagnoser(msg):
- """Diagnoses the NRNULL disease, given the error messages by the compiler."""
-
- gcc_regex = ('instantiated from \'testing::internal::ReturnAction<R>'
- '::operator testing::Action<Func>\(\) const.*\n' +
- _GCC_FILE_LINE_RE + r'instantiated from here\n'
- r'.*error: no matching function for call to \'ImplicitCast_\('
- r'(:?long )?int&\)')
- clang_regex = (r'\bgmock-actions.h:.* error: no matching function for '
- r'call to \'ImplicitCast_\'\r?\n'
- r'(.*\n)*?' +
- _CLANG_NON_GMOCK_FILE_LINE_RE + r'note: in instantiation '
- r'of function template specialization '
- r'\'testing::internal::ReturnAction<(int|long)>::operator '
- r'Action<(?P<type>.*)\(\)>\' requested here')
- diagnosis = """
-You are probably calling Return(NULL) and the compiler isn't sure how to turn
-NULL into %(type)s. Use ReturnNull() instead.
-Note: the line number may be off; please fix all instances of Return(NULL)."""
- return _GenericDiagnoser(
- 'NRNULL', 'Need to use ReturnNull',
- [(clang_regex, diagnosis),
- (gcc_regex, diagnosis % {'type': 'the right type'})],
- msg)
-
-
-def _TypeInTemplatedBaseDiagnoser(msg):
- """Diagnoses the TTB disease, given the error messages by the compiler."""
-
- # This version works when the type is used as the mock function's return
- # type.
- gcc_4_3_1_regex_type_in_retval = (
- r'In member function \'int .*\n' + _GCC_FILE_LINE_RE +
- r'error: a function call cannot appear in a constant-expression')
- gcc_4_4_0_regex_type_in_retval = (
- r'error: a function call cannot appear in a constant-expression'
- + _GCC_FILE_LINE_RE + r'error: template argument 1 is invalid\n')
- # This version works when the type is used as the mock function's sole
- # parameter type.
- gcc_regex_type_of_sole_param = (
- _GCC_FILE_LINE_RE +
- r'error: \'(?P<type>.+)\' was not declared in this scope\n'
- r'.*error: template argument 1 is invalid\n')
- # This version works when the type is used as a parameter of a mock
- # function that has multiple parameters.
- gcc_regex_type_of_a_param = (
- r'error: expected `;\' before \'::\' token\n'
- + _GCC_FILE_LINE_RE +
- r'error: \'(?P<type>.+)\' was not declared in this scope\n'
- r'.*error: template argument 1 is invalid\n'
- r'.*error: \'.+\' was not declared in this scope')
- clang_regex_type_of_retval_or_sole_param = (
- _CLANG_FILE_LINE_RE +
- r'error: use of undeclared identifier \'(?P<type>.*)\'\n'
- r'(.*\n)*?'
- r'(?P=file):(?P=line):\d+: error: '
- r'non-friend class member \'Result\' cannot have a qualified name'
- )
- clang_regex_type_of_a_param = (
- _CLANG_FILE_LINE_RE +
- r'error: C\+\+ requires a type specifier for all declarations\n'
- r'(.*\n)*?'
- r'(?P=file):(?P=line):(?P=column): error: '
- r'C\+\+ requires a type specifier for all declarations'
- )
- clang_regex_unknown_type = (
- _CLANG_FILE_LINE_RE +
- r'error: unknown type name \'(?P<type>[^\']+)\''
- )
-
- diagnosis = """
-In a mock class template, types or typedefs defined in the base class
-template are *not* automatically visible. This is how C++ works. Before
-you can use a type or typedef named %(type)s defined in base class Base<T>, you
-need to make it visible. One way to do it is:
-
- typedef typename Base<T>::%(type)s %(type)s;"""
-
- for diag in _GenericDiagnoser(
- 'TTB', 'Type in Template Base',
- [(gcc_4_3_1_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
- (gcc_4_4_0_regex_type_in_retval, diagnosis % {'type': 'Foo'}),
- (gcc_regex_type_of_sole_param, diagnosis),
- (gcc_regex_type_of_a_param, diagnosis),
- (clang_regex_type_of_retval_or_sole_param, diagnosis),
- (clang_regex_type_of_a_param, diagnosis % {'type': 'Foo'})],
- msg):
- yield diag
- # Avoid overlap with the NUS pattern.
- for m in _FindAllMatches(clang_regex_unknown_type, msg):
- type_ = m.groupdict()['type']
- if type_ not in _COMMON_GMOCK_SYMBOLS:
- yield ('TTB', 'Type in Template Base', diagnosis % m.groupdict())
-
-
-def _WrongMockMethodMacroDiagnoser(msg):
- """Diagnoses the WMM disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE +
- r'.*this_method_does_not_take_(?P<wrong_args>\d+)_argument.*\n'
- r'.*\n'
- r'.*candidates are.*FunctionMocker<[^>]+A(?P<args>\d+)\)>')
- clang_regex = (_CLANG_NON_GMOCK_FILE_LINE_RE +
- r'error:.*array.*negative.*r?\n'
- r'(.*\n)*?'
- r'(?P=file):(?P=line):(?P=column): error: too few arguments '
- r'to function call, expected (?P<args>\d+), '
- r'have (?P<wrong_args>\d+)')
- clang11_re = (_CLANG_NON_GMOCK_FILE_LINE_RE +
- r'.*this_method_does_not_take_'
- r'(?P<wrong_args>\d+)_argument.*')
- diagnosis = """
-You are using MOCK_METHOD%(wrong_args)s to define a mock method that has
-%(args)s arguments. Use MOCK_METHOD%(args)s (or MOCK_CONST_METHOD%(args)s,
-MOCK_METHOD%(args)s_T, MOCK_CONST_METHOD%(args)s_T as appropriate) instead."""
- return _GenericDiagnoser('WMM', 'Wrong MOCK_METHODn Macro',
- [(gcc_regex, diagnosis),
- (clang11_re, diagnosis % {'wrong_args': 'm',
- 'args': 'n'}),
- (clang_regex, diagnosis)],
- msg)
-
-
-def _WrongParenPositionDiagnoser(msg):
- """Diagnoses the WPP disease, given the error messages by the compiler."""
-
- gcc_regex = (_GCC_FILE_LINE_RE +
- r'error:.*testing::internal::MockSpec<.* has no member named \''
- r'(?P<method>\w+)\'')
- clang_regex = (_CLANG_NON_GMOCK_FILE_LINE_RE +
- r'error: no member named \'(?P<method>\w+)\' in '
- r'\'testing::internal::MockSpec<.*>\'')
- diagnosis = """
-The closing parenthesis of ON_CALL or EXPECT_CALL should be *before*
-".%(method)s". For example, you should write:
- EXPECT_CALL(my_mock, Foo(_)).%(method)s(...);
-instead of:
- EXPECT_CALL(my_mock, Foo(_).%(method)s(...));"""
- return _GenericDiagnoser('WPP', 'Wrong Parenthesis Position',
- [(gcc_regex, diagnosis),
- (clang_regex, diagnosis)],
- msg)
-
-
-_DIAGNOSERS = [
- _IncompleteByReferenceArgumentDiagnoser,
- _MockObjectPointerDiagnoser,
- _NeedToReturnNothingDiagnoser,
- _NeedToReturnReferenceDiagnoser,
- _NeedToReturnSomethingDiagnoser,
- _NeedToUseReturnNullDiagnoser,
- _NeedToUseSymbolDiagnoser,
- _OverloadedFunctionActionDiagnoser,
- _OverloadedFunctionMatcherDiagnoser,
- _OverloadedMethodActionDiagnoser,
- _TypeInTemplatedBaseDiagnoser,
- _WrongMockMethodMacroDiagnoser,
- _WrongParenPositionDiagnoser,
- ]
-
-
-def Diagnose(msg):
- """Generates all possible diagnoses given the compiler error message."""
-
- msg = re.sub(r'\x1b\[[^m]*m', '', msg) # Strips all color formatting.
- # Assuming the string is using the UTF-8 encoding, replaces the left and
- # the right single quote characters with apostrophes.
- msg = re.sub(r'(\xe2\x80\x98|\xe2\x80\x99)', "'", msg)
-
- diagnoses = []
- for diagnoser in _DIAGNOSERS:
- for diag in diagnoser(msg):
- diagnosis = '[%s - %s]\n%s' % diag
- if not diagnosis in diagnoses:
- diagnoses.append(diagnosis)
- return diagnoses
-
-
-def main():
- print ('Google Mock Doctor v%s - '
- 'diagnoses problems in code using Google Mock.' % _VERSION)
-
- if sys.stdin.isatty():
- print ('Please copy and paste the compiler errors here. Press c-D when '
- 'you are done:')
- else:
- print ('Waiting for compiler errors on stdin . . .')
-
- msg = sys.stdin.read().strip()
- diagnoses = Diagnose(msg)
- count = len(diagnoses)
- if not count:
- print ("""
-Your compiler complained:
-8<------------------------------------------------------------
-%s
------------------------------------------------------------->8
-
-Uh-oh, I'm not smart enough to figure out what the problem is. :-(
-However...
-If you send your source code and the compiler's error messages to
-%s, you can be helped and I can get smarter --
-win-win for us!""" % (msg, _EMAIL))
- else:
- print ('------------------------------------------------------------')
- print ('Your code appears to have the following',)
- if count > 1:
- print ('%s diseases:' % (count,))
- else:
- print ('disease:')
- i = 0
- for d in diagnoses:
- i += 1
- if count > 1:
- print ('\n#%s:' % (i,))
- print (d)
- print ("""
-How did I do? If you think I'm wrong or unhelpful, please send your
-source code and the compiler's error messages to %s.
-Then you can be helped and I can get smarter -- I promise I won't be upset!""" %
- _EMAIL)
-
-
-if __name__ == '__main__':
- main()
diff --git a/googlemock/scripts/upload.py b/googlemock/scripts/upload.py
index 95239dc2..129f53ef 100755
--- a/googlemock/scripts/upload.py
+++ b/googlemock/scripts/upload.py
@@ -1,18 +1,33 @@
#!/usr/bin/env python
#
-# Copyright 2007 Google Inc.
+# Copyright 2009, Google Inc.
+# All rights reserved.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Tool for uploading diffs from a version control system to the codereview app.
diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc
index 16f97b0a..18c500f6 100644
--- a/googlemock/src/gmock_main.cc
+++ b/googlemock/src/gmock_main.cc
@@ -33,9 +33,9 @@
#include "gtest/gtest.h"
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
-# if GTEST_OS_ESP8266
+#if GTEST_OS_ESP8266
extern "C" {
-# endif
+#endif
void setup() {
// Since Google Mock depends on Google Test, InitGoogleMock() is
// also responsible for initializing Google Test. Therefore there's
@@ -43,9 +43,9 @@ void setup() {
testing::InitGoogleMock();
}
void loop() { RUN_ALL_TESTS(); }
-# if GTEST_OS_ESP8266
+#if GTEST_OS_ESP8266
}
-# endif
+#endif
#else
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index f63c8c5a..dcce111a 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -73,6 +73,7 @@ using testing::Return;
using testing::ReturnNull;
using testing::ReturnRef;
using testing::ReturnRefOfCopy;
+using testing::ReturnRoundRobin;
using testing::SetArgPointee;
using testing::SetArgumentPointee;
using testing::Unused;
@@ -670,6 +671,31 @@ TEST(ReturnRefOfCopyTest, IsCovariant) {
EXPECT_NE(&derived, &a.Perform(std::make_tuple()));
}
+// Tests that ReturnRoundRobin(v) works with initializer lists
+TEST(ReturnRoundRobinTest, WorksForInitList) {
+ Action<int()> ret = ReturnRoundRobin({1, 2, 3});
+
+ EXPECT_EQ(1, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(2, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(3, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(1, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(2, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(3, ret.Perform(std::make_tuple()));
+}
+
+// Tests that ReturnRoundRobin(v) works with vectors
+TEST(ReturnRoundRobinTest, WorksForVector) {
+ std::vector<double> v = {4.4, 5.5, 6.6};
+ Action<double()> ret = ReturnRoundRobin(v);
+
+ EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(4.4, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(5.5, ret.Perform(std::make_tuple()));
+ EXPECT_EQ(6.6, ret.Perform(std::make_tuple()));
+}
+
// Tests that DoDefault() does the default action for the mock method.
class MockClass {
diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc
index fbc5d5b2..55be70a8 100644
--- a/googlemock/test/gmock-function-mocker_test.cc
+++ b/googlemock/test/gmock-function-mocker_test.cc
@@ -101,6 +101,10 @@ class FooInterface {
virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
virtual int TypeWithTemplatedCopyCtor(const TemplatedCopyable<int>&) = 0;
+ virtual int (*ReturnsFunctionPointer1(int))(bool) = 0;
+ using fn_ptr = int (*)(bool);
+ virtual fn_ptr ReturnsFunctionPointer2(int) = 0;
+
#if GTEST_OS_WINDOWS
STDMETHOD_(int, CTNullary)() = 0;
STDMETHOD_(bool, CTUnary)(int x) = 0;
@@ -159,6 +163,9 @@ class MockFoo : public FooInterface {
MOCK_METHOD(int, TypeWithTemplatedCopyCtor,
(const TemplatedCopyable<int>&)); // NOLINT
+ MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ());
+ MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ());
+
#if GTEST_OS_WINDOWS
MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE)));
MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE)));
diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc
index 6c4b3000..f3f49a68 100644
--- a/googlemock/test/gmock-generated-matchers_test.cc
+++ b/googlemock/test/gmock-generated-matchers_test.cc
@@ -41,6 +41,8 @@
#include "gmock/gmock-generated-matchers.h"
+#include <array>
+#include <iterator>
#include <list>
#include <map>
#include <memory>
@@ -51,8 +53,8 @@
#include <vector>
#include "gmock/gmock.h"
-#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
namespace {
@@ -195,7 +197,7 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
ElementsAre(GreaterThan(1), 0, GreaterThan(2));
const int a[] = { 10, 0, 100 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n"
"and whose element #2 matches, which is 98 more than 2",
Explain(m, test_vector));
@@ -280,7 +282,7 @@ TEST(ElementsAreTest, MatchesThreeElementsMixedMatchers) {
TEST(ElementsAreTest, MatchesTenElementVector) {
const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector,
// The element list can contain values and/or matchers
@@ -317,13 +319,10 @@ TEST(ElementsAreTest, DoesNotMatchWrongOrder) {
}
TEST(ElementsAreTest, WorksForNestedContainer) {
- const char* strings[] = {
- "Hi",
- "world"
- };
+ constexpr std::array<const char*, 2> strings = {{"Hi", "world"}};
vector<list<char> > nested;
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(strings); i++) {
+ for (size_t i = 0; i < strings.size(); i++) {
nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
}
@@ -335,7 +334,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
int a[] = { 0, 1, 2 };
- vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> v(std::begin(a), std::end(a));
EXPECT_THAT(v, ElementsAre(Ref(v[0]), Ref(v[1]), Ref(v[2])));
EXPECT_THAT(v, Not(ElementsAre(Ref(v[0]), Ref(v[1]), Ref(a[2]))));
@@ -343,7 +342,7 @@ TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) {
int a[] = { 0, 1, 2 };
- vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> v(std::begin(a), std::end(a));
EXPECT_THAT(&v, Pointee(ElementsAre(0, 1, _)));
EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3))));
@@ -440,7 +439,7 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[2] = 0;
@@ -448,20 +447,20 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
}
TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
- const char* a[] = { "one", "two", "three" };
+ std::array<const char*, 3> a = {{"one", "two", "three"}};
- vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- EXPECT_THAT(test_vector, ElementsAreArray(a, GTEST_ARRAY_SIZE_(a)));
+ vector<std::string> test_vector(std::begin(a), std::end(a));
+ EXPECT_THAT(test_vector, ElementsAreArray(a.data(), a.size()));
- const char** p = a;
+ const char** p = a.data();
test_vector[0] = "1";
- EXPECT_THAT(test_vector, Not(ElementsAreArray(p, GTEST_ARRAY_SIZE_(a))));
+ EXPECT_THAT(test_vector, Not(ElementsAreArray(p, a.size())));
}
TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
const char* a[] = { "one", "two", "three" };
- vector<std::string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<std::string> test_vector(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[0] = "1";
@@ -484,8 +483,8 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) {
TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<int> expected(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@@ -530,9 +529,9 @@ TEST(ElementsAreArrayTest,
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
const int a[] = { 1, 2, 3 };
const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<Matcher<int> > expected(
- kMatchers, kMatchers + GTEST_ARRAY_SIZE_(kMatchers));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<Matcher<int>> expected(std::begin(kMatchers),
+ std::end(kMatchers));
EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@@ -540,11 +539,11 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) {
const int a[] = { 1, 2, 3 };
- const vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
+ const vector<int> test_vector(std::begin(a), std::end(a));
+ const vector<int> expected(std::begin(a), std::end(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end()));
// Pointers are iterators, too.
- EXPECT_THAT(test_vector, ElementsAreArray(a, a + GTEST_ARRAY_SIZE_(a)));
+ EXPECT_THAT(test_vector, ElementsAreArray(std::begin(a), std::end(a)));
// The empty range of NULL pointers should also be okay.
int* const null_int = nullptr;
EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int)));
@@ -564,8 +563,8 @@ TEST(ElementsAreArrayTest, WorksWithNativeArray) {
TEST(ElementsAreArrayTest, SourceLifeSpan) {
const int a[] = { 1, 2, 3 };
- vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
- vector<int> expect(a, a + GTEST_ARRAY_SIZE_(a));
+ vector<int> test_vector(std::begin(a), std::end(a));
+ vector<int> expect(std::begin(a), std::end(a));
ElementsAreArrayMatcher<int> matcher_maker =
ElementsAreArray(expect.begin(), expect.end());
EXPECT_THAT(test_vector, matcher_maker);
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index 03735267..bc49cb62 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -41,10 +41,11 @@
#endif
#include "gmock/gmock-matchers.h"
-#include "gmock/gmock-more-matchers.h"
#include <string.h>
#include <time.h>
+
+#include <array>
#include <deque>
#include <forward_list>
#include <functional>
@@ -60,9 +61,11 @@
#include <type_traits>
#include <utility>
#include <vector>
+
+#include "gmock/gmock-more-matchers.h"
#include "gmock/gmock.h"
-#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
+#include "gtest/gtest.h"
namespace testing {
namespace gmock_matchers_test {
@@ -2054,6 +2057,114 @@ TEST(PairMatchBaseTest, WorksWithMoveOnly) {
EXPECT_TRUE(matcher.Matches(pointers));
}
+// Tests that IsNan() matches a NaN, with float.
+TEST(IsNan, FloatMatchesNan) {
+ float quiet_nan = std::numeric_limits<float>::quiet_NaN();
+ float other_nan = std::nanf("1");
+ float real_value = 1.0f;
+
+ Matcher<float> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<float&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const float&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with double.
+TEST(IsNan, DoubleMatchesNan) {
+ double quiet_nan = std::numeric_limits<double>::quiet_NaN();
+ double other_nan = std::nan("1");
+ double real_value = 1.0;
+
+ Matcher<double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with long double.
+TEST(IsNan, LongDoubleMatchesNan) {
+ long double quiet_nan = std::numeric_limits<long double>::quiet_NaN();
+ long double other_nan = std::nan("1");
+ long double real_value = 1.0;
+
+ Matcher<long double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<long double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const long double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() works with Not.
+TEST(IsNan, NotMatchesNan) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN()));
+ EXPECT_FALSE(mf.Matches(std::nanf("1")));
+ EXPECT_TRUE(mf.Matches(1.0));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN()));
+ EXPECT_FALSE(md.Matches(std::nan("1")));
+ EXPECT_TRUE(md.Matches(1.0));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN()));
+ EXPECT_FALSE(mld.Matches(std::nanl("1")));
+ EXPECT_TRUE(mld.Matches(1.0));
+}
+
+// Tests that IsNan() can describe itself.
+TEST(IsNan, CanDescribeSelf) {
+ Matcher<float> mf = IsNan();
+ EXPECT_EQ("is NaN", Describe(mf));
+
+ Matcher<double> md = IsNan();
+ EXPECT_EQ("is NaN", Describe(md));
+
+ Matcher<long double> mld = IsNan();
+ EXPECT_EQ("is NaN", Describe(mld));
+}
+
+// Tests that IsNan() can describe itself with Not.
+TEST(IsNan, CanDescribeSelfWithNot) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mf));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(md));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mld));
+}
+
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST(FloatEq2Test, MatchesEqualArguments) {
@@ -5093,14 +5204,14 @@ TEST(WhenSortedTest, WorksForStreamlike) {
// Streamlike 'container' provides only minimal iterator support.
// Its iterators are tagged with input_iterator_tag.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, WhenSorted(ElementsAre(1, 2, 3, 4, 5)));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
}
TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
const int a[] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
Matcher<const std::vector<int>&> vector_match = ElementsAre(1, 2, 3, 4, 5);
EXPECT_THAT(s, WhenSorted(vector_match));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
@@ -5145,7 +5256,7 @@ TEST(IsSupersetOfTest, WorksForEmpty) {
TEST(IsSupersetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5273,7 +5384,7 @@ TEST(IsSubsetOfTest, WorksForEmpty) {
TEST(IsSubsetOfTest, WorksForStreamlike) {
const int a[5] = {1, 2};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5367,14 +5478,14 @@ TEST(IsSubsetOfTest, WorksWithMoveOnly) {
TEST(ElemensAreStreamTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, ElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(ElementsAre(2, 1, 4, 5, 3)));
}
TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
const int a[5] = {1, 2, 3, 4, 5};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
vector<int> expected;
expected.push_back(1);
@@ -5421,7 +5532,7 @@ TEST(ElementsAreTest, TakesStlContainer) {
TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
const int a[] = {0, 1, 2, 3, 4};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
do {
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(a),
@@ -5432,8 +5543,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
TEST(UnorderedElementsAreArrayTest, VectorBool) {
const bool a[] = {0, 1, 0, 1, 1};
const bool b[] = {1, 0, 1, 1, 0};
- std::vector<bool> expected(a, a + GTEST_ARRAY_SIZE_(a));
- std::vector<bool> actual(b, b + GTEST_ARRAY_SIZE_(b));
+ std::vector<bool> expected(std::begin(a), std::end(a));
+ std::vector<bool> actual(std::begin(b), std::end(b));
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(expected),
actual, &listener)) << listener.str();
@@ -5444,7 +5555,7 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
::std::vector<int> expected;
expected.push_back(1);
@@ -5527,7 +5638,7 @@ TEST_F(UnorderedElementsAreTest, WorksWithUncopyable) {
TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
const int a[] = {1, 2, 3};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
do {
StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3),
@@ -5537,7 +5648,7 @@ TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
TEST_F(UnorderedElementsAreTest, FailsWhenAnElementMatchesNoMatcher) {
const int a[] = {1, 2, 3};
- std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ std::vector<int> s(std::begin(a), std::end(a));
std::vector<Matcher<int> > mv;
mv.push_back(1);
mv.push_back(2);
@@ -5553,7 +5664,7 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods.
const int a[5] = {2, 1, 4, 5, 3};
- Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
+ Streamlike<int> s(std::begin(a), std::end(a));
EXPECT_THAT(s, UnorderedElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(UnorderedElementsAre(2, 2, 3, 4, 5)));
@@ -5869,8 +5980,9 @@ TEST_F(BipartiteNonSquareTest, SimpleBacktracking) {
// :.......:
// 0 1 2
MatchMatrix g(4, 3);
- static const size_t kEdges[][2] = {{0, 2}, {1, 1}, {2, 1}, {3, 0}};
- for (size_t i = 0; i < GTEST_ARRAY_SIZE_(kEdges); ++i) {
+ constexpr std::array<std::array<size_t, 2>, 4> kEdges = {
+ {{{0, 2}}, {{1, 1}}, {{2, 1}}, {{3, 0}}}};
+ for (size_t i = 0; i < kEdges.size(); ++i) {
g.SetEdge(kEdges[i][0], kEdges[i][1], true);
}
EXPECT_THAT(FindBacktrackingMaxBPM(g),
diff --git a/googlemock/test/gmock-pp_test.cc b/googlemock/test/gmock-pp_test.cc
index 7387d398..5d1566e3 100644
--- a/googlemock/test/gmock-pp_test.cc
+++ b/googlemock/test/gmock-pp_test.cc
@@ -1,5 +1,10 @@
#include "gmock/internal/gmock-pp.h"
+// Used to test MSVC treating __VA_ARGS__ with a comma in it as one value
+#define GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_comma ,
+#define GMOCK_TEST_REPLACE_comma_WITH_COMMA(x) \
+ GMOCK_PP_CAT(GMOCK_TEST_REPLACE_comma_WITH_COMMA_I_, x)
+
// Static assertions.
namespace testing {
namespace internal {
@@ -17,6 +22,11 @@ static_assert(GMOCK_PP_NARG(x, y, z, w) == 4, "");
static_assert(!GMOCK_PP_HAS_COMMA(), "");
static_assert(GMOCK_PP_HAS_COMMA(b, ), "");
static_assert(!GMOCK_PP_HAS_COMMA((, )), "");
+static_assert(GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma)),
+ "");
+static_assert(
+ GMOCK_PP_HAS_COMMA(GMOCK_TEST_REPLACE_comma_WITH_COMMA(comma(unrelated))),
+ "");
static_assert(!GMOCK_PP_IS_EMPTY(, ), "");
static_assert(!GMOCK_PP_IS_EMPTY(a), "");
static_assert(!GMOCK_PP_IS_EMPTY(()), "");
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index 7bf5a8ad..791a2476 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -69,8 +69,8 @@ using testing::AtMost;
using testing::Between;
using testing::Cardinality;
using testing::CardinalityInterface;
-using testing::ContainsRegex;
using testing::Const;
+using testing::ContainsRegex;
using testing::DoAll;
using testing::DoDefault;
using testing::Eq;