11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#!/usr/bin/env python
21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#
31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# Copyright 2006, Google Inc.
41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# All rights reserved.
51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#
61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# Redistribution and use in source and binary forms, with or without
71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# modification, are permitted provided that the following conditions are
81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# met:
91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#
101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#     * Redistributions of source code must retain the above copyright
111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# notice, this list of conditions and the following disclaimer.
121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#     * Redistributions in binary form must reproduce the above
131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# copyright notice, this list of conditions and the following disclaimer
141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# in the documentation and/or other materials provided with the
151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# distribution.
161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#     * Neither the name of Google Inc. nor the names of its
171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# contributors may be used to endorse or promote products derived from
181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# this software without specific prior written permission.
191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#
201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania"""Unit test for the gtest_xml_output module"""
331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania__author__ = 'eefacm@gmail.com (Sean Mcafee)'
351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaimport errno
371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaimport os
381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaimport sys
391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniafrom xml.dom import minidom, Node
401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotimport gtest_test_utils
421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaimport gtest_xml_test_utils
431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
4441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
451be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_OUTPUT_FLAG         = "--gtest_output"
461be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml"
4741d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotGTEST_PROGRAM_NAME = "gtest_xml_output_unittest_"
4841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
4941d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotSUPPORTS_STACK_TRACES = False
5041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
5141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotif SUPPORTS_STACK_TRACES:
5241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  STACK_TRACE_TEMPLATE = "\nStack trace:\n*"
5341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotelse:
5441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  STACK_TRACE_TEMPLATE = ""
551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
561be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaEXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
5741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot<testsuites tests="23" failures="4" disabled="2" errors="0" time="*" name="AllTests">
581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  <testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  </testsuite>
611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  <testsuite name="FailedTest" tests="1" failures="1" disabled="0" errors="0" time="*">
621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="Fails" status="run" time="*" classname="FailedTest">
631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      <failure message="Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
641be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaValue of: 2
6541d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotExpected: 1%(stack)s]]></failure>
661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    </testcase>
671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  </testsuite>
681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  <testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" errors="0" time="*">
691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="Succeeds" status="run" time="*" classname="MixedResultTest"/>
701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="Fails" status="run" time="*" classname="MixedResultTest">
711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      <failure message="Value of: 2&#x0A;Expected: 1" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
721be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaValue of: 2
7341d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotExpected: 1%(stack)s]]></failure>
741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      <failure message="Value of: 3&#x0A;Expected: 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
751be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaValue of: 3
7641d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotExpected: 2%(stack)s]]></failure>
771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    </testcase>
781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="DISABLED_test" status="notrun" time="*" classname="MixedResultTest"/>
791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  </testsuite>
8041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" errors="0" time="*">
8141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="OutputsCData" status="run" time="*" classname="XmlQuotingTest">
8241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      <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:*
8341d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotFailed
8441d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotXML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]&gt;<![CDATA[</top>%(stack)s]]></failure>
8541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    </testcase>
8641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
8741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" errors="0" time="*">
8841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="InvalidCharactersInMessage" status="run" time="*" classname="InvalidCharactersTest">
8941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      <failure message="Failed&#x0A;Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
9041d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotFailed
9141d0579e8de9ef4ff178fc4991043c61a19943f7Brett ChabotInvalid characters in brackets []%(stack)s]]></failure>
9241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    </testcase>
9341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  <testsuite name="DisabledTest" tests="1" failures="0" disabled="1" errors="0" time="*">
951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="DISABLED_test_not_run" status="notrun" time="*" classname="DisabledTest"/>
961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  </testsuite>
971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  <testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" errors="0" time="*">
981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="OneProperty" status="run" time="*" classname="PropertyRecordingTest" key_1="1"/>
991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="IntValuedProperty" status="run" time="*" classname="PropertyRecordingTest" key_int="1"/>
1001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="ThreeProperties" status="run" time="*" classname="PropertyRecordingTest" key_1="1" key_2="2" key_3="3"/>
1011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    <testcase name="TwoValuesForOneKeyUsesLastValue" status="run" time="*" classname="PropertyRecordingTest" key_1="2"/>
1021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  </testsuite>
1031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  <testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" errors="0" time="*">
1041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania     <testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest" key="1"/>
1051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania     <testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_int="1"/>
1061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania     <testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" time="*" classname="NoFixtureTest" key_for_utility_string="1"/>
1071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  </testsuite>
10841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" errors="0" time="*">
10941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="HasValueParamAttribute/0" value_param="33" status="run" time="*" classname="Single/ValueParamTest" />
11041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="HasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
11141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" time="*" classname="Single/ValueParamTest" />
11241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
11341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
11441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" errors="0" time="*">
11541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="TypedTest/0" />
11641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
11741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" errors="0" time="*">
11841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="TypedTest/1" />
11941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
12041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="Single/TypeParameterizedTestCase/0" tests="1" failures="0" disabled="0" errors="0" time="*">
12141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="Single/TypeParameterizedTestCase/0" />
12241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
12341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  <testsuite name="Single/TypeParameterizedTestCase/1" tests="1" failures="0" disabled="0" errors="0" time="*">
12441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    <testcase name="HasTypeParamAttribute" type_param="*" status="run" time="*" classname="Single/TypeParameterizedTestCase/1" />
12541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  </testsuite>
12641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot</testsuites>""" % {'stack': STACK_TRACE_TEMPLATE}
1271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1291be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaEXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
13041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot<testsuites tests="0" failures="0" disabled="0" errors="0" time="*" name="AllTests">
13141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot</testsuites>"""
1321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
1351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  """
1361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  Unit test for Google Test's XML output functionality.
1371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  """
1381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  def testNonEmptyXmlOutput(self):
1401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
1411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    Runs a test program that generates a non-empty XML output, and
1421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    tests that the XML output is expected.
1431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
14441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1)
1451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  def testEmptyXmlOutput(self):
1471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
1481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    Runs a test program that generates an empty XML output, and
1491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    tests that the XML output is expected.
1501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
1511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    self._TestXmlOutput("gtest_no_test_unittest",
1531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                        EXPECTED_EMPTY_XML, 0)
1541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  def testDefaultOutputFile(self):
1561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
1571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    Confirms that Google Test produces an XML output file with the expected
1581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    default name if no name is explicitly specified.
1591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
16041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    output_file = os.path.join(gtest_test_utils.GetTempDir(),
16141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                               GTEST_DEFAULT_OUTPUT_FILE)
16241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
16341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot        "gtest_no_test_unittest")
1641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    try:
1651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      os.remove(output_file)
1661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    except OSError, e:
1671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      if e.errno != errno.ENOENT:
1681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania        raise
1691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    p = gtest_test_utils.Subprocess(
1711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania        [gtest_prog_path, "%s=xml" % GTEST_OUTPUT_FLAG],
17241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot        working_dir=gtest_test_utils.GetTempDir())
1731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    self.assert_(p.exited)
1741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    self.assertEquals(0, p.exit_code)
1751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    self.assert_(os.path.isfile(output_file))
1761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
17741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  def testSuppressedXmlOutput(self):
17841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    """
17941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    Tests that no XML file is generated if the default XML listener is
18041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    shut down before RUN_ALL_TESTS is invoked.
18141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    """
18241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
18341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    xml_path = os.path.join(gtest_test_utils.GetTempDir(),
18441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                            GTEST_PROGRAM_NAME + "out.xml")
18541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if os.path.isfile(xml_path):
18641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      os.remove(xml_path)
18741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
18841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    gtest_prog_path = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)
18941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
19041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    command = [gtest_prog_path,
19141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot               "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path),
19241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot               "--shut_down_xml"]
19341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    p = gtest_test_utils.Subprocess(command)
19441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if p.terminated_by_signal:
19541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      self.assert_(False,
19641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                   "%s was killed by signal %d" % (gtest_prog_name, p.signal))
19741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    else:
19841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      self.assert_(p.exited)
19941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      self.assertEquals(1, p.exit_code,
20041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                        "'%s' exited with code %s, which doesn't match "
20141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                        "the expected exit code %s."
20241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                        % (command, p.exit_code, 1))
20341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
20441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    self.assert_(not os.path.isfile(xml_path))
20541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot
2061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code):
2081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
2091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    Asserts that the XML document generated by running the program
2101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    gtest_prog_name matches expected_xml, a string containing another
2111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    XML document.  Furthermore, the program's exit code must be
2121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    expected_exit_code.
2131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    """
21441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    xml_path = os.path.join(gtest_test_utils.GetTempDir(),
21541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot                            gtest_prog_name + "out.xml")
21641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name)
2171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    command = [gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path)]
2191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    p = gtest_test_utils.Subprocess(command)
2201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    if p.terminated_by_signal:
2211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      self.assert_(False,
2221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                   "%s was killed by signal %d" % (gtest_prog_name, p.signal))
2231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    else:
2241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      self.assert_(p.exited)
2251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      self.assertEquals(expected_exit_code, p.exit_code,
2261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                        "'%s' exited with code %s, which doesn't match "
2271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                        "the expected exit code %s."
2281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                        % (command, p.exit_code, expected_exit_code))
2291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    expected = minidom.parseString(expected_xml)
2311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    actual   = minidom.parse(xml_path)
2321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    self.NormalizeXml(actual.documentElement)
2331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    self.AssertEquivalentNodes(expected.documentElement,
2341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                               actual.documentElement)
2351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    expected.unlink()
2361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    actual  .unlink()
2371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaif __name__ == '__main__':
2411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  os.environ['GTEST_STACK_TRACE_DEPTH'] = '1'
2421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  gtest_test_utils.Main()
243