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() { |
| 73 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 74 | } |
| 75 | |
| 76 | // C++ doesn't (yet) allow inheritance of constructors, so we have |
| 77 | // to define it for each arity. |
| 78 | template <typename A1> |
| 79 | explicit NiceMock(const A1& a1) : MockClass(a1) { |
| 80 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 81 | } |
| 82 | template <typename A1, typename A2> |
| 83 | NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { |
| 84 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 85 | } |
| 86 | |
| 87 | template <typename A1, typename A2, typename A3> |
| 88 | NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { |
| 89 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 90 | } |
| 91 | |
| 92 | template <typename A1, typename A2, typename A3, typename A4> |
| 93 | NiceMock(const A1& a1, const A2& a2, const A3& a3, |
| 94 | const A4& a4) : MockClass(a1, a2, a3, a4) { |
| 95 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 96 | } |
| 97 | |
| 98 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 99 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 100 | const A5& a5) : MockClass(a1, a2, a3, a4, a5) { |
| 101 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 102 | } |
| 103 | |
| 104 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 105 | typename A6> |
| 106 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 107 | const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { |
| 108 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 109 | } |
| 110 | |
| 111 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 112 | typename A6, typename A7> |
| 113 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 114 | const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, |
| 115 | a6, a7) { |
| 116 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 117 | } |
| 118 | |
| 119 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 120 | typename A6, typename A7, typename A8> |
| 121 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 122 | const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, |
| 123 | a2, a3, a4, a5, a6, a7, a8) { |
| 124 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 125 | } |
| 126 | |
| 127 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 128 | typename A6, typename A7, typename A8, typename A9> |
| 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, |
| 131 | const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { |
| 132 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 133 | } |
| 134 | |
| 135 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 136 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 137 | NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 138 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, |
| 139 | const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
| 140 | Mock::AllowUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 141 | } |
| 142 | |
| 143 | virtual ~NiceMock() { |
| 144 | Mock::UnregisterCallReaction(internal::implicit_cast<MockClass*>(this)); |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | template <class MockClass> |
| 149 | class StrictMock : public MockClass { |
| 150 | public: |
| 151 | // We don't factor out the constructor body to a common method, as |
| 152 | // we have to avoid a possible clash with members of MockClass. |
| 153 | StrictMock() { |
| 154 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 155 | } |
| 156 | |
| 157 | template <typename A1> |
| 158 | explicit StrictMock(const A1& a1) : MockClass(a1) { |
| 159 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 160 | } |
| 161 | template <typename A1, typename A2> |
| 162 | StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { |
| 163 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 164 | } |
| 165 | |
| 166 | template <typename A1, typename A2, typename A3> |
| 167 | StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { |
| 168 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 169 | } |
| 170 | |
| 171 | template <typename A1, typename A2, typename A3, typename A4> |
| 172 | StrictMock(const A1& a1, const A2& a2, const A3& a3, |
| 173 | const A4& a4) : MockClass(a1, a2, a3, a4) { |
| 174 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 175 | } |
| 176 | |
| 177 | template <typename A1, typename A2, typename A3, typename A4, typename A5> |
| 178 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 179 | const A5& a5) : MockClass(a1, a2, a3, a4, a5) { |
| 180 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 181 | } |
| 182 | |
| 183 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 184 | typename A6> |
| 185 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 186 | const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { |
| 187 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 188 | } |
| 189 | |
| 190 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 191 | typename A6, typename A7> |
| 192 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 193 | const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, |
| 194 | a6, a7) { |
| 195 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 196 | } |
| 197 | |
| 198 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 199 | typename A6, typename A7, typename A8> |
| 200 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 201 | const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1, |
| 202 | a2, a3, a4, a5, a6, a7, a8) { |
| 203 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 204 | } |
| 205 | |
| 206 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 207 | typename A6, typename A7, typename A8, typename A9> |
| 208 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 209 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, |
| 210 | const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { |
| 211 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 212 | } |
| 213 | |
| 214 | template <typename A1, typename A2, typename A3, typename A4, typename A5, |
| 215 | typename A6, typename A7, typename A8, typename A9, typename A10> |
| 216 | StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 217 | const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, |
| 218 | const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { |
| 219 | Mock::FailUninterestingCalls(internal::implicit_cast<MockClass*>(this)); |
| 220 | } |
| 221 | |
| 222 | virtual ~StrictMock() { |
| 223 | Mock::UnregisterCallReaction(internal::implicit_cast<MockClass*>(this)); |
| 224 | } |
| 225 | }; |
| 226 | |
| 227 | // The following specializations catch some (relatively more common) |
| 228 | // user errors of nesting nice and strict mocks. They do NOT catch |
| 229 | // all possible errors. |
| 230 | |
| 231 | // These specializations are declared but not defined, as NiceMock and |
| 232 | // StrictMock cannot be nested. |
| 233 | template <typename MockClass> |
| 234 | class NiceMock<NiceMock<MockClass> >; |
| 235 | template <typename MockClass> |
| 236 | class NiceMock<StrictMock<MockClass> >; |
| 237 | template <typename MockClass> |
| 238 | class StrictMock<NiceMock<MockClass> >; |
| 239 | template <typename MockClass> |
| 240 | class StrictMock<StrictMock<MockClass> >; |
| 241 | |
| 242 | } // namespace testing |
| 243 | |
| 244 | #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ |