shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 1 | // This file was GENERATED by a script. DO NOT EDIT BY HAND!!! |
| 2 | |
| 3 | // Copyright 2008, 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 | // Author: wan@google.com (Zhanyong Wan) |
| 33 | |
| 34 | // Implements class templates NiceMock and StrictMock. |
| 35 | // |
| 36 | // Given a mock class MockFoo that is created using Google Mock, |
| 37 | // NiceMock<MockFoo> is a subclass of MockFoo that allows |
| 38 | // uninteresting calls (i.e. calls to mock methods that have no |
| 39 | // EXPECT_CALL specs), and StrictMock<MockFoo> is a subclass of |
| 40 | // MockFoo that treats all uninteresting calls as errors. |
| 41 | // |
| 42 | // NiceMock and StrictMock "inherits" the constructors of their |
| 43 | // respective base class, with up-to 10 arguments. Therefore you can |
| 44 | // write NiceMock<MockFoo>(5, "a") to construct a nice mock where |
| 45 | // MockFoo has a constructor that accepts (int, const char*), for |
| 46 | // example. |
| 47 | // |
| 48 | // A known limitation is that NiceMock<MockFoo> and |
| 49 | // StrictMock<MockFoo> only works for mock methods defined using the |
| 50 | // MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. If a |
| 51 | // mock method is defined in a base class of MockFoo, the "nice" or |
| 52 | // "strict" modifier may not affect it, depending on the compiler. In |
| 53 | // particular, nesting NiceMock and StrictMock is NOT supported. |
| 54 | // |
| 55 | // Another known limitation is that the constructors of the base mock |
| 56 | // cannot have arguments passed by non-const reference, which are |
| 57 | // banned by the Google C++ style guide anyway. |
| 58 | |
| 59 | #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |
| 60 | #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |
| 61 | |
| 62 | #include <gmock/gmock-spec-builders.h> |
| 63 | #include <gmock/internal/gmock-port.h> |
| 64 | |
| 65 | namespace testing { |
| 66 | |
| 67 | template <class MockClass> |
| 68 | class NiceMock : public MockClass { |
| 69 | public: |
| 70 | // We don't factor out the constructor body to a common method, as |
| 71 | // we have to avoid a possible clash with members of MockClass. |
| 72 | NiceMock() { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 73 | ::testing::Mock::AllowUninterestingCalls( |
| 74 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | // C++ doesn't (yet) allow inheritance of constructors, so we have |
| 78 | // to define it for each arity. |
| 79 | template <typename A1> |
| 80 | explicit NiceMock(const A1& a1) : MockClass(a1) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 81 | ::testing::Mock::AllowUninterestingCalls( |
| 82 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 83 | } |
| 84 | template <typename A1, typename A2> |
| 85 | NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 86 | ::testing::Mock::AllowUninterestingCalls( |
| 87 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | template <typename A1, typename A2, typename A3> |
| 91 | NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 92 | ::testing::Mock::AllowUninterestingCalls( |
| 93 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | template <typename A1, typename A2, typename A3, typename A4> |
| 97 | NiceMock(const A1& a1, const A2& a2, const A3& a3, |
| 98 | const A4& a4) : MockClass(a1, a2, a3, a4) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 99 | ::testing::Mock::AllowUninterestingCalls( |
| 100 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 104 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 105 | const A5& a5) : MockClass(a1, a2, a3, a4, a5) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 106 | ::testing::Mock::AllowUninterestingCalls( |
| 107 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 111 | typename A6> |
| 112 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 113 | const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 114 | ::testing::Mock::AllowUninterestingCalls( |
| 115 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 119 | typename A6, typename A7> |
| 120 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 121 | const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, |
| 122 | a6, a7) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 123 | ::testing::Mock::AllowUninterestingCalls( |
| 124 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 128 | typename A6, typename A7, typename A8> |
| 129 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 130 | const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, |
| 131 | a2, a3, a4, a5, a6, a7, a8) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 132 | ::testing::Mock::AllowUninterestingCalls( |
| 133 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 137 | typename A6, typename A7, typename A8, typename A9> |
| 138 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 139 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, |
| 140 | const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 141 | ::testing::Mock::AllowUninterestingCalls( |
| 142 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 146 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 147 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 148 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, |
| 149 | const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 150 | ::testing::Mock::AllowUninterestingCalls( |
| 151 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | virtual ~NiceMock() { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 155 | ::testing::Mock::UnregisterCallReaction( |
| 156 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 157 | } |
zhanyong.wan | 32de5f5 | 2009-12-23 00:13:23 +0000 | [diff] [blame^] | 158 | |
| 159 | private: |
| 160 | GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | template <class MockClass> |
| 164 | class StrictMock : public MockClass { |
| 165 | public: |
| 166 | // We don't factor out the constructor body to a common method, as |
| 167 | // we have to avoid a possible clash with members of MockClass. |
| 168 | StrictMock() { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 169 | ::testing::Mock::FailUninterestingCalls( |
| 170 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | template <typename A1> |
| 174 | explicit StrictMock(const A1& a1) : MockClass(a1) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 175 | ::testing::Mock::FailUninterestingCalls( |
| 176 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 177 | } |
| 178 | template <typename A1, typename A2> |
| 179 | StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 180 | ::testing::Mock::FailUninterestingCalls( |
| 181 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | template <typename A1, typename A2, typename A3> |
| 185 | StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 186 | ::testing::Mock::FailUninterestingCalls( |
| 187 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | template <typename A1, typename A2, typename A3, typename A4> |
| 191 | StrictMock(const A1& a1, const A2& a2, const A3& a3, |
| 192 | const A4& a4) : MockClass(a1, a2, a3, a4) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 193 | ::testing::Mock::FailUninterestingCalls( |
| 194 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 198 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 199 | const A5& a5) : MockClass(a1, a2, a3, a4, a5) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 200 | ::testing::Mock::FailUninterestingCalls( |
| 201 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 205 | typename A6> |
| 206 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 207 | const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 208 | ::testing::Mock::FailUninterestingCalls( |
| 209 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 213 | typename A6, typename A7> |
| 214 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 215 | const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, |
| 216 | a6, a7) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 217 | ::testing::Mock::FailUninterestingCalls( |
| 218 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 222 | typename A6, typename A7, typename A8> |
| 223 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 224 | const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, |
| 225 | a2, a3, a4, a5, a6, a7, a8) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 226 | ::testing::Mock::FailUninterestingCalls( |
| 227 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 231 | typename A6, typename A7, typename A8, typename A9> |
| 232 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 233 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, |
| 234 | const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 235 | ::testing::Mock::FailUninterestingCalls( |
| 236 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 240 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 241 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 242 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, |
| 243 | const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 244 | ::testing::Mock::FailUninterestingCalls( |
| 245 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | virtual ~StrictMock() { |
zhanyong.wan | 4bd79e4 | 2009-09-16 17:38:08 +0000 | [diff] [blame] | 249 | ::testing::Mock::UnregisterCallReaction( |
| 250 | internal::implicit_cast<MockClass*>(this)); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 251 | } |
zhanyong.wan | 32de5f5 | 2009-12-23 00:13:23 +0000 | [diff] [blame^] | 252 | |
| 253 | private: |
| 254 | GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); |
shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | // The following specializations catch some (relatively more common) |
| 258 | // user errors of nesting nice and strict mocks. They do NOT catch |
| 259 | // all possible errors. |
| 260 | |
| 261 | // These specializations are declared but not defined, as NiceMock and |
| 262 | // StrictMock cannot be nested. |
| 263 | template <typename MockClass> |
| 264 | class NiceMock<NiceMock<MockClass> >; |
| 265 | template <typename MockClass> |
| 266 | class NiceMock<StrictMock<MockClass> >; |
| 267 | template <typename MockClass> |
| 268 | class StrictMock<NiceMock<MockClass> >; |
| 269 | template <typename MockClass> |
| 270 | class StrictMock<StrictMock<MockClass> >; |
| 271 | |
| 272 | } // namespace testing |
| 273 | |
| 274 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |