Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
58e62f7a
Commit
58e62f7a
authored
Jan 03, 2019
by
Gennadiy Civil
Browse files
Merge branch 'master' of
https://github.com/google/googletest
parents
5d3a2cd9
827515f8
Changes
22
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1430 additions
and
1118 deletions
+1430
-1118
googlemock/src/gmock-spec-builders.cc
googlemock/src/gmock-spec-builders.cc
+4
-4
googletest/include/gtest/gtest-death-test.h
googletest/include/gtest/gtest-death-test.h
+3
-3
googletest/include/gtest/gtest-param-test.h
googletest/include/gtest/gtest-param-test.h
+93
-83
googletest/include/gtest/gtest-param-test.h.pump
googletest/include/gtest/gtest-param-test.h.pump
+67
-60
googletest/include/gtest/gtest-typed-test.h
googletest/include/gtest/gtest-typed-test.h
+96
-76
googletest/include/gtest/gtest.h
googletest/include/gtest/gtest.h
+186
-142
googletest/include/gtest/gtest_pred_impl.h
googletest/include/gtest/gtest_pred_impl.h
+37
-37
googletest/include/gtest/internal/gtest-internal.h
googletest/include/gtest/internal/gtest-internal.h
+101
-47
googletest/include/gtest/internal/gtest-param-util.h
googletest/include/gtest/internal/gtest-param-util.h
+110
-100
googletest/include/gtest/internal/gtest-port.h
googletest/include/gtest/internal/gtest-port.h
+1
-0
googletest/include/gtest/internal/gtest-type-util.h
googletest/include/gtest/internal/gtest-type-util.h
+3
-4
googletest/include/gtest/internal/gtest-type-util.h.pump
googletest/include/gtest/internal/gtest-type-util.h.pump
+3
-3
googletest/src/gtest-death-test.cc
googletest/src/gtest-death-test.cc
+9
-9
googletest/src/gtest-internal-inl.h
googletest/src/gtest-internal-inl.h
+83
-67
googletest/src/gtest-typed-test.cc
googletest/src/gtest-typed-test.cc
+2
-2
googletest/src/gtest.cc
googletest/src/gtest.cc
+413
-364
googletest/test/googletest-catch-exceptions-test.py
googletest/test/googletest-catch-exceptions-test.py
+2
-4
googletest/test/googletest-listener-test.cc
googletest/test/googletest-listener-test.cc
+186
-82
googletest/test/googletest-output-test-golden-lin.txt
googletest/test/googletest-output-test-golden-lin.txt
+29
-29
googletest/test/gtest-typed-test_test.cc
googletest/test/gtest-typed-test_test.cc
+2
-2
No files found.
googlemock/src/gmock-spec-builders.cc
View file @
58e62f7a
...
...
@@ -572,7 +572,7 @@ struct MockObjectState {
// invoked on this mock object.
const
char
*
first_used_file
;
int
first_used_line
;
::
std
::
string
first_used_test_
cas
e
;
::
std
::
string
first_used_test_
suit
e
;
::
std
::
string
first_used_test
;
bool
leakable
;
// true iff it's OK to leak the object.
FunctionMockers
function_mockers
;
// All registered methods of the object.
...
...
@@ -609,7 +609,7 @@ class MockObjectRegistry {
state
.
first_used_line
);
std
::
cout
<<
" ERROR: this mock object"
;
if
(
state
.
first_used_test
!=
""
)
{
std
::
cout
<<
" (used in test "
<<
state
.
first_used_test_
cas
e
<<
"."
std
::
cout
<<
" (used in test "
<<
state
.
first_used_test_
suit
e
<<
"."
<<
state
.
first_used_test
<<
")"
;
}
std
::
cout
<<
" should be deleted but never is. Its address is @"
...
...
@@ -790,7 +790,7 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
const
TestInfo
*
const
test_info
=
UnitTest
::
GetInstance
()
->
current_test_info
();
if
(
test_info
!=
nullptr
)
{
state
.
first_used_test_
cas
e
=
test_info
->
test_
cas
e_name
();
state
.
first_used_test_
suit
e
=
test_info
->
test_
suit
e_name
();
state
.
first_used_test
=
test_info
->
name
();
}
}
...
...
googletest/include/gtest/gtest-death-test.h
View file @
58e62f7a
...
...
@@ -169,7 +169,7 @@ GTEST_API_ bool InDeathTestChild();
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
// Like ASSERT_EXIT, but continues on to successive tests in the
// test
cas
e, if any:
// test
suit
e, if any:
# define EXPECT_EXIT(statement, predicate, regex) \
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
...
...
@@ -180,7 +180,7 @@ GTEST_API_ bool InDeathTestChild();
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
// Like ASSERT_DEATH, but continues on to successive tests in the
// test
cas
e, if any:
// test
suit
e, if any:
# define EXPECT_DEATH(statement, regex) \
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
...
...
@@ -227,7 +227,7 @@ class GTEST_API_ KilledBySignal {
// return 12;
// }
//
// TEST(Test
Cas
e, TestDieOr12WorksInDgbAndOpt) {
// TEST(Test
Suit
e, TestDieOr12WorksInDgbAndOpt) {
// int sideeffect = 0;
// // Only asserts in dbg.
// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
...
...
googletest/include/gtest/gtest-param-test.h
View file @
58e62f7a
...
...
@@ -75,7 +75,7 @@ TEST_P(FooTest, HasBlahBlah) {
...
}
// Finally, you can use INSTANTIATE_TEST_
CAS
E_P to instantiate the test
// Finally, you can use INSTANTIATE_TEST_
SUIT
E_P to instantiate the test
// case with any set of parameters you want. Google Test defines a number
// of functions for generating test parameters. They return what we call
// (surprise!) parameter generators. Here is a summary of them, which
...
...
@@ -96,17 +96,17 @@ TEST_P(FooTest, HasBlahBlah) {
// For more details, see comments at the definitions of these functions below
// in this file.
//
// The following statement will instantiate tests from the FooTest test
cas
e
// The following statement will instantiate tests from the FooTest test
suit
e
// each with parameter values "meeny", "miny", and "moe".
INSTANTIATE_TEST_
CAS
E_P(InstantiationName,
INSTANTIATE_TEST_
SUIT
E_P(InstantiationName,
FooTest,
Values("meeny", "miny", "moe"));
// To distinguish different instances of the pattern, (yes, you
// can instantiate it more then once) the first argument to the
// INSTANTIATE_TEST_
CAS
E_P macro is a prefix that will be added to the
// actual test
cas
e name. Remember to pick unique prefixes for different
// INSTANTIATE_TEST_
SUIT
E_P macro is a prefix that will be added to the
// actual test
suit
e name. Remember to pick unique prefixes for different
// instantiations. The tests from the instantiation above will have
// these names:
//
...
...
@@ -123,7 +123,7 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
// with parameter values "cat" and "dog":
const char* pets[] = {"cat", "dog"};
INSTANTIATE_TEST_
CAS
E_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
INSTANTIATE_TEST_
SUIT
E_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
// The tests from the instantiation above will have these names:
//
...
...
@@ -132,9 +132,9 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
//
// Please note that INSTANTIATE_TEST_
CAS
E_P will instantiate all tests
// in the given test
cas
e, whether their definitions come before or
// AFTER the INSTANTIATE_TEST_
CAS
E_P statement.
// Please note that INSTANTIATE_TEST_
SUIT
E_P will instantiate all tests
// in the given test
suit
e, whether their definitions come before or
// AFTER the INSTANTIATE_TEST_
SUIT
E_P statement.
//
// Please also note that generator expressions (including parameters to the
// generators) are evaluated in InitGoogleTest(), after main() has started.
...
...
@@ -190,11 +190,11 @@ namespace testing {
// Functions producing parameter generators.
//
// Google Test uses these generators to produce parameters for value-
// parameterized tests. When a parameterized test
cas
e is instantiated
// parameterized tests. When a parameterized test
suit
e is instantiated
// with a particular generator, Google Test creates and runs tests
// for each element in the sequence produced by the generator.
//
// In the following sample, tests from test
cas
e FooTest are instantiated
// In the following sample, tests from test
suit
e FooTest are instantiated
// each three times with parameter values 3, 5, and 8:
//
// class FooTest : public TestWithParam<int> { ... };
...
...
@@ -203,7 +203,7 @@ namespace testing {
// }
// TEST_P(FooTest, TestThat) {
// }
// INSTANTIATE_TEST_
CAS
E_P(TestSequence, FooTest, Values(3, 5, 8));
// INSTANTIATE_TEST_
SUIT
E_P(TestSequence, FooTest, Values(3, 5, 8));
//
// Range() returns generators providing sequences of values in a range.
...
...
@@ -260,13 +260,13 @@ internal::ParamGenerator<T> Range(T start, T end) {
//
// Examples:
//
// This instantiates tests from test
cas
e StringTest
// This instantiates tests from test
suit
e StringTest
// each with C-string values of "foo", "bar", and "baz":
//
// const char* strings[] = {"foo", "bar", "baz"};
// INSTANTIATE_TEST_
CAS
E_P(StringSequence, StringTest, ValuesIn(strings));
// INSTANTIATE_TEST_
SUIT
E_P(StringSequence, StringTest, ValuesIn(strings));
//
// This instantiates tests from test
cas
e StlStringTest
// This instantiates tests from test
suit
e StlStringTest
// each with STL strings with values "a" and "b":
//
// ::std::vector< ::std::string> GetParameterStrings() {
...
...
@@ -276,7 +276,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
// return v;
// }
//
// INSTANTIATE_TEST_
CAS
E_P(CharSequence,
// INSTANTIATE_TEST_
SUIT
E_P(CharSequence,
// StlStringTest,
// ValuesIn(GetParameterStrings()));
//
...
...
@@ -291,7 +291,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
// return list;
// }
// ::std::list<char> l = GetParameterChars();
// INSTANTIATE_TEST_
CAS
E_P(CharSequence2,
// INSTANTIATE_TEST_
SUIT
E_P(CharSequence2,
// CharTest,
// ValuesIn(l.begin(), l.end()));
//
...
...
@@ -323,15 +323,17 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
// Values(T v1, T v2, ..., T vN)
// - returns a generator producing sequences with elements v1, v2, ..., vN.
//
// For example, this instantiates tests from test
cas
e BarTest each
// For example, this instantiates tests from test
suit
e BarTest each
// with values "one", "two", and "three":
//
// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
// INSTANTIATE_TEST_SUITE_P(NumSequence,
// BarTest,
// Values("one", "two", "three"));
//
// This instantiates tests from test
cas
e BazTest each with values 1, 2, 3.5.
// This instantiates tests from test
suit
e BazTest each with values 1, 2, 3.5.
// The exact type of values will depend on the type of parameter in BazTest.
//
// INSTANTIATE_TEST_
CAS
E_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
// INSTANTIATE_TEST_
SUIT
E_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
//
//
template
<
typename
...
T
>
...
...
@@ -349,7 +351,7 @@ internal::ValueArray<T...> Values(T... v) {
// of multiple flags can be tested when several Bool()'s are combined using
// Combine() function.
//
// In the following example all tests in the test
cas
e FlagDependentTest
// In the following example all tests in the test
suit
e FlagDependentTest
// will be instantiated twice with parameters false and true.
//
// class FlagDependentTest : public testing::TestWithParam<bool> {
...
...
@@ -357,7 +359,7 @@ internal::ValueArray<T...> Values(T... v) {
// external_flag = GetParam();
// }
// }
// INSTANTIATE_TEST_
CAS
E_P(BoolSequence, FlagDependentTest, Bool());
// INSTANTIATE_TEST_
SUIT
E_P(BoolSequence, FlagDependentTest, Bool());
//
inline
internal
::
ParamGenerator
<
bool
>
Bool
()
{
return
Values
(
false
,
true
);
...
...
@@ -378,7 +380,7 @@ inline internal::ParamGenerator<bool> Bool() {
//
// Example:
//
// This will instantiate tests in test
cas
e AnimalTest each one with
// This will instantiate tests in test
suit
e AnimalTest each one with
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
// tuple("dog", BLACK), and tuple("dog", WHITE):
//
...
...
@@ -388,7 +390,7 @@ inline internal::ParamGenerator<bool> Bool() {
//
// TEST_P(AnimalTest, AnimalLooksNice) {...}
//
// INSTANTIATE_TEST_
CAS
E_P(AnimalVariations, AnimalTest,
// INSTANTIATE_TEST_
SUIT
E_P(AnimalVariations, AnimalTest,
// Combine(Values("cat", "dog"),
// Values(BLACK, WHITE)));
//
...
...
@@ -406,7 +408,7 @@ inline internal::ParamGenerator<bool> Bool() {
// TEST_P(FlagDependentTest, TestFeature1) {
// // Test your code using external_flag_1 and external_flag_2 here.
// }
// INSTANTIATE_TEST_
CAS
E_P(TwoBoolSequence, FlagDependentTest,
// INSTANTIATE_TEST_
SUIT
E_P(TwoBoolSequence, FlagDependentTest,
// Combine(Bool(), Bool()));
//
template
<
typename
Generator1
,
typename
Generator2
>
...
...
@@ -513,36 +515,36 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
g1
,
g2
,
g3
,
g4
,
g5
,
g6
,
g7
,
g8
,
g9
,
g10
);
}
#
define TEST_P(test_
cas
e_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name) \
: public test_
cas
e_name { \
#define TEST_P(test_
suit
e_name, test_name)
\
class GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)
\
: public test_
suit
e_name {
\
public: \
GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)() {} \
GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)() {}
\
virtual void TestBody(); \
\
private: \
static int AddToRegistry() { \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\
#test_case_name, \
::testing::internal::CodeLocation(\
__FILE__, __LINE__))->AddTestPattern(\
GTEST_STRINGIFY_(test_case_name), \
GTEST_STRINGIFY_(test_name), \
new ::testing::internal::TestMetaFactory< \
GTEST_TEST_CLASS_NAME_(\
test_case_name, test_name)>()); \
::testing::UnitTest::GetInstance() \
->parameterized_test_registry() \
.GetTestSuitePatternHolder<test_suite_name>( \
#test_suite_name, \
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
->AddTestPattern( \
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
test_suite_name, test_name)>()); \
return 0; \
} \
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name,
test_name)); \
GTEST_DISALLOW_COPY_AND_ASSIGN_(
GTEST_TEST_CLASS_NAME_(test_suite_name,
\
test_name));
\
}; \
int GTEST_TEST_CLASS_NAME_(test_
cas
e_name, \
int GTEST_TEST_CLASS_NAME_(test_
suit
e_name,
\
test_name)::gtest_registering_dummy_ = \
GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)::AddToRegistry(); \
void GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)::TestBody()
GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)::AddToRegistry();
\
void GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)::TestBody()
// The optional last argument to INSTANTIATE_TEST_
CAS
E_P allows the user
// The optional last argument to INSTANTIATE_TEST_
SUIT
E_P allows the user
// to specify a function or functor that generates custom test name suffixes
// based on the test parameters. The function should accept one argument of
// type testing::TestParamInfo<class ParamType>, and return std::string.
...
...
@@ -554,25 +556,33 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
// alphanumeric characters or underscore. Because PrintToString adds quotes
// to std::string and C strings, it won't work for these types.
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
(__VA_ARGS__)(info); \
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, generator, ...) \
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
return generator; \
} \
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\
#test_case_name, \
::testing::internal::CodeLocation(\
__FILE__, __LINE__))->AddTestCaseInstantiation(\
#prefix, \
>est_##prefix##test_case_name##_EvalGenerator_, \
>est_##prefix##test_case_name##_EvalGenerateName_, \
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
return ::testing::internal::GetParamNameGen<test_suite_name::ParamType>( \
__VA_ARGS__)(info); \
} \
static int gtest_##prefix##test_suite_name##_dummy_ \
GTEST_ATTRIBUTE_UNUSED_ = \
::testing::UnitTest::GetInstance() \
->parameterized_test_registry() \
.GetTestSuitePatternHolder<test_suite_name>( \
#test_suite_name, \
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
->AddTestSuiteInstantiation( \
#prefix, >est_##prefix##test_suite_name##_EvalGenerator_, \
>est_##prefix##test_suite_name##_EvalGenerateName_, \
__FILE__, __LINE__)
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define INSTANTIATE_TEST_CASE_P INSTANTIATE_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
}
// namespace testing
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
googletest/include/gtest/gtest-param-test.h.pump
View file @
58e62f7a
...
...
@@ -74,7 +74,7 @@ TEST_P(FooTest, HasBlahBlah) {
...
}
// Finally, you can use INSTANTIATE_TEST_
CAS
E_P to instantiate the test
// Finally, you can use INSTANTIATE_TEST_
SUIT
E_P to instantiate the test
// case with any set of parameters you want. Google Test defines a number
// of functions for generating test parameters. They return what we call
// (surprise!) parameter generators. Here is a summary of them, which
...
...
@@ -95,17 +95,17 @@ TEST_P(FooTest, HasBlahBlah) {
// For more details, see comments at the definitions of these functions below
// in this file.
//
// The following statement will instantiate tests from the FooTest test
cas
e
// The following statement will instantiate tests from the FooTest test
suit
e
// each with parameter values "meeny", "miny", and "moe".
INSTANTIATE_TEST_
CAS
E_P(InstantiationName,
INSTANTIATE_TEST_
SUIT
E_P(InstantiationName,
FooTest,
Values("meeny", "miny", "moe"));
// To distinguish different instances of the pattern, (yes, you
// can instantiate it more then once) the first argument to the
// INSTANTIATE_TEST_
CAS
E_P macro is a prefix that will be added to the
// actual test
cas
e name. Remember to pick unique prefixes for different
// INSTANTIATE_TEST_
SUIT
E_P macro is a prefix that will be added to the
// actual test
suit
e name. Remember to pick unique prefixes for different
// instantiations. The tests from the instantiation above will have
// these names:
//
...
...
@@ -122,7 +122,7 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
// with parameter values "cat" and "dog":
const char* pets[] = {"cat", "dog"};
INSTANTIATE_TEST_
CAS
E_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
INSTANTIATE_TEST_
SUIT
E_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
// The tests from the instantiation above will have these names:
//
...
...
@@ -131,9 +131,9 @@ INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
//
// Please note that INSTANTIATE_TEST_
CAS
E_P will instantiate all tests
// in the given test
cas
e, whether their definitions come before or
// AFTER the INSTANTIATE_TEST_
CAS
E_P statement.
// Please note that INSTANTIATE_TEST_
SUIT
E_P will instantiate all tests
// in the given test
suit
e, whether their definitions come before or
// AFTER the INSTANTIATE_TEST_
SUIT
E_P statement.
//
// Please also note that generator expressions (including parameters to the
// generators) are evaluated in InitGoogleTest(), after main() has started.
...
...
@@ -189,11 +189,11 @@ namespace testing {
// Functions producing parameter generators.
//
// Google Test uses these generators to produce parameters for value-
// parameterized tests. When a parameterized test
cas
e is instantiated
// parameterized tests. When a parameterized test
suit
e is instantiated
// with a particular generator, Google Test creates and runs tests
// for each element in the sequence produced by the generator.
//
// In the following sample, tests from test
cas
e FooTest are instantiated
// In the following sample, tests from test
suit
e FooTest are instantiated
// each three times with parameter values 3, 5, and 8:
//
// class FooTest : public TestWithParam<int> { ... };
...
...
@@ -202,7 +202,7 @@ namespace testing {
// }
// TEST_P(FooTest, TestThat) {
// }
// INSTANTIATE_TEST_
CAS
E_P(TestSequence, FooTest, Values(3, 5, 8));
// INSTANTIATE_TEST_
SUIT
E_P(TestSequence, FooTest, Values(3, 5, 8));
//
// Range() returns generators providing sequences of values in a range.
...
...
@@ -259,13 +259,13 @@ internal::ParamGenerator<T> Range(T start, T end) {
//
// Examples:
//
// This instantiates tests from test
cas
e StringTest
// This instantiates tests from test
suit
e StringTest
// each with C-string values of "foo", "bar", and "baz":
//
// const char* strings[] = {"foo", "bar", "baz"};
// INSTANTIATE_TEST_
CAS
E_P(StringSequence, StringTest, ValuesIn(strings));
// INSTANTIATE_TEST_
SUIT
E_P(StringSequence, StringTest, ValuesIn(strings));
//
// This instantiates tests from test
cas
e StlStringTest
// This instantiates tests from test
suit
e StlStringTest
// each with STL strings with values "a" and "b":
//
// ::std::vector< ::std::string> GetParameterStrings() {
...
...
@@ -275,7 +275,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
// return v;
// }
//
// INSTANTIATE_TEST_
CAS
E_P(CharSequence,
// INSTANTIATE_TEST_
SUIT
E_P(CharSequence,
// StlStringTest,
// ValuesIn(GetParameterStrings()));
//
...
...
@@ -290,7 +290,7 @@ internal::ParamGenerator<T> Range(T start, T end) {
// return list;
// }
// ::std::list<char> l = GetParameterChars();
// INSTANTIATE_TEST_
CAS
E_P(CharSequence2,
// INSTANTIATE_TEST_
SUIT
E_P(CharSequence2,
// CharTest,
// ValuesIn(l.begin(), l.end()));
//
...
...
@@ -322,15 +322,17 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
// Values(T v1, T v2, ..., T vN)
// - returns a generator producing sequences with elements v1, v2, ..., vN.
//
// For example, this instantiates tests from test
cas
e BarTest each
// For example, this instantiates tests from test
suit
e BarTest each
// with values "one", "two", and "three":
//
// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
// INSTANTIATE_TEST_SUITE_P(NumSequence,
// BarTest,
// Values("one", "two", "three"));
//
// This instantiates tests from test
cas
e BazTest each with values 1, 2, 3.5.
// This instantiates tests from test
suit
e BazTest each with values 1, 2, 3.5.
// The exact type of values will depend on the type of parameter in BazTest.
//
// INSTANTIATE_TEST_
CAS
E_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
// INSTANTIATE_TEST_
SUIT
E_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
//
//
template
<
typename
...
T
>
...
...
@@ -348,7 +350,7 @@ internal::ValueArray<T...> Values(T... v) {
// of multiple flags can be tested when several Bool()'s are combined using
// Combine() function.
//
// In the following example all tests in the test
cas
e FlagDependentTest
// In the following example all tests in the test
suit
e FlagDependentTest
// will be instantiated twice with parameters false and true.
//
// class FlagDependentTest : public testing::TestWithParam<bool> {
...
...
@@ -356,7 +358,7 @@ internal::ValueArray<T...> Values(T... v) {
// external_flag = GetParam();
// }
// }
// INSTANTIATE_TEST_
CAS
E_P(BoolSequence, FlagDependentTest, Bool());
// INSTANTIATE_TEST_
SUIT
E_P(BoolSequence, FlagDependentTest, Bool());
//
inline
internal
::
ParamGenerator
<
bool
>
Bool
()
{
return
Values
(
false
,
true
);
...
...
@@ -377,7 +379,7 @@ inline internal::ParamGenerator<bool> Bool() {
//
// Example:
//
// This will instantiate tests in test
cas
e AnimalTest each one with
// This will instantiate tests in test
suit
e AnimalTest each one with
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
// tuple("dog", BLACK), and tuple("dog", WHITE):
//
...
...
@@ -387,7 +389,7 @@ inline internal::ParamGenerator<bool> Bool() {
//
// TEST_P(AnimalTest, AnimalLooksNice) {...}
//
// INSTANTIATE_TEST_
CAS
E_P(AnimalVariations, AnimalTest,
// INSTANTIATE_TEST_
SUIT
E_P(AnimalVariations, AnimalTest,
// Combine(Values("cat", "dog"),
// Values(BLACK, WHITE)));
//
...
...
@@ -405,7 +407,7 @@ inline internal::ParamGenerator<bool> Bool() {
// TEST_P(FlagDependentTest, TestFeature1) {
// // Test your code using external_flag_1 and external_flag_2 here.
// }
// INSTANTIATE_TEST_
CAS
E_P(TwoBoolSequence, FlagDependentTest,
// INSTANTIATE_TEST_
SUIT
E_P(TwoBoolSequence, FlagDependentTest,
// Combine(Bool(), Bool()));
//
$
range
i
2.
.
maxtuple
...
...
@@ -421,36 +423,36 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
]]
# define TEST_P(test_
cas
e_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name) \
: public test_
cas
e_name { \
# define TEST_P(test_
suit
e_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name) \
: public test_
suit
e_name { \
public: \
GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)() {} \
GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)() {} \
virtual void TestBody(); \
private: \
static int AddToRegistry() { \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTest
Cas
ePatternHolder<test_
cas
e_name>(\
#test_
cas
e_name, \
GetTest
Suit
ePatternHolder<test_
suit
e_name>(\
#test_
suit
e_name, \
::testing::internal::CodeLocation(\
__FILE__, __LINE__))->AddTestPattern(\
GTEST_STRINGIFY_(test_
cas
e_name), \
GTEST_STRINGIFY_(test_
suit
e_name), \
GTEST_STRINGIFY_(test_name), \
new ::testing::internal::TestMetaFactory< \
GTEST_TEST_CLASS_NAME_(\
test_
cas
e_name, test_name)>()); \
test_
suit
e_name, test_name)>()); \
return 0; \
} \
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)); \
GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)); \
}; \
int GTEST_TEST_CLASS_NAME_(test_
cas
e_name, \
int GTEST_TEST_CLASS_NAME_(test_
suit
e_name, \
test_name)::gtest_registering_dummy_ = \
GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)::AddToRegistry(); \
void GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)::TestBody()
GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)::AddToRegistry(); \
void GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)::TestBody()
// The optional last argument to INSTANTIATE_TEST_
CAS
E_P allows the user
// The optional last argument to INSTANTIATE_TEST_
SUIT
E_P allows the user
// to specify a function or functor that generates custom test name suffixes
// based on the test parameters. The function should accept one argument of
// type testing::TestParamInfo<class ParamType>, and return std::string.
...
...
@@ -462,25 +464,30 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
// alphanumeric characters or underscore. Because PrintToString adds quotes
// to std::string and C strings, it won't work for these types.
# define INSTANTIATE_TEST_
CAS
E_P(prefix, test_
cas
e_name, generator, ...) \
static ::testing::internal::ParamGenerator<test_
cas
e_name::ParamType> \
gtest_##prefix##test_
cas
e_name##_EvalGenerator_() { return generator; } \
static ::std::string gtest_##prefix##test_
cas
e_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_
cas
e_name::ParamType>& info) { \
return ::testing::internal::GetParamNameGen<test_
cas
e_name::ParamType> \
# define INSTANTIATE_TEST_
SUIT
E_P(prefix, test_
suit
e_name, generator, ...) \
static ::testing::internal::ParamGenerator<test_
suit
e_name::ParamType> \
gtest_##prefix##test_
suit
e_name##_EvalGenerator_() { return generator; } \
static ::std::string gtest_##prefix##test_
suit
e_name##_EvalGenerateName_( \
const ::testing::TestParamInfo<test_
suit
e_name::ParamType>& info) { \
return ::testing::internal::GetParamNameGen<test_
suit
e_name::ParamType> \
(__VA_ARGS__)(info); \
} \
static int gtest_##prefix##test_
cas
e_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
static int gtest_##prefix##test_
suit
e_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTest
Cas
ePatternHolder<test_
cas
e_name>(\
#test_
cas
e_name, \
GetTest
Suit
ePatternHolder<test_
suit
e_name>(\
#test_
suit
e_name, \
::testing::internal::CodeLocation(\
__FILE__, __LINE__))->AddTest
Cas
eInstantiation(\
__FILE__, __LINE__))->AddTest
Suit
eInstantiation(\
#prefix, \
>est_##prefix##test_
cas
e_name##_EvalGenerator_, \
>est_##prefix##test_
cas
e_name##_EvalGenerateName_, \
>est_##prefix##test_
suit
e_name##_EvalGenerator_, \
>est_##prefix##test_
suit
e_name##_EvalGenerateName_, \
__FILE__, __LINE__)
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define INSTANTIATE_TEST_CASE_P INSTANTIATE_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
}
// namespace testing
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
googletest/include/gtest/gtest-typed-test.h
View file @
58e62f7a
...
...
@@ -52,18 +52,18 @@ class FooTest : public testing::Test {
T value_;
};
// Next, associate a list of types with the test
cas
e, which will be
// Next, associate a list of types with the test
suit
e, which will be
// repeated for each type in the list. The typedef is necessary for
// the macro to parse correctly.
typedef testing::Types<char, int, unsigned int> MyTypes;
TYPED_TEST_
CAS
E(FooTest, MyTypes);
TYPED_TEST_
SUIT
E(FooTest, MyTypes);
// If the type list contains only one type, you can write that type
// directly without Types<...>:
// TYPED_TEST_
CAS
E(FooTest, int);
// TYPED_TEST_
SUIT
E(FooTest, int);
// Then, use TYPED_TEST() instead of TEST_F() to define as many typed
// tests for this test
cas
e as you want.
// tests for this test
suit
e as you want.
TYPED_TEST(FooTest, DoesBlah) {
// Inside a test, refer to TypeParam to get the type parameter.
// Since we are inside a derived class template, C++ requires use to
...
...
@@ -83,7 +83,7 @@ TYPED_TEST(FooTest, DoesBlah) {
TYPED_TEST(FooTest, HasPropertyA) { ... }
// TYPED_TEST_
CAS
E takes an optional third argument which allows to specify a
// TYPED_TEST_
SUIT
E takes an optional third argument which allows to specify a
// class that generates custom test name suffixes based on the type. This should
// be a class which has a static template function GetName(int index) returning
// a string for each type. The provided integer index equals the index of the
...
...
@@ -99,7 +99,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... }
// if (std::is_same<T, unsigned int>()) return "unsignedInt";
// }
// };
// TYPED_TEST_
CAS
E(FooTest, MyTypes, MyTypeNames);
// TYPED_TEST_
SUIT
E(FooTest, MyTypes, MyTypeNames);
#endif // 0
...
...
@@ -126,13 +126,13 @@ class FooTest : public testing::Test {
...
};
// Next, declare that you will define a type-parameterized test
cas
e
// Next, declare that you will define a type-parameterized test
suit
e
// (the _P suffix is for "parameterized" or "pattern", whichever you
// prefer):
TYPED_TEST_
CAS
E_P(FooTest);
TYPED_TEST_
SUIT
E_P(FooTest);
// Then, use TYPED_TEST_P() to define as many type-parameterized tests
// for this type-parameterized test
cas
e as you want.
// for this type-parameterized test
suit
e as you want.
TYPED_TEST_P(FooTest, DoesBlah) {
// Inside a test, refer to TypeParam to get the type parameter.
TypeParam n = 0;
...
...
@@ -143,9 +143,9 @@ TYPED_TEST_P(FooTest, HasPropertyA) { ... }
// Now the tricky part: you need to register all test patterns before
// you can instantiate them. The first argument of the macro is the
// test
cas
e name; the rest are the names of the tests in this test
// test
suit
e name; the rest are the names of the tests in this test
// case.
REGISTER_TYPED_TEST_
CAS
E_P(FooTest,
REGISTER_TYPED_TEST_
SUIT
E_P(FooTest,
DoesBlah, HasPropertyA);
// Finally, you are free to instantiate the pattern with the types you
...
...
@@ -154,19 +154,19 @@ REGISTER_TYPED_TEST_CASE_P(FooTest,
//
// To distinguish different instances of the pattern, the first
// argument to the INSTANTIATE_* macro is a prefix that will be added
// to the actual test
cas
e name. Remember to pick unique prefixes for
// to the actual test
suit
e name. Remember to pick unique prefixes for
// different instances.
typedef testing::Types<char, int, unsigned int> MyTypes;
INSTANTIATE_TYPED_TEST_
CAS
E_P(My, FooTest, MyTypes);
INSTANTIATE_TYPED_TEST_
SUIT
E_P(My, FooTest, MyTypes);
// If the type list contains only one type, you can write that type
// directly without Types<...>:
// INSTANTIATE_TYPED_TEST_
CAS
E_P(My, FooTest, int);
// INSTANTIATE_TYPED_TEST_
SUIT
E_P(My, FooTest, int);
//
// Similar to the optional argument of TYPED_TEST_
CAS
E above,
// INSTANTIATE_TEST_
CAS
E_P takes an optional fourth argument which allows to
// Similar to the optional argument of TYPED_TEST_
SUIT
E above,
// INSTANTIATE_TEST_
SUIT
E_P takes an optional fourth argument which allows to
// generate custom names.
// INSTANTIATE_TYPED_TEST_
CAS
E_P(My, FooTest, MyTypes, MyTypeNames);
// INSTANTIATE_TYPED_TEST_
SUIT
E_P(My, FooTest, MyTypes, MyTypeNames);
#endif // 0
...
...
@@ -180,19 +180,19 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// Expands to the name of the typedef for the type parameters of the
// given test
cas
e.
#
define GTEST_TYPE_PARAMS_(Test
Cas
eName) gtest_type_params_##Test
Cas
eName##_
// given test
suit
e.
#define GTEST_TYPE_PARAMS_(Test
Suit
eName) gtest_type_params_##Test
Suit
eName##_
// Expands to the name of the typedef for the NameGenerator, responsible for
// creating the suffixes of the name.
#define GTEST_NAME_GENERATOR_(Test
Cas
eName) \
gtest_type_params_##Test
Cas
eName##_NameGenerator
#define GTEST_NAME_GENERATOR_(Test
Suit
eName) \
gtest_type_params_##Test
Suit
eName##_NameGenerator
// The 'Types' template argument below must have spaces around it
// since some compilers may choke on '>>' when passing a template
// instance (e.g. Types<int>)
#
define TYPED_TEST_
CAS
E(CaseName, Types, ...)
\
typedef ::testing::internal::TypeList<
Types
>::type GTEST_TYPE_PARAMS_( \
#define TYPED_TEST_
SUIT
E(CaseName, Types, ...) \
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
CaseName); \
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
GTEST_NAME_GENERATOR_(CaseName)
...
...
@@ -224,6 +224,11 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
void GTEST_TEST_CLASS_NAME_(CaseName, \
TestName)<gtest_TypeParam_>::TestBody()
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define TYPED_TEST_CASE TYPED_TEST_SUITE
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#endif // GTEST_HAS_TYPED_TEST
// Implements type-parameterized tests.
...
...
@@ -233,73 +238,88 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// Expands to the namespace name that the type-parameterized tests for
// the given type-parameterized test
cas
e are defined in. The exact
// the given type-parameterized test
suit
e are defined in. The exact
// name of the namespace is subject to change without notice.
# define GTEST_CASE_NAMESPACE_(TestCaseName) \
gtest_case_##TestCaseName##_
#define GTEST_SUITE_NAMESPACE_(TestSuiteName) gtest_suite_##TestSuiteName##_
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// Expands to the name of the variable used to remember the names of
// the defined tests in the given test
cas
e.
#
define GTEST_TYPED_TEST_
CAS
E_P_STATE_(Test
Cas
eName) \
gtest_typed_test_
cas
e_p_state_##Test
Cas
eName##_
// the defined tests in the given test
suit
e.
#define GTEST_TYPED_TEST_
SUIT
E_P_STATE_(Test
Suit
eName) \
gtest_typed_test_
suit
e_p_state_##Test
Suit
eName##_
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
//
// Expands to the name of the variable used to remember the names of
// the registered tests in the given test
cas
e.
#
define GTEST_REGISTERED_TEST_NAMES_(Test
Cas
eName) \
gtest_registered_test_names_##Test
Cas
eName##_
// the registered tests in the given test
suit
e.
#define GTEST_REGISTERED_TEST_NAMES_(Test
Suit
eName) \
gtest_registered_test_names_##Test
Suit
eName##_
// The variables defined in the type-parameterized test macros are
// static as typically these macros are used in a .h file that can be
// #included in multiple translation units linked together.
# define TYPED_TEST_CASE_P(CaseName) \
static ::testing::internal::TypedTestCasePState \
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
#define TYPED_TEST_SUITE_P(SuiteName) \
static ::testing::internal::TypedTestSuitePState \
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define TYPED_TEST_CASE_P TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#
define TYPED_TEST_P(
Cas
eName, TestName) \
namespace GTEST_
CAS
E_NAMESPACE_(
Cas
eName) { \
#define TYPED_TEST_P(
Suit
eName, TestName)
\
namespace GTEST_
SUIT
E_NAMESPACE_(
Suit
eName) {
\
template <typename gtest_TypeParam_> \
class TestName : public
Cas
eName<gtest_TypeParam_> { \
class TestName : public
Suit
eName<gtest_TypeParam_> {
\
private: \
typedef
Cas
eName<gtest_TypeParam_> TestFixture; \
typedef
Suit
eName<gtest_TypeParam_> TestFixture;
\
typedef gtest_TypeParam_ TypeParam; \
virtual void TestBody(); \
}; \
static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
GTEST_TYPED_TEST_
CAS
E_P_STATE_(
Cas
eName).AddTestName(\
__FILE__, __LINE__, #
Cas
eName, #TestName); \
GTEST_TYPED_TEST_
SUIT
E_P_STATE_(
Suit
eName).AddTestName(
\
__FILE__, __LINE__, #
Suit
eName, #TestName);
\
} \
template <typename gtest_TypeParam_> \
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
void GTEST_SUITE_NAMESPACE_( \
SuiteName)::TestName<gtest_TypeParam_>::TestBody()
#
define REGISTER_TYPED_TEST_
CASE_P(CaseName, ...)
\
namespace GTEST_
CAS
E_NAMESPACE_(
Cas
eName) { \
#define REGISTER_TYPED_TEST_
SUITE_P(SuiteName, ...)
\
namespace GTEST_
SUIT
E_NAMESPACE_(
Suit
eName) {
\
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
} \
static const char* const GTEST_REGISTERED_TEST_NAMES_(
CaseName)
\
GTEST_ATTRIBUTE_UNUSED_ = \
GTEST_TYPED_TEST_
CAS
E_P_STATE_(
Cas
eName).VerifyRegisteredTestNames( \
static const char* const GTEST_REGISTERED_TEST_NAMES_(
\
SuiteName)
GTEST_ATTRIBUTE_UNUSED_ =
\
GTEST_TYPED_TEST_
SUIT
E_P_STATE_(
Suit
eName).VerifyRegisteredTestNames(
\
__FILE__, __LINE__, #__VA_ARGS__)
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define REGISTER_TYPED_TEST_CASE_P REGISTER_TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// The 'Types' template argument below must have spaces around it
// since some compilers may choke on '>>' when passing a template
// instance (e.g. Types<int>)
#
define INSTANTIATE_TYPED_TEST_
CAS
E_P(Prefix,
Cas
eName, Types, ...) \
static bool gtest_##Prefix##_##
Cas
eName GTEST_ATTRIBUTE_UNUSED_ = \
::testing::internal::TypeParameterizedTest
Cas
e< \
Cas
eName, GTEST_
CAS
E_NAMESPACE_(
Cas
eName)::gtest_AllTests_,
\
::testing::internal::TypeList<
Types
>::type>:: \
#define INSTANTIATE_TYPED_TEST_
SUIT
E_P(Prefix,
Suit
eName, Types, ...)
\
static bool gtest_##Prefix##_##
Suit
eName GTEST_ATTRIBUTE_UNUSED_ =
\
::testing::internal::TypeParameterizedTest
Suit
e<
\
Suit
eName, GTEST_
SUIT
E_NAMESPACE_(
Suit
eName)::gtest_AllTests_, \
::testing::internal::TypeList<Types>::type>::
\
Register(#Prefix, \
::testing::internal::CodeLocation(__FILE__, __LINE__), \
>EST_TYPED_TEST_
CAS
E_P_STATE_(
Cas
eName), #
Cas
eName,
\
GTEST_REGISTERED_TEST_NAMES_(
Cas
eName), \
>EST_TYPED_TEST_
SUIT
E_P_STATE_(
Suit
eName), #
Suit
eName, \
GTEST_REGISTERED_TEST_NAMES_(
Suit
eName),
\
::testing::internal::GenerateNames< \
::testing::internal::NameGeneratorSelector< \
__VA_ARGS__>::type, \
::testing::internal::TypeList< Types >::type>())
::testing::internal::TypeList<Types>::type>())
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#define INSTANTIATE_TYPED_TEST_CASE_P INSTANTIATE_TYPED_TEST_SUITE_P
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
#endif // GTEST_HAS_TYPED_TEST_P
...
...
googletest/include/gtest/gtest.h
View file @
58e62f7a
...
...
@@ -197,7 +197,12 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
// If we don't forward declare them the compiler might confuse the classes
// in friendship clauses with same named classes on the scope.
class
Test
;
class
TestCase
;
class
TestSuite
;
// Old API is still available but deprecated
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
using
TestCase
=
TestSuite
;
#endif
class
TestInfo
;
class
UnitTest
;
...
...
@@ -386,8 +391,8 @@ namespace testing {
// The abstract class that all tests inherit from.
//
// In Google Test, a unit test program contains one or many Test
Cas
es, and
// each Test
Cas
e contains one or many Tests.
// In Google Test, a unit test program contains one or many Test
Suit
es, and
// each Test
Suit
e contains one or many Tests.
//
// When you define a test using the TEST macro, you don't need to
// explicitly derive from Test - the TEST macro automatically does
...
...
@@ -411,29 +416,30 @@ class GTEST_API_ Test {
public:
friend
class
TestInfo
;
// Defines types for pointers to functions that set up and tear down
// a test case.
typedef
internal
::
SetUpTestCaseFunc
SetUpTestCaseFunc
;
typedef
internal
::
TearDownTestCaseFunc
TearDownTestCaseFunc
;
// The d'tor is virtual as we intend to inherit from Test.
virtual
~
Test
();
// Sets up the stuff shared by all tests in this test case.
//
// Google Test will call Foo::SetUpTest
Cas
e() before running the first
// Google Test will call Foo::SetUpTest
Suit
e() before running the first
// test in test case Foo. Hence a sub-class can define its own
// SetUpTest
Cas
e() method to shadow the one defined in the super
// SetUpTest
Suit
e() method to shadow the one defined in the super
// class.
static
void
SetUpTest
Cas
e
()
{}
static
void
SetUpTest
Suit
e
()
{}
// Tears down the stuff shared by all tests in this test case.
//
// Google Test will call Foo::TearDownTest
Cas
e() after running the last
// Google Test will call Foo::TearDownTest
Suit
e() after running the last
// test in test case Foo. Hence a sub-class can define its own
// TearDownTest
Cas
e() method to shadow the one defined in the super
// TearDownTest
Suit
e() method to shadow the one defined in the super
// class.
static
void
TearDownTestSuite
()
{}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
static
void
TearDownTestCase
()
{}
static
void
SetUpTestCase
()
{}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Returns true iff the current test has a fatal failure.
static
bool
HasFatalFailure
();
...
...
@@ -448,15 +454,15 @@ class GTEST_API_ Test {
// non-fatal) failure.
static
bool
HasFailure
()
{
return
HasFatalFailure
()
||
HasNonfatalFailure
();
}
// Logs a property for the current test, test
cas
e, or for the entire
// Logs a property for the current test, test
suit
e, or for the entire
// invocation of the test program when used outside of the context of a
// test
cas
e. Only the last value for a given key is remembered. These
// test
suit
e. Only the last value for a given key is remembered. These
// are public static so they can be called from utility functions that are
// not members of the test fixture. Calls to RecordProperty made during
// lifespan of the test (from the moment its constructor starts to the
// moment its destructor finishes) will be output in XML as attributes of
// the <testcase> element. Properties recorded from fixture's
// SetUpTest
Cas
e or TearDownTest
Cas
e are logged as attributes of the
// SetUpTest
Suit
e or TearDownTest
Suit
e are logged as attributes of the
// corresponding <testsuite> element. Calls to RecordProperty made in the
// global context (before or after invocation of RUN_ALL_TESTS and from
// SetUp/TearDown method of Environment objects registered with Google
...
...
@@ -476,7 +482,7 @@ class GTEST_API_ Test {
private:
// Returns true iff the current test has the same fixture class as
// the first test in the current test
cas
e.
// the first test in the current test
suit
e.
static
bool
HasSameFixtureClass
();
// Runs the test after the test fixture has been set up.
...
...
@@ -606,7 +612,7 @@ class GTEST_API_ TestResult {
private:
friend
class
TestInfo
;
friend
class
Test
Cas
e
;
friend
class
Test
Suit
e
;
friend
class
UnitTest
;
friend
class
internal
::
DefaultGlobalTestPartResultReporter
;
friend
class
internal
::
ExecDeathTest
;
...
...
@@ -638,7 +644,7 @@ class GTEST_API_ TestResult {
const
TestProperty
&
test_property
);
// Adds a failure if the key is a reserved attribute of Google Test
// test
cas
e tags. Returns true if the property is valid.
// test
suit
e tags. Returns true if the property is valid.
// FIXME: Validate attribute names are legal and human readable.
static
bool
ValidateTestProperty
(
const
std
::
string
&
xml_element
,
const
TestProperty
&
test_property
);
...
...
@@ -677,7 +683,7 @@ class GTEST_API_ TestResult {
// A TestInfo object stores the following information about a test:
//
// Test
cas
e name
// Test
suit
e name
// Test name
// Whether the test should be run
// A function pointer that creates the test object when invoked
...
...
@@ -692,8 +698,13 @@ class GTEST_API_ TestInfo {
// don't inherit from TestInfo.
~
TestInfo
();
// Returns the test case name.
const
char
*
test_case_name
()
const
{
return
test_case_name_
.
c_str
();
}
// Returns the test suite name.
const
char
*
test_suite_name
()
const
{
return
test_suite_name_
.
c_str
();
}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const
char
*
test_case_name
()
const
{
return
test_suite_name
();
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Returns the test name.
const
char
*
name
()
const
{
return
name_
.
c_str
();
}
...
...
@@ -726,7 +737,7 @@ class GTEST_API_ TestInfo {
// been specified) and its full name matches the user-specified filter.
//
// Google Test allows the user to filter the tests by their full names.
// The full name of a test Bar in test
cas
e Foo is defined as
// The full name of a test Bar in test
suit
e Foo is defined as
// "Foo.Bar". Only the tests that match the filter will run.
//
// A filter is a colon-separated list of glob (not regex) patterns,
...
...
@@ -754,24 +765,19 @@ class GTEST_API_ TestInfo {
friend
class
internal
::
DefaultDeathTestFactory
;
#endif // GTEST_HAS_DEATH_TEST
friend
class
Test
;
friend
class
Test
Cas
e
;
friend
class
Test
Suit
e
;
friend
class
internal
::
UnitTestImpl
;
friend
class
internal
::
StreamingListenerTest
;
friend
TestInfo
*
internal
::
MakeAndRegisterTestInfo
(
const
char
*
test_case_name
,
const
char
*
name
,
const
char
*
type_param
,
const
char
*
value_param
,
internal
::
CodeLocation
code_location
,
internal
::
TypeId
fixture_class_id
,
Test
::
SetUpTestCaseFunc
set_up_tc
,
Test
::
TearDownTestCaseFunc
tear_down_tc
,
const
char
*
test_suite_name
,
const
char
*
name
,
const
char
*
type_param
,
const
char
*
value_param
,
internal
::
CodeLocation
code_location
,
internal
::
TypeId
fixture_class_id
,
internal
::
SetUpTestSuiteFunc
set_up_tc
,
internal
::
TearDownTestSuiteFunc
tear_down_tc
,
internal
::
TestFactoryBase
*
factory
);
// Constructs a TestInfo object. The newly constructed instance assumes
// ownership of the factory object.
TestInfo
(
const
std
::
string
&
test_case_name
,
const
std
::
string
&
name
,
TestInfo
(
const
std
::
string
&
test_suite_name
,
const
std
::
string
&
name
,
const
char
*
a_type_param
,
// NULL if not a type-parameterized test
const
char
*
a_value_param
,
// NULL if not a value-parameterized test
internal
::
CodeLocation
a_code_location
,
...
...
@@ -793,7 +799,7 @@ class GTEST_API_ TestInfo {
}
// These fields are immutable properties of the test.
const
std
::
string
test_
cas
e_name_
;
//
T
est
cas
e name
const
std
::
string
test_
suit
e_name_
;
//
t
est
suit
e name
const
std
::
string
name_
;
// Test name
// Name of the parameter type, or NULL if this is not a typed or a
// type-parameterized test.
...
...
@@ -818,71 +824,71 @@ class GTEST_API_ TestInfo {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
TestInfo
);
};
// A test
cas
e, which consists of a vector of TestInfos.
// A test
suit
e, which consists of a vector of TestInfos.
//
// Test
Cas
e is not copyable.
class
GTEST_API_
Test
Cas
e
{
// Test
Suit
e is not copyable.
class
GTEST_API_
Test
Suit
e
{
public:
// Creates a Test
Cas
e with the given name.
// Creates a Test
Suit
e with the given name.
//
// Test
Cas
e does NOT have a default constructor. Always use this
// constructor to create a Test
Cas
e object.
// Test
Suit
e does NOT have a default constructor. Always use this
// constructor to create a Test
Suit
e object.
//
// Arguments:
//
// name: name of the test
cas
e
// name: name of the test
suit
e
// a_type_param: the name of the test's type parameter, or NULL if
// this is not a type-parameterized test.
// set_up_tc: pointer to the function that sets up the test
cas
e
// tear_down_tc: pointer to the function that tears down the test
cas
e
Test
Cas
e
(
const
char
*
name
,
const
char
*
a_type_param
,
Test
::
SetUpTest
Cas
eFunc
set_up_tc
,
Test
::
TearDownTest
Cas
eFunc
tear_down_tc
);
// set_up_tc: pointer to the function that sets up the test
suit
e
// tear_down_tc: pointer to the function that tears down the test
suit
e
Test
Suit
e
(
const
char
*
name
,
const
char
*
a_type_param
,
internal
::
SetUpTest
Suit
eFunc
set_up_tc
,
internal
::
TearDownTest
Suit
eFunc
tear_down_tc
);
// Destructor of Test
Cas
e.
virtual
~
Test
Cas
e
();
// Destructor of Test
Suit
e.
virtual
~
Test
Suit
e
();
// Gets the name of the Test
Cas
e.
// Gets the name of the Test
Suit
e.
const
char
*
name
()
const
{
return
name_
.
c_str
();
}
// Returns the name of the parameter type, or NULL if this is not a
// type-parameterized test
cas
e.
// type-parameterized test
suit
e.
const
char
*
type_param
()
const
{
if
(
type_param_
.
get
()
!=
nullptr
)
return
type_param_
->
c_str
();
return
nullptr
;
}
// Returns true if any test in this test
cas
e should run.
// Returns true if any test in this test
suit
e should run.
bool
should_run
()
const
{
return
should_run_
;
}
// Gets the number of successful tests in this test
cas
e.
// Gets the number of successful tests in this test
suit
e.
int
successful_test_count
()
const
;
// Gets the number of skipped tests in this test
cas
e.
// Gets the number of skipped tests in this test
suit
e.
int
skipped_test_count
()
const
;
// Gets the number of failed tests in this test
cas
e.
// Gets the number of failed tests in this test
suit
e.
int
failed_test_count
()
const
;
// Gets the number of disabled tests that will be reported in the XML report.
int
reportable_disabled_test_count
()
const
;
// Gets the number of disabled tests in this test
cas
e.
// Gets the number of disabled tests in this test
suit
e.
int
disabled_test_count
()
const
;
// Gets the number of tests to be printed in the XML report.
int
reportable_test_count
()
const
;
// Get the number of tests in this test
cas
e that should run.
// Get the number of tests in this test
suit
e that should run.
int
test_to_run_count
()
const
;
// Gets the number of all tests in this test
cas
e.
// Gets the number of all tests in this test
suit
e.
int
total_test_count
()
const
;
// Returns true iff the test
cas
e passed.
// Returns true iff the test
suit
e passed.
bool
Passed
()
const
{
return
!
Failed
();
}
// Returns true iff the test
cas
e failed.
// Returns true iff the test
suit
e failed.
bool
Failed
()
const
{
return
failed_test_count
()
>
0
;
}
// Returns the elapsed time, in milliseconds.
...
...
@@ -893,17 +899,17 @@ class GTEST_API_ TestCase {
const
TestInfo
*
GetTestInfo
(
int
i
)
const
;
// Returns the TestResult that holds test properties recorded during
// execution of SetUpTest
Cas
e and TearDownTest
Cas
e.
// execution of SetUpTest
Suit
e and TearDownTest
Suit
e.
const
TestResult
&
ad_hoc_test_result
()
const
{
return
ad_hoc_test_result_
;
}
private:
friend
class
Test
;
friend
class
internal
::
UnitTestImpl
;
// Gets the (mutable) vector of TestInfos in this Test
Cas
e.
// Gets the (mutable) vector of TestInfos in this Test
Suit
e.
std
::
vector
<
TestInfo
*>&
test_info_list
()
{
return
test_info_list_
;
}
// Gets the (immutable) vector of TestInfos in this Test
Cas
e.
// Gets the (immutable) vector of TestInfos in this Test
Suit
e.
const
std
::
vector
<
TestInfo
*>&
test_info_list
()
const
{
return
test_info_list_
;
}
...
...
@@ -915,28 +921,36 @@ class GTEST_API_ TestCase {
// Sets the should_run member.
void
set_should_run
(
bool
should
)
{
should_run_
=
should
;
}
// Adds a TestInfo to this test
cas
e. Will delete the TestInfo upon
// destruction of the Test
Cas
e object.
// Adds a TestInfo to this test
suit
e. Will delete the TestInfo upon
// destruction of the Test
Suit
e object.
void
AddTestInfo
(
TestInfo
*
test_info
);
// Clears the results of all tests in this test
cas
e.
// Clears the results of all tests in this test
suit
e.
void
ClearResult
();
// Clears the results of all tests in the given test
cas
e.
static
void
ClearTest
Cas
eResult
(
Test
Cas
e
*
test_
cas
e
)
{
test_
cas
e
->
ClearResult
();
// Clears the results of all tests in the given test
suit
e.
static
void
ClearTest
Suit
eResult
(
Test
Suit
e
*
test_
suit
e
)
{
test_
suit
e
->
ClearResult
();
}
// Runs every test in this Test
Cas
e.
// Runs every test in this Test
Suit
e.
void
Run
();
// Runs SetUpTestCase() for this TestCase. This wrapper is needed
// for catching exceptions thrown from SetUpTestCase().
void
RunSetUpTestCase
()
{
(
*
set_up_tc_
)();
}
// Runs SetUpTestSuite() for this TestSuite. This wrapper is needed
// for catching exceptions thrown from SetUpTestSuite().
void
RunSetUpTestSuite
()
{
if
(
set_up_tc_
!=
nullptr
)
{
(
*
set_up_tc_
)();
}
}
// Runs TearDownTestCase() for this TestCase. This wrapper is
// needed for catching exceptions thrown from TearDownTestCase().
void
RunTearDownTestCase
()
{
(
*
tear_down_tc_
)();
}
// Runs TearDownTestSuite() for this TestSuite. This wrapper is
// needed for catching exceptions thrown from TearDownTestSuite().
void
RunTearDownTestSuite
()
{
if
(
tear_down_tc_
!=
nullptr
)
{
(
*
tear_down_tc_
)();
}
}
// Returns true iff test passed.
static
bool
TestPassed
(
const
TestInfo
*
test_info
)
{
...
...
@@ -974,13 +988,13 @@ class GTEST_API_ TestCase {
return
test_info
->
should_run
();
}
// Shuffles the tests in this test
cas
e.
// Shuffles the tests in this test
suit
e.
void
ShuffleTests
(
internal
::
Random
*
random
);
// Restores the test order to before the first shuffle.
void
UnshuffleTests
();
// Name of the test
cas
e.
// Name of the test
suit
e.
std
::
string
name_
;
// Name of the parameter type, or NULL if this is not a typed or a
// type-parameterized test.
...
...
@@ -992,20 +1006,20 @@ class GTEST_API_ TestCase {
// shuffling and restoring the test order. The i-th element in this
// vector is the index of the i-th test in the shuffled test list.
std
::
vector
<
int
>
test_indices_
;
// Pointer to the function that sets up the test
cas
e.
Test
::
SetUpTest
Cas
eFunc
set_up_tc_
;
// Pointer to the function that tears down the test
cas
e.
Test
::
TearDownTest
Cas
eFunc
tear_down_tc_
;
// True iff any test in this test
cas
e should run.
// Pointer to the function that sets up the test
suit
e.
internal
::
SetUpTest
Suit
eFunc
set_up_tc_
;
// Pointer to the function that tears down the test
suit
e.
internal
::
TearDownTest
Suit
eFunc
tear_down_tc_
;
// True iff any test in this test
suit
e should run.
bool
should_run_
;
// Elapsed time, in milliseconds.
TimeInMillis
elapsed_time_
;
// Holds test properties recorded during execution of SetUpTest
Cas
e and
// TearDownTest
Cas
e.
// Holds test properties recorded during execution of SetUpTest
Suit
e and
// TearDownTest
Suit
e.
TestResult
ad_hoc_test_result_
;
// We disallow copying Test
Cas
es.
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
Test
Cas
e
);
// We disallow copying Test
Suit
es.
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
Test
Suit
e
);
};
// An Environment object is capable of setting up and tearing down an
...
...
@@ -1072,8 +1086,13 @@ class TestEventListener {
// Fired after environment set-up for each iteration of tests ends.
virtual
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
unit_test
)
=
0
;
// Fired before the test case starts.
virtual
void
OnTestCaseStart
(
const
TestCase
&
test_case
)
=
0
;
// Fired before the test suite starts.
virtual
void
OnTestSuiteStart
(
const
TestSuite
&
test_suite
)
{}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
virtual
void
OnTestCaseStart
(
const
TestCase
&
test_case
)
{}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Fired before the test starts.
virtual
void
OnTestStart
(
const
TestInfo
&
test_info
)
=
0
;
...
...
@@ -1086,8 +1105,13 @@ class TestEventListener {
// Fired after the test ends.
virtual
void
OnTestEnd
(
const
TestInfo
&
test_info
)
=
0
;
// Fired after the test case ends.
virtual
void
OnTestCaseEnd
(
const
TestCase
&
test_case
)
=
0
;
// Fired after the test suite ends.
virtual
void
OnTestSuiteEnd
(
const
TestSuite
&
test_suite
)
{}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
virtual
void
OnTestCaseEnd
(
const
TestCase
&
test_case
)
{}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Fired before environment tear-down for each iteration of tests starts.
virtual
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
)
=
0
;
...
...
@@ -1115,11 +1139,20 @@ class EmptyTestEventListener : public TestEventListener {
int
/*iteration*/
)
override
{}
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestCaseStart
(
const
TestCase
&
/*test_case*/
)
override
{}
void
OnTestSuiteStart
(
const
TestSuite
&
/*test_suite*/
)
override
{}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void
OnTestCaseStart
(
const
TestCase
&
tc
/*test_suite*/
)
override
{}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void
OnTestStart
(
const
TestInfo
&
/*test_info*/
)
override
{}
void
OnTestPartResult
(
const
TestPartResult
&
/*test_part_result*/
)
override
{}
void
OnTestEnd
(
const
TestInfo
&
/*test_info*/
)
override
{}
void
OnTestCaseEnd
(
const
TestCase
&
/*test_case*/
)
override
{}
void
OnTestSuiteEnd
(
const
TestSuite
&
/*test_suite*/
)
override
{}
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void
OnTestCaseEnd
(
const
TestCase
&
tc
/*test_suite*/
)
override
{}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestIterationEnd
(
const
UnitTest
&
/*unit_test*/
,
...
...
@@ -1164,7 +1197,7 @@ class GTEST_API_ TestEventListeners {
}
private:
friend
class
Test
Cas
e
;
friend
class
Test
Suit
e
;
friend
class
TestInfo
;
friend
class
internal
::
DefaultGlobalTestPartResultReporter
;
friend
class
internal
::
NoExecDeathTest
;
...
...
@@ -1205,7 +1238,7 @@ class GTEST_API_ TestEventListeners {
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
TestEventListeners
);
};
// A UnitTest consists of a vector of Test
Cas
es.
// A UnitTest consists of a vector of Test
Suit
es.
//
// This is a singleton class. The only instance of UnitTest is
// created when UnitTest::GetInstance() is first called. This
...
...
@@ -1234,10 +1267,14 @@ class GTEST_API_ UnitTest {
// was executed. The UnitTest object owns the string.
const
char
*
original_working_dir
()
const
;
// Returns the Test
Cas
e object for the test that's currently running,
// Returns the Test
Suit
e object for the test that's currently running,
// or NULL if no test is running.
const
TestCase
*
current_test_case
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
);
const
TestSuite
*
current_test_suite
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Legacy API is still available but deprecated
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const
TestCase
*
current_test_case
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
);
#endif
// Returns the TestInfo object for the test that's currently running,
// or NULL if no test is running.
...
...
@@ -1247,25 +1284,33 @@ class GTEST_API_ UnitTest {
// Returns the random seed used at the start of the current test run.
int
random_seed
()
const
;
// Returns the ParameterizedTest
Cas
eRegistry object used to keep track of
// Returns the ParameterizedTest
Suit
eRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
internal
::
ParameterizedTest
Cas
eRegistry
&
parameterized_test_registry
()
internal
::
ParameterizedTest
Suit
eRegistry
&
parameterized_test_registry
()
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Gets the number of successful test
cas
es.
int
successful_test_
cas
e_count
()
const
;
// Gets the number of successful test
suit
es.
int
successful_test_
suit
e_count
()
const
;
// Gets the number of failed test
cas
es.
int
failed_test_
cas
e_count
()
const
;
// Gets the number of failed test
suit
es.
int
failed_test_
suit
e_count
()
const
;
// Gets the number of all test
cas
es.
int
total_test_
cas
e_count
()
const
;
// Gets the number of all test
suit
es.
int
total_test_
suit
e_count
()
const
;
// Gets the number of all test
cas
es that contain at least one test
// Gets the number of all test
suit
es that contain at least one test
// that should run.
int
test_suite_to_run_count
()
const
;
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
int
successful_test_case_count
()
const
;
int
failed_test_case_count
()
const
;
int
total_test_case_count
()
const
;
int
test_case_to_run_count
()
const
;
#endif // EMOVE_LEGACY_TEST_CASEAPI
// Gets the number of successful tests.
int
successful_test_count
()
const
;
...
...
@@ -1298,19 +1343,24 @@ class GTEST_API_ UnitTest {
// Gets the elapsed time, in milliseconds.
TimeInMillis
elapsed_time
()
const
;
// Returns true iff the unit test passed (i.e. all test
cas
es passed).
// Returns true iff the unit test passed (i.e. all test
suit
es passed).
bool
Passed
()
const
;
// Returns true iff the unit test failed (i.e. some test
cas
e failed
// Returns true iff the unit test failed (i.e. some test
suit
e failed
// or something outside of all tests failed).
bool
Failed
()
const
;
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
// Gets the i-th test suite among all the test suites. i can range from 0 to
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
const
TestSuite
*
GetTestSuite
(
int
i
)
const
;
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const
TestCase
*
GetTestCase
(
int
i
)
const
;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Returns the TestResult containing information on test failures and
// properties logged outside of individual test
cas
es.
// properties logged outside of individual test
suit
es.
const
TestResult
&
ad_hoc_test_result
()
const
;
// Returns the list of event listeners that can be used to track events
...
...
@@ -1341,15 +1391,15 @@ class GTEST_API_ UnitTest {
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Adds a TestProperty to the current TestResult object when invoked from
// inside a test, to current Test
Cas
e's ad_hoc_test_result_ when invoked
// from SetUpTest
Cas
e or TearDownTest
Cas
e, or to the global property set
// inside a test, to current Test
Suit
e's ad_hoc_test_result_ when invoked
// from SetUpTest
Suit
e or TearDownTest
Suit
e, or to the global property set
// when invoked elsewhere. If the result already contains a property with
// the same key, the value will be updated.
void
RecordProperty
(
const
std
::
string
&
key
,
const
std
::
string
&
value
);
// Gets the i-th test
cas
e among all the test
cas
es. i can range from 0 to
// total_test_
cas
e_count() - 1. If i is not in that range, returns NULL.
Test
Cas
e
*
GetMutableTest
Cas
e
(
int
i
);
// Gets the i-th test
suit
e among all the test
suit
es. i can range from 0 to
// total_test_
suit
e_count() - 1. If i is not in that range, returns NULL.
Test
Suit
e
*
GetMutableTest
Suit
e
(
int
i
);
// Accessors for the implementation object.
internal
::
UnitTestImpl
*
impl
()
{
return
impl_
;
}
...
...
@@ -1815,7 +1865,7 @@ GTEST_API_ GTEST_ATTRIBUTE_PRINTF_(2, 3) void ColoredPrintf(GTestColor color,
// Foo foo;
// ASSERT_TRUE(foo.DoesBar(GetParam()));
// }
// INSTANTIATE_TEST_
CAS
E_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
// INSTANTIATE_TEST_
SUIT
E_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
template
<
typename
T
>
class
WithParamInterface
{
...
...
@@ -2282,11 +2332,11 @@ bool StaticAssertTypeEq() {
// Defines a test.
//
// The first parameter is the name of the test
cas
e, and the second
// parameter is the name of the test within the test
cas
e.
// The first parameter is the name of the test
suit
e, and the second
// parameter is the name of the test within the test
suit
e.
//
// The convention is to end the test
cas
e name with "Test". For
// example, a test
cas
e for the Foo class can be named FooTest.
// The convention is to end the test
suit
e name with "Test". For
// example, a test
suit
e for the Foo class can be named FooTest.
//
// Test code should appear between braces after an invocation of
// this macro. Example:
...
...
@@ -2305,21 +2355,21 @@ bool StaticAssertTypeEq() {
// code. GetTestTypeId() is guaranteed to always return the same
// value, as it always calls GetTypeId<>() from the Google Test
// framework.
#define GTEST_TEST(test_
cas
e_name, test_name)\
GTEST_TEST_(test_
cas
e_name, test_name, \
::testing::Test,
::testing::internal::GetTestTypeId())
#define GTEST_TEST(test_
suit
e_name, test_name)
\
GTEST_TEST_(test_
suit
e_name, test_name,
::testing::Test,
\
::testing::internal::GetTestTypeId())
// Define this macro to 1 to omit the definition of TEST(), which
// is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_TEST
#
define TEST(test_
cas
e_name, test_name) GTEST_TEST(test_
cas
e_name, test_name)
#define TEST(test_
suit
e_name, test_name) GTEST_TEST(test_
suit
e_name, test_name)
#endif
// Defines a test that uses a test fixture.
//
// The first parameter is the name of the test fixture class, which
// also doubles as the test
cas
e name. The second parameter is the
// name of the test within the test
cas
e.
// also doubles as the test
suit
e name. The second parameter is the
// name of the test within the test
suit
e.
//
// A test fixture class must be declared earlier. The user should put
// the test code between braces after using this macro. Example:
...
...
@@ -2363,11 +2413,11 @@ GTEST_API_ std::string TempDir();
// function pointer that creates a new instance of the Test object. It
// handles ownership to the caller. The signature of the callable is
// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
// tests registered with the same `test_
cas
e_name` must return the same
// tests registered with the same `test_
suit
e_name` must return the same
// fixture type. This is checked at runtime.
//
// The framework will infer the fixture class from the factory and will call
// the `SetUpTest
Cas
e` and `TearDownTest
Cas
e` for it.
// the `SetUpTest
Suit
e` and `TearDownTest
Suit
e` for it.
//
// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
// undefined.
...
...
@@ -2377,8 +2427,8 @@ GTEST_API_ std::string TempDir();
// class MyFixture : public ::testing::Test {
// public:
// // All of these optional, just like in regular macro usage.
// static void SetUpTest
Cas
e() { ... }
// static void TearDownTest
Cas
e() { ... }
// static void SetUpTest
Suit
e() { ... }
// static void TearDownTest
Suit
e() { ... }
// void SetUp() override { ... }
// void TearDown() override { ... }
// };
...
...
@@ -2411,18 +2461,11 @@ GTEST_API_ std::string TempDir();
// }
//
template
<
int
&
...
ExplicitParameterBarrier
,
typename
Factory
>
TestInfo
*
RegisterTest
(
const
char
*
test_
cas
e_name
,
const
char
*
test_name
,
TestInfo
*
RegisterTest
(
const
char
*
test_
suit
e_name
,
const
char
*
test_name
,
const
char
*
type_param
,
const
char
*
value_param
,
const
char
*
file
,
int
line
,
Factory
factory
)
{
using
TestT
=
typename
std
::
remove_pointer
<
decltype
(
factory
())
>::
type
;
// Helper class to get SetUpTestCase and TearDownTestCase when they are in a
// protected scope.
struct
Helper
:
TestT
{
using
TestT
::
SetUpTestCase
;
using
TestT
::
TearDownTestCase
;
};
class
FactoryImpl
:
public
internal
::
TestFactoryBase
{
public:
explicit
FactoryImpl
(
Factory
f
)
:
factory_
(
std
::
move
(
f
))
{}
...
...
@@ -2433,9 +2476,10 @@ TestInfo* RegisterTest(const char* test_case_name, const char* test_name,
};
return
internal
::
MakeAndRegisterTestInfo
(
test_
cas
e_name
,
test_name
,
type_param
,
value_param
,
test_
suit
e_name
,
test_name
,
type_param
,
value_param
,
internal
::
CodeLocation
(
file
,
line
),
internal
::
GetTypeId
<
TestT
>
(),
&
Helper
::
SetUpTestCase
,
&
Helper
::
TearDownTestCase
,
internal
::
SuiteApiResolver
<
TestT
>::
GetSetUpCaseOrSuite
(),
internal
::
SuiteApiResolver
<
TestT
>::
GetTearDownCaseOrSuite
(),
new
FactoryImpl
{
std
::
move
(
factory
)});
}
...
...
googletest/include/gtest/gtest_pred_impl.h
View file @
58e62f7a
...
...
@@ -27,11 +27,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on 01/02/201
8
by command
// This file is AUTOMATICALLY GENERATED on 01/02/201
9
by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
// GOOGLETEST_CM0001 DO NOT DELETE
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
...
...
@@ -67,6 +66,8 @@ namespace testing {
// We also define the EXPECT_* variations.
//
// For now we only support predicates whose arity is at most 5.
// Please email googletestframework@googlegroups.com if you need
// support for higher arities.
// GTEST_ASSERT_ is the basic statement to which all of the assertions
// in this file reduce. Don't use this in your code.
...
...
@@ -89,9 +90,10 @@ AssertionResult AssertPred1Helper(const char* pred_text,
const
T1
&
v1
)
{
if
(
pred
(
v1
))
return
AssertionSuccess
();
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
;
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v1
);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
...
...
@@ -133,11 +135,12 @@ AssertionResult AssertPred2Helper(const char* pred_text,
const
T2
&
v2
)
{
if
(
pred
(
v1
,
v2
))
return
AssertionSuccess
();
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
;
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v1
)
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v2
);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
...
...
@@ -184,13 +187,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
const
T3
&
v3
)
{
if
(
pred
(
v1
,
v2
,
v3
))
return
AssertionSuccess
();
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e
1
<<
", "
<<
e2
<<
",
"
<<
e3
<<
") evaluates to false, where
"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
;
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e
2
<<
", "
<<
e3
<<
") evaluates to false, where
"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v1
)
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v2
)
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v3
)
;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
...
...
@@ -242,15 +245,14 @@ AssertionResult AssertPred4Helper(const char* pred_text,
const
T4
&
v4
)
{
if
(
pred
(
v1
,
v2
,
v3
,
v4
))
return
AssertionSuccess
();
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
v4
;
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v1
)
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v2
)
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v3
)
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v4
);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
...
...
@@ -307,17 +309,15 @@ AssertionResult AssertPred5Helper(const char* pred_text,
const
T5
&
v5
)
{
if
(
pred
(
v1
,
v2
,
v3
,
v4
,
v5
))
return
AssertionSuccess
();
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
", "
<<
e5
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
v4
<<
"
\n
"
<<
e5
<<
" evaluates to "
<<
v5
;
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
", "
<<
e5
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v1
)
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v2
)
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v3
)
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v4
)
<<
"
\n
"
<<
e5
<<
" evaluates to "
<<
::
testing
::
PrintToString
(
v5
);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
...
...
googletest/include/gtest/internal/gtest-internal.h
View file @
58e62f7a
...
...
@@ -91,7 +91,7 @@ class Message; // Represents a failure message.
class
Test
;
// Represents a test.
class
TestInfo
;
// Information about a test.
class
TestPartResult
;
// Result of a test part.
class
UnitTest
;
// A collection of test
cas
es.
class
UnitTest
;
// A collection of test
suit
es.
template
<
typename
T
>
::
std
::
string
PrintToString
(
const
T
&
value
);
...
...
@@ -412,7 +412,7 @@ typedef FloatingPoint<float> Float;
typedef
FloatingPoint
<
double
>
Double
;
// In order to catch the mistake of putting tests that use different
// test fixture classes in the same test
cas
e, we need to assign
// test fixture classes in the same test
suit
e, we need to assign
// unique IDs to fixture classes and compare them. The TypeId type is
// used to hold such IDs. The user should treat TypeId as an opaque
// type: the only operation allowed on TypeId values is to compare
...
...
@@ -488,9 +488,9 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
#endif // GTEST_OS_WINDOWS
// Types of SetUpTest
Cas
e() and TearDownTest
Cas
e() functions.
typedef
void
(
*
SetUpTest
Cas
eFunc
)();
typedef
void
(
*
TearDownTest
Cas
eFunc
)();
// Types of SetUpTest
Suit
e() and TearDownTest
Suit
e() functions.
using
SetUpTest
Suit
eFunc
=
void
(
*
)();
using
TearDownTest
Suit
eFunc
=
void
(
*
)();
struct
CodeLocation
{
CodeLocation
(
const
std
::
string
&
a_file
,
int
a_line
)
...
...
@@ -500,12 +500,60 @@ struct CodeLocation {
int
line
;
};
// Helper to identify which setup function for TestCase / TestSuite to call.
// Only one function is allowed, either TestCase or TestSute but not both.
// Utility functions to help SuiteApiResolver
using
SetUpTearDownSuiteFuncType
=
void
(
*
)();
inline
SetUpTearDownSuiteFuncType
GetNotDefaultOrNull
(
SetUpTearDownSuiteFuncType
a
,
SetUpTearDownSuiteFuncType
def
)
{
return
a
==
def
?
nullptr
:
a
;
}
template
<
typename
T
>
// Note that SuiteApiResolver inherits from T because
// SetUpTestSuite()/TearDownTestSuite() could be protected. Ths way
// SuiteApiResolver can access them.
struct
SuiteApiResolver
:
T
{
// testing::Test is only forward declared at this point. So we make it a
// dependend class for the compiler to be OK with it.
using
Test
=
typename
std
::
conditional
<
sizeof
(
T
)
!=
0
,
::
testing
::
Test
,
void
>::
type
;
static
SetUpTearDownSuiteFuncType
GetSetUpCaseOrSuite
()
{
SetUpTearDownSuiteFuncType
test_case_fp
=
GetNotDefaultOrNull
(
&
T
::
SetUpTestCase
,
&
Test
::
SetUpTestCase
);
SetUpTearDownSuiteFuncType
test_suite_fp
=
GetNotDefaultOrNull
(
&
T
::
SetUpTestSuite
,
&
Test
::
SetUpTestSuite
);
GTEST_CHECK_
(
!
test_case_fp
||
!
test_suite_fp
)
<<
"Test can not provide both SetUpTestSuite and SetUpTestCase, please "
"make sure there is only one present "
;
return
test_case_fp
!=
nullptr
?
test_case_fp
:
test_suite_fp
;
}
static
SetUpTearDownSuiteFuncType
GetTearDownCaseOrSuite
()
{
SetUpTearDownSuiteFuncType
test_case_fp
=
GetNotDefaultOrNull
(
&
T
::
TearDownTestCase
,
&
Test
::
TearDownTestCase
);
SetUpTearDownSuiteFuncType
test_suite_fp
=
GetNotDefaultOrNull
(
&
T
::
TearDownTestSuite
,
&
Test
::
TearDownTestSuite
);
GTEST_CHECK_
(
!
test_case_fp
||
!
test_suite_fp
)
<<
"Test can not provide both TearDownTestSuite and TearDownTestCase,"
" please make sure there is only one present "
;
return
test_case_fp
!=
nullptr
?
test_case_fp
:
test_suite_fp
;
}
};
// Creates a new TestInfo object and registers it with Google Test;
// returns the created object.
//
// Arguments:
//
// test_
cas
e_name: name of the test
cas
e
// test_
suit
e_name: name of the test
suit
e
// name: name of the test
// type_param the name of the test's type parameter, or NULL if
// this is not a typed or a type-parameterized test.
...
...
@@ -513,21 +561,16 @@ struct CodeLocation {
// or NULL if this is not a type-parameterized test.
// code_location: code location where the test is defined
// fixture_class_id: ID of the test fixture class
// set_up_tc: pointer to the function that sets up the test
cas
e
// tear_down_tc: pointer to the function that tears down the test
cas
e
// set_up_tc: pointer to the function that sets up the test
suit
e
// tear_down_tc: pointer to the function that tears down the test
suit
e
// factory: pointer to the factory that creates a test object.
// The newly created TestInfo instance will assume
// ownership of the factory object.
GTEST_API_
TestInfo
*
MakeAndRegisterTestInfo
(
const
char
*
test_case_name
,
const
char
*
name
,
const
char
*
type_param
,
const
char
*
value_param
,
CodeLocation
code_location
,
TypeId
fixture_class_id
,
SetUpTestCaseFunc
set_up_tc
,
TearDownTestCaseFunc
tear_down_tc
,
TestFactoryBase
*
factory
);
const
char
*
test_suite_name
,
const
char
*
name
,
const
char
*
type_param
,
const
char
*
value_param
,
CodeLocation
code_location
,
TypeId
fixture_class_id
,
SetUpTestSuiteFunc
set_up_tc
,
TearDownTestSuiteFunc
tear_down_tc
,
TestFactoryBase
*
factory
);
// If *pstr starts with the given prefix, modifies *pstr to be right
// past the prefix and returns true; otherwise leaves *pstr unchanged
...
...
@@ -539,19 +582,20 @@ GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
GTEST_DISABLE_MSC_WARNINGS_PUSH_
(
4251
\
/* class A needs to have dll-interface to be used by clients of class B */
)
// State of the definition of a type-parameterized test
cas
e.
class
GTEST_API_
TypedTest
Cas
ePState
{
// State of the definition of a type-parameterized test
suit
e.
class
GTEST_API_
TypedTest
Suit
ePState
{
public:
TypedTest
Cas
ePState
()
:
registered_
(
false
)
{}
TypedTest
Suit
ePState
()
:
registered_
(
false
)
{}
// Adds the given test name to defined_test_names_ and return true
// if the test
cas
e hasn't been registered; otherwise aborts the
// if the test
suit
e hasn't been registered; otherwise aborts the
// program.
bool
AddTestName
(
const
char
*
file
,
int
line
,
const
char
*
case_name
,
const
char
*
test_name
)
{
if
(
registered_
)
{
fprintf
(
stderr
,
"%s Test %s must be defined before "
"REGISTER_TYPED_TEST_CASE_P(%s, ...).
\n
"
,
fprintf
(
stderr
,
"%s Test %s must be defined before "
"REGISTER_TYPED_TEST_SUITE_P(%s, ...).
\n
"
,
FormatFileLocation
(
file
,
line
).
c_str
(),
test_name
,
case_name
);
fflush
(
stderr
);
posix
::
Abort
();
...
...
@@ -584,6 +628,11 @@ class GTEST_API_ TypedTestCasePState {
RegisteredTestsMap
registered_tests_
;
};
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
using
TypedTestCasePState
=
TypedTestSuitePState
;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_DISABLE_MSC_WARNINGS_POP_
()
// 4251
// Skips to the first non-space char after the first comma in 'str';
...
...
@@ -651,7 +700,7 @@ template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
class
TypeParameterizedTest
{
public:
// 'index' is the index of the test in the type list 'Types'
// specified in INSTANTIATE_TYPED_TEST_
CAS
E_P(Prefix, Test
Cas
e,
// specified in INSTANTIATE_TYPED_TEST_
SUIT
E_P(Prefix, Test
Suit
e,
// Types). Valid values for 'index' are [0, N - 1] where N is the
// length of Types.
static
bool
Register
(
const
char
*
prefix
,
const
CodeLocation
&
code_location
,
...
...
@@ -671,8 +720,10 @@ class TypeParameterizedTest {
StripTrailingSpaces
(
GetPrefixUntilComma
(
test_names
)).
c_str
(),
GetTypeName
<
Type
>
().
c_str
(),
nullptr
,
// No value parameter.
code_location
,
GetTypeId
<
FixtureClass
>
(),
TestClass
::
SetUpTestCase
,
TestClass
::
TearDownTestCase
,
new
TestFactoryImpl
<
TestClass
>
);
code_location
,
GetTypeId
<
FixtureClass
>
(),
SuiteApiResolver
<
TestClass
>::
GetSetUpCaseOrSuite
(),
SuiteApiResolver
<
TestClass
>::
GetTearDownCaseOrSuite
(),
new
TestFactoryImpl
<
TestClass
>
);
// Next, recurses (at compile time) with the tail of the type list.
return
TypeParameterizedTest
<
Fixture
,
TestSel
,
...
...
@@ -698,15 +749,15 @@ class TypeParameterizedTest<Fixture, TestSel, Types0> {
}
};
// TypeParameterizedTest
Cas
e<Fixture, Tests, Types>::Register()
// TypeParameterizedTest
Suit
e<Fixture, Tests, Types>::Register()
// registers *all combinations* of 'Tests' and 'Types' with Google
// Test. The return value is insignificant - we just need to return
// something such that we can call this function in a namespace scope.
template
<
GTEST_TEMPLATE_
Fixture
,
typename
Tests
,
typename
Types
>
class
TypeParameterizedTest
Cas
e
{
class
TypeParameterizedTest
Suit
e
{
public:
static
bool
Register
(
const
char
*
prefix
,
CodeLocation
code_location
,
const
TypedTest
Cas
ePState
*
state
,
const
char
*
case_name
,
const
TypedTest
Suit
ePState
*
state
,
const
char
*
case_name
,
const
char
*
test_names
,
const
std
::
vector
<
std
::
string
>&
type_names
=
GenerateNames
<
DefaultNameGenerator
,
Types
>
())
{
...
...
@@ -729,7 +780,7 @@ class TypeParameterizedTestCase {
prefix
,
test_location
,
case_name
,
test_names
,
0
,
type_names
);
// Next, recurses (at compile time) with the tail of the test list.
return
TypeParameterizedTest
Cas
e
<
Fixture
,
typename
Tests
::
Tail
,
return
TypeParameterizedTest
Suit
e
<
Fixture
,
typename
Tests
::
Tail
,
Types
>::
Register
(
prefix
,
code_location
,
state
,
case_name
,
SkipComma
(
test_names
),
...
...
@@ -739,10 +790,10 @@ class TypeParameterizedTestCase {
// The base case for the compile time recursion.
template
<
GTEST_TEMPLATE_
Fixture
,
typename
Types
>
class
TypeParameterizedTest
Cas
e
<
Fixture
,
Templates0
,
Types
>
{
class
TypeParameterizedTest
Suit
e
<
Fixture
,
Templates0
,
Types
>
{
public:
static
bool
Register
(
const
char
*
/*prefix*/
,
const
CodeLocation
&
,
const
TypedTest
Cas
ePState
*
/*state*/
,
const
TypedTest
Suit
ePState
*
/*state*/
,
const
char
*
/*case_name*/
,
const
char
*
/*test_names*/
,
const
std
::
vector
<
std
::
string
>&
=
std
::
vector
<
std
::
string
>
()
/*type_names*/
)
{
...
...
@@ -1376,32 +1427,35 @@ class FlatTuple
" Actual: it does.")
// Expands to the name of the class that implements the given test.
#define GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name) \
test_
cas
e_name##_##test_name##_Test
#define GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name) \
test_
suit
e_name##_##test_name##_Test
// Helper macro for defining tests.
#define GTEST_TEST_(test_
cas
e_name, test_name, parent_class, parent_id)
\
class GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)
\
#define GTEST_TEST_(test_
suit
e_name, test_name, parent_class, parent_id) \
class GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name) \
: public parent_class { \
public: \
GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)() {}
\
GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)() {} \
\
private: \
virtual void TestBody(); \
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_
cas
e_name,
\
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_
suit
e_name, \
test_name)); \
}; \
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_
cas
e_name,
\
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_
suit
e_name, \
test_name)::test_info_ = \
::testing::internal::MakeAndRegisterTestInfo( \
#test_
cas
e_name, #test_name, nullptr, nullptr,
\
#test_
suit
e_name, #test_name, nullptr, nullptr, \
::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
parent_class::SetUpTestCase, parent_class::TearDownTestCase, \
::testing::internal::SuiteApiResolver< \
parent_class>::GetSetUpCaseOrSuite(), \
::testing::internal::SuiteApiResolver< \
parent_class>::GetTearDownCaseOrSuite(), \
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
test_
cas
e_name, test_name)>);
\
void GTEST_TEST_CLASS_NAME_(test_
cas
e_name, test_name)::TestBody()
test_
suit
e_name, test_name)>); \
void GTEST_TEST_CLASS_NAME_(test_
suit
e_name, test_name)::TestBody()
// Internal Macro to mark an API deprecated, for googletest usage only
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
...
...
googletest/include/gtest/internal/gtest-param-util.h
View file @
58e62f7a
...
...
@@ -75,10 +75,10 @@ namespace internal {
// Utility Functions
// Outputs a message explaining invalid registration of different
// fixture class for the same test
cas
e. This may happen when
// fixture class for the same test
suit
e. This may happen when
// TEST_P macro is used to define two tests with the same name
// but in different namespaces.
GTEST_API_
void
ReportInvalidTest
Cas
eType
(
const
char
*
test_
cas
e_name
,
GTEST_API_
void
ReportInvalidTest
Suit
eType
(
const
char
*
test_
suit
e_name
,
CodeLocation
code_location
);
template
<
typename
>
class
ParamGeneratorInterface
;
...
...
@@ -379,7 +379,7 @@ std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// Parameterized test name overload helpers, which help the
// INSTANTIATE_TEST_
CAS
E_P macro choose between the default parameterized
// INSTANTIATE_TEST_
SUIT
E_P macro choose between the default parameterized
// test name generator and user param name generator.
template
<
class
ParamType
,
class
ParamNameGenFunctor
>
ParamNameGenFunctor
GetParamNameGen
(
ParamNameGenFunctor
func
)
{
...
...
@@ -434,19 +434,19 @@ class TestMetaFactoryBase {
// TestMetaFactory creates test factories for passing into
// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
// ownership of test factory pointer, same factory object cannot be passed
// into that method twice. But ParameterizedTest
Cas
eInfo is going to call
// into that method twice. But ParameterizedTest
Suit
eInfo is going to call
// it for each Test/Parameter value combination. Thus it needs meta factory
// creator class.
template
<
class
Test
Cas
e
>
template
<
class
Test
Suit
e
>
class
TestMetaFactory
:
public
TestMetaFactoryBase
<
typename
Test
Cas
e
::
ParamType
>
{
:
public
TestMetaFactoryBase
<
typename
Test
Suit
e
::
ParamType
>
{
public:
typedef
typename
TestCase
::
ParamType
ParamType
;
using
ParamType
=
typename
TestSuite
::
ParamType
;
TestMetaFactory
()
{}
TestFactoryBase
*
CreateTestFactory
(
ParamType
parameter
)
override
{
return
new
ParameterizedTestFactory
<
Test
Cas
e
>
(
parameter
);
return
new
ParameterizedTestFactory
<
Test
Suit
e
>
(
parameter
);
}
private:
...
...
@@ -455,78 +455,77 @@ class TestMetaFactory
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// ParameterizedTest
Cas
eInfoBase is a generic interface
// to ParameterizedTest
Cas
eInfo classes. ParameterizedTest
Cas
eInfoBase
// ParameterizedTest
Suit
eInfoBase is a generic interface
// to ParameterizedTest
Suit
eInfo classes. ParameterizedTest
Suit
eInfoBase
// accumulates test information provided by TEST_P macro invocations
// and generators provided by INSTANTIATE_TEST_
CAS
E_P macro invocations
// and generators provided by INSTANTIATE_TEST_
SUIT
E_P macro invocations
// and uses that information to register all resulting test instances
// in RegisterTests method. The ParameterizeTest
Cas
eRegistry class holds
// a collection of pointers to the ParameterizedTest
Cas
eInfo objects
// in RegisterTests method. The ParameterizeTest
Suit
eRegistry class holds
// a collection of pointers to the ParameterizedTest
Suit
eInfo objects
// and calls RegisterTests() on each of them when asked.
class
ParameterizedTest
Cas
eInfoBase
{
class
ParameterizedTest
Suit
eInfoBase
{
public:
virtual
~
ParameterizedTest
Cas
eInfoBase
()
{}
virtual
~
ParameterizedTest
Suit
eInfoBase
()
{}
// Base part of test
cas
e name for display purposes.
virtual
const
std
::
string
&
GetTest
Cas
eName
()
const
=
0
;
// Base part of test
suit
e name for display purposes.
virtual
const
std
::
string
&
GetTest
Suit
eName
()
const
=
0
;
// Test case id to verify identity.
virtual
TypeId
GetTest
Cas
eTypeId
()
const
=
0
;
virtual
TypeId
GetTest
Suit
eTypeId
()
const
=
0
;
// UnitTest class invokes this method to register tests in this
// test
cas
e right before running them in RUN_ALL_TESTS macro.
// test
suit
e right before running them in RUN_ALL_TESTS macro.
// This method should not be called more then once on any single
// instance of a ParameterizedTest
Cas
eInfoBase derived class.
// instance of a ParameterizedTest
Suit
eInfoBase derived class.
virtual
void
RegisterTests
()
=
0
;
protected:
ParameterizedTest
Cas
eInfoBase
()
{}
ParameterizedTest
Suit
eInfoBase
()
{}
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ParameterizedTest
Cas
eInfoBase
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ParameterizedTest
Suit
eInfoBase
);
};
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// ParameterizedTest
Cas
eInfo accumulates tests obtained from TEST_P
// macro invocations for a particular test
cas
e and generators
// obtained from INSTANTIATE_TEST_
CAS
E_P macro invocations for that
// test
cas
e. It registers tests with all values generated by all
// ParameterizedTest
Suit
eInfo accumulates tests obtained from TEST_P
// macro invocations for a particular test
suit
e and generators
// obtained from INSTANTIATE_TEST_
SUIT
E_P macro invocations for that
// test
suit
e. It registers tests with all values generated by all
// generators when asked.
template
<
class
Test
Cas
e
>
class
ParameterizedTest
Cas
eInfo
:
public
ParameterizedTest
Cas
eInfoBase
{
template
<
class
Test
Suit
e
>
class
ParameterizedTest
Suit
eInfo
:
public
ParameterizedTest
Suit
eInfoBase
{
public:
// ParamType and GeneratorCreationFunc are private types but are required
// for declarations of public methods AddTestPattern() and
// AddTest
Cas
eInstantiation().
typedef
typename
TestCase
::
ParamType
ParamType
;
// AddTest
Suit
eInstantiation().
using
ParamType
=
typename
TestSuite
::
ParamType
;
// A function that returns an instance of appropriate generator type.
typedef
ParamGenerator
<
ParamType
>
(
GeneratorCreationFunc
)();
typedef
typename
ParamNameGenFunc
<
ParamType
>::
Type
ParamNameGeneratorFunc
;
explicit
ParameterizedTest
Cas
eInfo
(
const
char
*
name
,
CodeLocation
code_location
)
:
test_
cas
e_name_
(
name
),
code_location_
(
code_location
)
{}
explicit
ParameterizedTest
Suit
eInfo
(
const
char
*
name
,
CodeLocation
code_location
)
:
test_
suit
e_name_
(
name
),
code_location_
(
code_location
)
{}
// Test case base name for display purposes.
const
std
::
string
&
GetTest
Cas
eName
()
const
override
{
return
test_
cas
e_name_
;
const
std
::
string
&
GetTest
Suit
eName
()
const
override
{
return
test_
suit
e_name_
;
}
// Test case id to verify identity.
TypeId
GetTest
Cas
eTypeId
()
const
override
{
return
GetTypeId
<
Test
Cas
e
>
();
}
TypeId
GetTest
Suit
eTypeId
()
const
override
{
return
GetTypeId
<
Test
Suit
e
>
();
}
// TEST_P macro uses AddTestPattern() to record information
// about a single test in a LocalTestInfo structure.
// test_
cas
e_name is the base name of the test
cas
e (without invocation
// test_
suit
e_name is the base name of the test
suit
e (without invocation
// prefix). test_base_name is the name of an individual test without
// parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
// test case base name and DoBar is test base name.
void
AddTestPattern
(
const
char
*
test_case_name
,
const
char
*
test_base_name
,
// test suite base name and DoBar is test base name.
void
AddTestPattern
(
const
char
*
test_suite_name
,
const
char
*
test_base_name
,
TestMetaFactoryBase
<
ParamType
>*
meta_factory
)
{
tests_
.
push_back
(
std
::
shared_ptr
<
TestInfo
>
(
new
TestInfo
(
test_
cas
e_name
,
test_base_name
,
meta_factory
)));
new
TestInfo
(
test_
suit
e_name
,
test_base_name
,
meta_factory
)));
}
// INSTANTIATE_TEST_
CAS
E_P macro uses AddGenerator() to record information
// INSTANTIATE_TEST_
SUIT
E_P macro uses AddGenerator() to record information
// about a generator.
int
AddTest
Cas
eInstantiation
(
const
std
::
string
&
instantiation_name
,
int
AddTest
Suit
eInstantiation
(
const
std
::
string
&
instantiation_name
,
GeneratorCreationFunc
*
func
,
ParamNameGeneratorFunc
*
name_func
,
const
char
*
file
,
int
line
)
{
...
...
@@ -534,10 +533,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
InstantiationInfo
(
instantiation_name
,
func
,
name_func
,
file
,
line
));
return
0
;
// Return value used only to run this method in namespace scope.
}
// UnitTest class invokes this method to register tests in this test
cas
e
// test
cas
es right before running tests in RUN_ALL_TESTS macro.
// UnitTest class invokes this method to register tests in this test
suit
e
// test
suit
es right before running tests in RUN_ALL_TESTS macro.
// This method should not be called more then once on any single
// instance of a ParameterizedTest
Cas
eInfoBase derived class.
// instance of a ParameterizedTest
Suit
eInfoBase derived class.
// UnitTest has a guard to prevent from calling this method more then once.
void
RegisterTests
()
override
{
for
(
typename
TestInfoContainer
::
iterator
test_it
=
tests_
.
begin
();
...
...
@@ -552,10 +551,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
const
char
*
file
=
gen_it
->
file
;
int
line
=
gen_it
->
line
;
std
::
string
test_
cas
e_name
;
std
::
string
test_
suit
e_name
;
if
(
!
instantiation_name
.
empty
()
)
test_
cas
e_name
=
instantiation_name
+
"/"
;
test_
cas
e_name
+=
test_info
->
test_
cas
e_base_name
;
test_
suit
e_name
=
instantiation_name
+
"/"
;
test_
suit
e_name
+=
test_info
->
test_
suit
e_base_name
;
size_t
i
=
0
;
std
::
set
<
std
::
string
>
test_param_names
;
...
...
@@ -580,11 +579,12 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
test_name_stream
<<
test_info
->
test_base_name
<<
"/"
<<
param_name
;
MakeAndRegisterTestInfo
(
test_
cas
e_name
.
c_str
(),
test_name_stream
.
GetString
().
c_str
(),
test_
suit
e_name
.
c_str
(),
test_name_stream
.
GetString
().
c_str
(),
nullptr
,
// No type parameter.
PrintToString
(
*
param_it
).
c_str
(),
code_location_
,
GetTestCaseTypeId
(),
TestCase
::
SetUpTestCase
,
TestCase
::
TearDownTestCase
,
GetTestSuiteTypeId
(),
SuiteApiResolver
<
TestSuite
>::
GetSetUpCaseOrSuite
(),
SuiteApiResolver
<
TestSuite
>::
GetTearDownCaseOrSuite
(),
test_info
->
test_meta_factory
->
CreateTestFactory
(
*
param_it
));
}
// for param_it
}
// for gen_it
...
...
@@ -595,19 +595,18 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
// LocalTestInfo structure keeps information about a single test registered
// with TEST_P macro.
struct
TestInfo
{
TestInfo
(
const
char
*
a_test_case_base_name
,
const
char
*
a_test_base_name
,
TestMetaFactoryBase
<
ParamType
>*
a_test_meta_factory
)
:
test_case_base_name
(
a_test_case_base_name
),
TestInfo
(
const
char
*
a_test_suite_base_name
,
const
char
*
a_test_base_name
,
TestMetaFactoryBase
<
ParamType
>*
a_test_meta_factory
)
:
test_suite_base_name
(
a_test_suite_base_name
),
test_base_name
(
a_test_base_name
),
test_meta_factory
(
a_test_meta_factory
)
{}
const
std
::
string
test_
cas
e_base_name
;
const
std
::
string
test_
suit
e_base_name
;
const
std
::
string
test_base_name
;
const
std
::
unique_ptr
<
TestMetaFactoryBase
<
ParamType
>
>
test_meta_factory
;
};
using
TestInfoContainer
=
::
std
::
vector
<
std
::
shared_ptr
<
TestInfo
>
>
;
// Records data received from INSTANTIATE_TEST_
CAS
E_P macros:
// Records data received from INSTANTIATE_TEST_
SUIT
E_P macros:
// <Instantiation name, Sequence generator creation function,
// Name generator function, Source file, Source line>
struct
InstantiationInfo
{
...
...
@@ -644,76 +643,87 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
return
true
;
}
const
std
::
string
test_
cas
e_name_
;
const
std
::
string
test_
suit
e_name_
;
CodeLocation
code_location_
;
TestInfoContainer
tests_
;
InstantiationContainer
instantiations_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ParameterizedTestCaseInfo
);
};
// class ParameterizedTestCaseInfo
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ParameterizedTestSuiteInfo
);
};
// class ParameterizedTestSuiteInfo
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
template
<
class
TestCase
>
using
ParameterizedTestCaseInfo
=
ParameterizedTestSuiteInfo
<
TestCase
>
;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// ParameterizedTest
Cas
eRegistry contains a map of
ParameterizedTestCaseInfoBase
// classes accessed by test
cas
e names. TEST_P
and INSTANTIATE_TEST_CASE_P
// macros use it to locate their corresponding
ParameterizedTestCaseInfo
// descriptors.
class
ParameterizedTest
Cas
eRegistry
{
// ParameterizedTest
Suit
eRegistry contains a map of
//
ParameterizedTestSuiteInfoBase
classes accessed by test
suit
e names. TEST_P
//
and INSTANTIATE_TEST_SUITE_P
macros use it to locate their corresponding
//
ParameterizedTestSuiteInfo
descriptors.
class
ParameterizedTest
Suit
eRegistry
{
public:
ParameterizedTestCaseRegistry
()
{}
~
ParameterizedTestCaseRegistry
()
{
for
(
TestCaseInfoContainer
::
iterator
it
=
test_case_infos_
.
begin
();
it
!=
test_case_infos_
.
end
();
++
it
)
{
delete
*
it
;
ParameterizedTestSuiteRegistry
()
{}
~
ParameterizedTestSuiteRegistry
()
{
for
(
auto
&
test_suite_info
:
test_suite_infos_
)
{
delete
test_suite_info
;
}
}
// Looks up or creates and returns a structure containing information about
// tests and instantiations of a particular test case.
template
<
class
TestCase
>
ParameterizedTestCaseInfo
<
TestCase
>*
GetTestCasePatternHolder
(
const
char
*
test_case_name
,
CodeLocation
code_location
)
{
ParameterizedTestCaseInfo
<
TestCase
>*
typed_test_info
=
nullptr
;
for
(
TestCaseInfoContainer
::
iterator
it
=
test_case_infos_
.
begin
();
it
!=
test_case_infos_
.
end
();
++
it
)
{
if
((
*
it
)
->
GetTestCaseName
()
==
test_case_name
)
{
if
((
*
it
)
->
GetTestCaseTypeId
()
!=
GetTypeId
<
TestCase
>
())
{
// tests and instantiations of a particular test suite.
template
<
class
TestSuite
>
ParameterizedTestSuiteInfo
<
TestSuite
>*
GetTestSuitePatternHolder
(
const
char
*
test_suite_name
,
CodeLocation
code_location
)
{
ParameterizedTestSuiteInfo
<
TestSuite
>*
typed_test_info
=
nullptr
;
for
(
auto
&
test_suite_info
:
test_suite_infos_
)
{
if
(
test_suite_info
->
GetTestSuiteName
()
==
test_suite_name
)
{
if
(
test_suite_info
->
GetTestSuiteTypeId
()
!=
GetTypeId
<
TestSuite
>
())
{
// Complain about incorrect usage of Google Test facilities
// and terminate the program since we cannot guaranty correct
// test
cas
e setup and tear-down in this case.
ReportInvalidTest
Cas
eType
(
test_
cas
e_name
,
code_location
);
// test
suit
e setup and tear-down in this case.
ReportInvalidTest
Suit
eType
(
test_
suit
e_name
,
code_location
);
posix
::
Abort
();
}
else
{
// At this point we are sure that the object we found is of the same
// type we are looking for, so we downcast it to that type
// without further checks.
typed_test_info
=
CheckedDowncastToActualType
<
ParameterizedTest
Cas
eInfo
<
Test
Cas
e
>
>
(
*
it
);
ParameterizedTest
Suit
eInfo
<
Test
Suit
e
>
>
(
test_suite_info
);
}
break
;
}
}
if
(
typed_test_info
==
nullptr
)
{
typed_test_info
=
new
ParameterizedTest
Cas
eInfo
<
Test
Cas
e
>
(
test_
cas
e_name
,
code_location
);
test_
cas
e_infos_
.
push_back
(
typed_test_info
);
typed_test_info
=
new
ParameterizedTest
Suit
eInfo
<
Test
Suit
e
>
(
test_
suit
e_name
,
code_location
);
test_
suit
e_infos_
.
push_back
(
typed_test_info
);
}
return
typed_test_info
;
}
void
RegisterTests
()
{
for
(
TestCaseInfoContainer
::
iterator
it
=
test_case_infos_
.
begin
();
it
!=
test_case_infos_
.
end
();
++
it
)
{
(
*
it
)
->
RegisterTests
();
for
(
auto
&
test_suite_info
:
test_suite_infos_
)
{
test_suite_info
->
RegisterTests
();
}
}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
template
<
class
TestCase
>
ParameterizedTestCaseInfo
<
TestCase
>*
GetTestCasePatternHolder
(
const
char
*
test_case_name
,
CodeLocation
code_location
)
{
return
GetTestSuitePatternHolder
<
TestCase
>
(
test_case_name
,
code_location
);
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
private:
typedef
::
std
::
vector
<
ParameterizedTest
Cas
eInfoBase
*>
TestCaseInfoContainer
;
using
TestSuiteInfoContainer
=
::
std
::
vector
<
ParameterizedTest
Suit
eInfoBase
*>
;
Test
Cas
eInfoContainer
test_
cas
e_infos_
;
Test
Suit
eInfoContainer
test_
suit
e_infos_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ParameterizedTest
Cas
eRegistry
);
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
ParameterizedTest
Suit
eRegistry
);
};
}
// namespace internal
...
...
googletest/include/gtest/internal/gtest-port.h
View file @
58e62f7a
...
...
@@ -250,6 +250,7 @@
#include <stdlib.h>
#include <string.h>
#include <memory>
#include <type_traits>
#ifndef _WIN32_WCE
# include <sys/types.h>
...
...
googletest/include/gtest/internal/gtest-type-util.h
View file @
58e62f7a
...
...
@@ -31,12 +31,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Type utilities needed for implementing typed and type-parameterized
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
//
// Currently we support at most 50 types in a list, and at most 50
// type-parameterized tests in one type-parameterized test
cas
e.
// type-parameterized tests in one type-parameterized test
suit
e.
// Please contact googletestframework@googlegroups.com if you need
// more.
...
...
@@ -3312,8 +3311,8 @@ struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
};
// The TypeList template makes it possible to use either a single type
// or a Types<...> list in TYPED_TEST_
CAS
E() and
// INSTANTIATE_TYPED_TEST_
CAS
E_P().
// or a Types<...> list in TYPED_TEST_
SUIT
E() and
// INSTANTIATE_TYPED_TEST_
SUIT
E_P().
template
<
typename
T
>
struct
TypeList
{
...
...
googletest/include/gtest/internal/gtest-type-util.h.pump
View file @
58e62f7a
...
...
@@ -34,7 +34,7 @@ $var n = 50 $$ Maximum length of type lists we want to support.
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
//
// Currently we support at most $n types in a list, and at most $n
// type-parameterized tests in one type-parameterized test
cas
e.
// type-parameterized tests in one type-parameterized test
suit
e.
// Please contact googletestframework@googlegroups.com if you need
// more.
...
...
@@ -291,8 +291,8 @@ struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
]]
// The TypeList template makes it possible to use either a single type
// or a Types<...> list in TYPED_TEST_
CAS
E() and
// INSTANTIATE_TYPED_TEST_
CAS
E_P().
// or a Types<...> list in TYPED_TEST_
SUIT
E() and
// INSTANTIATE_TYPED_TEST_
SUIT
E_P().
template
<
typename
T
>
struct
TypeList
{
...
...
googletest/src/gtest-death-test.cc
View file @
58e62f7a
...
...
@@ -753,9 +753,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
FALSE
,
// The initial state is non-signalled.
nullptr
));
// The even is unnamed.
GTEST_DEATH_TEST_CHECK_
(
event_handle_
.
Get
()
!=
nullptr
);
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_case_name
()
+
"."
+
info
->
name
();
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_suite_name
()
+
"."
+
info
->
name
();
const
std
::
string
internal_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
+
file_
+
"|"
+
StreamableToString
(
line_
)
+
"|"
+
...
...
@@ -972,9 +972,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
FlushInfoLog
();
// Build the child process command line.
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_case_name
()
+
"."
+
info
->
name
();
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_suite_name
()
+
"."
+
info
->
name
();
const
std
::
string
internal_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
+
file_
+
"|"
...
...
@@ -1411,9 +1411,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
// it be closed when the child process does an exec:
GTEST_DEATH_TEST_CHECK_
(
fcntl
(
pipe_fd
[
1
],
F_SETFD
,
0
)
!=
-
1
);
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_case_name
()
+
"."
+
info
->
name
();
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kFilterFlag
+
"="
+
info
->
test_suite_name
()
+
"."
+
info
->
name
();
const
std
::
string
internal_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
+
file_
+
"|"
+
StreamableToString
(
line_
)
+
"|"
...
...
googletest/src/gtest-internal-inl.h
View file @
58e62f7a
...
...
@@ -388,10 +388,10 @@ class GTEST_API_ UnitTestOptions {
// works well enough for matching test names, which are short.
static
bool
PatternMatchesString
(
const
char
*
pattern
,
const
char
*
str
);
// Returns true iff the user-specified filter matches the test
cas
e
// Returns true iff the user-specified filter matches the test
suit
e
// name and the test name.
static
bool
FilterMatchesTest
(
const
std
::
string
&
test_
cas
e_name
,
const
std
::
string
&
test_name
);
static
bool
FilterMatchesTest
(
const
std
::
string
&
test_
suit
e_name
,
const
std
::
string
&
test_name
);
#if GTEST_OS_WINDOWS
// Function for supporting the gtest_catch_exception flag.
...
...
@@ -529,18 +529,18 @@ class GTEST_API_ UnitTestImpl {
void
SetTestPartResultReporterForCurrentThread
(
TestPartResultReporterInterface
*
reporter
);
// Gets the number of successful test
cas
es.
int
successful_test_
cas
e_count
()
const
;
// Gets the number of successful test
suit
es.
int
successful_test_
suit
e_count
()
const
;
// Gets the number of failed test
cas
es.
int
failed_test_
cas
e_count
()
const
;
// Gets the number of failed test
suit
es.
int
failed_test_
suit
e_count
()
const
;
// Gets the number of all test
cas
es.
int
total_test_
cas
e_count
()
const
;
// Gets the number of all test
suit
es.
int
total_test_
suit
e_count
()
const
;
// Gets the number of all test
cas
es that contain at least one test
// Gets the number of all test
suit
es that contain at least one test
// that should run.
int
test_
cas
e_to_run_count
()
const
;
int
test_
suit
e_to_run_count
()
const
;
// Gets the number of successful tests.
int
successful_test_count
()
const
;
...
...
@@ -573,27 +573,32 @@ class GTEST_API_ UnitTestImpl {
// Gets the elapsed time, in milliseconds.
TimeInMillis
elapsed_time
()
const
{
return
elapsed_time_
;
}
// Returns true iff the unit test passed (i.e. all test
cas
es passed).
// Returns true iff the unit test passed (i.e. all test
suit
es passed).
bool
Passed
()
const
{
return
!
Failed
();
}
// Returns true iff the unit test failed (i.e. some test
cas
e failed
// Returns true iff the unit test failed (i.e. some test
suit
e failed
// or something outside of all tests failed).
bool
Failed
()
const
{
return
failed_test_
cas
e_count
()
>
0
||
ad_hoc_test_result
()
->
Failed
();
return
failed_test_
suit
e_count
()
>
0
||
ad_hoc_test_result
()
->
Failed
();
}
// Gets the i-th test
cas
e among all the test
cas
es. i can range from 0 to
// total_test_
cas
e_count() - 1. If i is not in that range, returns NULL.
const
Test
Cas
e
*
GetTest
Cas
e
(
int
i
)
const
{
const
int
index
=
GetElementOr
(
test_
cas
e_indices_
,
i
,
-
1
);
return
index
<
0
?
nullptr
:
test_
cas
es_
[
i
];
// Gets the i-th test
suit
e among all the test
suit
es. i can range from 0 to
// total_test_
suit
e_count() - 1. If i is not in that range, returns NULL.
const
Test
Suit
e
*
GetTest
Suit
e
(
int
i
)
const
{
const
int
index
=
GetElementOr
(
test_
suit
e_indices_
,
i
,
-
1
);
return
index
<
0
?
nullptr
:
test_
suit
es_
[
i
];
}
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
TestCase
*
GetMutableTestCase
(
int
i
)
{
const
int
index
=
GetElementOr
(
test_case_indices_
,
i
,
-
1
);
return
index
<
0
?
nullptr
:
test_cases_
[
index
];
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const
TestCase
*
GetTestCase
(
int
i
)
const
{
return
GetTestSuite
(
i
);
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Gets the i-th test suite among all the test suites. i can range from 0 to
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
TestSuite
*
GetMutableSuiteCase
(
int
i
)
{
const
int
index
=
GetElementOr
(
test_suite_indices_
,
i
,
-
1
);
return
index
<
0
?
nullptr
:
test_suites_
[
index
];
}
// Provides access to the event listener list.
...
...
@@ -630,30 +635,38 @@ class GTEST_API_ UnitTestImpl {
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
std
::
string
CurrentOsStackTraceExceptTop
(
int
skip_count
)
GTEST_NO_INLINE_
;
// Finds and returns a Test
Cas
e with the given name. If one doesn't
// Finds and returns a Test
Suit
e with the given name. If one doesn't
// exist, creates one and returns it.
//
// Arguments:
//
// test_
cas
e_name: name of the test
cas
e
// test_
suit
e_name: name of the test
suit
e
// type_param: the name of the test's type parameter, or NULL if
// this is not a typed or a type-parameterized test.
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
TestCase
*
GetTestCase
(
const
char
*
test_case_name
,
const
char
*
type_param
,
Test
::
SetUpTestCaseFunc
set_up_tc
,
Test
::
TearDownTestCaseFunc
tear_down_tc
);
// set_up_tc: pointer to the function that sets up the test suite
// tear_down_tc: pointer to the function that tears down the test suite
TestSuite
*
GetTestSuite
(
const
char
*
test_suite_name
,
const
char
*
type_param
,
internal
::
SetUpTestSuiteFunc
set_up_tc
,
internal
::
TearDownTestSuiteFunc
tear_down_tc
);
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
TestCase
*
GetTestCase
(
const
char
*
test_case_name
,
const
char
*
type_param
,
internal
::
SetUpTestSuiteFunc
set_up_tc
,
internal
::
TearDownTestSuiteFunc
tear_down_tc
)
{
return
GetTestSuite
(
test_case_name
,
type_param
,
set_up_tc
,
tear_down_tc
);
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Adds a TestInfo to the unit test.
//
// Arguments:
//
// set_up_tc: pointer to the function that sets up the test
cas
e
// tear_down_tc: pointer to the function that tears down the test
cas
e
// set_up_tc: pointer to the function that sets up the test
suit
e
// tear_down_tc: pointer to the function that tears down the test
suit
e
// test_info: the TestInfo object
void
AddTestInfo
(
Test
::
SetUpTest
Cas
eFunc
set_up_tc
,
Test
::
TearDownTest
Cas
eFunc
tear_down_tc
,
void
AddTestInfo
(
internal
::
SetUpTest
Suit
eFunc
set_up_tc
,
internal
::
TearDownTest
Suit
eFunc
tear_down_tc
,
TestInfo
*
test_info
)
{
// In order to support thread-safe death tests, we need to
// remember the original working directory when the test program
...
...
@@ -668,21 +681,20 @@ class GTEST_API_ UnitTestImpl {
<<
"Failed to get the current working directory."
;
}
GetTestCase
(
test_info
->
test_case_name
(),
test_info
->
type_param
(),
set_up_tc
,
tear_down_tc
)
->
AddTestInfo
(
test_info
);
GetTestSuite
(
test_info
->
test_suite_name
(),
test_info
->
type_param
(),
set_up_tc
,
tear_down_tc
)
->
AddTestInfo
(
test_info
);
}
// Returns ParameterizedTest
Cas
eRegistry object used to keep track of
// Returns ParameterizedTest
Suit
eRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
internal
::
ParameterizedTest
Cas
eRegistry
&
parameterized_test_registry
()
{
internal
::
ParameterizedTest
Suit
eRegistry
&
parameterized_test_registry
()
{
return
parameterized_test_registry_
;
}
// Sets the Test
Cas
e object for the test that's currently running.
void
set_current_test_
cas
e
(
Test
Cas
e
*
a_current_test_
cas
e
)
{
current_test_
cas
e_
=
a_current_test_
cas
e
;
// Sets the Test
Suit
e object for the test that's currently running.
void
set_current_test_
suit
e
(
Test
Suit
e
*
a_current_test_
suit
e
)
{
current_test_
suit
e_
=
a_current_test_
suit
e
;
}
// Sets the TestInfo object for the test that's currently running. If
...
...
@@ -693,7 +705,7 @@ class GTEST_API_ UnitTestImpl {
}
// Registers all parameterized tests defined using TEST_P and
// INSTANTIATE_TEST_
CAS
E_P, creating regular tests for each test/parameter
// INSTANTIATE_TEST_
SUIT
E_P, creating regular tests for each test/parameter
// combination. This method can be called more then once; it has guards
// protecting from registering the tests more then once. If
// value-parameterized tests are disabled, RegisterParameterizedTests is
...
...
@@ -708,7 +720,7 @@ class GTEST_API_ UnitTestImpl {
// Clears the results of all tests, except the ad hoc tests.
void
ClearNonAdHocTestResult
()
{
ForEach
(
test_
cas
es_
,
Test
Cas
e
::
ClearTest
Cas
eResult
);
ForEach
(
test_
suit
es_
,
Test
Suit
e
::
ClearTest
Suit
eResult
);
}
// Clears the results of ad-hoc test assertions.
...
...
@@ -717,7 +729,7 @@ class GTEST_API_ UnitTestImpl {
}
// Adds a TestProperty to the current TestResult object when invoked in a
// context of a test or a test
cas
e, or to the global property set. If the
// context of a test or a test
suit
e, or to the global property set. If the
// result already contains a property with the same key, the value will be
// updated.
void
RecordProperty
(
const
TestProperty
&
test_property
);
...
...
@@ -729,7 +741,7 @@ class GTEST_API_ UnitTestImpl {
// Matches the full name of each test against the user-specified
// filter to decide whether the test should run, then records the
// result in each Test
Cas
e and TestInfo object.
// result in each Test
Suit
e and TestInfo object.
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
// based on sharding variables in the environment.
// Returns the number of tests that should run.
...
...
@@ -738,7 +750,7 @@ class GTEST_API_ UnitTestImpl {
// Prints the names of the tests matching the user-specified filter flag.
void
ListTestsMatchingFilter
();
const
Test
Cas
e
*
current_test_
cas
e
()
const
{
return
current_test_
cas
e_
;
}
const
Test
Suit
e
*
current_test_
suit
e
()
const
{
return
current_test_
suit
e_
;
}
TestInfo
*
current_test_info
()
{
return
current_test_info_
;
}
const
TestInfo
*
current_test_info
()
const
{
return
current_test_info_
;
}
...
...
@@ -799,11 +811,11 @@ class GTEST_API_ UnitTestImpl {
// Gets the random number generator.
internal
::
Random
*
random
()
{
return
&
random_
;
}
// Shuffles all test
cas
es, and the tests within each test
cas
e,
// Shuffles all test
suit
es, and the tests within each test
suit
e,
// making sure that death tests are still run first.
void
ShuffleTests
();
// Restores the test
cas
es and tests to their order before the first shuffle.
// Restores the test
suit
es and tests to their order before the first shuffle.
void
UnshuffleTests
();
// Returns the value of GTEST_FLAG(catch_exceptions) at the moment
...
...
@@ -843,31 +855,31 @@ class GTEST_API_ UnitTestImpl {
// before/after the tests are run.
std
::
vector
<
Environment
*>
environments_
;
// The vector of Test
Cas
es in their original order. It owns the
// The vector of Test
Suit
es in their original order. It owns the
// elements in the vector.
std
::
vector
<
Test
Cas
e
*>
test_
cas
es_
;
std
::
vector
<
Test
Suit
e
*>
test_
suit
es_
;
// Provides a level of indirection for the test
cas
e list to allow
// easy shuffling and restoring the test
cas
e order. The i-th
// element of this vector is the index of the i-th test
cas
e in the
// Provides a level of indirection for the test
suit
e list to allow
// easy shuffling and restoring the test
suit
e order. The i-th
// element of this vector is the index of the i-th test
suit
e in the
// shuffled order.
std
::
vector
<
int
>
test_
cas
e_indices_
;
std
::
vector
<
int
>
test_
suit
e_indices_
;
// ParameterizedTestRegistry object used to register value-parameterized
// tests.
internal
::
ParameterizedTest
Cas
eRegistry
parameterized_test_registry_
;
internal
::
ParameterizedTest
Suit
eRegistry
parameterized_test_registry_
;
// Indicates whether RegisterParameterizedTests() has been called already.
bool
parameterized_tests_registered_
;
// Index of the last death test
cas
e registered. Initially -1.
int
last_death_test_
cas
e_
;
// Index of the last death test
suit
e registered. Initially -1.
int
last_death_test_
suit
e_
;
// This points to the Test
Cas
e for the currently running test. It
// changes as Google Test goes through one test
cas
e after another.
// This points to the Test
Suit
e for the currently running test. It
// changes as Google Test goes through one test
suit
e after another.
// When no test is running, this is set to NULL and Google Test
// stores assertion results in ad_hoc_test_result_. Initially NULL.
Test
Cas
e
*
current_test_
cas
e_
;
Test
Suit
e
*
current_test_
suit
e_
;
// This points to the TestInfo for the currently running test. It
// changes as Google Test goes through one test after another. When
...
...
@@ -1136,14 +1148,18 @@ class StreamingListener : public EmptyTestEventListener {
StreamableToString
(
unit_test
.
elapsed_time
())
+
"ms"
);
}
// Note that "event=TestCaseStart" is a wire format and has to remain
// "case" for compatibilty
void
OnTestCaseStart
(
const
TestCase
&
test_case
)
override
{
SendLn
(
std
::
string
(
"event=TestCaseStart&name="
)
+
test_case
.
name
());
}
// Note that "event=TestCaseEnd" is a wire format and has to remain
// "case" for compatibilty
void
OnTestCaseEnd
(
const
TestCase
&
test_case
)
override
{
SendLn
(
"event=TestCaseEnd&passed="
+
FormatBool
(
test_case
.
Passed
())
+
"&elapsed_time="
+
StreamableToString
(
test_case
.
elapsed_time
())
+
"ms"
);
SendLn
(
"event=TestCaseEnd&passed="
+
FormatBool
(
test_case
.
Passed
())
+
"&elapsed_time="
+
StreamableToString
(
test_case
.
elapsed_time
())
+
"ms"
);
}
void
OnTestStart
(
const
TestInfo
&
test_info
)
override
{
...
...
googletest/src/gtest-typed-test.cc
View file @
58e62f7a
...
...
@@ -57,7 +57,7 @@ static std::vector<std::string> SplitIntoTestNames(const char* src) {
// Verifies that registered_tests match the test names in
// registered_tests_; returns registered_tests if successful, or
// aborts the program otherwise.
const
char
*
TypedTest
Cas
ePState
::
VerifyRegisteredTestNames
(
const
char
*
TypedTest
Suit
ePState
::
VerifyRegisteredTestNames
(
const
char
*
file
,
int
line
,
const
char
*
registered_tests
)
{
typedef
RegisteredTestsMap
::
const_iterator
RegisteredTestIter
;
registered_
=
true
;
...
...
@@ -89,7 +89,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
tests
.
insert
(
name
);
}
else
{
errors
<<
"No test named "
<<
name
<<
" can be found in this test
cas
e.
\n
"
;
<<
" can be found in this test
suit
e.
\n
"
;
}
}
...
...
googletest/src/gtest.cc
View file @
58e62f7a
...
...
@@ -147,14 +147,14 @@ using internal::Shuffle;
// Constants.
// A test whose test
cas
e name or test name matches this filter is
// A test whose test
suit
e name or test name matches this filter is
// disabled and not run.
static
const
char
kDisableTestFilter
[]
=
"DISABLED_*:*/DISABLED_*"
;
// A test
cas
e whose name matches this filter is considered a death
// test
cas
e and will be run before test
cas
es whose name doesn't
// A test
suit
e whose name matches this filter is considered a death
// test
suit
e and will be run before test
suit
es whose name doesn't
// match this filter.
static
const
char
kDeathTest
Cas
eFilter
[]
=
"*DeathTest:*DeathTest/*"
;
static
const
char
kDeathTest
Suit
eFilter
[]
=
"*DeathTest:*DeathTest/*"
;
// A test filter that matches everything.
static
const
char
kUniversalFilter
[]
=
"*"
;
...
...
@@ -359,11 +359,11 @@ UInt32 Random::Generate(UInt32 range) {
// Google Test before calling RUN_ALL_TESTS().
static
bool
GTestIsInitialized
()
{
return
GetArgvs
().
size
()
>
0
;
}
// Iterates over a vector of Test
Cas
es, keeping a running sum of the
// Iterates over a vector of Test
Suit
es, keeping a running sum of the
// results of calling a given int-returning method on each.
// Returns the sum.
static
int
SumOverTest
Cas
eList
(
const
std
::
vector
<
Test
Cas
e
*>&
case_list
,
int
(
Test
Cas
e
::*
method
)()
const
)
{
static
int
SumOverTest
Suit
eList
(
const
std
::
vector
<
Test
Suit
e
*>&
case_list
,
int
(
Test
Suit
e
::*
method
)()
const
)
{
int
sum
=
0
;
for
(
size_t
i
=
0
;
i
<
case_list
.
size
();
i
++
)
{
sum
+=
(
case_list
[
i
]
->*
method
)();
...
...
@@ -371,20 +371,20 @@ static int SumOverTestCaseList(const std::vector<TestCase*>& case_list,
return
sum
;
}
// Returns true iff the test
cas
e passed.
static
bool
Test
Cas
ePassed
(
const
Test
Cas
e
*
test_
cas
e
)
{
return
test_
cas
e
->
should_run
()
&&
test_
cas
e
->
Passed
();
// Returns true iff the test
suit
e passed.
static
bool
Test
Suit
ePassed
(
const
Test
Suit
e
*
test_
suit
e
)
{
return
test_
suit
e
->
should_run
()
&&
test_
suit
e
->
Passed
();
}
// Returns true iff the test
cas
e failed.
static
bool
Test
Cas
eFailed
(
const
Test
Cas
e
*
test_
cas
e
)
{
return
test_
cas
e
->
should_run
()
&&
test_
cas
e
->
Failed
();
// Returns true iff the test
suit
e failed.
static
bool
Test
Suit
eFailed
(
const
Test
Suit
e
*
test_
suit
e
)
{
return
test_
suit
e
->
should_run
()
&&
test_
suit
e
->
Failed
();
}
// Returns true iff test_
cas
e contains at least one test that should
// Returns true iff test_
suit
e contains at least one test that should
// run.
static
bool
ShouldRunTest
Cas
e
(
const
Test
Cas
e
*
test_
cas
e
)
{
return
test_
cas
e
->
should_run
();
static
bool
ShouldRunTest
Suit
e
(
const
Test
Suit
e
*
test_
suit
e
)
{
return
test_
suit
e
->
should_run
();
}
// AssertHelper constructor.
...
...
@@ -524,11 +524,11 @@ bool UnitTestOptions::MatchesFilter(
}
}
// Returns true iff the user-specified filter matches the test
cas
e
// Returns true iff the user-specified filter matches the test
suit
e
// name and the test name.
bool
UnitTestOptions
::
FilterMatchesTest
(
const
std
::
string
&
test_
cas
e_name
,
const
std
::
string
&
test_name
)
{
const
std
::
string
&
full_name
=
test_
cas
e_name
+
"."
+
test_name
.
c_str
();
bool
UnitTestOptions
::
FilterMatchesTest
(
const
std
::
string
&
test_
suit
e_name
,
const
std
::
string
&
test_name
)
{
const
std
::
string
&
full_name
=
test_
suit
e_name
+
"."
+
test_name
.
c_str
();
// Split --gtest_filter at '-', if there is one, to separate into
// positive filter and negative filter portions
...
...
@@ -750,66 +750,66 @@ void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
per_thread_test_part_result_reporter_
.
set
(
reporter
);
}
// Gets the number of successful test
cas
es.
int
UnitTestImpl
::
successful_test_
cas
e_count
()
const
{
return
CountIf
(
test_
cas
es_
,
Test
Cas
ePassed
);
// Gets the number of successful test
suit
es.
int
UnitTestImpl
::
successful_test_
suit
e_count
()
const
{
return
CountIf
(
test_
suit
es_
,
Test
Suit
ePassed
);
}
// Gets the number of failed test
cas
es.
int
UnitTestImpl
::
failed_test_
cas
e_count
()
const
{
return
CountIf
(
test_
cas
es_
,
Test
Cas
eFailed
);
// Gets the number of failed test
suit
es.
int
UnitTestImpl
::
failed_test_
suit
e_count
()
const
{
return
CountIf
(
test_
suit
es_
,
Test
Suit
eFailed
);
}
// Gets the number of all test
cas
es.
int
UnitTestImpl
::
total_test_
cas
e_count
()
const
{
return
static_cast
<
int
>
(
test_
cas
es_
.
size
());
// Gets the number of all test
suit
es.
int
UnitTestImpl
::
total_test_
suit
e_count
()
const
{
return
static_cast
<
int
>
(
test_
suit
es_
.
size
());
}
// Gets the number of all test
cas
es that contain at least one test
// Gets the number of all test
suit
es that contain at least one test
// that should run.
int
UnitTestImpl
::
test_
cas
e_to_run_count
()
const
{
return
CountIf
(
test_
cas
es_
,
ShouldRunTest
Cas
e
);
int
UnitTestImpl
::
test_
suit
e_to_run_count
()
const
{
return
CountIf
(
test_
suit
es_
,
ShouldRunTest
Suit
e
);
}
// Gets the number of successful tests.
int
UnitTestImpl
::
successful_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
successful_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
successful_test_count
);
}
// Gets the number of skipped tests.
int
UnitTestImpl
::
skipped_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
skipped_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
skipped_test_count
);
}
// Gets the number of failed tests.
int
UnitTestImpl
::
failed_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
failed_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
failed_test_count
);
}
// Gets the number of disabled tests that will be reported in the XML report.
int
UnitTestImpl
::
reportable_disabled_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
reportable_disabled_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
reportable_disabled_test_count
);
}
// Gets the number of disabled tests.
int
UnitTestImpl
::
disabled_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
disabled_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
disabled_test_count
);
}
// Gets the number of tests to be printed in the XML report.
int
UnitTestImpl
::
reportable_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
reportable_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
reportable_test_count
);
}
// Gets the number of all tests.
int
UnitTestImpl
::
total_test_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
total_test_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
total_test_count
);
}
// Gets the number of tests that should run.
int
UnitTestImpl
::
test_to_run_count
()
const
{
return
SumOverTest
Cas
eList
(
test_
cas
es_
,
&
Test
Cas
e
::
test_to_run_count
);
return
SumOverTest
Suit
eList
(
test_
suit
es_
,
&
Test
Suit
e
::
test_to_run_count
);
}
// Returns the current OS stack trace as an std::string.
...
...
@@ -2283,17 +2283,17 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
}
// namespace internal
// Google Test requires all tests in the same test
cas
e to use the same test
// Google Test requires all tests in the same test
suit
e to use the same test
// fixture class. This function checks if the current test has the
// same fixture class as the first test in the current test
cas
e. If
// same fixture class as the first test in the current test
suit
e. If
// yes, it returns true; otherwise it generates a Google Test failure and
// returns false.
bool
Test
::
HasSameFixtureClass
()
{
internal
::
UnitTestImpl
*
const
impl
=
internal
::
GetUnitTestImpl
();
const
Test
Cas
e
*
const
test_
cas
e
=
impl
->
current_test_
cas
e
();
const
Test
Suit
e
*
const
test_
suit
e
=
impl
->
current_test_
suit
e
();
// Info about the first test in the current test
cas
e.
const
TestInfo
*
const
first_test_info
=
test_
cas
e
->
test_info_list
()[
0
];
// Info about the first test in the current test
suit
e.
const
TestInfo
*
const
first_test_info
=
test_
suit
e
->
test_info_list
()[
0
];
const
internal
::
TypeId
first_fixture_id
=
first_test_info
->
fixture_class_id_
;
const
char
*
const
first_test_name
=
first_test_info
->
name
();
...
...
@@ -2309,7 +2309,7 @@ bool Test::HasSameFixtureClass() {
const
bool
this_is_TEST
=
this_fixture_id
==
internal
::
GetTestTypeId
();
if
(
first_is_TEST
||
this_is_TEST
)
{
// Both TEST and TEST_F appear in same test
cas
e, which is incorrect.
// Both TEST and TEST_F appear in same test
suit
e, which is incorrect.
// Tell the user how to fix this.
// Gets the name of the TEST and the name of the TEST_F. Note
...
...
@@ -2321,9 +2321,9 @@ bool Test::HasSameFixtureClass() {
first_is_TEST
?
this_test_name
:
first_test_name
;
ADD_FAILURE
()
<<
"All tests in the same test
cas
e must use the same test fixture
\n
"
<<
"class, so mixing TEST_F and TEST in the same test
cas
e is
\n
"
<<
"illegal. In test
cas
e "
<<
this_test_info
->
test_
cas
e_name
()
<<
"All tests in the same test
suit
e must use the same test fixture
\n
"
<<
"class, so mixing TEST_F and TEST in the same test
suit
e is
\n
"
<<
"illegal. In test
suit
e "
<<
this_test_info
->
test_
suit
e_name
()
<<
",
\n
"
<<
"test "
<<
TEST_F_name
<<
" is defined using TEST_F but
\n
"
<<
"test "
<<
TEST_name
<<
" is defined using TEST. You probably
\n
"
...
...
@@ -2333,15 +2333,15 @@ bool Test::HasSameFixtureClass() {
// Two fixture classes with the same name appear in two different
// namespaces, which is not allowed. Tell the user how to fix this.
ADD_FAILURE
()
<<
"All tests in the same test
cas
e must use the same test fixture
\n
"
<<
"class. However, in test
cas
e "
<<
this_test_info
->
test_
cas
e_name
()
<<
",
\n
"
<<
"you defined test "
<<
first_test_name
<<
" and test "
<<
this_test_name
<<
"
\n
"
<<
"All tests in the same test
suit
e must use the same test fixture
\n
"
<<
"class. However, in test
suit
e "
<<
this_test_info
->
test_
suit
e_name
()
<<
",
\n
"
<<
"you defined test "
<<
first_test_name
<<
" and test "
<<
this_test_name
<<
"
\n
"
<<
"using two different test fixture classes. This can happen if
\n
"
<<
"the two classes are from different namespaces or translation
\n
"
<<
"units and have the same name. You should probably rename one
\n
"
<<
"of the classes to put the tests into different test
cas
es."
;
<<
"of the classes to put the tests into different test
suit
es."
;
}
return
false
;
}
...
...
@@ -2528,13 +2528,13 @@ bool Test::IsSkipped() {
// Constructs a TestInfo object. It assumes ownership of the test factory
// object.
TestInfo
::
TestInfo
(
const
std
::
string
&
a_test_
cas
e_name
,
TestInfo
::
TestInfo
(
const
std
::
string
&
a_test_
suit
e_name
,
const
std
::
string
&
a_name
,
const
char
*
a_type_param
,
const
char
*
a_value_param
,
internal
::
CodeLocation
a_code_location
,
internal
::
TypeId
fixture_class_id
,
internal
::
TestFactoryBase
*
factory
)
:
test_
cas
e_name_
(
a_test_
cas
e_name
),
:
test_
suit
e_name_
(
a_test_
suit
e_name
),
name_
(
a_name
),
type_param_
(
a_type_param
?
new
std
::
string
(
a_type_param
)
:
nullptr
),
value_param_
(
a_value_param
?
new
std
::
string
(
a_value_param
)
:
nullptr
),
...
...
@@ -2556,7 +2556,7 @@ namespace internal {
//
// Arguments:
//
// test_
cas
e_name: name of the test
cas
e
// test_
suit
e_name: name of the test
suit
e
// name: name of the test
// type_param: the name of the test's type parameter, or NULL if
// this is not a typed or a type-parameterized test.
...
...
@@ -2564,40 +2564,35 @@ namespace internal {
// or NULL if this is not a value-parameterized test.
// code_location: code location where the test is defined
// fixture_class_id: ID of the test fixture class
// set_up_tc: pointer to the function that sets up the test
cas
e
// tear_down_tc: pointer to the function that tears down the test
cas
e
// set_up_tc: pointer to the function that sets up the test
suit
e
// tear_down_tc: pointer to the function that tears down the test
suit
e
// factory: pointer to the factory that creates a test object.
// The newly created TestInfo instance will assume
// ownership of the factory object.
TestInfo
*
MakeAndRegisterTestInfo
(
const
char
*
test_case_name
,
const
char
*
name
,
const
char
*
type_param
,
const
char
*
value_param
,
CodeLocation
code_location
,
TypeId
fixture_class_id
,
SetUpTestCaseFunc
set_up_tc
,
TearDownTestCaseFunc
tear_down_tc
,
TestFactoryBase
*
factory
)
{
const
char
*
test_suite_name
,
const
char
*
name
,
const
char
*
type_param
,
const
char
*
value_param
,
CodeLocation
code_location
,
TypeId
fixture_class_id
,
SetUpTestSuiteFunc
set_up_tc
,
TearDownTestSuiteFunc
tear_down_tc
,
TestFactoryBase
*
factory
)
{
TestInfo
*
const
test_info
=
new
TestInfo
(
test_
cas
e_name
,
name
,
type_param
,
value_param
,
new
TestInfo
(
test_
suit
e_name
,
name
,
type_param
,
value_param
,
code_location
,
fixture_class_id
,
factory
);
GetUnitTestImpl
()
->
AddTestInfo
(
set_up_tc
,
tear_down_tc
,
test_info
);
return
test_info
;
}
void
ReportInvalidTest
Cas
eType
(
const
char
*
test_
cas
e_name
,
void
ReportInvalidTest
Suit
eType
(
const
char
*
test_
suit
e_name
,
CodeLocation
code_location
)
{
Message
errors
;
errors
<<
"Attempted redefinition of test
cas
e "
<<
test_
cas
e_name
<<
".
\n
"
<<
"All tests in the same test
cas
e must use the same test fixture
\n
"
<<
"class. However, in test
cas
e "
<<
test_
cas
e_name
<<
", you tried
\n
"
<<
"Attempted redefinition of test
suit
e "
<<
test_
suit
e_name
<<
".
\n
"
<<
"All tests in the same test
suit
e must use the same test fixture
\n
"
<<
"class. However, in test
suit
e "
<<
test_
suit
e_name
<<
", you tried
\n
"
<<
"to define a test using a fixture class different from the one
\n
"
<<
"used earlier. This can happen if the two fixture classes are
\n
"
<<
"from different namespaces and have the same name. You should
\n
"
<<
"probably rename one of the classes to put the tests into different
\n
"
<<
"test
cas
es."
;
<<
"test
suit
es."
;
GTEST_LOG_
(
ERROR
)
<<
FormatFileLocation
(
code_location
.
file
.
c_str
(),
code_location
.
line
)
...
...
@@ -2610,7 +2605,7 @@ namespace {
// A predicate that checks the test name of a TestInfo against a known
// value.
//
// This is used for implementation of the Test
Cas
e class only. We put
// This is used for implementation of the Test
Suit
e class only. We put
// it in the anonymous namespace to prevent polluting the outer
// namespace.
//
...
...
@@ -2637,7 +2632,7 @@ class TestNameIs {
namespace
internal
{
// This method expands all parameterized tests registered with macros TEST_P
// and INSTANTIATE_TEST_
CAS
E_P into regular tests and registers those.
// and INSTANTIATE_TEST_
SUIT
E_P into regular tests and registers those.
// This will be done just once during the program runtime.
void
UnitTestImpl
::
RegisterParameterizedTests
()
{
if
(
!
parameterized_tests_registered_
)
{
...
...
@@ -2695,60 +2690,60 @@ void TestInfo::Run() {
impl
->
set_current_test_info
(
nullptr
);
}
// class Test
Cas
e
// class Test
Suit
e
// Gets the number of successful tests in this test
cas
e.
int
Test
Cas
e
::
successful_test_count
()
const
{
// Gets the number of successful tests in this test
suit
e.
int
Test
Suit
e
::
successful_test_count
()
const
{
return
CountIf
(
test_info_list_
,
TestPassed
);
}
// Gets the number of successful tests in this test
cas
e.
int
Test
Cas
e
::
skipped_test_count
()
const
{
// Gets the number of successful tests in this test
suit
e.
int
Test
Suit
e
::
skipped_test_count
()
const
{
return
CountIf
(
test_info_list_
,
TestSkipped
);
}
// Gets the number of failed tests in this test
cas
e.
int
Test
Cas
e
::
failed_test_count
()
const
{
// Gets the number of failed tests in this test
suit
e.
int
Test
Suit
e
::
failed_test_count
()
const
{
return
CountIf
(
test_info_list_
,
TestFailed
);
}
// Gets the number of disabled tests that will be reported in the XML report.
int
Test
Cas
e
::
reportable_disabled_test_count
()
const
{
int
Test
Suit
e
::
reportable_disabled_test_count
()
const
{
return
CountIf
(
test_info_list_
,
TestReportableDisabled
);
}
// Gets the number of disabled tests in this test
cas
e.
int
Test
Cas
e
::
disabled_test_count
()
const
{
// Gets the number of disabled tests in this test
suit
e.
int
Test
Suit
e
::
disabled_test_count
()
const
{
return
CountIf
(
test_info_list_
,
TestDisabled
);
}
// Gets the number of tests to be printed in the XML report.
int
Test
Cas
e
::
reportable_test_count
()
const
{
int
Test
Suit
e
::
reportable_test_count
()
const
{
return
CountIf
(
test_info_list_
,
TestReportable
);
}
// Get the number of tests in this test
cas
e that should run.
int
Test
Cas
e
::
test_to_run_count
()
const
{
// Get the number of tests in this test
suit
e that should run.
int
Test
Suit
e
::
test_to_run_count
()
const
{
return
CountIf
(
test_info_list_
,
ShouldRunTest
);
}
// Gets the number of all tests.
int
Test
Cas
e
::
total_test_count
()
const
{
int
Test
Suit
e
::
total_test_count
()
const
{
return
static_cast
<
int
>
(
test_info_list_
.
size
());
}
// Creates a Test
Cas
e with the given name.
// Creates a Test
Suit
e with the given name.
//
// Arguments:
//
// name: name of the test
cas
e
// a_type_param: the name of the test
cas
e's type parameter, or NULL if
// this is not a typed or a type-parameterized test
cas
e.
// set_up_tc: pointer to the function that sets up the test
cas
e
// tear_down_tc: pointer to the function that tears down the test
cas
e
Test
Cas
e
::
Test
Cas
e
(
const
char
*
a_name
,
const
char
*
a_type_param
,
Test
::
SetUpTest
Cas
eFunc
set_up_tc
,
Test
::
TearDownTest
Cas
eFunc
tear_down_tc
)
// name: name of the test
suit
e
// a_type_param: the name of the test
suit
e's type parameter, or NULL if
// this is not a typed or a type-parameterized test
suit
e.
// set_up_tc: pointer to the function that sets up the test
suit
e
// tear_down_tc: pointer to the function that tears down the test
suit
e
Test
Suit
e
::
Test
Suit
e
(
const
char
*
a_name
,
const
char
*
a_type_param
,
internal
::
SetUpTest
Suit
eFunc
set_up_tc
,
internal
::
TearDownTest
Suit
eFunc
tear_down_tc
)
:
name_
(
a_name
),
type_param_
(
a_type_param
?
new
std
::
string
(
a_type_param
)
:
nullptr
),
set_up_tc_
(
set_up_tc
),
...
...
@@ -2756,46 +2751,52 @@ TestCase::TestCase(const char* a_name, const char* a_type_param,
should_run_
(
false
),
elapsed_time_
(
0
)
{}
// Destructor of Test
Cas
e.
Test
Cas
e
::~
Test
Cas
e
()
{
// Destructor of Test
Suit
e.
Test
Suit
e
::~
Test
Suit
e
()
{
// Deletes every Test in the collection.
ForEach
(
test_info_list_
,
internal
::
Delete
<
TestInfo
>
);
}
// Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL.
const
TestInfo
*
Test
Cas
e
::
GetTestInfo
(
int
i
)
const
{
const
TestInfo
*
Test
Suit
e
::
GetTestInfo
(
int
i
)
const
{
const
int
index
=
GetElementOr
(
test_indices_
,
i
,
-
1
);
return
index
<
0
?
nullptr
:
test_info_list_
[
index
];
}
// Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL.
TestInfo
*
Test
Cas
e
::
GetMutableTestInfo
(
int
i
)
{
TestInfo
*
Test
Suit
e
::
GetMutableTestInfo
(
int
i
)
{
const
int
index
=
GetElementOr
(
test_indices_
,
i
,
-
1
);
return
index
<
0
?
nullptr
:
test_info_list_
[
index
];
}
// Adds a test to this test
cas
e. Will delete the test upon
// destruction of the Test
Cas
e object.
void
Test
Cas
e
::
AddTestInfo
(
TestInfo
*
test_info
)
{
// Adds a test to this test
suit
e. Will delete the test upon
// destruction of the Test
Suit
e object.
void
Test
Suit
e
::
AddTestInfo
(
TestInfo
*
test_info
)
{
test_info_list_
.
push_back
(
test_info
);
test_indices_
.
push_back
(
static_cast
<
int
>
(
test_indices_
.
size
()));
}
// Runs every test in this Test
Cas
e.
void
Test
Cas
e
::
Run
()
{
// Runs every test in this Test
Suit
e.
void
Test
Suit
e
::
Run
()
{
if
(
!
should_run_
)
return
;
internal
::
UnitTestImpl
*
const
impl
=
internal
::
GetUnitTestImpl
();
impl
->
set_current_test_
cas
e
(
this
);
impl
->
set_current_test_
suit
e
(
this
);
TestEventListener
*
repeater
=
UnitTest
::
GetInstance
()
->
listeners
().
repeater
();
// Call both legacy and the new API
repeater
->
OnTestSuiteStart
(
*
this
);
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
repeater
->
OnTestCaseStart
(
*
this
);
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
impl
->
os_stack_trace_getter
()
->
UponLeavingGTest
();
internal
::
HandleExceptionsInMethodIfSupported
(
this
,
&
Test
Cas
e
::
RunSetUpTest
Cas
e
,
"SetUpTest
Cas
e()"
);
this
,
&
Test
Suit
e
::
RunSetUpTest
Suit
e
,
"SetUpTest
Suit
e()"
);
const
internal
::
TimeInMillis
start
=
internal
::
GetTimeInMillis
();
for
(
int
i
=
0
;
i
<
total_test_count
();
i
++
)
{
...
...
@@ -2805,25 +2806,31 @@ void TestCase::Run() {
impl
->
os_stack_trace_getter
()
->
UponLeavingGTest
();
internal
::
HandleExceptionsInMethodIfSupported
(
this
,
&
Test
Cas
e
::
RunTearDownTest
Cas
e
,
"TearDownTest
Cas
e()"
);
this
,
&
Test
Suit
e
::
RunTearDownTest
Suit
e
,
"TearDownTest
Suit
e()"
);
// Call both legacy and the new API
repeater
->
OnTestSuiteEnd
(
*
this
);
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
repeater
->
OnTestCaseEnd
(
*
this
);
impl
->
set_current_test_case
(
nullptr
);
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
impl
->
set_current_test_suite
(
nullptr
);
}
// Clears the results of all tests in this test
cas
e.
void
Test
Cas
e
::
ClearResult
()
{
// Clears the results of all tests in this test
suit
e.
void
Test
Suit
e
::
ClearResult
()
{
ad_hoc_test_result_
.
Clear
();
ForEach
(
test_info_list_
,
TestInfo
::
ClearTestResult
);
}
// Shuffles the tests in this test
cas
e.
void
Test
Cas
e
::
ShuffleTests
(
internal
::
Random
*
random
)
{
// Shuffles the tests in this test
suit
e.
void
Test
Suit
e
::
ShuffleTests
(
internal
::
Random
*
random
)
{
Shuffle
(
random
,
&
test_indices_
);
}
// Restores the test order to before the first shuffle.
void
Test
Cas
e
::
UnshuffleTests
()
{
void
Test
Suit
e
::
UnshuffleTests
()
{
for
(
size_t
i
=
0
;
i
<
test_indices_
.
size
();
i
++
)
{
test_indices_
[
i
]
=
static_cast
<
int
>
(
i
);
}
...
...
@@ -2846,9 +2853,9 @@ static std::string FormatTestCount(int test_count) {
return
FormatCountableNoun
(
test_count
,
"test"
,
"tests"
);
}
// Formats the count of test
cas
es.
static
std
::
string
FormatTest
Cas
eCount
(
int
test_
cas
e_count
)
{
return
FormatCountableNoun
(
test_
cas
e_count
,
"test
cas
e"
,
"test
cas
es"
);
// Formats the count of test
suit
es.
static
std
::
string
FormatTest
Suit
eCount
(
int
test_
suit
e_count
)
{
return
FormatCountableNoun
(
test_
suit
e_count
,
"test
suit
e"
,
"test
suit
es"
);
}
// Converts a TestPartResult::Type enum to human-friendly string
...
...
@@ -3082,8 +3089,8 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
class
PrettyUnitTestResultPrinter
:
public
TestEventListener
{
public:
PrettyUnitTestResultPrinter
()
{}
static
void
PrintTestName
(
const
char
*
test_
cas
e
,
const
char
*
test
)
{
printf
(
"%s.%s"
,
test_
cas
e
,
test
);
static
void
PrintTestName
(
const
char
*
test_
suit
e
,
const
char
*
test
)
{
printf
(
"%s.%s"
,
test_
suit
e
,
test
);
}
// The following methods override what's in the TestEventListener class.
...
...
@@ -3091,11 +3098,11 @@ class PrettyUnitTestResultPrinter : public TestEventListener {
void
OnTestIterationStart
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestCaseStart
(
const
Test
Cas
e
&
test_
cas
e
)
override
;
void
OnTestCaseStart
(
const
Test
Suit
e
&
test_
suit
e
)
override
;
void
OnTestStart
(
const
TestInfo
&
test_info
)
override
;
void
OnTestPartResult
(
const
TestPartResult
&
result
)
override
;
void
OnTestEnd
(
const
TestInfo
&
test_info
)
override
;
void
OnTestCaseEnd
(
const
Test
Cas
e
&
test_
cas
e
)
override
;
void
OnTestCaseEnd
(
const
Test
Suit
e
&
test_
suit
e
)
override
;
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
...
...
@@ -3138,7 +3145,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
ColoredPrintf
(
COLOR_GREEN
,
"[==========] "
);
printf
(
"Running %s from %s.
\n
"
,
FormatTestCount
(
unit_test
.
test_to_run_count
()).
c_str
(),
FormatTest
Cas
eCount
(
unit_test
.
test_
cas
e_to_run_count
()).
c_str
());
FormatTest
Suit
eCount
(
unit_test
.
test_
suit
e_to_run_count
()).
c_str
());
fflush
(
stdout
);
}
...
...
@@ -3149,22 +3156,22 @@ void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
fflush
(
stdout
);
}
void
PrettyUnitTestResultPrinter
::
OnTestCaseStart
(
const
Test
Cas
e
&
test_
cas
e
)
{
void
PrettyUnitTestResultPrinter
::
OnTestCaseStart
(
const
Test
Suit
e
&
test_
suit
e
)
{
const
std
::
string
counts
=
FormatCountableNoun
(
test_
cas
e
.
test_to_run_count
(),
"test"
,
"tests"
);
FormatCountableNoun
(
test_
suit
e
.
test_to_run_count
(),
"test"
,
"tests"
);
ColoredPrintf
(
COLOR_GREEN
,
"[----------] "
);
printf
(
"%s from %s"
,
counts
.
c_str
(),
test_
cas
e
.
name
());
if
(
test_
cas
e
.
type_param
()
==
nullptr
)
{
printf
(
"%s from %s"
,
counts
.
c_str
(),
test_
suit
e
.
name
());
if
(
test_
suit
e
.
type_param
()
==
nullptr
)
{
printf
(
"
\n
"
);
}
else
{
printf
(
", where %s = %s
\n
"
,
kTypeParamLabel
,
test_
cas
e
.
type_param
());
printf
(
", where %s = %s
\n
"
,
kTypeParamLabel
,
test_
suit
e
.
type_param
());
}
fflush
(
stdout
);
}
void
PrettyUnitTestResultPrinter
::
OnTestStart
(
const
TestInfo
&
test_info
)
{
ColoredPrintf
(
COLOR_GREEN
,
"[ RUN ] "
);
PrintTestName
(
test_info
.
test_
cas
e_name
(),
test_info
.
name
());
PrintTestName
(
test_info
.
test_
suit
e_name
(),
test_info
.
name
());
printf
(
"
\n
"
);
fflush
(
stdout
);
}
...
...
@@ -3194,7 +3201,7 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
}
else
{
ColoredPrintf
(
COLOR_RED
,
"[ FAILED ] "
);
}
PrintTestName
(
test_info
.
test_
cas
e_name
(),
test_info
.
name
());
PrintTestName
(
test_info
.
test_
suit
e_name
(),
test_info
.
name
());
if
(
test_info
.
result
()
->
Failed
())
PrintFullTestCommentIfPresent
(
test_info
);
...
...
@@ -3207,15 +3214,14 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
fflush
(
stdout
);
}
void
PrettyUnitTestResultPrinter
::
OnTestCaseEnd
(
const
Test
Cas
e
&
test_
cas
e
)
{
void
PrettyUnitTestResultPrinter
::
OnTestCaseEnd
(
const
Test
Suit
e
&
test_
suit
e
)
{
if
(
!
GTEST_FLAG
(
print_time
))
return
;
const
std
::
string
counts
=
FormatCountableNoun
(
test_
cas
e
.
test_to_run_count
(),
"test"
,
"tests"
);
FormatCountableNoun
(
test_
suit
e
.
test_to_run_count
(),
"test"
,
"tests"
);
ColoredPrintf
(
COLOR_GREEN
,
"[----------] "
);
printf
(
"%s from %s (%s ms total)
\n\n
"
,
counts
.
c_str
(),
test_case
.
name
(),
internal
::
StreamableToString
(
test_case
.
elapsed_time
()).
c_str
());
printf
(
"%s from %s (%s ms total)
\n\n
"
,
counts
.
c_str
(),
test_suite
.
name
(),
internal
::
StreamableToString
(
test_suite
.
elapsed_time
()).
c_str
());
fflush
(
stdout
);
}
...
...
@@ -3233,18 +3239,18 @@ void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
return
;
}
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
cas
e_count
();
++
i
)
{
const
Test
Cas
e
&
test_
cas
e
=
*
unit_test
.
GetTest
Cas
e
(
i
);
if
(
!
test_
cas
e
.
should_run
()
||
(
test_
cas
e
.
failed_test_count
()
==
0
))
{
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
suit
e_count
();
++
i
)
{
const
Test
Suit
e
&
test_
suit
e
=
*
unit_test
.
GetTest
Suit
e
(
i
);
if
(
!
test_
suit
e
.
should_run
()
||
(
test_
suit
e
.
failed_test_count
()
==
0
))
{
continue
;
}
for
(
int
j
=
0
;
j
<
test_
cas
e
.
total_test_count
();
++
j
)
{
const
TestInfo
&
test_info
=
*
test_
cas
e
.
GetTestInfo
(
j
);
for
(
int
j
=
0
;
j
<
test_
suit
e
.
total_test_count
();
++
j
)
{
const
TestInfo
&
test_info
=
*
test_
suit
e
.
GetTestInfo
(
j
);
if
(
!
test_info
.
should_run
()
||
!
test_info
.
result
()
->
Failed
())
{
continue
;
}
ColoredPrintf
(
COLOR_RED
,
"[ FAILED ] "
);
printf
(
"%s.%s"
,
test_
cas
e
.
name
(),
test_info
.
name
());
printf
(
"%s.%s"
,
test_
suit
e
.
name
(),
test_info
.
name
());
PrintFullTestCommentIfPresent
(
test_info
);
printf
(
"
\n
"
);
}
...
...
@@ -3258,18 +3264,18 @@ void PrettyUnitTestResultPrinter::PrintSkippedTests(const UnitTest& unit_test) {
return
;
}
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
cas
e_count
();
++
i
)
{
const
Test
Cas
e
&
test_
cas
e
=
*
unit_test
.
GetTest
Cas
e
(
i
);
if
(
!
test_
cas
e
.
should_run
()
||
(
test_
cas
e
.
skipped_test_count
()
==
0
))
{
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
suit
e_count
();
++
i
)
{
const
Test
Suit
e
&
test_
suit
e
=
*
unit_test
.
GetTest
Suit
e
(
i
);
if
(
!
test_
suit
e
.
should_run
()
||
(
test_
suit
e
.
skipped_test_count
()
==
0
))
{
continue
;
}
for
(
int
j
=
0
;
j
<
test_
cas
e
.
total_test_count
();
++
j
)
{
const
TestInfo
&
test_info
=
*
test_
cas
e
.
GetTestInfo
(
j
);
for
(
int
j
=
0
;
j
<
test_
suit
e
.
total_test_count
();
++
j
)
{
const
TestInfo
&
test_info
=
*
test_
suit
e
.
GetTestInfo
(
j
);
if
(
!
test_info
.
should_run
()
||
!
test_info
.
result
()
->
Skipped
())
{
continue
;
}
ColoredPrintf
(
COLOR_GREEN
,
"[ SKIPPED ] "
);
printf
(
"%s.%s"
,
test_
cas
e
.
name
(),
test_info
.
name
());
printf
(
"%s.%s"
,
test_
suit
e
.
name
(),
test_info
.
name
());
printf
(
"
\n
"
);
}
}
...
...
@@ -3280,7 +3286,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
ColoredPrintf
(
COLOR_GREEN
,
"[==========] "
);
printf
(
"%s from %s ran."
,
FormatTestCount
(
unit_test
.
test_to_run_count
()).
c_str
(),
FormatTest
Cas
eCount
(
unit_test
.
test_
cas
e_to_run_count
()).
c_str
());
FormatTest
Suit
eCount
(
unit_test
.
test_
suit
e_to_run_count
()).
c_str
());
if
(
GTEST_FLAG
(
print_time
))
{
printf
(
" (%s ms total)"
,
internal
::
StreamableToString
(
unit_test
.
elapsed_time
()).
c_str
());
...
...
@@ -3341,11 +3347,19 @@ class TestEventRepeater : public TestEventListener {
void
OnTestIterationStart
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
unit_test
)
override
;
void
OnTestCaseStart
(
const
TestCase
&
test_case
)
override
;
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
void
OnTestCaseStart
(
const
TestSuite
&
parameter
)
override
;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
void
OnTestSuiteStart
(
const
TestSuite
&
parameter
)
override
;
void
OnTestStart
(
const
TestInfo
&
test_info
)
override
;
void
OnTestPartResult
(
const
TestPartResult
&
result
)
override
;
void
OnTestEnd
(
const
TestInfo
&
test_info
)
override
;
void
OnTestCaseEnd
(
const
TestCase
&
test_case
)
override
;
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
void
OnTestCaseEnd
(
const
TestSuite
&
parameter
)
override
;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
void
OnTestSuiteEnd
(
const
TestSuite
&
parameter
)
override
;
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
unit_test
)
override
;
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
...
...
@@ -3403,14 +3417,22 @@ void TestEventRepeater::Name(const Type& parameter) { \
GTEST_REPEATER_METHOD_
(
OnTestProgramStart
,
UnitTest
)
GTEST_REPEATER_METHOD_
(
OnEnvironmentsSetUpStart
,
UnitTest
)
GTEST_REPEATER_METHOD_
(
OnTestCaseStart
,
TestCase
)
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REPEATER_METHOD_
(
OnTestCaseStart
,
TestSuite
)
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REPEATER_METHOD_
(
OnTestSuiteStart
,
TestSuite
)
GTEST_REPEATER_METHOD_
(
OnTestStart
,
TestInfo
)
GTEST_REPEATER_METHOD_
(
OnTestPartResult
,
TestPartResult
)
GTEST_REPEATER_METHOD_
(
OnEnvironmentsTearDownStart
,
UnitTest
)
GTEST_REVERSE_REPEATER_METHOD_
(
OnEnvironmentsSetUpEnd
,
UnitTest
)
GTEST_REVERSE_REPEATER_METHOD_
(
OnEnvironmentsTearDownEnd
,
UnitTest
)
GTEST_REVERSE_REPEATER_METHOD_
(
OnTestEnd
,
TestInfo
)
GTEST_REVERSE_REPEATER_METHOD_
(
OnTestCaseEnd
,
TestCase
)
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REVERSE_REPEATER_METHOD_
(
OnTestCaseEnd
,
TestSuite
)
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REVERSE_REPEATER_METHOD_
(
OnTestSuiteEnd
,
TestSuite
)
GTEST_REVERSE_REPEATER_METHOD_
(
OnTestProgramEnd
,
UnitTest
)
#undef GTEST_REPEATER_METHOD_
...
...
@@ -3442,11 +3464,11 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
explicit
XmlUnitTestResultPrinter
(
const
char
*
output_file
);
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
ListTestsMatchingFilter
(
const
std
::
vector
<
Test
Cas
e
*>&
test_
cas
es
);
void
ListTestsMatchingFilter
(
const
std
::
vector
<
Test
Suit
e
*>&
test_
suit
es
);
// Prints an XML summary of all unit tests.
static
void
PrintXmlTestsList
(
std
::
ostream
*
stream
,
const
std
::
vector
<
Test
Cas
e
*>&
test_
cas
es
);
const
std
::
vector
<
Test
Suit
e
*>&
test_
suit
es
);
private:
// Is c a whitespace character that is normalized to a space character
...
...
@@ -3491,12 +3513,12 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
// Streams an XML representation of a TestInfo object.
static
void
OutputXmlTestInfo
(
::
std
::
ostream
*
stream
,
const
char
*
test_
cas
e_name
,
const
char
*
test_
suit
e_name
,
const
TestInfo
&
test_info
);
// Prints an XML representation of a Test
Cas
e object
static
void
PrintXmlTest
Cas
e
(
::
std
::
ostream
*
stream
,
const
Test
Cas
e
&
test_
cas
e
);
// Prints an XML representation of a Test
Suit
e object
static
void
PrintXmlTest
Suit
e
(
::
std
::
ostream
*
stream
,
const
Test
Suit
e
&
test_
suit
e
);
// Prints an XML summary of unit_test to output stream out.
static
void
PrintXmlUnitTest
(
::
std
::
ostream
*
stream
,
...
...
@@ -3538,10 +3560,10 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
}
void
XmlUnitTestResultPrinter
::
ListTestsMatchingFilter
(
const
std
::
vector
<
Test
Cas
e
*>&
test_
cas
es
)
{
const
std
::
vector
<
Test
Suit
e
*>&
test_
suit
es
)
{
FILE
*
xmlout
=
OpenFileForWriting
(
output_file_
);
std
::
stringstream
stream
;
PrintXmlTestsList
(
&
stream
,
test_
cas
es
);
PrintXmlTestsList
(
&
stream
,
test_
suit
es
);
fprintf
(
xmlout
,
"%s"
,
StringStreamToString
(
&
stream
).
c_str
());
fclose
(
xmlout
);
}
...
...
@@ -3620,7 +3642,7 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
// This is how Google Test concepts map to the DTD:
//
// <testsuites name="AllTests"> <-- corresponds to a UnitTest object
// <testsuite name="testcase-name"> <-- corresponds to a Test
Cas
e object
// <testsuite name="testcase-name"> <-- corresponds to a Test
Suit
e object
// <testcase name="test-name"> <-- corresponds to a TestInfo object
// <failure message="...">...</failure>
// <failure message="...">...</failure>
...
...
@@ -3705,39 +3727,40 @@ void XmlUnitTestResultPrinter::OutputXmlAttribute(
// Prints an XML representation of a TestInfo object.
void
XmlUnitTestResultPrinter
::
OutputXmlTestInfo
(
::
std
::
ostream
*
stream
,
const
char
*
test_
cas
e_name
,
const
char
*
test_
suit
e_name
,
const
TestInfo
&
test_info
)
{
const
TestResult
&
result
=
*
test_info
.
result
();
const
std
::
string
kTest
cas
e
=
"testcase"
;
const
std
::
string
kTest
suit
e
=
"testcase"
;
if
(
test_info
.
is_in_another_shard
())
{
return
;
}
*
stream
<<
" <testcase"
;
OutputXmlAttribute
(
stream
,
kTest
cas
e
,
"name"
,
test_info
.
name
());
OutputXmlAttribute
(
stream
,
kTest
suit
e
,
"name"
,
test_info
.
name
());
if
(
test_info
.
value_param
()
!=
nullptr
)
{
OutputXmlAttribute
(
stream
,
kTest
cas
e
,
"value_param"
,
OutputXmlAttribute
(
stream
,
kTest
suit
e
,
"value_param"
,
test_info
.
value_param
());
}
if
(
test_info
.
type_param
()
!=
nullptr
)
{
OutputXmlAttribute
(
stream
,
kTestcase
,
"type_param"
,
test_info
.
type_param
());
OutputXmlAttribute
(
stream
,
kTestsuite
,
"type_param"
,
test_info
.
type_param
());
}
if
(
GTEST_FLAG
(
list_tests
))
{
OutputXmlAttribute
(
stream
,
kTest
cas
e
,
"file"
,
test_info
.
file
());
OutputXmlAttribute
(
stream
,
kTest
cas
e
,
"line"
,
OutputXmlAttribute
(
stream
,
kTest
suit
e
,
"file"
,
test_info
.
file
());
OutputXmlAttribute
(
stream
,
kTest
suit
e
,
"line"
,
StreamableToString
(
test_info
.
line
()));
*
stream
<<
" />
\n
"
;
return
;
}
OutputXmlAttribute
(
stream
,
kTestcase
,
"status"
,
result
.
Skipped
()
?
"skipped"
:
test_info
.
should_run
()
?
"run"
:
"notrun"
);
OutputXmlAttribute
(
stream
,
kTest
cas
e
,
"time"
,
OutputXmlAttribute
(
stream
,
kTestsuite
,
"status"
,
result
.
Skipped
()
?
"skipped"
:
test_info
.
should_run
()
?
"run"
:
"notrun"
);
OutputXmlAttribute
(
stream
,
kTest
suit
e
,
"time"
,
FormatTimeInMillisAsSeconds
(
result
.
elapsed_time
()));
OutputXmlAttribute
(
stream
,
kTest
cas
e
,
"classname"
,
test_
cas
e_name
);
OutputXmlAttribute
(
stream
,
kTest
suit
e
,
"classname"
,
test_
suit
e_name
);
int
failures
=
0
;
for
(
int
i
=
0
;
i
<
result
.
total_part_count
();
++
i
)
{
...
...
@@ -3770,29 +3793,29 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
}
}
// Prints an XML representation of a Test
Cas
e object
void
XmlUnitTestResultPrinter
::
PrintXmlTest
Cas
e
(
std
::
ostream
*
stream
,
const
Test
Cas
e
&
test_
cas
e
)
{
// Prints an XML representation of a Test
Suit
e object
void
XmlUnitTestResultPrinter
::
PrintXmlTest
Suit
e
(
std
::
ostream
*
stream
,
const
Test
Suit
e
&
test_
suit
e
)
{
const
std
::
string
kTestsuite
=
"testsuite"
;
*
stream
<<
" <"
<<
kTestsuite
;
OutputXmlAttribute
(
stream
,
kTestsuite
,
"name"
,
test_
cas
e
.
name
());
OutputXmlAttribute
(
stream
,
kTestsuite
,
"name"
,
test_
suit
e
.
name
());
OutputXmlAttribute
(
stream
,
kTestsuite
,
"tests"
,
StreamableToString
(
test_
cas
e
.
reportable_test_count
()));
StreamableToString
(
test_
suit
e
.
reportable_test_count
()));
if
(
!
GTEST_FLAG
(
list_tests
))
{
OutputXmlAttribute
(
stream
,
kTestsuite
,
"failures"
,
StreamableToString
(
test_
cas
e
.
failed_test_count
()));
StreamableToString
(
test_
suit
e
.
failed_test_count
()));
OutputXmlAttribute
(
stream
,
kTestsuite
,
"disabled"
,
StreamableToString
(
test_
cas
e
.
reportable_disabled_test_count
()));
StreamableToString
(
test_
suit
e
.
reportable_disabled_test_count
()));
OutputXmlAttribute
(
stream
,
kTestsuite
,
"errors"
,
"0"
);
OutputXmlAttribute
(
stream
,
kTestsuite
,
"time"
,
FormatTimeInMillisAsSeconds
(
test_
cas
e
.
elapsed_time
()));
*
stream
<<
TestPropertiesAsXmlAttributes
(
test_
cas
e
.
ad_hoc_test_result
());
FormatTimeInMillisAsSeconds
(
test_
suit
e
.
elapsed_time
()));
*
stream
<<
TestPropertiesAsXmlAttributes
(
test_
suit
e
.
ad_hoc_test_result
());
}
*
stream
<<
">
\n
"
;
for
(
int
i
=
0
;
i
<
test_
cas
e
.
total_test_count
();
++
i
)
{
if
(
test_
cas
e
.
GetTestInfo
(
i
)
->
is_reportable
())
OutputXmlTestInfo
(
stream
,
test_
cas
e
.
name
(),
*
test_
cas
e
.
GetTestInfo
(
i
));
for
(
int
i
=
0
;
i
<
test_
suit
e
.
total_test_count
();
++
i
)
{
if
(
test_
suit
e
.
GetTestInfo
(
i
)
->
is_reportable
())
OutputXmlTestInfo
(
stream
,
test_
suit
e
.
name
(),
*
test_
suit
e
.
GetTestInfo
(
i
));
}
*
stream
<<
" </"
<<
kTestsuite
<<
">
\n
"
;
}
...
...
@@ -3828,31 +3851,31 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
OutputXmlAttribute
(
stream
,
kTestsuites
,
"name"
,
"AllTests"
);
*
stream
<<
">
\n
"
;
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
cas
e_count
();
++
i
)
{
if
(
unit_test
.
GetTest
Cas
e
(
i
)
->
reportable_test_count
()
>
0
)
PrintXmlTest
Cas
e
(
stream
,
*
unit_test
.
GetTest
Cas
e
(
i
));
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
suit
e_count
();
++
i
)
{
if
(
unit_test
.
GetTest
Suit
e
(
i
)
->
reportable_test_count
()
>
0
)
PrintXmlTest
Suit
e
(
stream
,
*
unit_test
.
GetTest
Suit
e
(
i
));
}
*
stream
<<
"</"
<<
kTestsuites
<<
">
\n
"
;
}
void
XmlUnitTestResultPrinter
::
PrintXmlTestsList
(
std
::
ostream
*
stream
,
const
std
::
vector
<
Test
Cas
e
*>&
test_
cas
es
)
{
std
::
ostream
*
stream
,
const
std
::
vector
<
Test
Suit
e
*>&
test_
suit
es
)
{
const
std
::
string
kTestsuites
=
"testsuites"
;
*
stream
<<
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
"
;
*
stream
<<
"<"
<<
kTestsuites
;
int
total_tests
=
0
;
for
(
size_t
i
=
0
;
i
<
test_cases
.
size
();
++
i
)
{
total_tests
+=
test_
cases
[
i
]
->
total_test_count
();
for
(
auto
test_suite
:
test_suites
)
{
total_tests
+=
test_
suite
->
total_test_count
();
}
OutputXmlAttribute
(
stream
,
kTestsuites
,
"tests"
,
StreamableToString
(
total_tests
));
OutputXmlAttribute
(
stream
,
kTestsuites
,
"name"
,
"AllTests"
);
*
stream
<<
">
\n
"
;
for
(
size_t
i
=
0
;
i
<
test_cases
.
size
();
++
i
)
{
PrintXmlTest
Cas
e
(
stream
,
*
test_
cases
[
i
]
);
for
(
auto
test_suite
:
test_suites
)
{
PrintXmlTest
Suit
e
(
stream
,
*
test_
suite
);
}
*
stream
<<
"</"
<<
kTestsuites
<<
">
\n
"
;
}
...
...
@@ -3901,7 +3924,7 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener {
// Prints an JSON summary of all unit tests.
static
void
PrintJsonTestList
(
::
std
::
ostream
*
stream
,
const
std
::
vector
<
Test
Cas
e
*>&
test_
cas
es
);
const
std
::
vector
<
Test
Suit
e
*>&
test_
suit
es
);
private:
// Returns an JSON-escaped copy of the input string str.
...
...
@@ -3924,12 +3947,12 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener {
// Streams a JSON representation of a TestInfo object.
static
void
OutputJsonTestInfo
(
::
std
::
ostream
*
stream
,
const
char
*
test_
cas
e_name
,
const
char
*
test_
suit
e_name
,
const
TestInfo
&
test_info
);
// Prints a JSON representation of a Test
Cas
e object
static
void
PrintJsonTest
Cas
e
(
::
std
::
ostream
*
stream
,
const
Test
Cas
e
&
test_
cas
e
);
// Prints a JSON representation of a Test
Suit
e object
static
void
PrintJsonTest
Suit
e
(
::
std
::
ostream
*
stream
,
const
Test
Suit
e
&
test_
suit
e
);
// Prints a JSON summary of unit_test to output stream out.
static
void
PrintJsonUnitTest
(
::
std
::
ostream
*
stream
,
...
...
@@ -4074,36 +4097,38 @@ void JsonUnitTestResultPrinter::OutputJsonKey(
// Prints a JSON representation of a TestInfo object.
void
JsonUnitTestResultPrinter
::
OutputJsonTestInfo
(
::
std
::
ostream
*
stream
,
const
char
*
test_
cas
e_name
,
const
char
*
test_
suit
e_name
,
const
TestInfo
&
test_info
)
{
const
TestResult
&
result
=
*
test_info
.
result
();
const
std
::
string
kTest
cas
e
=
"testcase"
;
const
std
::
string
kTest
suit
e
=
"testcase"
;
const
std
::
string
kIndent
=
Indent
(
10
);
*
stream
<<
Indent
(
8
)
<<
"{
\n
"
;
OutputJsonKey
(
stream
,
kTest
cas
e
,
"name"
,
test_info
.
name
(),
kIndent
);
OutputJsonKey
(
stream
,
kTest
suit
e
,
"name"
,
test_info
.
name
(),
kIndent
);
if
(
test_info
.
value_param
()
!=
nullptr
)
{
OutputJsonKey
(
stream
,
kTest
cas
e
,
"value_param"
,
test_info
.
value_param
(),
kIndent
);
OutputJsonKey
(
stream
,
kTest
suit
e
,
"value_param"
,
test_info
.
value_param
(),
kIndent
);
}
if
(
test_info
.
type_param
()
!=
nullptr
)
{
OutputJsonKey
(
stream
,
kTest
cas
e
,
"type_param"
,
test_info
.
type_param
(),
OutputJsonKey
(
stream
,
kTest
suit
e
,
"type_param"
,
test_info
.
type_param
(),
kIndent
);
}
if
(
GTEST_FLAG
(
list_tests
))
{
OutputJsonKey
(
stream
,
kTest
cas
e
,
"file"
,
test_info
.
file
(),
kIndent
);
OutputJsonKey
(
stream
,
kTest
cas
e
,
"line"
,
test_info
.
line
(),
kIndent
,
false
);
OutputJsonKey
(
stream
,
kTest
suit
e
,
"file"
,
test_info
.
file
(),
kIndent
);
OutputJsonKey
(
stream
,
kTest
suit
e
,
"line"
,
test_info
.
line
(),
kIndent
,
false
);
*
stream
<<
"
\n
"
<<
Indent
(
8
)
<<
"}"
;
return
;
}
OutputJsonKey
(
stream
,
kTestcase
,
"status"
,
result
.
Skipped
()
?
"SKIPPED"
:
test_info
.
should_run
()
?
"RUN"
:
"NOTRUN"
,
kIndent
);
OutputJsonKey
(
stream
,
kTestcase
,
"time"
,
OutputJsonKey
(
stream
,
kTestsuite
,
"status"
,
result
.
Skipped
()
?
"SKIPPED"
:
test_info
.
should_run
()
?
"RUN"
:
"NOTRUN"
,
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"time"
,
FormatTimeInMillisAsDuration
(
result
.
elapsed_time
()),
kIndent
);
OutputJsonKey
(
stream
,
kTestcase
,
"classname"
,
test_case_name
,
kIndent
,
false
);
OutputJsonKey
(
stream
,
kTestsuite
,
"classname"
,
test_suite_name
,
kIndent
,
false
);
*
stream
<<
TestPropertiesAsJson
(
result
,
kIndent
);
int
failures
=
0
;
...
...
@@ -4130,40 +4155,40 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
*
stream
<<
"
\n
"
<<
Indent
(
8
)
<<
"}"
;
}
// Prints an JSON representation of a Test
Cas
e object
void
JsonUnitTestResultPrinter
::
PrintJsonTest
Case
(
std
::
ostream
*
stream
,
const
Test
Cas
e
&
test_
cas
e
)
{
// Prints an JSON representation of a Test
Suit
e object
void
JsonUnitTestResultPrinter
::
PrintJsonTest
Suite
(
std
::
ostream
*
stream
,
const
Test
Suit
e
&
test_
suit
e
)
{
const
std
::
string
kTestsuite
=
"testsuite"
;
const
std
::
string
kIndent
=
Indent
(
6
);
*
stream
<<
Indent
(
4
)
<<
"{
\n
"
;
OutputJsonKey
(
stream
,
kTestsuite
,
"name"
,
test_
cas
e
.
name
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"tests"
,
test_
cas
e
.
reportable_test_count
(),
OutputJsonKey
(
stream
,
kTestsuite
,
"name"
,
test_
suit
e
.
name
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"tests"
,
test_
suit
e
.
reportable_test_count
(),
kIndent
);
if
(
!
GTEST_FLAG
(
list_tests
))
{
OutputJsonKey
(
stream
,
kTestsuite
,
"failures"
,
test_case
.
failed_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"failures"
,
test_suite
.
failed_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"disabled"
,
test_
cas
e
.
reportable_disabled_test_count
(),
kIndent
);
test_
suit
e
.
reportable_disabled_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"errors"
,
0
,
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"time"
,
FormatTimeInMillisAsDuration
(
test_
cas
e
.
elapsed_time
()),
FormatTimeInMillisAsDuration
(
test_
suit
e
.
elapsed_time
()),
kIndent
,
false
);
*
stream
<<
TestPropertiesAsJson
(
test_
cas
e
.
ad_hoc_test_result
(),
kIndent
)
*
stream
<<
TestPropertiesAsJson
(
test_
suit
e
.
ad_hoc_test_result
(),
kIndent
)
<<
",
\n
"
;
}
*
stream
<<
kIndent
<<
"
\"
"
<<
kTestsuite
<<
"
\"
: [
\n
"
;
bool
comma
=
false
;
for
(
int
i
=
0
;
i
<
test_
cas
e
.
total_test_count
();
++
i
)
{
if
(
test_
cas
e
.
GetTestInfo
(
i
)
->
is_reportable
())
{
for
(
int
i
=
0
;
i
<
test_
suit
e
.
total_test_count
();
++
i
)
{
if
(
test_
suit
e
.
GetTestInfo
(
i
)
->
is_reportable
())
{
if
(
comma
)
{
*
stream
<<
",
\n
"
;
}
else
{
comma
=
true
;
}
OutputJsonTestInfo
(
stream
,
test_
cas
e
.
name
(),
*
test_
cas
e
.
GetTestInfo
(
i
));
OutputJsonTestInfo
(
stream
,
test_
suit
e
.
name
(),
*
test_
suit
e
.
GetTestInfo
(
i
));
}
}
*
stream
<<
"
\n
"
<<
kIndent
<<
"]
\n
"
<<
Indent
(
4
)
<<
"}"
;
...
...
@@ -4201,14 +4226,14 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
*
stream
<<
kIndent
<<
"
\"
"
<<
kTestsuites
<<
"
\"
: [
\n
"
;
bool
comma
=
false
;
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
cas
e_count
();
++
i
)
{
if
(
unit_test
.
GetTest
Cas
e
(
i
)
->
reportable_test_count
()
>
0
)
{
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_
suit
e_count
();
++
i
)
{
if
(
unit_test
.
GetTest
Suit
e
(
i
)
->
reportable_test_count
()
>
0
)
{
if
(
comma
)
{
*
stream
<<
",
\n
"
;
}
else
{
comma
=
true
;
}
PrintJsonTest
Cas
e
(
stream
,
*
unit_test
.
GetTest
Cas
e
(
i
));
PrintJsonTest
Suit
e
(
stream
,
*
unit_test
.
GetTest
Suit
e
(
i
));
}
}
...
...
@@ -4216,24 +4241,24 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
}
void
JsonUnitTestResultPrinter
::
PrintJsonTestList
(
std
::
ostream
*
stream
,
const
std
::
vector
<
Test
Cas
e
*>&
test_
cas
es
)
{
std
::
ostream
*
stream
,
const
std
::
vector
<
Test
Suit
e
*>&
test_
suit
es
)
{
const
std
::
string
kTestsuites
=
"testsuites"
;
const
std
::
string
kIndent
=
Indent
(
2
);
*
stream
<<
"{
\n
"
;
int
total_tests
=
0
;
for
(
size_t
i
=
0
;
i
<
test_cases
.
size
();
++
i
)
{
total_tests
+=
test_
cases
[
i
]
->
total_test_count
();
for
(
auto
test_suite
:
test_suites
)
{
total_tests
+=
test_
suite
->
total_test_count
();
}
OutputJsonKey
(
stream
,
kTestsuites
,
"tests"
,
total_tests
,
kIndent
);
OutputJsonKey
(
stream
,
kTestsuites
,
"name"
,
"AllTests"
,
kIndent
);
*
stream
<<
kIndent
<<
"
\"
"
<<
kTestsuites
<<
"
\"
: [
\n
"
;
for
(
size_t
i
=
0
;
i
<
test_
cas
es
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
test_
suit
es
.
size
();
++
i
)
{
if
(
i
!=
0
)
{
*
stream
<<
",
\n
"
;
}
PrintJsonTest
Cas
e
(
stream
,
*
test_
cas
es
[
i
]);
PrintJsonTest
Suit
e
(
stream
,
*
test_
suit
es
[
i
]);
}
*
stream
<<
"
\n
"
...
...
@@ -4524,26 +4549,42 @@ UnitTest* UnitTest::GetInstance() {
#endif // defined(__BORLANDC__)
}
// Gets the number of successful test
cas
es.
int
UnitTest
::
successful_test_
cas
e_count
()
const
{
return
impl
()
->
successful_test_
cas
e_count
();
// Gets the number of successful test
suit
es.
int
UnitTest
::
successful_test_
suit
e_count
()
const
{
return
impl
()
->
successful_test_
suit
e_count
();
}
// Gets the number of failed test
cas
es.
int
UnitTest
::
failed_test_
cas
e_count
()
const
{
return
impl
()
->
failed_test_
cas
e_count
();
// Gets the number of failed test
suit
es.
int
UnitTest
::
failed_test_
suit
e_count
()
const
{
return
impl
()
->
failed_test_
suit
e_count
();
}
// Gets the number of all test
cas
es.
int
UnitTest
::
total_test_
cas
e_count
()
const
{
return
impl
()
->
total_test_
cas
e_count
();
// Gets the number of all test
suit
es.
int
UnitTest
::
total_test_
suit
e_count
()
const
{
return
impl
()
->
total_test_
suit
e_count
();
}
// Gets the number of all test
cas
es that contain at least one test
// Gets the number of all test
suit
es that contain at least one test
// that should run.
int
UnitTest
::
test_suite_to_run_count
()
const
{
return
impl
()
->
test_suite_to_run_count
();
}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
int
UnitTest
::
successful_test_case_count
()
const
{
return
impl
()
->
successful_test_suite_count
();
}
int
UnitTest
::
failed_test_case_count
()
const
{
return
impl
()
->
failed_test_suite_count
();
}
int
UnitTest
::
total_test_case_count
()
const
{
return
impl
()
->
total_test_suite_count
();
}
int
UnitTest
::
test_case_to_run_count
()
const
{
return
impl
()
->
test_
cas
e_to_run_count
();
return
impl
()
->
test_
suit
e_to_run_count
();
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Gets the number of successful tests.
int
UnitTest
::
successful_test_count
()
const
{
...
...
@@ -4590,29 +4631,36 @@ internal::TimeInMillis UnitTest::elapsed_time() const {
return
impl
()
->
elapsed_time
();
}
// Returns true iff the unit test passed (i.e. all test
cas
es passed).
// Returns true iff the unit test passed (i.e. all test
suit
es passed).
bool
UnitTest
::
Passed
()
const
{
return
impl
()
->
Passed
();
}
// Returns true iff the unit test failed (i.e. some test
cas
e failed
// Returns true iff the unit test failed (i.e. some test
suit
e failed
// or something outside of all tests failed).
bool
UnitTest
::
Failed
()
const
{
return
impl
()
->
Failed
();
}
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
// Gets the i-th test suite among all the test suites. i can range from 0 to
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
const
TestSuite
*
UnitTest
::
GetTestSuite
(
int
i
)
const
{
return
impl
()
->
GetTestSuite
(
i
);
}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const
TestCase
*
UnitTest
::
GetTestCase
(
int
i
)
const
{
return
impl
()
->
GetTestCase
(
i
);
}
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Returns the TestResult containing information on test failures and
// properties logged outside of individual test
cas
es.
// properties logged outside of individual test
suit
es.
const
TestResult
&
UnitTest
::
ad_hoc_test_result
()
const
{
return
*
impl
()
->
ad_hoc_test_result
();
}
// Gets the i-th test
cas
e among all the test
cas
es. i can range from 0 to
// total_test_
cas
e_count() - 1. If i is not in that range, returns NULL.
Test
Cas
e
*
UnitTest
::
GetMutableTest
Cas
e
(
int
i
)
{
return
impl
()
->
GetMutable
Test
Case
(
i
);
// Gets the i-th test
suit
e among all the test
suit
es. i can range from 0 to
// total_test_
suit
e_count() - 1. If i is not in that range, returns NULL.
Test
Suit
e
*
UnitTest
::
GetMutableTest
Suit
e
(
int
i
)
{
return
impl
()
->
GetMutable
Suite
Case
(
i
);
}
// Returns the list of event listeners that can be used to track events
...
...
@@ -4711,8 +4759,8 @@ void UnitTest::AddTestPartResult(
}
// Adds a TestProperty to the current TestResult object when invoked from
// inside a test, to current Test
Cas
e's ad_hoc_test_result_ when invoked
// from SetUpTest
Cas
e or TearDownTest
Cas
e, or to the global property set
// inside a test, to current Test
Suit
e's ad_hoc_test_result_ when invoked
// from SetUpTest
Suit
e or TearDownTest
Suit
e, or to the global property set
// when invoked elsewhere. If the result already contains a property with
// the same key, the value will be updated.
void
UnitTest
::
RecordProperty
(
const
std
::
string
&
key
,
...
...
@@ -4804,13 +4852,22 @@ const char* UnitTest::original_working_dir() const {
return
impl_
->
original_working_dir_
.
c_str
();
}
// Returns the Test
Cas
e object for the test that's currently running,
// Returns the Test
Suit
e object for the test that's currently running,
// or NULL if no test is running.
const
TestSuite
*
UnitTest
::
current_test_suite
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
MutexLock
lock
(
&
mutex_
);
return
impl_
->
current_test_suite
();
}
// Legacy API is still available but deprecated
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const
TestCase
*
UnitTest
::
current_test_case
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
MutexLock
lock
(
&
mutex_
);
return
impl_
->
current_test_
cas
e
();
return
impl_
->
current_test_
suit
e
();
}
#endif
// Returns the TestInfo object for the test that's currently running,
// or NULL if no test is running.
...
...
@@ -4823,11 +4880,10 @@ const TestInfo* UnitTest::current_test_info() const
// Returns the random seed used at the start of the current test run.
int
UnitTest
::
random_seed
()
const
{
return
impl_
->
random_seed
();
}
// Returns ParameterizedTest
Cas
eRegistry object used to keep track of
// Returns ParameterizedTest
Suit
eRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
internal
::
ParameterizedTestCaseRegistry
&
UnitTest
::
parameterized_test_registry
()
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
ParameterizedTestSuiteRegistry
&
UnitTest
::
parameterized_test_registry
()
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
return
impl_
->
parameterized_test_registry
();
}
...
...
@@ -4869,8 +4925,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
&
default_per_thread_test_part_result_reporter_
),
parameterized_test_registry_
(),
parameterized_tests_registered_
(
false
),
last_death_test_
cas
e_
(
-
1
),
current_test_
cas
e_
(
nullptr
),
last_death_test_
suit
e_
(
-
1
),
current_test_
suit
e_
(
nullptr
),
current_test_info_
(
nullptr
),
ad_hoc_test_result_
(),
os_stack_trace_getter_
(
nullptr
),
...
...
@@ -4888,8 +4944,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
}
UnitTestImpl
::~
UnitTestImpl
()
{
// Deletes every Test
Cas
e.
ForEach
(
test_
cas
es_
,
internal
::
Delete
<
Test
Cas
e
>
);
// Deletes every Test
Suit
e.
ForEach
(
test_
suit
es_
,
internal
::
Delete
<
Test
Suit
e
>
);
// Deletes every Environment.
ForEach
(
environments_
,
internal
::
Delete
<
Environment
>
);
...
...
@@ -4898,8 +4954,8 @@ UnitTestImpl::~UnitTestImpl() {
}
// Adds a TestProperty to the current TestResult object when invoked in a
// context of a test, to current test
cas
e's ad_hoc_test_result when invoke
// from SetUpTest
Cas
e/TearDownTest
Cas
e, or to the global property set
// context of a test, to current test
suit
e's ad_hoc_test_result when invoke
// from SetUpTest
Suit
e/TearDownTest
Suit
e, or to the global property set
// otherwise. If the result already contains a property with the same key,
// the value will be updated.
void
UnitTestImpl
::
RecordProperty
(
const
TestProperty
&
test_property
)
{
...
...
@@ -4909,9 +4965,9 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
if
(
current_test_info_
!=
nullptr
)
{
xml_element
=
"testcase"
;
test_result
=
&
(
current_test_info_
->
result_
);
}
else
if
(
current_test_
cas
e_
!=
nullptr
)
{
}
else
if
(
current_test_
suit
e_
!=
nullptr
)
{
xml_element
=
"testsuite"
;
test_result
=
&
(
current_test_
cas
e_
->
ad_hoc_test_result_
);
test_result
=
&
(
current_test_
suit
e_
->
ad_hoc_test_result_
);
}
else
{
xml_element
=
"testsuites"
;
test_result
=
&
ad_hoc_test_result_
;
...
...
@@ -5005,75 +5061,73 @@ void UnitTestImpl::PostFlagParsingInit() {
}
}
// A predicate that checks the name of a Test
Cas
e against a known
// A predicate that checks the name of a Test
Suit
e against a known
// value.
//
// This is used for implementation of the UnitTest class only. We put
// it in the anonymous namespace to prevent polluting the outer
// namespace.
//
// Test
Cas
eNameIs is copyable.
class
Test
Cas
eNameIs
{
// Test
Suit
eNameIs is copyable.
class
Test
Suit
eNameIs
{
public:
// Constructor.
explicit
TestCaseNameIs
(
const
std
::
string
&
name
)
:
name_
(
name
)
{}
explicit
TestSuiteNameIs
(
const
std
::
string
&
name
)
:
name_
(
name
)
{}
// Returns true iff the name of test_
cas
e matches name_.
bool
operator
()(
const
Test
Cas
e
*
test_
cas
e
)
const
{
return
test_
cas
e
!=
nullptr
&&
strcmp
(
test_
cas
e
->
name
(),
name_
.
c_str
())
==
0
;
// Returns true iff the name of test_
suit
e matches name_.
bool
operator
()(
const
Test
Suit
e
*
test_
suit
e
)
const
{
return
test_
suit
e
!=
nullptr
&&
strcmp
(
test_
suit
e
->
name
(),
name_
.
c_str
())
==
0
;
}
private:
std
::
string
name_
;
};
// Finds and returns a Test
Cas
e with the given name. If one doesn't
// Finds and returns a Test
Suit
e with the given name. If one doesn't
// exist, creates one and returns it. It's the CALLER'S
// RESPONSIBILITY to ensure that this function is only called WHEN THE
// TESTS ARE NOT SHUFFLED.
//
// Arguments:
//
// test_case_name: name of the test case
// type_param: the name of the test case's type parameter, or NULL if
// this is not a typed or a type-parameterized test case.
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
TestCase
*
UnitTestImpl
::
GetTestCase
(
const
char
*
test_case_name
,
const
char
*
type_param
,
Test
::
SetUpTestCaseFunc
set_up_tc
,
Test
::
TearDownTestCaseFunc
tear_down_tc
)
{
// Can we find a TestCase with the given name?
const
std
::
vector
<
TestCase
*>::
const_reverse_iterator
test_case
=
std
::
find_if
(
test_cases_
.
rbegin
(),
test_cases_
.
rend
(),
TestCaseNameIs
(
test_case_name
));
if
(
test_case
!=
test_cases_
.
rend
())
return
*
test_case
;
// test_suite_name: name of the test suite
// type_param: the name of the test suite's type parameter, or NULL if
// this is not a typed or a type-parameterized test suite.
// set_up_tc: pointer to the function that sets up the test suite
// tear_down_tc: pointer to the function that tears down the test suite
TestSuite
*
UnitTestImpl
::
GetTestSuite
(
const
char
*
test_suite_name
,
const
char
*
type_param
,
internal
::
SetUpTestSuiteFunc
set_up_tc
,
internal
::
TearDownTestSuiteFunc
tear_down_tc
)
{
// Can we find a TestSuite with the given name?
const
auto
test_suite
=
std
::
find_if
(
test_suites_
.
rbegin
(),
test_suites_
.
rend
(),
TestSuiteNameIs
(
test_suite_name
));
if
(
test_suite
!=
test_suites_
.
rend
())
return
*
test_suite
;
// No. Let's create one.
TestCase
*
const
new_test_
cas
e
=
new
Test
Cas
e
(
test_
cas
e_name
,
type_param
,
set_up_tc
,
tear_down_tc
);
// Is this a death test
cas
e?
if
(
internal
::
UnitTestOptions
::
MatchesFilter
(
test_
cas
e_name
,
kDeathTest
Cas
eFilter
))
{
// Yes. Inserts the test
cas
e after the last death test
cas
e
// defined so far. This only works when the test
cas
es haven't
auto
*
const
new_test_
suit
e
=
new
Test
Suit
e
(
test_
suit
e_name
,
type_param
,
set_up_tc
,
tear_down_tc
);
// Is this a death test
suit
e?
if
(
internal
::
UnitTestOptions
::
MatchesFilter
(
test_
suit
e_name
,
kDeathTest
Suit
eFilter
))
{
// Yes. Inserts the test
suit
e after the last death test
suit
e
// defined so far. This only works when the test
suit
es haven't
// been shuffled. Otherwise we may end up running a death test
// after a non-death test.
++
last_death_test_
cas
e_
;
test_
cas
es_
.
insert
(
test_
cas
es_
.
begin
()
+
last_death_test_
cas
e_
,
new_test_
cas
e
);
++
last_death_test_
suit
e_
;
test_
suit
es_
.
insert
(
test_
suit
es_
.
begin
()
+
last_death_test_
suit
e_
,
new_test_
suit
e
);
}
else
{
// No. Appends to the end of the list.
test_
cas
es_
.
push_back
(
new_test_
cas
e
);
test_
suit
es_
.
push_back
(
new_test_
suit
e
);
}
test_
cas
e_indices_
.
push_back
(
static_cast
<
int
>
(
test_
cas
e_indices_
.
size
()));
return
new_test_
cas
e
;
test_
suit
e_indices_
.
push_back
(
static_cast
<
int
>
(
test_
suit
e_indices_
.
size
()));
return
new_test_
suit
e
;
}
// Helpers for setting up / tearing down the given environment. They
...
...
@@ -5160,7 +5214,7 @@ bool UnitTestImpl::RunAllTests() {
const
TimeInMillis
start
=
GetTimeInMillis
();
// Shuffles test
cas
es and tests if requested.
// Shuffles test
suit
es and tests if requested.
if
(
has_tests_to_run
&&
GTEST_FLAG
(
shuffle
))
{
random
()
->
Reseed
(
random_seed_
);
// This should be done before calling OnTestIterationStart(),
...
...
@@ -5172,7 +5226,7 @@ bool UnitTestImpl::RunAllTests() {
// Tells the unit test event listeners that the tests are about to start.
repeater
->
OnTestIterationStart
(
*
parent_
,
i
);
// Runs each test
cas
e if there is at least one test to run.
// Runs each test
suit
e if there is at least one test to run.
if
(
has_tests_to_run
)
{
// Sets up all environments beforehand.
repeater
->
OnEnvironmentsSetUpStart
(
*
parent_
);
...
...
@@ -5182,9 +5236,9 @@ bool UnitTestImpl::RunAllTests() {
// Runs the tests only if there was no fatal failure during global
// set-up.
if
(
!
Test
::
HasFatalFailure
())
{
for
(
int
test_index
=
0
;
test_index
<
total_test_
cas
e_count
();
for
(
int
test_index
=
0
;
test_index
<
total_test_
suit
e_count
();
test_index
++
)
{
GetMutable
Test
Case
(
test_index
)
->
Run
();
GetMutable
Suite
Case
(
test_index
)
->
Run
();
}
}
...
...
@@ -5333,7 +5387,7 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {
// Compares the name of each test with the user-specified filter to
// decide whether the test should be run, then records the result in
// each Test
Cas
e and TestInfo object.
// each Test
Suit
e and TestInfo object.
// If shard_tests == true, further filters tests based on sharding
// variables in the environment - see
// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md
...
...
@@ -5350,26 +5404,23 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
// this shard.
int
num_runnable_tests
=
0
;
int
num_selected_tests
=
0
;
for
(
size_t
i
=
0
;
i
<
test_cases_
.
size
();
i
++
)
{
TestCase
*
const
test_case
=
test_cases_
[
i
];
const
std
::
string
&
test_case_name
=
test_case
->
name
();
test_case
->
set_should_run
(
false
);
for
(
auto
*
test_suite
:
test_suites_
)
{
const
std
::
string
&
test_suite_name
=
test_suite
->
name
();
test_suite
->
set_should_run
(
false
);
for
(
size_t
j
=
0
;
j
<
test_
cas
e
->
test_info_list
().
size
();
j
++
)
{
TestInfo
*
const
test_info
=
test_
cas
e
->
test_info_list
()[
j
];
for
(
size_t
j
=
0
;
j
<
test_
suit
e
->
test_info_list
().
size
();
j
++
)
{
TestInfo
*
const
test_info
=
test_
suit
e
->
test_info_list
()[
j
];
const
std
::
string
test_name
(
test_info
->
name
());
// A test is disabled if test
cas
e name or test name matches
// A test is disabled if test
suit
e name or test name matches
// kDisableTestFilter.
const
bool
is_disabled
=
internal
::
UnitTestOptions
::
MatchesFilter
(
test_case_name
,
kDisableTestFilter
)
||
internal
::
UnitTestOptions
::
MatchesFilter
(
test_name
,
kDisableTestFilter
);
const
bool
is_disabled
=
internal
::
UnitTestOptions
::
MatchesFilter
(
test_suite_name
,
kDisableTestFilter
)
||
internal
::
UnitTestOptions
::
MatchesFilter
(
test_name
,
kDisableTestFilter
);
test_info
->
is_disabled_
=
is_disabled
;
const
bool
matches_filter
=
internal
::
UnitTestOptions
::
FilterMatchesTest
(
test_case_name
,
test_name
);
const
bool
matches_filter
=
internal
::
UnitTestOptions
::
FilterMatchesTest
(
test_suite_name
,
test_name
);
test_info
->
matches_filter_
=
matches_filter
;
const
bool
is_runnable
=
...
...
@@ -5386,7 +5437,7 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
num_selected_tests
+=
is_selected
;
test_info
->
should_run_
=
is_selected
;
test_
cas
e
->
set_should_run
(
test_
cas
e
->
should_run
()
||
is_selected
);
test_
suit
e
->
set_should_run
(
test_
suit
e
->
should_run
()
||
is_selected
);
}
}
return
num_selected_tests
;
...
...
@@ -5419,22 +5470,20 @@ void UnitTestImpl::ListTestsMatchingFilter() {
// Print at most this many characters for each type/value parameter.
const
int
kMaxParamLength
=
250
;
for
(
size_t
i
=
0
;
i
<
test_cases_
.
size
();
i
++
)
{
const
TestCase
*
const
test_case
=
test_cases_
[
i
];
bool
printed_test_case_name
=
false
;
for
(
auto
*
test_suite
:
test_suites_
)
{
bool
printed_test_suite_name
=
false
;
for
(
size_t
j
=
0
;
j
<
test_case
->
test_info_list
().
size
();
j
++
)
{
const
TestInfo
*
const
test_info
=
test_case
->
test_info_list
()[
j
];
for
(
size_t
j
=
0
;
j
<
test_suite
->
test_info_list
().
size
();
j
++
)
{
const
TestInfo
*
const
test_info
=
test_suite
->
test_info_list
()[
j
];
if
(
test_info
->
matches_filter_
)
{
if
(
!
printed_test_
cas
e_name
)
{
printed_test_
cas
e_name
=
true
;
printf
(
"%s."
,
test_
cas
e
->
name
());
if
(
test_
cas
e
->
type_param
()
!=
nullptr
)
{
if
(
!
printed_test_
suit
e_name
)
{
printed_test_
suit
e_name
=
true
;
printf
(
"%s."
,
test_
suit
e
->
name
());
if
(
test_
suit
e
->
type_param
()
!=
nullptr
)
{
printf
(
" # %s = "
,
kTypeParamLabel
);
// We print the type parameter on a single line to make
// the output easy to parse by a program.
PrintOnOneLine
(
test_
cas
e
->
type_param
(),
kMaxParamLength
);
PrintOnOneLine
(
test_
suit
e
->
type_param
(),
kMaxParamLength
);
}
printf
(
"
\n
"
);
}
...
...
@@ -5458,11 +5507,11 @@ void UnitTestImpl::ListTestsMatchingFilter() {
if
(
output_format
==
"xml"
)
{
XmlUnitTestResultPrinter
(
UnitTestOptions
::
GetAbsolutePathToOutputFile
().
c_str
())
.
PrintXmlTestsList
(
&
stream
,
test_
cas
es_
);
.
PrintXmlTestsList
(
&
stream
,
test_
suit
es_
);
}
else
if
(
output_format
==
"json"
)
{
JsonUnitTestResultPrinter
(
UnitTestOptions
::
GetAbsolutePathToOutputFile
().
c_str
())
.
PrintJsonTestList
(
&
stream
,
test_
cas
es_
);
.
PrintJsonTestList
(
&
stream
,
test_
suit
es_
);
}
fprintf
(
fileout
,
"%s"
,
StringStreamToString
(
&
stream
).
c_str
());
fclose
(
fileout
);
...
...
@@ -5502,35 +5551,35 @@ TestResult* UnitTestImpl::current_test_result() {
if
(
current_test_info_
!=
nullptr
)
{
return
&
current_test_info_
->
result_
;
}
if
(
current_test_
cas
e_
!=
nullptr
)
{
return
&
current_test_
cas
e_
->
ad_hoc_test_result_
;
if
(
current_test_
suit
e_
!=
nullptr
)
{
return
&
current_test_
suit
e_
->
ad_hoc_test_result_
;
}
return
&
ad_hoc_test_result_
;
}
// Shuffles all test
cas
es, and the tests within each test
cas
e,
// Shuffles all test
suit
es, and the tests within each test
suit
e,
// making sure that death tests are still run first.
void
UnitTestImpl
::
ShuffleTests
()
{
// Shuffles the death test
cas
es.
ShuffleRange
(
random
(),
0
,
last_death_test_
cas
e_
+
1
,
&
test_
cas
e_indices_
);
// Shuffles the death test
suit
es.
ShuffleRange
(
random
(),
0
,
last_death_test_
suit
e_
+
1
,
&
test_
suit
e_indices_
);
// Shuffles the non-death test
cas
es.
ShuffleRange
(
random
(),
last_death_test_
cas
e_
+
1
,
static_cast
<
int
>
(
test_
cas
es_
.
size
()),
&
test_
cas
e_indices_
);
// Shuffles the non-death test
suit
es.
ShuffleRange
(
random
(),
last_death_test_
suit
e_
+
1
,
static_cast
<
int
>
(
test_
suit
es_
.
size
()),
&
test_
suit
e_indices_
);
// Shuffles the tests inside each test
cas
e.
for
(
size_t
i
=
0
;
i
<
test_cases_
.
size
();
i
++
)
{
test_
cases_
[
i
]
->
ShuffleTests
(
random
());
// Shuffles the tests inside each test
suit
e.
for
(
auto
&
test_suite
:
test_suites_
)
{
test_
suite
->
ShuffleTests
(
random
());
}
}
// Restores the test
cas
es and tests to their order before the first shuffle.
// Restores the test
suit
es and tests to their order before the first shuffle.
void
UnitTestImpl
::
UnshuffleTests
()
{
for
(
size_t
i
=
0
;
i
<
test_
cas
es_
.
size
();
i
++
)
{
// Unshuffles the tests in each test
cas
e.
test_
cas
es_
[
i
]
->
UnshuffleTests
();
// Resets the index of each test
cas
e.
test_
cas
e_indices_
[
i
]
=
static_cast
<
int
>
(
i
);
for
(
size_t
i
=
0
;
i
<
test_
suit
es_
.
size
();
i
++
)
{
// Unshuffles the tests in each test
suit
e.
test_
suit
es_
[
i
]
->
UnshuffleTests
();
// Resets the index of each test
suit
e.
test_
suit
e_indices_
[
i
]
=
static_cast
<
int
>
(
i
);
}
}
...
...
googletest/test/googletest-catch-exceptions-test.py
View file @
58e62f7a
...
...
@@ -140,8 +140,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
def
testCatchesCxxExceptionsInSetUpTestCase
(
self
):
self
.
assert_
(
'C++ exception with description "Standard C++ exception"'
' thrown in SetUpTestCase()'
in
EX_BINARY_OUTPUT
)
' thrown in SetUpTestSuite()'
in
EX_BINARY_OUTPUT
)
self
.
assert_
(
'CxxExceptionInConstructorTest::TearDownTestCase() '
'called as expected.'
in
EX_BINARY_OUTPUT
)
...
...
@@ -163,8 +162,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
def
testCatchesCxxExceptionsInTearDownTestCase
(
self
):
self
.
assert_
(
'C++ exception with description "Standard C++ exception"'
' thrown in TearDownTestCase()'
in
EX_BINARY_OUTPUT
)
' thrown in TearDownTestSuite()'
in
EX_BINARY_OUTPUT
)
def
testCatchesCxxExceptionsInSetUp
(
self
):
self
.
assert_
(
'C++ exception with description "Standard C++ exception"'
...
...
googletest/test/googletest-listener-test.cc
View file @
58e62f7a
...
...
@@ -125,6 +125,78 @@ class EventRecordingListener : public TestEventListener {
std
::
string
name_
;
};
// This listener is using OnTestSuiteStart, OnTestSuiteEnd API
class
EventRecordingListener2
:
public
TestEventListener
{
public:
explicit
EventRecordingListener2
(
const
char
*
name
)
:
name_
(
name
)
{}
protected:
void
OnTestProgramStart
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestProgramStart"
));
}
void
OnTestIterationStart
(
const
UnitTest
&
/*unit_test*/
,
int
iteration
)
override
{
Message
message
;
message
<<
GetFullMethodName
(
"OnTestIterationStart"
)
<<
"("
<<
iteration
<<
")"
;
g_events
->
push_back
(
message
.
GetString
());
}
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsSetUpStart"
));
}
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsSetUpEnd"
));
}
void
OnTestSuiteStart
(
const
TestSuite
&
/*test_suite*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestSuiteStart"
));
}
void
OnTestStart
(
const
TestInfo
&
/*test_info*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestStart"
));
}
void
OnTestPartResult
(
const
TestPartResult
&
/*test_part_result*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestPartResult"
));
}
void
OnTestEnd
(
const
TestInfo
&
/*test_info*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestEnd"
));
}
void
OnTestSuiteEnd
(
const
TestSuite
&
/*test_suite*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestSuiteEnd"
));
}
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsTearDownStart"
));
}
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsTearDownEnd"
));
}
void
OnTestIterationEnd
(
const
UnitTest
&
/*unit_test*/
,
int
iteration
)
override
{
Message
message
;
message
<<
GetFullMethodName
(
"OnTestIterationEnd"
)
<<
"("
<<
iteration
<<
")"
;
g_events
->
push_back
(
message
.
GetString
());
}
void
OnTestProgramEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestProgramEnd"
));
}
private:
std
::
string
GetFullMethodName
(
const
char
*
name
)
{
return
name_
+
"."
+
name
;
}
std
::
string
name_
;
};
class
EnvironmentInvocationCatcher
:
public
Environment
{
protected:
void
SetUp
()
override
{
g_events
->
push_back
(
"Environment::SetUp"
);
}
...
...
@@ -165,6 +237,7 @@ TEST_F(ListenerTest, DoesBar) {
using
::
testing
::
internal
::
EnvironmentInvocationCatcher
;
using
::
testing
::
internal
::
EventRecordingListener
;
using
::
testing
::
internal
::
EventRecordingListener2
;
void
VerifyResults
(
const
std
::
vector
<
std
::
string
>&
data
,
const
char
*
const
*
expected_data
,
...
...
@@ -199,6 +272,8 @@ int main(int argc, char **argv) {
new
EventRecordingListener
(
"1st"
));
UnitTest
::
GetInstance
()
->
listeners
().
Append
(
new
EventRecordingListener
(
"2nd"
));
UnitTest
::
GetInstance
()
->
listeners
().
Append
(
new
EventRecordingListener2
(
"3rd"
));
AddGlobalTestEnvironment
(
new
EnvironmentInvocationCatcher
);
...
...
@@ -208,88 +283,117 @@ int main(int argc, char **argv) {
::
testing
::
GTEST_FLAG
(
repeat
)
=
2
;
int
ret_val
=
RUN_ALL_TESTS
();
const
char
*
const
expected_events
[]
=
{
"1st.OnTestProgramStart"
,
const
char
*
const
expected_events
[]
=
{
"1st.OnTestProgramStart"
,
"2nd.OnTestProgramStart"
,
"3rd.OnTestProgramStart"
,
"1st.OnTestIterationStart(0)"
,
"2nd.OnTestIterationStart(0)"
,
"3rd.OnTestIterationStart(0)"
,
"1st.OnEnvironmentsSetUpStart"
,
"2nd.OnEnvironmentsSetUpStart"
,
"3rd.OnEnvironmentsSetUpStart"
,
"Environment::SetUp"
,
"3rd.OnEnvironmentsSetUpEnd"
,
"2nd.OnEnvironmentsSetUpEnd"
,
"1st.OnEnvironmentsSetUpEnd"
,
"3rd.OnTestSuiteStart"
,
"1st.OnTestCaseStart"
,
"2nd.OnTestCaseStart"
,
"ListenerTest::SetUpTestCase"
,
"1st.OnTestStart"
,
"2nd.OnTestStart"
,
"3rd.OnTestStart"
,
"ListenerTest::SetUp"
,
"ListenerTest::* Test Body"
,
"1st.OnTestPartResult"
,
"2nd.OnTestPartResult"
,
"3rd.OnTestPartResult"
,
"ListenerTest::TearDown"
,
"3rd.OnTestEnd"
,
"2nd.OnTestEnd"
,
"1st.OnTestEnd"
,
"1st.OnTestStart"
,
"2nd.OnTestStart"
,
"3rd.OnTestStart"
,
"ListenerTest::SetUp"
,
"ListenerTest::* Test Body"
,
"1st.OnTestPartResult"
,
"2nd.OnTestPartResult"
,
"3rd.OnTestPartResult"
,
"ListenerTest::TearDown"
,
"3rd.OnTestEnd"
,
"2nd.OnTestEnd"
,
"1st.OnTestEnd"
,
"ListenerTest::TearDownTestCase"
,
"3rd.OnTestSuiteEnd"
,
"2nd.OnTestCaseEnd"
,
"1st.OnTestCaseEnd"
,
"1st.OnEnvironmentsTearDownStart"
,
"2nd.OnEnvironmentsTearDownStart"
,
"3rd.OnEnvironmentsTearDownStart"
,
"Environment::TearDown"
,
"3rd.OnEnvironmentsTearDownEnd"
,
"2nd.OnEnvironmentsTearDownEnd"
,
"1st.OnEnvironmentsTearDownEnd"
,
"3rd.OnTestIterationEnd(0)"
,
"2nd.OnTestIterationEnd(0)"
,
"1st.OnTestIterationEnd(0)"
,
"1st.OnTestIterationStart(1)"
,
"2nd.OnTestIterationStart(1)"
,
"3rd.OnTestIterationStart(1)"
,
"1st.OnEnvironmentsSetUpStart"
,
"2nd.OnEnvironmentsSetUpStart"
,
"3rd.OnEnvironmentsSetUpStart"
,
"Environment::SetUp"
,
"3rd.OnEnvironmentsSetUpEnd"
,
"2nd.OnEnvironmentsSetUpEnd"
,
"1st.OnEnvironmentsSetUpEnd"
,
"3rd.OnTestSuiteStart"
,
"1st.OnTestCaseStart"
,
"2nd.OnTestCaseStart"
,
"ListenerTest::SetUpTestCase"
,
"1st.OnTestStart"
,
"2nd.OnTestStart"
,
"3rd.OnTestStart"
,
"ListenerTest::SetUp"
,
"ListenerTest::* Test Body"
,
"1st.OnTestPartResult"
,
"2nd.OnTestPartResult"
,
"3rd.OnTestPartResult"
,
"ListenerTest::TearDown"
,
"3rd.OnTestEnd"
,
"2nd.OnTestEnd"
,
"1st.OnTestEnd"
,
"1st.OnTestStart"
,
"2nd.OnTestStart"
,
"3rd.OnTestStart"
,
"ListenerTest::SetUp"
,
"ListenerTest::* Test Body"
,
"1st.OnTestPartResult"
,
"2nd.OnTestPartResult"
,
"3rd.OnTestPartResult"
,
"ListenerTest::TearDown"
,
"3rd.OnTestEnd"
,
"2nd.OnTestEnd"
,
"1st.OnTestEnd"
,
"ListenerTest::TearDownTestCase"
,
"3rd.OnTestSuiteEnd"
,
"2nd.OnTestCaseEnd"
,
"1st.OnTestCaseEnd"
,
"1st.OnEnvironmentsTearDownStart"
,
"2nd.OnEnvironmentsTearDownStart"
,
"3rd.OnEnvironmentsTearDownStart"
,
"Environment::TearDown"
,
"3rd.OnEnvironmentsTearDownEnd"
,
"2nd.OnEnvironmentsTearDownEnd"
,
"1st.OnEnvironmentsTearDownEnd"
,
"3rd.OnTestIterationEnd(1)"
,
"2nd.OnTestIterationEnd(1)"
,
"1st.OnTestIterationEnd(1)"
,
"3rd.OnTestProgramEnd"
,
"2nd.OnTestProgramEnd"
,
"1st.OnTestProgramEnd"
};
"1st.OnTestProgramEnd"
};
VerifyResults
(
events
,
expected_events
,
sizeof
(
expected_events
)
/
sizeof
(
expected_events
[
0
]));
...
...
googletest/test/googletest-output-test-golden-lin.txt
View file @
58e62f7a
...
...
@@ -12,7 +12,7 @@ Expected equality of these values:
3
Stack trace: (omitted)
[0;32m[==========] [mRunning 83 tests from 38 test
cas
es.
[0;32m[==========] [mRunning 83 tests from 38 test
suit
es.
[0;32m[----------] [mGlobal test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
...
...
@@ -392,26 +392,26 @@ Stack trace: (omitted)
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFail
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class. However, in test
cas
e MixedUpTestCaseTest,
All tests in the same test
suit
e must use the same test fixture
class. However, in test
suit
e MixedUpTestCaseTest,
you defined test FirstTestFromNamespaceFoo and test ThisShouldFail
using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation
units and have the same name. You should probably rename one
of the classes to put the tests into different test
cas
es.
of the classes to put the tests into different test
suit
es.
Stack trace: (omitted)
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFailToo
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class. However, in test
cas
e MixedUpTestCaseTest,
All tests in the same test
suit
e must use the same test fixture
class. However, in test
suit
e MixedUpTestCaseTest,
you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo
using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation
units and have the same name. You should probably rename one
of the classes to put the tests into different test
cas
es.
of the classes to put the tests into different test
suit
es.
Stack trace: (omitted)
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
...
...
@@ -421,13 +421,13 @@ Stack trace: (omitted)
[0;32m[ RUN ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class. However, in test
cas
e MixedUpTestCaseWithSameTestNameTest,
All tests in the same test
suit
e must use the same test fixture
class. However, in test
suit
e MixedUpTestCaseWithSameTestNameTest,
you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail
using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation
units and have the same name. You should probably rename one
of the classes to put the tests into different test
cas
es.
of the classes to put the tests into different test
suit
es.
Stack trace: (omitted)
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
...
...
@@ -437,9 +437,9 @@ Stack trace: (omitted)
[0;32m[ RUN ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class, so mixing TEST_F and TEST in the same test
cas
e is
illegal. In test
cas
e TEST_F_before_TEST_in_same_test_case,
All tests in the same test
suit
e must use the same test fixture
class, so mixing TEST_F and TEST in the same test
suit
e is
illegal. In test
suit
e TEST_F_before_TEST_in_same_test_case,
test DefinedUsingTEST_F is defined using TEST_F but
test DefinedUsingTESTAndShouldFail is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test
...
...
@@ -453,9 +453,9 @@ Stack trace: (omitted)
[0;32m[ RUN ] [mTEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class, so mixing TEST_F and TEST in the same test
cas
e is
illegal. In test
cas
e TEST_before_TEST_F_in_same_test_case,
All tests in the same test
suit
e must use the same test fixture
class, so mixing TEST_F and TEST in the same test
suit
e is
illegal. In test
suit
e TEST_before_TEST_F_in_same_test_case,
test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but
test DefinedUsingTEST is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test
...
...
@@ -912,9 +912,9 @@ DynamicFixture::TearDown
DynamicFixture()
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class, so mixing TEST_F and TEST in the same test
cas
e is
illegal. In test
cas
e BadDynamicFixture1,
All tests in the same test
suit
e must use the same test fixture
class, so mixing TEST_F and TEST in the same test
suit
e is
illegal. In test
suit
e BadDynamicFixture1,
test FixtureBase is defined using TEST_F but
test TestBase is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test
...
...
@@ -936,13 +936,13 @@ DynamicFixture::TearDown
DynamicFixture()
gtest.cc:#: Failure
Failed
All tests in the same test
cas
e must use the same test fixture
class. However, in test
cas
e BadDynamicFixture2,
All tests in the same test
suit
e must use the same test fixture
class. However, in test
suit
e BadDynamicFixture2,
you defined test FixtureBase and test Derived
using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation
units and have the same name. You should probably rename one
of the classes to put the tests into different test
cas
es.
of the classes to put the tests into different test
suit
es.
Stack trace: (omitted)
~DynamicFixture()
...
...
@@ -984,7 +984,7 @@ Failed
Expected fatal failure.
Stack trace: (omitted)
[0;32m[==========] [m83 tests from 38 test
cas
es ran.
[0;32m[==========] [m83 tests from 38 test
suit
es ran.
[0;32m[ PASSED ] [m30 tests.
[0;31m[ FAILED ] [m53 tests, listed below:
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
...
...
@@ -1045,7 +1045,7 @@ Stack trace: (omitted)
[0;33m YOU HAVE 1 DISABLED TEST
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
[==========] Running 4 tests from 2 test
cas
es.
[==========] Running 4 tests from 2 test
suit
es.
[----------] Global test environment set-up.
[----------] 3 tests from FatalFailureTest
[ RUN ] FatalFailureTest.FatalFailureInSubroutine
...
...
@@ -1098,7 +1098,7 @@ Stack trace: (omitted)
[----------] 1 test from LoggingTest (? ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 2 test
cas
es ran. (? ms total)
[==========] 4 tests from 2 test
suit
es ran. (? ms total)
[ PASSED ] 0 tests.
[ FAILED ] 4 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
...
...
@@ -1108,21 +1108,21 @@ Stack trace: (omitted)
4 FAILED TESTS
Note: Google Test filter = *DISABLED_*
[==========] Running 1 test from 1 test
cas
e.
[==========] Running 1 test from 1 test
suit
e.
[----------] Global test environment set-up.
[----------] 1 test from DisabledTestsWarningTest
[ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
[ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
[----------] Global test environment tear-down
[==========] 1 test from 1 test
cas
e ran.
[==========] 1 test from 1 test
suit
e ran.
[ PASSED ] 1 test.
Note: Google Test filter = PassingTest.*
Note: This is test shard 2 of 2.
[==========] Running 1 test from 1 test
cas
e.
[==========] Running 1 test from 1 test
suit
e.
[----------] Global test environment set-up.
[----------] 1 test from PassingTest
[ RUN ] PassingTest.PassingTest2
[ OK ] PassingTest.PassingTest2
[----------] Global test environment tear-down
[==========] 1 test from 1 test
cas
e ran.
[==========] 1 test from 1 test
suit
e ran.
[ PASSED ] 1 test.
googletest/test/gtest-typed-test_test.cc
View file @
58e62f7a
...
...
@@ -249,7 +249,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsDuplicates) {
TEST_F
(
TypedTestCasePStateDeathTest
,
DetectsExtraTest
)
{
EXPECT_DEATH_IF_SUPPORTED
(
state_
.
VerifyRegisteredTestNames
(
"foo.cc"
,
1
,
"A, B, C, D"
),
"foo
\\
.cc.1.?: No test named D can be found in this test
cas
e
\\
."
);
"foo
\\
.cc.1.?: No test named D can be found in this test
suit
e
\\
."
);
}
TEST_F
(
TypedTestCasePStateDeathTest
,
DetectsMissedTest
)
{
...
...
@@ -264,7 +264,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsTestAfterRegistration) {
state_
.
VerifyRegisteredTestNames
(
"foo.cc"
,
1
,
"A, B, C"
);
EXPECT_DEATH_IF_SUPPORTED
(
state_
.
AddTestName
(
"foo.cc"
,
2
,
"FooTest"
,
"D"
),
"foo
\\
.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_
CAS
E_P"
"foo
\\
.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_
SUIT
E_P"
"
\\
(FooTest,
\\
.
\\
.
\\
.
\\
)
\\
."
);
}
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment