Merge branch 'master' of https://github.com/google/googletest
This commit is contained in:
commit
58e62f7a98
@ -572,7 +572,7 @@ struct MockObjectState {
|
|||||||
// invoked on this mock object.
|
// invoked on this mock object.
|
||||||
const char* first_used_file;
|
const char* first_used_file;
|
||||||
int first_used_line;
|
int first_used_line;
|
||||||
::std::string first_used_test_case;
|
::std::string first_used_test_suite;
|
||||||
::std::string first_used_test;
|
::std::string first_used_test;
|
||||||
bool leakable; // true iff it's OK to leak the object.
|
bool leakable; // true iff it's OK to leak the object.
|
||||||
FunctionMockers function_mockers; // All registered methods of the object.
|
FunctionMockers function_mockers; // All registered methods of the object.
|
||||||
@ -609,8 +609,8 @@ class MockObjectRegistry {
|
|||||||
state.first_used_line);
|
state.first_used_line);
|
||||||
std::cout << " ERROR: this mock object";
|
std::cout << " ERROR: this mock object";
|
||||||
if (state.first_used_test != "") {
|
if (state.first_used_test != "") {
|
||||||
std::cout << " (used in test " << state.first_used_test_case << "."
|
std::cout << " (used in test " << state.first_used_test_suite << "."
|
||||||
<< state.first_used_test << ")";
|
<< state.first_used_test << ")";
|
||||||
}
|
}
|
||||||
std::cout << " should be deleted but never is. Its address is @"
|
std::cout << " should be deleted but never is. Its address is @"
|
||||||
<< it->first << ".";
|
<< it->first << ".";
|
||||||
@ -790,7 +790,7 @@ void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
|
|||||||
const TestInfo* const test_info =
|
const TestInfo* const test_info =
|
||||||
UnitTest::GetInstance()->current_test_info();
|
UnitTest::GetInstance()->current_test_info();
|
||||||
if (test_info != nullptr) {
|
if (test_info != nullptr) {
|
||||||
state.first_used_test_case = test_info->test_case_name();
|
state.first_used_test_suite = test_info->test_suite_name();
|
||||||
state.first_used_test = test_info->name();
|
state.first_used_test = test_info->name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ GTEST_API_ bool InDeathTestChild();
|
|||||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
|
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
|
||||||
|
|
||||||
// Like ASSERT_EXIT, but continues on to successive tests in the
|
// Like ASSERT_EXIT, but continues on to successive tests in the
|
||||||
// test case, if any:
|
// test suite, if any:
|
||||||
# define EXPECT_EXIT(statement, predicate, regex) \
|
# define EXPECT_EXIT(statement, predicate, regex) \
|
||||||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
|
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ GTEST_API_ bool InDeathTestChild();
|
|||||||
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||||
|
|
||||||
// Like ASSERT_DEATH, but continues on to successive tests in the
|
// Like ASSERT_DEATH, but continues on to successive tests in the
|
||||||
// test case, if any:
|
// test suite, if any:
|
||||||
# define EXPECT_DEATH(statement, regex) \
|
# define EXPECT_DEATH(statement, regex) \
|
||||||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ class GTEST_API_ KilledBySignal {
|
|||||||
// return 12;
|
// return 12;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// TEST(TestCase, TestDieOr12WorksInDgbAndOpt) {
|
// TEST(TestSuite, TestDieOr12WorksInDgbAndOpt) {
|
||||||
// int sideeffect = 0;
|
// int sideeffect = 0;
|
||||||
// // Only asserts in dbg.
|
// // Only asserts in dbg.
|
||||||
// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
|
// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
|
||||||
|
@ -75,7 +75,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
|||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
|
// Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test
|
||||||
// case with any set of parameters you want. Google Test defines a number
|
// case with any set of parameters you want. Google Test defines a number
|
||||||
// of functions for generating test parameters. They return what we call
|
// of functions for generating test parameters. They return what we call
|
||||||
// (surprise!) parameter generators. Here is a summary of them, which
|
// (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
|
// For more details, see comments at the definitions of these functions below
|
||||||
// in this file.
|
// in this file.
|
||||||
//
|
//
|
||||||
// The following statement will instantiate tests from the FooTest test case
|
// The following statement will instantiate tests from the FooTest test suite
|
||||||
// each with parameter values "meeny", "miny", and "moe".
|
// each with parameter values "meeny", "miny", and "moe".
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
INSTANTIATE_TEST_SUITE_P(InstantiationName,
|
||||||
FooTest,
|
FooTest,
|
||||||
Values("meeny", "miny", "moe"));
|
Values("meeny", "miny", "moe"));
|
||||||
|
|
||||||
// To distinguish different instances of the pattern, (yes, you
|
// To distinguish different instances of the pattern, (yes, you
|
||||||
// can instantiate it more then once) the first argument to the
|
// can instantiate it more then once) the first argument to the
|
||||||
// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
|
// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the
|
||||||
// actual test case name. Remember to pick unique prefixes for different
|
// actual test suite name. Remember to pick unique prefixes for different
|
||||||
// instantiations. The tests from the instantiation above will have
|
// instantiations. The tests from the instantiation above will have
|
||||||
// these names:
|
// these names:
|
||||||
//
|
//
|
||||||
@ -123,7 +123,7 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
|
|||||||
// with parameter values "cat" and "dog":
|
// with parameter values "cat" and "dog":
|
||||||
|
|
||||||
const char* pets[] = {"cat", "dog"};
|
const char* pets[] = {"cat", "dog"};
|
||||||
INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||||
|
|
||||||
// The tests from the instantiation above will have these names:
|
// 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/0 for "cat"
|
||||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
||||||
//
|
//
|
||||||
// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
|
// Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests
|
||||||
// in the given test case, whether their definitions come before or
|
// in the given test suite, whether their definitions come before or
|
||||||
// AFTER the INSTANTIATE_TEST_CASE_P statement.
|
// AFTER the INSTANTIATE_TEST_SUITE_P statement.
|
||||||
//
|
//
|
||||||
// Please also note that generator expressions (including parameters to the
|
// Please also note that generator expressions (including parameters to the
|
||||||
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
||||||
@ -190,11 +190,11 @@ namespace testing {
|
|||||||
// Functions producing parameter generators.
|
// Functions producing parameter generators.
|
||||||
//
|
//
|
||||||
// Google Test uses these generators to produce parameters for value-
|
// Google Test uses these generators to produce parameters for value-
|
||||||
// parameterized tests. When a parameterized test case is instantiated
|
// parameterized tests. When a parameterized test suite is instantiated
|
||||||
// with a particular generator, Google Test creates and runs tests
|
// with a particular generator, Google Test creates and runs tests
|
||||||
// for each element in the sequence produced by the generator.
|
// for each element in the sequence produced by the generator.
|
||||||
//
|
//
|
||||||
// In the following sample, tests from test case FooTest are instantiated
|
// In the following sample, tests from test suite FooTest are instantiated
|
||||||
// each three times with parameter values 3, 5, and 8:
|
// each three times with parameter values 3, 5, and 8:
|
||||||
//
|
//
|
||||||
// class FooTest : public TestWithParam<int> { ... };
|
// class FooTest : public TestWithParam<int> { ... };
|
||||||
@ -203,7 +203,7 @@ namespace testing {
|
|||||||
// }
|
// }
|
||||||
// TEST_P(FooTest, TestThat) {
|
// TEST_P(FooTest, TestThat) {
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
|
// INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||||
//
|
//
|
||||||
|
|
||||||
// Range() returns generators providing sequences of values in a range.
|
// Range() returns generators providing sequences of values in a range.
|
||||||
@ -260,13 +260,13 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
|||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
//
|
//
|
||||||
// This instantiates tests from test case StringTest
|
// This instantiates tests from test suite StringTest
|
||||||
// each with C-string values of "foo", "bar", and "baz":
|
// each with C-string values of "foo", "bar", and "baz":
|
||||||
//
|
//
|
||||||
// const char* strings[] = {"foo", "bar", "baz"};
|
// const char* strings[] = {"foo", "bar", "baz"};
|
||||||
// INSTANTIATE_TEST_CASE_P(StringSequence, StringTest, ValuesIn(strings));
|
// INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||||
//
|
//
|
||||||
// This instantiates tests from test case StlStringTest
|
// This instantiates tests from test suite StlStringTest
|
||||||
// each with STL strings with values "a" and "b":
|
// each with STL strings with values "a" and "b":
|
||||||
//
|
//
|
||||||
// ::std::vector< ::std::string> GetParameterStrings() {
|
// ::std::vector< ::std::string> GetParameterStrings() {
|
||||||
@ -276,9 +276,9 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
|||||||
// return v;
|
// return v;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// INSTANTIATE_TEST_CASE_P(CharSequence,
|
// INSTANTIATE_TEST_SUITE_P(CharSequence,
|
||||||
// StlStringTest,
|
// StlStringTest,
|
||||||
// ValuesIn(GetParameterStrings()));
|
// ValuesIn(GetParameterStrings()));
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// This will also instantiate tests from CharTest
|
// This will also instantiate tests from CharTest
|
||||||
@ -291,9 +291,9 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
|||||||
// return list;
|
// return list;
|
||||||
// }
|
// }
|
||||||
// ::std::list<char> l = GetParameterChars();
|
// ::std::list<char> l = GetParameterChars();
|
||||||
// INSTANTIATE_TEST_CASE_P(CharSequence2,
|
// INSTANTIATE_TEST_SUITE_P(CharSequence2,
|
||||||
// CharTest,
|
// CharTest,
|
||||||
// ValuesIn(l.begin(), l.end()));
|
// ValuesIn(l.begin(), l.end()));
|
||||||
//
|
//
|
||||||
template <typename ForwardIterator>
|
template <typename ForwardIterator>
|
||||||
internal::ParamGenerator<
|
internal::ParamGenerator<
|
||||||
@ -323,15 +323,17 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
|||||||
// Values(T v1, T v2, ..., T vN)
|
// Values(T v1, T v2, ..., T vN)
|
||||||
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
||||||
//
|
//
|
||||||
// For example, this instantiates tests from test case BarTest each
|
// For example, this instantiates tests from test suite BarTest each
|
||||||
// with values "one", "two", and "three":
|
// 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 case BazTest each with values 1, 2, 3.5.
|
// This instantiates tests from test suite BazTest each with values 1, 2, 3.5.
|
||||||
// The exact type of values will depend on the type of parameter in BazTest.
|
// The exact type of values will depend on the type of parameter in BazTest.
|
||||||
//
|
//
|
||||||
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
template <typename... T>
|
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
|
// of multiple flags can be tested when several Bool()'s are combined using
|
||||||
// Combine() function.
|
// Combine() function.
|
||||||
//
|
//
|
||||||
// In the following example all tests in the test case FlagDependentTest
|
// In the following example all tests in the test suite FlagDependentTest
|
||||||
// will be instantiated twice with parameters false and true.
|
// will be instantiated twice with parameters false and true.
|
||||||
//
|
//
|
||||||
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
||||||
@ -357,7 +359,7 @@ internal::ValueArray<T...> Values(T... v) {
|
|||||||
// external_flag = GetParam();
|
// external_flag = GetParam();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
|
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
|
||||||
//
|
//
|
||||||
inline internal::ParamGenerator<bool> Bool() {
|
inline internal::ParamGenerator<bool> Bool() {
|
||||||
return Values(false, true);
|
return Values(false, true);
|
||||||
@ -378,7 +380,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
|||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// This will instantiate tests in test case AnimalTest each one with
|
// This will instantiate tests in test suite AnimalTest each one with
|
||||||
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
||||||
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
||||||
//
|
//
|
||||||
@ -388,9 +390,9 @@ inline internal::ParamGenerator<bool> Bool() {
|
|||||||
//
|
//
|
||||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||||
//
|
//
|
||||||
// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
|
// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest,
|
||||||
// Combine(Values("cat", "dog"),
|
// Combine(Values("cat", "dog"),
|
||||||
// Values(BLACK, WHITE)));
|
// Values(BLACK, WHITE)));
|
||||||
//
|
//
|
||||||
// This will instantiate tests in FlagDependentTest with all variations of two
|
// This will instantiate tests in FlagDependentTest with all variations of two
|
||||||
// Boolean flags:
|
// Boolean flags:
|
||||||
@ -406,8 +408,8 @@ inline internal::ParamGenerator<bool> Bool() {
|
|||||||
// TEST_P(FlagDependentTest, TestFeature1) {
|
// TEST_P(FlagDependentTest, TestFeature1) {
|
||||||
// // Test your code using external_flag_1 and external_flag_2 here.
|
// // Test your code using external_flag_1 and external_flag_2 here.
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
|
// INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest,
|
||||||
// Combine(Bool(), Bool()));
|
// Combine(Bool(), Bool()));
|
||||||
//
|
//
|
||||||
template <typename Generator1, typename Generator2>
|
template <typename Generator1, typename Generator2>
|
||||||
internal::CartesianProductHolder2<Generator1, Generator2> Combine(
|
internal::CartesianProductHolder2<Generator1, Generator2> Combine(
|
||||||
@ -513,36 +515,36 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
|||||||
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
|
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
|
||||||
}
|
}
|
||||||
|
|
||||||
# define TEST_P(test_case_name, test_name) \
|
#define TEST_P(test_suite_name, test_name) \
|
||||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||||
: public test_case_name { \
|
: public test_suite_name { \
|
||||||
public: \
|
public: \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||||
virtual void TestBody(); \
|
virtual void TestBody(); \
|
||||||
private: \
|
\
|
||||||
static int AddToRegistry() { \
|
private: \
|
||||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
static int AddToRegistry() { \
|
||||||
GetTestCasePatternHolder<test_case_name>(\
|
::testing::UnitTest::GetInstance() \
|
||||||
#test_case_name, \
|
->parameterized_test_registry() \
|
||||||
::testing::internal::CodeLocation(\
|
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||||
__FILE__, __LINE__))->AddTestPattern(\
|
#test_suite_name, \
|
||||||
GTEST_STRINGIFY_(test_case_name), \
|
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||||
GTEST_STRINGIFY_(test_name), \
|
->AddTestPattern( \
|
||||||
new ::testing::internal::TestMetaFactory< \
|
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
|
||||||
GTEST_TEST_CLASS_NAME_(\
|
new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
|
||||||
test_case_name, test_name)>()); \
|
test_suite_name, test_name)>()); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
test_name)); \
|
||||||
}; \
|
}; \
|
||||||
int GTEST_TEST_CLASS_NAME_(test_case_name, \
|
int GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||||
test_name)::gtest_registering_dummy_ = \
|
test_name)::gtest_registering_dummy_ = \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
|
||||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||||
|
|
||||||
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
// The optional last argument to INSTANTIATE_TEST_SUITE_P allows the user
|
||||||
// to specify a function or functor that generates custom test name suffixes
|
// to specify a function or functor that generates custom test name suffixes
|
||||||
// based on the test parameters. The function should accept one argument of
|
// based on the test parameters. The function should accept one argument of
|
||||||
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
||||||
@ -554,24 +556,32 @@ internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
|
|||||||
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||||
// to std::string and C strings, it won't work for these types.
|
// to std::string and C strings, it won't work for these types.
|
||||||
|
|
||||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, generator, ...) \
|
||||||
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
|
||||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
|
||||||
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
return generator; \
|
||||||
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
} \
|
||||||
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
|
||||||
(__VA_ARGS__)(info); \
|
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
|
||||||
} \
|
return ::testing::internal::GetParamNameGen<test_suite_name::ParamType>( \
|
||||||
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
__VA_ARGS__)(info); \
|
||||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
} \
|
||||||
GetTestCasePatternHolder<test_case_name>(\
|
static int gtest_##prefix##test_suite_name##_dummy_ \
|
||||||
#test_case_name, \
|
GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
::testing::internal::CodeLocation(\
|
::testing::UnitTest::GetInstance() \
|
||||||
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
->parameterized_test_registry() \
|
||||||
#prefix, \
|
.GetTestSuitePatternHolder<test_suite_name>( \
|
||||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
#test_suite_name, \
|
||||||
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
::testing::internal::CodeLocation(__FILE__, __LINE__)) \
|
||||||
__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
|
} // namespace testing
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ TEST_P(FooTest, HasBlahBlah) {
|
|||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
|
// Finally, you can use INSTANTIATE_TEST_SUITE_P to instantiate the test
|
||||||
// case with any set of parameters you want. Google Test defines a number
|
// case with any set of parameters you want. Google Test defines a number
|
||||||
// of functions for generating test parameters. They return what we call
|
// of functions for generating test parameters. They return what we call
|
||||||
// (surprise!) parameter generators. Here is a summary of them, which
|
// (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
|
// For more details, see comments at the definitions of these functions below
|
||||||
// in this file.
|
// in this file.
|
||||||
//
|
//
|
||||||
// The following statement will instantiate tests from the FooTest test case
|
// The following statement will instantiate tests from the FooTest test suite
|
||||||
// each with parameter values "meeny", "miny", and "moe".
|
// each with parameter values "meeny", "miny", and "moe".
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(InstantiationName,
|
INSTANTIATE_TEST_SUITE_P(InstantiationName,
|
||||||
FooTest,
|
FooTest,
|
||||||
Values("meeny", "miny", "moe"));
|
Values("meeny", "miny", "moe"));
|
||||||
|
|
||||||
// To distinguish different instances of the pattern, (yes, you
|
// To distinguish different instances of the pattern, (yes, you
|
||||||
// can instantiate it more then once) the first argument to the
|
// can instantiate it more then once) the first argument to the
|
||||||
// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
|
// INSTANTIATE_TEST_SUITE_P macro is a prefix that will be added to the
|
||||||
// actual test case name. Remember to pick unique prefixes for different
|
// actual test suite name. Remember to pick unique prefixes for different
|
||||||
// instantiations. The tests from the instantiation above will have
|
// instantiations. The tests from the instantiation above will have
|
||||||
// these names:
|
// these names:
|
||||||
//
|
//
|
||||||
@ -122,7 +122,7 @@ INSTANTIATE_TEST_CASE_P(InstantiationName,
|
|||||||
// with parameter values "cat" and "dog":
|
// with parameter values "cat" and "dog":
|
||||||
|
|
||||||
const char* pets[] = {"cat", "dog"};
|
const char* pets[] = {"cat", "dog"};
|
||||||
INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
INSTANTIATE_TEST_SUITE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
|
||||||
|
|
||||||
// The tests from the instantiation above will have these names:
|
// 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/0 for "cat"
|
||||||
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
|
||||||
//
|
//
|
||||||
// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
|
// Please note that INSTANTIATE_TEST_SUITE_P will instantiate all tests
|
||||||
// in the given test case, whether their definitions come before or
|
// in the given test suite, whether their definitions come before or
|
||||||
// AFTER the INSTANTIATE_TEST_CASE_P statement.
|
// AFTER the INSTANTIATE_TEST_SUITE_P statement.
|
||||||
//
|
//
|
||||||
// Please also note that generator expressions (including parameters to the
|
// Please also note that generator expressions (including parameters to the
|
||||||
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
// generators) are evaluated in InitGoogleTest(), after main() has started.
|
||||||
@ -189,11 +189,11 @@ namespace testing {
|
|||||||
// Functions producing parameter generators.
|
// Functions producing parameter generators.
|
||||||
//
|
//
|
||||||
// Google Test uses these generators to produce parameters for value-
|
// Google Test uses these generators to produce parameters for value-
|
||||||
// parameterized tests. When a parameterized test case is instantiated
|
// parameterized tests. When a parameterized test suite is instantiated
|
||||||
// with a particular generator, Google Test creates and runs tests
|
// with a particular generator, Google Test creates and runs tests
|
||||||
// for each element in the sequence produced by the generator.
|
// for each element in the sequence produced by the generator.
|
||||||
//
|
//
|
||||||
// In the following sample, tests from test case FooTest are instantiated
|
// In the following sample, tests from test suite FooTest are instantiated
|
||||||
// each three times with parameter values 3, 5, and 8:
|
// each three times with parameter values 3, 5, and 8:
|
||||||
//
|
//
|
||||||
// class FooTest : public TestWithParam<int> { ... };
|
// class FooTest : public TestWithParam<int> { ... };
|
||||||
@ -202,7 +202,7 @@ namespace testing {
|
|||||||
// }
|
// }
|
||||||
// TEST_P(FooTest, TestThat) {
|
// TEST_P(FooTest, TestThat) {
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
|
// INSTANTIATE_TEST_SUITE_P(TestSequence, FooTest, Values(3, 5, 8));
|
||||||
//
|
//
|
||||||
|
|
||||||
// Range() returns generators providing sequences of values in a range.
|
// Range() returns generators providing sequences of values in a range.
|
||||||
@ -259,13 +259,13 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
|||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
//
|
//
|
||||||
// This instantiates tests from test case StringTest
|
// This instantiates tests from test suite StringTest
|
||||||
// each with C-string values of "foo", "bar", and "baz":
|
// each with C-string values of "foo", "bar", and "baz":
|
||||||
//
|
//
|
||||||
// const char* strings[] = {"foo", "bar", "baz"};
|
// const char* strings[] = {"foo", "bar", "baz"};
|
||||||
// INSTANTIATE_TEST_CASE_P(StringSequence, StringTest, ValuesIn(strings));
|
// INSTANTIATE_TEST_SUITE_P(StringSequence, StringTest, ValuesIn(strings));
|
||||||
//
|
//
|
||||||
// This instantiates tests from test case StlStringTest
|
// This instantiates tests from test suite StlStringTest
|
||||||
// each with STL strings with values "a" and "b":
|
// each with STL strings with values "a" and "b":
|
||||||
//
|
//
|
||||||
// ::std::vector< ::std::string> GetParameterStrings() {
|
// ::std::vector< ::std::string> GetParameterStrings() {
|
||||||
@ -275,9 +275,9 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
|||||||
// return v;
|
// return v;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// INSTANTIATE_TEST_CASE_P(CharSequence,
|
// INSTANTIATE_TEST_SUITE_P(CharSequence,
|
||||||
// StlStringTest,
|
// StlStringTest,
|
||||||
// ValuesIn(GetParameterStrings()));
|
// ValuesIn(GetParameterStrings()));
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// This will also instantiate tests from CharTest
|
// This will also instantiate tests from CharTest
|
||||||
@ -290,9 +290,9 @@ internal::ParamGenerator<T> Range(T start, T end) {
|
|||||||
// return list;
|
// return list;
|
||||||
// }
|
// }
|
||||||
// ::std::list<char> l = GetParameterChars();
|
// ::std::list<char> l = GetParameterChars();
|
||||||
// INSTANTIATE_TEST_CASE_P(CharSequence2,
|
// INSTANTIATE_TEST_SUITE_P(CharSequence2,
|
||||||
// CharTest,
|
// CharTest,
|
||||||
// ValuesIn(l.begin(), l.end()));
|
// ValuesIn(l.begin(), l.end()));
|
||||||
//
|
//
|
||||||
template <typename ForwardIterator>
|
template <typename ForwardIterator>
|
||||||
internal::ParamGenerator<
|
internal::ParamGenerator<
|
||||||
@ -322,15 +322,17 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
|
|||||||
// Values(T v1, T v2, ..., T vN)
|
// Values(T v1, T v2, ..., T vN)
|
||||||
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
// - returns a generator producing sequences with elements v1, v2, ..., vN.
|
||||||
//
|
//
|
||||||
// For example, this instantiates tests from test case BarTest each
|
// For example, this instantiates tests from test suite BarTest each
|
||||||
// with values "one", "two", and "three":
|
// 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 case BazTest each with values 1, 2, 3.5.
|
// This instantiates tests from test suite BazTest each with values 1, 2, 3.5.
|
||||||
// The exact type of values will depend on the type of parameter in BazTest.
|
// The exact type of values will depend on the type of parameter in BazTest.
|
||||||
//
|
//
|
||||||
// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
// INSTANTIATE_TEST_SUITE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
template <typename... T>
|
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
|
// of multiple flags can be tested when several Bool()'s are combined using
|
||||||
// Combine() function.
|
// Combine() function.
|
||||||
//
|
//
|
||||||
// In the following example all tests in the test case FlagDependentTest
|
// In the following example all tests in the test suite FlagDependentTest
|
||||||
// will be instantiated twice with parameters false and true.
|
// will be instantiated twice with parameters false and true.
|
||||||
//
|
//
|
||||||
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
// class FlagDependentTest : public testing::TestWithParam<bool> {
|
||||||
@ -356,7 +358,7 @@ internal::ValueArray<T...> Values(T... v) {
|
|||||||
// external_flag = GetParam();
|
// external_flag = GetParam();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
|
// INSTANTIATE_TEST_SUITE_P(BoolSequence, FlagDependentTest, Bool());
|
||||||
//
|
//
|
||||||
inline internal::ParamGenerator<bool> Bool() {
|
inline internal::ParamGenerator<bool> Bool() {
|
||||||
return Values(false, true);
|
return Values(false, true);
|
||||||
@ -377,7 +379,7 @@ inline internal::ParamGenerator<bool> Bool() {
|
|||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// This will instantiate tests in test case AnimalTest each one with
|
// This will instantiate tests in test suite AnimalTest each one with
|
||||||
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
// the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
|
||||||
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
// tuple("dog", BLACK), and tuple("dog", WHITE):
|
||||||
//
|
//
|
||||||
@ -387,9 +389,9 @@ inline internal::ParamGenerator<bool> Bool() {
|
|||||||
//
|
//
|
||||||
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
// TEST_P(AnimalTest, AnimalLooksNice) {...}
|
||||||
//
|
//
|
||||||
// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
|
// INSTANTIATE_TEST_SUITE_P(AnimalVariations, AnimalTest,
|
||||||
// Combine(Values("cat", "dog"),
|
// Combine(Values("cat", "dog"),
|
||||||
// Values(BLACK, WHITE)));
|
// Values(BLACK, WHITE)));
|
||||||
//
|
//
|
||||||
// This will instantiate tests in FlagDependentTest with all variations of two
|
// This will instantiate tests in FlagDependentTest with all variations of two
|
||||||
// Boolean flags:
|
// Boolean flags:
|
||||||
@ -405,8 +407,8 @@ inline internal::ParamGenerator<bool> Bool() {
|
|||||||
// TEST_P(FlagDependentTest, TestFeature1) {
|
// TEST_P(FlagDependentTest, TestFeature1) {
|
||||||
// // Test your code using external_flag_1 and external_flag_2 here.
|
// // Test your code using external_flag_1 and external_flag_2 here.
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
|
// INSTANTIATE_TEST_SUITE_P(TwoBoolSequence, FlagDependentTest,
|
||||||
// Combine(Bool(), Bool()));
|
// Combine(Bool(), Bool()));
|
||||||
//
|
//
|
||||||
$range i 2..maxtuple
|
$range i 2..maxtuple
|
||||||
$for i [[
|
$for i [[
|
||||||
@ -421,36 +423,36 @@ internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
|
|||||||
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
# define TEST_P(test_case_name, test_name) \
|
# define TEST_P(test_suite_name, test_name) \
|
||||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||||
: public test_case_name { \
|
: public test_suite_name { \
|
||||||
public: \
|
public: \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||||
virtual void TestBody(); \
|
virtual void TestBody(); \
|
||||||
private: \
|
private: \
|
||||||
static int AddToRegistry() { \
|
static int AddToRegistry() { \
|
||||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||||
GetTestCasePatternHolder<test_case_name>(\
|
GetTestSuitePatternHolder<test_suite_name>(\
|
||||||
#test_case_name, \
|
#test_suite_name, \
|
||||||
::testing::internal::CodeLocation(\
|
::testing::internal::CodeLocation(\
|
||||||
__FILE__, __LINE__))->AddTestPattern(\
|
__FILE__, __LINE__))->AddTestPattern(\
|
||||||
GTEST_STRINGIFY_(test_case_name), \
|
GTEST_STRINGIFY_(test_suite_name), \
|
||||||
GTEST_STRINGIFY_(test_name), \
|
GTEST_STRINGIFY_(test_name), \
|
||||||
new ::testing::internal::TestMetaFactory< \
|
new ::testing::internal::TestMetaFactory< \
|
||||||
GTEST_TEST_CLASS_NAME_(\
|
GTEST_TEST_CLASS_NAME_(\
|
||||||
test_case_name, test_name)>()); \
|
test_suite_name, test_name)>()); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(\
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
|
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
|
||||||
}; \
|
}; \
|
||||||
int GTEST_TEST_CLASS_NAME_(test_case_name, \
|
int GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||||
test_name)::gtest_registering_dummy_ = \
|
test_name)::gtest_registering_dummy_ = \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \
|
||||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||||
|
|
||||||
// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user
|
// The optional last argument to INSTANTIATE_TEST_SUITE_P allows the user
|
||||||
// to specify a function or functor that generates custom test name suffixes
|
// to specify a function or functor that generates custom test name suffixes
|
||||||
// based on the test parameters. The function should accept one argument of
|
// based on the test parameters. The function should accept one argument of
|
||||||
// type testing::TestParamInfo<class ParamType>, and return std::string.
|
// 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
|
// alphanumeric characters or underscore. Because PrintToString adds quotes
|
||||||
// to std::string and C strings, it won't work for these types.
|
// to std::string and C strings, it won't work for these types.
|
||||||
|
|
||||||
# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \
|
# define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, generator, ...) \
|
||||||
static ::testing::internal::ParamGenerator<test_case_name::ParamType> \
|
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
|
||||||
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
|
gtest_##prefix##test_suite_name##_EvalGenerator_() { return generator; } \
|
||||||
static ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \
|
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
|
||||||
const ::testing::TestParamInfo<test_case_name::ParamType>& info) { \
|
const ::testing::TestParamInfo<test_suite_name::ParamType>& info) { \
|
||||||
return ::testing::internal::GetParamNameGen<test_case_name::ParamType> \
|
return ::testing::internal::GetParamNameGen<test_suite_name::ParamType> \
|
||||||
(__VA_ARGS__)(info); \
|
(__VA_ARGS__)(info); \
|
||||||
} \
|
} \
|
||||||
static int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
static int gtest_##prefix##test_suite_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
|
||||||
GetTestCasePatternHolder<test_case_name>(\
|
GetTestSuitePatternHolder<test_suite_name>(\
|
||||||
#test_case_name, \
|
#test_suite_name, \
|
||||||
::testing::internal::CodeLocation(\
|
::testing::internal::CodeLocation(\
|
||||||
__FILE__, __LINE__))->AddTestCaseInstantiation(\
|
__FILE__, __LINE__))->AddTestSuiteInstantiation(\
|
||||||
#prefix, \
|
#prefix, \
|
||||||
>est_##prefix##test_case_name##_EvalGenerator_, \
|
>est_##prefix##test_suite_name##_EvalGenerator_, \
|
||||||
>est_##prefix##test_case_name##_EvalGenerateName_, \
|
>est_##prefix##test_suite_name##_EvalGenerateName_, \
|
||||||
__FILE__, __LINE__)
|
__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
|
} // namespace testing
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
|
||||||
|
@ -52,18 +52,18 @@ class FooTest : public testing::Test {
|
|||||||
T value_;
|
T value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Next, associate a list of types with the test case, which will be
|
// Next, associate a list of types with the test suite, which will be
|
||||||
// repeated for each type in the list. The typedef is necessary for
|
// repeated for each type in the list. The typedef is necessary for
|
||||||
// the macro to parse correctly.
|
// the macro to parse correctly.
|
||||||
typedef testing::Types<char, int, unsigned int> MyTypes;
|
typedef testing::Types<char, int, unsigned int> MyTypes;
|
||||||
TYPED_TEST_CASE(FooTest, MyTypes);
|
TYPED_TEST_SUITE(FooTest, MyTypes);
|
||||||
|
|
||||||
// If the type list contains only one type, you can write that type
|
// If the type list contains only one type, you can write that type
|
||||||
// directly without Types<...>:
|
// directly without Types<...>:
|
||||||
// TYPED_TEST_CASE(FooTest, int);
|
// TYPED_TEST_SUITE(FooTest, int);
|
||||||
|
|
||||||
// Then, use TYPED_TEST() instead of TEST_F() to define as many typed
|
// Then, use TYPED_TEST() instead of TEST_F() to define as many typed
|
||||||
// tests for this test case as you want.
|
// tests for this test suite as you want.
|
||||||
TYPED_TEST(FooTest, DoesBlah) {
|
TYPED_TEST(FooTest, DoesBlah) {
|
||||||
// Inside a test, refer to TypeParam to get the type parameter.
|
// Inside a test, refer to TypeParam to get the type parameter.
|
||||||
// Since we are inside a derived class template, C++ requires use to
|
// 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(FooTest, HasPropertyA) { ... }
|
||||||
|
|
||||||
// TYPED_TEST_CASE takes an optional third argument which allows to specify a
|
// TYPED_TEST_SUITE takes an optional third argument which allows to specify a
|
||||||
// class that generates custom test name suffixes based on the type. This should
|
// 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
|
// 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
|
// 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";
|
// if (std::is_same<T, unsigned int>()) return "unsignedInt";
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
// TYPED_TEST_CASE(FooTest, MyTypes, MyTypeNames);
|
// TYPED_TEST_SUITE(FooTest, MyTypes, MyTypeNames);
|
||||||
|
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
@ -126,13 +126,13 @@ class FooTest : public testing::Test {
|
|||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
||||||
// Next, declare that you will define a type-parameterized test case
|
// Next, declare that you will define a type-parameterized test suite
|
||||||
// (the _P suffix is for "parameterized" or "pattern", whichever you
|
// (the _P suffix is for "parameterized" or "pattern", whichever you
|
||||||
// prefer):
|
// prefer):
|
||||||
TYPED_TEST_CASE_P(FooTest);
|
TYPED_TEST_SUITE_P(FooTest);
|
||||||
|
|
||||||
// Then, use TYPED_TEST_P() to define as many type-parameterized tests
|
// Then, use TYPED_TEST_P() to define as many type-parameterized tests
|
||||||
// for this type-parameterized test case as you want.
|
// for this type-parameterized test suite as you want.
|
||||||
TYPED_TEST_P(FooTest, DoesBlah) {
|
TYPED_TEST_P(FooTest, DoesBlah) {
|
||||||
// Inside a test, refer to TypeParam to get the type parameter.
|
// Inside a test, refer to TypeParam to get the type parameter.
|
||||||
TypeParam n = 0;
|
TypeParam n = 0;
|
||||||
@ -143,10 +143,10 @@ TYPED_TEST_P(FooTest, HasPropertyA) { ... }
|
|||||||
|
|
||||||
// Now the tricky part: you need to register all test patterns before
|
// Now the tricky part: you need to register all test patterns before
|
||||||
// you can instantiate them. The first argument of the macro is the
|
// you can instantiate them. The first argument of the macro is the
|
||||||
// test case name; the rest are the names of the tests in this test
|
// test suite name; the rest are the names of the tests in this test
|
||||||
// case.
|
// case.
|
||||||
REGISTER_TYPED_TEST_CASE_P(FooTest,
|
REGISTER_TYPED_TEST_SUITE_P(FooTest,
|
||||||
DoesBlah, HasPropertyA);
|
DoesBlah, HasPropertyA);
|
||||||
|
|
||||||
// Finally, you are free to instantiate the pattern with the types you
|
// Finally, you are free to instantiate the pattern with the types you
|
||||||
// want. If you put the above code in a header file, you can #include
|
// want. If you put the above code in a header file, you can #include
|
||||||
@ -154,19 +154,19 @@ REGISTER_TYPED_TEST_CASE_P(FooTest,
|
|||||||
//
|
//
|
||||||
// To distinguish different instances of the pattern, the first
|
// To distinguish different instances of the pattern, the first
|
||||||
// argument to the INSTANTIATE_* macro is a prefix that will be added
|
// argument to the INSTANTIATE_* macro is a prefix that will be added
|
||||||
// to the actual test case name. Remember to pick unique prefixes for
|
// to the actual test suite name. Remember to pick unique prefixes for
|
||||||
// different instances.
|
// different instances.
|
||||||
typedef testing::Types<char, int, unsigned int> MyTypes;
|
typedef testing::Types<char, int, unsigned int> MyTypes;
|
||||||
INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes);
|
||||||
|
|
||||||
// If the type list contains only one type, you can write that type
|
// If the type list contains only one type, you can write that type
|
||||||
// directly without Types<...>:
|
// directly without Types<...>:
|
||||||
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
|
// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, int);
|
||||||
//
|
//
|
||||||
// Similar to the optional argument of TYPED_TEST_CASE above,
|
// Similar to the optional argument of TYPED_TEST_SUITE above,
|
||||||
// INSTANTIATE_TEST_CASE_P takes an optional fourth argument which allows to
|
// INSTANTIATE_TEST_SUITE_P takes an optional fourth argument which allows to
|
||||||
// generate custom names.
|
// generate custom names.
|
||||||
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes, MyTypeNames);
|
// INSTANTIATE_TYPED_TEST_SUITE_P(My, FooTest, MyTypes, MyTypeNames);
|
||||||
|
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
@ -180,21 +180,21 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
|||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// Expands to the name of the typedef for the type parameters of the
|
// Expands to the name of the typedef for the type parameters of the
|
||||||
// given test case.
|
// given test suite.
|
||||||
# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
|
#define GTEST_TYPE_PARAMS_(TestSuiteName) gtest_type_params_##TestSuiteName##_
|
||||||
|
|
||||||
// Expands to the name of the typedef for the NameGenerator, responsible for
|
// Expands to the name of the typedef for the NameGenerator, responsible for
|
||||||
// creating the suffixes of the name.
|
// creating the suffixes of the name.
|
||||||
#define GTEST_NAME_GENERATOR_(TestCaseName) \
|
#define GTEST_NAME_GENERATOR_(TestSuiteName) \
|
||||||
gtest_type_params_##TestCaseName##_NameGenerator
|
gtest_type_params_##TestSuiteName##_NameGenerator
|
||||||
|
|
||||||
// The 'Types' template argument below must have spaces around it
|
// The 'Types' template argument below must have spaces around it
|
||||||
// since some compilers may choke on '>>' when passing a template
|
// since some compilers may choke on '>>' when passing a template
|
||||||
// instance (e.g. Types<int>)
|
// instance (e.g. Types<int>)
|
||||||
# define TYPED_TEST_CASE(CaseName, Types, ...) \
|
#define TYPED_TEST_SUITE(CaseName, Types, ...) \
|
||||||
typedef ::testing::internal::TypeList< Types >::type GTEST_TYPE_PARAMS_( \
|
typedef ::testing::internal::TypeList<Types>::type GTEST_TYPE_PARAMS_( \
|
||||||
CaseName); \
|
CaseName); \
|
||||||
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
typedef ::testing::internal::NameGeneratorSelector<__VA_ARGS__>::type \
|
||||||
GTEST_NAME_GENERATOR_(CaseName)
|
GTEST_NAME_GENERATOR_(CaseName)
|
||||||
|
|
||||||
# define TYPED_TEST(CaseName, TestName) \
|
# define TYPED_TEST(CaseName, TestName) \
|
||||||
@ -224,6 +224,11 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
|||||||
void GTEST_TEST_CLASS_NAME_(CaseName, \
|
void GTEST_TEST_CLASS_NAME_(CaseName, \
|
||||||
TestName)<gtest_TypeParam_>::TestBody()
|
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
|
#endif // GTEST_HAS_TYPED_TEST
|
||||||
|
|
||||||
// Implements type-parameterized tests.
|
// Implements type-parameterized tests.
|
||||||
@ -233,73 +238,88 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
|
|||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// Expands to the namespace name that the type-parameterized tests for
|
// Expands to the namespace name that the type-parameterized tests for
|
||||||
// the given type-parameterized test case are defined in. The exact
|
// the given type-parameterized test suite are defined in. The exact
|
||||||
// name of the namespace is subject to change without notice.
|
// name of the namespace is subject to change without notice.
|
||||||
# define GTEST_CASE_NAMESPACE_(TestCaseName) \
|
#define GTEST_SUITE_NAMESPACE_(TestSuiteName) gtest_suite_##TestSuiteName##_
|
||||||
gtest_case_##TestCaseName##_
|
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// Expands to the name of the variable used to remember the names of
|
// Expands to the name of the variable used to remember the names of
|
||||||
// the defined tests in the given test case.
|
// the defined tests in the given test suite.
|
||||||
# define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
|
#define GTEST_TYPED_TEST_SUITE_P_STATE_(TestSuiteName) \
|
||||||
gtest_typed_test_case_p_state_##TestCaseName##_
|
gtest_typed_test_suite_p_state_##TestSuiteName##_
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
|
||||||
//
|
//
|
||||||
// Expands to the name of the variable used to remember the names of
|
// Expands to the name of the variable used to remember the names of
|
||||||
// the registered tests in the given test case.
|
// the registered tests in the given test suite.
|
||||||
# define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
|
#define GTEST_REGISTERED_TEST_NAMES_(TestSuiteName) \
|
||||||
gtest_registered_test_names_##TestCaseName##_
|
gtest_registered_test_names_##TestSuiteName##_
|
||||||
|
|
||||||
// The variables defined in the type-parameterized test macros are
|
// The variables defined in the type-parameterized test macros are
|
||||||
// static as typically these macros are used in a .h file that can be
|
// static as typically these macros are used in a .h file that can be
|
||||||
// #included in multiple translation units linked together.
|
// #included in multiple translation units linked together.
|
||||||
# define TYPED_TEST_CASE_P(CaseName) \
|
#define TYPED_TEST_SUITE_P(SuiteName) \
|
||||||
static ::testing::internal::TypedTestCasePState \
|
static ::testing::internal::TypedTestSuitePState \
|
||||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
|
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName)
|
||||||
|
|
||||||
# define TYPED_TEST_P(CaseName, TestName) \
|
// Legacy API is deprecated but still available
|
||||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
template <typename gtest_TypeParam_> \
|
#define TYPED_TEST_CASE_P TYPED_TEST_SUITE_P
|
||||||
class TestName : public CaseName<gtest_TypeParam_> { \
|
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
private: \
|
|
||||||
typedef CaseName<gtest_TypeParam_> TestFixture; \
|
|
||||||
typedef gtest_TypeParam_ TypeParam; \
|
|
||||||
virtual void TestBody(); \
|
|
||||||
}; \
|
|
||||||
static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
|
|
||||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\
|
|
||||||
__FILE__, __LINE__, #CaseName, #TestName); \
|
|
||||||
} \
|
|
||||||
template <typename gtest_TypeParam_> \
|
|
||||||
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
|
|
||||||
|
|
||||||
# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
|
#define TYPED_TEST_P(SuiteName, TestName) \
|
||||||
namespace GTEST_CASE_NAMESPACE_(CaseName) { \
|
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
|
||||||
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
template <typename gtest_TypeParam_> \
|
||||||
} \
|
class TestName : public SuiteName<gtest_TypeParam_> { \
|
||||||
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) \
|
private: \
|
||||||
GTEST_ATTRIBUTE_UNUSED_ = \
|
typedef SuiteName<gtest_TypeParam_> TestFixture; \
|
||||||
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames( \
|
typedef gtest_TypeParam_ TypeParam; \
|
||||||
__FILE__, __LINE__, #__VA_ARGS__)
|
virtual void TestBody(); \
|
||||||
|
}; \
|
||||||
|
static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
|
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).AddTestName( \
|
||||||
|
__FILE__, __LINE__, #SuiteName, #TestName); \
|
||||||
|
} \
|
||||||
|
template <typename gtest_TypeParam_> \
|
||||||
|
void GTEST_SUITE_NAMESPACE_( \
|
||||||
|
SuiteName)::TestName<gtest_TypeParam_>::TestBody()
|
||||||
|
|
||||||
|
#define REGISTER_TYPED_TEST_SUITE_P(SuiteName, ...) \
|
||||||
|
namespace GTEST_SUITE_NAMESPACE_(SuiteName) { \
|
||||||
|
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
|
||||||
|
} \
|
||||||
|
static const char* const GTEST_REGISTERED_TEST_NAMES_( \
|
||||||
|
SuiteName) GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
|
GTEST_TYPED_TEST_SUITE_P_STATE_(SuiteName).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
|
// The 'Types' template argument below must have spaces around it
|
||||||
// since some compilers may choke on '>>' when passing a template
|
// since some compilers may choke on '>>' when passing a template
|
||||||
// instance (e.g. Types<int>)
|
// instance (e.g. Types<int>)
|
||||||
# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types, ...) \
|
#define INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, SuiteName, Types, ...) \
|
||||||
static bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
|
static bool gtest_##Prefix##_##SuiteName GTEST_ATTRIBUTE_UNUSED_ = \
|
||||||
::testing::internal::TypeParameterizedTestCase< \
|
::testing::internal::TypeParameterizedTestSuite< \
|
||||||
CaseName, GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
|
SuiteName, GTEST_SUITE_NAMESPACE_(SuiteName)::gtest_AllTests_, \
|
||||||
::testing::internal::TypeList< Types >::type>:: \
|
::testing::internal::TypeList<Types>::type>:: \
|
||||||
Register(#Prefix, \
|
Register(#Prefix, \
|
||||||
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
::testing::internal::CodeLocation(__FILE__, __LINE__), \
|
||||||
>EST_TYPED_TEST_CASE_P_STATE_(CaseName), #CaseName, \
|
>EST_TYPED_TEST_SUITE_P_STATE_(SuiteName), #SuiteName, \
|
||||||
GTEST_REGISTERED_TEST_NAMES_(CaseName), \
|
GTEST_REGISTERED_TEST_NAMES_(SuiteName), \
|
||||||
::testing::internal::GenerateNames< \
|
::testing::internal::GenerateNames< \
|
||||||
::testing::internal::NameGeneratorSelector< \
|
::testing::internal::NameGeneratorSelector< \
|
||||||
__VA_ARGS__>::type, \
|
__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
|
#endif // GTEST_HAS_TYPED_TEST_P
|
||||||
|
|
||||||
|
@ -197,7 +197,12 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
|
|||||||
// If we don't forward declare them the compiler might confuse the classes
|
// If we don't forward declare them the compiler might confuse the classes
|
||||||
// in friendship clauses with same named classes on the scope.
|
// in friendship clauses with same named classes on the scope.
|
||||||
class Test;
|
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 TestInfo;
|
||||||
class UnitTest;
|
class UnitTest;
|
||||||
|
|
||||||
@ -386,8 +391,8 @@ namespace testing {
|
|||||||
|
|
||||||
// The abstract class that all tests inherit from.
|
// The abstract class that all tests inherit from.
|
||||||
//
|
//
|
||||||
// In Google Test, a unit test program contains one or many TestCases, and
|
// In Google Test, a unit test program contains one or many TestSuites, and
|
||||||
// each TestCase contains one or many Tests.
|
// each TestSuite contains one or many Tests.
|
||||||
//
|
//
|
||||||
// When you define a test using the TEST macro, you don't need to
|
// When you define a test using the TEST macro, you don't need to
|
||||||
// explicitly derive from Test - the TEST macro automatically does
|
// explicitly derive from Test - the TEST macro automatically does
|
||||||
@ -411,29 +416,30 @@ class GTEST_API_ Test {
|
|||||||
public:
|
public:
|
||||||
friend class TestInfo;
|
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.
|
// The d'tor is virtual as we intend to inherit from Test.
|
||||||
virtual ~Test();
|
virtual ~Test();
|
||||||
|
|
||||||
// Sets up the stuff shared by all tests in this test case.
|
// Sets up the stuff shared by all tests in this test case.
|
||||||
//
|
//
|
||||||
// Google Test will call Foo::SetUpTestCase() before running the first
|
// Google Test will call Foo::SetUpTestSuite() before running the first
|
||||||
// test in test case Foo. Hence a sub-class can define its own
|
// test in test case Foo. Hence a sub-class can define its own
|
||||||
// SetUpTestCase() method to shadow the one defined in the super
|
// SetUpTestSuite() method to shadow the one defined in the super
|
||||||
// class.
|
// class.
|
||||||
static void SetUpTestCase() {}
|
static void SetUpTestSuite() {}
|
||||||
|
|
||||||
// Tears down the stuff shared by all tests in this test case.
|
// Tears down the stuff shared by all tests in this test case.
|
||||||
//
|
//
|
||||||
// Google Test will call Foo::TearDownTestCase() after running the last
|
// Google Test will call Foo::TearDownTestSuite() after running the last
|
||||||
// test in test case Foo. Hence a sub-class can define its own
|
// test in test case Foo. Hence a sub-class can define its own
|
||||||
// TearDownTestCase() method to shadow the one defined in the super
|
// TearDownTestSuite() method to shadow the one defined in the super
|
||||||
// class.
|
// class.
|
||||||
|
static void TearDownTestSuite() {}
|
||||||
|
|
||||||
|
// Legacy API is deprecated but still available
|
||||||
|
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
static void TearDownTestCase() {}
|
static void TearDownTestCase() {}
|
||||||
|
static void SetUpTestCase() {}
|
||||||
|
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
|
|
||||||
// Returns true iff the current test has a fatal failure.
|
// Returns true iff the current test has a fatal failure.
|
||||||
static bool HasFatalFailure();
|
static bool HasFatalFailure();
|
||||||
@ -448,15 +454,15 @@ class GTEST_API_ Test {
|
|||||||
// non-fatal) failure.
|
// non-fatal) failure.
|
||||||
static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
|
static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
|
||||||
|
|
||||||
// Logs a property for the current test, test case, or for the entire
|
// Logs a property for the current test, test suite, or for the entire
|
||||||
// invocation of the test program when used outside of the context of a
|
// invocation of the test program when used outside of the context of a
|
||||||
// test case. Only the last value for a given key is remembered. These
|
// test suite. Only the last value for a given key is remembered. These
|
||||||
// are public static so they can be called from utility functions that are
|
// are public static so they can be called from utility functions that are
|
||||||
// not members of the test fixture. Calls to RecordProperty made during
|
// not members of the test fixture. Calls to RecordProperty made during
|
||||||
// lifespan of the test (from the moment its constructor starts to the
|
// lifespan of the test (from the moment its constructor starts to the
|
||||||
// moment its destructor finishes) will be output in XML as attributes of
|
// moment its destructor finishes) will be output in XML as attributes of
|
||||||
// the <testcase> element. Properties recorded from fixture's
|
// the <testcase> element. Properties recorded from fixture's
|
||||||
// SetUpTestCase or TearDownTestCase are logged as attributes of the
|
// SetUpTestSuite or TearDownTestSuite are logged as attributes of the
|
||||||
// corresponding <testsuite> element. Calls to RecordProperty made in the
|
// corresponding <testsuite> element. Calls to RecordProperty made in the
|
||||||
// global context (before or after invocation of RUN_ALL_TESTS and from
|
// global context (before or after invocation of RUN_ALL_TESTS and from
|
||||||
// SetUp/TearDown method of Environment objects registered with Google
|
// SetUp/TearDown method of Environment objects registered with Google
|
||||||
@ -476,7 +482,7 @@ class GTEST_API_ Test {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Returns true iff the current test has the same fixture class as
|
// Returns true iff the current test has the same fixture class as
|
||||||
// the first test in the current test case.
|
// the first test in the current test suite.
|
||||||
static bool HasSameFixtureClass();
|
static bool HasSameFixtureClass();
|
||||||
|
|
||||||
// Runs the test after the test fixture has been set up.
|
// Runs the test after the test fixture has been set up.
|
||||||
@ -606,7 +612,7 @@ class GTEST_API_ TestResult {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class TestInfo;
|
friend class TestInfo;
|
||||||
friend class TestCase;
|
friend class TestSuite;
|
||||||
friend class UnitTest;
|
friend class UnitTest;
|
||||||
friend class internal::DefaultGlobalTestPartResultReporter;
|
friend class internal::DefaultGlobalTestPartResultReporter;
|
||||||
friend class internal::ExecDeathTest;
|
friend class internal::ExecDeathTest;
|
||||||
@ -638,7 +644,7 @@ class GTEST_API_ TestResult {
|
|||||||
const TestProperty& test_property);
|
const TestProperty& test_property);
|
||||||
|
|
||||||
// Adds a failure if the key is a reserved attribute of Google Test
|
// Adds a failure if the key is a reserved attribute of Google Test
|
||||||
// testcase tags. Returns true if the property is valid.
|
// testsuite tags. Returns true if the property is valid.
|
||||||
// FIXME: Validate attribute names are legal and human readable.
|
// FIXME: Validate attribute names are legal and human readable.
|
||||||
static bool ValidateTestProperty(const std::string& xml_element,
|
static bool ValidateTestProperty(const std::string& xml_element,
|
||||||
const TestProperty& test_property);
|
const TestProperty& test_property);
|
||||||
@ -677,7 +683,7 @@ class GTEST_API_ TestResult {
|
|||||||
|
|
||||||
// A TestInfo object stores the following information about a test:
|
// A TestInfo object stores the following information about a test:
|
||||||
//
|
//
|
||||||
// Test case name
|
// Test suite name
|
||||||
// Test name
|
// Test name
|
||||||
// Whether the test should be run
|
// Whether the test should be run
|
||||||
// A function pointer that creates the test object when invoked
|
// A function pointer that creates the test object when invoked
|
||||||
@ -692,8 +698,13 @@ class GTEST_API_ TestInfo {
|
|||||||
// don't inherit from TestInfo.
|
// don't inherit from TestInfo.
|
||||||
~TestInfo();
|
~TestInfo();
|
||||||
|
|
||||||
// Returns the test case name.
|
// Returns the test suite name.
|
||||||
const char* test_case_name() const { return test_case_name_.c_str(); }
|
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.
|
// Returns the test name.
|
||||||
const char* name() const { return name_.c_str(); }
|
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.
|
// been specified) and its full name matches the user-specified filter.
|
||||||
//
|
//
|
||||||
// Google Test allows the user to filter the tests by their full names.
|
// Google Test allows the user to filter the tests by their full names.
|
||||||
// The full name of a test Bar in test case Foo is defined as
|
// The full name of a test Bar in test suite Foo is defined as
|
||||||
// "Foo.Bar". Only the tests that match the filter will run.
|
// "Foo.Bar". Only the tests that match the filter will run.
|
||||||
//
|
//
|
||||||
// A filter is a colon-separated list of glob (not regex) patterns,
|
// A filter is a colon-separated list of glob (not regex) patterns,
|
||||||
@ -754,24 +765,19 @@ class GTEST_API_ TestInfo {
|
|||||||
friend class internal::DefaultDeathTestFactory;
|
friend class internal::DefaultDeathTestFactory;
|
||||||
#endif // GTEST_HAS_DEATH_TEST
|
#endif // GTEST_HAS_DEATH_TEST
|
||||||
friend class Test;
|
friend class Test;
|
||||||
friend class TestCase;
|
friend class TestSuite;
|
||||||
friend class internal::UnitTestImpl;
|
friend class internal::UnitTestImpl;
|
||||||
friend class internal::StreamingListenerTest;
|
friend class internal::StreamingListenerTest;
|
||||||
friend TestInfo* internal::MakeAndRegisterTestInfo(
|
friend TestInfo* internal::MakeAndRegisterTestInfo(
|
||||||
const char* test_case_name,
|
const char* test_suite_name, const char* name, const char* type_param,
|
||||||
const char* name,
|
const char* value_param, internal::CodeLocation code_location,
|
||||||
const char* type_param,
|
internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc,
|
||||||
const char* value_param,
|
internal::TearDownTestSuiteFunc tear_down_tc,
|
||||||
internal::CodeLocation code_location,
|
|
||||||
internal::TypeId fixture_class_id,
|
|
||||||
Test::SetUpTestCaseFunc set_up_tc,
|
|
||||||
Test::TearDownTestCaseFunc tear_down_tc,
|
|
||||||
internal::TestFactoryBase* factory);
|
internal::TestFactoryBase* factory);
|
||||||
|
|
||||||
// Constructs a TestInfo object. The newly constructed instance assumes
|
// Constructs a TestInfo object. The newly constructed instance assumes
|
||||||
// ownership of the factory object.
|
// ownership of the factory object.
|
||||||
TestInfo(const std::string& test_case_name,
|
TestInfo(const std::string& test_suite_name, const std::string& name,
|
||||||
const std::string& name,
|
|
||||||
const char* a_type_param, // NULL if not a type-parameterized test
|
const char* a_type_param, // NULL if not a type-parameterized test
|
||||||
const char* a_value_param, // NULL if not a value-parameterized test
|
const char* a_value_param, // NULL if not a value-parameterized test
|
||||||
internal::CodeLocation a_code_location,
|
internal::CodeLocation a_code_location,
|
||||||
@ -793,7 +799,7 @@ class GTEST_API_ TestInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// These fields are immutable properties of the test.
|
// These fields are immutable properties of the test.
|
||||||
const std::string test_case_name_; // Test case name
|
const std::string test_suite_name_; // test suite name
|
||||||
const std::string name_; // Test name
|
const std::string name_; // Test name
|
||||||
// Name of the parameter type, or NULL if this is not a typed or a
|
// Name of the parameter type, or NULL if this is not a typed or a
|
||||||
// type-parameterized test.
|
// type-parameterized test.
|
||||||
@ -818,71 +824,71 @@ class GTEST_API_ TestInfo {
|
|||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A test case, which consists of a vector of TestInfos.
|
// A test suite, which consists of a vector of TestInfos.
|
||||||
//
|
//
|
||||||
// TestCase is not copyable.
|
// TestSuite is not copyable.
|
||||||
class GTEST_API_ TestCase {
|
class GTEST_API_ TestSuite {
|
||||||
public:
|
public:
|
||||||
// Creates a TestCase with the given name.
|
// Creates a TestSuite with the given name.
|
||||||
//
|
//
|
||||||
// TestCase does NOT have a default constructor. Always use this
|
// TestSuite does NOT have a default constructor. Always use this
|
||||||
// constructor to create a TestCase object.
|
// constructor to create a TestSuite object.
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
// name: name of the test case
|
// name: name of the test suite
|
||||||
// a_type_param: the name of the test's type parameter, or NULL if
|
// a_type_param: the name of the test's type parameter, or NULL if
|
||||||
// this is not a type-parameterized test.
|
// this is not a type-parameterized test.
|
||||||
// set_up_tc: pointer to the function that sets up the test case
|
// 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 case
|
// tear_down_tc: pointer to the function that tears down the test suite
|
||||||
TestCase(const char* name, const char* a_type_param,
|
TestSuite(const char* name, const char* a_type_param,
|
||||||
Test::SetUpTestCaseFunc set_up_tc,
|
internal::SetUpTestSuiteFunc set_up_tc,
|
||||||
Test::TearDownTestCaseFunc tear_down_tc);
|
internal::TearDownTestSuiteFunc tear_down_tc);
|
||||||
|
|
||||||
// Destructor of TestCase.
|
// Destructor of TestSuite.
|
||||||
virtual ~TestCase();
|
virtual ~TestSuite();
|
||||||
|
|
||||||
// Gets the name of the TestCase.
|
// Gets the name of the TestSuite.
|
||||||
const char* name() const { return name_.c_str(); }
|
const char* name() const { return name_.c_str(); }
|
||||||
|
|
||||||
// Returns the name of the parameter type, or NULL if this is not a
|
// Returns the name of the parameter type, or NULL if this is not a
|
||||||
// type-parameterized test case.
|
// type-parameterized test suite.
|
||||||
const char* type_param() const {
|
const char* type_param() const {
|
||||||
if (type_param_.get() != nullptr) return type_param_->c_str();
|
if (type_param_.get() != nullptr) return type_param_->c_str();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if any test in this test case should run.
|
// Returns true if any test in this test suite should run.
|
||||||
bool should_run() const { return should_run_; }
|
bool should_run() const { return should_run_; }
|
||||||
|
|
||||||
// Gets the number of successful tests in this test case.
|
// Gets the number of successful tests in this test suite.
|
||||||
int successful_test_count() const;
|
int successful_test_count() const;
|
||||||
|
|
||||||
// Gets the number of skipped tests in this test case.
|
// Gets the number of skipped tests in this test suite.
|
||||||
int skipped_test_count() const;
|
int skipped_test_count() const;
|
||||||
|
|
||||||
// Gets the number of failed tests in this test case.
|
// Gets the number of failed tests in this test suite.
|
||||||
int failed_test_count() const;
|
int failed_test_count() const;
|
||||||
|
|
||||||
// Gets the number of disabled tests that will be reported in the XML report.
|
// Gets the number of disabled tests that will be reported in the XML report.
|
||||||
int reportable_disabled_test_count() const;
|
int reportable_disabled_test_count() const;
|
||||||
|
|
||||||
// Gets the number of disabled tests in this test case.
|
// Gets the number of disabled tests in this test suite.
|
||||||
int disabled_test_count() const;
|
int disabled_test_count() const;
|
||||||
|
|
||||||
// Gets the number of tests to be printed in the XML report.
|
// Gets the number of tests to be printed in the XML report.
|
||||||
int reportable_test_count() const;
|
int reportable_test_count() const;
|
||||||
|
|
||||||
// Get the number of tests in this test case that should run.
|
// Get the number of tests in this test suite that should run.
|
||||||
int test_to_run_count() const;
|
int test_to_run_count() const;
|
||||||
|
|
||||||
// Gets the number of all tests in this test case.
|
// Gets the number of all tests in this test suite.
|
||||||
int total_test_count() const;
|
int total_test_count() const;
|
||||||
|
|
||||||
// Returns true iff the test case passed.
|
// Returns true iff the test suite passed.
|
||||||
bool Passed() const { return !Failed(); }
|
bool Passed() const { return !Failed(); }
|
||||||
|
|
||||||
// Returns true iff the test case failed.
|
// Returns true iff the test suite failed.
|
||||||
bool Failed() const { return failed_test_count() > 0; }
|
bool Failed() const { return failed_test_count() > 0; }
|
||||||
|
|
||||||
// Returns the elapsed time, in milliseconds.
|
// Returns the elapsed time, in milliseconds.
|
||||||
@ -893,17 +899,17 @@ class GTEST_API_ TestCase {
|
|||||||
const TestInfo* GetTestInfo(int i) const;
|
const TestInfo* GetTestInfo(int i) const;
|
||||||
|
|
||||||
// Returns the TestResult that holds test properties recorded during
|
// Returns the TestResult that holds test properties recorded during
|
||||||
// execution of SetUpTestCase and TearDownTestCase.
|
// execution of SetUpTestSuite and TearDownTestSuite.
|
||||||
const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
|
const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Test;
|
friend class Test;
|
||||||
friend class internal::UnitTestImpl;
|
friend class internal::UnitTestImpl;
|
||||||
|
|
||||||
// Gets the (mutable) vector of TestInfos in this TestCase.
|
// Gets the (mutable) vector of TestInfos in this TestSuite.
|
||||||
std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
|
std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
|
||||||
|
|
||||||
// Gets the (immutable) vector of TestInfos in this TestCase.
|
// Gets the (immutable) vector of TestInfos in this TestSuite.
|
||||||
const std::vector<TestInfo*>& test_info_list() const {
|
const std::vector<TestInfo*>& test_info_list() const {
|
||||||
return test_info_list_;
|
return test_info_list_;
|
||||||
}
|
}
|
||||||
@ -915,28 +921,36 @@ class GTEST_API_ TestCase {
|
|||||||
// Sets the should_run member.
|
// Sets the should_run member.
|
||||||
void set_should_run(bool should) { should_run_ = should; }
|
void set_should_run(bool should) { should_run_ = should; }
|
||||||
|
|
||||||
// Adds a TestInfo to this test case. Will delete the TestInfo upon
|
// Adds a TestInfo to this test suite. Will delete the TestInfo upon
|
||||||
// destruction of the TestCase object.
|
// destruction of the TestSuite object.
|
||||||
void AddTestInfo(TestInfo * test_info);
|
void AddTestInfo(TestInfo * test_info);
|
||||||
|
|
||||||
// Clears the results of all tests in this test case.
|
// Clears the results of all tests in this test suite.
|
||||||
void ClearResult();
|
void ClearResult();
|
||||||
|
|
||||||
// Clears the results of all tests in the given test case.
|
// Clears the results of all tests in the given test suite.
|
||||||
static void ClearTestCaseResult(TestCase* test_case) {
|
static void ClearTestSuiteResult(TestSuite* test_suite) {
|
||||||
test_case->ClearResult();
|
test_suite->ClearResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs every test in this TestCase.
|
// Runs every test in this TestSuite.
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
// Runs SetUpTestCase() for this TestCase. This wrapper is needed
|
// Runs SetUpTestSuite() for this TestSuite. This wrapper is needed
|
||||||
// for catching exceptions thrown from SetUpTestCase().
|
// for catching exceptions thrown from SetUpTestSuite().
|
||||||
void RunSetUpTestCase() { (*set_up_tc_)(); }
|
void RunSetUpTestSuite() {
|
||||||
|
if (set_up_tc_ != nullptr) {
|
||||||
|
(*set_up_tc_)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Runs TearDownTestCase() for this TestCase. This wrapper is
|
// Runs TearDownTestSuite() for this TestSuite. This wrapper is
|
||||||
// needed for catching exceptions thrown from TearDownTestCase().
|
// needed for catching exceptions thrown from TearDownTestSuite().
|
||||||
void RunTearDownTestCase() { (*tear_down_tc_)(); }
|
void RunTearDownTestSuite() {
|
||||||
|
if (tear_down_tc_ != nullptr) {
|
||||||
|
(*tear_down_tc_)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Returns true iff test passed.
|
// Returns true iff test passed.
|
||||||
static bool TestPassed(const TestInfo* test_info) {
|
static bool TestPassed(const TestInfo* test_info) {
|
||||||
@ -974,13 +988,13 @@ class GTEST_API_ TestCase {
|
|||||||
return test_info->should_run();
|
return test_info->should_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shuffles the tests in this test case.
|
// Shuffles the tests in this test suite.
|
||||||
void ShuffleTests(internal::Random* random);
|
void ShuffleTests(internal::Random* random);
|
||||||
|
|
||||||
// Restores the test order to before the first shuffle.
|
// Restores the test order to before the first shuffle.
|
||||||
void UnshuffleTests();
|
void UnshuffleTests();
|
||||||
|
|
||||||
// Name of the test case.
|
// Name of the test suite.
|
||||||
std::string name_;
|
std::string name_;
|
||||||
// Name of the parameter type, or NULL if this is not a typed or a
|
// Name of the parameter type, or NULL if this is not a typed or a
|
||||||
// type-parameterized test.
|
// type-parameterized test.
|
||||||
@ -992,20 +1006,20 @@ class GTEST_API_ TestCase {
|
|||||||
// shuffling and restoring the test order. The i-th element in this
|
// 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.
|
// vector is the index of the i-th test in the shuffled test list.
|
||||||
std::vector<int> test_indices_;
|
std::vector<int> test_indices_;
|
||||||
// Pointer to the function that sets up the test case.
|
// Pointer to the function that sets up the test suite.
|
||||||
Test::SetUpTestCaseFunc set_up_tc_;
|
internal::SetUpTestSuiteFunc set_up_tc_;
|
||||||
// Pointer to the function that tears down the test case.
|
// Pointer to the function that tears down the test suite.
|
||||||
Test::TearDownTestCaseFunc tear_down_tc_;
|
internal::TearDownTestSuiteFunc tear_down_tc_;
|
||||||
// True iff any test in this test case should run.
|
// True iff any test in this test suite should run.
|
||||||
bool should_run_;
|
bool should_run_;
|
||||||
// Elapsed time, in milliseconds.
|
// Elapsed time, in milliseconds.
|
||||||
TimeInMillis elapsed_time_;
|
TimeInMillis elapsed_time_;
|
||||||
// Holds test properties recorded during execution of SetUpTestCase and
|
// Holds test properties recorded during execution of SetUpTestSuite and
|
||||||
// TearDownTestCase.
|
// TearDownTestSuite.
|
||||||
TestResult ad_hoc_test_result_;
|
TestResult ad_hoc_test_result_;
|
||||||
|
|
||||||
// We disallow copying TestCases.
|
// We disallow copying TestSuites.
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestSuite);
|
||||||
};
|
};
|
||||||
|
|
||||||
// An Environment object is capable of setting up and tearing down an
|
// 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.
|
// Fired after environment set-up for each iteration of tests ends.
|
||||||
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
|
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
|
||||||
|
|
||||||
// Fired before the test case starts.
|
// Fired before the test suite starts.
|
||||||
virtual void OnTestCaseStart(const TestCase& test_case) = 0;
|
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.
|
// Fired before the test starts.
|
||||||
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
virtual void OnTestStart(const TestInfo& test_info) = 0;
|
||||||
@ -1086,8 +1105,13 @@ class TestEventListener {
|
|||||||
// Fired after the test ends.
|
// Fired after the test ends.
|
||||||
virtual void OnTestEnd(const TestInfo& test_info) = 0;
|
virtual void OnTestEnd(const TestInfo& test_info) = 0;
|
||||||
|
|
||||||
// Fired after the test case ends.
|
// Fired after the test suite ends.
|
||||||
virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
|
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.
|
// Fired before environment tear-down for each iteration of tests starts.
|
||||||
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
|
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
|
||||||
@ -1115,11 +1139,20 @@ class EmptyTestEventListener : public TestEventListener {
|
|||||||
int /*iteration*/) override {}
|
int /*iteration*/) override {}
|
||||||
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
|
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
|
||||||
void OnEnvironmentsSetUpEnd(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 OnTestStart(const TestInfo& /*test_info*/) override {}
|
||||||
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
|
void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
|
||||||
void OnTestEnd(const TestInfo& /*test_info*/) 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 OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
|
||||||
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
|
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
|
||||||
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
void OnTestIterationEnd(const UnitTest& /*unit_test*/,
|
||||||
@ -1164,7 +1197,7 @@ class GTEST_API_ TestEventListeners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class TestCase;
|
friend class TestSuite;
|
||||||
friend class TestInfo;
|
friend class TestInfo;
|
||||||
friend class internal::DefaultGlobalTestPartResultReporter;
|
friend class internal::DefaultGlobalTestPartResultReporter;
|
||||||
friend class internal::NoExecDeathTest;
|
friend class internal::NoExecDeathTest;
|
||||||
@ -1205,7 +1238,7 @@ class GTEST_API_ TestEventListeners {
|
|||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A UnitTest consists of a vector of TestCases.
|
// A UnitTest consists of a vector of TestSuites.
|
||||||
//
|
//
|
||||||
// This is a singleton class. The only instance of UnitTest is
|
// This is a singleton class. The only instance of UnitTest is
|
||||||
// created when UnitTest::GetInstance() is first called. This
|
// created when UnitTest::GetInstance() is first called. This
|
||||||
@ -1234,10 +1267,14 @@ class GTEST_API_ UnitTest {
|
|||||||
// was executed. The UnitTest object owns the string.
|
// was executed. The UnitTest object owns the string.
|
||||||
const char* original_working_dir() const;
|
const char* original_working_dir() const;
|
||||||
|
|
||||||
// Returns the TestCase object for the test that's currently running,
|
// Returns the TestSuite object for the test that's currently running,
|
||||||
// or NULL if no test is running.
|
// or NULL if no test is running.
|
||||||
const TestCase* current_test_case() const
|
const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_);
|
||||||
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,
|
// Returns the TestInfo object for the test that's currently running,
|
||||||
// or NULL if no test is 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.
|
// Returns the random seed used at the start of the current test run.
|
||||||
int random_seed() const;
|
int random_seed() const;
|
||||||
|
|
||||||
// Returns the ParameterizedTestCaseRegistry object used to keep track of
|
// Returns the ParameterizedTestSuiteRegistry object used to keep track of
|
||||||
// value-parameterized tests and instantiate and register them.
|
// value-parameterized tests and instantiate and register them.
|
||||||
//
|
//
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||||
internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
|
internal::ParameterizedTestSuiteRegistry& parameterized_test_registry()
|
||||||
GTEST_LOCK_EXCLUDED_(mutex_);
|
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||||
|
|
||||||
// Gets the number of successful test cases.
|
// Gets the number of successful test suites.
|
||||||
int successful_test_case_count() const;
|
int successful_test_suite_count() const;
|
||||||
|
|
||||||
// Gets the number of failed test cases.
|
// Gets the number of failed test suites.
|
||||||
int failed_test_case_count() const;
|
int failed_test_suite_count() const;
|
||||||
|
|
||||||
// Gets the number of all test cases.
|
// Gets the number of all test suites.
|
||||||
int total_test_case_count() const;
|
int total_test_suite_count() const;
|
||||||
|
|
||||||
// Gets the number of all test cases that contain at least one test
|
// Gets the number of all test suites that contain at least one test
|
||||||
// that should run.
|
// 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;
|
int test_case_to_run_count() const;
|
||||||
|
#endif // EMOVE_LEGACY_TEST_CASEAPI
|
||||||
|
|
||||||
// Gets the number of successful tests.
|
// Gets the number of successful tests.
|
||||||
int successful_test_count() const;
|
int successful_test_count() const;
|
||||||
@ -1298,19 +1343,24 @@ class GTEST_API_ UnitTest {
|
|||||||
// Gets the elapsed time, in milliseconds.
|
// Gets the elapsed time, in milliseconds.
|
||||||
TimeInMillis elapsed_time() const;
|
TimeInMillis elapsed_time() const;
|
||||||
|
|
||||||
// Returns true iff the unit test passed (i.e. all test cases passed).
|
// Returns true iff the unit test passed (i.e. all test suites passed).
|
||||||
bool Passed() const;
|
bool Passed() const;
|
||||||
|
|
||||||
// Returns true iff the unit test failed (i.e. some test case failed
|
// Returns true iff the unit test failed (i.e. some test suite failed
|
||||||
// or something outside of all tests failed).
|
// or something outside of all tests failed).
|
||||||
bool Failed() const;
|
bool Failed() const;
|
||||||
|
|
||||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
// 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;
|
const TestCase* GetTestCase(int i) const;
|
||||||
|
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
|
|
||||||
// Returns the TestResult containing information on test failures and
|
// Returns the TestResult containing information on test failures and
|
||||||
// properties logged outside of individual test cases.
|
// properties logged outside of individual test suites.
|
||||||
const TestResult& ad_hoc_test_result() const;
|
const TestResult& ad_hoc_test_result() const;
|
||||||
|
|
||||||
// Returns the list of event listeners that can be used to track events
|
// 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_);
|
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||||
|
|
||||||
// Adds a TestProperty to the current TestResult object when invoked from
|
// Adds a TestProperty to the current TestResult object when invoked from
|
||||||
// inside a test, to current TestCase's ad_hoc_test_result_ when invoked
|
// inside a test, to current TestSuite's ad_hoc_test_result_ when invoked
|
||||||
// from SetUpTestCase or TearDownTestCase, or to the global property set
|
// from SetUpTestSuite or TearDownTestSuite, or to the global property set
|
||||||
// when invoked elsewhere. If the result already contains a property with
|
// when invoked elsewhere. If the result already contains a property with
|
||||||
// the same key, the value will be updated.
|
// the same key, the value will be updated.
|
||||||
void RecordProperty(const std::string& key, const std::string& value);
|
void RecordProperty(const std::string& key, const std::string& value);
|
||||||
|
|
||||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||||
TestCase* GetMutableTestCase(int i);
|
TestSuite* GetMutableTestSuite(int i);
|
||||||
|
|
||||||
// Accessors for the implementation object.
|
// Accessors for the implementation object.
|
||||||
internal::UnitTestImpl* impl() { return impl_; }
|
internal::UnitTestImpl* impl() { return impl_; }
|
||||||
@ -1815,7 +1865,7 @@ GTEST_API_ GTEST_ATTRIBUTE_PRINTF_(2, 3) void ColoredPrintf(GTestColor color,
|
|||||||
// Foo foo;
|
// Foo foo;
|
||||||
// ASSERT_TRUE(foo.DoesBar(GetParam()));
|
// ASSERT_TRUE(foo.DoesBar(GetParam()));
|
||||||
// }
|
// }
|
||||||
// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
|
// INSTANTIATE_TEST_SUITE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class WithParamInterface {
|
class WithParamInterface {
|
||||||
@ -2282,11 +2332,11 @@ bool StaticAssertTypeEq() {
|
|||||||
|
|
||||||
// Defines a test.
|
// Defines a test.
|
||||||
//
|
//
|
||||||
// The first parameter is the name of the test case, and the second
|
// The first parameter is the name of the test suite, and the second
|
||||||
// parameter is the name of the test within the test case.
|
// parameter is the name of the test within the test suite.
|
||||||
//
|
//
|
||||||
// The convention is to end the test case name with "Test". For
|
// The convention is to end the test suite name with "Test". For
|
||||||
// example, a test case for the Foo class can be named FooTest.
|
// example, a test suite for the Foo class can be named FooTest.
|
||||||
//
|
//
|
||||||
// Test code should appear between braces after an invocation of
|
// Test code should appear between braces after an invocation of
|
||||||
// this macro. Example:
|
// this macro. Example:
|
||||||
@ -2305,21 +2355,21 @@ bool StaticAssertTypeEq() {
|
|||||||
// code. GetTestTypeId() is guaranteed to always return the same
|
// code. GetTestTypeId() is guaranteed to always return the same
|
||||||
// value, as it always calls GetTypeId<>() from the Google Test
|
// value, as it always calls GetTypeId<>() from the Google Test
|
||||||
// framework.
|
// framework.
|
||||||
#define GTEST_TEST(test_case_name, test_name)\
|
#define GTEST_TEST(test_suite_name, test_name) \
|
||||||
GTEST_TEST_(test_case_name, test_name, \
|
GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \
|
||||||
::testing::Test, ::testing::internal::GetTestTypeId())
|
::testing::internal::GetTestTypeId())
|
||||||
|
|
||||||
// Define this macro to 1 to omit the definition of TEST(), which
|
// Define this macro to 1 to omit the definition of TEST(), which
|
||||||
// is a generic name and clashes with some other libraries.
|
// is a generic name and clashes with some other libraries.
|
||||||
#if !GTEST_DONT_DEFINE_TEST
|
#if !GTEST_DONT_DEFINE_TEST
|
||||||
# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
|
#define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Defines a test that uses a test fixture.
|
// Defines a test that uses a test fixture.
|
||||||
//
|
//
|
||||||
// The first parameter is the name of the test fixture class, which
|
// The first parameter is the name of the test fixture class, which
|
||||||
// also doubles as the test case name. The second parameter is the
|
// also doubles as the test suite name. The second parameter is the
|
||||||
// name of the test within the test case.
|
// name of the test within the test suite.
|
||||||
//
|
//
|
||||||
// A test fixture class must be declared earlier. The user should put
|
// A test fixture class must be declared earlier. The user should put
|
||||||
// the test code between braces after using this macro. Example:
|
// 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
|
// function pointer that creates a new instance of the Test object. It
|
||||||
// handles ownership to the caller. The signature of the callable is
|
// handles ownership to the caller. The signature of the callable is
|
||||||
// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
|
// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
|
||||||
// tests registered with the same `test_case_name` must return the same
|
// tests registered with the same `test_suite_name` must return the same
|
||||||
// fixture type. This is checked at runtime.
|
// fixture type. This is checked at runtime.
|
||||||
//
|
//
|
||||||
// The framework will infer the fixture class from the factory and will call
|
// The framework will infer the fixture class from the factory and will call
|
||||||
// the `SetUpTestCase` and `TearDownTestCase` for it.
|
// the `SetUpTestSuite` and `TearDownTestSuite` for it.
|
||||||
//
|
//
|
||||||
// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
|
// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
|
||||||
// undefined.
|
// undefined.
|
||||||
@ -2377,8 +2427,8 @@ GTEST_API_ std::string TempDir();
|
|||||||
// class MyFixture : public ::testing::Test {
|
// class MyFixture : public ::testing::Test {
|
||||||
// public:
|
// public:
|
||||||
// // All of these optional, just like in regular macro usage.
|
// // All of these optional, just like in regular macro usage.
|
||||||
// static void SetUpTestCase() { ... }
|
// static void SetUpTestSuite() { ... }
|
||||||
// static void TearDownTestCase() { ... }
|
// static void TearDownTestSuite() { ... }
|
||||||
// void SetUp() override { ... }
|
// void SetUp() override { ... }
|
||||||
// void TearDown() override { ... }
|
// void TearDown() override { ... }
|
||||||
// };
|
// };
|
||||||
@ -2411,18 +2461,11 @@ GTEST_API_ std::string TempDir();
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
template <int&... ExplicitParameterBarrier, typename Factory>
|
template <int&... ExplicitParameterBarrier, typename Factory>
|
||||||
TestInfo* RegisterTest(const char* test_case_name, const char* test_name,
|
TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
|
||||||
const char* type_param, const char* value_param,
|
const char* type_param, const char* value_param,
|
||||||
const char* file, int line, Factory factory) {
|
const char* file, int line, Factory factory) {
|
||||||
using TestT = typename std::remove_pointer<decltype(factory())>::type;
|
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 {
|
class FactoryImpl : public internal::TestFactoryBase {
|
||||||
public:
|
public:
|
||||||
explicit FactoryImpl(Factory f) : factory_(std::move(f)) {}
|
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(
|
return internal::MakeAndRegisterTestInfo(
|
||||||
test_case_name, test_name, type_param, value_param,
|
test_suite_name, test_name, type_param, value_param,
|
||||||
internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
|
internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
|
||||||
&Helper::SetUpTestCase, &Helper::TearDownTestCase,
|
internal::SuiteApiResolver<TestT>::GetSetUpCaseOrSuite(),
|
||||||
|
internal::SuiteApiResolver<TestT>::GetTearDownCaseOrSuite(),
|
||||||
new FactoryImpl{std::move(factory)});
|
new FactoryImpl{std::move(factory)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,10 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
|
// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
|
||||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||||
//
|
//
|
||||||
// Implements a family of generic predicate assertion macros.
|
// Implements a family of generic predicate assertion macros.
|
||||||
|
|
||||||
// GOOGLETEST_CM0001 DO NOT DELETE
|
// GOOGLETEST_CM0001 DO NOT DELETE
|
||||||
|
|
||||||
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
|
||||||
@ -67,6 +66,8 @@ namespace testing {
|
|||||||
// We also define the EXPECT_* variations.
|
// We also define the EXPECT_* variations.
|
||||||
//
|
//
|
||||||
// For now we only support predicates whose arity is at most 5.
|
// 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
|
// GTEST_ASSERT_ is the basic statement to which all of the assertions
|
||||||
// in this file reduce. Don't use this in your code.
|
// in this file reduce. Don't use this in your code.
|
||||||
@ -89,9 +90,10 @@ AssertionResult AssertPred1Helper(const char* pred_text,
|
|||||||
const T1& v1) {
|
const T1& v1) {
|
||||||
if (pred(v1)) return AssertionSuccess();
|
if (pred(v1)) return AssertionSuccess();
|
||||||
|
|
||||||
return AssertionFailure() << pred_text << "("
|
return AssertionFailure()
|
||||||
<< e1 << ") evaluates to false, where"
|
<< pred_text << "(" << e1 << ") evaluates to false, where"
|
||||||
<< "\n" << e1 << " evaluates to " << v1;
|
<< "\n"
|
||||||
|
<< e1 << " evaluates to " << ::testing::PrintToString(v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
|
||||||
@ -133,11 +135,12 @@ AssertionResult AssertPred2Helper(const char* pred_text,
|
|||||||
const T2& v2) {
|
const T2& v2) {
|
||||||
if (pred(v1, v2)) return AssertionSuccess();
|
if (pred(v1, v2)) return AssertionSuccess();
|
||||||
|
|
||||||
return AssertionFailure() << pred_text << "("
|
return AssertionFailure()
|
||||||
<< e1 << ", "
|
<< pred_text << "(" << e1 << ", " << e2
|
||||||
<< e2 << ") evaluates to false, where"
|
<< ") evaluates to false, where"
|
||||||
<< "\n" << e1 << " evaluates to " << v1
|
<< "\n"
|
||||||
<< "\n" << e2 << " evaluates to " << v2;
|
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||||
|
<< e2 << " evaluates to " << ::testing::PrintToString(v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
|
||||||
@ -184,13 +187,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
|
|||||||
const T3& v3) {
|
const T3& v3) {
|
||||||
if (pred(v1, v2, v3)) return AssertionSuccess();
|
if (pred(v1, v2, v3)) return AssertionSuccess();
|
||||||
|
|
||||||
return AssertionFailure() << pred_text << "("
|
return AssertionFailure()
|
||||||
<< e1 << ", "
|
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3
|
||||||
<< e2 << ", "
|
<< ") evaluates to false, where"
|
||||||
<< e3 << ") evaluates to false, where"
|
<< "\n"
|
||||||
<< "\n" << e1 << " evaluates to " << v1
|
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||||
<< "\n" << e2 << " evaluates to " << v2
|
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||||
<< "\n" << e3 << " evaluates to " << v3;
|
<< e3 << " evaluates to " << ::testing::PrintToString(v3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
|
||||||
@ -242,15 +245,14 @@ AssertionResult AssertPred4Helper(const char* pred_text,
|
|||||||
const T4& v4) {
|
const T4& v4) {
|
||||||
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
|
if (pred(v1, v2, v3, v4)) return AssertionSuccess();
|
||||||
|
|
||||||
return AssertionFailure() << pred_text << "("
|
return AssertionFailure()
|
||||||
<< e1 << ", "
|
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
|
||||||
<< e2 << ", "
|
<< ") evaluates to false, where"
|
||||||
<< e3 << ", "
|
<< "\n"
|
||||||
<< e4 << ") evaluates to false, where"
|
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||||
<< "\n" << e1 << " evaluates to " << v1
|
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||||
<< "\n" << e2 << " evaluates to " << v2
|
<< e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
|
||||||
<< "\n" << e3 << " evaluates to " << v3
|
<< e4 << " evaluates to " << ::testing::PrintToString(v4);
|
||||||
<< "\n" << e4 << " evaluates to " << v4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
|
||||||
@ -307,17 +309,15 @@ AssertionResult AssertPred5Helper(const char* pred_text,
|
|||||||
const T5& v5) {
|
const T5& v5) {
|
||||||
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
|
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
|
||||||
|
|
||||||
return AssertionFailure() << pred_text << "("
|
return AssertionFailure()
|
||||||
<< e1 << ", "
|
<< pred_text << "(" << e1 << ", " << e2 << ", " << e3 << ", " << e4
|
||||||
<< e2 << ", "
|
<< ", " << e5 << ") evaluates to false, where"
|
||||||
<< e3 << ", "
|
<< "\n"
|
||||||
<< e4 << ", "
|
<< e1 << " evaluates to " << ::testing::PrintToString(v1) << "\n"
|
||||||
<< e5 << ") evaluates to false, where"
|
<< e2 << " evaluates to " << ::testing::PrintToString(v2) << "\n"
|
||||||
<< "\n" << e1 << " evaluates to " << v1
|
<< e3 << " evaluates to " << ::testing::PrintToString(v3) << "\n"
|
||||||
<< "\n" << e2 << " evaluates to " << v2
|
<< e4 << " evaluates to " << ::testing::PrintToString(v4) << "\n"
|
||||||
<< "\n" << e3 << " evaluates to " << v3
|
<< e5 << " evaluates to " << ::testing::PrintToString(v5);
|
||||||
<< "\n" << e4 << " evaluates to " << v4
|
|
||||||
<< "\n" << e5 << " evaluates to " << v5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
|
||||||
|
@ -91,7 +91,7 @@ class Message; // Represents a failure message.
|
|||||||
class Test; // Represents a test.
|
class Test; // Represents a test.
|
||||||
class TestInfo; // Information about a test.
|
class TestInfo; // Information about a test.
|
||||||
class TestPartResult; // Result of a test part.
|
class TestPartResult; // Result of a test part.
|
||||||
class UnitTest; // A collection of test cases.
|
class UnitTest; // A collection of test suites.
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
::std::string PrintToString(const T& value);
|
::std::string PrintToString(const T& value);
|
||||||
@ -412,7 +412,7 @@ typedef FloatingPoint<float> Float;
|
|||||||
typedef FloatingPoint<double> Double;
|
typedef FloatingPoint<double> Double;
|
||||||
|
|
||||||
// In order to catch the mistake of putting tests that use different
|
// In order to catch the mistake of putting tests that use different
|
||||||
// test fixture classes in the same test case, we need to assign
|
// test fixture classes in the same test suite, we need to assign
|
||||||
// unique IDs to fixture classes and compare them. The TypeId type is
|
// 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
|
// used to hold such IDs. The user should treat TypeId as an opaque
|
||||||
// type: the only operation allowed on TypeId values is to compare
|
// 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
|
#endif // GTEST_OS_WINDOWS
|
||||||
|
|
||||||
// Types of SetUpTestCase() and TearDownTestCase() functions.
|
// Types of SetUpTestSuite() and TearDownTestSuite() functions.
|
||||||
typedef void (*SetUpTestCaseFunc)();
|
using SetUpTestSuiteFunc = void (*)();
|
||||||
typedef void (*TearDownTestCaseFunc)();
|
using TearDownTestSuiteFunc = void (*)();
|
||||||
|
|
||||||
struct CodeLocation {
|
struct CodeLocation {
|
||||||
CodeLocation(const std::string& a_file, int a_line)
|
CodeLocation(const std::string& a_file, int a_line)
|
||||||
@ -500,12 +500,60 @@ struct CodeLocation {
|
|||||||
int line;
|
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;
|
// Creates a new TestInfo object and registers it with Google Test;
|
||||||
// returns the created object.
|
// returns the created object.
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
// test_case_name: name of the test case
|
// test_suite_name: name of the test suite
|
||||||
// name: name of the test
|
// name: name of the test
|
||||||
// type_param the name of the test's type parameter, or NULL if
|
// type_param the name of the test's type parameter, or NULL if
|
||||||
// this is not a typed or a type-parameterized test.
|
// 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.
|
// or NULL if this is not a type-parameterized test.
|
||||||
// code_location: code location where the test is defined
|
// code_location: code location where the test is defined
|
||||||
// fixture_class_id: ID of the test fixture class
|
// fixture_class_id: ID of the test fixture class
|
||||||
// set_up_tc: pointer to the function that sets up the test case
|
// 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 case
|
// tear_down_tc: pointer to the function that tears down the test suite
|
||||||
// factory: pointer to the factory that creates a test object.
|
// factory: pointer to the factory that creates a test object.
|
||||||
// The newly created TestInfo instance will assume
|
// The newly created TestInfo instance will assume
|
||||||
// ownership of the factory object.
|
// ownership of the factory object.
|
||||||
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
|
||||||
const char* test_case_name,
|
const char* test_suite_name, const char* name, const char* type_param,
|
||||||
const char* name,
|
const char* value_param, CodeLocation code_location,
|
||||||
const char* type_param,
|
TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc,
|
||||||
const char* value_param,
|
TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory);
|
||||||
CodeLocation code_location,
|
|
||||||
TypeId fixture_class_id,
|
|
||||||
SetUpTestCaseFunc set_up_tc,
|
|
||||||
TearDownTestCaseFunc tear_down_tc,
|
|
||||||
TestFactoryBase* factory);
|
|
||||||
|
|
||||||
// If *pstr starts with the given prefix, modifies *pstr to be right
|
// If *pstr starts with the given prefix, modifies *pstr to be right
|
||||||
// past the prefix and returns true; otherwise leaves *pstr unchanged
|
// 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 \
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
||||||
/* class A needs to have dll-interface to be used by clients of class B */)
|
/* class A needs to have dll-interface to be used by clients of class B */)
|
||||||
|
|
||||||
// State of the definition of a type-parameterized test case.
|
// State of the definition of a type-parameterized test suite.
|
||||||
class GTEST_API_ TypedTestCasePState {
|
class GTEST_API_ TypedTestSuitePState {
|
||||||
public:
|
public:
|
||||||
TypedTestCasePState() : registered_(false) {}
|
TypedTestSuitePState() : registered_(false) {}
|
||||||
|
|
||||||
// Adds the given test name to defined_test_names_ and return true
|
// Adds the given test name to defined_test_names_ and return true
|
||||||
// if the test case hasn't been registered; otherwise aborts the
|
// if the test suite hasn't been registered; otherwise aborts the
|
||||||
// program.
|
// program.
|
||||||
bool AddTestName(const char* file, int line, const char* case_name,
|
bool AddTestName(const char* file, int line, const char* case_name,
|
||||||
const char* test_name) {
|
const char* test_name) {
|
||||||
if (registered_) {
|
if (registered_) {
|
||||||
fprintf(stderr, "%s Test %s must be defined before "
|
fprintf(stderr,
|
||||||
"REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
|
"%s Test %s must be defined before "
|
||||||
|
"REGISTER_TYPED_TEST_SUITE_P(%s, ...).\n",
|
||||||
FormatFileLocation(file, line).c_str(), test_name, case_name);
|
FormatFileLocation(file, line).c_str(), test_name, case_name);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
posix::Abort();
|
posix::Abort();
|
||||||
@ -584,6 +628,11 @@ class GTEST_API_ TypedTestCasePState {
|
|||||||
RegisteredTestsMap registered_tests_;
|
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
|
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
||||||
|
|
||||||
// Skips to the first non-space char after the first comma in 'str';
|
// 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 {
|
class TypeParameterizedTest {
|
||||||
public:
|
public:
|
||||||
// 'index' is the index of the test in the type list 'Types'
|
// 'index' is the index of the test in the type list 'Types'
|
||||||
// specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
|
// specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite,
|
||||||
// Types). Valid values for 'index' are [0, N - 1] where N is the
|
// Types). Valid values for 'index' are [0, N - 1] where N is the
|
||||||
// length of Types.
|
// length of Types.
|
||||||
static bool Register(const char* prefix, const CodeLocation& code_location,
|
static bool Register(const char* prefix, const CodeLocation& code_location,
|
||||||
@ -671,8 +720,10 @@ class TypeParameterizedTest {
|
|||||||
StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
|
StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(),
|
||||||
GetTypeName<Type>().c_str(),
|
GetTypeName<Type>().c_str(),
|
||||||
nullptr, // No value parameter.
|
nullptr, // No value parameter.
|
||||||
code_location, GetTypeId<FixtureClass>(), TestClass::SetUpTestCase,
|
code_location, GetTypeId<FixtureClass>(),
|
||||||
TestClass::TearDownTestCase, new TestFactoryImpl<TestClass>);
|
SuiteApiResolver<TestClass>::GetSetUpCaseOrSuite(),
|
||||||
|
SuiteApiResolver<TestClass>::GetTearDownCaseOrSuite(),
|
||||||
|
new TestFactoryImpl<TestClass>);
|
||||||
|
|
||||||
// Next, recurses (at compile time) with the tail of the type list.
|
// Next, recurses (at compile time) with the tail of the type list.
|
||||||
return TypeParameterizedTest<Fixture, TestSel,
|
return TypeParameterizedTest<Fixture, TestSel,
|
||||||
@ -698,15 +749,15 @@ class TypeParameterizedTest<Fixture, TestSel, Types0> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
|
// TypeParameterizedTestSuite<Fixture, Tests, Types>::Register()
|
||||||
// registers *all combinations* of 'Tests' and 'Types' with Google
|
// registers *all combinations* of 'Tests' and 'Types' with Google
|
||||||
// Test. The return value is insignificant - we just need to return
|
// Test. The return value is insignificant - we just need to return
|
||||||
// something such that we can call this function in a namespace scope.
|
// something such that we can call this function in a namespace scope.
|
||||||
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
|
template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
|
||||||
class TypeParameterizedTestCase {
|
class TypeParameterizedTestSuite {
|
||||||
public:
|
public:
|
||||||
static bool Register(const char* prefix, CodeLocation code_location,
|
static bool Register(const char* prefix, CodeLocation code_location,
|
||||||
const TypedTestCasePState* state, const char* case_name,
|
const TypedTestSuitePState* state, const char* case_name,
|
||||||
const char* test_names,
|
const char* test_names,
|
||||||
const std::vector<std::string>& type_names =
|
const std::vector<std::string>& type_names =
|
||||||
GenerateNames<DefaultNameGenerator, Types>()) {
|
GenerateNames<DefaultNameGenerator, Types>()) {
|
||||||
@ -729,20 +780,20 @@ class TypeParameterizedTestCase {
|
|||||||
prefix, test_location, case_name, test_names, 0, type_names);
|
prefix, test_location, case_name, test_names, 0, type_names);
|
||||||
|
|
||||||
// Next, recurses (at compile time) with the tail of the test list.
|
// Next, recurses (at compile time) with the tail of the test list.
|
||||||
return TypeParameterizedTestCase<Fixture, typename Tests::Tail,
|
return TypeParameterizedTestSuite<Fixture, typename Tests::Tail,
|
||||||
Types>::Register(prefix, code_location,
|
Types>::Register(prefix, code_location,
|
||||||
state, case_name,
|
state, case_name,
|
||||||
SkipComma(test_names),
|
SkipComma(test_names),
|
||||||
type_names);
|
type_names);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The base case for the compile time recursion.
|
// The base case for the compile time recursion.
|
||||||
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
template <GTEST_TEMPLATE_ Fixture, typename Types>
|
||||||
class TypeParameterizedTestCase<Fixture, Templates0, Types> {
|
class TypeParameterizedTestSuite<Fixture, Templates0, Types> {
|
||||||
public:
|
public:
|
||||||
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
static bool Register(const char* /*prefix*/, const CodeLocation&,
|
||||||
const TypedTestCasePState* /*state*/,
|
const TypedTestSuitePState* /*state*/,
|
||||||
const char* /*case_name*/, const char* /*test_names*/,
|
const char* /*case_name*/, const char* /*test_names*/,
|
||||||
const std::vector<std::string>& =
|
const std::vector<std::string>& =
|
||||||
std::vector<std::string>() /*type_names*/) {
|
std::vector<std::string>() /*type_names*/) {
|
||||||
@ -1376,32 +1427,35 @@ class FlatTuple
|
|||||||
" Actual: it does.")
|
" Actual: it does.")
|
||||||
|
|
||||||
// Expands to the name of the class that implements the given test.
|
// Expands to the name of the class that implements the given test.
|
||||||
#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||||
test_case_name##_##test_name##_Test
|
test_suite_name##_##test_name##_Test
|
||||||
|
|
||||||
// Helper macro for defining tests.
|
// Helper macro for defining tests.
|
||||||
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id) \
|
#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \
|
||||||
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
|
class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \
|
||||||
: public parent_class { \
|
: public parent_class { \
|
||||||
public: \
|
public: \
|
||||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
|
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
virtual void TestBody(); \
|
virtual void TestBody(); \
|
||||||
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_case_name, \
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||||
test_name)); \
|
test_name)); \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, \
|
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \
|
||||||
test_name)::test_info_ = \
|
test_name)::test_info_ = \
|
||||||
::testing::internal::MakeAndRegisterTestInfo( \
|
::testing::internal::MakeAndRegisterTestInfo( \
|
||||||
#test_case_name, #test_name, nullptr, nullptr, \
|
#test_suite_name, #test_name, nullptr, nullptr, \
|
||||||
::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \
|
::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_( \
|
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
|
||||||
test_case_name, test_name)>); \
|
test_suite_name, test_name)>); \
|
||||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
|
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
|
||||||
|
|
||||||
// Internal Macro to mark an API deprecated, for googletest usage only
|
// Internal Macro to mark an API deprecated, for googletest usage only
|
||||||
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
|
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or
|
||||||
|
@ -75,11 +75,11 @@ namespace internal {
|
|||||||
// Utility Functions
|
// Utility Functions
|
||||||
|
|
||||||
// Outputs a message explaining invalid registration of different
|
// Outputs a message explaining invalid registration of different
|
||||||
// fixture class for the same test case. This may happen when
|
// fixture class for the same test suite. This may happen when
|
||||||
// TEST_P macro is used to define two tests with the same name
|
// TEST_P macro is used to define two tests with the same name
|
||||||
// but in different namespaces.
|
// but in different namespaces.
|
||||||
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name,
|
||||||
CodeLocation code_location);
|
CodeLocation code_location);
|
||||||
|
|
||||||
template <typename> class ParamGeneratorInterface;
|
template <typename> class ParamGeneratorInterface;
|
||||||
template <typename> class ParamGenerator;
|
template <typename> class ParamGenerator;
|
||||||
@ -379,7 +379,7 @@ std::string DefaultParamName(const TestParamInfo<ParamType>& info) {
|
|||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// Parameterized test name overload helpers, which help the
|
// Parameterized test name overload helpers, which help the
|
||||||
// INSTANTIATE_TEST_CASE_P macro choose between the default parameterized
|
// INSTANTIATE_TEST_SUITE_P macro choose between the default parameterized
|
||||||
// test name generator and user param name generator.
|
// test name generator and user param name generator.
|
||||||
template <class ParamType, class ParamNameGenFunctor>
|
template <class ParamType, class ParamNameGenFunctor>
|
||||||
ParamNameGenFunctor GetParamNameGen(ParamNameGenFunctor func) {
|
ParamNameGenFunctor GetParamNameGen(ParamNameGenFunctor func) {
|
||||||
@ -434,19 +434,19 @@ class TestMetaFactoryBase {
|
|||||||
// TestMetaFactory creates test factories for passing into
|
// TestMetaFactory creates test factories for passing into
|
||||||
// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
|
// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
|
||||||
// ownership of test factory pointer, same factory object cannot be passed
|
// ownership of test factory pointer, same factory object cannot be passed
|
||||||
// into that method twice. But ParameterizedTestCaseInfo is going to call
|
// into that method twice. But ParameterizedTestSuiteInfo is going to call
|
||||||
// it for each Test/Parameter value combination. Thus it needs meta factory
|
// it for each Test/Parameter value combination. Thus it needs meta factory
|
||||||
// creator class.
|
// creator class.
|
||||||
template <class TestCase>
|
template <class TestSuite>
|
||||||
class TestMetaFactory
|
class TestMetaFactory
|
||||||
: public TestMetaFactoryBase<typename TestCase::ParamType> {
|
: public TestMetaFactoryBase<typename TestSuite::ParamType> {
|
||||||
public:
|
public:
|
||||||
typedef typename TestCase::ParamType ParamType;
|
using ParamType = typename TestSuite::ParamType;
|
||||||
|
|
||||||
TestMetaFactory() {}
|
TestMetaFactory() {}
|
||||||
|
|
||||||
TestFactoryBase* CreateTestFactory(ParamType parameter) override {
|
TestFactoryBase* CreateTestFactory(ParamType parameter) override {
|
||||||
return new ParameterizedTestFactory<TestCase>(parameter);
|
return new ParameterizedTestFactory<TestSuite>(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -455,89 +455,88 @@ class TestMetaFactory
|
|||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// ParameterizedTestCaseInfoBase is a generic interface
|
// ParameterizedTestSuiteInfoBase is a generic interface
|
||||||
// to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase
|
// to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase
|
||||||
// accumulates test information provided by TEST_P macro invocations
|
// accumulates test information provided by TEST_P macro invocations
|
||||||
// and generators provided by INSTANTIATE_TEST_CASE_P macro invocations
|
// and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations
|
||||||
// and uses that information to register all resulting test instances
|
// and uses that information to register all resulting test instances
|
||||||
// in RegisterTests method. The ParameterizeTestCaseRegistry class holds
|
// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds
|
||||||
// a collection of pointers to the ParameterizedTestCaseInfo objects
|
// a collection of pointers to the ParameterizedTestSuiteInfo objects
|
||||||
// and calls RegisterTests() on each of them when asked.
|
// and calls RegisterTests() on each of them when asked.
|
||||||
class ParameterizedTestCaseInfoBase {
|
class ParameterizedTestSuiteInfoBase {
|
||||||
public:
|
public:
|
||||||
virtual ~ParameterizedTestCaseInfoBase() {}
|
virtual ~ParameterizedTestSuiteInfoBase() {}
|
||||||
|
|
||||||
// Base part of test case name for display purposes.
|
// Base part of test suite name for display purposes.
|
||||||
virtual const std::string& GetTestCaseName() const = 0;
|
virtual const std::string& GetTestSuiteName() const = 0;
|
||||||
// Test case id to verify identity.
|
// Test case id to verify identity.
|
||||||
virtual TypeId GetTestCaseTypeId() const = 0;
|
virtual TypeId GetTestSuiteTypeId() const = 0;
|
||||||
// UnitTest class invokes this method to register tests in this
|
// UnitTest class invokes this method to register tests in this
|
||||||
// test case right before running them in RUN_ALL_TESTS macro.
|
// test suite right before running them in RUN_ALL_TESTS macro.
|
||||||
// This method should not be called more then once on any single
|
// This method should not be called more then once on any single
|
||||||
// instance of a ParameterizedTestCaseInfoBase derived class.
|
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||||
virtual void RegisterTests() = 0;
|
virtual void RegisterTests() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ParameterizedTestCaseInfoBase() {}
|
ParameterizedTestSuiteInfoBase() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfoBase);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase);
|
||||||
};
|
};
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// ParameterizedTestCaseInfo accumulates tests obtained from TEST_P
|
// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P
|
||||||
// macro invocations for a particular test case and generators
|
// macro invocations for a particular test suite and generators
|
||||||
// obtained from INSTANTIATE_TEST_CASE_P macro invocations for that
|
// obtained from INSTANTIATE_TEST_SUITE_P macro invocations for that
|
||||||
// test case. It registers tests with all values generated by all
|
// test suite. It registers tests with all values generated by all
|
||||||
// generators when asked.
|
// generators when asked.
|
||||||
template <class TestCase>
|
template <class TestSuite>
|
||||||
class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase {
|
||||||
public:
|
public:
|
||||||
// ParamType and GeneratorCreationFunc are private types but are required
|
// ParamType and GeneratorCreationFunc are private types but are required
|
||||||
// for declarations of public methods AddTestPattern() and
|
// for declarations of public methods AddTestPattern() and
|
||||||
// AddTestCaseInstantiation().
|
// AddTestSuiteInstantiation().
|
||||||
typedef typename TestCase::ParamType ParamType;
|
using ParamType = typename TestSuite::ParamType;
|
||||||
// A function that returns an instance of appropriate generator type.
|
// A function that returns an instance of appropriate generator type.
|
||||||
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
|
||||||
typedef typename ParamNameGenFunc<ParamType>::Type ParamNameGeneratorFunc;
|
typedef typename ParamNameGenFunc<ParamType>::Type ParamNameGeneratorFunc;
|
||||||
|
|
||||||
explicit ParameterizedTestCaseInfo(
|
explicit ParameterizedTestSuiteInfo(const char* name,
|
||||||
const char* name, CodeLocation code_location)
|
CodeLocation code_location)
|
||||||
: test_case_name_(name), code_location_(code_location) {}
|
: test_suite_name_(name), code_location_(code_location) {}
|
||||||
|
|
||||||
// Test case base name for display purposes.
|
// Test case base name for display purposes.
|
||||||
const std::string& GetTestCaseName() const override {
|
const std::string& GetTestSuiteName() const override {
|
||||||
return test_case_name_;
|
return test_suite_name_;
|
||||||
}
|
}
|
||||||
// Test case id to verify identity.
|
// Test case id to verify identity.
|
||||||
TypeId GetTestCaseTypeId() const override { return GetTypeId<TestCase>(); }
|
TypeId GetTestSuiteTypeId() const override { return GetTypeId<TestSuite>(); }
|
||||||
// TEST_P macro uses AddTestPattern() to record information
|
// TEST_P macro uses AddTestPattern() to record information
|
||||||
// about a single test in a LocalTestInfo structure.
|
// about a single test in a LocalTestInfo structure.
|
||||||
// test_case_name is the base name of the test case (without invocation
|
// test_suite_name is the base name of the test suite (without invocation
|
||||||
// prefix). test_base_name is the name of an individual test without
|
// prefix). test_base_name is the name of an individual test without
|
||||||
// parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
|
// parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
|
||||||
// test case base name and DoBar is test base name.
|
// test suite base name and DoBar is test base name.
|
||||||
void AddTestPattern(const char* test_case_name,
|
void AddTestPattern(const char* test_suite_name, const char* test_base_name,
|
||||||
const char* test_base_name,
|
|
||||||
TestMetaFactoryBase<ParamType>* meta_factory) {
|
TestMetaFactoryBase<ParamType>* meta_factory) {
|
||||||
tests_.push_back(std::shared_ptr<TestInfo>(
|
tests_.push_back(std::shared_ptr<TestInfo>(
|
||||||
new TestInfo(test_case_name, test_base_name, meta_factory)));
|
new TestInfo(test_suite_name, test_base_name, meta_factory)));
|
||||||
}
|
}
|
||||||
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
|
// INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information
|
||||||
// about a generator.
|
// about a generator.
|
||||||
int AddTestCaseInstantiation(const std::string& instantiation_name,
|
int AddTestSuiteInstantiation(const std::string& instantiation_name,
|
||||||
GeneratorCreationFunc* func,
|
GeneratorCreationFunc* func,
|
||||||
ParamNameGeneratorFunc* name_func,
|
ParamNameGeneratorFunc* name_func,
|
||||||
const char* file, int line) {
|
const char* file, int line) {
|
||||||
instantiations_.push_back(
|
instantiations_.push_back(
|
||||||
InstantiationInfo(instantiation_name, func, name_func, file, line));
|
InstantiationInfo(instantiation_name, func, name_func, file, line));
|
||||||
return 0; // Return value used only to run this method in namespace scope.
|
return 0; // Return value used only to run this method in namespace scope.
|
||||||
}
|
}
|
||||||
// UnitTest class invokes this method to register tests in this test case
|
// UnitTest class invokes this method to register tests in this test suite
|
||||||
// test cases right before running tests in RUN_ALL_TESTS macro.
|
// test suites right before running tests in RUN_ALL_TESTS macro.
|
||||||
// This method should not be called more then once on any single
|
// This method should not be called more then once on any single
|
||||||
// instance of a ParameterizedTestCaseInfoBase derived class.
|
// instance of a ParameterizedTestSuiteInfoBase derived class.
|
||||||
// UnitTest has a guard to prevent from calling this method more then once.
|
// UnitTest has a guard to prevent from calling this method more then once.
|
||||||
void RegisterTests() override {
|
void RegisterTests() override {
|
||||||
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
for (typename TestInfoContainer::iterator test_it = tests_.begin();
|
||||||
@ -552,10 +551,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
|||||||
const char* file = gen_it->file;
|
const char* file = gen_it->file;
|
||||||
int line = gen_it->line;
|
int line = gen_it->line;
|
||||||
|
|
||||||
std::string test_case_name;
|
std::string test_suite_name;
|
||||||
if ( !instantiation_name.empty() )
|
if ( !instantiation_name.empty() )
|
||||||
test_case_name = instantiation_name + "/";
|
test_suite_name = instantiation_name + "/";
|
||||||
test_case_name += test_info->test_case_base_name;
|
test_suite_name += test_info->test_suite_base_name;
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
std::set<std::string> test_param_names;
|
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;
|
test_name_stream << test_info->test_base_name << "/" << param_name;
|
||||||
MakeAndRegisterTestInfo(
|
MakeAndRegisterTestInfo(
|
||||||
test_case_name.c_str(), test_name_stream.GetString().c_str(),
|
test_suite_name.c_str(), test_name_stream.GetString().c_str(),
|
||||||
nullptr, // No type parameter.
|
nullptr, // No type parameter.
|
||||||
PrintToString(*param_it).c_str(), code_location_,
|
PrintToString(*param_it).c_str(), code_location_,
|
||||||
GetTestCaseTypeId(), TestCase::SetUpTestCase,
|
GetTestSuiteTypeId(),
|
||||||
TestCase::TearDownTestCase,
|
SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(),
|
||||||
|
SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(),
|
||||||
test_info->test_meta_factory->CreateTestFactory(*param_it));
|
test_info->test_meta_factory->CreateTestFactory(*param_it));
|
||||||
} // for param_it
|
} // for param_it
|
||||||
} // for gen_it
|
} // for gen_it
|
||||||
@ -595,19 +595,18 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
|||||||
// LocalTestInfo structure keeps information about a single test registered
|
// LocalTestInfo structure keeps information about a single test registered
|
||||||
// with TEST_P macro.
|
// with TEST_P macro.
|
||||||
struct TestInfo {
|
struct TestInfo {
|
||||||
TestInfo(const char* a_test_case_base_name,
|
TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name,
|
||||||
const char* a_test_base_name,
|
TestMetaFactoryBase<ParamType>* a_test_meta_factory)
|
||||||
TestMetaFactoryBase<ParamType>* a_test_meta_factory) :
|
: test_suite_base_name(a_test_suite_base_name),
|
||||||
test_case_base_name(a_test_case_base_name),
|
test_base_name(a_test_base_name),
|
||||||
test_base_name(a_test_base_name),
|
test_meta_factory(a_test_meta_factory) {}
|
||||||
test_meta_factory(a_test_meta_factory) {}
|
|
||||||
|
|
||||||
const std::string test_case_base_name;
|
const std::string test_suite_base_name;
|
||||||
const std::string test_base_name;
|
const std::string test_base_name;
|
||||||
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
|
||||||
};
|
};
|
||||||
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
|
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
|
||||||
// Records data received from INSTANTIATE_TEST_CASE_P macros:
|
// Records data received from INSTANTIATE_TEST_SUITE_P macros:
|
||||||
// <Instantiation name, Sequence generator creation function,
|
// <Instantiation name, Sequence generator creation function,
|
||||||
// Name generator function, Source file, Source line>
|
// Name generator function, Source file, Source line>
|
||||||
struct InstantiationInfo {
|
struct InstantiationInfo {
|
||||||
@ -644,76 +643,87 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string test_case_name_;
|
const std::string test_suite_name_;
|
||||||
CodeLocation code_location_;
|
CodeLocation code_location_;
|
||||||
TestInfoContainer tests_;
|
TestInfoContainer tests_;
|
||||||
InstantiationContainer instantiations_;
|
InstantiationContainer instantiations_;
|
||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo);
|
||||||
}; // class ParameterizedTestCaseInfo
|
}; // 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.
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
//
|
//
|
||||||
// ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase
|
// ParameterizedTestSuiteRegistry contains a map of
|
||||||
// classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P
|
// ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P
|
||||||
// macros use it to locate their corresponding ParameterizedTestCaseInfo
|
// and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding
|
||||||
// descriptors.
|
// ParameterizedTestSuiteInfo descriptors.
|
||||||
class ParameterizedTestCaseRegistry {
|
class ParameterizedTestSuiteRegistry {
|
||||||
public:
|
public:
|
||||||
ParameterizedTestCaseRegistry() {}
|
ParameterizedTestSuiteRegistry() {}
|
||||||
~ParameterizedTestCaseRegistry() {
|
~ParameterizedTestSuiteRegistry() {
|
||||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
for (auto& test_suite_info : test_suite_infos_) {
|
||||||
it != test_case_infos_.end(); ++it) {
|
delete test_suite_info;
|
||||||
delete *it;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looks up or creates and returns a structure containing information about
|
// Looks up or creates and returns a structure containing information about
|
||||||
// tests and instantiations of a particular test case.
|
// tests and instantiations of a particular test suite.
|
||||||
template <class TestCase>
|
template <class TestSuite>
|
||||||
ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
|
ParameterizedTestSuiteInfo<TestSuite>* GetTestSuitePatternHolder(
|
||||||
const char* test_case_name,
|
const char* test_suite_name, CodeLocation code_location) {
|
||||||
CodeLocation code_location) {
|
ParameterizedTestSuiteInfo<TestSuite>* typed_test_info = nullptr;
|
||||||
ParameterizedTestCaseInfo<TestCase>* typed_test_info = nullptr;
|
for (auto& test_suite_info : test_suite_infos_) {
|
||||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
if (test_suite_info->GetTestSuiteName() == test_suite_name) {
|
||||||
it != test_case_infos_.end(); ++it) {
|
if (test_suite_info->GetTestSuiteTypeId() != GetTypeId<TestSuite>()) {
|
||||||
if ((*it)->GetTestCaseName() == test_case_name) {
|
|
||||||
if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) {
|
|
||||||
// Complain about incorrect usage of Google Test facilities
|
// Complain about incorrect usage of Google Test facilities
|
||||||
// and terminate the program since we cannot guaranty correct
|
// and terminate the program since we cannot guaranty correct
|
||||||
// test case setup and tear-down in this case.
|
// test suite setup and tear-down in this case.
|
||||||
ReportInvalidTestCaseType(test_case_name, code_location);
|
ReportInvalidTestSuiteType(test_suite_name, code_location);
|
||||||
posix::Abort();
|
posix::Abort();
|
||||||
} else {
|
} else {
|
||||||
// At this point we are sure that the object we found is of the same
|
// 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
|
// type we are looking for, so we downcast it to that type
|
||||||
// without further checks.
|
// without further checks.
|
||||||
typed_test_info = CheckedDowncastToActualType<
|
typed_test_info = CheckedDowncastToActualType<
|
||||||
ParameterizedTestCaseInfo<TestCase> >(*it);
|
ParameterizedTestSuiteInfo<TestSuite> >(test_suite_info);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typed_test_info == nullptr) {
|
if (typed_test_info == nullptr) {
|
||||||
typed_test_info = new ParameterizedTestCaseInfo<TestCase>(
|
typed_test_info = new ParameterizedTestSuiteInfo<TestSuite>(
|
||||||
test_case_name, code_location);
|
test_suite_name, code_location);
|
||||||
test_case_infos_.push_back(typed_test_info);
|
test_suite_infos_.push_back(typed_test_info);
|
||||||
}
|
}
|
||||||
return typed_test_info;
|
return typed_test_info;
|
||||||
}
|
}
|
||||||
void RegisterTests() {
|
void RegisterTests() {
|
||||||
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
|
for (auto& test_suite_info : test_suite_infos_) {
|
||||||
it != test_case_infos_.end(); ++it) {
|
test_suite_info->RegisterTests();
|
||||||
(*it)->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:
|
private:
|
||||||
typedef ::std::vector<ParameterizedTestCaseInfoBase*> TestCaseInfoContainer;
|
using TestSuiteInfoContainer = ::std::vector<ParameterizedTestSuiteInfoBase*>;
|
||||||
|
|
||||||
TestCaseInfoContainer test_case_infos_;
|
TestSuiteInfoContainer test_suite_infos_;
|
||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -250,6 +250,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#ifndef _WIN32_WCE
|
#ifndef _WIN32_WCE
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
@ -31,12 +31,11 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
// Type utilities needed for implementing typed and type-parameterized
|
// Type utilities needed for implementing typed and type-parameterized
|
||||||
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
|
// 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
|
// Currently we support at most 50 types in a list, and at most 50
|
||||||
// type-parameterized tests in one type-parameterized test case.
|
// type-parameterized tests in one type-parameterized test suite.
|
||||||
// Please contact googletestframework@googlegroups.com if you need
|
// Please contact googletestframework@googlegroups.com if you need
|
||||||
// more.
|
// 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
|
// The TypeList template makes it possible to use either a single type
|
||||||
// or a Types<...> list in TYPED_TEST_CASE() and
|
// or a Types<...> list in TYPED_TEST_SUITE() and
|
||||||
// INSTANTIATE_TYPED_TEST_CASE_P().
|
// INSTANTIATE_TYPED_TEST_SUITE_P().
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeList {
|
struct TypeList {
|
||||||
|
@ -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!
|
// 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
|
// Currently we support at most $n types in a list, and at most $n
|
||||||
// type-parameterized tests in one type-parameterized test case.
|
// type-parameterized tests in one type-parameterized test suite.
|
||||||
// Please contact googletestframework@googlegroups.com if you need
|
// Please contact googletestframework@googlegroups.com if you need
|
||||||
// more.
|
// 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
|
// The TypeList template makes it possible to use either a single type
|
||||||
// or a Types<...> list in TYPED_TEST_CASE() and
|
// or a Types<...> list in TYPED_TEST_SUITE() and
|
||||||
// INSTANTIATE_TYPED_TEST_CASE_P().
|
// INSTANTIATE_TYPED_TEST_SUITE_P().
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TypeList {
|
struct TypeList {
|
||||||
|
@ -753,9 +753,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
|
|||||||
FALSE, // The initial state is non-signalled.
|
FALSE, // The initial state is non-signalled.
|
||||||
nullptr)); // The even is unnamed.
|
nullptr)); // The even is unnamed.
|
||||||
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
|
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != nullptr);
|
||||||
const std::string filter_flag =
|
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
|
||||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
|
kFilterFlag + "=" + info->test_suite_name() +
|
||||||
info->test_case_name() + "." + info->name();
|
"." + info->name();
|
||||||
const std::string internal_flag =
|
const std::string internal_flag =
|
||||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
|
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
|
||||||
"=" + file_ + "|" + StreamableToString(line_) + "|" +
|
"=" + file_ + "|" + StreamableToString(line_) + "|" +
|
||||||
@ -972,9 +972,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
|
|||||||
FlushInfoLog();
|
FlushInfoLog();
|
||||||
|
|
||||||
// Build the child process command line.
|
// Build the child process command line.
|
||||||
const std::string filter_flag =
|
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
|
||||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
|
kFilterFlag + "=" + info->test_suite_name() +
|
||||||
+ info->test_case_name() + "." + info->name();
|
"." + info->name();
|
||||||
const std::string internal_flag =
|
const std::string internal_flag =
|
||||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
||||||
+ file_ + "|"
|
+ file_ + "|"
|
||||||
@ -1411,9 +1411,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
|
|||||||
// it be closed when the child process does an exec:
|
// it be closed when the child process does an exec:
|
||||||
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
|
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
|
||||||
|
|
||||||
const std::string filter_flag =
|
const std::string filter_flag = std::string("--") + GTEST_FLAG_PREFIX_ +
|
||||||
std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
|
kFilterFlag + "=" + info->test_suite_name() +
|
||||||
+ info->test_case_name() + "." + info->name();
|
"." + info->name();
|
||||||
const std::string internal_flag =
|
const std::string internal_flag =
|
||||||
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
|
||||||
+ file_ + "|" + StreamableToString(line_) + "|"
|
+ file_ + "|" + StreamableToString(line_) + "|"
|
||||||
|
@ -388,10 +388,10 @@ class GTEST_API_ UnitTestOptions {
|
|||||||
// works well enough for matching test names, which are short.
|
// works well enough for matching test names, which are short.
|
||||||
static bool PatternMatchesString(const char *pattern, const char *str);
|
static bool PatternMatchesString(const char *pattern, const char *str);
|
||||||
|
|
||||||
// Returns true iff the user-specified filter matches the test case
|
// Returns true iff the user-specified filter matches the test suite
|
||||||
// name and the test name.
|
// name and the test name.
|
||||||
static bool FilterMatchesTest(const std::string &test_case_name,
|
static bool FilterMatchesTest(const std::string& test_suite_name,
|
||||||
const std::string &test_name);
|
const std::string& test_name);
|
||||||
|
|
||||||
#if GTEST_OS_WINDOWS
|
#if GTEST_OS_WINDOWS
|
||||||
// Function for supporting the gtest_catch_exception flag.
|
// Function for supporting the gtest_catch_exception flag.
|
||||||
@ -529,18 +529,18 @@ class GTEST_API_ UnitTestImpl {
|
|||||||
void SetTestPartResultReporterForCurrentThread(
|
void SetTestPartResultReporterForCurrentThread(
|
||||||
TestPartResultReporterInterface* reporter);
|
TestPartResultReporterInterface* reporter);
|
||||||
|
|
||||||
// Gets the number of successful test cases.
|
// Gets the number of successful test suites.
|
||||||
int successful_test_case_count() const;
|
int successful_test_suite_count() const;
|
||||||
|
|
||||||
// Gets the number of failed test cases.
|
// Gets the number of failed test suites.
|
||||||
int failed_test_case_count() const;
|
int failed_test_suite_count() const;
|
||||||
|
|
||||||
// Gets the number of all test cases.
|
// Gets the number of all test suites.
|
||||||
int total_test_case_count() const;
|
int total_test_suite_count() const;
|
||||||
|
|
||||||
// Gets the number of all test cases that contain at least one test
|
// Gets the number of all test suites that contain at least one test
|
||||||
// that should run.
|
// that should run.
|
||||||
int test_case_to_run_count() const;
|
int test_suite_to_run_count() const;
|
||||||
|
|
||||||
// Gets the number of successful tests.
|
// Gets the number of successful tests.
|
||||||
int successful_test_count() const;
|
int successful_test_count() const;
|
||||||
@ -573,27 +573,32 @@ class GTEST_API_ UnitTestImpl {
|
|||||||
// Gets the elapsed time, in milliseconds.
|
// Gets the elapsed time, in milliseconds.
|
||||||
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
TimeInMillis elapsed_time() const { return elapsed_time_; }
|
||||||
|
|
||||||
// Returns true iff the unit test passed (i.e. all test cases passed).
|
// Returns true iff the unit test passed (i.e. all test suites passed).
|
||||||
bool Passed() const { return !Failed(); }
|
bool Passed() const { return !Failed(); }
|
||||||
|
|
||||||
// Returns true iff the unit test failed (i.e. some test case failed
|
// Returns true iff the unit test failed (i.e. some test suite failed
|
||||||
// or something outside of all tests failed).
|
// or something outside of all tests failed).
|
||||||
bool Failed() const {
|
bool Failed() const {
|
||||||
return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
|
return failed_test_suite_count() > 0 || ad_hoc_test_result()->Failed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
// Gets the i-th test suite among all the test suites. i can range from 0 to
|
||||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
// total_test_suite_count() - 1. If i is not in that range, returns NULL.
|
||||||
const TestCase* GetTestCase(int i) const {
|
const TestSuite* GetTestSuite(int i) const {
|
||||||
const int index = GetElementOr(test_case_indices_, i, -1);
|
const int index = GetElementOr(test_suite_indices_, i, -1);
|
||||||
return index < 0 ? nullptr : test_cases_[i];
|
return index < 0 ? nullptr : test_suites_[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the i-th test case among all the test cases. i can range from 0 to
|
// Legacy API is deprecated but still available
|
||||||
// total_test_case_count() - 1. If i is not in that range, returns NULL.
|
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
TestCase* GetMutableTestCase(int i) {
|
const TestCase* GetTestCase(int i) const { return GetTestSuite(i); }
|
||||||
const int index = GetElementOr(test_case_indices_, i, -1);
|
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||||
return index < 0 ? nullptr : test_cases_[index];
|
|
||||||
|
// 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.
|
// Provides access to the event listener list.
|
||||||
@ -630,30 +635,38 @@ class GTEST_API_ UnitTestImpl {
|
|||||||
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
|
||||||
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
|
std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
|
||||||
|
|
||||||
// Finds and returns a TestCase with the given name. If one doesn't
|
// Finds and returns a TestSuite with the given name. If one doesn't
|
||||||
// exist, creates one and returns it.
|
// exist, creates one and returns it.
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
// test_case_name: name of the test case
|
// test_suite_name: name of the test suite
|
||||||
// type_param: the name of the test's type parameter, or NULL if
|
// type_param: the name of the test's type parameter, or NULL if
|
||||||
// this is not a typed or a type-parameterized test.
|
// this is not a typed or a type-parameterized test.
|
||||||
// set_up_tc: pointer to the function that sets up the test case
|
// 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 case
|
// tear_down_tc: pointer to the function that tears down the test suite
|
||||||
TestCase* GetTestCase(const char* test_case_name,
|
TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param,
|
||||||
const char* type_param,
|
internal::SetUpTestSuiteFunc set_up_tc,
|
||||||
Test::SetUpTestCaseFunc set_up_tc,
|
internal::TearDownTestSuiteFunc tear_down_tc);
|
||||||
Test::TearDownTestCaseFunc 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.
|
// Adds a TestInfo to the unit test.
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
//
|
//
|
||||||
// set_up_tc: pointer to the function that sets up the test case
|
// 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 case
|
// tear_down_tc: pointer to the function that tears down the test suite
|
||||||
// test_info: the TestInfo object
|
// test_info: the TestInfo object
|
||||||
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
|
void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
|
||||||
Test::TearDownTestCaseFunc tear_down_tc,
|
internal::TearDownTestSuiteFunc tear_down_tc,
|
||||||
TestInfo* test_info) {
|
TestInfo* test_info) {
|
||||||
// In order to support thread-safe death tests, we need to
|
// In order to support thread-safe death tests, we need to
|
||||||
// remember the original working directory when the test program
|
// remember the original working directory when the test program
|
||||||
@ -668,21 +681,20 @@ class GTEST_API_ UnitTestImpl {
|
|||||||
<< "Failed to get the current working directory.";
|
<< "Failed to get the current working directory.";
|
||||||
}
|
}
|
||||||
|
|
||||||
GetTestCase(test_info->test_case_name(),
|
GetTestSuite(test_info->test_suite_name(), test_info->type_param(),
|
||||||
test_info->type_param(),
|
set_up_tc, tear_down_tc)
|
||||||
set_up_tc,
|
->AddTestInfo(test_info);
|
||||||
tear_down_tc)->AddTestInfo(test_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns ParameterizedTestCaseRegistry object used to keep track of
|
// Returns ParameterizedTestSuiteRegistry object used to keep track of
|
||||||
// value-parameterized tests and instantiate and register them.
|
// value-parameterized tests and instantiate and register them.
|
||||||
internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
|
internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() {
|
||||||
return parameterized_test_registry_;
|
return parameterized_test_registry_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the TestCase object for the test that's currently running.
|
// Sets the TestSuite object for the test that's currently running.
|
||||||
void set_current_test_case(TestCase* a_current_test_case) {
|
void set_current_test_suite(TestSuite* a_current_test_suite) {
|
||||||
current_test_case_ = a_current_test_case;
|
current_test_suite_ = a_current_test_suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the TestInfo object for the test that's currently running. If
|
// 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
|
// Registers all parameterized tests defined using TEST_P and
|
||||||
// INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
|
// INSTANTIATE_TEST_SUITE_P, creating regular tests for each test/parameter
|
||||||
// combination. This method can be called more then once; it has guards
|
// combination. This method can be called more then once; it has guards
|
||||||
// protecting from registering the tests more then once. If
|
// protecting from registering the tests more then once. If
|
||||||
// value-parameterized tests are disabled, RegisterParameterizedTests is
|
// 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.
|
// Clears the results of all tests, except the ad hoc tests.
|
||||||
void ClearNonAdHocTestResult() {
|
void ClearNonAdHocTestResult() {
|
||||||
ForEach(test_cases_, TestCase::ClearTestCaseResult);
|
ForEach(test_suites_, TestSuite::ClearTestSuiteResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clears the results of ad-hoc test assertions.
|
// 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
|
// Adds a TestProperty to the current TestResult object when invoked in a
|
||||||
// context of a test or a test case, or to the global property set. If the
|
// context of a test or a test suite, or to the global property set. If the
|
||||||
// result already contains a property with the same key, the value will be
|
// result already contains a property with the same key, the value will be
|
||||||
// updated.
|
// updated.
|
||||||
void RecordProperty(const TestProperty& test_property);
|
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
|
// Matches the full name of each test against the user-specified
|
||||||
// filter to decide whether the test should run, then records the
|
// filter to decide whether the test should run, then records the
|
||||||
// result in each TestCase and TestInfo object.
|
// result in each TestSuite and TestInfo object.
|
||||||
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
|
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
|
||||||
// based on sharding variables in the environment.
|
// based on sharding variables in the environment.
|
||||||
// Returns the number of tests that should run.
|
// 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.
|
// Prints the names of the tests matching the user-specified filter flag.
|
||||||
void ListTestsMatchingFilter();
|
void ListTestsMatchingFilter();
|
||||||
|
|
||||||
const TestCase* current_test_case() const { return current_test_case_; }
|
const TestSuite* current_test_suite() const { return current_test_suite_; }
|
||||||
TestInfo* current_test_info() { return current_test_info_; }
|
TestInfo* current_test_info() { return current_test_info_; }
|
||||||
const TestInfo* current_test_info() const { 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.
|
// Gets the random number generator.
|
||||||
internal::Random* random() { return &random_; }
|
internal::Random* random() { return &random_; }
|
||||||
|
|
||||||
// Shuffles all test cases, and the tests within each test case,
|
// Shuffles all test suites, and the tests within each test suite,
|
||||||
// making sure that death tests are still run first.
|
// making sure that death tests are still run first.
|
||||||
void ShuffleTests();
|
void ShuffleTests();
|
||||||
|
|
||||||
// Restores the test cases and tests to their order before the first shuffle.
|
// Restores the test suites and tests to their order before the first shuffle.
|
||||||
void UnshuffleTests();
|
void UnshuffleTests();
|
||||||
|
|
||||||
// Returns the value of GTEST_FLAG(catch_exceptions) at the moment
|
// 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.
|
// before/after the tests are run.
|
||||||
std::vector<Environment*> environments_;
|
std::vector<Environment*> environments_;
|
||||||
|
|
||||||
// The vector of TestCases in their original order. It owns the
|
// The vector of TestSuites in their original order. It owns the
|
||||||
// elements in the vector.
|
// elements in the vector.
|
||||||
std::vector<TestCase*> test_cases_;
|
std::vector<TestSuite*> test_suites_;
|
||||||
|
|
||||||
// Provides a level of indirection for the test case list to allow
|
// Provides a level of indirection for the test suite list to allow
|
||||||
// easy shuffling and restoring the test case order. The i-th
|
// easy shuffling and restoring the test suite order. The i-th
|
||||||
// element of this vector is the index of the i-th test case in the
|
// element of this vector is the index of the i-th test suite in the
|
||||||
// shuffled order.
|
// shuffled order.
|
||||||
std::vector<int> test_case_indices_;
|
std::vector<int> test_suite_indices_;
|
||||||
|
|
||||||
// ParameterizedTestRegistry object used to register value-parameterized
|
// ParameterizedTestRegistry object used to register value-parameterized
|
||||||
// tests.
|
// tests.
|
||||||
internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
|
internal::ParameterizedTestSuiteRegistry parameterized_test_registry_;
|
||||||
|
|
||||||
// Indicates whether RegisterParameterizedTests() has been called already.
|
// Indicates whether RegisterParameterizedTests() has been called already.
|
||||||
bool parameterized_tests_registered_;
|
bool parameterized_tests_registered_;
|
||||||
|
|
||||||
// Index of the last death test case registered. Initially -1.
|
// Index of the last death test suite registered. Initially -1.
|
||||||
int last_death_test_case_;
|
int last_death_test_suite_;
|
||||||
|
|
||||||
// This points to the TestCase for the currently running test. It
|
// This points to the TestSuite for the currently running test. It
|
||||||
// changes as Google Test goes through one test case after another.
|
// changes as Google Test goes through one test suite after another.
|
||||||
// When no test is running, this is set to NULL and Google Test
|
// When no test is running, this is set to NULL and Google Test
|
||||||
// stores assertion results in ad_hoc_test_result_. Initially NULL.
|
// stores assertion results in ad_hoc_test_result_. Initially NULL.
|
||||||
TestCase* current_test_case_;
|
TestSuite* current_test_suite_;
|
||||||
|
|
||||||
// This points to the TestInfo for the currently running test. It
|
// This points to the TestInfo for the currently running test. It
|
||||||
// changes as Google Test goes through one test after another. When
|
// 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");
|
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 {
|
void OnTestCaseStart(const TestCase& test_case) override {
|
||||||
SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
|
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 {
|
void OnTestCaseEnd(const TestCase& test_case) override {
|
||||||
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
|
SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) +
|
||||||
+ "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
|
"&elapsed_time=" + StreamableToString(test_case.elapsed_time()) +
|
||||||
+ "ms");
|
"ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTestStart(const TestInfo& test_info) override {
|
void OnTestStart(const TestInfo& test_info) override {
|
||||||
|
@ -57,7 +57,7 @@ static std::vector<std::string> SplitIntoTestNames(const char* src) {
|
|||||||
// Verifies that registered_tests match the test names in
|
// Verifies that registered_tests match the test names in
|
||||||
// registered_tests_; returns registered_tests if successful, or
|
// registered_tests_; returns registered_tests if successful, or
|
||||||
// aborts the program otherwise.
|
// aborts the program otherwise.
|
||||||
const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
const char* TypedTestSuitePState::VerifyRegisteredTestNames(
|
||||||
const char* file, int line, const char* registered_tests) {
|
const char* file, int line, const char* registered_tests) {
|
||||||
typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
|
typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
|
||||||
registered_ = true;
|
registered_ = true;
|
||||||
@ -89,7 +89,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
|||||||
tests.insert(name);
|
tests.insert(name);
|
||||||
} else {
|
} else {
|
||||||
errors << "No test named " << name
|
errors << "No test named " << name
|
||||||
<< " can be found in this test case.\n";
|
<< " can be found in this test suite.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -140,8 +140,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
def testCatchesCxxExceptionsInSetUpTestCase(self):
|
def testCatchesCxxExceptionsInSetUpTestCase(self):
|
||||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in SetUpTestCase()'
|
' thrown in SetUpTestSuite()' in EX_BINARY_OUTPUT)
|
||||||
in EX_BINARY_OUTPUT)
|
|
||||||
self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() '
|
self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() '
|
||||||
'called as expected.'
|
'called as expected.'
|
||||||
in EX_BINARY_OUTPUT)
|
in EX_BINARY_OUTPUT)
|
||||||
@ -163,8 +162,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
|
|||||||
|
|
||||||
def testCatchesCxxExceptionsInTearDownTestCase(self):
|
def testCatchesCxxExceptionsInTearDownTestCase(self):
|
||||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||||
' thrown in TearDownTestCase()'
|
' thrown in TearDownTestSuite()' in EX_BINARY_OUTPUT)
|
||||||
in EX_BINARY_OUTPUT)
|
|
||||||
|
|
||||||
def testCatchesCxxExceptionsInSetUp(self):
|
def testCatchesCxxExceptionsInSetUp(self):
|
||||||
self.assert_('C++ exception with description "Standard C++ exception"'
|
self.assert_('C++ exception with description "Standard C++ exception"'
|
||||||
|
@ -125,6 +125,78 @@ class EventRecordingListener : public TestEventListener {
|
|||||||
std::string name_;
|
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 {
|
class EnvironmentInvocationCatcher : public Environment {
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override { g_events->push_back("Environment::SetUp"); }
|
void SetUp() override { g_events->push_back("Environment::SetUp"); }
|
||||||
@ -165,6 +237,7 @@ TEST_F(ListenerTest, DoesBar) {
|
|||||||
|
|
||||||
using ::testing::internal::EnvironmentInvocationCatcher;
|
using ::testing::internal::EnvironmentInvocationCatcher;
|
||||||
using ::testing::internal::EventRecordingListener;
|
using ::testing::internal::EventRecordingListener;
|
||||||
|
using ::testing::internal::EventRecordingListener2;
|
||||||
|
|
||||||
void VerifyResults(const std::vector<std::string>& data,
|
void VerifyResults(const std::vector<std::string>& data,
|
||||||
const char* const* expected_data,
|
const char* const* expected_data,
|
||||||
@ -199,6 +272,8 @@ int main(int argc, char **argv) {
|
|||||||
new EventRecordingListener("1st"));
|
new EventRecordingListener("1st"));
|
||||||
UnitTest::GetInstance()->listeners().Append(
|
UnitTest::GetInstance()->listeners().Append(
|
||||||
new EventRecordingListener("2nd"));
|
new EventRecordingListener("2nd"));
|
||||||
|
UnitTest::GetInstance()->listeners().Append(
|
||||||
|
new EventRecordingListener2("3rd"));
|
||||||
|
|
||||||
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
|
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
|
||||||
|
|
||||||
@ -208,88 +283,117 @@ int main(int argc, char **argv) {
|
|||||||
::testing::GTEST_FLAG(repeat) = 2;
|
::testing::GTEST_FLAG(repeat) = 2;
|
||||||
int ret_val = RUN_ALL_TESTS();
|
int ret_val = RUN_ALL_TESTS();
|
||||||
|
|
||||||
const char* const expected_events[] = {
|
const char* const expected_events[] = {"1st.OnTestProgramStart",
|
||||||
"1st.OnTestProgramStart",
|
"2nd.OnTestProgramStart",
|
||||||
"2nd.OnTestProgramStart",
|
"3rd.OnTestProgramStart",
|
||||||
"1st.OnTestIterationStart(0)",
|
"1st.OnTestIterationStart(0)",
|
||||||
"2nd.OnTestIterationStart(0)",
|
"2nd.OnTestIterationStart(0)",
|
||||||
"1st.OnEnvironmentsSetUpStart",
|
"3rd.OnTestIterationStart(0)",
|
||||||
"2nd.OnEnvironmentsSetUpStart",
|
"1st.OnEnvironmentsSetUpStart",
|
||||||
"Environment::SetUp",
|
"2nd.OnEnvironmentsSetUpStart",
|
||||||
"2nd.OnEnvironmentsSetUpEnd",
|
"3rd.OnEnvironmentsSetUpStart",
|
||||||
"1st.OnEnvironmentsSetUpEnd",
|
"Environment::SetUp",
|
||||||
"1st.OnTestCaseStart",
|
"3rd.OnEnvironmentsSetUpEnd",
|
||||||
"2nd.OnTestCaseStart",
|
"2nd.OnEnvironmentsSetUpEnd",
|
||||||
"ListenerTest::SetUpTestCase",
|
"1st.OnEnvironmentsSetUpEnd",
|
||||||
"1st.OnTestStart",
|
"3rd.OnTestSuiteStart",
|
||||||
"2nd.OnTestStart",
|
"1st.OnTestCaseStart",
|
||||||
"ListenerTest::SetUp",
|
"2nd.OnTestCaseStart",
|
||||||
"ListenerTest::* Test Body",
|
"ListenerTest::SetUpTestCase",
|
||||||
"1st.OnTestPartResult",
|
"1st.OnTestStart",
|
||||||
"2nd.OnTestPartResult",
|
"2nd.OnTestStart",
|
||||||
"ListenerTest::TearDown",
|
"3rd.OnTestStart",
|
||||||
"2nd.OnTestEnd",
|
"ListenerTest::SetUp",
|
||||||
"1st.OnTestEnd",
|
"ListenerTest::* Test Body",
|
||||||
"1st.OnTestStart",
|
"1st.OnTestPartResult",
|
||||||
"2nd.OnTestStart",
|
"2nd.OnTestPartResult",
|
||||||
"ListenerTest::SetUp",
|
"3rd.OnTestPartResult",
|
||||||
"ListenerTest::* Test Body",
|
"ListenerTest::TearDown",
|
||||||
"1st.OnTestPartResult",
|
"3rd.OnTestEnd",
|
||||||
"2nd.OnTestPartResult",
|
"2nd.OnTestEnd",
|
||||||
"ListenerTest::TearDown",
|
"1st.OnTestEnd",
|
||||||
"2nd.OnTestEnd",
|
"1st.OnTestStart",
|
||||||
"1st.OnTestEnd",
|
"2nd.OnTestStart",
|
||||||
"ListenerTest::TearDownTestCase",
|
"3rd.OnTestStart",
|
||||||
"2nd.OnTestCaseEnd",
|
"ListenerTest::SetUp",
|
||||||
"1st.OnTestCaseEnd",
|
"ListenerTest::* Test Body",
|
||||||
"1st.OnEnvironmentsTearDownStart",
|
"1st.OnTestPartResult",
|
||||||
"2nd.OnEnvironmentsTearDownStart",
|
"2nd.OnTestPartResult",
|
||||||
"Environment::TearDown",
|
"3rd.OnTestPartResult",
|
||||||
"2nd.OnEnvironmentsTearDownEnd",
|
"ListenerTest::TearDown",
|
||||||
"1st.OnEnvironmentsTearDownEnd",
|
"3rd.OnTestEnd",
|
||||||
"2nd.OnTestIterationEnd(0)",
|
"2nd.OnTestEnd",
|
||||||
"1st.OnTestIterationEnd(0)",
|
"1st.OnTestEnd",
|
||||||
"1st.OnTestIterationStart(1)",
|
"ListenerTest::TearDownTestCase",
|
||||||
"2nd.OnTestIterationStart(1)",
|
"3rd.OnTestSuiteEnd",
|
||||||
"1st.OnEnvironmentsSetUpStart",
|
"2nd.OnTestCaseEnd",
|
||||||
"2nd.OnEnvironmentsSetUpStart",
|
"1st.OnTestCaseEnd",
|
||||||
"Environment::SetUp",
|
"1st.OnEnvironmentsTearDownStart",
|
||||||
"2nd.OnEnvironmentsSetUpEnd",
|
"2nd.OnEnvironmentsTearDownStart",
|
||||||
"1st.OnEnvironmentsSetUpEnd",
|
"3rd.OnEnvironmentsTearDownStart",
|
||||||
"1st.OnTestCaseStart",
|
"Environment::TearDown",
|
||||||
"2nd.OnTestCaseStart",
|
"3rd.OnEnvironmentsTearDownEnd",
|
||||||
"ListenerTest::SetUpTestCase",
|
"2nd.OnEnvironmentsTearDownEnd",
|
||||||
"1st.OnTestStart",
|
"1st.OnEnvironmentsTearDownEnd",
|
||||||
"2nd.OnTestStart",
|
"3rd.OnTestIterationEnd(0)",
|
||||||
"ListenerTest::SetUp",
|
"2nd.OnTestIterationEnd(0)",
|
||||||
"ListenerTest::* Test Body",
|
"1st.OnTestIterationEnd(0)",
|
||||||
"1st.OnTestPartResult",
|
"1st.OnTestIterationStart(1)",
|
||||||
"2nd.OnTestPartResult",
|
"2nd.OnTestIterationStart(1)",
|
||||||
"ListenerTest::TearDown",
|
"3rd.OnTestIterationStart(1)",
|
||||||
"2nd.OnTestEnd",
|
"1st.OnEnvironmentsSetUpStart",
|
||||||
"1st.OnTestEnd",
|
"2nd.OnEnvironmentsSetUpStart",
|
||||||
"1st.OnTestStart",
|
"3rd.OnEnvironmentsSetUpStart",
|
||||||
"2nd.OnTestStart",
|
"Environment::SetUp",
|
||||||
"ListenerTest::SetUp",
|
"3rd.OnEnvironmentsSetUpEnd",
|
||||||
"ListenerTest::* Test Body",
|
"2nd.OnEnvironmentsSetUpEnd",
|
||||||
"1st.OnTestPartResult",
|
"1st.OnEnvironmentsSetUpEnd",
|
||||||
"2nd.OnTestPartResult",
|
"3rd.OnTestSuiteStart",
|
||||||
"ListenerTest::TearDown",
|
"1st.OnTestCaseStart",
|
||||||
"2nd.OnTestEnd",
|
"2nd.OnTestCaseStart",
|
||||||
"1st.OnTestEnd",
|
"ListenerTest::SetUpTestCase",
|
||||||
"ListenerTest::TearDownTestCase",
|
"1st.OnTestStart",
|
||||||
"2nd.OnTestCaseEnd",
|
"2nd.OnTestStart",
|
||||||
"1st.OnTestCaseEnd",
|
"3rd.OnTestStart",
|
||||||
"1st.OnEnvironmentsTearDownStart",
|
"ListenerTest::SetUp",
|
||||||
"2nd.OnEnvironmentsTearDownStart",
|
"ListenerTest::* Test Body",
|
||||||
"Environment::TearDown",
|
"1st.OnTestPartResult",
|
||||||
"2nd.OnEnvironmentsTearDownEnd",
|
"2nd.OnTestPartResult",
|
||||||
"1st.OnEnvironmentsTearDownEnd",
|
"3rd.OnTestPartResult",
|
||||||
"2nd.OnTestIterationEnd(1)",
|
"ListenerTest::TearDown",
|
||||||
"1st.OnTestIterationEnd(1)",
|
"3rd.OnTestEnd",
|
||||||
"2nd.OnTestProgramEnd",
|
"2nd.OnTestEnd",
|
||||||
"1st.OnTestProgramEnd"
|
"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"};
|
||||||
|
|
||||||
VerifyResults(events,
|
VerifyResults(events,
|
||||||
expected_events,
|
expected_events,
|
||||||
sizeof(expected_events)/sizeof(expected_events[0]));
|
sizeof(expected_events)/sizeof(expected_events[0]));
|
||||||
|
@ -12,7 +12,7 @@ Expected equality of these values:
|
|||||||
3
|
3
|
||||||
Stack trace: (omitted)
|
Stack trace: (omitted)
|
||||||
|
|
||||||
[0;32m[==========] [mRunning 83 tests from 38 test cases.
|
[0;32m[==========] [mRunning 83 tests from 38 test suites.
|
||||||
[0;32m[----------] [mGlobal test environment set-up.
|
[0;32m[----------] [mGlobal test environment set-up.
|
||||||
FooEnvironment::SetUp() called.
|
FooEnvironment::SetUp() called.
|
||||||
BarEnvironment::SetUp() called.
|
BarEnvironment::SetUp() called.
|
||||||
@ -392,26 +392,26 @@ Stack trace: (omitted)
|
|||||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFail
|
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class. However, in test case MixedUpTestCaseTest,
|
class. However, in test suite MixedUpTestCaseTest,
|
||||||
you defined test FirstTestFromNamespaceFoo and test ThisShouldFail
|
you defined test FirstTestFromNamespaceFoo and test ThisShouldFail
|
||||||
using two different test fixture classes. This can happen if
|
using two different test fixture classes. This can happen if
|
||||||
the two classes are from different namespaces or translation
|
the two classes are from different namespaces or translation
|
||||||
units and have the same name. You should probably rename one
|
units and have the same name. You should probably rename one
|
||||||
of the classes to put the tests into different test cases.
|
of the classes to put the tests into different test suites.
|
||||||
Stack trace: (omitted)
|
Stack trace: (omitted)
|
||||||
|
|
||||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
|
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFail
|
||||||
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
[0;32m[ RUN ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class. However, in test case MixedUpTestCaseTest,
|
class. However, in test suite MixedUpTestCaseTest,
|
||||||
you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo
|
you defined test FirstTestFromNamespaceFoo and test ThisShouldFailToo
|
||||||
using two different test fixture classes. This can happen if
|
using two different test fixture classes. This can happen if
|
||||||
the two classes are from different namespaces or translation
|
the two classes are from different namespaces or translation
|
||||||
units and have the same name. You should probably rename one
|
units and have the same name. You should probably rename one
|
||||||
of the classes to put the tests into different test cases.
|
of the classes to put the tests into different test suites.
|
||||||
Stack trace: (omitted)
|
Stack trace: (omitted)
|
||||||
|
|
||||||
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
[0;31m[ FAILED ] [mMixedUpTestCaseTest.ThisShouldFailToo
|
||||||
@ -421,13 +421,13 @@ Stack trace: (omitted)
|
|||||||
[0;32m[ RUN ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
[0;32m[ RUN ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class. However, in test case MixedUpTestCaseWithSameTestNameTest,
|
class. However, in test suite MixedUpTestCaseWithSameTestNameTest,
|
||||||
you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail
|
you defined test TheSecondTestWithThisNameShouldFail and test TheSecondTestWithThisNameShouldFail
|
||||||
using two different test fixture classes. This can happen if
|
using two different test fixture classes. This can happen if
|
||||||
the two classes are from different namespaces or translation
|
the two classes are from different namespaces or translation
|
||||||
units and have the same name. You should probably rename one
|
units and have the same name. You should probably rename one
|
||||||
of the classes to put the tests into different test cases.
|
of the classes to put the tests into different test suites.
|
||||||
Stack trace: (omitted)
|
Stack trace: (omitted)
|
||||||
|
|
||||||
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
[0;31m[ FAILED ] [mMixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
|
||||||
@ -437,9 +437,9 @@ Stack trace: (omitted)
|
|||||||
[0;32m[ RUN ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
|
[0;32m[ RUN ] [mTEST_F_before_TEST_in_same_test_case.DefinedUsingTESTAndShouldFail
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class, so mixing TEST_F and TEST in the same test case is
|
class, so mixing TEST_F and TEST in the same test suite is
|
||||||
illegal. In test case TEST_F_before_TEST_in_same_test_case,
|
illegal. In test suite TEST_F_before_TEST_in_same_test_case,
|
||||||
test DefinedUsingTEST_F is defined using TEST_F but
|
test DefinedUsingTEST_F is defined using TEST_F but
|
||||||
test DefinedUsingTESTAndShouldFail is defined using TEST. You probably
|
test DefinedUsingTESTAndShouldFail is defined using TEST. You probably
|
||||||
want to change the TEST to TEST_F or move it to another test
|
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
|
[0;32m[ RUN ] [mTEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class, so mixing TEST_F and TEST in the same test case is
|
class, so mixing TEST_F and TEST in the same test suite is
|
||||||
illegal. In test case TEST_before_TEST_F_in_same_test_case,
|
illegal. In test suite TEST_before_TEST_F_in_same_test_case,
|
||||||
test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but
|
test DefinedUsingTEST_FAndShouldFail is defined using TEST_F but
|
||||||
test DefinedUsingTEST is defined using TEST. You probably
|
test DefinedUsingTEST is defined using TEST. You probably
|
||||||
want to change the TEST to TEST_F or move it to another test
|
want to change the TEST to TEST_F or move it to another test
|
||||||
@ -912,9 +912,9 @@ DynamicFixture::TearDown
|
|||||||
DynamicFixture()
|
DynamicFixture()
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class, so mixing TEST_F and TEST in the same test case is
|
class, so mixing TEST_F and TEST in the same test suite is
|
||||||
illegal. In test case BadDynamicFixture1,
|
illegal. In test suite BadDynamicFixture1,
|
||||||
test FixtureBase is defined using TEST_F but
|
test FixtureBase is defined using TEST_F but
|
||||||
test TestBase is defined using TEST. You probably
|
test TestBase is defined using TEST. You probably
|
||||||
want to change the TEST to TEST_F or move it to another test
|
want to change the TEST to TEST_F or move it to another test
|
||||||
@ -936,13 +936,13 @@ DynamicFixture::TearDown
|
|||||||
DynamicFixture()
|
DynamicFixture()
|
||||||
gtest.cc:#: Failure
|
gtest.cc:#: Failure
|
||||||
Failed
|
Failed
|
||||||
All tests in the same test case must use the same test fixture
|
All tests in the same test suite must use the same test fixture
|
||||||
class. However, in test case BadDynamicFixture2,
|
class. However, in test suite BadDynamicFixture2,
|
||||||
you defined test FixtureBase and test Derived
|
you defined test FixtureBase and test Derived
|
||||||
using two different test fixture classes. This can happen if
|
using two different test fixture classes. This can happen if
|
||||||
the two classes are from different namespaces or translation
|
the two classes are from different namespaces or translation
|
||||||
units and have the same name. You should probably rename one
|
units and have the same name. You should probably rename one
|
||||||
of the classes to put the tests into different test cases.
|
of the classes to put the tests into different test suites.
|
||||||
Stack trace: (omitted)
|
Stack trace: (omitted)
|
||||||
|
|
||||||
~DynamicFixture()
|
~DynamicFixture()
|
||||||
@ -984,7 +984,7 @@ Failed
|
|||||||
Expected fatal failure.
|
Expected fatal failure.
|
||||||
Stack trace: (omitted)
|
Stack trace: (omitted)
|
||||||
|
|
||||||
[0;32m[==========] [m83 tests from 38 test cases ran.
|
[0;32m[==========] [m83 tests from 38 test suites ran.
|
||||||
[0;32m[ PASSED ] [m30 tests.
|
[0;32m[ PASSED ] [m30 tests.
|
||||||
[0;31m[ FAILED ] [m53 tests, listed below:
|
[0;31m[ FAILED ] [m53 tests, listed below:
|
||||||
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
||||||
@ -1045,7 +1045,7 @@ Stack trace: (omitted)
|
|||||||
[0;33m YOU HAVE 1 DISABLED TEST
|
[0;33m YOU HAVE 1 DISABLED TEST
|
||||||
|
|
||||||
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||||
[==========] Running 4 tests from 2 test cases.
|
[==========] Running 4 tests from 2 test suites.
|
||||||
[----------] Global test environment set-up.
|
[----------] Global test environment set-up.
|
||||||
[----------] 3 tests from FatalFailureTest
|
[----------] 3 tests from FatalFailureTest
|
||||||
[ RUN ] FatalFailureTest.FatalFailureInSubroutine
|
[ RUN ] FatalFailureTest.FatalFailureInSubroutine
|
||||||
@ -1098,7 +1098,7 @@ Stack trace: (omitted)
|
|||||||
[----------] 1 test from LoggingTest (? ms total)
|
[----------] 1 test from LoggingTest (? ms total)
|
||||||
|
|
||||||
[----------] Global test environment tear-down
|
[----------] Global test environment tear-down
|
||||||
[==========] 4 tests from 2 test cases ran. (? ms total)
|
[==========] 4 tests from 2 test suites ran. (? ms total)
|
||||||
[ PASSED ] 0 tests.
|
[ PASSED ] 0 tests.
|
||||||
[ FAILED ] 4 tests, listed below:
|
[ FAILED ] 4 tests, listed below:
|
||||||
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
|
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
|
||||||
@ -1108,21 +1108,21 @@ Stack trace: (omitted)
|
|||||||
|
|
||||||
4 FAILED TESTS
|
4 FAILED TESTS
|
||||||
Note: Google Test filter = *DISABLED_*
|
Note: Google Test filter = *DISABLED_*
|
||||||
[==========] Running 1 test from 1 test case.
|
[==========] Running 1 test from 1 test suite.
|
||||||
[----------] Global test environment set-up.
|
[----------] Global test environment set-up.
|
||||||
[----------] 1 test from DisabledTestsWarningTest
|
[----------] 1 test from DisabledTestsWarningTest
|
||||||
[ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
[ RUN ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
||||||
[ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
[ OK ] DisabledTestsWarningTest.DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
|
||||||
[----------] Global test environment tear-down
|
[----------] Global test environment tear-down
|
||||||
[==========] 1 test from 1 test case ran.
|
[==========] 1 test from 1 test suite ran.
|
||||||
[ PASSED ] 1 test.
|
[ PASSED ] 1 test.
|
||||||
Note: Google Test filter = PassingTest.*
|
Note: Google Test filter = PassingTest.*
|
||||||
Note: This is test shard 2 of 2.
|
Note: This is test shard 2 of 2.
|
||||||
[==========] Running 1 test from 1 test case.
|
[==========] Running 1 test from 1 test suite.
|
||||||
[----------] Global test environment set-up.
|
[----------] Global test environment set-up.
|
||||||
[----------] 1 test from PassingTest
|
[----------] 1 test from PassingTest
|
||||||
[ RUN ] PassingTest.PassingTest2
|
[ RUN ] PassingTest.PassingTest2
|
||||||
[ OK ] PassingTest.PassingTest2
|
[ OK ] PassingTest.PassingTest2
|
||||||
[----------] Global test environment tear-down
|
[----------] Global test environment tear-down
|
||||||
[==========] 1 test from 1 test case ran.
|
[==========] 1 test from 1 test suite ran.
|
||||||
[ PASSED ] 1 test.
|
[ PASSED ] 1 test.
|
||||||
|
@ -249,7 +249,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsDuplicates) {
|
|||||||
TEST_F(TypedTestCasePStateDeathTest, DetectsExtraTest) {
|
TEST_F(TypedTestCasePStateDeathTest, DetectsExtraTest) {
|
||||||
EXPECT_DEATH_IF_SUPPORTED(
|
EXPECT_DEATH_IF_SUPPORTED(
|
||||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"),
|
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"),
|
||||||
"foo\\.cc.1.?: No test named D can be found in this test case\\.");
|
"foo\\.cc.1.?: No test named D can be found in this test suite\\.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) {
|
TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) {
|
||||||
@ -264,7 +264,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsTestAfterRegistration) {
|
|||||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C");
|
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C");
|
||||||
EXPECT_DEATH_IF_SUPPORTED(
|
EXPECT_DEATH_IF_SUPPORTED(
|
||||||
state_.AddTestName("foo.cc", 2, "FooTest", "D"),
|
state_.AddTestName("foo.cc", 2, "FooTest", "D"),
|
||||||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_CASE_P"
|
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P"
|
||||||
"\\(FooTest, \\.\\.\\.\\)\\.");
|
"\\(FooTest, \\.\\.\\.\\)\\.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
// This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
|
// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
|
||||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||||
|
|
||||||
// Regression test for gtest_pred_impl.h
|
// Regression test for gtest_pred_impl.h
|
||||||
|
@ -2357,6 +2357,16 @@ TEST(PredTest, SingleEvaluationOnFailure) {
|
|||||||
EXPECT_EQ(1, n4) << "Argument 4 is not evaluated exactly once.";
|
EXPECT_EQ(1, n4) << "Argument 4 is not evaluated exactly once.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test predicate assertions for sets
|
||||||
|
TEST(PredTest, ExpectPredEvalFailure) {
|
||||||
|
std::set<int> set_a = {2, 1, 3, 4, 5};
|
||||||
|
std::set<int> set_b = {0, 4, 8};
|
||||||
|
const auto compare_sets = [] (std::set<int>, std::set<int>) { return false; };
|
||||||
|
EXPECT_NONFATAL_FAILURE(
|
||||||
|
EXPECT_PRED2(compare_sets, set_a, set_b),
|
||||||
|
"compare_sets(set_a, set_b) evaluates to false, where\nset_a evaluates "
|
||||||
|
"to { 1, 2, 3, 4, 5 }\nset_b evaluates to { 0, 4, 8 }");
|
||||||
|
}
|
||||||
|
|
||||||
// Some helper functions for testing using overloaded/template
|
// Some helper functions for testing using overloaded/template
|
||||||
// functions with ASSERT_PREDn and EXPECT_PREDn.
|
// functions with ASSERT_PREDn and EXPECT_PREDn.
|
||||||
@ -5431,6 +5441,67 @@ TEST_F(SetUpTestCaseTest, Test2) {
|
|||||||
EXPECT_STREQ("123", shared_resource_);
|
EXPECT_STREQ("123", shared_resource_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests SetupTestSuite/TearDown TestSuite API
|
||||||
|
class SetUpTestSuiteTest : public Test {
|
||||||
|
protected:
|
||||||
|
// This will be called once before the first test in this test case
|
||||||
|
// is run.
|
||||||
|
static void SetUpTestSuite() {
|
||||||
|
printf("Setting up the test suite . . .\n");
|
||||||
|
|
||||||
|
// Initializes some shared resource. In this simple example, we
|
||||||
|
// just create a C string. More complex stuff can be done if
|
||||||
|
// desired.
|
||||||
|
shared_resource_ = "123";
|
||||||
|
|
||||||
|
// Increments the number of test cases that have been set up.
|
||||||
|
counter_++;
|
||||||
|
|
||||||
|
// SetUpTestSuite() should be called only once.
|
||||||
|
EXPECT_EQ(1, counter_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will be called once after the last test in this test case is
|
||||||
|
// run.
|
||||||
|
static void TearDownTestSuite() {
|
||||||
|
printf("Tearing down the test suite . . .\n");
|
||||||
|
|
||||||
|
// Decrements the number of test suites that have been set up.
|
||||||
|
counter_--;
|
||||||
|
|
||||||
|
// TearDownTestSuite() should be called only once.
|
||||||
|
EXPECT_EQ(0, counter_);
|
||||||
|
|
||||||
|
// Cleans up the shared resource.
|
||||||
|
shared_resource_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This will be called before each test in this test case.
|
||||||
|
void SetUp() override {
|
||||||
|
// SetUpTestSuite() should be called only once, so counter_ should
|
||||||
|
// always be 1.
|
||||||
|
EXPECT_EQ(1, counter_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Number of test suites that have been set up.
|
||||||
|
static int counter_;
|
||||||
|
|
||||||
|
// Some resource to be shared by all tests in this test case.
|
||||||
|
static const char* shared_resource_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int SetUpTestSuiteTest::counter_ = 0;
|
||||||
|
const char* SetUpTestSuiteTest::shared_resource_ = nullptr;
|
||||||
|
|
||||||
|
// A test that uses the shared resource.
|
||||||
|
TEST_F(SetUpTestSuiteTest, TestSetupTestSuite1) {
|
||||||
|
EXPECT_STRNE(nullptr, shared_resource_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another test that uses the shared resource.
|
||||||
|
TEST_F(SetUpTestSuiteTest, TestSetupTestSuite2) {
|
||||||
|
EXPECT_STREQ("123", shared_resource_);
|
||||||
|
}
|
||||||
|
|
||||||
// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly.
|
// The ParseFlagsTest test case tests ParseGoogleTestFlagsOnly.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user