Commit f8b268ee authored by zhanyong.wan's avatar zhanyong.wan
Browse files

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).
parent b50ef44a
...@@ -77,19 +77,29 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): ...@@ -77,19 +77,29 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
expected_attributes = expected_node.attributes expected_attributes = expected_node.attributes
actual_attributes = actual_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): for i in range(expected_attributes.length):
expected_attr = expected_attributes.item(i) expected_attr = expected_attributes.item(i)
actual_attr = actual_attributes.get(expected_attr.name) actual_attr = actual_attributes.get(expected_attr.name)
self.assert_(actual_attr is not None) self.assert_(
self.assertEquals(expected_attr.value, actual_attr.value) 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) expected_children = self._GetChildren(expected_node)
actual_children = self._GetChildren(actual_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(): for child_id, child in expected_children.iteritems():
self.assert_(child_id in actual_children, 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]) self.AssertEquivalentNodes(child, actual_children[child_id])
identifying_attribute = { identifying_attribute = {
...@@ -103,14 +113,13 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): ...@@ -103,14 +113,13 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
""" """
Fetches all of the child nodes of element, a DOM Element object. 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 Returns them as the values of a dictionary keyed by the IDs of the
children. For <testsuites>, <testsuite> and <testcase> elements, children. For <testsuites>, <testsuite> and <testcase> elements, the ID
the ID is the value of their "name" attribute; for <failure> is the value of their "name" attribute; for <failure> elements, it is
elements, it is the value of the "message" attribute; for CDATA the value of the "message" attribute; CDATA sections and non-whitespace
section node, it is "detail". An exception is raised if any text nodes are concatenated into a single CDATA section with ID
element other than the above four is encountered, if two child "detail". An exception is raised if any element other than the above
elements with the same identifying attributes are encountered, or four is encountered, if two child elements with the same identifying
if any other type of node is encountered, other than Text nodes attributes are encountered, or if any other type of node is encountered.
containing only whitespace.
""" """
children = {} children = {}
...@@ -121,11 +130,14 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): ...@@ -121,11 +130,14 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
childID = child.getAttribute(self.identifying_attribute[child.tagName]) childID = child.getAttribute(self.identifying_attribute[child.tagName])
self.assert_(childID not in children) self.assert_(childID not in children)
children[childID] = child children[childID] = child
elif child.nodeType == Node.TEXT_NODE: elif child.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]:
self.assert_(child.nodeValue.isspace()) if "detail" not in children:
elif child.nodeType == Node.CDATA_SECTION_NODE: if (child.nodeType == Node.CDATA_SECTION_NODE or
self.assert_("detail" not in children) not child.nodeValue.isspace()):
children["detail"] = child children["detail"] = child.ownerDocument.createCDATASection(
child.nodeValue)
else:
children["detail"].nodeValue += child.nodeValue
else: else:
self.fail("Encountered unexpected node type %d" % child.nodeType) self.fail("Encountered unexpected node type %d" % child.nodeType)
return children return children
......
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