From b539167cf0254f521b791e908f6d3a5ff3f30245 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 25 Apr 2018 13:10:41 -0400 Subject: merging, --- googlemock/test/gmock-matchers_test.cc | 67 +++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) (limited to 'googlemock/test/gmock-matchers_test.cc') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 8b115cd8..fedc248d 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -59,13 +59,6 @@ # include // NOLINT #endif -// Disable MSVC2015 warning for std::pair: -// "decorated name length exceeded, name was truncated". -#if defined _MSC_VER -# pragma warning(push) -# pragma warning(disable:4503) -#endif - #if GTEST_LANG_CXX11 # include #endif @@ -749,6 +742,13 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { EXPECT_FALSE(m3.Matches(239)); } +// ConvertibleFromAny does not work with MSVC. resulting in +// error C2440: 'initializing': cannot convert from 'Eq' to 'M' +// No constructor could take the source type, or constructor overload +// resolution was ambiguous + +#if !defined _MSC_VER + // The below ConvertibleFromAny struct is implicitly constructible from anything // and when in the same namespace can interact with other tests. In particular, // if it is in the same namespace as other tests and one removes @@ -761,7 +761,7 @@ namespace convertible_from_any { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; @@ -789,6 +789,8 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any +#endif // !defined _MSC_VER + struct IntReferenceWrapper { IntReferenceWrapper(const int& a_value) : value(&a_value) {} const int* value; @@ -893,6 +895,8 @@ TEST(SafeMatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } +#if !defined _MSC_VER + namespace convertible_from_any { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { Matcher m = SafeMatcherCast(1); @@ -908,6 +912,8 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) { } } // namespace convertible_from_any +#endif // !defined _MSC_VER + TEST(SafeMatcherCastTest, ValueIsNotCopied) { int n = 42; Matcher m = SafeMatcherCast(n); @@ -2539,7 +2545,7 @@ TEST(AllOfTest, VariadicMatchesWhenAllMatch) { ::testing::AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); Matcher m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), Ne(10), Ne(11)); - EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11))))))))))")); + EXPECT_THAT(Describe(m), EndsWith("and (isn't equal to 11)")); AllOfMatches(11, m); AllOfMatches(50, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), Ne(10), Ne(11), Ne(12), Ne(13), Ne(14), Ne(15), @@ -2733,7 +2739,7 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) { // on ADL. Matcher m = ::testing::AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); - EXPECT_THAT(Describe(m), EndsWith("or (is equal to 11))))))))))")); + EXPECT_THAT(Describe(m), EndsWith("or (is equal to 11)")); AnyOfMatches(11, m); AnyOfMatches(50, AnyOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, @@ -3093,6 +3099,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) { @@ -6723,7 +6767,4 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined_MSC_VER -# pragma warning(pop) -#endif -- cgit v1.2.3