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