1f92157deSopenharmony_ci# Testing Reference 2f92157deSopenharmony_ci 3f92157deSopenharmony_ci<!--* toc_depth: 3 *--> 4f92157deSopenharmony_ci 5f92157deSopenharmony_ciThis page lists the facilities provided by GoogleTest for writing test programs. 6f92157deSopenharmony_ciTo use them, include the header `gtest/gtest.h`. 7f92157deSopenharmony_ci 8f92157deSopenharmony_ci## Macros 9f92157deSopenharmony_ci 10f92157deSopenharmony_ciGoogleTest defines the following macros for writing tests. 11f92157deSopenharmony_ci 12f92157deSopenharmony_ci### TEST {#TEST} 13f92157deSopenharmony_ci 14f92157deSopenharmony_ci<pre> 15f92157deSopenharmony_ciTEST(<em>TestSuiteName</em>, <em>TestName</em>) { 16f92157deSopenharmony_ci ... <em>statements</em> ... 17f92157deSopenharmony_ci} 18f92157deSopenharmony_ci</pre> 19f92157deSopenharmony_ci 20f92157deSopenharmony_ciDefines an individual test named *`TestName`* in the test suite 21f92157deSopenharmony_ci*`TestSuiteName`*, consisting of the given statements. 22f92157deSopenharmony_ci 23f92157deSopenharmony_ciBoth arguments *`TestSuiteName`* and *`TestName`* must be valid C++ identifiers 24f92157deSopenharmony_ciand must not contain underscores (`_`). Tests in different test suites can have 25f92157deSopenharmony_cithe same individual name. 26f92157deSopenharmony_ci 27f92157deSopenharmony_ciThe statements within the test body can be any code under test. 28f92157deSopenharmony_ci[Assertions](assertions.md) used within the test body determine the outcome of 29f92157deSopenharmony_cithe test. 30f92157deSopenharmony_ci 31f92157deSopenharmony_ci### TEST_F {#TEST_F} 32f92157deSopenharmony_ci 33f92157deSopenharmony_ci<pre> 34f92157deSopenharmony_ciTEST_F(<em>TestFixtureName</em>, <em>TestName</em>) { 35f92157deSopenharmony_ci ... <em>statements</em> ... 36f92157deSopenharmony_ci} 37f92157deSopenharmony_ci</pre> 38f92157deSopenharmony_ci 39f92157deSopenharmony_ciDefines an individual test named *`TestName`* that uses the test fixture class 40f92157deSopenharmony_ci*`TestFixtureName`*. The test suite name is *`TestFixtureName`*. 41f92157deSopenharmony_ci 42f92157deSopenharmony_ciBoth arguments *`TestFixtureName`* and *`TestName`* must be valid C++ 43f92157deSopenharmony_ciidentifiers and must not contain underscores (`_`). *`TestFixtureName`* must be 44f92157deSopenharmony_cithe name of a test fixture class—see 45f92157deSopenharmony_ci[Test Fixtures](../primer.md#same-data-multiple-tests). 46f92157deSopenharmony_ci 47f92157deSopenharmony_ciThe statements within the test body can be any code under test. 48f92157deSopenharmony_ci[Assertions](assertions.md) used within the test body determine the outcome of 49f92157deSopenharmony_cithe test. 50f92157deSopenharmony_ci 51f92157deSopenharmony_ci### TEST_P {#TEST_P} 52f92157deSopenharmony_ci 53f92157deSopenharmony_ci<pre> 54f92157deSopenharmony_ciTEST_P(<em>TestFixtureName</em>, <em>TestName</em>) { 55f92157deSopenharmony_ci ... <em>statements</em> ... 56f92157deSopenharmony_ci} 57f92157deSopenharmony_ci</pre> 58f92157deSopenharmony_ci 59f92157deSopenharmony_ciDefines an individual value-parameterized test named *`TestName`* that uses the 60f92157deSopenharmony_citest fixture class *`TestFixtureName`*. The test suite name is 61f92157deSopenharmony_ci*`TestFixtureName`*. 62f92157deSopenharmony_ci 63f92157deSopenharmony_ciBoth arguments *`TestFixtureName`* and *`TestName`* must be valid C++ 64f92157deSopenharmony_ciidentifiers and must not contain underscores (`_`). *`TestFixtureName`* must be 65f92157deSopenharmony_cithe name of a value-parameterized test fixture class—see 66f92157deSopenharmony_ci[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 67f92157deSopenharmony_ci 68f92157deSopenharmony_ciThe statements within the test body can be any code under test. Within the test 69f92157deSopenharmony_cibody, the test parameter can be accessed with the `GetParam()` function (see 70f92157deSopenharmony_ci[`WithParamInterface`](#WithParamInterface)). For example: 71f92157deSopenharmony_ci 72f92157deSopenharmony_ci```cpp 73f92157deSopenharmony_ciTEST_P(MyTestSuite, DoesSomething) { 74f92157deSopenharmony_ci ... 75f92157deSopenharmony_ci EXPECT_TRUE(DoSomething(GetParam())); 76f92157deSopenharmony_ci ... 77f92157deSopenharmony_ci} 78f92157deSopenharmony_ci``` 79f92157deSopenharmony_ci 80f92157deSopenharmony_ci[Assertions](assertions.md) used within the test body determine the outcome of 81f92157deSopenharmony_cithe test. 82f92157deSopenharmony_ci 83f92157deSopenharmony_ciSee also [`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P). 84f92157deSopenharmony_ci 85f92157deSopenharmony_ci### INSTANTIATE_TEST_SUITE_P {#INSTANTIATE_TEST_SUITE_P} 86f92157deSopenharmony_ci 87f92157deSopenharmony_ci`INSTANTIATE_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`param_generator`*`)` 88f92157deSopenharmony_ci\ 89f92157deSopenharmony_ci`INSTANTIATE_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`param_generator`*`,`*`name_generator`*`)` 90f92157deSopenharmony_ci 91f92157deSopenharmony_ciInstantiates the value-parameterized test suite *`TestSuiteName`* (defined with 92f92157deSopenharmony_ci[`TEST_P`](#TEST_P)). 93f92157deSopenharmony_ci 94f92157deSopenharmony_ciThe argument *`InstantiationName`* is a unique name for the instantiation of the 95f92157deSopenharmony_citest suite, to distinguish between multiple instantiations. In test output, the 96f92157deSopenharmony_ciinstantiation name is added as a prefix to the test suite name 97f92157deSopenharmony_ci*`TestSuiteName`*. 98f92157deSopenharmony_ci 99f92157deSopenharmony_ciThe argument *`param_generator`* is one of the following GoogleTest-provided 100f92157deSopenharmony_cifunctions that generate the test parameters, all defined in the `::testing` 101f92157deSopenharmony_cinamespace: 102f92157deSopenharmony_ci 103f92157deSopenharmony_ci<span id="param-generators"></span> 104f92157deSopenharmony_ci 105f92157deSopenharmony_ci| Parameter Generator | Behavior | 106f92157deSopenharmony_ci| ------------------- | ---------------------------------------------------- | 107f92157deSopenharmony_ci| `Range(begin, end [, step])` | Yields values `{begin, begin+step, begin+step+step, ...}`. The values do not include `end`. `step` defaults to 1. | 108f92157deSopenharmony_ci| `Values(v1, v2, ..., vN)` | Yields values `{v1, v2, ..., vN}`. | 109f92157deSopenharmony_ci| `ValuesIn(container)` or `ValuesIn(begin,end)` | Yields values from a C-style array, an STL-style container, or an iterator range `[begin, end)`. | 110f92157deSopenharmony_ci| `Bool()` | Yields sequence `{false, true}`. | 111f92157deSopenharmony_ci| `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`. | 112f92157deSopenharmony_ci| `ConvertGenerator<T>(g)` | Yields values generated by generator `g`, `static_cast` to `T`. | 113f92157deSopenharmony_ciThe optional last argument *`name_generator`* is a function or functor that 114f92157deSopenharmony_cigenerates custom test name suffixes based on the test parameters. The function 115f92157deSopenharmony_cimust accept an argument of type 116f92157deSopenharmony_ci[`TestParamInfo<class ParamType>`](#TestParamInfo) and return a `std::string`. 117f92157deSopenharmony_ciThe test name suffix can only contain alphanumeric characters and underscores. 118f92157deSopenharmony_ciGoogleTest provides [`PrintToStringParamName`](#PrintToStringParamName), or a 119f92157deSopenharmony_cicustom function can be used for more control: 120f92157deSopenharmony_ci 121f92157deSopenharmony_ci```cpp 122f92157deSopenharmony_ciINSTANTIATE_TEST_SUITE_P( 123f92157deSopenharmony_ci MyInstantiation, MyTestSuite, 124f92157deSopenharmony_ci ::testing::Values(...), 125f92157deSopenharmony_ci [](const ::testing::TestParamInfo<MyTestSuite::ParamType>& info) { 126f92157deSopenharmony_ci // Can use info.param here to generate the test suffix 127f92157deSopenharmony_ci std::string name = ... 128f92157deSopenharmony_ci return name; 129f92157deSopenharmony_ci }); 130f92157deSopenharmony_ci``` 131f92157deSopenharmony_ci 132f92157deSopenharmony_ciFor more information, see 133f92157deSopenharmony_ci[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 134f92157deSopenharmony_ci 135f92157deSopenharmony_ciSee also 136f92157deSopenharmony_ci[`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST`](#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST). 137f92157deSopenharmony_ci 138f92157deSopenharmony_ci### TYPED_TEST_SUITE {#TYPED_TEST_SUITE} 139f92157deSopenharmony_ci 140f92157deSopenharmony_ci`TYPED_TEST_SUITE(`*`TestFixtureName`*`,`*`Types`*`)` 141f92157deSopenharmony_ci 142f92157deSopenharmony_ciDefines a typed test suite based on the test fixture *`TestFixtureName`*. The 143f92157deSopenharmony_citest suite name is *`TestFixtureName`*. 144f92157deSopenharmony_ci 145f92157deSopenharmony_ciThe argument *`TestFixtureName`* is a fixture class template, parameterized by a 146f92157deSopenharmony_citype, for example: 147f92157deSopenharmony_ci 148f92157deSopenharmony_ci```cpp 149f92157deSopenharmony_citemplate <typename T> 150f92157deSopenharmony_ciclass MyFixture : public ::testing::Test { 151f92157deSopenharmony_ci public: 152f92157deSopenharmony_ci ... 153f92157deSopenharmony_ci using List = std::list<T>; 154f92157deSopenharmony_ci static T shared_; 155f92157deSopenharmony_ci T value_; 156f92157deSopenharmony_ci}; 157f92157deSopenharmony_ci``` 158f92157deSopenharmony_ci 159f92157deSopenharmony_ciThe argument *`Types`* is a [`Types`](#Types) object representing the list of 160f92157deSopenharmony_citypes to run the tests on, for example: 161f92157deSopenharmony_ci 162f92157deSopenharmony_ci```cpp 163f92157deSopenharmony_ciusing MyTypes = ::testing::Types<char, int, unsigned int>; 164f92157deSopenharmony_ciTYPED_TEST_SUITE(MyFixture, MyTypes); 165f92157deSopenharmony_ci``` 166f92157deSopenharmony_ci 167f92157deSopenharmony_ciThe type alias (`using` or `typedef`) is necessary for the `TYPED_TEST_SUITE` 168f92157deSopenharmony_cimacro to parse correctly. 169f92157deSopenharmony_ci 170f92157deSopenharmony_ciSee also [`TYPED_TEST`](#TYPED_TEST) and 171f92157deSopenharmony_ci[Typed Tests](../advanced.md#typed-tests) for more information. 172f92157deSopenharmony_ci 173f92157deSopenharmony_ci### TYPED_TEST {#TYPED_TEST} 174f92157deSopenharmony_ci 175f92157deSopenharmony_ci<pre> 176f92157deSopenharmony_ciTYPED_TEST(<em>TestSuiteName</em>, <em>TestName</em>) { 177f92157deSopenharmony_ci ... <em>statements</em> ... 178f92157deSopenharmony_ci} 179f92157deSopenharmony_ci</pre> 180f92157deSopenharmony_ci 181f92157deSopenharmony_ciDefines an individual typed test named *`TestName`* in the typed test suite 182f92157deSopenharmony_ci*`TestSuiteName`*. The test suite must be defined with 183f92157deSopenharmony_ci[`TYPED_TEST_SUITE`](#TYPED_TEST_SUITE). 184f92157deSopenharmony_ci 185f92157deSopenharmony_ciWithin the test body, the special name `TypeParam` refers to the type parameter, 186f92157deSopenharmony_ciand `TestFixture` refers to the fixture class. See the following example: 187f92157deSopenharmony_ci 188f92157deSopenharmony_ci```cpp 189f92157deSopenharmony_ciTYPED_TEST(MyFixture, Example) { 190f92157deSopenharmony_ci // Inside a test, refer to the special name TypeParam to get the type 191f92157deSopenharmony_ci // parameter. Since we are inside a derived class template, C++ requires 192f92157deSopenharmony_ci // us to visit the members of MyFixture via 'this'. 193f92157deSopenharmony_ci TypeParam n = this->value_; 194f92157deSopenharmony_ci 195f92157deSopenharmony_ci // To visit static members of the fixture, add the 'TestFixture::' 196f92157deSopenharmony_ci // prefix. 197f92157deSopenharmony_ci n += TestFixture::shared_; 198f92157deSopenharmony_ci 199f92157deSopenharmony_ci // To refer to typedefs in the fixture, add the 'typename TestFixture::' 200f92157deSopenharmony_ci // prefix. The 'typename' is required to satisfy the compiler. 201f92157deSopenharmony_ci typename TestFixture::List values; 202f92157deSopenharmony_ci 203f92157deSopenharmony_ci values.push_back(n); 204f92157deSopenharmony_ci ... 205f92157deSopenharmony_ci} 206f92157deSopenharmony_ci``` 207f92157deSopenharmony_ci 208f92157deSopenharmony_ciFor more information, see [Typed Tests](../advanced.md#typed-tests). 209f92157deSopenharmony_ci 210f92157deSopenharmony_ci### TYPED_TEST_SUITE_P {#TYPED_TEST_SUITE_P} 211f92157deSopenharmony_ci 212f92157deSopenharmony_ci`TYPED_TEST_SUITE_P(`*`TestFixtureName`*`)` 213f92157deSopenharmony_ci 214f92157deSopenharmony_ciDefines a type-parameterized test suite based on the test fixture 215f92157deSopenharmony_ci*`TestFixtureName`*. The test suite name is *`TestFixtureName`*. 216f92157deSopenharmony_ci 217f92157deSopenharmony_ciThe argument *`TestFixtureName`* is a fixture class template, parameterized by a 218f92157deSopenharmony_citype. See [`TYPED_TEST_SUITE`](#TYPED_TEST_SUITE) for an example. 219f92157deSopenharmony_ci 220f92157deSopenharmony_ciSee also [`TYPED_TEST_P`](#TYPED_TEST_P) and 221f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 222f92157deSopenharmony_ciinformation. 223f92157deSopenharmony_ci 224f92157deSopenharmony_ci### TYPED_TEST_P {#TYPED_TEST_P} 225f92157deSopenharmony_ci 226f92157deSopenharmony_ci<pre> 227f92157deSopenharmony_ciTYPED_TEST_P(<em>TestSuiteName</em>, <em>TestName</em>) { 228f92157deSopenharmony_ci ... <em>statements</em> ... 229f92157deSopenharmony_ci} 230f92157deSopenharmony_ci</pre> 231f92157deSopenharmony_ci 232f92157deSopenharmony_ciDefines an individual type-parameterized test named *`TestName`* in the 233f92157deSopenharmony_citype-parameterized test suite *`TestSuiteName`*. The test suite must be defined 234f92157deSopenharmony_ciwith [`TYPED_TEST_SUITE_P`](#TYPED_TEST_SUITE_P). 235f92157deSopenharmony_ci 236f92157deSopenharmony_ciWithin the test body, the special name `TypeParam` refers to the type parameter, 237f92157deSopenharmony_ciand `TestFixture` refers to the fixture class. See [`TYPED_TEST`](#TYPED_TEST) 238f92157deSopenharmony_cifor an example. 239f92157deSopenharmony_ci 240f92157deSopenharmony_ciSee also [`REGISTER_TYPED_TEST_SUITE_P`](#REGISTER_TYPED_TEST_SUITE_P) and 241f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 242f92157deSopenharmony_ciinformation. 243f92157deSopenharmony_ci 244f92157deSopenharmony_ci### REGISTER_TYPED_TEST_SUITE_P {#REGISTER_TYPED_TEST_SUITE_P} 245f92157deSopenharmony_ci 246f92157deSopenharmony_ci`REGISTER_TYPED_TEST_SUITE_P(`*`TestSuiteName`*`,`*`TestNames...`*`)` 247f92157deSopenharmony_ci 248f92157deSopenharmony_ciRegisters the type-parameterized tests *`TestNames...`* of the test suite 249f92157deSopenharmony_ci*`TestSuiteName`*. The test suite and tests must be defined with 250f92157deSopenharmony_ci[`TYPED_TEST_SUITE_P`](#TYPED_TEST_SUITE_P) and [`TYPED_TEST_P`](#TYPED_TEST_P). 251f92157deSopenharmony_ci 252f92157deSopenharmony_ciFor example: 253f92157deSopenharmony_ci 254f92157deSopenharmony_ci```cpp 255f92157deSopenharmony_ci// Define the test suite and tests. 256f92157deSopenharmony_ciTYPED_TEST_SUITE_P(MyFixture); 257f92157deSopenharmony_ciTYPED_TEST_P(MyFixture, HasPropertyA) { ... } 258f92157deSopenharmony_ciTYPED_TEST_P(MyFixture, HasPropertyB) { ... } 259f92157deSopenharmony_ci 260f92157deSopenharmony_ci// Register the tests in the test suite. 261f92157deSopenharmony_ciREGISTER_TYPED_TEST_SUITE_P(MyFixture, HasPropertyA, HasPropertyB); 262f92157deSopenharmony_ci``` 263f92157deSopenharmony_ci 264f92157deSopenharmony_ciSee also [`INSTANTIATE_TYPED_TEST_SUITE_P`](#INSTANTIATE_TYPED_TEST_SUITE_P) and 265f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 266f92157deSopenharmony_ciinformation. 267f92157deSopenharmony_ci 268f92157deSopenharmony_ci### INSTANTIATE_TYPED_TEST_SUITE_P {#INSTANTIATE_TYPED_TEST_SUITE_P} 269f92157deSopenharmony_ci 270f92157deSopenharmony_ci`INSTANTIATE_TYPED_TEST_SUITE_P(`*`InstantiationName`*`,`*`TestSuiteName`*`,`*`Types`*`)` 271f92157deSopenharmony_ci 272f92157deSopenharmony_ciInstantiates the type-parameterized test suite *`TestSuiteName`*. The test suite 273f92157deSopenharmony_cimust be registered with 274f92157deSopenharmony_ci[`REGISTER_TYPED_TEST_SUITE_P`](#REGISTER_TYPED_TEST_SUITE_P). 275f92157deSopenharmony_ci 276f92157deSopenharmony_ciThe argument *`InstantiationName`* is a unique name for the instantiation of the 277f92157deSopenharmony_citest suite, to distinguish between multiple instantiations. In test output, the 278f92157deSopenharmony_ciinstantiation name is added as a prefix to the test suite name 279f92157deSopenharmony_ci*`TestSuiteName`*. 280f92157deSopenharmony_ci 281f92157deSopenharmony_ciThe argument *`Types`* is a [`Types`](#Types) object representing the list of 282f92157deSopenharmony_citypes to run the tests on, for example: 283f92157deSopenharmony_ci 284f92157deSopenharmony_ci```cpp 285f92157deSopenharmony_ciusing MyTypes = ::testing::Types<char, int, unsigned int>; 286f92157deSopenharmony_ciINSTANTIATE_TYPED_TEST_SUITE_P(MyInstantiation, MyFixture, MyTypes); 287f92157deSopenharmony_ci``` 288f92157deSopenharmony_ci 289f92157deSopenharmony_ciThe type alias (`using` or `typedef`) is necessary for the 290f92157deSopenharmony_ci`INSTANTIATE_TYPED_TEST_SUITE_P` macro to parse correctly. 291f92157deSopenharmony_ci 292f92157deSopenharmony_ciFor more information, see 293f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests). 294f92157deSopenharmony_ci 295f92157deSopenharmony_ci### FRIEND_TEST {#FRIEND_TEST} 296f92157deSopenharmony_ci 297f92157deSopenharmony_ci`FRIEND_TEST(`*`TestSuiteName`*`,`*`TestName`*`)` 298f92157deSopenharmony_ci 299f92157deSopenharmony_ciWithin a class body, declares an individual test as a friend of the class, 300f92157deSopenharmony_cienabling the test to access private class members. 301f92157deSopenharmony_ci 302f92157deSopenharmony_ciIf the class is defined in a namespace, then in order to be friends of the 303f92157deSopenharmony_ciclass, test fixtures and tests must be defined in the exact same namespace, 304f92157deSopenharmony_ciwithout inline or anonymous namespaces. 305f92157deSopenharmony_ci 306f92157deSopenharmony_ciFor example, if the class definition looks like the following: 307f92157deSopenharmony_ci 308f92157deSopenharmony_ci```cpp 309f92157deSopenharmony_cinamespace my_namespace { 310f92157deSopenharmony_ci 311f92157deSopenharmony_ciclass MyClass { 312f92157deSopenharmony_ci friend class MyClassTest; 313f92157deSopenharmony_ci FRIEND_TEST(MyClassTest, HasPropertyA); 314f92157deSopenharmony_ci FRIEND_TEST(MyClassTest, HasPropertyB); 315f92157deSopenharmony_ci ... definition of class MyClass ... 316f92157deSopenharmony_ci}; 317f92157deSopenharmony_ci 318f92157deSopenharmony_ci} // namespace my_namespace 319f92157deSopenharmony_ci``` 320f92157deSopenharmony_ci 321f92157deSopenharmony_ciThen the test code should look like: 322f92157deSopenharmony_ci 323f92157deSopenharmony_ci```cpp 324f92157deSopenharmony_cinamespace my_namespace { 325f92157deSopenharmony_ci 326f92157deSopenharmony_ciclass MyClassTest : public ::testing::Test { 327f92157deSopenharmony_ci ... 328f92157deSopenharmony_ci}; 329f92157deSopenharmony_ci 330f92157deSopenharmony_ciTEST_F(MyClassTest, HasPropertyA) { ... } 331f92157deSopenharmony_ciTEST_F(MyClassTest, HasPropertyB) { ... } 332f92157deSopenharmony_ci 333f92157deSopenharmony_ci} // namespace my_namespace 334f92157deSopenharmony_ci``` 335f92157deSopenharmony_ci 336f92157deSopenharmony_ciSee [Testing Private Code](../advanced.md#testing-private-code) for more 337f92157deSopenharmony_ciinformation. 338f92157deSopenharmony_ci 339f92157deSopenharmony_ci### SCOPED_TRACE {#SCOPED_TRACE} 340f92157deSopenharmony_ci 341f92157deSopenharmony_ci`SCOPED_TRACE(`*`message`*`)` 342f92157deSopenharmony_ci 343f92157deSopenharmony_ciCauses the current file name, line number, and the given message *`message`* to 344f92157deSopenharmony_cibe added to the failure message for each assertion failure that occurs in the 345f92157deSopenharmony_ciscope. 346f92157deSopenharmony_ci 347f92157deSopenharmony_ciFor more information, see 348f92157deSopenharmony_ci[Adding Traces to Assertions](../advanced.md#adding-traces-to-assertions). 349f92157deSopenharmony_ci 350f92157deSopenharmony_ciSee also the [`ScopedTrace` class](#ScopedTrace). 351f92157deSopenharmony_ci 352f92157deSopenharmony_ci### GTEST_SKIP {#GTEST_SKIP} 353f92157deSopenharmony_ci 354f92157deSopenharmony_ci`GTEST_SKIP()` 355f92157deSopenharmony_ci 356f92157deSopenharmony_ciPrevents further test execution at runtime. 357f92157deSopenharmony_ci 358f92157deSopenharmony_ciCan be used in individual test cases or in the `SetUp()` methods of test 359f92157deSopenharmony_cienvironments or test fixtures (classes derived from the 360f92157deSopenharmony_ci[`Environment`](#Environment) or [`Test`](#Test) classes). If used in a global 361f92157deSopenharmony_citest environment `SetUp()` method, it skips all tests in the test program. If 362f92157deSopenharmony_ciused in a test fixture `SetUp()` method, it skips all tests in the corresponding 363f92157deSopenharmony_citest suite. 364f92157deSopenharmony_ci 365f92157deSopenharmony_ciSimilar to assertions, `GTEST_SKIP` allows streaming a custom message into it. 366f92157deSopenharmony_ci 367f92157deSopenharmony_ciSee [Skipping Test Execution](../advanced.md#skipping-test-execution) for more 368f92157deSopenharmony_ciinformation. 369f92157deSopenharmony_ci 370f92157deSopenharmony_ci### GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST {#GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST} 371f92157deSopenharmony_ci 372f92157deSopenharmony_ci`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(`*`TestSuiteName`*`)` 373f92157deSopenharmony_ci 374f92157deSopenharmony_ciAllows the value-parameterized test suite *`TestSuiteName`* to be 375f92157deSopenharmony_ciuninstantiated. 376f92157deSopenharmony_ci 377f92157deSopenharmony_ciBy default, every [`TEST_P`](#TEST_P) call without a corresponding 378f92157deSopenharmony_ci[`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P) call causes a failing 379f92157deSopenharmony_citest in the test suite `GoogleTestVerification`. 380f92157deSopenharmony_ci`GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST` suppresses this failure for the 381f92157deSopenharmony_cigiven test suite. 382f92157deSopenharmony_ci 383f92157deSopenharmony_ci## Classes and types 384f92157deSopenharmony_ci 385f92157deSopenharmony_ciGoogleTest defines the following classes and types to help with writing tests. 386f92157deSopenharmony_ci 387f92157deSopenharmony_ci### AssertionResult {#AssertionResult} 388f92157deSopenharmony_ci 389f92157deSopenharmony_ci`::testing::AssertionResult` 390f92157deSopenharmony_ci 391f92157deSopenharmony_ciA class for indicating whether an assertion was successful. 392f92157deSopenharmony_ci 393f92157deSopenharmony_ciWhen the assertion wasn't successful, the `AssertionResult` object stores a 394f92157deSopenharmony_cinon-empty failure message that can be retrieved with the object's `message()` 395f92157deSopenharmony_cimethod. 396f92157deSopenharmony_ci 397f92157deSopenharmony_ciTo create an instance of this class, use one of the factory functions 398f92157deSopenharmony_ci[`AssertionSuccess()`](#AssertionSuccess) or 399f92157deSopenharmony_ci[`AssertionFailure()`](#AssertionFailure). 400f92157deSopenharmony_ci 401f92157deSopenharmony_ci### AssertionException {#AssertionException} 402f92157deSopenharmony_ci 403f92157deSopenharmony_ci`::testing::AssertionException` 404f92157deSopenharmony_ci 405f92157deSopenharmony_ciException which can be thrown from 406f92157deSopenharmony_ci[`TestEventListener::OnTestPartResult`](#TestEventListener::OnTestPartResult). 407f92157deSopenharmony_ci 408f92157deSopenharmony_ci### EmptyTestEventListener {#EmptyTestEventListener} 409f92157deSopenharmony_ci 410f92157deSopenharmony_ci`::testing::EmptyTestEventListener` 411f92157deSopenharmony_ci 412f92157deSopenharmony_ciProvides an empty implementation of all methods in the 413f92157deSopenharmony_ci[`TestEventListener`](#TestEventListener) interface, such that a subclass only 414f92157deSopenharmony_cineeds to override the methods it cares about. 415f92157deSopenharmony_ci 416f92157deSopenharmony_ci### Environment {#Environment} 417f92157deSopenharmony_ci 418f92157deSopenharmony_ci`::testing::Environment` 419f92157deSopenharmony_ci 420f92157deSopenharmony_ciRepresents a global test environment. See 421f92157deSopenharmony_ci[Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down). 422f92157deSopenharmony_ci 423f92157deSopenharmony_ci#### Protected Methods {#Environment-protected} 424f92157deSopenharmony_ci 425f92157deSopenharmony_ci##### SetUp {#Environment::SetUp} 426f92157deSopenharmony_ci 427f92157deSopenharmony_ci`virtual void Environment::SetUp()` 428f92157deSopenharmony_ci 429f92157deSopenharmony_ciOverride this to define how to set up the environment. 430f92157deSopenharmony_ci 431f92157deSopenharmony_ci##### TearDown {#Environment::TearDown} 432f92157deSopenharmony_ci 433f92157deSopenharmony_ci`virtual void Environment::TearDown()` 434f92157deSopenharmony_ci 435f92157deSopenharmony_ciOverride this to define how to tear down the environment. 436f92157deSopenharmony_ci 437f92157deSopenharmony_ci### ScopedTrace {#ScopedTrace} 438f92157deSopenharmony_ci 439f92157deSopenharmony_ci`::testing::ScopedTrace` 440f92157deSopenharmony_ci 441f92157deSopenharmony_ciAn instance of this class causes a trace to be included in every test failure 442f92157deSopenharmony_cimessage generated by code in the scope of the lifetime of the `ScopedTrace` 443f92157deSopenharmony_ciinstance. The effect is undone with the destruction of the instance. 444f92157deSopenharmony_ci 445f92157deSopenharmony_ciThe `ScopedTrace` constructor has the following form: 446f92157deSopenharmony_ci 447f92157deSopenharmony_ci```cpp 448f92157deSopenharmony_citemplate <typename T> 449f92157deSopenharmony_ciScopedTrace(const char* file, int line, const T& message) 450f92157deSopenharmony_ci``` 451f92157deSopenharmony_ci 452f92157deSopenharmony_ciExample usage: 453f92157deSopenharmony_ci 454f92157deSopenharmony_ci```cpp 455f92157deSopenharmony_ci::testing::ScopedTrace trace("file.cc", 123, "message"); 456f92157deSopenharmony_ci``` 457f92157deSopenharmony_ci 458f92157deSopenharmony_ciThe resulting trace includes the given source file path and line number, and the 459f92157deSopenharmony_cigiven message. The `message` argument can be anything streamable to 460f92157deSopenharmony_ci`std::ostream`. 461f92157deSopenharmony_ci 462f92157deSopenharmony_ciSee also [`SCOPED_TRACE`](#SCOPED_TRACE). 463f92157deSopenharmony_ci 464f92157deSopenharmony_ci### Test {#Test} 465f92157deSopenharmony_ci 466f92157deSopenharmony_ci`::testing::Test` 467f92157deSopenharmony_ci 468f92157deSopenharmony_ciThe abstract class that all tests inherit from. `Test` is not copyable. 469f92157deSopenharmony_ci 470f92157deSopenharmony_ci#### Public Methods {#Test-public} 471f92157deSopenharmony_ci 472f92157deSopenharmony_ci##### SetUpTestSuite {#Test::SetUpTestSuite} 473f92157deSopenharmony_ci 474f92157deSopenharmony_ci`static void Test::SetUpTestSuite()` 475f92157deSopenharmony_ci 476f92157deSopenharmony_ciPerforms shared setup for all tests in the test suite. GoogleTest calls 477f92157deSopenharmony_ci`SetUpTestSuite()` before running the first test in the test suite. 478f92157deSopenharmony_ci 479f92157deSopenharmony_ci##### TearDownTestSuite {#Test::TearDownTestSuite} 480f92157deSopenharmony_ci 481f92157deSopenharmony_ci`static void Test::TearDownTestSuite()` 482f92157deSopenharmony_ci 483f92157deSopenharmony_ciPerforms shared teardown for all tests in the test suite. GoogleTest calls 484f92157deSopenharmony_ci`TearDownTestSuite()` after running the last test in the test suite. 485f92157deSopenharmony_ci 486f92157deSopenharmony_ci##### HasFatalFailure {#Test::HasFatalFailure} 487f92157deSopenharmony_ci 488f92157deSopenharmony_ci`static bool Test::HasFatalFailure()` 489f92157deSopenharmony_ci 490f92157deSopenharmony_ciReturns true if and only if the current test has a fatal failure. 491f92157deSopenharmony_ci 492f92157deSopenharmony_ci##### HasNonfatalFailure {#Test::HasNonfatalFailure} 493f92157deSopenharmony_ci 494f92157deSopenharmony_ci`static bool Test::HasNonfatalFailure()` 495f92157deSopenharmony_ci 496f92157deSopenharmony_ciReturns true if and only if the current test has a nonfatal failure. 497f92157deSopenharmony_ci 498f92157deSopenharmony_ci##### HasFailure {#Test::HasFailure} 499f92157deSopenharmony_ci 500f92157deSopenharmony_ci`static bool Test::HasFailure()` 501f92157deSopenharmony_ci 502f92157deSopenharmony_ciReturns true if and only if the current test has any failure, either fatal or 503f92157deSopenharmony_cinonfatal. 504f92157deSopenharmony_ci 505f92157deSopenharmony_ci##### IsSkipped {#Test::IsSkipped} 506f92157deSopenharmony_ci 507f92157deSopenharmony_ci`static bool Test::IsSkipped()` 508f92157deSopenharmony_ci 509f92157deSopenharmony_ciReturns true if and only if the current test was skipped. 510f92157deSopenharmony_ci 511f92157deSopenharmony_ci##### RecordProperty {#Test::RecordProperty} 512f92157deSopenharmony_ci 513f92157deSopenharmony_ci`static void Test::RecordProperty(const std::string& key, const std::string& 514f92157deSopenharmony_civalue)` \ 515f92157deSopenharmony_ci`static void Test::RecordProperty(const std::string& key, int value)` 516f92157deSopenharmony_ci 517f92157deSopenharmony_ciLogs a property for the current test, test suite, or entire invocation of the 518f92157deSopenharmony_citest program. Only the last value for a given key is logged. 519f92157deSopenharmony_ci 520f92157deSopenharmony_ciThe key must be a valid XML attribute name, and cannot conflict with the ones 521f92157deSopenharmony_cialready used by GoogleTest (`name`, `file`, `line`, `status`, `time`, 522f92157deSopenharmony_ci`classname`, `type_param`, and `value_param`). 523f92157deSopenharmony_ci 524f92157deSopenharmony_ci`RecordProperty` is `public static` so it can be called from utility functions 525f92157deSopenharmony_cithat are not members of the test fixture. 526f92157deSopenharmony_ci 527f92157deSopenharmony_ciCalls to `RecordProperty` made during the lifespan of the test (from the moment 528f92157deSopenharmony_ciits constructor starts to the moment its destructor finishes) are output in XML 529f92157deSopenharmony_cias attributes of the `<testcase>` element. Properties recorded from a fixture's 530f92157deSopenharmony_ci`SetUpTestSuite` or `TearDownTestSuite` methods are logged as attributes of the 531f92157deSopenharmony_cicorresponding `<testsuite>` element. Calls to `RecordProperty` made in the 532f92157deSopenharmony_ciglobal context (before or after invocation of `RUN_ALL_TESTS` or from the 533f92157deSopenharmony_ci`SetUp`/`TearDown` methods of registered `Environment` objects) are output as 534f92157deSopenharmony_ciattributes of the `<testsuites>` element. 535f92157deSopenharmony_ci 536f92157deSopenharmony_ci#### Protected Methods {#Test-protected} 537f92157deSopenharmony_ci 538f92157deSopenharmony_ci##### SetUp {#Test::SetUp} 539f92157deSopenharmony_ci 540f92157deSopenharmony_ci`virtual void Test::SetUp()` 541f92157deSopenharmony_ci 542f92157deSopenharmony_ciOverride this to perform test fixture setup. GoogleTest calls `SetUp()` before 543f92157deSopenharmony_cirunning each individual test. 544f92157deSopenharmony_ci 545f92157deSopenharmony_ci##### TearDown {#Test::TearDown} 546f92157deSopenharmony_ci 547f92157deSopenharmony_ci`virtual void Test::TearDown()` 548f92157deSopenharmony_ci 549f92157deSopenharmony_ciOverride this to perform test fixture teardown. GoogleTest calls `TearDown()` 550f92157deSopenharmony_ciafter running each individual test. 551f92157deSopenharmony_ci 552f92157deSopenharmony_ci### TestWithParam {#TestWithParam} 553f92157deSopenharmony_ci 554f92157deSopenharmony_ci`::testing::TestWithParam<T>` 555f92157deSopenharmony_ci 556f92157deSopenharmony_ciA convenience class which inherits from both [`Test`](#Test) and 557f92157deSopenharmony_ci[`WithParamInterface<T>`](#WithParamInterface). 558f92157deSopenharmony_ci 559f92157deSopenharmony_ci### TestSuite {#TestSuite} 560f92157deSopenharmony_ci 561f92157deSopenharmony_ciRepresents a test suite. `TestSuite` is not copyable. 562f92157deSopenharmony_ci 563f92157deSopenharmony_ci#### Public Methods {#TestSuite-public} 564f92157deSopenharmony_ci 565f92157deSopenharmony_ci##### name {#TestSuite::name} 566f92157deSopenharmony_ci 567f92157deSopenharmony_ci`const char* TestSuite::name() const` 568f92157deSopenharmony_ci 569f92157deSopenharmony_ciGets the name of the test suite. 570f92157deSopenharmony_ci 571f92157deSopenharmony_ci##### type_param {#TestSuite::type_param} 572f92157deSopenharmony_ci 573f92157deSopenharmony_ci`const char* TestSuite::type_param() const` 574f92157deSopenharmony_ci 575f92157deSopenharmony_ciReturns the name of the parameter type, or `NULL` if this is not a typed or 576f92157deSopenharmony_citype-parameterized test suite. See [Typed Tests](../advanced.md#typed-tests) and 577f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests). 578f92157deSopenharmony_ci 579f92157deSopenharmony_ci##### should_run {#TestSuite::should_run} 580f92157deSopenharmony_ci 581f92157deSopenharmony_ci`bool TestSuite::should_run() const` 582f92157deSopenharmony_ci 583f92157deSopenharmony_ciReturns true if any test in this test suite should run. 584f92157deSopenharmony_ci 585f92157deSopenharmony_ci##### successful_test_count {#TestSuite::successful_test_count} 586f92157deSopenharmony_ci 587f92157deSopenharmony_ci`int TestSuite::successful_test_count() const` 588f92157deSopenharmony_ci 589f92157deSopenharmony_ciGets the number of successful tests in this test suite. 590f92157deSopenharmony_ci 591f92157deSopenharmony_ci##### skipped_test_count {#TestSuite::skipped_test_count} 592f92157deSopenharmony_ci 593f92157deSopenharmony_ci`int TestSuite::skipped_test_count() const` 594f92157deSopenharmony_ci 595f92157deSopenharmony_ciGets the number of skipped tests in this test suite. 596f92157deSopenharmony_ci 597f92157deSopenharmony_ci##### failed_test_count {#TestSuite::failed_test_count} 598f92157deSopenharmony_ci 599f92157deSopenharmony_ci`int TestSuite::failed_test_count() const` 600f92157deSopenharmony_ci 601f92157deSopenharmony_ciGets the number of failed tests in this test suite. 602f92157deSopenharmony_ci 603f92157deSopenharmony_ci##### reportable_disabled_test_count {#TestSuite::reportable_disabled_test_count} 604f92157deSopenharmony_ci 605f92157deSopenharmony_ci`int TestSuite::reportable_disabled_test_count() const` 606f92157deSopenharmony_ci 607f92157deSopenharmony_ciGets the number of disabled tests that will be reported in the XML report. 608f92157deSopenharmony_ci 609f92157deSopenharmony_ci##### disabled_test_count {#TestSuite::disabled_test_count} 610f92157deSopenharmony_ci 611f92157deSopenharmony_ci`int TestSuite::disabled_test_count() const` 612f92157deSopenharmony_ci 613f92157deSopenharmony_ciGets the number of disabled tests in this test suite. 614f92157deSopenharmony_ci 615f92157deSopenharmony_ci##### reportable_test_count {#TestSuite::reportable_test_count} 616f92157deSopenharmony_ci 617f92157deSopenharmony_ci`int TestSuite::reportable_test_count() const` 618f92157deSopenharmony_ci 619f92157deSopenharmony_ciGets the number of tests to be printed in the XML report. 620f92157deSopenharmony_ci 621f92157deSopenharmony_ci##### test_to_run_count {#TestSuite::test_to_run_count} 622f92157deSopenharmony_ci 623f92157deSopenharmony_ci`int TestSuite::test_to_run_count() const` 624f92157deSopenharmony_ci 625f92157deSopenharmony_ciGet the number of tests in this test suite that should run. 626f92157deSopenharmony_ci 627f92157deSopenharmony_ci##### total_test_count {#TestSuite::total_test_count} 628f92157deSopenharmony_ci 629f92157deSopenharmony_ci`int TestSuite::total_test_count() const` 630f92157deSopenharmony_ci 631f92157deSopenharmony_ciGets the number of all tests in this test suite. 632f92157deSopenharmony_ci 633f92157deSopenharmony_ci##### Passed {#TestSuite::Passed} 634f92157deSopenharmony_ci 635f92157deSopenharmony_ci`bool TestSuite::Passed() const` 636f92157deSopenharmony_ci 637f92157deSopenharmony_ciReturns true if and only if the test suite passed. 638f92157deSopenharmony_ci 639f92157deSopenharmony_ci##### Failed {#TestSuite::Failed} 640f92157deSopenharmony_ci 641f92157deSopenharmony_ci`bool TestSuite::Failed() const` 642f92157deSopenharmony_ci 643f92157deSopenharmony_ciReturns true if and only if the test suite failed. 644f92157deSopenharmony_ci 645f92157deSopenharmony_ci##### elapsed_time {#TestSuite::elapsed_time} 646f92157deSopenharmony_ci 647f92157deSopenharmony_ci`TimeInMillis TestSuite::elapsed_time() const` 648f92157deSopenharmony_ci 649f92157deSopenharmony_ciReturns the elapsed time, in milliseconds. 650f92157deSopenharmony_ci 651f92157deSopenharmony_ci##### start_timestamp {#TestSuite::start_timestamp} 652f92157deSopenharmony_ci 653f92157deSopenharmony_ci`TimeInMillis TestSuite::start_timestamp() const` 654f92157deSopenharmony_ci 655f92157deSopenharmony_ciGets the time of the test suite start, in ms from the start of the UNIX epoch. 656f92157deSopenharmony_ci 657f92157deSopenharmony_ci##### GetTestInfo {#TestSuite::GetTestInfo} 658f92157deSopenharmony_ci 659f92157deSopenharmony_ci`const TestInfo* TestSuite::GetTestInfo(int i) const` 660f92157deSopenharmony_ci 661f92157deSopenharmony_ciReturns the [`TestInfo`](#TestInfo) for the `i`-th test among all the tests. `i` 662f92157deSopenharmony_cican range from 0 to `total_test_count() - 1`. If `i` is not in that range, 663f92157deSopenharmony_cireturns `NULL`. 664f92157deSopenharmony_ci 665f92157deSopenharmony_ci##### ad_hoc_test_result {#TestSuite::ad_hoc_test_result} 666f92157deSopenharmony_ci 667f92157deSopenharmony_ci`const TestResult& TestSuite::ad_hoc_test_result() const` 668f92157deSopenharmony_ci 669f92157deSopenharmony_ciReturns the [`TestResult`](#TestResult) that holds test properties recorded 670f92157deSopenharmony_ciduring execution of `SetUpTestSuite` and `TearDownTestSuite`. 671f92157deSopenharmony_ci 672f92157deSopenharmony_ci### TestInfo {#TestInfo} 673f92157deSopenharmony_ci 674f92157deSopenharmony_ci`::testing::TestInfo` 675f92157deSopenharmony_ci 676f92157deSopenharmony_ciStores information about a test. 677f92157deSopenharmony_ci 678f92157deSopenharmony_ci#### Public Methods {#TestInfo-public} 679f92157deSopenharmony_ci 680f92157deSopenharmony_ci##### test_suite_name {#TestInfo::test_suite_name} 681f92157deSopenharmony_ci 682f92157deSopenharmony_ci`const char* TestInfo::test_suite_name() const` 683f92157deSopenharmony_ci 684f92157deSopenharmony_ciReturns the test suite name. 685f92157deSopenharmony_ci 686f92157deSopenharmony_ci##### name {#TestInfo::name} 687f92157deSopenharmony_ci 688f92157deSopenharmony_ci`const char* TestInfo::name() const` 689f92157deSopenharmony_ci 690f92157deSopenharmony_ciReturns the test name. 691f92157deSopenharmony_ci 692f92157deSopenharmony_ci##### type_param {#TestInfo::type_param} 693f92157deSopenharmony_ci 694f92157deSopenharmony_ci`const char* TestInfo::type_param() const` 695f92157deSopenharmony_ci 696f92157deSopenharmony_ciReturns the name of the parameter type, or `NULL` if this is not a typed or 697f92157deSopenharmony_citype-parameterized test. See [Typed Tests](../advanced.md#typed-tests) and 698f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests). 699f92157deSopenharmony_ci 700f92157deSopenharmony_ci##### value_param {#TestInfo::value_param} 701f92157deSopenharmony_ci 702f92157deSopenharmony_ci`const char* TestInfo::value_param() const` 703f92157deSopenharmony_ci 704f92157deSopenharmony_ciReturns the text representation of the value parameter, or `NULL` if this is not 705f92157deSopenharmony_cia value-parameterized test. See 706f92157deSopenharmony_ci[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 707f92157deSopenharmony_ci 708f92157deSopenharmony_ci##### file {#TestInfo::file} 709f92157deSopenharmony_ci 710f92157deSopenharmony_ci`const char* TestInfo::file() const` 711f92157deSopenharmony_ci 712f92157deSopenharmony_ciReturns the file name where this test is defined. 713f92157deSopenharmony_ci 714f92157deSopenharmony_ci##### line {#TestInfo::line} 715f92157deSopenharmony_ci 716f92157deSopenharmony_ci`int TestInfo::line() const` 717f92157deSopenharmony_ci 718f92157deSopenharmony_ciReturns the line where this test is defined. 719f92157deSopenharmony_ci 720f92157deSopenharmony_ci##### is_in_another_shard {#TestInfo::is_in_another_shard} 721f92157deSopenharmony_ci 722f92157deSopenharmony_ci`bool TestInfo::is_in_another_shard() const` 723f92157deSopenharmony_ci 724f92157deSopenharmony_ciReturns true if this test should not be run because it's in another shard. 725f92157deSopenharmony_ci 726f92157deSopenharmony_ci##### should_run {#TestInfo::should_run} 727f92157deSopenharmony_ci 728f92157deSopenharmony_ci`bool TestInfo::should_run() const` 729f92157deSopenharmony_ci 730f92157deSopenharmony_ciReturns true if this test should run, that is if the test is not disabled (or it 731f92157deSopenharmony_ciis disabled but the `also_run_disabled_tests` flag has been specified) and its 732f92157deSopenharmony_cifull name matches the user-specified filter. 733f92157deSopenharmony_ci 734f92157deSopenharmony_ciGoogleTest allows the user to filter the tests by their full names. Only the 735f92157deSopenharmony_citests that match the filter will run. See 736f92157deSopenharmony_ci[Running a Subset of the Tests](../advanced.md#running-a-subset-of-the-tests) 737f92157deSopenharmony_cifor more information. 738f92157deSopenharmony_ci 739f92157deSopenharmony_ci##### is_reportable {#TestInfo::is_reportable} 740f92157deSopenharmony_ci 741f92157deSopenharmony_ci`bool TestInfo::is_reportable() const` 742f92157deSopenharmony_ci 743f92157deSopenharmony_ciReturns true if and only if this test will appear in the XML report. 744f92157deSopenharmony_ci 745f92157deSopenharmony_ci##### result {#TestInfo::result} 746f92157deSopenharmony_ci 747f92157deSopenharmony_ci`const TestResult* TestInfo::result() const` 748f92157deSopenharmony_ci 749f92157deSopenharmony_ciReturns the result of the test. See [`TestResult`](#TestResult). 750f92157deSopenharmony_ci 751f92157deSopenharmony_ci### TestParamInfo {#TestParamInfo} 752f92157deSopenharmony_ci 753f92157deSopenharmony_ci`::testing::TestParamInfo<T>` 754f92157deSopenharmony_ci 755f92157deSopenharmony_ciDescribes a parameter to a value-parameterized test. The type `T` is the type of 756f92157deSopenharmony_cithe parameter. 757f92157deSopenharmony_ci 758f92157deSopenharmony_ciContains the fields `param` and `index` which hold the value of the parameter 759f92157deSopenharmony_ciand its integer index respectively. 760f92157deSopenharmony_ci 761f92157deSopenharmony_ci### UnitTest {#UnitTest} 762f92157deSopenharmony_ci 763f92157deSopenharmony_ci`::testing::UnitTest` 764f92157deSopenharmony_ci 765f92157deSopenharmony_ciThis class contains information about the test program. 766f92157deSopenharmony_ci 767f92157deSopenharmony_ci`UnitTest` is a singleton class. The only instance is created when 768f92157deSopenharmony_ci`UnitTest::GetInstance()` is first called. This instance is never deleted. 769f92157deSopenharmony_ci 770f92157deSopenharmony_ci`UnitTest` is not copyable. 771f92157deSopenharmony_ci 772f92157deSopenharmony_ci#### Public Methods {#UnitTest-public} 773f92157deSopenharmony_ci 774f92157deSopenharmony_ci##### GetInstance {#UnitTest::GetInstance} 775f92157deSopenharmony_ci 776f92157deSopenharmony_ci`static UnitTest* UnitTest::GetInstance()` 777f92157deSopenharmony_ci 778f92157deSopenharmony_ciGets the singleton `UnitTest` object. The first time this method is called, a 779f92157deSopenharmony_ci`UnitTest` object is constructed and returned. Consecutive calls will return the 780f92157deSopenharmony_cisame object. 781f92157deSopenharmony_ci 782f92157deSopenharmony_ci##### original_working_dir {#UnitTest::original_working_dir} 783f92157deSopenharmony_ci 784f92157deSopenharmony_ci`const char* UnitTest::original_working_dir() const` 785f92157deSopenharmony_ci 786f92157deSopenharmony_ciReturns the working directory when the first [`TEST()`](#TEST) or 787f92157deSopenharmony_ci[`TEST_F()`](#TEST_F) was executed. The `UnitTest` object owns the string. 788f92157deSopenharmony_ci 789f92157deSopenharmony_ci##### current_test_suite {#UnitTest::current_test_suite} 790f92157deSopenharmony_ci 791f92157deSopenharmony_ci`const TestSuite* UnitTest::current_test_suite() const` 792f92157deSopenharmony_ci 793f92157deSopenharmony_ciReturns the [`TestSuite`](#TestSuite) object for the test that's currently 794f92157deSopenharmony_cirunning, or `NULL` if no test is running. 795f92157deSopenharmony_ci 796f92157deSopenharmony_ci##### current_test_info {#UnitTest::current_test_info} 797f92157deSopenharmony_ci 798f92157deSopenharmony_ci`const TestInfo* UnitTest::current_test_info() const` 799f92157deSopenharmony_ci 800f92157deSopenharmony_ciReturns the [`TestInfo`](#TestInfo) object for the test that's currently 801f92157deSopenharmony_cirunning, or `NULL` if no test is running. 802f92157deSopenharmony_ci 803f92157deSopenharmony_ci##### random_seed {#UnitTest::random_seed} 804f92157deSopenharmony_ci 805f92157deSopenharmony_ci`int UnitTest::random_seed() const` 806f92157deSopenharmony_ci 807f92157deSopenharmony_ciReturns the random seed used at the start of the current test run. 808f92157deSopenharmony_ci 809f92157deSopenharmony_ci##### successful_test_suite_count {#UnitTest::successful_test_suite_count} 810f92157deSopenharmony_ci 811f92157deSopenharmony_ci`int UnitTest::successful_test_suite_count() const` 812f92157deSopenharmony_ci 813f92157deSopenharmony_ciGets the number of successful test suites. 814f92157deSopenharmony_ci 815f92157deSopenharmony_ci##### failed_test_suite_count {#UnitTest::failed_test_suite_count} 816f92157deSopenharmony_ci 817f92157deSopenharmony_ci`int UnitTest::failed_test_suite_count() const` 818f92157deSopenharmony_ci 819f92157deSopenharmony_ciGets the number of failed test suites. 820f92157deSopenharmony_ci 821f92157deSopenharmony_ci##### total_test_suite_count {#UnitTest::total_test_suite_count} 822f92157deSopenharmony_ci 823f92157deSopenharmony_ci`int UnitTest::total_test_suite_count() const` 824f92157deSopenharmony_ci 825f92157deSopenharmony_ciGets the number of all test suites. 826f92157deSopenharmony_ci 827f92157deSopenharmony_ci##### test_suite_to_run_count {#UnitTest::test_suite_to_run_count} 828f92157deSopenharmony_ci 829f92157deSopenharmony_ci`int UnitTest::test_suite_to_run_count() const` 830f92157deSopenharmony_ci 831f92157deSopenharmony_ciGets the number of all test suites that contain at least one test that should 832f92157deSopenharmony_cirun. 833f92157deSopenharmony_ci 834f92157deSopenharmony_ci##### successful_test_count {#UnitTest::successful_test_count} 835f92157deSopenharmony_ci 836f92157deSopenharmony_ci`int UnitTest::successful_test_count() const` 837f92157deSopenharmony_ci 838f92157deSopenharmony_ciGets the number of successful tests. 839f92157deSopenharmony_ci 840f92157deSopenharmony_ci##### skipped_test_count {#UnitTest::skipped_test_count} 841f92157deSopenharmony_ci 842f92157deSopenharmony_ci`int UnitTest::skipped_test_count() const` 843f92157deSopenharmony_ci 844f92157deSopenharmony_ciGets the number of skipped tests. 845f92157deSopenharmony_ci 846f92157deSopenharmony_ci##### failed_test_count {#UnitTest::failed_test_count} 847f92157deSopenharmony_ci 848f92157deSopenharmony_ci`int UnitTest::failed_test_count() const` 849f92157deSopenharmony_ci 850f92157deSopenharmony_ciGets the number of failed tests. 851f92157deSopenharmony_ci 852f92157deSopenharmony_ci##### reportable_disabled_test_count {#UnitTest::reportable_disabled_test_count} 853f92157deSopenharmony_ci 854f92157deSopenharmony_ci`int UnitTest::reportable_disabled_test_count() const` 855f92157deSopenharmony_ci 856f92157deSopenharmony_ciGets the number of disabled tests that will be reported in the XML report. 857f92157deSopenharmony_ci 858f92157deSopenharmony_ci##### disabled_test_count {#UnitTest::disabled_test_count} 859f92157deSopenharmony_ci 860f92157deSopenharmony_ci`int UnitTest::disabled_test_count() const` 861f92157deSopenharmony_ci 862f92157deSopenharmony_ciGets the number of disabled tests. 863f92157deSopenharmony_ci 864f92157deSopenharmony_ci##### reportable_test_count {#UnitTest::reportable_test_count} 865f92157deSopenharmony_ci 866f92157deSopenharmony_ci`int UnitTest::reportable_test_count() const` 867f92157deSopenharmony_ci 868f92157deSopenharmony_ciGets the number of tests to be printed in the XML report. 869f92157deSopenharmony_ci 870f92157deSopenharmony_ci##### total_test_count {#UnitTest::total_test_count} 871f92157deSopenharmony_ci 872f92157deSopenharmony_ci`int UnitTest::total_test_count() const` 873f92157deSopenharmony_ci 874f92157deSopenharmony_ciGets the number of all tests. 875f92157deSopenharmony_ci 876f92157deSopenharmony_ci##### test_to_run_count {#UnitTest::test_to_run_count} 877f92157deSopenharmony_ci 878f92157deSopenharmony_ci`int UnitTest::test_to_run_count() const` 879f92157deSopenharmony_ci 880f92157deSopenharmony_ciGets the number of tests that should run. 881f92157deSopenharmony_ci 882f92157deSopenharmony_ci##### start_timestamp {#UnitTest::start_timestamp} 883f92157deSopenharmony_ci 884f92157deSopenharmony_ci`TimeInMillis UnitTest::start_timestamp() const` 885f92157deSopenharmony_ci 886f92157deSopenharmony_ciGets the time of the test program start, in ms from the start of the UNIX epoch. 887f92157deSopenharmony_ci 888f92157deSopenharmony_ci##### elapsed_time {#UnitTest::elapsed_time} 889f92157deSopenharmony_ci 890f92157deSopenharmony_ci`TimeInMillis UnitTest::elapsed_time() const` 891f92157deSopenharmony_ci 892f92157deSopenharmony_ciGets the elapsed time, in milliseconds. 893f92157deSopenharmony_ci 894f92157deSopenharmony_ci##### Passed {#UnitTest::Passed} 895f92157deSopenharmony_ci 896f92157deSopenharmony_ci`bool UnitTest::Passed() const` 897f92157deSopenharmony_ci 898f92157deSopenharmony_ciReturns true if and only if the unit test passed (i.e. all test suites passed). 899f92157deSopenharmony_ci 900f92157deSopenharmony_ci##### Failed {#UnitTest::Failed} 901f92157deSopenharmony_ci 902f92157deSopenharmony_ci`bool UnitTest::Failed() const` 903f92157deSopenharmony_ci 904f92157deSopenharmony_ciReturns true if and only if the unit test failed (i.e. some test suite failed or 905f92157deSopenharmony_cisomething outside of all tests failed). 906f92157deSopenharmony_ci 907f92157deSopenharmony_ci##### GetTestSuite {#UnitTest::GetTestSuite} 908f92157deSopenharmony_ci 909f92157deSopenharmony_ci`const TestSuite* UnitTest::GetTestSuite(int i) const` 910f92157deSopenharmony_ci 911f92157deSopenharmony_ciGets the [`TestSuite`](#TestSuite) object for the `i`-th test suite among all 912f92157deSopenharmony_cithe test suites. `i` can range from 0 to `total_test_suite_count() - 1`. If `i` 913f92157deSopenharmony_ciis not in that range, returns `NULL`. 914f92157deSopenharmony_ci 915f92157deSopenharmony_ci##### ad_hoc_test_result {#UnitTest::ad_hoc_test_result} 916f92157deSopenharmony_ci 917f92157deSopenharmony_ci`const TestResult& UnitTest::ad_hoc_test_result() const` 918f92157deSopenharmony_ci 919f92157deSopenharmony_ciReturns the [`TestResult`](#TestResult) containing information on test failures 920f92157deSopenharmony_ciand properties logged outside of individual test suites. 921f92157deSopenharmony_ci 922f92157deSopenharmony_ci##### listeners {#UnitTest::listeners} 923f92157deSopenharmony_ci 924f92157deSopenharmony_ci`TestEventListeners& UnitTest::listeners()` 925f92157deSopenharmony_ci 926f92157deSopenharmony_ciReturns the list of event listeners that can be used to track events inside 927f92157deSopenharmony_ciGoogleTest. See [`TestEventListeners`](#TestEventListeners). 928f92157deSopenharmony_ci 929f92157deSopenharmony_ci### TestEventListener {#TestEventListener} 930f92157deSopenharmony_ci 931f92157deSopenharmony_ci`::testing::TestEventListener` 932f92157deSopenharmony_ci 933f92157deSopenharmony_ciThe interface for tracing execution of tests. The methods below are listed in 934f92157deSopenharmony_cithe order the corresponding events are fired. 935f92157deSopenharmony_ci 936f92157deSopenharmony_ci#### Public Methods {#TestEventListener-public} 937f92157deSopenharmony_ci 938f92157deSopenharmony_ci##### OnTestProgramStart {#TestEventListener::OnTestProgramStart} 939f92157deSopenharmony_ci 940f92157deSopenharmony_ci`virtual void TestEventListener::OnTestProgramStart(const UnitTest& unit_test)` 941f92157deSopenharmony_ci 942f92157deSopenharmony_ciFired before any test activity starts. 943f92157deSopenharmony_ci 944f92157deSopenharmony_ci##### OnTestIterationStart {#TestEventListener::OnTestIterationStart} 945f92157deSopenharmony_ci 946f92157deSopenharmony_ci`virtual void TestEventListener::OnTestIterationStart(const UnitTest& unit_test, 947f92157deSopenharmony_ciint iteration)` 948f92157deSopenharmony_ci 949f92157deSopenharmony_ciFired before each iteration of tests starts. There may be more than one 950f92157deSopenharmony_ciiteration if `GTEST_FLAG(repeat)` is set. `iteration` is the iteration index, 951f92157deSopenharmony_cistarting from 0. 952f92157deSopenharmony_ci 953f92157deSopenharmony_ci##### OnEnvironmentsSetUpStart {#TestEventListener::OnEnvironmentsSetUpStart} 954f92157deSopenharmony_ci 955f92157deSopenharmony_ci`virtual void TestEventListener::OnEnvironmentsSetUpStart(const UnitTest& 956f92157deSopenharmony_ciunit_test)` 957f92157deSopenharmony_ci 958f92157deSopenharmony_ciFired before environment set-up for each iteration of tests starts. 959f92157deSopenharmony_ci 960f92157deSopenharmony_ci##### OnEnvironmentsSetUpEnd {#TestEventListener::OnEnvironmentsSetUpEnd} 961f92157deSopenharmony_ci 962f92157deSopenharmony_ci`virtual void TestEventListener::OnEnvironmentsSetUpEnd(const UnitTest& 963f92157deSopenharmony_ciunit_test)` 964f92157deSopenharmony_ci 965f92157deSopenharmony_ciFired after environment set-up for each iteration of tests ends. 966f92157deSopenharmony_ci 967f92157deSopenharmony_ci##### OnTestSuiteStart {#TestEventListener::OnTestSuiteStart} 968f92157deSopenharmony_ci 969f92157deSopenharmony_ci`virtual void TestEventListener::OnTestSuiteStart(const TestSuite& test_suite)` 970f92157deSopenharmony_ci 971f92157deSopenharmony_ciFired before the test suite starts. 972f92157deSopenharmony_ci 973f92157deSopenharmony_ci##### OnTestStart {#TestEventListener::OnTestStart} 974f92157deSopenharmony_ci 975f92157deSopenharmony_ci`virtual void TestEventListener::OnTestStart(const TestInfo& test_info)` 976f92157deSopenharmony_ci 977f92157deSopenharmony_ciFired before the test starts. 978f92157deSopenharmony_ci 979f92157deSopenharmony_ci##### OnTestPartResult {#TestEventListener::OnTestPartResult} 980f92157deSopenharmony_ci 981f92157deSopenharmony_ci`virtual void TestEventListener::OnTestPartResult(const TestPartResult& 982f92157deSopenharmony_citest_part_result)` 983f92157deSopenharmony_ci 984f92157deSopenharmony_ciFired after a failed assertion or a `SUCCEED()` invocation. If you want to throw 985f92157deSopenharmony_cian exception from this function to skip to the next test, it must be an 986f92157deSopenharmony_ci[`AssertionException`](#AssertionException) or inherited from it. 987f92157deSopenharmony_ci 988f92157deSopenharmony_ci##### OnTestEnd {#TestEventListener::OnTestEnd} 989f92157deSopenharmony_ci 990f92157deSopenharmony_ci`virtual void TestEventListener::OnTestEnd(const TestInfo& test_info)` 991f92157deSopenharmony_ci 992f92157deSopenharmony_ciFired after the test ends. 993f92157deSopenharmony_ci 994f92157deSopenharmony_ci##### OnTestSuiteEnd {#TestEventListener::OnTestSuiteEnd} 995f92157deSopenharmony_ci 996f92157deSopenharmony_ci`virtual void TestEventListener::OnTestSuiteEnd(const TestSuite& test_suite)` 997f92157deSopenharmony_ci 998f92157deSopenharmony_ciFired after the test suite ends. 999f92157deSopenharmony_ci 1000f92157deSopenharmony_ci##### OnEnvironmentsTearDownStart {#TestEventListener::OnEnvironmentsTearDownStart} 1001f92157deSopenharmony_ci 1002f92157deSopenharmony_ci`virtual void TestEventListener::OnEnvironmentsTearDownStart(const UnitTest& 1003f92157deSopenharmony_ciunit_test)` 1004f92157deSopenharmony_ci 1005f92157deSopenharmony_ciFired before environment tear-down for each iteration of tests starts. 1006f92157deSopenharmony_ci 1007f92157deSopenharmony_ci##### OnEnvironmentsTearDownEnd {#TestEventListener::OnEnvironmentsTearDownEnd} 1008f92157deSopenharmony_ci 1009f92157deSopenharmony_ci`virtual void TestEventListener::OnEnvironmentsTearDownEnd(const UnitTest& 1010f92157deSopenharmony_ciunit_test)` 1011f92157deSopenharmony_ci 1012f92157deSopenharmony_ciFired after environment tear-down for each iteration of tests ends. 1013f92157deSopenharmony_ci 1014f92157deSopenharmony_ci##### OnTestIterationEnd {#TestEventListener::OnTestIterationEnd} 1015f92157deSopenharmony_ci 1016f92157deSopenharmony_ci`virtual void TestEventListener::OnTestIterationEnd(const UnitTest& unit_test, 1017f92157deSopenharmony_ciint iteration)` 1018f92157deSopenharmony_ci 1019f92157deSopenharmony_ciFired after each iteration of tests finishes. 1020f92157deSopenharmony_ci 1021f92157deSopenharmony_ci##### OnTestProgramEnd {#TestEventListener::OnTestProgramEnd} 1022f92157deSopenharmony_ci 1023f92157deSopenharmony_ci`virtual void TestEventListener::OnTestProgramEnd(const UnitTest& unit_test)` 1024f92157deSopenharmony_ci 1025f92157deSopenharmony_ciFired after all test activities have ended. 1026f92157deSopenharmony_ci 1027f92157deSopenharmony_ci### TestEventListeners {#TestEventListeners} 1028f92157deSopenharmony_ci 1029f92157deSopenharmony_ci`::testing::TestEventListeners` 1030f92157deSopenharmony_ci 1031f92157deSopenharmony_ciLets users add listeners to track events in GoogleTest. 1032f92157deSopenharmony_ci 1033f92157deSopenharmony_ci#### Public Methods {#TestEventListeners-public} 1034f92157deSopenharmony_ci 1035f92157deSopenharmony_ci##### Append {#TestEventListeners::Append} 1036f92157deSopenharmony_ci 1037f92157deSopenharmony_ci`void TestEventListeners::Append(TestEventListener* listener)` 1038f92157deSopenharmony_ci 1039f92157deSopenharmony_ciAppends an event listener to the end of the list. GoogleTest assumes ownership 1040f92157deSopenharmony_ciof the listener (i.e. it will delete the listener when the test program 1041f92157deSopenharmony_cifinishes). 1042f92157deSopenharmony_ci 1043f92157deSopenharmony_ci##### Release {#TestEventListeners::Release} 1044f92157deSopenharmony_ci 1045f92157deSopenharmony_ci`TestEventListener* TestEventListeners::Release(TestEventListener* listener)` 1046f92157deSopenharmony_ci 1047f92157deSopenharmony_ciRemoves the given event listener from the list and returns it. It then becomes 1048f92157deSopenharmony_cithe caller's responsibility to delete the listener. Returns `NULL` if the 1049f92157deSopenharmony_cilistener is not found in the list. 1050f92157deSopenharmony_ci 1051f92157deSopenharmony_ci##### default_result_printer {#TestEventListeners::default_result_printer} 1052f92157deSopenharmony_ci 1053f92157deSopenharmony_ci`TestEventListener* TestEventListeners::default_result_printer() const` 1054f92157deSopenharmony_ci 1055f92157deSopenharmony_ciReturns the standard listener responsible for the default console output. Can be 1056f92157deSopenharmony_ciremoved from the listeners list to shut down default console output. Note that 1057f92157deSopenharmony_ciremoving this object from the listener list with 1058f92157deSopenharmony_ci[`Release()`](#TestEventListeners::Release) transfers its ownership to the 1059f92157deSopenharmony_cicaller and makes this function return `NULL` the next time. 1060f92157deSopenharmony_ci 1061f92157deSopenharmony_ci##### default_xml_generator {#TestEventListeners::default_xml_generator} 1062f92157deSopenharmony_ci 1063f92157deSopenharmony_ci`TestEventListener* TestEventListeners::default_xml_generator() const` 1064f92157deSopenharmony_ci 1065f92157deSopenharmony_ciReturns the standard listener responsible for the default XML output controlled 1066f92157deSopenharmony_ciby the `--gtest_output=xml` flag. Can be removed from the listeners list by 1067f92157deSopenharmony_ciusers who want to shut down the default XML output controlled by this flag and 1068f92157deSopenharmony_cisubstitute it with custom one. Note that removing this object from the listener 1069f92157deSopenharmony_cilist with [`Release()`](#TestEventListeners::Release) transfers its ownership to 1070f92157deSopenharmony_cithe caller and makes this function return `NULL` the next time. 1071f92157deSopenharmony_ci 1072f92157deSopenharmony_ci### TestPartResult {#TestPartResult} 1073f92157deSopenharmony_ci 1074f92157deSopenharmony_ci`::testing::TestPartResult` 1075f92157deSopenharmony_ci 1076f92157deSopenharmony_ciA copyable object representing the result of a test part (i.e. an assertion or 1077f92157deSopenharmony_cian explicit `FAIL()`, `ADD_FAILURE()`, or `SUCCESS()`). 1078f92157deSopenharmony_ci 1079f92157deSopenharmony_ci#### Public Methods {#TestPartResult-public} 1080f92157deSopenharmony_ci 1081f92157deSopenharmony_ci##### type {#TestPartResult::type} 1082f92157deSopenharmony_ci 1083f92157deSopenharmony_ci`Type TestPartResult::type() const` 1084f92157deSopenharmony_ci 1085f92157deSopenharmony_ciGets the outcome of the test part. 1086f92157deSopenharmony_ci 1087f92157deSopenharmony_ciThe return type `Type` is an enum defined as follows: 1088f92157deSopenharmony_ci 1089f92157deSopenharmony_ci```cpp 1090f92157deSopenharmony_cienum Type { 1091f92157deSopenharmony_ci kSuccess, // Succeeded. 1092f92157deSopenharmony_ci kNonFatalFailure, // Failed but the test can continue. 1093f92157deSopenharmony_ci kFatalFailure, // Failed and the test should be terminated. 1094f92157deSopenharmony_ci kSkip // Skipped. 1095f92157deSopenharmony_ci}; 1096f92157deSopenharmony_ci``` 1097f92157deSopenharmony_ci 1098f92157deSopenharmony_ci##### file_name {#TestPartResult::file_name} 1099f92157deSopenharmony_ci 1100f92157deSopenharmony_ci`const char* TestPartResult::file_name() const` 1101f92157deSopenharmony_ci 1102f92157deSopenharmony_ciGets the name of the source file where the test part took place, or `NULL` if 1103f92157deSopenharmony_ciit's unknown. 1104f92157deSopenharmony_ci 1105f92157deSopenharmony_ci##### line_number {#TestPartResult::line_number} 1106f92157deSopenharmony_ci 1107f92157deSopenharmony_ci`int TestPartResult::line_number() const` 1108f92157deSopenharmony_ci 1109f92157deSopenharmony_ciGets the line in the source file where the test part took place, or `-1` if it's 1110f92157deSopenharmony_ciunknown. 1111f92157deSopenharmony_ci 1112f92157deSopenharmony_ci##### summary {#TestPartResult::summary} 1113f92157deSopenharmony_ci 1114f92157deSopenharmony_ci`const char* TestPartResult::summary() const` 1115f92157deSopenharmony_ci 1116f92157deSopenharmony_ciGets the summary of the failure message. 1117f92157deSopenharmony_ci 1118f92157deSopenharmony_ci##### message {#TestPartResult::message} 1119f92157deSopenharmony_ci 1120f92157deSopenharmony_ci`const char* TestPartResult::message() const` 1121f92157deSopenharmony_ci 1122f92157deSopenharmony_ciGets the message associated with the test part. 1123f92157deSopenharmony_ci 1124f92157deSopenharmony_ci##### skipped {#TestPartResult::skipped} 1125f92157deSopenharmony_ci 1126f92157deSopenharmony_ci`bool TestPartResult::skipped() const` 1127f92157deSopenharmony_ci 1128f92157deSopenharmony_ciReturns true if and only if the test part was skipped. 1129f92157deSopenharmony_ci 1130f92157deSopenharmony_ci##### passed {#TestPartResult::passed} 1131f92157deSopenharmony_ci 1132f92157deSopenharmony_ci`bool TestPartResult::passed() const` 1133f92157deSopenharmony_ci 1134f92157deSopenharmony_ciReturns true if and only if the test part passed. 1135f92157deSopenharmony_ci 1136f92157deSopenharmony_ci##### nonfatally_failed {#TestPartResult::nonfatally_failed} 1137f92157deSopenharmony_ci 1138f92157deSopenharmony_ci`bool TestPartResult::nonfatally_failed() const` 1139f92157deSopenharmony_ci 1140f92157deSopenharmony_ciReturns true if and only if the test part non-fatally failed. 1141f92157deSopenharmony_ci 1142f92157deSopenharmony_ci##### fatally_failed {#TestPartResult::fatally_failed} 1143f92157deSopenharmony_ci 1144f92157deSopenharmony_ci`bool TestPartResult::fatally_failed() const` 1145f92157deSopenharmony_ci 1146f92157deSopenharmony_ciReturns true if and only if the test part fatally failed. 1147f92157deSopenharmony_ci 1148f92157deSopenharmony_ci##### failed {#TestPartResult::failed} 1149f92157deSopenharmony_ci 1150f92157deSopenharmony_ci`bool TestPartResult::failed() const` 1151f92157deSopenharmony_ci 1152f92157deSopenharmony_ciReturns true if and only if the test part failed. 1153f92157deSopenharmony_ci 1154f92157deSopenharmony_ci### TestProperty {#TestProperty} 1155f92157deSopenharmony_ci 1156f92157deSopenharmony_ci`::testing::TestProperty` 1157f92157deSopenharmony_ci 1158f92157deSopenharmony_ciA copyable object representing a user-specified test property which can be 1159f92157deSopenharmony_cioutput as a key/value string pair. 1160f92157deSopenharmony_ci 1161f92157deSopenharmony_ci#### Public Methods {#TestProperty-public} 1162f92157deSopenharmony_ci 1163f92157deSopenharmony_ci##### key {#key} 1164f92157deSopenharmony_ci 1165f92157deSopenharmony_ci`const char* key() const` 1166f92157deSopenharmony_ci 1167f92157deSopenharmony_ciGets the user-supplied key. 1168f92157deSopenharmony_ci 1169f92157deSopenharmony_ci##### value {#value} 1170f92157deSopenharmony_ci 1171f92157deSopenharmony_ci`const char* value() const` 1172f92157deSopenharmony_ci 1173f92157deSopenharmony_ciGets the user-supplied value. 1174f92157deSopenharmony_ci 1175f92157deSopenharmony_ci##### SetValue {#SetValue} 1176f92157deSopenharmony_ci 1177f92157deSopenharmony_ci`void SetValue(const std::string& new_value)` 1178f92157deSopenharmony_ci 1179f92157deSopenharmony_ciSets a new value, overriding the previous one. 1180f92157deSopenharmony_ci 1181f92157deSopenharmony_ci### TestResult {#TestResult} 1182f92157deSopenharmony_ci 1183f92157deSopenharmony_ci`::testing::TestResult` 1184f92157deSopenharmony_ci 1185f92157deSopenharmony_ciContains information about the result of a single test. 1186f92157deSopenharmony_ci 1187f92157deSopenharmony_ci`TestResult` is not copyable. 1188f92157deSopenharmony_ci 1189f92157deSopenharmony_ci#### Public Methods {#TestResult-public} 1190f92157deSopenharmony_ci 1191f92157deSopenharmony_ci##### total_part_count {#TestResult::total_part_count} 1192f92157deSopenharmony_ci 1193f92157deSopenharmony_ci`int TestResult::total_part_count() const` 1194f92157deSopenharmony_ci 1195f92157deSopenharmony_ciGets the number of all test parts. This is the sum of the number of successful 1196f92157deSopenharmony_citest parts and the number of failed test parts. 1197f92157deSopenharmony_ci 1198f92157deSopenharmony_ci##### test_property_count {#TestResult::test_property_count} 1199f92157deSopenharmony_ci 1200f92157deSopenharmony_ci`int TestResult::test_property_count() const` 1201f92157deSopenharmony_ci 1202f92157deSopenharmony_ciReturns the number of test properties. 1203f92157deSopenharmony_ci 1204f92157deSopenharmony_ci##### Passed {#TestResult::Passed} 1205f92157deSopenharmony_ci 1206f92157deSopenharmony_ci`bool TestResult::Passed() const` 1207f92157deSopenharmony_ci 1208f92157deSopenharmony_ciReturns true if and only if the test passed (i.e. no test part failed). 1209f92157deSopenharmony_ci 1210f92157deSopenharmony_ci##### Skipped {#TestResult::Skipped} 1211f92157deSopenharmony_ci 1212f92157deSopenharmony_ci`bool TestResult::Skipped() const` 1213f92157deSopenharmony_ci 1214f92157deSopenharmony_ciReturns true if and only if the test was skipped. 1215f92157deSopenharmony_ci 1216f92157deSopenharmony_ci##### Failed {#TestResult::Failed} 1217f92157deSopenharmony_ci 1218f92157deSopenharmony_ci`bool TestResult::Failed() const` 1219f92157deSopenharmony_ci 1220f92157deSopenharmony_ciReturns true if and only if the test failed. 1221f92157deSopenharmony_ci 1222f92157deSopenharmony_ci##### HasFatalFailure {#TestResult::HasFatalFailure} 1223f92157deSopenharmony_ci 1224f92157deSopenharmony_ci`bool TestResult::HasFatalFailure() const` 1225f92157deSopenharmony_ci 1226f92157deSopenharmony_ciReturns true if and only if the test fatally failed. 1227f92157deSopenharmony_ci 1228f92157deSopenharmony_ci##### HasNonfatalFailure {#TestResult::HasNonfatalFailure} 1229f92157deSopenharmony_ci 1230f92157deSopenharmony_ci`bool TestResult::HasNonfatalFailure() const` 1231f92157deSopenharmony_ci 1232f92157deSopenharmony_ciReturns true if and only if the test has a non-fatal failure. 1233f92157deSopenharmony_ci 1234f92157deSopenharmony_ci##### elapsed_time {#TestResult::elapsed_time} 1235f92157deSopenharmony_ci 1236f92157deSopenharmony_ci`TimeInMillis TestResult::elapsed_time() const` 1237f92157deSopenharmony_ci 1238f92157deSopenharmony_ciReturns the elapsed time, in milliseconds. 1239f92157deSopenharmony_ci 1240f92157deSopenharmony_ci##### start_timestamp {#TestResult::start_timestamp} 1241f92157deSopenharmony_ci 1242f92157deSopenharmony_ci`TimeInMillis TestResult::start_timestamp() const` 1243f92157deSopenharmony_ci 1244f92157deSopenharmony_ciGets the time of the test case start, in ms from the start of the UNIX epoch. 1245f92157deSopenharmony_ci 1246f92157deSopenharmony_ci##### GetTestPartResult {#TestResult::GetTestPartResult} 1247f92157deSopenharmony_ci 1248f92157deSopenharmony_ci`const TestPartResult& TestResult::GetTestPartResult(int i) const` 1249f92157deSopenharmony_ci 1250f92157deSopenharmony_ciReturns the [`TestPartResult`](#TestPartResult) for the `i`-th test part result 1251f92157deSopenharmony_ciamong all the results. `i` can range from 0 to `total_part_count() - 1`. If `i` 1252f92157deSopenharmony_ciis not in that range, aborts the program. 1253f92157deSopenharmony_ci 1254f92157deSopenharmony_ci##### GetTestProperty {#TestResult::GetTestProperty} 1255f92157deSopenharmony_ci 1256f92157deSopenharmony_ci`const TestProperty& TestResult::GetTestProperty(int i) const` 1257f92157deSopenharmony_ci 1258f92157deSopenharmony_ciReturns the [`TestProperty`](#TestProperty) object for the `i`-th test property. 1259f92157deSopenharmony_ci`i` can range from 0 to `test_property_count() - 1`. If `i` is not in that 1260f92157deSopenharmony_cirange, aborts the program. 1261f92157deSopenharmony_ci 1262f92157deSopenharmony_ci### TimeInMillis {#TimeInMillis} 1263f92157deSopenharmony_ci 1264f92157deSopenharmony_ci`::testing::TimeInMillis` 1265f92157deSopenharmony_ci 1266f92157deSopenharmony_ciAn integer type representing time in milliseconds. 1267f92157deSopenharmony_ci 1268f92157deSopenharmony_ci### Types {#Types} 1269f92157deSopenharmony_ci 1270f92157deSopenharmony_ci`::testing::Types<T...>` 1271f92157deSopenharmony_ci 1272f92157deSopenharmony_ciRepresents a list of types for use in typed tests and type-parameterized tests. 1273f92157deSopenharmony_ci 1274f92157deSopenharmony_ciThe template argument `T...` can be any number of types, for example: 1275f92157deSopenharmony_ci 1276f92157deSopenharmony_ci``` 1277f92157deSopenharmony_ci::testing::Types<char, int, unsigned int> 1278f92157deSopenharmony_ci``` 1279f92157deSopenharmony_ci 1280f92157deSopenharmony_ciSee [Typed Tests](../advanced.md#typed-tests) and 1281f92157deSopenharmony_ci[Type-Parameterized Tests](../advanced.md#type-parameterized-tests) for more 1282f92157deSopenharmony_ciinformation. 1283f92157deSopenharmony_ci 1284f92157deSopenharmony_ci### WithParamInterface {#WithParamInterface} 1285f92157deSopenharmony_ci 1286f92157deSopenharmony_ci`::testing::WithParamInterface<T>` 1287f92157deSopenharmony_ci 1288f92157deSopenharmony_ciThe pure interface class that all value-parameterized tests inherit from. 1289f92157deSopenharmony_ci 1290f92157deSopenharmony_ciA value-parameterized test fixture class must inherit from both [`Test`](#Test) 1291f92157deSopenharmony_ciand `WithParamInterface`. In most cases that just means inheriting from 1292f92157deSopenharmony_ci[`TestWithParam`](#TestWithParam), but more complicated test hierarchies may 1293f92157deSopenharmony_cineed to inherit from `Test` and `WithParamInterface` at different levels. 1294f92157deSopenharmony_ci 1295f92157deSopenharmony_ciThis interface defines the type alias `ParamType` for the parameter type `T` and 1296f92157deSopenharmony_cihas support for accessing the test parameter value via the `GetParam()` method: 1297f92157deSopenharmony_ci 1298f92157deSopenharmony_ci``` 1299f92157deSopenharmony_cistatic const ParamType& GetParam() 1300f92157deSopenharmony_ci``` 1301f92157deSopenharmony_ci 1302f92157deSopenharmony_ciFor more information, see 1303f92157deSopenharmony_ci[Value-Parameterized Tests](../advanced.md#value-parameterized-tests). 1304f92157deSopenharmony_ci 1305f92157deSopenharmony_ci## Functions 1306f92157deSopenharmony_ci 1307f92157deSopenharmony_ciGoogleTest defines the following functions to help with writing and running 1308f92157deSopenharmony_citests. 1309f92157deSopenharmony_ci 1310f92157deSopenharmony_ci### InitGoogleTest {#InitGoogleTest} 1311f92157deSopenharmony_ci 1312f92157deSopenharmony_ci`void ::testing::InitGoogleTest(int* argc, char** argv)` \ 1313f92157deSopenharmony_ci`void ::testing::InitGoogleTest(int* argc, wchar_t** argv)` \ 1314f92157deSopenharmony_ci`void ::testing::InitGoogleTest()` 1315f92157deSopenharmony_ci 1316f92157deSopenharmony_ciInitializes GoogleTest. This must be called before calling 1317f92157deSopenharmony_ci[`RUN_ALL_TESTS()`](#RUN_ALL_TESTS). In particular, it parses the command line 1318f92157deSopenharmony_cifor the flags that GoogleTest recognizes. Whenever a GoogleTest flag is seen, it 1319f92157deSopenharmony_ciis removed from `argv`, and `*argc` is decremented. 1320f92157deSopenharmony_ci 1321f92157deSopenharmony_ciNo value is returned. Instead, the GoogleTest flag variables are updated. 1322f92157deSopenharmony_ci 1323f92157deSopenharmony_ciThe `InitGoogleTest(int* argc, wchar_t** argv)` overload can be used in Windows 1324f92157deSopenharmony_ciprograms compiled in `UNICODE` mode. 1325f92157deSopenharmony_ci 1326f92157deSopenharmony_ciThe argument-less `InitGoogleTest()` overload can be used on Arduino/embedded 1327f92157deSopenharmony_ciplatforms where there is no `argc`/`argv`. 1328f92157deSopenharmony_ci 1329f92157deSopenharmony_ci### AddGlobalTestEnvironment {#AddGlobalTestEnvironment} 1330f92157deSopenharmony_ci 1331f92157deSopenharmony_ci`Environment* ::testing::AddGlobalTestEnvironment(Environment* env)` 1332f92157deSopenharmony_ci 1333f92157deSopenharmony_ciAdds a test environment to the test program. Must be called before 1334f92157deSopenharmony_ci[`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is called. See 1335f92157deSopenharmony_ci[Global Set-Up and Tear-Down](../advanced.md#global-set-up-and-tear-down) for 1336f92157deSopenharmony_cimore information. 1337f92157deSopenharmony_ci 1338f92157deSopenharmony_ciSee also [`Environment`](#Environment). 1339f92157deSopenharmony_ci 1340f92157deSopenharmony_ci### RegisterTest {#RegisterTest} 1341f92157deSopenharmony_ci 1342f92157deSopenharmony_ci```cpp 1343f92157deSopenharmony_citemplate <typename Factory> 1344f92157deSopenharmony_ciTestInfo* ::testing::RegisterTest(const char* test_suite_name, const char* test_name, 1345f92157deSopenharmony_ci const char* type_param, const char* value_param, 1346f92157deSopenharmony_ci const char* file, int line, Factory factory) 1347f92157deSopenharmony_ci``` 1348f92157deSopenharmony_ci 1349f92157deSopenharmony_ciDynamically registers a test with the framework. 1350f92157deSopenharmony_ci 1351f92157deSopenharmony_ciThe `factory` argument is a factory callable (move-constructible) object or 1352f92157deSopenharmony_cifunction pointer that creates a new instance of the `Test` object. It handles 1353f92157deSopenharmony_ciownership to the caller. The signature of the callable is `Fixture*()`, where 1354f92157deSopenharmony_ci`Fixture` is the test fixture class for the test. All tests registered with the 1355f92157deSopenharmony_cisame `test_suite_name` must return the same fixture type. This is checked at 1356f92157deSopenharmony_ciruntime. 1357f92157deSopenharmony_ci 1358f92157deSopenharmony_ciThe framework will infer the fixture class from the factory and will call the 1359f92157deSopenharmony_ci`SetUpTestSuite` and `TearDownTestSuite` methods for it. 1360f92157deSopenharmony_ci 1361f92157deSopenharmony_ciMust be called before [`RUN_ALL_TESTS()`](#RUN_ALL_TESTS) is invoked, otherwise 1362f92157deSopenharmony_cibehavior is undefined. 1363f92157deSopenharmony_ci 1364f92157deSopenharmony_ciSee 1365f92157deSopenharmony_ci[Registering tests programmatically](../advanced.md#registering-tests-programmatically) 1366f92157deSopenharmony_cifor more information. 1367f92157deSopenharmony_ci 1368f92157deSopenharmony_ci### RUN_ALL_TESTS {#RUN_ALL_TESTS} 1369f92157deSopenharmony_ci 1370f92157deSopenharmony_ci`int RUN_ALL_TESTS()` 1371f92157deSopenharmony_ci 1372f92157deSopenharmony_ciUse this function in `main()` to run all tests. It returns `0` if all tests are 1373f92157deSopenharmony_cisuccessful, or `1` otherwise. 1374f92157deSopenharmony_ci 1375f92157deSopenharmony_ci`RUN_ALL_TESTS()` should be invoked after the command line has been parsed by 1376f92157deSopenharmony_ci[`InitGoogleTest()`](#InitGoogleTest). 1377f92157deSopenharmony_ci 1378f92157deSopenharmony_ciThis function was formerly a macro; thus, it is in the global namespace and has 1379f92157deSopenharmony_cian all-caps name. 1380f92157deSopenharmony_ci 1381f92157deSopenharmony_ci### AssertionSuccess {#AssertionSuccess} 1382f92157deSopenharmony_ci 1383f92157deSopenharmony_ci`AssertionResult ::testing::AssertionSuccess()` 1384f92157deSopenharmony_ci 1385f92157deSopenharmony_ciCreates a successful assertion result. See 1386f92157deSopenharmony_ci[`AssertionResult`](#AssertionResult). 1387f92157deSopenharmony_ci 1388f92157deSopenharmony_ci### AssertionFailure {#AssertionFailure} 1389f92157deSopenharmony_ci 1390f92157deSopenharmony_ci`AssertionResult ::testing::AssertionFailure()` 1391f92157deSopenharmony_ci 1392f92157deSopenharmony_ciCreates a failed assertion result. Use the `<<` operator to store a failure 1393f92157deSopenharmony_cimessage: 1394f92157deSopenharmony_ci 1395f92157deSopenharmony_ci```cpp 1396f92157deSopenharmony_ci::testing::AssertionFailure() << "My failure message"; 1397f92157deSopenharmony_ci``` 1398f92157deSopenharmony_ci 1399f92157deSopenharmony_ciSee [`AssertionResult`](#AssertionResult). 1400f92157deSopenharmony_ci 1401f92157deSopenharmony_ci### StaticAssertTypeEq {#StaticAssertTypeEq} 1402f92157deSopenharmony_ci 1403f92157deSopenharmony_ci`::testing::StaticAssertTypeEq<T1, T2>()` 1404f92157deSopenharmony_ci 1405f92157deSopenharmony_ciCompile-time assertion for type equality. Compiles if and only if `T1` and `T2` 1406f92157deSopenharmony_ciare the same type. The value it returns is irrelevant. 1407f92157deSopenharmony_ci 1408f92157deSopenharmony_ciSee [Type Assertions](../advanced.md#type-assertions) for more information. 1409f92157deSopenharmony_ci 1410f92157deSopenharmony_ci### PrintToString {#PrintToString} 1411f92157deSopenharmony_ci 1412f92157deSopenharmony_ci`std::string ::testing::PrintToString(x)` 1413f92157deSopenharmony_ci 1414f92157deSopenharmony_ciPrints any value `x` using GoogleTest's value printer. 1415f92157deSopenharmony_ci 1416f92157deSopenharmony_ciSee 1417f92157deSopenharmony_ci[Teaching GoogleTest How to Print Your Values](../advanced.md#teaching-googletest-how-to-print-your-values) 1418f92157deSopenharmony_cifor more information. 1419f92157deSopenharmony_ci 1420f92157deSopenharmony_ci### PrintToStringParamName {#PrintToStringParamName} 1421f92157deSopenharmony_ci 1422f92157deSopenharmony_ci`std::string ::testing::PrintToStringParamName(TestParamInfo<T>& info)` 1423f92157deSopenharmony_ci 1424f92157deSopenharmony_ciA built-in parameterized test name generator which returns the result of 1425f92157deSopenharmony_ci[`PrintToString`](#PrintToString) called on `info.param`. Does not work when the 1426f92157deSopenharmony_citest parameter is a `std::string` or C string. See 1427f92157deSopenharmony_ci[Specifying Names for Value-Parameterized Test Parameters](../advanced.md#specifying-names-for-value-parameterized-test-parameters) 1428f92157deSopenharmony_cifor more information. 1429f92157deSopenharmony_ci 1430f92157deSopenharmony_ciSee also [`TestParamInfo`](#TestParamInfo) and 1431f92157deSopenharmony_ci[`INSTANTIATE_TEST_SUITE_P`](#INSTANTIATE_TEST_SUITE_P). 1432