Lines Matching +full:1 +full:a
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 // Google Mock - a framework for writing C++ mock classes.
69 // This line verifies that a mock method can take a by-reference
74 // Tells Google Mock how to print a value of type Incomplete.
78 // Even though this mock class contains a mock method that takes in TEST()
94 // A type that's not default constructible.
138 // Tests that EXPECT_CALL and ON_CALL compile in a presence of macro
139 // redefining a mock method name. This could happen, for example, when
161 // Tests that a method with expanded name compiles.
168 // and returns a correct value, too.
175 // Tests that a method with expanded name compiles.
194 MockA a; in TEST() local
195 MockA* pa = &a; in TEST()
198 EXPECT_EQ(&a + 1, pa); in TEST()
202 MockA a; in TEST() local
205 ON_CALL(a, DoA(n++)); in TEST()
206 EXPECT_EQ(1, n); in TEST()
212 MockA a; in TEST() local
214 ON_CALL(a, DoA(5)).WillByDefault(Return()); in TEST()
215 ON_CALL(a, DoA(_)).With(_).WillByDefault(Return()); in TEST()
219 MockA a; in TEST() local
223 ON_CALL(a, ReturnResult(_)) in TEST()
232 MockA a; in TEST() local
236 ON_CALL(a, DoA(5)); in TEST()
237 a.DoA(5); in TEST()
243 MockA a; in TEST() local
247 ON_CALL(a, DoA(5)).WillByDefault(Return()).WillByDefault(Return()); in TEST()
255 MockA a; in TEST() local
256 MockA* pa = &a; in TEST()
259 a.DoA(0); in TEST()
260 EXPECT_EQ(&a + 1, pa); in TEST()
264 MockA a; in TEST() local
267 EXPECT_CALL(a, DoA(n++)); in TEST()
268 a.DoA(0); in TEST()
269 EXPECT_EQ(1, n); in TEST()
275 MockA a; in TEST() local
277 EXPECT_CALL(a, DoA(5)).Times(0); in TEST()
278 EXPECT_CALL(a, DoA(6)).With(_).Times(0); in TEST()
282 MockA a; in TEST() local
286 EXPECT_CALL(a, DoA(6)).With(_).With(_); in TEST()
290 a.DoA(6); in TEST()
294 MockA a; in TEST() local
298 EXPECT_CALL(a, DoA(1)).Times(1).With(_); in TEST()
302 a.DoA(1); in TEST()
306 EXPECT_CALL(a, DoA(2)).WillOnce(Return()).With(_); in TEST()
310 a.DoA(2); in TEST()
314 MockA a; in TEST() local
316 EXPECT_CALL(a, DoA(1)).WillOnce(Return()); in TEST()
318 EXPECT_CALL(a, DoA(2)).WillOnce(Return()).WillRepeatedly(Return()); in TEST()
320 a.DoA(1); in TEST()
321 a.DoA(2); in TEST()
322 a.DoA(2); in TEST()
326 MockA a; in TEST() local
330 EXPECT_CALL(a, DoA(1)).Times(1).Times(2); in TEST()
334 a.DoA(1); in TEST()
335 a.DoA(1); in TEST()
339 MockA a; in TEST() local
344 EXPECT_CALL(a, DoA(1)).InSequence(s).Times(1); in TEST()
348 a.DoA(1); in TEST()
352 MockA a; in TEST() local
355 EXPECT_CALL(a, DoA(1)); in TEST()
356 EXPECT_CALL(a, DoA(2)).InSequence(s); in TEST()
358 a.DoA(1); in TEST()
359 a.DoA(2); in TEST()
363 MockA a; in TEST() local
366 EXPECT_CALL(a, DoA(1)).InSequence(s1, s2).InSequence(s1); in TEST()
368 a.DoA(1); in TEST()
372 MockA a; in TEST() local
375 Expectation e = EXPECT_CALL(a, DoA(1)).Times(AnyNumber()); in TEST()
378 EXPECT_CALL(a, DoA(2)).After(e).InSequence(s); in TEST()
382 a.DoA(2); in TEST()
386 MockA a; in TEST() local
391 EXPECT_CALL(a, DoA(1)).WillOnce(Return()).InSequence(s); in TEST()
395 a.DoA(1); in TEST()
399 MockA a; in TEST() local
401 Expectation e = EXPECT_CALL(a, DoA(1)); in TEST()
403 { EXPECT_CALL(a, DoA(2)).WillOnce(Return()).After(e); }, in TEST()
406 a.DoA(1); in TEST()
407 a.DoA(2); in TEST()
411 MockA a; in TEST() local
413 EXPECT_CALL(a, DoA(1)); in TEST()
414 EXPECT_CALL(a, DoA(2)).WillOnce(Return()); in TEST()
416 a.DoA(1); in TEST()
417 a.DoA(2); in TEST()
421 MockA a; in TEST() local
423 EXPECT_CALL(a, DoA(1)) in TEST()
431 MockA a; in TEST() local
435 EXPECT_CALL(a, DoA(1)).WillRepeatedly(Return()).WillOnce(Return()); in TEST()
439 a.DoA(1); in TEST()
443 MockA a; in TEST() local
445 EXPECT_CALL(a, DoA(1)).WillOnce(Return()); in TEST()
446 EXPECT_CALL(a, DoA(2)).WillOnce(Return()).WillRepeatedly(Return()); in TEST()
448 a.DoA(1); in TEST()
449 a.DoA(2); in TEST()
450 a.DoA(2); in TEST()
454 MockA a; in TEST() local
458 EXPECT_CALL(a, DoA(1)).WillRepeatedly(Return()).WillRepeatedly( in TEST()
466 MockA a; in TEST() local
470 EXPECT_CALL(a, DoA(1)).RetiresOnSaturation().WillRepeatedly(Return()); in TEST()
476 MockA a; in TEST() local
478 EXPECT_CALL(a, DoA(1)); in TEST()
479 EXPECT_CALL(a, DoA(1)).RetiresOnSaturation(); in TEST()
481 a.DoA(1); in TEST()
482 a.DoA(1); in TEST()
486 MockA a; in TEST() local
490 EXPECT_CALL(a, DoA(1)).RetiresOnSaturation().RetiresOnSaturation(); in TEST()
494 a.DoA(1); in TEST()
499 MockA a; in TEST() local
500 EXPECT_CALL(a, DoA(1)); in TEST()
501 a.DoA(1); in TEST()
505 MockA a; in TEST()
506 EXPECT_CALL(a, DoA(1)); in TEST()
511 MockA a; in TEST()
512 EXPECT_CALL(a, DoA(1)); in TEST()
513 a.DoA(1); in TEST()
514 a.DoA(1); in TEST()
521 // Tests that Google Mock doesn't print a warning when the number of
530 EXPECT_CALL(b, DoB(1)).Times(AtMost(1)); in TEST()
531 EXPECT_CALL(b, DoB(2)).Times(1).WillRepeatedly(Return(1)); in TEST()
535 .Times(Between(1, 2)) in TEST()
536 .WillOnce(Return(1)) in TEST()
540 // upper bound when there is a WillRepeatedly(). in TEST()
541 EXPECT_CALL(b, DoB(4)).Times(AtMost(3)).WillOnce(Return(1)).WillRepeatedly( in TEST()
559 EXPECT_CALL(b, DoB()).Times(0).WillOnce(Return(1)); // #1 in TEST()
560 EXPECT_CALL(b, DoB()).Times(AtMost(1)).WillOnce(Return(1)).WillOnce( in TEST()
562 EXPECT_CALL(b, DoB(1)) in TEST()
563 .Times(1) in TEST()
564 .WillOnce(Return(1)) in TEST()
569 // there is a WillRepeatedly(). in TEST()
570 EXPECT_CALL(b, DoB()).Times(0).WillRepeatedly(Return(1)); // #4 in TEST()
571 EXPECT_CALL(b, DoB(2)).Times(1).WillOnce(Return(1)).WillRepeatedly( in TEST()
575 b.DoB(1); in TEST()
581 "Expected to be never called, but has 1 WillOnce().", in TEST()
582 output); // #1 in TEST()
590 "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n" in TEST()
596 "and a WillRepeatedly().", in TEST()
601 "Expected to be called once, but has 1 WillOnce() " in TEST()
602 "and a WillRepeatedly().", in TEST()
611 EXPECT_CALL(b, DoB()).Times(Between(2, 3)).WillOnce(Return(1)); in TEST()
619 "but has only 1 WillOnce().", in TEST()
630 MockA a; in TEST() local
631 a.DoA(0); in TEST()
639 MockA a; in TEST() local
640 a.DoA(0); in TEST()
650 MockA a; in TEST()
651 a.DoA(0); in TEST()
656 GMOCK_FLAG_SET(default_mock_behavior, -1); in TEST()
659 MockA a; in TEST() local
660 a.DoA(0); in TEST()
669 MockA a; in TEST() local
670 a.DoA(0); in TEST()
697 ON_CALL(b, DoB(1)).WillByDefault(Return(1)); in TEST()
708 ON_CALL(b, DoB(1)).WillByDefault(Return(1)); in TEST()
725 b.DoB(1); in TEST()
733 EXPECT_CALL(b, DoB(1)).WillRepeatedly(Return(1)); in TEST()
735 EXPECT_EQ(1, b.DoB(1)); in TEST()
758 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2)); in TEST()
760 EXPECT_EQ(1, b.DoB()); in TEST()
767 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2)); in TEST()
769 EXPECT_EQ(1, b.DoB()); in TEST()
775 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2)); in TEST()
777 EXPECT_EQ(1, b.DoB()); in TEST()
786 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2)); in TEST()
788 EXPECT_EQ(1, b.DoB()); in TEST()
793 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2)); in TEST()
795 EXPECT_EQ(1, b.DoB()); in TEST()
803 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2)); in TEST()
811 // It should be possible to return a non-moveable type from a mock action in
812 // C++17 and above, where it's guaranteed that such a type can be initialized
813 // from a prvalue returned from a function.
815 // Define a non-moveable result type. in TEST()
829 // We should be able to use a callable that returns that result as both a in TEST()
857 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillOnce(Return(2)).WillOnce( in TEST()
860 EXPECT_EQ(1, b.DoB()); in TEST()
869 EXPECT_CALL(b, DoB()).WillOnce(Return(1)).WillRepeatedly(Return(2)); in TEST()
871 EXPECT_EQ(1, b.DoB()); in TEST()
882 EXPECT_CALL(b, DoB(_)).Times(1); in TEST()
885 .WillOnce(Return(1)) in TEST()
889 EXPECT_EQ(0, b.DoB(1)); // Shouldn't generate a warning as the in TEST()
891 EXPECT_EQ(1, b.DoB()); in TEST()
912 std::string expect_call_location = FormatFileLocation(__FILE__, __LINE__ + 1); in TEST()
913 EXPECT_CALL(b, DoB()).Times(AnyNumber()).WillOnce(Return(1)); in TEST()
915 EXPECT_EQ(1, b.DoB()); in TEST()
930 on_call_location = FormatFileLocation(__FILE__, __LINE__ + 1); in TEST()
943 MockA a; in TEST() local
944 ON_CALL(a, Binary(_, _)).WillByDefault(Return(true)); in TEST()
945 EXPECT_TRUE(a.Binary(1, 2)); in TEST()
957 MockA a; in TEST() local
958 ON_CALL(a, Binary(_, _)).WillByDefault(Return(true)); in TEST()
959 EXPECT_CALL(a, Binary(0, 0)); in TEST()
960 a.Binary(0, 0); in TEST()
962 EXPECT_NONFATAL_FAILURE(result = a.Binary(1, 2), in TEST()
970 int n = -1; in TEST()
971 EXPECT_NONFATAL_FAILURE(n = b.DoB(1), "Unexpected mock function call"); in TEST()
980 EXPECT_CALL(a1, DoA(1)); in TEST()
981 a1.DoA(1); in TEST()
982 // Ideally we should match the failure message against a regex, but in TEST()
989 "Google Mock tried the following 1 expectation, but it didn't match:"); in TEST()
992 " Expected arg #0: is equal to 1\n" in TEST()
999 EXPECT_CALL(a2, DoA(1)); in TEST()
1001 a2.DoA(1); in TEST()
1009 "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n" in TEST()
1010 " Expected arg #0: is equal to 1\n" in TEST()
1016 "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n" in TEST()
1028 EXPECT_CALL(b1, DoB(1)); in TEST()
1029 b1.DoB(1); in TEST()
1035 "Google Mock tried the following 1 expectation, but it didn't match:"); in TEST()
1038 " Expected arg #0: is equal to 1\n" in TEST()
1048 EXPECT_CALL(b, DoB(1)).RetiresOnSaturation(); in TEST()
1050 b.DoB(1); in TEST()
1051 EXPECT_NONFATAL_FAILURE(b.DoB(1), in TEST()
1060 EXPECT_CALL(b, DoB(1)); in TEST()
1063 " Expected arg #0: is equal to 1\n" in TEST()
1065 b.DoB(1); in TEST()
1073 EXPECT_CALL(b, DoB(1)).InSequence(s1); in TEST()
1087 ASSERT_EQ(1, failures.size()); in TEST()
1100 "(.|\n)*: pre-requisite #1")); in TEST()
1107 EXPECT_THAT(r.message(), ContainsRegex(": pre-requisite #1")); in TEST()
1110 b.DoB(1); in TEST()
1117 MockA a; in TEST() local
1122 EXPECT_ANY_THROW(a.ReturnNonDefaultConstructible()); in TEST()
1124 EXPECT_DEATH_IF_SUPPORTED(a.ReturnNonDefaultConstructible(), ""); in TEST()
1133 MockA a; in TEST() local
1134 ON_CALL(a, Binary(_, _)).WillByDefault(Return(true)); in TEST()
1135 EXPECT_CALL(a, Binary(0, 0)); in TEST()
1136 a.Binary(0, 0); in TEST()
1138 EXPECT_NONFATAL_FAILURE(result = a.Binary(0, 0), in TEST()
1146 int n = -1; in TEST()
1153 // Tests that when a void function is called too many times,
1156 MockA a; in TEST() local
1157 EXPECT_CALL(a, DoA(_)).Description("DoA Method").Times(0); in TEST()
1159 a.DoA(9), in TEST()
1167 // Tests that when a non-void function is called too many times, the
1172 b.DoB(1); in TEST()
1186 MockA a; in TEST() local
1190 EXPECT_CALL(a, DoA(1)); in TEST()
1191 EXPECT_CALL(a, DoA(2)); in TEST()
1196 a.DoA(2); in TEST()
1200 a.DoA(1); in TEST()
1201 a.DoA(2); in TEST()
1205 MockA a; in TEST() local
1209 EXPECT_CALL(a, DoA(1)); in TEST()
1213 EXPECT_CALL(a, DoA(2)); in TEST()
1214 EXPECT_CALL(a, DoA(3)); in TEST()
1220 a.DoA(1); in TEST()
1221 a.DoA(3); in TEST()
1225 a.DoA(2); in TEST()
1226 a.DoA(3); in TEST()
1230 MockA a; in TEST() local
1234 EXPECT_CALL(a, DoA(1)); in TEST()
1235 EXPECT_CALL(a, DoA(2)); in TEST()
1237 EXPECT_CALL(a, DoA(3)); in TEST()
1241 a.DoA(2); in TEST()
1245 a.DoA(3); in TEST()
1246 a.DoA(1); in TEST()
1247 a.DoA(2); in TEST()
1253 MockA a; in TEST() local
1256 EXPECT_CALL(a, DoA(1)); in TEST()
1259 a.DoA(1); in TEST()
1264 MockA a; in TEST() local
1267 EXPECT_CALL(a, DoA(1)); in TEST()
1271 a.DoA(1); in TEST()
1275 // Tests that the calls must be in strict order when a complete order
1278 MockA a; in TEST() local
1279 ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result())); in TEST()
1282 EXPECT_CALL(a, ReturnResult(1)).InSequence(s); in TEST()
1283 EXPECT_CALL(a, ReturnResult(2)).InSequence(s); in TEST()
1284 EXPECT_CALL(a, ReturnResult(3)).InSequence(s); in TEST()
1286 a.ReturnResult(1); in TEST()
1288 // May only be called after a.ReturnResult(2). in TEST()
1289 EXPECT_NONFATAL_FAILURE(a.ReturnResult(3), "Unexpected mock function call"); in TEST()
1291 a.ReturnResult(2); in TEST()
1292 a.ReturnResult(3); in TEST()
1295 // Tests that the calls must be in strict order when a complete order
1298 MockA a; in TEST() local
1299 ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result())); in TEST()
1302 EXPECT_CALL(a, ReturnResult(1)).InSequence(s); in TEST()
1303 EXPECT_CALL(a, ReturnResult(2)).InSequence(s); in TEST()
1305 // May only be called after a.ReturnResult(1). in TEST()
1306 EXPECT_NONFATAL_FAILURE(a.ReturnResult(2), "Unexpected mock function call"); in TEST()
1308 a.ReturnResult(1); in TEST()
1309 a.ReturnResult(2); in TEST()
1312 // Tests specifying a DAG using multiple sequences.
1320 // a.ReturnResult(1) ==> in PartialOrderTest()
1321 // a.ReturnResult(2) * n ==> a.ReturnResult(3) in PartialOrderTest()
1324 EXPECT_CALL(a_, ReturnResult(1)).InSequence(x); in PartialOrderTest()
1335 a_.ReturnResult(1); in TEST_F()
1346 // May only be called after ReturnResult(1). in TEST_F()
1349 a_.ReturnResult(1); in TEST_F()
1359 a_.ReturnResult(1); in TEST_F()
1366 a_.ReturnResult(1); in TEST_F()
1376 MockA a; in TEST() local
1379 EXPECT_CALL(a, DoA(1)).InSequence(s); in TEST()
1380 EXPECT_CALL(a, DoA(_)).InSequence(s).RetiresOnSaturation(); in TEST()
1381 EXPECT_CALL(a, DoA(1)).InSequence(s); in TEST()
1383 a.DoA(1); in TEST()
1384 a.DoA(2); in TEST()
1385 a.DoA(1); in TEST()
1391 MockA a; in TEST() local
1395 Expectation e2 = EXPECT_CALL(a, DoA(2)); in TEST()
1396 Expectation e3 = EXPECT_CALL(a, DoA(3)).With(_); in TEST()
1399 Expectation e4 = EXPECT_CALL(a, DoA(4)).Times(1); in TEST()
1400 Expectation e5 = EXPECT_CALL(a, DoA(5)).InSequence(s); in TEST()
1402 Expectation e6 = EXPECT_CALL(a, DoA(6)).After(e2); in TEST()
1403 Expectation e7 = EXPECT_CALL(a, DoA(7)).WillOnce(Return()); in TEST()
1404 Expectation e8 = EXPECT_CALL(a, DoA(8)).WillRepeatedly(Return()); in TEST()
1405 Expectation e9 = EXPECT_CALL(a, DoA(9)).RetiresOnSaturation(); in TEST()
1412 a.DoA(2); in TEST()
1413 a.DoA(3); in TEST()
1414 a.DoA(4); in TEST()
1415 a.DoA(5); in TEST()
1416 a.DoA(6); in TEST()
1417 a.DoA(7); in TEST()
1418 a.DoA(8); in TEST()
1419 a.DoA(9); in TEST()
1423 MockA a; in TEST() local
1425 Expectation e2 = EXPECT_CALL(a, DoA(1)); in TEST()
1432 a.DoA(1); in TEST()
1442 MockA a; in TEST() local
1447 ExpectationSet es2 = EXPECT_CALL(a, DoA(1)); // Ctor from EXPECT_CALL. in TEST()
1455 EXPECT_EQ(1, es2.size()); in TEST()
1456 EXPECT_EQ(1, es3.size()); in TEST()
1457 EXPECT_EQ(1, es4.size()); in TEST()
1458 EXPECT_EQ(1, es5.size()); in TEST()
1459 EXPECT_EQ(1, es6.size()); in TEST()
1460 EXPECT_EQ(1, es7.size()); in TEST()
1467 a.DoA(1); in TEST()
1475 EXPECT_EQ(1, es1.size()); in TEST()
1484 EXPECT_EQ(1, es1.size()); in TEST()
1487 MockA a; in TEST() local
1488 Expectation e2 = EXPECT_CALL(a, DoA(1)); in TEST()
1497 a.DoA(1); in TEST()
1505 EXPECT_EQ(1, es.size()); in TEST()
1507 MockA a; in TEST() local
1508 es += EXPECT_CALL(a, DoA(1)); in TEST()
1511 a.DoA(1); in TEST()
1529 MockA a; in TEST() local
1531 es += EXPECT_CALL(a, DoA(1)); in TEST()
1532 es += EXPECT_CALL(a, DoA(2)); in TEST()
1533 EXPECT_CALL(a, DoA(3)).After(es); in TEST()
1535 a.DoA(1); in TEST()
1536 a.DoA(2); in TEST()
1537 a.DoA(3); in TEST()
1541 MockA a; in TEST() local
1545 const Expectation e1 = EXPECT_CALL(a, DoA(1)); in TEST()
1547 EXPECT_CALL(a, DoA(2)).After(e2); in TEST()
1549 a.DoA(1); in TEST()
1552 a.DoA(2); in TEST()
1557 MockA a; in TEST() local
1561 // a.DoA(1) ==> b.DoB() ==> a.DoA(2) in TEST()
1562 Expectation e1 = EXPECT_CALL(a, DoA(1)); in TEST()
1564 EXPECT_CALL(a, DoA(2)).After(e2); in TEST()
1566 a.DoA(1); in TEST()
1569 EXPECT_NONFATAL_FAILURE(a.DoA(2), "Unexpected mock function call"); in TEST()
1572 a.DoA(2); in TEST()
1577 MockA a; in TEST() local
1581 // a.DoA(1) ==> b.DoB() * 2 ==> a.DoA(2) in TEST()
1582 Expectation e1 = EXPECT_CALL(a, DoA(1)); in TEST()
1584 EXPECT_CALL(a, DoA(2)).After(e2); in TEST()
1586 a.DoA(1); in TEST()
1590 EXPECT_NONFATAL_FAILURE(a.DoA(2), "Unexpected mock function call"); in TEST()
1593 a.DoA(2); in TEST()
1598 MockA a; in TEST() local
1599 ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result())); in TEST()
1602 // a.DoA(1) ==> in TEST()
1603 // a.DoA(2) ==> a.ReturnResult(3) in TEST()
1604 Expectation e = EXPECT_CALL(a, DoA(1)); in TEST()
1605 const ExpectationSet es = EXPECT_CALL(a, DoA(2)); in TEST()
1606 EXPECT_CALL(a, ReturnResult(3)).After(e, es); in TEST()
1609 EXPECT_NONFATAL_FAILURE(a.ReturnResult(3), "Unexpected mock function call"); in TEST()
1611 a.DoA(2); in TEST()
1612 a.DoA(1); in TEST()
1613 a.ReturnResult(3); in TEST()
1618 MockA a; in TEST() local
1621 // a.DoA(1) ==> in TEST()
1622 // a.DoA(2) ==> a.DoA(3) in TEST()
1623 Expectation e = EXPECT_CALL(a, DoA(1)); in TEST()
1624 const ExpectationSet es = EXPECT_CALL(a, DoA(2)); in TEST()
1625 EXPECT_CALL(a, DoA(3)).After(e, es); in TEST()
1627 a.DoA(2); in TEST()
1630 EXPECT_NONFATAL_FAILURE(a.DoA(3), "Unexpected mock function call"); in TEST()
1632 a.DoA(1); in TEST()
1633 a.DoA(3); in TEST()
1638 MockA a; in TEST() local
1640 Expectation e = EXPECT_CALL(a, DoA(1)); in TEST()
1641 EXPECT_CALL(a, DoA(2)).InSequence(s); in TEST()
1642 EXPECT_CALL(a, DoA(3)).InSequence(s).After(e); in TEST()
1644 a.DoA(1); in TEST()
1647 EXPECT_NONFATAL_FAILURE(a.DoA(3), "Unexpected mock function call"); in TEST()
1649 a.DoA(2); in TEST()
1650 a.DoA(3); in TEST()
1655 MockA a; in TEST() local
1656 Expectation e1 = EXPECT_CALL(a, DoA(1)); in TEST()
1657 Expectation e2 = EXPECT_CALL(a, DoA(2)); in TEST()
1658 Expectation e3 = EXPECT_CALL(a, DoA(3)); in TEST()
1659 EXPECT_CALL(a, DoA(4)).After(e1).After(e2).After(e3); in TEST()
1661 a.DoA(3); in TEST()
1662 a.DoA(1); in TEST()
1663 a.DoA(2); in TEST()
1664 a.DoA(4); in TEST()
1669 MockA a; in TEST() local
1670 Expectation e1 = EXPECT_CALL(a, DoA(1)); in TEST()
1671 Expectation e2 = EXPECT_CALL(a, DoA(2)); in TEST()
1672 Expectation e3 = EXPECT_CALL(a, DoA(3)); in TEST()
1673 ExpectationSet es1 = EXPECT_CALL(a, DoA(4)); in TEST()
1674 ExpectationSet es2 = EXPECT_CALL(a, DoA(5)); in TEST()
1675 EXPECT_CALL(a, DoA(6)).After(e1, e2, e3, es1, es2); in TEST()
1677 a.DoA(5); in TEST()
1678 a.DoA(2); in TEST()
1679 a.DoA(4); in TEST()
1680 a.DoA(1); in TEST()
1681 a.DoA(3); in TEST()
1682 a.DoA(6); in TEST()
1687 MockA a; in TEST() local
1688 ON_CALL(a, ReturnResult(_)).WillByDefault(Return(Result())); in TEST()
1691 // DoA(1) ==> in TEST()
1693 Expectation e1 = EXPECT_CALL(a, DoA(1)); in TEST()
1694 Expectation e2 = EXPECT_CALL(a, DoA(2)); in TEST()
1698 EXPECT_CALL(a, ReturnResult(3)).After(e1, e2, es, e1); in TEST()
1700 a.DoA(1); in TEST()
1703 EXPECT_NONFATAL_FAILURE(a.ReturnResult(3), "Unexpected mock function call"); in TEST()
1705 a.DoA(2); in TEST()
1706 a.ReturnResult(3); in TEST()
1712 MockA a; in TEST() local
1713 ExpectationSet es1 = EXPECT_CALL(a, DoA(1)); in TEST()
1714 Expectation e2 = EXPECT_CALL(a, DoA(2)); in TEST()
1715 EXPECT_CALL(a, DoA(3)).After(es1); in TEST()
1718 a.DoA(1); in TEST()
1719 a.DoA(3); in TEST()
1720 a.DoA(2); in TEST()
1724 // after a mock object owning one of their pre-requisites has died.
1729 MockA* const a = new MockA; in TEST() local
1734 EXPECT_CALL(*b1, DoB(_)).WillOnce(Return(1)); in TEST()
1735 EXPECT_CALL(*a, Binary(_, _)) in TEST()
1741 EXPECT_EQ(1, b1->DoB(1)); in TEST()
1743 // a's pre-requisite has died. in TEST()
1744 EXPECT_TRUE(a->Binary(0, 1)); in TEST()
1746 // a's successor has died. in TEST()
1747 EXPECT_TRUE(a->Binary(1, 2)); in TEST()
1748 delete a; in TEST()
1754 MockA* const a = new MockA; in TEST() local
1759 EXPECT_CALL(*b1, DoB(_)).WillOnce(Return(1)); in TEST()
1760 EXPECT_CALL(*a, Binary(_, _)).Times(AnyNumber()); in TEST()
1764 delete a; // a is trivially satisfied. in TEST()
1765 EXPECT_EQ(1, b1->DoB(1)); in TEST()
1771 // Tests that it's OK to delete a mock object itself in its action.
1782 MockA* const a = new MockA; in TEST() local
1783 EXPECT_CALL(*a, DoA(_)).WillOnce(Delete(a)); in TEST()
1784 a->DoA(42); // This will cause a to be deleted. in TEST()
1788 MockA* const a = new MockA; in TEST() local
1789 EXPECT_CALL(*a, ReturnResult(_)).WillOnce(DoAll(Delete(a), Return(Result()))); in TEST()
1790 a->ReturnResult(42); // This will cause a to be deleted. in TEST()
1796 MockA* const a = new MockA; in TEST() local
1801 EXPECT_CALL(*b1, DoB(_)).WillOnce(Return(1)); in TEST()
1802 EXPECT_CALL(*a, Binary(_, _)).Times(AnyNumber()); in TEST()
1806 delete a; // a is trivially satisfied. in TEST()
1808 EXPECT_EQ(1, b1->DoB(1)); in TEST()
1816 MockA* const a = new MockA; in TEST() local
1822 EXPECT_CALL(*a, Binary(_, _)).Times(AnyNumber()); in TEST()
1827 EXPECT_NONFATAL_FAILURE(a->Binary(0, 1), "Unexpected mock function call"); in TEST()
1828 EXPECT_NONFATAL_FAILURE(b2->DoB(1), "Unexpected mock function call"); in TEST()
1829 delete a; in TEST()
1857 MockA* a = new MockA; in TEST() local
1860 EXPECT_CALL(*a, DoA(1)).Times(EvenNumber()).InSequence(s); in TEST()
1861 EXPECT_CALL(*a, DoA(2)).Times(AnyNumber()).InSequence(s); in TEST()
1862 EXPECT_CALL(*a, DoA(3)).Times(AnyNumber()); in TEST()
1864 a->DoA(3); in TEST()
1865 a->DoA(1); in TEST()
1866 EXPECT_NONFATAL_FAILURE(a->DoA(2), "Unexpected mock function call"); in TEST()
1867 EXPECT_NONFATAL_FAILURE(delete a, "to be called even number of times"); in TEST()
1870 // The following tests verify the message generated when a mock
1916 // Tests that an uninteresting mock function call on a naggy mock
1917 // generates a warning without the stack trace when
1930 // Tests that an uninteresting mock function call on a naggy mock
1931 // generates a warning containing the stack trace when
1948 // Verifies that a void mock function's name appears in the stack in TEST()
1952 // Verifies that a non-void mock function's name appears in the in TEST()
1962 // Tests that an uninteresting mock function call on a naggy mock
1966 // A non-void mock function. in TEST()
1979 // A void mock function. in TEST()
1990 // A void function has no return value to print. in TEST()
2021 MockA a; in TestExpectedCall() local
2022 EXPECT_CALL(a, DoA(5)); in TestExpectedCall()
2023 EXPECT_CALL(a, Binary(_, 1)).WillOnce(Return(true)); in TestExpectedCall()
2025 // A void-returning function. in TestExpectedCall()
2027 a.DoA(5); in TestExpectedCall()
2029 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n" in TestExpectedCall()
2034 // A non-void-returning function. in TestExpectedCall()
2036 a.Binary(2, 1); in TestExpectedCall()
2038 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n" in TestExpectedCall()
2039 " Function call: Binary(2, 1)\n" in TestExpectedCall()
2045 // Tests how the flag affects uninteresting calls on a naggy mock.
2047 NaggyMock<MockA> a; in TestUninterestingCallOnNaggyMock() local
2057 // A void-returning function. in TestUninterestingCallOnNaggyMock()
2059 a.DoA(5); in TestUninterestingCallOnNaggyMock()
2067 // A non-void-returning function. in TestUninterestingCallOnNaggyMock()
2069 a.Binary(2, 1); in TestUninterestingCallOnNaggyMock()
2073 " Function call: Binary(2, 1)\n" in TestUninterestingCallOnNaggyMock()
2114 // A helper class that generates a failure when printed. We use it to
2115 // ensure that Google Mock doesn't print a value (even to an internal
2120 ADD_FAILURE() << "Google Mock is printing a value that shouldn't be " in PrintTo()
2155 helper_.Foo(PrintMeNot()); // This should generate a warning. in TEST_F()
2161 MockA* a = new MockA; in TEST() local
2162 Mock::AllowLeak(a); in TEST()
2166 MockA* a = new MockA; in TEST() local
2167 Mock::AllowLeak(a); in TEST()
2168 ON_CALL(*a, DoA(_)).WillByDefault(Return()); in TEST()
2169 a->DoA(0); in TEST()
2173 MockA* a = new MockA; in TEST() local
2174 ON_CALL(*a, DoA(_)).WillByDefault(Return()); in TEST()
2175 Mock::AllowLeak(a); in TEST()
2179 MockA* a = new MockA; in TEST() local
2180 Mock::AllowLeak(a); in TEST()
2181 EXPECT_CALL(*a, DoA(_)); in TEST()
2182 a->DoA(0); in TEST()
2186 MockA* a = new MockA; in TEST() local
2187 EXPECT_CALL(*a, DoA(_)).Times(AnyNumber()); in TEST()
2188 Mock::AllowLeak(a); in TEST()
2192 MockA* a = new MockA; in TEST() local
2193 ON_CALL(*a, DoA(_)).WillByDefault(Return()); in TEST()
2194 EXPECT_CALL(*a, DoA(_)).Times(AnyNumber()); in TEST()
2195 Mock::AllowLeak(a); in TEST()
2198 // Tests that we can verify and clear a mock object's expectations
2207 EXPECT_EQ(0, b.DoB(1)); in TEST()
2210 // Tests that we can verify and clear a mock object's expectations
2215 EXPECT_CALL(b, DoB()).WillOnce(Return(1)); in TEST()
2222 EXPECT_EQ(0, b.DoB(1)); in TEST()
2225 // Tests that we can verify and clear a mock object's expectations
2230 EXPECT_CALL(b, DoB()).WillOnce(Return(1)); in TEST()
2239 EXPECT_EQ(0, b.DoB(1)); in TEST()
2242 // Tests that we can verify and clear a mock object's expectations
2246 EXPECT_CALL(b, DoB()).WillOnce(Return(1)); in TEST()
2249 b.DoB(1); in TEST()
2255 EXPECT_EQ(0, b.DoB(1)); in TEST()
2258 // Tests that we can verify and clear a mock object's expectations
2259 // when a method has more than one expectation.
2262 EXPECT_CALL(b, DoB(0)).WillOnce(Return(1)); in TEST()
2264 b.DoB(1); in TEST()
2273 EXPECT_EQ(0, b.DoB(1)); in TEST()
2284 EXPECT_CALL(b, DoB(_)).WillOnce(Return(1)); in TEST()
2285 b.DoB(1); in TEST()
2292 EXPECT_EQ(0, b.DoB(1)); in TEST()
2295 // Tests that we can clear a mock object's default actions when none
2299 // If this crashes or generates a failure, the test will catch it. in TEST()
2304 // Tests that we can clear a mock object's default actions when some,
2308 ON_CALL(b, DoB()).WillByDefault(Return(1)); in TEST()
2316 // Tests that we can clear a mock object's default actions when all of
2320 ON_CALL(b, DoB()).WillByDefault(Return(1)); in TEST()
2332 // Tests that we can clear a mock object's default actions when a
2336 ON_CALL(b, DoB(0)).WillByDefault(Return(1)); in TEST()
2344 EXPECT_EQ(0, b.DoB(1)); in TEST()
2347 // Tests that we can call VerifyAndClear() on a mock object multiple
2351 ON_CALL(b, DoB()).WillByDefault(Return(1)); in TEST()
2355 ON_CALL(b, DoB(_)).WillByDefault(Return(1)); in TEST()
2359 EXPECT_EQ(0, b.DoB(1)); in TEST()
2365 ON_CALL(b, DoB()).WillByDefault(Return(1)); in TEST()
2366 EXPECT_CALL(b, DoB(1)).WillOnce(Return(2)); in TEST()
2369 b.DoB(1); in TEST()
2375 EXPECT_EQ(0, b.DoB(1)); in TEST()
2381 ON_CALL(b, DoB(_)).WillByDefault(Return(1)); in TEST()
2384 b.DoB(1); in TEST()
2393 EXPECT_EQ(0, b.DoB(1)); in TEST()
2397 // expectations are set on a const mock object.
2400 ON_CALL(Const(b), DoB()).WillByDefault(Return(1)); in TEST()
2411 EXPECT_EQ(0, b.DoB(1)); in TEST()
2414 // Tests that we can set default actions and expectations on a mock
2418 ON_CALL(b, DoB()).WillByDefault(Return(1)); in TEST()
2420 b.DoB(1); in TEST()
2428 EXPECT_EQ(4, b.DoB(1)); in TEST()
2434 MockA a; in TEST() local
2438 ON_CALL(a, Binary(_, _)).WillByDefault(Return(true)); in TEST()
2439 EXPECT_CALL(a, Binary(_, _)).WillOnce(DoDefault()).WillOnce(Return(false)); in TEST()
2441 ON_CALL(b1, DoB()).WillByDefault(Return(1)); in TEST()
2450 // Verifies that the default actions and expectations of a and b1 in TEST()
2452 EXPECT_TRUE(a.Binary(0, 0)); in TEST()
2453 EXPECT_FALSE(a.Binary(0, 0)); in TEST()
2455 EXPECT_EQ(1, b1.DoB()); in TEST()
2461 std::shared_ptr<MockA> a(new MockA); in TEST() local
2464 // EXPECT_CALL stores a reference to a inside test_mock. in TEST()
2466 .WillRepeatedly(SetArgPointee<0>(a)); in TEST()
2468 // Throw away the reference to the mock that we have in a. After this, the in TEST()
2470 a.reset(); in TEST()
2473 // to the mock object originally pointed to by a. This will cause the MockA in TEST()
2475 // The state of all mocks is protected by a single global lock, but there in TEST()
2481 std::shared_ptr<MockA> a(new MockA); in TEST() local
2484 // ON_CALL stores a reference to a inside test_mock. in TEST()
2485 ON_CALL(test_mock, AcceptReference(_)).WillByDefault(SetArgPointee<0>(a)); in TEST()
2487 // Throw away the reference to the mock that we have in a. After this, the in TEST()
2489 a.reset(); in TEST()
2492 // to the mock object originally pointed to by a. This will cause the MockA in TEST()
2494 // The state of all mocks is protected by a single global lock, but there in TEST()
2498 // Tests that a mock function's action can call a mock function
2499 // (either the same function or a different one) either as an explicit
2500 // action or as a default action without causing a dead lock. It
2504 MockA a; in TEST() local
2506 ON_CALL(a, DoA(_)).WillByDefault( in TEST()
2508 EXPECT_CALL(a, DoA(1)); in TEST()
2509 EXPECT_CALL(a, DoA(1)) in TEST()
2510 .WillOnce(Invoke(&a, &MockA::DoA)) in TEST()
2514 a.DoA(1); in TEST()
2515 // This will match the second EXPECT_CALL() and trigger another a.DoA(1), in TEST()
2516 // which will in turn match the first EXPECT_CALL() and trigger a call to in TEST()
2522 MockA a; in TEST() local
2524 ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0)); in TEST()
2526 ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0)); in TEST()
2528 a.DoA(17); in TEST()
2531 a.DoA(47); in TEST()
2535 ON_CALL(a, Binary).WillByDefault(Return(true)); in TEST()
2536 ON_CALL(a, Binary(_, 14)).WillByDefault(Return(false)); in TEST()
2537 EXPECT_THAT(a.Binary(14, 17), true); in TEST()
2538 EXPECT_THAT(a.Binary(17, 14), false); in TEST()
2547 EXPECT_THAT(b.DoB(1), 0); // default value in TEST()
2580 EXPECT_THAT(mock.Overloaded(1), 7); in TEST()
2585 EXPECT_THAT(const_mock.Overloaded(1), 0); in TEST()