From 266a185a528bc2061016f133862e9af67fa126ce Mon Sep 17 00:00:00 2001 From: Li Peng Date: Wed, 27 Apr 2016 16:41:27 +0800 Subject: remove duplicated words Signed-off-by: Li Peng --- googlemock/test/gmock-generated-actions_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 5ca5bc78..f01390ca 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -1120,7 +1120,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) { EXPECT_FALSE(b); // Verifies that resetter is deleted. } -// Tests that ACTION_TEMPLATES works for template template parameters. +// Tests that ACTION_TEMPLATES works for template parameters. ACTION_TEMPLATE(ReturnSmartPointer, HAS_1_TEMPLATE_PARAMS(template class, Pointer), -- cgit v1.2.3 From 09fd5b3ebfaac10b78bda664ec7f57fac74ef214 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 15 May 2017 17:07:03 -0400 Subject: Use std::string and ::string explicitly in gtest and gmock code. This merges a Google-internal change (117235625). Original CL description: This CL was created manually in about an hour with sed, a Python script to find all the places unqualified 'string' was mentioned, and some help from Emacs to add the "std::" qualifications, plus a few manual tweaks. --- googlemock/test/gmock-generated-actions_test.cc | 114 +++++++-------- .../test/gmock-generated-function-mockers_test.cc | 38 ++--- googlemock/test/gmock-generated-matchers_test.cc | 72 ++++----- googlemock/test/gmock-internal-utils_test.cc | 25 ++-- googlemock/test/gmock-matchers_test.cc | 162 +++++++++++---------- googlemock/test/gmock-more-actions_test.cc | 151 +++++++++---------- googlemock/test/gmock-nice-strict_test.cc | 27 ++-- googlemock/test/gmock-spec-builders_test.cc | 11 +- googlemock/test/gmock_stress_test.cc | 2 +- 9 files changed, 305 insertions(+), 297 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 5ca5bc78..58d45728 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -81,12 +81,12 @@ bool Unary(int x) { return x < 0; } const char* Plus1(const char* s) { return s + 1; } -bool ByConstRef(const string& s) { return s == "Hi"; } +bool ByConstRef(const std::string& s) { return s == "Hi"; } const double g_double = 0; bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; } -string ByNonConstRef(string& s) { return s += "+"; } // NOLINT +std::string ByNonConstRef(std::string& s) { return s += "+"; } // NOLINT struct UnaryFunctor { int operator()(bool x) { return x ? 1 : -1; } @@ -102,9 +102,9 @@ void VoidTernary(int, char, bool) { g_done = true; } int SumOf4(int a, int b, int c, int d) { return a + b + c + d; } -string Concat4(const char* s1, const char* s2, const char* s3, - const char* s4) { - return string(s1) + s2 + s3 + s4; +std::string Concat4(const char* s1, const char* s2, const char* s3, + const char* s4) { + return std::string(s1) + s2 + s3 + s4; } int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; } @@ -115,9 +115,9 @@ struct SumOf5Functor { } }; -string Concat5(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5) { - return string(s1) + s2 + s3 + s4 + s5; +std::string Concat5(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5) { + return std::string(s1) + s2 + s3 + s4 + s5; } int SumOf6(int a, int b, int c, int d, int e, int f) { @@ -130,34 +130,34 @@ struct SumOf6Functor { } }; -string Concat6(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6) { - return string(s1) + s2 + s3 + s4 + s5 + s6; +std::string Concat6(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6; } -string Concat7(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7; +std::string Concat7(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7; } -string Concat8(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; +std::string Concat8(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; } -string Concat9(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8, const char* s9) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; +std::string Concat9(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8, const char* s9) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; } -string Concat10(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8, const char* s9, - const char* s10) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; +std::string Concat10(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8, const char* s9, + const char* s10) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; } // A helper that turns the type of a C-string literal from const @@ -208,38 +208,37 @@ TEST(InvokeArgumentTest, Functor6) { // Tests using InvokeArgument with a 7-ary function. TEST(InvokeArgumentTest, Function7) { - Action a = - InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7"); + Action + a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7"); EXPECT_EQ("1234567", a.Perform(make_tuple(&Concat7))); } // Tests using InvokeArgument with a 8-ary function. TEST(InvokeArgumentTest, Function8) { - Action a = - InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8"); + Action + a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8"); EXPECT_EQ("12345678", a.Perform(make_tuple(&Concat8))); } // Tests using InvokeArgument with a 9-ary function. TEST(InvokeArgumentTest, Function9) { - Action a = - InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9"); + Action + a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9"); EXPECT_EQ("123456789", a.Perform(make_tuple(&Concat9))); } // Tests using InvokeArgument with a 10-ary function. TEST(InvokeArgumentTest, Function10) { - Action a = - InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); + Action + a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); EXPECT_EQ("1234567890", a.Perform(make_tuple(&Concat10))); } @@ -260,8 +259,8 @@ TEST(InvokeArgumentTest, FunctionWithCStringLiteral) { // Tests using InvokeArgument with a function that takes a const reference. TEST(InvokeArgumentTest, ByConstReferenceFunction) { - Action a = // NOLINT - InvokeArgument<0>(string("Hi")); + Action a = // NOLINT + InvokeArgument<0>(std::string("Hi")); // When action 'a' is constructed, it makes a copy of the temporary // string object passed to it, so it's OK to use 'a' later, when the // temporary object has already died. @@ -305,17 +304,18 @@ TEST(WithArgsTest, ThreeArgs) { // Tests using WithArgs with an action that takes 4 arguments. TEST(WithArgsTest, FourArgs) { - Action a = - WithArgs<4, 3, 1, 0>(Invoke(Concat4)); + Action + a = WithArgs<4, 3, 1, 0>(Invoke(Concat4)); EXPECT_EQ("4310", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), 2.5, CharPtr("3"), CharPtr("4")))); } // Tests using WithArgs with an action that takes 5 arguments. TEST(WithArgsTest, FiveArgs) { - Action a = - WithArgs<4, 3, 2, 1, 0>(Invoke(Concat5)); + Action + a = WithArgs<4, 3, 2, 1, 0>(Invoke(Concat5)); EXPECT_EQ("43210", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4")))); @@ -323,7 +323,7 @@ TEST(WithArgsTest, FiveArgs) { // Tests using WithArgs with an action that takes 6 arguments. TEST(WithArgsTest, SixArgs) { - Action a = + Action a = WithArgs<0, 1, 2, 2, 1, 0>(Invoke(Concat6)); EXPECT_EQ("012210", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2")))); @@ -331,7 +331,7 @@ TEST(WithArgsTest, SixArgs) { // Tests using WithArgs with an action that takes 7 arguments. TEST(WithArgsTest, SevenArgs) { - Action a = + Action a = WithArgs<0, 1, 2, 3, 2, 1, 0>(Invoke(Concat7)); EXPECT_EQ("0123210", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), @@ -340,7 +340,7 @@ TEST(WithArgsTest, SevenArgs) { // Tests using WithArgs with an action that takes 8 arguments. TEST(WithArgsTest, EightArgs) { - Action a = + Action a = WithArgs<0, 1, 2, 3, 0, 1, 2, 3>(Invoke(Concat8)); EXPECT_EQ("01230123", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), @@ -349,7 +349,7 @@ TEST(WithArgsTest, EightArgs) { // Tests using WithArgs with an action that takes 9 arguments. TEST(WithArgsTest, NineArgs) { - Action a = + Action a = WithArgs<0, 1, 2, 3, 1, 2, 3, 2, 3>(Invoke(Concat9)); EXPECT_EQ("012312323", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), @@ -358,7 +358,7 @@ TEST(WithArgsTest, NineArgs) { // Tests using WithArgs with an action that takes 10 arguments. TEST(WithArgsTest, TenArgs) { - Action a = + Action a = WithArgs<0, 1, 2, 3, 2, 1, 0, 1, 2, 3>(Invoke(Concat10)); EXPECT_EQ("0123210123", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index a86a6135..08e5eba1 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -57,7 +57,6 @@ namespace testing { namespace gmock_generated_function_mockers_test { -using testing::internal::string; using testing::_; using testing::A; using testing::An; @@ -82,11 +81,11 @@ class FooInterface { virtual bool Unary(int x) = 0; virtual long Binary(short x, int y) = 0; // NOLINT virtual int Decimal(bool b, char c, short d, int e, long f, // NOLINT - float g, double h, unsigned i, char* j, const string& k) - = 0; + float g, double h, unsigned i, char* j, + const std::string& k) = 0; virtual bool TakesNonConstReference(int& n) = 0; // NOLINT - virtual string TakesConstReference(const int& n) = 0; + virtual std::string TakesConstReference(const int& n) = 0; #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS virtual bool TakesConst(const int x) = 0; #endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS @@ -101,13 +100,14 @@ class FooInterface { virtual char OverloadedOnConstness() const = 0; virtual int TypeWithHole(int (*func)()) = 0; - virtual int TypeWithComma(const std::map& a_map) = 0; + virtual int TypeWithComma(const std::map& a_map) = 0; #if GTEST_OS_WINDOWS STDMETHOD_(int, CTNullary)() = 0; STDMETHOD_(bool, CTUnary)(int x) = 0; - STDMETHOD_(int, CTDecimal)(bool b, char c, short d, int e, long f, // NOLINT - float g, double h, unsigned i, char* j, const string& k) = 0; + STDMETHOD_(int, CTDecimal) + (bool b, char c, short d, int e, long f, // NOLINT + float g, double h, unsigned i, char* j, const std::string& k) = 0; STDMETHOD_(char, CTConst)(int x) const = 0; #endif // GTEST_OS_WINDOWS }; @@ -133,19 +133,19 @@ class MockFoo : public FooInterface { MOCK_METHOD1(Unary, bool(int)); // NOLINT MOCK_METHOD2(Binary, long(short, int)); // NOLINT MOCK_METHOD10(Decimal, int(bool, char, short, int, long, float, // NOLINT - double, unsigned, char*, const string& str)); + double, unsigned, char*, const std::string& str)); MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT - MOCK_METHOD1(TakesConstReference, string(const int&)); + MOCK_METHOD1(TakesConstReference, std::string(const int&)); #ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT #endif // Tests that the function return type can contain unprotected comma. - MOCK_METHOD0(ReturnTypeWithComma, std::map()); + MOCK_METHOD0(ReturnTypeWithComma, std::map()); MOCK_CONST_METHOD1(ReturnTypeWithComma, - std::map(int)); // NOLINT + std::map(int)); // NOLINT MOCK_METHOD0(OverloadedOnArgumentNumber, int()); // NOLINT MOCK_METHOD1(OverloadedOnArgumentNumber, int(int)); // NOLINT @@ -157,19 +157,21 @@ class MockFoo : public FooInterface { MOCK_CONST_METHOD0(OverloadedOnConstness, char()); // NOLINT MOCK_METHOD1(TypeWithHole, int(int (*)())); // NOLINT - MOCK_METHOD1(TypeWithComma, int(const std::map&)); // NOLINT + MOCK_METHOD1(TypeWithComma, + int(const std::map&)); // NOLINT #if GTEST_OS_WINDOWS MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); - MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, int(bool b, char c, - short d, int e, long f, float g, double h, unsigned i, char* j, - const string& k)); + MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, + int(bool b, char c, short d, int e, long f, + float g, double h, unsigned i, char* j, + const std::string& k)); MOCK_CONST_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTConst, char(int)); // Tests that the function return type can contain unprotected comma. MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTReturnTypeWithComma, - std::map()); + std::map()); #endif // GTEST_OS_WINDOWS private: @@ -291,7 +293,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnConstnessOfThis) { } TEST_F(FunctionMockerTest, MocksReturnTypeWithComma) { - const std::map a_map; + const std::map a_map; EXPECT_CALL(mock_foo_, ReturnTypeWithComma()) .WillOnce(Return(a_map)); EXPECT_CALL(mock_foo_, ReturnTypeWithComma(42)) @@ -341,7 +343,7 @@ TEST_F(FunctionMockerTest, MocksFunctionsConstFunctionWithCallType) { } TEST_F(FunctionMockerTest, MocksReturnTypeWithCommaAndCallType) { - const std::map a_map; + const std::map a_map; EXPECT_CALL(mock_foo_, CTReturnTypeWithComma()) .WillOnce(Return(a_map)); diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 0e9f77f5..8234858d 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -79,11 +79,10 @@ using testing::StaticAssertTypeEq; using testing::StrEq; using testing::Value; using testing::internal::ElementsAreArrayMatcher; -using testing::internal::string; // Returns the description of the given matcher. template -string Describe(const Matcher& m) { +std::string Describe(const Matcher& m) { stringstream ss; m.DescribeTo(&ss); return ss.str(); @@ -91,7 +90,7 @@ string Describe(const Matcher& m) { // Returns the description of the negation of the given matcher. template -string DescribeNegation(const Matcher& m) { +std::string DescribeNegation(const Matcher& m) { stringstream ss; m.DescribeNegationTo(&ss); return ss.str(); @@ -99,7 +98,7 @@ string DescribeNegation(const Matcher& m) { // Returns the reason why x matches, or doesn't match, m. template -string Explain(const MatcherType& m, const Value& x) { +std::string Explain(const MatcherType& m, const Value& x) { stringstream ss; m.ExplainMatchResultTo(x, &ss); return ss.str(); @@ -296,7 +295,7 @@ TEST(ElementsAreTest, CanDescribeExpectingOneElement) { } TEST(ElementsAreTest, CanDescribeExpectingManyElements) { - Matcher > m = ElementsAre(StrEq("one"), "two"); + Matcher > m = ElementsAre(StrEq("one"), "two"); EXPECT_EQ("has 2 elements where\n" "element #0 is equal to \"one\",\n" "element #1 is equal to \"two\"", Describe(m)); @@ -314,7 +313,7 @@ TEST(ElementsAreTest, CanDescribeNegationOfExpectingOneElment) { } TEST(ElementsAreTest, CanDescribeNegationOfExpectingManyElements) { - Matcher& > m = ElementsAre("one", "two"); + Matcher&> m = ElementsAre("one", "two"); EXPECT_EQ("doesn't have 2 elements, or\n" "element #0 isn't equal to \"one\", or\n" "element #1 isn't equal to \"two\"", DescribeNegation(m)); @@ -365,21 +364,21 @@ TEST(ElementsAreTest, CanExplainMismatchRightSize) { } TEST(ElementsAreTest, MatchesOneElementVector) { - vector test_vector; + vector test_vector; test_vector.push_back("test string"); EXPECT_THAT(test_vector, ElementsAre(StrEq("test string"))); } TEST(ElementsAreTest, MatchesOneElementList) { - list test_list; + list test_list; test_list.push_back("test string"); EXPECT_THAT(test_list, ElementsAre("test string")); } TEST(ElementsAreTest, MatchesThreeElementVector) { - vector test_vector; + vector test_vector; test_vector.push_back("one"); test_vector.push_back("two"); test_vector.push_back("three"); @@ -428,30 +427,30 @@ TEST(ElementsAreTest, MatchesTenElementVector) { } TEST(ElementsAreTest, DoesNotMatchWrongSize) { - vector test_vector; + vector test_vector; test_vector.push_back("test string"); test_vector.push_back("test string"); - Matcher > m = ElementsAre(StrEq("test string")); + Matcher > m = ElementsAre(StrEq("test string")); EXPECT_FALSE(m.Matches(test_vector)); } TEST(ElementsAreTest, DoesNotMatchWrongValue) { - vector test_vector; + vector test_vector; test_vector.push_back("other string"); - Matcher > m = ElementsAre(StrEq("test string")); + Matcher > m = ElementsAre(StrEq("test string")); EXPECT_FALSE(m.Matches(test_vector)); } TEST(ElementsAreTest, DoesNotMatchWrongOrder) { - vector test_vector; + vector test_vector; test_vector.push_back("one"); test_vector.push_back("three"); test_vector.push_back("two"); - Matcher > m = ElementsAre( - StrEq("one"), StrEq("two"), StrEq("three")); + Matcher > m = + ElementsAre(StrEq("one"), StrEq("two"), StrEq("three")); EXPECT_FALSE(m.Matches(test_vector)); } @@ -527,7 +526,7 @@ TEST(ElementsAreTest, WorksWithTwoDimensionalNativeArray) { } TEST(ElementsAreTest, AcceptsStringLiteral) { - string array[] = { "hi", "one", "two" }; + std::string array[] = {"hi", "one", "two"}; EXPECT_THAT(array, ElementsAre("hi", "one", "two")); EXPECT_THAT(array, Not(ElementsAre("hi", "one", "too"))); } @@ -546,10 +545,10 @@ TEST(ElementsAreTest, AcceptsArrayWithUnknownSize) { // The size of kHi is not known in this test, but ElementsAre() should // still accept it. - string array1[] = { "hi" }; + std::string array1[] = {"hi"}; EXPECT_THAT(array1, ElementsAre(kHi)); - string array2[] = { "ho" }; + std::string array2[] = {"ho"}; EXPECT_THAT(array2, Not(ElementsAre(kHi))); } @@ -589,7 +588,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) { TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) { const char* a[] = { "one", "two", "three" }; - vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, ElementsAreArray(a, GTEST_ARRAY_SIZE_(a))); const char** p = a; @@ -600,7 +599,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) { TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) { const char* a[] = { "one", "two", "three" }; - vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, ElementsAreArray(a)); test_vector[0] = "1"; @@ -608,10 +607,10 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) { } TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) { - const Matcher kMatcherArray[] = - { StrEq("one"), StrEq("two"), StrEq("three") }; + const Matcher kMatcherArray[] = {StrEq("one"), StrEq("two"), + StrEq("three")}; - vector test_vector; + vector test_vector; test_vector.push_back("one"); test_vector.push_back("two"); test_vector.push_back("three"); @@ -640,7 +639,7 @@ TEST(ElementsAreArrayTest, TakesInitializerList) { } TEST(ElementsAreArrayTest, TakesInitializerListOfCStrings) { - const string a[5] = { "a", "b", "c", "d", "e" }; + const std::string a[5] = {"a", "b", "c", "d", "e"}; EXPECT_THAT(a, ElementsAreArray({ "a", "b", "c", "d", "e" })); EXPECT_THAT(a, Not(ElementsAreArray({ "a", "b", "c", "e", "d" }))); EXPECT_THAT(a, Not(ElementsAreArray({ "a", "b", "c", "d", "ef" }))); @@ -751,9 +750,9 @@ MATCHER(IsEven2, negation ? "is odd" : "is even") { // This also tests that the description string can reference matcher // parameters. -MATCHER_P2(EqSumOf, x, y, - string(negation ? "doesn't equal" : "equals") + " the sum of " + - PrintToString(x) + " and " + PrintToString(y)) { +MATCHER_P2(EqSumOf, x, y, std::string(negation ? "doesn't equal" : "equals") + + " the sum of " + PrintToString(x) + " and " + + PrintToString(y)) { if (arg == (x + y)) { *result_listener << "OK"; return true; @@ -1117,12 +1116,12 @@ TEST(ContainsTest, ListMatchesWhenElementIsInContainer) { EXPECT_THAT(some_list, Contains(Gt(2.5))); EXPECT_THAT(some_list, Contains(Eq(2.0f))); - list another_list; + list another_list; another_list.push_back("fee"); another_list.push_back("fie"); another_list.push_back("foe"); another_list.push_back("fum"); - EXPECT_THAT(another_list, Contains(string("fee"))); + EXPECT_THAT(another_list, Contains(std::string("fee"))); } TEST(ContainsTest, ListDoesNotMatchWhenElementIsNotInContainer) { @@ -1146,7 +1145,7 @@ TEST(ContainsTest, SetMatchesWhenElementIsInContainer) { another_set.insert("fie"); another_set.insert("foe"); another_set.insert("fum"); - EXPECT_THAT(another_set, Contains(Eq(string("fum")))); + EXPECT_THAT(another_set, Contains(Eq(std::string("fum")))); } TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) { @@ -1157,7 +1156,7 @@ TEST(ContainsTest, SetDoesNotMatchWhenElementIsNotInContainer) { set c_string_set; c_string_set.insert("hello"); - EXPECT_THAT(c_string_set, Not(Contains(string("hello").c_str()))); + EXPECT_THAT(c_string_set, Not(Contains(std::string("hello").c_str()))); } TEST(ContainsTest, ExplainsMatchResultCorrectly) { @@ -1189,13 +1188,14 @@ TEST(ContainsTest, MapMatchesWhenElementIsInContainer) { my_map[bar] = 2; EXPECT_THAT(my_map, Contains(pair(bar, 2))); - map another_map; + map another_map; another_map["fee"] = 1; another_map["fie"] = 2; another_map["foe"] = 3; another_map["fum"] = 4; - EXPECT_THAT(another_map, Contains(pair(string("fee"), 1))); - EXPECT_THAT(another_map, Contains(pair("fie", 2))); + EXPECT_THAT(another_map, + Contains(pair(std::string("fee"), 1))); + EXPECT_THAT(another_map, Contains(pair("fie", 2))); } TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) { @@ -1207,7 +1207,7 @@ TEST(ContainsTest, MapDoesNotMatchWhenElementIsNotInContainer) { TEST(ContainsTest, ArrayMatchesWhenElementIsInContainer) { const char* string_array[] = { "fee", "fie", "foe", "fum" }; - EXPECT_THAT(string_array, Contains(Eq(string("fum")))); + EXPECT_THAT(string_array, Contains(Eq(std::string("fum")))); } TEST(ContainsTest, ArrayDoesNotMatchWhenElementIsNotInContainer) { diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 9d5ec609..9c2423ec 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -319,11 +319,10 @@ TEST(TupleMatchesTest, WorksForSize2) { TEST(TupleMatchesTest, WorksForSize5) { tuple, Matcher, Matcher, Matcher, // NOLINT - Matcher > + Matcher > matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi")); - tuple // NOLINT - values1(1, 'a', true, 2L, "hi"), - values2(1, 'a', true, 2L, "hello"), + tuple // NOLINT + values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"), values3(2, 'a', true, 2L, "hi"); EXPECT_TRUE(TupleMatches(matchers, values1)); @@ -375,7 +374,7 @@ class LogIsVisibleTest : public ::testing::Test { virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; } - string original_verbose_; + std::string original_verbose_; }; TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) { @@ -402,9 +401,9 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { // Verifies that Log() behaves correctly for the given verbosity level // and log severity. -void TestLogWithSeverity(const string& verbosity, LogSeverity severity, +void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity, bool should_print) { - const string old_flag = GMOCK_FLAG(verbose); + const std::string old_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = verbosity; CaptureStdout(); Log(severity, "Test log.\n", 0); @@ -423,7 +422,7 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity, // Tests that when the stack_frames_to_skip parameter is negative, // Log() doesn't include the stack trace in the output. TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = kInfoVerbosity; CaptureStdout(); Log(kInfo, "Test log.\n", -1); @@ -432,7 +431,7 @@ TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { } struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface { - virtual string CurrentStackTrace(int max_depth, int skip_count) { + virtual std::string CurrentStackTrace(int max_depth, int skip_count) { return (testing::Message() << max_depth << "::" << skip_count << "\n") .GetString(); } @@ -447,11 +446,11 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) { CaptureStdout(); Log(kWarning, "Test log.\n", 100); - const string log = GetCapturedStdout(); + const std::string log = GetCapturedStdout(); - string expected_trace = + std::string expected_trace = (testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString(); - string expected_message = + std::string expected_message = "\nGMOCK WARNING:\n" "Test log.\n" "Stack trace:\n" + @@ -547,7 +546,7 @@ TEST(TypeTraitsTest, remove_reference) { // Verifies that Log() behaves correctly for the given verbosity level // and log severity. std::string GrabOutput(void(*logger)(), const char* verbosity) { - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = verbosity; CaptureStdout(); logger(); diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 9f62c3d8..f5ab7c81 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -189,7 +189,7 @@ Matcher GreaterThan(int n) { return MakeMatcher(new GreaterThanMatcher(n)); } -string OfType(const string& type_name) { +std::string OfType(const std::string& type_name) { #if GTEST_HAS_RTTI return " (of type " + type_name + ")"; #else @@ -199,7 +199,7 @@ string OfType(const string& type_name) { // Returns the description of the given matcher. template -string Describe(const Matcher& m) { +std::string Describe(const Matcher& m) { stringstream ss; m.DescribeTo(&ss); return ss.str(); @@ -207,7 +207,7 @@ string Describe(const Matcher& m) { // Returns the description of the negation of the given matcher. template -string DescribeNegation(const Matcher& m) { +std::string DescribeNegation(const Matcher& m) { stringstream ss; m.DescribeNegationTo(&ss); return ss.str(); @@ -215,7 +215,7 @@ string DescribeNegation(const Matcher& m) { // Returns the reason why x matches, or doesn't match, m. template -string Explain(const MatcherType& m, const Value& x) { +std::string Explain(const MatcherType& m, const Value& x) { StringMatchResultListener listener; ExplainMatchResult(m, x, &listener); return listener.str(); @@ -973,7 +973,7 @@ TEST(LeTest, CanDescribeSelf) { // Tests that Lt(v) matches anything < v. TEST(LtTest, ImplementsLessThan) { - Matcher m1 = Lt("Hello"); + Matcher m1 = Lt("Hello"); EXPECT_TRUE(m1.Matches("Abc")); EXPECT_FALSE(m1.Matches("Hello")); EXPECT_FALSE(m1.Matches("Hello, world!")); @@ -1125,7 +1125,7 @@ TEST(RefTest, CanDescribeSelf) { Matcher m = Ref(n); stringstream ss; ss << "references the variable @" << &n << " 5"; - EXPECT_EQ(string(ss.str()), Describe(m)); + EXPECT_EQ(ss.str(), Describe(m)); } // Test that Ref(non_const_varialbe) can be used as a matcher for a @@ -1169,27 +1169,27 @@ TEST(RefTest, ExplainsResult) { // Tests string comparison matchers. TEST(StrEqTest, MatchesEqualString) { - Matcher m = StrEq(string("Hello")); + Matcher m = StrEq(std::string("Hello")); EXPECT_TRUE(m.Matches("Hello")); EXPECT_FALSE(m.Matches("hello")); EXPECT_FALSE(m.Matches(NULL)); - Matcher m2 = StrEq("Hello"); + Matcher m2 = StrEq("Hello"); EXPECT_TRUE(m2.Matches("Hello")); EXPECT_FALSE(m2.Matches("Hi")); } TEST(StrEqTest, CanDescribeSelf) { - Matcher m = StrEq("Hi-\'\"?\\\a\b\f\n\r\t\v\xD3"); + Matcher m = StrEq("Hi-\'\"?\\\a\b\f\n\r\t\v\xD3"); EXPECT_EQ("is equal to \"Hi-\'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\xD3\"", Describe(m)); - string str("01204500800"); + std::string str("01204500800"); str[3] = '\0'; - Matcher m2 = StrEq(str); + Matcher m2 = StrEq(str); EXPECT_EQ("is equal to \"012\\04500800\"", Describe(m2)); str[0] = str[6] = str[7] = str[9] = str[10] = '\0'; - Matcher m3 = StrEq(str); + Matcher m3 = StrEq(str); EXPECT_EQ("is equal to \"\\012\\045\\0\\08\\0\\0\"", Describe(m3)); } @@ -1199,7 +1199,7 @@ TEST(StrNeTest, MatchesUnequalString) { EXPECT_TRUE(m.Matches(NULL)); EXPECT_FALSE(m.Matches("Hello")); - Matcher m2 = StrNe(string("Hello")); + Matcher m2 = StrNe(std::string("Hello")); EXPECT_TRUE(m2.Matches("hello")); EXPECT_FALSE(m2.Matches("Hello")); } @@ -1222,32 +1222,32 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { } TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) { - string str1("oabocdooeoo"); - string str2("OABOCDOOEOO"); - Matcher m0 = StrCaseEq(str1); - EXPECT_FALSE(m0.Matches(str2 + string(1, '\0'))); + std::string str1("oabocdooeoo"); + std::string str2("OABOCDOOEOO"); + Matcher m0 = StrCaseEq(str1); + EXPECT_FALSE(m0.Matches(str2 + std::string(1, '\0'))); str1[3] = str2[3] = '\0'; - Matcher m1 = StrCaseEq(str1); + Matcher m1 = StrCaseEq(str1); EXPECT_TRUE(m1.Matches(str2)); str1[0] = str1[6] = str1[7] = str1[10] = '\0'; str2[0] = str2[6] = str2[7] = str2[10] = '\0'; - Matcher m2 = StrCaseEq(str1); + Matcher m2 = StrCaseEq(str1); str1[9] = str2[9] = '\0'; EXPECT_FALSE(m2.Matches(str2)); - Matcher m3 = StrCaseEq(str1); + Matcher m3 = StrCaseEq(str1); EXPECT_TRUE(m3.Matches(str2)); EXPECT_FALSE(m3.Matches(str2 + "x")); str2.append(1, '\0'); EXPECT_FALSE(m3.Matches(str2)); - EXPECT_FALSE(m3.Matches(string(str2, 0, 9))); + EXPECT_FALSE(m3.Matches(std::string(str2, 0, 9))); } TEST(StrCaseEqTest, CanDescribeSelf) { - Matcher m = StrCaseEq("Hi"); + Matcher m = StrCaseEq("Hi"); EXPECT_EQ("is equal to (ignoring case) \"Hi\"", Describe(m)); } @@ -1258,7 +1258,7 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) { EXPECT_FALSE(m.Matches("Hello")); EXPECT_FALSE(m.Matches("hello")); - Matcher m2 = StrCaseNe(string("Hello")); + Matcher m2 = StrCaseNe(std::string("Hello")); EXPECT_TRUE(m2.Matches("")); EXPECT_FALSE(m2.Matches("Hello")); } @@ -1270,9 +1270,9 @@ TEST(StrCaseNeTest, CanDescribeSelf) { // Tests that HasSubstr() works for matching string-typed values. TEST(HasSubstrTest, WorksForStringClasses) { - const Matcher m1 = HasSubstr("foo"); - EXPECT_TRUE(m1.Matches(string("I love food."))); - EXPECT_FALSE(m1.Matches(string("tofo"))); + const Matcher m1 = HasSubstr("foo"); + EXPECT_TRUE(m1.Matches(std::string("I love food."))); + EXPECT_FALSE(m1.Matches(std::string("tofo"))); const Matcher m2 = HasSubstr("foo"); EXPECT_TRUE(m2.Matches(std::string("I love food."))); @@ -1294,7 +1294,7 @@ TEST(HasSubstrTest, WorksForCStrings) { // Tests that HasSubstr(s) describes itself properly. TEST(HasSubstrTest, CanDescribeSelf) { - Matcher m = HasSubstr("foo\n\""); + Matcher m = HasSubstr("foo\n\""); EXPECT_EQ("has substring \"foo\\n\\\"\"", Describe(m)); } @@ -1460,12 +1460,12 @@ TEST(PairTest, InsideContainsUsingMap) { // Tests StartsWith(s). TEST(StartsWithTest, MatchesStringWithGivenPrefix) { - const Matcher m1 = StartsWith(string("")); + const Matcher m1 = StartsWith(std::string("")); EXPECT_TRUE(m1.Matches("Hi")); EXPECT_TRUE(m1.Matches("")); EXPECT_FALSE(m1.Matches(NULL)); - const Matcher m2 = StartsWith("Hi"); + const Matcher m2 = StartsWith("Hi"); EXPECT_TRUE(m2.Matches("Hi")); EXPECT_TRUE(m2.Matches("Hi Hi!")); EXPECT_TRUE(m2.Matches("High")); @@ -1507,14 +1507,14 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) { EXPECT_TRUE(m1.Matches("abcz")); EXPECT_FALSE(m1.Matches(NULL)); - const Matcher m2 = MatchesRegex(new RE("a.*z")); + const Matcher m2 = MatchesRegex(new RE("a.*z")); EXPECT_TRUE(m2.Matches("azbz")); EXPECT_FALSE(m2.Matches("az1")); EXPECT_FALSE(m2.Matches("1az")); } TEST(MatchesRegexTest, CanDescribeSelf) { - Matcher m1 = MatchesRegex(string("Hi.*")); + Matcher m1 = MatchesRegex(std::string("Hi.*")); EXPECT_EQ("matches regular expression \"Hi.*\"", Describe(m1)); Matcher m2 = MatchesRegex(new RE("a.*")); @@ -1524,12 +1524,12 @@ TEST(MatchesRegexTest, CanDescribeSelf) { // Tests ContainsRegex(). TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) { - const Matcher m1 = ContainsRegex(string("a.*z")); + const Matcher m1 = ContainsRegex(std::string("a.*z")); EXPECT_TRUE(m1.Matches("az")); EXPECT_TRUE(m1.Matches("0abcz1")); EXPECT_FALSE(m1.Matches(NULL)); - const Matcher m2 = ContainsRegex(new RE("a.*z")); + const Matcher m2 = ContainsRegex(new RE("a.*z")); EXPECT_TRUE(m2.Matches("azbz")); EXPECT_TRUE(m2.Matches("az1")); EXPECT_FALSE(m2.Matches("1a")); @@ -2685,9 +2685,9 @@ TEST(MatcherAssertionTest, WorksForMonomorphicMatcher) { Matcher starts_with_he = StartsWith("he"); ASSERT_THAT("hello", starts_with_he); - Matcher ends_with_ok = EndsWith("ok"); + Matcher ends_with_ok = EndsWith("ok"); ASSERT_THAT("book", ends_with_ok); - const string bad = "bad"; + const std::string bad = "bad"; EXPECT_NONFATAL_FAILURE(EXPECT_THAT(bad, ends_with_ok), "Value of: bad\n" "Expected: ends with \"ok\"\n" @@ -3099,7 +3099,8 @@ TEST_F(DoubleNearTest, ExplainsResultWhenMatchFails) { EXPECT_EQ("which is 0.2 from 2", Explain(DoubleNear(2.0, 0.1), 2.2)); EXPECT_EQ("which is -0.3 from 2", Explain(DoubleNear(2.0, 0.1), 1.7)); - const string explanation = Explain(DoubleNear(2.1, 1e-10), 2.1 + 1.2e-10); + const std::string explanation = + Explain(DoubleNear(2.1, 1e-10), 2.1 + 1.2e-10); // Different C++ implementations may print floating-point numbers // slightly differently. EXPECT_TRUE(explanation == "which is 1.2e-10 from 2.1" || // GCC @@ -3337,9 +3338,9 @@ TEST(PointeeTest, CanDescribeSelf) { } TEST(PointeeTest, CanExplainMatchResult) { - const Matcher m = Pointee(StartsWith("Hi")); + const Matcher m = Pointee(StartsWith("Hi")); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(NULL))); const Matcher m2 = Pointee(GreaterThan(1)); // NOLINT long n = 3; // NOLINT @@ -3585,15 +3586,15 @@ class AClass { void set_n(int new_n) { n_ = new_n; } // A getter that returns a reference to const. - const string& s() const { return s_; } + const std::string& s() const { return s_; } - void set_s(const string& new_s) { s_ = new_s; } + void set_s(const std::string& new_s) { s_ = new_s; } // A getter that returns a reference to non-const. double& x() const { return x_; } private: int n_; - string s_; + std::string s_; static double x_; }; @@ -3799,10 +3800,12 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) { // Tests that ResultOf(f, ...) compiles and works as expected when f is a // function pointer. -string IntToStringFunction(int input) { return input == 1 ? "foo" : "bar"; } +std::string IntToStringFunction(int input) { + return input == 1 ? "foo" : "bar"; +} TEST(ResultOfTest, WorksForFunctionPointers) { - Matcher matcher = ResultOf(&IntToStringFunction, Eq(string("foo"))); + Matcher matcher = ResultOf(&IntToStringFunction, Eq(std::string("foo"))); EXPECT_TRUE(matcher.Matches(1)); EXPECT_FALSE(matcher.Matches(2)); @@ -3868,12 +3871,12 @@ TEST(ResultOfTest, WorksForReferenceToNonConstResults) { // Tests that ResultOf(f, ...) compiles and works as expected when f(x) // returns a reference to const. -const string& StringFunction(const string& input) { return input; } +const std::string& StringFunction(const std::string& input) { return input; } TEST(ResultOfTest, WorksForReferenceToConstResults) { - string s = "foo"; - string s2 = s; - Matcher matcher = ResultOf(&StringFunction, Ref(s)); + std::string s = "foo"; + std::string s2 = s; + Matcher matcher = ResultOf(&StringFunction, Ref(s)); EXPECT_TRUE(matcher.Matches(s)); EXPECT_FALSE(matcher.Matches(s2)); @@ -3893,8 +3896,9 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) { // a NULL function pointer. TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) { EXPECT_DEATH_IF_SUPPORTED( - ResultOf(static_cast(NULL), Eq(string("foo"))), - "NULL function pointer is passed into ResultOf\\(\\)\\."); + ResultOf(static_cast(NULL), + Eq(std::string("foo"))), + "NULL function pointer is passed into ResultOf\\(\\)\\."); } // Tests that ResultOf(f, ...) compiles and works as expected when f is a @@ -3907,14 +3911,14 @@ TEST(ResultOfTest, WorksForFunctionReferences) { // Tests that ResultOf(f, ...) compiles and works as expected when f is a // function object. -struct Functor : public ::std::unary_function { +struct Functor : public ::std::unary_function { result_type operator()(argument_type input) const { return IntToStringFunction(input); } }; TEST(ResultOfTest, WorksForFunctors) { - Matcher matcher = ResultOf(Functor(), Eq(string("foo"))); + Matcher matcher = ResultOf(Functor(), Eq(std::string("foo"))); EXPECT_TRUE(matcher.Matches(1)); EXPECT_FALSE(matcher.Matches(2)); @@ -4080,11 +4084,11 @@ TEST(IsEmptyTest, ImplementsIsEmpty) { } TEST(IsEmptyTest, WorksWithString) { - string text; + std::string text; EXPECT_THAT(text, IsEmpty()); text = "foo"; EXPECT_THAT(text, Not(IsEmpty())); - text = string("\0", 1); + text = std::string("\0", 1); EXPECT_THAT(text, Not(IsEmpty())); } @@ -4115,7 +4119,7 @@ TEST(SizeIsTest, ImplementsSizeIs) { } TEST(SizeIsTest, WorksWithMap) { - map container; + map container; EXPECT_THAT(container, SizeIs(0)); EXPECT_THAT(container, Not(SizeIs(1))); container.insert(make_pair("foo", 1)); @@ -4380,13 +4384,13 @@ TEST(WhenSortedByTest, WorksForNonEmptyContainer) { } TEST(WhenSortedByTest, WorksForNonVectorContainer) { - list words; + list words; words.push_back("say"); words.push_back("hello"); words.push_back("world"); - EXPECT_THAT(words, WhenSortedBy(less(), + EXPECT_THAT(words, WhenSortedBy(less(), ElementsAre("hello", "say", "world"))); - EXPECT_THAT(words, Not(WhenSortedBy(less(), + EXPECT_THAT(words, Not(WhenSortedBy(less(), ElementsAre("say", "hello", "world")))); } @@ -4429,7 +4433,7 @@ TEST(WhenSortedTest, WorksForEmptyContainer) { } TEST(WhenSortedTest, WorksForNonEmptyContainer) { - list words; + list words; words.push_back("3"); words.push_back("1"); words.push_back("2"); @@ -4439,14 +4443,16 @@ TEST(WhenSortedTest, WorksForNonEmptyContainer) { } TEST(WhenSortedTest, WorksForMapTypes) { - map word_counts; - word_counts["and"] = 1; - word_counts["the"] = 1; - word_counts["buffalo"] = 2; - EXPECT_THAT(word_counts, WhenSorted(ElementsAre( - Pair("and", 1), Pair("buffalo", 2), Pair("the", 1)))); - EXPECT_THAT(word_counts, Not(WhenSorted(ElementsAre( - Pair("and", 1), Pair("the", 1), Pair("buffalo", 2))))); + map word_counts; + word_counts["and"] = 1; + word_counts["the"] = 1; + word_counts["buffalo"] = 2; + EXPECT_THAT(word_counts, + WhenSorted(ElementsAre(Pair("and", 1), Pair("buffalo", 2), + Pair("the", 1)))); + EXPECT_THAT(word_counts, + Not(WhenSorted(ElementsAre(Pair("and", 1), Pair("the", 1), + Pair("buffalo", 2))))); } TEST(WhenSortedTest, WorksForMultiMapTypes) { @@ -4763,7 +4769,7 @@ TEST(UnorderedElementsAreArrayTest, TakesInitializerList) { } TEST(UnorderedElementsAreArrayTest, TakesInitializerListOfCStrings) { - const string a[5] = {"a", "b", "c", "d", "e"}; + const std::string a[5] = {"a", "b", "c", "d", "e"}; EXPECT_THAT(a, UnorderedElementsAreArray({"a", "b", "c", "d", "e"})); EXPECT_THAT(a, Not(UnorderedElementsAreArray({"a", "b", "c", "d", "ef"}))); } @@ -4937,7 +4943,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageUnmatchedMatcherAndElement) { } // Test helper for formatting element, matcher index pairs in expectations. -static string EMString(int element, int matcher) { +static std::string EMString(int element, int matcher) { stringstream ss; ss << "(element #" << element << ", matcher #" << matcher << ")"; return ss.str(); @@ -4946,7 +4952,7 @@ static string EMString(int element, int matcher) { TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) { // A situation where all elements and matchers have a match // associated with them, but the max matching is not perfect. - std::vector v; + std::vector v; v.push_back("a"); v.push_back("b"); v.push_back("c"); @@ -4955,7 +4961,7 @@ TEST_F(UnorderedElementsAreTest, FailMessageImperfectMatchOnly) { UnorderedElementsAre("a", "a", AnyOf("b", "c")), v, &listener)) << listener.str(); - string prefix = + std::string prefix = "where no permutation of the elements can satisfy all matchers, " "and the closest match is 2 of 3 matchers with the " "pairings:\n"; @@ -5366,13 +5372,13 @@ TEST(EachTest, MatchesVectorWhenAllElementsMatch) { EXPECT_THAT(some_vector, Not(Each(3))); EXPECT_THAT(some_vector, Each(Lt(3.5))); - vector another_vector; + vector another_vector; another_vector.push_back("fee"); - EXPECT_THAT(another_vector, Each(string("fee"))); + EXPECT_THAT(another_vector, Each(std::string("fee"))); another_vector.push_back("fie"); another_vector.push_back("foe"); another_vector.push_back("fum"); - EXPECT_THAT(another_vector, Not(Each(string("fee")))); + EXPECT_THAT(another_vector, Not(Each(std::string("fee")))); } TEST(EachTest, MatchesMapWhenAllElementsMatch) { @@ -5381,15 +5387,15 @@ TEST(EachTest, MatchesMapWhenAllElementsMatch) { my_map[bar] = 2; EXPECT_THAT(my_map, Each(make_pair(bar, 2))); - map another_map; - EXPECT_THAT(another_map, Each(make_pair(string("fee"), 1))); + map another_map; + EXPECT_THAT(another_map, Each(make_pair(std::string("fee"), 1))); another_map["fee"] = 1; - EXPECT_THAT(another_map, Each(make_pair(string("fee"), 1))); + EXPECT_THAT(another_map, Each(make_pair(std::string("fee"), 1))); another_map["fie"] = 2; another_map["foe"] = 3; another_map["fum"] = 4; - EXPECT_THAT(another_map, Not(Each(make_pair(string("fee"), 1)))); - EXPECT_THAT(another_map, Not(Each(make_pair(string("fum"), 1)))); + EXPECT_THAT(another_map, Not(Each(make_pair(std::string("fee"), 1)))); + EXPECT_THAT(another_map, Not(Each(make_pair(std::string("fum"), 1)))); EXPECT_THAT(another_map, Each(Pair(_, Gt(0)))); } diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 77e15bd5..f5e28eae 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -94,12 +94,12 @@ const char* Plus1(const char* s) { return s + 1; } void VoidUnary(int /* n */) { g_done = true; } -bool ByConstRef(const string& s) { return s == "Hi"; } +bool ByConstRef(const std::string& s) { return s == "Hi"; } const double g_double = 0; bool ReferencesGlobalDouble(const double& x) { return &x == &g_double; } -string ByNonConstRef(string& s) { return s += "+"; } // NOLINT +std::string ByNonConstRef(std::string& s) { return s += "+"; } // NOLINT struct UnaryFunctor { int operator()(bool x) { return x ? 1 : -1; } @@ -119,9 +119,9 @@ int SumOfFirst2(int a, int b, Unused, Unused) { return a + b; } void VoidFunctionWithFourArguments(char, int, float, double) { g_done = true; } -string Concat4(const char* s1, const char* s2, const char* s3, - const char* s4) { - return string(s1) + s2 + s3 + s4; +std::string Concat4(const char* s1, const char* s2, const char* s3, + const char* s4) { + return std::string(s1) + s2 + s3 + s4; } int SumOf5(int a, int b, int c, int d, int e) { return a + b + c + d + e; } @@ -132,9 +132,9 @@ struct SumOf5Functor { } }; -string Concat5(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5) { - return string(s1) + s2 + s3 + s4 + s5; +std::string Concat5(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5) { + return std::string(s1) + s2 + s3 + s4 + s5; } int SumOf6(int a, int b, int c, int d, int e, int f) { @@ -147,34 +147,34 @@ struct SumOf6Functor { } }; -string Concat6(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6) { - return string(s1) + s2 + s3 + s4 + s5 + s6; +std::string Concat6(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6; } -string Concat7(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7; +std::string Concat7(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7; } -string Concat8(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; +std::string Concat8(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; } -string Concat9(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8, const char* s9) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; +std::string Concat9(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8, const char* s9) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; } -string Concat10(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8, const char* s9, - const char* s10) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; +std::string Concat10(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8, const char* s9, + const char* s10) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; } class Foo { @@ -185,7 +185,7 @@ class Foo { short Unary(long x) { return static_cast(value_ + x); } // NOLINT - string Binary(const string& str, char c) const { return str + c; } + std::string Binary(const std::string& str, char c) const { return str + c; } int Ternary(int x, bool y, char z) { return value_ + x + y*z; } @@ -201,29 +201,29 @@ class Foo { return a + b + c + d + e + f; } - string Concat7(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7; + std::string Concat7(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7; } - string Concat8(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; + std::string Concat8(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8; } - string Concat9(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8, const char* s9) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; + std::string Concat9(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8, const char* s9) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9; } - string Concat10(const char* s1, const char* s2, const char* s3, - const char* s4, const char* s5, const char* s6, - const char* s7, const char* s8, const char* s9, - const char* s10) { - return string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; + std::string Concat10(const char* s1, const char* s2, const char* s3, + const char* s4, const char* s5, const char* s6, + const char* s7, const char* s8, const char* s9, + const char* s10) { + return std::string(s1) + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10; } private: @@ -280,9 +280,9 @@ inline const char* CharPtr(const char* s) { return s; } // Tests using Invoke() with a 7-argument function. TEST(InvokeTest, FunctionThatTakes7Arguments) { - Action a = - Invoke(Concat7); + Action + a = Invoke(Concat7); EXPECT_EQ("1234567", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -291,9 +291,9 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) { // Tests using Invoke() with a 8-argument function. TEST(InvokeTest, FunctionThatTakes8Arguments) { - Action a = - Invoke(Concat8); + Action + a = Invoke(Concat8); EXPECT_EQ("12345678", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -302,9 +302,10 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) { // Tests using Invoke() with a 9-argument function. TEST(InvokeTest, FunctionThatTakes9Arguments) { - Action a = Invoke(Concat9); + Action + a = Invoke(Concat9); EXPECT_EQ("123456789", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -313,9 +314,10 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) { // Tests using Invoke() with a 10-argument function. TEST(InvokeTest, FunctionThatTakes10Arguments) { - Action a = Invoke(Concat10); + Action + a = Invoke(Concat10); EXPECT_EQ("1234567890", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -339,8 +341,7 @@ TEST(InvokeTest, FunctionWithUnusedParameters) { // Tests using Invoke() with methods with parameters declared as Unused. TEST(InvokeTest, MethodWithUnusedParameters) { Foo foo; - Action a1 = - Invoke(&foo, &Foo::SumOfLast2); + Action a1 = Invoke(&foo, &Foo::SumOfLast2); EXPECT_EQ(12, a1.Perform(make_tuple(CharPtr("hi"), true, 10, 2))); Action a2 = @@ -417,9 +418,9 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) { // Tests using Invoke() with a 7-argument method. TEST(InvokeMethodTest, MethodThatTakes7Arguments) { Foo foo; - Action a = - Invoke(&foo, &Foo::Concat7); + Action + a = Invoke(&foo, &Foo::Concat7); EXPECT_EQ("1234567", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -429,9 +430,9 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) { // Tests using Invoke() with a 8-argument method. TEST(InvokeMethodTest, MethodThatTakes8Arguments) { Foo foo; - Action a = - Invoke(&foo, &Foo::Concat8); + Action + a = Invoke(&foo, &Foo::Concat8); EXPECT_EQ("12345678", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -441,9 +442,10 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) { // Tests using Invoke() with a 9-argument method. TEST(InvokeMethodTest, MethodThatTakes9Arguments) { Foo foo; - Action a = Invoke(&foo, &Foo::Concat9); + Action + a = Invoke(&foo, &Foo::Concat9); EXPECT_EQ("123456789", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -453,9 +455,10 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) { // Tests using Invoke() with a 10-argument method. TEST(InvokeMethodTest, MethodThatTakes10Arguments) { Foo foo; - Action a = Invoke(&foo, &Foo::Concat10); + Action + a = Invoke(&foo, &Foo::Concat10); EXPECT_EQ("1234567890", a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), CharPtr("4"), CharPtr("5"), CharPtr("6"), @@ -495,8 +498,8 @@ TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) { } TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) { - const Action a = ReturnArg<2>(); - EXPECT_EQ("seven", a.Perform(make_tuple(5, 6, string("seven"), 8))); + const Action a = ReturnArg<2>(); + EXPECT_EQ("seven", a.Perform(make_tuple(5, 6, std::string("seven"), 8))); } TEST(SaveArgActionTest, WorksForSameType) { diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index d0adcbbe..5d6ccc4f 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -51,7 +51,6 @@ class Mock { namespace testing { namespace gmock_nice_strict_test { -using testing::internal::string; using testing::GMOCK_FLAG(verbose); using testing::HasSubstr; using testing::NaggyMock; @@ -87,23 +86,23 @@ class MockFoo : public Foo { class MockBar { public: - explicit MockBar(const string& s) : str_(s) {} + explicit MockBar(const std::string& s) : str_(s) {} - MockBar(char a1, char a2, string a3, string a4, int a5, int a6, - const string& a7, const string& a8, bool a9, bool a10) { - str_ = string() + a1 + a2 + a3 + a4 + static_cast(a5) + + MockBar(char a1, char a2, std::string a3, std::string a4, int a5, int a6, + const std::string& a7, const std::string& a8, bool a9, bool a10) { + str_ = std::string() + a1 + a2 + a3 + a4 + static_cast(a5) + static_cast(a6) + a7 + a8 + (a9 ? 'T' : 'F') + (a10 ? 'T' : 'F'); } virtual ~MockBar() {} - const string& str() const { return str_; } + const std::string& str() const { return str_; } MOCK_METHOD0(This, int()); - MOCK_METHOD2(That, string(int, bool)); + MOCK_METHOD2(That, std::string(int, bool)); private: - string str_; + std::string str_; GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); }; @@ -112,7 +111,7 @@ class MockBar { // Tests that a raw mock generates warnings for uninteresting calls. TEST(RawMockTest, WarningForUninterestingCall) { - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = "warning"; MockFoo raw_foo; @@ -129,7 +128,7 @@ TEST(RawMockTest, WarningForUninterestingCall) { // Tests that a raw mock generates warnings for uninteresting calls // that delete the mock object. TEST(RawMockTest, WarningForUninterestingCallAfterDeath) { - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = "warning"; MockFoo* const raw_foo = new MockFoo; @@ -150,7 +149,7 @@ TEST(RawMockTest, WarningForUninterestingCallAfterDeath) { TEST(RawMockTest, InfoForUninterestingCall) { MockFoo raw_foo; - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = "info"; CaptureStdout(); raw_foo.DoThis(); @@ -188,7 +187,7 @@ TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) { TEST(NiceMockTest, InfoForUninterestingCall) { NiceMock nice_foo; - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = "info"; CaptureStdout(); nice_foo.DoThis(); @@ -257,7 +256,7 @@ TEST(NiceMockTest, AcceptsClassNamedMock) { // Tests that a naggy mock generates warnings for uninteresting calls. TEST(NaggyMockTest, WarningForUninterestingCall) { - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = "warning"; NaggyMock naggy_foo; @@ -274,7 +273,7 @@ TEST(NaggyMockTest, WarningForUninterestingCall) { // Tests that a naggy mock generates a warning for an uninteresting call // that deletes the mock object. TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) { - const string saved_flag = GMOCK_FLAG(verbose); + const std::string saved_flag = GMOCK_FLAG(verbose); GMOCK_FLAG(verbose) = "warning"; NaggyMock* const naggy_foo = new NaggyMock; diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 59ea87c8..389e0709 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -97,7 +97,6 @@ using testing::internal::kErrorVerbosity; using testing::internal::kInfoVerbosity; using testing::internal::kWarningVerbosity; using testing::internal::linked_ptr; -using testing::internal::string; #if GTEST_HAS_STREAM_REDIRECTION using testing::HasSubstr; @@ -1954,7 +1953,7 @@ class MockC { public: MockC() {} - MOCK_METHOD6(VoidMethod, void(bool cond, int n, string s, void* p, + MOCK_METHOD6(VoidMethod, void(bool cond, int n, std::string s, void* p, const Printable& x, Unprintable y)); MOCK_METHOD0(NonVoidMethod, int()); // NOLINT @@ -1970,7 +1969,7 @@ class VerboseFlagPreservingFixture : public testing::Test { ~VerboseFlagPreservingFixture() { GMOCK_FLAG(verbose) = saved_verbose_flag_; } private: - const string saved_verbose_flag_; + const std::string saved_verbose_flag_; GTEST_DISALLOW_COPY_AND_ASSIGN_(VerboseFlagPreservingFixture); }; @@ -2062,8 +2061,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { // contain the given function name in the stack trace. When it's // false, the output should be empty.) void VerifyOutput(const std::string& output, bool should_print, - const string& expected_substring, - const string& function_name) { + const std::string& expected_substring, + const std::string& function_name) { if (should_print) { EXPECT_THAT(output.c_str(), HasSubstr(expected_substring)); # ifndef NDEBUG @@ -2113,7 +2112,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { // Tests how the flag affects uninteresting calls on a naggy mock. void TestUninterestingCallOnNaggyMock(bool should_print) { NaggyMock a; - const string note = + const std::string note = "NOTE: You can safely ignore the above warning unless this " "call should not happen. Do not suppress it by blindly adding " "an EXPECT_CALL() if you don't mean to enforce the call. " diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index 0e97aeed..c16badda 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -51,7 +51,7 @@ const int kRepeat = 50; class MockFoo { public: MOCK_METHOD1(Bar, int(int n)); // NOLINT - MOCK_METHOD2(Baz, char(const char* s1, const internal::string& s2)); // NOLINT + MOCK_METHOD2(Baz, char(const char* s1, const std::string& s2)); // NOLINT }; // Helper for waiting for the given thread to finish and then deleting it. -- cgit v1.2.3 From aac403334d57ca59a7e5930e2b6f73e9cfadee2a Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 4 Jan 2017 15:51:29 +0200 Subject: Correct some typos in a comment --- googlemock/test/gmock-generated-actions_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 03908588..80bcb31c 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -1120,7 +1120,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) { EXPECT_FALSE(b); // Verifies that resetter is deleted. } -// Tests that ACTION_TEMPLATES works for template parameters. +// Tests that ACTION_TEMPLATE works for a template with template parameters. ACTION_TEMPLATE(ReturnSmartPointer, HAS_1_TEMPLATE_PARAMS(template class, Pointer), -- cgit v1.2.3 From 4f5c01b4c96913e2d773b23ca5b81b92bdc29fd0 Mon Sep 17 00:00:00 2001 From: misterg Date: Wed, 9 Aug 2017 12:15:00 -0400 Subject: Added googlemock tests --- googlemock/test/BUILD | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 googlemock/test/BUILD (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD b/googlemock/test/BUILD new file mode 100644 index 00000000..ae0a66e8 --- /dev/null +++ b/googlemock/test/BUILD @@ -0,0 +1,29 @@ +# Copyright 2017 Google Inc. All Rights Reserved. +# Author: misterg@google.com (Gennadiy Civil) +# +# Description: +# Bazel BUILD file for googletest-googlemock, initial revision +# + +""" gmock own tests """ + +cc_test( + name = "gmock_all_test", + size = "small", + srcs = glob( + include = [ + "gmock-*.cc", + ], + ), + copts = select({ + "//:win": ["-DGTEST_USE_OWN_TR1_TUPLE=0"], + "//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"], + }), + linkopts = select({ + "//:win": [], + "//conditions:default": [ + "-pthread", + ], + }), + deps = ["//:gtest"], +) -- cgit v1.2.3 From 5a5e3c17bbec88eb48ba92e0ad325ceaa45a81aa Mon Sep 17 00:00:00 2001 From: misterg Date: Wed, 9 Aug 2017 12:18:12 -0400 Subject: Added googlemock tests --- googlemock/test/BUILD | 4 ---- 1 file changed, 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD b/googlemock/test/BUILD index ae0a66e8..ca597002 100644 --- a/googlemock/test/BUILD +++ b/googlemock/test/BUILD @@ -15,10 +15,6 @@ cc_test( "gmock-*.cc", ], ), - copts = select({ - "//:win": ["-DGTEST_USE_OWN_TR1_TUPLE=0"], - "//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"], - }), linkopts = select({ "//:win": [], "//conditions:default": [ -- cgit v1.2.3 From 66a036959f09071fa0d5f7af4a5cbf470a2c6137 Mon Sep 17 00:00:00 2001 From: misterg Date: Wed, 9 Aug 2017 14:37:58 -0400 Subject: WIP --- googlemock/test/BUILD.bazel | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 googlemock/test/BUILD.bazel (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel new file mode 100644 index 00000000..88e82e60 --- /dev/null +++ b/googlemock/test/BUILD.bazel @@ -0,0 +1,25 @@ +# Copyright 2017 Google Inc. All Rights Reserved. +# Author: misterg@google.com (Gennadiy Civil) +# +# Description: +# Bazel BUILD file for googletest-googlemock/test, initial revision +# + +""" gmock own tests """ + +cc_test( + name = "gmock_all_test", + size = "small", + srcs = glob( + include = [ + "gmock-*.cc", + ], + ), + linkopts = select({ + "//:win": [], + "//conditions:default": [ + "-pthread", + ], + }), + deps = ["//:gtest"], +) -- cgit v1.2.3 From 6e1970e2376c14bf658eb88f655a054030353f9f Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Thu, 10 Aug 2017 09:41:09 -0400 Subject: Adding a flag option to change the default mock type --- googlemock/test/gmock-spec-builders_test.cc | 35 ++++++++++++++++++++++++ googlemock/test/gmock_test.cc | 41 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 389e0709..00cb1198 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -93,8 +93,11 @@ using testing::Sequence; using testing::SetArgPointee; using testing::internal::ExpectationTester; using testing::internal::FormatFileLocation; +using testing::internal::kAllow; using testing::internal::kErrorVerbosity; +using testing::internal::kFail; using testing::internal::kInfoVerbosity; +using testing::internal::kWarn; using testing::internal::kWarningVerbosity; using testing::internal::linked_ptr; @@ -691,6 +694,38 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) { b.DoB(); } +TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { + int original_behavior = testing::GMOCK_FLAG(default_mock_behavior); + + testing::GMOCK_FLAG(default_mock_behavior) = kAllow; + CaptureStdout(); + { + MockA a; + a.DoA(0); + } + std::string output = GetCapturedStdout(); + EXPECT_TRUE(output.empty()) << output; + + testing::GMOCK_FLAG(default_mock_behavior) = kWarn; + CaptureStdout(); + { + MockA a; + a.DoA(0); + } + std::string warning_output = GetCapturedStdout(); + EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output); + EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", warning_output); + + testing::GMOCK_FLAG(default_mock_behavior) = kFail; + EXPECT_NONFATAL_FAILURE({ + MockA a; + a.DoA(0); + },"Uninteresting mock function call"); + + testing::GMOCK_FLAG(default_mock_behavior) = original_behavior; +} + + #endif // GTEST_HAS_STREAM_REDIRECTION // Tests the semantics of ON_CALL(). diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index d8d0c57b..28995345 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -40,6 +40,7 @@ #if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) +using testing::GMOCK_FLAG(default_mock_behavior); using testing::GMOCK_FLAG(verbose); using testing::InitGoogleMock; @@ -103,6 +104,26 @@ TEST(InitGoogleMockTest, ParsesSingleFlag) { TestInitGoogleMock(argv, new_argv, "info"); } +TEST(InitGoogleMockTest, ParsesMultipleFlags) { + int old_default_behavior = GMOCK_FLAG(default_mock_behavior); + const wchar_t* argv[] = { + L"foo.exe", + L"--gmock_verbose=info", + L"--gmock_default_mock_behavior=2", + NULL + }; + + const wchar_t* new_argv[] = { + L"foo.exe", + NULL + }; + + TestInitGoogleMock(argv, new_argv, "info"); + EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); + EXPECT_NE(2, old_default_behavior); + GMOCK_FLAG(default_mock_behavior) = old_default_behavior; +} + TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) { const char* argv[] = { "foo.exe", @@ -177,6 +198,26 @@ TEST(WideInitGoogleMockTest, ParsesSingleFlag) { TestInitGoogleMock(argv, new_argv, "info"); } +TEST(WideInitGoogleMockTest, ParsesMultipleFlags) { + int old_default_behavior = GMOCK_FLAG(default_mock_behavior); + const wchar_t* argv[] = { + L"foo.exe", + L"--gmock_verbose=info", + L"--gmock_default_mock_behavior=2", + NULL + }; + + const wchar_t* new_argv[] = { + L"foo.exe", + NULL + }; + + TestInitGoogleMock(argv, new_argv, "info"); + EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); + EXPECT_NE(2, old_default_behavior); + GMOCK_FLAG(default_mock_behavior) = old_default_behavior; +} + TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) { const wchar_t* argv[] = { L"foo.exe", -- cgit v1.2.3 From b98e30b42704e214871f6baba458ba7c1066d0ed Mon Sep 17 00:00:00 2001 From: misterg Date: Thu, 10 Aug 2017 11:54:46 -0400 Subject: Initial Revision, review 164634031 --- googlemock/test/BUILD | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 googlemock/test/BUILD (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD b/googlemock/test/BUILD deleted file mode 100644 index ca597002..00000000 --- a/googlemock/test/BUILD +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2017 Google Inc. All Rights Reserved. -# Author: misterg@google.com (Gennadiy Civil) -# -# Description: -# Bazel BUILD file for googletest-googlemock, initial revision -# - -""" gmock own tests """ - -cc_test( - name = "gmock_all_test", - size = "small", - srcs = glob( - include = [ - "gmock-*.cc", - ], - ), - linkopts = select({ - "//:win": [], - "//conditions:default": [ - "-pthread", - ], - }), - deps = ["//:gtest"], -) -- cgit v1.2.3 From cb5b05436dfc247399c8a3cc0dc6199bb00200f8 Mon Sep 17 00:00:00 2001 From: misterg Date: Thu, 10 Aug 2017 12:03:27 -0400 Subject: Added Copyright --- googlemock/test/BUILD.bazel | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel index 88e82e60..6e67f187 100644 --- a/googlemock/test/BUILD.bazel +++ b/googlemock/test/BUILD.bazel @@ -1,9 +1,36 @@ -# Copyright 2017 Google Inc. All Rights Reserved. -# Author: misterg@google.com (Gennadiy Civil) +# Copyright 2017 Google Inc. +# All Rights Reserved. +# +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: # -# Description: -# Bazel BUILD file for googletest-googlemock/test, initial revision +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. # +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Author: misterg@google.com (Gennadiy Civil) +# +# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock """ gmock own tests """ -- cgit v1.2.3 From a2803bc37dafdaad05b335e64a83aff03096a4ba Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Wed, 16 Aug 2017 12:43:26 -0400 Subject: Handling invalid flag values --- googlemock/test/gmock-spec-builders_test.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 00cb1198..34088de1 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -722,6 +722,26 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { a.DoA(0); },"Uninteresting mock function call"); + // Out of bounds values are converted to kWarn + testing::GMOCK_FLAG(default_mock_behavior) = -1; + CaptureStdout(); + { + MockA a; + a.DoA(0); + } + warning_output = GetCapturedStdout(); + EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output); + EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", warning_output); + testing::GMOCK_FLAG(default_mock_behavior) = 3; + CaptureStdout(); + { + MockA a; + a.DoA(0); + } + warning_output = GetCapturedStdout(); + EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output); + EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", warning_output); + testing::GMOCK_FLAG(default_mock_behavior) = original_behavior; } -- cgit v1.2.3 From 95f18d99383c27bf645e8dc4f5dcaa188f6bafe3 Mon Sep 17 00:00:00 2001 From: Maurice Gilden Date: Fri, 18 Aug 2017 11:21:28 +0200 Subject: adds test for NiceMock with unknown return value --- googlemock/test/gmock-nice-strict_test.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 5d6ccc4f..5e6d53be 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -79,6 +79,7 @@ class MockFoo : public Foo { MOCK_METHOD0(DoThis, void()); MOCK_METHOD1(DoThat, int(bool flag)); + MOCK_METHOD0(ReturnSomething, Mock()); private: GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); @@ -207,6 +208,20 @@ TEST(NiceMockTest, AllowsExpectedCall) { nice_foo.DoThis(); } +// Tests that an unexpected call on a nice mock which returns a non-built in +// default value throws an exception and the exception contains the name of +// the method. +TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { + NiceMock nice_foo; + try { + nice_foo.ReturnSomething(); + FAIL(); + } catch (const std::runtime_error& ex) { + const std::string exception_msg(ex.what()); + EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos); + } +} + // Tests that an unexpected call on a nice mock fails. TEST(NiceMockTest, UnexpectedCallFails) { NiceMock nice_foo; -- cgit v1.2.3 From cc99900036ae3514d8918acba87817fa24f6c993 Mon Sep 17 00:00:00 2001 From: Maurice Gilden Date: Fri, 18 Aug 2017 11:46:15 +0200 Subject: Fix test if exceptions are not supported --- googlemock/test/gmock-nice-strict_test.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 5e6d53be..86706814 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -213,6 +213,7 @@ TEST(NiceMockTest, AllowsExpectedCall) { // the method. TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { NiceMock nice_foo; +#if GTEST_HAS_EXCEPTIONS try { nice_foo.ReturnSomething(); FAIL(); @@ -220,6 +221,11 @@ TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { const std::string exception_msg(ex.what()); EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos); } +#else + EXPECT_DEATH_IF_SUPPORTED({ + nice_foo.ReturnSomething(); + }, ""); +#endif } // Tests that an unexpected call on a nice mock fails. -- cgit v1.2.3 From 36777251c07788549eaa72a9be0cf482ab322c46 Mon Sep 17 00:00:00 2001 From: Maurice Gilden Date: Fri, 18 Aug 2017 12:28:50 +0200 Subject: Switch return type to class without default constructor --- googlemock/test/gmock-nice-strict_test.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 86706814..1d7784b1 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -62,6 +62,12 @@ using testing::internal::CaptureStdout; using testing::internal::GetCapturedStdout; #endif +// Dummy class without default constructor. +class Dummy { + public: + Dummy(int) {} +}; + // Defines some mock classes needed by the tests. class Foo { @@ -79,7 +85,7 @@ class MockFoo : public Foo { MOCK_METHOD0(DoThis, void()); MOCK_METHOD1(DoThat, int(bool flag)); - MOCK_METHOD0(ReturnSomething, Mock()); + MOCK_METHOD0(ReturnSomething, Dummy()); private: GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); -- cgit v1.2.3 From b0ed43e72447c99f297dc86a75d7d58d53af5a07 Mon Sep 17 00:00:00 2001 From: Maurice Gilden Date: Fri, 18 Aug 2017 15:27:02 +0200 Subject: Change tabs to spaces in test case --- googlemock/test/gmock-nice-strict_test.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 1d7784b1..a8032e24 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -218,19 +218,19 @@ TEST(NiceMockTest, AllowsExpectedCall) { // default value throws an exception and the exception contains the name of // the method. TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { - NiceMock nice_foo; + NiceMock nice_foo; #if GTEST_HAS_EXCEPTIONS - try { - nice_foo.ReturnSomething(); - FAIL(); - } catch (const std::runtime_error& ex) { - const std::string exception_msg(ex.what()); - EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos); - } + try { + nice_foo.ReturnSomething(); + FAIL(); + } catch (const std::runtime_error& ex) { + const std::string exception_msg(ex.what()); + EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos); + } #else - EXPECT_DEATH_IF_SUPPORTED({ - nice_foo.ReturnSomething(); - }, ""); + EXPECT_DEATH_IF_SUPPORTED({ + nice_foo.ReturnSomething(); + }, ""); #endif } -- cgit v1.2.3 From 026735daf34cf180e34a976b3167cc4b311e3f11 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Sun, 20 Aug 2017 15:15:31 -0400 Subject: Proposing these changes, please review Slightly better names and cleaner tests. Please review --- googlemock/test/gmock-nice-strict_test.cc | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index a8032e24..2cb0a96d 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -62,10 +62,10 @@ using testing::internal::CaptureStdout; using testing::internal::GetCapturedStdout; #endif -// Dummy class without default constructor. -class Dummy { +// Class without default constructor. +class NotDefaultConstructible { public: - Dummy(int) {} + NotDefaultConstructible(int) {} }; // Defines some mock classes needed by the tests. @@ -85,7 +85,7 @@ class MockFoo : public Foo { MOCK_METHOD0(DoThis, void()); MOCK_METHOD1(DoThat, int(bool flag)); - MOCK_METHOD0(ReturnSomething, Dummy()); + MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible()); private: GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); @@ -214,23 +214,20 @@ TEST(NiceMockTest, AllowsExpectedCall) { nice_foo.DoThis(); } -// Tests that an unexpected call on a nice mock which returns a non-built in -// default value throws an exception and the exception contains the name of -// the method. +// Tests that an unexpected call on a nice mock which returns a not-default-constructible +// type throws an exception and the exception contains the method's name. TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { NiceMock nice_foo; #if GTEST_HAS_EXCEPTIONS try { - nice_foo.ReturnSomething(); + nice_foo.ReturnNonDefaultConstructible(); FAIL(); } catch (const std::runtime_error& ex) { const std::string exception_msg(ex.what()); - EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos); + EXPECT_THAT(ex.what(), HasSubstr("ReturnNonDefaultConstructible")); } #else - EXPECT_DEATH_IF_SUPPORTED({ - nice_foo.ReturnSomething(); - }, ""); + EXPECT_DEATH_IF_SUPPORTED({ nice_foo.ReturnNonDefaultConstructible(); }, ""); #endif } -- cgit v1.2.3 From 3cf65b5d86d46cceb96ac44672fad84e2d5ad5a7 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Sun, 20 Aug 2017 15:20:13 -0400 Subject: Added "explicit" as per compiler suggestion --- googlemock/test/gmock-nice-strict_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 2cb0a96d..fce9ca5b 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -65,7 +65,7 @@ using testing::internal::GetCapturedStdout; // Class without default constructor. class NotDefaultConstructible { public: - NotDefaultConstructible(int) {} + explicit NotDefaultConstructible(int) {} }; // Defines some mock classes needed by the tests. -- cgit v1.2.3 From 1ee8079651584b6bcc444f4b7a66dd2c65a79eb6 Mon Sep 17 00:00:00 2001 From: Maurice Gilden Date: Mon, 21 Aug 2017 10:10:14 +0200 Subject: Remove unused variable --- googlemock/test/gmock-nice-strict_test.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index fce9ca5b..0eac6439 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -223,7 +223,6 @@ TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { nice_foo.ReturnNonDefaultConstructible(); FAIL(); } catch (const std::runtime_error& ex) { - const std::string exception_msg(ex.what()); EXPECT_THAT(ex.what(), HasSubstr("ReturnNonDefaultConstructible")); } #else -- cgit v1.2.3 From 966b549c88032ec43ecd344ab19ca9ca36c30ad9 Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Tue, 22 Aug 2017 16:06:26 +0200 Subject: Support ref-qualified member functions in Property(). --- googlemock/test/gmock-matchers_test.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f5ab7c81..fc867487 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3588,10 +3588,15 @@ class AClass { // A getter that returns a reference to const. const std::string& s() const { return s_; } +#if GTEST_LANG_CXX11 + const std::string& s_ref() const & { return s_; } +#endif + void set_s(const std::string& new_s) { s_ = new_s; } // A getter that returns a reference to non-const. double& x() const { return x_; } + private: int n_; std::string s_; @@ -3635,6 +3640,21 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) { EXPECT_FALSE(m.Matches(a)); } +#if GTEST_LANG_CXX11 +// Tests that Property(&Foo::property, ...) works when property() is +// ref-qualified. +TEST(PropertyTest, WorksForRefQualifiedProperty) { + Matcher m = Property(&AClass::s_ref, StartsWith("hi")); + + AClass a; + a.set_s("hill"); + EXPECT_TRUE(m.Matches(a)); + + a.set_s("hole"); + EXPECT_FALSE(m.Matches(a)); +} +#endif + // Tests that Property(&Foo::property, ...) works when property() // returns a reference to non-const. TEST(PropertyTest, WorksForReferenceToNonConstProperty) { -- cgit v1.2.3 From fa5d3b3845aa4cc38eef41c2e7ba0e98bfe15b39 Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Mon, 28 Aug 2017 16:13:41 -0400 Subject: Applying lint checks from upstream google3 --- googlemock/test/gmock-spec-builders_test.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 34088de1..c649bfd9 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -714,13 +714,14 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { } std::string warning_output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output); - EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", warning_output); + EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", + warning_output); testing::GMOCK_FLAG(default_mock_behavior) = kFail; EXPECT_NONFATAL_FAILURE({ MockA a; a.DoA(0); - },"Uninteresting mock function call"); + }, "Uninteresting mock function call"); // Out of bounds values are converted to kWarn testing::GMOCK_FLAG(default_mock_behavior) = -1; @@ -731,7 +732,8 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { } warning_output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output); - EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", warning_output); + EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", + warning_output); testing::GMOCK_FLAG(default_mock_behavior) = 3; CaptureStdout(); { @@ -740,7 +742,8 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { } warning_output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output); - EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", warning_output); + EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call", + warning_output); testing::GMOCK_FLAG(default_mock_behavior) = original_behavior; } -- cgit v1.2.3 From b70cf1a663ad30f77ab9867095a87d3d5429450d Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 27 Sep 2017 13:31:13 +0100 Subject: Use gender-neutral pronouns in comments and docs --- googlemock/test/gmock-cardinalities_test.cc | 2 +- googlemock/test/gmock-internal-utils_test.cc | 2 +- googlemock/test/gmock-spec-builders_test.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-cardinalities_test.cc b/googlemock/test/gmock-cardinalities_test.cc index 64815e57..04c792b5 100644 --- a/googlemock/test/gmock-cardinalities_test.cc +++ b/googlemock/test/gmock-cardinalities_test.cc @@ -391,7 +391,7 @@ TEST(ExactlyTest, HasCorrectBounds) { EXPECT_EQ(3, c.ConservativeUpperBound()); } -// Tests that a user can make his own cardinality by implementing +// Tests that a user can make their own cardinality by implementing // CardinalityInterface and calling MakeCardinality(). class EvenCardinality : public CardinalityInterface { diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 9c2423ec..72d9a854 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -49,7 +49,7 @@ // implementation. It must come before gtest-internal-inl.h is // included, or there will be a compiler error. This trick is to // prevent a user from accidentally including gtest-internal-inl.h in -// his code. +// their code. #define GTEST_IMPLEMENTATION_ 1 #include "src/gtest-internal-inl.h" #undef GTEST_IMPLEMENTATION_ diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index c649bfd9..a7bf03e5 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2682,7 +2682,7 @@ TEST(SynchronizationTest, CanCallMockMethodInAction) { } // namespace -// Allows the user to define his own main and then invoke gmock_main +// Allows the user to define their own main and then invoke gmock_main // from it. This might be necessary on some platforms which require // specific setup and teardown. #if GMOCK_RENAME_MAIN -- cgit v1.2.3 From 2641b021fc2ab12896cf868d90f19936ef4b4696 Mon Sep 17 00:00:00 2001 From: Arkadiy Shapkin Date: Wed, 3 May 2017 13:40:33 +0300 Subject: Fix tests with VS2015 and VS2017 --- googlemock/test/gmock-generated-matchers_test.cc | 8 ++++---- googlemock/test/gmock-matchers_test.cc | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 8234858d..6cba726d 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -120,7 +120,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) { } TEST(ArgsTest, AcceptsTwoTemplateArgs) { - const tuple t(4, 5, 6L); // NOLINT + const tuple t(static_cast(4), 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 1>(Lt()))); EXPECT_THAT(t, (Args<1, 2>(Lt()))); @@ -128,13 +128,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) { } TEST(ArgsTest, AcceptsRepeatedTemplateArgs) { - const tuple t(4, 5, 6L); // NOLINT + const tuple t(static_cast(4), 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 0>(Eq()))); EXPECT_THAT(t, Not(Args<1, 1>(Ne()))); } TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { - const tuple t(4, 5, 6L); // NOLINT + const tuple t(static_cast(4), 5, 6L); // NOLINT EXPECT_THAT(t, (Args<2, 0>(Gt()))); EXPECT_THAT(t, Not(Args<2, 1>(Lt()))); } @@ -159,7 +159,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) { } TEST(ArgsTest, CanBeNested) { - const tuple t(4, 5, 6L, 6); // NOLINT + const tuple t(static_cast(4), 5, 6L, 6); // NOLINT EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq())))); EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt())))); } diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index fc867487..207c6fdd 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -58,6 +58,11 @@ # include // NOLINT #endif +// Disable MSVC2015 warning for std::pair: "decorated name length exceeded, name was truncated". +#if defined(_MSC_VER) && (_MSC_VER == 1900) +# pragma warning(disable:4503) +#endif + namespace testing { namespace internal { -- cgit v1.2.3 From 840c711e7bd7240b3f451821473c759ad3578412 Mon Sep 17 00:00:00 2001 From: Arkady Shapkin Date: Thu, 8 Jun 2017 02:28:17 +0300 Subject: Fix gmock tests when std::unary_function unavailable --- googlemock/test/gmock-matchers_test.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 207c6fdd..4beaec4c 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3936,8 +3936,11 @@ TEST(ResultOfTest, WorksForFunctionReferences) { // Tests that ResultOf(f, ...) compiles and works as expected when f is a // function object. -struct Functor : public ::std::unary_function { - result_type operator()(argument_type input) const { +struct Functor { + typedef std::string result_type; + typedef int argument_type; + + std::string operator()(int input) const { return IntToStringFunction(input); } }; -- cgit v1.2.3 From cf3adad594b68caad7a4093dbcd29c6bd7693eb0 Mon Sep 17 00:00:00 2001 From: Carlos O'Ryan Date: Sun, 3 Dec 2017 14:24:13 -0500 Subject: Add licenses() directive for googlemock/tests. Without the directive embedding googletest into third_party breaks any //... target. --- googlemock/test/BUILD.bazel | 2 ++ 1 file changed, 2 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel index 6e67f187..9f1a64d8 100644 --- a/googlemock/test/BUILD.bazel +++ b/googlemock/test/BUILD.bazel @@ -32,6 +32,8 @@ # # Bazel Build for Google C++ Testing Framework(Google Test)-googlemock +licenses(["notice"]) + """ gmock own tests """ cc_test( -- cgit v1.2.3 From b3d9be5c1d969dfdbf1f1ff924b9fd1be5eaecc9 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 10 Feb 2017 19:19:54 -0500 Subject: Pass the -Wmissing-declarations warning. This makes it easier to use GTest in projects that build with the -Wmissing-declarations warning. This fixes the warning in headers and source files, though not GTest's own tests as it is rather noisy there. --- googlemock/test/gmock-matchers_test.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 4beaec4c..5c764eb4 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -65,10 +65,6 @@ namespace testing { -namespace internal { -GTEST_API_ string JoinAsTuple(const Strings& fields); -} // namespace internal - namespace gmock_matchers_test { using std::greater; -- cgit v1.2.3 From 1c09831acc69d6d77af5d5aa45feee6f52dc1a76 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 3 Jan 2018 16:57:05 -0500 Subject: upstreaming cl 124976692 --- googlemock/test/gmock-internal-utils_test.cc | 8 -------- 1 file changed, 8 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 72d9a854..c7893ae2 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -44,15 +44,7 @@ #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" #include "gtest/gtest-spi.h" - -// Indicates that this translation unit is part of Google Test's -// implementation. It must come before gtest-internal-inl.h is -// included, or there will be a compiler error. This trick is to -// prevent a user from accidentally including gtest-internal-inl.h in -// their code. -#define GTEST_IMPLEMENTATION_ 1 #include "src/gtest-internal-inl.h" -#undef GTEST_IMPLEMENTATION_ #if GTEST_OS_CYGWIN # include // For ssize_t. NOLINT -- cgit v1.2.3 From cbd15d417e9a9b8dfbac4483d49b4e0c6664b940 Mon Sep 17 00:00:00 2001 From: Loo Rong Jie Date: Sun, 7 Jan 2018 22:52:52 +0800 Subject: [Bazel] Detect Windows with cpu value x64_windows and x64_windows_msvc and x64_windows_msvc --- googlemock/test/BUILD.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel index 9f1a64d8..4c2df9e2 100644 --- a/googlemock/test/BUILD.bazel +++ b/googlemock/test/BUILD.bazel @@ -45,7 +45,8 @@ cc_test( ], ), linkopts = select({ - "//:win": [], + "//:windows": [], + "//:windows_msvc": [], "//conditions:default": [ "-pthread", ], -- cgit v1.2.3 From fbb48a7708fc791ef25096b383791966bbf369f0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 26 Jan 2018 11:57:58 -0500 Subject: Code merges --- googlemock/test/gmock_stress_test.cc | 3 ++- googlemock/test/gmock_test.cc | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index c16badda..b9fdc45c 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -33,12 +33,13 @@ // threads concurrently. #include "gmock/gmock.h" + #include "gtest/gtest.h" namespace testing { namespace { -// From . +// From "gtest/internal/gtest-port.h". using ::testing::internal::ThreadWithParam; // The maximum number of test threads (not including helper threads) diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index 28995345..70075679 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -37,6 +37,7 @@ #include #include "gtest/gtest.h" +#include "gtest/internal/custom/gtest.h" #if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) @@ -51,9 +52,9 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N], const ::std::string& expected_gmock_verbose) { const ::std::string old_verbose = GMOCK_FLAG(verbose); - int argc = M; + int argc = M - 1; InitGoogleMock(&argc, const_cast(argv)); - ASSERT_EQ(N, argc) << "The new argv has wrong number of elements."; + ASSERT_EQ(N - 1, argc) << "The new argv has wrong number of elements."; for (int i = 0; i < N; i++) { EXPECT_STREQ(new_argv[i], argv[i]); -- cgit v1.2.3 From 6c0c389601fc823f2e4c1ae27b39cb13d5d0a7d4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 26 Jan 2018 16:30:57 -0500 Subject: Adding tests to googlemock bazel --- googlemock/test/BUILD.bazel | 72 +++++++++++++++++++++++++++++++++++-- googlemock/test/gmock_test_utils.py | 6 ++-- 2 files changed, 72 insertions(+), 6 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel index 4c2df9e2..0fe72a67 100644 --- a/googlemock/test/BUILD.bazel +++ b/googlemock/test/BUILD.bazel @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. +# Copyright 2017 Google Inc. # All Rights Reserved. # # @@ -29,7 +29,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Author: misterg@google.com (Gennadiy Civil) -# +# # Bazel Build for Google C++ Testing Framework(Google Test)-googlemock licenses(["notice"]) @@ -53,3 +53,71 @@ cc_test( }), deps = ["//:gtest"], ) + +# Py tests + +py_library( + name = "gmock_test_utils", + testonly = 1, + srcs = ["gmock_test_utils.py"], +) + +cc_binary( + name = "gmock_leak_test_", + testonly = 1, + srcs = ["gmock_leak_test_.cc"], + deps = [ + "//:gtest_main", + ], +) + +py_test( + name = "gmock_leak_test", + size = "medium", + srcs = ["gmock_leak_test.py"], + data = [ + ":gmock_leak_test_", + ":gmock_test_utils", + ], +) + +cc_test( + name = "gmock_link_test", + size = "small", + srcs = [ + "gmock_link2_test.cc", + "gmock_link_test.cc", + "gmock_link_test.h", + ], + deps = [ + "//:gtest_main", + ], +) + +cc_binary( + name = "gmock_output_test_", + srcs = ["gmock_output_test_.cc"], + deps = [ + "//:gtest", + ], +) + +py_test( + name = "gmock_output_test", + size = "medium", + srcs = ["gmock_output_test.py"], + data = [ + ":gmock_output_test_", + ":gmock_output_test_golden.txt", + ], + deps = [":gmock_test_utils"], +) + +cc_test( + name = "gmock_test", + size = "small", + srcs = ["gmock_test.cc"], + deps = [ + "//:gtest_main", + ], +) diff --git a/googlemock/test/gmock_test_utils.py b/googlemock/test/gmock_test_utils.py index 20e3d3d4..1983c53b 100755 --- a/googlemock/test/gmock_test_utils.py +++ b/googlemock/test/gmock_test_utils.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Copyright 2006, Google Inc. # All rights reserved. # @@ -41,11 +39,11 @@ import sys SCRIPT_DIR = os.path.dirname(__file__) or '.' # isdir resolves symbolic links. -gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test') +gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../googletest/test') if os.path.isdir(gtest_tests_util_dir): GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir else: - GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test') + GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../googletest/test') sys.path.append(GTEST_TESTS_UTIL_DIR) import gtest_test_utils # pylint: disable-msg=C6204 -- cgit v1.2.3 From c8510504ddf3bd9e486fdce076bdf5dba62d18bb Mon Sep 17 00:00:00 2001 From: Troy Holsapple Date: Wed, 7 Feb 2018 22:06:00 -0800 Subject: Fixed typos --- googlemock/test/gmock-actions_test.cc | 2 +- googlemock/test/gmock-matchers_test.cc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f470de4c..f7218391 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -751,7 +751,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overriden by an ON_CALL(). +// DefaultValue::Set() when it's not overridden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 5c764eb4..07e5fa63 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -915,7 +915,7 @@ TEST(TypedEqTest, CanDescribeSelf) { // Type::IsTypeOf(v) compiles iff the type of value v is T, where T // is a "bare" type (i.e. not in the form of const U or U&). If v's // type is not T, the compiler will generate a message about -// "undefined referece". +// "undefined reference". template struct Type { static bool IsTypeOf(const T& /* v */) { return true; } @@ -1424,7 +1424,7 @@ TEST(PairTest, MatchesCorrectly) { EXPECT_THAT(p, Pair(25, "foo")); EXPECT_THAT(p, Pair(Ge(20), HasSubstr("o"))); - // 'first' doesnt' match, but 'second' matches. + // 'first' does not match, but 'second' matches. EXPECT_THAT(p, Not(Pair(42, "foo"))); EXPECT_THAT(p, Not(Pair(Lt(25), "foo"))); @@ -4263,7 +4263,7 @@ TYPED_TEST(ContainerEqTest, DuplicateDifference) { #endif // GTEST_HAS_TYPED_TEST // Tests that mutliple missing values are reported. -// Using just vector here, so order is predicatble. +// Using just vector here, so order is predictable. TEST(ContainerEqExtraTest, MultipleValuesMissing) { static const int vals[] = {1, 1, 2, 3, 5, 8}; static const int test_vals[] = {2, 1, 5}; @@ -4276,7 +4276,7 @@ TEST(ContainerEqExtraTest, MultipleValuesMissing) { } // Tests that added values are reported. -// Using just vector here, so order is predicatble. +// Using just vector here, so order is predictable. TEST(ContainerEqExtraTest, MultipleValuesAdded) { static const int vals[] = {1, 1, 2, 3, 5, 8}; static const int test_vals[] = {1, 2, 92, 3, 5, 8, 46}; -- cgit v1.2.3 From ec7faa943d7817c81ce7bdf71a21ebc9244dc8de Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 9 Feb 2018 10:41:09 -0500 Subject: merges --- googlemock/test/gmock_output_test.py | 13 ++++++++----- googlemock/test/gmock_test_utils.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test.py b/googlemock/test/gmock_output_test.py index eced8a81..9d73d570 100755 --- a/googlemock/test/gmock_output_test.py +++ b/googlemock/test/gmock_output_test.py @@ -31,11 +31,11 @@ """Tests the text output of Google C++ Mocking Framework. -SYNOPSIS - gmock_output_test.py --build_dir=BUILD/DIR --gengolden - # where BUILD/DIR contains the built gmock_output_test_ file. - gmock_output_test.py --gengolden - gmock_output_test.py +To update the golden file: +gmock_output_test.py --build_dir=BUILD/DIR --gengolden +# where BUILD/DIR contains the built gmock_output_test_ file. +gmock_output_test.py --gengolden +gmock_output_test.py """ __author__ = 'wan@google.com (Zhanyong Wan)' @@ -176,5 +176,8 @@ if __name__ == '__main__': golden_file = open(GOLDEN_PATH, 'wb') golden_file.write(output) golden_file.close() + # Suppress the error "googletest was imported but a call to its main() + # was never detected." + os._exit(0) else: gmock_test_utils.Main() diff --git a/googlemock/test/gmock_test_utils.py b/googlemock/test/gmock_test_utils.py index 1983c53b..b5130001 100755 --- a/googlemock/test/gmock_test_utils.py +++ b/googlemock/test/gmock_test_utils.py @@ -34,7 +34,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)' import os import sys - # Determines path to gtest_test_utils and imports it. SCRIPT_DIR = os.path.dirname(__file__) or '.' @@ -44,9 +43,10 @@ if os.path.isdir(gtest_tests_util_dir): GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir else: GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../googletest/test') - sys.path.append(GTEST_TESTS_UTIL_DIR) -import gtest_test_utils # pylint: disable-msg=C6204 + +# pylint: disable=C6204 +import gtest_test_utils def GetSourceDir(): -- cgit v1.2.3 From 225e6741acfaa38375589dafcc84254a92313dac Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 12 Feb 2018 16:42:12 -0500 Subject: moving JoinAsTuple to internal --- googlemock/test/gmock-matchers_test.cc | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 07e5fa63..761c0c22 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -146,7 +146,6 @@ using testing::internal::ExplainMatchFailureTupleTo; using testing::internal::FloatingEqMatcher; using testing::internal::FormatMatcherDescription; using testing::internal::IsReadableTypeName; -using testing::internal::JoinAsTuple; using testing::internal::linked_ptr; using testing::internal::MatchMatrix; using testing::internal::RE; @@ -872,9 +871,9 @@ class Unprintable { char c_; }; -inline bool operator==(const Unprintable& /* lhs */, - const Unprintable& /* rhs */) { - return true; +inline bool operator==(const Unprintable& /* lhs */, + const Unprintable& /* rhs */) { + return true; } TEST(EqTest, CanDescribeSelf) { @@ -5268,28 +5267,6 @@ TEST(IsReadableTypeNameTest, ReturnsFalseForLongFunctionTypeNames) { EXPECT_FALSE(IsReadableTypeName("void (&)(int, bool, char, float)")); } -// Tests JoinAsTuple(). - -TEST(JoinAsTupleTest, JoinsEmptyTuple) { - EXPECT_EQ("", JoinAsTuple(Strings())); -} - -TEST(JoinAsTupleTest, JoinsOneTuple) { - const char* fields[] = {"1"}; - EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1))); -} - -TEST(JoinAsTupleTest, JoinsTwoTuple) { - const char* fields[] = {"1", "a"}; - EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2))); -} - -TEST(JoinAsTupleTest, JoinsTenTuple) { - const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; - EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", - JoinAsTuple(Strings(fields, fields + 10))); -} - // Tests FormatMatcherDescription(). TEST(FormatMatcherDescriptionTest, WorksForEmptyDescription) { -- cgit v1.2.3 From 567b40eeb15338402a204fc15362e553549aadea Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Fri, 23 Feb 2018 12:28:09 -0800 Subject: Try to handle unsigned wchar_t (arm) a bit better --- googlemock/test/gmock-actions_test.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f7218391..9447c22b 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -107,7 +107,11 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) { EXPECT_EQ(0, BuiltInDefaultValue::Get()); #endif #if GMOCK_WCHAR_T_IS_NATIVE_ +#if !defined(__WCHAR_UNSIGNED__) EXPECT_EQ(0, BuiltInDefaultValue::Get()); +#else + EXPECT_EQ(0U, BuiltInDefaultValue::Get()); +#endif #endif EXPECT_EQ(0U, BuiltInDefaultValue::Get()); // NOLINT EXPECT_EQ(0, BuiltInDefaultValue::Get()); // NOLINT -- cgit v1.2.3 From 190e2cdd0b55d289136a177638942e1cd1b2d457 Mon Sep 17 00:00:00 2001 From: Xiaoyi Zhang Date: Tue, 27 Feb 2018 11:36:21 -0500 Subject: Add matcher for std::variant. --- googlemock/test/gmock-matchers_test.cc | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 761c0c22..829935ef 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5655,5 +5655,69 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) { EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs)); } +class SampleVariantIntString { + public: + SampleVariantIntString(int i) : i_(i), has_int_(true) {} + SampleVariantIntString(const std::string& s) : s_(s), has_int_(false) {} + + template + friend bool holds_alternative(const SampleVariantIntString& value) { + return value.has_int_ == internal::IsSame::value; + } + + template + friend const T& get(const SampleVariantIntString& value) { + return value.get_impl(static_cast(NULL)); + } + + private: + const int& get_impl(int*) const { return i_; } + const std::string& get_impl(std::string*) const { return s_; } + + int i_; + std::string s_; + bool has_int_; +}; + +TEST(VariantTest, DescribesSelf) { + const Matcher m = VariantWith(Eq(1)); + EXPECT_THAT(Describe(m), ContainsRegex("is a variant<> with value of type " + "'.*' and the value is equal to 1")); +} + +TEST(VariantTest, ExplainsSelf) { + const Matcher m = VariantWith(Eq(1)); + EXPECT_THAT(Explain(m, SampleVariantIntString(1)), + ContainsRegex("whose value 1")); + EXPECT_THAT(Explain(m, SampleVariantIntString("A")), + HasSubstr("whose value is not of type '")); + EXPECT_THAT(Explain(m, SampleVariantIntString(2)), + "whose value 2 doesn't match"); +} + +TEST(VariantTest, FullMatch) { + Matcher m = VariantWith(Eq(1)); + EXPECT_TRUE(m.Matches(SampleVariantIntString(1))); + + m = VariantWith(Eq("1")); + EXPECT_TRUE(m.Matches(SampleVariantIntString("1"))); +} + +TEST(VariantTest, TypeDoesNotMatch) { + Matcher m = VariantWith(Eq(1)); + EXPECT_FALSE(m.Matches(SampleVariantIntString("1"))); + + m = VariantWith(Eq("1")); + EXPECT_FALSE(m.Matches(SampleVariantIntString(1))); +} + +TEST(VariantTest, InnerDoesNotMatch) { + Matcher m = VariantWith(Eq(1)); + EXPECT_FALSE(m.Matches(SampleVariantIntString(2))); + + m = VariantWith(Eq("1")); + EXPECT_FALSE(m.Matches(SampleVariantIntString("2"))); +} + } // namespace gmock_matchers_test } // namespace testing -- cgit v1.2.3 From 2bd1750ba7bd23038a329ff80613b9a4e9b89497 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 27 Feb 2018 13:51:09 -0500 Subject: gmock merging -2 --- googlemock/test/gmock_link_test.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 1f55f5bd..5f855d19 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -120,13 +120,15 @@ # include #endif -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" #include #include +#include "gtest/gtest.h" +#include "gtest/internal/gtest-port.h" + using testing::_; using testing::A; +using testing::Action; using testing::AllOf; using testing::AnyOf; using testing::Assign; @@ -148,6 +150,8 @@ using testing::Invoke; using testing::InvokeArgument; using testing::InvokeWithoutArgs; using testing::IsNull; +using testing::IsSubsetOf; +using testing::IsSupersetOf; using testing::Le; using testing::Lt; using testing::Matcher; @@ -592,6 +596,22 @@ TEST(LinkTest, TestMatcherElementsAreArray) { ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return()); } +// Tests the linkage of the IsSubsetOf matcher. +TEST(LinkTest, TestMatcherIsSubsetOf) { + Mock mock; + char arr[] = {'a', 'b'}; + + ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return()); +} + +// Tests the linkage of the IsSupersetOf matcher. +TEST(LinkTest, TestMatcherIsSupersetOf) { + Mock mock; + char arr[] = {'a', 'b'}; + + ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return()); +} + // Tests the linkage of the ContainerEq matcher. TEST(LinkTest, TestMatcherContainerEq) { Mock mock; -- cgit v1.2.3 From 0d5e01ad7bf0796679417e3acdb0418f5b19fc31 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 5 Mar 2018 12:26:15 -0500 Subject: Merges-1 --- googlemock/test/gmock_link_test.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 5f855d19..06a1cf89 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -90,8 +90,10 @@ // Field // Property // ResultOf(function) +// ResultOf(callback) // Pointee // Truly(predicate) +// AddressSatisfies // AllOf // AnyOf // Not -- cgit v1.2.3 From af463c43ac22279239c1b8065ded7026b9224de1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 13 Mar 2018 11:13:37 -0400 Subject: More merges, removing old dead code --- googlemock/test/gmock-actions_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 9447c22b..01286634 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -218,7 +218,7 @@ class MyNonDefaultConstructible { int value_; }; -#if GTEST_HAS_STD_TYPE_TRAITS_ +#if GTEST_LANG_CXX11 TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) { EXPECT_TRUE(BuiltInDefaultValue::Exists()); @@ -228,7 +228,7 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) { EXPECT_EQ(42, BuiltInDefaultValue::Get().value()); } -#endif // GTEST_HAS_STD_TYPE_TRAITS_ +#endif // GTEST_LANG_CXX11 TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) { EXPECT_FALSE(BuiltInDefaultValue::Exists()); -- cgit v1.2.3 From b7c568326c969c59a5f90e4731dc5b91f260c6f0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 22 Mar 2018 15:35:37 -0400 Subject: merging, gmock -1 --- googlemock/test/gmock-internal-utils_test.cc | 28 ++++++++++++++++++++++++++++ googlemock/test/gmock_output_test_.cc | 6 +++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index c7893ae2..f8633df2 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -44,7 +44,15 @@ #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" #include "gtest/gtest-spi.h" + +// Indicates that this translation unit is part of Google Test's +// implementation. It must come before gtest-internal-inl.h is +// included, or there will be a compiler error. This trick is to +// prevent a user from accidentally including gtest-internal-inl.h in +// their code. +#define GTEST_IMPLEMENTATION_ 1 #include "src/gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_ #if GTEST_OS_CYGWIN # include // For ssize_t. NOLINT @@ -61,6 +69,26 @@ namespace internal { namespace { +TEST(JoinAsTupleTest, JoinsEmptyTuple) { + EXPECT_EQ("", JoinAsTuple(Strings())); +} + +TEST(JoinAsTupleTest, JoinsOneTuple) { + const char* fields[] = {"1"}; + EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1))); +} + +TEST(JoinAsTupleTest, JoinsTwoTuple) { + const char* fields[] = {"1", "a"}; + EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2))); +} + +TEST(JoinAsTupleTest, JoinsTenTuple) { + const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; + EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", + JoinAsTuple(Strings(fields, fields + 10))); +} + TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) { EXPECT_EQ("", ConvertIdentifierNameToWords("")); EXPECT_EQ("", ConvertIdentifierNameToWords("_")); diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 44cba342..d80e2b08 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -47,6 +47,7 @@ using testing::NaggyMock; using testing::Ref; using testing::Return; using testing::Sequence; +using testing::Value; class MockFoo { public: @@ -268,6 +269,10 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) { // Both foo1 and foo2 are deliberately leaked. } +MATCHER_P2(IsPair, first, second, "") { + return Value(arg.first, first) && Value(arg.second, second); +} + void TestCatchesLeakedMocksInAdHocTests() { MockFoo* foo = new MockFoo; @@ -280,7 +285,6 @@ void TestCatchesLeakedMocksInAdHocTests() { int main(int argc, char **argv) { testing::InitGoogleMock(&argc, argv); - // Ensures that the tests pass no matter what value of // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies. testing::GMOCK_FLAG(catch_leaked_mocks) = true; -- cgit v1.2.3 From e55089ec115db3eb1877e49c9351d096b37583df Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 14:05:00 -0400 Subject: merging gmock matchers 1 --- googlemock/test/gmock-matchers_test.cc | 299 +++++++++++++++++++++++++++++---- 1 file changed, 262 insertions(+), 37 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 829935ef..cc161346 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -58,13 +59,11 @@ # include // NOLINT #endif -// Disable MSVC2015 warning for std::pair: "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER == 1900) -# pragma warning(disable:4503) +#if GTEST_LANG_CXX11 +# include #endif namespace testing { - namespace gmock_matchers_test { using std::greater; @@ -200,17 +199,13 @@ std::string OfType(const std::string& type_name) { // Returns the description of the given matcher. template std::string Describe(const Matcher& m) { - stringstream ss; - m.DescribeTo(&ss); - return ss.str(); + return DescribeMatcher(m); } // Returns the description of the negation of the given matcher. template std::string DescribeNegation(const Matcher& m) { - stringstream ss; - m.DescribeNegationTo(&ss); - return ss.str(); + return DescribeMatcher(m, true); } // Returns the reason why x matches, or doesn't match, m. @@ -221,6 +216,12 @@ std::string Explain(const MatcherType& m, const Value& x) { return listener.str(); } +TEST(MonotonicMatcherTest, IsPrintable) { + stringstream ss; + ss << GreaterThan(5); + EXPECT_EQ("is > 5", ss.str()); +} + TEST(MatchResultListenerTest, StreamingWorks) { StringMatchResultListener listener; listener << "hi" << 5; @@ -332,6 +333,22 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) { EXPECT_FALSE(m1.Matches(&n)); } +// Tests that matchers can be constructed from a variable that is not properly +// defined. This should be illegal, but many users rely on this accidentally. +struct Undefined { + virtual ~Undefined() = 0; + static const int kInt = 1; +}; + +TEST(MatcherTest, CanBeConstructedFromUndefinedVariable) { + Matcher m1 = Undefined::kInt; + EXPECT_TRUE(m1.Matches(1)); + EXPECT_FALSE(m1.Matches(2)); +} + +// Test that a matcher parameterized with an abstract class compiles. +TEST(MatcherTest, CanAcceptAbstractClass) { Matcher m = _; } + // Tests that matchers are copyable. TEST(MatcherTest, IsCopyable) { // Tests the copy constructor. @@ -365,66 +382,132 @@ TEST(MatcherTest, MatchAndExplain) { } // Tests that a C-string literal can be implicitly converted to a -// Matcher or Matcher. +// Matcher or Matcher. TEST(StringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { - Matcher m1 = "hi"; + Matcher m1 = "hi"; EXPECT_TRUE(m1.Matches("hi")); EXPECT_FALSE(m1.Matches("hello")); - Matcher m2 = "hi"; + Matcher m2 = "hi"; EXPECT_TRUE(m2.Matches("hi")); EXPECT_FALSE(m2.Matches("hello")); } // Tests that a string object can be implicitly converted to a -// Matcher or Matcher. +// Matcher or Matcher. TEST(StringMatcherTest, CanBeImplicitlyConstructedFromString) { - Matcher m1 = string("hi"); + Matcher m1 = std::string("hi"); + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = std::string("hi"); + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} + +#if GTEST_HAS_GLOBAL_STRING +// Tests that a ::string object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) { + Matcher m1 = ::string("hi"); + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = ::string("hi"); + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} +#endif // GTEST_HAS_GLOBAL_STRING + +#if GTEST_HAS_GLOBAL_STRING +// Tests that a C-string literal can be implicitly converted to a +// Matcher<::string> or Matcher. +TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { + Matcher< ::string> m1 = "hi"; + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = "hi"; + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} + +// Tests that a std::string object can be implicitly converted to a +// Matcher<::string> or Matcher. +TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromString) { + Matcher< ::string> m1 = std::string("hi"); + EXPECT_TRUE(m1.Matches("hi")); + EXPECT_FALSE(m1.Matches("hello")); + + Matcher m2 = std::string("hi"); + EXPECT_TRUE(m2.Matches("hi")); + EXPECT_FALSE(m2.Matches("hello")); +} + +// Tests that a ::string object can be implicitly converted to a +// Matcher<::string> or Matcher. +TEST(GlobalStringMatcherTest, CanBeImplicitlyConstructedFromGlobalString) { + Matcher< ::string> m1 = ::string("hi"); EXPECT_TRUE(m1.Matches("hi")); EXPECT_FALSE(m1.Matches("hello")); - Matcher m2 = string("hi"); + Matcher m2 = ::string("hi"); EXPECT_TRUE(m2.Matches("hi")); EXPECT_FALSE(m2.Matches("hello")); } +#endif // GTEST_HAS_GLOBAL_STRING -#if GTEST_HAS_STRING_PIECE_ +#if GTEST_HAS_ABSL // Tests that a C-string literal can be implicitly converted to a -// Matcher or Matcher. -TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { - Matcher m1 = "cats"; +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromCStringLiteral) { + Matcher m1 = "cats"; EXPECT_TRUE(m1.Matches("cats")); EXPECT_FALSE(m1.Matches("dogs")); - Matcher m2 = "cats"; + Matcher m2 = "cats"; EXPECT_TRUE(m2.Matches("cats")); EXPECT_FALSE(m2.Matches("dogs")); } -// Tests that a string object can be implicitly converted to a -// Matcher or Matcher. -TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromString) { - Matcher m1 = string("cats"); +// Tests that a std::string object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromString) { + Matcher m1 = std::string("cats"); + EXPECT_TRUE(m1.Matches("cats")); + EXPECT_FALSE(m1.Matches("dogs")); + + Matcher m2 = std::string("cats"); + EXPECT_TRUE(m2.Matches("cats")); + EXPECT_FALSE(m2.Matches("dogs")); +} + +#if GTEST_HAS_GLOBAL_STRING +// Tests that a ::string object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromGlobalString) { + Matcher m1 = ::string("cats"); EXPECT_TRUE(m1.Matches("cats")); EXPECT_FALSE(m1.Matches("dogs")); - Matcher m2 = string("cats"); + Matcher m2 = ::string("cats"); EXPECT_TRUE(m2.Matches("cats")); EXPECT_FALSE(m2.Matches("dogs")); } +#endif // GTEST_HAS_GLOBAL_STRING -// Tests that a StringPiece object can be implicitly converted to a -// Matcher or Matcher. -TEST(StringPieceMatcherTest, CanBeImplicitlyConstructedFromStringPiece) { - Matcher m1 = StringPiece("cats"); +// Tests that a absl::string_view object can be implicitly converted to a +// Matcher or Matcher. +TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) { + Matcher m1 = absl::string_view("cats"); EXPECT_TRUE(m1.Matches("cats")); EXPECT_FALSE(m1.Matches("dogs")); - Matcher m2 = StringPiece("cats"); + Matcher m2 = absl::string_view("cats"); EXPECT_TRUE(m2.Matches("cats")); EXPECT_FALSE(m2.Matches("dogs")); } -#endif // GTEST_HAS_STRING_PIECE_ +#endif // GTEST_HAS_ABSL // Tests that MakeMatcher() constructs a Matcher from a // MatcherInterface* without requiring the user to explicitly @@ -613,7 +696,7 @@ TEST(MatcherCastTest, FromSameType) { 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; @@ -1177,6 +1260,13 @@ TEST(StrEqTest, MatchesEqualString) { Matcher m2 = StrEq("Hello"); EXPECT_TRUE(m2.Matches("Hello")); EXPECT_FALSE(m2.Matches("Hi")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrEq("Hello"); + EXPECT_TRUE(m3.Matches(absl::string_view("Hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view("hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(StrEqTest, CanDescribeSelf) { @@ -1202,6 +1292,13 @@ TEST(StrNeTest, MatchesUnequalString) { Matcher m2 = StrNe(std::string("Hello")); EXPECT_TRUE(m2.Matches("hello")); EXPECT_FALSE(m2.Matches("Hello")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrNe("Hello"); + EXPECT_TRUE(m3.Matches(absl::string_view(""))); + EXPECT_TRUE(m3.Matches(absl::string_view())); + EXPECT_FALSE(m3.Matches(absl::string_view("Hello"))); +#endif // GTEST_HAS_ABSL } TEST(StrNeTest, CanDescribeSelf) { @@ -1210,15 +1307,23 @@ TEST(StrNeTest, CanDescribeSelf) { } TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { - Matcher m = StrCaseEq(string("Hello")); + Matcher m = StrCaseEq(std::string("Hello")); EXPECT_TRUE(m.Matches("Hello")); EXPECT_TRUE(m.Matches("hello")); EXPECT_FALSE(m.Matches("Hi")); EXPECT_FALSE(m.Matches(NULL)); - Matcher m2 = StrCaseEq("Hello"); + Matcher m2 = StrCaseEq("Hello"); EXPECT_TRUE(m2.Matches("hello")); EXPECT_FALSE(m2.Matches("Hi")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrCaseEq(std::string("Hello")); + EXPECT_TRUE(m3.Matches(absl::string_view("Hello"))); + EXPECT_TRUE(m3.Matches(absl::string_view("hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view("Hi"))); + EXPECT_FALSE(m3.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(StrCaseEqTest, MatchesEqualStringWith0IgnoringCase) { @@ -1261,6 +1366,14 @@ TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m2 = StrCaseNe(std::string("Hello")); EXPECT_TRUE(m2.Matches("")); EXPECT_FALSE(m2.Matches("Hello")); + +#if GTEST_HAS_ABSL + Matcher m3 = StrCaseNe("Hello"); + EXPECT_TRUE(m3.Matches(absl::string_view("Hi"))); + EXPECT_TRUE(m3.Matches(absl::string_view())); + EXPECT_FALSE(m3.Matches(absl::string_view("Hello"))); + EXPECT_FALSE(m3.Matches(absl::string_view("hello"))); +#endif // GTEST_HAS_ABSL } TEST(StrCaseNeTest, CanDescribeSelf) { @@ -1292,6 +1405,25 @@ TEST(HasSubstrTest, WorksForCStrings) { EXPECT_FALSE(m2.Matches(NULL)); } +#if GTEST_HAS_ABSL +// Tests that HasSubstr() works for matching absl::string_view-typed values. +TEST(HasSubstrTest, WorksForStringViewClasses) { + const Matcher m1 = HasSubstr("foo"); + EXPECT_TRUE(m1.Matches(absl::string_view("I love food."))); + EXPECT_FALSE(m1.Matches(absl::string_view("tofo"))); + EXPECT_FALSE(m1.Matches(absl::string_view())); + + const Matcher m2 = HasSubstr("foo"); + EXPECT_TRUE(m2.Matches(absl::string_view("I love food."))); + EXPECT_FALSE(m2.Matches(absl::string_view("tofo"))); + EXPECT_FALSE(m2.Matches(absl::string_view())); + + const Matcher m3 = HasSubstr(""); + EXPECT_TRUE(m3.Matches(absl::string_view("foo"))); + EXPECT_FALSE(m3.Matches(absl::string_view())); +} +#endif // GTEST_HAS_ABSL + // Tests that HasSubstr(s) describes itself properly. TEST(HasSubstrTest, CanDescribeSelf) { Matcher m = HasSubstr("foo\n\""); @@ -1320,6 +1452,35 @@ TEST(KeyTest, MatchesCorrectly) { EXPECT_THAT(p, Not(Key(Lt(25)))); } +#if GTEST_LANG_CXX11 +template +struct Tag {}; + +struct PairWithGet { + int member_1; + string member_2; + using first_type = int; + using second_type = string; + + const int& GetImpl(Tag<0>) const { return member_1; } + const string& GetImpl(Tag<1>) const { return member_2; } +}; +template +auto get(const PairWithGet& value) -> decltype(value.GetImpl(Tag())) { + return value.GetImpl(Tag()); +} +TEST(PairTest, MatchesPairWithGetCorrectly) { + PairWithGet p{25, "foo"}; + EXPECT_THAT(p, Key(25)); + EXPECT_THAT(p, Not(Key(42))); + EXPECT_THAT(p, Key(Ge(20))); + EXPECT_THAT(p, Not(Key(Lt(25)))); + + std::vector v = {{11, "Foo"}, {29, "gMockIsBestMock"}}; + EXPECT_THAT(v, Contains(Key(29))); +} +#endif // GTEST_LANG_CXX11 + TEST(KeyTest, SafelyCastsInnerMatcher) { Matcher is_positive = Gt(0); Matcher is_negative = Lt(0); @@ -1423,7 +1584,7 @@ TEST(PairTest, MatchesCorrectly) { EXPECT_THAT(p, Pair(25, "foo")); EXPECT_THAT(p, Pair(Ge(20), HasSubstr("o"))); - // 'first' does not match, but 'second' matches. + // 'first' doesnt' match, but 'second' matches. EXPECT_THAT(p, Not(Pair(42, "foo"))); EXPECT_THAT(p, Not(Pair(Lt(25), "foo"))); @@ -1457,6 +1618,18 @@ TEST(PairTest, InsideContainsUsingMap) { EXPECT_THAT(container, Not(Contains(Pair(3, _)))); } +#if GTEST_LANG_CXX11 +TEST(PairTest, UseGetInsteadOfMembers) { + PairWithGet pair{7, "ABC"}; + EXPECT_THAT(pair, Pair(7, "ABC")); + EXPECT_THAT(pair, Pair(Ge(7), HasSubstr("AB"))); + EXPECT_THAT(pair, Not(Pair(Lt(7), "ABC"))); + + std::vector v = {{11, "Foo"}, {29, "gMockIsBestMock"}}; + EXPECT_THAT(v, ElementsAre(Pair(11, string("Foo")), Pair(Ge(10), Not("")))); +} +#endif // GTEST_LANG_CXX11 + // Tests StartsWith(s). TEST(StartsWithTest, MatchesStringWithGivenPrefix) { @@ -1486,12 +1659,30 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) { EXPECT_TRUE(m1.Matches("")); EXPECT_FALSE(m1.Matches(NULL)); - const Matcher m2 = EndsWith(string("Hi")); + const Matcher m2 = EndsWith(std::string("Hi")); EXPECT_TRUE(m2.Matches("Hi")); EXPECT_TRUE(m2.Matches("Wow Hi Hi")); EXPECT_TRUE(m2.Matches("Super Hi")); EXPECT_FALSE(m2.Matches("i")); EXPECT_FALSE(m2.Matches("Hi ")); + +#if GTEST_HAS_GLOBAL_STRING + const Matcher m3 = EndsWith(::string("Hi")); + EXPECT_TRUE(m3.Matches("Hi")); + EXPECT_TRUE(m3.Matches("Wow Hi Hi")); + EXPECT_TRUE(m3.Matches("Super Hi")); + EXPECT_FALSE(m3.Matches("i")); + EXPECT_FALSE(m3.Matches("Hi ")); +#endif // GTEST_HAS_GLOBAL_STRING + +#if GTEST_HAS_ABSL + const Matcher m4 = EndsWith(""); + EXPECT_TRUE(m4.Matches("Hi")); + EXPECT_TRUE(m4.Matches("")); + // Default-constructed absl::string_view should not match anything, in order + // to distinguish it from an empty string. + EXPECT_FALSE(m4.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(EndsWithTest, CanDescribeSelf) { @@ -1511,6 +1702,18 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) { EXPECT_TRUE(m2.Matches("azbz")); EXPECT_FALSE(m2.Matches("az1")); EXPECT_FALSE(m2.Matches("1az")); + +#if GTEST_HAS_ABSL + const Matcher m3 = MatchesRegex("a.*z"); + EXPECT_TRUE(m3.Matches(absl::string_view("az"))); + EXPECT_TRUE(m3.Matches(absl::string_view("abcz"))); + EXPECT_FALSE(m3.Matches(absl::string_view("1az"))); + // Default-constructed absl::string_view should not match anything, in order + // to distinguish it from an empty string. + EXPECT_FALSE(m3.Matches(absl::string_view())); + const Matcher m4 = MatchesRegex(""); + EXPECT_FALSE(m4.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(MatchesRegexTest, CanDescribeSelf) { @@ -1519,6 +1722,11 @@ TEST(MatchesRegexTest, CanDescribeSelf) { Matcher m2 = MatchesRegex(new RE("a.*")); EXPECT_EQ("matches regular expression \"a.*\"", Describe(m2)); + +#if GTEST_HAS_ABSL + Matcher m3 = MatchesRegex(new RE("0.*")); + EXPECT_EQ("matches regular expression \"0.*\"", Describe(m3)); +#endif // GTEST_HAS_ABSL } // Tests ContainsRegex(). @@ -1533,6 +1741,18 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) { EXPECT_TRUE(m2.Matches("azbz")); EXPECT_TRUE(m2.Matches("az1")); EXPECT_FALSE(m2.Matches("1a")); + +#if GTEST_HAS_ABSL + const Matcher m3 = ContainsRegex(new RE("a.*z")); + EXPECT_TRUE(m3.Matches(absl::string_view("azbz"))); + EXPECT_TRUE(m3.Matches(absl::string_view("az1"))); + EXPECT_FALSE(m3.Matches(absl::string_view("1a"))); + // Default-constructed absl::string_view should not match anything, in order + // to distinguish it from an empty string. + EXPECT_FALSE(m3.Matches(absl::string_view())); + const Matcher m4 = ContainsRegex(""); + EXPECT_FALSE(m4.Matches(absl::string_view())); +#endif // GTEST_HAS_ABSL } TEST(ContainsRegexTest, CanDescribeSelf) { @@ -1541,6 +1761,11 @@ TEST(ContainsRegexTest, CanDescribeSelf) { Matcher m2 = ContainsRegex(new RE("a.*")); EXPECT_EQ("contains regular expression \"a.*\"", Describe(m2)); + +#if GTEST_HAS_ABSL + Matcher m3 = ContainsRegex(new RE("0.*")); + EXPECT_EQ("contains regular expression \"0.*\"", Describe(m3)); +#endif // GTEST_HAS_ABSL } // Tests for wide strings. -- cgit v1.2.3 From aa14cc42858a7aec2605b27e0a221e9a4dac8921 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 14:48:06 -0400 Subject: Fixing build break on MSVC --- googlemock/test/gmock-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index cc161346..f2ce8f24 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -696,7 +696,7 @@ TEST(MatcherCastTest, FromSameType) { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { +explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v1.2.3 From 5b3d27729b118f2c8b5e74039409db0c517651fa Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:07:52 -0400 Subject: Address MSVC warning C4503, decorated name length exceeded, name was truncated --- googlemock/test/gmock-matchers_test.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f2ce8f24..62defe56 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5459,6 +5459,7 @@ TEST_P(BipartiteRandomTest, LargerNets) { } // Test argument is a std::pair representing (nodes, iters). +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, testing::Values( std::make_pair(5, 10000), @@ -5466,6 +5467,7 @@ INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, std::make_pair(7, 2000), std::make_pair(8, 500), std::make_pair(9, 100))); +GTEST_DISABLE_MSC_WARNINGS_POP_() // Tests IsReadableTypeName(). -- cgit v1.2.3 From 6f4e93943a9e24e7bd619e76e68c513b7a992780 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:29:05 -0400 Subject: More on MSVC warning C4503, decorated name length exceeded --- googlemock/test/gmock-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 62defe56..190cedd0 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -5382,6 +5382,7 @@ INSTANTIATE_TEST_CASE_P(AllGraphs, BipartiteTest, ::testing::Range(0, 5)); // Parameterized by a pair interpreted as (LhsSize, RhsSize). +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) class BipartiteNonSquareTest : public ::testing::TestWithParam > { }; @@ -5459,7 +5460,6 @@ TEST_P(BipartiteRandomTest, LargerNets) { } // Test argument is a std::pair representing (nodes, iters). -GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, testing::Values( std::make_pair(5, 10000), -- cgit v1.2.3 From a608d4a36274d4bcbae3ed1216cb22f289348b57 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:44:27 -0400 Subject: More on MSVC warning C4503, decorated name length exceeded --- googlemock/test/gmock-matchers_test.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 190cedd0..41407548 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -59,6 +59,12 @@ # include // NOLINT #endif +// Disable MSVC2015 warning for std::pair: +// "decorated name length exceeded, name was truncated". +#if defined(_MSC_VER) && (_MSC_VER == 1900) +# include +# pragma warning(disable:4503) +#endif + #if GTEST_LANG_CXX11 # include #endif @@ -5382,7 +5388,6 @@ INSTANTIATE_TEST_CASE_P(AllGraphs, BipartiteTest, ::testing::Range(0, 5)); // Parameterized by a pair interpreted as (LhsSize, RhsSize). -GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) class BipartiteNonSquareTest : public ::testing::TestWithParam > { }; @@ -5467,7 +5472,6 @@ INSTANTIATE_TEST_CASE_P(Samples, BipartiteRandomTest, std::make_pair(7, 2000), std::make_pair(8, 500), std::make_pair(9, 100))); -GTEST_DISABLE_MSC_WARNINGS_POP_() // Tests IsReadableTypeName(). -- cgit v1.2.3 From d81b6a0c4cecbe087fae28bd6a3a40d1f5f45df4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 4 Apr 2018 15:46:04 -0400 Subject: bad cut/paste --- googlemock/test/gmock-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 41407548..3cc5d35c 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -61,7 +61,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER == 1900) +# include +#if defined(_MSC_VER) && (_MSC_VER == 1900) # pragma warning(disable:4503) #endif -- cgit v1.2.3 From 0cd6a4f5f585f4a58a24254dc4cc81675edba16c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:34:19 -0400 Subject: Merging matchers test --- googlemock/test/gmock-matchers_test.cc | 819 +++++++++++++++++++++++++++++++-- 1 file changed, 779 insertions(+), 40 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 3cc5d35c..d97889e1 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -157,9 +157,6 @@ using testing::internal::RE; using testing::internal::scoped_ptr; using testing::internal::StreamMatchResultListener; using testing::internal::Strings; -using testing::internal::linked_ptr; -using testing::internal::scoped_ptr; -using testing::internal::string; using testing::make_tuple; using testing::tuple; @@ -698,11 +695,69 @@ TEST(MatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } +// Tests that MatcherCast(m) works when m is a value of the same type as the +// value type of the Matcher. +TEST(MatcherCastTest, FromAValue) { + Matcher m = MatcherCast(42); + EXPECT_TRUE(m.Matches(42)); + EXPECT_FALSE(m.Matches(239)); +} + +// Tests that MatcherCast(m) works when m is a value of the type implicitly +// convertible to the value type of the Matcher. +TEST(MatcherCastTest, FromAnImplicitlyConvertibleValue) { + const int kExpected = 'c'; + Matcher m = MatcherCast('c'); + EXPECT_TRUE(m.Matches(kExpected)); + EXPECT_FALSE(m.Matches(kExpected + 1)); +} + +struct NonImplicitlyConstructibleTypeWithOperatorEq { + friend bool operator==( + const NonImplicitlyConstructibleTypeWithOperatorEq& /* ignored */, + int rhs) { + return 42 == rhs; + } + friend bool operator==( + int lhs, + const NonImplicitlyConstructibleTypeWithOperatorEq& /* ignored */) { + return lhs == 42; + } +}; + +// Tests that MatcherCast(m) works when m is a neither a matcher nor +// implicitly convertible to the value type of the Matcher, but the value type +// of the matcher has operator==() overload accepting m. +TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { + Matcher m1 = + MatcherCast(42); + EXPECT_TRUE(m1.Matches(NonImplicitlyConstructibleTypeWithOperatorEq())); + + Matcher m2 = + MatcherCast(239); + EXPECT_FALSE(m2.Matches(NonImplicitlyConstructibleTypeWithOperatorEq())); + + // When updating the following lines please also change the comment to + // namespace convertible_from_any. + Matcher m3 = + MatcherCast(NonImplicitlyConstructibleTypeWithOperatorEq()); + EXPECT_TRUE(m3.Matches(42)); + EXPECT_FALSE(m3.Matches(239)); +} + +// 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 +// NonImplicitlyConstructibleTypeWithOperatorEq::operator==(int lhs, ...); +// then the corresponding test still compiles (and it should not!) by implicitly +// converting NonImplicitlyConstructibleTypeWithOperatorEq to ConvertibleFromAny +// in m3.Matcher(). +namespace convertible_from_any { // Implicitly convertible from any type. 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; @@ -728,6 +783,7 @@ TEST(MatcherCastTest, FromConvertibleFromAny) { EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_FALSE(m.Matches(ConvertibleFromAny(2))); } +} // namespace convertible_from_any struct IntReferenceWrapper { IntReferenceWrapper(const int& a_value) : value(&a_value) {} @@ -833,6 +889,7 @@ TEST(SafeMatcherCastTest, FromSameType) { EXPECT_FALSE(m2.Matches(1)); } +namespace convertible_from_any { TEST(SafeMatcherCastTest, ConversionConstructorIsUsed) { Matcher m = SafeMatcherCast(1); EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); @@ -845,6 +902,7 @@ TEST(SafeMatcherCastTest, FromConvertibleFromAny) { EXPECT_TRUE(m.Matches(ConvertibleFromAny(1))); EXPECT_FALSE(m.Matches(ConvertibleFromAny(2))); } +} // namespace convertible_from_any TEST(SafeMatcherCastTest, ValueIsNotCopied) { int n = 42; @@ -856,7 +914,7 @@ TEST(SafeMatcherCastTest, ValueIsNotCopied) { TEST(ExpectThat, TakesLiterals) { EXPECT_THAT(1, 1); EXPECT_THAT(1.0, 1.0); - EXPECT_THAT(string(), ""); + EXPECT_THAT(std::string(), ""); } TEST(ExpectThat, TakesFunctions) { @@ -956,15 +1014,11 @@ class Unprintable { public: Unprintable() : c_('a') {} + bool operator==(const Unprintable& /* rhs */) const { return true; } private: char c_; }; -inline bool operator==(const Unprintable& /* lhs */, - const Unprintable& /* rhs */) { - return true; -} - TEST(EqTest, CanDescribeSelf) { Matcher m = Eq(Unprintable()); EXPECT_EQ("is equal to 1-byte object <61>", Describe(m)); @@ -1135,14 +1189,14 @@ TEST(IsNullTest, ReferenceToConstLinkedPtr) { EXPECT_FALSE(m.Matches(non_null_p)); } -#if GTEST_HAS_STD_FUNCTION_ +#if GTEST_LANG_CXX11 TEST(IsNullTest, StdFunction) { const Matcher> m = IsNull(); EXPECT_TRUE(m.Matches(std::function())); EXPECT_FALSE(m.Matches([]{})); } -#endif // GTEST_HAS_STD_FUNCTION_ +#endif // GTEST_LANG_CXX11 // Tests that IsNull() describes itself properly. TEST(IsNullTest, CanDescribeSelf) { @@ -1183,14 +1237,14 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) { EXPECT_TRUE(m.Matches(non_null_p)); } -#if GTEST_HAS_STD_FUNCTION_ +#if GTEST_LANG_CXX11 TEST(NotNullTest, StdFunction) { const Matcher> m = NotNull(); EXPECT_TRUE(m.Matches([]{})); EXPECT_FALSE(m.Matches(std::function())); } -#endif // GTEST_HAS_STD_FUNCTION_ +#endif // GTEST_LANG_CXX11 // Tests that NotNull() describes itself properly. TEST(NotNullTest, CanDescribeSelf) { @@ -2249,6 +2303,150 @@ TEST(Ne2Test, CanDescribeSelf) { EXPECT_EQ("are an unequal pair", Describe(m)); } +// Tests that FloatEq() matches a 2-tuple where +// FloatEq(first field) matches the second field. +TEST(FloatEq2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = FloatEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(0.3f, 0.1f + 0.1f + 0.1f))); + EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f))); +} + +// Tests that FloatEq() describes itself properly. +TEST(FloatEq2Test, CanDescribeSelf) { + Matcher&> m = FloatEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveFloatEq() matches a 2-tuple where +// NanSensitiveFloatEq(first field) matches the second field. +TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveFloatEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that NanSensitiveFloatEq() describes itself properly. +TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) { + Matcher&> m = NanSensitiveFloatEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that DoubleEq() matches a 2-tuple where +// DoubleEq(first field) matches the second field. +TEST(DoubleEq2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = DoubleEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0))); + EXPECT_TRUE(m.Matches(Tpl(0.3, 0.1 + 0.1 + 0.1))); + EXPECT_FALSE(m.Matches(Tpl(1.1, 1.0))); +} + +// Tests that DoubleEq() describes itself properly. +TEST(DoubleEq2Test, CanDescribeSelf) { + Matcher&> m = DoubleEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveDoubleEq() matches a 2-tuple where +// NanSensitiveDoubleEq(first field) matches the second field. +TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveDoubleEq(); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that DoubleEq() describes itself properly. +TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) { + Matcher&> m = NanSensitiveDoubleEq(); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that FloatEq() matches a 2-tuple where +// FloatNear(first field, max_abs_error) matches the second field. +TEST(FloatNear2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = FloatNear(0.5f); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(1.3f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.8f, 1.0f))); +} + +// Tests that FloatNear() describes itself properly. +TEST(FloatNear2Test, CanDescribeSelf) { + Matcher&> m = FloatNear(0.5f); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveFloatNear() matches a 2-tuple where +// NanSensitiveFloatNear(first field) matches the second field. +TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveFloatNear(0.5f); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.6f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that NanSensitiveFloatNear() describes itself properly. +TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) { + Matcher&> m = + NanSensitiveFloatNear(0.5f); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that FloatEq() matches a 2-tuple where +// DoubleNear(first field, max_abs_error) matches the second field. +TEST(DoubleNear2Test, MatchesEqualArguments) { + typedef ::testing::tuple Tpl; + Matcher m = DoubleNear(0.5); + EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0))); + EXPECT_TRUE(m.Matches(Tpl(1.3, 1.0))); + EXPECT_FALSE(m.Matches(Tpl(1.8, 1.0))); +} + +// Tests that DoubleNear() describes itself properly. +TEST(DoubleNear2Test, CanDescribeSelf) { + Matcher&> m = DoubleNear(0.5); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + +// Tests that NanSensitiveDoubleNear() matches a 2-tuple where +// NanSensitiveDoubleNear(first field) matches the second field. +TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) { + typedef ::testing::tuple Tpl; + Matcher m = NanSensitiveDoubleNear(0.5f); + EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f))); + EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(1.6f, 1.0f))); + EXPECT_FALSE(m.Matches(Tpl(1.0f, std::numeric_limits::quiet_NaN()))); + EXPECT_FALSE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), 1.0f))); +} + +// Tests that NanSensitiveDoubleNear() describes itself properly. +TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) { + Matcher&> m = + NanSensitiveDoubleNear(0.5f); + EXPECT_EQ("are an almost-equal pair", Describe(m)); +} + // Tests that Not(m) matches any value that doesn't match m. TEST(NotTest, NegatesMatcher) { Matcher m; @@ -2814,6 +3012,22 @@ TEST(ExplainMatchResultTest, WorksInsideMATCHER) { EXPECT_THAT(0, Really(Eq(0))); } +TEST(DescribeMatcherTest, WorksWithValue) { + EXPECT_EQ("is equal to 42", DescribeMatcher(42)); + EXPECT_EQ("isn't equal to 42", DescribeMatcher(42, true)); +} + +TEST(DescribeMatcherTest, WorksWithMonomorphicMatcher) { + const Matcher monomorphic = Le(0); + EXPECT_EQ("is <= 0", DescribeMatcher(monomorphic)); + EXPECT_EQ("isn't <= 0", DescribeMatcher(monomorphic, true)); +} + +TEST(DescribeMatcherTest, WorksWithPolymorphicMatcher) { + EXPECT_EQ("is even", DescribeMatcher(PolymorphicIsEven())); + EXPECT_EQ("is odd", DescribeMatcher(PolymorphicIsEven(), true)); +} + TEST(AllArgsTest, WorksForTuple) { EXPECT_THAT(make_tuple(1, 2L), AllArgs(Lt())); EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt()))); @@ -2943,18 +3157,22 @@ class FloatingPointTest : public testing::Test { zero_bits_(Floating(0).bits()), one_bits_(Floating(1).bits()), infinity_bits_(Floating(Floating::Infinity()).bits()), - close_to_positive_zero_(AsBits(zero_bits_ + max_ulps_/2)), - close_to_negative_zero_(AsBits(zero_bits_ + max_ulps_ - max_ulps_/2)), - further_from_negative_zero_(-AsBits( + close_to_positive_zero_( + Floating::ReinterpretBits(zero_bits_ + max_ulps_/2)), + close_to_negative_zero_( + -Floating::ReinterpretBits(zero_bits_ + max_ulps_ - max_ulps_/2)), + further_from_negative_zero_(-Floating::ReinterpretBits( zero_bits_ + max_ulps_ + 1 - max_ulps_/2)), - close_to_one_(AsBits(one_bits_ + max_ulps_)), - further_from_one_(AsBits(one_bits_ + max_ulps_ + 1)), + close_to_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_)), + further_from_one_(Floating::ReinterpretBits(one_bits_ + max_ulps_ + 1)), infinity_(Floating::Infinity()), - close_to_infinity_(AsBits(infinity_bits_ - max_ulps_)), - further_from_infinity_(AsBits(infinity_bits_ - max_ulps_ - 1)), + close_to_infinity_( + Floating::ReinterpretBits(infinity_bits_ - max_ulps_)), + further_from_infinity_( + Floating::ReinterpretBits(infinity_bits_ - max_ulps_ - 1)), max_(Floating::Max()), - nan1_(AsBits(Floating::kExponentBitMask | 1)), - nan2_(AsBits(Floating::kExponentBitMask | 200)) { + nan1_(Floating::ReinterpretBits(Floating::kExponentBitMask | 1)), + nan2_(Floating::ReinterpretBits(Floating::kExponentBitMask | 200)) { } void TestSize() { @@ -3009,7 +3227,7 @@ class FloatingPointTest : public testing::Test { // Pre-calculated numbers to be used by the tests. - const size_t max_ulps_; + const Bits max_ulps_; const Bits zero_bits_; // The bits that represent 0.0. const Bits one_bits_; // The bits that represent 1.0. @@ -3035,12 +3253,6 @@ class FloatingPointTest : public testing::Test { // Some NaNs. const RawType nan1_; const RawType nan2_; - - private: - template - static RawType AsBits(T value) { - return Floating::ReinterpretBits(static_cast(value)); - } }; // Tests floating-point matchers with fixed epsilons. @@ -3417,8 +3629,6 @@ MATCHER_P(FieldIIs, inner_matcher, "") { return ExplainMatchResult(inner_matcher, arg.i, result_listener); } -#if GTEST_HAS_RTTI - TEST(WhenDynamicCastToTest, SameType) { Derived derived; derived.i = 4; @@ -3476,8 +3686,12 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) { TEST(WhenDynamicCastToTest, Describe) { Matcher matcher = WhenDynamicCastTo(Pointee(_)); - const string prefix = +#if GTEST_HAS_RTTI + const std::string prefix = "when dynamic_cast to " + internal::GetTypeName() + ", "; +#else // GTEST_HAS_RTTI + const std::string prefix = "when dynamic_cast, "; +#endif // GTEST_HAS_RTTI EXPECT_EQ(prefix + "points to a value that is anything", Describe(matcher)); EXPECT_EQ(prefix + "does not point to a value that is anything", DescribeNegation(matcher)); @@ -3511,8 +3725,6 @@ TEST(WhenDynamicCastToTest, BadReference) { EXPECT_THAT(as_base_ref, Not(WhenDynamicCastTo(_))); } -#endif // GTEST_HAS_RTTI - // Minimal const-propagating pointer. template class ConstPropagatingPtr { @@ -3632,11 +3844,14 @@ struct DerivedStruct : public AStruct { // Tests that Field(&Foo::field, ...) works when field is non-const. TEST(FieldTest, WorksForNonConstField) { Matcher m = Field(&AStruct::x, Ge(0)); + Matcher m_with_name = Field("x", &AStruct::x, Ge(0)); AStruct a; EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.x = -1; EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Field(&Foo::field, ...) works when field is const. @@ -3644,9 +3859,13 @@ TEST(FieldTest, WorksForConstField) { AStruct a; Matcher m = Field(&AStruct::y, Ge(0.0)); + Matcher m_with_name = Field("y", &AStruct::y, Ge(0.0)); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); m = Field(&AStruct::y, Le(0.0)); + m_with_name = Field("y", &AStruct::y, Le(0.0)); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Field(&Foo::field, ...) works when field is not copyable. @@ -3720,6 +3939,14 @@ TEST(FieldTest, CanDescribeSelf) { EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); } +TEST(FieldTest, CanDescribeSelfWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + EXPECT_EQ("is an object whose field `field_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose field `field_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Field() can explain the match result. TEST(FieldTest, CanExplainMatchResult) { Matcher m = Field(&AStruct::x, Ge(0)); @@ -3734,6 +3961,19 @@ TEST(FieldTest, CanExplainMatchResult) { Explain(m, a)); } +TEST(FieldTest, CanExplainMatchResultWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + AStruct a; + a.x = 1; + EXPECT_EQ("whose field `field_name` is 1" + OfType("int"), Explain(m, a)); + + m = Field("field_name", &AStruct::x, GreaterThan(0)); + EXPECT_EQ("whose field `field_name` is 1" + OfType("int") + + ", which is 1 more than 0", + Explain(m, a)); +} + // Tests that Field() works when the argument is a pointer to const. TEST(FieldForPointerTest, WorksForPointerToConst) { Matcher m = Field(&AStruct::x, Ge(0)); @@ -3791,6 +4031,14 @@ TEST(FieldForPointerTest, CanDescribeSelf) { EXPECT_EQ("is an object whose given field isn't >= 0", DescribeNegation(m)); } +TEST(FieldForPointerTest, CanDescribeSelfWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + EXPECT_EQ("is an object whose field `field_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose field `field_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Field() can explain the result of matching a pointer. TEST(FieldForPointerTest, CanExplainMatchResult) { Matcher m = Field(&AStruct::x, Ge(0)); @@ -3806,6 +4054,22 @@ TEST(FieldForPointerTest, CanExplainMatchResult) { ", which is 1 more than 0", Explain(m, &a)); } +TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) { + Matcher m = Field("field_name", &AStruct::x, Ge(0)); + + AStruct a; + a.x = 1; + EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ( + "which points to an object whose field `field_name` is 1" + OfType("int"), + Explain(m, &a)); + + m = Field("field_name", &AStruct::x, GreaterThan(0)); + EXPECT_EQ("which points to an object whose field `field_name` is 1" + + OfType("int") + ", which is 1 more than 0", + Explain(m, &a)); +} + // A user-defined class for testing Property(). class AClass { public: @@ -3849,26 +4113,33 @@ class DerivedClass : public AClass { // returns a non-reference. TEST(PropertyTest, WorksForNonReferenceProperty) { Matcher m = Property(&AClass::n, Ge(0)); + Matcher m_with_name = Property("n", &AClass::n, Ge(0)); AClass a; a.set_n(1); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_n(-1); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Property(&Foo::property, ...) works when property() // returns a reference to const. TEST(PropertyTest, WorksForReferenceToConstProperty) { Matcher m = Property(&AClass::s, StartsWith("hi")); + Matcher m_with_name = + Property("s", &AClass::s, StartsWith("hi")); AClass a; a.set_s("hill"); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_s("hole"); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } #if GTEST_LANG_CXX11 @@ -3934,10 +4205,15 @@ TEST(PropertyTest, WorksForCompatibleMatcherType) { Matcher m = Property(&AClass::n, Matcher(Ge(0))); + Matcher m_with_name = + Property("n", &AClass::n, Matcher(Ge(0))); + AClass a; EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_n(-1); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } // Tests that Property() can describe itself. @@ -3949,6 +4225,14 @@ TEST(PropertyTest, CanDescribeSelf) { DescribeNegation(m)); } +TEST(PropertyTest, CanDescribeSelfWithPropertyName) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + EXPECT_EQ("is an object whose property `fancy_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose property `fancy_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Property() can explain the match result. TEST(PropertyTest, CanExplainMatchResult) { Matcher m = Property(&AClass::n, Ge(0)); @@ -3963,6 +4247,19 @@ TEST(PropertyTest, CanExplainMatchResult) { Explain(m, a)); } +TEST(PropertyTest, CanExplainMatchResultWithPropertyName) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + AClass a; + a.set_n(1); + EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int"), Explain(m, a)); + + m = Property("fancy_name", &AClass::n, GreaterThan(0)); + EXPECT_EQ("whose property `fancy_name` is 1" + OfType("int") + + ", which is 1 more than 0", + Explain(m, a)); +} + // Tests that Property() works when the argument is a pointer to const. TEST(PropertyForPointerTest, WorksForPointerToConst) { Matcher m = Property(&AClass::n, Ge(0)); @@ -4030,6 +4327,14 @@ TEST(PropertyForPointerTest, CanDescribeSelf) { DescribeNegation(m)); } +TEST(PropertyForPointerTest, CanDescribeSelfWithPropertyDescription) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + EXPECT_EQ("is an object whose property `fancy_name` is >= 0", Describe(m)); + EXPECT_EQ("is an object whose property `fancy_name` isn't >= 0", + DescribeNegation(m)); +} + // Tests that Property() can explain the result of matching a pointer. TEST(PropertyForPointerTest, CanExplainMatchResult) { Matcher m = Property(&AClass::n, Ge(0)); @@ -4047,6 +4352,22 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) { Explain(m, &a)); } +TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) { + Matcher m = Property("fancy_name", &AClass::n, Ge(0)); + + AClass a; + a.set_n(1); + EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + + OfType("int"), + Explain(m, &a)); + + m = Property("fancy_name", &AClass::n, GreaterThan(0)); + EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + + OfType("int") + ", which is 1 more than 0", + Explain(m, &a)); +} + // Tests ResultOf. // Tests that ResultOf(f, ...) compiles and works as expected when f is a @@ -4162,11 +4483,8 @@ TEST(ResultOfTest, WorksForFunctionReferences) { // Tests that ResultOf(f, ...) compiles and works as expected when f is a // function object. -struct Functor { - typedef std::string result_type; - typedef int argument_type; - - std::string operator()(int input) const { +struct Functor : public ::std::unary_function { + result_type operator()(argument_type input) const { return IntToStringFunction(input); } }; @@ -4360,6 +4678,44 @@ TEST(IsEmptyTest, ExplainsResult) { EXPECT_EQ("whose size is 1", Explain(m, container)); } +TEST(IsTrueTest, IsTrueIsFalse) { + EXPECT_THAT(true, IsTrue()); + EXPECT_THAT(false, IsFalse()); + EXPECT_THAT(true, Not(IsFalse())); + EXPECT_THAT(false, Not(IsTrue())); + EXPECT_THAT(0, Not(IsTrue())); + EXPECT_THAT(0, IsFalse()); + EXPECT_THAT(NULL, Not(IsTrue())); + EXPECT_THAT(NULL, IsFalse()); + EXPECT_THAT(-1, IsTrue()); + EXPECT_THAT(-1, Not(IsFalse())); + EXPECT_THAT(1, IsTrue()); + EXPECT_THAT(1, Not(IsFalse())); + EXPECT_THAT(2, IsTrue()); + EXPECT_THAT(2, Not(IsFalse())); + int a = 42; + EXPECT_THAT(a, IsTrue()); + EXPECT_THAT(a, Not(IsFalse())); + EXPECT_THAT(&a, IsTrue()); + EXPECT_THAT(&a, Not(IsFalse())); + EXPECT_THAT(false, Not(IsTrue())); + EXPECT_THAT(true, Not(IsFalse())); +#if GTEST_LANG_CXX11 + EXPECT_THAT(std::true_type(), IsTrue()); + EXPECT_THAT(std::true_type(), Not(IsFalse())); + EXPECT_THAT(std::false_type(), IsFalse()); + EXPECT_THAT(std::false_type(), Not(IsTrue())); + EXPECT_THAT(nullptr, Not(IsTrue())); + EXPECT_THAT(nullptr, IsFalse()); + std::unique_ptr null_unique; + std::unique_ptr nonnull_unique(new int(0)); + EXPECT_THAT(null_unique, Not(IsTrue())); + EXPECT_THAT(null_unique, IsFalse()); + EXPECT_THAT(nonnull_unique, IsTrue()); + EXPECT_THAT(nonnull_unique, Not(IsFalse())); +#endif // GTEST_LANG_CXX11 +} + TEST(SizeIsTest, ImplementsSizeIs) { vector container; EXPECT_THAT(container, SizeIs(0)); @@ -4914,6 +5270,250 @@ TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) { EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); } +TEST(IsSupersetOfTest, WorksForNativeArray) { + const int subset[] = {1, 4}; + const int superset[] = {1, 2, 4}; + const int disjoint[] = {1, 0, 3}; + EXPECT_THAT(subset, IsSupersetOf(subset)); + EXPECT_THAT(subset, Not(IsSupersetOf(superset))); + EXPECT_THAT(superset, IsSupersetOf(subset)); + EXPECT_THAT(subset, Not(IsSupersetOf(disjoint))); + EXPECT_THAT(disjoint, Not(IsSupersetOf(subset))); +} + +TEST(IsSupersetOfTest, WorksWithDuplicates) { + const int not_enough[] = {1, 2}; + const int enough[] = {1, 1, 2}; + const int expected[] = {1, 1}; + EXPECT_THAT(not_enough, Not(IsSupersetOf(expected))); + EXPECT_THAT(enough, IsSupersetOf(expected)); +} + +TEST(IsSupersetOfTest, WorksForEmpty) { + vector numbers; + vector expected; + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(1); + EXPECT_THAT(numbers, Not(IsSupersetOf(expected))); + expected.clear(); + numbers.push_back(1); + numbers.push_back(2); + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(1); + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(2); + EXPECT_THAT(numbers, IsSupersetOf(expected)); + expected.push_back(3); + EXPECT_THAT(numbers, Not(IsSupersetOf(expected))); +} + +TEST(IsSupersetOfTest, WorksForStreamlike) { + const int a[5] = {1, 2, 3, 4, 5}; + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); + + vector expected; + expected.push_back(1); + expected.push_back(2); + expected.push_back(5); + EXPECT_THAT(s, IsSupersetOf(expected)); + + expected.push_back(0); + EXPECT_THAT(s, Not(IsSupersetOf(expected))); +} + +TEST(IsSupersetOfTest, TakesStlContainer) { + const int actual[] = {3, 1, 2}; + + ::std::list expected; + expected.push_back(1); + expected.push_back(3); + EXPECT_THAT(actual, IsSupersetOf(expected)); + + expected.push_back(4); + EXPECT_THAT(actual, Not(IsSupersetOf(expected))); +} + +TEST(IsSupersetOfTest, Describe) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + EXPECT_THAT( + Describe(IsSupersetOf(expected)), + Eq("a surjection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSupersetOfTest, DescribeNegation) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + EXPECT_THAT( + DescribeNegation(IsSupersetOf(expected)), + Eq("no surjection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSupersetOfTest, MatchAndExplain) { + std::vector v; + v.push_back(2); + v.push_back(3); + std::vector expected; + expected.push_back(1); + expected.push_back(2); + StringMatchResultListener listener; + ASSERT_FALSE(ExplainMatchResult(IsSupersetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), + Eq("where the following matchers don't match any elements:\n" + "matcher #0: is equal to 1")); + + v.push_back(1); + listener.Clear(); + ASSERT_TRUE(ExplainMatchResult(IsSupersetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), Eq("where:\n" + " - element #0 is matched by matcher #1,\n" + " - element #2 is matched by matcher #0")); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +TEST(IsSupersetOfTest, WorksForRhsInitializerList) { + const int numbers[] = {1, 3, 6, 2, 4, 5}; + EXPECT_THAT(numbers, IsSupersetOf({1, 2})); + EXPECT_THAT(numbers, Not(IsSupersetOf({3, 0}))); +} +#endif + +TEST(IsSubsetOfTest, WorksForNativeArray) { + const int subset[] = {1, 4}; + const int superset[] = {1, 2, 4}; + const int disjoint[] = {1, 0, 3}; + EXPECT_THAT(subset, IsSubsetOf(subset)); + EXPECT_THAT(subset, IsSubsetOf(superset)); + EXPECT_THAT(superset, Not(IsSubsetOf(subset))); + EXPECT_THAT(subset, Not(IsSubsetOf(disjoint))); + EXPECT_THAT(disjoint, Not(IsSubsetOf(subset))); +} + +TEST(IsSubsetOfTest, WorksWithDuplicates) { + const int not_enough[] = {1, 2}; + const int enough[] = {1, 1, 2}; + const int actual[] = {1, 1}; + EXPECT_THAT(actual, Not(IsSubsetOf(not_enough))); + EXPECT_THAT(actual, IsSubsetOf(enough)); +} + +TEST(IsSubsetOfTest, WorksForEmpty) { + vector numbers; + vector expected; + EXPECT_THAT(numbers, IsSubsetOf(expected)); + expected.push_back(1); + EXPECT_THAT(numbers, IsSubsetOf(expected)); + expected.clear(); + numbers.push_back(1); + numbers.push_back(2); + EXPECT_THAT(numbers, Not(IsSubsetOf(expected))); + expected.push_back(1); + EXPECT_THAT(numbers, Not(IsSubsetOf(expected))); + expected.push_back(2); + EXPECT_THAT(numbers, IsSubsetOf(expected)); + expected.push_back(3); + EXPECT_THAT(numbers, IsSubsetOf(expected)); +} + +TEST(IsSubsetOfTest, WorksForStreamlike) { + const int a[5] = {1, 2}; + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); + + vector expected; + expected.push_back(1); + EXPECT_THAT(s, Not(IsSubsetOf(expected))); + expected.push_back(2); + expected.push_back(5); + EXPECT_THAT(s, IsSubsetOf(expected)); +} + +TEST(IsSubsetOfTest, TakesStlContainer) { + const int actual[] = {3, 1, 2}; + + ::std::list expected; + expected.push_back(1); + expected.push_back(3); + EXPECT_THAT(actual, Not(IsSubsetOf(expected))); + + expected.push_back(2); + expected.push_back(4); + EXPECT_THAT(actual, IsSubsetOf(expected)); +} + +TEST(IsSubsetOfTest, Describe) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + + EXPECT_THAT( + Describe(IsSubsetOf(expected)), + Eq("an injection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSubsetOfTest, DescribeNegation) { + typedef std::vector IntVec; + IntVec expected; + expected.push_back(111); + expected.push_back(222); + expected.push_back(333); + EXPECT_THAT( + DescribeNegation(IsSubsetOf(expected)), + Eq("no injection from elements to requirements exists such that:\n" + " - an element is equal to 111\n" + " - an element is equal to 222\n" + " - an element is equal to 333")); +} + +TEST(IsSubsetOfTest, MatchAndExplain) { + std::vector v; + v.push_back(2); + v.push_back(3); + std::vector expected; + expected.push_back(1); + expected.push_back(2); + StringMatchResultListener listener; + ASSERT_FALSE(ExplainMatchResult(IsSubsetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), + Eq("where the following elements don't match any matchers:\n" + "element #1: 3")); + + expected.push_back(3); + listener.Clear(); + ASSERT_TRUE(ExplainMatchResult(IsSubsetOf(expected), v, &listener)) + << listener.str(); + EXPECT_THAT(listener.str(), Eq("where:\n" + " - element #0 is matched by matcher #1,\n" + " - element #1 is matched by matcher #2")); +} + +#if GTEST_HAS_STD_INITIALIZER_LIST_ +TEST(IsSubsetOfTest, WorksForRhsInitializerList) { + const int numbers[] = {1, 2, 3}; + EXPECT_THAT(numbers, IsSubsetOf({1, 2, 3, 4})); + EXPECT_THAT(numbers, Not(IsSubsetOf({1, 2}))); +} +#endif + // Tests using ElementsAre() and ElementsAreArray() with stream-like // "containers". @@ -5721,6 +6321,16 @@ TEST(PointwiseTest, WorksForRhsNativeArray) { EXPECT_THAT(lhs, Not(Pointwise(Lt(), rhs))); } +// Test is effective only with sanitizers. +TEST(PointwiseTest, WorksForVectorOfBool) { + vector rhs(3, false); + rhs[1] = true; + vector lhs = rhs; + EXPECT_THAT(lhs, Pointwise(Eq(), rhs)); + rhs[0] = true; + EXPECT_THAT(lhs, Not(Pointwise(Eq(), rhs))); +} + #if GTEST_HAS_STD_INITIALIZER_LIST_ TEST(PointwiseTest, WorksForRhsInitializerList) { @@ -5886,6 +6496,51 @@ TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) { EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs)); } +// Sample optional type implementation with minimal requirements for use with +// Optional matcher. +class SampleOptionalInt { + public: + typedef int value_type; + explicit SampleOptionalInt(int value) : value_(value), has_value_(true) {} + SampleOptionalInt() : value_(0), has_value_(false) {} + operator bool() const { + return has_value_; + } + const int& operator*() const { + return value_; + } + private: + int value_; + bool has_value_; +}; + +TEST(OptionalTest, DescribesSelf) { + const Matcher m = Optional(Eq(1)); + EXPECT_EQ("value is equal to 1", Describe(m)); +} + +TEST(OptionalTest, ExplainsSelf) { + const Matcher m = Optional(Eq(1)); + EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptionalInt(1))); + EXPECT_EQ("whose value 2 doesn't match", Explain(m, SampleOptionalInt(2))); +} + +TEST(OptionalTest, MatchesNonEmptyOptional) { + const Matcher m1 = Optional(1); + const Matcher m2 = Optional(Eq(2)); + const Matcher m3 = Optional(Lt(3)); + SampleOptionalInt opt(1); + EXPECT_TRUE(m1.Matches(opt)); + EXPECT_FALSE(m2.Matches(opt)); + EXPECT_TRUE(m3.Matches(opt)); +} + +TEST(OptionalTest, DoesNotMatchNullopt) { + const Matcher m = Optional(1); + SampleOptionalInt empty; + EXPECT_FALSE(m.Matches(empty)); +} + class SampleVariantIntString { public: SampleVariantIntString(int i) : i_(i), has_int_(true) {} @@ -5950,5 +6605,89 @@ TEST(VariantTest, InnerDoesNotMatch) { EXPECT_FALSE(m.Matches(SampleVariantIntString("2"))); } +class SampleAnyType { + public: + explicit SampleAnyType(int i) : index_(0), i_(i) {} + explicit SampleAnyType(const std::string& s) : index_(1), s_(s) {} + + template + friend const T* any_cast(const SampleAnyType* any) { + return any->get_impl(static_cast(NULL)); + } + + private: + int index_; + int i_; + std::string s_; + + const int* get_impl(int*) const { return index_ == 0 ? &i_ : NULL; } + const std::string* get_impl(std::string*) const { + return index_ == 1 ? &s_ : NULL; + } +}; + +TEST(AnyWithTest, FullMatch) { + Matcher m = AnyWith(Eq(1)); + EXPECT_TRUE(m.Matches(SampleAnyType(1))); +} + +TEST(AnyWithTest, TestBadCastType) { + Matcher m = AnyWith(Eq("fail")); + EXPECT_FALSE(m.Matches(SampleAnyType(1))); +} + +#if GTEST_LANG_CXX11 +TEST(AnyWithTest, TestUseInContainers) { + std::vector a; + a.emplace_back(1); + a.emplace_back(2); + a.emplace_back(3); + EXPECT_THAT( + a, ElementsAreArray({AnyWith(1), AnyWith(2), AnyWith(3)})); + + std::vector b; + b.emplace_back("hello"); + b.emplace_back("merhaba"); + b.emplace_back("salut"); + EXPECT_THAT(b, ElementsAreArray({AnyWith("hello"), + AnyWith("merhaba"), + AnyWith("salut")})); +} +#endif // GTEST_LANG_CXX11 +TEST(AnyWithTest, TestCompare) { + EXPECT_THAT(SampleAnyType(1), AnyWith(Gt(0))); +} + +TEST(AnyWithTest, DescribesSelf) { + const Matcher m = AnyWith(Eq(1)); + EXPECT_THAT(Describe(m), ContainsRegex("is an 'any' type with value of type " + "'.*' and the value is equal to 1")); +} + +TEST(AnyWithTest, ExplainsSelf) { + const Matcher m = AnyWith(Eq(1)); + + EXPECT_THAT(Explain(m, SampleAnyType(1)), ContainsRegex("whose value 1")); + EXPECT_THAT(Explain(m, SampleAnyType("A")), + HasSubstr("whose value is not of type '")); + EXPECT_THAT(Explain(m, SampleAnyType(2)), "whose value 2 doesn't match"); +} + +#if GTEST_LANG_CXX11 + +TEST(PointeeTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, Pointee(Eq(3))); + EXPECT_THAT(p, Not(Pointee(Eq(2)))); +} + +TEST(NotTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, Pointee(Eq(3))); + EXPECT_THAT(p, Not(Pointee(Eq(2)))); +} + +#endif // GTEST_LANG_CXX11 + } // namespace gmock_matchers_test } // namespace testing -- cgit v1.2.3 From af93d59eb7b3b2b4d678d999a6f302f0cd28d841 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:35:20 -0400 Subject: Merging matchers test --- googlemock/test/gmock-matchers_test.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index d97889e1..f0e42f59 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -157,6 +157,9 @@ using testing::internal::RE; using testing::internal::scoped_ptr; using testing::internal::StreamMatchResultListener; using testing::internal::Strings; +using testing::internal::linked_ptr; +using testing::internal::scoped_ptr; +using testing::internal::string; using testing::make_tuple; using testing::tuple; -- cgit v1.2.3 From 66eaf9f0eb894851f22544297f26aab39fe110d1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:55:25 -0400 Subject: Have to wait for this one --- googlemock/test/gmock-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f0e42f59..daac0327 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -758,7 +758,7 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { - ConvertibleFromAny(int a_value) : value(a_value) {} + explicit ConvertibleFromAny(int a_value) : value(a_value) {} template ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; -- cgit v1.2.3 From 7045138a0d4fdc4c3d0bb582c3def9b3cbea9a26 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 11:59:59 -0400 Subject: Have to wait for this one --- googlemock/test/gmock-matchers_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index daac0327..33be41a9 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -758,9 +758,9 @@ TEST(MatcherCastTest, NonImplicitlyConstructibleTypeWithOperatorEq) { namespace convertible_from_any { // Implicitly convertible from any type. struct ConvertibleFromAny { - explicit ConvertibleFromAny(int a_value) : value(a_value) {} + ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v1.2.3 From fe402c27790ff1cc9a7e17c5d0aea4ebe7fd8a71 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 5 Apr 2018 16:09:17 -0400 Subject: Merging gMock, 2 --- googlemock/test/gmock-actions_test.cc | 1 + googlemock/test/gmock-spec-builders_test.cc | 2 -- googlemock/test/gmock_output_test_.cc | 5 +++++ googlemock/test/gmock_output_test_golden.txt | 9 ++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 01286634..46011570 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -704,6 +704,7 @@ class MockClass { MOCK_METHOD0(MakeUnique, std::unique_ptr()); MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); + MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); #endif private: diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index a7bf03e5..6001582a 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -748,7 +748,6 @@ TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) { testing::GMOCK_FLAG(default_mock_behavior) = original_behavior; } - #endif // GTEST_HAS_STREAM_REDIRECTION // Tests the semantics of ON_CALL(). @@ -2691,7 +2690,6 @@ int gmock_main(int argc, char **argv) { int main(int argc, char **argv) { #endif // GMOCK_RENAME_MAIN testing::InitGoogleMock(&argc, argv); - // Ensures that the tests pass no matter what value of // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies. testing::GMOCK_FLAG(catch_leaked_mocks) = true; diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index d80e2b08..ca628df6 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -273,6 +273,11 @@ MATCHER_P2(IsPair, first, second, "") { return Value(arg.first, first) && Value(arg.second, second); } +TEST_F(GMockOutputTest, PrintsMatcher) { + const testing::Matcher m1 = Ge(48); + EXPECT_THAT((std::pair(42, true)), IsPair(m1, true)); +} + void TestCatchesLeakedMocksInAdHocTests() { MockFoo* foo = new MockFoo; diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index 689d5eeb..dbcb2118 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -288,6 +288,12 @@ Stack trace: [ OK ] GMockOutputTest.ExplicitActionsRunOutWithDefaultAction [ RUN ] GMockOutputTest.CatchesLeakedMocks [ OK ] GMockOutputTest.CatchesLeakedMocks +[ RUN ] GMockOutputTest.PrintsMatcher +FILE:#: Failure +Value of: (std::pair(42, true)) +Expected: is pair (is >= 48, true) + Actual: (42, true) (of type std::pair) +[ FAILED ] GMockOutputTest.PrintsMatcher [ FAILED ] GMockOutputTest.UnexpectedCall [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction [ FAILED ] GMockOutputTest.ExcessiveCall @@ -302,9 +308,10 @@ Stack trace: [ FAILED ] GMockOutputTest.MismatchArgumentsAndWith [ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction [ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction +[ FAILED ] GMockOutputTest.PrintsMatcher FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. -ERROR: 3 leaked mock objects found at program exit. +ERROR: 3 leaked mock objects found at program exit. Expectations on a mock object is verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock. -- cgit v1.2.3 From 88fc7d7552ead9d9c224b06bf0d2c1f17e21d612 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 09:50:01 -0400 Subject: merging gmock-actions 2 --- googlemock/test/gmock-actions_test.cc | 144 +++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 46011570..ea6129d7 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -65,6 +65,7 @@ using testing::ReturnRef; using testing::ReturnRefOfCopy; using testing::SetArgPointee; using testing::SetArgumentPointee; +using testing::Unused; using testing::_; using testing::get; using testing::internal::BuiltInDefaultValue; @@ -705,6 +706,8 @@ class MockClass { MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); + MOCK_METHOD2(TakeUnique, + int(const std::unique_ptr&, std::unique_ptr)); #endif private: @@ -756,7 +759,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overridden by an ON_CALL(). +// DefaultValue::Set() when it's not overriden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; @@ -1411,6 +1414,145 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { EXPECT_EQ(7, *vresult[0]); } +TEST(MockMethodTest, CanTakeMoveOnlyValue) { + MockClass mock; + auto make = [](int i) { return std::unique_ptr(new int(i)); }; + + EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { + return *i; + }); + // DoAll() does not compile, since it would move from its arguments twice. + // EXPECT_CALL(mock, TakeUnique(_, _)) + // .WillRepeatedly(DoAll(Invoke([](std::unique_ptr j) {}), + // Return(1))); + EXPECT_CALL(mock, TakeUnique(testing::Pointee(7))) + .WillOnce(Return(-7)) + .RetiresOnSaturation(); + EXPECT_CALL(mock, TakeUnique(testing::IsNull())) + .WillOnce(Return(-1)) + .RetiresOnSaturation(); + + EXPECT_EQ(5, mock.TakeUnique(make(5))); + EXPECT_EQ(-7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(-1, mock.TakeUnique({})); + + // Some arguments are moved, some passed by reference. + auto lvalue = make(6); + EXPECT_CALL(mock, TakeUnique(_, _)) + .WillOnce([](const std::unique_ptr& i, std::unique_ptr j) { + return *i * *j; + }); + EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7))); + + // The unique_ptr can be saved by the action. + std::unique_ptr saved; + EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr i) { + saved = std::move(i); + return 0; + }); + EXPECT_EQ(0, mock.TakeUnique(make(42))); + EXPECT_EQ(42, *saved); +} + #endif // GTEST_HAS_STD_UNIQUE_PTR_ +#if GTEST_LANG_CXX11 +// Tests for std::function based action. + +int Add(int val, int& ref, int* ptr) { // NOLINT + int result = val + ref + *ptr; + ref = 42; + *ptr = 43; + return result; +} + +int Deref(std::unique_ptr ptr) { return *ptr; } + +struct Double { + template + T operator()(T t) { return 2 * t; } +}; + +std::unique_ptr UniqueInt(int i) { + return std::unique_ptr(new int(i)); +} + +TEST(FunctorActionTest, ActionFromFunction) { + Action a = &Add; + int x = 1, y = 2, z = 3; + EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z))); + EXPECT_EQ(42, y); + EXPECT_EQ(43, z); + + Action)> a1 = &Deref; + EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7)))); +} + +TEST(FunctorActionTest, ActionFromLambda) { + Action a1 = [](bool b, int i) { return b ? i : 0; }; + EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); + + std::unique_ptr saved; + Action)> a2 = [&saved](std::unique_ptr p) { + saved = std::move(p); + }; + a2.Perform(make_tuple(UniqueInt(5))); + EXPECT_EQ(5, *saved); +} + +TEST(FunctorActionTest, PolymorphicFunctor) { + Action ai = Double(); + EXPECT_EQ(2, ai.Perform(make_tuple(1))); + Action ad = Double(); // Double? Double double! + EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); +} + +TEST(FunctorActionTest, TypeConversion) { + // Numeric promotions are allowed. + const Action a1 = [](int i) { return i > 1; }; + const Action a2 = Action(a1); + EXPECT_EQ(1, a1.Perform(make_tuple(42))); + EXPECT_EQ(0, a2.Perform(make_tuple(42))); + + // Implicit constructors are allowed. + const Action s1 = [](std::string s) { return !s.empty(); }; + const Action s2 = Action(s1); + EXPECT_EQ(0, s2.Perform(make_tuple(""))); + EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); + + // Also between the lambda and the action itself. + const Action x = [](Unused) { return 42; }; + EXPECT_TRUE(x.Perform(make_tuple("hello"))); +} + +TEST(FunctorActionTest, UnusedArguments) { + // Verify that users can ignore uninteresting arguments. + Action, const int&)> a = + [](int i, Unused, Unused) { return 2 * i; }; + EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); +} + +// Test that basic built-in actions work with move-only arguments. +// TODO(rburny): Currently, almost all ActionInterface-based actions will not +// work, even if they only try to use other, copyable arguments. Implement them +// if necessary (but note that DoAll cannot work on non-copyable types anyway - +// so maybe it's better to make users use lambdas instead. +TEST(MoveOnlyArgumentsTest, ReturningActions) { + Action)> a = Return(1); + EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); + + a = testing::WithoutArgs([]() { return 7; }); + EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); + + Action, int*)> a2 = testing::SetArgPointee<1>(3); + int x = 0; + a2.Perform(make_tuple(nullptr, &x)); + EXPECT_EQ(x, 3); +} + +#endif // GTEST_LANG_CXX11 + } // Unnamed namespace -- cgit v1.2.3 From 5fe8de5ded685541a63b0ac22b1cfb4c59406dfd Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 6 Apr 2018 11:40:04 -0400 Subject: more warnings --- googlemock/test/gmock_output_test_.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index ca628df6..d5f909d9 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,6 +39,14 @@ #include "gtest/gtest.h" + +// Silence C4100 (unreferenced formal parameter) for MSVC +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +#endif + + using testing::_; using testing::AnyNumber; using testing::Ge; @@ -298,3 +306,7 @@ int main(int argc, char **argv) { TestCatchesLeakedMocksInAdHocTests(); return RUN_ALL_TESTS(); } + +#ifdef _MSC_VER +# pragma warning(pop) +#endif -- cgit v1.2.3 From c4e3d77ddc155a32e9f98f64ea1e111a5cce0e43 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 11:22:11 -0400 Subject: More msvc 14 --- googlemock/test/gmock-actions_test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index ea6129d7..f8b9a1ef 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -43,6 +43,16 @@ #include "gtest/gtest.h" #include "gtest/gtest-spi.h" +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + + namespace { // This list should be kept sorted. @@ -1556,3 +1566,9 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif -- cgit v1.2.3 From 8bc7c631e848e7fc9eef2d95eeac12966caefb43 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 11:35:01 -0400 Subject: testing msvc again --- googlemock/test/gmock-actions_test.cc | 16 ---------------- googlemock/test/gmock-more-actions_test.cc | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index f8b9a1ef..ea6129d7 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -43,16 +43,6 @@ #include "gtest/gtest.h" #include "gtest/gtest-spi.h" -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - - namespace { // This list should be kept sorted. @@ -1566,9 +1556,3 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace - -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index f5e28eae..e9b272b3 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -42,6 +42,15 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-linked_ptr.h" +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + namespace testing { namespace gmock_more_actions_test { @@ -709,3 +718,8 @@ TEST(ReturnPointeeTest, Works) { } // namespace gmock_generated_actions_test } // namespace testing +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif -- cgit v1.2.3 From 431bfdcaf4a0f08c7ebd571291bf41d06195c20d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 11:48:02 -0400 Subject: msvc 14 --- googlemock/test/gmock-more-actions_test.cc | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index e9b272b3..f5e28eae 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -42,15 +42,6 @@ #include "gtest/gtest.h" #include "gtest/internal/gtest-linked_ptr.h" -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - namespace testing { namespace gmock_more_actions_test { @@ -718,8 +709,3 @@ TEST(ReturnPointeeTest, Works) { } // namespace gmock_generated_actions_test } // namespace testing -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif -- cgit v1.2.3 From c4684b49cf0d4334dfb522fcb3c8012cb63a4f61 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 12:03:40 -0400 Subject: more msvc --- googlemock/test/gmock_all_test.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index 56d6c49c..bb87729e 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -36,6 +36,15 @@ // includes most such tests, making it easier for these users to maintain // their build scripts (they just need to build this file, even though the // below list of actual *_test.cc files might change). +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "test/gmock-actions_test.cc" #include "test/gmock-cardinalities_test.cc" #include "test/gmock-generated-actions_test.cc" @@ -49,3 +58,9 @@ #include "test/gmock-port_test.cc" #include "test/gmock-spec-builders_test.cc" #include "test/gmock_test.cc" + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif -- cgit v1.2.3 From e93a0ece26844351da7cdc675a55a2520412134d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 13:51:01 -0400 Subject: msvc --- googlemock/test/gmock-actions_test.cc | 13 +++++++++++++ googlemock/test/gmock_all_test.cc | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index ea6129d7..cd517a7d 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,6 +33,13 @@ // // This file tests the built-in actions. +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "gmock/gmock-actions.h" #include #include @@ -1556,3 +1563,9 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index bb87729e..fa9d84b6 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -38,13 +38,6 @@ // below list of actual *_test.cc files might change). // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - #include "test/gmock-actions_test.cc" #include "test/gmock-cardinalities_test.cc" #include "test/gmock-generated-actions_test.cc" @@ -59,8 +52,3 @@ #include "test/gmock-spec-builders_test.cc" #include "test/gmock_test.cc" -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif -- cgit v1.2.3 From 44da2b9ac5dff919966d7bf488c7058bc8563023 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:23:00 -0400 Subject: cont --- googlemock/test/gmock_all_test.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index fa9d84b6..56d6c49c 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -36,8 +36,6 @@ // includes most such tests, making it easier for these users to maintain // their build scripts (they just need to build this file, even though the // below list of actual *_test.cc files might change). -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 #include "test/gmock-actions_test.cc" #include "test/gmock-cardinalities_test.cc" #include "test/gmock-generated-actions_test.cc" @@ -51,4 +49,3 @@ #include "test/gmock-port_test.cc" #include "test/gmock-spec-builders_test.cc" #include "test/gmock_test.cc" - -- cgit v1.2.3 From 055f32199a81a159eebeaabb6666d6de11127064 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:38:38 -0400 Subject: tuning --- googlemock/test/gmock_output_test_.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index d5f909d9..4166c6c6 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -42,8 +42,10 @@ // Silence C4100 (unreferenced formal parameter) for MSVC #ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) +# if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4100) +# endif #endif @@ -308,5 +310,7 @@ int main(int argc, char **argv) { } #ifdef _MSC_VER -# pragma warning(pop) +# if _MSC_VER <= 1900 +# pragma warning(pop) +# endif #endif -- cgit v1.2.3 From 2de24fbf7a26e679e8dc7d185addd3dc820f347c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:39:12 -0400 Subject: tuning --- googlemock/test/gmock_output_test_.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 4166c6c6..56a00b21 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -40,7 +40,7 @@ #include "gtest/gtest.h" -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 #ifdef _MSC_VER # if _MSC_VER <= 1900 # pragma warning(push) -- cgit v1.2.3 From 05b5a53898c2466e49f37e84324644949d279b34 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 15:50:19 -0400 Subject: formatting --- googlemock/test/gmock-actions_test.cc | 3 +++ googlemock/test/gmock_output_test_.cc | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index cd517a7d..5dd48460 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,6 +33,8 @@ // // This file tests the built-in actions. +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 #ifdef _MSC_VER #if _MSC_VER <= 1900 # pragma warning(push) @@ -1569,3 +1571,4 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { # pragma warning(pop) #endif #endif + diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 56a00b21..a01b95e5 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,7 +39,6 @@ #include "gtest/gtest.h" - // Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 #ifdef _MSC_VER # if _MSC_VER <= 1900 @@ -48,7 +47,6 @@ # endif #endif - using testing::_; using testing::AnyNumber; using testing::Ge; -- cgit v1.2.3 From 64d24b810f37681680a84d615f2601ac73dea78a Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 16:24:30 -0400 Subject: ... and this --- googlemock/test/gmock_output_test_.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index a01b95e5..1b59eb3f 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,12 +39,10 @@ #include "gtest/gtest.h" -// Silence C4100 (unreferenced formal parameter) for MSVC 14 and 15 +// Silence C4100 (unreferenced formal parameter) #ifdef _MSC_VER -# if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4100) -# endif +# pragma warning(push) +# pragma warning(disable:4100) #endif using testing::_; @@ -308,7 +306,5 @@ int main(int argc, char **argv) { } #ifdef _MSC_VER -# if _MSC_VER <= 1900 -# pragma warning(pop) -# endif +# pragma warning(pop) #endif -- cgit v1.2.3 From ca54b673034f6f182ff22ac554efcd1176f5808c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 9 Apr 2018 22:10:12 -0400 Subject: Revert "gmock actions 2" --- googlemock/test/gmock-actions_test.cc | 160 +--------------------------------- googlemock/test/gmock_output_test_.cc | 10 --- 2 files changed, 1 insertion(+), 169 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 5dd48460..46011570 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,15 +33,6 @@ // // This file tests the built-in actions. -// Silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 14,15 -#ifdef _MSC_VER -#if _MSC_VER <= 1900 -# pragma warning(push) -# pragma warning(disable:4800) -#endif -#endif - #include "gmock/gmock-actions.h" #include #include @@ -74,7 +65,6 @@ using testing::ReturnRef; using testing::ReturnRefOfCopy; using testing::SetArgPointee; using testing::SetArgumentPointee; -using testing::Unused; using testing::_; using testing::get; using testing::internal::BuiltInDefaultValue; @@ -715,8 +705,6 @@ class MockClass { MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); - MOCK_METHOD2(TakeUnique, - int(const std::unique_ptr&, std::unique_ptr)); #endif private: @@ -768,7 +756,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overriden by an ON_CALL(). +// DefaultValue::Set() when it's not overridden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; @@ -1423,152 +1411,6 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { EXPECT_EQ(7, *vresult[0]); } -TEST(MockMethodTest, CanTakeMoveOnlyValue) { - MockClass mock; - auto make = [](int i) { return std::unique_ptr(new int(i)); }; - - EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { - return *i; - }); - // DoAll() does not compile, since it would move from its arguments twice. - // EXPECT_CALL(mock, TakeUnique(_, _)) - // .WillRepeatedly(DoAll(Invoke([](std::unique_ptr j) {}), - // Return(1))); - EXPECT_CALL(mock, TakeUnique(testing::Pointee(7))) - .WillOnce(Return(-7)) - .RetiresOnSaturation(); - EXPECT_CALL(mock, TakeUnique(testing::IsNull())) - .WillOnce(Return(-1)) - .RetiresOnSaturation(); - - EXPECT_EQ(5, mock.TakeUnique(make(5))); - EXPECT_EQ(-7, mock.TakeUnique(make(7))); - EXPECT_EQ(7, mock.TakeUnique(make(7))); - EXPECT_EQ(7, mock.TakeUnique(make(7))); - EXPECT_EQ(-1, mock.TakeUnique({})); - - // Some arguments are moved, some passed by reference. - auto lvalue = make(6); - EXPECT_CALL(mock, TakeUnique(_, _)) - .WillOnce([](const std::unique_ptr& i, std::unique_ptr j) { - return *i * *j; - }); - EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7))); - - // The unique_ptr can be saved by the action. - std::unique_ptr saved; - EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr i) { - saved = std::move(i); - return 0; - }); - EXPECT_EQ(0, mock.TakeUnique(make(42))); - EXPECT_EQ(42, *saved); -} - #endif // GTEST_HAS_STD_UNIQUE_PTR_ -#if GTEST_LANG_CXX11 -// Tests for std::function based action. - -int Add(int val, int& ref, int* ptr) { // NOLINT - int result = val + ref + *ptr; - ref = 42; - *ptr = 43; - return result; -} - -int Deref(std::unique_ptr ptr) { return *ptr; } - -struct Double { - template - T operator()(T t) { return 2 * t; } -}; - -std::unique_ptr UniqueInt(int i) { - return std::unique_ptr(new int(i)); -} - -TEST(FunctorActionTest, ActionFromFunction) { - Action a = &Add; - int x = 1, y = 2, z = 3; - EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z))); - EXPECT_EQ(42, y); - EXPECT_EQ(43, z); - - Action)> a1 = &Deref; - EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7)))); -} - -TEST(FunctorActionTest, ActionFromLambda) { - Action a1 = [](bool b, int i) { return b ? i : 0; }; - EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); - - std::unique_ptr saved; - Action)> a2 = [&saved](std::unique_ptr p) { - saved = std::move(p); - }; - a2.Perform(make_tuple(UniqueInt(5))); - EXPECT_EQ(5, *saved); -} - -TEST(FunctorActionTest, PolymorphicFunctor) { - Action ai = Double(); - EXPECT_EQ(2, ai.Perform(make_tuple(1))); - Action ad = Double(); // Double? Double double! - EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); -} - -TEST(FunctorActionTest, TypeConversion) { - // Numeric promotions are allowed. - const Action a1 = [](int i) { return i > 1; }; - const Action a2 = Action(a1); - EXPECT_EQ(1, a1.Perform(make_tuple(42))); - EXPECT_EQ(0, a2.Perform(make_tuple(42))); - - // Implicit constructors are allowed. - const Action s1 = [](std::string s) { return !s.empty(); }; - const Action s2 = Action(s1); - EXPECT_EQ(0, s2.Perform(make_tuple(""))); - EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); - - // Also between the lambda and the action itself. - const Action x = [](Unused) { return 42; }; - EXPECT_TRUE(x.Perform(make_tuple("hello"))); -} - -TEST(FunctorActionTest, UnusedArguments) { - // Verify that users can ignore uninteresting arguments. - Action, const int&)> a = - [](int i, Unused, Unused) { return 2 * i; }; - EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); -} - -// Test that basic built-in actions work with move-only arguments. -// TODO(rburny): Currently, almost all ActionInterface-based actions will not -// work, even if they only try to use other, copyable arguments. Implement them -// if necessary (but note that DoAll cannot work on non-copyable types anyway - -// so maybe it's better to make users use lambdas instead. -TEST(MoveOnlyArgumentsTest, ReturningActions) { - Action)> a = Return(1); - EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); - - a = testing::WithoutArgs([]() { return 7; }); - EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); - - Action, int*)> a2 = testing::SetArgPointee<1>(3); - int x = 0; - a2.Perform(make_tuple(nullptr, &x)); - EXPECT_EQ(x, 3); -} - -#endif // GTEST_LANG_CXX11 - } // Unnamed namespace - -#ifdef _MSC_VER -#if _MSC_VER == 1900 -# pragma warning(pop) -#endif -#endif - diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 1b59eb3f..ca628df6 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,12 +39,6 @@ #include "gtest/gtest.h" -// Silence C4100 (unreferenced formal parameter) -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#endif - using testing::_; using testing::AnyNumber; using testing::Ge; @@ -304,7 +298,3 @@ int main(int argc, char **argv) { TestCatchesLeakedMocksInAdHocTests(); return RUN_ALL_TESTS(); } - -#ifdef _MSC_VER -# pragma warning(pop) -#endif -- cgit v1.2.3 From e1071eb9497304a38e69737e90a88b4877b8b736 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 15:57:16 -0400 Subject: RE-Doing the merge, this time with gcc on mac in the PR so I can catch errors before merging the PR --- googlemock/test/gmock-actions_test.cc | 16 ++++++++++++++++ googlemock/test/gmock-generated-actions_test.cc | 11 +++++------ googlemock/test/gmock_output_test_.cc | 4 +--- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index ea6129d7..5dd48460 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -33,6 +33,15 @@ // // This file tests the built-in actions. +// Silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 14,15 +#ifdef _MSC_VER +#if _MSC_VER <= 1900 +# pragma warning(push) +# pragma warning(disable:4800) +#endif +#endif + #include "gmock/gmock-actions.h" #include #include @@ -1556,3 +1565,10 @@ TEST(MoveOnlyArgumentsTest, ReturningActions) { #endif // GTEST_LANG_CXX11 } // Unnamed namespace + +#ifdef _MSC_VER +#if _MSC_VER == 1900 +# pragma warning(pop) +#endif +#endif + diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 80bcb31c..b821e5a2 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -374,10 +374,9 @@ class SubstractAction : public ActionInterface { // NOLINT }; TEST(WithArgsTest, NonInvokeAction) { - Action a = // NOLINT + Action a = // NOLINT WithArgs<2, 1>(MakeAction(new SubstractAction)); - string s("hello"); - EXPECT_EQ(8, a.Perform(tuple(s, 2, 10))); + EXPECT_EQ(8, a.Perform(make_tuple(std::string("hi"), 2, 10))); } // Tests using WithArgs to pass all original arguments in the original order. @@ -754,7 +753,7 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { TEST(ActionPMacroTest, WorksInCompatibleMockFunction) { Action a1 = Plus("tail"); const std::string re = "re"; - EXPECT_EQ("retail", a1.Perform(tuple(re))); + EXPECT_EQ("retail", a1.Perform(make_tuple(re))); } // Tests that we can use ACTION*() to define actions overloaded on the @@ -796,7 +795,7 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - EXPECT_EQ("retail->", a2.Perform(tuple(re))); + EXPECT_EQ("retail->", a2.Perform(make_tuple(re))); } ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; } @@ -1120,7 +1119,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) { EXPECT_FALSE(b); // Verifies that resetter is deleted. } -// Tests that ACTION_TEMPLATE works for a template with template parameters. +// Tests that ACTION_TEMPLATES works for template template parameters. ACTION_TEMPLATE(ReturnSmartPointer, HAS_1_TEMPLATE_PARAMS(template class, Pointer), diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index d5f909d9..1b59eb3f 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,14 +39,12 @@ #include "gtest/gtest.h" - -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4100) #endif - using testing::_; using testing::AnyNumber; using testing::Ge; -- cgit v1.2.3 From 9bc82ce7251b01ac3abfb28efc9793b56fa835d6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 10 Apr 2018 16:22:50 -0400 Subject: merging --- googlemock/test/gmock_output_test_.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 59ea51bd..1b59eb3f 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -39,14 +39,12 @@ #include "gtest/gtest.h" - -// Silence C4100 (unreferenced formal parameter) for MSVC +// Silence C4100 (unreferenced formal parameter) #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4100) #endif - using testing::_; using testing::AnyNumber; using testing::Ge; @@ -306,3 +304,7 @@ int main(int argc, char **argv) { TestCatchesLeakedMocksInAdHocTests(); return RUN_ALL_TESTS(); } + +#ifdef _MSC_VER +# pragma warning(pop) +#endif -- cgit v1.2.3 From b15be9a819ee3e0a36fcc8172a00ecf41e79f230 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:20:48 -0400 Subject: fixing osx pizza --- googlemock/test/gmock-generated-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index b821e5a2..1d685e58 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -376,7 +376,8 @@ class SubstractAction : public ActionInterface { // NOLINT TEST(WithArgsTest, NonInvokeAction) { Action a = // NOLINT WithArgs<2, 1>(MakeAction(new SubstractAction)); - EXPECT_EQ(8, a.Perform(make_tuple(std::string("hi"), 2, 10))); + tuple dummy = make_tuple(std::string("hi"), 2, 10); + EXPECT_EQ(8, a.Perform(dummy)); } // Tests using WithArgs to pass all original arguments in the original order. -- cgit v1.2.3 From f15fd9610b8a462b19a259b4b7ae279b9e97a77c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:33:51 -0400 Subject: osx pizzas, cont --- googlemock/test/gmock-generated-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 1d685e58..6ddd57f8 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -754,7 +754,8 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { TEST(ActionPMacroTest, WorksInCompatibleMockFunction) { Action a1 = Plus("tail"); const std::string re = "re"; - EXPECT_EQ("retail", a1.Perform(make_tuple(re))); + tuple dummy = make_tuple(re); + EXPECT_EQ("retail", a1.Perform(dummy)); } // Tests that we can use ACTION*() to define actions overloaded on the -- cgit v1.2.3 From 039d9b54c25829915679992671030caaa706f8fc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:47:38 -0400 Subject: pizza work, cont --- googlemock/test/gmock-generated-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 6ddd57f8..11d12dcb 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -797,7 +797,8 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - EXPECT_EQ("retail->", a2.Perform(make_tuple(re))); + tuple dummy = make_tuple(re); + EXPECT_EQ("retail->", a2.Perform(dummy)); } ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; } -- cgit v1.2.3 From 6a7573a7de99501ac928a058cc4732598f45be69 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 11 Apr 2018 09:55:36 -0400 Subject: more --- googlemock/test/gmock-generated-actions_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 11d12dcb..40bbe6d9 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -797,7 +797,7 @@ TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - tuple dummy = make_tuple(re); + tuple dummy = make_tuple(re); EXPECT_EQ("retail->", a2.Perform(dummy)); } -- cgit v1.2.3 From 1324e2d706d739217cceae361259a5cc01d1ff41 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Mon, 9 Apr 2018 21:57:54 -0700 Subject: Remove multiple inheritance from "unintesting call" mock classes. Internal CL 156157936, which was published in commit fe402c27790ff1cc9a7e17c5d0aea4ebe7fd8a71, introduced undefined behavior by casting a base class (internal::{Naggy,Nice,Strict}Base, using the curiously recurring template pattern) pointer to a derived class ({Naggy,Nice,Strict}Mock), in the base class' constructor. At that point, the object isn't guaranteed to have taken on the shape of the derived class, and casting is undefined behavior. The undefined behavior was caught by Chrome's CFI build bot [1], and prevents rolling googletest past that commit / CL. This commit simplifies the {Naggy,Nice,Strict}Mock class hierarchy in a way that removes the undefined behavior. [1] https://www.chromium.org/developers/testing/control-flow-integrity --- googlemock/test/gmock-nice-strict_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 0eac6439..7812f626 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -259,6 +259,13 @@ TEST(NiceMockTest, NonDefaultConstructor10) { nice_bar.That(5, true); } +TEST(NiceMockTest, AllowLeak) { + NiceMock* leaked = new NiceMock; + Mock::AllowLeak(leaked); + EXPECT_CALL(*leaked, DoThis()); + leaked->DoThis(); +} + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NiceMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -352,6 +359,13 @@ TEST(NaggyMockTest, NonDefaultConstructor10) { naggy_bar.That(5, true); } +TEST(NaggyMockTest, AllowLeak) { + NaggyMock* leaked = new NaggyMock; + Mock::AllowLeak(leaked); + EXPECT_CALL(*leaked, DoThis()); + leaked->DoThis(); +} + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NaggyMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -426,6 +440,13 @@ TEST(StrictMockTest, NonDefaultConstructor10) { "Uninteresting mock function call"); } +TEST(StrictMockTest, AllowLeak) { + StrictMock* leaked = new StrictMock; + Mock::AllowLeak(leaked); + EXPECT_CALL(*leaked, DoThis()); + leaked->DoThis(); +} + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that StrictMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an -- cgit v1.2.3 From e77deb29a65444247343c3ace800782de3706fd1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 09:12:02 -0400 Subject: small cleanup --- googlemock/test/gmock-matchers_test.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 33be41a9..4f7d0ec0 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -62,6 +62,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". #if defined(_MSC_VER) && (_MSC_VER == 1900) +# pragma warning(push) # pragma warning(disable:4503) #endif @@ -6656,7 +6657,7 @@ TEST(AnyWithTest, TestUseInContainers) { AnyWith("merhaba"), AnyWith("salut")})); } -#endif // GTEST_LANG_CXX11 +#endif // GTEST_LANG_CXX11 TEST(AnyWithTest, TestCompare) { EXPECT_THAT(SampleAnyType(1), AnyWith(Gt(0))); } @@ -6694,3 +6695,8 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing + +#if defined(_MSC_VER) && (_MSC_VER == 1900) +# pragma warning(pop) +#endif + -- cgit v1.2.3 From b2d81b4fb2a229d01655afabec9679197cc2c1f4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 09:45:07 -0400 Subject: merge, ... gmock-matchers test --- googlemock/test/gmock-matchers_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 4f7d0ec0..0e40df31 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -61,7 +61,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER == 1900) +#if defined(_MSC_VER) && (_MSC_VER <= 1900) # pragma warning(push) # pragma warning(disable:4503) #endif @@ -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; @@ -6696,7 +6696,7 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined(_MSC_VER) && (_MSC_VER == 1900) +#if defined(_MSC_VER) && (_MSC_VER <= 1900) # pragma warning(pop) #endif -- cgit v1.2.3 From 9b5940e040c9e0f45bb3dfe3ab457d1e6ec022b0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 10:28:02 -0400 Subject: revert this one --- googlemock/test/gmock-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 0e40df31..3162a05e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -761,7 +761,7 @@ namespace convertible_from_any { struct ConvertibleFromAny { ConvertibleFromAny(int a_value) : value(a_value) {} template - ConvertibleFromAny(const T& /*a_value*/) : value(-1) { + explicit ConvertibleFromAny(const T& /*a_value*/) : value(-1) { ADD_FAILURE() << "Conversion constructor called"; } int value; -- cgit v1.2.3 From c67f51b5dc1a7e2b614d50b60061bb143be71d45 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 11:32:17 -0400 Subject: msvc --- googlemock/test/gmock-matchers_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 3162a05e..16116b5c 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -61,7 +61,7 @@ // Disable MSVC2015 warning for std::pair: // "decorated name length exceeded, name was truncated". -#if defined(_MSC_VER) && (_MSC_VER <= 1900) +#if defined _MSC_VER # pragma warning(push) # pragma warning(disable:4503) #endif @@ -6696,7 +6696,7 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#if defined(_MSC_VER) && (_MSC_VER <= 1900) +#if defined_MSC_VER # pragma warning(pop) #endif -- cgit v1.2.3 From fa658e0cc08075b134b5ed35808f31a557616c9c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 13:42:47 -0400 Subject: merging --- .../test/gmock-generated-function-mockers_test.cc | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index 08e5eba1..0ff37556 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -620,5 +620,28 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) { } #endif // GTEST_HAS_STD_FUNCTION_ +struct MockMethodSizes0 { + MOCK_METHOD0(func, void()); +}; +struct MockMethodSizes1 { + MOCK_METHOD1(func, void(int)); +}; +struct MockMethodSizes2 { + MOCK_METHOD2(func, void(int, int)); +}; +struct MockMethodSizes3 { + MOCK_METHOD3(func, void(int, int, int)); +}; +struct MockMethodSizes4 { + MOCK_METHOD4(func, void(int, int, int, int)); +}; + +TEST(MockFunctionTest, MockMethodSizeOverhead) { + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes1)); + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes2)); + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes3)); + EXPECT_EQ(sizeof(MockMethodSizes0), sizeof(MockMethodSizes4)); +} + } // namespace gmock_generated_function_mockers_test } // namespace testing -- cgit v1.2.3 From a79851f2c26755324bf0340eed3538d3a047b7a7 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 14:00:38 -0400 Subject: merging --- googlemock/test/gmock-nice-strict_test.cc | 50 +++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 7812f626..c4194946 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -32,9 +32,10 @@ #include "gmock/gmock-generated-nice-strict.h" #include +#include #include "gmock/gmock.h" -#include "gtest/gtest.h" #include "gtest/gtest-spi.h" +#include "gtest/gtest.h" // This must not be defined inside the ::testing namespace, or it will // clash with ::testing::Mock. @@ -114,6 +115,24 @@ class MockBar { GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); }; +#if GTEST_GTEST_LANG_CXX11 + +class MockBaz { + public: + class MoveOnly { + MoveOnly() = default; + + MoveOnly(const MoveOnly&) = delete; + operator=(const MoveOnly&) = delete; + + MoveOnly(MoveOnly&&) = default; + operator=(MoveOnly&&) = default; + }; + + MockBaz(MoveOnly) {} +} +#endif // GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if GTEST_HAS_STREAM_REDIRECTION // Tests that a raw mock generates warnings for uninteresting calls. @@ -214,8 +233,9 @@ TEST(NiceMockTest, AllowsExpectedCall) { nice_foo.DoThis(); } -// Tests that an unexpected call on a nice mock which returns a not-default-constructible -// type throws an exception and the exception contains the method's name. +// Tests that an unexpected call on a nice mock which returns a +// not-default-constructible type throws an exception and the exception contains +// the method's name. TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { NiceMock nice_foo; #if GTEST_HAS_EXCEPTIONS @@ -266,6 +286,14 @@ TEST(NiceMockTest, AllowLeak) { leaked->DoThis(); } +#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + +TEST(NiceMockTest, MoveOnlyConstructor) { + NiceMock nice_baz(MockBaz::MoveOnly()); +} + +#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NiceMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -366,6 +394,14 @@ TEST(NaggyMockTest, AllowLeak) { leaked->DoThis(); } +#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + +TEST(NaggyMockTest, MoveOnlyConstructor) { + NaggyMock naggy_baz(MockBaz::MoveOnly()); +} + +#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that NaggyMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an @@ -447,6 +483,14 @@ TEST(StrictMockTest, AllowLeak) { leaked->DoThis(); } +#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + +TEST(StrictMockTest, MoveOnlyConstructor) { + StrictMock strict_baz(MockBaz::MoveOnly()); +} + +#endif // GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_ + #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE // Tests that StrictMock compiles where Mock is a user-defined // class (as opposed to ::testing::Mock). We had to work around an -- cgit v1.2.3 From 092ca91072bfca56da3f7c19d4a07f0f5074f0ba Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 14:46:57 -0400 Subject: merging --- googlemock/test/gmock-more-actions_test.cc | 14 +++++--------- googlemock/test/gmock-spec-builders_test.cc | 4 +++- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index f5e28eae..ed83fad4 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -327,11 +327,8 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { - Action a1 = - Invoke(SumOfFirst2); - string s("hi"); - EXPECT_EQ(12, a1.Perform( - tuple(10, 2, 5.6, s))); + Action a1 = Invoke(SumOfFirst2); + EXPECT_EQ(12, a1.Perform(make_tuple(10, 2, 5.6, std::string("hi")))); Action a2 = Invoke(SumOfFirst2); @@ -380,10 +377,9 @@ TEST(InvokeMethodTest, Unary) { // Tests using Invoke() with a binary method. TEST(InvokeMethodTest, Binary) { Foo foo; - Action a = Invoke(&foo, &Foo::Binary); - string s("Hell"); - EXPECT_EQ("Hello", a.Perform( - tuple(s, 'o'))); + Action a = Invoke(&foo, &Foo::Binary); + std::string s("Hell"); + EXPECT_EQ("Hello", a.Perform(make_tuple(s, 'o'))); } // Tests using Invoke() with a ternary method. diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 6001582a..f1d571be 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2173,7 +2173,9 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture { "NOTE: You can safely ignore the above warning unless this " "call should not happen. Do not suppress it by blindly adding " "an EXPECT_CALL() if you don't mean to enforce the call. " - "See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#" + "See " + "https://github.com/google/googletest/blob/master/googlemock/docs/" + "CookBook.md#" "knowing-when-to-expect for details."; // A void-returning function. -- cgit v1.2.3 From dc4f5638c2d0365ae464bff03ce297955e5393a9 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 15:45:21 -0400 Subject: merging, fix OSX issue --- googlemock/test/gmock-internal-utils_test.cc | 1 - googlemock/test/gmock-more-actions_test.cc | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index f8633df2..6c898cd2 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -36,7 +36,6 @@ #include "gmock/internal/gmock-internal-utils.h" #include #include -#include #include #include #include diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index ed83fad4..7145a04b 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -379,7 +379,8 @@ TEST(InvokeMethodTest, Binary) { Foo foo; Action a = Invoke(&foo, &Foo::Binary); std::string s("Hell"); - EXPECT_EQ("Hello", a.Perform(make_tuple(s, 'o'))); + tuple dummy = make_tuple(s, 'o'); + EXPECT_EQ("Hello", a.Perform(dummy)); } // Tests using Invoke() with a ternary method. -- cgit v1.2.3 From 65380492b2b43fe3f6ddb7e85a1a01b833f0c6da Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 16:32:03 -0400 Subject: fixing --- googlemock/test/gmock-internal-utils_test.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 6c898cd2..f8633df2 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -36,6 +36,7 @@ #include "gmock/internal/gmock-internal-utils.h" #include #include +#include #include #include #include -- cgit v1.2.3 From f7330f9f14e8860bbec0620eb1d06f9c812cf561 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 12 Apr 2018 17:00:31 -0400 Subject: more fixing osx libstd++ bugs --- googlemock/test/gmock-more-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 7145a04b..911d034a 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -328,7 +328,8 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { Action a1 = Invoke(SumOfFirst2); - EXPECT_EQ(12, a1.Perform(make_tuple(10, 2, 5.6, std::string("hi")))); + tuple dummy = make_tuple(10, 2, 5.6, std::string("hi")); + EXPECT_EQ(12, a1.Perform(dummy)); Action a2 = Invoke(SumOfFirst2); -- cgit v1.2.3 From 2dc576ec55aede9e8a5df571cf60d42de5a48105 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 09:16:40 -0400 Subject: merging --- .../test/gmock-generated-internal-utils_test.cc | 20 +++++++++++--------- googlemock/test/gmock-more-actions_test.cc | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-internal-utils_test.cc b/googlemock/test/gmock-generated-internal-utils_test.cc index e0a535a3..2e5abe56 100644 --- a/googlemock/test/gmock-generated-internal-utils_test.cc +++ b/googlemock/test/gmock-generated-internal-utils_test.cc @@ -63,10 +63,10 @@ TEST(MatcherTupleTest, ForSize2) { } TEST(MatcherTupleTest, ForSize5) { - CompileAssertTypesEqual, Matcher, Matcher, - Matcher, Matcher >, - MatcherTuple - >::type>(); + CompileAssertTypesEqual< + tuple, Matcher, Matcher, Matcher, + Matcher >, + MatcherTuple >::type>(); } // Tests the Function template struct. @@ -97,8 +97,9 @@ TEST(FunctionTest, Binary) { CompileAssertTypesEqual(); CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual, F::ArgumentTuple>(); // NOLINT - CompileAssertTypesEqual, Matcher >, // NOLINT - F::ArgumentMatcherTuple>(); + CompileAssertTypesEqual< + tuple, Matcher >, // NOLINT + F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual(); @@ -114,9 +115,10 @@ TEST(FunctionTest, LongArgumentList) { CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual, // NOLINT F::ArgumentTuple>(); - CompileAssertTypesEqual, Matcher, Matcher, - Matcher, Matcher >, // NOLINT - F::ArgumentMatcherTuple>(); + CompileAssertTypesEqual< + tuple, Matcher, Matcher, Matcher, + Matcher >, // NOLINT + F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); CompileAssertTypesEqual< diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 911d034a..b13518aa 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -328,7 +328,8 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { Action a1 = Invoke(SumOfFirst2); - tuple dummy = make_tuple(10, 2, 5.6, std::string("hi")); + tuple dummy = + make_tuple(10, 2, 5.6, std::string("hi")); EXPECT_EQ(12, a1.Perform(dummy)); Action a2 = -- cgit v1.2.3 From 0bfa8237855a2a56ae676fd703a8c2147771680d Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 11:02:25 -0400 Subject: merging, gmock actions test --- googlemock/test/gmock-actions_test.cc | 143 +++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 2cbf0ee3..da7cc0d0 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -714,6 +714,8 @@ class MockClass { MOCK_METHOD0(MakeUniqueBase, std::unique_ptr()); MOCK_METHOD0(MakeVectorUnique, std::vector>()); MOCK_METHOD1(TakeUnique, int(std::unique_ptr)); + MOCK_METHOD2(TakeUnique, + int(const std::unique_ptr&, std::unique_ptr)); #endif private: @@ -765,7 +767,7 @@ TEST(DoDefaultDeathTest, DiesIfUsedInCompositeAction) { } // Tests that DoDefault() returns the default value set by -// DefaultValue::Set() when it's not overridden by an ON_CALL(). +// DefaultValue::Set() when it's not overriden by an ON_CALL(). TEST(DoDefaultTest, ReturnsUserSpecifiedPerTypeDefaultValueWhenThereIsOne) { DefaultValue::Set(1); MockClass mock; @@ -1420,8 +1422,147 @@ TEST(MockMethodTest, CanReturnMoveOnlyValue_Invoke) { EXPECT_EQ(7, *vresult[0]); } +TEST(MockMethodTest, CanTakeMoveOnlyValue) { + MockClass mock; + auto make = [](int i) { return std::unique_ptr(new int(i)); }; + + EXPECT_CALL(mock, TakeUnique(_)).WillRepeatedly([](std::unique_ptr i) { + return *i; + }); + // DoAll() does not compile, since it would move from its arguments twice. + // EXPECT_CALL(mock, TakeUnique(_, _)) + // .WillRepeatedly(DoAll(Invoke([](std::unique_ptr j) {}), + // Return(1))); + EXPECT_CALL(mock, TakeUnique(testing::Pointee(7))) + .WillOnce(Return(-7)) + .RetiresOnSaturation(); + EXPECT_CALL(mock, TakeUnique(testing::IsNull())) + .WillOnce(Return(-1)) + .RetiresOnSaturation(); + + EXPECT_EQ(5, mock.TakeUnique(make(5))); + EXPECT_EQ(-7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(7, mock.TakeUnique(make(7))); + EXPECT_EQ(-1, mock.TakeUnique({})); + + // Some arguments are moved, some passed by reference. + auto lvalue = make(6); + EXPECT_CALL(mock, TakeUnique(_, _)) + .WillOnce([](const std::unique_ptr& i, std::unique_ptr j) { + return *i * *j; + }); + EXPECT_EQ(42, mock.TakeUnique(lvalue, make(7))); + + // The unique_ptr can be saved by the action. + std::unique_ptr saved; + EXPECT_CALL(mock, TakeUnique(_)).WillOnce([&saved](std::unique_ptr i) { + saved = std::move(i); + return 0; + }); + EXPECT_EQ(0, mock.TakeUnique(make(42))); + EXPECT_EQ(42, *saved); +} + #endif // GTEST_HAS_STD_UNIQUE_PTR_ +#if GTEST_LANG_CXX11 +// Tests for std::function based action. + +int Add(int val, int& ref, int* ptr) { // NOLINT + int result = val + ref + *ptr; + ref = 42; + *ptr = 43; + return result; +} + +int Deref(std::unique_ptr ptr) { return *ptr; } + +struct Double { + template + T operator()(T t) { return 2 * t; } +}; + +std::unique_ptr UniqueInt(int i) { + return std::unique_ptr(new int(i)); +} + +TEST(FunctorActionTest, ActionFromFunction) { + Action a = &Add; + int x = 1, y = 2, z = 3; + EXPECT_EQ(6, a.Perform(std::forward_as_tuple(x, y, &z))); + EXPECT_EQ(42, y); + EXPECT_EQ(43, z); + + Action)> a1 = &Deref; + EXPECT_EQ(7, a1.Perform(std::make_tuple(UniqueInt(7)))); +} + +TEST(FunctorActionTest, ActionFromLambda) { + Action a1 = [](bool b, int i) { return b ? i : 0; }; + EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); + + std::unique_ptr saved; + Action)> a2 = [&saved](std::unique_ptr p) { + saved = std::move(p); + }; + a2.Perform(make_tuple(UniqueInt(5))); + EXPECT_EQ(5, *saved); +} + +TEST(FunctorActionTest, PolymorphicFunctor) { + Action ai = Double(); + EXPECT_EQ(2, ai.Perform(make_tuple(1))); + Action ad = Double(); // Double? Double double! + EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); +} + +TEST(FunctorActionTest, TypeConversion) { + // Numeric promotions are allowed. + const Action a1 = [](int i) { return i > 1; }; + const Action a2 = Action(a1); + EXPECT_EQ(1, a1.Perform(make_tuple(42))); + EXPECT_EQ(0, a2.Perform(make_tuple(42))); + + // Implicit constructors are allowed. + const Action s1 = [](std::string s) { return !s.empty(); }; + const Action s2 = Action(s1); + EXPECT_EQ(0, s2.Perform(make_tuple(""))); + EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); + + // Also between the lambda and the action itself. + const Action x = [](Unused) { return 42; }; + EXPECT_TRUE(x.Perform(make_tuple("hello"))); +} + +TEST(FunctorActionTest, UnusedArguments) { + // Verify that users can ignore uninteresting arguments. + Action, const int&)> a = + [](int i, Unused, Unused) { return 2 * i; }; + EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); +} + +// Test that basic built-in actions work with move-only arguments. +// TODO(rburny): Currently, almost all ActionInterface-based actions will not +// work, even if they only try to use other, copyable arguments. Implement them +// if necessary (but note that DoAll cannot work on non-copyable types anyway - +// so maybe it's better to make users use lambdas instead. +TEST(MoveOnlyArgumentsTest, ReturningActions) { + Action)> a = Return(1); + EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); + + a = testing::WithoutArgs([]() { return 7; }); + EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); + + Action, int*)> a2 = testing::SetArgPointee<1>(3); + int x = 0; + a2.Perform(make_tuple(nullptr, &x)); + EXPECT_EQ(x, 3); +} + +#endif // GTEST_LANG_CXX11 + } // Unnamed namespace #ifdef _MSC_VER -- cgit v1.2.3 From f9bd6180debc46d59fa0ddd0e08bb361e3ca18bc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 11:02:55 -0400 Subject: merging gmock actions test --- googlemock/test/gmock-actions_test.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index da7cc0d0..5dd48460 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -74,6 +74,7 @@ using testing::ReturnRef; using testing::ReturnRefOfCopy; using testing::SetArgPointee; using testing::SetArgumentPointee; +using testing::Unused; using testing::_; using testing::get; using testing::internal::BuiltInDefaultValue; -- cgit v1.2.3 From b74a1af00f17cd52c426c08e0d1a1b4ea93f78dd Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 11:49:37 -0400 Subject: osx pizzas --- googlemock/test/gmock-actions_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 5dd48460..c8b62fc2 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,9 +1539,10 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action, const int&)> a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - EXPECT_EQ(6, a.Perform(make_tuple(3, UniqueInt(7), 9))); + tuple dummy = make_tuple(3, 7.3, 9); + EXPECT_EQ(6, a.Perform(dummy)); } // Test that basic built-in actions work with move-only arguments. -- cgit v1.2.3 From f45728a5ac69bcbc5c713938ee63591df40e35bb Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 15:48:57 -0400 Subject: more OSX pizzas --- googlemock/test/gmock-actions_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index c8b62fc2..646a10c1 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1541,7 +1541,8 @@ TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9); + int nine = 9; + tuple dummy = make_tuple(3, 7.3, nine); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v1.2.3 From d84eb86df5d129f39064e2f3349699e84faf8493 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 13 Apr 2018 16:04:34 -0400 Subject: more pizza --- googlemock/test/gmock-actions_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 646a10c1..08f2a559 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,10 +1539,9 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - int nine = 9; - tuple dummy = make_tuple(3, 7.3, nine); + tuple dummy = make_tuple(3, 7.3, 9); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v1.2.3 From 26c10dc7e6505b5880c6d3bd87e033864ce23eab Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 10:16:48 -0400 Subject: merging --- googlemock/test/gmock-actions_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 08f2a559..646a10c1 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,9 +1539,10 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9); + int nine = 9; + tuple dummy = make_tuple(3, 7.3, nine); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v1.2.3 From 1c6e68cf6cdd800a8183b54a3dd1a22e5932f1c6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 10:34:07 -0400 Subject: merging --- googlemock/test/gmock-actions_test.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 646a10c1..e391428f 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1539,10 +1539,9 @@ TEST(FunctorActionTest, TypeConversion) { TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. - Action a = + Action a = [](int i, Unused, Unused) { return 2 * i; }; - int nine = 9; - tuple dummy = make_tuple(3, 7.3, nine); + tuple dummy = make_tuple(3, 7.3, 9.44); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v1.2.3 From 9fba10315628d4e93d2975ae9c9a214b9665cc59 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 10:42:08 -0400 Subject: merging, testing, this should be it --- googlemock/test/gmock-actions_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index e391428f..7fbb50d3 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1541,7 +1541,7 @@ TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9.44); + tuple dummy = make_tuple(3, 7.3, 9.44); EXPECT_EQ(6, a.Perform(dummy)); } -- cgit v1.2.3 From bd2a1aed03c8319f43ee01ed675d2a2365aac7c5 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:18:49 -0400 Subject: merging gmock generated matchers --- googlemock/test/gmock-generated-matchers_test.cc | 51 ++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 6cba726d..f24d7c80 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -57,6 +58,8 @@ using testing::get; using testing::make_tuple; using testing::tuple; using testing::_; +using testing::AllOf; +using testing::AnyOf; using testing::Args; using testing::Contains; using testing::ElementsAre; @@ -120,7 +123,7 @@ TEST(ArgsTest, AcceptsOneTemplateArg) { } TEST(ArgsTest, AcceptsTwoTemplateArgs) { - const tuple t(static_cast(4), 5, 6L); // NOLINT + const tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 1>(Lt()))); EXPECT_THAT(t, (Args<1, 2>(Lt()))); @@ -128,13 +131,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) { } TEST(ArgsTest, AcceptsRepeatedTemplateArgs) { - const tuple t(static_cast(4), 5, 6L); // NOLINT + const tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 0>(Eq()))); EXPECT_THAT(t, Not(Args<1, 1>(Ne()))); } TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { - const tuple t(static_cast(4), 5, 6L); // NOLINT + const tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<2, 0>(Gt()))); EXPECT_THAT(t, Not(Args<2, 1>(Lt()))); } @@ -159,7 +162,7 @@ TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) { } TEST(ArgsTest, CanBeNested) { - const tuple t(static_cast(4), 5, 6L, 6); // NOLINT + const tuple t(4, 5, 6L, 6); // NOLINT EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq())))); EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt())))); } @@ -1283,4 +1286,44 @@ TEST(AnyOfTest, DoesNotCallAnyOfUnqualified) { # pragma warning(pop) #endif +#if GTEST_LANG_CXX11 + +TEST(AllOfTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(5)))); + EXPECT_THAT(p, Not(AllOf(Pointee(Eq(3)), Pointee(Gt(0)), Pointee(Lt(3))))); +} + +TEST(AnyOfTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Lt(5)))); + EXPECT_THAT(p, Not(AnyOf(Pointee(Eq(5)), Pointee(Lt(0)), Pointee(Gt(5))))); +} + +MATCHER(IsNotNull, "") { + return arg != nullptr; +} + +// Verifies that a matcher defined using MATCHER() can work on +// move-only types. +TEST(MatcherMacroTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, IsNotNull()); + EXPECT_THAT(std::unique_ptr(), Not(IsNotNull())); +} + +MATCHER_P(UniquePointee, pointee, "") { + return *arg == pointee; +} + +// Verifies that a matcher defined using MATCHER_P*() can work on +// move-only types. +TEST(MatcherPMacroTest, WorksOnMoveOnlyType) { + std::unique_ptr p(new int(3)); + EXPECT_THAT(p, UniquePointee(3)); + EXPECT_THAT(p, Not(UniquePointee(2))); +} + +#endif // GTEST_LASNG_CXX11 + } // namespace -- cgit v1.2.3 From e9eff488f9a41e95773d2c361294a0ffee5bbe65 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:32:16 -0400 Subject: msvc warnings --- googlemock/test/gmock-generated-matchers_test.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index f24d7c80..9190522b 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -31,6 +31,13 @@ // // This file tests the built-in matchers generated by a script. +// Silence warning C4244: 'initializing': conversion from 'int' to 'short', +// possible loss of data +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:C4244) +#endif + #include "gmock/gmock-generated-matchers.h" #include @@ -1327,3 +1334,7 @@ TEST(MatcherPMacroTest, WorksOnMoveOnlyType) { #endif // GTEST_LASNG_CXX11 } // namespace + +#ifdef _MSC_VER +# pragma warning(pop) +#endif -- cgit v1.2.3 From 1944bc0f510fa631b8d35075b4ff95c3efeacf39 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:41:36 -0400 Subject: typo --- googlemock/test/gmock-generated-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 9190522b..85108558 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -35,7 +35,7 @@ // possible loss of data #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable:C4244) +# pragma warning(disable:4244) #endif #include "gmock/gmock-generated-matchers.h" -- cgit v1.2.3 From e4ab316c85c172de3717bebd68fcb1d4eb420ccf Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 11:52:22 -0400 Subject: more msvc --- googlemock/test/gmock-generated-matchers_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 85108558..bc9df722 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -32,10 +32,11 @@ // This file tests the built-in matchers generated by a script. // Silence warning C4244: 'initializing': conversion from 'int' to 'short', -// possible loss of data +// possible loss of data C4100: : unreferenced formal parameter #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4244) +# pragma warning(disable:4100) #endif #include "gmock/gmock-generated-matchers.h" -- cgit v1.2.3 From ec425d71601ddf5ee6272f22c670fe6f959afbf4 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 16 Apr 2018 12:00:37 -0400 Subject: typo --- googlemock/test/gmock-generated-matchers_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index bc9df722..0ebd4701 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -32,7 +32,7 @@ // This file tests the built-in matchers generated by a script. // Silence warning C4244: 'initializing': conversion from 'int' to 'short', -// possible loss of data C4100: : unreferenced formal parameter +// possible loss of data and C4100, unreferenced local parameter #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable:4244) -- cgit v1.2.3 From dff32aff97a682dfc603ac99bedc639b959e24a8 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 17 Apr 2018 16:12:04 -0400 Subject: http://cl/193060888 --- googlemock/test/gmock-matchers_test.cc | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 16116b5c..c2738c37 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2742,6 +2742,48 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)); } +// Tests the variadic version of the ElementsAreMatcher +TEST(ElementsAreTest, HugeMatcher) { + vector test_vector; + test_vector.push_back(1); + test_vector.push_back(2); + test_vector.push_back(3); + test_vector.push_back(4); + test_vector.push_back(5); + test_vector.push_back(6); + test_vector.push_back(7); + test_vector.push_back(8); + test_vector.push_back(9); + test_vector.push_back(10); + test_vector.push_back(11); + test_vector.push_back(12); + + EXPECT_THAT(test_vector, + ElementsAre(Eq(1), Eq(2), Lt(13), Eq(4), Eq(5), Eq(6), Eq(7), + Eq(8), Eq(9), Eq(10), Gt(1), Eq(12) )); +} + +// Tests the variadic version of the UnorderedElementsAreMatcher +TEST(ElementsAreTest, HugeMatcherUnordered) { + vector test_vector; + test_vector.push_back(1); + test_vector.push_back(2); + test_vector.push_back(3); + test_vector.push_back(4); + test_vector.push_back(5); + test_vector.push_back(6); + test_vector.push_back(7); + test_vector.push_back(8); + test_vector.push_back(9); + test_vector.push_back(10); + test_vector.push_back(11); + test_vector.push_back(12); + + EXPECT_THAT(test_vector, + UnorderedElementsAre(Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), + Eq(8), Eq(9), Eq(10), Eq(11), Ne(122) )); +} + #endif // GTEST_LANG_CXX11 // Tests that AnyOf(m1, ..., mn) describes itself properly. -- cgit v1.2.3 From 5dccf6b79eb55fbbfb4783e2ac15fcc40f66e5bf Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 17 Apr 2018 16:22:35 -0400 Subject: http://cl/193060888 --- googlemock/test/gmock-matchers_test.cc | 36 ++++++---------------------------- 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index c2738c37..a76b331e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2744,44 +2744,20 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) { // Tests the variadic version of the ElementsAreMatcher TEST(ElementsAreTest, HugeMatcher) { - vector test_vector; - test_vector.push_back(1); - test_vector.push_back(2); - test_vector.push_back(3); - test_vector.push_back(4); - test_vector.push_back(5); - test_vector.push_back(6); - test_vector.push_back(7); - test_vector.push_back(8); - test_vector.push_back(9); - test_vector.push_back(10); - test_vector.push_back(11); - test_vector.push_back(12); + vector test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; EXPECT_THAT(test_vector, ElementsAre(Eq(1), Eq(2), Lt(13), Eq(4), Eq(5), Eq(6), Eq(7), - Eq(8), Eq(9), Eq(10), Gt(1), Eq(12) )); + Eq(8), Eq(9), Eq(10), Gt(1), Eq(12))); } // Tests the variadic version of the UnorderedElementsAreMatcher TEST(ElementsAreTest, HugeMatcherUnordered) { - vector test_vector; - test_vector.push_back(1); - test_vector.push_back(2); - test_vector.push_back(3); - test_vector.push_back(4); - test_vector.push_back(5); - test_vector.push_back(6); - test_vector.push_back(7); - test_vector.push_back(8); - test_vector.push_back(9); - test_vector.push_back(10); - test_vector.push_back(11); - test_vector.push_back(12); + vector test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - EXPECT_THAT(test_vector, - UnorderedElementsAre(Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), - Eq(8), Eq(9), Eq(10), Eq(11), Ne(122) )); + EXPECT_THAT(test_vector, UnorderedElementsAre( + Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), + Eq(8), Eq(9), Eq(10), Eq(11), Ne(122))); } #endif // GTEST_LANG_CXX11 -- cgit v1.2.3 From 80d6e26a9c170812614f2e29c53f0893446d8cee Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 17 Apr 2018 19:32:15 -0400 Subject: cl/193060888 --- googlemock/test/gmock-matchers_test.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index a76b331e..c40944bb 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2753,11 +2753,11 @@ TEST(ElementsAreTest, HugeMatcher) { // Tests the variadic version of the UnorderedElementsAreMatcher TEST(ElementsAreTest, HugeMatcherUnordered) { - vector test_vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + vector test_vector{2, 1, 8, 5, 4, 6, 7, 3, 9, 12, 11, 10}; EXPECT_THAT(test_vector, UnorderedElementsAre( - Eq(1), Eq(2), Eq(3), Eq(4), Eq(5), Eq(6), Eq(7), - Eq(8), Eq(9), Eq(10), Eq(11), Ne(122))); + Eq(2), Eq(1), Gt(7), Eq(5), Eq(4), Eq(6), Eq(7), + Eq(3), Eq(9), Eq(12), Eq(11), Ne(122))); } #endif // GTEST_LANG_CXX11 -- cgit v1.2.3 From 4707c0ffd4385e7195170a427e4a0471bb5335a6 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Apr 2018 10:36:12 -0400 Subject: 193353312 --- googlemock/test/gmock-matchers_test.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index c40944bb..8b115cd8 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2751,6 +2751,15 @@ TEST(ElementsAreTest, HugeMatcher) { Eq(8), Eq(9), Eq(10), Gt(1), Eq(12))); } +// Tests the variadic version of the UnorderedElementsAreMatcher +TEST(ElementsAreTest, HugeMatcherStr) { + vector test_vector{ + "literal_string", "", "", "", "", "", "", "", "", "", "", ""}; + + EXPECT_THAT(test_vector, UnorderedElementsAre("literal_string", _, _, _, _, _, + _, _, _, _, _, _)); +} + // Tests the variadic version of the UnorderedElementsAreMatcher TEST(ElementsAreTest, HugeMatcherUnordered) { vector test_vector{2, 1, 8, 5, 4, 6, 7, 3, 9, 12, 11, 10}; -- cgit v1.2.3 From f437f8ca0d4d13d6b1b6279ee40dc61121873a94 Mon Sep 17 00:00:00 2001 From: David Sunderland Date: Wed, 18 Apr 2018 19:28:56 -0400 Subject: Clone of unsubmitted cr/176529515. Introduce parameterless expectations. --- googlemock/test/gmock-matchers_test.cc | 39 +++++++++++++++- googlemock/test/gmock-spec-builders_test.cc | 70 +++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 16116b5c..8170bdb8 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 - diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index f1d571be..715aac8c 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -89,6 +89,7 @@ using testing::Mock; using testing::NaggyMock; using testing::Ne; using testing::Return; +using testing::SaveArg; using testing::Sequence; using testing::SetArgPointee; using testing::internal::ExpectationTester; @@ -2681,6 +2682,75 @@ TEST(SynchronizationTest, CanCallMockMethodInAction) { // EXPECT_CALL() did not specify an action. } +TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) { + MockA a; + int do_a_arg0 = 0; + ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0)); + int do_a_47_arg0 = 0; + ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0)); + + a.DoA(17); + EXPECT_THAT(do_a_arg0, 17); + EXPECT_THAT(do_a_47_arg0, 0); + a.DoA(47); + EXPECT_THAT(do_a_arg0, 17); + EXPECT_THAT(do_a_47_arg0, 47); + + ON_CALL(a, Binary).WillByDefault(Return(true)); + ON_CALL(a, Binary(_, 14)).WillByDefault(Return(false)); + EXPECT_THAT(a.Binary(14, 17), true); + EXPECT_THAT(a.Binary(17, 14), false); +} + +TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) { + MockB b; + ON_CALL(b, DoB()).WillByDefault(Return(9)); + ON_CALL(b, DoB(5)).WillByDefault(Return(11)); + + EXPECT_THAT(b.DoB(), 9); + EXPECT_THAT(b.DoB(1), 0); // default value + EXPECT_THAT(b.DoB(5), 11); +} + +struct MockWithConstMethods { + public: + MOCK_CONST_METHOD1(Foo, int(int)); + MOCK_CONST_METHOD2(Bar, int(int, const char*)); +}; + +TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) { + MockWithConstMethods mock; + ON_CALL(mock, Foo).WillByDefault(Return(7)); + ON_CALL(mock, Bar).WillByDefault(Return(33)); + + EXPECT_THAT(mock.Foo(17), 7); + EXPECT_THAT(mock.Bar(27, "purple"), 33); +} + +class MockConstOverload { + public: + MOCK_METHOD1(Overloaded, int(int)); + MOCK_CONST_METHOD1(Overloaded, int(int)); +}; + +TEST(ParameterlessExpectationsTest, + CanSetExpectationsForConstOverloadedMethods) { + MockConstOverload mock; + ON_CALL(mock, Overloaded(_)).WillByDefault(Return(7)); + ON_CALL(mock, Overloaded(5)).WillByDefault(Return(9)); + ON_CALL(Const(mock), Overloaded(5)).WillByDefault(Return(11)); + ON_CALL(Const(mock), Overloaded(7)).WillByDefault(Return(13)); + + EXPECT_THAT(mock.Overloaded(1), 7); + EXPECT_THAT(mock.Overloaded(5), 9); + EXPECT_THAT(mock.Overloaded(7), 7); + + const MockConstOverload& const_mock = mock; + EXPECT_THAT(const_mock.Overloaded(1), 0); + EXPECT_THAT(const_mock.Overloaded(5), 11); + EXPECT_THAT(const_mock.Overloaded(7), 13); +} + } // namespace // Allows the user to define their own main and then invoke gmock_main -- cgit v1.2.3 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 +++++++++++++++++++++------ googlemock/test/gmock-spec-builders_test.cc | 70 +++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 13 deletions(-) (limited to 'googlemock/test') 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 diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index f1d571be..715aac8c 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -89,6 +89,7 @@ using testing::Mock; using testing::NaggyMock; using testing::Ne; using testing::Return; +using testing::SaveArg; using testing::Sequence; using testing::SetArgPointee; using testing::internal::ExpectationTester; @@ -2681,6 +2682,75 @@ TEST(SynchronizationTest, CanCallMockMethodInAction) { // EXPECT_CALL() did not specify an action. } +TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) { + MockA a; + int do_a_arg0 = 0; + ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0)); + int do_a_47_arg0 = 0; + ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0)); + + a.DoA(17); + EXPECT_THAT(do_a_arg0, 17); + EXPECT_THAT(do_a_47_arg0, 0); + a.DoA(47); + EXPECT_THAT(do_a_arg0, 17); + EXPECT_THAT(do_a_47_arg0, 47); + + ON_CALL(a, Binary).WillByDefault(Return(true)); + ON_CALL(a, Binary(_, 14)).WillByDefault(Return(false)); + EXPECT_THAT(a.Binary(14, 17), true); + EXPECT_THAT(a.Binary(17, 14), false); +} + +TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) { + MockB b; + ON_CALL(b, DoB()).WillByDefault(Return(9)); + ON_CALL(b, DoB(5)).WillByDefault(Return(11)); + + EXPECT_THAT(b.DoB(), 9); + EXPECT_THAT(b.DoB(1), 0); // default value + EXPECT_THAT(b.DoB(5), 11); +} + +struct MockWithConstMethods { + public: + MOCK_CONST_METHOD1(Foo, int(int)); + MOCK_CONST_METHOD2(Bar, int(int, const char*)); +}; + +TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) { + MockWithConstMethods mock; + ON_CALL(mock, Foo).WillByDefault(Return(7)); + ON_CALL(mock, Bar).WillByDefault(Return(33)); + + EXPECT_THAT(mock.Foo(17), 7); + EXPECT_THAT(mock.Bar(27, "purple"), 33); +} + +class MockConstOverload { + public: + MOCK_METHOD1(Overloaded, int(int)); + MOCK_CONST_METHOD1(Overloaded, int(int)); +}; + +TEST(ParameterlessExpectationsTest, + CanSetExpectationsForConstOverloadedMethods) { + MockConstOverload mock; + ON_CALL(mock, Overloaded(_)).WillByDefault(Return(7)); + ON_CALL(mock, Overloaded(5)).WillByDefault(Return(9)); + ON_CALL(Const(mock), Overloaded(5)).WillByDefault(Return(11)); + ON_CALL(Const(mock), Overloaded(7)).WillByDefault(Return(13)); + + EXPECT_THAT(mock.Overloaded(1), 7); + EXPECT_THAT(mock.Overloaded(5), 9); + EXPECT_THAT(mock.Overloaded(7), 7); + + const MockConstOverload& const_mock = mock; + EXPECT_THAT(const_mock.Overloaded(1), 0); + EXPECT_THAT(const_mock.Overloaded(5), 11); + EXPECT_THAT(const_mock.Overloaded(7), 13); +} + } // namespace // Allows the user to define their own main and then invoke gmock_main -- cgit v1.2.3 From a9653c401e799933be77ee9dfa4aa0c378031b1d Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Wed, 2 May 2018 11:14:39 -0700 Subject: Fix gmock not building when -fno-rtti Fixes issue #1554. This is internal cl/195020996. --- googlemock/test/gmock-matchers_test.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index b4224651..87b2ad5c 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -3704,6 +3704,7 @@ MATCHER_P(FieldIIs, inner_matcher, "") { return ExplainMatchResult(inner_matcher, arg.i, result_listener); } +#if GTEST_HAS_RTTI TEST(WhenDynamicCastToTest, SameType) { Derived derived; derived.i = 4; @@ -3761,12 +3762,8 @@ TEST(WhenDynamicCastToTest, AmbiguousCast) { TEST(WhenDynamicCastToTest, Describe) { Matcher matcher = WhenDynamicCastTo(Pointee(_)); -#if GTEST_HAS_RTTI const std::string prefix = "when dynamic_cast to " + internal::GetTypeName() + ", "; -#else // GTEST_HAS_RTTI - const std::string prefix = "when dynamic_cast, "; -#endif // GTEST_HAS_RTTI EXPECT_EQ(prefix + "points to a value that is anything", Describe(matcher)); EXPECT_EQ(prefix + "does not point to a value that is anything", DescribeNegation(matcher)); @@ -3799,6 +3796,7 @@ TEST(WhenDynamicCastToTest, BadReference) { Base& as_base_ref = derived; EXPECT_THAT(as_base_ref, Not(WhenDynamicCastTo(_))); } +#endif // GTEST_HAS_RTTI // Minimal const-propagating pointer. template -- cgit v1.2.3 From 28c91e2cea88ee6ddc0e0dc6ca18b8e86f85d80c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 23 May 2018 11:03:31 -0400 Subject: Formatting changes --- googlemock/test/gmock_link2_test.cc | 2 +- googlemock/test/gmock_link_test.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_link2_test.cc b/googlemock/test/gmock_link2_test.cc index 4c310c3d..2b48395c 100644 --- a/googlemock/test/gmock_link2_test.cc +++ b/googlemock/test/gmock_link2_test.cc @@ -37,4 +37,4 @@ #define LinkTest LinkTest2 -#include "test/gmock_link_test.h" +#include "test/gmock_link_test.h" diff --git a/googlemock/test/gmock_link_test.cc b/googlemock/test/gmock_link_test.cc index 61e97d10..ef041be9 100644 --- a/googlemock/test/gmock_link_test.cc +++ b/googlemock/test/gmock_link_test.cc @@ -37,4 +37,4 @@ #define LinkTest LinkTest1 -#include "test/gmock_link_test.h" +#include "test/gmock_link_test.h" -- cgit v1.2.3 From 8977af0ecfdd49baedfd4ea020afe68d5c5e1fbb Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 23 May 2018 11:49:11 -0400 Subject: formatting changes --- googlemock/test/gmock_test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_test_utils.py b/googlemock/test/gmock_test_utils.py index b5130001..92b1ac14 100755 --- a/googlemock/test/gmock_test_utils.py +++ b/googlemock/test/gmock_test_utils.py @@ -38,7 +38,7 @@ import sys SCRIPT_DIR = os.path.dirname(__file__) or '.' # isdir resolves symbolic links. -gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../googletest/test') +gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../../googletest/test') if os.path.isdir(gtest_tests_util_dir): GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir else: -- cgit v1.2.3 From 93bfdde0eeac83fb51b856dc4dc9c38c408b0ee0 Mon Sep 17 00:00:00 2001 From: Adrian Moran Date: Wed, 11 Jul 2018 14:59:01 +0200 Subject: Fix issue #1654. Signed-off-by: Adrian Moran --- googlemock/test/gmock_ex_test.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc index 3afed86a..8c83890f 100644 --- a/googlemock/test/gmock_ex_test.cc +++ b/googlemock/test/gmock_ex_test.cc @@ -37,7 +37,9 @@ namespace { using testing::HasSubstr; +#if GTEST_HAS_EXCEPTIONS using testing::internal::GoogleTestFailureException; +#endif // A type that cannot be default constructed. class NonDefaultConstructible { -- cgit v1.2.3 From 0acdf796420e4562ef7399b8610d23eda3256a5a Mon Sep 17 00:00:00 2001 From: Adrian Moran Date: Thu, 12 Jul 2018 15:10:08 +0200 Subject: Avoid full test in no exceptions are enabled. Signed-off-by: Adrian Moran --- googlemock/test/gmock_ex_test.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc index 8c83890f..5a299dae 100644 --- a/googlemock/test/gmock_ex_test.cc +++ b/googlemock/test/gmock_ex_test.cc @@ -31,15 +31,14 @@ // Tests Google Mock's functionality that depends on exceptions. +#if GTEST_HAS_EXCEPTIONS #include "gmock/gmock.h" #include "gtest/gtest.h" namespace { using testing::HasSubstr; -#if GTEST_HAS_EXCEPTIONS using testing::internal::GoogleTestFailureException; -#endif // A type that cannot be default constructed. class NonDefaultConstructible { @@ -54,7 +53,6 @@ class MockFoo { MOCK_METHOD0(GetNonDefaultConstructible, NonDefaultConstructible()); }; -#if GTEST_HAS_EXCEPTIONS TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) { MockFoo mock; @@ -78,6 +76,5 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) { } } -#endif - } // unnamed namespace +#endif -- cgit v1.2.3 From cbd07191f4b7a3498fd0d1d7c58c4c39cccb8fb8 Mon Sep 17 00:00:00 2001 From: Adrian Moran Date: Fri, 13 Jul 2018 08:53:03 +0200 Subject: Put ifdef guard after the includes. Signed-off-by: Adrian Moran --- googlemock/test/gmock_ex_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc index 5a299dae..99268b31 100644 --- a/googlemock/test/gmock_ex_test.cc +++ b/googlemock/test/gmock_ex_test.cc @@ -31,10 +31,10 @@ // Tests Google Mock's functionality that depends on exceptions. -#if GTEST_HAS_EXCEPTIONS #include "gmock/gmock.h" #include "gtest/gtest.h" +#if GTEST_HAS_EXCEPTIONS namespace { using testing::HasSubstr; -- cgit v1.2.3 From 8d07cfd0532352379c624ce8844aeca0dc68a585 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Jul 2018 11:30:36 -0400 Subject: Code sync, mostly formatting and removing outdates --- googlemock/test/gmock-actions_test.cc | 202 ---------------------------------- googlemock/test/gmock_ex_test.cc | 3 +- 2 files changed, 2 insertions(+), 203 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 7fbb50d3..e8bdbee7 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -88,10 +88,6 @@ using testing::tuple_element; using testing::SetErrnoAndReturn; #endif -#if GTEST_HAS_PROTOBUF_ -using testing::internal::TestMessage; -#endif // GTEST_HAS_PROTOBUF_ - // Tests that BuiltInDefaultValue::Get() returns NULL. TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) { EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); @@ -895,105 +891,6 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { # endif } -#if GTEST_HAS_PROTOBUF_ - -// Tests that SetArgPointee(proto_buffer) sets the v1 protobuf -// variable pointed to by the N-th (0-based) argument to proto_buffer. -TEST(SetArgPointeeTest, SetsTheNthPointeeOfProtoBufferType) { - TestMessage* const msg = new TestMessage; - msg->set_member("yes"); - TestMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgPointee<1>(*msg); - // SetArgPointee(proto_buffer) makes a copy of proto_buffer - // s.t. the action works even when the original proto_buffer has - // died. We ensure this behavior by deleting msg before using the - // action. - delete msg; - - TestMessage dest; - EXPECT_FALSE(orig_msg.Equals(dest)); - a.Perform(make_tuple(true, &dest)); - EXPECT_TRUE(orig_msg.Equals(dest)); -} - -// Tests that SetArgPointee(proto_buffer) sets the -// ::ProtocolMessage variable pointed to by the N-th (0-based) -// argument to proto_buffer. -TEST(SetArgPointeeTest, SetsTheNthPointeeOfProtoBufferBaseType) { - TestMessage* const msg = new TestMessage; - msg->set_member("yes"); - TestMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgPointee<1>(*msg); - // SetArgPointee(proto_buffer) makes a copy of proto_buffer - // s.t. the action works even when the original proto_buffer has - // died. We ensure this behavior by deleting msg before using the - // action. - delete msg; - - TestMessage dest; - ::ProtocolMessage* const dest_base = &dest; - EXPECT_FALSE(orig_msg.Equals(dest)); - a.Perform(make_tuple(true, dest_base)); - EXPECT_TRUE(orig_msg.Equals(dest)); -} - -// Tests that SetArgPointee(proto2_buffer) sets the v2 -// protobuf variable pointed to by the N-th (0-based) argument to -// proto2_buffer. -TEST(SetArgPointeeTest, SetsTheNthPointeeOfProto2BufferType) { - using testing::internal::FooMessage; - FooMessage* const msg = new FooMessage; - msg->set_int_field(2); - msg->set_string_field("hi"); - FooMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgPointee<1>(*msg); - // SetArgPointee(proto2_buffer) makes a copy of - // proto2_buffer s.t. the action works even when the original - // proto2_buffer has died. We ensure this behavior by deleting msg - // before using the action. - delete msg; - - FooMessage dest; - dest.set_int_field(0); - a.Perform(make_tuple(true, &dest)); - EXPECT_EQ(2, dest.int_field()); - EXPECT_EQ("hi", dest.string_field()); -} - -// Tests that SetArgPointee(proto2_buffer) sets the -// proto2::Message variable pointed to by the N-th (0-based) argument -// to proto2_buffer. -TEST(SetArgPointeeTest, SetsTheNthPointeeOfProto2BufferBaseType) { - using testing::internal::FooMessage; - FooMessage* const msg = new FooMessage; - msg->set_int_field(2); - msg->set_string_field("hi"); - FooMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgPointee<1>(*msg); - // SetArgPointee(proto2_buffer) makes a copy of - // proto2_buffer s.t. the action works even when the original - // proto2_buffer has died. We ensure this behavior by deleting msg - // before using the action. - delete msg; - - FooMessage dest; - dest.set_int_field(0); - ::proto2::Message* const dest_base = &dest; - a.Perform(make_tuple(true, dest_base)); - EXPECT_EQ(2, dest.int_field()); - EXPECT_EQ("hi", dest.string_field()); -} - -#endif // GTEST_HAS_PROTOBUF_ - // Tests that SetArgumentPointee(v) sets the variable pointed to by // the N-th (0-based) argument to v. TEST(SetArgumentPointeeTest, SetsTheNthPointee) { @@ -1014,105 +911,6 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) { EXPECT_EQ('a', ch); } -#if GTEST_HAS_PROTOBUF_ - -// Tests that SetArgumentPointee(proto_buffer) sets the v1 protobuf -// variable pointed to by the N-th (0-based) argument to proto_buffer. -TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferType) { - TestMessage* const msg = new TestMessage; - msg->set_member("yes"); - TestMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgumentPointee<1>(*msg); - // SetArgumentPointee(proto_buffer) makes a copy of proto_buffer - // s.t. the action works even when the original proto_buffer has - // died. We ensure this behavior by deleting msg before using the - // action. - delete msg; - - TestMessage dest; - EXPECT_FALSE(orig_msg.Equals(dest)); - a.Perform(make_tuple(true, &dest)); - EXPECT_TRUE(orig_msg.Equals(dest)); -} - -// Tests that SetArgumentPointee(proto_buffer) sets the -// ::ProtocolMessage variable pointed to by the N-th (0-based) -// argument to proto_buffer. -TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProtoBufferBaseType) { - TestMessage* const msg = new TestMessage; - msg->set_member("yes"); - TestMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgumentPointee<1>(*msg); - // SetArgumentPointee(proto_buffer) makes a copy of proto_buffer - // s.t. the action works even when the original proto_buffer has - // died. We ensure this behavior by deleting msg before using the - // action. - delete msg; - - TestMessage dest; - ::ProtocolMessage* const dest_base = &dest; - EXPECT_FALSE(orig_msg.Equals(dest)); - a.Perform(make_tuple(true, dest_base)); - EXPECT_TRUE(orig_msg.Equals(dest)); -} - -// Tests that SetArgumentPointee(proto2_buffer) sets the v2 -// protobuf variable pointed to by the N-th (0-based) argument to -// proto2_buffer. -TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferType) { - using testing::internal::FooMessage; - FooMessage* const msg = new FooMessage; - msg->set_int_field(2); - msg->set_string_field("hi"); - FooMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgumentPointee<1>(*msg); - // SetArgumentPointee(proto2_buffer) makes a copy of - // proto2_buffer s.t. the action works even when the original - // proto2_buffer has died. We ensure this behavior by deleting msg - // before using the action. - delete msg; - - FooMessage dest; - dest.set_int_field(0); - a.Perform(make_tuple(true, &dest)); - EXPECT_EQ(2, dest.int_field()); - EXPECT_EQ("hi", dest.string_field()); -} - -// Tests that SetArgumentPointee(proto2_buffer) sets the -// proto2::Message variable pointed to by the N-th (0-based) argument -// to proto2_buffer. -TEST(SetArgumentPointeeTest, SetsTheNthPointeeOfProto2BufferBaseType) { - using testing::internal::FooMessage; - FooMessage* const msg = new FooMessage; - msg->set_int_field(2); - msg->set_string_field("hi"); - FooMessage orig_msg; - orig_msg.CopyFrom(*msg); - - Action a = SetArgumentPointee<1>(*msg); - // SetArgumentPointee(proto2_buffer) makes a copy of - // proto2_buffer s.t. the action works even when the original - // proto2_buffer has died. We ensure this behavior by deleting msg - // before using the action. - delete msg; - - FooMessage dest; - dest.set_int_field(0); - ::proto2::Message* const dest_base = &dest; - a.Perform(make_tuple(true, dest_base)); - EXPECT_EQ(2, dest.int_field()); - EXPECT_EQ("hi", dest.string_field()); -} - -#endif // GTEST_HAS_PROTOBUF_ - // Sample functions and functors for testing Invoke() and etc. int Nullary() { return 1; } diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc index 99268b31..b03de82e 100644 --- a/googlemock/test/gmock_ex_test.cc +++ b/googlemock/test/gmock_ex_test.cc @@ -38,6 +38,7 @@ namespace { using testing::HasSubstr; + using testing::internal::GoogleTestFailureException; // A type that cannot be default constructed. @@ -53,7 +54,6 @@ class MockFoo { MOCK_METHOD0(GetNonDefaultConstructible, NonDefaultConstructible()); }; - TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) { MockFoo mock; try { @@ -76,5 +76,6 @@ TEST(DefaultValueTest, ThrowsRuntimeErrorWhenNoDefaultValue) { } } + } // unnamed namespace #endif -- cgit v1.2.3 From 3530ab9e437b57e9d6778f646d5b88343cae5e02 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 18 Jul 2018 11:51:14 -0400 Subject: Code sync --- googlemock/test/gmock-matchers_test.cc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 87b2ad5c..a4518425 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2680,7 +2680,7 @@ TEST(AllOfTest, ExplainsResult) { } // Helper to allow easy testing of AnyOf matchers with num parameters. -void AnyOfMatches(int num, const Matcher& m) { +static void AnyOfMatches(int num, const Matcher& m) { SCOPED_TRACE(Describe(m)); EXPECT_FALSE(m.Matches(0)); for (int i = 1; i <= num; ++i) { @@ -2689,6 +2689,18 @@ void AnyOfMatches(int num, const Matcher& m) { EXPECT_FALSE(m.Matches(num + 1)); } +#if GTEST_LANG_CXX11 +static void AnyOfStringMatches(int num, const Matcher& m) { + SCOPED_TRACE(Describe(m)); + EXPECT_FALSE(m.Matches(std::to_string(0))); + + for (int i = 1; i <= num; ++i) { + EXPECT_TRUE(m.Matches(std::to_string(i))); + } + EXPECT_FALSE(m.Matches(std::to_string(num + 1))); +} +#endif + // Tests that AnyOf(m1, ..., mn) matches any value that matches at // least one of the given matchers. TEST(AnyOfTest, MatchesWhenAnyMatches) { @@ -2746,6 +2758,12 @@ TEST(AnyOfTest, VariadicMatchesWhenAnyMatches) { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)); + AnyOfStringMatches( + 50, AnyOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", + "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", + "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", + "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", + "43", "44", "45", "46", "47", "48", "49", "50")); } // Tests the variadic version of the ElementsAreMatcher @@ -4570,7 +4588,7 @@ TEST(ResultOfTest, WorksForFunctors) { } // Tests that ResultOf(f, ...) compiles and works as expected when f is a -// functor with more then one operator() defined. ResultOf() must work +// functor with more than one operator() defined. ResultOf() must work // for each defined operator(). struct PolymorphicFunctor { typedef int result_type; @@ -6764,4 +6782,3 @@ TEST(NotTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing - -- cgit v1.2.3 From 0c17888bcfa7a05ae2cb14c1f5e2451ea9745211 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 19 Jul 2018 12:42:39 -0400 Subject: code sync --- googlemock/test/gmock-matchers_test.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index a4518425..f9dfd3c1 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2795,6 +2795,7 @@ TEST(ElementsAreTest, HugeMatcherUnordered) { #endif // GTEST_LANG_CXX11 + // Tests that AnyOf(m1, ..., mn) describes itself properly. TEST(AnyOfTest, CanDescribeSelf) { Matcher m; -- cgit v1.2.3 From a02af2f689426aa9622b06643f53ed27fa6dc8a5 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Fri, 20 Jul 2018 11:28:58 -0400 Subject: code merge --- googlemock/test/gmock-matchers_test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index f9dfd3c1..9f1a5471 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2795,7 +2795,6 @@ TEST(ElementsAreTest, HugeMatcherUnordered) { #endif // GTEST_LANG_CXX11 - // Tests that AnyOf(m1, ..., mn) describes itself properly. TEST(AnyOfTest, CanDescribeSelf) { Matcher m; @@ -4239,13 +4238,17 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) { // ref-qualified. TEST(PropertyTest, WorksForRefQualifiedProperty) { Matcher m = Property(&AClass::s_ref, StartsWith("hi")); + Matcher m_with_name = + Property("s", &AClass::s_ref, StartsWith("hi")); AClass a; a.set_s("hill"); EXPECT_TRUE(m.Matches(a)); + EXPECT_TRUE(m_with_name.Matches(a)); a.set_s("hole"); EXPECT_FALSE(m.Matches(a)); + EXPECT_FALSE(m_with_name.Matches(a)); } #endif -- cgit v1.2.3 From ed1edf641dc5a04dc559df763ca71a5d6d05d939 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 25 Jul 2018 10:24:13 -0400 Subject: Formatting changes, code sync --- googlemock/test/gmock_stress_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index b9fdc45c..e4e61f0f 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -33,13 +33,12 @@ // threads concurrently. #include "gmock/gmock.h" - #include "gtest/gtest.h" namespace testing { namespace { -// From "gtest/internal/gtest-port.h". +// From gtest-port.h. using ::testing::internal::ThreadWithParam; // The maximum number of test threads (not including helper threads) -- cgit v1.2.3 From 539ee4bc549846e3bd98b77f85d0aff8410ef8c0 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 1 Aug 2018 11:07:22 -0400 Subject: Formatting changes and upstreaming one test --- googlemock/test/gmock_leak_test.py | 2 -- googlemock/test/gmock_output_test.py | 1 - 2 files changed, 3 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_leak_test.py b/googlemock/test/gmock_leak_test.py index 997680ce..a2fee4b6 100755 --- a/googlemock/test/gmock_leak_test.py +++ b/googlemock/test/gmock_leak_test.py @@ -33,10 +33,8 @@ __author__ = 'wan@google.com (Zhanyong Wan)' - import gmock_test_utils - PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_') TEST_WITH_EXPECT_CALL = [PROGRAM_PATH, '--gtest_filter=*ExpectCall*'] TEST_WITH_ON_CALL = [PROGRAM_PATH, '--gtest_filter=*OnCall*'] diff --git a/googlemock/test/gmock_output_test.py b/googlemock/test/gmock_output_test.py index 9d73d570..8f57d46c 100755 --- a/googlemock/test/gmock_output_test.py +++ b/googlemock/test/gmock_output_test.py @@ -43,7 +43,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)' import os import re import sys - import gmock_test_utils -- cgit v1.2.3 From 24edf4e3bfc132fe21509ed5fba394ddcc02cb5f Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Mon, 6 Aug 2018 15:40:21 -0400 Subject: automatic code sync mgt, comment only --- googlemock/test/gmock-actions_test.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index e8bdbee7..2d169f88 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -937,6 +937,8 @@ class Foo { int value_; }; +// GOOGLETEST_CM0005 DO NOT DELETE + // Tests InvokeWithoutArgs(function). TEST(InvokeWithoutArgsTest, Function) { // As an action that takes one argument. -- cgit v1.2.3 From b78c3b8e008ea8ef059d224ece6aa52a4727ae2c Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 7 Aug 2018 10:38:41 -0400 Subject: small cleanup, np functional changes --- googlemock/test/gmock-actions_test.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 2d169f88..e8bdbee7 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -937,8 +937,6 @@ class Foo { int value_; }; -// GOOGLETEST_CM0005 DO NOT DELETE - // Tests InvokeWithoutArgs(function). TEST(InvokeWithoutArgsTest, Function) { // As an action that takes one argument. -- cgit v1.2.3 From 063a90b391d475f8f7ddc12e1df3dabcaf643f79 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 9 Aug 2018 10:51:49 -0400 Subject: Formatting change for auto code management, no functionality changes Merge branch 'master' of https://github.com/google/googletest --- googlemock/test/gmock_output_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test.py b/googlemock/test/gmock_output_test.py index 8f57d46c..c8af0f96 100755 --- a/googlemock/test/gmock_output_test.py +++ b/googlemock/test/gmock_output_test.py @@ -33,9 +33,10 @@ To update the golden file: gmock_output_test.py --build_dir=BUILD/DIR --gengolden -# where BUILD/DIR contains the built gmock_output_test_ file. +where BUILD/DIR contains the built gmock_output_test_ file. gmock_output_test.py --gengolden gmock_output_test.py + """ __author__ = 'wan@google.com (Zhanyong Wan)' -- cgit v1.2.3 From 5eb263569bc1f90ff3820c4f9f5fbc8fa25a031f Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 9 Aug 2018 15:24:43 -0400 Subject: Update gmock_output_test.py --- googlemock/test/gmock_output_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock_output_test.py b/googlemock/test/gmock_output_test.py index c8af0f96..20323e17 100755 --- a/googlemock/test/gmock_output_test.py +++ b/googlemock/test/gmock_output_test.py @@ -29,7 +29,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""Tests the text output of Google C++ Mocking Framework. +r"""Tests the text output of Google C++ Mocking Framework. To update the golden file: gmock_output_test.py --build_dir=BUILD/DIR --gengolden -- cgit v1.2.3 From a3c0dd0f4d58e6c01a1432fdc69a9aff937309a9 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 14 Aug 2018 14:04:07 -0400 Subject: Comments changes, no functionality changes --- googlemock/test/gmock-actions_test.cc | 3 +-- googlemock/test/gmock-cardinalities_test.cc | 3 +-- googlemock/test/gmock-generated-actions_test.cc | 3 +-- googlemock/test/gmock-generated-function-mockers_test.cc | 3 +-- googlemock/test/gmock-generated-internal-utils_test.cc | 3 +-- googlemock/test/gmock-internal-utils_test.cc | 3 +-- googlemock/test/gmock-matchers_test.cc | 3 +-- googlemock/test/gmock-more-actions_test.cc | 3 +-- googlemock/test/gmock-nice-strict_test.cc | 3 +-- googlemock/test/gmock-port_test.cc | 3 +-- googlemock/test/gmock-spec-builders_test.cc | 3 +-- googlemock/test/gmock_all_test.cc | 3 +-- googlemock/test/gmock_ex_test.cc | 3 +-- googlemock/test/gmock_leak_test_.cc | 3 +-- googlemock/test/gmock_link2_test.cc | 3 +-- googlemock/test/gmock_link_test.cc | 3 +-- googlemock/test/gmock_link_test.h | 3 +-- googlemock/test/gmock_output_test_.cc | 3 +-- googlemock/test/gmock_stress_test.cc | 3 +-- googlemock/test/gmock_test.cc | 3 +-- 20 files changed, 20 insertions(+), 40 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index e8bdbee7..e216fe2a 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-cardinalities_test.cc b/googlemock/test/gmock-cardinalities_test.cc index 04c792b5..132591bc 100644 --- a/googlemock/test/gmock-cardinalities_test.cc +++ b/googlemock/test/gmock-cardinalities_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index 40bbe6d9..a4602806 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index 0ff37556..f16833b2 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-generated-internal-utils_test.cc b/googlemock/test/gmock-generated-internal-utils_test.cc index 2e5abe56..ae0280fc 100644 --- a/googlemock/test/gmock-generated-internal-utils_test.cc +++ b/googlemock/test/gmock-generated-internal-utils_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index f8633df2..5f53077c 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 9f1a5471..d08f08f7 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index b13518aa..08a2df09 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index c4194946..dce66423 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + #include "gmock/gmock-generated-nice-strict.h" diff --git a/googlemock/test/gmock-port_test.cc b/googlemock/test/gmock-port_test.cc index d6a8d444..a2c2be24 100644 --- a/googlemock/test/gmock-port_test.cc +++ b/googlemock/test/gmock-port_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: vladl@google.com (Vlad Losev) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 715aac8c..78fbc3f0 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock_all_test.cc b/googlemock/test/gmock_all_test.cc index 56d6c49c..e1774fbb 100644 --- a/googlemock/test/gmock_all_test.cc +++ b/googlemock/test/gmock_all_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // // Tests for Google C++ Mocking Framework (Google Mock) // diff --git a/googlemock/test/gmock_ex_test.cc b/googlemock/test/gmock_ex_test.cc index b03de82e..72eb43f7 100644 --- a/googlemock/test/gmock_ex_test.cc +++ b/googlemock/test/gmock_ex_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Tests Google Mock's functionality that depends on exceptions. diff --git a/googlemock/test/gmock_leak_test_.cc b/googlemock/test/gmock_leak_test_.cc index 1d27d22f..2e095abc 100644 --- a/googlemock/test/gmock_leak_test_.cc +++ b/googlemock/test/gmock_leak_test_.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock_link2_test.cc b/googlemock/test/gmock_link2_test.cc index 2b48395c..d27ce176 100644 --- a/googlemock/test/gmock_link2_test.cc +++ b/googlemock/test/gmock_link2_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock_link_test.cc b/googlemock/test/gmock_link_test.cc index ef041be9..e7c54cc2 100644 --- a/googlemock/test/gmock_link_test.cc +++ b/googlemock/test/gmock_link_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 06a1cf89..d26670ec 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: vladl@google.com (Vlad Losev) + // Google Mock - a framework for writing C++ mock classes. // diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 1b59eb3f..3955c733 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Tests Google Mock's output in various scenarios. This ensures that // Google Mock's messages are readable and useful. diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index e4e61f0f..0d99bede 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Tests that Google Mock constructs can be used in a large number of // threads concurrently. diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index 70075679..341a17da 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // -- cgit v1.2.3 From 265efde9a5b35fbd23622620fa597822e122f38a Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 14 Aug 2018 15:04:11 -0400 Subject: Comments changes, no functionality changes. --- googlemock/test/gmock-actions_test.cc | 2 +- googlemock/test/gmock-spec-builders_test.cc | 2 +- googlemock/test/gmock_leak_test.py | 2 -- googlemock/test/gmock_output_test.py | 2 -- googlemock/test/gmock_test_utils.py | 2 -- 5 files changed, 2 insertions(+), 8 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index e216fe2a..06e29a1e 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -1343,7 +1343,7 @@ TEST(FunctorActionTest, UnusedArguments) { } // Test that basic built-in actions work with move-only arguments. -// TODO(rburny): Currently, almost all ActionInterface-based actions will not +// FIXME: Currently, almost all ActionInterface-based actions will not // work, even if they only try to use other, copyable arguments. Implement them // if necessary (but note that DoAll cannot work on non-copyable types anyway - // so maybe it's better to make users use lambdas instead. diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 78fbc3f0..7056c43c 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -1175,7 +1175,7 @@ TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) { TEST(UndefinedReturnValueTest, ReturnValueIsMandatoryWhenNotDefaultConstructible) { MockA a; - // TODO(wan@google.com): We should really verify the output message, + // FIXME: We should really verify the output message, // but we cannot yet due to that EXPECT_DEATH only captures stderr // while Google Mock logs to stdout. #if GTEST_HAS_EXCEPTIONS diff --git a/googlemock/test/gmock_leak_test.py b/googlemock/test/gmock_leak_test.py index a2fee4b6..7e4b1eea 100755 --- a/googlemock/test/gmock_leak_test.py +++ b/googlemock/test/gmock_leak_test.py @@ -31,8 +31,6 @@ """Tests that leaked mock objects can be caught be Google Mock.""" -__author__ = 'wan@google.com (Zhanyong Wan)' - import gmock_test_utils PROGRAM_PATH = gmock_test_utils.GetTestExecutablePath('gmock_leak_test_') diff --git a/googlemock/test/gmock_output_test.py b/googlemock/test/gmock_output_test.py index 20323e17..0527bd93 100755 --- a/googlemock/test/gmock_output_test.py +++ b/googlemock/test/gmock_output_test.py @@ -39,8 +39,6 @@ gmock_output_test.py """ -__author__ = 'wan@google.com (Zhanyong Wan)' - import os import re import sys diff --git a/googlemock/test/gmock_test_utils.py b/googlemock/test/gmock_test_utils.py index 92b1ac14..7dc4e119 100755 --- a/googlemock/test/gmock_test_utils.py +++ b/googlemock/test/gmock_test_utils.py @@ -29,8 +29,6 @@ """Unit test utilities for Google C++ Mocking Framework.""" -__author__ = 'wan@google.com (Zhanyong Wan)' - import os import sys -- cgit v1.2.3 From a0e62d9f1a5f24cbc9d16bb9d1c4b606e960b2af Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 24 Aug 2018 13:30:17 -0400 Subject: No longer require a functor passed to ResultOf matcher to define `result_of` type. This makes ResultOf more convenient to use. In particular, the matcher now accepts lambdas. PiperOrigin-RevId: 210118509 --- googlemock/test/gmock-matchers_test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index d08f08f7..4697f0bf 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -4597,6 +4597,7 @@ struct PolymorphicFunctor { typedef int result_type; int operator()(int n) { return n; } int operator()(const char* s) { return static_cast(strlen(s)); } + std::string operator()(int *p) { return p ? "good ptr" : "null"; } }; TEST(ResultOfTest, WorksForPolymorphicFunctors) { @@ -4611,6 +4612,23 @@ TEST(ResultOfTest, WorksForPolymorphicFunctors) { EXPECT_FALSE(matcher_string.Matches("shrt")); } +#if GTEST_LANG_CXX11 +TEST(ResultOfTest, WorksForPolymorphicFunctorsIgnoringResultType) { + Matcher matcher = ResultOf(PolymorphicFunctor(), "good ptr"); + + int n = 0; + EXPECT_TRUE(matcher.Matches(&n)); + EXPECT_FALSE(matcher.Matches(nullptr)); +} + +TEST(ResultOfTest, WorksForLambdas) { + Matcher matcher = + ResultOf([](int str_len) { return std::string(str_len, 'x'); }, "xxx"); + EXPECT_TRUE(matcher.Matches(3)); + EXPECT_FALSE(matcher.Matches(1)); +} +#endif + const int* ReferencingFunction(const int& n) { return &n; } struct ReferencingFunctor { -- cgit v1.2.3 From ffc9baeb4cb81a7db250249920a9bd3d5ace760a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 13 Sep 2018 11:27:56 -0400 Subject: Googletest export Treat default-constructed string_view same as constructed from "". In the context of string comparison (e.g. HasSubstr, StartsWith, EndsWith, etc.), a default-constructed string_view (nullptr) should be semantically same as a empty string "". PiperOrigin-RevId: 212816839 --- googlemock/test/gmock-matchers_test.cc | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 4697f0bf..79eb552e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -1335,6 +1335,11 @@ TEST(StrEqTest, MatchesEqualString) { EXPECT_TRUE(m3.Matches(absl::string_view("Hello"))); EXPECT_FALSE(m3.Matches(absl::string_view("hello"))); EXPECT_FALSE(m3.Matches(absl::string_view())); + + Matcher m_empty = StrEq(""); + EXPECT_TRUE(m_empty.Matches(absl::string_view(""))); + EXPECT_TRUE(m_empty.Matches(absl::string_view())); + EXPECT_FALSE(m_empty.Matches(absl::string_view("hello"))); #endif // GTEST_HAS_ABSL } @@ -1459,6 +1464,10 @@ TEST(HasSubstrTest, WorksForStringClasses) { const Matcher m2 = HasSubstr("foo"); EXPECT_TRUE(m2.Matches(std::string("I love food."))); EXPECT_FALSE(m2.Matches(std::string("tofo"))); + + const Matcher m_empty = HasSubstr(""); + EXPECT_TRUE(m_empty.Matches(std::string())); + EXPECT_TRUE(m_empty.Matches(std::string("not empty"))); } // Tests that HasSubstr() works for matching C-string-typed values. @@ -1472,6 +1481,11 @@ TEST(HasSubstrTest, WorksForCStrings) { EXPECT_TRUE(m2.Matches("I love food.")); EXPECT_FALSE(m2.Matches("tofo")); EXPECT_FALSE(m2.Matches(NULL)); + + const Matcher m_empty = HasSubstr(""); + EXPECT_TRUE(m_empty.Matches("not empty")); + EXPECT_TRUE(m_empty.Matches("")); + EXPECT_FALSE(m_empty.Matches(NULL)); } #if GTEST_HAS_ABSL @@ -1489,7 +1503,8 @@ TEST(HasSubstrTest, WorksForStringViewClasses) { const Matcher m3 = HasSubstr(""); EXPECT_TRUE(m3.Matches(absl::string_view("foo"))); - EXPECT_FALSE(m3.Matches(absl::string_view())); + EXPECT_TRUE(m3.Matches(absl::string_view(""))); + EXPECT_TRUE(m3.Matches(absl::string_view())); } #endif // GTEST_HAS_ABSL @@ -1713,6 +1728,13 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) { EXPECT_TRUE(m2.Matches("High")); EXPECT_FALSE(m2.Matches("H")); EXPECT_FALSE(m2.Matches(" Hi")); + +#if GTEST_HAS_ABSL + const Matcher m_empty = StartsWith(""); + EXPECT_TRUE(m_empty.Matches(absl::string_view())); + EXPECT_TRUE(m_empty.Matches(absl::string_view(""))); + EXPECT_TRUE(m_empty.Matches(absl::string_view("not empty"))); +#endif // GTEST_HAS_ABSL } TEST(StartsWithTest, CanDescribeSelf) { @@ -1748,9 +1770,8 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m4 = EndsWith(""); EXPECT_TRUE(m4.Matches("Hi")); EXPECT_TRUE(m4.Matches("")); - // Default-constructed absl::string_view should not match anything, in order - // to distinguish it from an empty string. - EXPECT_FALSE(m4.Matches(absl::string_view())); + EXPECT_TRUE(m4.Matches(absl::string_view())); + EXPECT_TRUE(m4.Matches(absl::string_view(""))); #endif // GTEST_HAS_ABSL } @@ -1777,11 +1798,10 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) { EXPECT_TRUE(m3.Matches(absl::string_view("az"))); EXPECT_TRUE(m3.Matches(absl::string_view("abcz"))); EXPECT_FALSE(m3.Matches(absl::string_view("1az"))); - // Default-constructed absl::string_view should not match anything, in order - // to distinguish it from an empty string. EXPECT_FALSE(m3.Matches(absl::string_view())); const Matcher m4 = MatchesRegex(""); - EXPECT_FALSE(m4.Matches(absl::string_view())); + EXPECT_TRUE(m4.Matches(absl::string_view(""))); + EXPECT_TRUE(m4.Matches(absl::string_view())); #endif // GTEST_HAS_ABSL } @@ -1816,11 +1836,10 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) { EXPECT_TRUE(m3.Matches(absl::string_view("azbz"))); EXPECT_TRUE(m3.Matches(absl::string_view("az1"))); EXPECT_FALSE(m3.Matches(absl::string_view("1a"))); - // Default-constructed absl::string_view should not match anything, in order - // to distinguish it from an empty string. EXPECT_FALSE(m3.Matches(absl::string_view())); const Matcher m4 = ContainsRegex(""); - EXPECT_FALSE(m4.Matches(absl::string_view())); + EXPECT_TRUE(m4.Matches(absl::string_view(""))); + EXPECT_TRUE(m4.Matches(absl::string_view())); #endif // GTEST_HAS_ABSL } -- cgit v1.2.3 From 77962730563eece3525f40b8769e4ca0c6baf64c Mon Sep 17 00:00:00 2001 From: Marco Bubke <30830880+marbub@users.noreply.github.com> Date: Tue, 2 Oct 2018 11:31:21 -0400 Subject: Merge 86fe8a25eb5a6e4546f9e39cf23a5c764217bf85 into 440527a61e1c91188195f7de212c63c77e8f0a45 Closes #1867 PiperOrigin-RevId: 215392714 --- googlemock/test/gmock-generated-function-mockers_test.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index f16833b2..4c490694 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -617,6 +617,17 @@ TEST(MockFunctionTest, AsStdFunctionReturnsReference) { value = 2; EXPECT_EQ(2, ref); } + +TEST(MockFunctionTest, AsStdFunctionWithReferenceParameter) { + MockFunction foo; + auto call = [](const std::function &f, int &i) { + return f(i); + }; + int i = 42; + EXPECT_CALL(foo, Call(i)).WillOnce(Return(-1)); + EXPECT_EQ(-1, call(foo.AsStdFunction(), i)); +} + #endif // GTEST_HAS_STD_FUNCTION_ struct MockMethodSizes0 { -- cgit v1.2.3 From 4bb49ed640e34e23187ad7ea689693ef9927033f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 4 Oct 2018 18:28:05 -0400 Subject: Apply clang-tidy modernize-use-nullptr to googletest. Now that googletest has moved to C++11, it should no longer use NULL or 0 for the null pointer. This patch converts all such usages to nullptr using clang-tidy. This prevents LLVM from issuing -Wzero-as-null-pointer-constant warnings. PiperOrigin-RevId: 215814400 --- googlemock/test/gmock-actions_test.cc | 28 ++-- .../test/gmock-generated-function-mockers_test.cc | 2 +- googlemock/test/gmock-generated-matchers_test.cc | 4 +- googlemock/test/gmock-internal-utils_test.cc | 6 +- googlemock/test/gmock-matchers_test.cc | 124 ++++++++--------- googlemock/test/gmock-more-actions_test.cc | 3 +- googlemock/test/gmock-spec-builders_test.cc | 6 +- googlemock/test/gmock_link_test.h | 38 +++--- googlemock/test/gmock_stress_test.cc | 8 +- googlemock/test/gmock_test.cc | 148 +++++---------------- 10 files changed, 144 insertions(+), 223 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 06e29a1e..7db5d3cb 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -89,9 +89,9 @@ using testing::SetErrnoAndReturn; // Tests that BuiltInDefaultValue::Get() returns NULL. TEST(BuiltInDefaultValueTest, IsNullForPointerTypes) { - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); } // Tests that BuiltInDefaultValue::Exists() return true. @@ -196,7 +196,7 @@ TEST(BuiltInDefaultValueTest, ExistsForString) { TEST(BuiltInDefaultValueTest, WorksForConstTypes) { EXPECT_EQ("", BuiltInDefaultValue::Get()); EXPECT_EQ(0, BuiltInDefaultValue::Get()); - EXPECT_TRUE(BuiltInDefaultValue::Get() == NULL); + EXPECT_TRUE(BuiltInDefaultValue::Get() == nullptr); EXPECT_FALSE(BuiltInDefaultValue::Get()); } @@ -306,7 +306,7 @@ TEST(DefaultValueDeathTest, GetReturnsBuiltInDefaultValueWhenUnset) { #if GTEST_HAS_STD_UNIQUE_PTR_ TEST(DefaultValueTest, GetWorksForMoveOnlyIfSet) { EXPECT_TRUE(DefaultValue>::Exists()); - EXPECT_TRUE(DefaultValue>::Get() == NULL); + EXPECT_TRUE(DefaultValue>::Get() == nullptr); DefaultValue>::SetFactory([] { return std::unique_ptr(new int(42)); }); @@ -519,7 +519,7 @@ TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) { EXPECT_EQ(0, a1.Perform(make_tuple())); Action a2 = ReturnZeroFromNullaryFunction(); - EXPECT_TRUE(a2.Perform(make_tuple()) == NULL); + EXPECT_TRUE(a2.Perform(make_tuple()) == nullptr); } // Tests that Return() works as an action for void-returning @@ -636,10 +636,10 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) { // Tests that ReturnNull() returns NULL in a pointer-returning function. TEST(ReturnNullTest, WorksInPointerReturningFunction) { const Action a1 = ReturnNull(); - EXPECT_TRUE(a1.Perform(make_tuple()) == NULL); + EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr); const Action a2 = ReturnNull(); // NOLINT - EXPECT_TRUE(a2.Perform(make_tuple(true)) == NULL); + EXPECT_TRUE(a2.Perform(make_tuple(true)) == nullptr); } #if GTEST_HAS_STD_UNIQUE_PTR_ @@ -819,10 +819,10 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { typedef void MyFunction(std::string*, const char**); Action a = SetArgPointee<0>("hi"); std::string str; - const char* ptr = NULL; + const char* ptr = nullptr; a.Perform(make_tuple(&str, &ptr)); EXPECT_EQ("hi", str); - EXPECT_TRUE(ptr == NULL); + EXPECT_TRUE(ptr == nullptr); a = SetArgPointee<1>("world"); str = ""; @@ -834,7 +834,7 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { typedef void MyFunction(const wchar_t**); Action a = SetArgPointee<0>(L"world"); - const wchar_t* ptr = NULL; + const wchar_t* ptr = nullptr; a.Perform(make_tuple(&ptr)); EXPECT_STREQ(L"world", ptr); @@ -856,10 +856,10 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { const char* const hi = "hi"; Action a = SetArgPointee<1>(hi); std::string str; - const char* ptr = NULL; + const char* ptr = nullptr; a.Perform(make_tuple(true, &str, &ptr)); EXPECT_EQ("hi", str); - EXPECT_TRUE(ptr == NULL); + EXPECT_TRUE(ptr == nullptr); char world_array[] = "world"; char* const world = world_array; @@ -874,7 +874,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { typedef void MyFunction(bool, const wchar_t**); const wchar_t* const hi = L"hi"; Action a = SetArgPointee<1>(hi); - const wchar_t* ptr = NULL; + const wchar_t* ptr = nullptr; a.Perform(make_tuple(true, &ptr)); EXPECT_EQ(hi, ptr); diff --git a/googlemock/test/gmock-generated-function-mockers_test.cc b/googlemock/test/gmock-generated-function-mockers_test.cc index 4c490694..820a2b69 100644 --- a/googlemock/test/gmock-generated-function-mockers_test.cc +++ b/googlemock/test/gmock-generated-function-mockers_test.cc @@ -228,7 +228,7 @@ TEST_F(FunctionMockerTest, MocksDecimalFunction) { Lt(100), 5U, NULL, "hi")) .WillOnce(Return(5)); - EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, NULL, "hi")); + EXPECT_EQ(5, foo_->Decimal(true, 'a', 0, 0, 1, 0, 0, 5, nullptr, "hi")); } // Tests mocking a function that takes a non-const reference. diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 0ebd4701..10a4ac39 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -697,7 +697,7 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) { // Pointers are iterators, too. EXPECT_THAT(test_vector, ElementsAreArray(a, a + GTEST_ARRAY_SIZE_(a))); // The empty range of NULL pointers should also be okay. - int* const null_int = NULL; + int* const null_int = nullptr; EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int))); EXPECT_THAT((vector()), ElementsAreArray(null_int, null_int)); } @@ -770,7 +770,7 @@ MATCHER_P2(EqSumOf, x, y, std::string(negation ? "doesn't equal" : "equals") + } else { // Verifies that we can stream to the underlying stream of // result_listener. - if (result_listener->stream() != NULL) { + if (result_listener->stream() != nullptr) { *result_listener->stream() << "diff == " << (x + y - arg); } return false; diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 5f53077c..7116e4fc 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -158,9 +158,9 @@ TEST(GetRawPointerTest, WorksForSmartPointers) { } TEST(GetRawPointerTest, WorksForRawPointers) { - int* p = NULL; + int* p = nullptr; // Don't use EXPECT_EQ as no NULL-testing magic on Symbian. - EXPECT_TRUE(NULL == GetRawPointer(p)); + EXPECT_TRUE(nullptr == GetRawPointer(p)); int n = 1; EXPECT_EQ(&n, GetRawPointer(&n)); } @@ -492,7 +492,7 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) { AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10))); // Restores the default OS stack trace getter. - GetUnitTestImpl()->set_os_stack_trace_getter(NULL); + GetUnitTestImpl()->set_os_stack_trace_getter(nullptr); } // Tests that all logs are printed when the value of the diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 79eb552e..ceff5b08 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -238,8 +238,8 @@ TEST(MatchResultListenerTest, StreamingWorks) { } TEST(MatchResultListenerTest, CanAccessUnderlyingStream) { - EXPECT_TRUE(DummyMatchResultListener().stream() == NULL); - EXPECT_TRUE(StreamMatchResultListener(NULL).stream() == NULL); + EXPECT_TRUE(DummyMatchResultListener().stream() == nullptr); + EXPECT_TRUE(StreamMatchResultListener(nullptr).stream() == nullptr); EXPECT_EQ(&std::cout, StreamMatchResultListener(&std::cout).stream()); } @@ -249,7 +249,7 @@ TEST(MatchResultListenerTest, IsInterestedWorks) { EXPECT_TRUE(StreamMatchResultListener(&std::cout).IsInterested()); EXPECT_FALSE(DummyMatchResultListener().IsInterested()); - EXPECT_FALSE(StreamMatchResultListener(NULL).IsInterested()); + EXPECT_FALSE(StreamMatchResultListener(nullptr).IsInterested()); } // Makes sure that the MatcherInterface interface doesn't @@ -283,7 +283,7 @@ class NewEvenMatcherImpl : public MatcherInterface { const bool match = x % 2 == 0; // Verifies that we can stream to a listener directly. *listener << "value % " << 2; - if (listener->stream() != NULL) { + if (listener->stream() != nullptr) { // Verifies that we can stream to a listener's underlying stream // too. *listener->stream() << " == " << (x % 2); @@ -327,7 +327,7 @@ TEST(MatcherTest, CanBeImplicitlyConstructedFromValue) { // Tests that NULL can be used in place of Eq(NULL). TEST(MatcherTest, CanBeImplicitlyConstructedFromNULL) { Matcher m1 = NULL; - EXPECT_TRUE(m1.Matches(NULL)); + EXPECT_TRUE(m1.Matches(nullptr)); int n = 0; EXPECT_FALSE(m1.Matches(&n)); } @@ -512,7 +512,7 @@ TEST(StringViewMatcherTest, CanBeImplicitlyConstructedFromStringView) { // MatcherInterface* without requiring the user to explicitly // write the type. TEST(MakeMatcherTest, ConstructsMatcherFromMatcherInterface) { - const MatcherInterface* dummy_impl = NULL; + const MatcherInterface* dummy_impl = nullptr; Matcher m = MakeMatcher(dummy_impl); } @@ -571,7 +571,7 @@ class PolymorphicIsEvenImpl { bool MatchAndExplain(const T& x, MatchResultListener* listener) const { // Verifies that we can stream to the listener directly. *listener << "% " << 2; - if (listener->stream() != NULL) { + if (listener->stream() != nullptr) { // Verifies that we can stream to the listener's underlying stream // too. *listener->stream() << " == " << (x % 2); @@ -1154,13 +1154,13 @@ TEST(NeTest, CanDescribeSelf) { // Tests that IsNull() matches any NULL pointer of any type. TEST(IsNullTest, MatchesNullPointer) { Matcher m1 = IsNull(); - int* p1 = NULL; + int* p1 = nullptr; int n = 0; EXPECT_TRUE(m1.Matches(p1)); EXPECT_FALSE(m1.Matches(&n)); Matcher m2 = IsNull(); - const char* p2 = NULL; + const char* p2 = nullptr; EXPECT_TRUE(m2.Matches(p2)); EXPECT_FALSE(m2.Matches("hi")); @@ -1174,7 +1174,7 @@ TEST(IsNullTest, MatchesNullPointer) { // gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()') // gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc Matcher m3 = IsNull(); - void* p3 = NULL; + void* p3 = nullptr; EXPECT_TRUE(m3.Matches(p3)); EXPECT_FALSE(m3.Matches(reinterpret_cast(0xbeef))); #endif @@ -1217,13 +1217,13 @@ TEST(IsNullTest, CanDescribeSelf) { // Tests that NotNull() matches any non-NULL pointer of any type. TEST(NotNullTest, MatchesNonNullPointer) { Matcher m1 = NotNull(); - int* p1 = NULL; + int* p1 = nullptr; int n = 0; EXPECT_FALSE(m1.Matches(p1)); EXPECT_TRUE(m1.Matches(&n)); Matcher m2 = NotNull(); - const char* p2 = NULL; + const char* p2 = nullptr; EXPECT_FALSE(m2.Matches(p2)); EXPECT_TRUE(m2.Matches("hi")); } @@ -1324,7 +1324,7 @@ TEST(StrEqTest, MatchesEqualString) { Matcher m = StrEq(std::string("Hello")); EXPECT_TRUE(m.Matches("Hello")); EXPECT_FALSE(m.Matches("hello")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrEq("Hello"); EXPECT_TRUE(m2.Matches("Hello")); @@ -1360,7 +1360,7 @@ TEST(StrEqTest, CanDescribeSelf) { TEST(StrNeTest, MatchesUnequalString) { Matcher m = StrNe("Hello"); EXPECT_TRUE(m.Matches("")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches("Hello")); Matcher m2 = StrNe(std::string("Hello")); @@ -1385,7 +1385,7 @@ TEST(StrCaseEqTest, MatchesEqualStringIgnoringCase) { EXPECT_TRUE(m.Matches("Hello")); EXPECT_TRUE(m.Matches("hello")); EXPECT_FALSE(m.Matches("Hi")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrCaseEq("Hello"); EXPECT_TRUE(m2.Matches("hello")); @@ -1433,7 +1433,7 @@ TEST(StrCaseEqTest, CanDescribeSelf) { TEST(StrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m = StrCaseNe("Hello"); EXPECT_TRUE(m.Matches("Hi")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches("Hello")); EXPECT_FALSE(m.Matches("hello")); @@ -1475,17 +1475,17 @@ TEST(HasSubstrTest, WorksForCStrings) { const Matcher m1 = HasSubstr("foo"); EXPECT_TRUE(m1.Matches(const_cast("I love food."))); EXPECT_FALSE(m1.Matches(const_cast("tofo"))); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = HasSubstr("foo"); EXPECT_TRUE(m2.Matches("I love food.")); EXPECT_FALSE(m2.Matches("tofo")); - EXPECT_FALSE(m2.Matches(NULL)); + EXPECT_FALSE(m2.Matches(nullptr)); const Matcher m_empty = HasSubstr(""); EXPECT_TRUE(m_empty.Matches("not empty")); EXPECT_TRUE(m_empty.Matches("")); - EXPECT_FALSE(m_empty.Matches(NULL)); + EXPECT_FALSE(m_empty.Matches(nullptr)); } #if GTEST_HAS_ABSL @@ -1720,7 +1720,7 @@ TEST(StartsWithTest, MatchesStringWithGivenPrefix) { const Matcher m1 = StartsWith(std::string("")); EXPECT_TRUE(m1.Matches("Hi")); EXPECT_TRUE(m1.Matches("")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = StartsWith("Hi"); EXPECT_TRUE(m2.Matches("Hi")); @@ -1748,7 +1748,7 @@ TEST(EndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m1 = EndsWith(""); EXPECT_TRUE(m1.Matches("Hi")); EXPECT_TRUE(m1.Matches("")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = EndsWith(std::string("Hi")); EXPECT_TRUE(m2.Matches("Hi")); @@ -1786,7 +1786,7 @@ TEST(MatchesRegexTest, MatchesStringMatchingGivenRegex) { const Matcher m1 = MatchesRegex("a.*z"); EXPECT_TRUE(m1.Matches("az")); EXPECT_TRUE(m1.Matches("abcz")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = MatchesRegex(new RE("a.*z")); EXPECT_TRUE(m2.Matches("azbz")); @@ -1824,7 +1824,7 @@ TEST(ContainsRegexTest, MatchesStringContainingGivenRegex) { const Matcher m1 = ContainsRegex(std::string("a.*z")); EXPECT_TRUE(m1.Matches("az")); EXPECT_TRUE(m1.Matches("0abcz1")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = ContainsRegex(new RE("a.*z")); EXPECT_TRUE(m2.Matches("azbz")); @@ -1862,7 +1862,7 @@ TEST(StdWideStrEqTest, MatchesEqual) { Matcher m = StrEq(::std::wstring(L"Hello")); EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"Hello")); @@ -1902,7 +1902,7 @@ TEST(StdWideStrEqTest, CanDescribeSelf) { TEST(StdWideStrNeTest, MatchesUnequalString) { Matcher m = StrNe(L"Hello"); EXPECT_TRUE(m.Matches(L"")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); Matcher< ::std::wstring> m2 = StrNe(::std::wstring(L"Hello")); @@ -1920,7 +1920,7 @@ TEST(StdWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_TRUE(m.Matches(L"hello")); EXPECT_FALSE(m.Matches(L"Hi")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrCaseEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"hello")); @@ -1960,7 +1960,7 @@ TEST(StdWideStrCaseEqTest, CanDescribeSelf) { TEST(StdWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m = StrCaseNe(L"Hello"); EXPECT_TRUE(m.Matches(L"Hi")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); @@ -1990,12 +1990,12 @@ TEST(StdWideHasSubstrTest, WorksForCStrings) { const Matcher m1 = HasSubstr(L"foo"); EXPECT_TRUE(m1.Matches(const_cast(L"I love food."))); EXPECT_FALSE(m1.Matches(const_cast(L"tofo"))); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = HasSubstr(L"foo"); EXPECT_TRUE(m2.Matches(L"I love food.")); EXPECT_FALSE(m2.Matches(L"tofo")); - EXPECT_FALSE(m2.Matches(NULL)); + EXPECT_FALSE(m2.Matches(nullptr)); } // Tests that HasSubstr(s) describes itself properly. @@ -2010,7 +2010,7 @@ TEST(StdWideStartsWithTest, MatchesStringWithGivenPrefix) { const Matcher m1 = StartsWith(::std::wstring(L"")); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = StartsWith(L"Hi"); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -2031,7 +2031,7 @@ TEST(StdWideEndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m1 = EndsWith(L""); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = EndsWith(::std::wstring(L"Hi")); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -2053,7 +2053,7 @@ TEST(GlobalWideStrEqTest, MatchesEqual) { Matcher m = StrEq(::wstring(L"Hello")); EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"Hello")); @@ -2093,7 +2093,7 @@ TEST(GlobalWideStrEqTest, CanDescribeSelf) { TEST(GlobalWideStrNeTest, MatchesUnequalString) { Matcher m = StrNe(L"Hello"); EXPECT_TRUE(m.Matches(L"")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); Matcher< ::wstring> m2 = StrNe(::wstring(L"Hello")); @@ -2111,7 +2111,7 @@ TEST(GlobalWideStrCaseEqTest, MatchesEqualStringIgnoringCase) { EXPECT_TRUE(m.Matches(L"Hello")); EXPECT_TRUE(m.Matches(L"hello")); EXPECT_FALSE(m.Matches(L"Hi")); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); Matcher m2 = StrCaseEq(L"Hello"); EXPECT_TRUE(m2.Matches(L"hello")); @@ -2151,7 +2151,7 @@ TEST(GlobalWideStrCaseEqTest, CanDescribeSelf) { TEST(GlobalWideStrCaseNeTest, MatchesUnequalStringIgnoringCase) { Matcher m = StrCaseNe(L"Hello"); EXPECT_TRUE(m.Matches(L"Hi")); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); EXPECT_FALSE(m.Matches(L"Hello")); EXPECT_FALSE(m.Matches(L"hello")); @@ -2181,12 +2181,12 @@ TEST(GlobalWideHasSubstrTest, WorksForCStrings) { const Matcher m1 = HasSubstr(L"foo"); EXPECT_TRUE(m1.Matches(const_cast(L"I love food."))); EXPECT_FALSE(m1.Matches(const_cast(L"tofo"))); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = HasSubstr(L"foo"); EXPECT_TRUE(m2.Matches(L"I love food.")); EXPECT_FALSE(m2.Matches(L"tofo")); - EXPECT_FALSE(m2.Matches(NULL)); + EXPECT_FALSE(m2.Matches(nullptr)); } // Tests that HasSubstr(s) describes itself properly. @@ -2201,7 +2201,7 @@ TEST(GlobalWideStartsWithTest, MatchesStringWithGivenPrefix) { const Matcher m1 = StartsWith(::wstring(L"")); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = StartsWith(L"Hi"); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -2222,7 +2222,7 @@ TEST(GlobalWideEndsWithTest, MatchesStringWithGivenSuffix) { const Matcher m1 = EndsWith(L""); EXPECT_TRUE(m1.Matches(L"Hi")); EXPECT_TRUE(m1.Matches(L"")); - EXPECT_FALSE(m1.Matches(NULL)); + EXPECT_FALSE(m1.Matches(nullptr)); const Matcher m2 = EndsWith(::wstring(L"Hi")); EXPECT_TRUE(m2.Matches(L"Hi")); @@ -3701,7 +3701,7 @@ TEST(PointeeTest, RawPointer) { EXPECT_TRUE(m.Matches(&n)); n = -1; EXPECT_FALSE(m.Matches(&n)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, RawPointerToConst) { @@ -3711,7 +3711,7 @@ TEST(PointeeTest, RawPointerToConst) { EXPECT_TRUE(m.Matches(&x)); x = -1; EXPECT_FALSE(m.Matches(&x)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, ReferenceToConstRawPointer) { @@ -3721,7 +3721,7 @@ TEST(PointeeTest, ReferenceToConstRawPointer) { EXPECT_TRUE(m.Matches(&n)); n = -1; EXPECT_FALSE(m.Matches(&n)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, ReferenceToNonConstRawPointer) { @@ -3732,7 +3732,7 @@ TEST(PointeeTest, ReferenceToNonConstRawPointer) { EXPECT_TRUE(m.Matches(p)); x = -1; EXPECT_FALSE(m.Matches(p)); - p = NULL; + p = nullptr; EXPECT_FALSE(m.Matches(p)); } @@ -3771,7 +3771,7 @@ TEST(WhenDynamicCastToTest, WrongTypes) { TEST(WhenDynamicCastToTest, AlreadyNull) { // Already NULL. - Base* as_base_ptr = NULL; + Base* as_base_ptr = nullptr; EXPECT_THAT(as_base_ptr, WhenDynamicCastTo(IsNull())); } @@ -3807,7 +3807,7 @@ TEST(WhenDynamicCastToTest, Describe) { TEST(WhenDynamicCastToTest, Explain) { Matcher matcher = WhenDynamicCastTo(Pointee(_)); - Base* null = NULL; + Base* null = nullptr; EXPECT_THAT(Explain(matcher, null), HasSubstr("NULL")); Derived derived; EXPECT_TRUE(matcher.Matches(&derived)); @@ -3868,7 +3868,7 @@ TEST(PointeeTest, WorksWithConstPropagatingPointers) { TEST(PointeeTest, NeverMatchesNull) { const Matcher m = Pointee(_); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } // Tests that we can write Pointee(value) instead of Pointee(Eq(value)). @@ -3879,7 +3879,7 @@ TEST(PointeeTest, MatchesAgainstAValue) { EXPECT_TRUE(m.Matches(&n)); n = -1; EXPECT_FALSE(m.Matches(&n)); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } TEST(PointeeTest, CanDescribeSelf) { @@ -3892,7 +3892,7 @@ TEST(PointeeTest, CanDescribeSelf) { TEST(PointeeTest, CanExplainMatchResult) { const Matcher m = Pointee(StartsWith("Hi")); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); const Matcher m2 = Pointee(GreaterThan(1)); // NOLINT long n = 3; // NOLINT @@ -3929,7 +3929,7 @@ MATCHER_P(UncopyableIs, inner_matcher, "") { // A user-defined struct for testing Field(). struct AStruct { - AStruct() : x(0), y(1.0), z(5), p(NULL) {} + AStruct() : x(0), y(1.0), z(5), p(nullptr) {} AStruct(const AStruct& rhs) : x(rhs.x), y(rhs.y), z(rhs.z.value()), p(rhs.p) {} @@ -3990,7 +3990,7 @@ TEST(FieldTest, WorksForUncopyableField) { // Tests that Field(&Foo::field, ...) works when field is a pointer. TEST(FieldTest, WorksForPointerField) { // Matching against NULL. - Matcher m = Field(&AStruct::p, static_cast(NULL)); + Matcher m = Field(&AStruct::p, static_cast(nullptr)); AStruct a; EXPECT_TRUE(m.Matches(a)); a.p = "hi"; @@ -4116,7 +4116,7 @@ TEST(FieldForPointerTest, WorksForReferenceToConstPointer) { // Tests that Field() does not match the NULL pointer. TEST(FieldForPointerTest, DoesNotMatchNull) { Matcher m = Field(&AStruct::x, _); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } // Tests that Field(&Foo::field, ...) works when the argument's type @@ -4154,7 +4154,7 @@ TEST(FieldForPointerTest, CanExplainMatchResult) { AStruct a; a.x = 1; - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ("which points to an object whose given field is 1" + OfType("int"), Explain(m, &a)); @@ -4168,7 +4168,7 @@ TEST(FieldForPointerTest, CanExplainMatchResultWithFieldName) { AStruct a; a.x = 1; - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ( "which points to an object whose field `field_name` is 1" + OfType("int"), Explain(m, &a)); @@ -4413,7 +4413,7 @@ TEST(PropertyForPointerTest, WorksForReferenceToConstPointer) { // Tests that Property() does not match the NULL pointer. TEST(PropertyForPointerTest, WorksForReferenceToNonConstProperty) { Matcher m = Property(&AClass::x, _); - EXPECT_FALSE(m.Matches(NULL)); + EXPECT_FALSE(m.Matches(nullptr)); } // Tests that Property(&Foo::property, ...) works when the argument's @@ -4454,7 +4454,7 @@ TEST(PropertyForPointerTest, CanExplainMatchResult) { AClass a; a.set_n(1); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ( "which points to an object whose given property is 1" + OfType("int"), Explain(m, &a)); @@ -4470,7 +4470,7 @@ TEST(PropertyForPointerTest, CanExplainMatchResultWithPropertyName) { AClass a; a.set_n(1); - EXPECT_EQ("", Explain(m, static_cast(NULL))); + EXPECT_EQ("", Explain(m, static_cast(nullptr))); EXPECT_EQ("which points to an object whose property `fancy_name` is 1" + OfType("int"), Explain(m, &a)); @@ -4581,7 +4581,7 @@ TEST(ResultOfTest, WorksForCompatibleMatcherTypes) { // a NULL function pointer. TEST(ResultOfDeathTest, DiesOnNullFunctionPointers) { EXPECT_DEATH_IF_SUPPORTED( - ResultOf(static_cast(NULL), + ResultOf(static_cast(nullptr), Eq(std::string("foo"))), "NULL function pointer is passed into ResultOf\\(\\)\\."); } @@ -6181,7 +6181,7 @@ TEST_P(BipartiteRandomTest, LargerNets) { testing::internal::Int32 seed = GTEST_FLAG(random_seed); if (seed == 0) { - seed = static_cast(time(NULL)); + seed = static_cast(time(nullptr)); } for (; iters > 0; --iters, ++seed) { @@ -6684,7 +6684,7 @@ class SampleVariantIntString { template friend const T& get(const SampleVariantIntString& value) { - return value.get_impl(static_cast(NULL)); + return value.get_impl(static_cast(nullptr)); } private: @@ -6743,7 +6743,7 @@ class SampleAnyType { template friend const T* any_cast(const SampleAnyType* any) { - return any->get_impl(static_cast(NULL)); + return any->get_impl(static_cast(nullptr)); } private: @@ -6751,9 +6751,9 @@ class SampleAnyType { int i_; std::string s_; - const int* get_impl(int*) const { return index_ == 0 ? &i_ : NULL; } + const int* get_impl(int*) const { return index_ == 0 ? &i_ : nullptr; } const std::string* get_impl(std::string*) const { - return index_ == 1 ? &s_ : NULL; + return index_ == 1 ? &s_ : nullptr; } }; diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 08a2df09..976b245e 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -333,7 +333,8 @@ TEST(InvokeTest, FunctionWithUnusedParameters) { Action a2 = Invoke(SumOfFirst2); - EXPECT_EQ(23, a2.Perform(make_tuple(20, 3, true, static_cast(NULL)))); + EXPECT_EQ(23, + a2.Perform(make_tuple(20, 3, true, static_cast(nullptr)))); } // Tests using Invoke() with methods with parameters declared as Unused. diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 7056c43c..65c9fcc4 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -2041,7 +2041,7 @@ TEST(FunctionCallMessageTest, GMOCK_FLAG(verbose) = kWarningVerbosity; NaggyMock c; CaptureStdout(); - c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); + c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); const std::string output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output); EXPECT_PRED_FORMAT2(IsNotSubstring, "Stack trace:", output); @@ -2055,7 +2055,7 @@ TEST(FunctionCallMessageTest, GMOCK_FLAG(verbose) = kInfoVerbosity; NaggyMock c; CaptureStdout(); - c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); + c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); const std::string output = GetCapturedStdout(); EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", output); EXPECT_PRED_FORMAT2(IsSubstring, "Stack trace:", output); @@ -2098,7 +2098,7 @@ TEST(FunctionCallMessageTest, // A void mock function. NaggyMock c; CaptureStdout(); - c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable()); + c.VoidMethod(false, 5, "Hi", nullptr, Printable(), Unprintable()); const std::string output2 = GetCapturedStdout(); EXPECT_THAT(output2.c_str(), ContainsRegex( diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index d26670ec..e85f7502 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -248,7 +248,7 @@ TEST(LinkTest, TestReturnVoid) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return()); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the Return action. @@ -257,7 +257,7 @@ TEST(LinkTest, TestReturn) { char ch = 'x'; EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch)); - mock.StringFromString(NULL); + mock.StringFromString(nullptr); } // Tests the linkage of the ReturnNull action. @@ -265,7 +265,7 @@ TEST(LinkTest, TestReturnNull) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return()); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the ReturnRef action. @@ -274,7 +274,7 @@ TEST(LinkTest, TestReturnRef) { int n = 42; EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n)); - mock.IntRefFromString(NULL); + mock.IntRefFromString(nullptr); } // Tests the linkage of the Assign action. @@ -283,7 +283,7 @@ TEST(LinkTest, TestAssign) { char ch = 'x'; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y')); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the SetArgPointee action. @@ -314,7 +314,7 @@ TEST(LinkTest, TestSetErrnoAndReturn) { int saved_errno = errno; EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1)); - mock.IntFromString(NULL); + mock.IntFromString(nullptr); errno = saved_errno; } @@ -328,8 +328,8 @@ TEST(LinkTest, TestInvoke) { EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString)) .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString)); - mock.VoidFromString(NULL); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); + mock.VoidFromString(nullptr); } // Tests the linkage of the InvokeWithoutArgs action. @@ -341,8 +341,8 @@ TEST(LinkTest, TestInvokeWithoutArgs) { .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid)) .WillOnce(InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid)); - mock.VoidFromString(NULL); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); + mock.VoidFromString(nullptr); } // Tests the linkage of the InvokeArgument action. @@ -360,7 +360,7 @@ TEST(LinkTest, TestWithArg) { EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString))); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the WithArgs action. @@ -369,7 +369,7 @@ TEST(LinkTest, TestWithArgs) { EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString))); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the WithoutArgs action. @@ -377,7 +377,7 @@ TEST(LinkTest, TestWithoutArgs) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return())); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } // Tests the linkage of the DoAll action. @@ -405,7 +405,7 @@ TEST(LinkTest, TestIgnoreResult) { Mock mock; EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42))); - mock.VoidFromString(NULL); + mock.VoidFromString(nullptr); } #if GTEST_HAS_EXCEPTIONS @@ -437,7 +437,7 @@ TEST(LinkTest, TestActionMacro) { Mock mock; EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1()); - mock.IntFromString(NULL); + mock.IntFromString(nullptr); } // Tests the linkage of actions created using ACTION_P macro. @@ -449,7 +449,7 @@ TEST(LinkTest, TestActionPMacro) { Mock mock; EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42)); - mock.IntFromString(NULL); + mock.IntFromString(nullptr); } // Tests the linkage of actions created using ACTION_P2 macro. @@ -646,7 +646,7 @@ TEST(LinkTest, TestMatcherProperty) { // Tests the linkage of the ResultOf matcher. TEST(LinkTest, TestMatcherResultOf) { Matcher m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1)); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); } // Tests the linkage of the ResultOf matcher. @@ -660,7 +660,7 @@ TEST(LinkTest, TestMatcherPointee) { // Tests the linkage of the Truly matcher. TEST(LinkTest, TestMatcherTruly) { Matcher m = Truly(&InvokeHelper::StaticBoolFromString); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); } // Tests the linkage of the AllOf matcher. @@ -684,7 +684,7 @@ TEST(LinkTest, TestMatcherNot) { // Tests the linkage of the MatcherCast() function. TEST(LinkTest, TestMatcherCast) { Matcher m = MatcherCast(_); - EXPECT_TRUE(m.Matches(NULL)); + EXPECT_TRUE(m.Matches(nullptr)); } #endif // GMOCK_TEST_GMOCK_LINK_TEST_H_ diff --git a/googlemock/test/gmock_stress_test.cc b/googlemock/test/gmock_stress_test.cc index 0d99bede..9ae0b1e5 100644 --- a/googlemock/test/gmock_stress_test.cc +++ b/googlemock/test/gmock_stress_test.cc @@ -210,7 +210,7 @@ void TestConcurrentCallsOnSameObject(Dummy /* dummy */) { int count1 = 0; const Helper1Param param = { &foo, &count1 }; ThreadWithParam* const t = - new ThreadWithParam(Helper1, param, NULL); + new ThreadWithParam(Helper1, param, nullptr); int count2 = 0; const Helper1Param param2 = { &foo, &count2 }; @@ -264,7 +264,7 @@ void TestPartiallyOrderedExpectationsWithThreads(Dummy /* dummy */) { foo.Bar(1); ThreadWithParam* const t = - new ThreadWithParam(Helper2, &foo, NULL); + new ThreadWithParam(Helper2, &foo, nullptr); Helper2(&foo); JoinAndDelete(t); @@ -288,8 +288,8 @@ TEST(StressTest, CanUseGMockWithThreads) { ThreadWithParam* threads[kTestThreads] = {}; for (int i = 0; i < kTestThreads; i++) { // Creates a thread to run the test function. - threads[i] = - new ThreadWithParam(test_routines[i % kRoutines], Dummy(), NULL); + threads[i] = new ThreadWithParam(test_routines[i % kRoutines], + Dummy(), nullptr); GTEST_LOG_(INFO) << "Thread #" << i << " running . . ."; } diff --git a/googlemock/test/gmock_test.cc b/googlemock/test/gmock_test.cc index 341a17da..e9840a33 100644 --- a/googlemock/test/gmock_test.cc +++ b/googlemock/test/gmock_test.cc @@ -64,59 +64,35 @@ void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N], } TEST(InitGoogleMockTest, ParsesInvalidCommandLine) { - const char* argv[] = { - NULL - }; + const char* argv[] = {nullptr}; - const char* new_argv[] = { - NULL - }; + const char* new_argv[] = {nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(InitGoogleMockTest, ParsesEmptyCommandLine) { - const char* argv[] = { - "foo.exe", - NULL - }; + const char* argv[] = {"foo.exe", nullptr}; - const char* new_argv[] = { - "foo.exe", - NULL - }; + const char* new_argv[] = {"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(InitGoogleMockTest, ParsesSingleFlag) { - const char* argv[] = { - "foo.exe", - "--gmock_verbose=info", - NULL - }; + const char* argv[] = {"foo.exe", "--gmock_verbose=info", nullptr}; - const char* new_argv[] = { - "foo.exe", - NULL - }; + const char* new_argv[] = {"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); } TEST(InitGoogleMockTest, ParsesMultipleFlags) { int old_default_behavior = GMOCK_FLAG(default_mock_behavior); - const wchar_t* argv[] = { - L"foo.exe", - L"--gmock_verbose=info", - L"--gmock_default_mock_behavior=2", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", + L"--gmock_default_mock_behavior=2", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); @@ -125,92 +101,52 @@ TEST(InitGoogleMockTest, ParsesMultipleFlags) { } TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) { - const char* argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - NULL - }; - - const char* new_argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - NULL - }; + const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; + + const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { - const char* argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - "--gmock_verbose=error", - NULL - }; - - const char* new_argv[] = { - "foo.exe", - "--non_gmock_flag=blah", - NULL - }; + const char* argv[] = {"foo.exe", "--non_gmock_flag=blah", + "--gmock_verbose=error", nullptr}; + + const char* new_argv[] = {"foo.exe", "--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, "error"); } TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) { - const wchar_t* argv[] = { - NULL - }; + const wchar_t* argv[] = {nullptr}; - const wchar_t* new_argv[] = { - NULL - }; + const wchar_t* new_argv[] = {nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) { - const wchar_t* argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", nullptr}; - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(WideInitGoogleMockTest, ParsesSingleFlag) { - const wchar_t* argv[] = { - L"foo.exe", - L"--gmock_verbose=info", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", nullptr}; - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); } TEST(WideInitGoogleMockTest, ParsesMultipleFlags) { int old_default_behavior = GMOCK_FLAG(default_mock_behavior); - const wchar_t* argv[] = { - L"foo.exe", - L"--gmock_verbose=info", - L"--gmock_default_mock_behavior=2", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info", + L"--gmock_default_mock_behavior=2", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", nullptr}; TestInitGoogleMock(argv, new_argv, "info"); EXPECT_EQ(2, GMOCK_FLAG(default_mock_behavior)); @@ -219,34 +155,18 @@ TEST(WideInitGoogleMockTest, ParsesMultipleFlags) { } TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) { - const wchar_t* argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose)); } TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) { - const wchar_t* argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - L"--gmock_verbose=error", - NULL - }; - - const wchar_t* new_argv[] = { - L"foo.exe", - L"--non_gmock_flag=blah", - NULL - }; + const wchar_t* argv[] = {L"foo.exe", L"--non_gmock_flag=blah", + L"--gmock_verbose=error", nullptr}; + + const wchar_t* new_argv[] = {L"foo.exe", L"--non_gmock_flag=blah", nullptr}; TestInitGoogleMock(argv, new_argv, "error"); } -- cgit v1.2.3 From fab35920ad7e709847a94175337b8674bea0f9ae Mon Sep 17 00:00:00 2001 From: misterg Date: Mon, 8 Oct 2018 10:30:02 -0400 Subject: Remove non-variadic pre C++11 AllOf PiperOrigin-RevId: 216183352 --- googlemock/test/gmock-matchers_test.cc | 95 +++++++++++++--------------------- 1 file changed, 37 insertions(+), 58 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index ceff5b08..c38be994 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2555,27 +2555,6 @@ TEST(AllOfTest, MatchesWhenAllMatch) { Ne(9), Ne(10))); } -#if GTEST_LANG_CXX11 -// Tests the variadic version of the AllOfMatcher. -TEST(AllOfTest, VariadicMatchesWhenAllMatch) { - // Make sure AllOf is defined in the right namespace and does not depend on - // ADL. - ::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)")); - 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), - Ne(16), Ne(17), Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), - Ne(23), Ne(24), Ne(25), Ne(26), Ne(27), Ne(28), Ne(29), - Ne(30), Ne(31), Ne(32), Ne(33), Ne(34), Ne(35), Ne(36), - Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), Ne(42), Ne(43), - Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), - Ne(50))); -} - -#endif // GTEST_LANG_CXX11 // Tests that AllOf(m1, ..., mn) describes itself properly. TEST(AllOfTest, CanDescribeSelf) { @@ -2584,59 +2563,59 @@ TEST(AllOfTest, CanDescribeSelf) { EXPECT_EQ("(is <= 2) and (is >= 1)", Describe(m)); m = AllOf(Gt(0), Ne(1), Ne(2)); - EXPECT_EQ("(is > 0) and " - "((isn't equal to 1) and " - "(isn't equal to 2))", - Describe(m)); - + std::string expected_descr1 = + "(is > 0) and (isn't equal to 1) and (isn't equal to 2)"; + EXPECT_EQ(expected_descr1, Describe(m)); m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); - EXPECT_EQ("((is > 0) and " - "(isn't equal to 1)) and " - "((isn't equal to 2) and " - "(isn't equal to 3))", - Describe(m)); - + std::string expected_descr2 = + "(is > 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't equal " + "to 3)"; + EXPECT_EQ(expected_descr2, Describe(m)); m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); - EXPECT_EQ("((is >= 0) and " - "(is < 10)) and " - "((isn't equal to 3) and " - "((isn't equal to 5) and " - "(isn't equal to 7)))", - Describe(m)); + std::string expected_descr3 = + "(is >= 0) and (is < 10) and (isn't equal to 3) and (isn't equal to 5) " + "and (isn't equal to 7)"; + EXPECT_EQ(expected_descr3, Describe(m)); } // Tests that AllOf(m1, ..., mn) describes its negation properly. TEST(AllOfTest, CanDescribeNegation) { Matcher m; m = AllOf(Le(2), Ge(1)); - EXPECT_EQ("(isn't <= 2) or " - "(isn't >= 1)", - DescribeNegation(m)); + std::string expected_descr4 = "(isn't <= 2) or (isn't >= 1)"; + EXPECT_EQ(expected_descr4, DescribeNegation(m)); m = AllOf(Gt(0), Ne(1), Ne(2)); - EXPECT_EQ("(isn't > 0) or " - "((is equal to 1) or " - "(is equal to 2))", - DescribeNegation(m)); - + std::string expected_descr5 = + "(isn't > 0) or (is equal to 1) or (is equal to 2)"; + EXPECT_EQ(expected_descr5, DescribeNegation(m)); m = AllOf(Gt(0), Ne(1), Ne(2), Ne(3)); - EXPECT_EQ("((isn't > 0) or " - "(is equal to 1)) or " - "((is equal to 2) or " - "(is equal to 3))", - DescribeNegation(m)); - + std::string expected_descr6 = + "(isn't > 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)"; + EXPECT_EQ(expected_descr6, DescribeNegation(m)); m = AllOf(Ge(0), Lt(10), Ne(3), Ne(5), Ne(7)); - EXPECT_EQ("((isn't >= 0) or " - "(isn't < 10)) or " - "((is equal to 3) or " - "((is equal to 5) or " - "(is equal to 7)))", - DescribeNegation(m)); + std::string expected_desr7 = + "(isn't >= 0) or (isn't < 10) or (is equal to 3) or (is equal to 5) or " + "(is equal to 7)"; + EXPECT_EQ(expected_desr7, DescribeNegation(m)); + + m = AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), + Ne(10), Ne(11)); + AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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), Ne(16), Ne(17), + Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25), + Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33), + Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), + Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), + Ne(50))); } // Tests that monomorphic matchers are safely cast by the AllOf matcher. -- cgit v1.2.3 From 4ac07de8de545c8e907d3de273228de814f9c999 Mon Sep 17 00:00:00 2001 From: misterg Date: Mon, 8 Oct 2018 11:56:57 -0400 Subject: Fixing AllOfMatches test, where it properly belongs PiperOrigin-RevId: 216193701 --- googlemock/test/gmock-matchers_test.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index c38be994..6d432340 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2553,6 +2553,14 @@ TEST(AllOfTest, MatchesWhenAllMatch) { Ne(8), Ne(9))); AllOfMatches(10, AllOf(Ne(1), Ne(2), Ne(3), Ne(4), Ne(5), Ne(6), Ne(7), Ne(8), Ne(9), Ne(10))); + 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), Ne(16), Ne(17), + Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25), + Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33), + Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), + Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), + Ne(50))); } @@ -2608,14 +2616,6 @@ TEST(AllOfTest, CanDescribeNegation) { AllOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 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), Ne(16), Ne(17), - Ne(18), Ne(19), Ne(20), Ne(21), Ne(22), Ne(23), Ne(24), Ne(25), - Ne(26), Ne(27), Ne(28), Ne(29), Ne(30), Ne(31), Ne(32), Ne(33), - Ne(34), Ne(35), Ne(36), Ne(37), Ne(38), Ne(39), Ne(40), Ne(41), - Ne(42), Ne(43), Ne(44), Ne(45), Ne(46), Ne(47), Ne(48), Ne(49), - Ne(50))); } // Tests that monomorphic matchers are safely cast by the AllOf matcher. -- cgit v1.2.3 From 7d3b73c85a42811309eac26e5cbe054c40b64785 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 9 Oct 2018 14:50:26 -0400 Subject: Unconditionally use std::tuple. Remove all mention of TR1 tuple and our own implementation of tuple. PiperOrigin-RevId: 216395043 --- googlemock/test/gmock-actions_test.cc | 182 ++++++++--------- googlemock/test/gmock-generated-actions_test.cc | 223 ++++++++++----------- .../test/gmock-generated-internal-utils_test.cc | 40 ++-- googlemock/test/gmock-generated-matchers_test.cc | 82 ++++---- googlemock/test/gmock-internal-utils_test.cc | 43 ++-- googlemock/test/gmock-matchers_test.cc | 93 +++++---- googlemock/test/gmock-more-actions_test.cc | 162 ++++++++------- 7 files changed, 410 insertions(+), 415 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 7db5d3cb..0de84811 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -75,13 +75,9 @@ using testing::SetArgPointee; using testing::SetArgumentPointee; using testing::Unused; using testing::_; -using testing::get; using testing::internal::BuiltInDefaultValue; using testing::internal::Int64; using testing::internal::UInt64; -using testing::make_tuple; -using testing::tuple; -using testing::tuple_element; #if !GTEST_OS_WINDOWS_MOBILE using testing::SetErrnoAndReturn; @@ -382,8 +378,8 @@ typedef int MyGlobalFunction(bool, int); class MyActionImpl : public ActionInterface { public: - virtual int Perform(const tuple& args) { - return get<0>(args) ? get<1>(args) : 0; + virtual int Perform(const std::tuple& args) { + return std::get<0>(args) ? std::get<1>(args) : 0; } }; @@ -399,8 +395,8 @@ TEST(ActionInterfaceTest, MakeAction) { // it a tuple whose size and type are compatible with F's argument // types. For example, if F is int(), then Perform() takes a // 0-tuple; if F is void(bool, int), then Perform() takes a - // tuple, and so on. - EXPECT_EQ(5, action.Perform(make_tuple(true, 5))); + // std::tuple, and so on. + EXPECT_EQ(5, action.Perform(std::make_tuple(true, 5))); } // Tests that Action can be contructed from a pointer to @@ -413,8 +409,8 @@ TEST(ActionTest, CanBeConstructedFromActionInterface) { TEST(ActionTest, DelegatesWorkToActionInterface) { const Action action(new MyActionImpl); - EXPECT_EQ(5, action.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, action.Perform(make_tuple(false, 1))); + EXPECT_EQ(5, action.Perform(std::make_tuple(true, 5))); + EXPECT_EQ(0, action.Perform(std::make_tuple(false, 1))); } // Tests that Action can be copied. @@ -423,22 +419,22 @@ TEST(ActionTest, IsCopyable) { Action a2(a1); // Tests the copy constructor. // a1 should continue to work after being copied from. - EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a1.Perform(make_tuple(false, 1))); + EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 1))); // a2 should work like the action it was copied from. - EXPECT_EQ(5, a2.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a2.Perform(make_tuple(false, 1))); + EXPECT_EQ(5, a2.Perform(std::make_tuple(true, 5))); + EXPECT_EQ(0, a2.Perform(std::make_tuple(false, 1))); a2 = a1; // Tests the assignment operator. // a1 should continue to work after being copied from. - EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a1.Perform(make_tuple(false, 1))); + EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 1))); // a2 should work like the action it was copied from. - EXPECT_EQ(5, a2.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a2.Perform(make_tuple(false, 1))); + EXPECT_EQ(5, a2.Perform(std::make_tuple(true, 5))); + EXPECT_EQ(0, a2.Perform(std::make_tuple(false, 1))); } // Tests that an Action object can be converted to a @@ -446,8 +442,8 @@ TEST(ActionTest, IsCopyable) { class IsNotZero : public ActionInterface { // NOLINT public: - virtual bool Perform(const tuple& arg) { - return get<0>(arg) != 0; + virtual bool Perform(const std::tuple& arg) { + return std::get<0>(arg) != 0; } }; @@ -460,8 +456,8 @@ class IsNotZero : public ActionInterface { // NOLINT TEST(ActionTest, CanBeConvertedToOtherActionType) { const Action a1(new IsNotZero); // NOLINT const Action a2 = Action(a1); // NOLINT - EXPECT_EQ(1, a2.Perform(make_tuple('a'))); - EXPECT_EQ(0, a2.Perform(make_tuple('\0'))); + EXPECT_EQ(1, a2.Perform(std::make_tuple('a'))); + EXPECT_EQ(0, a2.Perform(std::make_tuple('\0'))); } #endif // !GTEST_OS_SYMBIAN @@ -475,7 +471,9 @@ class ReturnSecondArgumentAction { // polymorphic action whose Perform() method template is either // const or not. This lets us verify the non-const case. template - Result Perform(const ArgumentTuple& args) { return get<1>(args); } + Result Perform(const ArgumentTuple& args) { + return std::get<1>(args); + } }; // Implements a polymorphic action that can be used in a nullary @@ -490,7 +488,9 @@ class ReturnZeroFromNullaryFunctionAction { // polymorphic action whose Perform() method template is either // const or not. This lets us verify the const case. template - Result Perform(const tuple<>&) const { return 0; } + Result Perform(const std::tuple<>&) const { + return 0; + } }; // These functions verify that MakePolymorphicAction() returns a @@ -509,42 +509,42 @@ ReturnZeroFromNullaryFunction() { // implementation class into a polymorphic action. TEST(MakePolymorphicActionTest, ConstructsActionFromImpl) { Action a1 = ReturnSecondArgument(); // NOLINT - EXPECT_EQ(5, a1.Perform(make_tuple(false, 5, 2.0))); + EXPECT_EQ(5, a1.Perform(std::make_tuple(false, 5, 2.0))); } // Tests that MakePolymorphicAction() works when the implementation // class' Perform() method template has only one template parameter. TEST(MakePolymorphicActionTest, WorksWhenPerformHasOneTemplateParameter) { Action a1 = ReturnZeroFromNullaryFunction(); - EXPECT_EQ(0, a1.Perform(make_tuple())); + EXPECT_EQ(0, a1.Perform(std::make_tuple())); Action a2 = ReturnZeroFromNullaryFunction(); - EXPECT_TRUE(a2.Perform(make_tuple()) == nullptr); + EXPECT_TRUE(a2.Perform(std::make_tuple()) == nullptr); } // Tests that Return() works as an action for void-returning // functions. TEST(ReturnTest, WorksForVoid) { const Action ret = Return(); // NOLINT - return ret.Perform(make_tuple(1)); + return ret.Perform(std::make_tuple(1)); } // Tests that Return(v) returns v. TEST(ReturnTest, ReturnsGivenValue) { Action ret = Return(1); // NOLINT - EXPECT_EQ(1, ret.Perform(make_tuple())); + EXPECT_EQ(1, ret.Perform(std::make_tuple())); ret = Return(-5); - EXPECT_EQ(-5, ret.Perform(make_tuple())); + EXPECT_EQ(-5, ret.Perform(std::make_tuple())); } // Tests that Return("string literal") works. TEST(ReturnTest, AcceptsStringLiteral) { Action a1 = Return("Hello"); - EXPECT_STREQ("Hello", a1.Perform(make_tuple())); + EXPECT_STREQ("Hello", a1.Perform(std::make_tuple())); Action a2 = Return("world"); - EXPECT_EQ("world", a2.Perform(make_tuple())); + EXPECT_EQ("world", a2.Perform(std::make_tuple())); } // Test struct which wraps a vector of integers. Used in @@ -563,7 +563,7 @@ TEST(ReturnTest, SupportsWrapperReturnType) { // Return() called with 'v' as argument. The Action will return the same data // as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper. Action a = Return(v); - const std::vector& result = *(a.Perform(make_tuple()).v); + const std::vector& result = *(a.Perform(std::make_tuple()).v); EXPECT_THAT(result, ::testing::ElementsAre(0, 1, 2, 3, 4)); } @@ -581,10 +581,10 @@ TEST(ReturnTest, IsCovariant) { Base base; Derived derived; Action ret = Return(&base); - EXPECT_EQ(&base, ret.Perform(make_tuple())); + EXPECT_EQ(&base, ret.Perform(std::make_tuple())); ret = Return(&derived); - EXPECT_EQ(&derived, ret.Perform(make_tuple())); + EXPECT_EQ(&derived, ret.Perform(std::make_tuple())); } // Tests that the type of the value passed into Return is converted into T @@ -615,7 +615,7 @@ TEST(ReturnTest, ConvertsArgumentWhenConverted) { EXPECT_TRUE(converted) << "Return must convert its argument in its own " << "conversion operator."; converted = false; - action.Perform(tuple<>()); + action.Perform(std::tuple<>()); EXPECT_FALSE(converted) << "Action must NOT convert its argument " << "when performed."; } @@ -636,10 +636,10 @@ TEST(ReturnTest, CanConvertArgumentUsingNonConstTypeCastOperator) { // Tests that ReturnNull() returns NULL in a pointer-returning function. TEST(ReturnNullTest, WorksInPointerReturningFunction) { const Action a1 = ReturnNull(); - EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr); + EXPECT_TRUE(a1.Perform(std::make_tuple()) == nullptr); const Action a2 = ReturnNull(); // NOLINT - EXPECT_TRUE(a2.Perform(make_tuple(true)) == nullptr); + EXPECT_TRUE(a2.Perform(std::make_tuple(true)) == nullptr); } #if GTEST_HAS_STD_UNIQUE_PTR_ @@ -647,10 +647,10 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) { // functions. TEST(ReturnNullTest, WorksInSmartPointerReturningFunction) { const Action()> a1 = ReturnNull(); - EXPECT_TRUE(a1.Perform(make_tuple()) == nullptr); + EXPECT_TRUE(a1.Perform(std::make_tuple()) == nullptr); const Action(std::string)> a2 = ReturnNull(); - EXPECT_TRUE(a2.Perform(make_tuple("foo")) == nullptr); + EXPECT_TRUE(a2.Perform(std::make_tuple("foo")) == nullptr); } #endif // GTEST_HAS_STD_UNIQUE_PTR_ @@ -659,7 +659,7 @@ TEST(ReturnRefTest, WorksForReference) { const int n = 0; const Action ret = ReturnRef(n); // NOLINT - EXPECT_EQ(&n, &ret.Perform(make_tuple(true))); + EXPECT_EQ(&n, &ret.Perform(std::make_tuple(true))); } // Tests that ReturnRef(v) is covariant. @@ -667,10 +667,10 @@ TEST(ReturnRefTest, IsCovariant) { Base base; Derived derived; Action a = ReturnRef(base); - EXPECT_EQ(&base, &a.Perform(make_tuple())); + EXPECT_EQ(&base, &a.Perform(std::make_tuple())); a = ReturnRef(derived); - EXPECT_EQ(&derived, &a.Perform(make_tuple())); + EXPECT_EQ(&derived, &a.Perform(std::make_tuple())); } // Tests that ReturnRefOfCopy(v) works for reference types. @@ -678,12 +678,12 @@ TEST(ReturnRefOfCopyTest, WorksForReference) { int n = 42; const Action ret = ReturnRefOfCopy(n); - EXPECT_NE(&n, &ret.Perform(make_tuple())); - EXPECT_EQ(42, ret.Perform(make_tuple())); + EXPECT_NE(&n, &ret.Perform(std::make_tuple())); + EXPECT_EQ(42, ret.Perform(std::make_tuple())); n = 43; - EXPECT_NE(&n, &ret.Perform(make_tuple())); - EXPECT_EQ(42, ret.Perform(make_tuple())); + EXPECT_NE(&n, &ret.Perform(std::make_tuple())); + EXPECT_EQ(42, ret.Perform(std::make_tuple())); } // Tests that ReturnRefOfCopy(v) is covariant. @@ -691,10 +691,10 @@ TEST(ReturnRefOfCopyTest, IsCovariant) { Base base; Derived derived; Action a = ReturnRefOfCopy(base); - EXPECT_NE(&base, &a.Perform(make_tuple())); + EXPECT_NE(&base, &a.Perform(std::make_tuple())); a = ReturnRefOfCopy(derived); - EXPECT_NE(&derived, &a.Perform(make_tuple())); + EXPECT_NE(&derived, &a.Perform(std::make_tuple())); } // Tests that DoDefault() does the default action for the mock method. @@ -800,14 +800,14 @@ TEST(SetArgPointeeTest, SetsTheNthPointee) { int n = 0; char ch = '\0'; - a.Perform(make_tuple(true, &n, &ch)); + a.Perform(std::make_tuple(true, &n, &ch)); EXPECT_EQ(2, n); EXPECT_EQ('\0', ch); a = SetArgPointee<2>('a'); n = 0; ch = '\0'; - a.Perform(make_tuple(true, &n, &ch)); + a.Perform(std::make_tuple(true, &n, &ch)); EXPECT_EQ(0, n); EXPECT_EQ('a', ch); } @@ -820,13 +820,13 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) { Action a = SetArgPointee<0>("hi"); std::string str; const char* ptr = nullptr; - a.Perform(make_tuple(&str, &ptr)); + a.Perform(std::make_tuple(&str, &ptr)); EXPECT_EQ("hi", str); EXPECT_TRUE(ptr == nullptr); a = SetArgPointee<1>("world"); str = ""; - a.Perform(make_tuple(&str, &ptr)); + a.Perform(std::make_tuple(&str, &ptr)); EXPECT_EQ("", str); EXPECT_STREQ("world", ptr); } @@ -835,7 +835,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { typedef void MyFunction(const wchar_t**); Action a = SetArgPointee<0>(L"world"); const wchar_t* ptr = nullptr; - a.Perform(make_tuple(&ptr)); + a.Perform(std::make_tuple(&ptr)); EXPECT_STREQ(L"world", ptr); # if GTEST_HAS_STD_WSTRING @@ -843,7 +843,7 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) { typedef void MyStringFunction(std::wstring*); Action a2 = SetArgPointee<0>(L"world"); std::wstring str = L""; - a2.Perform(make_tuple(&str)); + a2.Perform(std::make_tuple(&str)); EXPECT_EQ(L"world", str); # endif @@ -857,7 +857,7 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { Action a = SetArgPointee<1>(hi); std::string str; const char* ptr = nullptr; - a.Perform(make_tuple(true, &str, &ptr)); + a.Perform(std::make_tuple(true, &str, &ptr)); EXPECT_EQ("hi", str); EXPECT_TRUE(ptr == nullptr); @@ -865,7 +865,7 @@ TEST(SetArgPointeeTest, AcceptsCharPointer) { char* const world = world_array; a = SetArgPointee<2>(world); str = ""; - a.Perform(make_tuple(true, &str, &ptr)); + a.Perform(std::make_tuple(true, &str, &ptr)); EXPECT_EQ("", str); EXPECT_EQ(world, ptr); } @@ -875,7 +875,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { const wchar_t* const hi = L"hi"; Action a = SetArgPointee<1>(hi); const wchar_t* ptr = nullptr; - a.Perform(make_tuple(true, &ptr)); + a.Perform(std::make_tuple(true, &ptr)); EXPECT_EQ(hi, ptr); # if GTEST_HAS_STD_WSTRING @@ -885,7 +885,7 @@ TEST(SetArgPointeeTest, AcceptsWideCharPointer) { wchar_t* const world = world_array; Action a2 = SetArgPointee<1>(world); std::wstring str; - a2.Perform(make_tuple(true, &str)); + a2.Perform(std::make_tuple(true, &str)); EXPECT_EQ(world_array, str); # endif } @@ -898,14 +898,14 @@ TEST(SetArgumentPointeeTest, SetsTheNthPointee) { int n = 0; char ch = '\0'; - a.Perform(make_tuple(true, &n, &ch)); + a.Perform(std::make_tuple(true, &n, &ch)); EXPECT_EQ(2, n); EXPECT_EQ('\0', ch); a = SetArgumentPointee<2>('a'); n = 0; ch = '\0'; - a.Perform(make_tuple(true, &n, &ch)); + a.Perform(std::make_tuple(true, &n, &ch)); EXPECT_EQ(0, n); EXPECT_EQ('a', ch); } @@ -940,16 +940,16 @@ class Foo { TEST(InvokeWithoutArgsTest, Function) { // As an action that takes one argument. Action a = InvokeWithoutArgs(Nullary); // NOLINT - EXPECT_EQ(1, a.Perform(make_tuple(2))); + EXPECT_EQ(1, a.Perform(std::make_tuple(2))); // As an action that takes two arguments. Action a2 = InvokeWithoutArgs(Nullary); // NOLINT - EXPECT_EQ(1, a2.Perform(make_tuple(2, 3.5))); + EXPECT_EQ(1, a2.Perform(std::make_tuple(2, 3.5))); // As an action that returns void. Action a3 = InvokeWithoutArgs(VoidNullary); // NOLINT g_done = false; - a3.Perform(make_tuple(1)); + a3.Perform(std::make_tuple(1)); EXPECT_TRUE(g_done); } @@ -957,17 +957,17 @@ TEST(InvokeWithoutArgsTest, Function) { TEST(InvokeWithoutArgsTest, Functor) { // As an action that takes no argument. Action a = InvokeWithoutArgs(NullaryFunctor()); // NOLINT - EXPECT_EQ(2, a.Perform(make_tuple())); + EXPECT_EQ(2, a.Perform(std::make_tuple())); // As an action that takes three arguments. Action a2 = // NOLINT InvokeWithoutArgs(NullaryFunctor()); - EXPECT_EQ(2, a2.Perform(make_tuple(3, 3.5, 'a'))); + EXPECT_EQ(2, a2.Perform(std::make_tuple(3, 3.5, 'a'))); // As an action that returns void. Action a3 = InvokeWithoutArgs(VoidNullaryFunctor()); g_done = false; - a3.Perform(make_tuple()); + a3.Perform(std::make_tuple()); EXPECT_TRUE(g_done); } @@ -976,13 +976,13 @@ TEST(InvokeWithoutArgsTest, Method) { Foo foo; Action a = // NOLINT InvokeWithoutArgs(&foo, &Foo::Nullary); - EXPECT_EQ(123, a.Perform(make_tuple(true, 'a'))); + EXPECT_EQ(123, a.Perform(std::make_tuple(true, 'a'))); } // Tests using IgnoreResult() on a polymorphic action. TEST(IgnoreResultTest, PolymorphicAction) { Action a = IgnoreResult(Return(5)); // NOLINT - a.Perform(make_tuple(1)); + a.Perform(std::make_tuple(1)); } // Tests using IgnoreResult() on a monomorphic action. @@ -995,7 +995,7 @@ int ReturnOne() { TEST(IgnoreResultTest, MonomorphicAction) { g_done = false; Action a = IgnoreResult(Invoke(ReturnOne)); - a.Perform(make_tuple()); + a.Perform(std::make_tuple()); EXPECT_TRUE(g_done); } @@ -1010,28 +1010,28 @@ TEST(IgnoreResultTest, ActionReturningClass) { g_done = false; Action a = IgnoreResult(Invoke(ReturnMyNonDefaultConstructible)); // NOLINT - a.Perform(make_tuple(2)); + a.Perform(std::make_tuple(2)); EXPECT_TRUE(g_done); } TEST(AssignTest, Int) { int x = 0; Action a = Assign(&x, 5); - a.Perform(make_tuple(0)); + a.Perform(std::make_tuple(0)); EXPECT_EQ(5, x); } TEST(AssignTest, String) { ::std::string x; Action a = Assign(&x, "Hello, world"); - a.Perform(make_tuple()); + a.Perform(std::make_tuple()); EXPECT_EQ("Hello, world", x); } TEST(AssignTest, CompatibleTypes) { double x = 0; Action a = Assign(&x, 5); - a.Perform(make_tuple(0)); + a.Perform(std::make_tuple(0)); EXPECT_DOUBLE_EQ(5, x); } @@ -1045,20 +1045,20 @@ class SetErrnoAndReturnTest : public testing::Test { TEST_F(SetErrnoAndReturnTest, Int) { Action a = SetErrnoAndReturn(ENOTTY, -5); - EXPECT_EQ(-5, a.Perform(make_tuple())); + EXPECT_EQ(-5, a.Perform(std::make_tuple())); EXPECT_EQ(ENOTTY, errno); } TEST_F(SetErrnoAndReturnTest, Ptr) { int x; Action a = SetErrnoAndReturn(ENOTTY, &x); - EXPECT_EQ(&x, a.Perform(make_tuple())); + EXPECT_EQ(&x, a.Perform(std::make_tuple())); EXPECT_EQ(ENOTTY, errno); } TEST_F(SetErrnoAndReturnTest, CompatibleTypes) { Action a = SetErrnoAndReturn(EINVAL, 5); - EXPECT_DOUBLE_EQ(5.0, a.Perform(make_tuple())); + EXPECT_DOUBLE_EQ(5.0, a.Perform(std::make_tuple())); EXPECT_EQ(EINVAL, errno); } @@ -1298,47 +1298,47 @@ TEST(FunctorActionTest, ActionFromFunction) { TEST(FunctorActionTest, ActionFromLambda) { Action a1 = [](bool b, int i) { return b ? i : 0; }; - EXPECT_EQ(5, a1.Perform(make_tuple(true, 5))); - EXPECT_EQ(0, a1.Perform(make_tuple(false, 5))); + EXPECT_EQ(5, a1.Perform(std::make_tuple(true, 5))); + EXPECT_EQ(0, a1.Perform(std::make_tuple(false, 5))); std::unique_ptr saved; Action)> a2 = [&saved](std::unique_ptr p) { saved = std::move(p); }; - a2.Perform(make_tuple(UniqueInt(5))); + a2.Perform(std::make_tuple(UniqueInt(5))); EXPECT_EQ(5, *saved); } TEST(FunctorActionTest, PolymorphicFunctor) { Action ai = Double(); - EXPECT_EQ(2, ai.Perform(make_tuple(1))); + EXPECT_EQ(2, ai.Perform(std::make_tuple(1))); Action ad = Double(); // Double? Double double! - EXPECT_EQ(3.0, ad.Perform(make_tuple(1.5))); + EXPECT_EQ(3.0, ad.Perform(std::make_tuple(1.5))); } TEST(FunctorActionTest, TypeConversion) { // Numeric promotions are allowed. const Action a1 = [](int i) { return i > 1; }; const Action a2 = Action(a1); - EXPECT_EQ(1, a1.Perform(make_tuple(42))); - EXPECT_EQ(0, a2.Perform(make_tuple(42))); + EXPECT_EQ(1, a1.Perform(std::make_tuple(42))); + EXPECT_EQ(0, a2.Perform(std::make_tuple(42))); // Implicit constructors are allowed. const Action s1 = [](std::string s) { return !s.empty(); }; const Action s2 = Action(s1); - EXPECT_EQ(0, s2.Perform(make_tuple(""))); - EXPECT_EQ(1, s2.Perform(make_tuple("hello"))); + EXPECT_EQ(0, s2.Perform(std::make_tuple(""))); + EXPECT_EQ(1, s2.Perform(std::make_tuple("hello"))); // Also between the lambda and the action itself. const Action x = [](Unused) { return 42; }; - EXPECT_TRUE(x.Perform(make_tuple("hello"))); + EXPECT_TRUE(x.Perform(std::make_tuple("hello"))); } TEST(FunctorActionTest, UnusedArguments) { // Verify that users can ignore uninteresting arguments. Action a = [](int i, Unused, Unused) { return 2 * i; }; - tuple dummy = make_tuple(3, 7.3, 9.44); + std::tuple dummy = std::make_tuple(3, 7.3, 9.44); EXPECT_EQ(6, a.Perform(dummy)); } @@ -1349,14 +1349,14 @@ TEST(FunctorActionTest, UnusedArguments) { // so maybe it's better to make users use lambdas instead. TEST(MoveOnlyArgumentsTest, ReturningActions) { Action)> a = Return(1); - EXPECT_EQ(1, a.Perform(make_tuple(nullptr))); + EXPECT_EQ(1, a.Perform(std::make_tuple(nullptr))); a = testing::WithoutArgs([]() { return 7; }); - EXPECT_EQ(7, a.Perform(make_tuple(nullptr))); + EXPECT_EQ(7, a.Perform(std::make_tuple(nullptr))); Action, int*)> a2 = testing::SetArgPointee<1>(3); int x = 0; - a2.Perform(make_tuple(nullptr, &x)); + a2.Perform(std::make_tuple(nullptr, &x)); EXPECT_EQ(x, 3); } diff --git a/googlemock/test/gmock-generated-actions_test.cc b/googlemock/test/gmock-generated-actions_test.cc index a4602806..2d663a5e 100644 --- a/googlemock/test/gmock-generated-actions_test.cc +++ b/googlemock/test/gmock-generated-actions_test.cc @@ -45,10 +45,6 @@ namespace gmock_generated_actions_test { using ::std::plus; using ::std::string; -using testing::get; -using testing::make_tuple; -using testing::tuple; -using testing::tuple_element; using testing::_; using testing::Action; using testing::ActionInterface; @@ -168,41 +164,41 @@ inline const char* CharPtr(const char* s) { return s; } // Tests using InvokeArgument with a nullary function. TEST(InvokeArgumentTest, Function0) { Action a = InvokeArgument<1>(); // NOLINT - EXPECT_EQ(1, a.Perform(make_tuple(2, &Nullary))); + EXPECT_EQ(1, a.Perform(std::make_tuple(2, &Nullary))); } // Tests using InvokeArgument with a unary function. TEST(InvokeArgumentTest, Functor1) { Action a = InvokeArgument<0>(true); // NOLINT - EXPECT_EQ(1, a.Perform(make_tuple(UnaryFunctor()))); + EXPECT_EQ(1, a.Perform(std::make_tuple(UnaryFunctor()))); } // Tests using InvokeArgument with a 5-ary function. TEST(InvokeArgumentTest, Function5) { Action a = // NOLINT InvokeArgument<0>(10000, 2000, 300, 40, 5); - EXPECT_EQ(12345, a.Perform(make_tuple(&SumOf5))); + EXPECT_EQ(12345, a.Perform(std::make_tuple(&SumOf5))); } // Tests using InvokeArgument with a 5-ary functor. TEST(InvokeArgumentTest, Functor5) { Action a = // NOLINT InvokeArgument<0>(10000, 2000, 300, 40, 5); - EXPECT_EQ(12345, a.Perform(make_tuple(SumOf5Functor()))); + EXPECT_EQ(12345, a.Perform(std::make_tuple(SumOf5Functor()))); } // Tests using InvokeArgument with a 6-ary function. TEST(InvokeArgumentTest, Function6) { Action a = // NOLINT InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6); - EXPECT_EQ(123456, a.Perform(make_tuple(&SumOf6))); + EXPECT_EQ(123456, a.Perform(std::make_tuple(&SumOf6))); } // Tests using InvokeArgument with a 6-ary functor. TEST(InvokeArgumentTest, Functor6) { Action a = // NOLINT InvokeArgument<0>(100000, 20000, 3000, 400, 50, 6); - EXPECT_EQ(123456, a.Perform(make_tuple(SumOf6Functor()))); + EXPECT_EQ(123456, a.Perform(std::make_tuple(SumOf6Functor()))); } // Tests using InvokeArgument with a 7-ary function. @@ -211,7 +207,7 @@ TEST(InvokeArgumentTest, Function7) { const char*, const char*, const char*, const char*))> a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7"); - EXPECT_EQ("1234567", a.Perform(make_tuple(&Concat7))); + EXPECT_EQ("1234567", a.Perform(std::make_tuple(&Concat7))); } // Tests using InvokeArgument with a 8-ary function. @@ -220,7 +216,7 @@ TEST(InvokeArgumentTest, Function8) { const char*, const char*, const char*, const char*, const char*))> a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8"); - EXPECT_EQ("12345678", a.Perform(make_tuple(&Concat8))); + EXPECT_EQ("12345678", a.Perform(std::make_tuple(&Concat8))); } // Tests using InvokeArgument with a 9-ary function. @@ -229,7 +225,7 @@ TEST(InvokeArgumentTest, Function9) { const char*, const char*, const char*, const char*, const char*, const char*))> a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9"); - EXPECT_EQ("123456789", a.Perform(make_tuple(&Concat9))); + EXPECT_EQ("123456789", a.Perform(std::make_tuple(&Concat9))); } // Tests using InvokeArgument with a 10-ary function. @@ -238,14 +234,14 @@ TEST(InvokeArgumentTest, Function10) { const char*, const char*, const char*, const char*, const char*, const char*, const char*, const char*, const char*, const char*))> a = InvokeArgument<0>("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); - EXPECT_EQ("1234567890", a.Perform(make_tuple(&Concat10))); + EXPECT_EQ("1234567890", a.Perform(std::make_tuple(&Concat10))); } // Tests using InvokeArgument with a function that takes a pointer argument. TEST(InvokeArgumentTest, ByPointerFunction) { Action a = // NOLINT InvokeArgument<0>(static_cast("Hi"), Short(1)); - EXPECT_STREQ("i", a.Perform(make_tuple(&Binary))); + EXPECT_STREQ("i", a.Perform(std::make_tuple(&Binary))); } // Tests using InvokeArgument with a function that takes a const char* @@ -253,7 +249,7 @@ TEST(InvokeArgumentTest, ByPointerFunction) { TEST(InvokeArgumentTest, FunctionWithCStringLiteral) { Action a = // NOLINT InvokeArgument<0>("Hi", Short(1)); - EXPECT_STREQ("i", a.Perform(make_tuple(&Binary))); + EXPECT_STREQ("i", a.Perform(std::make_tuple(&Binary))); } // Tests using InvokeArgument with a function that takes a const reference. @@ -263,7 +259,7 @@ TEST(InvokeArgumentTest, ByConstReferenceFunction) { // When action 'a' is constructed, it makes a copy of the temporary // string object passed to it, so it's OK to use 'a' later, when the // temporary object has already died. - EXPECT_TRUE(a.Perform(make_tuple(&ByConstRef))); + EXPECT_TRUE(a.Perform(std::make_tuple(&ByConstRef))); } // Tests using InvokeArgument with ByRef() and a function that takes a @@ -272,18 +268,18 @@ TEST(InvokeArgumentTest, ByExplicitConstReferenceFunction) { Action a = // NOLINT InvokeArgument<0>(ByRef(g_double)); // The above line calls ByRef() on a const value. - EXPECT_TRUE(a.Perform(make_tuple(&ReferencesGlobalDouble))); + EXPECT_TRUE(a.Perform(std::make_tuple(&ReferencesGlobalDouble))); double x = 0; a = InvokeArgument<0>(ByRef(x)); // This calls ByRef() on a non-const. - EXPECT_FALSE(a.Perform(make_tuple(&ReferencesGlobalDouble))); + EXPECT_FALSE(a.Perform(std::make_tuple(&ReferencesGlobalDouble))); } // Tests using WithArgs and with an action that takes 1 argument. TEST(WithArgsTest, OneArg) { Action a = WithArgs<1>(Invoke(Unary)); // NOLINT - EXPECT_TRUE(a.Perform(make_tuple(1.5, -1))); - EXPECT_FALSE(a.Perform(make_tuple(1.5, 1))); + EXPECT_TRUE(a.Perform(std::make_tuple(1.5, -1))); + EXPECT_FALSE(a.Perform(std::make_tuple(1.5, 1))); } // Tests using WithArgs with an action that takes 2 arguments. @@ -291,14 +287,14 @@ TEST(WithArgsTest, TwoArgs) { Action a = WithArgs<0, 2>(Invoke(Binary)); const char s[] = "Hello"; - EXPECT_EQ(s + 2, a.Perform(make_tuple(CharPtr(s), 0.5, Short(2)))); + EXPECT_EQ(s + 2, a.Perform(std::make_tuple(CharPtr(s), 0.5, Short(2)))); } // Tests using WithArgs with an action that takes 3 arguments. TEST(WithArgsTest, ThreeArgs) { Action a = // NOLINT WithArgs<0, 2, 3>(Invoke(Ternary)); - EXPECT_EQ(123, a.Perform(make_tuple(100, 6.5, Char(20), Short(3)))); + EXPECT_EQ(123, a.Perform(std::make_tuple(100, 6.5, Char(20), Short(3)))); } // Tests using WithArgs with an action that takes 4 arguments. @@ -306,8 +302,8 @@ TEST(WithArgsTest, FourArgs) { Action a = WithArgs<4, 3, 1, 0>(Invoke(Concat4)); - EXPECT_EQ("4310", a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), 2.5, - CharPtr("3"), CharPtr("4")))); + EXPECT_EQ("4310", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), 2.5, + CharPtr("3"), CharPtr("4")))); } // Tests using WithArgs with an action that takes 5 arguments. @@ -316,34 +312,32 @@ TEST(WithArgsTest, FiveArgs) { const char*)> a = WithArgs<4, 3, 2, 1, 0>(Invoke(Concat5)); EXPECT_EQ("43210", - a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), - CharPtr("3"), CharPtr("4")))); + a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), + CharPtr("3"), CharPtr("4")))); } // Tests using WithArgs with an action that takes 6 arguments. TEST(WithArgsTest, SixArgs) { Action a = WithArgs<0, 1, 2, 2, 1, 0>(Invoke(Concat6)); - EXPECT_EQ("012210", - a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2")))); + EXPECT_EQ("012210", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), + CharPtr("2")))); } // Tests using WithArgs with an action that takes 7 arguments. TEST(WithArgsTest, SevenArgs) { Action a = WithArgs<0, 1, 2, 3, 2, 1, 0>(Invoke(Concat7)); - EXPECT_EQ("0123210", - a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), - CharPtr("3")))); + EXPECT_EQ("0123210", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), + CharPtr("2"), CharPtr("3")))); } // Tests using WithArgs with an action that takes 8 arguments. TEST(WithArgsTest, EightArgs) { Action a = WithArgs<0, 1, 2, 3, 0, 1, 2, 3>(Invoke(Concat8)); - EXPECT_EQ("01230123", - a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), - CharPtr("3")))); + EXPECT_EQ("01230123", a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), + CharPtr("2"), CharPtr("3")))); } // Tests using WithArgs with an action that takes 9 arguments. @@ -351,8 +345,8 @@ TEST(WithArgsTest, NineArgs) { Action a = WithArgs<0, 1, 2, 3, 1, 2, 3, 2, 3>(Invoke(Concat9)); EXPECT_EQ("012312323", - a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), - CharPtr("3")))); + a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), + CharPtr("3")))); } // Tests using WithArgs with an action that takes 10 arguments. @@ -360,22 +354,23 @@ TEST(WithArgsTest, TenArgs) { Action a = WithArgs<0, 1, 2, 3, 2, 1, 0, 1, 2, 3>(Invoke(Concat10)); EXPECT_EQ("0123210123", - a.Perform(make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), - CharPtr("3")))); + a.Perform(std::make_tuple(CharPtr("0"), CharPtr("1"), CharPtr("2"), + CharPtr("3")))); } // Tests using WithArgs with an action that is not Invoke(). class SubstractAction : public ActionInterface { // NOLINT public: - virtual int Perform(const tuple& args) { - return get<0>(args) - get<1>(args); + virtual int Perform(const std::tuple& args) { + return std::get<0>(args) - std::get<1>(args); } }; TEST(WithArgsTest, NonInvokeAction) { Action a = // NOLINT WithArgs<2, 1>(MakeAction(new SubstractAction)); - tuple dummy = make_tuple(std::string("hi"), 2, 10); + std::tuple dummy = + std::make_tuple(std::string("hi"), 2, 10); EXPECT_EQ(8, a.Perform(dummy)); } @@ -383,14 +378,14 @@ TEST(WithArgsTest, NonInvokeAction) { TEST(WithArgsTest, Identity) { Action a = // NOLINT WithArgs<0, 1, 2>(Invoke(Ternary)); - EXPECT_EQ(123, a.Perform(make_tuple(100, Char(20), Short(3)))); + EXPECT_EQ(123, a.Perform(std::make_tuple(100, Char(20), Short(3)))); } // Tests using WithArgs with repeated arguments. TEST(WithArgsTest, RepeatedArguments) { Action a = // NOLINT WithArgs<1, 1, 1, 1>(Invoke(SumOf4)); - EXPECT_EQ(4, a.Perform(make_tuple(false, 1, 10))); + EXPECT_EQ(4, a.Perform(std::make_tuple(false, 1, 10))); } // Tests using WithArgs with reversed argument order. @@ -398,21 +393,22 @@ TEST(WithArgsTest, ReversedArgumentOrder) { Action a = // NOLINT WithArgs<1, 0>(Invoke(Binary)); const char s[] = "Hello"; - EXPECT_EQ(s + 2, a.Perform(make_tuple(Short(2), CharPtr(s)))); + EXPECT_EQ(s + 2, a.Perform(std::make_tuple(Short(2), CharPtr(s)))); } // Tests using WithArgs with compatible, but not identical, argument types. TEST(WithArgsTest, ArgsOfCompatibleTypes) { Action a = // NOLINT WithArgs<0, 1, 3>(Invoke(Ternary)); - EXPECT_EQ(123, a.Perform(make_tuple(Short(100), Char(20), 5.6, Char(3)))); + EXPECT_EQ(123, + a.Perform(std::make_tuple(Short(100), Char(20), 5.6, Char(3)))); } // Tests using WithArgs with an action that returns void. TEST(WithArgsTest, VoidAction) { Action a = WithArgs<2, 1>(Invoke(VoidBinary)); g_done = false; - a.Perform(make_tuple(1.5, 'a', 3)); + a.Perform(std::make_tuple(1.5, 'a', 3)); EXPECT_TRUE(g_done); } @@ -421,7 +417,7 @@ TEST(DoAllTest, TwoActions) { int n = 0; Action a = DoAll(SetArgPointee<0>(1), // NOLINT Return(2)); - EXPECT_EQ(2, a.Perform(make_tuple(&n))); + EXPECT_EQ(2, a.Perform(std::make_tuple(&n))); EXPECT_EQ(1, n); } @@ -431,7 +427,7 @@ TEST(DoAllTest, ThreeActions) { Action a = DoAll(SetArgPointee<0>(1), // NOLINT SetArgPointee<1>(2), Return(3)); - EXPECT_EQ(3, a.Perform(make_tuple(&m, &n))); + EXPECT_EQ(3, a.Perform(std::make_tuple(&m, &n))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); } @@ -445,7 +441,7 @@ TEST(DoAllTest, FourActions) { SetArgPointee<1>(2), SetArgPointee<2>('a'), Return(3)); - EXPECT_EQ(3, a.Perform(make_tuple(&m, &n, &ch))); + EXPECT_EQ(3, a.Perform(std::make_tuple(&m, &n, &ch))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', ch); @@ -461,7 +457,7 @@ TEST(DoAllTest, FiveActions) { SetArgPointee<2>('a'), SetArgPointee<3>('b'), Return(3)); - EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b))); + EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', a); @@ -479,7 +475,7 @@ TEST(DoAllTest, SixActions) { SetArgPointee<3>('b'), SetArgPointee<4>('c'), Return(3)); - EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c))); + EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', a); @@ -499,7 +495,7 @@ TEST(DoAllTest, SevenActions) { SetArgPointee<4>('c'), SetArgPointee<5>('d'), Return(3)); - EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d))); + EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', a); @@ -522,7 +518,7 @@ TEST(DoAllTest, EightActions) { SetArgPointee<5>('d'), SetArgPointee<6>('e'), Return(3)); - EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d, &e))); + EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', a); @@ -547,7 +543,7 @@ TEST(DoAllTest, NineActions) { SetArgPointee<6>('e'), SetArgPointee<7>('f'), Return(3)); - EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d, &e, &f))); + EXPECT_EQ(3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', a); @@ -575,7 +571,8 @@ TEST(DoAllTest, TenActions) { SetArgPointee<7>('f'), SetArgPointee<8>('g'), Return(3)); - EXPECT_EQ(3, action.Perform(make_tuple(&m, &n, &a, &b, &c, &d, &e, &f, &g))); + EXPECT_EQ( + 3, action.Perform(std::make_tuple(&m, &n, &a, &b, &c, &d, &e, &f, &g))); EXPECT_EQ(1, m); EXPECT_EQ(2, n); EXPECT_EQ('a', a); @@ -605,10 +602,10 @@ ACTION(Return5) { return 5; } TEST(ActionMacroTest, WorksWhenNotReferencingArguments) { Action a1 = Return5(); - EXPECT_DOUBLE_EQ(5, a1.Perform(make_tuple())); + EXPECT_DOUBLE_EQ(5, a1.Perform(std::make_tuple())); Action a2 = Return5(); - EXPECT_EQ(5, a2.Perform(make_tuple(1, true))); + EXPECT_EQ(5, a2.Perform(std::make_tuple(1, true))); } // Tests that ACTION() can define an action that returns void. @@ -617,7 +614,7 @@ ACTION(IncrementArg1) { (*arg1)++; } TEST(ActionMacroTest, WorksWhenReturningVoid) { Action a1 = IncrementArg1(); int n = 0; - a1.Perform(make_tuple(5, &n)); + a1.Perform(std::make_tuple(5, &n)); EXPECT_EQ(1, n); } @@ -632,22 +629,22 @@ ACTION(IncrementArg2) { TEST(ActionMacroTest, CanReferenceArgumentType) { Action a1 = IncrementArg2(); int n = 0; - a1.Perform(make_tuple(5, false, &n)); + a1.Perform(std::make_tuple(5, false, &n)); EXPECT_EQ(1, n); } // Tests that the body of ACTION() can reference the argument tuple // via args_type and args. ACTION(Sum2) { - StaticAssertTypeEq, args_type>(); + StaticAssertTypeEq, args_type>(); args_type args_copy = args; - return get<0>(args_copy) + get<1>(args_copy); + return std::get<0>(args_copy) + std::get<1>(args_copy); } TEST(ActionMacroTest, CanReferenceArgumentTuple) { Action a1 = Sum2(); int dummy = 0; - EXPECT_EQ(11, a1.Perform(make_tuple(5, Char(6), &dummy))); + EXPECT_EQ(11, a1.Perform(std::make_tuple(5, Char(6), &dummy))); } // Tests that the body of ACTION() can reference the mock function @@ -662,8 +659,8 @@ ACTION(InvokeDummy) { TEST(ActionMacroTest, CanReferenceMockFunctionType) { Action a1 = InvokeDummy(); - EXPECT_EQ(1, a1.Perform(make_tuple(true))); - EXPECT_EQ(1, a1.Perform(make_tuple(false))); + EXPECT_EQ(1, a1.Perform(std::make_tuple(true))); + EXPECT_EQ(1, a1.Perform(std::make_tuple(false))); } // Tests that the body of ACTION() can reference the mock function's @@ -676,8 +673,8 @@ ACTION(InvokeDummy2) { TEST(ActionMacroTest, CanReferenceMockFunctionReturnType) { Action a1 = InvokeDummy2(); - EXPECT_EQ(1, a1.Perform(make_tuple(true))); - EXPECT_EQ(1, a1.Perform(make_tuple(false))); + EXPECT_EQ(1, a1.Perform(std::make_tuple(true))); + EXPECT_EQ(1, a1.Perform(std::make_tuple(false))); } // Tests that ACTION() works for arguments passed by const reference. @@ -689,7 +686,7 @@ ACTION(ReturnAddrOfConstBoolReferenceArg) { TEST(ActionMacroTest, WorksForConstReferenceArg) { Action a = ReturnAddrOfConstBoolReferenceArg(); const bool b = false; - EXPECT_EQ(&b, a.Perform(tuple(0, b))); + EXPECT_EQ(&b, a.Perform(std::tuple(0, b))); } // Tests that ACTION() works for arguments passed by non-const reference. @@ -701,7 +698,7 @@ ACTION(ReturnAddrOfIntReferenceArg) { TEST(ActionMacroTest, WorksForNonConstReferenceArg) { Action a = ReturnAddrOfIntReferenceArg(); int n = 0; - EXPECT_EQ(&n, a.Perform(tuple(n, true, 1))); + EXPECT_EQ(&n, a.Perform(std::tuple(n, true, 1))); } // Tests that ACTION() can be used in a namespace. @@ -711,7 +708,7 @@ ACTION(Sum) { return arg0 + arg1; } TEST(ActionMacroTest, WorksInNamespace) { Action a1 = action_test::Sum(); - EXPECT_EQ(3, a1.Perform(make_tuple(1, 2))); + EXPECT_EQ(3, a1.Perform(std::make_tuple(1, 2))); } // Tests that the same ACTION definition works for mock functions with @@ -720,11 +717,11 @@ ACTION(PlusTwo) { return arg0 + 2; } TEST(ActionMacroTest, WorksForDifferentArgumentNumbers) { Action a1 = PlusTwo(); - EXPECT_EQ(4, a1.Perform(make_tuple(2))); + EXPECT_EQ(4, a1.Perform(std::make_tuple(2))); Action a2 = PlusTwo(); int dummy; - EXPECT_DOUBLE_EQ(6, a2.Perform(make_tuple(4.0f, &dummy))); + EXPECT_DOUBLE_EQ(6, a2.Perform(std::make_tuple(4.0f, &dummy))); } // Tests that ACTION_P can define a parameterized action. @@ -732,7 +729,7 @@ ACTION_P(Plus, n) { return arg0 + n; } TEST(ActionPMacroTest, DefinesParameterizedAction) { Action a1 = Plus(9); - EXPECT_EQ(10, a1.Perform(make_tuple(1, true))); + EXPECT_EQ(10, a1.Perform(std::make_tuple(1, true))); } // Tests that the body of ACTION_P can reference the argument types @@ -745,7 +742,7 @@ ACTION_P(TypedPlus, n) { TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { Action a1 = TypedPlus(9); - EXPECT_EQ(10, a1.Perform(make_tuple(Char(1), true))); + EXPECT_EQ(10, a1.Perform(std::make_tuple(Char(1), true))); } // Tests that a parameterized action can be used in any mock function @@ -753,7 +750,7 @@ TEST(ActionPMacroTest, CanReferenceArgumentAndParameterTypes) { TEST(ActionPMacroTest, WorksInCompatibleMockFunction) { Action a1 = Plus("tail"); const std::string re = "re"; - tuple dummy = make_tuple(re); + std::tuple dummy = std::make_tuple(re); EXPECT_EQ("retail", a1.Perform(dummy)); } @@ -774,16 +771,16 @@ TEST(ActionMacroTest, CanDefineOverloadedActions) { typedef Action MyAction; const MyAction a1 = OverloadedAction(); - EXPECT_STREQ("hello", a1.Perform(make_tuple(false, CharPtr("world")))); - EXPECT_STREQ("world", a1.Perform(make_tuple(true, CharPtr("world")))); + EXPECT_STREQ("hello", a1.Perform(std::make_tuple(false, CharPtr("world")))); + EXPECT_STREQ("world", a1.Perform(std::make_tuple(true, CharPtr("world")))); const MyAction a2 = OverloadedAction("hi"); - EXPECT_STREQ("hi", a2.Perform(make_tuple(false, CharPtr("world")))); - EXPECT_STREQ("world", a2.Perform(make_tuple(true, CharPtr("world")))); + EXPECT_STREQ("hi", a2.Perform(std::make_tuple(false, CharPtr("world")))); + EXPECT_STREQ("world", a2.Perform(std::make_tuple(true, CharPtr("world")))); const MyAction a3 = OverloadedAction("hi", "you"); - EXPECT_STREQ("hi", a3.Perform(make_tuple(true, CharPtr("world")))); - EXPECT_STREQ("you", a3.Perform(make_tuple(false, CharPtr("world")))); + EXPECT_STREQ("hi", a3.Perform(std::make_tuple(true, CharPtr("world")))); + EXPECT_STREQ("you", a3.Perform(std::make_tuple(false, CharPtr("world")))); } // Tests ACTION_Pn where n >= 3. @@ -792,11 +789,11 @@ ACTION_P3(Plus, m, n, k) { return arg0 + m + n + k; } TEST(ActionPnMacroTest, WorksFor3Parameters) { Action a1 = Plus(100, 20, 3.4); - EXPECT_DOUBLE_EQ(3123.4, a1.Perform(make_tuple(3000, true))); + EXPECT_DOUBLE_EQ(3123.4, a1.Perform(std::make_tuple(3000, true))); Action a2 = Plus("tail", "-", ">"); const std::string re = "re"; - tuple dummy = make_tuple(re); + std::tuple dummy = std::make_tuple(re); EXPECT_EQ("retail->", a2.Perform(dummy)); } @@ -804,14 +801,14 @@ ACTION_P4(Plus, p0, p1, p2, p3) { return arg0 + p0 + p1 + p2 + p3; } TEST(ActionPnMacroTest, WorksFor4Parameters) { Action a1 = Plus(1, 2, 3, 4); - EXPECT_EQ(10 + 1 + 2 + 3 + 4, a1.Perform(make_tuple(10))); + EXPECT_EQ(10 + 1 + 2 + 3 + 4, a1.Perform(std::make_tuple(10))); } ACTION_P5(Plus, p0, p1, p2, p3, p4) { return arg0 + p0 + p1 + p2 + p3 + p4; } TEST(ActionPnMacroTest, WorksFor5Parameters) { Action a1 = Plus(1, 2, 3, 4, 5); - EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5, a1.Perform(make_tuple(10))); + EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5, a1.Perform(std::make_tuple(10))); } ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) { @@ -820,7 +817,7 @@ ACTION_P6(Plus, p0, p1, p2, p3, p4, p5) { TEST(ActionPnMacroTest, WorksFor6Parameters) { Action a1 = Plus(1, 2, 3, 4, 5, 6); - EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6, a1.Perform(make_tuple(10))); + EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6, a1.Perform(std::make_tuple(10))); } ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) { @@ -829,7 +826,7 @@ ACTION_P7(Plus, p0, p1, p2, p3, p4, p5, p6) { TEST(ActionPnMacroTest, WorksFor7Parameters) { Action a1 = Plus(1, 2, 3, 4, 5, 6, 7); - EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a1.Perform(make_tuple(10))); + EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a1.Perform(std::make_tuple(10))); } ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) { @@ -838,7 +835,8 @@ ACTION_P8(Plus, p0, p1, p2, p3, p4, p5, p6, p7) { TEST(ActionPnMacroTest, WorksFor8Parameters) { Action a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8); - EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a1.Perform(make_tuple(10))); + EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, + a1.Perform(std::make_tuple(10))); } ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) { @@ -847,7 +845,8 @@ ACTION_P9(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8) { TEST(ActionPnMacroTest, WorksFor9Parameters) { Action a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9); - EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, a1.Perform(make_tuple(10))); + EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, + a1.Perform(std::make_tuple(10))); } ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) { @@ -859,7 +858,7 @@ ACTION_P10(Plus, p0, p1, p2, p3, p4, p5, p6, p7, p8, last_param) { TEST(ActionPnMacroTest, WorksFor10Parameters) { Action a1 = Plus(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); EXPECT_EQ(10 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, - a1.Perform(make_tuple(10))); + a1.Perform(std::make_tuple(10))); } // Tests that the action body can promote the parameter types. @@ -876,8 +875,8 @@ TEST(ActionPnMacroTest, SimpleTypePromotion) { PadArgument(std::string("foo"), 'r'); Action promo = PadArgument("foo", static_cast('r')); - EXPECT_EQ("foobar", no_promo.Perform(make_tuple(CharPtr("ba")))); - EXPECT_EQ("foobar", promo.Perform(make_tuple(CharPtr("ba")))); + EXPECT_EQ("foobar", no_promo.Perform(std::make_tuple(CharPtr("ba")))); + EXPECT_EQ("foobar", promo.Perform(std::make_tuple(CharPtr("ba")))); } // Tests that we can partially restrict parameter types using a @@ -926,10 +925,10 @@ Concat(T1 a, int b, T2 c) { TEST(ActionPnMacroTest, CanPartiallyRestrictParameterTypes) { Action a1 = Concat("Hello", "1", 2); - EXPECT_EQ("Hello12", a1.Perform(make_tuple())); + EXPECT_EQ("Hello12", a1.Perform(std::make_tuple())); a1 = Concat(1, 2, 3); - EXPECT_EQ("123", a1.Perform(make_tuple())); + EXPECT_EQ("123", a1.Perform(std::make_tuple())); } // Verifies the type of an ACTION*. @@ -987,7 +986,7 @@ ACTION_P10(Plus10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { TEST(ActionPnMacroTest, CanExplicitlyInstantiateWithReferenceTypes) { int x = 1, y = 2, z = 3; - const tuple<> empty = make_tuple(); + const std::tuple<> empty = std::make_tuple(); Action a = Plus1(x); EXPECT_EQ(1, a.Perform(empty)); @@ -1014,7 +1013,7 @@ class NullaryConstructorClass { // Tests using ReturnNew() with a nullary constructor. TEST(ReturnNewTest, NoArgs) { Action a = ReturnNew(); - NullaryConstructorClass* c = a.Perform(make_tuple()); + NullaryConstructorClass* c = a.Perform(std::make_tuple()); EXPECT_EQ(123, c->value_); delete c; } @@ -1028,7 +1027,7 @@ class UnaryConstructorClass { // Tests using ReturnNew() with a unary constructor. TEST(ReturnNewTest, Unary) { Action a = ReturnNew(4000); - UnaryConstructorClass* c = a.Perform(make_tuple()); + UnaryConstructorClass* c = a.Perform(std::make_tuple()); EXPECT_EQ(4000, c->value_); delete c; } @@ -1036,7 +1035,7 @@ TEST(ReturnNewTest, Unary) { TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { Action a = ReturnNew(4000); - UnaryConstructorClass* c = a.Perform(make_tuple(false, 5)); + UnaryConstructorClass* c = a.Perform(std::make_tuple(false, 5)); EXPECT_EQ(4000, c->value_); delete c; } @@ -1044,7 +1043,7 @@ TEST(ReturnNewTest, UnaryWorksWhenMockMethodHasArgs) { TEST(ReturnNewTest, UnaryWorksWhenMockMethodReturnsPointerToConst) { Action a = ReturnNew(4000); - const UnaryConstructorClass* c = a.Perform(make_tuple()); + const UnaryConstructorClass* c = a.Perform(std::make_tuple()); EXPECT_EQ(4000, c->value_); delete c; } @@ -1064,7 +1063,7 @@ TEST(ReturnNewTest, ConstructorThatTakes10Arguments) { ReturnNew(1000000000, 200000000, 30000000, 4000000, 500000, 60000, 7000, 800, 90, 0); - TenArgConstructorClass* c = a.Perform(make_tuple()); + TenArgConstructorClass* c = a.Perform(std::make_tuple()); EXPECT_EQ(1234567890, c->value_); delete c; } @@ -1078,7 +1077,7 @@ ACTION_TEMPLATE(CreateNew, TEST(ActionTemplateTest, WorksWithoutValueParam) { const Action a = CreateNew(); - int* p = a.Perform(make_tuple()); + int* p = a.Perform(std::make_tuple()); delete p; } @@ -1091,7 +1090,7 @@ ACTION_TEMPLATE(CreateNew, TEST(ActionTemplateTest, WorksWithValueParams) { const Action a = CreateNew(42); - int* p = a.Perform(make_tuple()); + int* p = a.Perform(std::make_tuple()); EXPECT_EQ(42, *p); delete p; } @@ -1100,7 +1099,7 @@ TEST(ActionTemplateTest, WorksWithValueParams) { ACTION_TEMPLATE(MyDeleteArg, HAS_1_TEMPLATE_PARAMS(int, k), AND_0_VALUE_PARAMS()) { - delete get(args); + delete std::get(args); } // Resets a bool variable in the destructor. @@ -1117,7 +1116,7 @@ TEST(ActionTemplateTest, WorksForIntegralTemplateParams) { int n = 0; bool b = true; BoolResetter* resetter = new BoolResetter(&b); - a.Perform(make_tuple(&n, resetter)); + a.Perform(std::make_tuple(&n, resetter)); EXPECT_FALSE(b); // Verifies that resetter is deleted. } @@ -1132,7 +1131,7 @@ ACTION_TEMPLATE(ReturnSmartPointer, TEST(ActionTemplateTest, WorksForTemplateTemplateParameters) { using ::testing::internal::linked_ptr; const Action()> a = ReturnSmartPointer(42); - linked_ptr p = a.Perform(make_tuple()); + linked_ptr p = a.Perform(std::make_tuple()); EXPECT_EQ(42, *p); } @@ -1167,7 +1166,7 @@ TEST(ActionTemplateTest, WorksFor10TemplateParameters) { true, 6, char, unsigned, int> Giant; const Action a = ReturnGiant< int, bool, double, 5, true, 6, char, unsigned, int, linked_ptr>(42); - Giant giant = a.Perform(make_tuple()); + Giant giant = a.Perform(std::make_tuple()); EXPECT_EQ(42, giant.value); } @@ -1180,7 +1179,7 @@ ACTION_TEMPLATE(ReturnSum, TEST(ActionTemplateTest, WorksFor10ValueParameters) { const Action a = ReturnSum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - EXPECT_EQ(55, a.Perform(make_tuple())); + EXPECT_EQ(55, a.Perform(std::make_tuple())); } // Tests that ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded @@ -1214,11 +1213,11 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) { const Action a2 = ReturnSum(1, 2); const Action a3 = ReturnSum(1, 2, 3); const Action a4 = ReturnSum(2000, 300, 40, 5); - EXPECT_EQ(0, a0.Perform(make_tuple())); - EXPECT_EQ(1, a1.Perform(make_tuple())); - EXPECT_EQ(3, a2.Perform(make_tuple())); - EXPECT_EQ(6, a3.Perform(make_tuple())); - EXPECT_EQ(12345, a4.Perform(make_tuple())); + EXPECT_EQ(0, a0.Perform(std::make_tuple())); + EXPECT_EQ(1, a1.Perform(std::make_tuple())); + EXPECT_EQ(3, a2.Perform(std::make_tuple())); + EXPECT_EQ(6, a3.Perform(std::make_tuple())); + EXPECT_EQ(12345, a4.Perform(std::make_tuple())); } #ifdef _MSC_VER diff --git a/googlemock/test/gmock-generated-internal-utils_test.cc b/googlemock/test/gmock-generated-internal-utils_test.cc index ae0280fc..965cbaa6 100644 --- a/googlemock/test/gmock-generated-internal-utils_test.cc +++ b/googlemock/test/gmock-generated-internal-utils_test.cc @@ -38,7 +38,6 @@ namespace { -using ::testing::tuple; using ::testing::Matcher; using ::testing::internal::CompileAssertTypesEqual; using ::testing::internal::MatcherTuple; @@ -48,24 +47,24 @@ using ::testing::internal::IgnoredValue; // Tests the MatcherTuple template struct. TEST(MatcherTupleTest, ForSize0) { - CompileAssertTypesEqual, MatcherTuple >::type>(); + CompileAssertTypesEqual, MatcherTuple >::type>(); } TEST(MatcherTupleTest, ForSize1) { - CompileAssertTypesEqual >, - MatcherTuple >::type>(); + CompileAssertTypesEqual >, + MatcherTuple >::type>(); } TEST(MatcherTupleTest, ForSize2) { - CompileAssertTypesEqual, Matcher >, - MatcherTuple >::type>(); + CompileAssertTypesEqual, Matcher >, + MatcherTuple >::type>(); } TEST(MatcherTupleTest, ForSize5) { CompileAssertTypesEqual< - tuple, Matcher, Matcher, Matcher, - Matcher >, - MatcherTuple >::type>(); + std::tuple, Matcher, Matcher, Matcher, + Matcher >, + MatcherTuple >::type>(); } // Tests the Function template struct. @@ -73,8 +72,8 @@ TEST(MatcherTupleTest, ForSize5) { TEST(FunctionTest, Nullary) { typedef Function F; // NOLINT CompileAssertTypesEqual(); - CompileAssertTypesEqual, F::ArgumentTuple>(); - CompileAssertTypesEqual, F::ArgumentMatcherTuple>(); + CompileAssertTypesEqual, F::ArgumentTuple>(); + CompileAssertTypesEqual, F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); CompileAssertTypesEqual(); } @@ -83,8 +82,9 @@ TEST(FunctionTest, Unary) { typedef Function F; // NOLINT CompileAssertTypesEqual(); CompileAssertTypesEqual(); - CompileAssertTypesEqual, F::ArgumentTuple>(); - CompileAssertTypesEqual >, F::ArgumentMatcherTuple>(); + CompileAssertTypesEqual, F::ArgumentTuple>(); + CompileAssertTypesEqual >, + F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual(); @@ -95,9 +95,10 @@ TEST(FunctionTest, Binary) { CompileAssertTypesEqual(); CompileAssertTypesEqual(); CompileAssertTypesEqual(); // NOLINT - CompileAssertTypesEqual, F::ArgumentTuple>(); // NOLINT + CompileAssertTypesEqual, // NOLINT + F::ArgumentTuple>(); CompileAssertTypesEqual< - tuple, Matcher >, // NOLINT + std::tuple, Matcher >, // NOLINT F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); // NOLINT CompileAssertTypesEqual(); CompileAssertTypesEqual(); CompileAssertTypesEqual(); // NOLINT - CompileAssertTypesEqual, // NOLINT - F::ArgumentTuple>(); CompileAssertTypesEqual< - tuple, Matcher, Matcher, Matcher, - Matcher >, // NOLINT + std::tuple, // NOLINT + F::ArgumentTuple>(); + CompileAssertTypesEqual< + std::tuple, Matcher, Matcher, Matcher, + Matcher >, // NOLINT F::ArgumentMatcherTuple>(); CompileAssertTypesEqual(); diff --git a/googlemock/test/gmock-generated-matchers_test.cc b/googlemock/test/gmock-generated-matchers_test.cc index 10a4ac39..fdbfb549 100644 --- a/googlemock/test/gmock-generated-matchers_test.cc +++ b/googlemock/test/gmock-generated-matchers_test.cc @@ -62,9 +62,6 @@ using std::pair; using std::set; using std::stringstream; using std::vector; -using testing::get; -using testing::make_tuple; -using testing::tuple; using testing::_; using testing::AllOf; using testing::AnyOf; @@ -118,20 +115,20 @@ std::string Explain(const MatcherType& m, const Value& x) { // Tests Args(m). TEST(ArgsTest, AcceptsZeroTemplateArg) { - const tuple t(5, true); - EXPECT_THAT(t, Args<>(Eq(tuple<>()))); - EXPECT_THAT(t, Not(Args<>(Ne(tuple<>())))); + const std::tuple t(5, true); + EXPECT_THAT(t, Args<>(Eq(std::tuple<>()))); + EXPECT_THAT(t, Not(Args<>(Ne(std::tuple<>())))); } TEST(ArgsTest, AcceptsOneTemplateArg) { - const tuple t(5, true); - EXPECT_THAT(t, Args<0>(Eq(make_tuple(5)))); - EXPECT_THAT(t, Args<1>(Eq(make_tuple(true)))); - EXPECT_THAT(t, Not(Args<1>(Eq(make_tuple(false))))); + const std::tuple t(5, true); + EXPECT_THAT(t, Args<0>(Eq(std::make_tuple(5)))); + EXPECT_THAT(t, Args<1>(Eq(std::make_tuple(true)))); + EXPECT_THAT(t, Not(Args<1>(Eq(std::make_tuple(false))))); } TEST(ArgsTest, AcceptsTwoTemplateArgs) { - const tuple t(4, 5, 6L); // NOLINT + const std::tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 1>(Lt()))); EXPECT_THAT(t, (Args<1, 2>(Lt()))); @@ -139,13 +136,13 @@ TEST(ArgsTest, AcceptsTwoTemplateArgs) { } TEST(ArgsTest, AcceptsRepeatedTemplateArgs) { - const tuple t(4, 5, 6L); // NOLINT + const std::tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<0, 0>(Eq()))); EXPECT_THAT(t, Not(Args<1, 1>(Ne()))); } TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { - const tuple t(4, 5, 6L); // NOLINT + const std::tuple t(4, 5, 6L); // NOLINT EXPECT_THAT(t, (Args<2, 0>(Gt()))); EXPECT_THAT(t, Not(Args<2, 1>(Lt()))); } @@ -161,29 +158,29 @@ TEST(ArgsTest, AcceptsDecreasingTemplateArgs) { #endif MATCHER(SumIsZero, "") { - return get<0>(arg) + get<1>(arg) + get<2>(arg) == 0; + return std::get<0>(arg) + std::get<1>(arg) + std::get<2>(arg) == 0; } TEST(ArgsTest, AcceptsMoreTemplateArgsThanArityOfOriginalTuple) { - EXPECT_THAT(make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero()))); - EXPECT_THAT(make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero()))); + EXPECT_THAT(std::make_tuple(-1, 2), (Args<0, 0, 1>(SumIsZero()))); + EXPECT_THAT(std::make_tuple(1, 2), Not(Args<0, 0, 1>(SumIsZero()))); } TEST(ArgsTest, CanBeNested) { - const tuple t(4, 5, 6L, 6); // NOLINT + const std::tuple t(4, 5, 6L, 6); // NOLINT EXPECT_THAT(t, (Args<1, 2, 3>(Args<1, 2>(Eq())))); EXPECT_THAT(t, (Args<0, 1, 3>(Args<0, 2>(Lt())))); } TEST(ArgsTest, CanMatchTupleByValue) { - typedef tuple Tuple3; + typedef std::tuple Tuple3; const Matcher m = Args<1, 2>(Lt()); EXPECT_TRUE(m.Matches(Tuple3('a', 1, 2))); EXPECT_FALSE(m.Matches(Tuple3('b', 2, 2))); } TEST(ArgsTest, CanMatchTupleByReference) { - typedef tuple Tuple3; + typedef std::tuple Tuple3; const Matcher m = Args<0, 1>(Lt()); EXPECT_TRUE(m.Matches(Tuple3('a', 'b', 2))); EXPECT_FALSE(m.Matches(Tuple3('b', 'b', 2))); @@ -195,23 +192,23 @@ MATCHER_P(PrintsAs, str, "") { } TEST(ArgsTest, AcceptsTenTemplateArgs) { - EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), + EXPECT_THAT(std::make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), (Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>( PrintsAs("(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); - EXPECT_THAT(make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), + EXPECT_THAT(std::make_tuple(0, 1L, 2, 3L, 4, 5, 6, 7, 8, 9), Not(Args<9, 8, 7, 6, 5, 4, 3, 2, 1, 0>( - PrintsAs("(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); + PrintsAs("(0, 8, 7, 6, 5, 4, 3, 2, 1, 0)")))); } TEST(ArgsTest, DescirbesSelfCorrectly) { - const Matcher > m = Args<2, 0>(Lt()); + const Matcher > m = Args<2, 0>(Lt()); EXPECT_EQ("are a tuple whose fields (#2, #0) are a pair where " "the first < the second", Describe(m)); } TEST(ArgsTest, DescirbesNestedArgsCorrectly) { - const Matcher&> m = + const Matcher&> m = Args<0, 2, 3>(Args<2, 0>(Lt())); EXPECT_EQ("are a tuple whose fields (#0, #2, #3) are a tuple " "whose fields (#2, #0) are a pair where the first < the second", @@ -219,28 +216,28 @@ TEST(ArgsTest, DescirbesNestedArgsCorrectly) { } TEST(ArgsTest, DescribesNegationCorrectly) { - const Matcher > m = Args<1, 0>(Gt()); + const Matcher > m = Args<1, 0>(Gt()); EXPECT_EQ("are a tuple whose fields (#1, #0) aren't a pair " "where the first > the second", DescribeNegation(m)); } TEST(ArgsTest, ExplainsMatchResultWithoutInnerExplanation) { - const Matcher > m = Args<1, 2>(Eq()); + const Matcher > m = Args<1, 2>(Eq()); EXPECT_EQ("whose fields (#1, #2) are (42, 42)", - Explain(m, make_tuple(false, 42, 42))); + Explain(m, std::make_tuple(false, 42, 42))); EXPECT_EQ("whose fields (#1, #2) are (42, 43)", - Explain(m, make_tuple(false, 42, 43))); + Explain(m, std::make_tuple(false, 42, 43))); } // For testing Args<>'s explanation. -class LessThanMatcher : public MatcherInterface > { +class LessThanMatcher : public MatcherInterface > { public: virtual void DescribeTo(::std::ostream* os) const {} - virtual bool MatchAndExplain(tuple value, + virtual bool MatchAndExplain(std::tuple value, MatchResultListener* listener) const { - const int diff = get<0>(value) - get<1>(value); + const int diff = std::get<0>(value) - std::get<1>(value); if (diff > 0) { *listener << "where the first value is " << diff << " more than the second"; @@ -249,17 +246,18 @@ class LessThanMatcher : public MatcherInterface > { } }; -Matcher > LessThan() { +Matcher > LessThan() { return MakeMatcher(new LessThanMatcher); } TEST(ArgsTest, ExplainsMatchResultWithInnerExplanation) { - const Matcher > m = Args<0, 2>(LessThan()); - EXPECT_EQ("whose fields (#0, #2) are ('a' (97, 0x61), 42), " - "where the first value is 55 more than the second", - Explain(m, make_tuple('a', 42, 42))); + const Matcher > m = Args<0, 2>(LessThan()); + EXPECT_EQ( + "whose fields (#0, #2) are ('a' (97, 0x61), 42), " + "where the first value is 55 more than the second", + Explain(m, std::make_tuple('a', 42, 42))); EXPECT_EQ("whose fields (#0, #2) are ('\\0', 43)", - Explain(m, make_tuple('\0', 42, 43))); + Explain(m, std::make_tuple('\0', 42, 43))); } // For testing ExplainMatchResultTo(). @@ -517,7 +515,7 @@ class NativeArrayPassedAsPointerAndSize { TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) { int array[] = { 0, 1 }; - ::testing::tuple array_as_tuple(array, 2); + ::std::tuple array_as_tuple(array, 2); EXPECT_THAT(array_as_tuple, ElementsAre(0, 1)); EXPECT_THAT(array_as_tuple, Not(ElementsAre(0))); @@ -571,8 +569,8 @@ TEST(ElementsAreTest, MakesCopyOfArguments) { int x = 1; int y = 2; // This should make a copy of x and y. - ::testing::internal::ElementsAreMatcher > - polymorphic_matcher = ElementsAre(x, y); + ::testing::internal::ElementsAreMatcher > + polymorphic_matcher = ElementsAre(x, y); // Changing x and y now shouldn't affect the meaning of the above matcher. x = y = 0; const int array1[] = { 1, 2 }; @@ -1235,8 +1233,8 @@ TEST(ContainsTest, AcceptsMatcher) { TEST(ContainsTest, WorksForNativeArrayAsTuple) { const int a[] = { 1, 2 }; const int* const pointer = a; - EXPECT_THAT(make_tuple(pointer, 2), Contains(1)); - EXPECT_THAT(make_tuple(pointer, 2), Not(Contains(Gt(3)))); + EXPECT_THAT(std::make_tuple(pointer, 2), Contains(1)); + EXPECT_THAT(std::make_tuple(pointer, 2), Not(Contains(Gt(3)))); } TEST(ContainsTest, WorksForTwoDimensionalNativeArray) { diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 7116e4fc..41498f0e 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -308,26 +308,23 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) { // Tests the TupleMatches() template function. TEST(TupleMatchesTest, WorksForSize0) { - tuple<> matchers; - tuple<> values; + std::tuple<> matchers; + std::tuple<> values; EXPECT_TRUE(TupleMatches(matchers, values)); } TEST(TupleMatchesTest, WorksForSize1) { - tuple > matchers(Eq(1)); - tuple values1(1), - values2(2); + std::tuple > matchers(Eq(1)); + std::tuple values1(1), values2(2); EXPECT_TRUE(TupleMatches(matchers, values1)); EXPECT_FALSE(TupleMatches(matchers, values2)); } TEST(TupleMatchesTest, WorksForSize2) { - tuple, Matcher > matchers(Eq(1), Eq('a')); - tuple values1(1, 'a'), - values2(1, 'b'), - values3(2, 'a'), + std::tuple, Matcher > matchers(Eq(1), Eq('a')); + std::tuple values1(1, 'a'), values2(1, 'b'), values3(2, 'a'), values4(2, 'b'); EXPECT_TRUE(TupleMatches(matchers, values1)); @@ -337,10 +334,11 @@ TEST(TupleMatchesTest, WorksForSize2) { } TEST(TupleMatchesTest, WorksForSize5) { - tuple, Matcher, Matcher, Matcher, // NOLINT - Matcher > + std::tuple, Matcher, Matcher, + Matcher, // NOLINT + Matcher > matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi")); - tuple // NOLINT + std::tuple // NOLINT values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"), values3(2, 'a', true, 2L, "hi"); @@ -686,22 +684,25 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) { TEST(StlContainerViewTest, WorksForDynamicNativeArray) { StaticAssertTypeEq, - StlContainerView >::type>(); - StaticAssertTypeEq, - StlContainerView, int> >::type>(); + StlContainerView >::type>(); + StaticAssertTypeEq< + NativeArray, + StlContainerView, int> >::type>(); - StaticAssertTypeEq, - StlContainerView >::const_reference>(); + StaticAssertTypeEq< + const NativeArray, + StlContainerView >::const_reference>(); int a1[3] = { 0, 1, 2 }; const int* const p1 = a1; - NativeArray a2 = StlContainerView >:: - ConstReference(make_tuple(p1, 3)); + NativeArray a2 = + StlContainerView >::ConstReference( + std::make_tuple(p1, 3)); EXPECT_EQ(3U, a2.size()); EXPECT_EQ(a1, a2.begin()); - const NativeArray a3 = StlContainerView >:: - Copy(make_tuple(static_cast(a1), 3)); + const NativeArray a3 = StlContainerView >::Copy( + std::make_tuple(static_cast(a1), 3)); ASSERT_EQ(3U, a3.size()); EXPECT_EQ(0, a3.begin()[0]); EXPECT_EQ(1, a3.begin()[1]); diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 6d432340..86ff580a 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -136,7 +136,6 @@ using testing::Value; using testing::WhenSorted; using testing::WhenSortedBy; using testing::_; -using testing::get; using testing::internal::DummyMatchResultListener; using testing::internal::ElementMatcherPair; using testing::internal::ElementMatcherPairs; @@ -153,8 +152,6 @@ using testing::internal::Strings; using testing::internal::linked_ptr; using testing::internal::scoped_ptr; using testing::internal::string; -using testing::make_tuple; -using testing::tuple; // For testing ExplainMatchResultTo(). class GreaterThanMatcher : public MatcherInterface { @@ -2239,8 +2236,7 @@ TEST(GlobalWideEndsWithTest, CanDescribeSelf) { #endif // GTEST_HAS_GLOBAL_WSTRING - -typedef ::testing::tuple Tuple2; // NOLINT +typedef ::std::tuple Tuple2; // NOLINT // Tests that Eq() matches a 2-tuple where the first field == the // second field. @@ -2334,7 +2330,7 @@ TEST(Ne2Test, CanDescribeSelf) { // Tests that FloatEq() matches a 2-tuple where // FloatEq(first field) matches the second field. TEST(FloatEq2Test, MatchesEqualArguments) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = FloatEq(); EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); EXPECT_TRUE(m.Matches(Tpl(0.3f, 0.1f + 0.1f + 0.1f))); @@ -2343,14 +2339,14 @@ TEST(FloatEq2Test, MatchesEqualArguments) { // Tests that FloatEq() describes itself properly. TEST(FloatEq2Test, CanDescribeSelf) { - Matcher&> m = FloatEq(); + Matcher&> m = FloatEq(); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that NanSensitiveFloatEq() matches a 2-tuple where // NanSensitiveFloatEq(first field) matches the second field. TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = NanSensitiveFloatEq(); EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), @@ -2362,14 +2358,14 @@ TEST(NanSensitiveFloatEqTest, MatchesEqualArgumentsWithNaN) { // Tests that NanSensitiveFloatEq() describes itself properly. TEST(NanSensitiveFloatEqTest, CanDescribeSelfWithNaNs) { - Matcher&> m = NanSensitiveFloatEq(); + Matcher&> m = NanSensitiveFloatEq(); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that DoubleEq() matches a 2-tuple where // DoubleEq(first field) matches the second field. TEST(DoubleEq2Test, MatchesEqualArguments) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = DoubleEq(); EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0))); EXPECT_TRUE(m.Matches(Tpl(0.3, 0.1 + 0.1 + 0.1))); @@ -2378,14 +2374,14 @@ TEST(DoubleEq2Test, MatchesEqualArguments) { // Tests that DoubleEq() describes itself properly. TEST(DoubleEq2Test, CanDescribeSelf) { - Matcher&> m = DoubleEq(); + Matcher&> m = DoubleEq(); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that NanSensitiveDoubleEq() matches a 2-tuple where // NanSensitiveDoubleEq(first field) matches the second field. TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = NanSensitiveDoubleEq(); EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); EXPECT_TRUE(m.Matches(Tpl(std::numeric_limits::quiet_NaN(), @@ -2397,14 +2393,14 @@ TEST(NanSensitiveDoubleEqTest, MatchesEqualArgumentsWithNaN) { // Tests that DoubleEq() describes itself properly. TEST(NanSensitiveDoubleEqTest, CanDescribeSelfWithNaNs) { - Matcher&> m = NanSensitiveDoubleEq(); + Matcher&> m = NanSensitiveDoubleEq(); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that FloatEq() matches a 2-tuple where // FloatNear(first field, max_abs_error) matches the second field. TEST(FloatNear2Test, MatchesEqualArguments) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = FloatNear(0.5f); EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); EXPECT_TRUE(m.Matches(Tpl(1.3f, 1.0f))); @@ -2413,14 +2409,14 @@ TEST(FloatNear2Test, MatchesEqualArguments) { // Tests that FloatNear() describes itself properly. TEST(FloatNear2Test, CanDescribeSelf) { - Matcher&> m = FloatNear(0.5f); + Matcher&> m = FloatNear(0.5f); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that NanSensitiveFloatNear() matches a 2-tuple where // NanSensitiveFloatNear(first field) matches the second field. TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = NanSensitiveFloatNear(0.5f); EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f))); @@ -2433,15 +2429,14 @@ TEST(NanSensitiveFloatNearTest, MatchesNearbyArgumentsWithNaN) { // Tests that NanSensitiveFloatNear() describes itself properly. TEST(NanSensitiveFloatNearTest, CanDescribeSelfWithNaNs) { - Matcher&> m = - NanSensitiveFloatNear(0.5f); + Matcher&> m = NanSensitiveFloatNear(0.5f); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that FloatEq() matches a 2-tuple where // DoubleNear(first field, max_abs_error) matches the second field. TEST(DoubleNear2Test, MatchesEqualArguments) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = DoubleNear(0.5); EXPECT_TRUE(m.Matches(Tpl(1.0, 1.0))); EXPECT_TRUE(m.Matches(Tpl(1.3, 1.0))); @@ -2450,14 +2445,14 @@ TEST(DoubleNear2Test, MatchesEqualArguments) { // Tests that DoubleNear() describes itself properly. TEST(DoubleNear2Test, CanDescribeSelf) { - Matcher&> m = DoubleNear(0.5); + Matcher&> m = DoubleNear(0.5); EXPECT_EQ("are an almost-equal pair", Describe(m)); } // Tests that NanSensitiveDoubleNear() matches a 2-tuple where // NanSensitiveDoubleNear(first field) matches the second field. TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) { - typedef ::testing::tuple Tpl; + typedef ::std::tuple Tpl; Matcher m = NanSensitiveDoubleNear(0.5f); EXPECT_TRUE(m.Matches(Tpl(1.0f, 1.0f))); EXPECT_TRUE(m.Matches(Tpl(1.1f, 1.0f))); @@ -2470,8 +2465,7 @@ TEST(NanSensitiveDoubleNearTest, MatchesNearbyArgumentsWithNaN) { // Tests that NanSensitiveDoubleNear() describes itself properly. TEST(NanSensitiveDoubleNearTest, CanDescribeSelfWithNaNs) { - Matcher&> m = - NanSensitiveDoubleNear(0.5f); + Matcher&> m = NanSensitiveDoubleNear(0.5f); EXPECT_EQ("are an almost-equal pair", Describe(m)); } @@ -3081,8 +3075,8 @@ TEST(DescribeMatcherTest, WorksWithPolymorphicMatcher) { } TEST(AllArgsTest, WorksForTuple) { - EXPECT_THAT(make_tuple(1, 2L), AllArgs(Lt())); - EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt()))); + EXPECT_THAT(std::make_tuple(1, 2L), AllArgs(Lt())); + EXPECT_THAT(std::make_tuple(2L, 1), Not(AllArgs(Lt()))); } TEST(AllArgsTest, WorksForNonTuple) { @@ -5060,11 +5054,11 @@ TEST(ContainerEqExtraTest, WorksForNativeArrayAsTuple) { const int b[] = {1, 2, 3, 4}; const int* const p1 = a1; - EXPECT_THAT(make_tuple(p1, 3), ContainerEq(a2)); - EXPECT_THAT(make_tuple(p1, 3), Not(ContainerEq(b))); + EXPECT_THAT(std::make_tuple(p1, 3), ContainerEq(a2)); + EXPECT_THAT(std::make_tuple(p1, 3), Not(ContainerEq(b))); const int c[] = {1, 3, 2}; - EXPECT_THAT(make_tuple(p1, 3), Not(ContainerEq(c))); + EXPECT_THAT(std::make_tuple(p1, 3), Not(ContainerEq(c))); } TEST(ContainerEqExtraTest, CopiesNativeArrayParameter) { @@ -6246,13 +6240,15 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) { TEST(MatcherTupleTest, ExplainsMatchFailure) { stringstream ss1; - ExplainMatchFailureTupleTo(make_tuple(Matcher(Eq('a')), GreaterThan(5)), - make_tuple('a', 10), &ss1); + ExplainMatchFailureTupleTo( + std::make_tuple(Matcher(Eq('a')), GreaterThan(5)), + std::make_tuple('a', 10), &ss1); EXPECT_EQ("", ss1.str()); // Successful match. stringstream ss2; - ExplainMatchFailureTupleTo(make_tuple(GreaterThan(5), Matcher(Eq('a'))), - make_tuple(2, 'b'), &ss2); + ExplainMatchFailureTupleTo( + std::make_tuple(GreaterThan(5), Matcher(Eq('a'))), + std::make_tuple(2, 'b'), &ss2); EXPECT_EQ(" Expected arg #0: is > 5\n" " Actual: 2, which is 3 less than 5\n" " Expected arg #1: is equal to 'a' (97, 0x61)\n" @@ -6260,8 +6256,9 @@ TEST(MatcherTupleTest, ExplainsMatchFailure) { ss2.str()); // Failed match where both arguments need explanation. stringstream ss3; - ExplainMatchFailureTupleTo(make_tuple(GreaterThan(5), Matcher(Eq('a'))), - make_tuple(2, 'a'), &ss3); + ExplainMatchFailureTupleTo( + std::make_tuple(GreaterThan(5), Matcher(Eq('a'))), + std::make_tuple(2, 'a'), &ss3); EXPECT_EQ(" Expected arg #0: is > 5\n" " Actual: 2, which is 3 less than 5\n", ss3.str()); // Failed match where only one argument needs @@ -6350,21 +6347,21 @@ TEST(EachTest, AcceptsMatcher) { TEST(EachTest, WorksForNativeArrayAsTuple) { const int a[] = {1, 2}; const int* const pointer = a; - EXPECT_THAT(make_tuple(pointer, 2), Each(Gt(0))); - EXPECT_THAT(make_tuple(pointer, 2), Not(Each(Gt(1)))); + EXPECT_THAT(std::make_tuple(pointer, 2), Each(Gt(0))); + EXPECT_THAT(std::make_tuple(pointer, 2), Not(Each(Gt(1)))); } // For testing Pointwise(). class IsHalfOfMatcher { public: template - bool MatchAndExplain(const tuple& a_pair, + bool MatchAndExplain(const std::tuple& a_pair, MatchResultListener* listener) const { - if (get<0>(a_pair) == get<1>(a_pair)/2) { - *listener << "where the second is " << get<1>(a_pair); + if (std::get<0>(a_pair) == std::get<1>(a_pair) / 2) { + *listener << "where the second is " << std::get<1>(a_pair); return true; } else { - *listener << "where the second/2 is " << get<1>(a_pair)/2; + *listener << "where the second/2 is " << std::get<1>(a_pair) / 2; return false; } } @@ -6481,13 +6478,13 @@ TEST(PointwiseTest, AcceptsCorrectContent) { TEST(PointwiseTest, AllowsMonomorphicInnerMatcher) { const double lhs[3] = {1, 2, 3}; const int rhs[3] = {2, 4, 6}; - const Matcher > m1 = IsHalfOf(); + const Matcher> m1 = IsHalfOf(); EXPECT_THAT(lhs, Pointwise(m1, rhs)); EXPECT_EQ("", Explain(Pointwise(m1, rhs), lhs)); - // This type works as a tuple can be - // implicitly cast to tuple. - const Matcher > m2 = IsHalfOf(); + // This type works as a std::tuple can be + // implicitly cast to std::tuple. + const Matcher> m2 = IsHalfOf(); EXPECT_THAT(lhs, Pointwise(m2, rhs)); EXPECT_EQ("", Explain(Pointwise(m2, rhs), lhs)); } @@ -6597,12 +6594,12 @@ TEST(UnorderedPointwiseTest, AcceptsCorrectContentInDifferentOrder) { TEST(UnorderedPointwiseTest, AllowsMonomorphicInnerMatcher) { const double lhs[3] = {1, 2, 3}; const int rhs[3] = {4, 6, 2}; - const Matcher > m1 = IsHalfOf(); + const Matcher> m1 = IsHalfOf(); EXPECT_THAT(lhs, UnorderedPointwise(m1, rhs)); - // This type works as a tuple can be - // implicitly cast to tuple. - const Matcher > m2 = IsHalfOf(); + // This type works as a std::tuple can be + // implicitly cast to std::tuple. + const Matcher> m2 = IsHalfOf(); EXPECT_THAT(lhs, UnorderedPointwise(m2, rhs)); } diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index 976b245e..521f3058 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -46,10 +46,6 @@ namespace gmock_more_actions_test { using ::std::plus; using ::std::string; -using testing::get; -using testing::make_tuple; -using testing::tuple; -using testing::tuple_element; using testing::_; using testing::Action; using testing::ActionInterface; @@ -232,45 +228,46 @@ class Foo { // Tests using Invoke() with a nullary function. TEST(InvokeTest, Nullary) { Action a = Invoke(Nullary); // NOLINT - EXPECT_EQ(1, a.Perform(make_tuple())); + EXPECT_EQ(1, a.Perform(std::make_tuple())); } // Tests using Invoke() with a unary function. TEST(InvokeTest, Unary) { Action a = Invoke(Unary); // NOLINT - EXPECT_FALSE(a.Perform(make_tuple(1))); - EXPECT_TRUE(a.Perform(make_tuple(-1))); + EXPECT_FALSE(a.Perform(std::make_tuple(1))); + EXPECT_TRUE(a.Perform(std::make_tuple(-1))); } // Tests using Invoke() with a binary function. TEST(InvokeTest, Binary) { Action a = Invoke(Binary); // NOLINT const char* p = "Hello"; - EXPECT_EQ(p + 2, a.Perform(make_tuple(p, Short(2)))); + EXPECT_EQ(p + 2, a.Perform(std::make_tuple(p, Short(2)))); } // Tests using Invoke() with a ternary function. TEST(InvokeTest, Ternary) { Action a = Invoke(Ternary); // NOLINT - EXPECT_EQ(6, a.Perform(make_tuple(1, '\2', Short(3)))); + EXPECT_EQ(6, a.Perform(std::make_tuple(1, '\2', Short(3)))); } // Tests using Invoke() with a 4-argument function. TEST(InvokeTest, FunctionThatTakes4Arguments) { Action a = Invoke(SumOf4); // NOLINT - EXPECT_EQ(1234, a.Perform(make_tuple(1000, 200, 30, 4))); + EXPECT_EQ(1234, a.Perform(std::make_tuple(1000, 200, 30, 4))); } // Tests using Invoke() with a 5-argument function. TEST(InvokeTest, FunctionThatTakes5Arguments) { Action a = Invoke(SumOf5); // NOLINT - EXPECT_EQ(12345, a.Perform(make_tuple(10000, 2000, 300, 40, 5))); + EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5))); } // Tests using Invoke() with a 6-argument function. TEST(InvokeTest, FunctionThatTakes6Arguments) { Action a = Invoke(SumOf6); // NOLINT - EXPECT_EQ(123456, a.Perform(make_tuple(100000, 20000, 3000, 400, 50, 6))); + EXPECT_EQ(123456, + a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6))); } // A helper that turns the type of a C-string literal from const @@ -283,9 +280,9 @@ TEST(InvokeTest, FunctionThatTakes7Arguments) { const char*, const char*, const char*)> a = Invoke(Concat7); EXPECT_EQ("1234567", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7")))); + a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7")))); } // Tests using Invoke() with a 8-argument function. @@ -294,9 +291,9 @@ TEST(InvokeTest, FunctionThatTakes8Arguments) { const char*, const char*, const char*, const char*)> a = Invoke(Concat8); EXPECT_EQ("12345678", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7"), CharPtr("8")))); + a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7"), CharPtr("8")))); } // Tests using Invoke() with a 9-argument function. @@ -305,10 +302,10 @@ TEST(InvokeTest, FunctionThatTakes9Arguments) { const char*, const char*, const char*, const char*, const char*)> a = Invoke(Concat9); - EXPECT_EQ("123456789", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7"), CharPtr("8"), CharPtr("9")))); + EXPECT_EQ("123456789", a.Perform(std::make_tuple( + CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7"), CharPtr("8"), CharPtr("9")))); } // Tests using Invoke() with a 10-argument function. @@ -318,46 +315,46 @@ TEST(InvokeTest, FunctionThatTakes10Arguments) { const char*, const char*)> a = Invoke(Concat10); EXPECT_EQ("1234567890", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7"), CharPtr("8"), CharPtr("9"), - CharPtr("0")))); + a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7"), CharPtr("8"), CharPtr("9"), + CharPtr("0")))); } // Tests using Invoke() with functions with parameters declared as Unused. TEST(InvokeTest, FunctionWithUnusedParameters) { Action a1 = Invoke(SumOfFirst2); - tuple dummy = - make_tuple(10, 2, 5.6, std::string("hi")); + std::tuple dummy = + std::make_tuple(10, 2, 5.6, std::string("hi")); EXPECT_EQ(12, a1.Perform(dummy)); Action a2 = Invoke(SumOfFirst2); - EXPECT_EQ(23, - a2.Perform(make_tuple(20, 3, true, static_cast(nullptr)))); + EXPECT_EQ( + 23, a2.Perform(std::make_tuple(20, 3, true, static_cast(nullptr)))); } // Tests using Invoke() with methods with parameters declared as Unused. TEST(InvokeTest, MethodWithUnusedParameters) { Foo foo; Action a1 = Invoke(&foo, &Foo::SumOfLast2); - EXPECT_EQ(12, a1.Perform(make_tuple(CharPtr("hi"), true, 10, 2))); + EXPECT_EQ(12, a1.Perform(std::make_tuple(CharPtr("hi"), true, 10, 2))); Action a2 = Invoke(&foo, &Foo::SumOfLast2); - EXPECT_EQ(23, a2.Perform(make_tuple('a', 2.5, 20, 3))); + EXPECT_EQ(23, a2.Perform(std::make_tuple('a', 2.5, 20, 3))); } // Tests using Invoke() with a functor. TEST(InvokeTest, Functor) { Action a = Invoke(plus()); // NOLINT - EXPECT_EQ(3L, a.Perform(make_tuple(1, 2))); + EXPECT_EQ(3L, a.Perform(std::make_tuple(1, 2))); } // Tests using Invoke(f) as an action of a compatible type. TEST(InvokeTest, FunctionWithCompatibleType) { Action a = Invoke(SumOf4); // NOLINT - EXPECT_EQ(4321, a.Perform(make_tuple(4000, Short(300), Char(20), true))); + EXPECT_EQ(4321, a.Perform(std::make_tuple(4000, Short(300), Char(20), true))); } // Tests using Invoke() with an object pointer and a method pointer. @@ -366,14 +363,14 @@ TEST(InvokeTest, FunctionWithCompatibleType) { TEST(InvokeMethodTest, Nullary) { Foo foo; Action a = Invoke(&foo, &Foo::Nullary); // NOLINT - EXPECT_EQ(123, a.Perform(make_tuple())); + EXPECT_EQ(123, a.Perform(std::make_tuple())); } // Tests using Invoke() with a unary method. TEST(InvokeMethodTest, Unary) { Foo foo; Action a = Invoke(&foo, &Foo::Unary); // NOLINT - EXPECT_EQ(4123, a.Perform(make_tuple(4000))); + EXPECT_EQ(4123, a.Perform(std::make_tuple(4000))); } // Tests using Invoke() with a binary method. @@ -381,7 +378,7 @@ TEST(InvokeMethodTest, Binary) { Foo foo; Action a = Invoke(&foo, &Foo::Binary); std::string s("Hell"); - tuple dummy = make_tuple(s, 'o'); + std::tuple dummy = std::make_tuple(s, 'o'); EXPECT_EQ("Hello", a.Perform(dummy)); } @@ -389,21 +386,21 @@ TEST(InvokeMethodTest, Binary) { TEST(InvokeMethodTest, Ternary) { Foo foo; Action a = Invoke(&foo, &Foo::Ternary); // NOLINT - EXPECT_EQ(1124, a.Perform(make_tuple(1000, true, Char(1)))); + EXPECT_EQ(1124, a.Perform(std::make_tuple(1000, true, Char(1)))); } // Tests using Invoke() with a 4-argument method. TEST(InvokeMethodTest, MethodThatTakes4Arguments) { Foo foo; Action a = Invoke(&foo, &Foo::SumOf4); // NOLINT - EXPECT_EQ(1357, a.Perform(make_tuple(1000, 200, 30, 4))); + EXPECT_EQ(1357, a.Perform(std::make_tuple(1000, 200, 30, 4))); } // Tests using Invoke() with a 5-argument method. TEST(InvokeMethodTest, MethodThatTakes5Arguments) { Foo foo; Action a = Invoke(&foo, &Foo::SumOf5); // NOLINT - EXPECT_EQ(12345, a.Perform(make_tuple(10000, 2000, 300, 40, 5))); + EXPECT_EQ(12345, a.Perform(std::make_tuple(10000, 2000, 300, 40, 5))); } // Tests using Invoke() with a 6-argument method. @@ -411,7 +408,8 @@ TEST(InvokeMethodTest, MethodThatTakes6Arguments) { Foo foo; Action a = // NOLINT Invoke(&foo, &Foo::SumOf6); - EXPECT_EQ(123456, a.Perform(make_tuple(100000, 20000, 3000, 400, 50, 6))); + EXPECT_EQ(123456, + a.Perform(std::make_tuple(100000, 20000, 3000, 400, 50, 6))); } // Tests using Invoke() with a 7-argument method. @@ -421,9 +419,9 @@ TEST(InvokeMethodTest, MethodThatTakes7Arguments) { const char*, const char*, const char*)> a = Invoke(&foo, &Foo::Concat7); EXPECT_EQ("1234567", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7")))); + a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7")))); } // Tests using Invoke() with a 8-argument method. @@ -433,9 +431,9 @@ TEST(InvokeMethodTest, MethodThatTakes8Arguments) { const char*, const char*, const char*, const char*)> a = Invoke(&foo, &Foo::Concat8); EXPECT_EQ("12345678", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7"), CharPtr("8")))); + a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7"), CharPtr("8")))); } // Tests using Invoke() with a 9-argument method. @@ -445,10 +443,10 @@ TEST(InvokeMethodTest, MethodThatTakes9Arguments) { const char*, const char*, const char*, const char*, const char*)> a = Invoke(&foo, &Foo::Concat9); - EXPECT_EQ("123456789", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7"), CharPtr("8"), CharPtr("9")))); + EXPECT_EQ("123456789", a.Perform(std::make_tuple( + CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7"), CharPtr("8"), CharPtr("9")))); } // Tests using Invoke() with a 10-argument method. @@ -459,10 +457,10 @@ TEST(InvokeMethodTest, MethodThatTakes10Arguments) { const char*, const char*)> a = Invoke(&foo, &Foo::Concat10); EXPECT_EQ("1234567890", - a.Perform(make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), - CharPtr("4"), CharPtr("5"), CharPtr("6"), - CharPtr("7"), CharPtr("8"), CharPtr("9"), - CharPtr("0")))); + a.Perform(std::make_tuple(CharPtr("1"), CharPtr("2"), CharPtr("3"), + CharPtr("4"), CharPtr("5"), CharPtr("6"), + CharPtr("7"), CharPtr("8"), CharPtr("9"), + CharPtr("0")))); } // Tests using Invoke(f) as an action of a compatible type. @@ -470,48 +468,48 @@ TEST(InvokeMethodTest, MethodWithCompatibleType) { Foo foo; Action a = // NOLINT Invoke(&foo, &Foo::SumOf4); - EXPECT_EQ(4444, a.Perform(make_tuple(4000, Short(300), Char(20), true))); + EXPECT_EQ(4444, a.Perform(std::make_tuple(4000, Short(300), Char(20), true))); } // Tests using WithoutArgs with an action that takes no argument. TEST(WithoutArgsTest, NoArg) { Action a = WithoutArgs(Invoke(Nullary)); // NOLINT - EXPECT_EQ(1, a.Perform(make_tuple(2))); + EXPECT_EQ(1, a.Perform(std::make_tuple(2))); } // Tests using WithArg with an action that takes 1 argument. TEST(WithArgTest, OneArg) { Action b = WithArg<1>(Invoke(Unary)); // NOLINT - EXPECT_TRUE(b.Perform(make_tuple(1.5, -1))); - EXPECT_FALSE(b.Perform(make_tuple(1.5, 1))); + EXPECT_TRUE(b.Perform(std::make_tuple(1.5, -1))); + EXPECT_FALSE(b.Perform(std::make_tuple(1.5, 1))); } TEST(ReturnArgActionTest, WorksForOneArgIntArg0) { const Action a = ReturnArg<0>(); - EXPECT_EQ(5, a.Perform(make_tuple(5))); + EXPECT_EQ(5, a.Perform(std::make_tuple(5))); } TEST(ReturnArgActionTest, WorksForMultiArgBoolArg0) { const Action a = ReturnArg<0>(); - EXPECT_TRUE(a.Perform(make_tuple(true, false, false))); + EXPECT_TRUE(a.Perform(std::make_tuple(true, false, false))); } TEST(ReturnArgActionTest, WorksForMultiArgStringArg2) { const Action a = ReturnArg<2>(); - EXPECT_EQ("seven", a.Perform(make_tuple(5, 6, std::string("seven"), 8))); + EXPECT_EQ("seven", a.Perform(std::make_tuple(5, 6, std::string("seven"), 8))); } TEST(SaveArgActionTest, WorksForSameType) { int result = 0; const Action a1 = SaveArg<0>(&result); - a1.Perform(make_tuple(5)); + a1.Perform(std::make_tuple(5)); EXPECT_EQ(5, result); } TEST(SaveArgActionTest, WorksForCompatibleType) { int result = 0; const Action a1 = SaveArg<1>(&result); - a1.Perform(make_tuple(true, 'a')); + a1.Perform(std::make_tuple(true, 'a')); EXPECT_EQ('a', result); } @@ -519,7 +517,7 @@ TEST(SaveArgPointeeActionTest, WorksForSameType) { int result = 0; const int value = 5; const Action a1 = SaveArgPointee<0>(&result); - a1.Perform(make_tuple(&value)); + a1.Perform(std::make_tuple(&value)); EXPECT_EQ(5, result); } @@ -527,7 +525,7 @@ TEST(SaveArgPointeeActionTest, WorksForCompatibleType) { int result = 0; char value = 'a'; const Action a1 = SaveArgPointee<1>(&result); - a1.Perform(make_tuple(true, &value)); + a1.Perform(std::make_tuple(true, &value)); EXPECT_EQ('a', result); } @@ -535,28 +533,28 @@ TEST(SaveArgPointeeActionTest, WorksForLinkedPtr) { int result = 0; linked_ptr value(new int(5)); const Action)> a1 = SaveArgPointee<0>(&result); - a1.Perform(make_tuple(value)); + a1.Perform(std::make_tuple(value)); EXPECT_EQ(5, result); } TEST(SetArgRefereeActionTest, WorksForSameType) { int value = 0; const Action a1 = SetArgReferee<0>(1); - a1.Perform(tuple(value)); + a1.Perform(std::tuple(value)); EXPECT_EQ(1, value); } TEST(SetArgRefereeActionTest, WorksForCompatibleType) { int value = 0; const Action a1 = SetArgReferee<1>('a'); - a1.Perform(tuple(0, value)); + a1.Perform(std::tuple(0, value)); EXPECT_EQ('a', value); } TEST(SetArgRefereeActionTest, WorksWithExtraArguments) { int value = 0; const Action a1 = SetArgReferee<2>('a'); - a1.Perform(tuple(true, 0, value, "hi")); + a1.Perform(std::tuple(true, 0, value, "hi")); EXPECT_EQ('a', value); } @@ -583,7 +581,7 @@ TEST(DeleteArgActionTest, OneArg) { DeletionTester* t = new DeletionTester(&is_deleted); const Action a1 = DeleteArg<0>(); // NOLINT EXPECT_FALSE(is_deleted); - a1.Perform(make_tuple(t)); + a1.Perform(std::make_tuple(t)); EXPECT_TRUE(is_deleted); } @@ -593,7 +591,7 @@ TEST(DeleteArgActionTest, TenArgs) { const Action a1 = DeleteArg<9>(); EXPECT_FALSE(is_deleted); - a1.Perform(make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t)); + a1.Perform(std::make_tuple(true, 5, 6, CharPtr("hi"), false, 7, 8, 9, 10, t)); EXPECT_TRUE(is_deleted); } @@ -601,19 +599,19 @@ TEST(DeleteArgActionTest, TenArgs) { TEST(ThrowActionTest, ThrowsGivenExceptionInVoidFunction) { const Action a = Throw('a'); - EXPECT_THROW(a.Perform(make_tuple(0)), char); + EXPECT_THROW(a.Perform(std::make_tuple(0)), char); } class MyException {}; TEST(ThrowActionTest, ThrowsGivenExceptionInNonVoidFunction) { const Action a = Throw(MyException()); - EXPECT_THROW(a.Perform(make_tuple('0')), MyException); + EXPECT_THROW(a.Perform(std::make_tuple('0')), MyException); } TEST(ThrowActionTest, ThrowsGivenExceptionInNullaryFunction) { const Action a = Throw(MyException()); - EXPECT_THROW(a.Perform(make_tuple()), MyException); + EXPECT_THROW(a.Perform(std::make_tuple()), MyException); } #endif // GTEST_HAS_EXCEPTIONS @@ -629,7 +627,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) { int* pn = n; char ch[4] = {}; char* pch = ch; - a.Perform(make_tuple(true, pn, pch)); + a.Perform(std::make_tuple(true, pn, pch)); EXPECT_EQ(1, n[0]); EXPECT_EQ(2, n[1]); EXPECT_EQ(3, n[2]); @@ -644,7 +642,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArray) { a = SetArrayArgument<2>(letters.begin(), letters.end()); std::fill_n(n, 4, 0); std::fill_n(ch, 4, '\0'); - a.Perform(make_tuple(true, pn, pch)); + a.Perform(std::make_tuple(true, pn, pch)); EXPECT_EQ(0, n[0]); EXPECT_EQ(0, n[1]); EXPECT_EQ(0, n[2]); @@ -663,7 +661,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithEmptyRange) { int n[4] = {}; int* pn = n; - a.Perform(make_tuple(true, pn)); + a.Perform(std::make_tuple(true, pn)); EXPECT_EQ(0, n[0]); EXPECT_EQ(0, n[1]); EXPECT_EQ(0, n[2]); @@ -679,7 +677,7 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithConvertibleType) { int codes[4] = { 111, 222, 333, 444 }; int* pcodes = codes; - a.Perform(make_tuple(true, pcodes)); + a.Perform(std::make_tuple(true, pcodes)); EXPECT_EQ(97, codes[0]); EXPECT_EQ(98, codes[1]); EXPECT_EQ(99, codes[2]); @@ -693,17 +691,17 @@ TEST(SetArrayArgumentTest, SetsTheNthArrayWithIteratorArgument) { Action a = SetArrayArgument<1>(letters.begin(), letters.end()); std::string s; - a.Perform(make_tuple(true, back_inserter(s))); + a.Perform(std::make_tuple(true, back_inserter(s))); EXPECT_EQ(letters, s); } TEST(ReturnPointeeTest, Works) { int n = 42; const Action a = ReturnPointee(&n); - EXPECT_EQ(42, a.Perform(make_tuple())); + EXPECT_EQ(42, a.Perform(std::make_tuple())); n = 43; - EXPECT_EQ(43, a.Perform(make_tuple())); + EXPECT_EQ(43, a.Perform(std::make_tuple())); } } // namespace gmock_generated_actions_test -- cgit v1.2.3 From 78761b58fc9ae65acaebb6a9e34087e593c89c93 Mon Sep 17 00:00:00 2001 From: misterg Date: Tue, 9 Oct 2018 16:26:28 -0400 Subject: Remove non-variadic pre C++11 AnyOf PiperOrigin-RevId: 216411381 --- googlemock/test/gmock-matchers_test.cc | 42 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 86ff580a..f4e9e9f7 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2790,28 +2790,22 @@ TEST(ElementsAreTest, HugeMatcherUnordered) { TEST(AnyOfTest, CanDescribeSelf) { Matcher m; m = AnyOf(Le(1), Ge(3)); + EXPECT_EQ("(is <= 1) or (is >= 3)", Describe(m)); m = AnyOf(Lt(0), Eq(1), Eq(2)); - EXPECT_EQ("(is < 0) or " - "((is equal to 1) or (is equal to 2))", - Describe(m)); + EXPECT_EQ("(is < 0) or (is equal to 1) or (is equal to 2)", Describe(m)); m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3)); - EXPECT_EQ("((is < 0) or " - "(is equal to 1)) or " - "((is equal to 2) or " - "(is equal to 3))", + EXPECT_EQ("(is < 0) or (is equal to 1) or (is equal to 2) or (is equal to 3)", Describe(m)); m = AnyOf(Le(0), Gt(10), 3, 5, 7); - EXPECT_EQ("((is <= 0) or " - "(is > 10)) or " - "((is equal to 3) or " - "((is equal to 5) or " - "(is equal to 7)))", - Describe(m)); + EXPECT_EQ( + "(is <= 0) or (is > 10) or (is equal to 3) or (is equal to 5) or (is " + "equal to 7)", + Describe(m)); } // Tests that AnyOf(m1, ..., mn) describes its negation properly. @@ -2822,24 +2816,20 @@ TEST(AnyOfTest, CanDescribeNegation) { DescribeNegation(m)); m = AnyOf(Lt(0), Eq(1), Eq(2)); - EXPECT_EQ("(isn't < 0) and " - "((isn't equal to 1) and (isn't equal to 2))", + EXPECT_EQ("(isn't < 0) and (isn't equal to 1) and (isn't equal to 2)", DescribeNegation(m)); m = AnyOf(Lt(0), Eq(1), Eq(2), Eq(3)); - EXPECT_EQ("((isn't < 0) and " - "(isn't equal to 1)) and " - "((isn't equal to 2) and " - "(isn't equal to 3))", - DescribeNegation(m)); + EXPECT_EQ( + "(isn't < 0) and (isn't equal to 1) and (isn't equal to 2) and (isn't " + "equal to 3)", + DescribeNegation(m)); m = AnyOf(Le(0), Gt(10), 3, 5, 7); - EXPECT_EQ("((isn't <= 0) and " - "(isn't > 10)) and " - "((isn't equal to 3) and " - "((isn't equal to 5) and " - "(isn't equal to 7)))", - DescribeNegation(m)); + EXPECT_EQ( + "(isn't <= 0) and (isn't > 10) and (isn't equal to 3) and (isn't equal " + "to 5) and (isn't equal to 7)", + DescribeNegation(m)); } // Tests that monomorphic matchers are safely cast by the AnyOf matcher. -- cgit v1.2.3 From 0e71eb069a797671b7e98bd5297a134c980f4b42 Mon Sep 17 00:00:00 2001 From: misterg Date: Tue, 9 Oct 2018 16:57:30 -0400 Subject: Internal Change PiperOrigin-RevId: 216417182 --- googlemock/test/BUILD.bazel | 123 -------------------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 googlemock/test/BUILD.bazel (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel deleted file mode 100644 index 0fe72a67..00000000 --- a/googlemock/test/BUILD.bazel +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright 2017 Google Inc. -# All Rights Reserved. -# -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Author: misterg@google.com (Gennadiy Civil) -# -# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock - -licenses(["notice"]) - -""" gmock own tests """ - -cc_test( - name = "gmock_all_test", - size = "small", - srcs = glob( - include = [ - "gmock-*.cc", - ], - ), - linkopts = select({ - "//:windows": [], - "//:windows_msvc": [], - "//conditions:default": [ - "-pthread", - ], - }), - deps = ["//:gtest"], -) - -# Py tests - -py_library( - name = "gmock_test_utils", - testonly = 1, - srcs = ["gmock_test_utils.py"], -) - -cc_binary( - name = "gmock_leak_test_", - testonly = 1, - srcs = ["gmock_leak_test_.cc"], - deps = [ - "//:gtest_main", - ], -) - -py_test( - name = "gmock_leak_test", - size = "medium", - srcs = ["gmock_leak_test.py"], - data = [ - ":gmock_leak_test_", - ":gmock_test_utils", - ], -) - -cc_test( - name = "gmock_link_test", - size = "small", - srcs = [ - "gmock_link2_test.cc", - "gmock_link_test.cc", - "gmock_link_test.h", - ], - deps = [ - "//:gtest_main", - ], -) - -cc_binary( - name = "gmock_output_test_", - srcs = ["gmock_output_test_.cc"], - deps = [ - "//:gtest", - ], -) - -py_test( - name = "gmock_output_test", - size = "medium", - srcs = ["gmock_output_test.py"], - data = [ - ":gmock_output_test_", - ":gmock_output_test_golden.txt", - ], - deps = [":gmock_test_utils"], -) - -cc_test( - name = "gmock_test", - size = "small", - srcs = ["gmock_test.cc"], - deps = [ - "//:gtest_main", - ], -) -- cgit v1.2.3 From bc6a4ce380862ba274a3b7b2a33b295a858eb0a9 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 9 Oct 2018 17:30:36 -0400 Subject: Project import generated by Copybara. PiperOrigin-RevId: 216423319 --- googlemock/test/BUILD.bazel | 123 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 googlemock/test/BUILD.bazel (limited to 'googlemock/test') diff --git a/googlemock/test/BUILD.bazel b/googlemock/test/BUILD.bazel new file mode 100644 index 00000000..0fe72a67 --- /dev/null +++ b/googlemock/test/BUILD.bazel @@ -0,0 +1,123 @@ +# Copyright 2017 Google Inc. +# All Rights Reserved. +# +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Author: misterg@google.com (Gennadiy Civil) +# +# Bazel Build for Google C++ Testing Framework(Google Test)-googlemock + +licenses(["notice"]) + +""" gmock own tests """ + +cc_test( + name = "gmock_all_test", + size = "small", + srcs = glob( + include = [ + "gmock-*.cc", + ], + ), + linkopts = select({ + "//:windows": [], + "//:windows_msvc": [], + "//conditions:default": [ + "-pthread", + ], + }), + deps = ["//:gtest"], +) + +# Py tests + +py_library( + name = "gmock_test_utils", + testonly = 1, + srcs = ["gmock_test_utils.py"], +) + +cc_binary( + name = "gmock_leak_test_", + testonly = 1, + srcs = ["gmock_leak_test_.cc"], + deps = [ + "//:gtest_main", + ], +) + +py_test( + name = "gmock_leak_test", + size = "medium", + srcs = ["gmock_leak_test.py"], + data = [ + ":gmock_leak_test_", + ":gmock_test_utils", + ], +) + +cc_test( + name = "gmock_link_test", + size = "small", + srcs = [ + "gmock_link2_test.cc", + "gmock_link_test.cc", + "gmock_link_test.h", + ], + deps = [ + "//:gtest_main", + ], +) + +cc_binary( + name = "gmock_output_test_", + srcs = ["gmock_output_test_.cc"], + deps = [ + "//:gtest", + ], +) + +py_test( + name = "gmock_output_test", + size = "medium", + srcs = ["gmock_output_test.py"], + data = [ + ":gmock_output_test_", + ":gmock_output_test_golden.txt", + ], + deps = [":gmock_test_utils"], +) + +cc_test( + name = "gmock_test", + size = "small", + srcs = ["gmock_test.cc"], + deps = [ + "//:gtest_main", + ], +) -- cgit v1.2.3