![]() |
|
|||
File indexing completed on 2025-08-06 08:19:59
0001 // Copyright 2009, Google Inc. 0002 // All rights reserved. 0003 // 0004 // Redistribution and use in source and binary forms, with or without 0005 // modification, are permitted provided that the following conditions are 0006 // met: 0007 // 0008 // * Redistributions of source code must retain the above copyright 0009 // notice, this list of conditions and the following disclaimer. 0010 // * Redistributions in binary form must reproduce the above 0011 // copyright notice, this list of conditions and the following disclaimer 0012 // in the documentation and/or other materials provided with the 0013 // distribution. 0014 // * Neither the name of Google Inc. nor the names of its 0015 // contributors may be used to endorse or promote products derived from 0016 // this software without specific prior written permission. 0017 // 0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0029 // 0030 // Author: wan@google.com (Zhanyong Wan) 0031 0032 // Google Mock - a framework for writing C++ mock classes. 0033 // 0034 // This program is for verifying that a leaked mock object can be 0035 // caught by Google Mock's leak detector. 0036 0037 #include "gmock/gmock.h" 0038 0039 namespace { 0040 0041 using ::testing::Return; 0042 0043 class FooInterface { 0044 public: 0045 virtual ~FooInterface() {} 0046 virtual void DoThis() = 0; 0047 }; 0048 0049 class MockFoo : public FooInterface { 0050 public: 0051 MockFoo() {} 0052 0053 MOCK_METHOD0(DoThis, void()); 0054 0055 private: 0056 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); 0057 }; 0058 0059 TEST(LeakTest, LeakedMockWithExpectCallCausesFailureWhenLeakCheckingIsEnabled) { 0060 MockFoo* foo = new MockFoo; 0061 0062 EXPECT_CALL(*foo, DoThis()); 0063 foo->DoThis(); 0064 0065 // In order to test the leak detector, we deliberately leak foo. 0066 0067 // Makes sure Google Mock's leak detector can change the exit code 0068 // to 1 even when the code is already exiting with 0. 0069 exit(0); 0070 } 0071 0072 TEST(LeakTest, LeakedMockWithOnCallCausesFailureWhenLeakCheckingIsEnabled) { 0073 MockFoo* foo = new MockFoo; 0074 0075 ON_CALL(*foo, DoThis()).WillByDefault(Return()); 0076 0077 // In order to test the leak detector, we deliberately leak foo. 0078 0079 // Makes sure Google Mock's leak detector can change the exit code 0080 // to 1 even when the code is already exiting with 0. 0081 exit(0); 0082 } 0083 0084 TEST(LeakTest, CatchesMultipleLeakedMockObjects) { 0085 MockFoo* foo1 = new MockFoo; 0086 MockFoo* foo2 = new MockFoo; 0087 0088 ON_CALL(*foo1, DoThis()).WillByDefault(Return()); 0089 EXPECT_CALL(*foo2, DoThis()); 0090 foo2->DoThis(); 0091 0092 // In order to test the leak detector, we deliberately leak foo1 and 0093 // foo2. 0094 0095 // Makes sure Google Mock's leak detector can change the exit code 0096 // to 1 even when the code is already exiting with 0. 0097 exit(0); 0098 } 0099 0100 } // namespace
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |