aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock')
-rw-r--r--googlemock/cmake/gmock.pc.in5
-rw-r--r--googlemock/cmake/gmock_main.pc.in5
-rw-r--r--googlemock/docs/cheat_sheet.md34
-rw-r--r--googlemock/docs/cook_book.md195
-rw-r--r--googlemock/docs/for_dummies.md2
-rw-r--r--googlemock/include/gmock/gmock-actions.h15
-rw-r--r--googlemock/include/gmock/gmock-cardinalities.h14
-rw-r--r--googlemock/include/gmock/gmock-function-mocker.h29
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h24
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump4
-rw-r--r--googlemock/include/gmock/gmock-generated-matchers.h88
-rw-r--r--googlemock/include/gmock/gmock-generated-matchers.h.pump8
-rw-r--r--googlemock/include/gmock/gmock-matchers.h100
-rw-r--r--googlemock/include/gmock/gmock-spec-builders.h35
-rw-r--r--googlemock/include/gmock/internal/gmock-internal-utils.h34
-rw-r--r--googlemock/src/gmock-internal-utils.cc6
-rw-r--r--googlemock/src/gmock-spec-builders.cc19
-rw-r--r--googlemock/src/gmock.cc4
-rw-r--r--googlemock/test/gmock-cardinalities_test.cc6
-rw-r--r--googlemock/test/gmock-function-mocker_test.cc7
-rw-r--r--googlemock/test/gmock-internal-utils_test.cc102
-rw-r--r--googlemock/test/gmock-matchers_test.cc131
-rw-r--r--googlemock/test/gmock-more-actions_test.cc1
-rw-r--r--googlemock/test/gmock-spec-builders_test.cc8
24 files changed, 536 insertions, 340 deletions
diff --git a/googlemock/cmake/gmock.pc.in b/googlemock/cmake/gmock.pc.in
index 08e04547..2ef0fbca 100644
--- a/googlemock/cmake/gmock.pc.in
+++ b/googlemock/cmake/gmock.pc.in
@@ -1,6 +1,5 @@
-prefix=${pcfiledir}/../..
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: gmock
Description: GoogleMock (without main() function)
diff --git a/googlemock/cmake/gmock_main.pc.in b/googlemock/cmake/gmock_main.pc.in
index b22fe614..04658fe2 100644
--- a/googlemock/cmake/gmock_main.pc.in
+++ b/googlemock/cmake/gmock_main.pc.in
@@ -1,6 +1,5 @@
-prefix=${pcfiledir}/../..
-libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
Name: gmock_main
Description: GoogleMock (with main() function)
diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md
index 239a4c6d..3236e6a9 100644
--- a/googlemock/docs/cheat_sheet.md
+++ b/googlemock/docs/cheat_sheet.md
@@ -202,6 +202,15 @@ EXPECT_CALL(mock-object, method (matchers)?)
.RetiresOnSaturation(); ?
```
+For each item above, `?` means it can be used at most once, while `*` means it
+can be used any number of times.
+
+In order to pass, `EXPECT_CALL` must be used before the calls are actually made.
+
+The `(matchers)` is a comma-separated list of matchers that correspond to each
+of the arguments of `method`, and sets the expectation only for calls of
+`method` that matches all of the matchers.
+
If `(matchers)` is omitted, the expectation is the same as if the matchers were
set to anything matchers (for example, `(_, _, _, _)` for a four-arg method).
@@ -221,17 +230,19 @@ and the default action will be taken each time.
<!-- GOOGLETEST_CM0020 DO NOT DELETE -->
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
-`EXPECT_CALL()`, or use it to validate a value directly:
+`EXPECT_CALL()`, or use it to validate a value directly using two macros:
<!-- mdformat off(github rendering does not support multiline tables) -->
-| Matcher | Description |
+| Macro | Description |
| :----------------------------------- | :------------------------------------ |
| `EXPECT_THAT(actual_value, matcher)` | Asserts that `actual_value` matches `matcher`. |
| `ASSERT_THAT(actual_value, matcher)` | The same as `EXPECT_THAT(actual_value, matcher)`, except that it generates a **fatal** failure. |
<!-- mdformat on -->
-Built-in matchers (where `argument` is the function argument) are divided into
-several categories:
+Built-in matchers (where `argument` is the function argument, e.g.
+`actual_value` in the example above, or when used in the context of
+`EXPECT_CALL(mock_object, method(matchers))`, the arguments of `method`) are
+divided into several categories:
#### Wildcard
@@ -251,6 +262,8 @@ Matcher | Description
| `Le(value)` | `argument <= value` |
| `Lt(value)` | `argument < value` |
| `Ne(value)` | `argument != value` |
+| `IsFalse()` | `argument` evaluates to `false` in a Boolean context. |
+| `IsTrue()` | `argument` evaluates to `true` in a Boolean context. |
| `IsNull()` | `argument` is a `NULL` pointer (raw or smart). |
| `NotNull()` | `argument` is a non-null pointer (raw or smart). |
| `Optional(m)` | `argument` is `optional<>` that contains a value matching `m`. |
@@ -274,6 +287,7 @@ is not changed afterwards, or the meaning of your matcher will be changed.
| `FloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as unequal. |
| `NanSensitiveDoubleEq(a_double)` | `argument` is a `double` value approximately equal to `a_double`, treating two NaNs as equal. |
| `NanSensitiveFloatEq(a_float)` | `argument` is a `float` value approximately equal to `a_float`, treating two NaNs as equal. |
+| `IsNan()` | `argument` is any floating-point type with a NaN value. |
<!-- mdformat on -->
The above matchers use ULP-based comparison (the same as used in googletest).
@@ -312,9 +326,9 @@ The `argument` can be either a C string or a C++ string object:
`ContainsRegex()` and `MatchesRegex()` take ownership of the `RE` object. They
use the regular expression syntax defined
-[here](../../googletest/docs/advanced.md#regular-expression-syntax).
-`StrCaseEq()`, `StrCaseNe()`, `StrEq()`, and `StrNe()` work for wide strings as
-well.
+[here](../../googletest/docs/advanced.md#regular-expression-syntax). All of
+these matchers, except `ContainsRegex()` and `MatchesRegex()` work for wide
+strings as well.
#### Container Matchers
@@ -333,10 +347,8 @@ messages, you can use:
| `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, where the *i*-th element matches `ei`, which can be a value or a matcher. |
| `ElementsAreArray({e0, e1, ..., en})`, `ElementsAreArray(a_container)`, `ElementsAreArray(begin, end)`, `ElementsAreArray(array)`, or `ElementsAreArray(array, count)` | The same as `ElementsAre()` except that the expected element values/matchers come from an initializer list, STL-style container, iterator range, or C-style array. |
| `IsEmpty()` | `argument` is an empty container (`container.empty()`). |
-| `IsFalse()` | `argument` evaluates to `false` in a Boolean context. |
| `IsSubsetOf({e0, e1, ..., en})`, `IsSubsetOf(a_container)`, `IsSubsetOf(begin, end)`, `IsSubsetOf(array)`, or `IsSubsetOf(array, count)` | `argument` matches `UnorderedElementsAre(x0, x1, ..., xk)` for some subset `{x0, x1, ..., xk}` of the expected matchers. |
| `IsSupersetOf({e0, e1, ..., en})`, `IsSupersetOf(a_container)`, `IsSupersetOf(begin, end)`, `IsSupersetOf(array)`, or `IsSupersetOf(array, count)` | Some subset of `argument` matches `UnorderedElementsAre(`expected matchers`)`. |
-| `IsTrue()` | `argument` evaluates to `true` in a Boolean context. |
| `Pointwise(m, container)`, `Pointwise(m, {e0, e1, ..., en})` | `argument` contains the same number of elements as in `container`, and for all i, (the i-th element in `argument`, the i-th element in `container`) match `m`, which is a matcher on 2-tuples. E.g. `Pointwise(Le(), upper_bounds)` verifies that each element in `argument` doesn't exceed the corresponding element in `upper_bounds`. See more detail below. |
| `SizeIs(m)` | `argument` is a container whose size matches `m`. E.g. `SizeIs(2)` or `SizeIs(Lt(2))`. |
| `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, and under *some* permutation of the elements, each element matches an `ei` (for a different `i`), which can be a value or a matcher. |
@@ -731,12 +743,12 @@ you can do it earlier:
using ::testing::Mock;
...
// Verifies and removes the expectations on mock_obj;
-// returns true if successful.
+// returns true if and only if successful.
Mock::VerifyAndClearExpectations(&mock_obj);
...
// Verifies and removes the expectations on mock_obj;
// also removes the default actions set by ON_CALL();
-// returns true if successful.
+// returns true if and only if successful.
Mock::VerifyAndClear(&mock_obj);
```
diff --git a/googlemock/docs/cook_book.md b/googlemock/docs/cook_book.md
index 28f7ba1d..ea55ab35 100644
--- a/googlemock/docs/cook_book.md
+++ b/googlemock/docs/cook_book.md
@@ -1,4 +1,4 @@
-## gMock Cookbook
+# gMock Cookbook
<!-- GOOGLETEST_CM0012 DO NOT DELETE -->
@@ -10,7 +10,7 @@ recommended to write `using ::testing::Foo;` once in your file before using the
name `Foo` defined by gMock. We omit such `using` statements in this section for
brevity, but you should do it in your own code.
-### Creating Mock Classes
+## Creating Mock Classes
Mock classes are defined as normal classes, using the `MOCK_METHOD` macro to
generate mocked methods. The macro gets 3 or 4 parameters:
@@ -36,7 +36,7 @@ generated method:
* **`Calltype(...)`** - Sets the call type for the method (e.g. to
`STDMETHODCALLTYPE`), useful in Windows.
-#### Dealing with unprotected commas
+### Dealing with unprotected commas
Unprotected commas, i.e. commas which are not surrounded by parentheses, prevent
`MOCK_METHOD` from parsing its arguments correctly:
@@ -74,7 +74,7 @@ class MockFoo {
};
```
-#### Mocking Private or Protected Methods
+### Mocking Private or Protected Methods
You must always put a mock method definition (`MOCK_METHOD`) in a `public:`
section of the mock class, regardless of the method being mocked being `public`,
@@ -108,7 +108,7 @@ class MockFoo : public Foo {
};
```
-#### Mocking Overloaded Methods
+### Mocking Overloaded Methods
You can mock overloaded functions as usual. No special attention is required:
@@ -152,7 +152,7 @@ class MockFoo : public Foo {
};
```
-#### Mocking Class Templates
+### Mocking Class Templates
You can mock class templates just like any class.
@@ -175,7 +175,7 @@ class MockStack : public StackInterface<Elem> {
};
```
-#### Mocking Non-virtual Methods {#MockingNonVirtualMethods}
+### Mocking Non-virtual Methods {#MockingNonVirtualMethods}
gMock can mock non-virtual functions to be used in Hi-perf dependency
injection.<!-- GOOGLETEST_CM0017 DO NOT DELETE -->
@@ -243,7 +243,7 @@ tests.
... exercise reader ...
```
-#### Mocking Free Functions
+### Mocking Free Functions
It's possible to use gMock to mock a free function (i.e. a C-style function or a
static method). You just need to rewrite your code to use an interface (abstract
@@ -279,7 +279,7 @@ If you are concerned about the performance overhead incurred by virtual
functions, and profiling confirms your concern, you can combine this with the
recipe for [mocking non-virtual methods](#MockingNonVirtualMethods).
-#### Old-Style `MOCK_METHODn` Macros
+### Old-Style `MOCK_METHODn` Macros
Before the generic `MOCK_METHOD` macro was introduced, mocks where created using
a family of macros collectively called `MOCK_METHODn`. These macros are still
@@ -337,7 +337,7 @@ Foo, bool(int))` </td> </tr> <tr> <td> New </td> <td> `MOCK_METHOD(bool, Foo,
</table>
-#### The Nice, the Strict, and the Naggy {#NiceStrictNaggy}
+### The Nice, the Strict, and the Naggy {#NiceStrictNaggy}
If a mock method has no `EXPECT_CALL` spec but is called, we say that it's an
"uninteresting call", and the default action (which can be specified using
@@ -444,7 +444,7 @@ nice mocks (not yet the default) most of the time, use naggy mocks (the current
default) when developing or debugging tests, and use strict mocks only as the
last resort.
-#### Simplifying the Interface without Breaking Existing Code {#SimplerInterfaces}
+### Simplifying the Interface without Breaking Existing Code {#SimplerInterfaces}
Sometimes a method has a long list of arguments that is mostly uninteresting.
For example:
@@ -516,7 +516,7 @@ ON_CALL(factory, DoMakeTurtle)
.WillByDefault(MakeMockTurtle());
```
-#### Alternative to Mocking Concrete Classes
+### Alternative to Mocking Concrete Classes
Often you may find yourself using classes that don't implement interfaces. In
order to test your code that uses such a class (let's call it `Concrete`), you
@@ -578,7 +578,7 @@ I'd like to assure you that the Java community has been practicing this for a
long time and it's a proven effective technique applicable in a wide variety of
situations. :-)
-#### Delegating Calls to a Fake {#DelegatingToFake}
+### Delegating Calls to a Fake {#DelegatingToFake}
Some times you have a non-trivial fake implementation of an interface. For
example:
@@ -696,7 +696,7 @@ Instead, you can define a `FileOps` interface and an `IOOps` interface and split
`System`'s functionalities into the two. Then you can mock `IOOps` without
mocking `FileOps`.
-#### Delegating Calls to a Real Object
+### Delegating Calls to a Real Object
When using testing doubles (mocks, fakes, stubs, and etc), sometimes their
behaviors will differ from those of the real objects. This difference could be
@@ -747,7 +747,7 @@ arguments, in the right order, called the right number of times, etc), and a
real object will answer the calls (so the behavior will be the same as in
production). This gives you the best of both worlds.
-#### Delegating Calls to a Parent Class
+### Delegating Calls to a Parent Class
Ideally, you should code to interfaces, whose methods are all pure virtual. In
reality, sometimes you do need to mock a virtual method that is not pure (i.e,
@@ -815,9 +815,9 @@ or tell the mock object that you don't want to mock `Concrete()`:
`MockFoo::Concrete()` will be called (and cause an infinite recursion) since
`Foo::Concrete()` is virtual. That's just how C++ works.)
-### Using Matchers
+## Using Matchers
-#### Matching Argument Values Exactly
+### Matching Argument Values Exactly
You can specify exactly which arguments a mock method is expecting:
@@ -829,7 +829,7 @@ using ::testing::Return;
EXPECT_CALL(foo, DoThat("Hello", bar));
```
-#### Using Simple Matchers
+### Using Simple Matchers
You can use matchers to match arguments that have a certain property:
@@ -850,7 +850,7 @@ A frequently used matcher is `_`, which matches anything:
```
<!-- GOOGLETEST_CM0022 DO NOT DELETE -->
-#### Combining Matchers {#CombiningMatchers}
+### Combining Matchers {#CombiningMatchers}
You can build complex matchers from existing ones using `AllOf()`,
`AllOfArray()`, `AnyOf()`, `AnyOfArray()` and `Not()`:
@@ -871,7 +871,7 @@ using ::testing::Not;
NULL));
```
-#### Casting Matchers {#SafeMatcherCast}
+### Casting Matchers {#SafeMatcherCast}
gMock matchers are statically typed, meaning that the compiler can catch your
mistake if you use a matcher of the wrong type (for example, if you use `Eq(5)`
@@ -926,7 +926,7 @@ can `static_cast` type `T` to type `U`.
always safe as it could throw away information, for example), so be careful not
to misuse/abuse it.
-#### Selecting Between Overloaded Functions {#SelectOverload}
+### Selecting Between Overloaded Functions {#SelectOverload}
If you expect an overloaded function to be called, the compiler may need some
help on which overloaded version it is.
@@ -983,7 +983,7 @@ TEST(PrinterTest, Print) {
}
```
-#### Performing Different Actions Based on the Arguments
+### Performing Different Actions Based on the Arguments
When a mock method is called, the *last* matching expectation that's still
active will be selected (think "newer overrides older"). So, you can make a
@@ -1005,7 +1005,7 @@ using ::testing::Return;
Now, if `foo.DoThis()` is called with a value less than 5, `'a'` will be
returned; otherwise `'b'` will be returned.
-#### Matching Multiple Arguments as a Whole
+### Matching Multiple Arguments as a Whole
Sometimes it's not enough to match the arguments individually. For example, we
may want to say that the first argument must be less than the second argument.
@@ -1057,7 +1057,7 @@ Note that if you want to pass the arguments to a predicate of your own (e.g.
take a `::std::tuple` as its argument; gMock will pass the `n` selected
arguments as *one* single tuple to the predicate.
-#### Using Matchers as Predicates
+### Using Matchers as Predicates
Have you noticed that a matcher is just a fancy predicate that also knows how to
describe itself? Many existing algorithms take predicates as arguments (e.g.
@@ -1095,7 +1095,7 @@ using testing::Ne;
Matches(AllOf(Ge(0), Le(100), Ne(50)))
```
-#### Using Matchers in googletest Assertions
+### Using Matchers in googletest Assertions
Since matchers are basically predicates that also know how to describe
themselves, there is a way to take advantage of them in googletest assertions.
@@ -1143,7 +1143,7 @@ Expected: starts with "Hello"
**Credit:** The idea of `(ASSERT|EXPECT)_THAT` was borrowed from Joe Walnes'
Hamcrest project, which adds `assertThat()` to JUnit.
-#### Using Predicates as Matchers
+### Using Predicates as Matchers
gMock provides a [built-in set](#MatcherList) of matchers. In case you find them
lacking, you can use an arbitrary unary predicate function or functor as a
@@ -1165,7 +1165,7 @@ works as long as the return value can be used as the condition in in statement
<!-- GOOGLETEST_CM0023 DO NOT DELETE -->
-#### Matching Arguments that Are Not Copyable
+### Matching Arguments that Are Not Copyable
When you do an `EXPECT_CALL(mock_obj, Foo(bar))`, gMock saves away a copy of
`bar`. When `Foo()` is called later, gMock compares the argument to `Foo()` with
@@ -1195,7 +1195,7 @@ using ::testing::Lt;
Remember: if you do this, don't change `bar` after the `EXPECT_CALL()`, or the
result is undefined.
-#### Validating a Member of an Object
+### Validating a Member of an Object
Often a mock function takes a reference to object as an argument. When matching
the argument, you may not want to compare the entire object against a fixed
@@ -1262,7 +1262,7 @@ Matcher<Foo> IsFoo(const Foo& foo) {
}
```
-#### Validating the Value Pointed to by a Pointer Argument
+### Validating the Value Pointed to by a Pointer Argument
C++ functions often take pointers as arguments. You can use matchers like
`IsNull()`, `NotNull()`, and other comparison matchers to match a pointer, but
@@ -1270,8 +1270,8 @@ what if you want to make sure the value *pointed to* by the pointer, instead of
the pointer itself, has a certain property? Well, you can use the `Pointee(m)`
matcher.
-`Pointee(m)` matches a pointer if `m` matches the value the pointer points to.
-For example:
+`Pointee(m)` matches a pointer if and only if `m` matches the value the pointer
+points to. For example:
```cpp
using ::testing::Ge;
@@ -1304,7 +1304,7 @@ What if you have a pointer to pointer? You guessed it - you can use nested
`Pointee(Pointee(Lt(3)))` matches a pointer that points to a pointer that points
to a number less than 3 (what a mouthful...).
-#### Testing a Certain Property of an Object
+### Testing a Certain Property of an Object
Sometimes you want to specify that an object argument has a certain property,
but there is no existing matcher that does this. If you want good error
@@ -1350,7 +1350,7 @@ Matcher<const Foo&> BarPlusBazEq(int expected_sum) {
EXPECT_CALL(..., DoThis(BarPlusBazEq(5)))...;
```
-#### Matching Containers
+### Matching Containers
Sometimes an STL container (e.g. list, vector, map, ...) is passed to a mock
function and you may want to validate it. Since most STL containers support the
@@ -1446,7 +1446,7 @@ using testing::Pair;
with containers whose element order are undefined (e.g. `hash_map`) you
should use `WhenSorted` around `ElementsAre`.
-#### Sharing Matchers
+### Sharing Matchers
Under the hood, a gMock matcher object consists of a pointer to a ref-counted
implementation object. Copying matchers is allowed and very efficient, as only
@@ -1467,7 +1467,7 @@ using ::testing::Matcher;
... use in_range as a matcher in multiple EXPECT_CALLs ...
```
-#### Matchers must have no side-effects {#PureMatchers}
+### Matchers must have no side-effects {#PureMatchers}
WARNING: gMock does not guarantee when or how many times a matcher will be
invoked. Therefore, all matchers must be *purely functional*: they cannot have
@@ -1479,9 +1479,9 @@ it is one of the standard matchers, or a custom matcher). In particular, a
matcher can never call a mock function, as that will affect the state of the
mock object and gMock.
-### Setting Expectations
+## Setting Expectations
-#### Knowing When to Expect {#UseOnCall}
+### Knowing When to Expect {#UseOnCall}
<!-- GOOGLETEST_CM0018 DO NOT DELETE -->
@@ -1534,7 +1534,7 @@ message for specific methods by adding `EXPECT_CALL(...).Times(AnyNumber())`. DO
NOT suppress it by blindly adding an `EXPECT_CALL(...)`, or you'll have a test
that's a pain to maintain.
-#### Ignoring Uninteresting Calls
+### Ignoring Uninteresting Calls
If you are not interested in how a mock method is called, just don't say
anything about it. In this case, if the method is ever called, gMock will
@@ -1547,7 +1547,7 @@ Please note that once you expressed interest in a particular mock method (via
function is called but the arguments don't match any `EXPECT_CALL()` statement,
it will be an error.
-#### Disallowing Unexpected Calls
+### Disallowing Unexpected Calls
If a mock method shouldn't be called at all, explicitly say so:
@@ -1573,7 +1573,7 @@ using ::testing::Gt;
A call to `foo.Bar()` that doesn't match any of the `EXPECT_CALL()` statements
will be an error.
-#### Understanding Uninteresting vs Unexpected Calls {#uninteresting-vs-unexpected}
+### Understanding Uninteresting vs Unexpected Calls {#uninteresting-vs-unexpected}
*Uninteresting* calls and *unexpected* calls are different concepts in gMock.
*Very* different.
@@ -1648,7 +1648,7 @@ Note that the order of the two `EXPECT_CALL`s is important, as a newer
For more on uninteresting calls, nice mocks, and strict mocks, read
["The Nice, the Strict, and the Naggy"](#NiceStrictNaggy).
-#### Ignoring Uninteresting Arguments {#ParameterlessExpectations}
+### Ignoring Uninteresting Arguments {#ParameterlessExpectations}
If your test doesn't care about the parameters (it only cares about the number
or order of calls), you can often simply omit the parameter list:
@@ -1674,7 +1674,7 @@ SaveArg actions to [save the values for later verification](#SaveArgVerify). If
you do that, you can easily differentiate calling the method the wrong number of
times from calling it with the wrong arguments.
-#### Expecting Ordered Calls {#OrderedCalls}
+### Expecting Ordered Calls {#OrderedCalls}
Although an `EXPECT_CALL()` statement defined earlier takes precedence when
gMock tries to match a function call with an expectation, by default calls don't
@@ -1705,7 +1705,7 @@ In this example, we expect a call to `foo.DoThis(5)`, followed by two calls to
a call to `foo.DoThis(6)`. If a call occurred out-of-order, gMock will report an
error.
-#### Expecting Partially Ordered Calls {#PartialOrder}
+### Expecting Partially Ordered Calls {#PartialOrder}
Sometimes requiring everything to occur in a predetermined order can lead to
brittle tests. For example, we may care about `A` occurring before both `B` and
@@ -1763,7 +1763,7 @@ specifies the following DAG (where `s1` is `A -> B`, and `s2` is `A -> C -> D`):
This means that A must occur before B and C, and C must occur before D. There's
no restriction about the order other than these.
-#### Controlling When an Expectation Retires
+### Controlling When an Expectation Retires
When a mock method is called, gMock only considers expectations that are still
active. An expectation is active when created, and becomes inactive (aka
@@ -1816,9 +1816,9 @@ Here #2 can be used only once, so if you have two warnings with the message
`"File too large."`, the first will match #2 and the second will match #1 -
there will be no error.
-### Using Actions
+## Using Actions
-#### Returning References from Mock Methods
+### Returning References from Mock Methods
If a mock function's return type is a reference, you need to use `ReturnRef()`
instead of `Return()` to return a result:
@@ -1838,7 +1838,7 @@ class MockFoo : public Foo {
...
```
-#### Returning Live Values from Mock Methods
+### Returning Live Values from Mock Methods
The `Return(x)` action saves a copy of `x` when the action is created, and
always returns the same value whenever it's executed. Sometimes you may want to
@@ -1900,7 +1900,7 @@ using testing::ReturnPointee;
EXPECT_EQ(42, foo.GetValue()); // This will succeed now.
```
-#### Combining Actions
+### Combining Actions
Want to do more than one thing when a function is called? That's fine. `DoAll()`
allow you to do sequence of actions every time. Only the return value of the
@@ -1922,7 +1922,7 @@ class MockFoo : public Foo {
action_n));
```
-#### Verifying Complex Arguments {#SaveArgVerify}
+### Verifying Complex Arguments {#SaveArgVerify}
If you want to verify that a method is called with a particular argument but the
match criteria is complex, it can be difficult to distinguish between
@@ -1946,7 +1946,7 @@ You can instead save the arguments and test them individually:
EXPECT_THAT(actual_proto, EqualsProto( ... ));
```
-#### Mocking Side Effects {#MockingSideEffects}
+### Mocking Side Effects {#MockingSideEffects}
Sometimes a method exhibits its effect not via returning a value but via side
effects. For example, it may change some global state or modify an output
@@ -2045,7 +2045,7 @@ class MockRolodex : public Rolodex {
.WillOnce(SetArrayArgument<0>(names.begin(), names.end()));
```
-#### Changing a Mock Object's Behavior Based on the State
+### Changing a Mock Object's Behavior Based on the State
If you expect a call to change the behavior of a mock object, you can use
`::testing::InSequence` to specify different behaviors before and after the
@@ -2091,7 +2091,7 @@ ACTION_P(ReturnPointee, p) { return *p; }
Here `my_mock.GetPrevValue()` will always return the argument of the last
`UpdateValue()` call.
-#### Setting the Default Value for a Return Type {#DefaultValue}
+### Setting the Default Value for a Return Type {#DefaultValue}
If a mock method's return type is a built-in C++ type or pointer, by default it
will return 0 when invoked. Also, in C++ 11 and above, a mock method whose
@@ -2134,7 +2134,7 @@ to understand. We recommend you to use this feature judiciously. For example,
you may want to make sure the `Set()` and `Clear()` calls are right next to the
code that uses your mock.
-#### Setting the Default Actions for a Mock Method
+### Setting the Default Actions for a Mock Method
You've learned how to change the default value of a given type. However, this
may be too coarse for your purpose: perhaps you have two mock methods with the
@@ -2172,7 +2172,7 @@ Note that both `ON_CALL` and `EXPECT_CALL` have the same "later statements take
precedence" rule, but they don't interact. That is, `EXPECT_CALL`s have their
own precedence order distinct from the `ON_CALL` precedence order.
-#### Using Functions/Methods/Functors/Lambdas as Actions {#FunctionsAsActions}
+### Using Functions/Methods/Functors/Lambdas as Actions {#FunctionsAsActions}
If the built-in actions don't suit you, you can use an existing callable
(function, `std::function`, method, functor, lambda as an action.
@@ -2236,7 +2236,7 @@ as long as it's safe to do so - nice, huh?
... Invoke(implicit_cast<Closure*>(done)) ...; // The cast is necessary.
```
-#### Using Functions with Extra Info as Actions
+### Using Functions with Extra Info as Actions
The function or functor you call using `Invoke()` must have the same number of
arguments as the mock function you use it for. Sometimes you may have a function
@@ -2266,7 +2266,7 @@ TEST_F(FooTest, Test) {
}
```
-#### Invoking a Function/Method/Functor/Lambda/Callback Without Arguments
+### Invoking a Function/Method/Functor/Lambda/Callback Without Arguments
`Invoke()` is very useful for doing actions that are more complex. It passes the
mock function's arguments to the function, etc being invoked such that the
@@ -2322,7 +2322,7 @@ bool Job2(int n, char c) { ... }
// The cast is necessary.
```
-#### Invoking an Argument of the Mock Function
+### Invoking an Argument of the Mock Function
Sometimes a mock function will receive a function pointer, a functor (in other
words, a "callable") as an argument, e.g.
@@ -2421,7 +2421,7 @@ temporary value:
// are kept inside the InvokeArgument action.
```
-#### Ignoring an Action's Result
+### Ignoring an Action's Result
Sometimes you have an action that returns *something*, but you need an action
that returns `void` (perhaps you want to use it in a mock function that returns
@@ -2459,7 +2459,7 @@ class MockFoo : public Foo {
Note that you **cannot** use `IgnoreResult()` on an action that already returns
`void`. Doing so will lead to ugly compiler errors.
-#### Selecting an Action's Arguments {#SelectingArgs}
+### Selecting an Action's Arguments {#SelectingArgs}
Say you have a mock function `Foo()` that takes seven arguments, and you have a
custom action that you want to invoke when `Foo()` is called. Trouble is, the
@@ -2543,7 +2543,7 @@ Here are more tips:
if the 4-th argument of the mock function is an `int` and `my_action` takes
a `double`, `WithArg<4>(my_action)` will work.
-#### Ignoring Arguments in Action Functions
+### Ignoring Arguments in Action Functions
The [selecting-an-action's-arguments](#SelectingArgs) recipe showed us one way
to make a mock function and an action with incompatible argument lists fit
@@ -2600,7 +2600,7 @@ double DistanceToOrigin(Unused, double x, double y) {
.WillOnce(Invoke(DistanceToOrigin));
```
-#### Sharing Actions
+### Sharing Actions
Just like matchers, a gMock action object consists of a pointer to a ref-counted
implementation object. Therefore copying actions is also allowed and very
@@ -2656,7 +2656,7 @@ using ::testing::Action;
foo.DoThat(); // Returns 3 - the counter is shared.
```
-#### Testing Asynchronous Behavior
+### Testing Asynchronous Behavior
One oft-encountered problem with gMock is that it can be hard to test
asynchronous behavior. Suppose you had a `EventQueue` class that you wanted to
@@ -2705,9 +2705,9 @@ our test will run forever. It will eventually time-out and fail, but it will
take longer and be slightly harder to debug. To alleviate this problem, you can
use `WaitForNotificationWithTimeout(ms)` instead of `WaitForNotification()`.
-### Misc Recipes on Using gMock
+## Misc Recipes on Using gMock
-#### Mocking Methods That Use Move-Only Types
+### Mocking Methods That Use Move-Only Types
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
@@ -2847,7 +2847,7 @@ 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}
+#### 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
@@ -2879,7 +2879,7 @@ method:
mock_buzzer_.ShareBuzz(MakeUnique<Buzz>(AccessLevel::kInternal), 0);
```
-#### Making the Compilation Faster
+### Making the Compilation Faster
Believe it or not, the *vast majority* of the time spent on compiling a mock
class is in generating its constructor and destructor, as they perform
@@ -2943,7 +2943,7 @@ MockFoo::MockFoo() {}
MockFoo::~MockFoo() {}
```
-#### Forcing a Verification
+### Forcing a Verification
When it's being destroyed, your friendly mock object will automatically verify
that all expectations on it have been satisfied, and will generate googletest
@@ -2984,7 +2984,7 @@ indicate whether the verification was successful (`true` for yes), so you can
wrap that function call inside a `ASSERT_TRUE()` if there is no point going
further when the verification has failed.
-#### Using Check Points {#UsingCheckPoints}
+### Using Check Points {#UsingCheckPoints}
Sometimes you may want to "reset" a mock object at various check points in your
test: at each check point, you verify that all existing expectations on the mock
@@ -3048,7 +3048,7 @@ point "1", the second `Bar("a")` must happen after check point "2", and nothing
should happen between the two check points. The explicit check points make it
easy to tell which `Bar("a")` is called by which call to `Foo()`.
-#### Mocking Destructors
+### Mocking Destructors
Sometimes you want to make sure a mock object is destructed at the right time,
e.g. after `bar->A()` is called but before `bar->B()` is called. We already know
@@ -3096,7 +3096,7 @@ testing when its `Die()` method is called:
And that's that.
-#### Using gMock and Threads {#UsingThreads}
+### Using gMock and Threads {#UsingThreads}
In a **unit** test, it's best if you could isolate and test a piece of code in a
single-threaded context. That avoids race conditions and dead locks, and makes
@@ -3154,7 +3154,7 @@ Also, remember that `DefaultValue<T>` is a global resource that potentially
affects *all* living mock objects in your program. Naturally, you won't want to
mess with it from multiple threads or when there still are mocks in action.
-#### Controlling How Much Information gMock Prints
+### Controlling How Much Information gMock Prints
When gMock sees something that has the potential of being an error (e.g. a mock
function with no expectation is called, a.k.a. an uninteresting call, which is
@@ -3193,7 +3193,7 @@ warning messages, remember that you can control their amount with the
Now, judiciously use the right flag to enable gMock serve you better!
-#### Gaining Super Vision into Mock Calls
+### Gaining Super Vision into Mock Calls
You have a test using gMock. It fails: gMock tells you some expectations aren't
satisfied. However, you aren't sure why: Is there a typo somewhere in the
@@ -3273,7 +3273,7 @@ command line.
<!-- GOOGLETEST_CM0025 DO NOT DELETE -->
-#### Running Tests in Emacs
+### Running Tests in Emacs
If you build and run your tests in Emacs using the `M-x google-compile` command
(as many googletest users do), the source file locations of gMock and googletest
@@ -3293,9 +3293,9 @@ Then you can type `M-m` to start a build (if you want to run the test as well,
just make sure `foo_test.run` or `runtests` is in the build command you supply
after typing `M-m`), or `M-up`/`M-down` to move back and forth between errors.
-### Extending gMock
+## Extending gMock
-#### Writing New Matchers Quickly {#NewMatchers}
+### Writing New Matchers Quickly {#NewMatchers}
WARNING: gMock does not guarantee when or how many times a matcher will be
invoked. Therefore, all matchers must be functionally pure. See
@@ -3409,7 +3409,7 @@ any type where the value of `(arg % 7) == 0` can be implicitly converted to a
`int`, `arg_type` will be `int`; if it takes an `unsigned long`, `arg_type` will
be `unsigned long`; and so on.
-#### Writing New Parameterized Matchers Quickly
+### Writing New Parameterized Matchers Quickly
Sometimes you'll want to define a matcher that has parameters. For that you can
use the macro:
@@ -3546,7 +3546,7 @@ matcher parameters, which in general leads to better compiler error messages
that pay off in the long run. They also allow overloading matchers based on
parameter types (as opposed to just based on the number of parameters).
-#### Writing New Monomorphic Matchers
+### Writing New Monomorphic Matchers
A matcher of argument type `T` implements `::testing::MatcherInterface<T>` and
does two things: it tests whether a value of type `T` matches the matcher, and
@@ -3573,7 +3573,7 @@ class MatcherInterface {
public:
virtual ~MatcherInterface();
- // Returns true if the matcher matches x; also explains the match
+ // Returns true if and only if the matcher matches x; also explains the match
// result to 'listener'.
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0;
@@ -3652,7 +3652,7 @@ Expected: is divisible by 7
Actual: 23 (the remainder is 2)
```
-#### Writing New Polymorphic Matchers
+### Writing New Polymorphic Matchers
You've learned how to write your own matchers in the previous recipe. Just one
problem: a matcher created using `MakeMatcher()` only works for one particular
@@ -3688,10 +3688,10 @@ class NotNullMatcher {
}
// Describes the property of a value matching this matcher.
- void DescribeTo(::std::ostream* os) const { *os << "is not NULL"; }
+ void DescribeTo(std::ostream* os) const { *os << "is not NULL"; }
// Describes the property of a value NOT matching this matcher.
- void DescribeNegationTo(::std::ostream* os) const { *os << "is NULL"; }
+ void DescribeNegationTo(std::ostream* os) const { *os << "is NULL"; }
};
// To construct a polymorphic matcher, pass an instance of the class
@@ -3712,7 +3712,7 @@ virtual.
Like in a monomorphic matcher, you may explain the match result by streaming
additional information to the `listener` argument in `MatchAndExplain()`.
-#### Writing New Cardinalities
+### Writing New Cardinalities
A cardinality is used in `Times()` to tell gMock how many times you expect a
call to occur. It doesn't have to be exact. For example, you can say
@@ -3727,14 +3727,15 @@ class CardinalityInterface {
public:
virtual ~CardinalityInterface();
- // Returns true if call_count calls will satisfy this cardinality.
+ // Returns true if and only if call_count calls will satisfy this cardinality.
virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
- // Returns true if call_count calls will saturate this cardinality.
+ // Returns true if and only if call_count calls will saturate this
+ // cardinality.
virtual bool IsSaturatedByCallCount(int call_count) const = 0;
// Describes self to an ostream.
- virtual void DescribeTo(::std::ostream* os) const = 0;
+ virtual void DescribeTo(std::ostream* os) const = 0;
};
```
@@ -3756,7 +3757,7 @@ class EvenNumberCardinality : public CardinalityInterface {
return false;
}
- void DescribeTo(::std::ostream* os) const {
+ void DescribeTo(std::ostream* os) const {
*os << "called even number of times";
}
};
@@ -3770,7 +3771,7 @@ Cardinality EvenNumber() {
.Times(EvenNumber());
```
-#### Writing New Actions Quickly {#QuickNewActions}
+### Writing New Actions Quickly {#QuickNewActions}
If the built-in actions don't work for you, you can easily define your own one.
Just define a functor class with a (possibly templated) call operator, matching
@@ -3799,7 +3800,7 @@ struct MultiplyBy {
// EXPECT_CALL(...).WillOnce(MultiplyBy{7});
```
-##### Legacy macro-based Actions
+#### Legacy macro-based Actions
Before C++11, the functor-based actions were not supported; the old way of
writing actions was through a set of `ACTION*` macros. We suggest to avoid them
@@ -3878,7 +3879,7 @@ Pre-defined Symbol | Is Bound To
`return_type` | the type `int`
`function_type` | the type `int(bool, int*)`
-##### Legacy macro-based parameterized Actions
+#### Legacy macro-based parameterized Actions
Sometimes you'll want to parameterize an action you define. For that we have
another macro
@@ -3937,7 +3938,7 @@ ACTION_P(Plus, a) { ... }
ACTION_P2(Plus, a, b) { ... }
```
-#### Restricting the Type of an Argument or Parameter in an ACTION
+### Restricting the Type of an Argument or Parameter in an ACTION
For maximum brevity and reusability, the `ACTION*` macros don't ask you to
provide the types of the mock function arguments and the action parameters.
@@ -3965,7 +3966,7 @@ ACTION_P(Bar, param) {
where `StaticAssertTypeEq` is a compile-time assertion in googletest that
verifies two types are the same.
-#### Writing New Action Templates Quickly
+### Writing New Action Templates Quickly
Sometimes you want to give an action explicit template parameters that cannot be
inferred from its value parameters. `ACTION_TEMPLATE()` supports that and can be
@@ -4035,7 +4036,7 @@ Are we using a single-template-parameter action where `bool` refers to the type
of `x`, or a two-template-parameter action where the compiler is asked to infer
the type of `x`?
-#### Using the ACTION Object's Type
+### Using the ACTION Object's Type
If you are writing a function that returns an `ACTION` object, you'll need to
know its type. The type depends on the macro used to define the action and the
@@ -4062,7 +4063,7 @@ Note that we have to pick different suffixes (`Action`, `ActionP`, `ActionP2`,
and etc) for actions with different numbers of value parameters, or the action
definitions cannot be overloaded on the number of them.
-#### Writing New Monomorphic Actions {#NewMonoActions}
+### Writing New Monomorphic Actions {#NewMonoActions}
While the `ACTION*` macros are very convenient, sometimes they are
inappropriate. For example, despite the tricks shown in the previous recipes,
@@ -4119,7 +4120,7 @@ Action<IncrementMethod> IncrementArgument() {
foo.Baz(&n); // Should return 5 and change n to 6.
```
-#### Writing New Polymorphic Actions {#NewPolyActions}
+### Writing New Polymorphic Actions {#NewPolyActions}
The previous recipe showed you how to define your own action. This is all good,
except that you need to know the type of the function in which the action will
@@ -4195,7 +4196,7 @@ class MockFoo : public Foo {
foo.DoThat(1, "Hi", "Bye"); // Will return "Hi".
```
-#### Teaching gMock How to Print Your Values
+### Teaching gMock How to Print Your Values
When an uninteresting or unexpected call occurs, gMock prints the argument
values and the stack trace to help you debug. Assertion macros like
@@ -4210,12 +4211,12 @@ prints the raw bytes in the value and hopes that you the user can figure it out.
explains how to extend the printer to do a better job at printing your
particular type than to dump the bytes.
-### Useful Mocks Created Using gMock
+## Useful Mocks Created Using gMock
<!--#include file="includes/g3_testing_LOGs.md"-->
<!--#include file="includes/g3_mock_callbacks.md"-->
-#### Mock std::function {#MockFunction}
+### Mock std::function {#MockFunction}
`std::function` is a general function type introduced in C++11. It is a
preferred way of passing callbacks to new interfaces. Functions are copiable,
diff --git a/googlemock/docs/for_dummies.md b/googlemock/docs/for_dummies.md
index e11c18d9..93cf06f3 100644
--- a/googlemock/docs/for_dummies.md
+++ b/googlemock/docs/for_dummies.md
@@ -213,7 +213,7 @@ specific domain much better than `Foo` does.
Once you have a mock class, using it is easy. The typical work flow is:
1. Import the gMock names from the `testing` namespace such that you can use
- them unqualified (You only have to do it once per file. Remember that
+ them unqualified (You only have to do it once per file). Remember that
namespaces are a good idea.
2. Create some mock objects.
3. Specify your expectations on them (How many times will a method be called?
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index 9605c43a..f12d39be 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -99,7 +99,8 @@ struct BuiltInDefaultValueGetter<T, false> {
template <typename T>
class BuiltInDefaultValue {
public:
- // This function returns true if type T has a built-in default value.
+ // This function returns true if and only if type T has a built-in default
+ // value.
static bool Exists() {
return ::std::is_default_constructible<T>::value;
}
@@ -208,7 +209,7 @@ class DefaultValue {
producer_ = nullptr;
}
- // Returns true if the user has set the default value for type T.
+ // Returns true if and only if the user has set the default value for type T.
static bool IsSet() { return producer_ != nullptr; }
// Returns true if T has a default return value set by the user or there
@@ -269,7 +270,7 @@ class DefaultValue<T&> {
// Unsets the default value for type T&.
static void Clear() { address_ = nullptr; }
- // Returns true if the user has set the default value for type T&.
+ // Returns true if and only if the user has set the default value for type T&.
static bool IsSet() { return address_ != nullptr; }
// Returns true if T has a default return value set by the user or there
@@ -375,7 +376,7 @@ class Action {
template <typename Func>
explicit Action(const Action<Func>& action) : fun_(action.fun_) {}
- // Returns true if this is the DoDefault() action.
+ // Returns true if and only if this is the DoDefault() action.
bool IsDoDefault() const { return fun_ == nullptr; }
// Performs the action. Note that this method is const even though
@@ -395,7 +396,7 @@ class Action {
template <typename G>
friend class Action;
- // fun_ is an empty function if this is the DoDefault() action.
+ // fun_ is an empty function if and only if this is the DoDefault() action.
::std::function<F> fun_;
};
@@ -619,7 +620,7 @@ class ReturnVoidAction {
// Allows Return() to be used in any void-returning function.
template <typename Result, typename ArgumentTuple>
static void Perform(const ArgumentTuple&) {
- CompileAssertTypesEqual<void, Result>();
+ static_assert(std::is_void<Result>::value, "Result should be void.");
}
};
@@ -842,7 +843,7 @@ class IgnoreResultAction {
typedef typename internal::Function<F>::Result Result;
// Asserts at compile time that F returns void.
- CompileAssertTypesEqual<void, Result>();
+ static_assert(std::is_void<Result>::value, "Result type should be void.");
return Action<F>(new Impl<F>(action_));
}
diff --git a/googlemock/include/gmock/gmock-cardinalities.h b/googlemock/include/gmock/gmock-cardinalities.h
index 4b269a3e..46e01e10 100644
--- a/googlemock/include/gmock/gmock-cardinalities.h
+++ b/googlemock/include/gmock/gmock-cardinalities.h
@@ -70,10 +70,12 @@ class CardinalityInterface {
virtual int ConservativeLowerBound() const { return 0; }
virtual int ConservativeUpperBound() const { return INT_MAX; }
- // Returns true if call_count calls will satisfy this cardinality.
+ // Returns true if and only if call_count calls will satisfy this
+ // cardinality.
virtual bool IsSatisfiedByCallCount(int call_count) const = 0;
- // Returns true if call_count calls will saturate this cardinality.
+ // Returns true if and only if call_count calls will saturate this
+ // cardinality.
virtual bool IsSaturatedByCallCount(int call_count) const = 0;
// Describes self to an ostream.
@@ -98,17 +100,19 @@ class GTEST_API_ Cardinality {
int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); }
int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); }
- // Returns true if call_count calls will satisfy this cardinality.
+ // Returns true if and only if call_count calls will satisfy this
+ // cardinality.
bool IsSatisfiedByCallCount(int call_count) const {
return impl_->IsSatisfiedByCallCount(call_count);
}
- // Returns true if call_count calls will saturate this cardinality.
+ // Returns true if and only if call_count calls will saturate this
+ // cardinality.
bool IsSaturatedByCallCount(int call_count) const {
return impl_->IsSaturatedByCallCount(call_count);
}
- // Returns true if call_count calls will over-saturate this
+ // Returns true if and only if call_count calls will over-saturate this
// cardinality, i.e. exceed the maximum number of allowed calls.
bool IsOverSaturatedByCallCount(int call_count) const {
return impl_->IsSaturatedByCallCount(call_count) &&
diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h
index cc1535c8..684db139 100644
--- a/googlemock/include/gmock/gmock-function-mocker.h
+++ b/googlemock/include/gmock/gmock-function-mocker.h
@@ -39,6 +39,13 @@
#include "gmock/gmock-generated-function-mockers.h" // NOLINT
#include "gmock/internal/gmock-pp.h"
+namespace testing {
+namespace internal {
+template <typename T>
+using identity_t = T;
+} // namespace internal
+} // namespace testing
+
#define MOCK_METHOD(...) \
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
@@ -207,10 +214,24 @@
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
-#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
- GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
- GMOCK_PP_IDENTITY) \
- (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
+// Note: The use of `identity_t` here allows _Ret to represent return types that
+// would normally need to be specified in a different way. For example, a method
+// returning a function pointer must be written as
+//
+// fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...)
+//
+// But we only support placing the return type at the beginning. To handle this,
+// we wrap all calls in identity_t, so that a declaration will be expanded to
+//
+// identity_t<fn_ptr_return_t (*)(fn_ptr_args_t...)> method(method_args_t...)
+//
+// This allows us to work around the syntactic oddities of function/method
+// types.
+#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
+ ::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \
+ GMOCK_PP_REMOVE_PARENS, \
+ GMOCK_PP_IDENTITY)(_Ret)>( \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
GMOCK_PP_COMMA_IF(_i) \
diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h
index 981af78f..cee96dae 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h
+++ b/googlemock/include/gmock/gmock-generated-actions.h
@@ -663,7 +663,7 @@ class ActionHelper {
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -726,7 +726,7 @@ class ActionHelper {
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
gmock_Impl() {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -776,7 +776,7 @@ class ActionHelper {
args_type;\
explicit gmock_Impl(p0##_type gmock_p0) : \
p0(::std::forward<p0##_type>(gmock_p0)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -832,7 +832,7 @@ class ActionHelper {
gmock_Impl(p0##_type gmock_p0, \
p1##_type gmock_p1) : p0(::std::forward<p0##_type>(gmock_p0)), \
p1(::std::forward<p1##_type>(gmock_p1)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -893,7 +893,7 @@ class ActionHelper {
p2##_type gmock_p2) : p0(::std::forward<p0##_type>(gmock_p0)), \
p1(::std::forward<p1##_type>(gmock_p1)), \
p2(::std::forward<p2##_type>(gmock_p2)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -961,7 +961,7 @@ class ActionHelper {
p1(::std::forward<p1##_type>(gmock_p1)), \
p2(::std::forward<p2##_type>(gmock_p2)), \
p3(::std::forward<p3##_type>(gmock_p3)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1038,7 +1038,7 @@ class ActionHelper {
p2(::std::forward<p2##_type>(gmock_p2)), \
p3(::std::forward<p3##_type>(gmock_p3)), \
p4(::std::forward<p4##_type>(gmock_p4)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1119,7 +1119,7 @@ class ActionHelper {
p3(::std::forward<p3##_type>(gmock_p3)), \
p4(::std::forward<p4##_type>(gmock_p4)), \
p5(::std::forward<p5##_type>(gmock_p5)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1206,7 +1206,7 @@ class ActionHelper {
p4(::std::forward<p4##_type>(gmock_p4)), \
p5(::std::forward<p5##_type>(gmock_p5)), \
p6(::std::forward<p6##_type>(gmock_p6)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1302,7 +1302,7 @@ class ActionHelper {
p5(::std::forward<p5##_type>(gmock_p5)), \
p6(::std::forward<p6##_type>(gmock_p6)), \
p7(::std::forward<p7##_type>(gmock_p7)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1404,7 +1404,7 @@ class ActionHelper {
p6(::std::forward<p6##_type>(gmock_p6)), \
p7(::std::forward<p7##_type>(gmock_p7)), \
p8(::std::forward<p8##_type>(gmock_p8)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -1513,7 +1513,7 @@ class ActionHelper {
p7(::std::forward<p7##_type>(gmock_p7)), \
p8(::std::forward<p8##_type>(gmock_p8)), \
p9(::std::forward<p9##_type>(gmock_p9)) {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 209603c5..283abcdc 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -395,7 +395,7 @@ $range k 0..n-1
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
@@ -482,7 +482,7 @@ $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
typedef typename ::testing::internal::Function<F>::ArgumentTuple\
args_type;\
[[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\
- virtual return_type Perform(const args_type& args) {\
+ return_type Perform(const args_type& args) override {\
return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
Perform(this, args);\
}\
diff --git a/googlemock/include/gmock/gmock-generated-matchers.h b/googlemock/include/gmock/gmock-generated-matchers.h
index 690a57f1..61892380 100644
--- a/googlemock/include/gmock/gmock-generated-matchers.h
+++ b/googlemock/include/gmock/gmock-generated-matchers.h
@@ -269,13 +269,13 @@
public:\
gmock_Impl()\
{}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
private:\
@@ -318,13 +318,13 @@
public:\
explicit gmock_Impl(p0##_type gmock_p0)\
: p0(::std::move(gmock_p0)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -371,13 +371,13 @@
public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -431,13 +431,13 @@
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -495,13 +495,13 @@
p3##_type gmock_p3)\
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -568,13 +568,13 @@
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -644,13 +644,13 @@
: p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1)), \
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -726,13 +726,13 @@
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -814,13 +814,13 @@
p2(::std::move(gmock_p2)), p3(::std::move(gmock_p3)), \
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -909,13 +909,13 @@
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
p8(::std::move(gmock_p8)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
@@ -1009,13 +1009,13 @@
p4(::std::move(gmock_p4)), p5(::std::move(gmock_p5)), \
p6(::std::move(gmock_p6)), p7(::std::move(gmock_p7)), \
p8(::std::move(gmock_p8)), p9(::std::move(gmock_p9)) {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\
p0##_type const p0;\
diff --git a/googlemock/include/gmock/gmock-generated-matchers.h.pump b/googlemock/include/gmock/gmock-generated-matchers.h.pump
index ae90917c..69d2ae41 100644
--- a/googlemock/include/gmock/gmock-generated-matchers.h.pump
+++ b/googlemock/include/gmock/gmock-generated-matchers.h.pump
@@ -302,13 +302,13 @@ $var param_field_decls2 = [[$for j
public:\
[[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
$impl_inits {}\
- virtual bool MatchAndExplain(\
+ bool MatchAndExplain(\
GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
- ::testing::MatchResultListener* result_listener) const;\
- virtual void DescribeTo(::std::ostream* gmock_os) const {\
+ ::testing::MatchResultListener* result_listener) const override;\
+ void DescribeTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(false);\
}\
- virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
+ void DescribeNegationTo(::std::ostream* gmock_os) const override {\
*gmock_os << FormatDescription(true);\
}\$param_field_decls
private:\
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 70092157..be446aad 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -42,8 +42,8 @@
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
-#include <math.h>
#include <algorithm>
+#include <cmath>
#include <initializer_list>
#include <iterator>
#include <limits>
@@ -54,6 +54,7 @@
#include <type_traits>
#include <utility>
#include <vector>
+
#include "gmock/internal/gmock-internal-utils.h"
#include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h"
@@ -358,8 +359,8 @@ template <size_t N>
class TuplePrefix {
public:
// TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
- // if the first N fields of matcher_tuple matches the first N
- // fields of value_tuple, respectively.
+ // if and only if the first N fields of matcher_tuple matches
+ // the first N fields of value_tuple, respectively.
template <typename MatcherTuple, typename ValueTuple>
static bool Matches(const MatcherTuple& matcher_tuple,
const ValueTuple& value_tuple) {
@@ -417,8 +418,8 @@ class TuplePrefix<0> {
::std::ostream* /* os */) {}
};
-// TupleMatches(matcher_tuple, value_tuple) returns true if all
-// matchers in matcher_tuple match the corresponding fields in
+// TupleMatches(matcher_tuple, value_tuple) returns true if and only if
+// all matchers in matcher_tuple match the corresponding fields in
// value_tuple. It is a compiler error if matcher_tuple and
// value_tuple have different number of fields or incompatible field
// types.
@@ -1349,6 +1350,22 @@ MakePredicateFormatterFromMatcher(M matcher) {
return PredicateFormatterFromMatcher<M>(std::move(matcher));
}
+// Implements the polymorphic IsNan() matcher, which matches any floating type
+// value that is Nan.
+class IsNanMatcher {
+ public:
+ template <typename FloatType>
+ bool MatchAndExplain(const FloatType& f,
+ MatchResultListener* /* listener */) const {
+ return (::std::isnan)(f);
+ }
+
+ void DescribeTo(::std::ostream* os) const { *os << "is NaN"; }
+ void DescribeNegationTo(::std::ostream* os) const {
+ *os << "isn't NaN";
+ }
+};
+
// Implements the polymorphic floating point equality matcher, which matches
// two float values using ULP-based approximation or, optionally, a
// user-specified epsilon. The template is meant to be instantiated with
@@ -1409,7 +1426,7 @@ class FloatingEqMatcher {
}
const FloatType diff = value - expected_;
- if (fabs(diff) <= max_abs_error_) {
+ if (::std::fabs(diff) <= max_abs_error_) {
return true;
}
@@ -1607,8 +1624,8 @@ class PointeeMatcher {
template <typename Pointer>
class Impl : public MatcherInterface<Pointer> {
public:
- typedef typename PointeeOf<typename std::remove_const<
- typename std::remove_reference<Pointer>::type>::type>::type Pointee;
+ typedef typename PointeeOf<GTEST_REMOVE_REFERENCE_AND_CONST_(Pointer)>::type
+ Pointee;
explicit Impl(const InnerMatcher& matcher)
: matcher_(MatcherCast<const Pointee&>(matcher)) {}
@@ -1858,7 +1875,9 @@ struct CallableTraits {
static void CheckIsValid(Functor /* functor */) {}
template <typename T>
- static auto Invoke(Functor f, T arg) -> decltype(f(arg)) { return f(arg); }
+ static auto Invoke(Functor f, const T& arg) -> decltype(f(arg)) {
+ return f(arg);
+ }
};
// Specialization for function pointers.
@@ -1889,7 +1908,7 @@ class ResultOfMatcher {
template <typename T>
operator Matcher<T>() const {
- return Matcher<T>(new Impl<T>(callable_, matcher_));
+ return Matcher<T>(new Impl<const T&>(callable_, matcher_));
}
private:
@@ -2068,15 +2087,15 @@ class ContainerEqMatcher {
typedef typename View::type StlContainer;
typedef typename View::const_reference StlContainerReference;
+ static_assert(!std::is_const<Container>::value,
+ "Container type must not be const");
+ static_assert(!std::is_reference<Container>::value,
+ "Container type must not be a reference");
+
// We make a copy of expected in case the elements in it are modified
// after this matcher is created.
explicit ContainerEqMatcher(const Container& expected)
- : expected_(View::Copy(expected)) {
- // Makes sure the user doesn't instantiate this class template
- // with a const or reference type.
- (void)testing::StaticAssertTypeEq<Container,
- GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
- }
+ : expected_(View::Copy(expected)) {}
void DescribeTo(::std::ostream* os) const {
*os << "equals ";
@@ -2243,15 +2262,15 @@ class PointwiseMatcher {
typedef typename RhsView::type RhsStlContainer;
typedef typename RhsStlContainer::value_type RhsValue;
+ static_assert(!std::is_const<RhsContainer>::value,
+ "RhsContainer type must not be const");
+ static_assert(!std::is_reference<RhsContainer>::value,
+ "RhsContainer type must not be a reference");
+
// Like ContainerEq, we make a copy of rhs in case the elements in
// it are modified after this matcher is created.
PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& rhs)
- : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
- // Makes sure the user doesn't instantiate this class template
- // with a const or reference type.
- (void)testing::StaticAssertTypeEq<RhsContainer,
- GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
- }
+ : tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {}
template <typename LhsContainer>
operator Matcher<LhsContainer>() const {
@@ -2530,7 +2549,8 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
}
- // Returns true if 'key_value.first' (the key) matches the inner matcher.
+ // Returns true if and only if 'key_value.first' (the key) matches the inner
+ // matcher.
bool MatchAndExplain(PairType key_value,
MatchResultListener* listener) const override {
StringMatchResultListener inner_listener;
@@ -2612,8 +2632,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
second_matcher_.DescribeNegationTo(os);
}
- // Returns true if 'a_pair.first' matches first_matcher and 'a_pair.second'
- // matches second_matcher.
+ // Returns true if and only if 'a_pair.first' matches first_matcher and
+ // 'a_pair.second' matches second_matcher.
bool MatchAndExplain(PairType a_pair,
MatchResultListener* listener) const override {
if (!listener->IsInterested()) {
@@ -3148,8 +3168,8 @@ class ElementsAreArrayMatcher {
// Given a 2-tuple matcher tm of type Tuple2Matcher and a value second
// of type Second, BoundSecondMatcher<Tuple2Matcher, Second>(tm,
-// second) is a polymorphic matcher that matches a value x if tm
-// matches tuple (x, second). Useful for implementing
+// second) is a polymorphic matcher that matches a value x if and only if
+// tm matches tuple (x, second). Useful for implementing
// UnorderedPointwise() in terms of UnorderedElementsAreArray().
//
// BoundSecondMatcher is copyable and assignable, as we need to put
@@ -3213,8 +3233,8 @@ class BoundSecondMatcher {
// Given a 2-tuple matcher tm and a value second,
// MatcherBindSecond(tm, second) returns a matcher that matches a
-// value x if tm matches tuple (x, second). Useful for implementing
-// UnorderedPointwise() in terms of UnorderedElementsAreArray().
+// value x if and only if tm matches tuple (x, second). Useful for
+// implementing UnorderedPointwise() in terms of UnorderedElementsAreArray().
template <typename Tuple2Matcher, typename Second>
BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
const Tuple2Matcher& tm, const Second& second) {
@@ -3623,6 +3643,11 @@ inline internal::RefMatcher<T&> Ref(T& x) { // NOLINT
return internal::RefMatcher<T&>(x);
}
+// Creates a polymorphic matcher that matches any NaN floating point.
+inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
+ return MakePolymorphicMatcher(internal::IsNanMatcher());
+}
+
// Creates a matcher that matches any double argument approximately
// equal to rhs, where two NANs are considered unequal.
inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
@@ -3705,7 +3730,7 @@ WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
// Creates a matcher that matches an object whose given field matches
// 'matcher'. For example,
// Field(&Foo::number, Ge(5))
-// matches a Foo object x if x.number >= 5.
+// matches a Foo object x if and only if x.number >= 5.
template <typename Class, typename FieldType, typename FieldMatcher>
inline PolymorphicMatcher<
internal::FieldMatcher<Class, FieldType> > Field(
@@ -3732,7 +3757,7 @@ inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field(
// Creates a matcher that matches an object whose given property
// matches 'matcher'. For example,
// Property(&Foo::str, StartsWith("hi"))
-// matches a Foo object x if x.str() starts with "hi".
+// matches a Foo object x if and only if x.str() starts with "hi".
template <typename Class, typename PropertyType, typename PropertyMatcher>
inline PolymorphicMatcher<internal::PropertyMatcher<
Class, PropertyType, PropertyType (Class::*)() const> >
@@ -3787,11 +3812,10 @@ Property(const std::string& property_name,
property_name, property, MatcherCast<const PropertyType&>(matcher)));
}
-// Creates a matcher that matches an object if the result of applying
-// a callable to x matches 'matcher'.
-// For example,
+// Creates a matcher that matches an object if and only if the result of
+// applying a callable to x matches 'matcher'. For example,
// ResultOf(f, StartsWith("hi"))
-// matches a Foo object x if f(x) starts with "hi".
+// matches a Foo object x if and only if f(x) starts with "hi".
// `callable` parameter can be a function, function pointer, or a functor. It is
// required to keep no state affecting the results of the calls on it and make
// no assumptions about how many calls will be made. Any state it keeps must be
@@ -4341,7 +4365,7 @@ inline internal::MatcherAsPredicate<M> Matches(M matcher) {
return internal::MatcherAsPredicate<M>(matcher);
}
-// Returns true if the value matches the matcher.
+// Returns true if and only if the value matches the matcher.
template <typename T, typename M>
inline bool Value(const T& value, M matcher) {
return testing::Matches(matcher)(value);
@@ -4547,8 +4571,8 @@ PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
// These macros allow using matchers to check values in Google Test
// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
-// succeed if the value matches the matcher. If the assertion fails,
-// the value and the description of the matcher will be printed.
+// succeed if and only if the value matches the matcher. If the assertion
+// fails, the value and the description of the matcher will be printed.
#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\
::testing::internal::MakePredicateFormatterFromMatcher(matcher), value)
#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\
diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h
index 66429dfa..80c13b55 100644
--- a/googlemock/include/gmock/gmock-spec-builders.h
+++ b/googlemock/include/gmock/gmock-spec-builders.h
@@ -332,7 +332,7 @@ class OnCallSpec : public UntypedOnCallSpecBase {
return *this;
}
- // Returns true if the given arguments match the matchers.
+ // Returns true if and only if the given arguments match the matchers.
bool Matches(const ArgumentTuple& args) const {
return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
}
@@ -390,7 +390,7 @@ class GTEST_API_ Mock {
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
// Verifies all expectations on the given mock object and clears its
- // default actions and expectations. Returns true if the
+ // default actions and expectations. Returns true if and only if the
// verification was successful.
static bool VerifyAndClear(void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
@@ -516,7 +516,8 @@ class GTEST_API_ Expectation {
// The compiler-generated copy ctor and operator= work exactly as
// intended, so we don't need to define our own.
- // Returns true if rhs references the same expectation as this object does.
+ // Returns true if and only if rhs references the same expectation as this
+ // object does.
bool operator==(const Expectation& rhs) const {
return expectation_base_ == rhs.expectation_base_;
}
@@ -598,8 +599,8 @@ class ExpectationSet {
// The compiler-generator ctor and operator= works exactly as
// intended, so we don't need to define our own.
- // Returns true if rhs contains the same set of Expectation objects
- // as this does.
+ // Returns true if and only if rhs contains the same set of Expectation
+ // objects as this does.
bool operator==(const ExpectationSet& rhs) const {
return expectations_ == rhs.expectations_;
}
@@ -760,8 +761,8 @@ class GTEST_API_ ExpectationBase {
// by the subclasses to implement the .Times() clause.
void SpecifyCardinality(const Cardinality& cardinality);
- // Returns true if the user specified the cardinality explicitly
- // using a .Times().
+ // Returns true if and only if the user specified the cardinality
+ // explicitly using a .Times().
bool cardinality_specified() const { return cardinality_specified_; }
// Sets the cardinality of this expectation spec.
@@ -777,7 +778,7 @@ class GTEST_API_ ExpectationBase {
void RetireAllPreRequisites()
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
- // Returns true if this expectation is retired.
+ // Returns true if and only if this expectation is retired.
bool is_retired() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
@@ -791,28 +792,29 @@ class GTEST_API_ ExpectationBase {
retired_ = true;
}
- // Returns true if this expectation is satisfied.
+ // Returns true if and only if this expectation is satisfied.
bool IsSatisfied() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
return cardinality().IsSatisfiedByCallCount(call_count_);
}
- // Returns true if this expectation is saturated.
+ // Returns true if and only if this expectation is saturated.
bool IsSaturated() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
return cardinality().IsSaturatedByCallCount(call_count_);
}
- // Returns true if this expectation is over-saturated.
+ // Returns true if and only if this expectation is over-saturated.
bool IsOverSaturated() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
return cardinality().IsOverSaturatedByCallCount(call_count_);
}
- // Returns true if all pre-requisites of this expectation are satisfied.
+ // Returns true if and only if all pre-requisites of this expectation are
+ // satisfied.
bool AllPrerequisitesAreSatisfied() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
@@ -855,7 +857,7 @@ class GTEST_API_ ExpectationBase {
const char* file_; // The file that contains the expectation.
int line_; // The line number of the expectation.
const std::string source_text_; // The EXPECT_CALL(...) source text.
- // True if the cardinality is specified explicitly.
+ // True if and only if the cardinality is specified explicitly.
bool cardinality_specified_;
Cardinality cardinality_; // The cardinality of the expectation.
// The immediate pre-requisites (i.e. expectations that must be
@@ -869,7 +871,7 @@ class GTEST_API_ ExpectationBase {
// This group of fields are the current state of the expectation,
// and can change as the mock function is called.
int call_count_; // How many times this expectation has been invoked.
- bool retired_; // True if this expectation has retired.
+ bool retired_; // True if and only if this expectation has retired.
UntypedActions untyped_actions_;
bool extra_matcher_specified_;
bool repeated_action_specified_; // True if a WillRepeatedly() was specified.
@@ -1087,14 +1089,15 @@ class TypedExpectation : public ExpectationBase {
// statement finishes and when the current thread holds
// g_gmock_mutex.
- // Returns true if this expectation matches the given arguments.
+ // Returns true if and only if this expectation matches the given arguments.
bool Matches(const ArgumentTuple& args) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
}
- // Returns true if this expectation should handle the given arguments.
+ // Returns true if and only if this expectation should handle the given
+ // arguments.
bool ShouldHandleArguments(const ArgumentTuple& args) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index 53b6d976..584afa98 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -157,11 +157,11 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
static_cast< ::testing::internal::TypeKind>( \
::testing::internal::KindOf<type>::value)
-// Evaluates to true if integer type T is signed.
+// Evaluates to true if and only if integer type T is signed.
#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
-// is true if arithmetic type From can be losslessly converted to
+// is true if and only if arithmetic type From can be losslessly converted to
// arithmetic type To.
//
// It's the user's responsibility to ensure that both From and To are
@@ -192,8 +192,8 @@ template <typename From>
struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
: public std::false_type {};
-// Converting an integer to another non-bool integer is lossless if
-// the target type's range encloses the source type's range.
+// Converting an integer to another non-bool integer is lossless
+// if and only if the target type's range encloses the source type's range.
template <typename From, typename To>
struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
: public bool_constant<
@@ -224,14 +224,14 @@ struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
: public std::false_type {};
// Converting a floating-point to another floating-point is lossless
-// if the target type is at least as big as the source type.
+// if and only if the target type is at least as big as the source type.
template <typename From, typename To>
struct LosslessArithmeticConvertibleImpl<
kFloatingPoint, From, kFloatingPoint, To>
: public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
-// LosslessArithmeticConvertible<From, To>::value is true if arithmetic
-// type From can be losslessly converted to arithmetic type To.
+// LosslessArithmeticConvertible<From, To>::value is true if and only if
+// arithmetic type From can be losslessly converted to arithmetic type To.
//
// It's the user's responsibility to ensure that both From and To are
// raw (i.e. has no CV modifier, is not a pointer, and is not a
@@ -305,11 +305,11 @@ const char kWarningVerbosity[] = "warning";
// No logs are printed.
const char kErrorVerbosity[] = "error";
-// Returns true if a log with the given severity is visible according
-// to the --gmock_verbose flag.
+// Returns true if and only if a log with the given severity is visible
+// according to the --gmock_verbose flag.
GTEST_API_ bool LogIsVisible(LogSeverity severity);
-// Prints the given message to stdout if 'severity' >= the level
+// Prints the given message to stdout if and only if 'severity' >= the level
// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
// 0, also prints the stack trace excluding the top
// stack_frames_to_skip frames. In opt mode, any positive
@@ -334,8 +334,6 @@ class WithoutMatchers {
// Internal use only: access the singleton instance of WithoutMatchers.
GTEST_API_ WithoutMatchers GetWithoutMatchers();
-// Type traits.
-
// Disable MSVC warnings for infinite recursion, since in this case the
// the recursion is unreachable.
#ifdef _MSC_VER
@@ -384,9 +382,8 @@ class StlContainerView {
typedef const type& const_reference;
static const_reference ConstReference(const RawContainer& container) {
- // Ensures that RawContainer is not a const type.
- testing::StaticAssertTypeEq<
- RawContainer, typename std::remove_const<RawContainer>::type>();
+ static_assert(!std::is_const<RawContainer>::value,
+ "RawContainer type must not be const");
return container;
}
static type Copy(const RawContainer& container) { return container; }
@@ -406,8 +403,8 @@ class StlContainerView<Element[N]> {
typedef const type const_reference;
static const_reference ConstReference(const Element (&array)[N]) {
- // Ensures that Element is not a const type.
- testing::StaticAssertTypeEq<Element, RawElement>();
+ static_assert(std::is_same<Element, RawElement>::value,
+ "Element type must not be const");
return type(array, N, RelationToSourceReference());
}
static type Copy(const Element (&array)[N]) {
@@ -493,8 +490,7 @@ struct Function<R(Args...)> {
using Result = R;
static constexpr size_t ArgumentCount = sizeof...(Args);
template <size_t I>
- using Arg = ElemFromList<I, typename MakeIndexSequence<sizeof...(Args)>::type,
- Args...>;
+ using Arg = ElemFromList<I, Args...>;
using ArgumentTuple = std::tuple<Args...>;
using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
using MakeResultVoid = void(Args...);
diff --git a/googlemock/src/gmock-internal-utils.cc b/googlemock/src/gmock-internal-utils.cc
index 1292e1d8..e5b54798 100644
--- a/googlemock/src/gmock-internal-utils.cc
+++ b/googlemock/src/gmock-internal-utils.cc
@@ -123,8 +123,8 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter() {
// Protects global resources (stdout in particular) used by Log().
static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex);
-// Returns true if a log with the given severity is visible according
-// to the --gmock_verbose flag.
+// Returns true if and only if a log with the given severity is visible
+// according to the --gmock_verbose flag.
GTEST_API_ bool LogIsVisible(LogSeverity severity) {
if (GMOCK_FLAG(verbose) == kInfoVerbosity) {
// Always show the log if --gmock_verbose=info.
@@ -139,7 +139,7 @@ GTEST_API_ bool LogIsVisible(LogSeverity severity) {
}
}
-// Prints the given message to stdout if 'severity' >= the level
+// Prints the given message to stdout if and only if 'severity' >= the level
// specified by the --gmock_verbose flag. If stack_frames_to_skip >=
// 0, also prints the stack trace excluding the top
// stack_frames_to_skip frames. In opt mode, any positive
diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc
index f6705a32..81ea9894 100644
--- a/googlemock/src/gmock-spec-builders.cc
+++ b/googlemock/src/gmock-spec-builders.cc
@@ -36,14 +36,17 @@
#include "gmock/gmock-spec-builders.h"
#include <stdlib.h>
+
#include <iostream> // NOLINT
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
+
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+#include "gtest/internal/gtest-port.h"
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC
# include <unistd.h> // NOLINT
@@ -70,7 +73,8 @@ GTEST_API_ void LogWithLocation(testing::internal::LogSeverity severity,
const char* file, int line,
const std::string& message) {
::std::ostringstream s;
- s << file << ":" << line << ": " << message << ::std::endl;
+ s << internal::FormatFileLocation(file, line) << " " << message
+ << ::std::endl;
Log(severity, s.str(), 0);
}
@@ -126,8 +130,8 @@ void ExpectationBase::RetireAllPreRequisites()
}
}
-// Returns true if all pre-requisites of this expectation have been
-// satisfied.
+// Returns true if and only if all pre-requisites of this expectation
+// have been satisfied.
bool ExpectationBase::AllPrerequisitesAreSatisfied() const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld();
@@ -384,7 +388,7 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
const CallReaction reaction =
Mock::GetReactionOnUninterestingCalls(MockObject());
- // True if we need to print this call's arguments and return
+ // True if and only if we need to print this call's arguments and return
// value. This definition must be kept in sync with
// the behavior of ReportUninterestingCall().
const bool need_to_report_uninteresting_call =
@@ -435,7 +439,8 @@ UntypedActionResultHolderBase* UntypedFunctionMockerBase::UntypedInvokeWith(
&ss, &why);
const bool found = untyped_expectation != nullptr;
- // True if we need to print the call's arguments and return value.
+ // True if and only if we need to print the call's arguments
+ // and return value.
// This definition must be kept in sync with the uses of Expect()
// and Log() in this function.
const bool need_to_report_call =
@@ -574,7 +579,7 @@ struct MockObjectState {
int first_used_line;
::std::string first_used_test_suite;
::std::string first_used_test;
- bool leakable; // true if it's OK to leak the object.
+ bool leakable; // true if and only if it's OK to leak the object.
FunctionMockers function_mockers; // All registered methods of the object.
};
@@ -718,7 +723,7 @@ bool Mock::VerifyAndClearExpectations(void* mock_obj)
}
// Verifies all expectations on the given mock object and clears its
-// default actions and expectations. Returns true if the
+// default actions and expectations. Returns true if and only if the
// verification was successful.
bool Mock::VerifyAndClear(void* mock_obj)
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc
index ce926f2d..32b2a739 100644
--- a/googlemock/src/gmock.cc
+++ b/googlemock/src/gmock.cc
@@ -34,8 +34,8 @@
namespace testing {
GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
- "true if Google Mock should report leaked mock objects "
- "as failures.");
+ "true if and only if Google Mock should report leaked "
+ "mock objects as failures.");
GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
"Controls how verbose Google Mock's output is."
diff --git a/googlemock/test/gmock-cardinalities_test.cc b/googlemock/test/gmock-cardinalities_test.cc
index 66042d40..ca97cae2 100644
--- a/googlemock/test/gmock-cardinalities_test.cc
+++ b/googlemock/test/gmock-cardinalities_test.cc
@@ -395,12 +395,14 @@ TEST(ExactlyTest, HasCorrectBounds) {
class EvenCardinality : public CardinalityInterface {
public:
- // Returns true if call_count calls will satisfy this cardinality.
+ // Returns true if and only if call_count calls will satisfy this
+ // cardinality.
bool IsSatisfiedByCallCount(int call_count) const override {
return (call_count % 2 == 0);
}
- // Returns true if call_count calls will saturate this cardinality.
+ // Returns true if and only if call_count calls will saturate this
+ // cardinality.
bool IsSaturatedByCallCount(int /* call_count */) const override {
return false;
}
diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc
index fbc5d5b2..55be70a8 100644
--- a/googlemock/test/gmock-function-mocker_test.cc
+++ b/googlemock/test/gmock-function-mocker_test.cc
@@ -101,6 +101,10 @@ class FooInterface {
virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
virtual int TypeWithTemplatedCopyCtor(const TemplatedCopyable<int>&) = 0;
+ virtual int (*ReturnsFunctionPointer1(int))(bool) = 0;
+ using fn_ptr = int (*)(bool);
+ virtual fn_ptr ReturnsFunctionPointer2(int) = 0;
+
#if GTEST_OS_WINDOWS
STDMETHOD_(int, CTNullary)() = 0;
STDMETHOD_(bool, CTUnary)(int x) = 0;
@@ -159,6 +163,9 @@ class MockFoo : public FooInterface {
MOCK_METHOD(int, TypeWithTemplatedCopyCtor,
(const TemplatedCopyable<int>&)); // NOLINT
+ MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ());
+ MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ());
+
#if GTEST_OS_WINDOWS
MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE)));
MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE)));
diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc
index 7df4078e..19ba6fe5 100644
--- a/googlemock/test/gmock-internal-utils_test.cc
+++ b/googlemock/test/gmock-internal-utils_test.cc
@@ -40,7 +40,6 @@
#include <memory>
#include <sstream>
#include <string>
-#include <type_traits>
#include <vector>
#include "gmock/gmock.h"
@@ -125,15 +124,17 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
}
TEST(PointeeOfTest, WorksForSmartPointers) {
- CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
- CompileAssertTypesEqual<std::string,
- PointeeOf<std::shared_ptr<std::string> >::type>();
+ EXPECT_TRUE(
+ (std::is_same<int, PointeeOf<std::unique_ptr<int>>::type>::value));
+ EXPECT_TRUE(
+ (std::is_same<std::string,
+ PointeeOf<std::shared_ptr<std::string>>::type>::value));
}
TEST(PointeeOfTest, WorksForRawPointers) {
- CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
- CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
- CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
+ EXPECT_TRUE((std::is_same<int, PointeeOf<int*>::type>::value));
+ EXPECT_TRUE((std::is_same<const char, PointeeOf<const char*>::type>::value));
+ EXPECT_TRUE((std::is_void<PointeeOf<void*>::type>::value));
}
TEST(GetRawPointerTest, WorksForSmartPointers) {
@@ -664,63 +665,66 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
TEST(FunctionTest, Nullary) {
typedef Function<int()> F; // NOLINT
EXPECT_EQ(0u, F::ArgumentCount);
- CompileAssertTypesEqual<int, F::Result>();
- CompileAssertTypesEqual<std::tuple<>, F::ArgumentTuple>();
- CompileAssertTypesEqual<std::tuple<>, F::ArgumentMatcherTuple>();
- CompileAssertTypesEqual<void(), F::MakeResultVoid>();
- CompileAssertTypesEqual<IgnoredValue(), F::MakeResultIgnoredValue>();
+ EXPECT_TRUE((std::is_same<int, F::Result>::value));
+ EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentTuple>::value));
+ EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentMatcherTuple>::value));
+ EXPECT_TRUE((std::is_same<void(), F::MakeResultVoid>::value));
+ EXPECT_TRUE((std::is_same<IgnoredValue(), F::MakeResultIgnoredValue>::value));
}
TEST(FunctionTest, Unary) {
typedef Function<int(bool)> F; // NOLINT
EXPECT_EQ(1u, F::ArgumentCount);
- CompileAssertTypesEqual<int, F::Result>();
- CompileAssertTypesEqual<bool, F::Arg<0>::type>();
- CompileAssertTypesEqual<std::tuple<bool>, F::ArgumentTuple>();
- CompileAssertTypesEqual<std::tuple<Matcher<bool> >,
- F::ArgumentMatcherTuple>();
- CompileAssertTypesEqual<void(bool), F::MakeResultVoid>(); // NOLINT
- CompileAssertTypesEqual<IgnoredValue(bool), // NOLINT
- F::MakeResultIgnoredValue>();
+ EXPECT_TRUE((std::is_same<int, F::Result>::value));
+ EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
+ EXPECT_TRUE((std::is_same<std::tuple<bool>, F::ArgumentTuple>::value));
+ EXPECT_TRUE((
+ std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>::value));
+ EXPECT_TRUE((std::is_same<void(bool), F::MakeResultVoid>::value)); // NOLINT
+ EXPECT_TRUE((std::is_same<IgnoredValue(bool), // NOLINT
+ F::MakeResultIgnoredValue>::value));
}
TEST(FunctionTest, Binary) {
typedef Function<int(bool, const long&)> F; // NOLINT
EXPECT_EQ(2u, F::ArgumentCount);
- CompileAssertTypesEqual<int, F::Result>();
- CompileAssertTypesEqual<bool, F::Arg<0>::type>();
- CompileAssertTypesEqual<const long&, F::Arg<1>::type>(); // NOLINT
- CompileAssertTypesEqual<std::tuple<bool, const long&>, // NOLINT
- F::ArgumentTuple>();
- CompileAssertTypesEqual<
- std::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>();
+ EXPECT_TRUE((std::is_same<int, F::Result>::value));
+ EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
+ EXPECT_TRUE((std::is_same<const long&, F::Arg<1>::type>::value)); // NOLINT
+ EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>, // NOLINT
+ F::ArgumentTuple>::value));
+ EXPECT_TRUE(
+ (std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>, // NOLINT
+ F::ArgumentMatcherTuple>::value));
+ EXPECT_TRUE((std::is_same<void(bool, const long&), // NOLINT
+ F::MakeResultVoid>::value));
+ EXPECT_TRUE((std::is_same<IgnoredValue(bool, const long&), // NOLINT
+ F::MakeResultIgnoredValue>::value));
}
TEST(FunctionTest, LongArgumentList) {
typedef Function<char(bool, int, char*, int&, const long&)> F; // NOLINT
EXPECT_EQ(5u, F::ArgumentCount);
- CompileAssertTypesEqual<char, F::Result>();
- CompileAssertTypesEqual<bool, F::Arg<0>::type>();
- CompileAssertTypesEqual<int, F::Arg<1>::type>();
- CompileAssertTypesEqual<char*, F::Arg<2>::type>();
- CompileAssertTypesEqual<int&, F::Arg<3>::type>();
- CompileAssertTypesEqual<const long&, F::Arg<4>::type>(); // NOLINT
- CompileAssertTypesEqual<
- std::tuple<bool, int, char*, int&, const long&>, // NOLINT
- F::ArgumentTuple>();
- CompileAssertTypesEqual<
- std::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<
- IgnoredValue(bool, int, char*, int&, const long&), // NOLINT
- F::MakeResultIgnoredValue>();
+ EXPECT_TRUE((std::is_same<char, F::Result>::value));
+ EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
+ EXPECT_TRUE((std::is_same<int, F::Arg<1>::type>::value));
+ EXPECT_TRUE((std::is_same<char*, F::Arg<2>::type>::value));
+ EXPECT_TRUE((std::is_same<int&, F::Arg<3>::type>::value));
+ EXPECT_TRUE((std::is_same<const long&, F::Arg<4>::type>::value)); // NOLINT
+ EXPECT_TRUE(
+ (std::is_same<std::tuple<bool, int, char*, int&, const long&>, // NOLINT
+ F::ArgumentTuple>::value));
+ EXPECT_TRUE(
+ (std::is_same<
+ std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
+ Matcher<const long&>>, // NOLINT
+ F::ArgumentMatcherTuple>::value));
+ EXPECT_TRUE(
+ (std::is_same<void(bool, int, char*, int&, const long&), // NOLINT
+ F::MakeResultVoid>::value));
+ EXPECT_TRUE((
+ std::is_same<IgnoredValue(bool, int, char*, int&, const long&), // NOLINT
+ F::MakeResultIgnoredValue>::value));
}
} // namespace
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index a61d040b..b9eb894d 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -956,10 +956,9 @@ TEST(TypedEqTest, CanDescribeSelf) {
// Tests that TypedEq<T>(v) has type Matcher<T>.
-// Type<T>::IsTypeOf(v) compiles if the type of value v is T, where T
-// is a "bare" type (i.e. not in the form of const U or U&). If v's
-// type is not T, the compiler will generate a message about
-// "undefined reference".
+// Type<T>::IsTypeOf(v) compiles if and only if the type of value v is T, where
+// T is a "bare" type (i.e. not in the form of const U or U&). If v's type is
+// not T, the compiler will generate a message about "undefined reference".
template <typename T>
struct Type {
static bool IsTypeOf(const T& /* v */) { return true; }
@@ -2055,6 +2054,114 @@ TEST(PairMatchBaseTest, WorksWithMoveOnly) {
EXPECT_TRUE(matcher.Matches(pointers));
}
+// Tests that IsNan() matches a NaN, with float.
+TEST(IsNan, FloatMatchesNan) {
+ float quiet_nan = std::numeric_limits<float>::quiet_NaN();
+ float other_nan = std::nanf("1");
+ float real_value = 1.0f;
+
+ Matcher<float> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<float&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const float&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with double.
+TEST(IsNan, DoubleMatchesNan) {
+ double quiet_nan = std::numeric_limits<double>::quiet_NaN();
+ double other_nan = std::nan("1");
+ double real_value = 1.0;
+
+ Matcher<double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() matches a NaN, with long double.
+TEST(IsNan, LongDoubleMatchesNan) {
+ long double quiet_nan = std::numeric_limits<long double>::quiet_NaN();
+ long double other_nan = std::nan("1");
+ long double real_value = 1.0;
+
+ Matcher<long double> m = IsNan();
+ EXPECT_TRUE(m.Matches(quiet_nan));
+ EXPECT_TRUE(m.Matches(other_nan));
+ EXPECT_FALSE(m.Matches(real_value));
+
+ Matcher<long double&> m_ref = IsNan();
+ EXPECT_TRUE(m_ref.Matches(quiet_nan));
+ EXPECT_TRUE(m_ref.Matches(other_nan));
+ EXPECT_FALSE(m_ref.Matches(real_value));
+
+ Matcher<const long double&> m_cref = IsNan();
+ EXPECT_TRUE(m_cref.Matches(quiet_nan));
+ EXPECT_TRUE(m_cref.Matches(other_nan));
+ EXPECT_FALSE(m_cref.Matches(real_value));
+}
+
+// Tests that IsNan() works with Not.
+TEST(IsNan, NotMatchesNan) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_FALSE(mf.Matches(std::numeric_limits<float>::quiet_NaN()));
+ EXPECT_FALSE(mf.Matches(std::nanf("1")));
+ EXPECT_TRUE(mf.Matches(1.0));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_FALSE(md.Matches(std::numeric_limits<double>::quiet_NaN()));
+ EXPECT_FALSE(md.Matches(std::nan("1")));
+ EXPECT_TRUE(md.Matches(1.0));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_FALSE(mld.Matches(std::numeric_limits<long double>::quiet_NaN()));
+ EXPECT_FALSE(mld.Matches(std::nanl("1")));
+ EXPECT_TRUE(mld.Matches(1.0));
+}
+
+// Tests that IsNan() can describe itself.
+TEST(IsNan, CanDescribeSelf) {
+ Matcher<float> mf = IsNan();
+ EXPECT_EQ("is NaN", Describe(mf));
+
+ Matcher<double> md = IsNan();
+ EXPECT_EQ("is NaN", Describe(md));
+
+ Matcher<long double> mld = IsNan();
+ EXPECT_EQ("is NaN", Describe(mld));
+}
+
+// Tests that IsNan() can describe itself with Not.
+TEST(IsNan, CanDescribeSelfWithNot) {
+ Matcher<float> mf = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mf));
+
+ Matcher<double> md = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(md));
+
+ Matcher<long double> mld = Not(IsNan());
+ EXPECT_EQ("isn't NaN", Describe(mld));
+}
+
// Tests that FloatEq() matches a 2-tuple where
// FloatEq(first field) matches the second field.
TEST(FloatEq2Test, MatchesEqualArguments) {
@@ -2640,8 +2747,8 @@ class IsGreaterThan {
// For testing Truly().
const int foo = 0;
-// This predicate returns true if the argument references foo and has
-// a zero value.
+// This predicate returns true if and only if the argument references foo and
+// has a zero value.
bool ReferencesFooAndIsZero(const int& n) {
return (&n == &foo) && (n == 0);
}
@@ -3594,7 +3701,7 @@ class Uncopyable {
GTEST_DISALLOW_COPY_AND_ASSIGN_(Uncopyable);
};
-// Returns true if x.value() is positive.
+// Returns true if and only if x.value() is positive.
bool ValueIsPositive(const Uncopyable& x) { return x.value() > 0; }
MATCHER_P(UncopyableIs, inner_matcher, "") {
@@ -4319,6 +4426,16 @@ TEST(ResultOfTest, WorksForLambdas) {
EXPECT_FALSE(matcher.Matches(1));
}
+TEST(ResultOfTest, WorksForNonCopyableArguments) {
+ Matcher<std::unique_ptr<int>> matcher = ResultOf(
+ [](const std::unique_ptr<int>& str_len) {
+ return std::string(static_cast<size_t>(*str_len), 'x');
+ },
+ "xxx");
+ EXPECT_TRUE(matcher.Matches(std::unique_ptr<int>(new int(3))));
+ EXPECT_FALSE(matcher.Matches(std::unique_ptr<int>(new int(1))));
+}
+
const int* ReferencingFunction(const int& n) { return &n; }
struct ReferencingFunctor {
diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc
index b4e0fc30..97ec5cf0 100644
--- a/googlemock/test/gmock-more-actions_test.cc
+++ b/googlemock/test/gmock-more-actions_test.cc
@@ -57,7 +57,6 @@ using testing::ReturnPointee;
using testing::SaveArg;
using testing::SaveArgPointee;
using testing::SetArgReferee;
-using testing::StaticAssertTypeEq;
using testing::Unused;
using testing::WithArg;
using testing::WithoutArgs;
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index 95b4b8b7..791a2476 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -69,8 +69,8 @@ using testing::AtMost;
using testing::Between;
using testing::Cardinality;
using testing::CardinalityInterface;
-using testing::ContainsRegex;
using testing::Const;
+using testing::ContainsRegex;
using testing::DoAll;
using testing::DoDefault;
using testing::Eq;
@@ -1952,12 +1952,14 @@ TEST(DeletingMockEarlyTest, Failure2) {
class EvenNumberCardinality : public CardinalityInterface {
public:
- // Returns true if call_count calls will satisfy this cardinality.
+ // Returns true if and only if call_count calls will satisfy this
+ // cardinality.
bool IsSatisfiedByCallCount(int call_count) const override {
return call_count % 2 == 0;
}
- // Returns true if call_count calls will saturate this cardinality.
+ // Returns true if and only if call_count calls will saturate this
+ // cardinality.
bool IsSaturatedByCallCount(int /* call_count */) const override {
return false;
}