Commit fd1c7976 authored by Chris's avatar Chris
Browse files

Merge branch 'chore/fix_library_json' of https://github.com/ciband/googletest...

Merge branch 'chore/fix_library_json' of https://github.com/ciband/googletest into chore/fix_library_json
parents 23533009 0ffa5f97
...@@ -75,11 +75,11 @@ namespace internal { ...@@ -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) { ...@@ -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 { ...@@ -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 ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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_suite_base_name;
const std::string test_case_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 { ...@@ -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
......
...@@ -41,8 +41,6 @@ ...@@ -41,8 +41,6 @@
# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) # elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__)
# define GTEST_OS_WINDOWS_MINGW 1 # define GTEST_OS_WINDOWS_MINGW 1
# define GTEST_OS_WINDOWS 1 # define GTEST_OS_WINDOWS 1
#elif defined __SYMBIAN32__
# define GTEST_OS_SYMBIAN 1
#elif defined _WIN32 #elif defined _WIN32
# define GTEST_OS_WINDOWS 1 # define GTEST_OS_WINDOWS 1
# ifdef _WIN32_WCE # ifdef _WIN32_WCE
......
...@@ -92,8 +92,6 @@ ...@@ -92,8 +92,6 @@
// - Define it to 1/0 to indicate whether the // - Define it to 1/0 to indicate whether the
// platform supports I/O stream redirection using // platform supports I/O stream redirection using
// dup() and dup2(). // dup() and dup2().
// GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test
// is building in C++11/C++98 mode.
// GTEST_LINKED_AS_SHARED_LIBRARY // GTEST_LINKED_AS_SHARED_LIBRARY
// - Define to 1 when compiling tests that use // - Define to 1 when compiling tests that use
// Google Test as a shared library (known as // Google Test as a shared library (known as
...@@ -132,7 +130,6 @@ ...@@ -132,7 +130,6 @@
// GTEST_OS_OS2 - OS/2 // GTEST_OS_OS2 - OS/2
// GTEST_OS_QNX - QNX // GTEST_OS_QNX - QNX
// GTEST_OS_SOLARIS - Sun Solaris // GTEST_OS_SOLARIS - Sun Solaris
// GTEST_OS_SYMBIAN - Symbian
// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) // GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop // GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
// GTEST_OS_WINDOWS_MINGW - MinGW // GTEST_OS_WINDOWS_MINGW - MinGW
...@@ -177,7 +174,6 @@ ...@@ -177,7 +174,6 @@
// define themselves. // define themselves.
// GTEST_USES_SIMPLE_RE - our own simple regex is used; // GTEST_USES_SIMPLE_RE - our own simple regex is used;
// the above RE\b(s) are mutually exclusive. // the above RE\b(s) are mutually exclusive.
// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
// Misc public macros // Misc public macros
// ------------------ // ------------------
...@@ -208,7 +204,6 @@ ...@@ -208,7 +204,6 @@
// - synchronization primitives. // - synchronization primitives.
// //
// Template meta programming: // Template meta programming:
// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
// IteratorTraits - partial implementation of std::iterator_traits, which // IteratorTraits - partial implementation of std::iterator_traits, which
// is not available in libCstd when compiled with Sun C++. // is not available in libCstd when compiled with Sun C++.
// //
...@@ -255,6 +250,7 @@ ...@@ -255,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>
...@@ -332,44 +328,6 @@ ...@@ -332,44 +328,6 @@
GTEST_DISABLE_MSC_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
#endif #endif
#define GTEST_LANG_CXX11 1
// Distinct from C++11 language support, some environments don't provide
// proper C++11 library support. Notably, it's possible to build in
// C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++
// with no C++11 support.
//
// libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__
// 20110325, but maintenance releases in the 4.4 and 4.5 series followed
// this date, so check for those versions by their date stamps.
// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning
#if GTEST_LANG_CXX11 && \
(!defined(__GLIBCXX__) || ( \
__GLIBCXX__ >= 20110325ul && /* GCC >= 4.6.0 */ \
/* Blacklist of patch releases of older branches: */ \
__GLIBCXX__ != 20110416ul && /* GCC 4.4.6 */ \
__GLIBCXX__ != 20120313ul && /* GCC 4.4.7 */ \
__GLIBCXX__ != 20110428ul && /* GCC 4.5.3 */ \
__GLIBCXX__ != 20120702ul)) /* GCC 4.5.4 */
# define GTEST_STDLIB_CXX11 1
#endif
// Only use C++11 library features if the library provides them.
#if GTEST_STDLIB_CXX11
# define GTEST_HAS_STD_BEGIN_AND_END_ 1
# define GTEST_HAS_STD_FORWARD_LIST_ 1
# if !defined(_MSC_VER) || (_MSC_FULL_VER >= 190023824)
// works only with VS2015U2 and better
# define GTEST_HAS_STD_FUNCTION_ 1
# endif
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
# define GTEST_HAS_STD_MOVE_ 1
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
# define GTEST_HAS_STD_SHARED_PTR_ 1
# define GTEST_HAS_UNORDERED_MAP_ 1
# define GTEST_HAS_UNORDERED_SET_ 1
#endif
// Brings in definitions for functions used in the testing::internal::posix // Brings in definitions for functions used in the testing::internal::posix
// namespace (read, write, close, chdir, isatty, stat). We do not currently // namespace (read, write, close, chdir, isatty, stat). We do not currently
// use them on Windows Mobile. // use them on Windows Mobile.
...@@ -500,9 +458,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -500,9 +458,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_STD_WSTRING #ifndef GTEST_HAS_STD_WSTRING
// The user didn't tell us whether ::std::wstring is available, so we need // The user didn't tell us whether ::std::wstring is available, so we need
// to figure it out. // to figure it out.
// FIXME: uses autoconf to detect whether ::std::wstring
// is available.
// Cygwin 1.7 and below doesn't support ::std::wstring. // Cygwin 1.7 and below doesn't support ::std::wstring.
// Solaris' libc++ doesn't support it either. Android has // Solaris' libc++ doesn't support it either. Android has
// no support for it at least as recent as Froyo (2.2). // no support for it at least as recent as Froyo (2.2).
...@@ -532,7 +487,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -532,7 +487,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# endif # endif
// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled. // Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302) # elif defined(__GNUC__)
# ifdef __GXX_RTTI # ifdef __GXX_RTTI
// When building against STLport with the Android NDK and with // When building against STLport with the Android NDK and with
...@@ -635,12 +590,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -635,12 +590,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_STREAM_REDIRECTION #ifndef GTEST_HAS_STREAM_REDIRECTION
// By default, we assume that stream redirection is supported on all // By default, we assume that stream redirection is supported on all
// platforms except known mobile ones. // platforms except known mobile ones.
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \ # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
# define GTEST_HAS_STREAM_REDIRECTION 0 # define GTEST_HAS_STREAM_REDIRECTION 0
# else # else
# define GTEST_HAS_STREAM_REDIRECTION 1 # define GTEST_HAS_STREAM_REDIRECTION 1
# endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN # endif // !GTEST_OS_WINDOWS_MOBILE
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Determines whether to support death tests. // Determines whether to support death tests.
...@@ -666,8 +620,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -666,8 +620,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Determines whether the system compiler uses UTF-16 for encoding wide strings. // Determines whether the system compiler uses UTF-16 for encoding wide strings.
#define GTEST_WIDE_STRING_USES_UTF16_ \ #define GTEST_WIDE_STRING_USES_UTF16_ \
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || \ (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2)
GTEST_OS_AIX || GTEST_OS_OS2)
// Determines whether test results can be streamed to a socket. // Determines whether test results can be streamed to a socket.
#if GTEST_OS_LINUX #if GTEST_OS_LINUX
...@@ -712,12 +665,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -712,12 +665,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
# define GTEST_ATTRIBUTE_UNUSED_ # define GTEST_ATTRIBUTE_UNUSED_
#endif #endif
#if GTEST_LANG_CXX11
# define GTEST_CXX11_EQUALS_DELETE_ = delete
#else // GTEST_LANG_CXX11
# define GTEST_CXX11_EQUALS_DELETE_
#endif // GTEST_LANG_CXX11
// Use this annotation before a function that takes a printf format string. // Use this annotation before a function that takes a printf format string.
#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) #if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC)
# if defined(__MINGW_PRINTF_FORMAT) # if defined(__MINGW_PRINTF_FORMAT)
...@@ -739,12 +686,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -739,12 +686,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// A macro to disallow operator= // A macro to disallow operator=
// This should be used in the private: declarations for a class. // This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_ASSIGN_(type) \ #define GTEST_DISALLOW_ASSIGN_(type) \
void operator=(type const &) GTEST_CXX11_EQUALS_DELETE_ void operator=(type const &) = delete
// A macro to disallow copy constructor and operator= // A macro to disallow copy constructor and operator=
// This should be used in the private: declarations for a class. // This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \
type(type const &) GTEST_CXX11_EQUALS_DELETE_; \ type(type const &) = delete; \
GTEST_DISALLOW_ASSIGN_(type) GTEST_DISALLOW_ASSIGN_(type)
// Tell the compiler to warn about unused return values for functions declared // Tell the compiler to warn about unused return values for functions declared
...@@ -752,11 +699,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -752,11 +699,11 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// following the argument list: // following the argument list:
// //
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC) #if defined(__GNUC__) && !defined(COMPILER_ICC)
# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
#else #else
# define GTEST_MUST_USE_RESULT_ # define GTEST_MUST_USE_RESULT_
#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC #endif // __GNUC__ && !COMPILER_ICC
// MS C++ compiler emits warning when a conditional expression is compile time // MS C++ compiler emits warning when a conditional expression is compile time
// constant. In some contexts this warning is false positive and needs to be // constant. In some contexts this warning is false positive and needs to be
...@@ -893,75 +840,16 @@ namespace internal { ...@@ -893,75 +840,16 @@ namespace internal {
// Secret object, which is what we want. // Secret object, which is what we want.
class Secret; class Secret;
// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time // The GTEST_COMPILE_ASSERT_ is a legacy macro used to verify that a compile
// expression is true. For example, you could use it to verify the // time expression is true (in new code, use static_assert instead). For
// size of a static array: // example, you could use it to verify the size of a static array:
// //
// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES, // GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES,
// names_incorrect_size); // names_incorrect_size);
// //
// or to make sure a struct is smaller than a certain size: // The second argument to the macro must be a valid C++ identifier. If the
// // expression is false, compiler will issue an error containing this identifier.
// GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large); #define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
//
// The second argument to the macro is the name of the variable. If
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
#if GTEST_LANG_CXX11
# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
#else // !GTEST_LANG_CXX11
template <bool>
struct CompileAssert {
};
# define GTEST_COMPILE_ASSERT_(expr, msg) \
typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
#endif // !GTEST_LANG_CXX11
// Implementation details of GTEST_COMPILE_ASSERT_:
//
// (In C++11, we simply use static_assert instead of the following)
//
// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
// elements (and thus is invalid) when the expression is false.
//
// - The simpler definition
//
// #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
//
// does not work, as gcc supports variable-length arrays whose sizes
// are determined at run-time (this is gcc's extension and not part
// of the C++ standard). As a result, gcc fails to reject the
// following code with the simple definition:
//
// int foo;
// GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
// // not a compile-time constant.
//
// - By using the type CompileAssert<(bool(expr))>, we ensures that
// expr is a compile-time constant. (Template arguments must be
// determined at compile-time.)
//
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// CompileAssert<bool(expr)>
//
// instead, these compilers will refuse to compile
//
// GTEST_COMPILE_ASSERT_(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
//
// ((expr) ? 1 : -1).
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h. // StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
// //
...@@ -1036,9 +924,6 @@ class GTEST_API_ RE { ...@@ -1036,9 +924,6 @@ class GTEST_API_ RE {
// the entire str. // the entire str.
// PartialMatch(str, re) returns true iff regular expression re // PartialMatch(str, re) returns true iff regular expression re
// matches a substring of str (including str itself). // matches a substring of str (including str itself).
//
// FIXME: make FullMatch() and PartialMatch() work
// when str contains NUL characters.
static bool FullMatch(const ::std::string& str, const RE& re) { static bool FullMatch(const ::std::string& str, const RE& re) {
return FullMatch(str.c_str(), re); return FullMatch(str.c_str(), re);
} }
...@@ -1062,10 +947,6 @@ class GTEST_API_ RE { ...@@ -1062,10 +947,6 @@ class GTEST_API_ RE {
private: private:
void Init(const char* regex); void Init(const char* regex);
// We use a const char* instead of an std::string, as Google Test used to be
// used where std::string is not available. FIXME: change to
// std::string.
const char* pattern_; const char* pattern_;
bool is_valid_; bool is_valid_;
...@@ -2065,29 +1946,6 @@ class GTEST_API_ ThreadLocal { ...@@ -2065,29 +1946,6 @@ class GTEST_API_ ThreadLocal {
// we cannot detect it. // we cannot detect it.
GTEST_API_ size_t GetThreadCount(); GTEST_API_ size_t GetThreadCount();
// Passing non-POD classes through ellipsis (...) crashes the ARM
// compiler and generates a warning in Sun Studio before 12u4. The Nokia Symbian
// and the IBM XL C/C++ compiler try to instantiate a copy constructor
// for objects passed through ellipsis (...), failing for uncopyable
// objects. We define this to ensure that only POD is passed through
// ellipsis on these systems.
#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || \
(defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5130)
// We lose support for NULL detection where the compiler doesn't like
// passing non-POD classes through ellipsis (...).
# define GTEST_ELLIPSIS_NEEDS_POD_ 1
#else
# define GTEST_CAN_COMPARE_NULL 1
#endif
// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
// const T& and const T* in a function template. These compilers
// _can_ decide between class template specializations for T and T*,
// so a tr1::type_traits-like is_pointer works.
#if defined(__SYMBIAN32__) || defined(__IBMCPP__)
# define GTEST_NEEDS_IS_POINTER_ 1
#endif
template <bool bool_value> template <bool bool_value>
struct bool_constant { struct bool_constant {
typedef bool_constant<bool_value> type; typedef bool_constant<bool_value> type;
...@@ -2104,13 +1962,6 @@ struct is_same : public false_type {}; ...@@ -2104,13 +1962,6 @@ struct is_same : public false_type {};
template <typename T> template <typename T>
struct is_same<T, T> : public true_type {}; struct is_same<T, T> : public true_type {};
template <typename T>
struct is_pointer : public false_type {};
template <typename T>
struct is_pointer<T*> : public true_type {};
template <typename Iterator> template <typename Iterator>
struct IteratorTraits { struct IteratorTraits {
typedef typename Iterator::value_type value_type; typedef typename Iterator::value_type value_type;
...@@ -2433,9 +2284,6 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. ...@@ -2433,9 +2284,6 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
// Parses 'str' for a 32-bit signed integer. If successful, writes the result // Parses 'str' for a 32-bit signed integer. If successful, writes the result
// to *value and returns true; otherwise leaves *value unchanged and returns // to *value and returns true; otherwise leaves *value unchanged and returns
// false. // false.
// FIXME: Find a better way to refactor flag and environment parsing
// out of both gtest-port.cc and gtest.cc to avoid exporting this utility
// function.
bool ParseInt32(const Message& src_text, const char* str, Int32* value); bool ParseInt32(const Message& src_text, const char* str, Int32* value);
// Parses a bool/Int32/string from the environment variable // Parses a bool/Int32/string from the environment variable
......
...@@ -31,12 +31,11 @@ ...@@ -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, ...@@ -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. ...@@ -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]]> { ...@@ -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 {
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
# Remember to tweak this if you move this file. # Remember to tweak this if you move this file.
GTEST_DIR = .. GTEST_DIR = ..
# Points to the location of the Google Test libraries
GTEST_LIB_DIR = .
# Where to find user code. # Where to find user code.
USER_DIR = ../samples USER_DIR = ../samples
...@@ -27,6 +30,9 @@ CPPFLAGS += -isystem $(GTEST_DIR)/include ...@@ -27,6 +30,9 @@ CPPFLAGS += -isystem $(GTEST_DIR)/include
# Flags passed to the C++ compiler. # Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11 CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11
# Google Test libraries
GTEST_LIBS = libgtest.a libgtest_main.a
# All tests produced by this Makefile. Remember to add new tests you # All tests produced by this Makefile. Remember to add new tests you
# created to the list. # created to the list.
TESTS = sample1_unittest TESTS = sample1_unittest
...@@ -38,10 +44,10 @@ GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ ...@@ -38,10 +44,10 @@ GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
# House-keeping build targets. # House-keeping build targets.
all : $(TESTS) all : $(GTEST_LIBS) $(TESTS)
clean : clean :
rm -f $(TESTS) gtest.a gtest_main.a *.o rm -f $(GTEST_LIBS) $(TESTS) *.o
# Builds gtest.a and gtest_main.a. # Builds gtest.a and gtest_main.a.
...@@ -61,10 +67,10 @@ gtest_main.o : $(GTEST_SRCS_) ...@@ -61,10 +67,10 @@ gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \ $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest_main.cc $(GTEST_DIR)/src/gtest_main.cc
gtest.a : gtest-all.o libgtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^ $(AR) $(ARFLAGS) $@ $^
gtest_main.a : gtest-all.o gtest_main.o libgtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $@ $^ $(AR) $(ARFLAGS) $@ $^
# Builds a sample test. A test should link with either gtest.a or # Builds a sample test. A test should link with either gtest.a or
...@@ -78,5 +84,5 @@ sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \ ...@@ -78,5 +84,5 @@ sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
$(USER_DIR)/sample1.h $(GTEST_HEADERS) $(USER_DIR)/sample1.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
sample1_unittest : sample1.o sample1_unittest.o gtest_main.a sample1_unittest : sample1.o sample1_unittest.o $(GTEST_LIBS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -L$(GTEST_LIB_DIR) -lgtest_main -lpthread $^ -o $@
...@@ -274,8 +274,6 @@ static const int kFuchsiaReadPipeFd = 3; ...@@ -274,8 +274,6 @@ static const int kFuchsiaReadPipeFd = 3;
// statement, which is not allowed; THREW means that the test statement // statement, which is not allowed; THREW means that the test statement
// returned control by throwing an exception. IN_PROGRESS means the test // returned control by throwing an exception. IN_PROGRESS means the test
// has not yet concluded. // has not yet concluded.
// FIXME: Unify names and possibly values for
// AbortReason, DeathTestOutcome, and flag characters above.
enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
// Routine for aborting the program which is safe to call from an // Routine for aborting the program which is safe to call from an
...@@ -755,9 +753,9 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { ...@@ -755,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_) + "|" +
...@@ -974,9 +972,9 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { ...@@ -974,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_ + "|"
...@@ -1413,9 +1411,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { ...@@ -1413,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_) + "|"
...@@ -1523,8 +1521,6 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id, ...@@ -1523,8 +1521,6 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
StreamableToString(parent_process_id)); StreamableToString(parent_process_id));
} }
// FIXME: Replace the following check with a
// compile-time assertion when available.
GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t)); GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
const HANDLE write_handle = const HANDLE write_handle =
......
...@@ -38,9 +38,6 @@ ...@@ -38,9 +38,6 @@
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
# include <direct.h> # include <direct.h>
# include <io.h> # include <io.h>
#elif GTEST_OS_SYMBIAN
// Symbian OpenC has PATH_MAX in sys/syslimits.h
# include <sys/syslimits.h>
#else #else
# include <limits.h> # include <limits.h>
# include <climits> // Some Linux distributions define PATH_MAX here. # include <climits> // Some Linux distributions define PATH_MAX here.
...@@ -250,9 +247,6 @@ bool FilePath::DirectoryExists() const { ...@@ -250,9 +247,6 @@ bool FilePath::DirectoryExists() const {
// root directory per disk drive.) // root directory per disk drive.)
bool FilePath::IsRootDirectory() const { bool FilePath::IsRootDirectory() const {
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// FIXME: on Windows a network share like
// \\server\share can be a root directory, although it cannot be the
// current directory. Handle this properly.
return pathname_.length() == 3 && IsAbsolutePath(); return pathname_.length() == 3 && IsAbsolutePath();
#else #else
return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]); return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
...@@ -350,7 +344,6 @@ FilePath FilePath::RemoveTrailingPathSeparator() const { ...@@ -350,7 +344,6 @@ FilePath FilePath::RemoveTrailingPathSeparator() const {
// Removes any redundant separators that might be in the pathname. // Removes any redundant separators that might be in the pathname.
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
// redundancies that might be in a pathname involving "." or "..". // redundancies that might be in a pathname involving "." or "..".
// FIXME: handle Windows network shares (e.g. \\server\share).
void FilePath::Normalize() { void FilePath::Normalize() {
if (pathname_.c_str() == nullptr) { if (pathname_.c_str() == nullptr) {
pathname_ = ""; pathname_ = "";
......
...@@ -231,7 +231,7 @@ GTEST_API_ std::string CodePointToUtf8(UInt32 code_point); ...@@ -231,7 +231,7 @@ GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
// Converts a wide string to a narrow string in UTF-8 encoding. // Converts a wide string to a narrow string in UTF-8 encoding.
// The wide string is assumed to have the following encoding: // The wide string is assumed to have the following encoding:
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS) // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin)
// UTF-32 if sizeof(wchar_t) == 4 (on Linux) // UTF-32 if sizeof(wchar_t) == 4 (on Linux)
// Parameter str points to a null-terminated wide string. // Parameter str points to a null-terminated wide string.
// Parameter num_chars may additionally limit the number // Parameter num_chars may additionally limit the number
...@@ -388,10 +388,10 @@ class GTEST_API_ UnitTestOptions { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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
...@@ -998,8 +1010,6 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) { ...@@ -998,8 +1010,6 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
const bool parse_success = *end == '\0' && errno == 0; const bool parse_success = *end == '\0' && errno == 0;
// FIXME: Convert this to compile time assertion when it is
// available.
GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed)); GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
const Integer result = static_cast<Integer>(parsed); const Integer result = static_cast<Integer>(parsed);
...@@ -1138,14 +1148,18 @@ class StreamingListener : public EmptyTestEventListener { ...@@ -1138,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 {
......
...@@ -265,9 +265,6 @@ Mutex::Mutex() ...@@ -265,9 +265,6 @@ Mutex::Mutex()
Mutex::~Mutex() { Mutex::~Mutex() {
// Static mutexes are leaked intentionally. It is not thread-safe to try // Static mutexes are leaked intentionally. It is not thread-safe to try
// to clean them up. // to clean them up.
// FIXME: Switch to Slim Reader/Writer (SRW) Locks, which requires
// nothing to clean it up but is available only on Vista and later.
// https://docs.microsoft.com/en-us/windows/desktop/Sync/slim-reader-writer--srw--locks
if (type_ == kDynamic) { if (type_ == kDynamic) {
::DeleteCriticalSection(critical_section_); ::DeleteCriticalSection(critical_section_);
delete critical_section_; delete critical_section_;
...@@ -388,7 +385,6 @@ class ThreadWithParamSupport : public ThreadWithParamBase { ...@@ -388,7 +385,6 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
Notification* thread_can_start) { Notification* thread_can_start) {
ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start); ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start);
DWORD thread_id; DWORD thread_id;
// FIXME: Consider to use _beginthreadex instead.
HANDLE thread_handle = ::CreateThread( HANDLE thread_handle = ::CreateThread(
nullptr, // Default security. nullptr, // Default security.
0, // Default stack size. 0, // Default stack size.
...@@ -741,9 +737,6 @@ static std::string FormatRegexSyntaxError(const char* regex, int index) { ...@@ -741,9 +737,6 @@ static std::string FormatRegexSyntaxError(const char* regex, int index) {
// otherwise returns true. // otherwise returns true.
bool ValidateRegex(const char* regex) { bool ValidateRegex(const char* regex) {
if (regex == nullptr) { if (regex == nullptr) {
// FIXME: fix the source file location in the
// assertion failures to match where the regex is used in user
// code.
ADD_FAILURE() << "NULL is not a valid simple regular expression."; ADD_FAILURE() << "NULL is not a valid simple regular expression.";
return false; return false;
} }
......
...@@ -89,7 +89,6 @@ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count, ...@@ -89,7 +89,6 @@ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
// If the object size is bigger than kThreshold, we'll have to omit // If the object size is bigger than kThreshold, we'll have to omit
// some details by printing only the first and the last kChunkSize // some details by printing only the first and the last kChunkSize
// bytes. // bytes.
// FIXME: let the user control the threshold using a flag.
if (count < kThreshold) { if (count < kThreshold) {
PrintByteSegmentInObjectTo(obj_bytes, 0, count, os); PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
} else { } else {
......
...@@ -57,7 +57,7 @@ static std::vector<std::string> SplitIntoTestNames(const char* src) { ...@@ -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( ...@@ -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";
} }
} }
......
...@@ -54,8 +54,6 @@ ...@@ -54,8 +54,6 @@
#if GTEST_OS_LINUX #if GTEST_OS_LINUX
// FIXME: Use autoconf to detect availability of
// gettimeofday().
# define GTEST_HAS_GETTIMEOFDAY_ 1 # define GTEST_HAS_GETTIMEOFDAY_ 1
# include <fcntl.h> // NOLINT # include <fcntl.h> // NOLINT
...@@ -68,10 +66,6 @@ ...@@ -68,10 +66,6 @@
# include <unistd.h> // NOLINT # include <unistd.h> // NOLINT
# include <string> # include <string>
#elif GTEST_OS_SYMBIAN
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT
#elif GTEST_OS_ZOS #elif GTEST_OS_ZOS
# define GTEST_HAS_GETTIMEOFDAY_ 1 # define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT # include <sys/time.h> // NOLINT
...@@ -93,11 +87,6 @@ ...@@ -93,11 +87,6 @@
# if GTEST_OS_WINDOWS_MINGW # if GTEST_OS_WINDOWS_MINGW
// MinGW has gettimeofday() but not _ftime64(). // MinGW has gettimeofday() but not _ftime64().
// FIXME: Use autoconf to detect availability of
// gettimeofday().
// FIXME: There are other ways to get the time on
// Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW
// supports these. consider using them instead.
# define GTEST_HAS_GETTIMEOFDAY_ 1 # define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT # include <sys/time.h> // NOLINT
# endif // GTEST_OS_WINDOWS_MINGW # endif // GTEST_OS_WINDOWS_MINGW
...@@ -110,8 +99,6 @@ ...@@ -110,8 +99,6 @@
#else #else
// Assume other platforms have gettimeofday(). // Assume other platforms have gettimeofday().
// FIXME: Use autoconf to detect availability of
// gettimeofday().
# define GTEST_HAS_GETTIMEOFDAY_ 1 # define GTEST_HAS_GETTIMEOFDAY_ 1
// cpplint thinks that the header is already included, so we want to // cpplint thinks that the header is already included, so we want to
...@@ -160,14 +147,14 @@ using internal::Shuffle; ...@@ -160,14 +147,14 @@ using internal::Shuffle;
// Constants. // Constants.
// A test whose test case name or test name matches this filter is // A test whose test suite name or test name matches this filter is
// disabled and not run. // disabled and not run.
static const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*"; static const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*";
// A test case whose name matches this filter is considered a death // A test suite whose name matches this filter is considered a death
// test case and will be run before test cases whose name doesn't // test suite and will be run before test suites whose name doesn't
// match this filter. // match this filter.
static const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*"; static const char kDeathTestSuiteFilter[] = "*DeathTest:*DeathTest/*";
// A test filter that matches everything. // A test filter that matches everything.
static const char kUniversalFilter[] = "*"; static const char kUniversalFilter[] = "*";
...@@ -372,11 +359,11 @@ UInt32 Random::Generate(UInt32 range) { ...@@ -372,11 +359,11 @@ UInt32 Random::Generate(UInt32 range) {
// Google Test before calling RUN_ALL_TESTS(). // Google Test before calling RUN_ALL_TESTS().
static bool GTestIsInitialized() { return GetArgvs().size() > 0; } static bool GTestIsInitialized() { return GetArgvs().size() > 0; }
// Iterates over a vector of TestCases, keeping a running sum of the // Iterates over a vector of TestSuites, keeping a running sum of the
// results of calling a given int-returning method on each. // results of calling a given int-returning method on each.
// Returns the sum. // Returns the sum.
static int SumOverTestCaseList(const std::vector<TestCase*>& case_list, static int SumOverTestSuiteList(const std::vector<TestSuite*>& case_list,
int (TestCase::*method)() const) { int (TestSuite::*method)() const) {
int sum = 0; int sum = 0;
for (size_t i = 0; i < case_list.size(); i++) { for (size_t i = 0; i < case_list.size(); i++) {
sum += (case_list[i]->*method)(); sum += (case_list[i]->*method)();
...@@ -384,20 +371,20 @@ static int SumOverTestCaseList(const std::vector<TestCase*>& case_list, ...@@ -384,20 +371,20 @@ static int SumOverTestCaseList(const std::vector<TestCase*>& case_list,
return sum; return sum;
} }
// Returns true iff the test case passed. // Returns true iff the test suite passed.
static bool TestCasePassed(const TestCase* test_case) { static bool TestSuitePassed(const TestSuite* test_suite) {
return test_case->should_run() && test_case->Passed(); return test_suite->should_run() && test_suite->Passed();
} }
// Returns true iff the test case failed. // Returns true iff the test suite failed.
static bool TestCaseFailed(const TestCase* test_case) { static bool TestSuiteFailed(const TestSuite* test_suite) {
return test_case->should_run() && test_case->Failed(); return test_suite->should_run() && test_suite->Failed();
} }
// Returns true iff test_case contains at least one test that should // Returns true iff test_suite contains at least one test that should
// run. // run.
static bool ShouldRunTestCase(const TestCase* test_case) { static bool ShouldRunTestSuite(const TestSuite* test_suite) {
return test_case->should_run(); return test_suite->should_run();
} }
// AssertHelper constructor. // AssertHelper constructor.
...@@ -481,10 +468,6 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() { ...@@ -481,10 +468,6 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
internal::FilePath output_name(colon + 1); internal::FilePath output_name(colon + 1);
if (!output_name.IsAbsolutePath()) if (!output_name.IsAbsolutePath())
// FIXME: on Windows \some\path is not an absolute
// path (as its meaning depends on the current drive), yet the
// following logic for turning it into an absolute path is wrong.
// Fix it.
output_name = internal::FilePath::ConcatPaths( output_name = internal::FilePath::ConcatPaths(
internal::FilePath(UnitTest::GetInstance()->original_working_dir()), internal::FilePath(UnitTest::GetInstance()->original_working_dir()),
internal::FilePath(colon + 1)); internal::FilePath(colon + 1));
...@@ -541,11 +524,11 @@ bool UnitTestOptions::MatchesFilter( ...@@ -541,11 +524,11 @@ bool UnitTestOptions::MatchesFilter(
} }
} }
// 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.
bool UnitTestOptions::FilterMatchesTest(const std::string &test_case_name, bool UnitTestOptions::FilterMatchesTest(const std::string& test_suite_name,
const std::string &test_name) { const std::string& test_name) {
const std::string& full_name = test_case_name + "." + test_name.c_str(); const std::string& full_name = test_suite_name + "." + test_name.c_str();
// Split --gtest_filter at '-', if there is one, to separate into // Split --gtest_filter at '-', if there is one, to separate into
// positive filter and negative filter portions // positive filter and negative filter portions
...@@ -767,66 +750,66 @@ void UnitTestImpl::SetTestPartResultReporterForCurrentThread( ...@@ -767,66 +750,66 @@ void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
per_thread_test_part_result_reporter_.set(reporter); per_thread_test_part_result_reporter_.set(reporter);
} }
// Gets the number of successful test cases. // Gets the number of successful test suites.
int UnitTestImpl::successful_test_case_count() const { int UnitTestImpl::successful_test_suite_count() const {
return CountIf(test_cases_, TestCasePassed); return CountIf(test_suites_, TestSuitePassed);
} }
// Gets the number of failed test cases. // Gets the number of failed test suites.
int UnitTestImpl::failed_test_case_count() const { int UnitTestImpl::failed_test_suite_count() const {
return CountIf(test_cases_, TestCaseFailed); return CountIf(test_suites_, TestSuiteFailed);
} }
// Gets the number of all test cases. // Gets the number of all test suites.
int UnitTestImpl::total_test_case_count() const { int UnitTestImpl::total_test_suite_count() const {
return static_cast<int>(test_cases_.size()); return static_cast<int>(test_suites_.size());
} }
// 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 UnitTestImpl::test_case_to_run_count() const { int UnitTestImpl::test_suite_to_run_count() const {
return CountIf(test_cases_, ShouldRunTestCase); return CountIf(test_suites_, ShouldRunTestSuite);
} }
// Gets the number of successful tests. // Gets the number of successful tests.
int UnitTestImpl::successful_test_count() const { int UnitTestImpl::successful_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::successful_test_count); return SumOverTestSuiteList(test_suites_, &TestSuite::successful_test_count);
} }
// Gets the number of skipped tests. // Gets the number of skipped tests.
int UnitTestImpl::skipped_test_count() const { int UnitTestImpl::skipped_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::skipped_test_count); return SumOverTestSuiteList(test_suites_, &TestSuite::skipped_test_count);
} }
// Gets the number of failed tests. // Gets the number of failed tests.
int UnitTestImpl::failed_test_count() const { int UnitTestImpl::failed_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::failed_test_count); return SumOverTestSuiteList(test_suites_, &TestSuite::failed_test_count);
} }
// 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 UnitTestImpl::reportable_disabled_test_count() const { int UnitTestImpl::reportable_disabled_test_count() const {
return SumOverTestCaseList(test_cases_, return SumOverTestSuiteList(test_suites_,
&TestCase::reportable_disabled_test_count); &TestSuite::reportable_disabled_test_count);
} }
// Gets the number of disabled tests. // Gets the number of disabled tests.
int UnitTestImpl::disabled_test_count() const { int UnitTestImpl::disabled_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::disabled_test_count); return SumOverTestSuiteList(test_suites_, &TestSuite::disabled_test_count);
} }
// 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 UnitTestImpl::reportable_test_count() const { int UnitTestImpl::reportable_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::reportable_test_count); return SumOverTestSuiteList(test_suites_, &TestSuite::reportable_test_count);
} }
// Gets the number of all tests. // Gets the number of all tests.
int UnitTestImpl::total_test_count() const { int UnitTestImpl::total_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::total_test_count); return SumOverTestSuiteList(test_suites_, &TestSuite::total_test_count);
} }
// Gets the number of tests that should run. // Gets the number of tests that should run.
int UnitTestImpl::test_to_run_count() const { int UnitTestImpl::test_to_run_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count); return SumOverTestSuiteList(test_suites_, &TestSuite::test_to_run_count);
} }
// Returns the current OS stack trace as an std::string. // Returns the current OS stack trace as an std::string.
...@@ -860,8 +843,6 @@ TimeInMillis GetTimeInMillis() { ...@@ -860,8 +843,6 @@ TimeInMillis GetTimeInMillis() {
SYSTEMTIME now_systime; SYSTEMTIME now_systime;
FILETIME now_filetime; FILETIME now_filetime;
ULARGE_INTEGER now_int64; ULARGE_INTEGER now_int64;
// FIXME: Shouldn't this just use
// GetSystemTimeAsFileTime()?
GetSystemTime(&now_systime); GetSystemTime(&now_systime);
if (SystemTimeToFileTime(&now_systime, &now_filetime)) { if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
now_int64.LowPart = now_filetime.dwLowDateTime; now_int64.LowPart = now_filetime.dwLowDateTime;
...@@ -876,8 +857,6 @@ TimeInMillis GetTimeInMillis() { ...@@ -876,8 +857,6 @@ TimeInMillis GetTimeInMillis() {
// MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996 // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
// (deprecated function) there. // (deprecated function) there.
// FIXME: Use GetTickCount()? Or use
// SystemTimeToFileTime()
GTEST_DISABLE_MSC_DEPRECATED_PUSH_() GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
_ftime64(&now); _ftime64(&now);
GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_DEPRECATED_POP_()
...@@ -1411,8 +1390,6 @@ AssertionResult DoubleNearPredFormat(const char* expr1, ...@@ -1411,8 +1390,6 @@ AssertionResult DoubleNearPredFormat(const char* expr1,
const double diff = fabs(val1 - val2); const double diff = fabs(val1 - val2);
if (diff <= abs_error) return AssertionSuccess(); if (diff <= abs_error) return AssertionSuccess();
// FIXME: do not print the value of an expression if it's
// already a literal.
return AssertionFailure() return AssertionFailure()
<< "The difference between " << expr1 << " and " << expr2 << "The difference between " << expr1 << " and " << expr2
<< " is " << diff << ", which exceeds " << abs_error_expr << ", where\n" << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
...@@ -1827,7 +1804,7 @@ std::string CodePointToUtf8(UInt32 code_point) { ...@@ -1827,7 +1804,7 @@ std::string CodePointToUtf8(UInt32 code_point) {
// The following two functions only make sense if the system // The following two functions only make sense if the system
// uses UTF-16 for wide string encoding. All supported systems // uses UTF-16 for wide string encoding. All supported systems
// with 16 bit wchar_t (Windows, Cygwin, Symbian OS) do use UTF-16. // with 16 bit wchar_t (Windows, Cygwin) do use UTF-16.
// Determines if the arguments constitute UTF-16 surrogate pair // Determines if the arguments constitute UTF-16 surrogate pair
// and thus should be combined into a single Unicode code point // and thus should be combined into a single Unicode code point
...@@ -1850,7 +1827,7 @@ inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first, ...@@ -1850,7 +1827,7 @@ inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
// Converts a wide string to a narrow string in UTF-8 encoding. // Converts a wide string to a narrow string in UTF-8 encoding.
// The wide string is assumed to have the following encoding: // The wide string is assumed to have the following encoding:
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS) // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin)
// UTF-32 if sizeof(wchar_t) == 4 (on Linux) // UTF-32 if sizeof(wchar_t) == 4 (on Linux)
// Parameter str points to a null-terminated wide string. // Parameter str points to a null-terminated wide string.
// Parameter num_chars may additionally limit the number // Parameter num_chars may additionally limit the number
...@@ -2306,17 +2283,17 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, ...@@ -2306,17 +2283,17 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
} // namespace internal } // namespace internal
// Google Test requires all tests in the same test case to use the same test // Google Test requires all tests in the same test suite to use the same test
// fixture class. This function checks if the current test has the // fixture class. This function checks if the current test has the
// same fixture class as the first test in the current test case. If // same fixture class as the first test in the current test suite. If
// yes, it returns true; otherwise it generates a Google Test failure and // yes, it returns true; otherwise it generates a Google Test failure and
// returns false. // returns false.
bool Test::HasSameFixtureClass() { bool Test::HasSameFixtureClass() {
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
const TestCase* const test_case = impl->current_test_case(); const TestSuite* const test_suite = impl->current_test_suite();
// Info about the first test in the current test case. // Info about the first test in the current test suite.
const TestInfo* const first_test_info = test_case->test_info_list()[0]; const TestInfo* const first_test_info = test_suite->test_info_list()[0];
const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_; const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
const char* const first_test_name = first_test_info->name(); const char* const first_test_name = first_test_info->name();
...@@ -2332,7 +2309,7 @@ bool Test::HasSameFixtureClass() { ...@@ -2332,7 +2309,7 @@ bool Test::HasSameFixtureClass() {
const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId(); const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
if (first_is_TEST || this_is_TEST) { if (first_is_TEST || this_is_TEST) {
// Both TEST and TEST_F appear in same test case, which is incorrect. // Both TEST and TEST_F appear in same test suite, which is incorrect.
// Tell the user how to fix this. // Tell the user how to fix this.
// Gets the name of the TEST and the name of the TEST_F. Note // Gets the name of the TEST and the name of the TEST_F. Note
...@@ -2344,9 +2321,9 @@ bool Test::HasSameFixtureClass() { ...@@ -2344,9 +2321,9 @@ bool Test::HasSameFixtureClass() {
first_is_TEST ? this_test_name : first_test_name; first_is_TEST ? this_test_name : first_test_name;
ADD_FAILURE() ADD_FAILURE()
<< "All tests in the same test case must use the same test fixture\n" << "All tests in the same test suite must use the same test fixture\n"
<< "class, so mixing TEST_F and TEST in the same test case is\n" << "class, so mixing TEST_F and TEST in the same test suite is\n"
<< "illegal. In test case " << this_test_info->test_case_name() << "illegal. In test suite " << this_test_info->test_suite_name()
<< ",\n" << ",\n"
<< "test " << TEST_F_name << " is defined using TEST_F but\n" << "test " << TEST_F_name << " is defined using TEST_F but\n"
<< "test " << TEST_name << " is defined using TEST. You probably\n" << "test " << TEST_name << " is defined using TEST. You probably\n"
...@@ -2356,15 +2333,15 @@ bool Test::HasSameFixtureClass() { ...@@ -2356,15 +2333,15 @@ bool Test::HasSameFixtureClass() {
// Two fixture classes with the same name appear in two different // Two fixture classes with the same name appear in two different
// namespaces, which is not allowed. Tell the user how to fix this. // namespaces, which is not allowed. Tell the user how to fix this.
ADD_FAILURE() ADD_FAILURE()
<< "All tests in the same test case must use the same test fixture\n" << "All tests in the same test suite must use the same test fixture\n"
<< "class. However, in test case " << "class. However, in test suite "
<< this_test_info->test_case_name() << ",\n" << this_test_info->test_suite_name() << ",\n"
<< "you defined test " << first_test_name << "you defined test " << first_test_name << " and test "
<< " and test " << this_test_name << "\n" << this_test_name << "\n"
<< "using two different test fixture classes. This can happen if\n" << "using two different test fixture classes. This can happen if\n"
<< "the two classes are from different namespaces or translation\n" << "the two classes are from different namespaces or translation\n"
<< "units and have the same name. You should probably rename one\n" << "units and have the same name. You should probably rename one\n"
<< "of the classes to put the tests into different test cases."; << "of the classes to put the tests into different test suites.";
} }
return false; return false;
} }
...@@ -2551,13 +2528,13 @@ bool Test::IsSkipped() { ...@@ -2551,13 +2528,13 @@ bool Test::IsSkipped() {
// Constructs a TestInfo object. It assumes ownership of the test factory // Constructs a TestInfo object. It assumes ownership of the test factory
// object. // object.
TestInfo::TestInfo(const std::string& a_test_case_name, TestInfo::TestInfo(const std::string& a_test_suite_name,
const std::string& a_name, const char* a_type_param, const std::string& a_name, const char* a_type_param,
const char* a_value_param, const char* a_value_param,
internal::CodeLocation a_code_location, internal::CodeLocation a_code_location,
internal::TypeId fixture_class_id, internal::TypeId fixture_class_id,
internal::TestFactoryBase* factory) internal::TestFactoryBase* factory)
: test_case_name_(a_test_case_name), : test_suite_name_(a_test_suite_name),
name_(a_name), name_(a_name),
type_param_(a_type_param ? new std::string(a_type_param) : nullptr), type_param_(a_type_param ? new std::string(a_type_param) : nullptr),
value_param_(a_value_param ? new std::string(a_value_param) : nullptr), value_param_(a_value_param ? new std::string(a_value_param) : nullptr),
...@@ -2579,7 +2556,7 @@ namespace internal { ...@@ -2579,7 +2556,7 @@ namespace internal {
// //
// 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.
...@@ -2587,40 +2564,35 @@ namespace internal { ...@@ -2587,40 +2564,35 @@ namespace internal {
// or NULL if this is not a value-parameterized test. // or NULL if this is not a value-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.
TestInfo* MakeAndRegisterTestInfo( 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) {
TestInfo* const test_info = TestInfo* const test_info =
new TestInfo(test_case_name, name, type_param, value_param, new TestInfo(test_suite_name, name, type_param, value_param,
code_location, fixture_class_id, factory); code_location, fixture_class_id, factory);
GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info); GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
return test_info; return test_info;
} }
void ReportInvalidTestCaseType(const char* test_case_name, void ReportInvalidTestSuiteType(const char* test_suite_name,
CodeLocation code_location) { CodeLocation code_location) {
Message errors; Message errors;
errors errors
<< "Attempted redefinition of test case " << test_case_name << ".\n" << "Attempted redefinition of test suite " << test_suite_name << ".\n"
<< "All tests in the same test case must use the same test fixture\n" << "All tests in the same test suite must use the same test fixture\n"
<< "class. However, in test case " << test_case_name << ", you tried\n" << "class. However, in test suite " << test_suite_name << ", you tried\n"
<< "to define a test using a fixture class different from the one\n" << "to define a test using a fixture class different from the one\n"
<< "used earlier. This can happen if the two fixture classes are\n" << "used earlier. This can happen if the two fixture classes are\n"
<< "from different namespaces and have the same name. You should\n" << "from different namespaces and have the same name. You should\n"
<< "probably rename one of the classes to put the tests into different\n" << "probably rename one of the classes to put the tests into different\n"
<< "test cases."; << "test suites.";
GTEST_LOG_(ERROR) << FormatFileLocation(code_location.file.c_str(), GTEST_LOG_(ERROR) << FormatFileLocation(code_location.file.c_str(),
code_location.line) code_location.line)
...@@ -2633,7 +2605,7 @@ namespace { ...@@ -2633,7 +2605,7 @@ namespace {
// A predicate that checks the test name of a TestInfo against a known // A predicate that checks the test name of a TestInfo against a known
// value. // value.
// //
// This is used for implementation of the TestCase class only. We put // This is used for implementation of the TestSuite class only. We put
// it in the anonymous namespace to prevent polluting the outer // it in the anonymous namespace to prevent polluting the outer
// namespace. // namespace.
// //
...@@ -2660,7 +2632,7 @@ class TestNameIs { ...@@ -2660,7 +2632,7 @@ class TestNameIs {
namespace internal { namespace internal {
// This method expands all parameterized tests registered with macros TEST_P // This method expands all parameterized tests registered with macros TEST_P
// and INSTANTIATE_TEST_CASE_P into regular tests and registers those. // and INSTANTIATE_TEST_SUITE_P into regular tests and registers those.
// This will be done just once during the program runtime. // This will be done just once during the program runtime.
void UnitTestImpl::RegisterParameterizedTests() { void UnitTestImpl::RegisterParameterizedTests() {
if (!parameterized_tests_registered_) { if (!parameterized_tests_registered_) {
...@@ -2718,60 +2690,60 @@ void TestInfo::Run() { ...@@ -2718,60 +2690,60 @@ void TestInfo::Run() {
impl->set_current_test_info(nullptr); impl->set_current_test_info(nullptr);
} }
// class TestCase // class TestSuite
// Gets the number of successful tests in this test case. // Gets the number of successful tests in this test suite.
int TestCase::successful_test_count() const { int TestSuite::successful_test_count() const {
return CountIf(test_info_list_, TestPassed); return CountIf(test_info_list_, TestPassed);
} }
// Gets the number of successful tests in this test case. // Gets the number of successful tests in this test suite.
int TestCase::skipped_test_count() const { int TestSuite::skipped_test_count() const {
return CountIf(test_info_list_, TestSkipped); return CountIf(test_info_list_, TestSkipped);
} }
// Gets the number of failed tests in this test case. // Gets the number of failed tests in this test suite.
int TestCase::failed_test_count() const { int TestSuite::failed_test_count() const {
return CountIf(test_info_list_, TestFailed); return CountIf(test_info_list_, TestFailed);
} }
// 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 TestCase::reportable_disabled_test_count() const { int TestSuite::reportable_disabled_test_count() const {
return CountIf(test_info_list_, TestReportableDisabled); return CountIf(test_info_list_, TestReportableDisabled);
} }
// Gets the number of disabled tests in this test case. // Gets the number of disabled tests in this test suite.
int TestCase::disabled_test_count() const { int TestSuite::disabled_test_count() const {
return CountIf(test_info_list_, TestDisabled); return CountIf(test_info_list_, TestDisabled);
} }
// 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 TestCase::reportable_test_count() const { int TestSuite::reportable_test_count() const {
return CountIf(test_info_list_, TestReportable); return CountIf(test_info_list_, TestReportable);
} }
// 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 TestCase::test_to_run_count() const { int TestSuite::test_to_run_count() const {
return CountIf(test_info_list_, ShouldRunTest); return CountIf(test_info_list_, ShouldRunTest);
} }
// Gets the number of all tests. // Gets the number of all tests.
int TestCase::total_test_count() const { int TestSuite::total_test_count() const {
return static_cast<int>(test_info_list_.size()); return static_cast<int>(test_info_list_.size());
} }
// Creates a TestCase with the given name. // Creates a TestSuite with the given name.
// //
// Arguments: // Arguments:
// //
// name: name of the test case // name: name of the test suite
// a_type_param: the name of the test case's type parameter, or NULL if // a_type_param: the name of the test suite's type parameter, or NULL if
// this is not a typed or a type-parameterized test case. // this is not a typed or a type-parameterized test suite.
// 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::TestCase(const char* a_name, const char* a_type_param, TestSuite::TestSuite(const char* a_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)
: name_(a_name), : name_(a_name),
type_param_(a_type_param ? new std::string(a_type_param) : nullptr), type_param_(a_type_param ? new std::string(a_type_param) : nullptr),
set_up_tc_(set_up_tc), set_up_tc_(set_up_tc),
...@@ -2779,46 +2751,52 @@ TestCase::TestCase(const char* a_name, const char* a_type_param, ...@@ -2779,46 +2751,52 @@ TestCase::TestCase(const char* a_name, const char* a_type_param,
should_run_(false), should_run_(false),
elapsed_time_(0) {} elapsed_time_(0) {}
// Destructor of TestCase. // Destructor of TestSuite.
TestCase::~TestCase() { TestSuite::~TestSuite() {
// Deletes every Test in the collection. // Deletes every Test in the collection.
ForEach(test_info_list_, internal::Delete<TestInfo>); ForEach(test_info_list_, internal::Delete<TestInfo>);
} }
// Returns the i-th test among all the tests. i can range from 0 to // Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL. // total_test_count() - 1. If i is not in that range, returns NULL.
const TestInfo* TestCase::GetTestInfo(int i) const { const TestInfo* TestSuite::GetTestInfo(int i) const {
const int index = GetElementOr(test_indices_, i, -1); const int index = GetElementOr(test_indices_, i, -1);
return index < 0 ? nullptr : test_info_list_[index]; return index < 0 ? nullptr : test_info_list_[index];
} }
// Returns the i-th test among all the tests. i can range from 0 to // Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL. // total_test_count() - 1. If i is not in that range, returns NULL.
TestInfo* TestCase::GetMutableTestInfo(int i) { TestInfo* TestSuite::GetMutableTestInfo(int i) {
const int index = GetElementOr(test_indices_, i, -1); const int index = GetElementOr(test_indices_, i, -1);
return index < 0 ? nullptr : test_info_list_[index]; return index < 0 ? nullptr : test_info_list_[index];
} }
// Adds a test to this test case. Will delete the test upon // Adds a test to this test suite. Will delete the test upon
// destruction of the TestCase object. // destruction of the TestSuite object.
void TestCase::AddTestInfo(TestInfo * test_info) { void TestSuite::AddTestInfo(TestInfo* test_info) {
test_info_list_.push_back(test_info); test_info_list_.push_back(test_info);
test_indices_.push_back(static_cast<int>(test_indices_.size())); test_indices_.push_back(static_cast<int>(test_indices_.size()));
} }
// Runs every test in this TestCase. // Runs every test in this TestSuite.
void TestCase::Run() { void TestSuite::Run() {
if (!should_run_) return; if (!should_run_) return;
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
impl->set_current_test_case(this); impl->set_current_test_suite(this);
TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
// Call both legacy and the new API
repeater->OnTestSuiteStart(*this);
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
repeater->OnTestCaseStart(*this); repeater->OnTestCaseStart(*this);
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
impl->os_stack_trace_getter()->UponLeavingGTest(); impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported( internal::HandleExceptionsInMethodIfSupported(
this, &TestCase::RunSetUpTestCase, "SetUpTestCase()"); this, &TestSuite::RunSetUpTestSuite, "SetUpTestSuite()");
const internal::TimeInMillis start = internal::GetTimeInMillis(); const internal::TimeInMillis start = internal::GetTimeInMillis();
for (int i = 0; i < total_test_count(); i++) { for (int i = 0; i < total_test_count(); i++) {
...@@ -2828,25 +2806,31 @@ void TestCase::Run() { ...@@ -2828,25 +2806,31 @@ void TestCase::Run() {
impl->os_stack_trace_getter()->UponLeavingGTest(); impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported( internal::HandleExceptionsInMethodIfSupported(
this, &TestCase::RunTearDownTestCase, "TearDownTestCase()"); this, &TestSuite::RunTearDownTestSuite, "TearDownTestSuite()");
// Call both legacy and the new API
repeater->OnTestSuiteEnd(*this);
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
repeater->OnTestCaseEnd(*this); repeater->OnTestCaseEnd(*this);
impl->set_current_test_case(nullptr); #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
impl->set_current_test_suite(nullptr);
} }
// Clears the results of all tests in this test case. // Clears the results of all tests in this test suite.
void TestCase::ClearResult() { void TestSuite::ClearResult() {
ad_hoc_test_result_.Clear(); ad_hoc_test_result_.Clear();
ForEach(test_info_list_, TestInfo::ClearTestResult); ForEach(test_info_list_, TestInfo::ClearTestResult);
} }
// Shuffles the tests in this test case. // Shuffles the tests in this test suite.
void TestCase::ShuffleTests(internal::Random* random) { void TestSuite::ShuffleTests(internal::Random* random) {
Shuffle(random, &test_indices_); Shuffle(random, &test_indices_);
} }
// Restores the test order to before the first shuffle. // Restores the test order to before the first shuffle.
void TestCase::UnshuffleTests() { void TestSuite::UnshuffleTests() {
for (size_t i = 0; i < test_indices_.size(); i++) { for (size_t i = 0; i < test_indices_.size(); i++) {
test_indices_[i] = static_cast<int>(i); test_indices_[i] = static_cast<int>(i);
} }
...@@ -2869,9 +2853,9 @@ static std::string FormatTestCount(int test_count) { ...@@ -2869,9 +2853,9 @@ static std::string FormatTestCount(int test_count) {
return FormatCountableNoun(test_count, "test", "tests"); return FormatCountableNoun(test_count, "test", "tests");
} }
// Formats the count of test cases. // Formats the count of test suites.
static std::string FormatTestCaseCount(int test_case_count) { static std::string FormatTestSuiteCount(int test_suite_count) {
return FormatCountableNoun(test_case_count, "test case", "test cases"); return FormatCountableNoun(test_suite_count, "test suite", "test suites");
} }
// Converts a TestPartResult::Type enum to human-friendly string // Converts a TestPartResult::Type enum to human-friendly string
...@@ -3034,15 +3018,14 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { ...@@ -3034,15 +3018,14 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || \ #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \
GTEST_OS_IOS || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
const bool use_color = AlwaysFalse(); const bool use_color = AlwaysFalse();
#else #else
static const bool in_color_mode = static const bool in_color_mode =
ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0); ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0);
const bool use_color = in_color_mode && (color != COLOR_DEFAULT); const bool use_color = in_color_mode && (color != COLOR_DEFAULT);
#endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS
// The '!= 0' comparison is necessary to satisfy MSVC 7.1.
if (!use_color) { if (!use_color) {
vprintf(fmt, args); vprintf(fmt, args);
...@@ -3106,8 +3089,8 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) { ...@@ -3106,8 +3089,8 @@ static void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
class PrettyUnitTestResultPrinter : public TestEventListener { class PrettyUnitTestResultPrinter : public TestEventListener {
public: public:
PrettyUnitTestResultPrinter() {} PrettyUnitTestResultPrinter() {}
static void PrintTestName(const char * test_case, const char * test) { static void PrintTestName(const char* test_suite, const char* test) {
printf("%s.%s", test_case, test); printf("%s.%s", test_suite, test);
} }
// The following methods override what's in the TestEventListener class. // The following methods override what's in the TestEventListener class.
...@@ -3115,11 +3098,11 @@ class PrettyUnitTestResultPrinter : public TestEventListener { ...@@ -3115,11 +3098,11 @@ class PrettyUnitTestResultPrinter : public TestEventListener {
void OnTestIterationStart(const UnitTest& unit_test, int iteration) override; void OnTestIterationStart(const UnitTest& unit_test, 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 OnTestCaseStart(const TestSuite& test_suite) override;
void OnTestStart(const TestInfo& test_info) override; void OnTestStart(const TestInfo& test_info) override;
void OnTestPartResult(const TestPartResult& result) override; void OnTestPartResult(const TestPartResult& result) override;
void OnTestEnd(const TestInfo& test_info) override; void OnTestEnd(const TestInfo& test_info) override;
void OnTestCaseEnd(const TestCase& test_case) override; void OnTestCaseEnd(const TestSuite& test_suite) override;
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, int iteration) override; void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
...@@ -3162,7 +3145,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart( ...@@ -3162,7 +3145,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
ColoredPrintf(COLOR_GREEN, "[==========] "); ColoredPrintf(COLOR_GREEN, "[==========] ");
printf("Running %s from %s.\n", printf("Running %s from %s.\n",
FormatTestCount(unit_test.test_to_run_count()).c_str(), FormatTestCount(unit_test.test_to_run_count()).c_str(),
FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str()); FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str());
fflush(stdout); fflush(stdout);
} }
...@@ -3173,22 +3156,22 @@ void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart( ...@@ -3173,22 +3156,22 @@ void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
fflush(stdout); fflush(stdout);
} }
void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) { void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestSuite& test_suite) {
const std::string counts = const std::string counts =
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); FormatCountableNoun(test_suite.test_to_run_count(), "test", "tests");
ColoredPrintf(COLOR_GREEN, "[----------] "); ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("%s from %s", counts.c_str(), test_case.name()); printf("%s from %s", counts.c_str(), test_suite.name());
if (test_case.type_param() == nullptr) { if (test_suite.type_param() == nullptr) {
printf("\n"); printf("\n");
} else { } else {
printf(", where %s = %s\n", kTypeParamLabel, test_case.type_param()); printf(", where %s = %s\n", kTypeParamLabel, test_suite.type_param());
} }
fflush(stdout); fflush(stdout);
} }
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) { void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
ColoredPrintf(COLOR_GREEN, "[ RUN ] "); ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
PrintTestName(test_info.test_case_name(), test_info.name()); PrintTestName(test_info.test_suite_name(), test_info.name());
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);
} }
...@@ -3218,7 +3201,7 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) { ...@@ -3218,7 +3201,7 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
} else { } else {
ColoredPrintf(COLOR_RED, "[ FAILED ] "); ColoredPrintf(COLOR_RED, "[ FAILED ] ");
} }
PrintTestName(test_info.test_case_name(), test_info.name()); PrintTestName(test_info.test_suite_name(), test_info.name());
if (test_info.result()->Failed()) if (test_info.result()->Failed())
PrintFullTestCommentIfPresent(test_info); PrintFullTestCommentIfPresent(test_info);
...@@ -3231,15 +3214,14 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) { ...@@ -3231,15 +3214,14 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
fflush(stdout); fflush(stdout);
} }
void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) { void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestSuite& test_suite) {
if (!GTEST_FLAG(print_time)) return; if (!GTEST_FLAG(print_time)) return;
const std::string counts = const std::string counts =
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); FormatCountableNoun(test_suite.test_to_run_count(), "test", "tests");
ColoredPrintf(COLOR_GREEN, "[----------] "); ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("%s from %s (%s ms total)\n\n", printf("%s from %s (%s ms total)\n\n", counts.c_str(), test_suite.name(),
counts.c_str(), test_case.name(), internal::StreamableToString(test_suite.elapsed_time()).c_str());
internal::StreamableToString(test_case.elapsed_time()).c_str());
fflush(stdout); fflush(stdout);
} }
...@@ -3257,18 +3239,18 @@ void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) { ...@@ -3257,18 +3239,18 @@ void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
return; return;
} }
for (int i = 0; i < unit_test.total_test_case_count(); ++i) { for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
const TestCase& test_case = *unit_test.GetTestCase(i); const TestSuite& test_suite = *unit_test.GetTestSuite(i);
if (!test_case.should_run() || (test_case.failed_test_count() == 0)) { if (!test_suite.should_run() || (test_suite.failed_test_count() == 0)) {
continue; continue;
} }
for (int j = 0; j < test_case.total_test_count(); ++j) { for (int j = 0; j < test_suite.total_test_count(); ++j) {
const TestInfo& test_info = *test_case.GetTestInfo(j); const TestInfo& test_info = *test_suite.GetTestInfo(j);
if (!test_info.should_run() || !test_info.result()->Failed()) { if (!test_info.should_run() || !test_info.result()->Failed()) {
continue; continue;
} }
ColoredPrintf(COLOR_RED, "[ FAILED ] "); ColoredPrintf(COLOR_RED, "[ FAILED ] ");
printf("%s.%s", test_case.name(), test_info.name()); printf("%s.%s", test_suite.name(), test_info.name());
PrintFullTestCommentIfPresent(test_info); PrintFullTestCommentIfPresent(test_info);
printf("\n"); printf("\n");
} }
...@@ -3282,18 +3264,18 @@ void PrettyUnitTestResultPrinter::PrintSkippedTests(const UnitTest& unit_test) { ...@@ -3282,18 +3264,18 @@ void PrettyUnitTestResultPrinter::PrintSkippedTests(const UnitTest& unit_test) {
return; return;
} }
for (int i = 0; i < unit_test.total_test_case_count(); ++i) { for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
const TestCase& test_case = *unit_test.GetTestCase(i); const TestSuite& test_suite = *unit_test.GetTestSuite(i);
if (!test_case.should_run() || (test_case.skipped_test_count() == 0)) { if (!test_suite.should_run() || (test_suite.skipped_test_count() == 0)) {
continue; continue;
} }
for (int j = 0; j < test_case.total_test_count(); ++j) { for (int j = 0; j < test_suite.total_test_count(); ++j) {
const TestInfo& test_info = *test_case.GetTestInfo(j); const TestInfo& test_info = *test_suite.GetTestInfo(j);
if (!test_info.should_run() || !test_info.result()->Skipped()) { if (!test_info.should_run() || !test_info.result()->Skipped()) {
continue; continue;
} }
ColoredPrintf(COLOR_GREEN, "[ SKIPPED ] "); ColoredPrintf(COLOR_GREEN, "[ SKIPPED ] ");
printf("%s.%s", test_case.name(), test_info.name()); printf("%s.%s", test_suite.name(), test_info.name());
printf("\n"); printf("\n");
} }
} }
...@@ -3304,7 +3286,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, ...@@ -3304,7 +3286,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
ColoredPrintf(COLOR_GREEN, "[==========] "); ColoredPrintf(COLOR_GREEN, "[==========] ");
printf("%s from %s ran.", printf("%s from %s ran.",
FormatTestCount(unit_test.test_to_run_count()).c_str(), FormatTestCount(unit_test.test_to_run_count()).c_str(),
FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str()); FormatTestSuiteCount(unit_test.test_suite_to_run_count()).c_str());
if (GTEST_FLAG(print_time)) { if (GTEST_FLAG(print_time)) {
printf(" (%s ms total)", printf(" (%s ms total)",
internal::StreamableToString(unit_test.elapsed_time()).c_str()); internal::StreamableToString(unit_test.elapsed_time()).c_str());
...@@ -3365,11 +3347,19 @@ class TestEventRepeater : public TestEventListener { ...@@ -3365,11 +3347,19 @@ class TestEventRepeater : public TestEventListener {
void OnTestIterationStart(const UnitTest& unit_test, int iteration) override; void OnTestIterationStart(const UnitTest& unit_test, 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; // Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
void OnTestCaseStart(const TestSuite& parameter) override;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
void OnTestSuiteStart(const TestSuite& parameter) override;
void OnTestStart(const TestInfo& test_info) override; void OnTestStart(const TestInfo& test_info) override;
void OnTestPartResult(const TestPartResult& result) override; void OnTestPartResult(const TestPartResult& result) override;
void OnTestEnd(const TestInfo& test_info) override; void OnTestEnd(const TestInfo& test_info) override;
void OnTestCaseEnd(const TestCase& test_case) override; // Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI
void OnTestCaseEnd(const TestSuite& parameter) override;
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI
void OnTestSuiteEnd(const TestSuite& parameter) override;
void OnEnvironmentsTearDownStart(const UnitTest& unit_test) override; void 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, int iteration) override; void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
...@@ -3393,7 +3383,6 @@ void TestEventRepeater::Append(TestEventListener *listener) { ...@@ -3393,7 +3383,6 @@ void TestEventRepeater::Append(TestEventListener *listener) {
listeners_.push_back(listener); listeners_.push_back(listener);
} }
// FIXME: Factor the search functionality into Vector::Find.
TestEventListener* TestEventRepeater::Release(TestEventListener *listener) { TestEventListener* TestEventRepeater::Release(TestEventListener *listener) {
for (size_t i = 0; i < listeners_.size(); ++i) { for (size_t i = 0; i < listeners_.size(); ++i) {
if (listeners_[i] == listener) { if (listeners_[i] == listener) {
...@@ -3428,14 +3417,22 @@ void TestEventRepeater::Name(const Type& parameter) { \ ...@@ -3428,14 +3417,22 @@ void TestEventRepeater::Name(const Type& parameter) { \
GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest) GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest) GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase) // Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REPEATER_METHOD_(OnTestCaseStart, TestSuite)
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REPEATER_METHOD_(OnTestSuiteStart, TestSuite)
GTEST_REPEATER_METHOD_(OnTestStart, TestInfo) GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult) GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest) GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest) GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest) GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo) GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase) // Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestSuite)
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
GTEST_REVERSE_REPEATER_METHOD_(OnTestSuiteEnd, TestSuite)
GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest) GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
#undef GTEST_REPEATER_METHOD_ #undef GTEST_REPEATER_METHOD_
...@@ -3467,11 +3464,11 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { ...@@ -3467,11 +3464,11 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
explicit XmlUnitTestResultPrinter(const char* output_file); explicit XmlUnitTestResultPrinter(const char* output_file);
void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override; void OnTestIterationEnd(const UnitTest& unit_test, int iteration) override;
void ListTestsMatchingFilter(const std::vector<TestCase*>& test_cases); void ListTestsMatchingFilter(const std::vector<TestSuite*>& test_suites);
// Prints an XML summary of all unit tests. // Prints an XML summary of all unit tests.
static void PrintXmlTestsList(std::ostream* stream, static void PrintXmlTestsList(std::ostream* stream,
const std::vector<TestCase*>& test_cases); const std::vector<TestSuite*>& test_suites);
private: private:
// Is c a whitespace character that is normalized to a space character // Is c a whitespace character that is normalized to a space character
...@@ -3516,12 +3513,12 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { ...@@ -3516,12 +3513,12 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
// Streams an XML representation of a TestInfo object. // Streams an XML representation of a TestInfo object.
static void OutputXmlTestInfo(::std::ostream* stream, static void OutputXmlTestInfo(::std::ostream* stream,
const char* test_case_name, const char* test_suite_name,
const TestInfo& test_info); const TestInfo& test_info);
// Prints an XML representation of a TestCase object // Prints an XML representation of a TestSuite object
static void PrintXmlTestCase(::std::ostream* stream, static void PrintXmlTestSuite(::std::ostream* stream,
const TestCase& test_case); const TestSuite& test_suite);
// Prints an XML summary of unit_test to output stream out. // Prints an XML summary of unit_test to output stream out.
static void PrintXmlUnitTest(::std::ostream* stream, static void PrintXmlUnitTest(::std::ostream* stream,
...@@ -3563,10 +3560,10 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, ...@@ -3563,10 +3560,10 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
} }
void XmlUnitTestResultPrinter::ListTestsMatchingFilter( void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
const std::vector<TestCase*>& test_cases) { const std::vector<TestSuite*>& test_suites) {
FILE* xmlout = OpenFileForWriting(output_file_); FILE* xmlout = OpenFileForWriting(output_file_);
std::stringstream stream; std::stringstream stream;
PrintXmlTestsList(&stream, test_cases); PrintXmlTestsList(&stream, test_suites);
fprintf(xmlout, "%s", StringStreamToString(&stream).c_str()); fprintf(xmlout, "%s", StringStreamToString(&stream).c_str());
fclose(xmlout); fclose(xmlout);
} }
...@@ -3581,8 +3578,6 @@ void XmlUnitTestResultPrinter::ListTestsMatchingFilter( ...@@ -3581,8 +3578,6 @@ void XmlUnitTestResultPrinter::ListTestsMatchingFilter(
// module will consist of ordinary English text. // module will consist of ordinary English text.
// If this module is ever modified to produce version 1.1 XML output, // If this module is ever modified to produce version 1.1 XML output,
// most invalid characters can be retained using character references. // most invalid characters can be retained using character references.
// FIXME: It might be nice to have a minimally invasive, human-readable
// escaping scheme for invalid characters, rather than dropping them.
std::string XmlUnitTestResultPrinter::EscapeXml( std::string XmlUnitTestResultPrinter::EscapeXml(
const std::string& str, bool is_attribute) { const std::string& str, bool is_attribute) {
Message m; Message m;
...@@ -3647,7 +3642,7 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters( ...@@ -3647,7 +3642,7 @@ std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
// This is how Google Test concepts map to the DTD: // This is how Google Test concepts map to the DTD:
// //
// <testsuites name="AllTests"> <-- corresponds to a UnitTest object // <testsuites name="AllTests"> <-- corresponds to a UnitTest object
// <testsuite name="testcase-name"> <-- corresponds to a TestCase object // <testsuite name="testcase-name"> <-- corresponds to a TestSuite object
// <testcase name="test-name"> <-- corresponds to a TestInfo object // <testcase name="test-name"> <-- corresponds to a TestInfo object
// <failure message="...">...</failure> // <failure message="...">...</failure>
// <failure message="...">...</failure> // <failure message="...">...</failure>
...@@ -3731,41 +3726,41 @@ void XmlUnitTestResultPrinter::OutputXmlAttribute( ...@@ -3731,41 +3726,41 @@ void XmlUnitTestResultPrinter::OutputXmlAttribute(
} }
// Prints an XML representation of a TestInfo object. // Prints an XML representation of a TestInfo object.
// FIXME: There is also value in printing properties with the plain printer.
void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
const char* test_case_name, const char* test_suite_name,
const TestInfo& test_info) { const TestInfo& test_info) {
const TestResult& result = *test_info.result(); const TestResult& result = *test_info.result();
const std::string kTestcase = "testcase"; const std::string kTestsuite = "testcase";
if (test_info.is_in_another_shard()) { if (test_info.is_in_another_shard()) {
return; return;
} }
*stream << " <testcase"; *stream << " <testcase";
OutputXmlAttribute(stream, kTestcase, "name", test_info.name()); OutputXmlAttribute(stream, kTestsuite, "name", test_info.name());
if (test_info.value_param() != nullptr) { if (test_info.value_param() != nullptr) {
OutputXmlAttribute(stream, kTestcase, "value_param", OutputXmlAttribute(stream, kTestsuite, "value_param",
test_info.value_param()); test_info.value_param());
} }
if (test_info.type_param() != nullptr) { if (test_info.type_param() != nullptr) {
OutputXmlAttribute(stream, kTestcase, "type_param", test_info.type_param()); OutputXmlAttribute(stream, kTestsuite, "type_param",
test_info.type_param());
} }
if (GTEST_FLAG(list_tests)) { if (GTEST_FLAG(list_tests)) {
OutputXmlAttribute(stream, kTestcase, "file", test_info.file()); OutputXmlAttribute(stream, kTestsuite, "file", test_info.file());
OutputXmlAttribute(stream, kTestcase, "line", OutputXmlAttribute(stream, kTestsuite, "line",
StreamableToString(test_info.line())); StreamableToString(test_info.line()));
*stream << " />\n"; *stream << " />\n";
return; return;
} }
OutputXmlAttribute(stream, kTestcase, "status", OutputXmlAttribute(
result.Skipped() ? "skipped" : stream, kTestsuite, "status",
test_info.should_run() ? "run" : "notrun"); result.Skipped() ? "skipped" : test_info.should_run() ? "run" : "notrun");
OutputXmlAttribute(stream, kTestcase, "time", OutputXmlAttribute(stream, kTestsuite, "time",
FormatTimeInMillisAsSeconds(result.elapsed_time())); FormatTimeInMillisAsSeconds(result.elapsed_time()));
OutputXmlAttribute(stream, kTestcase, "classname", test_case_name); OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name);
int failures = 0; int failures = 0;
for (int i = 0; i < result.total_part_count(); ++i) { for (int i = 0; i < result.total_part_count(); ++i) {
...@@ -3798,29 +3793,29 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, ...@@ -3798,29 +3793,29 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
} }
} }
// Prints an XML representation of a TestCase object // Prints an XML representation of a TestSuite object
void XmlUnitTestResultPrinter::PrintXmlTestCase(std::ostream* stream, void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream,
const TestCase& test_case) { const TestSuite& test_suite) {
const std::string kTestsuite = "testsuite"; const std::string kTestsuite = "testsuite";
*stream << " <" << kTestsuite; *stream << " <" << kTestsuite;
OutputXmlAttribute(stream, kTestsuite, "name", test_case.name()); OutputXmlAttribute(stream, kTestsuite, "name", test_suite.name());
OutputXmlAttribute(stream, kTestsuite, "tests", OutputXmlAttribute(stream, kTestsuite, "tests",
StreamableToString(test_case.reportable_test_count())); StreamableToString(test_suite.reportable_test_count()));
if (!GTEST_FLAG(list_tests)) { if (!GTEST_FLAG(list_tests)) {
OutputXmlAttribute(stream, kTestsuite, "failures", OutputXmlAttribute(stream, kTestsuite, "failures",
StreamableToString(test_case.failed_test_count())); StreamableToString(test_suite.failed_test_count()));
OutputXmlAttribute( OutputXmlAttribute(
stream, kTestsuite, "disabled", stream, kTestsuite, "disabled",
StreamableToString(test_case.reportable_disabled_test_count())); StreamableToString(test_suite.reportable_disabled_test_count()));
OutputXmlAttribute(stream, kTestsuite, "errors", "0"); OutputXmlAttribute(stream, kTestsuite, "errors", "0");
OutputXmlAttribute(stream, kTestsuite, "time", OutputXmlAttribute(stream, kTestsuite, "time",
FormatTimeInMillisAsSeconds(test_case.elapsed_time())); FormatTimeInMillisAsSeconds(test_suite.elapsed_time()));
*stream << TestPropertiesAsXmlAttributes(test_case.ad_hoc_test_result()); *stream << TestPropertiesAsXmlAttributes(test_suite.ad_hoc_test_result());
} }
*stream << ">\n"; *stream << ">\n";
for (int i = 0; i < test_case.total_test_count(); ++i) { for (int i = 0; i < test_suite.total_test_count(); ++i) {
if (test_case.GetTestInfo(i)->is_reportable()) if (test_suite.GetTestInfo(i)->is_reportable())
OutputXmlTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i)); OutputXmlTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(i));
} }
*stream << " </" << kTestsuite << ">\n"; *stream << " </" << kTestsuite << ">\n";
} }
...@@ -3856,31 +3851,31 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream, ...@@ -3856,31 +3851,31 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
OutputXmlAttribute(stream, kTestsuites, "name", "AllTests"); OutputXmlAttribute(stream, kTestsuites, "name", "AllTests");
*stream << ">\n"; *stream << ">\n";
for (int i = 0; i < unit_test.total_test_case_count(); ++i) { for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
if (unit_test.GetTestCase(i)->reportable_test_count() > 0) if (unit_test.GetTestSuite(i)->reportable_test_count() > 0)
PrintXmlTestCase(stream, *unit_test.GetTestCase(i)); PrintXmlTestSuite(stream, *unit_test.GetTestSuite(i));
} }
*stream << "</" << kTestsuites << ">\n"; *stream << "</" << kTestsuites << ">\n";
} }
void XmlUnitTestResultPrinter::PrintXmlTestsList( void XmlUnitTestResultPrinter::PrintXmlTestsList(
std::ostream* stream, const std::vector<TestCase*>& test_cases) { std::ostream* stream, const std::vector<TestSuite*>& test_suites) {
const std::string kTestsuites = "testsuites"; const std::string kTestsuites = "testsuites";
*stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
*stream << "<" << kTestsuites; *stream << "<" << kTestsuites;
int total_tests = 0; int total_tests = 0;
for (size_t i = 0; i < test_cases.size(); ++i) { for (auto test_suite : test_suites) {
total_tests += test_cases[i]->total_test_count(); total_tests += test_suite->total_test_count();
} }
OutputXmlAttribute(stream, kTestsuites, "tests", OutputXmlAttribute(stream, kTestsuites, "tests",
StreamableToString(total_tests)); StreamableToString(total_tests));
OutputXmlAttribute(stream, kTestsuites, "name", "AllTests"); OutputXmlAttribute(stream, kTestsuites, "name", "AllTests");
*stream << ">\n"; *stream << ">\n";
for (size_t i = 0; i < test_cases.size(); ++i) { for (auto test_suite : test_suites) {
PrintXmlTestCase(stream, *test_cases[i]); PrintXmlTestSuite(stream, *test_suite);
} }
*stream << "</" << kTestsuites << ">\n"; *stream << "</" << kTestsuites << ">\n";
} }
...@@ -3929,7 +3924,7 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener { ...@@ -3929,7 +3924,7 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener {
// Prints an JSON summary of all unit tests. // Prints an JSON summary of all unit tests.
static void PrintJsonTestList(::std::ostream* stream, static void PrintJsonTestList(::std::ostream* stream,
const std::vector<TestCase*>& test_cases); const std::vector<TestSuite*>& test_suites);
private: private:
// Returns an JSON-escaped copy of the input string str. // Returns an JSON-escaped copy of the input string str.
...@@ -3952,12 +3947,12 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener { ...@@ -3952,12 +3947,12 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener {
// Streams a JSON representation of a TestInfo object. // Streams a JSON representation of a TestInfo object.
static void OutputJsonTestInfo(::std::ostream* stream, static void OutputJsonTestInfo(::std::ostream* stream,
const char* test_case_name, const char* test_suite_name,
const TestInfo& test_info); const TestInfo& test_info);
// Prints a JSON representation of a TestCase object // Prints a JSON representation of a TestSuite object
static void PrintJsonTestCase(::std::ostream* stream, static void PrintJsonTestSuite(::std::ostream* stream,
const TestCase& test_case); const TestSuite& test_suite);
// Prints a JSON summary of unit_test to output stream out. // Prints a JSON summary of unit_test to output stream out.
static void PrintJsonUnitTest(::std::ostream* stream, static void PrintJsonUnitTest(::std::ostream* stream,
...@@ -4102,36 +4097,38 @@ void JsonUnitTestResultPrinter::OutputJsonKey( ...@@ -4102,36 +4097,38 @@ void JsonUnitTestResultPrinter::OutputJsonKey(
// Prints a JSON representation of a TestInfo object. // Prints a JSON representation of a TestInfo object.
void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
const char* test_case_name, const char* test_suite_name,
const TestInfo& test_info) { const TestInfo& test_info) {
const TestResult& result = *test_info.result(); const TestResult& result = *test_info.result();
const std::string kTestcase = "testcase"; const std::string kTestsuite = "testcase";
const std::string kIndent = Indent(10); const std::string kIndent = Indent(10);
*stream << Indent(8) << "{\n"; *stream << Indent(8) << "{\n";
OutputJsonKey(stream, kTestcase, "name", test_info.name(), kIndent); OutputJsonKey(stream, kTestsuite, "name", test_info.name(), kIndent);
if (test_info.value_param() != nullptr) { if (test_info.value_param() != nullptr) {
OutputJsonKey(stream, kTestcase, "value_param", OutputJsonKey(stream, kTestsuite, "value_param", test_info.value_param(),
test_info.value_param(), kIndent); kIndent);
} }
if (test_info.type_param() != nullptr) { if (test_info.type_param() != nullptr) {
OutputJsonKey(stream, kTestcase, "type_param", test_info.type_param(), OutputJsonKey(stream, kTestsuite, "type_param", test_info.type_param(),
kIndent); kIndent);
} }
if (GTEST_FLAG(list_tests)) { if (GTEST_FLAG(list_tests)) {
OutputJsonKey(stream, kTestcase, "file", test_info.file(), kIndent); OutputJsonKey(stream, kTestsuite, "file", test_info.file(), kIndent);
OutputJsonKey(stream, kTestcase, "line", test_info.line(), kIndent, false); OutputJsonKey(stream, kTestsuite, "line", test_info.line(), kIndent, false);
*stream << "\n" << Indent(8) << "}"; *stream << "\n" << Indent(8) << "}";
return; return;
} }
OutputJsonKey(stream, kTestcase, "status", OutputJsonKey(
result.Skipped() ? "SKIPPED" : stream, kTestsuite, "status",
test_info.should_run() ? "RUN" : "NOTRUN", kIndent); result.Skipped() ? "SKIPPED" : test_info.should_run() ? "RUN" : "NOTRUN",
OutputJsonKey(stream, kTestcase, "time", kIndent);
OutputJsonKey(stream, kTestsuite, "time",
FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent); FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
OutputJsonKey(stream, kTestcase, "classname", test_case_name, kIndent, false); OutputJsonKey(stream, kTestsuite, "classname", test_suite_name, kIndent,
false);
*stream << TestPropertiesAsJson(result, kIndent); *stream << TestPropertiesAsJson(result, kIndent);
int failures = 0; int failures = 0;
...@@ -4158,40 +4155,40 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, ...@@ -4158,40 +4155,40 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
*stream << "\n" << Indent(8) << "}"; *stream << "\n" << Indent(8) << "}";
} }
// Prints an JSON representation of a TestCase object // Prints an JSON representation of a TestSuite object
void JsonUnitTestResultPrinter::PrintJsonTestCase(std::ostream* stream, void JsonUnitTestResultPrinter::PrintJsonTestSuite(
const TestCase& test_case) { std::ostream* stream, const TestSuite& test_suite) {
const std::string kTestsuite = "testsuite"; const std::string kTestsuite = "testsuite";
const std::string kIndent = Indent(6); const std::string kIndent = Indent(6);
*stream << Indent(4) << "{\n"; *stream << Indent(4) << "{\n";
OutputJsonKey(stream, kTestsuite, "name", test_case.name(), kIndent); OutputJsonKey(stream, kTestsuite, "name", test_suite.name(), kIndent);
OutputJsonKey(stream, kTestsuite, "tests", test_case.reportable_test_count(), OutputJsonKey(stream, kTestsuite, "tests", test_suite.reportable_test_count(),
kIndent); kIndent);
if (!GTEST_FLAG(list_tests)) { if (!GTEST_FLAG(list_tests)) {
OutputJsonKey(stream, kTestsuite, "failures", test_case.failed_test_count(), OutputJsonKey(stream, kTestsuite, "failures",
kIndent); test_suite.failed_test_count(), kIndent);
OutputJsonKey(stream, kTestsuite, "disabled", OutputJsonKey(stream, kTestsuite, "disabled",
test_case.reportable_disabled_test_count(), kIndent); test_suite.reportable_disabled_test_count(), kIndent);
OutputJsonKey(stream, kTestsuite, "errors", 0, kIndent); OutputJsonKey(stream, kTestsuite, "errors", 0, kIndent);
OutputJsonKey(stream, kTestsuite, "time", OutputJsonKey(stream, kTestsuite, "time",
FormatTimeInMillisAsDuration(test_case.elapsed_time()), FormatTimeInMillisAsDuration(test_suite.elapsed_time()),
kIndent, false); kIndent, false);
*stream << TestPropertiesAsJson(test_case.ad_hoc_test_result(), kIndent) *stream << TestPropertiesAsJson(test_suite.ad_hoc_test_result(), kIndent)
<< ",\n"; << ",\n";
} }
*stream << kIndent << "\"" << kTestsuite << "\": [\n"; *stream << kIndent << "\"" << kTestsuite << "\": [\n";
bool comma = false; bool comma = false;
for (int i = 0; i < test_case.total_test_count(); ++i) { for (int i = 0; i < test_suite.total_test_count(); ++i) {
if (test_case.GetTestInfo(i)->is_reportable()) { if (test_suite.GetTestInfo(i)->is_reportable()) {
if (comma) { if (comma) {
*stream << ",\n"; *stream << ",\n";
} else { } else {
comma = true; comma = true;
} }
OutputJsonTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i)); OutputJsonTestInfo(stream, test_suite.name(), *test_suite.GetTestInfo(i));
} }
} }
*stream << "\n" << kIndent << "]\n" << Indent(4) << "}"; *stream << "\n" << kIndent << "]\n" << Indent(4) << "}";
...@@ -4229,14 +4226,14 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, ...@@ -4229,14 +4226,14 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
*stream << kIndent << "\"" << kTestsuites << "\": [\n"; *stream << kIndent << "\"" << kTestsuites << "\": [\n";
bool comma = false; bool comma = false;
for (int i = 0; i < unit_test.total_test_case_count(); ++i) { for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
if (unit_test.GetTestCase(i)->reportable_test_count() > 0) { if (unit_test.GetTestSuite(i)->reportable_test_count() > 0) {
if (comma) { if (comma) {
*stream << ",\n"; *stream << ",\n";
} else { } else {
comma = true; comma = true;
} }
PrintJsonTestCase(stream, *unit_test.GetTestCase(i)); PrintJsonTestSuite(stream, *unit_test.GetTestSuite(i));
} }
} }
...@@ -4244,24 +4241,24 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream, ...@@ -4244,24 +4241,24 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
} }
void JsonUnitTestResultPrinter::PrintJsonTestList( void JsonUnitTestResultPrinter::PrintJsonTestList(
std::ostream* stream, const std::vector<TestCase*>& test_cases) { std::ostream* stream, const std::vector<TestSuite*>& test_suites) {
const std::string kTestsuites = "testsuites"; const std::string kTestsuites = "testsuites";
const std::string kIndent = Indent(2); const std::string kIndent = Indent(2);
*stream << "{\n"; *stream << "{\n";
int total_tests = 0; int total_tests = 0;
for (size_t i = 0; i < test_cases.size(); ++i) { for (auto test_suite : test_suites) {
total_tests += test_cases[i]->total_test_count(); total_tests += test_suite->total_test_count();
} }
OutputJsonKey(stream, kTestsuites, "tests", total_tests, kIndent); OutputJsonKey(stream, kTestsuites, "tests", total_tests, kIndent);
OutputJsonKey(stream, kTestsuites, "name", "AllTests", kIndent); OutputJsonKey(stream, kTestsuites, "name", "AllTests", kIndent);
*stream << kIndent << "\"" << kTestsuites << "\": [\n"; *stream << kIndent << "\"" << kTestsuites << "\": [\n";
for (size_t i = 0; i < test_cases.size(); ++i) { for (size_t i = 0; i < test_suites.size(); ++i) {
if (i != 0) { if (i != 0) {
*stream << ",\n"; *stream << ",\n";
} }
PrintJsonTestCase(stream, *test_cases[i]); PrintJsonTestSuite(stream, *test_suites[i]);
} }
*stream << "\n" *stream << "\n"
...@@ -4552,26 +4549,42 @@ UnitTest* UnitTest::GetInstance() { ...@@ -4552,26 +4549,42 @@ UnitTest* UnitTest::GetInstance() {
#endif // defined(__BORLANDC__) #endif // defined(__BORLANDC__)
} }
// Gets the number of successful test cases. // Gets the number of successful test suites.
int UnitTest::successful_test_case_count() const { int UnitTest::successful_test_suite_count() const {
return impl()->successful_test_case_count(); return impl()->successful_test_suite_count();
} }
// Gets the number of failed test cases. // Gets the number of failed test suites.
int UnitTest::failed_test_case_count() const { int UnitTest::failed_test_suite_count() const {
return impl()->failed_test_case_count(); return impl()->failed_test_suite_count();
} }
// Gets the number of all test cases. // Gets the number of all test suites.
int UnitTest::total_test_case_count() const { int UnitTest::total_test_suite_count() const {
return impl()->total_test_case_count(); return impl()->total_test_suite_count();
} }
// 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 UnitTest::test_suite_to_run_count() const {
return impl()->test_suite_to_run_count();
}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
int UnitTest::successful_test_case_count() const {
return impl()->successful_test_suite_count();
}
int UnitTest::failed_test_case_count() const {
return impl()->failed_test_suite_count();
}
int UnitTest::total_test_case_count() const {
return impl()->total_test_suite_count();
}
int UnitTest::test_case_to_run_count() const { int UnitTest::test_case_to_run_count() const {
return impl()->test_case_to_run_count(); return impl()->test_suite_to_run_count();
} }
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// Gets the number of successful tests. // Gets the number of successful tests.
int UnitTest::successful_test_count() const { int UnitTest::successful_test_count() const {
...@@ -4618,29 +4631,36 @@ internal::TimeInMillis UnitTest::elapsed_time() const { ...@@ -4618,29 +4631,36 @@ internal::TimeInMillis UnitTest::elapsed_time() const {
return impl()->elapsed_time(); return impl()->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 UnitTest::Passed() const { return impl()->Passed(); } bool UnitTest::Passed() const { return impl()->Passed(); }
// 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 UnitTest::Failed() const { return impl()->Failed(); } bool UnitTest::Failed() const { return impl()->Failed(); }
// Gets the i-th test case among all the test cases. i can range from 0 to // 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* UnitTest::GetTestSuite(int i) const {
return impl()->GetTestSuite(i);
}
// Legacy API is deprecated but still available
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const TestCase* UnitTest::GetTestCase(int i) const { const TestCase* UnitTest::GetTestCase(int i) const {
return impl()->GetTestCase(i); return impl()->GetTestCase(i);
} }
#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& UnitTest::ad_hoc_test_result() const { const TestResult& UnitTest::ad_hoc_test_result() const {
return *impl()->ad_hoc_test_result(); return *impl()->ad_hoc_test_result();
} }
// 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* UnitTest::GetMutableTestCase(int i) { TestSuite* UnitTest::GetMutableTestSuite(int i) {
return impl()->GetMutableTestCase(i); return impl()->GetMutableSuiteCase(i);
} }
// 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
...@@ -4723,8 +4743,7 @@ void UnitTest::AddTestPartResult( ...@@ -4723,8 +4743,7 @@ void UnitTest::AddTestPartResult(
#else #else
// Dereference nullptr through a volatile pointer to prevent the compiler // Dereference nullptr through a volatile pointer to prevent the compiler
// from removing. We use this rather than abort() or __builtin_trap() for // from removing. We use this rather than abort() or __builtin_trap() for
// portability: Symbian doesn't implement abort() well, and some debuggers // portability: some debuggers don't correctly trap abort().
// don't correctly trap abort().
*static_cast<volatile int*>(nullptr) = 1; *static_cast<volatile int*>(nullptr) = 1;
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} else if (GTEST_FLAG(throw_on_failure)) { } else if (GTEST_FLAG(throw_on_failure)) {
...@@ -4740,8 +4759,8 @@ void UnitTest::AddTestPartResult( ...@@ -4740,8 +4759,8 @@ void UnitTest::AddTestPartResult(
} }
// 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 UnitTest::RecordProperty(const std::string& key, void UnitTest::RecordProperty(const std::string& key,
...@@ -4833,13 +4852,22 @@ const char* UnitTest::original_working_dir() const { ...@@ -4833,13 +4852,22 @@ const char* UnitTest::original_working_dir() const {
return impl_->original_working_dir_.c_str(); return impl_->original_working_dir_.c_str();
} }
// 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 TestSuite* UnitTest::current_test_suite() const
GTEST_LOCK_EXCLUDED_(mutex_) {
internal::MutexLock lock(&mutex_);
return impl_->current_test_suite();
}
// Legacy API is still available but deprecated
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
const TestCase* UnitTest::current_test_case() const const TestCase* UnitTest::current_test_case() const
GTEST_LOCK_EXCLUDED_(mutex_) { GTEST_LOCK_EXCLUDED_(mutex_) {
internal::MutexLock lock(&mutex_); internal::MutexLock lock(&mutex_);
return impl_->current_test_case(); return impl_->current_test_suite();
} }
#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.
...@@ -4852,11 +4880,10 @@ const TestInfo* UnitTest::current_test_info() const ...@@ -4852,11 +4880,10 @@ const TestInfo* UnitTest::current_test_info() const
// 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 UnitTest::random_seed() const { return impl_->random_seed(); } int UnitTest::random_seed() const { return impl_->random_seed(); }
// 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& internal::ParameterizedTestSuiteRegistry&
UnitTest::parameterized_test_registry() UnitTest::parameterized_test_registry() GTEST_LOCK_EXCLUDED_(mutex_) {
GTEST_LOCK_EXCLUDED_(mutex_) {
return impl_->parameterized_test_registry(); return impl_->parameterized_test_registry();
} }
...@@ -4898,8 +4925,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent) ...@@ -4898,8 +4925,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
&default_per_thread_test_part_result_reporter_), &default_per_thread_test_part_result_reporter_),
parameterized_test_registry_(), parameterized_test_registry_(),
parameterized_tests_registered_(false), parameterized_tests_registered_(false),
last_death_test_case_(-1), last_death_test_suite_(-1),
current_test_case_(nullptr), current_test_suite_(nullptr),
current_test_info_(nullptr), current_test_info_(nullptr),
ad_hoc_test_result_(), ad_hoc_test_result_(),
os_stack_trace_getter_(nullptr), os_stack_trace_getter_(nullptr),
...@@ -4917,8 +4944,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent) ...@@ -4917,8 +4944,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
} }
UnitTestImpl::~UnitTestImpl() { UnitTestImpl::~UnitTestImpl() {
// Deletes every TestCase. // Deletes every TestSuite.
ForEach(test_cases_, internal::Delete<TestCase>); ForEach(test_suites_, internal::Delete<TestSuite>);
// Deletes every Environment. // Deletes every Environment.
ForEach(environments_, internal::Delete<Environment>); ForEach(environments_, internal::Delete<Environment>);
...@@ -4927,8 +4954,8 @@ UnitTestImpl::~UnitTestImpl() { ...@@ -4927,8 +4954,8 @@ UnitTestImpl::~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, to current test case's ad_hoc_test_result when invoke // context of a test, to current test suite's ad_hoc_test_result when invoke
// from SetUpTestCase/TearDownTestCase, or to the global property set // from SetUpTestSuite/TearDownTestSuite, or to the global property set
// otherwise. If the result already contains a property with the same key, // otherwise. If the result already contains a property with the same key,
// the value will be updated. // the value will be updated.
void UnitTestImpl::RecordProperty(const TestProperty& test_property) { void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
...@@ -4938,9 +4965,9 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) { ...@@ -4938,9 +4965,9 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
if (current_test_info_ != nullptr) { if (current_test_info_ != nullptr) {
xml_element = "testcase"; xml_element = "testcase";
test_result = &(current_test_info_->result_); test_result = &(current_test_info_->result_);
} else if (current_test_case_ != nullptr) { } else if (current_test_suite_ != nullptr) {
xml_element = "testsuite"; xml_element = "testsuite";
test_result = &(current_test_case_->ad_hoc_test_result_); test_result = &(current_test_suite_->ad_hoc_test_result_);
} else { } else {
xml_element = "testsuites"; xml_element = "testsuites";
test_result = &ad_hoc_test_result_; test_result = &ad_hoc_test_result_;
...@@ -5034,75 +5061,73 @@ void UnitTestImpl::PostFlagParsingInit() { ...@@ -5034,75 +5061,73 @@ void UnitTestImpl::PostFlagParsingInit() {
} }
} }
// A predicate that checks the name of a TestCase against a known // A predicate that checks the name of a TestSuite against a known
// value. // value.
// //
// This is used for implementation of the UnitTest class only. We put // This is used for implementation of the UnitTest class only. We put
// it in the anonymous namespace to prevent polluting the outer // it in the anonymous namespace to prevent polluting the outer
// namespace. // namespace.
// //
// TestCaseNameIs is copyable. // TestSuiteNameIs is copyable.
class TestCaseNameIs { class TestSuiteNameIs {
public: public:
// Constructor. // Constructor.
explicit TestCaseNameIs(const std::string& name) explicit TestSuiteNameIs(const std::string& name) : name_(name) {}
: name_(name) {}
// Returns true iff the name of test_case matches name_. // Returns true iff the name of test_suite matches name_.
bool operator()(const TestCase* test_case) const { bool operator()(const TestSuite* test_suite) const {
return test_case != nullptr && return test_suite != nullptr &&
strcmp(test_case->name(), name_.c_str()) == 0; strcmp(test_suite->name(), name_.c_str()) == 0;
} }
private: private:
std::string name_; std::string name_;
}; };
// 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. It's the CALLER'S // exist, creates one and returns it. It's the CALLER'S
// RESPONSIBILITY to ensure that this function is only called WHEN THE // RESPONSIBILITY to ensure that this function is only called WHEN THE
// TESTS ARE NOT SHUFFLED. // TESTS ARE NOT SHUFFLED.
// //
// 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 case's type parameter, or NULL if // type_param: the name of the test suite's type parameter, or NULL if
// this is not a typed or a type-parameterized test case. // this is not a typed or a type-parameterized test suite.
// 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* UnitTestImpl::GetTestCase(const char* test_case_name, TestSuite* UnitTestImpl::GetTestSuite(
const char* type_param, const char* test_suite_name, const char* type_param,
Test::SetUpTestCaseFunc set_up_tc, internal::SetUpTestSuiteFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc) { internal::TearDownTestSuiteFunc tear_down_tc) {
// Can we find a TestCase with the given name? // Can we find a TestSuite with the given name?
const std::vector<TestCase*>::const_reverse_iterator test_case = const auto test_suite =
std::find_if(test_cases_.rbegin(), test_cases_.rend(), std::find_if(test_suites_.rbegin(), test_suites_.rend(),
TestCaseNameIs(test_case_name)); TestSuiteNameIs(test_suite_name));
if (test_case != test_cases_.rend()) if (test_suite != test_suites_.rend()) return *test_suite;
return *test_case;
// No. Let's create one. // No. Let's create one.
TestCase* const new_test_case = auto* const new_test_suite =
new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc); new TestSuite(test_suite_name, type_param, set_up_tc, tear_down_tc);
// Is this a death test case? // Is this a death test suite?
if (internal::UnitTestOptions::MatchesFilter(test_case_name, if (internal::UnitTestOptions::MatchesFilter(test_suite_name,
kDeathTestCaseFilter)) { kDeathTestSuiteFilter)) {
// Yes. Inserts the test case after the last death test case // Yes. Inserts the test suite after the last death test suite
// defined so far. This only works when the test cases haven't // defined so far. This only works when the test suites haven't
// been shuffled. Otherwise we may end up running a death test // been shuffled. Otherwise we may end up running a death test
// after a non-death test. // after a non-death test.
++last_death_test_case_; ++last_death_test_suite_;
test_cases_.insert(test_cases_.begin() + last_death_test_case_, test_suites_.insert(test_suites_.begin() + last_death_test_suite_,
new_test_case); new_test_suite);
} else { } else {
// No. Appends to the end of the list. // No. Appends to the end of the list.
test_cases_.push_back(new_test_case); test_suites_.push_back(new_test_suite);
} }
test_case_indices_.push_back(static_cast<int>(test_case_indices_.size())); test_suite_indices_.push_back(static_cast<int>(test_suite_indices_.size()));
return new_test_case; return new_test_suite;
} }
// Helpers for setting up / tearing down the given environment. They // Helpers for setting up / tearing down the given environment. They
...@@ -5189,7 +5214,7 @@ bool UnitTestImpl::RunAllTests() { ...@@ -5189,7 +5214,7 @@ bool UnitTestImpl::RunAllTests() {
const TimeInMillis start = GetTimeInMillis(); const TimeInMillis start = GetTimeInMillis();
// Shuffles test cases and tests if requested. // Shuffles test suites and tests if requested.
if (has_tests_to_run && GTEST_FLAG(shuffle)) { if (has_tests_to_run && GTEST_FLAG(shuffle)) {
random()->Reseed(random_seed_); random()->Reseed(random_seed_);
// This should be done before calling OnTestIterationStart(), // This should be done before calling OnTestIterationStart(),
...@@ -5201,7 +5226,7 @@ bool UnitTestImpl::RunAllTests() { ...@@ -5201,7 +5226,7 @@ bool UnitTestImpl::RunAllTests() {
// Tells the unit test event listeners that the tests are about to start. // Tells the unit test event listeners that the tests are about to start.
repeater->OnTestIterationStart(*parent_, i); repeater->OnTestIterationStart(*parent_, i);
// Runs each test case if there is at least one test to run. // Runs each test suite if there is at least one test to run.
if (has_tests_to_run) { if (has_tests_to_run) {
// Sets up all environments beforehand. // Sets up all environments beforehand.
repeater->OnEnvironmentsSetUpStart(*parent_); repeater->OnEnvironmentsSetUpStart(*parent_);
...@@ -5211,9 +5236,9 @@ bool UnitTestImpl::RunAllTests() { ...@@ -5211,9 +5236,9 @@ bool UnitTestImpl::RunAllTests() {
// Runs the tests only if there was no fatal failure during global // Runs the tests only if there was no fatal failure during global
// set-up. // set-up.
if (!Test::HasFatalFailure()) { if (!Test::HasFatalFailure()) {
for (int test_index = 0; test_index < total_test_case_count(); for (int test_index = 0; test_index < total_test_suite_count();
test_index++) { test_index++) {
GetMutableTestCase(test_index)->Run(); GetMutableSuiteCase(test_index)->Run();
} }
} }
...@@ -5362,7 +5387,7 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { ...@@ -5362,7 +5387,7 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {
// Compares the name of each test with the user-specified filter to // Compares the name of each test with the user-specified filter to
// decide whether the test should be run, then records the result in // decide whether the test should be run, then records the result in
// each TestCase and TestInfo object. // each TestSuite and TestInfo object.
// If shard_tests == true, further filters tests based on sharding // If shard_tests == true, further filters tests based on sharding
// variables in the environment - see // variables in the environment - see
// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md // https://github.com/google/googletest/blob/master/googletest/docs/advanced.md
...@@ -5379,26 +5404,23 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { ...@@ -5379,26 +5404,23 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
// this shard. // this shard.
int num_runnable_tests = 0; int num_runnable_tests = 0;
int num_selected_tests = 0; int num_selected_tests = 0;
for (size_t i = 0; i < test_cases_.size(); i++) { for (auto* test_suite : test_suites_) {
TestCase* const test_case = test_cases_[i]; const std::string& test_suite_name = test_suite->name();
const std::string &test_case_name = test_case->name(); test_suite->set_should_run(false);
test_case->set_should_run(false);
for (size_t j = 0; j < test_case->test_info_list().size(); j++) { for (size_t j = 0; j < test_suite->test_info_list().size(); j++) {
TestInfo* const test_info = test_case->test_info_list()[j]; TestInfo* const test_info = test_suite->test_info_list()[j];
const std::string test_name(test_info->name()); const std::string test_name(test_info->name());
// A test is disabled if test case name or test name matches // A test is disabled if test suite name or test name matches
// kDisableTestFilter. // kDisableTestFilter.
const bool is_disabled = const bool is_disabled = internal::UnitTestOptions::MatchesFilter(
internal::UnitTestOptions::MatchesFilter(test_case_name, test_suite_name, kDisableTestFilter) ||
kDisableTestFilter) || internal::UnitTestOptions::MatchesFilter(
internal::UnitTestOptions::MatchesFilter(test_name, test_name, kDisableTestFilter);
kDisableTestFilter);
test_info->is_disabled_ = is_disabled; test_info->is_disabled_ = is_disabled;
const bool matches_filter = const bool matches_filter = internal::UnitTestOptions::FilterMatchesTest(
internal::UnitTestOptions::FilterMatchesTest(test_case_name, test_suite_name, test_name);
test_name);
test_info->matches_filter_ = matches_filter; test_info->matches_filter_ = matches_filter;
const bool is_runnable = const bool is_runnable =
...@@ -5415,7 +5437,7 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { ...@@ -5415,7 +5437,7 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
num_selected_tests += is_selected; num_selected_tests += is_selected;
test_info->should_run_ = is_selected; test_info->should_run_ = is_selected;
test_case->set_should_run(test_case->should_run() || is_selected); test_suite->set_should_run(test_suite->should_run() || is_selected);
} }
} }
return num_selected_tests; return num_selected_tests;
...@@ -5448,22 +5470,20 @@ void UnitTestImpl::ListTestsMatchingFilter() { ...@@ -5448,22 +5470,20 @@ void UnitTestImpl::ListTestsMatchingFilter() {
// Print at most this many characters for each type/value parameter. // Print at most this many characters for each type/value parameter.
const int kMaxParamLength = 250; const int kMaxParamLength = 250;
for (size_t i = 0; i < test_cases_.size(); i++) { for (auto* test_suite : test_suites_) {
const TestCase* const test_case = test_cases_[i]; bool printed_test_suite_name = false;
bool printed_test_case_name = false;
for (size_t j = 0; j < test_case->test_info_list().size(); j++) { for (size_t j = 0; j < test_suite->test_info_list().size(); j++) {
const TestInfo* const test_info = const TestInfo* const test_info = test_suite->test_info_list()[j];
test_case->test_info_list()[j];
if (test_info->matches_filter_) { if (test_info->matches_filter_) {
if (!printed_test_case_name) { if (!printed_test_suite_name) {
printed_test_case_name = true; printed_test_suite_name = true;
printf("%s.", test_case->name()); printf("%s.", test_suite->name());
if (test_case->type_param() != nullptr) { if (test_suite->type_param() != nullptr) {
printf(" # %s = ", kTypeParamLabel); printf(" # %s = ", kTypeParamLabel);
// We print the type parameter on a single line to make // We print the type parameter on a single line to make
// the output easy to parse by a program. // the output easy to parse by a program.
PrintOnOneLine(test_case->type_param(), kMaxParamLength); PrintOnOneLine(test_suite->type_param(), kMaxParamLength);
} }
printf("\n"); printf("\n");
} }
...@@ -5487,11 +5507,11 @@ void UnitTestImpl::ListTestsMatchingFilter() { ...@@ -5487,11 +5507,11 @@ void UnitTestImpl::ListTestsMatchingFilter() {
if (output_format == "xml") { if (output_format == "xml") {
XmlUnitTestResultPrinter( XmlUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()) UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
.PrintXmlTestsList(&stream, test_cases_); .PrintXmlTestsList(&stream, test_suites_);
} else if (output_format == "json") { } else if (output_format == "json") {
JsonUnitTestResultPrinter( JsonUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()) UnitTestOptions::GetAbsolutePathToOutputFile().c_str())
.PrintJsonTestList(&stream, test_cases_); .PrintJsonTestList(&stream, test_suites_);
} }
fprintf(fileout, "%s", StringStreamToString(&stream).c_str()); fprintf(fileout, "%s", StringStreamToString(&stream).c_str());
fclose(fileout); fclose(fileout);
...@@ -5531,35 +5551,35 @@ TestResult* UnitTestImpl::current_test_result() { ...@@ -5531,35 +5551,35 @@ TestResult* UnitTestImpl::current_test_result() {
if (current_test_info_ != nullptr) { if (current_test_info_ != nullptr) {
return &current_test_info_->result_; return &current_test_info_->result_;
} }
if (current_test_case_ != nullptr) { if (current_test_suite_ != nullptr) {
return &current_test_case_->ad_hoc_test_result_; return &current_test_suite_->ad_hoc_test_result_;
} }
return &ad_hoc_test_result_; return &ad_hoc_test_result_;
} }
// 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 UnitTestImpl::ShuffleTests() { void UnitTestImpl::ShuffleTests() {
// Shuffles the death test cases. // Shuffles the death test suites.
ShuffleRange(random(), 0, last_death_test_case_ + 1, &test_case_indices_); ShuffleRange(random(), 0, last_death_test_suite_ + 1, &test_suite_indices_);
// Shuffles the non-death test cases. // Shuffles the non-death test suites.
ShuffleRange(random(), last_death_test_case_ + 1, ShuffleRange(random(), last_death_test_suite_ + 1,
static_cast<int>(test_cases_.size()), &test_case_indices_); static_cast<int>(test_suites_.size()), &test_suite_indices_);
// Shuffles the tests inside each test case. // Shuffles the tests inside each test suite.
for (size_t i = 0; i < test_cases_.size(); i++) { for (auto& test_suite : test_suites_) {
test_cases_[i]->ShuffleTests(random()); test_suite->ShuffleTests(random());
} }
} }
// 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 UnitTestImpl::UnshuffleTests() { void UnitTestImpl::UnshuffleTests() {
for (size_t i = 0; i < test_cases_.size(); i++) { for (size_t i = 0; i < test_suites_.size(); i++) {
// Unshuffles the tests in each test case. // Unshuffles the tests in each test suite.
test_cases_[i]->UnshuffleTests(); test_suites_[i]->UnshuffleTests();
// Resets the index of each test case. // Resets the index of each test suite.
test_case_indices_[i] = static_cast<int>(i); test_suite_indices_[i] = static_cast<int>(i);
} }
} }
...@@ -5723,8 +5743,6 @@ static bool HasGoogleTestFlagPrefix(const char* str) { ...@@ -5723,8 +5743,6 @@ static bool HasGoogleTestFlagPrefix(const char* str) {
// @Y changes the color to yellow. // @Y changes the color to yellow.
// @D changes to the default terminal text color. // @D changes to the default terminal text color.
// //
// FIXME: Write tests for this once we add stdout
// capturing to Google Test.
static void PrintColorEncoded(const char* str) { static void PrintColorEncoded(const char* str) {
GTestColor color = COLOR_DEFAULT; // The current color. GTestColor color = COLOR_DEFAULT; // The current color.
......
...@@ -278,6 +278,13 @@ cc_binary( ...@@ -278,6 +278,13 @@ cc_binary(
deps = ["//:gtest"], deps = ["//:gtest"],
) )
cc_test(
name = "gtest_skip_test",
size = "small",
srcs = ["gtest_skip_test.cc"],
deps = ["//:gtest_main"],
)
py_test( py_test(
name = "googletest-list-tests-unittest", name = "googletest-list-tests-unittest",
size = "small", size = "small",
......
...@@ -140,8 +140,7 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase): ...@@ -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): ...@@ -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"'
......
...@@ -1281,9 +1281,6 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) { ...@@ -1281,9 +1281,6 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
# if GTEST_OS_WINDOWS # if GTEST_OS_WINDOWS
TEST(EnvironmentTest, HandleFitsIntoSizeT) { TEST(EnvironmentTest, HandleFitsIntoSizeT) {
// FIXME: Remove this test after this condition is verified
// in a static assertion in gtest-death-test.cc in the function
// GetStatusFileDescriptor.
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t)); ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
} }
# endif // GTEST_OS_WINDOWS # endif // GTEST_OS_WINDOWS
......
...@@ -50,8 +50,6 @@ namespace internal { ...@@ -50,8 +50,6 @@ namespace internal {
namespace { namespace {
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
// FIXME: Move these to the POSIX adapter section in
// gtest-port.h.
// Windows CE doesn't have the remove C function. // Windows CE doesn't have the remove C function.
int remove(const char* path) { int remove(const char* path) {
......
...@@ -136,11 +136,6 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase): ...@@ -136,11 +136,6 @@ class GTestJsonOutFilesTest(gtest_test_utils.TestCase):
self.assert_(p.exited) self.assert_(p.exited)
self.assertEquals(0, p.exit_code) self.assertEquals(0, p.exit_code)
# FIXME: libtool causes the built test binary to be
# named lt-gtest_xml_outfiles_test_ instead of
# gtest_xml_outfiles_test_. To account for this possibility, we
# allow both names in the following code. We should remove this
# when libtool replacement tool is ready.
output_file_name1 = test_name + '.json' output_file_name1 = test_name + '.json'
output_file1 = os.path.join(self.output_dir_, output_file_name1) output_file1 = os.path.join(self.output_dir_, output_file_name1)
output_file_name2 = 'lt-' + output_file_name1 output_file_name2 = 'lt-' + output_file_name1
......
...@@ -125,6 +125,78 @@ class EventRecordingListener : public TestEventListener { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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]));
......
...@@ -111,7 +111,6 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) { ...@@ -111,7 +111,6 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
#elif GTEST_OS_FUCHSIA #elif GTEST_OS_FUCHSIA
const bool success = exe_str == "app"; const bool success = exe_str == "app";
#else #else
// FIXME: remove the hard-coded "lt-" prefix when libtool replacement is ready
const bool success = const bool success =
exe_str == "googletest-options-test" || exe_str == "googletest-options-test" ||
exe_str == "gtest_all_test" || exe_str == "gtest_all_test" ||
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment