Update googletest to 1.18.0 and SIMDe to 0.8.2.
Googletest 1.18 asks for CMake 3.13 or newer, so configuring the tests no longer warns that CMake compatibility below 3.10 is deprecated. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e4e666f459
commit
3f10e05176
912 changed files with 224964 additions and 11502 deletions
|
|
@ -24,7 +24,8 @@ provided by GoogleTest. All actions are defined in the `::testing` namespace.
|
|||
| :--------------------------------- | :-------------------------------------- |
|
||||
| `Assign(&variable, value)` | Assign `value` to variable. |
|
||||
| `DeleteArg<N>()` | Delete the `N`-th (0-based) argument, which must be a pointer. |
|
||||
| `SaveArg<N>(pointer)` | Save the `N`-th (0-based) argument to `*pointer`. |
|
||||
| `SaveArg<N>(pointer)` | Save the `N`-th (0-based) argument to `*pointer` by copy-assignment. |
|
||||
| `SaveArgByMove<N>(pointer)` | Save the `N`-th (0-based) argument to `*pointer` by move-assignment. |
|
||||
| `SaveArgPointee<N>(pointer)` | Save the value pointed to by the `N`-th (0-based) argument to `*pointer`. |
|
||||
| `SetArgReferee<N>(value)` | Assign `value` to the variable referenced by the `N`-th (0-based) argument. |
|
||||
| `SetArgPointee<N>(value)` | Assign `value` to the variable pointed by the `N`-th (0-based) argument. |
|
||||
|
|
@ -47,8 +48,8 @@ functor, or lambda.
|
|||
| `InvokeWithoutArgs(object_pointer, &class::method)` | Invoke the method on the object, which takes no arguments. |
|
||||
| `InvokeArgument<N>(arg1, arg2, ..., argk)` | Invoke the mock function's `N`-th (0-based) argument, which must be a function or a functor, with the `k` arguments. |
|
||||
|
||||
The return value of the invoked function is used as the return value of the
|
||||
action.
|
||||
The return value of the invoked function (except `InvokeArgument`) is used as
|
||||
the return value of the action.
|
||||
|
||||
When defining a callable to be used with `Invoke*()`, you can declare any unused
|
||||
parameters as `Unused`:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Assertions Reference
|
||||
|
||||
This page lists the assertion macros provided by GoogleTest for verifying code
|
||||
behavior. To use them, include the header `gtest/gtest.h`.
|
||||
behavior. To use them, add `#include <gtest/gtest.h>`.
|
||||
|
||||
The majority of the macros listed below come as a pair with an `EXPECT_` variant
|
||||
and an `ASSERT_` variant. Upon failure, `EXPECT_` macros generate nonfatal
|
||||
|
|
@ -88,7 +88,7 @@ For example, the following code verifies that the string `value1` starts with
|
|||
10:
|
||||
|
||||
```cpp
|
||||
#include "gmock/gmock.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
using ::testing::AllOf;
|
||||
using ::testing::Gt;
|
||||
|
|
@ -276,7 +276,8 @@ Units in the Last Place (ULPs). To learn more about ULPs, see the article
|
|||
`ASSERT_FLOAT_EQ(`*`val1`*`,`*`val2`*`)`
|
||||
|
||||
Verifies that the two `float` values *`val1`* and *`val2`* are approximately
|
||||
equal, to within 4 ULPs from each other.
|
||||
equal, to within 4 ULPs from each other. Infinity and the largest finite float
|
||||
value are considered to be one ULP apart.
|
||||
|
||||
### EXPECT_DOUBLE_EQ {#EXPECT_DOUBLE_EQ}
|
||||
|
||||
|
|
@ -284,7 +285,8 @@ equal, to within 4 ULPs from each other.
|
|||
`ASSERT_DOUBLE_EQ(`*`val1`*`,`*`val2`*`)`
|
||||
|
||||
Verifies that the two `double` values *`val1`* and *`val2`* are approximately
|
||||
equal, to within 4 ULPs from each other.
|
||||
equal, to within 4 ULPs from each other. Infinity and the largest finite double
|
||||
value are considered to be one ULP apart.
|
||||
|
||||
### EXPECT_NEAR {#EXPECT_NEAR}
|
||||
|
||||
|
|
@ -294,6 +296,11 @@ equal, to within 4 ULPs from each other.
|
|||
Verifies that the difference between *`val1`* and *`val2`* does not exceed the
|
||||
absolute error bound *`abs_error`*.
|
||||
|
||||
If *`val`* and *`val2`* are both infinity of the same sign, the difference is
|
||||
considered to be 0. Otherwise, if either value is infinity, the difference is
|
||||
considered to be infinity. All non-NaN values (including infinity) are
|
||||
considered to not exceed an *`abs_error`* of infinity.
|
||||
|
||||
## Exception Assertions {#exceptions}
|
||||
|
||||
The following assertions verify that a piece of code throws, or does not throw,
|
||||
|
|
@ -515,7 +522,7 @@ Verifies that *`expression`* is a success `HRESULT`.
|
|||
### EXPECT_HRESULT_FAILED {#EXPECT_HRESULT_FAILED}
|
||||
|
||||
`EXPECT_HRESULT_FAILED(`*`expression`*`)` \
|
||||
`EXPECT_HRESULT_FAILED(`*`expression`*`)`
|
||||
`ASSERT_HRESULT_FAILED(`*`expression`*`)`
|
||||
|
||||
Verifies that *`expression`* is a failure `HRESULT`.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# Matchers Reference
|
||||
|
||||
<!-- disableFinding(LINK_RELATIVE_G3DOC) -->
|
||||
|
||||
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
|
||||
`EXPECT_CALL()`, or use it to validate a value directly using two macros:
|
||||
|
||||
|
|
@ -42,11 +44,14 @@ Matcher | Description
|
|||
| `Lt(value)` | `argument < value` |
|
||||
| `Ne(value)` | `argument != value` |
|
||||
| `IsFalse()` | `argument` evaluates to `false` in a Boolean context. |
|
||||
| `DistanceFrom(target, m)` | The distance between `argument` and `target` (computed by `abs(argument - target)`) matches `m`. |
|
||||
| `DistanceFrom(target, get_distance, m)` | The distance between `argument` and `target` (computed by `get_distance(argument, target)`) matches `m`. |
|
||||
| `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`. (For testing whether an `optional<>` is set, check for equality with `nullopt`. You may need to use `Eq(nullopt)` if the inner type doesn't have `==`.)|
|
||||
| `Optional(m)` | `argument` is `optional<>` that contains a value matching `m`. (For testing whether an `optional<>` is unset, check for equality with `nullopt`. You may need to use `Eq(nullopt)` if the inner type doesn't have `==`.)|
|
||||
| `VariantWith<T>(m)` | `argument` is `variant<>` that holds the alternative of type T with a value matching `m`. |
|
||||
| `AnyWith<T>(m)` | `argument` is `any<>` that holds a value of type T with a value matching `m`. |
|
||||
| `Ref(variable)` | `argument` is a reference to `variable`. |
|
||||
| `TypedEq<type>(value)` | `argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded. |
|
||||
|
||||
|
|
@ -109,6 +114,33 @@ use the regular expression syntax defined
|
|||
[here](../advanced.md#regular-expression-syntax). All of these matchers, except
|
||||
`ContainsRegex()` and `MatchesRegex()` work for wide strings as well.
|
||||
|
||||
## Exception Matchers
|
||||
|
||||
| Matcher | Description |
|
||||
| :---------------------------------------- | :------------------------------- |
|
||||
| `Throws<E>()` | The `argument` is a callable object that, when called, throws an exception of the expected type `E`. |
|
||||
| `Throws<E>(m)` | The `argument` is a callable object that, when called, throws an exception of type `E` that satisfies the matcher `m`. |
|
||||
| `ThrowsMessage<E>(m)` | The `argument` is a callable object that, when called, throws an exception of type `E` with a message that satisfies the matcher `m`. |
|
||||
|
||||
Examples:
|
||||
|
||||
```cpp
|
||||
auto argument = [] { throw std::runtime_error("error msg"); };
|
||||
|
||||
// Checks if the lambda throws a `std::runtime_error`.
|
||||
EXPECT_THAT(argument, Throws<std::runtime_error>());
|
||||
|
||||
// Checks if the lambda throws a `std::runtime_error` with a specific message
|
||||
// that matches "error msg".
|
||||
EXPECT_THAT(argument,
|
||||
Throws<std::runtime_error>(Property(&std::runtime_error::what,
|
||||
Eq("error msg"))));
|
||||
|
||||
// Checks if the lambda throws a `std::runtime_error` with a message that
|
||||
// contains "msg".
|
||||
EXPECT_THAT(argument, ThrowsMessage<std::runtime_error>(HasSubstr("msg")));
|
||||
```
|
||||
|
||||
## Container Matchers
|
||||
|
||||
Most STL-style containers support `==`, so you can use `Eq(expected_container)`
|
||||
|
|
@ -171,6 +203,11 @@ 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_. The method `property()` must take no argument and be declared as `const`. |
|
||||
| `Property(property_name, &class::property, m)` | The same as the two-parameter version, but provides a better error message.
|
||||
|
||||
{: .callout .warning}
|
||||
Warning: Don't use `Property()` against member functions that you do not own,
|
||||
because taking addresses of functions is fragile and generally not part of the
|
||||
contract of the function.
|
||||
|
||||
**Notes:**
|
||||
|
||||
* You can use `FieldsAre()` to match any type that supports structured
|
||||
|
|
@ -189,10 +226,6 @@ messages, you can use:
|
|||
EXPECT_THAT(s, FieldsAre(42, "aloha"));
|
||||
```
|
||||
|
||||
* Don't use `Property()` against member functions that you do not own, because
|
||||
taking addresses of functions is fragile and generally not part of the
|
||||
contract of the function.
|
||||
|
||||
## Matching the Result of a Function, Functor, or Callback
|
||||
|
||||
| Matcher | Description |
|
||||
|
|
@ -223,6 +256,14 @@ Matcher | Description
|
|||
`Le()` | `x <= y`
|
||||
`Lt()` | `x < y`
|
||||
`Ne()` | `x != y`
|
||||
`FloatEq()` | `x` approximately equals `y`
|
||||
`DoubleEq()` | `x` approximately equals `y`
|
||||
`NanSensitiveFloatEq()` | Same as `FloatEq()`, but treats two NaNs as equal
|
||||
`NanSensitiveDoubleEq()` | Same as `DoubleEq()`, but treats two NaNs as equal
|
||||
`FloatNear(max_abs_error)` | `x` is within `max_abs_error` of `y`
|
||||
`DoubleNear(max_abs_error)` | `x` is within `max_abs_error` of `y`
|
||||
`NanSensitiveFloatNear(max_abs_error)` | Same as `FloatNear(max_abs_error)`, but treats two NaNs as near
|
||||
`NanSensitiveDoubleNear(max_abs_error)` | Same as `DoubleNear(max_abs_error)`, but treats two NaNs as near
|
||||
|
||||
You can use the following selectors to pick a subset of the arguments (or
|
||||
reorder them) to participate in the matching:
|
||||
|
|
@ -266,6 +307,13 @@ which must be a permanent callback.
|
|||
|
||||
## Defining Matchers
|
||||
|
||||
{: .callout .note}
|
||||
Note: full details about defining new matchers are in the
|
||||
[cookbook](../gmock_cook_book.md#NewMatchers). In particular, if `MATCHER`
|
||||
macros are not sufficient, you can directly implement
|
||||
[monomorphic](../gmock_cook_book.md#MonomorphicMatchers) or
|
||||
[polymorphic](../gmock_cook_book.md#PolymorphicMatchers) matchers.
|
||||
|
||||
| Macro | Description |
|
||||
| :----------------------------------- | :------------------------------------ |
|
||||
| `MATCHER(IsEven, "") { return (arg % 2) == 0; }` | Defines a matcher `IsEven()` to match an even number. |
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
# Mocking Reference
|
||||
|
||||
This page lists the facilities provided by GoogleTest for creating and working
|
||||
with mock objects. To use them, include the header
|
||||
`gmock/gmock.h`.
|
||||
with mock objects. To use them, add `#include <gmock/gmock.h>`.
|
||||
|
||||
## Macros {#macros}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<!--* toc_depth: 3 *-->
|
||||
|
||||
This page lists the facilities provided by GoogleTest for writing test programs.
|
||||
To use them, include the header `gtest/gtest.h`.
|
||||
To use them, add `#include <gtest/gtest.h>`.
|
||||
|
||||
## Macros
|
||||
|
||||
|
|
@ -94,7 +94,8 @@ Instantiates the value-parameterized test suite *`TestSuiteName`* (defined with
|
|||
The argument *`InstantiationName`* is a unique name for the instantiation of the
|
||||
test suite, to distinguish between multiple instantiations. In test output, the
|
||||
instantiation name is added as a prefix to the test suite name
|
||||
*`TestSuiteName`*.
|
||||
*`TestSuiteName`*. If *`InstantiationName`* is empty
|
||||
(`INSTANTIATE_TEST_SUITE_P(, ...)`), no prefix is added.
|
||||
|
||||
The argument *`param_generator`* is one of the following GoogleTest-provided
|
||||
functions that generate the test parameters, all defined in the `::testing`
|
||||
|
|
@ -109,7 +110,8 @@ namespace:
|
|||
| `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. |
|
||||
| `Bool()` | Yields sequence `{false, true}`. |
|
||||
| `Combine(g1, g2, ..., gN)` | Yields as `std::tuple` *n*-tuples all combinations (Cartesian product) of the values generated by the given *n* generators `g1`, `g2`, ..., `gN`. |
|
||||
| `ConvertGenerator<T>(g)` | Yields values generated by generator `g`, `static_cast` to `T`. |
|
||||
| `ConvertGenerator<T>(g)` or `ConvertGenerator(g, func)` | Yields values generated by generator `g`, `static_cast` from `T`. (Note: `T` might not be what you expect. See [*Using ConvertGenerator*](#using-convertgenerator) below.) The second overload uses `func` to perform the conversion. |
|
||||
|
||||
The optional last argument *`name_generator`* is a function or functor that
|
||||
generates custom test name suffixes based on the test parameters. The function
|
||||
must accept an argument of type
|
||||
|
|
@ -121,8 +123,8 @@ custom function can be used for more control:
|
|||
```cpp
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
MyInstantiation, MyTestSuite,
|
||||
::testing::Values(...),
|
||||
[](const ::testing::TestParamInfo<MyTestSuite::ParamType>& info) {
|
||||
testing::Values(...),
|
||||
[](const testing::TestParamInfo<MyTestSuite::ParamType>& info) {
|
||||
// Can use info.param here to generate the test suffix
|
||||
std::string name = ...
|
||||
return name;
|
||||
|
|
@ -135,9 +137,107 @@ For more information, see
|
|||
See also
|
||||
[`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST`](#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST).
|
||||
|
||||
###### Using `ConvertGenerator`
|
||||
|
||||
The functions listed in the table above appear to return generators that create
|
||||
values of the desired types, but this is not generally the case. Rather, they
|
||||
typically return factory objects that convert to the the desired generators.
|
||||
This affords some flexibility in allowing you to specify values of types that
|
||||
are different from, yet implicitly convertible to, the actual parameter type
|
||||
required by your fixture class.
|
||||
|
||||
For example, you can do the following with a fixture that requires an `int`
|
||||
parameter:
|
||||
|
||||
```cpp
|
||||
INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
|
||||
testing::Values(1, 1.2)); // Yes, Values() supports heterogeneous argument types.
|
||||
```
|
||||
|
||||
It might seem obvious that `1.2` — a `double` — will be converted to
|
||||
an `int` but in actuality it requires some template gymnastics involving the
|
||||
indirection described in the previous paragraph.
|
||||
|
||||
What if your parameter type is not implicitly convertible from the generated
|
||||
type but is *explicitly* convertible? There will be no automatic conversion, but
|
||||
you can force it by applying `ConvertGenerator<T>`. The compiler can
|
||||
automatically deduce the target type (your fixture's parameter type), but
|
||||
because of the aforementioned indirection it cannot decide what the generated
|
||||
type should be. You need to tell it, by providing the type `T` explicitly. Thus
|
||||
`T` should not be your fixture's parameter type, but rather an intermediate type
|
||||
that is supported by the factory object, and which can be `static_cast` to the
|
||||
fixture's parameter type:
|
||||
|
||||
```cpp
|
||||
// The fixture's parameter type.
|
||||
class MyParam {
|
||||
public:
|
||||
// Explicit converting ctor.
|
||||
explicit MyParam(const std::tuple<int, bool>& t);
|
||||
...
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
|
||||
ConvertGenerator<std::tuple<int, bool>>(Combine(Values(0.1, 1.2), Bool())));
|
||||
```
|
||||
|
||||
In this example `Combine` supports the generation of `std::tuple<int, bool>>`
|
||||
objects (even though the provided values for the first tuple element are
|
||||
`double`s) and those `tuple`s get converted into `MyParam` objects by virtue of
|
||||
the call to `ConvertGenerator`.
|
||||
|
||||
For parameter types that are not convertible from the generated types you can
|
||||
provide a callable that does the conversion. The callable accepts an object of
|
||||
the generated type and returns an object of the fixture's parameter type. The
|
||||
generated type can often be deduced by the compiler from the callable's call
|
||||
signature so you do not usually need specify it explicitly (but see a caveat
|
||||
below).
|
||||
|
||||
```cpp
|
||||
// The fixture's parameter type.
|
||||
class MyParam {
|
||||
public:
|
||||
MyParam(int, bool);
|
||||
...
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
|
||||
ConvertGenerator(Combine(Values(1, 1.2), Bool()),
|
||||
[](const std::tuple<int, bool>& t){
|
||||
const auto [i, b] = t;
|
||||
return MyParam(i, b);
|
||||
}));
|
||||
```
|
||||
|
||||
The callable may be anything that can be used to initialize a `std::function`
|
||||
with the appropriate call signature. Note the callable's return object gets
|
||||
`static_cast` to the fixture's parameter type, so it does not have to be of that
|
||||
exact type, only convertible to it.
|
||||
|
||||
**Caveat:** Consider the following example.
|
||||
|
||||
```cpp
|
||||
INSTANTIATE_TEST_SUITE_P(MyInstantiation, MyTestSuite,
|
||||
ConvertGenerator(Values(std::string("s")), [](std::string_view s) { ... }));
|
||||
```
|
||||
|
||||
The `string` argument gets copied into the factory object returned by `Values`.
|
||||
Then, because the generated type deduced from the lambda is `string_view`, the
|
||||
factory object spawns a generator that holds a `string_view` referencing that
|
||||
`string`. Unfortunately, by the time this generator gets invoked, the factory
|
||||
object is gone and the `string_view` is dangling.
|
||||
|
||||
To overcome this problem you can specify the generated type explicitly:
|
||||
`ConvertGenerator<std::string>(Values(std::string("s")), [](std::string_view s)
|
||||
{ ... })`. Alternatively, you can change the lambda's signature to take a
|
||||
`std::string` or a `const std::string&` (the latter will not leave you with a
|
||||
dangling reference because the type deduction strips off the reference and the
|
||||
`const`).
|
||||
|
||||
### TYPED_TEST_SUITE {#TYPED_TEST_SUITE}
|
||||
|
||||
`TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`)`
|
||||
`TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`,`*`NameGenerator`*`)`
|
||||
|
||||
Defines a typed test suite based on the test fixture *`TestFixtureName`*. The
|
||||
test suite name is *`TestFixtureName`*.
|
||||
|
|
@ -147,7 +247,7 @@ type, for example:
|
|||
|
||||
```cpp
|
||||
template <typename T>
|
||||
class MyFixture : public ::testing::Test {
|
||||
class MyFixture : public testing::Test {
|
||||
public:
|
||||
...
|
||||
using List = std::list<T>;
|
||||
|
|
@ -167,6 +267,22 @@ TYPED_TEST_SUITE(MyFixture, MyTypes);
|
|||
The type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_SUITE`
|
||||
macro to parse correctly.
|
||||
|
||||
The optional third argument *`NameGenerator`* allows specifying a class that
|
||||
exposes a templated static function `GetName(int)`. For example:
|
||||
|
||||
```cpp
|
||||
class NameGenerator {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int) {
|
||||
if constexpr (std::is_same_v<T, char>) return "char";
|
||||
if constexpr (std::is_same_v<T, int>) return "int";
|
||||
if constexpr (std::is_same_v<T, unsigned int>) return "unsignedInt";
|
||||
}
|
||||
};
|
||||
TYPED_TEST_SUITE(MyFixture, MyTypes, NameGenerator);
|
||||
```
|
||||
|
||||
See also [`TYPED_TEST`](#TYPED_TEST) and
|
||||
[Typed Tests](../advanced.md#typed-tests) for more information.
|
||||
|
||||
|
|
@ -276,7 +392,8 @@ must be registered with
|
|||
The argument *`InstantiationName`* is a unique name for the instantiation of the
|
||||
test suite, to distinguish between multiple instantiations. In test output, the
|
||||
instantiation name is added as a prefix to the test suite name
|
||||
*`TestSuiteName`*.
|
||||
*`TestSuiteName`*. If *`InstantiationName`* is empty
|
||||
(`INSTANTIATE_TYPED_TEST_SUITE_P(, ...)`), no prefix is added.
|
||||
|
||||
The argument *`Types`* is a [`Types`](#Types) object representing the list of
|
||||
types to run the tests on, for example:
|
||||
|
|
@ -323,7 +440,7 @@ Then the test code should look like:
|
|||
```cpp
|
||||
namespace my_namespace {
|
||||
|
||||
class MyClassTest : public ::testing::Test {
|
||||
class MyClassTest : public testing::Test {
|
||||
...
|
||||
};
|
||||
|
||||
|
|
@ -386,7 +503,7 @@ GoogleTest defines the following classes and types to help with writing tests.
|
|||
|
||||
### AssertionResult {#AssertionResult}
|
||||
|
||||
`::testing::AssertionResult`
|
||||
`testing::AssertionResult`
|
||||
|
||||
A class for indicating whether an assertion was successful.
|
||||
|
||||
|
|
@ -400,14 +517,14 @@ To create an instance of this class, use one of the factory functions
|
|||
|
||||
### AssertionException {#AssertionException}
|
||||
|
||||
`::testing::AssertionException`
|
||||
`testing::AssertionException`
|
||||
|
||||
Exception which can be thrown from
|
||||
[`TestEventListener::OnTestPartResult`](#TestEventListener::OnTestPartResult).
|
||||
|
||||
### EmptyTestEventListener {#EmptyTestEventListener}
|
||||
|
||||
`::testing::EmptyTestEventListener`
|
||||
`testing::EmptyTestEventListener`
|
||||
|
||||
Provides an empty implementation of all methods in the
|
||||
[`TestEventListener`](#TestEventListener) interface, such that a subclass only
|
||||
|
|
@ -415,7 +532,7 @@ needs to override the methods it cares about.
|
|||
|
||||
### Environment {#Environment}
|
||||
|
||||
`::testing::Environment`
|
||||
`testing::Environment`
|
||||
|
||||
Represents a global test environment. See
|
||||
[Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down).
|
||||
|
|
@ -436,7 +553,7 @@ Override this to define how to tear down the environment.
|
|||
|
||||
### ScopedTrace {#ScopedTrace}
|
||||
|
||||
`::testing::ScopedTrace`
|
||||
`testing::ScopedTrace`
|
||||
|
||||
An instance of this class causes a trace to be included in every test failure
|
||||
message generated by code in the scope of the lifetime of the `ScopedTrace`
|
||||
|
|
@ -452,7 +569,7 @@ ScopedTrace(const char* file, int line, const T& message)
|
|||
Example usage:
|
||||
|
||||
```cpp
|
||||
::testing::ScopedTrace trace("file.cc", 123, "message");
|
||||
testing::ScopedTrace trace("file.cc", 123, "message");
|
||||
```
|
||||
|
||||
The resulting trace includes the given source file path and line number, and the
|
||||
|
|
@ -463,7 +580,7 @@ See also [`SCOPED_TRACE`](#SCOPED_TRACE).
|
|||
|
||||
### Test {#Test}
|
||||
|
||||
`::testing::Test`
|
||||
`testing::Test`
|
||||
|
||||
The abstract class that all tests inherit from. `Test` is not copyable.
|
||||
|
||||
|
|
@ -551,7 +668,7 @@ after running each individual test.
|
|||
|
||||
### TestWithParam {#TestWithParam}
|
||||
|
||||
`::testing::TestWithParam<T>`
|
||||
`testing::TestWithParam<T>`
|
||||
|
||||
A convenience class which inherits from both [`Test`](#Test) and
|
||||
[`WithParamInterface<T>`](#WithParamInterface).
|
||||
|
|
@ -671,7 +788,7 @@ during execution of `SetUpTestSuite` and `TearDownTestSuite`.
|
|||
|
||||
### TestInfo {#TestInfo}
|
||||
|
||||
`::testing::TestInfo`
|
||||
`testing::TestInfo`
|
||||
|
||||
Stores information about a test.
|
||||
|
||||
|
|
@ -750,7 +867,7 @@ Returns the result of the test. See [`TestResult`](#TestResult).
|
|||
|
||||
### TestParamInfo {#TestParamInfo}
|
||||
|
||||
`::testing::TestParamInfo<T>`
|
||||
`testing::TestParamInfo<T>`
|
||||
|
||||
Describes a parameter to a value-parameterized test. The type `T` is the type of
|
||||
the parameter.
|
||||
|
|
@ -760,7 +877,7 @@ and its integer index respectively.
|
|||
|
||||
### UnitTest {#UnitTest}
|
||||
|
||||
`::testing::UnitTest`
|
||||
`testing::UnitTest`
|
||||
|
||||
This class contains information about the test program.
|
||||
|
||||
|
|
@ -928,7 +1045,7 @@ GoogleTest. See [`TestEventListeners`](#TestEventListeners).
|
|||
|
||||
### TestEventListener {#TestEventListener}
|
||||
|
||||
`::testing::TestEventListener`
|
||||
`testing::TestEventListener`
|
||||
|
||||
The interface for tracing execution of tests. The methods below are listed in
|
||||
the order the corresponding events are fired.
|
||||
|
|
@ -1026,7 +1143,7 @@ Fired after all test activities have ended.
|
|||
|
||||
### TestEventListeners {#TestEventListeners}
|
||||
|
||||
`::testing::TestEventListeners`
|
||||
`testing::TestEventListeners`
|
||||
|
||||
Lets users add listeners to track events in GoogleTest.
|
||||
|
||||
|
|
@ -1071,7 +1188,7 @@ the caller and makes this function return `NULL` the next time.
|
|||
|
||||
### TestPartResult {#TestPartResult}
|
||||
|
||||
`::testing::TestPartResult`
|
||||
`testing::TestPartResult`
|
||||
|
||||
A copyable object representing the result of a test part (i.e. an assertion or
|
||||
an explicit `FAIL()`, `ADD_FAILURE()`, or `SUCCESS()`).
|
||||
|
|
@ -1153,7 +1270,7 @@ Returns true if and only if the test part failed.
|
|||
|
||||
### TestProperty {#TestProperty}
|
||||
|
||||
`::testing::TestProperty`
|
||||
`testing::TestProperty`
|
||||
|
||||
A copyable object representing a user-specified test property which can be
|
||||
output as a key/value string pair.
|
||||
|
|
@ -1180,7 +1297,7 @@ Sets a new value, overriding the previous one.
|
|||
|
||||
### TestResult {#TestResult}
|
||||
|
||||
`::testing::TestResult`
|
||||
`testing::TestResult`
|
||||
|
||||
Contains information about the result of a single test.
|
||||
|
||||
|
|
@ -1261,20 +1378,20 @@ range, aborts the program.
|
|||
|
||||
### TimeInMillis {#TimeInMillis}
|
||||
|
||||
`::testing::TimeInMillis`
|
||||
`testing::TimeInMillis`
|
||||
|
||||
An integer type representing time in milliseconds.
|
||||
|
||||
### Types {#Types}
|
||||
|
||||
`::testing::Types<T...>`
|
||||
`testing::Types<T...>`
|
||||
|
||||
Represents a list of types for use in typed tests and type-parameterized tests.
|
||||
|
||||
The template argument `T...` can be any number of types, for example:
|
||||
|
||||
```
|
||||
::testing::Types<char, int, unsigned int>
|
||||
testing::Types<char, int, unsigned int>
|
||||
```
|
||||
|
||||
See [Typed Tests](../advanced.md#typed-tests) and
|
||||
|
|
@ -1283,7 +1400,7 @@ information.
|
|||
|
||||
### WithParamInterface {#WithParamInterface}
|
||||
|
||||
`::testing::WithParamInterface<T>`
|
||||
`testing::WithParamInterface<T>`
|
||||
|
||||
The pure interface class that all value-parameterized tests inherit from.
|
||||
|
||||
|
|
@ -1309,14 +1426,16 @@ tests.
|
|||
|
||||
### InitGoogleTest {#InitGoogleTest}
|
||||
|
||||
`void ::testing::InitGoogleTest(int* argc, char** argv)` \
|
||||
`void ::testing::InitGoogleTest(int* argc, wchar_t** argv)` \
|
||||
`void ::testing::InitGoogleTest()`
|
||||
`void testing::InitGoogleTest(int* argc, char** argv)` \
|
||||
`void testing::InitGoogleTest(int* argc, wchar_t** argv)` \
|
||||
`void testing::InitGoogleTest()`
|
||||
|
||||
Initializes GoogleTest. This must be called before calling
|
||||
[`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line
|
||||
for the flags that GoogleTest recognizes. Whenever a GoogleTest flag is seen, it
|
||||
is removed from `argv`, and `*argc` is decremented.
|
||||
is removed from `argv`, and `*argc` is decremented. Keep in mind that `argv`
|
||||
must terminate with a `NULL` pointer (i.e. `argv[argc]` is `NULL`), which is
|
||||
already the case with the default `argv` passed to `main`.
|
||||
|
||||
No value is returned. Instead, the GoogleTest flag variables are updated.
|
||||
|
||||
|
|
@ -1328,7 +1447,7 @@ platforms where there is no `argc`/`argv`.
|
|||
|
||||
### AddGlobalTestEnvironment {#AddGlobalTestEnvironment}
|
||||
|
||||
`Environment* ::testing::AddGlobalTestEnvironment(Environment* env)`
|
||||
`Environment* testing::AddGlobalTestEnvironment(Environment* env)`
|
||||
|
||||
Adds a test environment to the test program. Must be called before
|
||||
[`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is called. See
|
||||
|
|
@ -1341,7 +1460,7 @@ See also [`Environment`](#Environment).
|
|||
|
||||
```cpp
|
||||
template <typename Factory>
|
||||
TestInfo* ::testing::RegisterTest(const char* test_suite_name, const char* test_name,
|
||||
TestInfo* testing::RegisterTest(const char* test_suite_name, const char* test_name,
|
||||
const char* type_param, const char* value_param,
|
||||
const char* file, int line, Factory factory)
|
||||
```
|
||||
|
|
@ -1380,27 +1499,27 @@ an all-caps name.
|
|||
|
||||
### AssertionSuccess {#AssertionSuccess}
|
||||
|
||||
`AssertionResult ::testing::AssertionSuccess()`
|
||||
`AssertionResult testing::AssertionSuccess()`
|
||||
|
||||
Creates a successful assertion result. See
|
||||
[`AssertionResult`](#AssertionResult).
|
||||
|
||||
### AssertionFailure {#AssertionFailure}
|
||||
|
||||
`AssertionResult ::testing::AssertionFailure()`
|
||||
`AssertionResult testing::AssertionFailure()`
|
||||
|
||||
Creates a failed assertion result. Use the `<<` operator to store a failure
|
||||
message:
|
||||
|
||||
```cpp
|
||||
::testing::AssertionFailure() << "My failure message";
|
||||
testing::AssertionFailure() << "My failure message";
|
||||
```
|
||||
|
||||
See [`AssertionResult`](#AssertionResult).
|
||||
|
||||
### StaticAssertTypeEq {#StaticAssertTypeEq}
|
||||
|
||||
`::testing::StaticAssertTypeEq<T1, T2>()`
|
||||
`testing::StaticAssertTypeEq<T1, T2>()`
|
||||
|
||||
Compile-time assertion for type equality. Compiles if and only if `T1` and `T2`
|
||||
are the same type. The value it returns is irrelevant.
|
||||
|
|
@ -1409,7 +1528,7 @@ See [Type Assertions](../advanced.md#type-assertions) for more information.
|
|||
|
||||
### PrintToString {#PrintToString}
|
||||
|
||||
`std::string ::testing::PrintToString(x)`
|
||||
`std::string testing::PrintToString(x)`
|
||||
|
||||
Prints any value `x` using GoogleTest's value printer.
|
||||
|
||||
|
|
@ -1419,7 +1538,7 @@ for more information.
|
|||
|
||||
### PrintToStringParamName {#PrintToStringParamName}
|
||||
|
||||
`std::string ::testing::PrintToStringParamName(TestParamInfo<T>& info)`
|
||||
`std::string testing::PrintToStringParamName(TestParamInfo<T>& info)`
|
||||
|
||||
A built-in parameterized test name generator which returns the result of
|
||||
[`PrintToString`](#PrintToString) called on `info.param`. Does not work when the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue