30 #include "gmock/gmock-nice-strict.h"
34 #include "gmock/gmock.h"
35 #include "gtest/gtest-spi.h"
36 #include "gtest/gtest.h"
51 namespace gmock_nice_strict_test {
58 #if GTEST_HAS_STREAM_REDIRECTION
64 class NotDefaultConstructible {
85 class MockFoo :
public Foo {
105 static_cast<char>(a6) + a7 + a8 + (a9 ?
'T' :
'F') + (a10 ?
'T' :
'F');
138 #if GTEST_HAS_STREAM_REDIRECTION
141 TEST(RawMockTest, WarningForUninterestingCall) {
149 raw_foo.DoThat(
true);
151 HasSubstr(
"Uninteresting mock function call"));
158 TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
162 MockFoo*
const raw_foo =
new MockFoo;
170 HasSubstr(
"Uninteresting mock function call"));
177 TEST(RawMockTest, InfoForUninterestingCall) {
185 HasSubstr(
"Uninteresting mock function call"));
190 TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
198 TEST(NiceMockTest, NoWarningForUninterestingCall) {
199 NiceMock<MockFoo> nice_foo;
203 nice_foo.DoThat(
true);
209 TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
210 NiceMock<MockFoo>*
const nice_foo =
new NiceMock<MockFoo>;
222 TEST(NiceMockTest, InfoForUninterestingCall) {
223 NiceMock<MockFoo> nice_foo;
230 HasSubstr(
"Uninteresting mock function call"));
235 #endif // GTEST_HAS_STREAM_REDIRECTION
238 TEST(NiceMockTest, AllowsExpectedCall) {
239 NiceMock<MockFoo> nice_foo;
248 TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
249 NiceMock<MockFoo> nice_foo;
250 #if GTEST_HAS_EXCEPTIONS
252 nice_foo.ReturnNonDefaultConstructible();
254 }
catch (
const std::runtime_error&
ex) {
263 TEST(NiceMockTest, UnexpectedCallFails) {
264 NiceMock<MockFoo> nice_foo;
272 TEST(NiceMockTest, NonDefaultConstructor) {
273 NiceMock<MockBar> nice_bar(
"hi");
277 nice_bar.That(5,
true);
282 TEST(NiceMockTest, NonDefaultConstructor10) {
283 NiceMock<MockBar> nice_bar(
'a',
'b',
"c",
"d",
'e',
'f',
284 "g",
"h",
true,
false);
288 nice_bar.That(5,
true);
291 TEST(NiceMockTest, AllowLeak) {
292 NiceMock<MockFoo>* leaked =
new NiceMock<MockFoo>;
293 Mock::AllowLeak(leaked);
298 TEST(NiceMockTest, MoveOnlyConstructor) {
299 NiceMock<MockBaz> nice_baz(MockBaz::MoveOnly{});
304 TEST(NiceMockTest, AcceptsClassNamedMock) {
305 NiceMock< ::Mock> nice;
310 TEST(NiceMockTest, IsNiceInDestructor) {
317 TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
324 #if GTEST_HAS_STREAM_REDIRECTION
327 TEST(NaggyMockTest, WarningForUninterestingCall) {
331 NaggyMock<MockFoo> naggy_foo;
335 naggy_foo.DoThat(
true);
337 HasSubstr(
"Uninteresting mock function call"));
344 TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
348 NaggyMock<MockFoo>*
const naggy_foo =
new NaggyMock<MockFoo>;
356 HasSubstr(
"Uninteresting mock function call"));
361 #endif // GTEST_HAS_STREAM_REDIRECTION
364 TEST(NaggyMockTest, AllowsExpectedCall) {
365 NaggyMock<MockFoo> naggy_foo;
372 TEST(NaggyMockTest, UnexpectedCallFails) {
373 NaggyMock<MockFoo> naggy_foo;
377 "called more times than expected");
382 TEST(NaggyMockTest, NonDefaultConstructor) {
383 NaggyMock<MockBar> naggy_bar(
"hi");
387 naggy_bar.That(5,
true);
392 TEST(NaggyMockTest, NonDefaultConstructor10) {
393 NaggyMock<MockBar> naggy_bar(
'0',
'1',
"2",
"3",
'4',
'5',
394 "6",
"7",
true,
false);
395 EXPECT_EQ(
"01234567TF", naggy_bar.str());
398 naggy_bar.That(5,
true);
401 TEST(NaggyMockTest, AllowLeak) {
402 NaggyMock<MockFoo>* leaked =
new NaggyMock<MockFoo>;
403 Mock::AllowLeak(leaked);
408 TEST(NaggyMockTest, MoveOnlyConstructor) {
409 NaggyMock<MockBaz> naggy_baz(MockBaz::MoveOnly{});
414 TEST(NaggyMockTest, AcceptsClassNamedMock) {
415 NaggyMock< ::Mock> naggy;
420 TEST(NaggyMockTest, IsNaggyInDestructor) {
431 HasSubstr(
"Uninteresting mock function call"));
436 TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
444 TEST(StrictMockTest, AllowsExpectedCall) {
445 StrictMock<MockFoo> strict_foo;
452 TEST(StrictMockTest, UnexpectedCallFails) {
453 StrictMock<MockFoo> strict_foo;
457 "called more times than expected");
461 TEST(StrictMockTest, UninterestingCallFails) {
462 StrictMock<MockFoo> strict_foo;
465 "Uninteresting mock function call");
470 TEST(StrictMockTest, UninterestingCallFailsAfterDeath) {
471 StrictMock<MockFoo>*
const strict_foo =
new StrictMock<MockFoo>;
477 "Uninteresting mock function call");
482 TEST(StrictMockTest, NonDefaultConstructor) {
483 StrictMock<MockBar> strict_bar(
"hi");
487 "Uninteresting mock function call");
492 TEST(StrictMockTest, NonDefaultConstructor10) {
493 StrictMock<MockBar> strict_bar(
'a',
'b',
"c",
"d",
'e',
'f',
494 "g",
"h",
true,
false);
495 EXPECT_EQ(
"abcdefghTF", strict_bar.str());
498 "Uninteresting mock function call");
501 TEST(StrictMockTest, AllowLeak) {
502 StrictMock<MockFoo>* leaked =
new StrictMock<MockFoo>;
503 Mock::AllowLeak(leaked);
508 TEST(StrictMockTest, MoveOnlyConstructor) {
509 StrictMock<MockBaz> strict_baz(MockBaz::MoveOnly{});
514 TEST(StrictMockTest, AcceptsClassNamedMock) {
515 StrictMock< ::Mock> strict;
520 TEST(StrictMockTest, IsStrictInDestructor) {
527 "Uninteresting mock function call");
530 TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {