summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-30 20:23:50 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-09-30 20:23:50 +0000
commitf6d087b78d230d875bf5d8281112662795044680 (patch)
tree37e8c4680f5f6763c18aaa2739446c8ba08501f4 /test
parentfff033497b70e96a5dcadb6ba9570c12b5921d74 (diff)
downloadgoogletest-f6d087b78d230d875bf5d8281112662795044680.tar.gz
Makes gtest compile cleanly with MSVC's /W4 (by Zhanyong Wan).
Renames EventListenrs to TestEventListeners (by Zhanyong Wan). Fixes invalid characters in XML report (by Vlad Losev). Refacotrs SConscript (by Vlad Losev). git-svn-id: http://googletest.googlecode.com/svn/trunk@321 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test')
-rw-r--r--test/gtest-death-test_test.cc19
-rw-r--r--test/gtest-port_test.cc6
-rw-r--r--test/gtest-typed-test_test.cc10
-rw-r--r--test/gtest_repeat_test.cc4
-rw-r--r--test/gtest_unittest.cc156
-rwxr-xr-xtest/gtest_xml_output_unittest.py16
-rw-r--r--test/gtest_xml_output_unittest_.cc15
-rwxr-xr-xtest/gtest_xml_test_utils.py48
8 files changed, 154 insertions, 120 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc
index 7cc4caf..7bf6a71 100644
--- a/test/gtest-death-test_test.cc
+++ b/test/gtest-death-test_test.cc
@@ -35,6 +35,9 @@
#include <gtest/gtest.h>
#include <gtest/internal/gtest-filepath.h>
+using testing::internal::AlwaysFalse;
+using testing::internal::AlwaysTrue;
+
#if GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS
@@ -271,21 +274,21 @@ TEST(ExitStatusPredicateTest, KilledBySignal) {
// be followed by operator<<, and that in either case the complete text
// comprises only a single C++ statement.
TEST_F(TestForDeathTest, SingleStatement) {
- if (false)
+ if (AlwaysFalse())
// This would fail if executed; this is a compilation test only
ASSERT_DEATH(return, "");
- if (true)
+ if (AlwaysTrue())
EXPECT_DEATH(_exit(1), "");
else
// This empty "else" branch is meant to ensure that EXPECT_DEATH
// doesn't expand into an "if" statement without an "else"
;
- if (false)
+ if (AlwaysFalse())
ASSERT_DEATH(return, "") << "did not die";
- if (false)
+ if (AlwaysFalse())
;
else
EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3;
@@ -1188,21 +1191,21 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
//
// The syntax should work whether death tests are available or not.
TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
- if (false)
+ if (AlwaysFalse())
// This would fail if executed; this is a compilation test only
ASSERT_DEATH_IF_SUPPORTED(return, "");
- if (true)
+ if (AlwaysTrue())
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "");
else
// This empty "else" branch is meant to ensure that EXPECT_DEATH
// doesn't expand into an "if" statement without an "else"
; // NOLINT
- if (false)
+ if (AlwaysFalse())
ASSERT_DEATH_IF_SUPPORTED(return, "") << "did not die";
- if (false)
+ if (AlwaysFalse())
; // NOLINT
else
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3;
diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc
index 9785951..df59f9e 100644
--- a/test/gtest-port_test.cc
+++ b/test/gtest-port_test.cc
@@ -54,16 +54,16 @@ namespace testing {
namespace internal {
TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
- if (false)
+ if (AlwaysFalse())
GTEST_CHECK_(false) << "This should never be executed; "
"It's a compilation test only.";
- if (true)
+ if (AlwaysTrue())
GTEST_CHECK_(true);
else
; // NOLINT
- if (false)
+ if (AlwaysFalse())
; // NOLINT
else
GTEST_CHECK_(true) << "";
diff --git a/test/gtest-typed-test_test.cc b/test/gtest-typed-test_test.cc
index e97598f..4b6e971 100644
--- a/test/gtest-typed-test_test.cc
+++ b/test/gtest-typed-test_test.cc
@@ -29,8 +29,8 @@
//
// Author: wan@google.com (Zhanyong Wan)
-#include <list>
#include <set>
+#include <vector>
#include "test/gtest-typed-test_test.h"
#include <gtest/gtest.h>
@@ -57,7 +57,9 @@ class CommonTest : public Test {
// This 'protected:' is optional. There's no harm in making all
// members of this fixture class template public.
protected:
- typedef std::list<T> List;
+ // We used to use std::list here, but switched to std::vector since
+ // MSVC's <list> doesn't compile cleanly with /W4.
+ typedef std::vector<T> Vector;
typedef std::set<int> IntSet;
CommonTest() : value_(1) {}
@@ -99,7 +101,7 @@ TYPED_TEST(CommonTest, ValuesAreCorrect) {
// Typedefs in the fixture class template can be visited via the
// "typename TestFixture::" prefix.
- typename TestFixture::List empty;
+ typename TestFixture::Vector empty;
EXPECT_EQ(0U, empty.size());
typename TestFixture::IntSet empty2;
@@ -314,7 +316,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(Double, TypedTestP2, Types<double>);
// Tests that the same type-parameterized test case can be
// instantiated in different translation units linked together.
// (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
-typedef Types<std::list<double>, std::set<char> > MyContainers;
+typedef Types<std::vector<double>, std::set<char> > MyContainers;
INSTANTIATE_TYPED_TEST_CASE_P(My, ContainerTest, MyContainers);
// Tests that a type-parameterized test case can be defined and
diff --git a/test/gtest_repeat_test.cc b/test/gtest_repeat_test.cc
index 8ec3700..df6868b 100644
--- a/test/gtest_repeat_test.cc
+++ b/test/gtest_repeat_test.cc
@@ -64,14 +64,14 @@ namespace {
do {\
const int expected_val = (expected);\
const int actual_val = (actual);\
- if (expected_val != actual_val) {\
+ if (::testing::internal::IsTrue(expected_val != actual_val)) {\
::std::cout << "Value of: " #actual "\n"\
<< " Actual: " << actual_val << "\n"\
<< "Expected: " #expected "\n"\
<< "Which is: " << expected_val << "\n";\
abort();\
}\
- } while(false)
+ } while(::testing::internal::AlwaysFalse())
// Used for verifying that global environment set-up and tear-down are
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index 03acfb0..ba39ae6 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -80,32 +80,33 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
namespace testing {
namespace internal {
-const char* FormatTimeInMillisAsSeconds(TimeInMillis ms);
+bool ShouldUseColor(bool stdout_is_tty);
+const char* FormatTimeInMillisAsSeconds(TimeInMillis ms);
bool ParseInt32Flag(const char* str, const char* flag, Int32* value);
-// Provides access to otherwise private parts of the EventListeners class
+// Provides access to otherwise private parts of the TestEventListeners class
// that are needed to test it.
-class EventListenersAccessor {
+class TestEventListenersAccessor {
public:
- static TestEventListener* GetRepeater(EventListeners* listeners) {
+ static TestEventListener* GetRepeater(TestEventListeners* listeners) {
return listeners->repeater();
}
- static void SetDefaultResultPrinter(EventListeners* listeners,
+ static void SetDefaultResultPrinter(TestEventListeners* listeners,
TestEventListener* listener) {
listeners->SetDefaultResultPrinter(listener);
}
- static void SetDefaultXmlGenerator(EventListeners* listeners,
+ static void SetDefaultXmlGenerator(TestEventListeners* listeners,
TestEventListener* listener) {
listeners->SetDefaultXmlGenerator(listener);
}
- static bool EventForwardingEnabled(const EventListeners& listeners) {
+ static bool EventForwardingEnabled(const TestEventListeners& listeners) {
return listeners.EventForwardingEnabled();
}
- static void SuppressEventForwarding(EventListeners* listeners) {
+ static void SuppressEventForwarding(TestEventListeners* listeners) {
listeners->SuppressEventForwarding();
}
};
@@ -113,26 +114,11 @@ class EventListenersAccessor {
} // namespace internal
} // namespace testing
-using testing::internal::FormatTimeInMillisAsSeconds;
-using testing::internal::ParseInt32Flag;
-using testing::internal::EventListenersAccessor;
-
-namespace testing {
-
-GTEST_DECLARE_string_(output);
-GTEST_DECLARE_string_(color);
-
-namespace internal {
-bool ShouldUseColor(bool stdout_is_tty);
-} // namespace internal
-} // namespace testing
-
using testing::AssertionFailure;
using testing::AssertionResult;
using testing::AssertionSuccess;
using testing::DoubleLE;
using testing::EmptyTestEventListener;
-using testing::EventListeners;
using testing::FloatLE;
using testing::GTEST_FLAG(also_run_disabled_tests);
using testing::GTEST_FLAG(break_on_failure);
@@ -155,16 +141,20 @@ using testing::Message;
using testing::ScopedFakeTestPartResultReporter;
using testing::StaticAssertTypeEq;
using testing::Test;
+using testing::TestEventListeners;
using testing::TestCase;
using testing::TestPartResult;
using testing::TestPartResultArray;
using testing::TestProperty;
using testing::TestResult;
using testing::UnitTest;
+using testing::internal::AlwaysFalse;
+using testing::internal::AlwaysTrue;
using testing::internal::AppendUserMessage;
using testing::internal::CodePointToUtf8;
using testing::internal::EqFailure;
using testing::internal::FloatingPoint;
+using testing::internal::FormatTimeInMillisAsSeconds;
using testing::internal::GTestFlagSaver;
using testing::internal::GetCurrentOsStackTraceExceptTop;
using testing::internal::GetNextRandomSeed;
@@ -174,11 +164,13 @@ using testing::internal::GetTypeId;
using testing::internal::GetUnitTestImpl;
using testing::internal::Int32;
using testing::internal::Int32FromEnvOrDie;
+using testing::internal::ParseInt32Flag;
using testing::internal::ShouldRunTestOnShard;
using testing::internal::ShouldShard;
using testing::internal::ShouldUseColor;
using testing::internal::StreamableToString;
using testing::internal::String;
+using testing::internal::TestEventListenersAccessor;
using testing::internal::TestResultAccessor;
using testing::internal::ThreadLocal;
using testing::internal::UInt32;
@@ -3880,19 +3872,19 @@ TEST(HRESULTAssertionTest, Streaming) {
// Tests that the assertion macros behave like single statements.
TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
- if (false)
+ if (AlwaysFalse())
ASSERT_TRUE(false) << "This should never be executed; "
"It's a compilation test only.";
- if (true)
+ if (AlwaysTrue())
EXPECT_FALSE(false);
else
; // NOLINT
- if (false)
+ if (AlwaysFalse())
ASSERT_LT(1, 3);
- if (false)
+ if (AlwaysFalse())
; // NOLINT
else
EXPECT_GT(3, 2) << "";
@@ -3914,26 +3906,26 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
}
TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
- if (false)
+ if (AlwaysFalse())
EXPECT_THROW(ThrowNothing(), bool);
- if (true)
+ if (AlwaysTrue())
EXPECT_THROW(ThrowAnInteger(), int);
else
; // NOLINT
- if (false)
+ if (AlwaysFalse())
EXPECT_NO_THROW(ThrowAnInteger());
- if (true)
+ if (AlwaysTrue())
EXPECT_NO_THROW(ThrowNothing());
else
; // NOLINT
- if (false)
+ if (AlwaysFalse())
EXPECT_ANY_THROW(ThrowNothing());
- if (true)
+ if (AlwaysTrue())
EXPECT_ANY_THROW(ThrowAnInteger());
else
; // NOLINT
@@ -3941,23 +3933,23 @@ TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
#endif // GTEST_HAS_EXCEPTIONS
TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
- if (false)
+ if (AlwaysFalse())
EXPECT_NO_FATAL_FAILURE(FAIL()) << "This should never be executed. "
<< "It's a compilation test only.";
else
; // NOLINT
- if (false)
+ if (AlwaysFalse())
ASSERT_NO_FATAL_FAILURE(FAIL()) << "";
else
; // NOLINT
- if (true)
+ if (AlwaysTrue())
EXPECT_NO_FATAL_FAILURE(SUCCEED());
else
; // NOLINT
- if (false)
+ if (AlwaysFalse())
; // NOLINT
else
ASSERT_NO_FATAL_FAILURE(SUCCEED());
@@ -6272,17 +6264,17 @@ class TestListener : public EmptyTestEventListener {
};
// Tests the constructor.
-TEST(EventListenersTest, ConstructionWorks) {
- EventListeners listeners;
+TEST(TestEventListenersTest, ConstructionWorks) {
+ TestEventListeners listeners;
- EXPECT_TRUE(EventListenersAccessor::GetRepeater(&listeners) != NULL);
+ EXPECT_TRUE(TestEventListenersAccessor::GetRepeater(&listeners) != NULL);
EXPECT_TRUE(listeners.default_result_printer() == NULL);
EXPECT_TRUE(listeners.default_xml_generator() == NULL);
}
-// Tests that the EventListeners destructor deletes all the listeners it
+// Tests that the TestEventListeners destructor deletes all the listeners it
// owns.
-TEST(EventListenersTest, DestructionWorks) {
+TEST(TestEventListenersTest, DestructionWorks) {
bool default_result_printer_is_destroyed = false;
bool default_xml_printer_is_destroyed = false;
bool extra_listener_is_destroyed = false;
@@ -6294,11 +6286,11 @@ TEST(EventListenersTest, DestructionWorks) {
NULL, &extra_listener_is_destroyed);
{
- EventListeners listeners;
- EventListenersAccessor::SetDefaultResultPrinter(&listeners,
- default_result_printer);
- EventListenersAccessor::SetDefaultXmlGenerator(&listeners,
- default_xml_printer);
+ TestEventListeners listeners;
+ TestEventListenersAccessor::SetDefaultResultPrinter(&listeners,
+ default_result_printer);
+ TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners,
+ default_xml_printer);
listeners.Append(extra_listener);
}
EXPECT_TRUE(default_result_printer_is_destroyed);
@@ -6306,16 +6298,16 @@ TEST(EventListenersTest, DestructionWorks) {
EXPECT_TRUE(extra_listener_is_destroyed);
}
-// Tests that a listener Append'ed to an EventListeners list starts
+// Tests that a listener Append'ed to a TestEventListeners list starts
// receiving events.
-TEST(EventListenersTest, Append) {
+TEST(TestEventListenersTest, Append) {
int on_start_counter = 0;
bool is_destroyed = false;
TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
{
- EventListeners listeners;
+ TestEventListeners listeners;
listeners.Append(listener);
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter);
}
@@ -6364,12 +6356,12 @@ class SequenceTestingListener : public EmptyTestEventListener {
TEST(EventListenerTest, AppendKeepsOrder) {
Vector<String> vec;
- EventListeners listeners;
+ TestEventListeners listeners;
listeners.Append(new SequenceTestingListener(&vec, "1st"));
listeners.Append(new SequenceTestingListener(&vec, "2nd"));
listeners.Append(new SequenceTestingListener(&vec, "3rd"));
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("1st.OnTestProgramStart", vec.GetElement(0).c_str());
@@ -6377,7 +6369,7 @@ TEST(EventListenerTest, AppendKeepsOrder) {
EXPECT_STREQ("3rd.OnTestProgramStart", vec.GetElement(2).c_str());
vec.Clear();
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramEnd(
*UnitTest::GetInstance());
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("3rd.OnTestProgramEnd", vec.GetElement(0).c_str());
@@ -6385,7 +6377,7 @@ TEST(EventListenerTest, AppendKeepsOrder) {
EXPECT_STREQ("1st.OnTestProgramEnd", vec.GetElement(2).c_str());
vec.Clear();
- EventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationStart(
*UnitTest::GetInstance(), 0);
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("1st.OnTestIterationStart", vec.GetElement(0).c_str());
@@ -6393,7 +6385,7 @@ TEST(EventListenerTest, AppendKeepsOrder) {
EXPECT_STREQ("3rd.OnTestIterationStart", vec.GetElement(2).c_str());
vec.Clear();
- EventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestIterationEnd(
*UnitTest::GetInstance(), 0);
ASSERT_EQ(3, vec.size());
EXPECT_STREQ("3rd.OnTestIterationEnd", vec.GetElement(0).c_str());
@@ -6401,9 +6393,9 @@ TEST(EventListenerTest, AppendKeepsOrder) {
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 a TestEventListeners list stops receiving
// events and is not deleted when the list is destroyed.
-TEST(EventListenersTest, Release) {
+TEST(TestEventListenersTest, Release) {
int on_start_counter = 0;
bool is_destroyed = false;
// Although Append passes the ownership of this object to the list,
@@ -6411,10 +6403,10 @@ TEST(EventListenersTest, Release) {
// test ends.
TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
{
- EventListeners listeners;
+ TestEventListeners listeners;
listeners.Append(listener);
EXPECT_EQ(listener, listeners.Release(listener));
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_TRUE(listeners.Release(listener) == NULL);
}
@@ -6428,12 +6420,12 @@ TEST(EventListenerTest, SuppressEventForwarding) {
int on_start_counter = 0;
TestListener* listener = new TestListener(&on_start_counter, NULL);
- EventListeners listeners;
+ TestEventListeners listeners;
listeners.Append(listener);
- ASSERT_TRUE(EventListenersAccessor::EventForwardingEnabled(listeners));
- EventListenersAccessor::SuppressEventForwarding(&listeners);
- ASSERT_FALSE(EventListenersAccessor::EventForwardingEnabled(listeners));
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ ASSERT_TRUE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
+ TestEventListenersAccessor::SuppressEventForwarding(&listeners);
+ ASSERT_FALSE(TestEventListenersAccessor::EventForwardingEnabled(listeners));
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter);
}
@@ -6442,7 +6434,7 @@ TEST(EventListenerTest, SuppressEventForwarding) {
// death test subprocesses.
TEST(EventListenerDeathTest, EventsNotForwardedInDeathTestSubprecesses) {
EXPECT_DEATH_IF_SUPPORTED({
- GTEST_CHECK_(EventListenersAccessor::EventForwardingEnabled(
+ GTEST_CHECK_(TestEventListenersAccessor::EventForwardingEnabled(
*GetUnitTestImpl()->listeners())) << "expected failure";},
"expected failure");
}
@@ -6455,26 +6447,26 @@ TEST(EventListenerTest, default_result_printer) {
bool is_destroyed = false;
TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
- EventListeners listeners;
- EventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
+ TestEventListeners listeners;
+ TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
EXPECT_EQ(listener, listeners.default_result_printer());
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter);
// Replacing default_result_printer with something else should remove it
// from the list and destroy it.
- EventListenersAccessor::SetDefaultResultPrinter(&listeners, NULL);
+ TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, NULL);
EXPECT_TRUE(listeners.default_result_printer() == NULL);
EXPECT_TRUE(is_destroyed);
// After broadcasting an event the counter is still the same, indicating
// the listener is not in the list anymore.
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter);
}
@@ -6489,15 +6481,15 @@ TEST(EventListenerTest, RemovingDefaultResultPrinterWorks) {
// test ends.
TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
{
- EventListeners listeners;
- EventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
+ TestEventListeners listeners;
+ TestEventListenersAccessor::SetDefaultResultPrinter(&listeners, listener);
EXPECT_EQ(listener, listeners.Release(listener));
EXPECT_TRUE(listeners.default_result_printer() == NULL);
EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_result_printer.
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter);
}
@@ -6514,26 +6506,26 @@ TEST(EventListenerTest, default_xml_generator) {
bool is_destroyed = false;
TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
- EventListeners listeners;
- EventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
+ TestEventListeners listeners;
+ TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
EXPECT_EQ(listener, listeners.default_xml_generator());
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter);
// Replacing default_xml_generator with something else should remove it
// from the list and destroy it.
- EventListenersAccessor::SetDefaultXmlGenerator(&listeners, NULL);
+ TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, NULL);
EXPECT_TRUE(listeners.default_xml_generator() == NULL);
EXPECT_TRUE(is_destroyed);
// After broadcasting an event the counter is still the same, indicating
// the listener is not in the list anymore.
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(1, on_start_counter);
}
@@ -6548,15 +6540,15 @@ TEST(EventListenerTest, RemovingDefaultXmlGeneratorWorks) {
// test ends.
TestListener* listener = new TestListener(&on_start_counter, &is_destroyed);
{
- EventListeners listeners;
- EventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
+ TestEventListeners listeners;
+ TestEventListenersAccessor::SetDefaultXmlGenerator(&listeners, listener);
EXPECT_EQ(listener, listeners.Release(listener));
EXPECT_TRUE(listeners.default_xml_generator() == NULL);
EXPECT_FALSE(is_destroyed);
// Broadcasting events now should not affect default_xml_generator.
- EventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
+ TestEventListenersAccessor::GetRepeater(&listeners)->OnTestProgramStart(
*UnitTest::GetInstance());
EXPECT_EQ(0, on_start_counter);
}
diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py
index 3ee6846..6d44929 100755
--- a/test/gtest_xml_output_unittest.py
+++ b/test/gtest_xml_output_unittest.py
@@ -54,7 +54,7 @@ else:
STACK_TRACE_TEMPLATE = ""
EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
-<testsuites tests="13" failures="2" disabled="2" errors="0" time="*" name="AllTests">
+<testsuites tests="15" failures="4" disabled="2" errors="0" time="*" name="AllTests">
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
</testsuite>
@@ -77,6 +77,20 @@ Expected: 2%(stack)s]]></failure>
</testcase>
<testcase name="DISABLED_test" status="notrun" time="*" classname="MixedResultTest"/>
</testsuite>
+ <testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" errors="0" time="*">
+ <testcase name="OutputsCData" status="run" time="*" classname="XmlQuotingTest">
+ <failure message="Failed&#x0A;XML output: &lt;?xml encoding=&quot;utf-8&quot;&gt;&lt;top&gt;&lt;![CDATA[cdata text]]&gt;&lt;/top&gt;" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
+Failed
+XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]&gt;<![CDATA[</top>%(stack)s]]></failure>
+ </testcase>
+ </testsuite>
+ <testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" errors="0" time="*">
+ <testcase name="InvalidCharactersInMessage" status="run" time="*" classname="InvalidCharactersTest">
+ <failure message="Failed&#x0A;Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
+Failed
+Invalid characters in brackets []%(stack)s]]></failure>
+ </testcase>
+ </testsuite>
<testsuite name="DisabledTest" tests="1" failures="0" disabled="1" errors="0" time="*">
<testcase name="DISABLED_test_not_run" status="notrun" time="*" classname="DisabledTest"/>
</testsuite>
diff --git a/test/gtest_xml_output_unittest_.cc b/test/gtest_xml_output_unittest_.cc
index c0da215..fc07ef4 100644
--- a/test/gtest_xml_output_unittest_.cc
+++ b/test/gtest_xml_output_unittest_.cc
@@ -40,8 +40,8 @@
#include <gtest/gtest.h>
-using ::testing::EventListeners;
using ::testing::InitGoogleTest;
+using ::testing::TestEventListeners;
using ::testing::UnitTest;
class SuccessfulTest : public testing::Test {
@@ -80,6 +80,17 @@ TEST(MixedResultTest, DISABLED_test) {
FAIL() << "Unexpected failure: Disabled test should not be run";
}
+TEST(XmlQuotingTest, OutputsCData) {
+ FAIL() << "XML output: "
+ "<?xml encoding=\"utf-8\"><top><![CDATA[cdata text]]></top>";
+}
+
+// Helps to test that invalid characters produced by test code do not make
+// it into the XML file.
+TEST(InvalidCharactersTest, InvalidCharactersInMessage) {
+ FAIL() << "Invalid characters in brackets [\x1\x2]";
+}
+
class PropertyRecordingTest : public testing::Test {
};
@@ -127,7 +138,7 @@ int main(int argc, char** argv) {
InitGoogleTest(&argc, argv);
if (argc > 1 && strcmp(argv[1], "--shut_down_xml") == 0) {
- EventListeners& listeners = UnitTest::GetInstance()->listeners();
+ TestEventListeners& listeners = UnitTest::GetInstance()->listeners();
delete listeners.Release(listeners.default_xml_generator());
}
return RUN_ALL_TESTS();
diff --git a/test/gtest_xml_test_utils.py b/test/gtest_xml_test_utils.py
index 1811c40..c83c3b7 100755
--- a/test/gtest_xml_test_utils.py
+++ b/test/gtest_xml_test_utils.py
@@ -77,19 +77,29 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
expected_attributes = expected_node.attributes
actual_attributes = actual_node .attributes
- self.assertEquals(expected_attributes.length, actual_attributes.length)
+ self.assertEquals(
+ expected_attributes.length, actual_attributes.length,
+ "attribute numbers differ in element " + actual_node.tagName)
for i in range(expected_attributes.length):
expected_attr = expected_attributes.item(i)
actual_attr = actual_attributes.get(expected_attr.name)
- self.assert_(actual_attr is not None)
- self.assertEquals(expected_attr.value, actual_attr.value)
+ self.assert_(
+ actual_attr is not None,
+ "expected attribute %s not found in element %s" %
+ (expected_attr.name, actual_node.tagName))
+ self.assertEquals(expected_attr.value, actual_attr.value,
+ " values of attribute %s in element %s differ" %
+ (expected_attr.name, actual_node.tagName))
expected_children = self._GetChildren(expected_node)
actual_children = self._GetChildren(actual_node)
- self.assertEquals(len(expected_children), len(actual_children))
+ self.assertEquals(
+ len(expected_children), len(actual_children),
+ "number of child elements differ in element " + actual_node.tagName)
for child_id, child in expected_children.iteritems():
self.assert_(child_id in actual_children,
- '<%s> is not in <%s>' % (child_id, actual_children))
+ '<%s> is not in <%s> (in element %s)' %
+ (child_id, actual_children, actual_node.tagName))
self.AssertEquivalentNodes(child, actual_children[child_id])
identifying_attribute = {
@@ -103,14 +113,13 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
"""
Fetches all of the child nodes of element, a DOM Element object.
Returns them as the values of a dictionary keyed by the IDs of the
- children. For <testsuites>, <testsuite> and <testcase> elements,
- the ID is the value of their "name" attribute; for <failure>
- elements, it is the value of the "message" attribute; for CDATA
- section node, it is "detail". An exception is raised if any
- element other than the above four is encountered, if two child
- elements with the same identifying attributes are encountered, or
- if any other type of node is encountered, other than Text nodes
- containing only whitespace.
+ children. For <testsuites>, <testsuite> and <testcase> elements, the ID
+ is the value of their "name" attribute; for <failure> elements, it is
+ the value of the "message" attribute; CDATA sections and non-whitespace
+ text nodes are concatenated into a single CDATA section with ID
+ "detail". An exception is raised if any element other than the above
+ four is encountered, if two child elements with the same identifying
+ attributes are encountered, or if any other type of node is encountered.
"""
children = {}
@@ -121,11 +130,14 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
childID = child.getAttribute(self.identifying_attribute[child.tagName])
self.assert_(childID not in children)
children[childID] = child
- elif child.nodeType == Node.TEXT_NODE:
- self.assert_(child.nodeValue.isspace())
- elif child.nodeType == Node.CDATA_SECTION_NODE:
- self.assert_("detail" not in children)
- children["detail"] = child
+ elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
+ if "detail" not in children:
+ if (child.nodeType == Node.CDATA_SECTION_NODE or
+ not child.nodeValue.isspace()):
+ children["detail"] = child.ownerDocument.createCDATASection(
+ child.nodeValue)
+ else:
+ children["detail"].nodeValue += child.nodeValue
else:
self.fail("Encountered unexpected node type %d" % child.nodeType)
return children