Renames the methods in the event listener API, and changes the order of *End events (by Vlad Losev).

This commit is contained in:
zhanyong.wan 2009-09-17 19:12:30 +00:00
parent 12d740faef
commit f43e4ff3ad
5 changed files with 372 additions and 202 deletions

View File

@ -158,8 +158,7 @@ class TestCase;
class TestInfoImpl; class TestInfoImpl;
class TestResultAccessor; class TestResultAccessor;
class UnitTestAccessor; class UnitTestAccessor;
// TODO(vladl@google.com): Rename to TestEventRepeater. class TestEventRepeater;
class UnitTestEventsRepeater;
class WindowsDeathTest; class WindowsDeathTest;
class UnitTestImpl* GetUnitTestImpl(); class UnitTestImpl* GetUnitTestImpl();
void ReportFailureInUnknownLocation(TestPartResultType result_type, void ReportFailureInUnknownLocation(TestPartResultType result_type,
@ -781,86 +780,75 @@ class UnitTestEventListenerInterface {
public: public:
virtual ~UnitTestEventListenerInterface() {} virtual ~UnitTestEventListenerInterface() {}
// TODO(vladl@google.com): Add events for test program start and test program // TODO(vladl@google.com): Add tests for OnTestIterationStart and
// end: OnTestIterationStart(const UnitTest&); // Start of one iteration. // OnTestIterationEnd.
// Add tests, too.
// TODO(vladl@google.com): Rename OnUnitTestStart() and OnUnitTestEnd() to
// OnTestProgramStart() and OnTestProgramEnd().
// Called before any test activity starts.
virtual void OnUnitTestStart(const UnitTest& unit_test) = 0;
// Called after all test activities have ended. // Fired before any test activity starts.
virtual void OnUnitTestEnd(const UnitTest& unit_test) = 0; virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
// Called before the test case starts. // Fired after all test activities have ended.
virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
// Fired before each iteration of tests starts. There may be more than
// one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
// index, starting from 0.
virtual void OnTestIterationStart(const UnitTest& unit_test,
int iteration) = 0;
// Fired after each iteration of tests finishes.
virtual void OnTestIterationEnd(const UnitTest& unit_test,
int iteration) = 0;
// Fired before environment set-up for each iteration of tests starts.
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
// Fired after environment set-up for each iteration of tests ends.
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
// Fired before environment tear-down for each iteration of tests starts.
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
// Fired after environment tear-down for each iteration of tests ends.
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
// Fired before the test case starts.
virtual void OnTestCaseStart(const TestCase& test_case) = 0; virtual void OnTestCaseStart(const TestCase& test_case) = 0;
// Called after the test case ends. // Fired after the test case ends.
virtual void OnTestCaseEnd(const TestCase& test_case) = 0; virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
// TODO(vladl@google.com): Rename OnGlobalSetUpStart to // Fired before the test starts.
// OnEnvironmentsSetUpStart. Make similar changes for the rest of
// environment-related events.
// Called before the global set-up starts.
virtual void OnGlobalSetUpStart(const UnitTest& unit_test) = 0;
// Called after the global set-up ends.
virtual void OnGlobalSetUpEnd(const UnitTest& unit_test) = 0;
// Called before the global tear-down starts.
virtual void OnGlobalTearDownStart(const UnitTest& unit_test) = 0;
// Called after the global tear-down ends.
virtual void OnGlobalTearDownEnd(const UnitTest& unit_test) = 0;
// Called before the test starts.
virtual void OnTestStart(const TestInfo& test_info) = 0; virtual void OnTestStart(const TestInfo& test_info) = 0;
// Called after the test ends. // Fired after the test ends.
virtual void OnTestEnd(const TestInfo& test_info) = 0; virtual void OnTestEnd(const TestInfo& test_info) = 0;
// Called after a failed assertion or a SUCCESS(). // Fired after a failed assertion or a SUCCESS().
virtual void OnNewTestPartResult(const TestPartResult& test_part_result) = 0; virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
}; };
// The convenience class for users who need to override just one or two // The convenience class for users who need to override just one or two
// methods and are not concerned that a possible change to a signature of // methods and are not concerned that a possible change to a signature of
// the methods they override will not be caught during the build. // the methods they override will not be caught during the build.
// For comments about each method please see the definition of
// UnitTestEventListenerInterface above.
class EmptyTestEventListener : public UnitTestEventListenerInterface { class EmptyTestEventListener : public UnitTestEventListenerInterface {
public: public:
// Called before the unit test starts. virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
virtual void OnUnitTestStart(const UnitTest& /*unit_test*/) {} virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
// Called after the unit test ends. int /*iteration*/) {}
virtual void OnUnitTestEnd(const UnitTest& /*unit_test*/) {} virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
int /*iteration*/) {}
// Called before the test case starts. virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
virtual void OnTestCaseStart(const TestCase& /*test_case*/) {} virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
// Called after the test case ends.
virtual void OnTestCaseEnd(const TestCase& /*test_case&*/) {}
// Called before the global set-up starts.
virtual void OnGlobalSetUpStart(const UnitTest& /*unit_test*/) {}
// Called after the global set-up ends.
virtual void OnGlobalSetUpEnd(const UnitTest& /*unit_test*/) {}
// Called before the global tear-down starts.
virtual void OnGlobalTearDownStart(const UnitTest& /*unit_test*/) {}
// Called after the global tear-down ends.
virtual void OnGlobalTearDownEnd(const UnitTest& /*unit_test*/) {}
// Called before the test starts.
virtual void OnTestStart(const TestInfo& /*test_info*/) {} virtual void OnTestStart(const TestInfo& /*test_info*/) {}
// Called after the test ends.
virtual void OnTestEnd(const TestInfo& /*test_info*/) {} virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
// Called after a failed assertion or a SUCCESS().
virtual void OnNewTestPartResult(const TestPartResult& /*test_part_result*/) {
}
}; };
// EventListeners lets users add listeners to track events in Google Test. // EventListeners lets users add listeners to track events in Google Test.
@ -932,7 +920,7 @@ class EventListeners {
void SuppressEventForwarding(); void SuppressEventForwarding();
// The actual list of listeners. // The actual list of listeners.
internal::UnitTestEventsRepeater* repeater_; internal::TestEventRepeater* repeater_;
// Listener responsible for the standard result output. // Listener responsible for the standard result output.
UnitTestEventListenerInterface* default_result_printer_; UnitTestEventListenerInterface* default_result_printer_;
// Listener responsible for the creation of the XML output file. // Listener responsible for the creation of the XML output file.

View File

@ -105,7 +105,7 @@ class TersePrinter : public EmptyTestEventListener {
} }
// Called after a failed assertion or a SUCCESS(). // Called after a failed assertion or a SUCCESS().
virtual void OnNewTestPartResult(const TestPartResult& test_part_result) { virtual void OnTestPartResult(const TestPartResult& test_part_result) {
fprintf(stdout, fprintf(stdout,
"%s in %s:%d\n%s\n", "%s in %s:%d\n%s\n",
test_part_result.failed() ? "*** Failure" : "Success", test_part_result.failed() ? "*** Failure" : "Success",

View File

@ -617,7 +617,7 @@ DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
void DefaultGlobalTestPartResultReporter::ReportTestPartResult( void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
const TestPartResult& result) { const TestPartResult& result) {
unit_test_->current_test_result()->AddTestPartResult(result); unit_test_->current_test_result()->AddTestPartResult(result);
unit_test_->listeners()->repeater()->OnNewTestPartResult(result); unit_test_->listeners()->repeater()->OnTestPartResult(result);
} }
DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter( DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
@ -2471,12 +2471,10 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) {
// following statements add the test part result message to the Output // following statements add the test part result message to the Output
// window such that the user can double-click on it to jump to the // window such that the user can double-click on it to jump to the
// corresponding source code location; otherwise they do nothing. // corresponding source code location; otherwise they do nothing.
#ifdef _WIN32_WCE #if GTEST_OS_WINDOWS && !defined(_WIN32_WCE)
// Windows Mobile doesn't support the ANSI version of OutputDebugString, // We don't call OutputDebugString*() on Windows Mobile, as printing
// it works only with UTF16 strings. // to stdout is done by OutputDebugString() there already - we don't
::OutputDebugString(internal::String::AnsiToUtf16(result.c_str())); // want the same message printed twice.
::OutputDebugString(L"\n");
#elif GTEST_OS_WINDOWS
::OutputDebugStringA(result.c_str()); ::OutputDebugStringA(result.c_str());
::OutputDebugStringA("\n"); ::OutputDebugStringA("\n");
#endif #endif
@ -2608,17 +2606,19 @@ class PrettyUnitTestResultPrinter : public UnitTestEventListenerInterface {
// The following methods override what's in the // The following methods override what's in the
// UnitTestEventListenerInterface class. // UnitTestEventListenerInterface class.
virtual void OnUnitTestStart(const UnitTest& unit_test); virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
virtual void OnGlobalSetUpStart(const UnitTest& unit_test); virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
virtual void OnGlobalSetUpEnd(const UnitTest& /*unit_test*/) {} virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
virtual void OnTestCaseStart(const TestCase& test_case); virtual void OnTestCaseStart(const TestCase& test_case);
virtual void OnTestCaseEnd(const TestCase& test_case); virtual void OnTestCaseEnd(const TestCase& test_case);
virtual void OnTestStart(const TestInfo& test_info); virtual void OnTestStart(const TestInfo& test_info);
virtual void OnNewTestPartResult(const TestPartResult& result); virtual void OnTestPartResult(const TestPartResult& result);
virtual void OnTestEnd(const TestInfo& test_info); virtual void OnTestEnd(const TestInfo& test_info);
virtual void OnGlobalTearDownStart(const UnitTest& unit_test); virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
virtual void OnGlobalTearDownEnd(const UnitTest& /*unit_test*/) {} virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
virtual void OnUnitTestEnd(const UnitTest& unit_test); virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
private: private:
static void PrintFailedTests(const UnitTest& unit_test); static void PrintFailedTests(const UnitTest& unit_test);
@ -2626,8 +2626,12 @@ class PrettyUnitTestResultPrinter : public UnitTestEventListenerInterface {
internal::String test_case_name_; internal::String test_case_name_;
}; };
// Called before the unit test starts. // Fired before each iteration of tests starts.
void PrettyUnitTestResultPrinter::OnUnitTestStart(const UnitTest& unit_test) { void PrettyUnitTestResultPrinter::OnTestIterationStart(
const UnitTest& unit_test, int iteration) {
if (GTEST_FLAG(repeat) != 1)
printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
const char* const filter = GTEST_FLAG(filter).c_str(); const char* const filter = GTEST_FLAG(filter).c_str();
// Prints the filter if it's not *. This reminds the user that some // Prints the filter if it's not *. This reminds the user that some
@ -2657,7 +2661,7 @@ void PrettyUnitTestResultPrinter::OnUnitTestStart(const UnitTest& unit_test) {
fflush(stdout); fflush(stdout);
} }
void PrettyUnitTestResultPrinter::OnGlobalSetUpStart( void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
const UnitTest& /*unit_test*/) { const UnitTest& /*unit_test*/) {
ColoredPrintf(COLOR_GREEN, "[----------] "); ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("Global test environment set-up.\n"); printf("Global test environment set-up.\n");
@ -2719,7 +2723,7 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
} }
// Called after an assertion failure. // Called after an assertion failure.
void PrettyUnitTestResultPrinter::OnNewTestPartResult( void PrettyUnitTestResultPrinter::OnTestPartResult(
const TestPartResult& result) { const TestPartResult& result) {
// If the test part succeeded, we don't need to do anything. // If the test part succeeded, we don't need to do anything.
if (result.type() == TPRT_SUCCESS) if (result.type() == TPRT_SUCCESS)
@ -2730,7 +2734,7 @@ void PrettyUnitTestResultPrinter::OnNewTestPartResult(
fflush(stdout); fflush(stdout);
} }
void PrettyUnitTestResultPrinter::OnGlobalTearDownStart( void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
const UnitTest& /*unit_test*/) { const UnitTest& /*unit_test*/) {
ColoredPrintf(COLOR_GREEN, "[----------] "); ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("Global test environment tear-down\n"); printf("Global test environment tear-down\n");
@ -2769,7 +2773,8 @@ void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
} }
} }
void PrettyUnitTestResultPrinter::OnUnitTestEnd(const UnitTest& unit_test) { void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
int /*iteration*/) {
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(),
@ -2808,13 +2813,13 @@ void PrettyUnitTestResultPrinter::OnUnitTestEnd(const UnitTest& unit_test) {
// End PrettyUnitTestResultPrinter // End PrettyUnitTestResultPrinter
// class UnitTestEventsRepeater // class TestEventRepeater
// //
// This class forwards events to other event listeners. // This class forwards events to other event listeners.
class UnitTestEventsRepeater : public UnitTestEventListenerInterface { class TestEventRepeater : public UnitTestEventListenerInterface {
public: public:
UnitTestEventsRepeater() : forwarding_enabled_(true) {} TestEventRepeater() : forwarding_enabled_(true) {}
virtual ~UnitTestEventsRepeater(); virtual ~TestEventRepeater();
void Append(UnitTestEventListenerInterface *listener); void Append(UnitTestEventListenerInterface *listener);
UnitTestEventListenerInterface* Release( UnitTestEventListenerInterface* Release(
UnitTestEventListenerInterface* listener); UnitTestEventListenerInterface* listener);
@ -2824,17 +2829,19 @@ class UnitTestEventsRepeater : public UnitTestEventListenerInterface {
bool forwarding_enabled() const { return forwarding_enabled_; } bool forwarding_enabled() const { return forwarding_enabled_; }
void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; } void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
virtual void OnUnitTestStart(const UnitTest& unit_test); virtual void OnTestProgramStart(const UnitTest& unit_test);
virtual void OnUnitTestEnd(const UnitTest& unit_test); virtual void OnTestProgramEnd(const UnitTest& unit_test);
virtual void OnGlobalSetUpStart(const UnitTest& unit_test); virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
virtual void OnGlobalSetUpEnd(const UnitTest& unit_test); virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
virtual void OnGlobalTearDownStart(const UnitTest& unit_test); virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
virtual void OnGlobalTearDownEnd(const UnitTest& unit_test); virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test);
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test);
virtual void OnTestCaseStart(const TestCase& test_case); virtual void OnTestCaseStart(const TestCase& test_case);
virtual void OnTestCaseEnd(const TestCase& test_case); virtual void OnTestCaseEnd(const TestCase& test_case);
virtual void OnTestStart(const TestInfo& test_info); virtual void OnTestStart(const TestInfo& test_info);
virtual void OnTestEnd(const TestInfo& test_info); virtual void OnTestEnd(const TestInfo& test_info);
virtual void OnNewTestPartResult(const TestPartResult& result); virtual void OnTestPartResult(const TestPartResult& result);
private: private:
// Controls whether events will be forwarded to listeners_. Set to false // Controls whether events will be forwarded to listeners_. Set to false
@ -2843,21 +2850,21 @@ class UnitTestEventsRepeater : public UnitTestEventListenerInterface {
// The list of listeners that receive events. // The list of listeners that receive events.
Vector<UnitTestEventListenerInterface*> listeners_; Vector<UnitTestEventListenerInterface*> listeners_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestEventsRepeater); GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater);
}; };
UnitTestEventsRepeater::~UnitTestEventsRepeater() { TestEventRepeater::~TestEventRepeater() {
for (int i = 0; i < listeners_.size(); i++) { for (int i = 0; i < listeners_.size(); i++) {
delete listeners_.GetElement(i); delete listeners_.GetElement(i);
} }
} }
void UnitTestEventsRepeater::Append(UnitTestEventListenerInterface *listener) { void TestEventRepeater::Append(UnitTestEventListenerInterface *listener) {
listeners_.PushBack(listener); listeners_.PushBack(listener);
} }
// TODO(vladl@google.com): Factor the search functionality into Vector::Find. // TODO(vladl@google.com): Factor the search functionality into Vector::Find.
UnitTestEventListenerInterface* UnitTestEventsRepeater::Release( UnitTestEventListenerInterface* TestEventRepeater::Release(
UnitTestEventListenerInterface *listener) { UnitTestEventListenerInterface *listener) {
for (int i = 0; i < listeners_.size(); ++i) { for (int i = 0; i < listeners_.size(); ++i) {
if (listeners_.GetElement(i) == listener) { if (listeners_.GetElement(i) == listener) {
@ -2869,39 +2876,68 @@ UnitTestEventListenerInterface* UnitTestEventsRepeater::Release(
return NULL; return NULL;
} }
// Since the methods are identical, use a macro to reduce boilerplate. // Since most methods are very similar, use macros to reduce boilerplate.
// This defines a member that repeats the call to all listeners. // This defines a member that forwards the call to all listeners.
#define GTEST_REPEATER_METHOD_(Name, Type) \ #define GTEST_REPEATER_METHOD_(Name, Type) \
void UnitTestEventsRepeater::Name(const Type& parameter) { \ void TestEventRepeater::Name(const Type& parameter) { \
if (forwarding_enabled_) { \ if (forwarding_enabled_) { \
for (int i = 0; i < listeners_.size(); i++) { \ for (int i = 0; i < listeners_.size(); i++) { \
listeners_.GetElement(i)->Name(parameter); \ listeners_.GetElement(i)->Name(parameter); \
} \ } \
} \ } \
} }
// This defines a member that forwards the call to all listeners in reverse
// order.
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
void TestEventRepeater::Name(const Type& parameter) { \
if (forwarding_enabled_) { \
for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \
listeners_.GetElement(i)->Name(parameter); \
} \
} \
}
GTEST_REPEATER_METHOD_(OnUnitTestStart, UnitTest) GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
GTEST_REPEATER_METHOD_(OnUnitTestEnd, UnitTest) GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
GTEST_REPEATER_METHOD_(OnGlobalSetUpStart, UnitTest) GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
GTEST_REPEATER_METHOD_(OnGlobalSetUpEnd, UnitTest)
GTEST_REPEATER_METHOD_(OnGlobalTearDownStart, UnitTest)
GTEST_REPEATER_METHOD_(OnGlobalTearDownEnd, UnitTest)
GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase) GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase)
GTEST_REPEATER_METHOD_(OnTestCaseEnd, TestCase)
GTEST_REPEATER_METHOD_(OnTestStart, TestInfo) GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
GTEST_REPEATER_METHOD_(OnTestEnd, TestInfo) GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
GTEST_REPEATER_METHOD_(OnNewTestPartResult, TestPartResult) GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase)
GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
#undef GTEST_REPEATER_METHOD_ #undef GTEST_REPEATER_METHOD_
#undef GTEST_REVERSE_REPEATER_METHOD_
// End UnitTestEventsRepeater void TestEventRepeater::OnTestIterationStart(const UnitTest& unit_test,
int iteration) {
if (forwarding_enabled_) {
for (int i = 0; i < listeners_.size(); i++) {
listeners_.GetElement(i)->OnTestIterationStart(unit_test, iteration);
}
}
}
void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,
int iteration) {
if (forwarding_enabled_) {
for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {
listeners_.GetElement(i)->OnTestIterationEnd(unit_test, iteration);
}
}
}
// End TestEventRepeater
// This class generates an XML output file. // This class generates an XML output file.
class XmlUnitTestResultPrinter : public EmptyTestEventListener { class XmlUnitTestResultPrinter : public EmptyTestEventListener {
public: public:
explicit XmlUnitTestResultPrinter(const char* output_file); explicit XmlUnitTestResultPrinter(const char* output_file);
virtual void OnUnitTestEnd(const UnitTest& unit_test); virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
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
@ -2963,7 +2999,8 @@ XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
} }
// Called after the unit test ends. // Called after the unit test ends.
void XmlUnitTestResultPrinter::OnUnitTestEnd(const UnitTest& unit_test) { void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
int /*iteration*/) {
FILE* xmlout = NULL; FILE* xmlout = NULL;
FilePath output_file(output_file_); FilePath output_file(output_file_);
FilePath output_dir(output_file.RemoveFileName()); FilePath output_dir(output_file.RemoveFileName());
@ -3210,7 +3247,7 @@ OsStackTraceGetter::kElidedFramesMarker =
// class EventListeners // class EventListeners
EventListeners::EventListeners() EventListeners::EventListeners()
: repeater_(new internal::UnitTestEventsRepeater()), : repeater_(new internal::TestEventRepeater()),
default_result_printer_(NULL), default_result_printer_(NULL),
default_xml_generator_(NULL) { default_xml_generator_(NULL) {
} }
@ -3834,31 +3871,27 @@ int UnitTestImpl::RunAllTests() {
UnitTestEventListenerInterface* repeater = listeners()->repeater(); UnitTestEventListenerInterface* repeater = listeners()->repeater();
repeater->OnTestProgramStart(*parent_);
// How many times to repeat the tests? We don't want to repeat them // How many times to repeat the tests? We don't want to repeat them
// when we are inside the subprocess of a death test. // when we are inside the subprocess of a death test.
const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat); const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat);
// Repeats forever if the repeat count is negative. // Repeats forever if the repeat count is negative.
const bool forever = repeat < 0; const bool forever = repeat < 0;
for (int i = 0; forever || i != repeat; i++) { for (int i = 0; forever || i != repeat; i++) {
if (repeat != 1) { ClearResult();
// TODO(vladl@google.com): Move this output to
// PrettyUnitTestResultPrinter. Add the iteration number parameter to const TimeInMillis start = GetTimeInMillis();
// OnUnitTestStart.
printf("\nRepeating all tests (iteration %d) . . .\n\n", i + 1);
}
// 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->OnUnitTestStart(*parent_); repeater->OnTestIterationStart(*parent_, i);
// TODO(vladl@google.com): Move to before the OnUnitTestStart notification?
const TimeInMillis start = GetTimeInMillis();
// Runs each test case if there is at least one test to run. // Runs each test case 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->OnGlobalSetUpStart(*parent_); repeater->OnEnvironmentsSetUpStart(*parent_);
environments_.ForEach(SetUpEnvironment); environments_.ForEach(SetUpEnvironment);
repeater->OnGlobalSetUpEnd(*parent_); repeater->OnEnvironmentsSetUpEnd(*parent_);
// 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.
@ -3867,21 +3900,20 @@ int UnitTestImpl::RunAllTests() {
} }
// Tears down all environments in reverse order afterwards. // Tears down all environments in reverse order afterwards.
repeater->OnGlobalTearDownStart(*parent_); repeater->OnEnvironmentsTearDownStart(*parent_);
environments_in_reverse_order_.ForEach(TearDownEnvironment); environments_in_reverse_order_.ForEach(TearDownEnvironment);
repeater->OnGlobalTearDownEnd(*parent_); repeater->OnEnvironmentsTearDownEnd(*parent_);
} }
elapsed_time_ = GetTimeInMillis() - start; elapsed_time_ = GetTimeInMillis() - start;
// Tells the unit test event listener that the tests have just finished. // Tells the unit test event listener that the tests have just finished.
repeater->OnUnitTestEnd(*parent_); repeater->OnTestIterationEnd(*parent_, i);
// Gets the result and clears it. // Gets the result and clears it.
if (!Passed()) { if (!Passed()) {
failed = true; failed = true;
} }
ClearResult();
if (GTEST_FLAG(shuffle)) { if (GTEST_FLAG(shuffle)) {
// Picks a new random seed for each run. // Picks a new random seed for each run.
@ -3889,6 +3921,8 @@ int UnitTestImpl::RunAllTests() {
} }
} }
repeater->OnTestProgramEnd(*parent_);
// Returns 0 if all tests passed, or 1 other wise. // Returns 0 if all tests passed, or 1 other wise.
return failed ? 1 : 0; return failed ? 1 : 0;
} }

