Googletest export

Normalize headers in gMock docs

Increasing Header levels on two pages, to better match other pages in the same directory.

PiperOrigin-RevId: 318280892
This commit is contained in:
Abseil Team
2020-06-25 11:56:24 -04:00
committed by Mark Barolak
parent 05c4a036bb
commit e5613588a1
2 changed files with 54 additions and 54 deletions

View File

@@ -1,12 +1,12 @@
## gMock Cheat Sheet
# gMock Cheat Sheet
<!-- GOOGLETEST_CM0019 DO NOT DELETE -->
<!-- GOOGLETEST_CM0033 DO NOT DELETE -->
### Defining a Mock Class
## Defining a Mock Class
#### Mocking a Normal Class {#MockClass}
### Mocking a Normal Class {#MockClass}
Given
@@ -52,7 +52,7 @@ StrictMock<MockFoo> strict_foo; // The type is a subclass of MockFoo.
**Note:** A mock object is currently naggy by default. We may make it nice by
default in the future.
#### Mocking a Class Template {#MockTemplate}
### Mocking a Class Template {#MockTemplate}
Class templates can be mocked just like any class.
@@ -80,7 +80,7 @@ class MockStack : public StackInterface<Elem> {
};
```
#### Specifying Calling Conventions for Mock Functions
### Specifying Calling Conventions for Mock Functions
If your mock function doesn't use the default calling convention, you can
specify it by adding `Calltype(convention)` to `MOCK_METHOD`'s 4th parameter.
@@ -94,7 +94,7 @@ For example,
where `STDMETHODCALLTYPE` is defined by `<objbase.h>` on Windows.
### Using Mocks in Tests {#UsingMocks}
## Using Mocks in Tests {#UsingMocks}
The typical work flow is:
@@ -130,7 +130,7 @@ TEST(BarTest, DoesThis) {
} // #6
```
### Setting Default Actions {#OnCall}
## Setting Default Actions {#OnCall}
gMock has a **built-in default action** for any function that returns `void`,
`bool`, a numeric value, or a pointer. In C++11, it will additionally returns
@@ -186,7 +186,7 @@ ON_CALL(mock-object, method(matchers))
.WillByDefault(action);
```
### Setting Expectations {#ExpectCall}
## Setting Expectations {#ExpectCall}
`EXPECT_CALL()` sets **expectations** on a mock method (How will it be called?
What will it do?):
@@ -225,7 +225,7 @@ If `Times()` is omitted, the cardinality is assumed to be:
A method with no `EXPECT_CALL()` is free to be invoked *any number of times*,
and the default action will be taken each time.
### Matchers {#MatcherList}
## Matchers {#MatcherList}
<!-- GOOGLETEST_CM0020 DO NOT DELETE -->
@@ -249,14 +249,14 @@ Built-in matchers (where `argument` is the function argument, e.g.
`EXPECT_CALL(mock_object, method(matchers))`, the arguments of `method`) are
divided into several categories:
#### Wildcard
### Wildcard
Matcher | Description
:-------------------------- | :-----------------------------------------------
`_` | `argument` can be any value of the correct type.
`A<type>()` or `An<type>()` | `argument` can be any value of type `type`.
#### Generic Comparison
### Generic Comparison
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -289,7 +289,7 @@ Boolean. In other cases, you can use the basic
[`EXPECT_TRUE` and `EXPECT_FALSE`](../../googletest/docs/primer#basic-assertions)
assertions.
#### Floating-Point Matchers {#FpMatchers}
### Floating-Point Matchers {#FpMatchers}
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -317,7 +317,7 @@ user wants.
| `NanSensitiveFloatNear(a_float, max_abs_error)` | `argument` is a `float` value close to `a_float` (absolute error <= `max_abs_error`), treating two NaNs as equal. |
<!-- mdformat on -->
#### String Matchers
### String Matchers
The `argument` can be either a C string or a C++ string object:
@@ -341,7 +341,7 @@ use the regular expression syntax defined
these matchers, except `ContainsRegex()` and `MatchesRegex()` work for wide
strings as well.
#### Container Matchers
### Container Matchers
Most STL-style containers support `==`, so you can use `Eq(expected_container)`
or simply `expected_container` to match a container exactly. If you want to
@@ -392,7 +392,7 @@ messages, you can use:
EXPECT_THAT(actual_foos, Pointwise(FooEq(), expected_foos));
```
#### Member Matchers
### Member Matchers
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -403,7 +403,7 @@ messages, you can use:
| `Property(&class::property, m)` | `argument.property()` (or `argument->property()` when `argument` is a plain pointer) matches matcher `m`, where `argument` is an object of type _class_. |
<!-- mdformat on -->
#### Matching the Result of a Function, Functor, or Callback
### Matching the Result of a Function, Functor, or Callback
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -411,7 +411,7 @@ messages, you can use:
| `ResultOf(f, m)` | `f(argument)` matches matcher `m`, where `f` is a function or functor. |
<!-- mdformat on -->
#### Pointer Matchers
### Pointer Matchers
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -424,7 +424,7 @@ messages, you can use:
<!-- GOOGLETEST_CM0027 DO NOT DELETE -->
#### Multi-argument Matchers {#MultiArgMatchers}
### Multi-argument Matchers {#MultiArgMatchers}
Technically, all matchers match a *single* value. A "multi-argument" matcher is
just one that matches a *tuple*. The following matchers can be used to match a
@@ -449,7 +449,7 @@ reorder them) to participate in the matching:
| `Args<N1, N2, ..., Nk>(m)` | The tuple of the `k` selected (using 0-based indices) arguments matches `m`, e.g. `Args<1, 2>(Eq())`. |
<!-- mdformat on -->
#### Composite Matchers
### Composite Matchers
You can make a matcher from one or more other matchers:
@@ -465,7 +465,7 @@ You can make a matcher from one or more other matchers:
<!-- GOOGLETEST_CM0028 DO NOT DELETE -->
#### Adapters for Matchers
### Adapters for Matchers
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -478,7 +478,7 @@ You can make a matcher from one or more other matchers:
`AddressSatisfies(callback)` and `Truly(callback)` take ownership of `callback`,
which must be a permanent callback.
#### Using Matchers as Predicates {#MatchersAsPredicatesCheat}
### Using Matchers as Predicates {#MatchersAsPredicatesCheat}
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -488,7 +488,7 @@ which must be a permanent callback.
| `Value(value, m)` | evaluates to `true` if `value` matches `m`. |
<!-- mdformat on -->
#### Defining Matchers
### Defining Matchers
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -507,11 +507,11 @@ which must be a permanent callback.
3. You can use `PrintToString(x)` to convert a value `x` of any type to a
string.
### Actions {#ActionList}
## Actions {#ActionList}
**Actions** specify what a mock function should do when invoked.
#### Returning a Value
### Returning a Value
<!-- mdformat off(no multiline tables) -->
| | |
@@ -527,7 +527,7 @@ which must be a permanent callback.
| `ReturnRoundRobin({a1, ..., ak})` | Each call will return the next `ai` in the list, starting at the beginning when the end of the list is reached. |
<!-- mdformat on -->
#### Side Effects
### Side Effects
<!-- mdformat off(no multiline tables) -->
| | |
@@ -544,7 +544,7 @@ which must be a permanent callback.
| `Throw(exception)` | Throws the given exception, which can be any copyable value. Available since v1.1.0. |
<!-- mdformat on -->
#### Using a Function, Functor, or Lambda as an Action
### Using a Function, Functor, or Lambda as an Action
In the following, by "callable" we mean a free function, `std::function`,
functor, or lambda.
@@ -598,7 +598,7 @@ InvokeArgument<2>(5, string("Hi"), ByRef(foo))
calls the mock function's #2 argument, passing to it `5` and `string("Hi")` by
value, and `foo` by reference.
#### Default Action
### Default Action
<!-- mdformat off(no multiline tables) -->
| Matcher | Description |
@@ -611,7 +611,7 @@ composite action - trying to do so will result in a run-time error.
<!-- GOOGLETEST_CM0032 DO NOT DELETE -->
#### Composite Actions
### Composite Actions
<!-- mdformat off(no multiline tables) -->
| | |
@@ -623,7 +623,7 @@ composite action - trying to do so will result in a run-time error.
| `WithoutArgs(a)` | Perform action `a` without any arguments. |
<!-- mdformat on -->
#### Defining Actions
### Defining Actions
<!-- mdformat off(no multiline tables) -->
| | |
@@ -635,7 +635,7 @@ composite action - trying to do so will result in a run-time error.
The `ACTION*` macros cannot be used inside a function or class.
### Cardinalities {#CardinalityList}
## Cardinalities {#CardinalityList}
These are used in `Times()` to specify how many times a mock function will be
called:
@@ -650,13 +650,13 @@ called:
| `Exactly(n) or n` | The call is expected exactly `n` times. In particular, the call should never happen when `n` is 0. |
<!-- mdformat on -->
### Expectation Order
## Expectation Order
By default, the expectations can be matched in *any* order. If some or all
expectations must be matched in a given order, there are two ways to specify it.
They can be used either independently or together.
#### The After Clause {#AfterClause}
### The After Clause {#AfterClause}
```cpp
using ::testing::Expectation;
@@ -690,7 +690,7 @@ says that `Bar()` can be called only after all elements have been initialized
Modifying an `ExpectationSet` after using it in an `.After()` doesn't affect the
meaning of the `.After()`.
#### Sequences {#UsingSequences}
### Sequences {#UsingSequences}
When you have a long chain of sequential expectations, it's easier to specify
the order using **sequences**, which don't require you to given each expectation
@@ -733,7 +733,7 @@ using ::testing::InSequence;
says that all expected calls in the scope of `seq` must occur in strict order.
The name `seq` is irrelevant.
### Verifying and Resetting a Mock
## Verifying and Resetting a Mock
gMock will verify the expectations on a mock object when it is destructed, or
you can do it earlier:
@@ -758,7 +758,7 @@ verified:
Mock::AllowLeak(&mock_obj);
```
### Mock Classes
## Mock Classes
gMock defines a convenient mock class template
@@ -771,7 +771,7 @@ class MockFunction<R(A1, ..., An)> {
See this [recipe](cook_book.md#using-check-points) for one application of it.
### Flags
## Flags
<!-- mdformat off(no multiline tables) -->
| Flag | Description |