blob: 1337e0b05861188e49df5652e0af6cd29302b83a [file] [log] [blame]
zhanyong.wandf35a762009-04-22 22:25:31 +00001#!/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__author__ = 'wan@google.com (Zhanyong Wan)'
35
36import gmock_test_utils
37import os
38import unittest
39
40IS_WINDOWS = os.name == 'nt'
41
42if IS_WINDOWS:
43 # TODO(wan@google.com): test the opt build too. We should do it
44 # when Vlad Losev's work on Google Test's Python test driver is
45 # done, such that we can reuse the work.
46 PROGRAM = r'..\build.dbg\gmock_leak_test_.exe'
47else:
48 PROGRAM = 'gmock_leak_test_'
49
50PROGRAM_PATH = os.path.join(gmock_test_utils.GetBuildDir(), PROGRAM)
51TEST_WITH_EXPECT_CALL = PROGRAM_PATH + ' --gtest_filter=*ExpectCall*'
52TEST_WITH_ON_CALL = PROGRAM_PATH + ' --gtest_filter=*OnCall*'
53TEST_MULTIPLE_LEAKS = PROGRAM_PATH + ' --gtest_filter=*MultipleLeaked*'
54
55
56class GMockLeakTest(unittest.TestCase):
57
zhanyong.wanbf0d0a42009-04-29 23:52:29 +000058 def testCatchesLeakedMockByDefault(self):
59 self.assertNotEqual(os.system(TEST_WITH_EXPECT_CALL), 0)
60 self.assertNotEqual(os.system(TEST_WITH_ON_CALL), 0)
zhanyong.wandf35a762009-04-22 22:25:31 +000061
62 def testDoesNotCatchLeakedMockWhenDisabled(self):
63 self.assertEquals(
64 0, os.system(TEST_WITH_EXPECT_CALL + ' --gmock_catch_leaked_mocks=0'))
65 self.assertEquals(
66 0, os.system(TEST_WITH_ON_CALL + ' --gmock_catch_leaked_mocks=0'))
67
68 def testCatchesLeakedMockWhenEnabled(self):
69 self.assertNotEqual(
70 os.system(TEST_WITH_EXPECT_CALL + ' --gmock_catch_leaked_mocks'), 0)
71 self.assertNotEqual(
72 os.system(TEST_WITH_ON_CALL + ' --gmock_catch_leaked_mocks'), 0)
73
74 def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self):
75 self.assertNotEqual(
76 os.system(TEST_WITH_EXPECT_CALL + ' --gmock_catch_leaked_mocks=1'), 0)
77
78 def testCatchesMultipleLeakedMocks(self):
79 self.assertNotEqual(
80 os.system(TEST_MULTIPLE_LEAKS + ' --gmock_catch_leaked_mocks'), 0)
81
82
83if __name__ == '__main__':
84 gmock_test_utils.Main()