gmock-generated-nice-strict.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. // This file was GENERATED by command:
  2. // pump.py gmock-generated-nice-strict.h.pump
  3. // DO NOT EDIT BY HAND!!!
  4. // Copyright 2008, Google Inc.
  5. // All rights reserved.
  6. //
  7. // Redistribution and use in source and binary forms, with or without
  8. // modification, are permitted provided that the following conditions are
  9. // met:
  10. //
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Google Inc. nor the names of its
  18. // contributors may be used to endorse or promote products derived from
  19. // this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. // Implements class templates NiceMock, NaggyMock, and StrictMock.
  33. //
  34. // Given a mock class MockFoo that is created using Google Mock,
  35. // NiceMock<MockFoo> is a subclass of MockFoo that allows
  36. // uninteresting calls (i.e. calls to mock methods that have no
  37. // EXPECT_CALL specs), NaggyMock<MockFoo> is a subclass of MockFoo
  38. // that prints a warning when an uninteresting call occurs, and
  39. // StrictMock<MockFoo> is a subclass of MockFoo that treats all
  40. // uninteresting calls as errors.
  41. //
  42. // Currently a mock is naggy by default, so MockFoo and
  43. // NaggyMock<MockFoo> behave like the same. However, we will soon
  44. // switch the default behavior of mocks to be nice, as that in general
  45. // leads to more maintainable tests. When that happens, MockFoo will
  46. // stop behaving like NaggyMock<MockFoo> and start behaving like
  47. // NiceMock<MockFoo>.
  48. //
  49. // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
  50. // their respective base class. Therefore you can write
  51. // NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
  52. // has a constructor that accepts (int, const char*), for example.
  53. //
  54. // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
  55. // and StrictMock<MockFoo> only works for mock methods defined using
  56. // the MOCK_METHOD* family of macros DIRECTLY in the MockFoo class.
  57. // If a mock method is defined in a base class of MockFoo, the "nice"
  58. // or "strict" modifier may not affect it, depending on the compiler.
  59. // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
  60. // supported.
  61. // GOOGLETEST_CM0002 DO NOT DELETE
  62. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
  63. #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
  64. #include "gmock/gmock-spec-builders.h"
  65. #include "gmock/internal/gmock-port.h"
  66. namespace testing {
  67. template <class MockClass>
  68. class NiceMock : public MockClass {
  69. public:
  70. NiceMock() : MockClass() {
  71. ::testing::Mock::AllowUninterestingCalls(
  72. internal::ImplicitCast_<MockClass*>(this));
  73. }
  74. #if GTEST_LANG_CXX11
  75. // Ideally, we would inherit base class's constructors through a using
  76. // declaration, which would preserve their visibility. However, many existing
  77. // tests rely on the fact that current implementation reexports protected
  78. // constructors as public. These tests would need to be cleaned up first.
  79. // Single argument constructor is special-cased so that it can be
  80. // made explicit.
  81. template <typename A>
  82. explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
  83. ::testing::Mock::AllowUninterestingCalls(
  84. internal::ImplicitCast_<MockClass*>(this));
  85. }
  86. template <typename A1, typename A2, typename... An>
  87. NiceMock(A1&& arg1, A2&& arg2, An&&... args)
  88. : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
  89. std::forward<An>(args)...) {
  90. ::testing::Mock::AllowUninterestingCalls(
  91. internal::ImplicitCast_<MockClass*>(this));
  92. }
  93. #else
  94. // C++98 doesn't have variadic templates, so we have to define one
  95. // for each arity.
  96. template <typename A1>
  97. explicit NiceMock(const A1& a1) : MockClass(a1) {
  98. ::testing::Mock::AllowUninterestingCalls(
  99. internal::ImplicitCast_<MockClass*>(this));
  100. }
  101. template <typename A1, typename A2>
  102. NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
  103. ::testing::Mock::AllowUninterestingCalls(
  104. internal::ImplicitCast_<MockClass*>(this));
  105. }
  106. template <typename A1, typename A2, typename A3>
  107. NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
  108. ::testing::Mock::AllowUninterestingCalls(
  109. internal::ImplicitCast_<MockClass*>(this));
  110. }
  111. template <typename A1, typename A2, typename A3, typename A4>
  112. NiceMock(const A1& a1, const A2& a2, const A3& a3,
  113. const A4& a4) : MockClass(a1, a2, a3, a4) {
  114. ::testing::Mock::AllowUninterestingCalls(
  115. internal::ImplicitCast_<MockClass*>(this));
  116. }
  117. template <typename A1, typename A2, typename A3, typename A4, typename A5>
  118. NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  119. const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
  120. ::testing::Mock::AllowUninterestingCalls(
  121. internal::ImplicitCast_<MockClass*>(this));
  122. }
  123. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  124. typename A6>
  125. NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  126. const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
  127. ::testing::Mock::AllowUninterestingCalls(
  128. internal::ImplicitCast_<MockClass*>(this));
  129. }
  130. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  131. typename A6, typename A7>
  132. NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  133. const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
  134. a6, a7) {
  135. ::testing::Mock::AllowUninterestingCalls(
  136. internal::ImplicitCast_<MockClass*>(this));
  137. }
  138. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  139. typename A6, typename A7, typename A8>
  140. NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  141. const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
  142. a2, a3, a4, a5, a6, a7, a8) {
  143. ::testing::Mock::AllowUninterestingCalls(
  144. internal::ImplicitCast_<MockClass*>(this));
  145. }
  146. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  147. typename A6, typename A7, typename A8, typename A9>
  148. NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  149. const A5& a5, const A6& a6, const A7& a7, const A8& a8,
  150. const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
  151. ::testing::Mock::AllowUninterestingCalls(
  152. internal::ImplicitCast_<MockClass*>(this));
  153. }
  154. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  155. typename A6, typename A7, typename A8, typename A9, typename A10>
  156. NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  157. const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
  158. const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
  159. ::testing::Mock::AllowUninterestingCalls(
  160. internal::ImplicitCast_<MockClass*>(this));
  161. }
  162. #endif // GTEST_LANG_CXX11
  163. ~NiceMock() {
  164. ::testing::Mock::UnregisterCallReaction(
  165. internal::ImplicitCast_<MockClass*>(this));
  166. }
  167. private:
  168. GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
  169. };
  170. template <class MockClass>
  171. class NaggyMock : public MockClass {
  172. public:
  173. NaggyMock() : MockClass() {
  174. ::testing::Mock::WarnUninterestingCalls(
  175. internal::ImplicitCast_<MockClass*>(this));
  176. }
  177. #if GTEST_LANG_CXX11
  178. // Ideally, we would inherit base class's constructors through a using
  179. // declaration, which would preserve their visibility. However, many existing
  180. // tests rely on the fact that current implementation reexports protected
  181. // constructors as public. These tests would need to be cleaned up first.
  182. // Single argument constructor is special-cased so that it can be
  183. // made explicit.
  184. template <typename A>
  185. explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
  186. ::testing::Mock::WarnUninterestingCalls(
  187. internal::ImplicitCast_<MockClass*>(this));
  188. }
  189. template <typename A1, typename A2, typename... An>
  190. NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
  191. : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
  192. std::forward<An>(args)...) {
  193. ::testing::Mock::WarnUninterestingCalls(
  194. internal::ImplicitCast_<MockClass*>(this));
  195. }
  196. #else
  197. // C++98 doesn't have variadic templates, so we have to define one
  198. // for each arity.
  199. template <typename A1>
  200. explicit NaggyMock(const A1& a1) : MockClass(a1) {
  201. ::testing::Mock::WarnUninterestingCalls(
  202. internal::ImplicitCast_<MockClass*>(this));
  203. }
  204. template <typename A1, typename A2>
  205. NaggyMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
  206. ::testing::Mock::WarnUninterestingCalls(
  207. internal::ImplicitCast_<MockClass*>(this));
  208. }
  209. template <typename A1, typename A2, typename A3>
  210. NaggyMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
  211. ::testing::Mock::WarnUninterestingCalls(
  212. internal::ImplicitCast_<MockClass*>(this));
  213. }
  214. template <typename A1, typename A2, typename A3, typename A4>
  215. NaggyMock(const A1& a1, const A2& a2, const A3& a3,
  216. const A4& a4) : MockClass(a1, a2, a3, a4) {
  217. ::testing::Mock::WarnUninterestingCalls(
  218. internal::ImplicitCast_<MockClass*>(this));
  219. }
  220. template <typename A1, typename A2, typename A3, typename A4, typename A5>
  221. NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  222. const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
  223. ::testing::Mock::WarnUninterestingCalls(
  224. internal::ImplicitCast_<MockClass*>(this));
  225. }
  226. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  227. typename A6>
  228. NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  229. const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
  230. ::testing::Mock::WarnUninterestingCalls(
  231. internal::ImplicitCast_<MockClass*>(this));
  232. }
  233. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  234. typename A6, typename A7>
  235. NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  236. const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
  237. a6, a7) {
  238. ::testing::Mock::WarnUninterestingCalls(
  239. internal::ImplicitCast_<MockClass*>(this));
  240. }
  241. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  242. typename A6, typename A7, typename A8>
  243. NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  244. const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
  245. a2, a3, a4, a5, a6, a7, a8) {
  246. ::testing::Mock::WarnUninterestingCalls(
  247. internal::ImplicitCast_<MockClass*>(this));
  248. }
  249. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  250. typename A6, typename A7, typename A8, typename A9>
  251. NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  252. const A5& a5, const A6& a6, const A7& a7, const A8& a8,
  253. const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
  254. ::testing::Mock::WarnUninterestingCalls(
  255. internal::ImplicitCast_<MockClass*>(this));
  256. }
  257. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  258. typename A6, typename A7, typename A8, typename A9, typename A10>
  259. NaggyMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  260. const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
  261. const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
  262. ::testing::Mock::WarnUninterestingCalls(
  263. internal::ImplicitCast_<MockClass*>(this));
  264. }
  265. #endif // GTEST_LANG_CXX11
  266. ~NaggyMock() {
  267. ::testing::Mock::UnregisterCallReaction(
  268. internal::ImplicitCast_<MockClass*>(this));
  269. }
  270. private:
  271. GTEST_DISALLOW_COPY_AND_ASSIGN_(NaggyMock);
  272. };
  273. template <class MockClass>
  274. class StrictMock : public MockClass {
  275. public:
  276. StrictMock() : MockClass() {
  277. ::testing::Mock::FailUninterestingCalls(
  278. internal::ImplicitCast_<MockClass*>(this));
  279. }
  280. #if GTEST_LANG_CXX11
  281. // Ideally, we would inherit base class's constructors through a using
  282. // declaration, which would preserve their visibility. However, many existing
  283. // tests rely on the fact that current implementation reexports protected
  284. // constructors as public. These tests would need to be cleaned up first.
  285. // Single argument constructor is special-cased so that it can be
  286. // made explicit.
  287. template <typename A>
  288. explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
  289. ::testing::Mock::FailUninterestingCalls(
  290. internal::ImplicitCast_<MockClass*>(this));
  291. }
  292. template <typename A1, typename A2, typename... An>
  293. StrictMock(A1&& arg1, A2&& arg2, An&&... args)
  294. : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
  295. std::forward<An>(args)...) {
  296. ::testing::Mock::FailUninterestingCalls(
  297. internal::ImplicitCast_<MockClass*>(this));
  298. }
  299. #else
  300. // C++98 doesn't have variadic templates, so we have to define one
  301. // for each arity.
  302. template <typename A1>
  303. explicit StrictMock(const A1& a1) : MockClass(a1) {
  304. ::testing::Mock::FailUninterestingCalls(
  305. internal::ImplicitCast_<MockClass*>(this));
  306. }
  307. template <typename A1, typename A2>
  308. StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
  309. ::testing::Mock::FailUninterestingCalls(
  310. internal::ImplicitCast_<MockClass*>(this));
  311. }
  312. template <typename A1, typename A2, typename A3>
  313. StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
  314. ::testing::Mock::FailUninterestingCalls(
  315. internal::ImplicitCast_<MockClass*>(this));
  316. }
  317. template <typename A1, typename A2, typename A3, typename A4>
  318. StrictMock(const A1& a1, const A2& a2, const A3& a3,
  319. const A4& a4) : MockClass(a1, a2, a3, a4) {
  320. ::testing::Mock::FailUninterestingCalls(
  321. internal::ImplicitCast_<MockClass*>(this));
  322. }
  323. template <typename A1, typename A2, typename A3, typename A4, typename A5>
  324. StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  325. const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
  326. ::testing::Mock::FailUninterestingCalls(
  327. internal::ImplicitCast_<MockClass*>(this));
  328. }
  329. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  330. typename A6>
  331. StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  332. const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
  333. ::testing::Mock::FailUninterestingCalls(
  334. internal::ImplicitCast_<MockClass*>(this));
  335. }
  336. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  337. typename A6, typename A7>
  338. StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  339. const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
  340. a6, a7) {
  341. ::testing::Mock::FailUninterestingCalls(
  342. internal::ImplicitCast_<MockClass*>(this));
  343. }
  344. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  345. typename A6, typename A7, typename A8>
  346. StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  347. const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a1,
  348. a2, a3, a4, a5, a6, a7, a8) {
  349. ::testing::Mock::FailUninterestingCalls(
  350. internal::ImplicitCast_<MockClass*>(this));
  351. }
  352. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  353. typename A6, typename A7, typename A8, typename A9>
  354. StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  355. const A5& a5, const A6& a6, const A7& a7, const A8& a8,
  356. const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
  357. ::testing::Mock::FailUninterestingCalls(
  358. internal::ImplicitCast_<MockClass*>(this));
  359. }
  360. template <typename A1, typename A2, typename A3, typename A4, typename A5,
  361. typename A6, typename A7, typename A8, typename A9, typename A10>
  362. StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
  363. const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
  364. const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
  365. ::testing::Mock::FailUninterestingCalls(
  366. internal::ImplicitCast_<MockClass*>(this));
  367. }
  368. #endif // GTEST_LANG_CXX11
  369. ~StrictMock() {
  370. ::testing::Mock::UnregisterCallReaction(
  371. internal::ImplicitCast_<MockClass*>(this));
  372. }
  373. private:
  374. GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
  375. };
  376. // The following specializations catch some (relatively more common)
  377. // user errors of nesting nice and strict mocks. They do NOT catch
  378. // all possible errors.
  379. // These specializations are declared but not defined, as NiceMock,
  380. // NaggyMock, and StrictMock cannot be nested.
  381. template <typename MockClass>
  382. class NiceMock<NiceMock<MockClass> >;
  383. template <typename MockClass>
  384. class NiceMock<NaggyMock<MockClass> >;
  385. template <typename MockClass>
  386. class NiceMock<StrictMock<MockClass> >;
  387. template <typename MockClass>
  388. class NaggyMock<NiceMock<MockClass> >;
  389. template <typename MockClass>
  390. class NaggyMock<NaggyMock<MockClass> >;
  391. template <typename MockClass>
  392. class NaggyMock<StrictMock<MockClass> >;
  393. template <typename MockClass>
  394. class StrictMock<NiceMock<MockClass> >;
  395. template <typename MockClass>
  396. class StrictMock<NaggyMock<MockClass> >;
  397. template <typename MockClass>
  398. class StrictMock<StrictMock<MockClass> >;
  399. } // namespace testing
  400. #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_