1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/testing/gtest/test/gtest_xml_outfiles_test.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +#!/usr/bin/env python 1.5 +# 1.6 +# Copyright 2008, Google Inc. 1.7 +# All rights reserved. 1.8 +# 1.9 +# Redistribution and use in source and binary forms, with or without 1.10 +# modification, are permitted provided that the following conditions are 1.11 +# met: 1.12 +# 1.13 +# * Redistributions of source code must retain the above copyright 1.14 +# notice, this list of conditions and the following disclaimer. 1.15 +# * Redistributions in binary form must reproduce the above 1.16 +# copyright notice, this list of conditions and the following disclaimer 1.17 +# in the documentation and/or other materials provided with the 1.18 +# distribution. 1.19 +# * Neither the name of Google Inc. nor the names of its 1.20 +# contributors may be used to endorse or promote products derived from 1.21 +# this software without specific prior written permission. 1.22 +# 1.23 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.27 +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.28 +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.29 +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.30 +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.31 +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.32 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.33 +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 + 1.35 +"""Unit test for the gtest_xml_output module.""" 1.36 + 1.37 +__author__ = "keith.ray@gmail.com (Keith Ray)" 1.38 + 1.39 +import os 1.40 +from xml.dom import minidom, Node 1.41 + 1.42 +import gtest_test_utils 1.43 +import gtest_xml_test_utils 1.44 + 1.45 + 1.46 +GTEST_OUTPUT_SUBDIR = "xml_outfiles" 1.47 +GTEST_OUTPUT_1_TEST = "gtest_xml_outfile1_test_" 1.48 +GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" 1.49 + 1.50 +EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?> 1.51 +<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> 1.52 + <testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*"> 1.53 + <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne" SetUpProp="1" TestSomeProperty="1" TearDownProp="1" /> 1.54 + </testsuite> 1.55 +</testsuites> 1.56 +""" 1.57 + 1.58 +EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?> 1.59 +<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> 1.60 + <testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*"> 1.61 + <testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo" SetUpProp="2" TestSomeProperty="2" TearDownProp="2" /> 1.62 + </testsuite> 1.63 +</testsuites> 1.64 +""" 1.65 + 1.66 + 1.67 +class GTestXMLOutFilesTest(gtest_xml_test_utils.GTestXMLTestCase): 1.68 + """Unit test for Google Test's XML output functionality.""" 1.69 + 1.70 + def setUp(self): 1.71 + # We want the trailing '/' that the last "" provides in os.path.join, for 1.72 + # telling Google Test to create an output directory instead of a single file 1.73 + # for xml output. 1.74 + self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(), 1.75 + GTEST_OUTPUT_SUBDIR, "") 1.76 + self.DeleteFilesAndDir() 1.77 + 1.78 + def tearDown(self): 1.79 + self.DeleteFilesAndDir() 1.80 + 1.81 + def DeleteFilesAndDir(self): 1.82 + try: 1.83 + os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_1_TEST + ".xml")) 1.84 + except os.error: 1.85 + pass 1.86 + try: 1.87 + os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_2_TEST + ".xml")) 1.88 + except os.error: 1.89 + pass 1.90 + try: 1.91 + os.rmdir(self.output_dir_) 1.92 + except os.error: 1.93 + pass 1.94 + 1.95 + def testOutfile1(self): 1.96 + self._TestOutFile(GTEST_OUTPUT_1_TEST, EXPECTED_XML_1) 1.97 + 1.98 + def testOutfile2(self): 1.99 + self._TestOutFile(GTEST_OUTPUT_2_TEST, EXPECTED_XML_2) 1.100 + 1.101 + def _TestOutFile(self, test_name, expected_xml): 1.102 + gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name) 1.103 + command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_] 1.104 + p = gtest_test_utils.Subprocess(command, 1.105 + working_dir=gtest_test_utils.GetTempDir()) 1.106 + self.assert_(p.exited) 1.107 + self.assertEquals(0, p.exit_code) 1.108 + 1.109 + # TODO(wan@google.com): libtool causes the built test binary to be 1.110 + # named lt-gtest_xml_outfiles_test_ instead of 1.111 + # gtest_xml_outfiles_test_. To account for this possibillity, we 1.112 + # allow both names in the following code. We should remove this 1.113 + # hack when Chandler Carruth's libtool replacement tool is ready. 1.114 + output_file_name1 = test_name + ".xml" 1.115 + output_file1 = os.path.join(self.output_dir_, output_file_name1) 1.116 + output_file_name2 = 'lt-' + output_file_name1 1.117 + output_file2 = os.path.join(self.output_dir_, output_file_name2) 1.118 + self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2), 1.119 + output_file1) 1.120 + 1.121 + expected = minidom.parseString(expected_xml) 1.122 + if os.path.isfile(output_file1): 1.123 + actual = minidom.parse(output_file1) 1.124 + else: 1.125 + actual = minidom.parse(output_file2) 1.126 + self.NormalizeXml(actual.documentElement) 1.127 + self.AssertEquivalentNodes(expected.documentElement, 1.128 + actual.documentElement) 1.129 + expected.unlink() 1.130 + actual.unlink() 1.131 + 1.132 + 1.133 +if __name__ == "__main__": 1.134 + os.environ["GTEST_STACK_TRACE_DEPTH"] = "0" 1.135 + gtest_test_utils.Main()