Commit aaebfcdc by zhanyong.wan

Refactors for the event listener API (by Vlad Losev): hides some methods in…

Refactors for the event listener API (by Vlad Losev): hides some methods in UnitTest; implements the result printers using the public API.
parent e6095dee
......@@ -141,8 +141,12 @@ const int kMaxStackTraceDepth = 100;
namespace internal {
class AssertHelper;
class GTestFlagSaver;
class TestCase; // A collection of related tests.
class UnitTestImpl* GetUnitTestImpl();
void ReportFailureInUnknownLocation(TestPartResultType result_type,
const String& message);
// Converts a streamable value to a String. A NULL pointer is
// converted to "(null)". When the input value is a ::string,
......@@ -759,33 +763,6 @@ class UnitTest {
// Consecutive calls will return the same object.
static UnitTest* GetInstance();
// Registers and returns a global test environment. When a test
// program is run, all global test environments will be set-up in
// the order they were registered. After all tests in the program
// have finished, all global test environments will be torn-down in
// the *reverse* order they were registered.
//
// The UnitTest object takes ownership of the given environment.
//
// This method can only be called from the main thread.
Environment* AddEnvironment(Environment* env);
// Adds a TestPartResult to the current TestResult object. All
// Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
// eventually call this to report their results. The user code
// should use the assertion macros instead of calling this directly.
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
void AddTestPartResult(TestPartResultType result_type,
const char* file_name,
int line_number,
const internal::String& message,
const internal::String& os_stack_trace);
// Adds a TestProperty to the current TestResult object. If the result already
// contains a property with the same key, the value will be updated.
void RecordPropertyForCurrentTest(const char* key, const char* value);
// Runs all tests in this UnitTest object and prints the result.
// Returns 0 if successful, or 1 otherwise.
//
......@@ -809,14 +786,41 @@ class UnitTest {
#if GTEST_HAS_PARAM_TEST
// Returns the ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
internal::ParameterizedTestCaseRegistry& parameterized_test_registry();
#endif // GTEST_HAS_PARAM_TEST
private:
// Registers and returns a global test environment. When a test
// program is run, all global test environments will be set-up in
// the order they were registered. After all tests in the program
// have finished, all global test environments will be torn-down in
// the *reverse* order they were registered.
//
// The UnitTest object takes ownership of the given environment.
//
// This method can only be called from the main thread.
Environment* AddEnvironment(Environment* env);
// Adds a TestPartResult to the current TestResult object. All
// Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
// eventually call this to report their results. The user code
// should use the assertion macros instead of calling this directly.
void AddTestPartResult(TestPartResultType result_type,
const char* file_name,
int line_number,
const internal::String& message,
const internal::String& os_stack_trace);
// Adds a TestProperty to the current TestResult object. If the result already
// contains a property with the same key, the value will be updated.
void RecordPropertyForCurrentTest(const char* key, const char* value);
// Accessors for the implementation object.
internal::UnitTestImpl* impl() { return impl_; }
const internal::UnitTestImpl* impl() const { return impl_; }
private:
// Gets the number of successful test cases.
int successful_test_case_count() const;
......@@ -861,7 +865,20 @@ class UnitTest {
// ScopedTrace is a friend as it needs to modify the per-thread
// trace stack, which is a private member of UnitTest.
// TODO(vladl@google.com): Order all declarations according to the style
// guide after publishing of the above methods is done.
friend class internal::ScopedTrace;
friend Environment* AddGlobalTestEnvironment(Environment* env);
friend internal::UnitTestImpl* internal::GetUnitTestImpl();
friend class internal::AssertHelper;
friend class Test;
friend void internal::ReportFailureInUnknownLocation(
TestPartResultType result_type,
const internal::String& message);
// TODO(vladl@google.com): Remove these when publishing the new accessors.
friend class PrettyUnitTestResultPrinter;
friend class XmlUnitTestResultPrinter;
// Creates an empty UnitTest.
UnitTest();
......
......@@ -44,6 +44,8 @@
namespace testing {
using internal::GetUnitTestImpl;
// Gets the summary of the failure message by omitting the stack trace
// in it.
internal::String TestPartResult::ExtractSummary(const char* message) {
......@@ -101,14 +103,13 @@ namespace internal {
HasNewFatalFailureHelper::HasNewFatalFailureHelper()
: has_new_fatal_failure_(false),
original_reporter_(UnitTest::GetInstance()->impl()->
original_reporter_(GetUnitTestImpl()->
GetTestPartResultReporterForCurrentThread()) {
UnitTest::GetInstance()->impl()->SetTestPartResultReporterForCurrentThread(
this);
GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
}
HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
UnitTest::GetInstance()->impl()->SetTestPartResultReporterForCurrentThread(
GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
original_reporter_);
}
......
......@@ -67,6 +67,7 @@ using testing::internal::DeathTest;
using testing::internal::DeathTestFactory;
using testing::internal::FilePath;
using testing::internal::GetLastErrnoDescription;
using testing::internal::GetUnitTestImpl;
using testing::internal::ParseNaturalNumber;
using testing::internal::String;
......@@ -77,22 +78,22 @@ namespace internal {
// single UnitTest object during their lifetimes.
class ReplaceDeathTestFactory {
public:
ReplaceDeathTestFactory(UnitTest* parent, DeathTestFactory* new_factory)
: parent_impl_(parent->impl()) {
old_factory_ = parent_impl_->death_test_factory_.release();
parent_impl_->death_test_factory_.reset(new_factory);
explicit ReplaceDeathTestFactory(DeathTestFactory* new_factory)
: unit_test_impl_(GetUnitTestImpl()) {
old_factory_ = unit_test_impl_->death_test_factory_.release();
unit_test_impl_->death_test_factory_.reset(new_factory);
}
~ReplaceDeathTestFactory() {
parent_impl_->death_test_factory_.release();
parent_impl_->death_test_factory_.reset(old_factory_);
unit_test_impl_->death_test_factory_.release();
unit_test_impl_->death_test_factory_.reset(old_factory_);
}
private:
// Prevents copying ReplaceDeathTestFactory objects.
ReplaceDeathTestFactory(const ReplaceDeathTestFactory&);
void operator=(const ReplaceDeathTestFactory&);
UnitTestImpl* parent_impl_;
UnitTestImpl* unit_test_impl_;
DeathTestFactory* old_factory_;
};
......@@ -846,8 +847,7 @@ class MacroLogicDeathTest : public testing::Test {
static void SetUpTestCase() {
factory_ = new MockDeathTestFactory;
replacer_ = new testing::internal::ReplaceDeathTestFactory(
testing::UnitTest::GetInstance(), factory_);
replacer_ = new testing::internal::ReplaceDeathTestFactory(factory_);
}
static void TearDownTestCase() {
......@@ -959,8 +959,7 @@ TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
// Returns the number of successful parts in the current test.
static size_t GetSuccessfulTestPartCount() {
return testing::UnitTest::GetInstance()->impl()->current_test_result()->
successful_part_count();
return GetUnitTestImpl()->current_test_result()->successful_part_count();
}
// Tests that a successful death test does not register a successful
......
......@@ -136,6 +136,7 @@ using testing::internal::GetCurrentOsStackTraceExceptTop;
using testing::internal::GetFailedPartCount;
using testing::internal::GetTestTypeId;
using testing::internal::GetTypeId;
using testing::internal::GetUnitTestImpl;
using testing::internal::GTestFlagSaver;
using testing::internal::Int32;
using testing::internal::Int32FromEnvOrDie;
......@@ -3600,8 +3601,7 @@ TEST(AssertionSyntaxTest, WorksWithConst) {
// Returns the number of successful parts in the current test.
static size_t GetSuccessfulPartCount() {
return UnitTest::GetInstance()->impl()->current_test_result()->
successful_part_count();
return GetUnitTestImpl()->current_test_result()->successful_part_count();
}
namespace testing {
......@@ -4416,8 +4416,7 @@ namespace testing {
class TestInfoTest : public Test {
protected:
static TestInfo * GetTestInfo(const char* test_name) {
return UnitTest::GetInstance()->impl()->
GetTestCase("TestInfoTest", "", NULL, NULL)->
return GetUnitTestImpl()->GetTestCase("TestInfoTest", "", NULL, NULL)->
GetTestInfo(test_name);
}
......
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