View File

@ -73,50 +73,78 @@ class UnitTestAccessor {
}; };
class EventRecordingListener : public UnitTestEventListenerInterface { class EventRecordingListener : public UnitTestEventListenerInterface {
public:
EventRecordingListener(const char* name) : name_(name) {}
protected: protected:
virtual void OnUnitTestStart(const UnitTest& /*unit_test*/) { virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {
g_events->PushBack(String("TestEventListener::OnUnitTestStart")); g_events->PushBack(GetFullMethodName("OnTestProgramStart"));
} }
virtual void OnGlobalSetUpStart(const UnitTest& /*unit_test*/) { virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
g_events->PushBack(String("TestEventListener::OnGlobalSetUpStart")); int iteration) {
Message message;
message << GetFullMethodName("OnTestIterationStart")
<< "(" << iteration << ")";
g_events->PushBack(message.GetString());
} }
virtual void OnGlobalSetUpEnd(const UnitTest& /*unit_test*/) { virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {
g_events->PushBack(String("TestEventListener::OnGlobalSetUpEnd")); g_events->PushBack(GetFullMethodName("OnEnvironmentsSetUpStart"));
}
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {
g_events->PushBack(GetFullMethodName("OnEnvironmentsSetUpEnd"));
} }
virtual void OnTestCaseStart(const TestCase& /*test_case*/) { virtual void OnTestCaseStart(const TestCase& /*test_case*/) {
g_events->PushBack(String("TestEventListener::OnTestCaseStart")); g_events->PushBack(GetFullMethodName("OnTestCaseStart"));
} }
virtual void OnTestStart(const TestInfo& /*test_info*/) { virtual void OnTestStart(const TestInfo& /*test_info*/) {
g_events->PushBack(String("TestEventListener::OnTestStart")); g_events->PushBack(GetFullMethodName("OnTestStart"));
} }
virtual void OnNewTestPartResult(const TestPartResult& /*test_part_result*/) { virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {
g_events->PushBack(String("TestEventListener::OnNewTestPartResult")); g_events->PushBack(GetFullMethodName("OnTestPartResult"));
} }
virtual void OnTestEnd(const TestInfo& /*test_info*/) { virtual void OnTestEnd(const TestInfo& /*test_info*/) {
g_events->PushBack(String("TestEventListener::OnTestEnd")); g_events->PushBack(GetFullMethodName("OnTestEnd"));
} }
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) { virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {
g_events->PushBack(String("TestEventListener::OnTestCaseEnd")); g_events->PushBack(GetFullMethodName("OnTestCaseEnd"));
} }
virtual void OnGlobalTearDownStart(const UnitTest& /*unit_test*/) { virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {
g_events->PushBack(String("TestEventListener::OnGlobalTearDownStart")); g_events->PushBack(GetFullMethodName("OnEnvironmentsTearDownStart"));
} }
virtual void OnGlobalTearDownEnd(const UnitTest& /*unit_test*/) { virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {
g_events->PushBack(String("TestEventListener::OnGlobalTearDownEnd")); g_events->PushBack(GetFullMethodName("OnEnvironmentsTearDownEnd"));
} }
virtual void OnUnitTestEnd(const UnitTest& /*unit_test*/) { virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
g_events->PushBack(String("TestEventListener::OnUnitTestEnd")); int iteration) {
Message message;
message << GetFullMethodName("OnTestIterationEnd")
<< "(" << iteration << ")";
g_events->PushBack(message.GetString());
} }
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {
g_events->PushBack(GetFullMethodName("OnTestProgramEnd"));
}
private:
String GetFullMethodName(const char* name) {
Message message;
message << name_ << "." << name;
return message.GetString();
}
String name_;
}; };
class EnvironmentInvocationCatcher : public Environment { class EnvironmentInvocationCatcher : public Environment {
@ -169,57 +197,132 @@ using ::testing::internal::EnvironmentInvocationCatcher;
using ::testing::internal::EventRecordingListener; using ::testing::internal::EventRecordingListener;
using ::testing::internal::UnitTestAccessor; using ::testing::internal::UnitTestAccessor;
void VerifyResults(const Vector<String>& data,
const char* const* expected_data,
int expected_data_size) {
const int actual_size = data.size();
// If the following assertion fails, a new entry will be appended to
// data. Hence we save data.size() first.
EXPECT_EQ(expected_data_size, actual_size);
// Compares the common prefix.
const int shorter_size = expected_data_size <= actual_size ?
expected_data_size : actual_size;
int i = 0;
for (; i < shorter_size; ++i) {
ASSERT_STREQ(expected_data[i], data.GetElement(i).c_str())
<< "at position " << i;
}
// Prints extra elements in the actual data.
for (; i < actual_size; ++i) {
printf(" Actual event #%d: %s\n", i, data.GetElement(i).c_str());
}
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
Vector<String> events; Vector<String> events;
g_events = &events; g_events = &events;
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
UnitTestEventListenerInterface* listener = new EventRecordingListener; UnitTestAccessor::GetEventListeners().Append(
UnitTestAccessor::GetEventListeners().Append(listener); new EventRecordingListener("1st"));
UnitTestAccessor::GetEventListeners().Append(
new EventRecordingListener("2nd"));
AddGlobalTestEnvironment(new EnvironmentInvocationCatcher); AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
GTEST_CHECK_(events.size() == 0) GTEST_CHECK_(events.size() == 0)
<< "AddGlobalTestEnvironment should not generate any events itself."; << "AddGlobalTestEnvironment should not generate any events itself.";
::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[] = {
"TestEventListener::OnUnitTestStart", "1st.OnTestProgramStart",
"TestEventListener::OnGlobalSetUpStart", "2nd.OnTestProgramStart",
"1st.OnTestIterationStart(0)",
"2nd.OnTestIterationStart(0)",
"1st.OnEnvironmentsSetUpStart",
"2nd.OnEnvironmentsSetUpStart",
"Environment::SetUp", "Environment::SetUp",
"TestEventListener::OnGlobalSetUpEnd", "2nd.OnEnvironmentsSetUpEnd",
"TestEventListener::OnTestCaseStart", "1st.OnEnvironmentsSetUpEnd",
"1st.OnTestCaseStart",
"2nd.OnTestCaseStart",
"ListenerTest::SetUpTestCase", "ListenerTest::SetUpTestCase",
"TestEventListener::OnTestStart", "1st.OnTestStart",
"2nd.OnTestStart",
"ListenerTest::SetUp", "ListenerTest::SetUp",
"ListenerTest::* Test Body", "ListenerTest::* Test Body",
"TestEventListener::OnNewTestPartResult", "1st.OnTestPartResult",
"2nd.OnTestPartResult",
"ListenerTest::TearDown", "ListenerTest::TearDown",
"TestEventListener::OnTestEnd", "2nd.OnTestEnd",
"TestEventListener::OnTestStart", "1st.OnTestEnd",
"1st.OnTestStart",
"2nd.OnTestStart",
"ListenerTest::SetUp", "ListenerTest::SetUp",
"ListenerTest::* Test Body", "ListenerTest::* Test Body",
"TestEventListener::OnNewTestPartResult", "1st.OnTestPartResult",
"2nd.OnTestPartResult",
"ListenerTest::TearDown", "ListenerTest::TearDown",
"TestEventListener::OnTestEnd", "2nd.OnTestEnd",
"1st.OnTestEnd",
"ListenerTest::TearDownTestCase", "ListenerTest::TearDownTestCase",
"TestEventListener::OnTestCaseEnd", "2nd.OnTestCaseEnd",
"TestEventListener::OnGlobalTearDownStart", "1st.OnTestCaseEnd",
"1st.OnEnvironmentsTearDownStart",
"2nd.OnEnvironmentsTearDownStart",
"Environment::TearDown", "Environment::TearDown",
"TestEventListener::OnGlobalTearDownEnd", "2nd.OnEnvironmentsTearDownEnd",
"TestEventListener::OnUnitTestEnd" "1st.OnEnvironmentsTearDownEnd",
"2nd.OnTestIterationEnd(0)",
"1st.OnTestIterationEnd(0)",
"1st.OnTestIterationStart(1)",
"2nd.OnTestIterationStart(1)",
"1st.OnEnvironmentsSetUpStart",
"2nd.OnEnvironmentsSetUpStart",
"Environment::SetUp",
"2nd.OnEnvironmentsSetUpEnd",
"1st.OnEnvironmentsSetUpEnd",
"1st.OnTestCaseStart",
"2nd.OnTestCaseStart",
"ListenerTest::SetUpTestCase",
"1st.OnTestStart",
"2nd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"ListenerTest::TearDown",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"1st.OnTestStart",
"2nd.OnTestStart",
"ListenerTest::SetUp",
"ListenerTest::* Test Body",
"1st.OnTestPartResult",
"2nd.OnTestPartResult",
"ListenerTest::TearDown",
"2nd.OnTestEnd",
"1st.OnTestEnd",
"ListenerTest::TearDownTestCase",
"2nd.OnTestCaseEnd",
"1st.OnTestCaseEnd",
"1st.OnEnvironmentsTearDownStart",
"2nd.OnEnvironmentsTearDownStart",
"Environment::TearDown",
"2nd.OnEnvironmentsTearDownEnd",
"1st.OnEnvironmentsTearDownEnd",
"2nd.OnTestIterationEnd(1)",
"1st.OnTestIterationEnd(1)",
"2nd.OnTestProgramEnd",
"1st.OnTestProgramEnd"
}; };
const int kExpectedEventsSize = VerifyResults(events,
sizeof(expected_events)/sizeof(expected_events[0]); expected_events,
sizeof(expected_events)/sizeof(expected_events[0]));
// Cannot use ASSERT_EQ() here because it requires the scoping function to
// return void.
GTEST_CHECK_(events.size() == kExpectedEventsSize);
for (int i = 0; i < events.size(); ++i)
GTEST_CHECK_(String(events.GetElement(i)) == expected_events[i])
<< "At position " << i;
// We need to check manually for ad hoc test failures that happen after // We need to check manually for ad hoc test failures that happen after
// RUN_ALL_TESTS finishes. // RUN_ALL_TESTS finishes.

View File

@ -6215,7 +6215,7 @@ class TestListener : public EmptyTestEventListener {
} }
protected: protected:
virtual void OnUnitTestStart(const UnitTest& /*unit_test*/) { virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {
if (on_start_counter_ != NULL) if (on_start_counter_ != NULL)
(*on_start_counter_)++; (*on_start_counter_)++;
} }
@ -6269,43 +6269,88 @@ TEST(EventListenersTest, Append) {
{ {
EventListeners listeners; EventListeners listeners;
listeners.Append(listener); listeners.Append(listener);
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
} }
EXPECT_TRUE(is_destroyed); EXPECT_TRUE(is_destroyed);
} }
// Tests that listeners receive requests in the order they were appended to // Tests that listeners receive events in the order they were appended to
// the list. // the list, except for *End requests, which must be received in the reverse
// order.
class SequenceTestingListener : public EmptyTestEventListener { class SequenceTestingListener : public EmptyTestEventListener {
public: public:
SequenceTestingListener(Vector<const char*>* vector, const char* signature) SequenceTestingListener(Vector<String>* vector, const char* id)
: vector_(vector), signature_(signature) {} : vector_(vector), id_(id) {}
protected: protected:
virtual void OnUnitTestStart(const UnitTest& /*unit_test*/) { virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {
if (vector_ != NULL) vector_->PushBack(GetEventDescription("OnTestProgramStart"));
vector_->PushBack(signature_); }
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {
vector_->PushBack(GetEventDescription("OnTestProgramEnd"));
}
virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
int /*iteration*/) {
vector_->PushBack(GetEventDescription("OnTestIterationStart"));
}
virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
int /*iteration*/) {
vector_->PushBack(GetEventDescription("OnTestIterationEnd"));
} }
private: private:
Vector<const char*>* vector_; String GetEventDescription(const char* method) {
const char* const signature_; Message message;
message << id_ << "." << method;
return message.GetString();
}
Vector<String>* vector_;
const char* const id_;
}; };
TEST(EventListenerTest, AppendKeepsOrder) { TEST(EventListenerTest, AppendKeepsOrder) {
Vector<const char*> vec; Vector<String> vec;
EventListeners listeners; EventListeners listeners;
listeners.Append(new SequenceTestingListener(&vec, "0")); listeners.Append(new SequenceTestingListener(&vec, "1st"));
listeners.Append(new SequenceTestingListener(&vec, "1")); listeners.Append(new SequenceTestingListener(&vec, "2nd"));
listeners.Append(new SequenceTestingListener(&vec, "2")); listeners.Append(new SequenceTestingListener(&vec, "3rd"));
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart(
EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
ASSERT_EQ(3, vec.size()); ASSERT_EQ(3, vec.size());
ASSERT_STREQ("0", vec.GetElement(0)); EXPECT_STREQ("1st.OnTestProgramStart", vec.GetElement(0).c_str());
ASSERT_STREQ("1", vec.GetElement(1)); EXPECT_STREQ("2nd.OnTestProgramStart", vec.GetElement(1).c_str());
ASSERT_STREQ("2", vec.GetElement(2)); EXPECT_STREQ("3rd.OnTestProgramStart", vec.GetElement(2).c_str());
vec.Clear();
EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
*UnitTest::GetInstance());
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("3rd.OnTestProgramEnd", vec.GetElement(0).c_str());
EXPECT_STREQ("2nd.OnTestProgramEnd", vec.GetElement(1).c_str());
EXPECT_STREQ("1st.OnTestProgramEnd", vec.GetElement(2).c_str());
vec.Clear();
EventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
*UnitTest::GetInstance(), 0);
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("1st.OnTestIterationStart", vec.GetElement(0).c_str());
EXPECT_STREQ("2nd.OnTestIterationStart", vec.GetElement(1).c_str());
EXPECT_STREQ("3rd.OnTestIterationStart", vec.GetElement(2).c_str());
vec.Clear();
EventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
*UnitTest::GetInstance(), 0);
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("3rd.OnTestIterationEnd", vec.GetElement(0).c_str());
EXPECT_STREQ("2nd.OnTestIterationEnd", vec.GetElement(1).c_str());
EXPECT_STREQ("1st.OnTestIterationEnd", vec.GetElement(2).c_str());
} }
// Tests that a listener removed from an EventListeners list stops receiving // Tests that a listener removed from an EventListeners list stops receiving
@ -6321,7 +6366,7 @@ TEST(EventListenersTest, Release) {
EventListeners listeners; EventListeners listeners;
listeners.Append(listener); listeners.Append(listener);
EXPECT_EQ(listener, listeners.Release(listener)); EXPECT_EQ(listener, listeners.Release(listener));
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_TRUE(listeners.Release(listener) == NULL); EXPECT_TRUE(listeners.Release(listener) == NULL);
} }
@ -6340,7 +6385,7 @@ TEST(EventListenerTest, SuppressEventForwarding) {
ASSERT_TRUE(EventListenersAccessor::EventForwardingEnabled(listeners)); ASSERT_TRUE(EventListenersAccessor::EventForwardingEnabled(listeners));
EventListenersAccessor::SuppressEventForwarding(&listeners); EventListenersAccessor::SuppressEventForwarding(&listeners);
ASSERT_FALSE(EventListenersAccessor::EventForwardingEnabled(listeners)); ASSERT_FALSE(EventListenersAccessor::EventForwardingEnabled(listeners));
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
} }
@ -6367,7 +6412,7 @@ TEST(EventListenerTest, default_result_printer) {
EXPECT_EQ(listener, listeners.default_result_printer()); EXPECT_EQ(listener, listeners.default_result_printer());
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
@ -6381,7 +6426,7 @@ TEST(EventListenerTest, default_result_printer) {
// After broadcasting an event the counter is still the same, indicating // After broadcasting an event the counter is still the same, indicating
// the listener is not in the list anymore. // the listener is not in the list anymore.
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
} }
@ -6404,7 +6449,7 @@ TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
EXPECT_FALSE(is_destroyed); EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_result_printer. // Broadcasting events now should not affect default_result_printer.
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
} }
@ -6426,7 +6471,7 @@ TEST(EventListenerTest, default_xml_generator) {
EXPECT_EQ(listener, listeners.default_xml_generator()); EXPECT_EQ(listener, listeners.default_xml_generator());
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
@ -6440,7 +6485,7 @@ TEST(EventListenerTest, default_xml_generator) {
// After broadcasting an event the counter is still the same, indicating // After broadcasting an event the counter is still the same, indicating
// the listener is not in the list anymore. // the listener is not in the list anymore.
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter); EXPECT_EQ(1, on_start_counter);
} }
@ -6463,7 +6508,7 @@ TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
EXPECT_FALSE(is_destroyed); EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_xml_generator. // Broadcasting events now should not affect default_xml_generator.
EventListenersAccessor::GetRepeater(&listeners)->OnUnitTestStart( EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance()); *UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter); EXPECT_EQ(0, on_start_counter);
} }