gmock_leak_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2009, 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 """Tests that leaked mock objects can be caught be Google Mock."""
00033 
00034 __author__ = 'wan@google.com (Zhanyong Wan)'
00035 
00036 
00037 import gmock_test_utils
00038 
00039 
00040 PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_')
00041 TEST_WITH_EXPECT_CALL = [PROGRAM_PATH, '--gtest_filter=*ExpectCall*']
00042 TEST_WITH_ON_CALL = [PROGRAM_PATH, '--gtest_filter=*OnCall*']
00043 TEST_MULTIPLE_LEAKS = [PROGRAM_PATH, '--gtest_filter=*MultipleLeaked*']
00044 
00045 environ = gmock_test_utils.environ
00046 SetEnvVar = gmock_test_utils.SetEnvVar
00047 
00048 # Tests in this file run a Google-Test-based test program and expect it
00049 # to terminate prematurely.  Therefore they are incompatible with
00050 # the premature-exit-file protocol by design.  Unset the
00051 # premature-exit filepath to prevent Google Test from creating
00052 # the file.
00053 SetEnvVar(gmock_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
00054 
00055 
00056 class GMockLeakTest(gmock_test_utils.TestCase):
00057 
00058   def testCatchesLeakedMockByDefault(self):
00059     self.assertNotEqual(
00060         0,
00061         gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL,
00062                                     env=environ).exit_code)
00063     self.assertNotEqual(
00064         0,
00065         gmock_test_utils.Subprocess(TEST_WITH_ON_CALL,
00066                                     env=environ).exit_code)
00067 
00068   def testDoesNotCatchLeakedMockWhenDisabled(self):
00069     self.assertEquals(
00070         0,
00071         gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
00072                                     ['--gmock_catch_leaked_mocks=0'],
00073                                     env=environ).exit_code)
00074     self.assertEquals(
00075         0,
00076         gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
00077                                     ['--gmock_catch_leaked_mocks=0'],
00078                                     env=environ).exit_code)
00079 
00080   def testCatchesLeakedMockWhenEnabled(self):
00081     self.assertNotEqual(
00082         0,
00083         gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
00084                                     ['--gmock_catch_leaked_mocks'],
00085                                     env=environ).exit_code)
00086     self.assertNotEqual(
00087         0,
00088         gmock_test_utils.Subprocess(TEST_WITH_ON_CALL +
00089                                     ['--gmock_catch_leaked_mocks'],
00090                                     env=environ).exit_code)
00091 
00092   def testCatchesLeakedMockWhenEnabledWithExplictFlagValue(self):
00093     self.assertNotEqual(
00094         0,
00095         gmock_test_utils.Subprocess(TEST_WITH_EXPECT_CALL +
00096                                     ['--gmock_catch_leaked_mocks=1'],
00097                                     env=environ).exit_code)
00098 
00099   def testCatchesMultipleLeakedMocks(self):
00100     self.assertNotEqual(
00101         0,
00102         gmock_test_utils.Subprocess(TEST_MULTIPLE_LEAKS +
00103                                     ['--gmock_catch_leaked_mocks'],
00104                                     env=environ).exit_code)
00105 
00106 
00107 if __name__ == '__main__':
00108   gmock_test_utils.Main()


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:43