Commit c214ebc8 by zhanyong.wan

More refactoring for the event listener API, by Vlad Losev.

parent 3a47ddf8
...@@ -292,6 +292,11 @@ check_PROGRAMS += test/gtest_unittest ...@@ -292,6 +292,11 @@ check_PROGRAMS += test/gtest_unittest
test_gtest_unittest_SOURCES = test/gtest_unittest.cc test_gtest_unittest_SOURCES = test/gtest_unittest.cc
test_gtest_unittest_LDADD = lib/libgtest_main.la test_gtest_unittest_LDADD = lib/libgtest_main.la
TESTS += test/gtest-unittest-api_test
check_PROGRAMS += test/gtest-unittest-api_test
test_gtest_unittest_api_test_SOURCES = test/gtest-unittest-api_test.cc
test_gtest_unittest_api_test_LDADD = lib/libgtest_main.la
# Verifies that Google Test works when RTTI is disabled. # Verifies that Google Test works when RTTI is disabled.
TESTS += test/gtest_no_rtti_test TESTS += test/gtest_no_rtti_test
check_PROGRAMS += test/gtest_no_rtti_test check_PROGRAMS += test/gtest_no_rtti_test
......
...@@ -150,9 +150,13 @@ namespace internal { ...@@ -150,9 +150,13 @@ namespace internal {
class AssertHelper; class AssertHelper;
class DefaultGlobalTestPartResultReporter; class DefaultGlobalTestPartResultReporter;
class ExecDeathTest; class ExecDeathTest;
class FinalSuccessChecker;
class GTestFlagSaver; class GTestFlagSaver;
class TestCase; // A collection of related tests. class TestCase;
class TestInfoImpl; class TestInfoImpl;
class TestResultAccessor;
class UnitTestAccessor;
class WindowsDeathTest;
class UnitTestImpl* GetUnitTestImpl(); class UnitTestImpl* GetUnitTestImpl();
void ReportFailureInUnknownLocation(TestPartResultType result_type, void ReportFailureInUnknownLocation(TestPartResultType result_type,
const String& message); const String& message);
...@@ -360,6 +364,8 @@ class Test { ...@@ -360,6 +364,8 @@ class Test {
GTEST_DISALLOW_COPY_AND_ASSIGN_(Test); GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
}; };
typedef internal::TimeInMillis TimeInMillis;
namespace internal { namespace internal {
// A copyable object representing a user specified test property which can be // A copyable object representing a user specified test property which can be
...@@ -392,9 +398,9 @@ class TestProperty { ...@@ -392,9 +398,9 @@ class TestProperty {
private: private:
// The key supplied by the user. // The key supplied by the user.
String key_; internal::String key_;
// The value supplied by the user. // The value supplied by the user.
String value_; internal::String value_;
}; };
// The result of a single Test. This includes a list of // The result of a single Test. This includes a list of
...@@ -411,12 +417,6 @@ class TestResult { ...@@ -411,12 +417,6 @@ class TestResult {
// D'tor. Do not inherit from TestResult. // D'tor. Do not inherit from TestResult.
~TestResult(); ~TestResult();
// Gets the number of successful test parts.
int successful_part_count() const;
// Gets the number of failed test parts.
int failed_part_count() const;
// Gets the number of all test parts. This is the sum of the number // Gets the number of all test parts. This is the sum of the number
// of successful test parts and the number of failed test parts. // of successful test parts and the number of failed test parts.
int total_part_count() const; int total_part_count() const;
...@@ -428,7 +428,7 @@ class TestResult { ...@@ -428,7 +428,7 @@ class TestResult {
bool Passed() const { return !Failed(); } bool Passed() const { return !Failed(); }
// Returns true iff the test failed. // Returns true iff the test failed.
bool Failed() const { return failed_part_count() > 0; } bool Failed() const;
// Returns true iff the test fatally failed. // Returns true iff the test fatally failed.
bool HasFatalFailure() const; bool HasFatalFailure() const;
...@@ -450,12 +450,12 @@ class TestResult { ...@@ -450,12 +450,12 @@ class TestResult {
const TestProperty& GetTestProperty(int i) const; const TestProperty& GetTestProperty(int i) const;
private: private:
friend class DefaultGlobalTestPartResultReporter; friend class internal::DefaultGlobalTestPartResultReporter;
friend class ExecDeathTest; friend class internal::ExecDeathTest;
friend class TestInfoImpl; friend class internal::TestInfoImpl;
friend class TestResultAccessor; friend class internal::TestResultAccessor;
friend class UnitTestImpl; friend class internal::UnitTestImpl;
friend class WindowsDeathTest; friend class internal::WindowsDeathTest;
friend class testing::TestInfo; friend class testing::TestInfo;
friend class testing::UnitTest; friend class testing::UnitTest;
...@@ -465,7 +465,7 @@ class TestResult { ...@@ -465,7 +465,7 @@ class TestResult {
} }
// Gets the vector of TestProperties. // Gets the vector of TestProperties.
const internal::Vector<internal::TestProperty>& test_properties() const { const internal::Vector<TestProperty>& test_properties() const {
return *test_properties_; return *test_properties_;
} }
...@@ -477,12 +477,12 @@ class TestResult { ...@@ -477,12 +477,12 @@ class TestResult {
// key names). If a property is already recorded for the same key, the // key names). If a property is already recorded for the same key, the
// value will be updated, rather than storing multiple values for the same // value will be updated, rather than storing multiple values for the same
// key. // key.
void RecordProperty(const internal::TestProperty& test_property); void RecordProperty(const TestProperty& test_property);
// Adds a failure if the key is a reserved attribute of Google Test // Adds a failure if the key is a reserved attribute of Google Test
// testcase tags. Returns true if the property is valid. // testcase tags. Returns true if the property is valid.
// TODO(russr): Validate attribute names are legal and human readable. // TODO(russr): Validate attribute names are legal and human readable.
static bool ValidateTestProperty(const internal::TestProperty& test_property); static bool ValidateTestProperty(const TestProperty& test_property);
// Adds a test part result to the list. // Adds a test part result to the list.
void AddTestPartResult(const TestPartResult& test_part_result); void AddTestPartResult(const TestPartResult& test_part_result);
...@@ -506,8 +506,7 @@ class TestResult { ...@@ -506,8 +506,7 @@ class TestResult {
// The vector of TestPartResults // The vector of TestPartResults
internal::scoped_ptr<internal::Vector<TestPartResult> > test_part_results_; internal::scoped_ptr<internal::Vector<TestPartResult> > test_part_results_;
// The vector of TestProperties // The vector of TestProperties
internal::scoped_ptr<internal::Vector<internal::TestProperty> > internal::scoped_ptr<internal::Vector<TestProperty> > test_properties_;
test_properties_;
// Running count of death tests. // Running count of death tests.
int death_test_count_; int death_test_count_;
// The elapsed time, in milliseconds. // The elapsed time, in milliseconds.
...@@ -664,7 +663,7 @@ class TestCase { ...@@ -664,7 +663,7 @@ class TestCase {
bool Failed() const { return failed_test_count() > 0; } bool Failed() const { return failed_test_count() > 0; }
// Returns the elapsed time, in milliseconds. // Returns the elapsed time, in milliseconds.
internal::TimeInMillis elapsed_time() const { return elapsed_time_; } TimeInMillis elapsed_time() const { return elapsed_time_; }
// 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.
...@@ -672,7 +671,7 @@ class TestCase { ...@@ -672,7 +671,7 @@ class TestCase {
private: private:
friend class testing::Test; friend class testing::Test;
friend class UnitTestImpl; friend class internal::UnitTestImpl;
// Gets the (mutable) vector of TestInfos in this TestCase. // Gets the (mutable) vector of TestInfos in this TestCase.
internal::Vector<TestInfo*>& test_info_list() { return *test_info_list_; } internal::Vector<TestInfo*>& test_info_list() { return *test_info_list_; }
...@@ -728,7 +727,7 @@ class TestCase { ...@@ -728,7 +727,7 @@ class TestCase {
// True iff any test in this test case should run. // True iff any test in this test case should run.
bool should_run_; bool should_run_;
// Elapsed time, in milliseconds. // Elapsed time, in milliseconds.
internal::TimeInMillis elapsed_time_; TimeInMillis elapsed_time_;
// We disallow copying TestCases. // We disallow copying TestCases.
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase); GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
...@@ -874,7 +873,7 @@ class UnitTest { ...@@ -874,7 +873,7 @@ class UnitTest {
int test_to_run_count() const; int test_to_run_count() const;
// Gets the elapsed time, in milliseconds. // Gets the elapsed time, in milliseconds.
internal::TimeInMillis elapsed_time() const; TimeInMillis elapsed_time() const;
// Returns true iff the unit test passed (i.e. all test cases passed). // Returns true iff the unit test passed (i.e. all test cases passed).
bool Passed() const; bool Passed() const;
...@@ -902,6 +901,11 @@ class UnitTest { ...@@ -902,6 +901,11 @@ class UnitTest {
// TODO(vladl@google.com): Remove these when publishing the new accessors. // TODO(vladl@google.com): Remove these when publishing the new accessors.
friend class PrettyUnitTestResultPrinter; friend class PrettyUnitTestResultPrinter;
friend class XmlUnitTestResultPrinter; friend class XmlUnitTestResultPrinter;
friend class internal::UnitTestAccessor;
friend class FinalSuccessChecker;
FRIEND_TEST(ApiTest, UnitTestImmutableAccessorsWork);
FRIEND_TEST(ApiTest, TestCaseImmutableAccessorsWork);
FRIEND_TEST(ApiTest, DisabledTestCaseAccessorsWork);
// Creates an empty UnitTest. // Creates an empty UnitTest.
......
...@@ -101,20 +101,19 @@ namespace testing { ...@@ -101,20 +101,19 @@ namespace testing {
// Forward declaration of classes. // Forward declaration of classes.
class AssertionResult; // Result of an assertion.
class Message; // Represents a failure message. class Message; // Represents a failure message.
class Test; // Represents a test. class Test; // Represents a test.
class TestPartResult; // Result of a test part.
class TestInfo; // Information about a test. class TestInfo; // Information about a test.
class TestPartResult; // Result of a test part.
class UnitTest; // A collection of test cases. class UnitTest; // A collection of test cases.
class UnitTestEventListenerInterface; // Listens to Google Test events. class UnitTestEventListenerInterface; // Listens to Google Test events.
class AssertionResult; // Result of an assertion.
namespace internal { namespace internal {
struct TraceInfo; // Information about a trace point. struct TraceInfo; // Information about a trace point.
class ScopedTrace; // Implements scoped trace. class ScopedTrace; // Implements scoped trace.
class TestInfoImpl; // Opaque implementation of TestInfo class TestInfoImpl; // Opaque implementation of TestInfo
class TestResult; // Result of a single Test.
class UnitTestImpl; // Opaque implementation of UnitTest class UnitTestImpl; // Opaque implementation of UnitTest
template <typename E> class Vector; // A generic vector. template <typename E> class Vector; // A generic vector.
...@@ -747,9 +746,6 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> { ...@@ -747,9 +746,6 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count);
// Returns the number of failed test parts in the given test result object.
int GetFailedPartCount(const TestResult* result);
// A helper for suppressing warnings on unreachable code in some macros. // A helper for suppressing warnings on unreachable code in some macros.
bool AlwaysTrue(); bool AlwaysTrue();
......
...@@ -98,16 +98,16 @@ KNOWN BUILD DIRECTORIES ...@@ -98,16 +98,16 @@ KNOWN BUILD DIRECTORIES
defines them as follows (the default build directory is the first one defines them as follows (the default build directory is the first one
listed in each group): listed in each group):
On Windows: On Windows:
<gtest root>/scons/build/win-dbg8/scons/ <gtest root>/scons/build/win-dbg8/gtest/scons/
<gtest root>/scons/build/win-opt8/scons/ <gtest root>/scons/build/win-opt8/gtest/scons/
<gtest root>/scons/build/win-dbg/scons/ <gtest root>/scons/build/win-dbg/gtest/scons/
<gtest root>/scons/build/win-opt/scons/ <gtest root>/scons/build/win-opt/gtest/scons/
On Mac: On Mac:
<gtest root>/scons/build/mac-dbg/scons/ <gtest root>/scons/build/mac-dbg/gtest/scons/
<gtest root>/scons/build/mac-opt/scons/ <gtest root>/scons/build/mac-opt/gtest/scons/
On other platforms: On other platforms:
<gtest root>/scons/build/dbg/scons/ <gtest root>/scons/build/dbg/gtest/scons/
<gtest root>/scons/build/opt/scons/ <gtest root>/scons/build/opt/gtest/scons/
AUTHOR AUTHOR
Written by Zhanyong Wan (wan@google.com) Written by Zhanyong Wan (wan@google.com)
...@@ -177,7 +177,8 @@ class TestRunner(object): ...@@ -177,7 +177,8 @@ class TestRunner(object):
"""Returns the build directory for a given configuration.""" """Returns the build directory for a given configuration."""
return self.os.path.normpath( return self.os.path.normpath(
self.os.path.join(self.script_dir, 'scons/build/%s/scons' % config)) self.os.path.join(self.script_dir,
'scons/build/%s/gtest/scons' % config))
def Run(self, args): def Run(self, args):
"""Runs the executable with given args (args[0] is the executable name). """Runs the executable with given args (args[0] is the executable name).
......
...@@ -483,8 +483,8 @@ class TestInfoImpl { ...@@ -483,8 +483,8 @@ class TestInfoImpl {
TypeId fixture_class_id() const { return fixture_class_id_; } TypeId fixture_class_id() const { return fixture_class_id_; }
// Returns the test result. // Returns the test result.
internal::TestResult* result() { return &result_; } TestResult* result() { return &result_; }
const internal::TestResult* result() const { return &result_; } const TestResult* result() const { return &result_; }
// Creates the test object, runs it, records its result, and then // Creates the test object, runs it, records its result, and then
// deletes it. // deletes it.
...@@ -520,7 +520,7 @@ class TestInfoImpl { ...@@ -520,7 +520,7 @@ class TestInfoImpl {
// This field is mutable and needs to be reset before running the // This field is mutable and needs to be reset before running the
// test for the second time. // test for the second time.
internal::TestResult result_; TestResult result_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfoImpl); GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfoImpl);
}; };
...@@ -742,19 +742,17 @@ class UnitTestImpl { ...@@ -742,19 +742,17 @@ class UnitTestImpl {
// Returns the TestResult for the test that's currently running, or // Returns the TestResult for the test that's currently running, or
// the TestResult for the ad hoc test if no test is running. // the TestResult for the ad hoc test if no test is running.
internal::TestResult* current_test_result(); TestResult* current_test_result();
// Returns the TestResult for the ad hoc test. // Returns the TestResult for the ad hoc test.
const internal::TestResult* ad_hoc_test_result() const { const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
return &ad_hoc_test_result_;
}
// Sets the unit test result printer. // Sets the unit test result printer.
// //
// Does nothing if the input and the current printer object are the // Does nothing if the input and the current printer object are the
// same; otherwise, deletes the old printer object and makes the // same; otherwise, deletes the old printer object and makes the
// input the current printer. // input the current printer.
void set_result_printer(UnitTestEventListenerInterface * result_printer); void set_result_printer(UnitTestEventListenerInterface* result_printer);
// Returns the current unit test result printer if it is not NULL; // Returns the current unit test result printer if it is not NULL;
// otherwise, creates an appropriate result printer, makes it the // otherwise, creates an appropriate result printer, makes it the
...@@ -991,7 +989,7 @@ class UnitTestImpl { ...@@ -991,7 +989,7 @@ class UnitTestImpl {
// If an assertion is encountered when no TEST or TEST_F is running, // If an assertion is encountered when no TEST or TEST_F is running,
// Google Test attributes the assertion result to an imaginary "ad hoc" // Google Test attributes the assertion result to an imaginary "ad hoc"
// test, and records the result in ad_hoc_test_result_. // test, and records the result in ad_hoc_test_result_.
internal::TestResult ad_hoc_test_result_; TestResult ad_hoc_test_result_;
// The unit test result printer. Will be deleted when the UnitTest // The unit test result printer. Will be deleted when the UnitTest
// object is destructed. By default, a plain text printer is used, // object is destructed. By default, a plain text printer is used,
...@@ -1122,6 +1120,28 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) { ...@@ -1122,6 +1120,28 @@ bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
} }
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
// TestResult contains some private methods that should be hidden from
// Google Test user but are required for testing. This class allow our tests
// to access them.
class TestResultAccessor {
public:
static void RecordProperty(TestResult* test_result,
const TestProperty& property) {
test_result->RecordProperty(property);
}
static bool Passed(const TestResult& result) { return result.Passed(); }
static void ClearTestPartResults(TestResult* test_result) {
test_result->ClearTestPartResults();
}
static const Vector<testing::TestPartResult>& test_part_results(
const TestResult& test_result) {
return test_result.test_part_results();
}
};
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
......
...@@ -130,6 +130,8 @@ ...@@ -130,6 +130,8 @@
namespace testing { namespace testing {
using internal::TestCase; using internal::TestCase;
using internal::TestProperty;
using internal::TestResult;
// Constants. // Constants.
...@@ -1831,8 +1833,8 @@ String AppendUserMessage(const String& gtest_msg, ...@@ -1831,8 +1833,8 @@ String AppendUserMessage(const String& gtest_msg,
// Creates an empty TestResult. // Creates an empty TestResult.
TestResult::TestResult() TestResult::TestResult()
: test_part_results_(new Vector<TestPartResult>), : test_part_results_(new internal::Vector<TestPartResult>),
test_properties_(new Vector<TestProperty>), test_properties_(new internal::Vector<TestProperty>),
death_test_count_(0), death_test_count_(0),
elapsed_time_(0) { elapsed_time_(0) {
} }
...@@ -1872,9 +1874,10 @@ void TestResult::RecordProperty(const TestProperty& test_property) { ...@@ -1872,9 +1874,10 @@ void TestResult::RecordProperty(const TestProperty& test_property) {
if (!ValidateTestProperty(test_property)) { if (!ValidateTestProperty(test_property)) {
return; return;
} }
MutexLock lock(&test_properites_mutex_); internal::MutexLock lock(&test_properites_mutex_);
TestProperty* const property_with_matching_key = TestProperty* const property_with_matching_key =
test_properties_->FindIf(TestPropertyKeyIs(test_property.key())); test_properties_->FindIf(
internal::TestPropertyKeyIs(test_property.key()));
if (property_with_matching_key == NULL) { if (property_with_matching_key == NULL) {
test_properties_->PushBack(test_property); test_properties_->PushBack(test_property);
return; return;
...@@ -1885,7 +1888,7 @@ void TestResult::RecordProperty(const TestProperty& test_property) { ...@@ -1885,7 +1888,7 @@ void TestResult::RecordProperty(const TestProperty& test_property) {
// Adds a failure if the key is a reserved attribute of Google Test // Adds a failure if the key is a reserved attribute of Google Test
// testcase tags. Returns true if the property is valid. // testcase tags. Returns true if the property is valid.
bool TestResult::ValidateTestProperty(const TestProperty& test_property) { bool TestResult::ValidateTestProperty(const TestProperty& test_property) {
String key(test_property.key()); internal::String key(test_property.key());
if (key == "name" || key == "status" || key == "time" || key == "classname") { if (key == "name" || key == "status" || key == "time" || key == "classname") {
ADD_FAILURE() ADD_FAILURE()
<< "Reserved key used in RecordProperty(): " << "Reserved key used in RecordProperty(): "
...@@ -1905,24 +1908,13 @@ void TestResult::Clear() { ...@@ -1905,24 +1908,13 @@ void TestResult::Clear() {
elapsed_time_ = 0; elapsed_time_ = 0;
} }
// Returns true iff the test part passed. // Returns true iff the test failed.
static bool TestPartPassed(const TestPartResult & result) { bool TestResult::Failed() const {
return result.passed(); for (int i = 0; i < total_part_count(); ++i) {
} if (GetTestPartResult(i).failed())
return true;
// Gets the number of successful test parts. }
int TestResult::successful_part_count() const { return false;
return test_part_results_->CountIf(TestPartPassed);
}
// Returns true iff the test part failed.
static bool TestPartFailed(const TestPartResult & result) {
return result.failed();
}
// Gets the number of failed test parts.
int TestResult::failed_part_count() const {
return test_part_results_->CountIf(TestPartFailed);
} }
// Returns true iff the test part fatally failed. // Returns true iff the test part fatally failed.
...@@ -2264,7 +2256,7 @@ bool TestInfo::should_run() const { return impl_->should_run(); } ...@@ -2264,7 +2256,7 @@ bool TestInfo::should_run() const { return impl_->should_run(); }
bool TestInfo::matches_filter() const { return impl_->matches_filter(); } bool TestInfo::matches_filter() const { return impl_->matches_filter(); }
// Returns the result of the test. // Returns the result of the test.
const internal::TestResult* TestInfo::result() const { return impl_->result(); } const TestResult* TestInfo::result() const { return impl_->result(); }
// Increments the number of death tests encountered in this test so // Increments the number of death tests encountered in this test so
// far. // far.
...@@ -3021,7 +3013,7 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener { ...@@ -3021,7 +3013,7 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
// When the String is not empty, it includes a space at the beginning, // When the String is not empty, it includes a space at the beginning,
// to delimit this attribute from prior attributes. // to delimit this attribute from prior attributes.
static internal::String TestPropertiesAsXmlAttributes( static internal::String TestPropertiesAsXmlAttributes(
const internal::TestResult& result); const TestResult& result);
// The output file. // The output file.
const internal::String output_file_; const internal::String output_file_;
...@@ -3160,7 +3152,7 @@ const char* FormatTimeInMillisAsSeconds(TimeInMillis ms) { ...@@ -3160,7 +3152,7 @@ const char* FormatTimeInMillisAsSeconds(TimeInMillis ms) {
void XmlUnitTestResultPrinter::PrintXmlTestInfo(FILE* out, void XmlUnitTestResultPrinter::PrintXmlTestInfo(FILE* out,
const char* test_case_name, const char* test_case_name,
const TestInfo& test_info) { const TestInfo& test_info) {
const internal::TestResult& result = *test_info.result(); const TestResult& result = *test_info.result();
fprintf(out, fprintf(out,
" <testcase name=\"%s\" status=\"%s\" time=\"%s\" " " <testcase name=\"%s\" status=\"%s\" time=\"%s\" "
"classname=\"%s\"%s", "classname=\"%s\"%s",
...@@ -3233,8 +3225,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out, ...@@ -3233,8 +3225,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
// Produces a string representing the test properties in a result as space // Produces a string representing the test properties in a result as space
// delimited XML attributes based on the property key="value" pairs. // delimited XML attributes based on the property key="value" pairs.
internal::String XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( internal::String XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
const internal::TestResult& result) { const TestResult& result) {
using internal::TestProperty;
Message attributes; Message attributes;
for (int i = 0; i < result.test_property_count(); ++i) { for (int i = 0; i < result.test_property_count(); ++i) {
const TestProperty& property = result.GetTestProperty(i); const TestProperty& property = result.GetTestProperty(i);
...@@ -3481,7 +3472,7 @@ void UnitTest::AddTestPartResult(TestPartResultType result_type, ...@@ -3481,7 +3472,7 @@ void UnitTest::AddTestPartResult(TestPartResultType result_type,
// the supplied value already exists, updates its value instead. // the supplied value already exists, updates its value instead.
void UnitTest::RecordPropertyForCurrentTest(const char* key, void UnitTest::RecordPropertyForCurrentTest(const char* key,
const char* value) { const char* value) {
const internal::TestProperty test_property(key, value); const TestProperty test_property(key, value);
impl_->current_test_result()->RecordProperty(test_property); impl_->current_test_result()->RecordProperty(test_property);
} }
...@@ -4089,7 +4080,7 @@ OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() { ...@@ -4089,7 +4080,7 @@ OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
// Returns the TestResult for the test that's currently running, or // Returns the TestResult for the test that's currently running, or
// the TestResult for the ad hoc test if no test is running. // the TestResult for the ad hoc test if no test is running.
internal::TestResult* UnitTestImpl::current_test_result() { TestResult* UnitTestImpl::current_test_result() {
return current_test_info_ ? return current_test_info_ ?
current_test_info_->impl()->result() : &ad_hoc_test_result_; current_test_info_->impl()->result() : &ad_hoc_test_result_;
} }
...@@ -4136,11 +4127,6 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count) { ...@@ -4136,11 +4127,6 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count) {
return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1); return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
} }
// Returns the number of failed test parts in the given test result object.
int GetFailedPartCount(const TestResult* result) {
return result->failed_part_count();
}
// Used by the GTEST_HIDE_UNREACHABLE_CODE_ macro to suppress unreachable // Used by the GTEST_HIDE_UNREACHABLE_CODE_ macro to suppress unreachable
// code warnings. // code warnings.
namespace { namespace {
......
...@@ -957,16 +957,11 @@ TEST_F(MacroLogicDeathTest, ChildDoesNotDie) { ...@@ -957,16 +957,11 @@ TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
EXPECT_TRUE(factory_->TestDeleted()); EXPECT_TRUE(factory_->TestDeleted());
} }
// Returns the number of successful parts in the current test.
static size_t GetSuccessfulTestPartCount() {
return GetUnitTestImpl()->current_test_result()->successful_part_count();
}
// Tests that a successful death test does not register a successful // Tests that a successful death test does not register a successful
// test part. // test part.
TEST(SuccessRegistrationDeathTest, NoSuccessPart) { TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
EXPECT_DEATH(_exit(1), ""); EXPECT_DEATH(_exit(1), "");
EXPECT_EQ(0u, GetSuccessfulTestPartCount()); EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
} }
TEST(StreamingAssertionsDeathTest, DeathTest) { TEST(StreamingAssertionsDeathTest, DeathTest) {
......
...@@ -94,26 +94,6 @@ const char* FormatTimeInMillisAsSeconds(TimeInMillis ms); ...@@ -94,26 +94,6 @@ const char* FormatTimeInMillisAsSeconds(TimeInMillis ms);
bool ParseInt32Flag(const char* str, const char* flag, Int32* value); bool ParseInt32Flag(const char* str, const char* flag, Int32* value);
// TestResult contains some private methods that should be hidden from
// Google Test user but are required for testing. This class allow our tests
// to access them.
class TestResultAccessor {
public:
static void RecordProperty(TestResult* test_result,
const TestProperty& property) {
test_result->RecordProperty(property);
}
static void ClearTestPartResults(TestResult* test_result) {
test_result->ClearTestPartResults();
}
static const Vector<testing::TestPartResult>& test_part_results(
const TestResult& test_result) {
return test_result.test_part_results();
}
};
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
...@@ -138,8 +118,8 @@ using testing::FloatLE; ...@@ -138,8 +118,8 @@ using testing::FloatLE;
using testing::GTEST_FLAG(also_run_disabled_tests); using testing::GTEST_FLAG(also_run_disabled_tests);
using testing::GTEST_FLAG(break_on_failure); using testing::GTEST_FLAG(break_on_failure);
using testing::GTEST_FLAG(catch_exceptions); using testing::GTEST_FLAG(catch_exceptions);
using testing::GTEST_FLAG(death_test_use_fork);
using testing::GTEST_FLAG(color); using testing::GTEST_FLAG(color);
using testing::GTEST_FLAG(death_test_use_fork);
using testing::GTEST_FLAG(filter); using testing::GTEST_FLAG(filter);
using testing::GTEST_FLAG(list_tests); using testing::GTEST_FLAG(list_tests);
using testing::GTEST_FLAG(output); using testing::GTEST_FLAG(output);
...@@ -155,12 +135,12 @@ using testing::IsSubstring; ...@@ -155,12 +135,12 @@ using testing::IsSubstring;
using testing::Message; using testing::Message;
using testing::ScopedFakeTestPartResultReporter; using testing::ScopedFakeTestPartResultReporter;
using testing::StaticAssertTypeEq; using testing::StaticAssertTypeEq;
using testing::Test;
using testing::TestPartResult;
using testing::TestPartResultArray;
using testing::TPRT_FATAL_FAILURE; using testing::TPRT_FATAL_FAILURE;
using testing::TPRT_NONFATAL_FAILURE; using testing::TPRT_NONFATAL_FAILURE;
using testing::TPRT_SUCCESS; using testing::TPRT_SUCCESS;
using testing::Test;
using testing::TestPartResult;
using testing::TestPartResultArray;
using testing::UnitTest; using testing::UnitTest;
using testing::internal::kMaxRandomSeed; using testing::internal::kMaxRandomSeed;
using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::kTestTypeIdInGoogleTest;
...@@ -168,14 +148,13 @@ using testing::internal::AppendUserMessage; ...@@ -168,14 +148,13 @@ using testing::internal::AppendUserMessage;
using testing::internal::CodePointToUtf8; using testing::internal::CodePointToUtf8;
using testing::internal::EqFailure; using testing::internal::EqFailure;
using testing::internal::FloatingPoint; using testing::internal::FloatingPoint;
using testing::internal::GTestFlagSaver;
using testing::internal::GetCurrentOsStackTraceExceptTop; using testing::internal::GetCurrentOsStackTraceExceptTop;
using testing::internal::GetFailedPartCount;
using testing::internal::GetNextRandomSeed; using testing::internal::GetNextRandomSeed;
using testing::internal::GetRandomSeedFromFlag; using testing::internal::GetRandomSeedFromFlag;
using testing::internal::GetTestTypeId; using testing::internal::GetTestTypeId;
using testing::internal::GetTypeId; using testing::internal::GetTypeId;
using testing::internal::GetUnitTestImpl; using testing::internal::GetUnitTestImpl;
using testing::internal::GTestFlagSaver;
using testing::internal::Int32; using testing::internal::Int32;
using testing::internal::Int32FromEnvOrDie; using testing::internal::Int32FromEnvOrDie;
using testing::internal::ShouldRunTestOnShard; using testing::internal::ShouldRunTestOnShard;
...@@ -190,6 +169,7 @@ using testing::internal::TestResultAccessor; ...@@ -190,6 +169,7 @@ using testing::internal::TestResultAccessor;
using testing::internal::ThreadLocal; using testing::internal::ThreadLocal;
using testing::internal::Vector; using testing::internal::Vector;
using testing::internal::WideStringToUtf8; using testing::internal::WideStringToUtf8;
using testing::internal::kTestTypeIdInGoogleTest;
// This line tests that we can define tests in an unnamed namespace. // This line tests that we can define tests in an unnamed namespace.
namespace { namespace {
...@@ -1227,6 +1207,68 @@ TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) { ...@@ -1227,6 +1207,68 @@ TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD #endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
// Tests the TestProperty class.
TEST(TestPropertyTest, ConstructorWorks) {
const TestProperty property("key", "value");
EXPECT_STREQ("key", property.key());
EXPECT_STREQ("value", property.value());
}
TEST(TestPropertyTest, SetValue) {
TestProperty property("key", "value_1");
EXPECT_STREQ("key", property.key());
property.SetValue("value_2");
EXPECT_STREQ("key", property.key());
EXPECT_STREQ("value_2", property.value());
}
// Tests the TestPartResult class.
TEST(TestPartResultTest, ConstructorWorks) {
Message message;
message << "something is terribly wrong";
message << static_cast<const char*>(testing::internal::kStackTraceMarker);
message << "some unimportant stack trace";
const TestPartResult result(TPRT_NONFATAL_FAILURE,
"some_file.cc",
42,
message.GetString().c_str());
EXPECT_EQ(TPRT_NONFATAL_FAILURE, result.type());
EXPECT_STREQ("some_file.cc", result.file_name());
EXPECT_EQ(42, result.line_number());
EXPECT_STREQ(message.GetString().c_str(), result.message());
EXPECT_STREQ("something is terribly wrong", result.summary());
}
TEST(TestPartResultTest, ResultAccessorsWork) {
const TestPartResult success(TPRT_SUCCESS, "file.cc", 42, "message");
EXPECT_TRUE(success.passed());
EXPECT_FALSE(success.failed());
EXPECT_FALSE(success.nonfatally_failed());
EXPECT_FALSE(success.fatally_failed());
const TestPartResult nonfatal_failure(TPRT_NONFATAL_FAILURE,
"file.cc",
42,
"message");
EXPECT_FALSE(nonfatal_failure.passed());
EXPECT_TRUE(nonfatal_failure.failed());
EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
EXPECT_FALSE(nonfatal_failure.fatally_failed());
const TestPartResult fatal_failure(TPRT_FATAL_FAILURE,
"file.cc",
42,
"message");
EXPECT_FALSE(fatal_failure.passed());
EXPECT_TRUE(fatal_failure.failed());
EXPECT_FALSE(fatal_failure.nonfatally_failed());
EXPECT_TRUE(fatal_failure.fatally_failed());
}
// Tests the TestResult class // Tests the TestResult class
// The test fixture for testing TestResult. // The test fixture for testing TestResult.
...@@ -1299,34 +1341,6 @@ class TestResultTest : public Test { ...@@ -1299,34 +1341,6 @@ class TestResultTest : public Test {
}; };
// Tests TestResult::total_part_count(). // Tests TestResult::total_part_count().
TEST_F(TestResultTest, test_part_results) {
ASSERT_EQ(0, r0->total_part_count());
ASSERT_EQ(1, r1->total_part_count());
ASSERT_EQ(2, r2->total_part_count());
}
// Tests TestResult::successful_part_count().
TEST_F(TestResultTest, successful_part_count) {
ASSERT_EQ(0, r0->successful_part_count());
ASSERT_EQ(1, r1->successful_part_count());
ASSERT_EQ(1, r2->successful_part_count());
}
// Tests TestResult::failed_part_count().
TEST_F(TestResultTest, failed_part_count) {
ASSERT_EQ(0, r0->failed_part_count());
ASSERT_EQ(0, r1->failed_part_count());
ASSERT_EQ(1, r2->failed_part_count());
}
// Tests testing::internal::GetFailedPartCount().
TEST_F(TestResultTest, GetFailedPartCount) {
ASSERT_EQ(0, GetFailedPartCount(r0));
ASSERT_EQ(0, GetFailedPartCount(r1));
ASSERT_EQ(1, GetFailedPartCount(r2));
}
// Tests TestResult::total_part_count().
TEST_F(TestResultTest, total_part_count) { TEST_F(TestResultTest, total_part_count) {
ASSERT_EQ(0, r0->total_part_count()); ASSERT_EQ(0, r0->total_part_count());
ASSERT_EQ(1, r1->total_part_count()); ASSERT_EQ(1, r1->total_part_count());
...@@ -3778,42 +3792,37 @@ TEST(AssertionSyntaxTest, WorksWithConst) { ...@@ -3778,42 +3792,37 @@ TEST(AssertionSyntaxTest, WorksWithConst) {
} // namespace } // namespace
// Returns the number of successful parts in the current test.
static size_t GetSuccessfulPartCount() {
return GetUnitTestImpl()->current_test_result()->successful_part_count();
}
namespace testing { namespace testing {
// Tests that Google Test tracks SUCCEED*. // Tests that Google Test tracks SUCCEED*.
TEST(SuccessfulAssertionTest, SUCCEED) { TEST(SuccessfulAssertionTest, SUCCEED) {
SUCCEED(); SUCCEED();
SUCCEED() << "OK"; SUCCEED() << "OK";
EXPECT_EQ(2, GetSuccessfulPartCount()); EXPECT_EQ(2, GetUnitTestImpl()->current_test_result()->total_part_count());
} }
// Tests that Google Test doesn't track successful EXPECT_*. // Tests that Google Test doesn't track successful EXPECT_*.
TEST(SuccessfulAssertionTest, EXPECT) { TEST(SuccessfulAssertionTest, EXPECT) {
EXPECT_TRUE(true); EXPECT_TRUE(true);
EXPECT_EQ(0, GetSuccessfulPartCount()); EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
} }
// Tests that Google Test doesn't track successful EXPECT_STR*. // Tests that Google Test doesn't track successful EXPECT_STR*.
TEST(SuccessfulAssertionTest, EXPECT_STR) { TEST(SuccessfulAssertionTest, EXPECT_STR) {
EXPECT_STREQ("", ""); EXPECT_STREQ("", "");
EXPECT_EQ(0, GetSuccessfulPartCount()); EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
} }
// Tests that Google Test doesn't track successful ASSERT_*. // Tests that Google Test doesn't track successful ASSERT_*.
TEST(SuccessfulAssertionTest, ASSERT) { TEST(SuccessfulAssertionTest, ASSERT) {
ASSERT_TRUE(true); ASSERT_TRUE(true);
EXPECT_EQ(0, GetSuccessfulPartCount()); EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
} }
// Tests that Google Test doesn't track successful ASSERT_STR*. // Tests that Google Test doesn't track successful ASSERT_STR*.
TEST(SuccessfulAssertionTest, ASSERT_STR) { TEST(SuccessfulAssertionTest, ASSERT_STR) {
ASSERT_STREQ("", ""); ASSERT_STREQ("", "");
EXPECT_EQ(0, GetSuccessfulPartCount()); EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
} }
} // namespace testing } // namespace testing
......
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