"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/test/googletest-listener-test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

googletest-listener-test.cc  (googletest-release-1.11.0):googletest-listener-test.cc  (googletest-release-1.12.0)
skipping to change at line 44 skipping to change at line 44
#include <vector> #include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/custom/gtest.h" #include "gtest/internal/custom/gtest.h"
using ::testing::AddGlobalTestEnvironment; using ::testing::AddGlobalTestEnvironment;
using ::testing::Environment; using ::testing::Environment;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
using ::testing::TestSuite;
using ::testing::TestEventListener; using ::testing::TestEventListener;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
using ::testing::TestSuite;
using ::testing::UnitTest; using ::testing::UnitTest;
// Used by tests to register their events. // Used by tests to register their events.
std::vector<std::string>* g_events = nullptr; std::vector<std::string>* g_events = nullptr;
namespace testing { namespace testing {
namespace internal { namespace internal {
class EventRecordingListener : public TestEventListener { class EventRecordingListener : public TestEventListener {
public: public:
explicit EventRecordingListener(const char* name) : name_(name) {} explicit EventRecordingListener(const char* name) : name_(name) {}
protected: protected:
void OnTestProgramStart(const UnitTest& /*unit_test*/) override { void OnTestProgramStart(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnTestProgramStart")); g_events->push_back(GetFullMethodName("OnTestProgramStart"));
} }
void OnTestIterationStart(const UnitTest& /*unit_test*/, void OnTestIterationStart(const UnitTest& /*unit_test*/,
int iteration) override { int iteration) override {
Message message; Message message;
message << GetFullMethodName("OnTestIterationStart") message << GetFullMethodName("OnTestIterationStart") << "(" << iteration
<< "(" << iteration << ")"; << ")";
g_events->push_back(message.GetString()); g_events->push_back(message.GetString());
} }
void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override { void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart")); g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart"));
} }
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override { void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd")); g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
} }
skipping to change at line 115 skipping to change at line 115
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart")); g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
} }
void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override { void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd")); g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd"));
} }
void OnTestIterationEnd(const UnitTest& /*unit_test*/, void OnTestIterationEnd(const UnitTest& /*unit_test*/,
int iteration) override { int iteration) override {
Message message; Message message;
message << GetFullMethodName("OnTestIterationEnd") message << GetFullMethodName("OnTestIterationEnd") << "(" << iteration
<< "(" << iteration << ")"; << ")";
g_events->push_back(message.GetString()); g_events->push_back(message.GetString());
} }
void OnTestProgramEnd(const UnitTest& /*unit_test*/) override { void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {
g_events->push_back(GetFullMethodName("OnTestProgramEnd")); g_events->push_back(GetFullMethodName("OnTestProgramEnd"));
} }
private: private:
std::string GetFullMethodName(const char* name) { std::string GetFullMethodName(const char* name) { return name_ + "." + name; }
return name_ + "." + name;
}
std::string name_; std::string name_;
}; };
// This listener is using OnTestSuiteStart, OnTestSuiteEnd API // This listener is using OnTestSuiteStart, OnTestSuiteEnd API
class EventRecordingListener2 : public TestEventListener { class EventRecordingListener2 : public TestEventListener {
public: public:
explicit EventRecordingListener2(const char* name) : name_(name) {} explicit EventRecordingListener2(const char* name) : name_(name) {}
protected: protected:
skipping to change at line 255 skipping to change at line 253
void VerifyResults(const std::vector<std::string>& data, void VerifyResults(const std::vector<std::string>& data,
const char* const* expected_data, const char* const* expected_data,
size_t expected_data_size) { size_t expected_data_size) {
const size_t actual_size = data.size(); const size_t actual_size = data.size();
// If the following assertion fails, a new entry will be appended to // If the following assertion fails, a new entry will be appended to
// data. Hence we save data.size() first. // data. Hence we save data.size() first.
EXPECT_EQ(expected_data_size, actual_size); EXPECT_EQ(expected_data_size, actual_size);
// Compares the common prefix. // Compares the common prefix.
const size_t shorter_size = expected_data_size <= actual_size ? const size_t shorter_size =
expected_data_size : actual_size; expected_data_size <= actual_size ? expected_data_size : actual_size;
size_t i = 0; size_t i = 0;
for (; i < shorter_size; ++i) { for (; i < shorter_size; ++i) {
ASSERT_STREQ(expected_data[i], data[i].c_str()) ASSERT_STREQ(expected_data[i], data[i].c_str()) << "at position " << i;
<< "at position " << i;
} }
// Prints extra elements in the actual data. // Prints extra elements in the actual data.
for (; i < actual_size; ++i) { for (; i < actual_size; ++i) {
printf(" Actual event #%lu: %s\n", printf(" Actual event #%lu: %s\n", static_cast<unsigned long>(i),
static_cast<unsigned long>(i), data[i].c_str()); data[i].c_str());
} }
} }
int main(int argc, char **argv) { int main(int argc, char** argv) {
std::vector<std::string> events; std::vector<std::string> events;
g_events = &events; g_events = &events;
InitGoogleTest(&argc, argv); InitGoogleTest(&argc, argv);
UnitTest::GetInstance()->listeners().Append( UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener("1st")); new EventRecordingListener("1st"));
UnitTest::GetInstance()->listeners().Append( UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener("2nd")); new EventRecordingListener("2nd"));
UnitTest::GetInstance()->listeners().Append( UnitTest::GetInstance()->listeners().Append(
new EventRecordingListener2("3rd")); new EventRecordingListener2("3rd"));
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; GTEST_FLAG_SET(repeat, 2);
GTEST_FLAG_SET(recreate_environments_when_repeating, true);
int ret_val = RUN_ALL_TESTS(); int ret_val = RUN_ALL_TESTS();
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
// The deprecated OnTestSuiteStart/OnTestCaseStart events are included // The deprecated OnTestSuiteStart/OnTestCaseStart events are included
const char* const expected_events[] = {"1st.OnTestProgramStart", const char* const expected_events[] = {"1st.OnTestProgramStart",
"2nd.OnTestProgramStart", "2nd.OnTestProgramStart",
"3rd.OnTestProgramStart", "3rd.OnTestProgramStart",
"1st.OnTestIterationStart(0)", "1st.OnTestIterationStart(0)",
"2nd.OnTestIterationStart(0)", "2nd.OnTestIterationStart(0)",
skipping to change at line 508 skipping to change at line 506
"2nd.OnEnvironmentsTearDownEnd", "2nd.OnEnvironmentsTearDownEnd",
"1st.OnEnvironmentsTearDownEnd", "1st.OnEnvironmentsTearDownEnd",
"3rd.OnTestIterationEnd(1)", "3rd.OnTestIterationEnd(1)",
"2nd.OnTestIterationEnd(1)", "2nd.OnTestIterationEnd(1)",
"1st.OnTestIterationEnd(1)", "1st.OnTestIterationEnd(1)",
"3rd.OnTestProgramEnd", "3rd.OnTestProgramEnd",
"2nd.OnTestProgramEnd", "2nd.OnTestProgramEnd",
"1st.OnTestProgramEnd"}; "1st.OnTestProgramEnd"};
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
VerifyResults(events, VerifyResults(events, expected_events,
expected_events, sizeof(expected_events) / sizeof(expected_events[0]));
sizeof(expected_events)/sizeof(expected_events[0]));
// 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.
if (UnitTest::GetInstance()->Failed()) if (UnitTest::GetInstance()->Failed()) ret_val = 1;
ret_val = 1;
return ret_val; return ret_val;
} }
 End of changes. 12 change blocks. 
21 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)