gmock-function-mocker_test.cc 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. // Copyright 2007, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Google Mock - a framework for writing C++ mock classes.
  30. //
  31. // This file tests the function mocker classes.
  32. #include "gmock/gmock-function-mocker.h"
  33. #if GTEST_OS_WINDOWS
  34. // MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
  35. // we are getting compiler errors if we use basetyps.h, hence including
  36. // objbase.h for definition of STDMETHOD.
  37. # include <objbase.h>
  38. #endif // GTEST_OS_WINDOWS
  39. #include <functional>
  40. #include <map>
  41. #include <string>
  42. #include <type_traits>
  43. #include "gmock/gmock.h"
  44. #include "gtest/gtest.h"
  45. namespace testing {
  46. namespace gmock_function_mocker_test {
  47. using testing::_;
  48. using testing::A;
  49. using testing::An;
  50. using testing::AnyNumber;
  51. using testing::Const;
  52. using testing::DoDefault;
  53. using testing::Eq;
  54. using testing::Lt;
  55. using testing::MockFunction;
  56. using testing::Ref;
  57. using testing::Return;
  58. using testing::ReturnRef;
  59. using testing::TypedEq;
  60. template<typename T>
  61. class TemplatedCopyable {
  62. public:
  63. TemplatedCopyable() {}
  64. template <typename U>
  65. TemplatedCopyable(const U& other) {} // NOLINT
  66. };
  67. class FooInterface {
  68. public:
  69. virtual ~FooInterface() {}
  70. virtual void VoidReturning(int x) = 0;
  71. virtual int Nullary() = 0;
  72. virtual bool Unary(int x) = 0;
  73. virtual long Binary(short x, int y) = 0; // NOLINT
  74. virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT
  75. float g, double h, unsigned i, char* j,
  76. const std::string& k) = 0;
  77. virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
  78. virtual std::string TakesConstReference(const int& n) = 0;
  79. virtual bool TakesConst(const int x) = 0;
  80. virtual int OverloadedOnArgumentNumber() = 0;
  81. virtual int OverloadedOnArgumentNumber(int n) = 0;
  82. virtual int OverloadedOnArgumentType(int n) = 0;
  83. virtual char OverloadedOnArgumentType(char c) = 0;
  84. virtual int OverloadedOnConstness() = 0;
  85. virtual char OverloadedOnConstness() const = 0;
  86. virtual int TypeWithHole(int (*func)()) = 0;
  87. virtual int TypeWithComma(const std::map<int, std::string>& a_map) = 0;
  88. virtual int TypeWithTemplatedCopyCtor(const TemplatedCopyable<int>&) = 0;
  89. virtual int (*ReturnsFunctionPointer1(int))(bool) = 0;
  90. using fn_ptr = int (*)(bool);
  91. virtual fn_ptr ReturnsFunctionPointer2(int) = 0;
  92. virtual int RefQualifiedConstRef() const& = 0;
  93. virtual int RefQualifiedConstRefRef() const&& = 0;
  94. virtual int RefQualifiedRef() & = 0;
  95. virtual int RefQualifiedRefRef() && = 0;
  96. virtual int RefQualifiedOverloaded() const& = 0;
  97. virtual int RefQualifiedOverloaded() const&& = 0;
  98. virtual int RefQualifiedOverloaded() & = 0;
  99. virtual int RefQualifiedOverloaded() && = 0;
  100. #if GTEST_OS_WINDOWS
  101. STDMETHOD_(int, CTNullary)() = 0;
  102. STDMETHOD_(bool, CTUnary)(int x) = 0;
  103. STDMETHOD_(int, CTDecimal)
  104. (bool b, char c, short d, int e, long f, // NOLINT
  105. float g, double h, unsigned i, char* j, const std::string& k) = 0;
  106. STDMETHOD_(char, CTConst)(int x) const = 0;
  107. #endif // GTEST_OS_WINDOWS
  108. };
  109. // Const qualifiers on arguments were once (incorrectly) considered
  110. // significant in determining whether two virtual functions had the same
  111. // signature. This was fixed in Visual Studio 2008. However, the compiler
  112. // still emits a warning that alerts about this change in behavior.
  113. #ifdef _MSC_VER
  114. # pragma warning(push)
  115. # pragma warning(disable : 4373)
  116. #endif
  117. class MockFoo : public FooInterface {
  118. public:
  119. MockFoo() {}
  120. // Makes sure that a mock function parameter can be named.
  121. MOCK_METHOD(void, VoidReturning, (int n)); // NOLINT
  122. MOCK_METHOD(int, Nullary, ()); // NOLINT
  123. // Makes sure that a mock function parameter can be unnamed.
  124. MOCK_METHOD(bool, Unary, (int)); // NOLINT
  125. MOCK_METHOD(long, Binary, (short, int)); // NOLINT
  126. MOCK_METHOD(int, Decimal,
  127. (bool, char, short, int, long, float, // NOLINT
  128. double, unsigned, char*, const std::string& str),
  129. (override));
  130. MOCK_METHOD(bool, TakesNonConstReference, (int&)); // NOLINT
  131. MOCK_METHOD(std::string, TakesConstReference, (const int&));
  132. MOCK_METHOD(bool, TakesConst, (const int)); // NOLINT
  133. // Tests that the function return type can contain unprotected comma.
  134. MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (), ());
  135. MOCK_METHOD((std::map<int, std::string>), ReturnTypeWithComma, (int),
  136. (const)); // NOLINT
  137. MOCK_METHOD(int, OverloadedOnArgumentNumber, ()); // NOLINT
  138. MOCK_METHOD(int, OverloadedOnArgumentNumber, (int)); // NOLINT
  139. MOCK_METHOD(int, OverloadedOnArgumentType, (int)); // NOLINT
  140. MOCK_METHOD(char, OverloadedOnArgumentType, (char)); // NOLINT
  141. MOCK_METHOD(int, OverloadedOnConstness, (), (override)); // NOLINT
  142. MOCK_METHOD(char, OverloadedOnConstness, (), (override, const)); // NOLINT
  143. MOCK_METHOD(int, TypeWithHole, (int (*)()), ()); // NOLINT
  144. MOCK_METHOD(int, TypeWithComma, ((const std::map<int, std::string>&)));
  145. MOCK_METHOD(int, TypeWithTemplatedCopyCtor,
  146. (const TemplatedCopyable<int>&)); // NOLINT
  147. MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ());
  148. MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ());
  149. #if GTEST_OS_WINDOWS
  150. MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE)));
  151. MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE)));
  152. MOCK_METHOD(int, CTDecimal,
  153. (bool b, char c, short d, int e, long f, float g, double h,
  154. unsigned i, char* j, const std::string& k),
  155. (Calltype(STDMETHODCALLTYPE)));
  156. MOCK_METHOD(char, CTConst, (int), (const, Calltype(STDMETHODCALLTYPE)));
  157. MOCK_METHOD((std::map<int, std::string>), CTReturnTypeWithComma, (),
  158. (Calltype(STDMETHODCALLTYPE)));
  159. #endif // GTEST_OS_WINDOWS
  160. // Test reference qualified functions.
  161. MOCK_METHOD(int, RefQualifiedConstRef, (), (const, ref(&), override));
  162. MOCK_METHOD(int, RefQualifiedConstRefRef, (), (const, ref(&&), override));
  163. MOCK_METHOD(int, RefQualifiedRef, (), (ref(&), override));
  164. MOCK_METHOD(int, RefQualifiedRefRef, (), (ref(&&), override));
  165. MOCK_METHOD(int, RefQualifiedOverloaded, (), (const, ref(&), override));
  166. MOCK_METHOD(int, RefQualifiedOverloaded, (), (const, ref(&&), override));
  167. MOCK_METHOD(int, RefQualifiedOverloaded, (), (ref(&), override));
  168. MOCK_METHOD(int, RefQualifiedOverloaded, (), (ref(&&), override));
  169. private:
  170. GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
  171. };
  172. class LegacyMockFoo : public FooInterface {
  173. public:
  174. LegacyMockFoo() {}
  175. // Makes sure that a mock function parameter can be named.
  176. MOCK_METHOD1(VoidReturning, void(int n)); // NOLINT
  177. MOCK_METHOD0(Nullary, int()); // NOLINT
  178. // Makes sure that a mock function parameter can be unnamed.
  179. MOCK_METHOD1(Unary, bool(int)); // NOLINT
  180. MOCK_METHOD2(Binary, long(short, int)); // NOLINT
  181. MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // NOLINT
  182. double, unsigned, char*, const std::string& str));
  183. MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
  184. MOCK_METHOD1(TakesConstReference, std::string(const int&));
  185. MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
  186. // Tests that the function return type can contain unprotected comma.
  187. MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
  188. MOCK_CONST_METHOD1(ReturnTypeWithComma,
  189. std::map<int, std::string>(int)); // NOLINT
  190. MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT
  191. MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT
  192. MOCK_METHOD1(OverloadedOnArgumentType, int(int)); // NOLINT
  193. MOCK_METHOD1(OverloadedOnArgumentType, char(char)); // NOLINT
  194. MOCK_METHOD0(OverloadedOnConstness, int()); // NOLINT
  195. MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT
  196. MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT
  197. MOCK_METHOD1(TypeWithComma,
  198. int(const std::map<int, std::string>&)); // NOLINT
  199. MOCK_METHOD1(TypeWithTemplatedCopyCtor,
  200. int(const TemplatedCopyable<int>&)); // NOLINT
  201. MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool));
  202. MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int));
  203. #if GTEST_OS_WINDOWS
  204. MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int());
  205. MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); // NOLINT
  206. MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal,
  207. int(bool b, char c, short d, int e, // NOLINT
  208. long f, float g, double h, // NOLINT
  209. unsigned i, char* j, const std::string& k));
  210. MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst,
  211. char(int)); // NOLINT
  212. // Tests that the function return type can contain unprotected comma.
  213. MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma,
  214. std::map<int, std::string>());
  215. #endif // GTEST_OS_WINDOWS
  216. // We can't mock these with the old macros, but we need to define them to make
  217. // it concrete.
  218. int RefQualifiedConstRef() const& override { return 0; }
  219. int RefQualifiedConstRefRef() const&& override { return 0; }
  220. int RefQualifiedRef() & override { return 0; }
  221. int RefQualifiedRefRef() && override { return 0; }
  222. int RefQualifiedOverloaded() const& override { return 0; }
  223. int RefQualifiedOverloaded() const&& override { return 0; }
  224. int RefQualifiedOverloaded() & override { return 0; }
  225. int RefQualifiedOverloaded() && override { return 0; }
  226. private:
  227. GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockFoo);
  228. };
  229. #ifdef _MSC_VER
  230. # pragma warning(pop)
  231. #endif
  232. template <class T>
  233. class FunctionMockerTest : public testing::Test {
  234. protected:
  235. FunctionMockerTest() : foo_(&mock_foo_) {}
  236. FooInterface* const foo_;
  237. T mock_foo_;
  238. };
  239. using FunctionMockerTestTypes = ::testing::Types<MockFoo, LegacyMockFoo>;
  240. TYPED_TEST_SUITE(FunctionMockerTest, FunctionMockerTestTypes);
  241. // Tests mocking a void-returning function.
  242. TYPED_TEST(FunctionMockerTest, MocksVoidFunction) {
  243. EXPECT_CALL(this->mock_foo_, VoidReturning(Lt(100)));
  244. this->foo_->VoidReturning(0);
  245. }
  246. // Tests mocking a nullary function.
  247. TYPED_TEST(FunctionMockerTest, MocksNullaryFunction) {
  248. EXPECT_CALL(this->mock_foo_, Nullary())
  249. .WillOnce(DoDefault())
  250. .WillOnce(Return(1));
  251. EXPECT_EQ(0, this->foo_->Nullary());
  252. EXPECT_EQ(1, this->foo_->Nullary());
  253. }
  254. // Tests mocking a unary function.
  255. TYPED_TEST(FunctionMockerTest, MocksUnaryFunction) {
  256. EXPECT_CALL(this->mock_foo_, Unary(Eq(2))).Times(2).WillOnce(Return(true));
  257. EXPECT_TRUE(this->foo_->Unary(2));
  258. EXPECT_FALSE(this->foo_->Unary(2));
  259. }
  260. // Tests mocking a binary function.
  261. TYPED_TEST(FunctionMockerTest, MocksBinaryFunction) {
  262. EXPECT_CALL(this->mock_foo_, Binary(2, _)).WillOnce(Return(3));
  263. EXPECT_EQ(3, this->foo_->Binary(2, 1));
  264. }
  265. // Tests mocking a decimal function.
  266. TYPED_TEST(FunctionMockerTest, MocksDecimalFunction) {
  267. EXPECT_CALL(this->mock_foo_,
  268. Decimal(true, 'a', 0, 0, 1L, A<float>(), Lt(100), 5U, NULL, "hi"))
  269. .WillOnce(Return(5));
  270. EXPECT_EQ(5, this->foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi"));
  271. }
  272. // Tests mocking a function that takes a non-const reference.
  273. TYPED_TEST(FunctionMockerTest, MocksFunctionWithNonConstReferenceArgument) {
  274. int a = 0;
  275. EXPECT_CALL(this->mock_foo_, TakesNonConstReference(Ref(a)))
  276. .WillOnce(Return(true));
  277. EXPECT_TRUE(this->foo_->TakesNonConstReference(a));
  278. }
  279. // Tests mocking a function that takes a const reference.
  280. TYPED_TEST(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
  281. int a = 0;
  282. EXPECT_CALL(this->mock_foo_, TakesConstReference(Ref(a)))
  283. .WillOnce(Return("Hello"));
  284. EXPECT_EQ("Hello", this->foo_->TakesConstReference(a));
  285. }
  286. // Tests mocking a function that takes a const variable.
  287. TYPED_TEST(FunctionMockerTest, MocksFunctionWithConstArgument) {
  288. EXPECT_CALL(this->mock_foo_, TakesConst(Lt(10))).WillOnce(DoDefault());
  289. EXPECT_FALSE(this->foo_->TakesConst(5));
  290. }
  291. // Tests mocking functions overloaded on the number of arguments.
  292. TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {
  293. EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentNumber())
  294. .WillOnce(Return(1));
  295. EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentNumber(_))
  296. .WillOnce(Return(2));
  297. EXPECT_EQ(2, this->foo_->OverloadedOnArgumentNumber(1));
  298. EXPECT_EQ(1, this->foo_->OverloadedOnArgumentNumber());
  299. }
  300. // Tests mocking functions overloaded on the types of argument.
  301. TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentType) {
  302. EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentType(An<int>()))
  303. .WillOnce(Return(1));
  304. EXPECT_CALL(this->mock_foo_, OverloadedOnArgumentType(TypedEq<char>('a')))
  305. .WillOnce(Return('b'));
  306. EXPECT_EQ(1, this->foo_->OverloadedOnArgumentType(0));
  307. EXPECT_EQ('b', this->foo_->OverloadedOnArgumentType('a'));
  308. }
  309. // Tests mocking functions overloaded on the const-ness of this object.
  310. TYPED_TEST(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) {
  311. EXPECT_CALL(this->mock_foo_, OverloadedOnConstness());
  312. EXPECT_CALL(Const(this->mock_foo_), OverloadedOnConstness())
  313. .WillOnce(Return('a'));
  314. EXPECT_EQ(0, this->foo_->OverloadedOnConstness());
  315. EXPECT_EQ('a', Const(*this->foo_).OverloadedOnConstness());
  316. }
  317. TYPED_TEST(FunctionMockerTest, MocksReturnTypeWithComma) {
  318. const std::map<int, std::string> a_map;
  319. EXPECT_CALL(this->mock_foo_, ReturnTypeWithComma()).WillOnce(Return(a_map));
  320. EXPECT_CALL(this->mock_foo_, ReturnTypeWithComma(42)).WillOnce(Return(a_map));
  321. EXPECT_EQ(a_map, this->mock_foo_.ReturnTypeWithComma());
  322. EXPECT_EQ(a_map, this->mock_foo_.ReturnTypeWithComma(42));
  323. }
  324. TYPED_TEST(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) {
  325. EXPECT_CALL(this->mock_foo_, TypeWithTemplatedCopyCtor(_))
  326. .WillOnce(Return(true));
  327. EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>()));
  328. }
  329. #if GTEST_OS_WINDOWS
  330. // Tests mocking a nullary function with calltype.
  331. TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
  332. EXPECT_CALL(this->mock_foo_, CTNullary())
  333. .WillOnce(Return(-1))
  334. .WillOnce(Return(0));
  335. EXPECT_EQ(-1, this->foo_->CTNullary());
  336. EXPECT_EQ(0, this->foo_->CTNullary());
  337. }
  338. // Tests mocking a unary function with calltype.
  339. TYPED_TEST(FunctionMockerTest, MocksUnaryFunctionWithCallType) {
  340. EXPECT_CALL(this->mock_foo_, CTUnary(Eq(2)))
  341. .Times(2)
  342. .WillOnce(Return(true))
  343. .WillOnce(Return(false));
  344. EXPECT_TRUE(this->foo_->CTUnary(2));
  345. EXPECT_FALSE(this->foo_->CTUnary(2));
  346. }
  347. // Tests mocking a decimal function with calltype.
  348. TYPED_TEST(FunctionMockerTest, MocksDecimalFunctionWithCallType) {
  349. EXPECT_CALL(this->mock_foo_, CTDecimal(true, 'a', 0, 0, 1L, A<float>(),
  350. Lt(100), 5U, NULL, "hi"))
  351. .WillOnce(Return(10));
  352. EXPECT_EQ(10, this->foo_->CTDecimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi"));
  353. }
  354. // Tests mocking functions overloaded on the const-ness of this object.
  355. TYPED_TEST(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) {
  356. EXPECT_CALL(Const(this->mock_foo_), CTConst(_)).WillOnce(Return('a'));
  357. EXPECT_EQ('a', Const(*this->foo_).CTConst(0));
  358. }
  359. TYPED_TEST(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) {
  360. const std::map<int, std::string> a_map;
  361. EXPECT_CALL(this->mock_foo_, CTReturnTypeWithComma()).WillOnce(Return(a_map));
  362. EXPECT_EQ(a_map, this->mock_foo_.CTReturnTypeWithComma());
  363. }
  364. #endif // GTEST_OS_WINDOWS
  365. TEST(FunctionMockerTest, RefQualified) {
  366. MockFoo mock_foo;
  367. EXPECT_CALL(mock_foo, RefQualifiedConstRef).WillOnce(Return(1));
  368. EXPECT_CALL(std::move(mock_foo), // NOLINT
  369. RefQualifiedConstRefRef)
  370. .WillOnce(Return(2));
  371. EXPECT_CALL(mock_foo, RefQualifiedRef).WillOnce(Return(3));
  372. EXPECT_CALL(std::move(mock_foo), // NOLINT
  373. RefQualifiedRefRef)
  374. .WillOnce(Return(4));
  375. EXPECT_CALL(static_cast<const MockFoo&>(mock_foo), RefQualifiedOverloaded())
  376. .WillOnce(Return(5));
  377. EXPECT_CALL(static_cast<const MockFoo&&>(mock_foo), RefQualifiedOverloaded())
  378. .WillOnce(Return(6));
  379. EXPECT_CALL(static_cast<MockFoo&>(mock_foo), RefQualifiedOverloaded())
  380. .WillOnce(Return(7));
  381. EXPECT_CALL(static_cast<MockFoo&&>(mock_foo), RefQualifiedOverloaded())
  382. .WillOnce(Return(8));
  383. EXPECT_EQ(mock_foo.RefQualifiedConstRef(), 1);
  384. EXPECT_EQ(std::move(mock_foo).RefQualifiedConstRefRef(), 2); // NOLINT
  385. EXPECT_EQ(mock_foo.RefQualifiedRef(), 3);
  386. EXPECT_EQ(std::move(mock_foo).RefQualifiedRefRef(), 4); // NOLINT
  387. EXPECT_EQ(std::cref(mock_foo).get().RefQualifiedOverloaded(), 5);
  388. EXPECT_EQ(std::move(std::cref(mock_foo).get()) // NOLINT
  389. .RefQualifiedOverloaded(),
  390. 6);
  391. EXPECT_EQ(mock_foo.RefQualifiedOverloaded(), 7);
  392. EXPECT_EQ(std::move(mock_foo).RefQualifiedOverloaded(), 8); // NOLINT
  393. }
  394. class MockB {
  395. public:
  396. MockB() {}
  397. MOCK_METHOD(void, DoB, ());
  398. private:
  399. GTEST_DISALLOW_COPY_AND_ASSIGN_(MockB);
  400. };
  401. class LegacyMockB {
  402. public:
  403. LegacyMockB() {}
  404. MOCK_METHOD0(DoB, void());
  405. private:
  406. GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockB);
  407. };
  408. template <typename T>
  409. class ExpectCallTest : public ::testing::Test {};
  410. using ExpectCallTestTypes = ::testing::Types<MockB, LegacyMockB>;
  411. TYPED_TEST_SUITE(ExpectCallTest, ExpectCallTestTypes);
  412. // Tests that functions with no EXPECT_CALL() rules can be called any
  413. // number of times.
  414. TYPED_TEST(ExpectCallTest, UnmentionedFunctionCanBeCalledAnyNumberOfTimes) {
  415. { TypeParam b; }
  416. {
  417. TypeParam b;
  418. b.DoB();
  419. }
  420. {
  421. TypeParam b;
  422. b.DoB();
  423. b.DoB();
  424. }
  425. }
  426. // Tests mocking template interfaces.
  427. template <typename T>
  428. class StackInterface {
  429. public:
  430. virtual ~StackInterface() {}
  431. // Template parameter appears in function parameter.
  432. virtual void Push(const T& value) = 0;
  433. virtual void Pop() = 0;
  434. virtual int GetSize() const = 0;
  435. // Template parameter appears in function return type.
  436. virtual const T& GetTop() const = 0;
  437. };
  438. template <typename T>
  439. class MockStack : public StackInterface<T> {
  440. public:
  441. MockStack() {}
  442. MOCK_METHOD(void, Push, (const T& elem), ());
  443. MOCK_METHOD(void, Pop, (), (final));
  444. MOCK_METHOD(int, GetSize, (), (const, override));
  445. MOCK_METHOD(const T&, GetTop, (), (const));
  446. // Tests that the function return type can contain unprotected comma.
  447. MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (), ());
  448. MOCK_METHOD((std::map<int, int>), ReturnTypeWithComma, (int), (const));
  449. private:
  450. GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStack);
  451. };
  452. template <typename T>
  453. class LegacyMockStack : public StackInterface<T> {
  454. public:
  455. LegacyMockStack() {}
  456. MOCK_METHOD1_T(Push, void(const T& elem));
  457. MOCK_METHOD0_T(Pop, void());
  458. MOCK_CONST_METHOD0_T(GetSize, int()); // NOLINT
  459. MOCK_CONST_METHOD0_T(GetTop, const T&());
  460. // Tests that the function return type can contain unprotected comma.
  461. MOCK_METHOD0_T(ReturnTypeWithComma, std::map<int, int>());
  462. MOCK_CONST_METHOD1_T(ReturnTypeWithComma, std::map<int, int>(int)); // NOLINT
  463. private:
  464. GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStack);
  465. };
  466. template <typename T>
  467. class TemplateMockTest : public ::testing::Test {};
  468. using TemplateMockTestTypes =
  469. ::testing::Types<MockStack<int>, LegacyMockStack<int>>;
  470. TYPED_TEST_SUITE(TemplateMockTest, TemplateMockTestTypes);
  471. // Tests that template mock works.
  472. TYPED_TEST(TemplateMockTest, Works) {
  473. TypeParam mock;
  474. EXPECT_CALL(mock, GetSize())
  475. .WillOnce(Return(0))
  476. .WillOnce(Return(1))
  477. .WillOnce(Return(0));
  478. EXPECT_CALL(mock, Push(_));
  479. int n = 5;
  480. EXPECT_CALL(mock, GetTop())
  481. .WillOnce(ReturnRef(n));
  482. EXPECT_CALL(mock, Pop())
  483. .Times(AnyNumber());
  484. EXPECT_EQ(0, mock.GetSize());
  485. mock.Push(5);
  486. EXPECT_EQ(1, mock.GetSize());
  487. EXPECT_EQ(5, mock.GetTop());
  488. mock.Pop();
  489. EXPECT_EQ(0, mock.GetSize());
  490. }
  491. TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
  492. TypeParam mock;
  493. const std::map<int, int> a_map;
  494. EXPECT_CALL(mock, ReturnTypeWithComma())
  495. .WillOnce(Return(a_map));
  496. EXPECT_CALL(mock, ReturnTypeWithComma(1))
  497. .WillOnce(Return(a_map));
  498. EXPECT_EQ(a_map, mock.ReturnTypeWithComma());
  499. EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
  500. }
  501. #if GTEST_OS_WINDOWS
  502. // Tests mocking template interfaces with calltype.
  503. template <typename T>
  504. class StackInterfaceWithCallType {
  505. public:
  506. virtual ~StackInterfaceWithCallType() {}
  507. // Template parameter appears in function parameter.
  508. STDMETHOD_(void, Push)(const T& value) = 0;
  509. STDMETHOD_(void, Pop)() = 0;
  510. STDMETHOD_(int, GetSize)() const = 0;
  511. // Template parameter appears in function return type.
  512. STDMETHOD_(const T&, GetTop)() const = 0;
  513. };
  514. template <typename T>
  515. class MockStackWithCallType : public StackInterfaceWithCallType<T> {
  516. public:
  517. MockStackWithCallType() {}
  518. MOCK_METHOD(void, Push, (const T& elem),
  519. (Calltype(STDMETHODCALLTYPE), override));
  520. MOCK_METHOD(void, Pop, (), (Calltype(STDMETHODCALLTYPE), override));
  521. MOCK_METHOD(int, GetSize, (), (Calltype(STDMETHODCALLTYPE), override, const));
  522. MOCK_METHOD(const T&, GetTop, (),
  523. (Calltype(STDMETHODCALLTYPE), override, const));
  524. private:
  525. GTEST_DISALLOW_COPY_AND_ASSIGN_(MockStackWithCallType);
  526. };
  527. template <typename T>
  528. class LegacyMockStackWithCallType : public StackInterfaceWithCallType<T> {
  529. public:
  530. LegacyMockStackWithCallType() {}
  531. MOCK_METHOD1_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Push, void(const T& elem));
  532. MOCK_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, Pop, void());
  533. MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetSize, int());
  534. MOCK_CONST_METHOD0_T_WITH_CALLTYPE(STDMETHODCALLTYPE, GetTop, const T&());
  535. private:
  536. GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockStackWithCallType);
  537. };
  538. template <typename T>
  539. class TemplateMockTestWithCallType : public ::testing::Test {};
  540. using TemplateMockTestWithCallTypeTypes =
  541. ::testing::Types<MockStackWithCallType<int>,
  542. LegacyMockStackWithCallType<int>>;
  543. TYPED_TEST_SUITE(TemplateMockTestWithCallType,
  544. TemplateMockTestWithCallTypeTypes);
  545. // Tests that template mock with calltype works.
  546. TYPED_TEST(TemplateMockTestWithCallType, Works) {
  547. TypeParam mock;
  548. EXPECT_CALL(mock, GetSize())
  549. .WillOnce(Return(0))
  550. .WillOnce(Return(1))
  551. .WillOnce(Return(0));
  552. EXPECT_CALL(mock, Push(_));
  553. int n = 5;
  554. EXPECT_CALL(mock, GetTop())
  555. .WillOnce(ReturnRef(n));
  556. EXPECT_CALL(mock, Pop())
  557. .Times(AnyNumber());
  558. EXPECT_EQ(0, mock.GetSize());
  559. mock.Push(5);
  560. EXPECT_EQ(1, mock.GetSize());
  561. EXPECT_EQ(5, mock.GetTop());
  562. mock.Pop();
  563. EXPECT_EQ(0, mock.GetSize());
  564. }
  565. #endif // GTEST_OS_WINDOWS
  566. #define MY_MOCK_METHODS1_ \
  567. MOCK_METHOD(void, Overloaded, ()); \
  568. MOCK_METHOD(int, Overloaded, (int), (const)); \
  569. MOCK_METHOD(bool, Overloaded, (bool f, int n))
  570. #define LEGACY_MY_MOCK_METHODS1_ \
  571. MOCK_METHOD0(Overloaded, void()); \
  572. MOCK_CONST_METHOD1(Overloaded, int(int n)); \
  573. MOCK_METHOD2(Overloaded, bool(bool f, int n))
  574. class MockOverloadedOnArgNumber {
  575. public:
  576. MockOverloadedOnArgNumber() {}
  577. MY_MOCK_METHODS1_;
  578. private:
  579. GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnArgNumber);
  580. };
  581. class LegacyMockOverloadedOnArgNumber {
  582. public:
  583. LegacyMockOverloadedOnArgNumber() {}
  584. LEGACY_MY_MOCK_METHODS1_;
  585. private:
  586. GTEST_DISALLOW_COPY_AND_ASSIGN_(LegacyMockOverloadedOnArgNumber);
  587. };
  588. template <typename T>
  589. class OverloadedMockMethodTest : public ::testing::Test {};
  590. using OverloadedMockMethodTestTypes =
  591. ::testing::Types<MockOverloadedOnArgNumber,
  592. LegacyMockOverloadedOnArgNumber>;
  593. TYPED_TEST_SUITE(OverloadedMockMethodTest, OverloadedMockMethodTestTypes);
  594. TYPED_TEST(OverloadedMockMethodTest, CanOverloadOnArgNumberInMacroBody) {
  595. TypeParam mock;
  596. EXPECT_CALL(mock, Overloaded());
  597. EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
  598. EXPECT_CALL(mock, Overloaded(true, 1)).WillOnce(Return(true));
  599. mock.Overloaded();
  600. EXPECT_EQ(2, mock.Overloaded(1));
  601. EXPECT_TRUE(mock.Overloaded(true, 1));
  602. }
  603. #define MY_MOCK_METHODS2_ \
  604. MOCK_CONST_METHOD1(Overloaded, int(int n)); \
  605. MOCK_METHOD1(Overloaded, int(int n))
  606. class MockOverloadedOnConstness {
  607. public:
  608. MockOverloadedOnConstness() {}
  609. MY_MOCK_METHODS2_;
  610. private:
  611. GTEST_DISALLOW_COPY_AND_ASSIGN_(MockOverloadedOnConstness);
  612. };
  613. TEST(MockMethodOverloadedMockMethodTest, CanOverloadOnConstnessInMacroBody) {
  614. MockOverloadedOnConstness mock;
  615. const MockOverloadedOnConstness* const_mock = &mock;
  616. EXPECT_CALL(mock, Overloaded(1)).WillOnce(Return(2));
  617. EXPECT_CALL(*const_mock, Overloaded(1)).WillOnce(Return(3));
  618. EXPECT_EQ(2, mock.Overloaded(1));
  619. EXPECT_EQ(3, const_mock->Overloaded(1));
  620. }
  621. TEST(MockMethodMockFunctionTest, WorksForVoidNullary) {
  622. MockFunction<void()> foo;
  623. EXPECT_CALL(foo, Call());
  624. foo.Call();
  625. }
  626. TEST(MockMethodMockFunctionTest, WorksForNonVoidNullary) {
  627. MockFunction<int()> foo;
  628. EXPECT_CALL(foo, Call())
  629. .WillOnce(Return(1))
  630. .WillOnce(Return(2));
  631. EXPECT_EQ(1, foo.Call());
  632. EXPECT_EQ(2, foo.Call());
  633. }
  634. TEST(MockMethodMockFunctionTest, WorksForVoidUnary) {
  635. MockFunction<void(int)> foo;
  636. EXPECT_CALL(foo, Call(1));
  637. foo.Call(1);
  638. }
  639. TEST(MockMethodMockFunctionTest, WorksForNonVoidBinary) {
  640. MockFunction<int(bool, int)> foo;
  641. EXPECT_CALL(foo, Call(false, 42))
  642. .WillOnce(Return(1))
  643. .WillOnce(Return(2));
  644. EXPECT_CALL(foo, Call(true, Ge(100)))
  645. .WillOnce(Return(3));
  646. EXPECT_EQ(1, foo.Call(false, 42));
  647. EXPECT_EQ(2, foo.Call(false, 42));
  648. EXPECT_EQ(3, foo.Call(true, 120));
  649. }
  650. TEST(MockMethodMockFunctionTest, WorksFor10Arguments) {
  651. MockFunction<int(bool a0, char a1, int a2, int a3, int a4,
  652. int a5, int a6, char a7, int a8, bool a9)> foo;
  653. EXPECT_CALL(foo, Call(_, 'a', _, _, _, _, _, _, _, _))
  654. .WillOnce(Return(1))
  655. .WillOnce(Return(2));
  656. EXPECT_EQ(1, foo.Call(false, 'a', 0, 0, 0, 0, 0, 'b', 0, true));
  657. EXPECT_EQ(2, foo.Call(true, 'a', 0, 0, 0, 0, 0, 'b', 1, false));
  658. }
  659. TEST(MockMethodMockFunctionTest, AsStdFunction) {
  660. MockFunction<int(int)> foo;
  661. auto call = [](const std::function<int(int)> &f, int i) {
  662. return f(i);
  663. };
  664. EXPECT_CALL(foo, Call(1)).WillOnce(Return(-1));
  665. EXPECT_CALL(foo, Call(2)).WillOnce(Return(-2));
  666. EXPECT_EQ(-1, call(foo.AsStdFunction(), 1));
  667. EXPECT_EQ(-2, call(foo.AsStdFunction(), 2));
  668. }
  669. TEST(MockMethodMockFunctionTest, AsStdFunctionReturnsReference) {
  670. MockFunction<int&()> foo;
  671. int value = 1;
  672. EXPECT_CALL(foo, Call()).WillOnce(ReturnRef(value));
  673. int& ref = foo.AsStdFunction()();
  674. EXPECT_EQ(1, ref);
  675. value = 2;
  676. EXPECT_EQ(2, ref);
  677. }
  678. TEST(MockMethodMockFunctionTest, AsStdFunctionWithReferenceParameter) {
  679. MockFunction<int(int &)> foo;
  680. auto call = [](const std::function<int(int& )> &f, int &i) {
  681. return f(i);
  682. };
  683. int i = 42;
  684. EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1));
  685. EXPECT_EQ(-1, call(foo.AsStdFunction(), i));
  686. }
  687. namespace {
  688. template <typename Expected, typename F>
  689. static constexpr bool IsMockFunctionTemplateArgumentDeducedTo(
  690. const internal::MockFunction<F>&) {
  691. return std::is_same<F, Expected>::value;
  692. }
  693. } // namespace
  694. template <typename F>
  695. class MockMethodMockFunctionSignatureTest : public Test {};
  696. using MockMethodMockFunctionSignatureTypes =
  697. Types<void(), int(), void(int), int(int), int(bool, int),
  698. int(bool, char, int, int, int, int, int, char, int, bool)>;
  699. TYPED_TEST_SUITE(MockMethodMockFunctionSignatureTest,
  700. MockMethodMockFunctionSignatureTypes);
  701. TYPED_TEST(MockMethodMockFunctionSignatureTest,
  702. IsMockFunctionTemplateArgumentDeducedForRawSignature) {
  703. using Argument = TypeParam;
  704. MockFunction<Argument> foo;
  705. EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo));
  706. }
  707. TYPED_TEST(MockMethodMockFunctionSignatureTest,
  708. IsMockFunctionTemplateArgumentDeducedForStdFunction) {
  709. using Argument = std::function<TypeParam>;
  710. MockFunction<Argument> foo;
  711. EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo));
  712. }
  713. TYPED_TEST(
  714. MockMethodMockFunctionSignatureTest,
  715. IsMockFunctionCallMethodSignatureTheSameForRawSignatureAndStdFunction) {
  716. using ForRawSignature = decltype(&MockFunction<TypeParam>::Call);
  717. using ForStdFunction =
  718. decltype(&MockFunction<std::function<TypeParam>>::Call);
  719. EXPECT_TRUE((std::is_same<ForRawSignature, ForStdFunction>::value));
  720. }
  721. template <typename F>
  722. struct AlternateCallable {
  723. };
  724. TYPED_TEST(MockMethodMockFunctionSignatureTest,
  725. IsMockFunctionTemplateArgumentDeducedForAlternateCallable) {
  726. using Argument = AlternateCallable<TypeParam>;
  727. MockFunction<Argument> foo;
  728. EXPECT_TRUE(IsMockFunctionTemplateArgumentDeducedTo<TypeParam>(foo));
  729. }
  730. TYPED_TEST(
  731. MockMethodMockFunctionSignatureTest,
  732. IsMockFunctionCallMethodSignatureTheSameForAlternateCallable) {
  733. using ForRawSignature = decltype(&MockFunction<TypeParam>::Call);
  734. using ForStdFunction =
  735. decltype(&MockFunction<std::function<TypeParam>>::Call);
  736. EXPECT_TRUE((std::is_same<ForRawSignature, ForStdFunction>::value));
  737. }
  738. struct MockMethodSizes0 {
  739. MOCK_METHOD(void, func, ());
  740. };
  741. struct MockMethodSizes1 {
  742. MOCK_METHOD(void, func, (int));
  743. };
  744. struct MockMethodSizes2 {
  745. MOCK_METHOD(void, func, (int, int));
  746. };
  747. struct MockMethodSizes3 {
  748. MOCK_METHOD(void, func, (int, int, int));
  749. };
  750. struct MockMethodSizes4 {
  751. MOCK_METHOD(void, func, (int, int, int, int));
  752. };
  753. struct LegacyMockMethodSizes0 {
  754. MOCK_METHOD0(func, void());
  755. };
  756. struct LegacyMockMethodSizes1 {
  757. MOCK_METHOD1(func, void(int));
  758. };
  759. struct LegacyMockMethodSizes2 {
  760. MOCK_METHOD2(func, void(int, int));
  761. };
  762. struct LegacyMockMethodSizes3 {
  763. MOCK_METHOD3(func, void(int, int, int));
  764. };
  765. struct LegacyMockMethodSizes4 {
  766. MOCK_METHOD4(func, void(int, int, int, int));
  767. };
  768. TEST(MockMethodMockFunctionTest, MockMethodSizeOverhead) {
  769. EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1));
  770. EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2));
  771. EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3));
  772. EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4));
  773. EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes1));
  774. EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes2));
  775. EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes3));
  776. EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(LegacyMockMethodSizes4));
  777. EXPECT_EQ(sizeof(LegacyMockMethodSizes0), sizeof(MockMethodSizes0));
  778. }
  779. void hasTwoParams(int, int);
  780. void MaybeThrows();
  781. void DoesntThrow() noexcept;
  782. struct MockMethodNoexceptSpecifier {
  783. MOCK_METHOD(void, func1, (), (noexcept));
  784. MOCK_METHOD(void, func2, (), (noexcept(true)));
  785. MOCK_METHOD(void, func3, (), (noexcept(false)));
  786. MOCK_METHOD(void, func4, (), (noexcept(noexcept(MaybeThrows()))));
  787. MOCK_METHOD(void, func5, (), (noexcept(noexcept(DoesntThrow()))));
  788. MOCK_METHOD(void, func6, (), (noexcept(noexcept(DoesntThrow())), const));
  789. MOCK_METHOD(void, func7, (), (const, noexcept(noexcept(DoesntThrow()))));
  790. // Put commas in the noexcept expression
  791. MOCK_METHOD(void, func8, (), (noexcept(noexcept(hasTwoParams(1, 2))), const));
  792. };
  793. TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) {
  794. EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func1()));
  795. EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func2()));
  796. EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func3()));
  797. EXPECT_FALSE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func4()));
  798. EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func5()));
  799. EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func6()));
  800. EXPECT_TRUE(noexcept(std::declval<MockMethodNoexceptSpecifier>().func7()));
  801. EXPECT_EQ(noexcept(std::declval<MockMethodNoexceptSpecifier>().func8()),
  802. noexcept(hasTwoParams(1, 2)));
  803. }
  804. } // namespace gmock_function_mocker_test
  805. } // namespace testing