gtest_xml_outfiles_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2008, Google Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are
00008 # met:
00009 #
00010 #     * Redistributions of source code must retain the above copyright
00011 # notice, this list of conditions and the following disclaimer.
00012 #     * Redistributions in binary form must reproduce the above
00013 # copyright notice, this list of conditions and the following disclaimer
00014 # in the documentation and/or other materials provided with the
00015 # distribution.
00016 #     * Neither the name of Google Inc. nor the names of its
00017 # contributors may be used to endorse or promote products derived from
00018 # this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00023 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00024 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00026 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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     # We want the trailing '/' that the last "" provides in os.path.join, for
00069     # telling Google Test to create an output directory instead of a single file
00070     # for xml output.
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     # TODO(wan@google.com): libtool causes the built test binary to be
00107     #   named lt-gtest_xml_outfiles_test_ instead of
00108     #   gtest_xml_outfiles_test_.  To account for this possibillity, we
00109     #   allow both names in the following code.  We should remove this
00110     #   hack when Chandler Carruth's libtool replacement tool is ready.
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()


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04