Merge branch 'master' into fix_death_test_child_mingw_wer_issue1116
This commit is contained in:
commit
10f05a627c
|
@ -37,13 +37,15 @@ matrix:
|
|||
group: deprecated-2017Q4
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11 NO_EXCEPTION=ON NO_RTTI=ON COMPILER_IS_GNUCXX=ON
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Debug VERBOSE=1
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11
|
||||
if: type != pull_request
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: BUILD_TYPE=Debug VERBOSE=1
|
||||
|
|
|
@ -24,11 +24,19 @@ export MAKEFLAGS
|
|||
|
||||
env | sort
|
||||
|
||||
# Set default values to OFF for these variables if not specified.
|
||||
: "${NO_EXCEPTION:=OFF}"
|
||||
: "${NO_RTTI:=OFF}"
|
||||
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||
|
||||
mkdir build || true
|
||||
cd build
|
||||
cmake -Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
-Dcxx_no_exception=$NO_EXCEPTION \
|
||||
-Dcxx_no_rtti=$NO_RTTI \
|
||||
-DCMAKE_COMPILER_IS_GNUCXX=$COMPILER_IS_GNUCXX \
|
||||
-DCMAKE_CXX_FLAGS=$CXX_FLAGS \
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||
..
|
||||
|
|
|
@ -2229,13 +2229,20 @@ versus
|
|||
|
||||
## Mocking Methods That Use Move-Only Types ##
|
||||
|
||||
C++11 introduced <em>move-only types</em>. A move-only-typed value can be moved from one object to another, but cannot be copied. `std::unique_ptr<T>` is probably the most commonly used move-only type.
|
||||
C++11 introduced *move-only types*. A move-only-typed value can be moved from
|
||||
one object to another, but cannot be copied. `std::unique_ptr<T>` is
|
||||
probably the most commonly used move-only type.
|
||||
|
||||
Mocking a method that takes and/or returns move-only types presents some challenges, but nothing insurmountable. This recipe shows you how you can do it.
|
||||
Mocking a method that takes and/or returns move-only types presents some
|
||||
challenges, but nothing insurmountable. This recipe shows you how you can do it.
|
||||
Note that the support for move-only method arguments was only introduced to
|
||||
gMock in April 2017; in older code, you may find more complex
|
||||
[workarounds](#LegacyMoveOnly) for lack of this feature.
|
||||
|
||||
Let’s say we are working on a fictional project that lets one post and share snippets called “buzzes”. Your code uses these types:
|
||||
Let’s say we are working on a fictional project that lets one post and share
|
||||
snippets called “buzzes”. Your code uses these types:
|
||||
|
||||
```
|
||||
```cpp
|
||||
enum class AccessLevel { kInternal, kPublic };
|
||||
|
||||
class Buzz {
|
||||
|
@ -2247,59 +2254,46 @@ class Buzz {
|
|||
class Buzzer {
|
||||
public:
|
||||
virtual ~Buzzer() {}
|
||||
virtual std::unique_ptr<Buzz> MakeBuzz(const std::string& text) = 0;
|
||||
virtual bool ShareBuzz(std::unique_ptr<Buzz> buzz, Time timestamp) = 0;
|
||||
virtual std::unique_ptr<Buzz> MakeBuzz(StringPiece text) = 0;
|
||||
virtual bool ShareBuzz(std::unique_ptr<Buzz> buzz, int64_t timestamp) = 0;
|
||||
...
|
||||
};
|
||||
```
|
||||
|
||||
A `Buzz` object represents a snippet being posted. A class that implements the `Buzzer` interface is capable of creating and sharing `Buzz`. Methods in `Buzzer` may return a `unique_ptr<Buzz>` or take a `unique_ptr<Buzz>`. Now we need to mock `Buzzer` in our tests.
|
||||
A `Buzz` object represents a snippet being posted. A class that implements the
|
||||
`Buzzer` interface is capable of creating and sharing `Buzz`es. Methods in
|
||||
`Buzzer` may return a `unique_ptr<Buzz>` or take a
|
||||
`unique_ptr<Buzz>`. Now we need to mock `Buzzer` in our tests.
|
||||
|
||||
To mock a method that returns a move-only type, you just use the familiar `MOCK_METHOD` syntax as usual:
|
||||
To mock a method that accepts or returns move-only types, you just use the
|
||||
familiar `MOCK_METHOD` syntax as usual:
|
||||
|
||||
```
|
||||
```cpp
|
||||
class MockBuzzer : public Buzzer {
|
||||
public:
|
||||
MOCK_METHOD1(MakeBuzz, std::unique_ptr<Buzz>(const std::string& text));
|
||||
…
|
||||
MOCK_METHOD1(MakeBuzz, std::unique_ptr<Buzz>(StringPiece text));
|
||||
MOCK_METHOD2(ShareBuzz, bool(std::unique_ptr<Buzz> buzz, int64_t timestamp));
|
||||
};
|
||||
```
|
||||
|
||||
However, if you attempt to use the same `MOCK_METHOD` pattern to mock a method that takes a move-only parameter, you’ll get a compiler error currently:
|
||||
Now that we have the mock class defined, we can use it in tests. In the
|
||||
following code examples, we assume that we have defined a `MockBuzzer` object
|
||||
named `mock_buzzer_`:
|
||||
|
||||
```
|
||||
// Does NOT compile!
|
||||
MOCK_METHOD2(ShareBuzz, bool(std::unique_ptr<Buzz> buzz, Time timestamp));
|
||||
```
|
||||
|
||||
While it’s highly desirable to make this syntax just work, it’s not trivial and the work hasn’t been done yet. Fortunately, there is a trick you can apply today to get something that works nearly as well as this.
|
||||
|
||||
The trick, is to delegate the `ShareBuzz()` method to a mock method (let’s call it `DoShareBuzz()`) that does not take move-only parameters:
|
||||
|
||||
```
|
||||
class MockBuzzer : public Buzzer {
|
||||
public:
|
||||
MOCK_METHOD1(MakeBuzz, std::unique_ptr<Buzz>(const std::string& text));
|
||||
MOCK_METHOD2(DoShareBuzz, bool(Buzz* buzz, Time timestamp));
|
||||
bool ShareBuzz(std::unique_ptr<Buzz> buzz, Time timestamp) {
|
||||
return DoShareBuzz(buzz.get(), timestamp);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Note that there's no need to define or declare `DoShareBuzz()` in a base class. You only need to define it as a `MOCK_METHOD` in the mock class.
|
||||
|
||||
Now that we have the mock class defined, we can use it in tests. In the following code examples, we assume that we have defined a `MockBuzzer` object named `mock_buzzer_`:
|
||||
|
||||
```
|
||||
```cpp
|
||||
MockBuzzer mock_buzzer_;
|
||||
```
|
||||
|
||||
First let’s see how we can set expectations on the `MakeBuzz()` method, which returns a `unique_ptr<Buzz>`.
|
||||
First let’s see how we can set expectations on the `MakeBuzz()` method, which
|
||||
returns a `unique_ptr<Buzz>`.
|
||||
|
||||
As usual, if you set an expectation without an action (i.e. the `.WillOnce()` or `.WillRepeated()` clause), when that expectation fires, the default action for that method will be taken. Since `unique_ptr<>` has a default constructor that returns a null `unique_ptr`, that’s what you’ll get if you don’t specify an action:
|
||||
As usual, if you set an expectation without an action (i.e. the `.WillOnce()` or
|
||||
`.WillRepeated()` clause), when that expectation fires, the default action for
|
||||
that method will be taken. Since `unique_ptr<>` has a default constructor
|
||||
that returns a null `unique_ptr`, that’s what you’ll get if you don’t specify an
|
||||
action:
|
||||
|
||||
```
|
||||
```cpp
|
||||
// Use the default action.
|
||||
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello"));
|
||||
|
||||
|
@ -2307,32 +2301,13 @@ As usual, if you set an expectation without an action (i.e. the `.WillOnce()` or
|
|||
EXPECT_EQ(nullptr, mock_buzzer_.MakeBuzz("hello"));
|
||||
```
|
||||
|
||||
If you are not happy with the default action, you can tweak it. Depending on what you need, you may either tweak the default action for a specific (mock object, mock method) combination using `ON_CALL()`, or you may tweak the default action for all mock methods that return a specific type. The usage of `ON_CALL()` is similar to `EXPECT_CALL()`, so we’ll skip it and just explain how to do the latter (tweaking the default action for a specific return type). You do this via the `DefaultValue<>::SetFactory()` and `DefaultValue<>::Clear()` API:
|
||||
If you are not happy with the default action, you can tweak it as usual; see
|
||||
[Setting Default Actions](#OnCall).
|
||||
|
||||
```
|
||||
// Sets the default action for return type std::unique_ptr<Buzz> to
|
||||
// creating a new Buzz every time.
|
||||
DefaultValue<std::unique_ptr<Buzz>>::SetFactory(
|
||||
[] { return MakeUnique<Buzz>(AccessLevel::kInternal); });
|
||||
If you just need to return a pre-defined move-only value, you can use the
|
||||
`Return(ByMove(...))` action:
|
||||
|
||||
// When this fires, the default action of MakeBuzz() will run, which
|
||||
// will return a new Buzz object.
|
||||
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")).Times(AnyNumber());
|
||||
|
||||
auto buzz1 = mock_buzzer_.MakeBuzz("hello");
|
||||
auto buzz2 = mock_buzzer_.MakeBuzz("hello");
|
||||
EXPECT_NE(nullptr, buzz1);
|
||||
EXPECT_NE(nullptr, buzz2);
|
||||
EXPECT_NE(buzz1, buzz2);
|
||||
|
||||
// Resets the default action for return type std::unique_ptr<Buzz>,
|
||||
// to avoid interfere with other tests.
|
||||
DefaultValue<std::unique_ptr<Buzz>>::Clear();
|
||||
```
|
||||
|
||||
What if you want the method to do something other than the default action? If you just need to return a pre-defined move-only value, you can use the `Return(ByMove(...))` action:
|
||||
|
||||
```
|
||||
```cpp
|
||||
// When this fires, the unique_ptr<> specified by ByMove(...) will
|
||||
// be returned.
|
||||
EXPECT_CALL(mock_buzzer_, MakeBuzz("world"))
|
||||
|
@ -2343,81 +2318,87 @@ What if you want the method to do something other than the default action? If y
|
|||
|
||||
Note that `ByMove()` is essential here - if you drop it, the code won’t compile.
|
||||
|
||||
Quiz time! What do you think will happen if a `Return(ByMove(...))` action is performed more than once (e.g. you write `….WillRepeatedly(Return(ByMove(...)));`)? Come think of it, after the first time the action runs, the source value will be consumed (since it’s a move-only value), so the next time around, there’s no value to move from -- you’ll get a run-time error that `Return(ByMove(...))` can only be run once.
|
||||
Quiz time! What do you think will happen if a `Return(ByMove(...))` action is
|
||||
performed more than once (e.g. you write
|
||||
`….WillRepeatedly(Return(ByMove(...)));`)? Come think of it, after the first
|
||||
time the action runs, the source value will be consumed (since it’s a move-only
|
||||
value), so the next time around, there’s no value to move from -- you’ll get a
|
||||
run-time error that `Return(ByMove(...))` can only be run once.
|
||||
|
||||
If you need your mock method to do more than just moving a pre-defined value, remember that you can always use `Invoke()` to call a lambda or a callable object, which can do pretty much anything you want:
|
||||
If you need your mock method to do more than just moving a pre-defined value,
|
||||
remember that you can always use a lambda or a callable object, which can do
|
||||
pretty much anything you want:
|
||||
|
||||
```
|
||||
```cpp
|
||||
EXPECT_CALL(mock_buzzer_, MakeBuzz("x"))
|
||||
.WillRepeatedly(Invoke([](const std::string& text) {
|
||||
return std::make_unique<Buzz>(AccessLevel::kInternal);
|
||||
}));
|
||||
.WillRepeatedly([](StringPiece text) {
|
||||
return MakeUnique<Buzz>(AccessLevel::kInternal);
|
||||
});
|
||||
|
||||
EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x"));
|
||||
EXPECT_NE(nullptr, mock_buzzer_.MakeBuzz("x"));
|
||||
```
|
||||
|
||||
Every time this `EXPECT_CALL` fires, a new `unique_ptr<Buzz>` will be created and returned. You cannot do this with `Return(ByMove(...))`.
|
||||
Every time this `EXPECT_CALL` fires, a new `unique_ptr<Buzz>` will be
|
||||
created and returned. You cannot do this with `Return(ByMove(...))`.
|
||||
|
||||
Now there’s one topic we haven’t covered: how do you set expectations on `ShareBuzz()`, which takes a move-only-typed parameter? The answer is you don’t. Instead, you set expectations on the `DoShareBuzz()` mock method (remember that we defined a `MOCK_METHOD` for `DoShareBuzz()`, not `ShareBuzz()`):
|
||||
That covers returning move-only values; but how do we work with methods
|
||||
accepting move-only arguments? The answer is that they work normally, although
|
||||
some actions will not compile when any of method's arguments are move-only. You
|
||||
can always use `Return`, or a [lambda or functor](#FunctionsAsActions):
|
||||
|
||||
```cpp
|
||||
using ::testing::Unused;
|
||||
|
||||
EXPECT_CALL(mock_buzzer_, ShareBuzz(NotNull(), _)) .WillOnce(Return(true));
|
||||
EXPECT_TRUE(mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal)),
|
||||
0);
|
||||
|
||||
EXPECT_CALL(mock_buzzer_, ShareBuzz(_, _)) .WillOnce(
|
||||
[](std::unique_ptr<Buzz> buzz, Unused) { return buzz != nullptr; });
|
||||
EXPECT_FALSE(mock_buzzer_.ShareBuzz(nullptr, 0));
|
||||
```
|
||||
|
||||
Many built-in actions (`WithArgs`, `WithoutArgs`,`DeleteArg`, `SaveArg`, ...)
|
||||
could in principle support move-only arguments, but the support for this is not
|
||||
implemented yet. If this is blocking you, please file a bug.
|
||||
|
||||
A few actions (e.g. `DoAll`) copy their arguments internally, so they can never
|
||||
work with non-copyable objects; you'll have to use functors instead.
|
||||
|
||||
##### Legacy workarounds for move-only types {#LegacyMoveOnly}
|
||||
|
||||
Support for move-only function arguments was only introduced to gMock in April
|
||||
2017. In older code, you may encounter the following workaround for the lack of
|
||||
this feature (it is no longer necessary - we're including it just for
|
||||
reference):
|
||||
|
||||
```cpp
|
||||
class MockBuzzer : public Buzzer {
|
||||
public:
|
||||
MOCK_METHOD2(DoShareBuzz, bool(Buzz* buzz, Time timestamp));
|
||||
bool ShareBuzz(std::unique_ptr<Buzz> buzz, Time timestamp) override {
|
||||
return DoShareBuzz(buzz.get(), timestamp);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
The trick is to delegate the `ShareBuzz()` method to a mock method (let’s call
|
||||
it `DoShareBuzz()`) that does not take move-only parameters. Then, instead of
|
||||
setting expectations on `ShareBuzz()`, you set them on the `DoShareBuzz()` mock
|
||||
method:
|
||||
|
||||
```cpp
|
||||
MockBuzzer mock_buzzer_;
|
||||
EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _));
|
||||
|
||||
// When one calls ShareBuzz() on the MockBuzzer like this, the call is
|
||||
// forwarded to DoShareBuzz(), which is mocked. Therefore this statement
|
||||
// will trigger the above EXPECT_CALL.
|
||||
mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal),
|
||||
::base::Now());
|
||||
mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal), 0);
|
||||
```
|
||||
|
||||
Some of you may have spotted one problem with this approach: the `DoShareBuzz()` mock method differs from the real `ShareBuzz()` method in that it cannot take ownership of the buzz parameter - `ShareBuzz()` will always delete buzz after `DoShareBuzz()` returns. What if you need to save the buzz object somewhere for later use when `ShareBuzz()` is called? Indeed, you'd be stuck.
|
||||
|
||||
Another problem with the `DoShareBuzz()` we had is that it can surprise people reading or maintaining the test, as one would expect that `DoShareBuzz()` has (logically) the same contract as `ShareBuzz()`.
|
||||
|
||||
Fortunately, these problems can be fixed with a bit more code. Let's try to get it right this time:
|
||||
|
||||
```
|
||||
class MockBuzzer : public Buzzer {
|
||||
public:
|
||||
MockBuzzer() {
|
||||
// Since DoShareBuzz(buzz, time) is supposed to take ownership of
|
||||
// buzz, define a default behavior for DoShareBuzz(buzz, time) to
|
||||
// delete buzz.
|
||||
ON_CALL(*this, DoShareBuzz(_, _))
|
||||
.WillByDefault(Invoke([](Buzz* buzz, Time timestamp) {
|
||||
delete buzz;
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
MOCK_METHOD1(MakeBuzz, std::unique_ptr<Buzz>(const std::string& text));
|
||||
|
||||
// Takes ownership of buzz.
|
||||
MOCK_METHOD2(DoShareBuzz, bool(Buzz* buzz, Time timestamp));
|
||||
bool ShareBuzz(std::unique_ptr<Buzz> buzz, Time timestamp) {
|
||||
return DoShareBuzz(buzz.release(), timestamp);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Now, the mock `DoShareBuzz()` method is free to save the buzz argument for later use if this is what you want:
|
||||
|
||||
```
|
||||
std::unique_ptr<Buzz> intercepted_buzz;
|
||||
EXPECT_CALL(mock_buzzer_, DoShareBuzz(NotNull(), _))
|
||||
.WillOnce(Invoke([&intercepted_buzz](Buzz* buzz, Time timestamp) {
|
||||
// Save buzz in intercepted_buzz for analysis later.
|
||||
intercepted_buzz.reset(buzz);
|
||||
return false;
|
||||
}));
|
||||
|
||||
mock_buzzer_.ShareBuzz(std::make_unique<Buzz>(AccessLevel::kInternal),
|
||||
Now());
|
||||
EXPECT_NE(nullptr, intercepted_buzz);
|
||||
```
|
||||
|
||||
Using the tricks covered in this recipe, you are now able to mock methods that take and/or return move-only types. Put your newly-acquired power to good use - when you design a new API, you can now feel comfortable using `unique_ptrs` as appropriate, without fearing that doing so will compromise your tests.
|
||||
|
||||
## Making the Compilation Faster ##
|
||||
|
||||
|
|
|
@ -360,15 +360,21 @@ class Action {
|
|||
|
||||
// Constructs a null Action. Needed for storing Action objects in
|
||||
// STL containers.
|
||||
Action() : impl_(NULL) {}
|
||||
Action() {}
|
||||
|
||||
// Constructs an Action from its implementation. A NULL impl is
|
||||
// used to represent the "do-default" action.
|
||||
#if GTEST_LANG_CXX11
|
||||
// Construct an Action from a specified callable.
|
||||
// This cannot take std::function directly, because then Action would not be
|
||||
// directly constructible from lambda (it would require two conversions).
|
||||
template <typename G,
|
||||
typename = typename ::std::enable_if<
|
||||
::std::is_constructible<::std::function<F>, G>::value>::type>
|
||||
Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
|
||||
#endif
|
||||
|
||||
// Constructs an Action from its implementation.
|
||||
explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
|
||||
|
||||
// Copy constructor.
|
||||
Action(const Action& action) : impl_(action.impl_) {}
|
||||
|
||||
// This constructor allows us to turn an Action<Func> object into an
|
||||
// Action<F>, as long as F's arguments can be implicitly converted
|
||||
// to Func's and Func's return type can be implicitly converted to
|
||||
|
@ -377,7 +383,13 @@ class Action {
|
|||
explicit Action(const Action<Func>& action);
|
||||
|
||||
// Returns true iff this is the DoDefault() action.
|
||||
bool IsDoDefault() const { return impl_.get() == NULL; }
|
||||
bool IsDoDefault() const {
|
||||
#if GTEST_LANG_CXX11
|
||||
return impl_ == nullptr && fun_ == nullptr;
|
||||
#else
|
||||
return impl_ == NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Performs the action. Note that this method is const even though
|
||||
// the corresponding method in ActionInterface is not. The reason
|
||||
|
@ -385,14 +397,15 @@ class Action {
|
|||
// another concrete action, not that the concrete action it binds to
|
||||
// cannot change state. (Think of the difference between a const
|
||||
// pointer and a pointer to const.)
|
||||
Result Perform(const ArgumentTuple& args) const {
|
||||
internal::Assert(
|
||||
!IsDoDefault(), __FILE__, __LINE__,
|
||||
"You are using DoDefault() inside a composite action like "
|
||||
"DoAll() or WithArgs(). This is not supported for technical "
|
||||
"reasons. Please instead spell out the default action, or "
|
||||
"assign the default action to an Action variable and use "
|
||||
"the variable in various places.");
|
||||
Result Perform(ArgumentTuple args) const {
|
||||
if (IsDoDefault()) {
|
||||
internal::IllegalDoDefault(__FILE__, __LINE__);
|
||||
}
|
||||
#if GTEST_LANG_CXX11
|
||||
if (fun_ != nullptr) {
|
||||
return internal::Apply(fun_, ::std::move(args));
|
||||
}
|
||||
#endif
|
||||
return impl_->Perform(args);
|
||||
}
|
||||
|
||||
|
@ -400,6 +413,18 @@ class Action {
|
|||
template <typename F1, typename F2>
|
||||
friend class internal::ActionAdaptor;
|
||||
|
||||
template <typename G>
|
||||
friend class Action;
|
||||
|
||||
// In C++11, Action can be implemented either as a generic functor (through
|
||||
// std::function), or legacy ActionInterface. In C++98, only ActionInterface
|
||||
// is available. The invariants are as follows:
|
||||
// * in C++98, impl_ is null iff this is the default action
|
||||
// * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff
|
||||
// this is the default action
|
||||
#if GTEST_LANG_CXX11
|
||||
::std::function<F> fun_;
|
||||
#endif
|
||||
internal::linked_ptr<ActionInterface<F> > impl_;
|
||||
};
|
||||
|
||||
|
@ -531,6 +556,9 @@ struct ByMoveWrapper {
|
|||
// statement, and conversion of the result of Return to Action<T(U)> is a
|
||||
// good place for that.
|
||||
//
|
||||
// The real life example of the above scenario happens when an invocation
|
||||
// of gtl::Container() is passed into Return.
|
||||
//
|
||||
template <typename R>
|
||||
class ReturnAction {
|
||||
public:
|
||||
|
@ -750,7 +778,7 @@ class DoDefaultAction {
|
|||
// This template type conversion operator allows DoDefault() to be
|
||||
// used in any function.
|
||||
template <typename F>
|
||||
operator Action<F>() const { return Action<F>(NULL); }
|
||||
operator Action<F>() const { return Action<F>(); } // NOLINT
|
||||
};
|
||||
|
||||
// Implements the Assign action to set a given pointer referent to a
|
||||
|
@ -886,6 +914,28 @@ class InvokeMethodWithoutArgsAction {
|
|||
GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
|
||||
};
|
||||
|
||||
// Implements the InvokeWithoutArgs(callback) action.
|
||||
template <typename CallbackType>
|
||||
class InvokeCallbackWithoutArgsAction {
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackWithoutArgsAction(CallbackType* callback)
|
||||
: callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
// This type conversion operator template allows Invoke(callback) to
|
||||
// be used wherever the callback's return type can be implicitly
|
||||
// converted to that of the mock function.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
|
||||
|
||||
private:
|
||||
const internal::linked_ptr<CallbackType> callback_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
|
||||
};
|
||||
|
||||
// Implements the IgnoreResult(action) action.
|
||||
template <typename A>
|
||||
class IgnoreResultAction {
|
||||
|
@ -1053,7 +1103,13 @@ typedef internal::IgnoredValue Unused;
|
|||
template <typename To>
|
||||
template <typename From>
|
||||
Action<To>::Action(const Action<From>& from)
|
||||
: impl_(new internal::ActionAdaptor<To, From>(from)) {}
|
||||
:
|
||||
#if GTEST_LANG_CXX11
|
||||
fun_(from.fun_),
|
||||
#endif
|
||||
impl_(from.impl_ == NULL ? NULL
|
||||
: new internal::ActionAdaptor<To, From>(from)) {
|
||||
}
|
||||
|
||||
// Creates an action that returns 'value'. 'value' is passed by value
|
||||
// instead of const reference - otherwise Return("string literal")
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
|
||||
// This file was GENERATED by command:
|
||||
// pump.py gmock-generated-actions.h.pump
|
||||
// DO NOT EDIT BY HAND!!!
|
||||
|
||||
// Copyright 2007, Google Inc.
|
||||
// All rights reserved.
|
||||
|
@ -45,8 +47,8 @@ namespace testing {
|
|||
namespace internal {
|
||||
|
||||
// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
|
||||
// function or method with the unpacked values, where F is a function
|
||||
// type that takes N arguments.
|
||||
// function, method, or callback with the unpacked values, where F is
|
||||
// a function type that takes N arguments.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
class InvokeHelper;
|
||||
|
||||
|
@ -64,6 +66,12 @@ class InvokeHelper<R, ::testing::tuple<> > {
|
|||
const ::testing::tuple<>&) {
|
||||
return (obj_ptr->*method_ptr)();
|
||||
}
|
||||
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<>&) {
|
||||
return callback->Run();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R, typename A1>
|
||||
|
@ -80,6 +88,12 @@ class InvokeHelper<R, ::testing::tuple<A1> > {
|
|||
const ::testing::tuple<A1>& args) {
|
||||
return (obj_ptr->*method_ptr)(get<0>(args));
|
||||
}
|
||||
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<A1>& args) {
|
||||
return callback->Run(get<0>(args));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2>
|
||||
|
@ -96,6 +110,12 @@ class InvokeHelper<R, ::testing::tuple<A1, A2> > {
|
|||
const ::testing::tuple<A1, A2>& args) {
|
||||
return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args));
|
||||
}
|
||||
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<A1, A2>& args) {
|
||||
return callback->Run(get<0>(args), get<1>(args));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3>
|
||||
|
@ -113,6 +133,12 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3> > {
|
|||
return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
|
||||
get<2>(args));
|
||||
}
|
||||
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<A1, A2, A3>& args) {
|
||||
return callback->Run(get<0>(args), get<1>(args), get<2>(args));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4>
|
||||
|
@ -132,6 +158,13 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4> > {
|
|||
return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
|
||||
get<2>(args), get<3>(args));
|
||||
}
|
||||
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<A1, A2, A3, A4>& args) {
|
||||
return callback->Run(get<0>(args), get<1>(args), get<2>(args),
|
||||
get<3>(args));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
|
@ -152,6 +185,13 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5> > {
|
|||
return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
|
||||
get<2>(args), get<3>(args), get<4>(args));
|
||||
}
|
||||
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<A1, A2, A3, A4, A5>& args) {
|
||||
return callback->Run(get<0>(args), get<1>(args), get<2>(args),
|
||||
get<3>(args), get<4>(args));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
|
@ -172,6 +212,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6> > {
|
|||
return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args),
|
||||
get<2>(args), get<3>(args), get<4>(args), get<5>(args));
|
||||
}
|
||||
|
||||
// There is no InvokeCallback() for 6-tuples, as google3 callbacks
|
||||
// support 5 arguments at most.
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
|
@ -194,6 +237,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7> > {
|
|||
get<2>(args), get<3>(args), get<4>(args), get<5>(args),
|
||||
get<6>(args));
|
||||
}
|
||||
|
||||
// There is no InvokeCallback() for 7-tuples, as google3 callbacks
|
||||
// support 5 arguments at most.
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
|
@ -217,6 +263,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8> > {
|
|||
get<2>(args), get<3>(args), get<4>(args), get<5>(args),
|
||||
get<6>(args), get<7>(args));
|
||||
}
|
||||
|
||||
// There is no InvokeCallback() for 8-tuples, as google3 callbacks
|
||||
// support 5 arguments at most.
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
|
@ -240,6 +289,9 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9> > {
|
|||
get<2>(args), get<3>(args), get<4>(args), get<5>(args),
|
||||
get<6>(args), get<7>(args), get<8>(args));
|
||||
}
|
||||
|
||||
// There is no InvokeCallback() for 9-tuples, as google3 callbacks
|
||||
// support 5 arguments at most.
|
||||
};
|
||||
|
||||
template <typename R, typename A1, typename A2, typename A3, typename A4,
|
||||
|
@ -265,6 +317,34 @@ class InvokeHelper<R, ::testing::tuple<A1, A2, A3, A4, A5, A6, A7, A8, A9,
|
|||
get<2>(args), get<3>(args), get<4>(args), get<5>(args),
|
||||
get<6>(args), get<7>(args), get<8>(args), get<9>(args));
|
||||
}
|
||||
|
||||
// There is no InvokeCallback() for 10-tuples, as google3 callbacks
|
||||
// support 5 arguments at most.
|
||||
};
|
||||
|
||||
// Implements the Invoke(callback) action.
|
||||
template <typename CallbackType>
|
||||
class InvokeCallbackAction {
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackAction(CallbackType* callback)
|
||||
: callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
// This type conversion operator template allows Invoke(callback) to
|
||||
// be used wherever the callback's type is compatible with that of
|
||||
// the mock function, i.e. if the mock function's arguments can be
|
||||
// implicitly converted to the callback's arguments and the
|
||||
// callback's result can be implicitly converted to the mock
|
||||
// function's result.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
Result Perform(const ArgumentTuple& args) const {
|
||||
return InvokeHelper<Result, ArgumentTuple>::InvokeCallback(
|
||||
callback_.get(), args);
|
||||
}
|
||||
private:
|
||||
const linked_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// An INTERNAL macro for extracting the type of a tuple field. It's
|
||||
|
@ -1073,52 +1153,90 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
|
||||
()
|
||||
#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
|
||||
(p0##_type gmock_p0) : p0(gmock_p0)
|
||||
(p0##_type gmock_p0) : p0(::testing::internal::move(gmock_p0))
|
||||
#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1)
|
||||
(p0##_type gmock_p0, \
|
||||
p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1))
|
||||
#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2)
|
||||
p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2))
|
||||
#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3)
|
||||
p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3))
|
||||
#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4)
|
||||
p3##_type gmock_p3, \
|
||||
p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4))
|
||||
#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5)
|
||||
p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5))
|
||||
#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6)
|
||||
p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6))
|
||||
#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7)
|
||||
p6##_type gmock_p6, \
|
||||
p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7))
|
||||
#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
|
||||
p8(gmock_p8)
|
||||
p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8))
|
||||
#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
|
||||
p7, p8, p9)\
|
||||
(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
|
||||
p8(gmock_p8), p9(gmock_p9)
|
||||
p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)), \
|
||||
p9(::testing::internal::move(gmock_p9))
|
||||
|
||||
// Declares the fields for storing the value parameters.
|
||||
#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
|
||||
|
@ -1354,7 +1472,8 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
template <typename p0##_type>\
|
||||
class name##ActionP {\
|
||||
public:\
|
||||
explicit name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\
|
||||
explicit name##ActionP(p0##_type gmock_p0) : \
|
||||
p0(::testing::internal::forward<p0##_type>(gmock_p0)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1362,7 +1481,8 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
typedef typename ::testing::internal::Function<F>::Result return_type;\
|
||||
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
|
||||
args_type;\
|
||||
explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\
|
||||
explicit gmock_Impl(p0##_type gmock_p0) : \
|
||||
p0(::testing::internal::forward<p0##_type>(gmock_p0)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1404,8 +1524,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
template <typename p0##_type, typename p1##_type>\
|
||||
class name##ActionP2 {\
|
||||
public:\
|
||||
name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
|
||||
p1(gmock_p1) {}\
|
||||
name##ActionP2(p0##_type gmock_p0, \
|
||||
p1##_type gmock_p1) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1413,8 +1534,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
typedef typename ::testing::internal::Function<F>::Result return_type;\
|
||||
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
|
||||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
|
||||
p1(gmock_p1) {}\
|
||||
gmock_Impl(p0##_type gmock_p0, \
|
||||
p1##_type gmock_p1) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1460,7 +1582,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
class name##ActionP3 {\
|
||||
public:\
|
||||
name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
|
||||
p2##_type gmock_p2) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1469,7 +1593,9 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
|
||||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
|
||||
p2##_type gmock_p2) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1519,8 +1645,11 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
class name##ActionP4 {\
|
||||
public:\
|
||||
name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3) {}\
|
||||
p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1529,8 +1658,10 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
|
||||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3) {}\
|
||||
p3##_type gmock_p3) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1587,8 +1718,11 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
public:\
|
||||
name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, \
|
||||
p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4) {}\
|
||||
p4##_type gmock_p4) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1597,8 +1731,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
|
||||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \
|
||||
p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\
|
||||
p3##_type gmock_p3, \
|
||||
p4##_type gmock_p4) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1657,8 +1795,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
public:\
|
||||
name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
|
||||
p5##_type gmock_p5) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1668,8 +1810,12 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\
|
||||
p5##_type gmock_p5) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1731,9 +1877,14 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
public:\
|
||||
name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
|
||||
p6(gmock_p6) {}\
|
||||
p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1743,8 +1894,13 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
|
||||
p6##_type gmock_p6) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1813,9 +1969,14 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, \
|
||||
p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7) {}\
|
||||
p7##_type gmock_p7) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)), \
|
||||
p7(::testing::internal::forward<p7##_type>(gmock_p7)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1825,9 +1986,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
args_type;\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7) : p0(gmock_p0), \
|
||||
p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), \
|
||||
p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
|
||||
p6##_type gmock_p6, \
|
||||
p7##_type gmock_p7) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)), \
|
||||
p7(::testing::internal::forward<p7##_type>(gmock_p7)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1900,9 +2067,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
|
||||
p8(gmock_p8) {}\
|
||||
p8##_type gmock_p8) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)), \
|
||||
p7(::testing::internal::forward<p7##_type>(gmock_p7)), \
|
||||
p8(::testing::internal::forward<p8##_type>(gmock_p8)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -1913,9 +2086,15 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7), p8(gmock_p8) {}\
|
||||
p8##_type gmock_p8) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)), \
|
||||
p7(::testing::internal::forward<p7##_type>(gmock_p7)), \
|
||||
p8(::testing::internal::forward<p8##_type>(gmock_p8)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -1992,9 +2171,17 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
|
||||
p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)), \
|
||||
p7(::testing::internal::forward<p7##_type>(gmock_p7)), \
|
||||
p8(::testing::internal::forward<p8##_type>(gmock_p8)), \
|
||||
p9(::testing::internal::forward<p9##_type>(gmock_p9)) {}\
|
||||
template <typename F>\
|
||||
class gmock_Impl : public ::testing::ActionInterface<F> {\
|
||||
public:\
|
||||
|
@ -2005,9 +2192,16 @@ DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6,
|
|||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\
|
||||
p9##_type gmock_p9) : p0(::testing::internal::forward<p0##_type>(gmock_p0)), \
|
||||
p1(::testing::internal::forward<p1##_type>(gmock_p1)), \
|
||||
p2(::testing::internal::forward<p2##_type>(gmock_p2)), \
|
||||
p3(::testing::internal::forward<p3##_type>(gmock_p3)), \
|
||||
p4(::testing::internal::forward<p4##_type>(gmock_p4)), \
|
||||
p5(::testing::internal::forward<p5##_type>(gmock_p5)), \
|
||||
p6(::testing::internal::forward<p6##_type>(gmock_p6)), \
|
||||
p7(::testing::internal::forward<p7##_type>(gmock_p7)), \
|
||||
p8(::testing::internal::forward<p8##_type>(gmock_p8)), \
|
||||
p9(::testing::internal::forward<p9##_type>(gmock_p9)) {}\
|
||||
virtual return_type Perform(const args_type& args) {\
|
||||
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
|
||||
Perform(this, args);\
|
||||
|
@ -2369,7 +2563,7 @@ ACTION_TEMPLATE(ReturnNew,
|
|||
|
||||
} // namespace testing
|
||||
|
||||
// Include any custom actions added by the local installation.
|
||||
// Include any custom callback actions added by the local installation.
|
||||
// We must include this header at the end to make sure it can use the
|
||||
// declarations from this file.
|
||||
#include "gmock/internal/custom/gmock-generated-actions.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert it to
|
||||
$$ This is a Pump source file. Please use Pump to convert it to
|
||||
$$ gmock-generated-actions.h.
|
||||
$$
|
||||
$var n = 10 $$ The maximum arity we support.
|
||||
|
@ -49,12 +49,13 @@ namespace testing {
|
|||
namespace internal {
|
||||
|
||||
// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
|
||||
// function or method with the unpacked values, where F is a function
|
||||
// type that takes N arguments.
|
||||
// function, method, or callback with the unpacked values, where F is
|
||||
// a function type that takes N arguments.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
class InvokeHelper;
|
||||
|
||||
|
||||
$var max_callback_arity = 5
|
||||
$range i 0..n
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
|
@ -76,10 +77,48 @@ class InvokeHelper<R, ::testing::tuple<$as> > {
|
|||
const ::testing::tuple<$as>&$args) {
|
||||
return (obj_ptr->*method_ptr)($gets);
|
||||
}
|
||||
|
||||
|
||||
$if i <= max_callback_arity [[
|
||||
template <typename CallbackType>
|
||||
static R InvokeCallback(CallbackType* callback,
|
||||
const ::testing::tuple<$as>&$args) {
|
||||
return callback->Run($gets);
|
||||
}
|
||||
]] $else [[
|
||||
// There is no InvokeCallback() for $i-tuples, as google3 callbacks
|
||||
// support $max_callback_arity arguments at most.
|
||||
]]
|
||||
|
||||
};
|
||||
|
||||
|
||||
]]
|
||||
// Implements the Invoke(callback) action.
|
||||
template <typename CallbackType>
|
||||
class InvokeCallbackAction {
|
||||
public:
|
||||
// The c'tor takes ownership of the callback.
|
||||
explicit InvokeCallbackAction(CallbackType* callback)
|
||||
: callback_(callback) {
|
||||
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
|
||||
}
|
||||
|
||||
// This type conversion operator template allows Invoke(callback) to
|
||||
// be used wherever the callback's type is compatible with that of
|
||||
// the mock function, i.e. if the mock function's arguments can be
|
||||
// implicitly converted to the callback's arguments and the
|
||||
// callback's result can be implicitly converted to the mock
|
||||
// function's result.
|
||||
template <typename Result, typename ArgumentTuple>
|
||||
Result Perform(const ArgumentTuple& args) const {
|
||||
return InvokeHelper<Result, ArgumentTuple>::InvokeCallback(
|
||||
callback_.get(), args);
|
||||
}
|
||||
private:
|
||||
const linked_ptr<CallbackType> callback_;
|
||||
};
|
||||
|
||||
// An INTERNAL macro for extracting the type of a tuple field. It's
|
||||
// subject to change without notice - DO NOT USE IN USER CODE!
|
||||
#define GMOCK_FIELD_(Tuple, N) \
|
||||
|
@ -486,7 +525,7 @@ _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
|
|||
$for i [[
|
||||
$range j 0..i-1
|
||||
#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\
|
||||
($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]]
|
||||
($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(::testing::internal::move(gmock_p$j))]]
|
||||
|
||||
|
||||
]]
|
||||
|
@ -619,7 +658,7 @@ $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
|
|||
$range j 0..i-1
|
||||
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
|
||||
$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::forward<p$j##_type>(gmock_p$j))]]]]]]
|
||||
$var param_field_decls = [[$for j
|
||||
[[
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert it to
|
||||
$$ gmock-generated-function-mockers.h.
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to gmock-generated-function-mockers.h.
|
||||
$$
|
||||
$var n = 10 $$ The maximum arity we support.
|
||||
// Copyright 2007, Google Inc.
|
||||
|
@ -68,7 +68,7 @@ $for i [[
|
|||
$range j 1..i
|
||||
$var typename_As = [[$for j [[, typename A$j]]]]
|
||||
$var As = [[$for j, [[A$j]]]]
|
||||
$var as = [[$for j, [[a$j]]]]
|
||||
$var as = [[$for j, [[internal::forward<A$j>(a$j)]]]]
|
||||
$var Aas = [[$for j, [[A$j a$j]]]]
|
||||
$var ms = [[$for j, [[m$j]]]]
|
||||
$var matchers = [[$for j, [[const Matcher<A$j>& m$j]]]]
|
||||
|
@ -79,13 +79,8 @@ class FunctionMocker<R($As)> : public
|
|||
typedef R F($As);
|
||||
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
|
||||
|
||||
MockSpec<F>& With($matchers) {
|
||||
|
||||
$if i >= 1 [[
|
||||
this->current_spec().SetMatchers(::testing::make_tuple($ms));
|
||||
|
||||
]]
|
||||
return this->current_spec();
|
||||
MockSpec<F> With($matchers) {
|
||||
return MockSpec<F>(this, ::testing::make_tuple($ms));
|
||||
}
|
||||
|
||||
R Invoke($Aas) {
|
||||
|
@ -99,6 +94,58 @@ $if i >= 1 [[
|
|||
|
||||
|
||||
]]
|
||||
// Removes the given pointer; this is a helper for the expectation setter method
|
||||
// for parameterless matchers.
|
||||
//
|
||||
// We want to make sure that the user cannot set a parameterless expectation on
|
||||
// overloaded methods, including methods which are overloaded on const. Example:
|
||||
//
|
||||
// class MockClass {
|
||||
// MOCK_METHOD0(GetName, string&());
|
||||
// MOCK_CONST_METHOD0(GetName, const string&());
|
||||
// };
|
||||
//
|
||||
// TEST() {
|
||||
// // This should be an error, as it's not clear which overload is expected.
|
||||
// EXPECT_CALL(mock, GetName).WillOnce(ReturnRef(value));
|
||||
// }
|
||||
//
|
||||
// Here are the generated expectation-setter methods:
|
||||
//
|
||||
// class MockClass {
|
||||
// // Overload 1
|
||||
// MockSpec<string&()> gmock_GetName() { … }
|
||||
// // Overload 2. Declared const so that the compiler will generate an
|
||||
// // error when trying to resolve between this and overload 4 in
|
||||
// // 'gmock_GetName(WithoutMatchers(), nullptr)'.
|
||||
// MockSpec<string&()> gmock_GetName(
|
||||
// const WithoutMatchers&, const Function<string&()>*) const {
|
||||
// // Removes const from this, calls overload 1
|
||||
// return AdjustConstness_(this)->gmock_GetName();
|
||||
// }
|
||||
//
|
||||
// // Overload 3
|
||||
// const string& gmock_GetName() const { … }
|
||||
// // Overload 4
|
||||
// MockSpec<const string&()> gmock_GetName(
|
||||
// const WithoutMatchers&, const Function<const string&()>*) const {
|
||||
// // Does not remove const, calls overload 3
|
||||
// return AdjustConstness_const(this)->gmock_GetName();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
template <typename MockType>
|
||||
const MockType* AdjustConstness_const(const MockType* mock) {
|
||||
return mock;
|
||||
}
|
||||
|
||||
// Removes const from and returns the given pointer; this is a helper for the
|
||||
// expectation setter method for parameterless matchers.
|
||||
template <typename MockType>
|
||||
MockType* AdjustConstness_(const MockType* mock) {
|
||||
return const_cast<MockType*>(mock);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// The style guide prohibits "using" statements in a namespace scope
|
||||
|
@ -134,11 +181,14 @@ using internal::FunctionMocker;
|
|||
|
||||
$for i [[
|
||||
$range j 1..i
|
||||
$var arg_as = [[$for j, \
|
||||
[[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
|
||||
$var as = [[$for j, [[gmock_a$j]]]]
|
||||
$var matcher_as = [[$for j, \
|
||||
$var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
|
||||
$var as = [[$for j, \
|
||||
[[::testing::internal::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]]
|
||||
$var matcher_arg_as = [[$for j, \
|
||||
[[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
|
||||
$var matcher_as = [[$for j, [[gmock_a$j]]]]
|
||||
$var anything_matchers = [[$for j, \
|
||||
[[::testing::A<GMOCK_ARG_(tn, $j, __VA_ARGS__)>()]]]]
|
||||
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
|
||||
#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \
|
||||
GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
|
||||
|
@ -149,11 +199,17 @@ $var matcher_as = [[$for j, \
|
|||
GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
|
||||
return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \
|
||||
} \
|
||||
::testing::MockSpec<__VA_ARGS__>& \
|
||||
gmock_##Method($matcher_as) constness { \
|
||||
::testing::MockSpec<__VA_ARGS__> \
|
||||
gmock_##Method($matcher_arg_as) constness { \
|
||||
GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \
|
||||
return GMOCK_MOCKER_($i, constness, Method).With($as); \
|
||||
return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \
|
||||
} \
|
||||
::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
|
||||
const ::testing::internal::WithoutMatchers&, \
|
||||
constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
|
||||
return ::testing::internal::AdjustConstness_##constness(this)-> \
|
||||
gmock_##Method($anything_matchers); \
|
||||
} \
|
||||
mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method)
|
||||
|
||||
|
||||
|
@ -263,7 +319,7 @@ class MockFunction;
|
|||
$for i [[
|
||||
$range j 0..i-1
|
||||
$var ArgTypes = [[$for j, [[A$j]]]]
|
||||
$var ArgNames = [[$for j, [[a$j]]]]
|
||||
$var ArgValues = [[$for j, [[::std::move(a$j)]]]]
|
||||
$var ArgDecls = [[$for j, [[A$j a$j]]]]
|
||||
template <typename R$for j [[, typename A$j]]>
|
||||
class MockFunction<R($ArgTypes)> {
|
||||
|
@ -273,9 +329,9 @@ class MockFunction<R($ArgTypes)> {
|
|||
MOCK_METHOD$i[[]]_T(Call, R($ArgTypes));
|
||||
|
||||
#if GTEST_HAS_STD_FUNCTION_
|
||||
std::function<R($ArgTypes)> AsStdFunction() {
|
||||
::std::function<R($ArgTypes)> AsStdFunction() {
|
||||
return [this]($ArgDecls) -> R {
|
||||
return this->Call($ArgNames);
|
||||
return this->Call($ArgValues);
|
||||
};
|
||||
}
|
||||
#endif // GTEST_HAS_STD_FUNCTION_
|
||||
|
|
|
@ -779,6 +779,9 @@ ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
|
|||
|
||||
// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
|
||||
// that matches n elements in any order. We support up to n=10 arguments.
|
||||
//
|
||||
// If you have >10 elements, consider UnorderedElementsAreArray() or
|
||||
// UnorderedPointwise() instead.
|
||||
|
||||
inline internal::UnorderedElementsAreMatcher<
|
||||
::testing::tuple<> >
|
||||
|
@ -1268,7 +1271,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
// using testing::PrintToString;
|
||||
//
|
||||
// MATCHER_P2(InClosedRange, low, hi,
|
||||
// string(negation ? "is not" : "is") + " in range [" +
|
||||
// std::string(negation ? "is not" : "is") + " in range [" +
|
||||
// PrintToString(low) + ", " + PrintToString(hi) + "]") {
|
||||
// return low <= arg && arg <= hi;
|
||||
// }
|
||||
|
@ -1383,12 +1386,14 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##Matcher {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl()\
|
||||
{}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
|
@ -1396,17 +1401,15 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<>()));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1416,14 +1419,13 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
name##Matcher() {\
|
||||
}\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##Matcher);\
|
||||
};\
|
||||
inline name##Matcher name() {\
|
||||
return name##Matcher();\
|
||||
}\
|
||||
template <typename arg_type>\
|
||||
bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1432,42 +1434,42 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
explicit gmock_Impl(p0##_type gmock_p0)\
|
||||
: p0(gmock_p0) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p0##_type const p0;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type>(p0)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
return ::testing::Matcher<arg_type>(\
|
||||
new gmock_Impl<arg_type>(p0));\
|
||||
}\
|
||||
explicit name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
|
||||
explicit name##MatcherP(p0##_type gmock_p0) : \
|
||||
p0(::testing::internal::move(gmock_p0)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p0##_type const p0;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
|
||||
};\
|
||||
template <typename p0##_type>\
|
||||
inline name##MatcherP<p0##_type> name(p0##_type p0) {\
|
||||
|
@ -1476,7 +1478,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename p0##_type>\
|
||||
template <typename arg_type>\
|
||||
bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1485,45 +1487,46 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP2 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
|
||||
: p0(gmock_p0), p1(gmock_p1) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type>(p0, p1)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
return ::testing::Matcher<arg_type>(\
|
||||
new gmock_Impl<arg_type>(p0, p1));\
|
||||
}\
|
||||
name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
|
||||
p1(gmock_p1) {\
|
||||
name##MatcherP2(p0##_type gmock_p0, \
|
||||
p1##_type gmock_p1) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type>\
|
||||
inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
|
||||
|
@ -1534,7 +1537,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename arg_type>\
|
||||
bool name##MatcherP2<p0##_type, \
|
||||
p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1543,34 +1546,36 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP3 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
|
||||
p2)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1578,13 +1583,14 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
new gmock_Impl<arg_type>(p0, p1, p2));\
|
||||
}\
|
||||
name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
|
||||
p2##_type gmock_p2) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type>\
|
||||
inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
|
||||
|
@ -1595,7 +1601,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename arg_type>\
|
||||
bool name##MatcherP3<p0##_type, p1##_type, \
|
||||
p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1605,36 +1611,39 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP4 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, \
|
||||
p3##_type>(p0, p1, p2, p3)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1642,15 +1651,17 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
new gmock_Impl<arg_type>(p0, p1, p2, p3));\
|
||||
}\
|
||||
name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3) {\
|
||||
p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type>\
|
||||
|
@ -1665,7 +1676,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename arg_type>\
|
||||
bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
|
||||
p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1675,38 +1686,41 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP5 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
|
||||
p4(gmock_p4) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type>(p0, p1, p2, p3, p4)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1715,16 +1729,18 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
}\
|
||||
name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, \
|
||||
p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4) {\
|
||||
p4##_type gmock_p4) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type>\
|
||||
|
@ -1739,7 +1755,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename arg_type>\
|
||||
bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1749,39 +1765,43 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP6 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
|
||||
p4(gmock_p4), p5(gmock_p5) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1790,17 +1810,20 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
}\
|
||||
name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
|
||||
p5##_type gmock_p5) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type>\
|
||||
|
@ -1815,7 +1838,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename arg_type>\
|
||||
bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
|
||||
p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1826,34 +1849,40 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP7 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
|
||||
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
|
@ -1861,7 +1890,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
|
||||
p6)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1870,19 +1898,23 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
}\
|
||||
name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
|
||||
p6(gmock_p6) {\
|
||||
p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
|
@ -1900,7 +1932,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
template <typename arg_type>\
|
||||
bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
|
||||
p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -1911,35 +1943,42 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP8 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
|
||||
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p7##_type p7;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
p7##_type const p7;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
|
@ -1947,7 +1986,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
|
||||
p3, p4, p5, p6, p7)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -1957,20 +1995,24 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, \
|
||||
p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7) {\
|
||||
p7##_type gmock_p7) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p7##_type p7;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
p7##_type const p7;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
|
@ -1990,7 +2032,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
|
||||
p5##_type, p6##_type, \
|
||||
p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -2001,37 +2043,44 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP9 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
|
||||
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
|
||||
p8(gmock_p8) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p7##_type p7;\
|
||||
p8##_type p8;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
p7##_type const p7;\
|
||||
p8##_type const p8;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
|
@ -2039,7 +2088,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
p4##_type, p5##_type, p6##_type, p7##_type, \
|
||||
p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -2049,21 +2097,26 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
|
||||
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
|
||||
p8(gmock_p8) {\
|
||||
p8##_type gmock_p8) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p7##_type p7;\
|
||||
p8##_type p8;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
p7##_type const p7;\
|
||||
p8##_type const p8;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
|
@ -2084,7 +2137,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
|
||||
p5##_type, p6##_type, p7##_type, \
|
||||
p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
@ -2096,39 +2149,47 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
class name##MatcherP10 {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
|
||||
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
|
||||
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9)\
|
||||
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
|
||||
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
|
||||
p8(gmock_p8), p9(gmock_p9) {}\
|
||||
: p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)), \
|
||||
p9(::testing::internal::move(gmock_p9)) {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(true);\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p7##_type p7;\
|
||||
p8##_type p8;\
|
||||
p9##_type p9;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
p7##_type const p7;\
|
||||
p8##_type const p8;\
|
||||
p9##_type const p9;\
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
|
@ -2136,7 +2197,6 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
|
||||
p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -2146,22 +2206,29 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
|
||||
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
|
||||
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
|
||||
p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
|
||||
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
|
||||
p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
|
||||
p8##_type gmock_p8, \
|
||||
p9##_type gmock_p9) : p0(::testing::internal::move(gmock_p0)), \
|
||||
p1(::testing::internal::move(gmock_p1)), \
|
||||
p2(::testing::internal::move(gmock_p2)), \
|
||||
p3(::testing::internal::move(gmock_p3)), \
|
||||
p4(::testing::internal::move(gmock_p4)), \
|
||||
p5(::testing::internal::move(gmock_p5)), \
|
||||
p6(::testing::internal::move(gmock_p6)), \
|
||||
p7(::testing::internal::move(gmock_p7)), \
|
||||
p8(::testing::internal::move(gmock_p8)), \
|
||||
p9(::testing::internal::move(gmock_p9)) {\
|
||||
}\
|
||||
p0##_type p0;\
|
||||
p1##_type p1;\
|
||||
p2##_type p2;\
|
||||
p3##_type p3;\
|
||||
p4##_type p4;\
|
||||
p5##_type p5;\
|
||||
p6##_type p6;\
|
||||
p7##_type p7;\
|
||||
p8##_type p8;\
|
||||
p9##_type p9;\
|
||||
p0##_type const p0;\
|
||||
p1##_type const p1;\
|
||||
p2##_type const p2;\
|
||||
p3##_type const p3;\
|
||||
p4##_type const p4;\
|
||||
p5##_type const p5;\
|
||||
p6##_type const p6;\
|
||||
p7##_type const p7;\
|
||||
p8##_type const p8;\
|
||||
p9##_type const p9;\
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
|
||||
};\
|
||||
template <typename p0##_type, typename p1##_type, typename p2##_type, \
|
||||
typename p3##_type, typename p4##_type, typename p5##_type, \
|
||||
|
@ -2184,7 +2251,7 @@ AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
|
|||
bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
|
||||
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
|
||||
p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert it to
|
||||
$$ gmock-generated-actions.h.
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to gmock-generated-matchers.h.
|
||||
$$
|
||||
$var n = 10 $$ The maximum arity we support.
|
||||
$$ }} This line fixes auto-indentation of the following code in Emacs.
|
||||
|
@ -303,6 +303,9 @@ $for j, [[
|
|||
|
||||
// UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
|
||||
// that matches n elements in any order. We support up to n=$n arguments.
|
||||
//
|
||||
// If you have >$n elements, consider UnorderedElementsAreArray() or
|
||||
// UnorderedPointwise() instead.
|
||||
|
||||
$range i 0..n
|
||||
$for i [[
|
||||
|
@ -479,7 +482,7 @@ $$ // show up in the generated code.
|
|||
// using testing::PrintToString;
|
||||
//
|
||||
// MATCHER_P2(InClosedRange, low, hi,
|
||||
// string(negation ? "is not" : "is") + " in range [" +
|
||||
// std::string(negation ? "is not" : "is") + " in range [" +
|
||||
// PrintToString(low) + ", " + PrintToString(hi) + "]") {
|
||||
// return low <= arg && arg <= hi;
|
||||
// }
|
||||
|
@ -604,32 +607,34 @@ $var template = [[$if i==0 [[]] $else [[
|
|||
]]]]
|
||||
$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
|
||||
$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
|
||||
$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
|
||||
$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
|
||||
$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
|
||||
$var params = [[$for j, [[p$j]]]]
|
||||
$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
|
||||
$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
|
||||
$var param_field_decls = [[$for j
|
||||
[[
|
||||
|
||||
p$j##_type p$j;\
|
||||
p$j##_type const p$j;\
|
||||
]]]]
|
||||
$var param_field_decls2 = [[$for j
|
||||
[[
|
||||
|
||||
p$j##_type p$j;\
|
||||
p$j##_type const p$j;\
|
||||
]]]]
|
||||
|
||||
#define $macro_name(name$for j [[, p$j]], description)\$template
|
||||
class $class_name {\
|
||||
public:\
|
||||
template <typename arg_type>\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
|
||||
class gmock_Impl : public ::testing::MatcherInterface<\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type)> {\
|
||||
public:\
|
||||
[[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
|
||||
$impl_inits {}\
|
||||
virtual bool MatchAndExplain(\
|
||||
arg_type arg, ::testing::MatchResultListener* result_listener) const;\
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener) const;\
|
||||
virtual void DescribeTo(::std::ostream* gmock_os) const {\
|
||||
*gmock_os << FormatDescription(false);\
|
||||
}\
|
||||
|
@ -637,17 +642,15 @@ $var param_field_decls2 = [[$for j
|
|||
*gmock_os << FormatDescription(true);\
|
||||
}\$param_field_decls
|
||||
private:\
|
||||
::testing::internal::string FormatDescription(bool negation) const {\
|
||||
const ::testing::internal::string gmock_description = (description);\
|
||||
if (!gmock_description.empty()) {\
|
||||
::std::string FormatDescription(bool negation) const {\
|
||||
::std::string gmock_description = (description);\
|
||||
if (!gmock_description.empty())\
|
||||
return gmock_description;\
|
||||
}\
|
||||
return ::testing::internal::FormatMatcherDescription(\
|
||||
negation, #name, \
|
||||
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
|
||||
::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
|
||||
}\
|
||||
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
|
||||
};\
|
||||
template <typename arg_type>\
|
||||
operator ::testing::Matcher<arg_type>() const {\
|
||||
|
@ -657,14 +660,13 @@ $var param_field_decls2 = [[$for j
|
|||
[[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\
|
||||
}\$param_field_decls2
|
||||
private:\
|
||||
GTEST_DISALLOW_ASSIGN_($class_name);\
|
||||
};\$template
|
||||
inline $class_name$param_types name($param_types_and_names) {\
|
||||
return $class_name$param_types($params);\
|
||||
}\$template
|
||||
template <typename arg_type>\
|
||||
bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\
|
||||
arg_type arg, \
|
||||
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
|
||||
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
|
||||
const
|
||||
]]
|
||||
|
|
|
@ -51,10 +51,9 @@
|
|||
// NiceMock<MockFoo>.
|
||||
//
|
||||
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
|
||||
// their respective base class, with up-to 10 arguments. Therefore
|
||||
// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
|
||||
// where MockFoo has a constructor that accepts (int, const char*),
|
||||
// for example.
|
||||
// their respective base class. Therefore you can write
|
||||
// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
|
||||
// has a constructor that accepts (int, const char*), for example.
|
||||
//
|
||||
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
|
||||
// and StrictMock<MockFoo> only works for mock methods defined using
|
||||
|
@ -63,10 +62,6 @@
|
|||
// or "strict" modifier may not affect it, depending on the compiler.
|
||||
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
|
||||
// supported.
|
||||
//
|
||||
// Another known limitation is that the constructors of the base mock
|
||||
// cannot have arguments passed by non-const reference, which are
|
||||
// banned by the Google C++ style guide anyway.
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
|
@ -79,15 +74,35 @@ namespace testing {
|
|||
template <class MockClass>
|
||||
class NiceMock : public MockClass {
|
||||
public:
|
||||
// We don't factor out the constructor body to a common method, as
|
||||
// we have to avoid a possible clash with members of MockClass.
|
||||
NiceMock() {
|
||||
NiceMock() : MockClass() {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// C++ doesn't (yet) allow inheritance of constructors, so we have
|
||||
// to define it for each arity.
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NiceMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit NiceMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::AllowUninterestingCalls(
|
||||
|
@ -163,7 +178,9 @@ class NiceMock : public MockClass {
|
|||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
virtual ~NiceMock() {
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~NiceMock() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
@ -175,15 +192,35 @@ class NiceMock : public MockClass {
|
|||
template <class MockClass>
|
||||
class NaggyMock : public MockClass {
|
||||
public:
|
||||
// We don't factor out the constructor body to a common method, as
|
||||
// we have to avoid a possible clash with members of MockClass.
|
||||
NaggyMock() {
|
||||
NaggyMock() : MockClass() {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// C++ doesn't (yet) allow inheritance of constructors, so we have
|
||||
// to define it for each arity.
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit NaggyMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::WarnUninterestingCalls(
|
||||
|
@ -259,7 +296,9 @@ class NaggyMock : public MockClass {
|
|||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
virtual ~NaggyMock() {
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~NaggyMock() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
@ -271,15 +310,35 @@ class NaggyMock : public MockClass {
|
|||
template <class MockClass>
|
||||
class StrictMock : public MockClass {
|
||||
public:
|
||||
// We don't factor out the constructor body to a common method, as
|
||||
// we have to avoid a possible clash with members of MockClass.
|
||||
StrictMock() {
|
||||
StrictMock() : MockClass() {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// C++ doesn't (yet) allow inheritance of constructors, so we have
|
||||
// to define it for each arity.
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
StrictMock(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit StrictMock(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::FailUninterestingCalls(
|
||||
|
@ -355,7 +414,9 @@ class StrictMock : public MockClass {
|
|||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
virtual ~StrictMock() {
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~StrictMock() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file. Please use Pump to convert it to
|
||||
$$ gmock-generated-nice-strict.h.
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to gmock-generated-nice-strict.h.
|
||||
$$
|
||||
$var n = 10 $$ The maximum arity we support.
|
||||
// Copyright 2008, Google Inc.
|
||||
|
@ -52,10 +52,9 @@ $var n = 10 $$ The maximum arity we support.
|
|||
// NiceMock<MockFoo>.
|
||||
//
|
||||
// NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
|
||||
// their respective base class, with up-to $n arguments. Therefore
|
||||
// you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
|
||||
// where MockFoo has a constructor that accepts (int, const char*),
|
||||
// for example.
|
||||
// their respective base class. Therefore you can write
|
||||
// NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
|
||||
// has a constructor that accepts (int, const char*), for example.
|
||||
//
|
||||
// A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
|
||||
// and StrictMock<MockFoo> only works for mock methods defined using
|
||||
|
@ -64,10 +63,6 @@ $var n = 10 $$ The maximum arity we support.
|
|||
// or "strict" modifier may not affect it, depending on the compiler.
|
||||
// In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
|
||||
// supported.
|
||||
//
|
||||
// Another known limitation is that the constructors of the base mock
|
||||
// cannot have arguments passed by non-const reference, which are
|
||||
// banned by the Google C++ style guide anyway.
|
||||
|
||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
|
||||
|
@ -91,15 +86,35 @@ $var method=[[$if kind==0 [[AllowUninterestingCalls]]
|
|||
template <class MockClass>
|
||||
class $clazz : public MockClass {
|
||||
public:
|
||||
// We don't factor out the constructor body to a common method, as
|
||||
// we have to avoid a possible clash with members of MockClass.
|
||||
$clazz() {
|
||||
$clazz() : MockClass() {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
// C++ doesn't (yet) allow inheritance of constructors, so we have
|
||||
// to define it for each arity.
|
||||
#if GTEST_LANG_CXX11
|
||||
// Ideally, we would inherit base class's constructors through a using
|
||||
// declaration, which would preserve their visibility. However, many existing
|
||||
// tests rely on the fact that current implementation reexports protected
|
||||
// constructors as public. These tests would need to be cleaned up first.
|
||||
|
||||
// Single argument constructor is special-cased so that it can be
|
||||
// made explicit.
|
||||
template <typename A>
|
||||
explicit $clazz(A&& arg) : MockClass(std::forward<A>(arg)) {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
||||
template <typename A1, typename A2, typename... An>
|
||||
$clazz(A1&& arg1, A2&& arg2, An&&... args)
|
||||
: MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
|
||||
std::forward<An>(args)...) {
|
||||
::testing::Mock::$method(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
#else
|
||||
// C++98 doesn't have variadic templates, so we have to define one
|
||||
// for each arity.
|
||||
template <typename A1>
|
||||
explicit $clazz(const A1& a1) : MockClass(a1) {
|
||||
::testing::Mock::$method(
|
||||
|
@ -117,7 +132,9 @@ $range j 1..i
|
|||
|
||||
|
||||
]]
|
||||
virtual ~$clazz() {
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
~$clazz() {
|
||||
::testing::Mock::UnregisterCallReaction(
|
||||
internal::ImplicitCast_<MockClass*>(this));
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ class MatcherBase {
|
|||
}
|
||||
|
||||
// Returns true iff this matcher matches x.
|
||||
bool Matches(T x) const {
|
||||
bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const {
|
||||
DummyMatchResultListener dummy;
|
||||
return MatchAndExplain(x, &dummy);
|
||||
}
|
||||
|
@ -301,7 +301,8 @@ class MatcherBase {
|
|||
}
|
||||
|
||||
// Explains why x matches, or doesn't match, the matcher.
|
||||
void ExplainMatchResultTo(T x, ::std::ostream* os) const {
|
||||
void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
::std::ostream* os) const {
|
||||
StreamMatchResultListener listener(os);
|
||||
MatchAndExplain(x, &listener);
|
||||
}
|
||||
|
@ -317,7 +318,8 @@ class MatcherBase {
|
|||
MatcherBase() {}
|
||||
|
||||
// Constructs a matcher from its implementation.
|
||||
explicit MatcherBase(const MatcherInterface<T>* impl)
|
||||
explicit MatcherBase(
|
||||
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
|
||||
: impl_(impl) {}
|
||||
|
||||
template <typename U>
|
||||
|
@ -342,7 +344,9 @@ class MatcherBase {
|
|||
//
|
||||
// If performance becomes a problem, we should see if using
|
||||
// shared_ptr helps.
|
||||
::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
|
||||
::testing::internal::linked_ptr<
|
||||
const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> >
|
||||
impl_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
@ -407,6 +411,8 @@ class GTEST_API_ Matcher<std::string>
|
|||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const std::string&>* impl)
|
||||
: internal::MatcherBase<std::string>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<std::string>* impl)
|
||||
: internal::MatcherBase<std::string>(impl) {}
|
||||
|
||||
|
@ -449,28 +455,95 @@ class GTEST_API_ Matcher<const ::string&>
|
|||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher<StringPiece>
|
||||
: public internal::MatcherBase<StringPiece> {
|
||||
class GTEST_API_ Matcher< ::string>
|
||||
: public internal::MatcherBase< ::string> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<StringPiece>* impl)
|
||||
: internal::MatcherBase<StringPiece>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<const ::string&>* impl)
|
||||
: internal::MatcherBase< ::string>(impl) {}
|
||||
explicit Matcher(const MatcherInterface< ::string>* impl)
|
||||
: internal::MatcherBase< ::string>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a string object.
|
||||
Matcher(const internal::string& s); // NOLINT
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
};
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// The following two specializations allow the user to write str
|
||||
// instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
|
||||
// matcher is expected.
|
||||
template <>
|
||||
class GTEST_API_ Matcher<const absl::string_view&>
|
||||
: public internal::MatcherBase<const absl::string_view&> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||
: internal::MatcherBase<const absl::string_view&>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
|
||||
// Allows the user to pass StringPieces directly.
|
||||
Matcher(StringPiece s); // NOLINT
|
||||
// Allows the user to pass absl::string_views directly.
|
||||
Matcher(absl::string_view s); // NOLINT
|
||||
};
|
||||
#endif // GTEST_HAS_STRING_PIECE_
|
||||
|
||||
template <>
|
||||
class GTEST_API_ Matcher<absl::string_view>
|
||||
: public internal::MatcherBase<absl::string_view> {
|
||||
public:
|
||||
Matcher() {}
|
||||
|
||||
explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
|
||||
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||
explicit Matcher(const MatcherInterface<absl::string_view>* impl)
|
||||
: internal::MatcherBase<absl::string_view>(impl) {}
|
||||
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a std::string object.
|
||||
Matcher(const std::string& s); // NOLINT
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Allows the user to write str instead of Eq(str) sometimes, where
|
||||
// str is a ::string object.
|
||||
Matcher(const ::string& s); // NOLINT
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Allows the user to write "foo" instead of Eq("foo") sometimes.
|
||||
Matcher(const char* s); // NOLINT
|
||||
|
||||
// Allows the user to pass absl::string_views directly.
|
||||
Matcher(absl::string_view s); // NOLINT
|
||||
};
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Prints a matcher in a human-readable format.
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
|
||||
matcher.DescribeTo(&os);
|
||||
return os;
|
||||
}
|
||||
|
||||
// The PolymorphicMatcher class template makes it easy to implement a
|
||||
// polymorphic matcher (i.e. a matcher that can match values of more
|
||||
|
@ -499,7 +572,7 @@ class PolymorphicMatcher {
|
|||
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new MonomorphicImpl<T>(impl_));
|
||||
return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -845,7 +918,7 @@ class TuplePrefix {
|
|||
typename tuple_element<N - 1, MatcherTuple>::type matcher =
|
||||
get<N - 1>(matchers);
|
||||
typedef typename tuple_element<N - 1, ValueTuple>::type Value;
|
||||
Value value = get<N - 1>(values);
|
||||
GTEST_REFERENCE_TO_CONST_(Value) value = get<N - 1>(values);
|
||||
StringMatchResultListener listener;
|
||||
if (!matcher.MatchAndExplain(value, &listener)) {
|
||||
// TODO(wan): include in the message the name of the parameter
|
||||
|
@ -950,10 +1023,12 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
|
|||
|
||||
// Implements A<T>().
|
||||
template <typename T>
|
||||
class AnyMatcherImpl : public MatcherInterface<T> {
|
||||
class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
public:
|
||||
virtual bool MatchAndExplain(
|
||||
T /* x */, MatchResultListener* /* listener */) const { return true; }
|
||||
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */,
|
||||
MatchResultListener* /* listener */) const {
|
||||
return true;
|
||||
}
|
||||
virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
// This is mostly for completeness' safe, as it's not very useful
|
||||
|
@ -1223,6 +1298,19 @@ class StrEqualityMatcher {
|
|||
bool case_sensitive)
|
||||
: string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
if (s.data() == NULL) {
|
||||
return !expect_eq_;
|
||||
}
|
||||
// This should fail to compile if absl::string_view is used with wide
|
||||
// strings.
|
||||
const StringType& str = string(s);
|
||||
return MatchAndExplain(str, listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
|
@ -1239,7 +1327,7 @@ class StrEqualityMatcher {
|
|||
// Matches anything that can convert to StringType.
|
||||
//
|
||||
// This is a template, not just a plain function with const StringType&,
|
||||
// because StringPiece has some interfering non-explicit constructors.
|
||||
// because absl::string_view has some interfering non-explicit constructors.
|
||||
template <typename MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
|
@ -1283,6 +1371,19 @@ class HasSubstrMatcher {
|
|||
explicit HasSubstrMatcher(const StringType& substring)
|
||||
: substring_(substring) {}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
if (s.data() == NULL) {
|
||||
return false;
|
||||
}
|
||||
// This should fail to compile if absl::string_view is used with wide
|
||||
// strings.
|
||||
const StringType& str = string(s);
|
||||
return MatchAndExplain(str, listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
|
@ -1296,7 +1397,7 @@ class HasSubstrMatcher {
|
|||
// Matches anything that can convert to StringType.
|
||||
//
|
||||
// This is a template, not just a plain function with const StringType&,
|
||||
// because StringPiece has some interfering non-explicit constructors.
|
||||
// because absl::string_view has some interfering non-explicit constructors.
|
||||
template <typename MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
|
@ -1330,6 +1431,19 @@ class StartsWithMatcher {
|
|||
explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
|
||||
}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
if (s.data() == NULL) {
|
||||
return false;
|
||||
}
|
||||
// This should fail to compile if absl::string_view is used with wide
|
||||
// strings.
|
||||
const StringType& str = string(s);
|
||||
return MatchAndExplain(str, listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
|
@ -1343,7 +1457,7 @@ class StartsWithMatcher {
|
|||
// Matches anything that can convert to StringType.
|
||||
//
|
||||
// This is a template, not just a plain function with const StringType&,
|
||||
// because StringPiece has some interfering non-explicit constructors.
|
||||
// because absl::string_view has some interfering non-explicit constructors.
|
||||
template <typename MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
|
@ -1376,6 +1490,19 @@ class EndsWithMatcher {
|
|||
public:
|
||||
explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
if (s.data() == NULL) {
|
||||
return false;
|
||||
}
|
||||
// This should fail to compile if absl::string_view is used with wide
|
||||
// strings.
|
||||
const StringType& str = string(s);
|
||||
return MatchAndExplain(str, listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
|
@ -1389,7 +1516,7 @@ class EndsWithMatcher {
|
|||
// Matches anything that can convert to StringType.
|
||||
//
|
||||
// This is a template, not just a plain function with const StringType&,
|
||||
// because StringPiece has some interfering non-explicit constructors.
|
||||
// because absl::string_view has some interfering non-explicit constructors.
|
||||
template <typename MatcheeStringType>
|
||||
bool MatchAndExplain(const MatcheeStringType& s,
|
||||
MatchResultListener* /* listener */) const {
|
||||
|
@ -1422,6 +1549,13 @@ class MatchesRegexMatcher {
|
|||
MatchesRegexMatcher(const RE* regex, bool full_match)
|
||||
: regex_(regex), full_match_(full_match) {}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
bool MatchAndExplain(const absl::string_view& s,
|
||||
MatchResultListener* listener) const {
|
||||
return s.data() && MatchAndExplain(string(s), listener);
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
// Accepts pointer types, particularly:
|
||||
// const char*
|
||||
// char*
|
||||
|
@ -1535,12 +1669,13 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
|
|||
// will prevent different instantiations of NotMatcher from sharing
|
||||
// the same NotMatcherImpl<T> class.
|
||||
template <typename T>
|
||||
class NotMatcherImpl : public MatcherInterface<T> {
|
||||
class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
public:
|
||||
explicit NotMatcherImpl(const Matcher<T>& matcher)
|
||||
: matcher_(matcher) {}
|
||||
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
||||
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
MatchResultListener* listener) const {
|
||||
return !matcher_.MatchAndExplain(x, listener);
|
||||
}
|
||||
|
||||
|
@ -1583,117 +1718,66 @@ class NotMatcher {
|
|||
// that will prevent different instantiations of BothOfMatcher from
|
||||
// sharing the same BothOfMatcherImpl<T> class.
|
||||
template <typename T>
|
||||
class BothOfMatcherImpl : public MatcherInterface<T> {
|
||||
class AllOfMatcherImpl
|
||||
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
public:
|
||||
BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
|
||||
: matcher1_(matcher1), matcher2_(matcher2) {}
|
||||
explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
|
||||
: matchers_(internal::move(matchers)) {}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
*os << "(";
|
||||
matcher1_.DescribeTo(os);
|
||||
*os << ") and (";
|
||||
matcher2_.DescribeTo(os);
|
||||
for (size_t i = 0; i < matchers_.size(); ++i) {
|
||||
if (i != 0) *os << ") and (";
|
||||
matchers_[i].DescribeTo(os);
|
||||
}
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "(";
|
||||
matcher1_.DescribeNegationTo(os);
|
||||
*os << ") or (";
|
||||
matcher2_.DescribeNegationTo(os);
|
||||
for (size_t i = 0; i < matchers_.size(); ++i) {
|
||||
if (i != 0) *os << ") or (";
|
||||
matchers_[i].DescribeNegationTo(os);
|
||||
}
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
||||
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
MatchResultListener* listener) const {
|
||||
// If either matcher1_ or matcher2_ doesn't match x, we only need
|
||||
// to explain why one of them fails.
|
||||
StringMatchResultListener listener1;
|
||||
if (!matcher1_.MatchAndExplain(x, &listener1)) {
|
||||
*listener << listener1.str();
|
||||
return false;
|
||||
}
|
||||
std::string all_match_result;
|
||||
|
||||
StringMatchResultListener listener2;
|
||||
if (!matcher2_.MatchAndExplain(x, &listener2)) {
|
||||
*listener << listener2.str();
|
||||
return false;
|
||||
for (size_t i = 0; i < matchers_.size(); ++i) {
|
||||
StringMatchResultListener slistener;
|
||||
if (matchers_[i].MatchAndExplain(x, &slistener)) {
|
||||
if (all_match_result.empty()) {
|
||||
all_match_result = slistener.str();
|
||||
} else {
|
||||
std::string result = slistener.str();
|
||||
if (!result.empty()) {
|
||||
all_match_result += ", and ";
|
||||
all_match_result += result;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*listener << slistener.str();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise we need to explain why *both* of them match.
|
||||
const std::string s1 = listener1.str();
|
||||
const std::string s2 = listener2.str();
|
||||
|
||||
if (s1 == "") {
|
||||
*listener << s2;
|
||||
} else {
|
||||
*listener << s1;
|
||||
if (s2 != "") {
|
||||
*listener << ", and " << s2;
|
||||
}
|
||||
}
|
||||
*listener << all_match_result;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
const Matcher<T> matcher1_;
|
||||
const Matcher<T> matcher2_;
|
||||
const std::vector<Matcher<T> > matchers_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
|
||||
GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl);
|
||||
};
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// MatcherList provides mechanisms for storing a variable number of matchers in
|
||||
// a list structure (ListType) and creating a combining matcher from such a
|
||||
// list.
|
||||
// The template is defined recursively using the following template parameters:
|
||||
// * kSize is the length of the MatcherList.
|
||||
// * Head is the type of the first matcher of the list.
|
||||
// * Tail denotes the types of the remaining matchers of the list.
|
||||
template <int kSize, typename Head, typename... Tail>
|
||||
struct MatcherList {
|
||||
typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
|
||||
typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
|
||||
|
||||
// BuildList stores variadic type values in a nested pair structure.
|
||||
// Example:
|
||||
// MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
|
||||
// the corresponding result of type pair<int, pair<string, float>>.
|
||||
static ListType BuildList(const Head& matcher, const Tail&... tail) {
|
||||
return ListType(matcher, MatcherListTail::BuildList(tail...));
|
||||
}
|
||||
|
||||
// CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
|
||||
// by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
|
||||
// list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
|
||||
// constructor taking two Matcher<T>s as input.
|
||||
template <typename T, template <typename /* T */> class CombiningMatcher>
|
||||
static Matcher<T> CreateMatcher(const ListType& matchers) {
|
||||
return Matcher<T>(new CombiningMatcher<T>(
|
||||
SafeMatcherCast<T>(matchers.first),
|
||||
MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
|
||||
matchers.second)));
|
||||
}
|
||||
};
|
||||
|
||||
// The following defines the base case for the recursive definition of
|
||||
// MatcherList.
|
||||
template <typename Matcher1, typename Matcher2>
|
||||
struct MatcherList<2, Matcher1, Matcher2> {
|
||||
typedef ::std::pair<Matcher1, Matcher2> ListType;
|
||||
|
||||
static ListType BuildList(const Matcher1& matcher1,
|
||||
const Matcher2& matcher2) {
|
||||
return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
|
||||
}
|
||||
|
||||
template <typename T, template <typename /* T */> class CombiningMatcher>
|
||||
static Matcher<T> CreateMatcher(const ListType& matchers) {
|
||||
return Matcher<T>(new CombiningMatcher<T>(
|
||||
SafeMatcherCast<T>(matchers.first),
|
||||
SafeMatcherCast<T>(matchers.second)));
|
||||
}
|
||||
};
|
||||
|
||||
// VariadicMatcher is used for the variadic implementation of
|
||||
// AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
|
||||
// CombiningMatcher<T> is used to recursively combine the provided matchers
|
||||
|
@ -1702,27 +1786,40 @@ template <template <typename T> class CombiningMatcher, typename... Args>
|
|||
class VariadicMatcher {
|
||||
public:
|
||||
VariadicMatcher(const Args&... matchers) // NOLINT
|
||||
: matchers_(MatcherListType::BuildList(matchers...)) {}
|
||||
: matchers_(matchers...) {
|
||||
static_assert(sizeof...(Args) > 0, "Must have at least one matcher.");
|
||||
}
|
||||
|
||||
// This template type conversion operator allows an
|
||||
// VariadicMatcher<Matcher1, Matcher2...> object to match any type that
|
||||
// all of the provided matchers (Matcher1, Matcher2, ...) can match.
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
|
||||
matchers_);
|
||||
std::vector<Matcher<T> > values;
|
||||
CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
|
||||
return Matcher<T>(new CombiningMatcher<T>(internal::move(values)));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
|
||||
template <typename T, size_t I>
|
||||
void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
|
||||
std::integral_constant<size_t, I>) const {
|
||||
values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
|
||||
CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
|
||||
}
|
||||
|
||||
const typename MatcherListType::ListType matchers_;
|
||||
template <typename T>
|
||||
void CreateVariadicMatcher(
|
||||
std::vector<Matcher<T> >*,
|
||||
std::integral_constant<size_t, sizeof...(Args)>) const {}
|
||||
|
||||
tuple<Args...> matchers_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
|
||||
using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
|
@ -1739,8 +1836,10 @@ class BothOfMatcher {
|
|||
// both Matcher1 and Matcher2 can match.
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
|
||||
SafeMatcherCast<T>(matcher2_)));
|
||||
std::vector<Matcher<T> > values;
|
||||
values.push_back(SafeMatcherCast<T>(matcher1_));
|
||||
values.push_back(SafeMatcherCast<T>(matcher2_));
|
||||
return Matcher<T>(new AllOfMatcherImpl<T>(internal::move(values)));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1755,68 +1854,69 @@ class BothOfMatcher {
|
|||
// that will prevent different instantiations of AnyOfMatcher from
|
||||
// sharing the same EitherOfMatcherImpl<T> class.
|
||||
template <typename T>
|
||||
class EitherOfMatcherImpl : public MatcherInterface<T> {
|
||||
class AnyOfMatcherImpl
|
||||
: public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
|
||||
public:
|
||||
EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
|
||||
: matcher1_(matcher1), matcher2_(matcher2) {}
|
||||
explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
|
||||
: matchers_(internal::move(matchers)) {}
|
||||
|
||||
virtual void DescribeTo(::std::ostream* os) const {
|
||||
*os << "(";
|
||||
matcher1_.DescribeTo(os);
|
||||
*os << ") or (";
|
||||
matcher2_.DescribeTo(os);
|
||||
for (size_t i = 0; i < matchers_.size(); ++i) {
|
||||
if (i != 0) *os << ") or (";
|
||||
matchers_[i].DescribeTo(os);
|
||||
}
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
virtual void DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "(";
|
||||
matcher1_.DescribeNegationTo(os);
|
||||
*os << ") and (";
|
||||
matcher2_.DescribeNegationTo(os);
|
||||
for (size_t i = 0; i < matchers_.size(); ++i) {
|
||||
if (i != 0) *os << ") and (";
|
||||
matchers_[i].DescribeNegationTo(os);
|
||||
}
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
|
||||
virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
|
||||
MatchResultListener* listener) const {
|
||||
std::string no_match_result;
|
||||
|
||||
// If either matcher1_ or matcher2_ matches x, we just need to
|
||||
// explain why *one* of them matches.
|
||||
StringMatchResultListener listener1;
|
||||
if (matcher1_.MatchAndExplain(x, &listener1)) {
|
||||
*listener << listener1.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
StringMatchResultListener listener2;
|
||||
if (matcher2_.MatchAndExplain(x, &listener2)) {
|
||||
*listener << listener2.str();
|
||||
return true;
|
||||
for (size_t i = 0; i < matchers_.size(); ++i) {
|
||||
StringMatchResultListener slistener;
|
||||
if (matchers_[i].MatchAndExplain(x, &slistener)) {
|
||||
*listener << slistener.str();
|
||||
return true;
|
||||
} else {
|
||||
if (no_match_result.empty()) {
|
||||
no_match_result = slistener.str();
|
||||
} else {
|
||||
std::string result = slistener.str();
|
||||
if (!result.empty()) {
|
||||
no_match_result += ", and ";
|
||||
no_match_result += result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise we need to explain why *both* of them fail.
|
||||
const std::string s1 = listener1.str();
|
||||
const std::string s2 = listener2.str();
|
||||
|
||||
if (s1 == "") {
|
||||
*listener << s2;
|
||||
} else {
|
||||
*listener << s1;
|
||||
if (s2 != "") {
|
||||
*listener << ", and " << s2;
|
||||
}
|
||||
}
|
||||
*listener << no_match_result;
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
const Matcher<T> matcher1_;
|
||||
const Matcher<T> matcher2_;
|
||||
const std::vector<Matcher<T> > matchers_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
|
||||
GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
|
||||
};
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
|
||||
template <typename... Args>
|
||||
using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
|
||||
using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
|
@ -1834,8 +1934,10 @@ class EitherOfMatcher {
|
|||
// both Matcher1 and Matcher2 can match.
|
||||
template <typename T>
|
||||
operator Matcher<T>() const {
|
||||
return Matcher<T>(new EitherOfMatcherImpl<T>(
|
||||
SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
|
||||
std::vector<Matcher<T> > values;
|
||||
values.push_back(SafeMatcherCast<T>(matcher1_));
|
||||
values.push_back(SafeMatcherCast<T>(matcher2_));
|
||||
return Matcher<T>(new AnyOfMatcherImpl<T>(internal::move(values)));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -2224,7 +2326,8 @@ class PointeeMatcher {
|
|||
// enough for implementing the DescribeTo() method of Pointee().
|
||||
template <typename Pointer>
|
||||
operator Matcher<Pointer>() const {
|
||||
return MakeMatcher(new Impl<Pointer>(matcher_));
|
||||
return Matcher<Pointer>(
|
||||
new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -4000,7 +4103,8 @@ class VariantMatcher {
|
|||
private:
|
||||
static std::string GetTypeName() {
|
||||
#if GTEST_HAS_RTTI
|
||||
return internal::GetTypeName<T>();
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
|
||||
return internal::GetTypeName<T>());
|
||||
#endif
|
||||
return "the element type";
|
||||
}
|
||||
|
@ -4060,7 +4164,8 @@ class AnyCastMatcher {
|
|||
private:
|
||||
static std::string GetTypeName() {
|
||||
#if GTEST_HAS_RTTI
|
||||
return internal::GetTypeName<T>();
|
||||
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
|
||||
return internal::GetTypeName<T>());
|
||||
#endif
|
||||
return "the element type";
|
||||
}
|
||||
|
@ -5060,15 +5165,32 @@ std::string DescribeMatcher(const M& matcher, bool negation = false) {
|
|||
// Define variadic matcher versions. They are overloaded in
|
||||
// gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
|
||||
template <typename... Args>
|
||||
inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
|
||||
internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
|
||||
return internal::AllOfMatcher<Args...>(matchers...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
|
||||
internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
|
||||
return internal::AnyOfMatcher<Args...>(matchers...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
internal::ElementsAreMatcher<tuple<typename std::decay<const Args&>::type...>>
|
||||
ElementsAre(const Args&... matchers) {
|
||||
return internal::ElementsAreMatcher<
|
||||
tuple<typename std::decay<const Args&>::type...>>(
|
||||
make_tuple(matchers...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
internal::UnorderedElementsAreMatcher<
|
||||
tuple<typename std::decay<const Args&>::type...>>
|
||||
UnorderedElementsAre(const Args&... matchers) {
|
||||
return internal::UnorderedElementsAreMatcher<
|
||||
tuple<typename std::decay<const Args&>::type...>>(
|
||||
make_tuple(matchers...));
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
// AllArgs(m) is a synonym of m. This is useful in
|
||||
|
|
|
@ -43,6 +43,18 @@
|
|||
|
||||
namespace testing {
|
||||
|
||||
// Silence C4100 (unreferenced formal
|
||||
// parameter) for MSVC
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#if (_MSC_VER == 1900)
|
||||
// and silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 14
|
||||
# pragma warning(disable:4800)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Defines a matcher that matches an empty container. The container must
|
||||
// support both size() and empty(), which all STL-like containers provide.
|
||||
MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
|
||||
|
@ -69,6 +81,11 @@ MATCHER(IsFalse, negation ? "is true" : "is false") {
|
|||
return !static_cast<bool>(arg);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#endif // GMOCK_GMOCK_MORE_MATCHERS_H_
|
||||
|
|
|
@ -147,14 +147,13 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||
// action fails.
|
||||
// L = *
|
||||
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
|
||||
const void* untyped_args, const std::string& call_description) const = 0;
|
||||
void* untyped_args, const std::string& call_description) const = 0;
|
||||
|
||||
// Performs the given action with the given arguments and returns
|
||||
// the action's result.
|
||||
// L = *
|
||||
virtual UntypedActionResultHolderBase* UntypedPerformAction(
|
||||
const void* untyped_action,
|
||||
const void* untyped_args) const = 0;
|
||||
const void* untyped_action, void* untyped_args) const = 0;
|
||||
|
||||
// Writes a message that the call is uninteresting (i.e. neither
|
||||
// explicitly expected nor explicitly unexpected) to the given
|
||||
|
@ -209,9 +208,8 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||
// arguments. This function can be safely called from multiple
|
||||
// threads concurrently. The caller is responsible for deleting the
|
||||
// result.
|
||||
UntypedActionResultHolderBase* UntypedInvokeWith(
|
||||
const void* untyped_args)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||
UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||
|
||||
protected:
|
||||
typedef std::vector<const void*> UntypedOnCallSpecs;
|
||||
|
@ -236,6 +234,14 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||
UntypedOnCallSpecs untyped_on_call_specs_;
|
||||
|
||||
// All expectations for this function mocker.
|
||||
//
|
||||
// It's undefined behavior to interleave expectations (EXPECT_CALLs
|
||||
// or ON_CALLs) and mock function calls. Also, the order of
|
||||
// expectations is important. Therefore it's a logic race condition
|
||||
// to read/write untyped_expectations_ concurrently. In order for
|
||||
// tools like tsan to catch concurrent read/write accesses to
|
||||
// untyped_expectations, we deliberately leave accesses to it
|
||||
// unprotected.
|
||||
UntypedExpectations untyped_expectations_;
|
||||
}; // class UntypedFunctionMockerBase
|
||||
|
||||
|
@ -1252,8 +1258,9 @@ class MockSpec {
|
|||
|
||||
// Constructs a MockSpec object, given the function mocker object
|
||||
// that the spec is associated with.
|
||||
explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
|
||||
: function_mocker_(function_mocker) {}
|
||||
MockSpec(internal::FunctionMockerBase<F>* function_mocker,
|
||||
const ArgumentMatcherTuple& matchers)
|
||||
: function_mocker_(function_mocker), matchers_(matchers) {}
|
||||
|
||||
// Adds a new default action spec to the function mocker and returns
|
||||
// the newly created spec.
|
||||
|
@ -1275,14 +1282,17 @@ class MockSpec {
|
|||
file, line, source_text, matchers_);
|
||||
}
|
||||
|
||||
// This operator overload is used to swallow the superfluous parameter list
|
||||
// introduced by the ON/EXPECT_CALL macros. See the macro comments for more
|
||||
// explanation.
|
||||
MockSpec<F>& operator()(const internal::WithoutMatchers&, void* const) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Function>
|
||||
friend class internal::FunctionMocker;
|
||||
|
||||
void SetMatchers(const ArgumentMatcherTuple& matchers) {
|
||||
matchers_ = matchers;
|
||||
}
|
||||
|
||||
// The function mocker that owns this spec.
|
||||
internal::FunctionMockerBase<F>* const function_mocker_;
|
||||
// The argument matchers specified in the spec.
|
||||
|
@ -1390,19 +1400,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
|
|||
template <typename F>
|
||||
static ActionResultHolder* PerformDefaultAction(
|
||||
const FunctionMockerBase<F>* func_mocker,
|
||||
const typename Function<F>::ArgumentTuple& args,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
|
||||
const std::string& call_description) {
|
||||
return new ActionResultHolder(Wrapper(
|
||||
func_mocker->PerformDefaultAction(args, call_description)));
|
||||
return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
|
||||
internal::move(args), call_description)));
|
||||
}
|
||||
|
||||
// Performs the given action and returns the result in a new-ed
|
||||
// ActionResultHolder.
|
||||
template <typename F>
|
||||
static ActionResultHolder*
|
||||
PerformAction(const Action<F>& action,
|
||||
const typename Function<F>::ArgumentTuple& args) {
|
||||
return new ActionResultHolder(Wrapper(action.Perform(args)));
|
||||
static ActionResultHolder* PerformAction(
|
||||
const Action<F>& action,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
|
||||
return new ActionResultHolder(
|
||||
Wrapper(action.Perform(internal::move(args))));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -1430,9 +1441,9 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
|
|||
template <typename F>
|
||||
static ActionResultHolder* PerformDefaultAction(
|
||||
const FunctionMockerBase<F>* func_mocker,
|
||||
const typename Function<F>::ArgumentTuple& args,
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
|
||||
const std::string& call_description) {
|
||||
func_mocker->PerformDefaultAction(args, call_description);
|
||||
func_mocker->PerformDefaultAction(internal::move(args), call_description);
|
||||
return new ActionResultHolder;
|
||||
}
|
||||
|
||||
|
@ -1441,8 +1452,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
|
|||
template <typename F>
|
||||
static ActionResultHolder* PerformAction(
|
||||
const Action<F>& action,
|
||||
const typename Function<F>::ArgumentTuple& args) {
|
||||
action.Perform(args);
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
|
||||
action.Perform(internal::move(args));
|
||||
return new ActionResultHolder;
|
||||
}
|
||||
|
||||
|
@ -1461,7 +1472,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
|
||||
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
|
||||
|
||||
FunctionMockerBase() : current_spec_(this) {}
|
||||
FunctionMockerBase() {}
|
||||
|
||||
// The destructor verifies that all expectations on this mock
|
||||
// function have been satisfied. If not, it will report Google Test
|
||||
|
@ -1497,12 +1508,13 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
// mutable state of this object, and thus can be called concurrently
|
||||
// without locking.
|
||||
// L = *
|
||||
Result PerformDefaultAction(const ArgumentTuple& args,
|
||||
const std::string& call_description) const {
|
||||
Result PerformDefaultAction(
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
|
||||
const std::string& call_description) const {
|
||||
const OnCallSpec<F>* const spec =
|
||||
this->FindOnCallSpec(args);
|
||||
if (spec != NULL) {
|
||||
return spec->GetAction().Perform(args);
|
||||
return spec->GetAction().Perform(internal::move(args));
|
||||
}
|
||||
const std::string message =
|
||||
call_description +
|
||||
|
@ -1524,11 +1536,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
// action fails. The caller is responsible for deleting the result.
|
||||
// L = *
|
||||
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
|
||||
const void* untyped_args, // must point to an ArgumentTuple
|
||||
void* untyped_args, // must point to an ArgumentTuple
|
||||
const std::string& call_description) const {
|
||||
const ArgumentTuple& args =
|
||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||
return ResultHolder::PerformDefaultAction(this, args, call_description);
|
||||
ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
|
||||
return ResultHolder::PerformDefaultAction(this, internal::move(*args),
|
||||
call_description);
|
||||
}
|
||||
|
||||
// Performs the given action with the given arguments and returns
|
||||
|
@ -1536,13 +1548,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
// result.
|
||||
// L = *
|
||||
virtual UntypedActionResultHolderBase* UntypedPerformAction(
|
||||
const void* untyped_action, const void* untyped_args) const {
|
||||
const void* untyped_action, void* untyped_args) const {
|
||||
// Make a copy of the action before performing it, in case the
|
||||
// action deletes the mock object (and thus deletes itself).
|
||||
const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
|
||||
const ArgumentTuple& args =
|
||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||
return ResultHolder::PerformAction(action, args);
|
||||
ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
|
||||
return ResultHolder::PerformAction(action, internal::move(*args));
|
||||
}
|
||||
|
||||
// Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
|
||||
|
@ -1582,10 +1593,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
// Returns the result of invoking this mock function with the given
|
||||
// arguments. This function can be safely called from multiple
|
||||
// threads concurrently.
|
||||
Result InvokeWith(const ArgumentTuple& args)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
Result InvokeWith(
|
||||
typename RvalueRef<typename Function<F>::ArgumentTuple>::type args)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
// const_cast is required since in C++98 we still pass ArgumentTuple around
|
||||
// by const& instead of rvalue reference.
|
||||
void* untyped_args = const_cast<void*>(static_cast<const void*>(&args));
|
||||
scoped_ptr<ResultHolder> holder(
|
||||
DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args)));
|
||||
DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args)));
|
||||
return holder->Unwrap();
|
||||
}
|
||||
|
||||
|
@ -1609,6 +1624,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
TypedExpectation<F>* const expectation =
|
||||
new TypedExpectation<F>(this, file, line, source_text, m);
|
||||
const linked_ptr<ExpectationBase> untyped_expectation(expectation);
|
||||
// See the definition of untyped_expectations_ for why access to
|
||||
// it is unprotected here.
|
||||
untyped_expectations_.push_back(untyped_expectation);
|
||||
|
||||
// Adds this expectation into the implicit sequence if there is one.
|
||||
|
@ -1620,10 +1637,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
return *expectation;
|
||||
}
|
||||
|
||||
// The current spec (either default action spec or expectation spec)
|
||||
// being described on this function mocker.
|
||||
MockSpec<F>& current_spec() { return current_spec_; }
|
||||
|
||||
private:
|
||||
template <typename Func> friend class TypedExpectation;
|
||||
|
||||
|
@ -1716,6 +1729,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
const ArgumentTuple& args) const
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
// See the definition of untyped_expectations_ for why access to
|
||||
// it is unprotected here.
|
||||
for (typename UntypedExpectations::const_reverse_iterator it =
|
||||
untyped_expectations_.rbegin();
|
||||
it != untyped_expectations_.rend(); ++it) {
|
||||
|
@ -1766,10 +1781,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||
}
|
||||
}
|
||||
|
||||
// The current spec (either default action spec or expectation spec)
|
||||
// being described on this function mocker.
|
||||
MockSpec<F> current_spec_;
|
||||
|
||||
// There is no generally useful and implementable semantics of
|
||||
// copying a mock object, so copying a mock is usually a user error.
|
||||
// Thus we disallow copying function mockers. If the user really
|
||||
|
@ -1832,17 +1843,76 @@ inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
|
|||
|
||||
} // namespace testing
|
||||
|
||||
// A separate macro is required to avoid compile errors when the name
|
||||
// of the method used in call is a result of macro expansion.
|
||||
// See CompilesWithMethodNameExpandedFromMacro tests in
|
||||
// internal/gmock-spec-builders_test.cc for more details.
|
||||
#define GMOCK_ON_CALL_IMPL_(obj, call) \
|
||||
((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \
|
||||
#obj, #call)
|
||||
#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call)
|
||||
// Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is
|
||||
// required to avoid compile errors when the name of the method used in call is
|
||||
// a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro
|
||||
// tests in internal/gmock-spec-builders_test.cc for more details.
|
||||
//
|
||||
// This macro supports statements both with and without parameter matchers. If
|
||||
// the parameter list is omitted, gMock will accept any parameters, which allows
|
||||
// tests to be written that don't need to encode the number of method
|
||||
// parameter. This technique may only be used for non-overloaded methods.
|
||||
//
|
||||
// // These are the same:
|
||||
// ON_CALL(mock, NoArgsMethod()).WillByDefault(…);
|
||||
// ON_CALL(mock, NoArgsMethod).WillByDefault(…);
|
||||
//
|
||||
// // As are these:
|
||||
// ON_CALL(mock, TwoArgsMethod(_, _)).WillByDefault(…);
|
||||
// ON_CALL(mock, TwoArgsMethod).WillByDefault(…);
|
||||
//
|
||||
// // Can also specify args if you want, of course:
|
||||
// ON_CALL(mock, TwoArgsMethod(_, 45)).WillByDefault(…);
|
||||
//
|
||||
// // Overloads work as long as you specify parameters:
|
||||
// ON_CALL(mock, OverloadedMethod(_)).WillByDefault(…);
|
||||
// ON_CALL(mock, OverloadedMethod(_, _)).WillByDefault(…);
|
||||
//
|
||||
// // Oops! Which overload did you want?
|
||||
// ON_CALL(mock, OverloadedMethod).WillByDefault(…);
|
||||
// => ERROR: call to member function 'gmock_OverloadedMethod' is ambiguous
|
||||
//
|
||||
// How this works: The mock class uses two overloads of the gmock_Method
|
||||
// expectation setter method plus an operator() overload on the MockSpec object.
|
||||
// In the matcher list form, the macro expands to:
|
||||
//
|
||||
// // This statement:
|
||||
// ON_CALL(mock, TwoArgsMethod(_, 45))…
|
||||
//
|
||||
// // …expands to:
|
||||
// mock.gmock_TwoArgsMethod(_, 45)(WithoutMatchers(), nullptr)…
|
||||
// |-------------v---------------||------------v-------------|
|
||||
// invokes first overload swallowed by operator()
|
||||
//
|
||||
// // …which is essentially:
|
||||
// mock.gmock_TwoArgsMethod(_, 45)…
|
||||
//
|
||||
// Whereas the form without a matcher list:
|
||||
//
|
||||
// // This statement:
|
||||
// ON_CALL(mock, TwoArgsMethod)…
|
||||
//
|
||||
// // …expands to:
|
||||
// mock.gmock_TwoArgsMethod(WithoutMatchers(), nullptr)…
|
||||
// |-----------------------v--------------------------|
|
||||
// invokes second overload
|
||||
//
|
||||
// // …which is essentially:
|
||||
// mock.gmock_TwoArgsMethod(_, _)…
|
||||
//
|
||||
// The WithoutMatchers() argument is used to disambiguate overloads and to
|
||||
// block the caller from accidentally invoking the second overload directly. The
|
||||
// second argument is an internal type derived from the method signature. The
|
||||
// failure to disambiguate two overloads of this method in the ON_CALL statement
|
||||
// is how we block callers from setting expectations on overloaded methods.
|
||||
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
|
||||
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), NULL) \
|
||||
.Setter(__FILE__, __LINE__, #mock_expr, #call)
|
||||
|
||||
#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \
|
||||
((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
|
||||
#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
|
||||
#define ON_CALL(obj, call) \
|
||||
GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
|
||||
|
||||
#define EXPECT_CALL(obj, call) \
|
||||
GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
|
||||
|
||||
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
$$ -*- mode: c++; -*-
|
||||
$$ This is a Pump source file (http://go/pump). Please use Pump to convert
|
||||
$$ This is a Pump source file. Please use Pump to convert
|
||||
$$ it to callback-actions.h.
|
||||
$$
|
||||
$var max_callback_arity = 5
|
||||
|
|
|
@ -48,6 +48,14 @@
|
|||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
// Silence MSVC C4100 (unreferenced formal parameter) and
|
||||
// C4805('==': unsafe mix of type 'const int' and type 'const bool')
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
# pragma warning(disable:4805)
|
||||
#endif
|
||||
|
||||
// Joins a vector of strings as if they are fields of a tuple; returns
|
||||
// the joined string.
|
||||
GTEST_API_ std::string JoinAsTuple(const Strings& fields);
|
||||
|
@ -336,6 +344,21 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity);
|
|||
GTEST_API_ void Log(LogSeverity severity, const std::string& message,
|
||||
int stack_frames_to_skip);
|
||||
|
||||
// A marker class that is used to resolve parameterless expectations to the
|
||||
// correct overload. This must not be instantiable, to prevent client code from
|
||||
// accidentally resolving to the overload; for example:
|
||||
//
|
||||
// ON_CALL(mock, Method({}, nullptr))…
|
||||
//
|
||||
class WithoutMatchers {
|
||||
private:
|
||||
WithoutMatchers() {}
|
||||
friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
||||
};
|
||||
|
||||
// Internal use only: access the singleton instance of WithoutMatchers.
|
||||
GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
||||
|
||||
// TODO(wan@google.com): group all type utilities together.
|
||||
|
||||
// Type traits.
|
||||
|
@ -510,7 +533,7 @@ struct BooleanConstant {};
|
|||
|
||||
// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
|
||||
// reduce code size.
|
||||
void IllegalDoDefault(const char* file, int line);
|
||||
GTEST_API_ void IllegalDoDefault(const char* file, int line);
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Helper types for Apply() below.
|
||||
|
@ -539,6 +562,12 @@ auto Apply(F&& f, Tuple&& args)
|
|||
make_int_pack<std::tuple_size<Tuple>::value>());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
|
|
|
@ -188,7 +188,9 @@ GTEST_API_ void Log(LogSeverity severity, const std::string& message,
|
|||
std::cout << ::std::flush;
|
||||
}
|
||||
|
||||
void IllegalDoDefault(const char* file, int line) {
|
||||
GTEST_API_ WithoutMatchers GetWithoutMatchers() { return WithoutMatchers(); }
|
||||
|
||||
GTEST_API_ void IllegalDoDefault(const char* file, int line) {
|
||||
internal::Assert(
|
||||
false, file, line,
|
||||
"You are using DoDefault() inside a composite action like "
|
||||
|
|
|
@ -105,6 +105,53 @@ Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); }
|
|||
Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const std::string& s) {
|
||||
*this = Eq(s);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a const absl::string_view& whose value is
|
||||
// equal to s.
|
||||
Matcher<const absl::string_view&>::Matcher(absl::string_view s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const std::string& s) { *this = Eq(s); }
|
||||
|
||||
#if GTEST_HAS_GLOBAL_STRING
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const ::string& s) { *this = Eq(s); }
|
||||
#endif // GTEST_HAS_GLOBAL_STRING
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(const char* s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
|
||||
// Constructs a matcher that matches a absl::string_view whose value is equal to
|
||||
// s.
|
||||
Matcher<absl::string_view>::Matcher(absl::string_view s) {
|
||||
*this = Eq(std::string(s));
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
|
||||
namespace internal {
|
||||
|
||||
|
@ -113,12 +160,11 @@ namespace internal {
|
|||
// 'negation' is false; otherwise returns the description of the
|
||||
// negation of the matcher. 'param_values' contains a list of strings
|
||||
// that are the print-out of the matcher's parameters.
|
||||
GTEST_API_ string FormatMatcherDescription(bool negation,
|
||||
const char* matcher_name,
|
||||
const Strings& param_values) {
|
||||
string result = ConvertIdentifierNameToWords(matcher_name);
|
||||
if (param_values.size() >= 1)
|
||||
result += " " + JoinAsTuple(param_values);
|
||||
GTEST_API_ std::string FormatMatcherDescription(bool negation,
|
||||
const char* matcher_name,
|
||||
const Strings& param_values) {
|
||||
std::string result = ConvertIdentifierNameToWords(matcher_name);
|
||||
if (param_values.size() >= 1) result += " " + JoinAsTuple(param_values);
|
||||
return negation ? "not (" + result + ")" : result;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
@ -48,6 +49,15 @@
|
|||
# include <unistd.h> // NOLINT
|
||||
#endif
|
||||
|
||||
// Silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 14,15
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1900
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4800)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace testing {
|
||||
namespace internal {
|
||||
|
||||
|
@ -99,12 +109,19 @@ void ExpectationBase::RetireAllPreRequisites()
|
|||
return;
|
||||
}
|
||||
|
||||
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
||||
it != immediate_prerequisites_.end(); ++it) {
|
||||
ExpectationBase* const prerequisite = it->expectation_base().get();
|
||||
if (!prerequisite->is_retired()) {
|
||||
prerequisite->RetireAllPreRequisites();
|
||||
prerequisite->Retire();
|
||||
::std::vector<ExpectationBase*> expectations(1, this);
|
||||
while (!expectations.empty()) {
|
||||
ExpectationBase* exp = expectations.back();
|
||||
expectations.pop_back();
|
||||
|
||||
for (ExpectationSet::const_iterator it =
|
||||
exp->immediate_prerequisites_.begin();
|
||||
it != exp->immediate_prerequisites_.end(); ++it) {
|
||||
ExpectationBase* next = it->expectation_base().get();
|
||||
if (!next->is_retired()) {
|
||||
next->Retire();
|
||||
expectations.push_back(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,11 +131,18 @@ void ExpectationBase::RetireAllPreRequisites()
|
|||
bool ExpectationBase::AllPrerequisitesAreSatisfied() const
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
||||
it != immediate_prerequisites_.end(); ++it) {
|
||||
if (!(it->expectation_base()->IsSatisfied()) ||
|
||||
!(it->expectation_base()->AllPrerequisitesAreSatisfied()))
|
||||
return false;
|
||||
::std::vector<const ExpectationBase*> expectations(1, this);
|
||||
while (!expectations.empty()) {
|
||||
const ExpectationBase* exp = expectations.back();
|
||||
expectations.pop_back();
|
||||
|
||||
for (ExpectationSet::const_iterator it =
|
||||
exp->immediate_prerequisites_.begin();
|
||||
it != exp->immediate_prerequisites_.end(); ++it) {
|
||||
const ExpectationBase* next = it->expectation_base().get();
|
||||
if (!next->IsSatisfied()) return false;
|
||||
expectations.push_back(next);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -127,19 +151,28 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const
|
|||
void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const
|
||||
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||
g_gmock_mutex.AssertHeld();
|
||||
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
||||
it != immediate_prerequisites_.end(); ++it) {
|
||||
if (it->expectation_base()->IsSatisfied()) {
|
||||
// If *it is satisfied and has a call count of 0, some of its
|
||||
// pre-requisites may not be satisfied yet.
|
||||
if (it->expectation_base()->call_count_ == 0) {
|
||||
it->expectation_base()->FindUnsatisfiedPrerequisites(result);
|
||||
::std::vector<const ExpectationBase*> expectations(1, this);
|
||||
while (!expectations.empty()) {
|
||||
const ExpectationBase* exp = expectations.back();
|
||||
expectations.pop_back();
|
||||
|
||||
for (ExpectationSet::const_iterator it =
|
||||
exp->immediate_prerequisites_.begin();
|
||||
it != exp->immediate_prerequisites_.end(); ++it) {
|
||||
const ExpectationBase* next = it->expectation_base().get();
|
||||
|
||||
if (next->IsSatisfied()) {
|
||||
// If *it is satisfied and has a call count of 0, some of its
|
||||
// pre-requisites may not be satisfied yet.
|
||||
if (next->call_count_ == 0) {
|
||||
expectations.push_back(next);
|
||||
}
|
||||
} else {
|
||||
// Now that we know next is unsatisfied, we are not so interested
|
||||
// in whether its pre-requisites are satisfied. Therefore we
|
||||
// don't iterate into it here.
|
||||
*result += *it;
|
||||
}
|
||||
} else {
|
||||
// Now that we know *it is unsatisfied, we are not so interested
|
||||
// in whether its pre-requisites are satisfied. Therefore we
|
||||
// don't recursively call FindUnsatisfiedPrerequisites() here.
|
||||
*result += *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,11 +287,13 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
|
|||
case kWarn:
|
||||
Log(kWarning,
|
||||
msg +
|
||||
"\nNOTE: You can safely ignore the above warning unless this "
|
||||
"call should not happen. Do not suppress it by blindly adding "
|
||||
"an EXPECT_CALL() if you don't mean to enforce the call. "
|
||||
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#"
|
||||
"knowing-when-to-expect for details.\n",
|
||||
"\nNOTE: You can safely ignore the above warning unless this "
|
||||
"call should not happen. Do not suppress it by blindly adding "
|
||||
"an EXPECT_CALL() if you don't mean to enforce the call. "
|
||||
"See "
|
||||
"https://github.com/google/googletest/blob/master/googlemock/"
|
||||
"docs/CookBook.md#"
|
||||
"knowing-when-to-expect for details.\n",
|
||||
stack_frames_to_skip);
|
||||
break;
|
||||
default: // FAIL
|
||||
|
@ -334,9 +369,10 @@ const char* UntypedFunctionMockerBase::Name() const
|
|||
// Calculates the result of invoking this mock function with the given
|
||||
// arguments, prints it, and returns it. The caller is responsible
|
||||
// for deleting the result.
|
||||
UntypedActionResultHolderBase*
|
||||
UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
|
||||
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
|
||||
void* const untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||
// See the definition of untyped_expectations_ for why access to it
|
||||
// is unprotected here.
|
||||
if (untyped_expectations_.size() == 0) {
|
||||
// No expectation is set on this mock method - we have an
|
||||
// uninteresting call.
|
||||
|
@ -355,16 +391,19 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
|
|||
// If the user allows this uninteresting call, we print it
|
||||
// only when they want informational messages.
|
||||
reaction == kAllow ? LogIsVisible(kInfo) :
|
||||
// If the user wants this to be a warning, we print it only
|
||||
// when they want to see warnings.
|
||||
reaction == kWarn ? LogIsVisible(kWarning) :
|
||||
// Otherwise, the user wants this to be an error, and we
|
||||
// should always print detailed information in the error.
|
||||
true;
|
||||
// If the user wants this to be a warning, we print
|
||||
// it only when they want to see warnings.
|
||||
reaction == kWarn
|
||||
? LogIsVisible(kWarning)
|
||||
:
|
||||
// Otherwise, the user wants this to be an error, and we
|
||||
// should always print detailed information in the error.
|
||||
true;
|
||||
|
||||
if (!need_to_report_uninteresting_call) {
|
||||
// Perform the action without printing the call information.
|
||||
return this->UntypedPerformDefaultAction(untyped_args, "Function call: " + std::string(Name()));
|
||||
return this->UntypedPerformDefaultAction(
|
||||
untyped_args, "Function call: " + std::string(Name()));
|
||||
}
|
||||
|
||||
// Warns about the uninteresting call.
|
||||
|
@ -446,6 +485,8 @@ UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
|
|||
// Returns an Expectation object that references and co-owns exp,
|
||||
// which must be an expectation on this mock function.
|
||||
Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) {
|
||||
// See the definition of untyped_expectations_ for why access to it
|
||||
// is unprotected here.
|
||||
for (UntypedExpectations::const_iterator it =
|
||||
untyped_expectations_.begin();
|
||||
it != untyped_expectations_.end(); ++it) {
|
||||
|
@ -508,7 +549,7 @@ bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
|
|||
return expectations_met;
|
||||
}
|
||||
|
||||
static CallReaction intToCallReaction(int mock_behavior) {
|
||||
CallReaction intToCallReaction(int mock_behavior) {
|
||||
if (mock_behavior >= kAllow && mock_behavior <= kFail) {
|
||||
return static_cast<internal::CallReaction>(mock_behavior);
|
||||
}
|
||||
|
@ -582,9 +623,15 @@ class MockObjectRegistry {
|
|||
leaked_count++;
|
||||
}
|
||||
if (leaked_count > 0) {
|
||||
std::cout << "\nERROR: " << leaked_count
|
||||
<< " leaked mock " << (leaked_count == 1 ? "object" : "objects")
|
||||
<< " found at program exit.\n";
|
||||
std::cout << "\nERROR: " << leaked_count << " leaked mock "
|
||||
<< (leaked_count == 1 ? "object" : "objects")
|
||||
<< " found at program exit. Expectations on a mock object is "
|
||||
"verified when the object is destructed. Leaking a mock "
|
||||
"means that its expectations aren't verified, which is "
|
||||
"usually a test bug. If you really intend to leak a mock, "
|
||||
"you can suppress this error using "
|
||||
"testing::Mock::AllowLeak(mock_object), or you may use a "
|
||||
"fake or stub instead of a mock.\n";
|
||||
std::cout.flush();
|
||||
::std::cerr.flush();
|
||||
// RUN_ALL_TESTS() has already returned when this destructor is
|
||||
|
@ -828,3 +875,9 @@ InSequence::~InSequence() {
|
|||
}
|
||||
|
||||
} // namespace testing
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1900
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -33,6 +33,15 @@
|
|||
//
|
||||
// This file tests the built-in actions.
|
||||
|
||||
// Silence C4800 (C4800: 'int *const ': forcing value
|
||||
// to bool 'true' or 'false') for MSVC 14,15
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1900
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4800)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "gmock/gmock-actions.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
@ -65,6 +74,7 @@ using testing::ReturnRef;
|
|||
using testing::ReturnRefOfCopy;
|
||||
using testing::SetArgPointee;
|
||||
using testing::SetArgumentPointee;
|
||||
using testing::Unused;
|
||||
using testing::_;
|
||||
using testing::get;
|
||||
using testing::internal::BuiltInDefaultValue;
|
||||
|
@ -704,6 +714,9 @@ class MockClass {
|
|||
MOCK_METHOD0(MakeUnique, std::unique_ptr<int>());
|
||||
MOCK_METHOD0(MakeUniqueBase, std::unique_ptr<Base>());
|
||||
MOCK_METHOD0(MakeVectorUnique, std::vector<std::unique_ptr<int>>());
|
||||
MOCK_METHOD1(TakeUnique, int(std::unique_ptr<int>));
|
||||
MOCK_METHOD2(TakeUnique,
|
||||
int(const std::unique_ptr<int>&, std::unique_ptr<int>));
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -755,7 +768,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) {
|
|||
}
|
||||
|
||||
// Tests that DoDefault() returns the default value set by
|
||||
// DefaultValue<T>::Set() when it's not overridden by an ON_CALL().
|
||||
// DefaultValue<T>::Set() when it's not overriden by an ON_CALL().
|
||||
TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) {
|
||||
DefaultValue<int>::Set(1);
|
||||
MockClass mock;
|
||||
|
@ -1410,6 +1423,153 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) {
|
|||
EXPECT_EQ(7, *vresult[0]);
|
||||
}
|
||||
|
||||
TEST(MockMethodTest, CanTakeMoveOnlyValue) {
|
||||
MockClass mock;
|
||||
auto make = [](int i) { return std::unique_ptr<int>(new int(i)); };
|
||||
|
||||
EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr<int> i) {
|
||||
return *i;
|
||||
});
|
||||
// DoAll() does not compile, since it would move from its arguments twice.
|
||||
// EXPECT_CALL(mock, TakeUnique(_, _))
|
||||
// .WillRepeatedly(DoAll(Invoke([](std::unique_ptr<int> j) {}),
|
||||
// Return(1)));
|
||||
EXPECT_CALL(mock, TakeUnique(testing::Pointee(7)))
|
||||
.WillOnce(Return(-7))
|
||||
.RetiresOnSaturation();
|
||||
EXPECT_CALL(mock, TakeUnique(testing::IsNull()))
|
||||
.WillOnce(Return(-1))
|
||||
.RetiresOnSaturation();
|
||||
|
||||
EXPECT_EQ(5, mock.TakeUnique(make(5)));
|
||||
EXPECT_EQ(-7, mock.TakeUnique(make(7)));
|
||||
EXPECT_EQ(7, mock.TakeUnique(make(7)));
|
||||
EXPECT_EQ(7, mock.TakeUnique(make(7)));
|
||||
EXPECT_EQ(-1, mock.TakeUnique({}));
|
||||
|
||||
// Some arguments are moved, some passed by reference.
|
||||
auto lvalue = make(6);
|
||||
EXPECT_CALL(mock, TakeUnique(_, _))
|
||||
.WillOnce([](const std::unique_ptr<int>& i, std::unique_ptr<int> j) {
|
||||
return *i * *j;
|
||||
});
|
||||
EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7)));
|
||||
|
||||
// The unique_ptr can be saved by the action.
|
||||
std::unique_ptr<int> saved;
|
||||
EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr<int> i) {
|
||||
saved = std::move(i);
|
||||
return 0;
|
||||
});
|
||||
EXPECT_EQ(0, mock.TakeUnique(make(42)));
|
||||
EXPECT_EQ(42, *saved);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
// Tests for std::function based action.
|
||||
|
||||
int Add(int val, int& ref, int* ptr) { // NOLINT
|
||||
int result = val + ref + *ptr;
|
||||
ref = 42;
|
||||
*ptr = 43;
|
||||
return result;
|
||||
}
|
||||
|
||||
int Deref(std::unique_ptr<int> ptr) { return *ptr; }
|
||||
|
||||
struct Double {
|
||||
template <typename T>
|
||||
T operator()(T t) { return 2 * t; }
|
||||
};
|
||||
|
||||
std::unique_ptr<int> UniqueInt(int i) {
|
||||
return std::unique_ptr<int>(new int(i));
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, ActionFromFunction) {
|
||||
Action<int(int, int&, int*)> a = &Add;
|
||||
int x = 1, y = 2, z = 3;
|
||||
EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z)));
|
||||
EXPECT_EQ(42, y);
|
||||
EXPECT_EQ(43, z);
|
||||
|
||||
Action<int(std::unique_ptr<int>)> a1 = &Deref;
|
||||
EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7))));
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, ActionFromLambda) {
|
||||
Action<int(bool, int)> a1 = [](bool b, int i) { return b ? i : 0; };
|
||||
EXPECT_EQ(5, a1.Perform(make_tuple(true, 5)));
|
||||
EXPECT_EQ(0, a1.Perform(make_tuple(false, 5)));
|
||||
|
||||
std::unique_ptr<int> saved;
|
||||
Action<void(std::unique_ptr<int>)> a2 = [&saved](std::unique_ptr<int> p) {
|
||||
saved = std::move(p);
|
||||
};
|
||||
a2.Perform(make_tuple(UniqueInt(5)));
|
||||
EXPECT_EQ(5, *saved);
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, PolymorphicFunctor) {
|
||||
Action<int(int)> ai = Double();
|
||||
EXPECT_EQ(2, ai.Perform(make_tuple(1)));
|
||||
Action<double(double)> ad = Double(); // Double? Double double!
|
||||
EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5)));
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, TypeConversion) {
|
||||
// Numeric promotions are allowed.
|
||||
const Action<bool(int)> a1 = [](int i) { return i > 1; };
|
||||
const Action<int(bool)> a2 = Action<int(bool)>(a1);
|
||||
EXPECT_EQ(1, a1.Perform(make_tuple(42)));
|
||||
EXPECT_EQ(0, a2.Perform(make_tuple(42)));
|
||||
|
||||
// Implicit constructors are allowed.
|
||||
const Action<bool(std::string)> s1 = [](std::string s) { return !s.empty(); };
|
||||
const Action<int(const char*)> s2 = Action<int(const char*)>(s1);
|
||||
EXPECT_EQ(0, s2.Perform(make_tuple("")));
|
||||
EXPECT_EQ(1, s2.Perform(make_tuple("hello")));
|
||||
|
||||
// Also between the lambda and the action itself.
|
||||
const Action<bool(std::string)> x = [](Unused) { return 42; };
|
||||
EXPECT_TRUE(x.Perform(make_tuple("hello")));
|
||||
}
|
||||
|
||||
TEST(FunctorActionTest, UnusedArguments) {
|
||||
// Verify that users can ignore uninteresting arguments.
|
||||
Action<int(int, double y, double z)> a =
|
||||
[](int i, Unused, Unused) { return 2 * i; };
|
||||
tuple<int, double, double> dummy = make_tuple(3, 7.3, 9.44);
|
||||
EXPECT_EQ(6, a.Perform(dummy));
|
||||
}
|
||||
|
||||
// Test that basic built-in actions work with move-only arguments.
|
||||
// TODO(rburny): Currently, almost all ActionInterface-based actions will not
|
||||
// work, even if they only try to use other, copyable arguments. Implement them
|
||||
// if necessary (but note that DoAll cannot work on non-copyable types anyway -
|
||||
// so maybe it's better to make users use lambdas instead.
|
||||
TEST(MoveOnlyArgumentsTest, ReturningActions) {
|
||||
Action<int(std::unique_ptr<int>)> a = Return(1);
|
||||
EXPECT_EQ(1, a.Perform(make_tuple(nullptr)));
|
||||
|
||||
a = testing::WithoutArgs([]() { return 7; });
|
||||
EXPECT_EQ(7, a.Perform(make_tuple(nullptr)));
|
||||
|
||||
Action<void(std::unique_ptr<int>, int*)> a2 = testing::SetArgPointee<1>(3);
|
||||
int x = 0;
|
||||
a2.Perform(make_tuple(nullptr, &x));
|
||||
EXPECT_EQ(x, 3);
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11
|
||||
|
||||
} // Unnamed namespace
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER == 1900
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -374,10 +374,10 @@ class SubstractAction : public ActionInterface<int(int, int)> { // NOLINT
|
|||
};
|
||||
|
||||
TEST(WithArgsTest, NonInvokeAction) {
|
||||
Action<int(const string&, int, int)> a = // NOLINT
|
||||
Action<int(const std::string&, int, int)> a = // NOLINT
|
||||
WithArgs<2, 1>(MakeAction(new SubstractAction));
|
||||
string s("hello");
|
||||
EXPECT_EQ(8, a.Perform(tuple<const string&, int, int>(s, 2, 10)));
|
||||
tuple<std::string, int, int> dummy = make_tuple(std::string("hi"), 2, 10);
|
||||
EXPECT_EQ(8, a.Perform(dummy));
|
||||
}
|
||||
|
||||
// Tests using WithArgs to pass all original arguments in the original order.
|
||||
|
@ -754,7 +754,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) {
|
|||
TEST(ActionPMacroTest, WorksInCompatibleMockFunction) {
|
||||
Action<std::string(const std::string& s)> a1 = Plus("tail");
|
||||
const std::string re = "re";
|
||||
EXPECT_EQ("retail", a1.Perform(tuple<const std::string&>(re)));
|
||||
tuple<const std::string> dummy = make_tuple(re);
|
||||
EXPECT_EQ("retail", a1.Perform(dummy));
|
||||
}
|
||||
|
||||
// Tests that we can use ACTION*() to define actions overloaded on the
|
||||
|
@ -796,7 +797,8 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) {
|
|||
|
||||
Action<std::string(const std::string& s)> a2 = Plus("tail", "-", ">");
|
||||
const std::string re = "re";
|
||||
EXPECT_EQ("retail->", a2.Perform(tuple<const std::string&>(re)));
|
||||
tuple<const std::string> dummy = make_tuple(re);
|
||||
EXPECT_EQ("retail->", a2.Perform(dummy));
|
||||
}
|
||||
|
||||
ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; }
|
||||
|
@ -1120,7 +1122,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) {
|
|||
EXPECT_FALSE(b); // Verifies that resetter is deleted.
|
||||
}
|
||||
|
||||
// Tests that ACTION_TEMPLATE works for a template with template parameters.
|
||||
// Tests that ACTION_TEMPLATES works for template template parameters.
|
||||
ACTION_TEMPLATE(ReturnSmartPointer,
|
||||
HAS_1_TEMPLATE_PARAMS(template <typename Pointee> class,
|
||||
Pointer),
|
||||
|
|
|
@ -620,5 +620,28 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) {
|
|||
}
|
||||
#endif // GTEST_HAS_STD_FUNCTION_
|
||||
|
||||
struct MockMethodSizes0 {
|
||||
MOCK_METHOD0(func, void());
|
||||
};
|
||||
struct MockMethodSizes1 {
|
||||
MOCK_METHOD1(func, void(int));
|
||||
};
|
||||
struct MockMethodSizes2 {
|
||||
MOCK_METHOD2(func, void(int, int));
|
||||
};
|
||||
struct MockMethodSizes3 {
|
||||
MOCK_METHOD3(func, void(int, int, int));
|
||||
};
|
||||
struct MockMethodSizes4 {
|
||||
MOCK_METHOD4(func, void(int, int, int, int));
|
||||
};
|
||||
|
||||
TEST(MockFunctionTest, MockMethodSizeOverhead) {
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3));
|
||||
EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4));
|
||||
}
|
||||
|
||||
} // namespace gmock_generated_function_mockers_test
|
||||
} // namespace testing
|
||||
|
|
|
@ -63,10 +63,10 @@ TEST(MatcherTupleTest, ForSize2) {
|
|||
}
|
||||
|
||||
TEST(MatcherTupleTest, ForSize5) {
|
||||
CompileAssertTypesEqual<tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
|
||||
Matcher<double>, Matcher<char*> >,
|
||||
MatcherTuple<tuple<int, char, bool, double, char*>
|
||||
>::type>();
|
||||
CompileAssertTypesEqual<
|
||||
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<double>,
|
||||
Matcher<char*> >,
|
||||
MatcherTuple<tuple<int, char, bool, double, char*> >::type>();
|
||||
}
|
||||
|
||||
// Tests the Function template struct.
|
||||
|
@ -97,8 +97,9 @@ TEST(FunctionTest, Binary) {
|
|||
CompileAssertTypesEqual<bool, F::Argument1>();
|
||||
CompileAssertTypesEqual<const long&, F::Argument2>(); // NOLINT
|
||||
CompileAssertTypesEqual<tuple<bool, const long&>, F::ArgumentTuple>(); // NOLINT
|
||||
CompileAssertTypesEqual<tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<
|
||||
tuple<Matcher<bool>, Matcher<const long&> >, // NOLINT
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<void(bool, const long&), F::MakeResultVoid>(); // NOLINT
|
||||
CompileAssertTypesEqual<IgnoredValue(bool, const long&), // NOLINT
|
||||
F::MakeResultIgnoredValue>();
|
||||
|
@ -114,9 +115,10 @@ TEST(FunctionTest, LongArgumentList) {
|
|||
CompileAssertTypesEqual<const long&, F::Argument5>(); // NOLINT
|
||||
CompileAssertTypesEqual<tuple<bool, int, char*, int&, const long&>, // NOLINT
|
||||
F::ArgumentTuple>();
|
||||
CompileAssertTypesEqual<tuple<Matcher<bool>, Matcher<int>, Matcher<char*>,
|
||||
Matcher<int&>, Matcher<const long&> >, // NOLINT
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<
|
||||
tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
|
||||
Matcher<const long&> >, // NOLINT
|
||||
F::ArgumentMatcherTuple>();
|
||||
CompileAssertTypesEqual<void(bool, int, char*, int&, const long&), // NOLINT
|
||||
F::MakeResultVoid>();
|
||||
CompileAssertTypesEqual<
|
||||
|
|
|
@ -31,10 +31,19 @@
|
|||
//
|
||||
// This file tests the built-in matchers generated by a script.
|
||||
|
||||
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
|
||||
// possible loss of data and C4100, unreferenced local parameter
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4244)
|
||||
# pragma warning(disable:4100)
|
||||
#endif
|
||||
|
||||
#include "gmock/gmock-generated-matchers.h"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
@ -57,6 +66,8 @@ using testing::get;
|
|||
using testing::make_tuple;
|
||||
using testing::tuple;
|
||||
using testing::_;
|
||||
using testing::AllOf;
|
||||
using testing::AnyOf;
|
||||
using testing::Args;
|
||||
using testing::Contains;
|
||||
using testing::ElementsAre;
|
||||
|
@ -120,7 +131,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) {
|
|||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsTwoTemplateArgs) {
|
||||
const tuple<short, int, long> t(static_cast<short>(4), 5, 6L); // NOLINT
|
||||
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
|
||||
|
||||
EXPECT_THAT(t, (Args<0, 1>(Lt())));
|
||||
EXPECT_THAT(t, (Args<1, 2>(Lt())));
|
||||
|
@ -128,13 +139,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) {
|
|||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsRepeatedTemplateArgs) {
|
||||
const tuple<short, int, long> t(static_cast<short>(4), 5, 6L); // NOLINT
|
||||
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
|
||||
EXPECT_THAT(t, (Args<0, 0>(Eq())));
|
||||
EXPECT_THAT(t, Not(Args<1, 1>(Ne())));
|
||||
}
|
||||
|
||||
TEST(ArgsTest, AcceptsDecreasingTemplateArgs) {
|
||||
const tuple<short, int, long> t(static_cast<short>(4), 5, 6L); // NOLINT
|
||||
const tuple<short, int, long> t(4, 5, 6L); // NOLINT
|
||||
EXPECT_THAT(t, (Args<2, 0>(Gt())));
|
||||
EXPECT_THAT(t, Not(Args<2, 1>(Lt())));
|
||||
}
|
||||
|
@ -159,7 +170,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) {
|
|||
}
|
||||
|
||||
TEST(ArgsTest, CanBeNested) {
|
||||
const tuple<short, int, long, int> t(static_cast<short>(4), 5, 6L, 6); // NOLINT
|
||||
const tuple<short, int, long, int> t(4, 5, 6L, 6); // NOLINT
|
||||
EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq()))));
|
||||
EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt()))));
|
||||
}
|
||||
|
@ -1283,4 +1294,48 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) {
|
|||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#if GTEST_LANG_CXX11
|
||||
|
||||
TEST(AllOfTest, WorksOnMoveOnlyType) {
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
EXPECT_THAT(p, AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(5))));
|
||||
EXPECT_THAT(p, Not(AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(3)))));
|
||||
}
|
||||
|
||||
TEST(AnyOfTest, WorksOnMoveOnlyType) {
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
EXPECT_THAT(p, AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Lt(5))));
|
||||
EXPECT_THAT(p, Not(AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Gt(5)))));
|
||||
}
|
||||
|
||||
MATCHER(IsNotNull, "") {
|
||||
return arg != nullptr;
|
||||
}
|
||||
|
||||
// Verifies that a matcher defined using MATCHER() can work on
|
||||
// move-only types.
|
||||
TEST(MatcherMacroTest, WorksOnMoveOnlyType) {
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
EXPECT_THAT(p, IsNotNull());
|
||||
EXPECT_THAT(std::unique_ptr<int>(), Not(IsNotNull()));
|
||||
}
|
||||
|
||||
MATCHER_P(UniquePointee, pointee, "") {
|
||||
return *arg == pointee;
|
||||
}
|
||||
|
||||
// Verifies that a matcher defined using MATCHER_P*() can work on
|
||||
// move-only types.
|
||||
TEST(MatcherPMacroTest, WorksOnMoveOnlyType) {
|
||||
std::unique_ptr<int> p(new int(3));
|
||||
EXPECT_THAT(p, UniquePointee(3));
|
||||
EXPECT_THAT(p, Not(UniquePointee(2)));
|
||||
}
|
||||
|
||||
#endif // GTEST_LASNG_CXX11
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -327,11 +327,10 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) {
|
|||
|
||||
// Tests using Invoke() with functions with parameters declared as Unused.
|
||||
TEST(InvokeTest, FunctionWithUnusedParameters) {
|
||||
Action<int(int, int, double, const string&)> a1 =
|
||||
Invoke(SumOfFirst2);
|
||||
string s("hi");
|
||||
EXPECT_EQ(12, a1.Perform(
|
||||
tuple<int, int, double, const string&>(10, 2, 5.6, s)));
|
||||
Action<int(int, int, double, const std::string&)> a1 = Invoke(SumOfFirst2);
|
||||
tuple<int, int, double, std::string> dummy =
|
||||
make_tuple(10, 2, 5.6, std::string("hi"));
|
||||
EXPECT_EQ(12, a1.Perform(dummy));
|
||||
|
||||
Action<int(int, int, bool, int*)> a2 =
|
||||
Invoke(SumOfFirst2);
|
||||
|
@ -380,10 +379,10 @@ TEST(InvokeMethodTest, Unary) {
|
|||
// Tests using Invoke() with a binary method.
|
||||
TEST(InvokeMethodTest, Binary) {
|
||||
Foo foo;
|
||||
Action<string(const string&, char)> a = Invoke(&foo, &Foo::Binary);
|
||||
string s("Hell");
|
||||
EXPECT_EQ("Hello", a.Perform(
|
||||
tuple<const string&, char>(s, 'o')));
|
||||
Action<std::string(const std::string&, char)> a = Invoke(&foo, &Foo::Binary);
|
||||
std::string s("Hell");
|
||||
tuple<std::string, char> dummy = make_tuple(s, 'o');
|
||||
EXPECT_EQ("Hello", a.Perform(dummy));
|
||||
}
|
||||
|
||||
// Tests using Invoke() with a ternary method.
|
||||
|
|
|
@ -32,9 +32,10 @@
|
|||
#include "gmock/gmock-generated-nice-strict.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// This must not be defined inside the ::testing namespace, or it will
|
||||
// clash with ::testing::Mock.
|
||||
|
@ -114,6 +115,24 @@ class MockBar {
|
|||
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar);
|
||||
};
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11
|
||||
|
||||
class MockBaz {
|
||||
public:
|
||||
class MoveOnly {
|
||||
MoveOnly() = default;
|
||||
|
||||
MoveOnly(const MoveOnly&) = delete;
|
||||
operator=(const MoveOnly&) = delete;
|
||||
|
||||
MoveOnly(MoveOnly&&) = default;
|
||||
operator=(MoveOnly&&) = default;
|
||||
};
|
||||
|
||||
MockBaz(MoveOnly) {}
|
||||
}
|
||||
#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Tests that a raw mock generates warnings for uninteresting calls.
|
||||
|
@ -214,8 +233,9 @@ TEST(NiceMockTest, AllowsExpectedCall) {
|
|||
nice_foo.DoThis();
|
||||
}
|
||||
|
||||
// Tests that an unexpected call on a nice mock which returns a not-default-constructible
|
||||
// type throws an exception and the exception contains the method's name.
|
||||
// Tests that an unexpected call on a nice mock which returns a
|
||||
// not-default-constructible type throws an exception and the exception contains
|
||||
// the method's name.
|
||||
TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
|
||||
NiceMock<MockFoo> nice_foo;
|
||||
#if GTEST_HAS_EXCEPTIONS
|
||||
|
@ -259,6 +279,21 @@ TEST(NiceMockTest, NonDefaultConstructor10) {
|
|||
nice_bar.That(5, true);
|
||||
}
|
||||
|
||||
TEST(NiceMockTest, AllowLeak) {
|
||||
NiceMock<MockFoo>* leaked = new NiceMock<MockFoo>;
|
||||
Mock::AllowLeak(leaked);
|
||||
EXPECT_CALL(*leaked, DoThis());
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(NiceMockTest, MoveOnlyConstructor) {
|
||||
NiceMock<MockBaz> nice_baz(MockBaz::MoveOnly());
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that NiceMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
|
@ -352,6 +387,21 @@ TEST(NaggyMockTest, NonDefaultConstructor10) {
|
|||
naggy_bar.That(5, true);
|
||||
}
|
||||
|
||||
TEST(NaggyMockTest, AllowLeak) {
|
||||
NaggyMock<MockFoo>* leaked = new NaggyMock<MockFoo>;
|
||||
Mock::AllowLeak(leaked);
|
||||
EXPECT_CALL(*leaked, DoThis());
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(NaggyMockTest, MoveOnlyConstructor) {
|
||||
NaggyMock<MockBaz> naggy_baz(MockBaz::MoveOnly());
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that NaggyMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
|
@ -426,6 +476,21 @@ TEST(StrictMockTest, NonDefaultConstructor10) {
|
|||
"Uninteresting mock function call");
|
||||
}
|
||||
|
||||
TEST(StrictMockTest, AllowLeak) {
|
||||
StrictMock<MockFoo>* leaked = new StrictMock<MockFoo>;
|
||||
Mock::AllowLeak(leaked);
|
||||
EXPECT_CALL(*leaked, DoThis());
|
||||
leaked->DoThis();
|
||||
}
|
||||
|
||||
#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
TEST(StrictMockTest, MoveOnlyConstructor) {
|
||||
StrictMock<MockBaz> strict_baz(MockBaz::MoveOnly());
|
||||
}
|
||||
|
||||
#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
|
||||
|
||||
#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
|
||||
// Tests that StrictMock<Mock> compiles where Mock is a user-defined
|
||||
// class (as opposed to ::testing::Mock). We had to work around an
|
||||
|
|
|
@ -89,6 +89,7 @@ using testing::Mock;
|
|||
using testing::NaggyMock;
|
||||
using testing::Ne;
|
||||
using testing::Return;
|
||||
using testing::SaveArg;
|
||||
using testing::Sequence;
|
||||
using testing::SetArgPointee;
|
||||
using testing::internal::ExpectationTester;
|
||||
|
@ -748,7 +749,6 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
|
|||
testing::GMOCK_FLAG(default_mock_behavior) = original_behavior;
|
||||
}
|
||||
|
||||
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Tests the semantics of ON_CALL().
|
||||
|
@ -2174,7 +2174,9 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
|
|||
"NOTE: You can safely ignore the above warning unless this "
|
||||
"call should not happen. Do not suppress it by blindly adding "
|
||||
"an EXPECT_CALL() if you don't mean to enforce the call. "
|
||||
"See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#"
|
||||
"See "
|
||||
"https://github.com/google/googletest/blob/master/googlemock/docs/"
|
||||
"CookBook.md#"
|
||||
"knowing-when-to-expect for details.";
|
||||
|
||||
// A void-returning function.
|
||||
|
@ -2680,6 +2682,75 @@ TEST(SynchronizationTest, CanCallMockMethodInAction) {
|
|||
// EXPECT_CALL() did not specify an action.
|
||||
}
|
||||
|
||||
TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) {
|
||||
MockA a;
|
||||
int do_a_arg0 = 0;
|
||||
ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0));
|
||||
int do_a_47_arg0 = 0;
|
||||
ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0));
|
||||
|
||||
a.DoA(17);
|
||||
EXPECT_THAT(do_a_arg0, 17);
|
||||
EXPECT_THAT(do_a_47_arg0, 0);
|
||||
a.DoA(47);
|
||||
EXPECT_THAT(do_a_arg0, 17);
|
||||
EXPECT_THAT(do_a_47_arg0, 47);
|
||||
|
||||
ON_CALL(a, Binary).WillByDefault(Return(true));
|
||||
ON_CALL(a, Binary(_, 14)).WillByDefault(Return(false));
|
||||
EXPECT_THAT(a.Binary(14, 17), true);
|
||||
EXPECT_THAT(a.Binary(17, 14), false);
|
||||
}
|
||||
|
||||
TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) {
|
||||
MockB b;
|
||||
ON_CALL(b, DoB()).WillByDefault(Return(9));
|
||||
ON_CALL(b, DoB(5)).WillByDefault(Return(11));
|
||||
|
||||
EXPECT_THAT(b.DoB(), 9);
|
||||
EXPECT_THAT(b.DoB(1), 0); // default value
|
||||
EXPECT_THAT(b.DoB(5), 11);
|
||||
}
|
||||
|
||||
struct MockWithConstMethods {
|
||||
public:
|
||||
MOCK_CONST_METHOD1(Foo, int(int));
|
||||
MOCK_CONST_METHOD2(Bar, int(int, const char*));
|
||||
};
|
||||
|
||||
TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) {
|
||||
MockWithConstMethods mock;
|
||||
ON_CALL(mock, Foo).WillByDefault(Return(7));
|
||||
ON_CALL(mock, Bar).WillByDefault(Return(33));
|
||||
|
||||
EXPECT_THAT(mock.Foo(17), 7);
|
||||
EXPECT_THAT(mock.Bar(27, "purple"), 33);
|
||||
}
|
||||
|
||||
class MockConstOverload {
|
||||
public:
|
||||
MOCK_METHOD1(Overloaded, int(int));
|
||||
MOCK_CONST_METHOD1(Overloaded, int(int));
|
||||
};
|
||||
|
||||
TEST(ParameterlessExpectationsTest,
|
||||
CanSetExpectationsForConstOverloadedMethods) {
|
||||
MockConstOverload mock;
|
||||
ON_CALL(mock, Overloaded(_)).WillByDefault(Return(7));
|
||||
ON_CALL(mock, Overloaded(5)).WillByDefault(Return(9));
|
||||
ON_CALL(Const(mock), Overloaded(5)).WillByDefault(Return(11));
|
||||
ON_CALL(Const(mock), Overloaded(7)).WillByDefault(Return(13));
|
||||
|
||||
EXPECT_THAT(mock.Overloaded(1), 7);
|
||||
EXPECT_THAT(mock.Overloaded(5), 9);
|
||||
EXPECT_THAT(mock.Overloaded(7), 7);
|
||||
|
||||
const MockConstOverload& const_mock = mock;
|
||||
EXPECT_THAT(const_mock.Overloaded(1), 0);
|
||||
EXPECT_THAT(const_mock.Overloaded(5), 11);
|
||||
EXPECT_THAT(const_mock.Overloaded(7), 13);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Allows the user to define their own main and then invoke gmock_main
|
||||
|
@ -2691,7 +2762,6 @@ int gmock_main(int argc, char **argv) {
|
|||
int main(int argc, char **argv) {
|
||||
#endif // GMOCK_RENAME_MAIN
|
||||
testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// Ensures that the tests pass no matter what value of
|
||||
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
|
||||
testing::GMOCK_FLAG(catch_leaked_mocks) = true;
|
||||
|
|
|
@ -39,6 +39,12 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// Silence C4100 (unreferenced formal parameter)
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4100)
|
||||
#endif
|
||||
|
||||
using testing::_;
|
||||
using testing::AnyNumber;
|
||||
using testing::Ge;
|
||||
|
@ -273,6 +279,11 @@ MATCHER_P2(IsPair, first, second, "") {
|
|||
return Value(arg.first, first) && Value(arg.second, second);
|
||||
}
|
||||
|
||||
TEST_F(GMockOutputTest, PrintsMatcher) {
|
||||
const testing::Matcher<int> m1 = Ge(48);
|
||||
EXPECT_THAT((std::pair<int, bool>(42, true)), IsPair(m1, true));
|
||||
}
|
||||
|
||||
void TestCatchesLeakedMocksInAdHocTests() {
|
||||
MockFoo* foo = new MockFoo;
|
||||
|
||||
|
@ -293,3 +304,7 @@ int main(int argc, char **argv) {
|
|||
TestCatchesLeakedMocksInAdHocTests();
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
|
|
@ -288,6 +288,12 @@ Stack trace:
|
|||
[ OK ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction
|
||||
[ RUN ] GMockOutputTest.CatchesLeakedMocks
|
||||
[ OK ] GMockOutputTest.CatchesLeakedMocks
|
||||
[ RUN ] GMockOutputTest.PrintsMatcher
|
||||
FILE:#: Failure
|
||||
Value of: (std::pair<int, bool>(42, true))
|
||||
Expected: is pair (is >= 48, true)
|
||||
Actual: (42, true) (of type std::pair<int, bool>)
|
||||
[ FAILED ] GMockOutputTest.PrintsMatcher
|
||||
[ FAILED ] GMockOutputTest.UnexpectedCall
|
||||
[ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction
|
||||
[ FAILED ] GMockOutputTest.ExcessiveCall
|
||||
|
@ -302,9 +308,10 @@ Stack trace:
|
|||
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWith
|
||||
[ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction
|
||||
[ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction
|
||||
[ FAILED ] GMockOutputTest.PrintsMatcher
|
||||
|
||||
|
||||
FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#.
|
||||
FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#.
|
||||
FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#.
|
||||
ERROR: 3 leaked mock objects found at program exit.
|
||||
ERROR: 3 leaked mock objects found at program exit. Expectations on a mock object is verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock.
|
||||
|
|
|
@ -82,6 +82,15 @@
|
|||
|
||||
namespace testing {
|
||||
|
||||
// Silence C4100 (unreferenced formal parameter) and 4805
|
||||
// unsafe mix of type 'const int' and type 'const bool'
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4805)
|
||||
# pragma warning(disable:4100)
|
||||
#endif
|
||||
|
||||
|
||||
// Declares the flags.
|
||||
|
||||
// This flag temporary enables the disabled tests.
|
||||
|
@ -2298,6 +2307,10 @@ bool StaticAssertTypeEq() {
|
|||
// Tries to determine an appropriate directory for the platform.
|
||||
GTEST_API_ std::string TempDir();
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
} // namespace testing
|
||||
|
||||
// Use this function in main() to run all tests. It returns 0 if all
|
||||
|
|
|
@ -157,7 +157,7 @@ namespace edit_distance {
|
|||
// Returns the optimal edits to go from 'left' to 'right'.
|
||||
// All edits cost the same, with replace having lower priority than
|
||||
// add/remove.
|
||||
// Simple implementation of the Wagner–Fischer algorithm.
|
||||
// Simple implementation of the Wagner-Fischer algorithm.
|
||||
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
|
||||
enum EditType { kMatch, kAdd, kRemove, kReplace };
|
||||
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||
|
@ -1155,7 +1155,7 @@ class NativeArray {
|
|||
#define GTEST_SUCCESS_(message) \
|
||||
GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
|
||||
|
||||
// Suppresses MSVC warnings 4072 (unreachable code) for the code following
|
||||
// Suppress MSVC warning 4702 (unreachable code) for the code following
|
||||
// statement if it returns or throws (or doesn't return or throw in some
|
||||
// situations).
|
||||
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
|
||||
|
|
|
@ -228,10 +228,9 @@
|
|||
//
|
||||
// Regular expressions:
|
||||
// RE - a simple regular expression class using the POSIX
|
||||
// Extended Regular Expression syntax on UNIX-like
|
||||
// platforms, or a reduced regular exception syntax on
|
||||
// other platforms, including Windows.
|
||||
//
|
||||
// Extended Regular Expression syntax on UNIX-like platforms
|
||||
// or a reduced regular exception syntax on other
|
||||
// platforms, including Windows.
|
||||
// Logging:
|
||||
// GTEST_LOG_() - logs messages at the specified severity level.
|
||||
// LogToStderr() - directs all log messages to stderr.
|
||||
|
@ -652,7 +651,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|||
// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
|
||||
# define GTEST_HAS_TR1_TUPLE 0
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1910)
|
||||
// Prevent `warning C4996: 'std::tr1': warning STL4002: The non-Standard std::tr1 namespace and TR1-only machinery are deprecated and will be REMOVED.`
|
||||
// Prevent `warning C4996: 'std::tr1': warning STL4002:
|
||||
// The non-Standard std::tr1 namespace and TR1-only machinery
|
||||
// are deprecated and will be REMOVED.`
|
||||
# define GTEST_HAS_TR1_TUPLE 0
|
||||
# elif GTEST_LANG_CXX11 && defined(_LIBCPP_VERSION)
|
||||
// libc++ doesn't support TR1.
|
||||
# define GTEST_HAS_TR1_TUPLE 0
|
||||
# else
|
||||
// The user didn't tell us not to do it, so we assume it's OK.
|
||||
|
@ -663,6 +667,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|||
// Determines whether Google Test's own tr1 tuple implementation
|
||||
// should be used.
|
||||
#ifndef GTEST_USE_OWN_TR1_TUPLE
|
||||
// We use our own tuple implementation on Symbian.
|
||||
# if GTEST_OS_SYMBIAN
|
||||
# define GTEST_USE_OWN_TR1_TUPLE 1
|
||||
# else
|
||||
// The user didn't tell us, so we need to figure it out.
|
||||
|
||||
// We use our own TR1 tuple if we aren't sure the user has an
|
||||
|
@ -693,12 +701,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|||
# else
|
||||
# define GTEST_USE_OWN_TR1_TUPLE 1
|
||||
# endif
|
||||
|
||||
# endif // GTEST_OS_SYMBIAN
|
||||
#endif // GTEST_USE_OWN_TR1_TUPLE
|
||||
|
||||
// To avoid conditional compilation everywhere, we make it
|
||||
// gtest-port.h's responsibility to #include the header implementing
|
||||
// tuple.
|
||||
// To avoid conditional compilation we make it gtest-port.h's responsibility
|
||||
// to #include the header implementing tuple.
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
# include <tuple> // IWYU pragma: export
|
||||
# define GTEST_TUPLE_NAMESPACE_ ::std
|
||||
|
@ -713,22 +720,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|||
|
||||
# if GTEST_USE_OWN_TR1_TUPLE
|
||||
# include "gtest/internal/gtest-tuple.h" // IWYU pragma: export // NOLINT
|
||||
# elif GTEST_ENV_HAS_STD_TUPLE_
|
||||
# include <tuple>
|
||||
// C++11 puts its tuple into the ::std namespace rather than
|
||||
// ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there.
|
||||
// This causes undefined behavior, but supported compilers react in
|
||||
// the way we intend.
|
||||
namespace std {
|
||||
namespace tr1 {
|
||||
using ::std::get;
|
||||
using ::std::make_tuple;
|
||||
using ::std::tuple;
|
||||
using ::std::tuple_element;
|
||||
using ::std::tuple_size;
|
||||
}
|
||||
}
|
||||
|
||||
# elif GTEST_OS_SYMBIAN
|
||||
|
||||
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
|
||||
|
@ -763,10 +754,12 @@ using ::std::tuple_size;
|
|||
# include <tr1/tuple> // NOLINT
|
||||
# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
|
||||
|
||||
# else
|
||||
// If the compiler is not GCC 4.0+, we assume the user is using a
|
||||
// spec-conforming TR1 implementation.
|
||||
// VS 2010 now has tr1 support.
|
||||
# elif _MSC_VER >= 1600
|
||||
# include <tuple> // IWYU pragma: export // NOLINT
|
||||
|
||||
# else // GTEST_USE_OWN_TR1_TUPLE
|
||||
# include <tr1/tuple> // IWYU pragma: export // NOLINT
|
||||
# endif // GTEST_USE_OWN_TR1_TUPLE
|
||||
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
@ -2093,8 +2086,13 @@ class MutexBase {
|
|||
extern ::testing::internal::MutexBase mutex
|
||||
|
||||
// Defines and statically (i.e. at link time) initializes a static mutex.
|
||||
// The initialization list here does not explicitly initialize each field,
|
||||
// instead relying on default initialization for the unspecified fields. In
|
||||
// particular, the owner_ field (a pthread_t) is not explicitly initialized.
|
||||
// This allows initialization to work whether pthread_t is a scalar or struct.
|
||||
// The flag -Wmissing-field-initializers must not be specified for this to work.
|
||||
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
|
||||
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false, pthread_t() }
|
||||
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
|
||||
|
||||
// The Mutex class can only be used for mutexes created at runtime. It
|
||||
// shares its API with MutexBase otherwise.
|
||||
|
|
|
@ -4549,6 +4549,11 @@ void UnitTest::AddTestPartResult(
|
|||
// when a failure happens and both the --gtest_break_on_failure and
|
||||
// the --gtest_catch_exceptions flags are specified.
|
||||
DebugBreak();
|
||||
#elif (!defined(__native_client__)) && \
|
||||
((defined(__clang__) || defined(__GNUC__)) && \
|
||||
(defined(__x86_64__) || defined(__i386__)))
|
||||
// with clang/gcc we can achieve the same effect on x86 by invoking int3
|
||||
asm("int3");
|
||||
#else
|
||||
// Dereference NULL through a volatile pointer to prevent the compiler
|
||||
// from removing. We use this rather than abort() or __builtin_trap() for
|
||||
|
|
|
@ -67,8 +67,8 @@ TEST(IsXDigitTest, WorksForNarrowAscii) {
|
|||
}
|
||||
|
||||
TEST(IsXDigitTest, ReturnsFalseForNarrowNonAscii) {
|
||||
EXPECT_FALSE(IsXDigit(static_cast<char>(0x80)));
|
||||
EXPECT_FALSE(IsXDigit(static_cast<char>('0' | 0x80)));
|
||||
EXPECT_FALSE(IsXDigit(static_cast<char>('\x80')));
|
||||
EXPECT_FALSE(IsXDigit(static_cast<char>('0' | '\x80')));
|
||||
}
|
||||
|
||||
TEST(IsXDigitTest, WorksForWideAscii) {
|
||||
|
|
|
@ -7572,7 +7572,7 @@ TEST(IsHashTable, Basic) {
|
|||
EXPECT_TRUE(testing::internal::IsHashTable<std::unordered_set<int>>::value);
|
||||
#endif // GTEST_LANG_CXX11
|
||||
#if GTEST_HAS_HASH_SET_
|
||||
EXPECT_TRUE(testing::internal::IsHashTable<hash_set<int>>::value);
|
||||
EXPECT_TRUE(testing::internal::IsHashTable<__gnu_cxx::hash_set<int>>::value);
|
||||
#endif // GTEST_HAS_HASH_SET_
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user