diff options
author | David Sunderland <sunderland@google.com> | 2018-04-18 23:28:56 (GMT) |
---|---|---|
committer | David Sunderland <sunderland@google.com> | 2018-04-18 23:28:56 (GMT) |
commit | f437f8ca0d4d13d6b1b6279ee40dc61121873a94 (patch) | |
tree | b2ebc307c41ed6658d0e1aefa9197e2b4cc5d52d /googlemock/test/gmock-matchers_test.cc | |
parent | 1f605414cc4137f0ad0cde4d0c7366ff2dfac590 (diff) | |
download | googletest-f437f8ca0d4d13d6b1b6279ee40dc61121873a94.zip googletest-f437f8ca0d4d13d6b1b6279ee40dc61121873a94.tar.gz googletest-f437f8ca0d4d13d6b1b6279ee40dc61121873a94.tar.bz2 |
Clone of unsubmitted cr/176529515. Introduce parameterless expectations.
Diffstat (limited to 'googlemock/test/gmock-matchers_test.cc')
-rw-r--r-- | googlemock/test/gmock-matchers_test.cc | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 16116b5..8170bdb 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3066,6 +3066,44 @@ TEST(AllArgsTest, WorksInWithClause) { EXPECT_EQ(2, helper.Helper('a', 1)); } +class OptionalMatchersHelper { + public: + OptionalMatchersHelper() {} + + MOCK_METHOD0(NoArgs, int()); + + MOCK_METHOD1(OneArg, int(int y)); + + MOCK_METHOD2(TwoArgs, int(char x, int y)); + + MOCK_METHOD1(Overloaded, int(char x)); + MOCK_METHOD2(Overloaded, int(char x, int y)); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(OptionalMatchersHelper); +}; + +TEST(AllArgsTest, WorksWithoutMatchers) { + OptionalMatchersHelper helper; + + ON_CALL(helper, NoArgs).WillByDefault(Return(10)); + ON_CALL(helper, OneArg).WillByDefault(Return(20)); + ON_CALL(helper, TwoArgs).WillByDefault(Return(30)); + + EXPECT_EQ(10, helper.NoArgs()); + EXPECT_EQ(20, helper.OneArg(1)); + EXPECT_EQ(30, helper.TwoArgs('\1', 2)); + + EXPECT_CALL(helper, NoArgs).Times(1); + EXPECT_CALL(helper, OneArg).WillOnce(Return(100)); + EXPECT_CALL(helper, OneArg(17)).WillOnce(Return(200)); + EXPECT_CALL(helper, TwoArgs).Times(0); + + EXPECT_EQ(10, helper.NoArgs()); + EXPECT_EQ(100, helper.OneArg(1)); + EXPECT_EQ(200, helper.OneArg(17)); +} + // Tests that ASSERT_THAT() and EXPECT_THAT() work when the value // matches the matcher. TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) { @@ -6699,4 +6737,3 @@ TEST(NotTest, WorksOnMoveOnlyType) { #if defined_MSC_VER # pragma warning(pop) #endif - |