gmock_leak_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright 2009, Google Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
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
15 # distribution.
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.
19 #
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.
31 
32 """Tests that leaked mock objects can be caught be Google Mock."""
33 
34 import gmock_test_utils
35 
36 PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_')
37 TEST_WITH_EXPECT_CALL = [PROGRAM_PATH, '--gtest_filter=*ExpectCall*']
38 TEST_WITH_ON_CALL = [PROGRAM_PATH, '--gtest_filter=*OnCall*']
39 TEST_MULTIPLE_LEAKS = [PROGRAM_PATH, '--gtest_filter=*MultipleLeaked*']
40 
41 environ = gmock_test_utils.environ
42 SetEnvVar = gmock_test_utils.SetEnvVar
43 
44 # Tests in this file run a Google-Test-based test program and expect it
45 # to terminate prematurely. Therefore they are incompatible with
46 # the premature-exit-file protocol by design. Unset the
47 # premature-exit filepath to prevent Google Test from creating
48 # the file.
49 SetEnvVar(gmock_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
50 
51 
53 
55  self.assertNotEqual(
56  0,
57  gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL,
58  env=environ).exit_code)
59  self.assertNotEqual(
60  0,
61  gmock_test_utils.Subprocess(TEST_WITH_ON_CALL,
62  env=environ).exit_code)
63 
65  self.assertEquals(
66  0,
67  gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
68  ['--gmock_catch_leaked_mocks=0'],
69  env=environ).exit_code)
70  self.assertEquals(
71  0,
72  gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
73  ['--gmock_catch_leaked_mocks=0'],
74  env=environ).exit_code)
75 
77  self.assertNotEqual(
78  0,
79  gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
80  ['--gmock_catch_leaked_mocks'],
81  env=environ).exit_code)
82  self.assertNotEqual(
83  0,
84  gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
85  ['--gmock_catch_leaked_mocks'],
86  env=environ).exit_code)
87 
89  self.assertNotEqual(
90  0,
91  gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
92  ['--gmock_catch_leaked_mocks=1'],
93  env=environ).exit_code)
94 
96  self.assertNotEqual(
97  0,
98  gmock_test_utils.Subprocess(TEST_MULTIPLE_LEAKS +
99  ['--gmock_catch_leaked_mocks'],
100  env=environ).exit_code)
101 
102 
103 if __name__ == '__main__':
gmock_leak_test.SetEnvVar
SetEnvVar
Definition: gmock_leak_test.py:42
gmock_test_utils.Subprocess
Subprocess
Definition: gmock_test_utils.py:96
gmock_test_utils.Main
def Main()
Definition: gmock_test_utils.py:105
gmock_leak_test.GMockLeakTest
Definition: gmock_leak_test.py:52
gmock_leak_test.GMockLeakTest.testCatchesLeakedMockWhenEnabled
def testCatchesLeakedMockWhenEnabled(self)
Definition: gmock_leak_test.py:76
gmock_leak_test.GMockLeakTest.testCatchesMultipleLeakedMocks
def testCatchesMultipleLeakedMocks(self)
Definition: gmock_leak_test.py:95
gmock_leak_test.GMockLeakTest.testCatchesLeakedMockWhenEnabledWithExplictFlagValue
def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self)
Definition: gmock_leak_test.py:88
gmock_leak_test.GMockLeakTest.testCatchesLeakedMockByDefault
def testCatchesLeakedMockByDefault(self)
Definition: gmock_leak_test.py:54
gmock_test_utils.GetTestExecutablePath
def GetTestExecutablePath(executable_name)
Definition: gmock_test_utils.py:56
gmock_test_utils.TestCase
TestCase
Definition: gmock_test_utils.py:97
gmock_leak_test.GMockLeakTest.testDoesNotCatchLeakedMockWhenDisabled
def testDoesNotCatchLeakedMockWhenDisabled(self)
Definition: gmock_leak_test.py:64


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:52