]>
git.proxmox.com Git - ceph.git/blob - ceph/src/s3select/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfiles_test.py
3 # Copyright 2008, Google Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
16 # * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 """Unit test for the gtest_xml_output module."""
35 from xml
.dom
import minidom
, Node
36 import gtest_test_utils
37 import gtest_xml_test_utils
39 GTEST_OUTPUT_SUBDIR
= "xml_outfiles"
40 GTEST_OUTPUT_1_TEST
= "gtest_xml_outfile1_test_"
41 GTEST_OUTPUT_2_TEST
= "gtest_xml_outfile2_test_"
43 EXPECTED_XML_1
= """<?xml version="1.0" encoding="UTF-8"?>
44 <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
45 <testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
46 <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne">
48 <property name="SetUpProp" value="1"/>
49 <property name="TestSomeProperty" value="1"/>
50 <property name="TearDownProp" value="1"/>
57 EXPECTED_XML_2
= """<?xml version="1.0" encoding="UTF-8"?>
58 <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
59 <testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
60 <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo">
62 <property name="SetUpProp" value="2"/>
63 <property name="TestSomeProperty" value="2"/>
64 <property name="TearDownProp" value="2"/>
72 class GTestXMLOutFilesTest(gtest_xml_test_utils
.GTestXMLTestCase
):
73 """Unit test for Google Test's XML output functionality."""
76 # We want the trailing '/' that the last "" provides in os.path.join, for
77 # telling Google Test to create an output directory instead of a single file
79 self
.output_dir_
= os
.path
.join(gtest_test_utils
.GetTempDir(),
80 GTEST_OUTPUT_SUBDIR
, "")
81 self
.DeleteFilesAndDir()
84 self
.DeleteFilesAndDir()
86 def DeleteFilesAndDir(self
):
88 os
.remove(os
.path
.join(self
.output_dir_
, GTEST_OUTPUT_1_TEST
+ ".xml"))
92 os
.remove(os
.path
.join(self
.output_dir_
, GTEST_OUTPUT_2_TEST
+ ".xml"))
96 os
.rmdir(self
.output_dir_
)
100 def testOutfile1(self
):
101 self
._TestOutFile
(GTEST_OUTPUT_1_TEST
, EXPECTED_XML_1
)
103 def testOutfile2(self
):
104 self
._TestOutFile
(GTEST_OUTPUT_2_TEST
, EXPECTED_XML_2
)
106 def _TestOutFile(self
, test_name
, expected_xml
):
107 gtest_prog_path
= gtest_test_utils
.GetTestExecutablePath(test_name
)
108 command
= [gtest_prog_path
, "--gtest_output=xml:%s" % self
.output_dir_
]
109 p
= gtest_test_utils
.Subprocess(command
,
110 working_dir
=gtest_test_utils
.GetTempDir())
111 self
.assert_(p
.exited
)
112 self
.assertEquals(0, p
.exit_code
)
114 # TODO(wan@google.com): libtool causes the built test binary to be
115 # named lt-gtest_xml_outfiles_test_ instead of
116 # gtest_xml_outfiles_test_. To account for this possibility, we
117 # allow both names in the following code. We should remove this
118 # hack when Chandler Carruth's libtool replacement tool is ready.
119 output_file_name1
= test_name
+ ".xml"
120 output_file1
= os
.path
.join(self
.output_dir_
, output_file_name1
)
121 output_file_name2
= 'lt-' + output_file_name1
122 output_file2
= os
.path
.join(self
.output_dir_
, output_file_name2
)
123 self
.assert_(os
.path
.isfile(output_file1
) or os
.path
.isfile(output_file2
),
126 expected
= minidom
.parseString(expected_xml
)
127 if os
.path
.isfile(output_file1
):
128 actual
= minidom
.parse(output_file1
)
130 actual
= minidom
.parse(output_file2
)
131 self
.NormalizeXml(actual
.documentElement
)
132 self
.AssertEquivalentNodes(expected
.documentElement
,
133 actual
.documentElement
)
138 if __name__
== "__main__":
139 os
.environ
["GTEST_STACK_TRACE_DEPTH"] = "0"
140 gtest_test_utils
.Main()