Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 """Unit test for the gtest_xml_output module."""
00033
00034 __author__ = "keith.ray@gmail.com (Keith Ray)"
00035
00036 import os
00037 from xml.dom import minidom, Node
00038
00039 import gtest_test_utils
00040 import gtest_xml_test_utils
00041
00042
00043 GTEST_OUTPUT_SUBDIR = "xml_outfiles"
00044 GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_"
00045 GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
00046
00047 EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
00048 <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
00049 <testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
00050 <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" />
00051 </testsuite>
00052 </testsuites>
00053 """
00054
00055 EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
00056 <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
00057 <testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
00058 <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" />
00059 </testsuite>
00060 </testsuites>
00061 """
00062
00063
00064 class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase):
00065 """Unit test for Google Test's XML output functionality."""
00066
00067 def setUp(self):
00068
00069
00070
00071 self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(),
00072 GTEST_OUTPUT_SUBDIR, "")
00073 self.DeleteFilesAndDir()
00074
00075 def tearDown(self):
00076 self.DeleteFilesAndDir()
00077
00078 def DeleteFilesAndDir(self):
00079 try:
00080 os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_1_TEST + ".xml"))
00081 except os.error:
00082 pass
00083 try:
00084 os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_2_TEST + ".xml"))
00085 except os.error:
00086 pass
00087 try:
00088 os.rmdir(self.output_dir_)
00089 except os.error:
00090 pass
00091
00092 def testOutfile1(self):
00093 self._TestOutFile(GTEST_OUTPUT_1_TEST, EXPECTED_XML_1)
00094
00095 def testOutfile2(self):
00096 self._TestOutFile(GTEST_OUTPUT_2_TEST, EXPECTED_XML_2)
00097
00098 def _TestOutFile(self, test_name, expected_xml):
00099 gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
00100 command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_]
00101 p = gtest_test_utils.Subprocess(command,
00102 working_dir=gtest_test_utils.GetTempDir())
00103 self.assert_(p.exited)
00104 self.assertEquals(0, p.exit_code)
00105
00106
00107
00108
00109
00110
00111 output_file_name1 = test_name + ".xml"
00112 output_file1 = os.path.join(self.output_dir_, output_file_name1)
00113 output_file_name2 = 'lt-' + output_file_name1
00114 output_file2 = os.path.join(self.output_dir_, output_file_name2)
00115 self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2),
00116 output_file1)
00117
00118 expected = minidom.parseString(expected_xml)
00119 if os.path.isfile(output_file1):
00120 actual = minidom.parse(output_file1)
00121 else:
00122 actual = minidom.parse(output_file2)
00123 self.NormalizeXml(actual.documentElement)
00124 self.AssertEquivalentNodes(expected.documentElement,
00125 actual.documentElement)
00126 expected.unlink()
00127 actual.unlink()
00128
00129
00130 if __name__ == "__main__":
00131 os.environ["GTEST_STACK_TRACE_DEPTH"] = "0"
00132 gtest_test_utils.Main()