Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # |
michael@0 | 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
michael@0 | 4 | # |
michael@0 | 5 | # Redistribution and use in source and binary forms, with or without |
michael@0 | 6 | # modification, are permitted provided that the following conditions are |
michael@0 | 7 | # met: |
michael@0 | 8 | # |
michael@0 | 9 | # * Redistributions of source code must retain the above copyright |
michael@0 | 10 | # notice, this list of conditions and the following disclaimer. |
michael@0 | 11 | # * Redistributions in binary form must reproduce the above |
michael@0 | 12 | # copyright notice, this list of conditions and the following disclaimer |
michael@0 | 13 | # in the documentation and/or other materials provided with the |
michael@0 | 14 | # distribution. |
michael@0 | 15 | # * Neither the name of Google Inc. nor the names of its |
michael@0 | 16 | # contributors may be used to endorse or promote products derived from |
michael@0 | 17 | # this software without specific prior written permission. |
michael@0 | 18 | # |
michael@0 | 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 30 | |
michael@0 | 31 | """Tests Google Test's exception catching behavior. |
michael@0 | 32 | |
michael@0 | 33 | This script invokes gtest_catch_exceptions_test_ and |
michael@0 | 34 | gtest_catch_exceptions_ex_test_ (programs written with |
michael@0 | 35 | Google Test) and verifies their output. |
michael@0 | 36 | """ |
michael@0 | 37 | |
michael@0 | 38 | __author__ = 'vladl@google.com (Vlad Losev)' |
michael@0 | 39 | |
michael@0 | 40 | import os |
michael@0 | 41 | |
michael@0 | 42 | import gtest_test_utils |
michael@0 | 43 | |
michael@0 | 44 | # Constants. |
michael@0 | 45 | FLAG_PREFIX = '--gtest_' |
michael@0 | 46 | LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests' |
michael@0 | 47 | NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions=0' |
michael@0 | 48 | FILTER_FLAG = FLAG_PREFIX + 'filter' |
michael@0 | 49 | |
michael@0 | 50 | # Path to the gtest_catch_exceptions_ex_test_ binary, compiled with |
michael@0 | 51 | # exceptions enabled. |
michael@0 | 52 | EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath( |
michael@0 | 53 | 'gtest_catch_exceptions_ex_test_') |
michael@0 | 54 | |
michael@0 | 55 | # Path to the gtest_catch_exceptions_test_ binary, compiled with |
michael@0 | 56 | # exceptions disabled. |
michael@0 | 57 | EXE_PATH = gtest_test_utils.GetTestExecutablePath( |
michael@0 | 58 | 'gtest_catch_exceptions_no_ex_test_') |
michael@0 | 59 | |
michael@0 | 60 | TEST_LIST = gtest_test_utils.Subprocess([EXE_PATH, LIST_TESTS_FLAG]).output |
michael@0 | 61 | |
michael@0 | 62 | SUPPORTS_SEH_EXCEPTIONS = 'ThrowsSehException' in TEST_LIST |
michael@0 | 63 | |
michael@0 | 64 | if SUPPORTS_SEH_EXCEPTIONS: |
michael@0 | 65 | BINARY_OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output |
michael@0 | 66 | |
michael@0 | 67 | EX_BINARY_OUTPUT = gtest_test_utils.Subprocess([EX_EXE_PATH]).output |
michael@0 | 68 | |
michael@0 | 69 | # The tests. |
michael@0 | 70 | if SUPPORTS_SEH_EXCEPTIONS: |
michael@0 | 71 | # pylint:disable-msg=C6302 |
michael@0 | 72 | class CatchSehExceptionsTest(gtest_test_utils.TestCase): |
michael@0 | 73 | """Tests exception-catching behavior.""" |
michael@0 | 74 | |
michael@0 | 75 | |
michael@0 | 76 | def TestSehExceptions(self, test_output): |
michael@0 | 77 | self.assert_('SEH exception with code 0x2a thrown ' |
michael@0 | 78 | 'in the test fixture\'s constructor' |
michael@0 | 79 | in test_output) |
michael@0 | 80 | self.assert_('SEH exception with code 0x2a thrown ' |
michael@0 | 81 | 'in the test fixture\'s destructor' |
michael@0 | 82 | in test_output) |
michael@0 | 83 | self.assert_('SEH exception with code 0x2a thrown in SetUpTestCase()' |
michael@0 | 84 | in test_output) |
michael@0 | 85 | self.assert_('SEH exception with code 0x2a thrown in TearDownTestCase()' |
michael@0 | 86 | in test_output) |
michael@0 | 87 | self.assert_('SEH exception with code 0x2a thrown in SetUp()' |
michael@0 | 88 | in test_output) |
michael@0 | 89 | self.assert_('SEH exception with code 0x2a thrown in TearDown()' |
michael@0 | 90 | in test_output) |
michael@0 | 91 | self.assert_('SEH exception with code 0x2a thrown in the test body' |
michael@0 | 92 | in test_output) |
michael@0 | 93 | |
michael@0 | 94 | def testCatchesSehExceptionsWithCxxExceptionsEnabled(self): |
michael@0 | 95 | self.TestSehExceptions(EX_BINARY_OUTPUT) |
michael@0 | 96 | |
michael@0 | 97 | def testCatchesSehExceptionsWithCxxExceptionsDisabled(self): |
michael@0 | 98 | self.TestSehExceptions(BINARY_OUTPUT) |
michael@0 | 99 | |
michael@0 | 100 | |
michael@0 | 101 | class CatchCxxExceptionsTest(gtest_test_utils.TestCase): |
michael@0 | 102 | """Tests C++ exception-catching behavior. |
michael@0 | 103 | |
michael@0 | 104 | Tests in this test case verify that: |
michael@0 | 105 | * C++ exceptions are caught and logged as C++ (not SEH) exceptions |
michael@0 | 106 | * Exception thrown affect the remainder of the test work flow in the |
michael@0 | 107 | expected manner. |
michael@0 | 108 | """ |
michael@0 | 109 | |
michael@0 | 110 | def testCatchesCxxExceptionsInFixtureConstructor(self): |
michael@0 | 111 | self.assert_('C++ exception with description ' |
michael@0 | 112 | '"Standard C++ exception" thrown ' |
michael@0 | 113 | 'in the test fixture\'s constructor' |
michael@0 | 114 | in EX_BINARY_OUTPUT) |
michael@0 | 115 | self.assert_('unexpected' not in EX_BINARY_OUTPUT, |
michael@0 | 116 | 'This failure belongs in this test only if ' |
michael@0 | 117 | '"CxxExceptionInConstructorTest" (no quotes) ' |
michael@0 | 118 | 'appears on the same line as words "called unexpectedly"') |
michael@0 | 119 | |
michael@0 | 120 | if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in |
michael@0 | 121 | EX_BINARY_OUTPUT): |
michael@0 | 122 | |
michael@0 | 123 | def testCatchesCxxExceptionsInFixtureDestructor(self): |
michael@0 | 124 | self.assert_('C++ exception with description ' |
michael@0 | 125 | '"Standard C++ exception" thrown ' |
michael@0 | 126 | 'in the test fixture\'s destructor' |
michael@0 | 127 | in EX_BINARY_OUTPUT) |
michael@0 | 128 | self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() ' |
michael@0 | 129 | 'called as expected.' |
michael@0 | 130 | in EX_BINARY_OUTPUT) |
michael@0 | 131 | |
michael@0 | 132 | def testCatchesCxxExceptionsInSetUpTestCase(self): |
michael@0 | 133 | self.assert_('C++ exception with description "Standard C++ exception"' |
michael@0 | 134 | ' thrown in SetUpTestCase()' |
michael@0 | 135 | in EX_BINARY_OUTPUT) |
michael@0 | 136 | self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() ' |
michael@0 | 137 | 'called as expected.' |
michael@0 | 138 | in EX_BINARY_OUTPUT) |
michael@0 | 139 | self.assert_('CxxExceptionInSetUpTestCaseTest constructor ' |
michael@0 | 140 | 'called as expected.' |
michael@0 | 141 | in EX_BINARY_OUTPUT) |
michael@0 | 142 | self.assert_('CxxExceptionInSetUpTestCaseTest destructor ' |
michael@0 | 143 | 'called as expected.' |
michael@0 | 144 | in EX_BINARY_OUTPUT) |
michael@0 | 145 | self.assert_('CxxExceptionInSetUpTestCaseTest::SetUp() ' |
michael@0 | 146 | 'called as expected.' |
michael@0 | 147 | in EX_BINARY_OUTPUT) |
michael@0 | 148 | self.assert_('CxxExceptionInSetUpTestCaseTest::TearDown() ' |
michael@0 | 149 | 'called as expected.' |
michael@0 | 150 | in EX_BINARY_OUTPUT) |
michael@0 | 151 | self.assert_('CxxExceptionInSetUpTestCaseTest test body ' |
michael@0 | 152 | 'called as expected.' |
michael@0 | 153 | in EX_BINARY_OUTPUT) |
michael@0 | 154 | |
michael@0 | 155 | def testCatchesCxxExceptionsInTearDownTestCase(self): |
michael@0 | 156 | self.assert_('C++ exception with description "Standard C++ exception"' |
michael@0 | 157 | ' thrown in TearDownTestCase()' |
michael@0 | 158 | in EX_BINARY_OUTPUT) |
michael@0 | 159 | |
michael@0 | 160 | def testCatchesCxxExceptionsInSetUp(self): |
michael@0 | 161 | self.assert_('C++ exception with description "Standard C++ exception"' |
michael@0 | 162 | ' thrown in SetUp()' |
michael@0 | 163 | in EX_BINARY_OUTPUT) |
michael@0 | 164 | self.assert_('CxxExceptionInSetUpTest::TearDownTestCase() ' |
michael@0 | 165 | 'called as expected.' |
michael@0 | 166 | in EX_BINARY_OUTPUT) |
michael@0 | 167 | self.assert_('CxxExceptionInSetUpTest destructor ' |
michael@0 | 168 | 'called as expected.' |
michael@0 | 169 | in EX_BINARY_OUTPUT) |
michael@0 | 170 | self.assert_('CxxExceptionInSetUpTest::TearDown() ' |
michael@0 | 171 | 'called as expected.' |
michael@0 | 172 | in EX_BINARY_OUTPUT) |
michael@0 | 173 | self.assert_('unexpected' not in EX_BINARY_OUTPUT, |
michael@0 | 174 | 'This failure belongs in this test only if ' |
michael@0 | 175 | '"CxxExceptionInSetUpTest" (no quotes) ' |
michael@0 | 176 | 'appears on the same line as words "called unexpectedly"') |
michael@0 | 177 | |
michael@0 | 178 | def testCatchesCxxExceptionsInTearDown(self): |
michael@0 | 179 | self.assert_('C++ exception with description "Standard C++ exception"' |
michael@0 | 180 | ' thrown in TearDown()' |
michael@0 | 181 | in EX_BINARY_OUTPUT) |
michael@0 | 182 | self.assert_('CxxExceptionInTearDownTest::TearDownTestCase() ' |
michael@0 | 183 | 'called as expected.' |
michael@0 | 184 | in EX_BINARY_OUTPUT) |
michael@0 | 185 | self.assert_('CxxExceptionInTearDownTest destructor ' |
michael@0 | 186 | 'called as expected.' |
michael@0 | 187 | in EX_BINARY_OUTPUT) |
michael@0 | 188 | |
michael@0 | 189 | def testCatchesCxxExceptionsInTestBody(self): |
michael@0 | 190 | self.assert_('C++ exception with description "Standard C++ exception"' |
michael@0 | 191 | ' thrown in the test body' |
michael@0 | 192 | in EX_BINARY_OUTPUT) |
michael@0 | 193 | self.assert_('CxxExceptionInTestBodyTest::TearDownTestCase() ' |
michael@0 | 194 | 'called as expected.' |
michael@0 | 195 | in EX_BINARY_OUTPUT) |
michael@0 | 196 | self.assert_('CxxExceptionInTestBodyTest destructor ' |
michael@0 | 197 | 'called as expected.' |
michael@0 | 198 | in EX_BINARY_OUTPUT) |
michael@0 | 199 | self.assert_('CxxExceptionInTestBodyTest::TearDown() ' |
michael@0 | 200 | 'called as expected.' |
michael@0 | 201 | in EX_BINARY_OUTPUT) |
michael@0 | 202 | |
michael@0 | 203 | def testCatchesNonStdCxxExceptions(self): |
michael@0 | 204 | self.assert_('Unknown C++ exception thrown in the test body' |
michael@0 | 205 | in EX_BINARY_OUTPUT) |
michael@0 | 206 | |
michael@0 | 207 | def testUnhandledCxxExceptionsAbortTheProgram(self): |
michael@0 | 208 | # Filters out SEH exception tests on Windows. Unhandled SEH exceptions |
michael@0 | 209 | # cause tests to show pop-up windows there. |
michael@0 | 210 | FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*' |
michael@0 | 211 | # By default, Google Test doesn't catch the exceptions. |
michael@0 | 212 | uncaught_exceptions_ex_binary_output = gtest_test_utils.Subprocess( |
michael@0 | 213 | [EX_EXE_PATH, |
michael@0 | 214 | NO_CATCH_EXCEPTIONS_FLAG, |
michael@0 | 215 | FITLER_OUT_SEH_TESTS_FLAG]).output |
michael@0 | 216 | |
michael@0 | 217 | self.assert_('Unhandled C++ exception terminating the program' |
michael@0 | 218 | in uncaught_exceptions_ex_binary_output) |
michael@0 | 219 | self.assert_('unexpected' not in uncaught_exceptions_ex_binary_output) |
michael@0 | 220 | |
michael@0 | 221 | |
michael@0 | 222 | if __name__ == '__main__': |
michael@0 | 223 | gtest_test_utils.Main() |