From 6414d806cd7d0954cce81348552fdd1e5bd31515 Mon Sep 17 00:00:00 2001 From: kosak Date: Tue, 3 Dec 2013 23:19:36 +0000 Subject: [PATCH] Fix warnings encountered with clang -Wall, and pull in gtest 670. --- test/gmock-generated-matchers_test.cc | 41 +++++++++++++-------------- test/gmock-matchers_test.cc | 29 +++++++++---------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/test/gmock-generated-matchers_test.cc b/test/gmock-generated-matchers_test.cc index dba74ecb..c59b7dec 100644 --- a/test/gmock-generated-matchers_test.cc +++ b/test/gmock-generated-matchers_test.cc @@ -81,9 +81,6 @@ using testing::Value; using testing::internal::ElementsAreArrayMatcher; using testing::internal::string; -// Evaluates to the number of elements in 'array'. -#define GMOCK_ARRAY_SIZE_(a) (sizeof(a) / sizeof(a[0])) - // Returns the description of the given matcher. template string Describe(const Matcher& m) { @@ -337,7 +334,7 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) { ElementsAre(GreaterThan(1), 0, GreaterThan(2)); const int a[] = { 10, 0, 100 }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n" "and whose element #2 matches, which is 98 more than 2", Explain(m, test_vector)); @@ -422,7 +419,7 @@ TEST(ElementsAreTest, MatchesThreeElementsMixedMatchers) { TEST(ElementsAreTest, MatchesTenElementVector) { const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, // The element list can contain values and/or matchers @@ -465,7 +462,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) { }; vector > nested; - for (size_t i = 0; i < GMOCK_ARRAY_SIZE_(strings); i++) { + for (size_t i = 0; i < GTEST_ARRAY_SIZE_(strings); i++) { nested.push_back(list(strings[i], strings[i] + strlen(strings[i]))); } @@ -477,7 +474,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) { TEST(ElementsAreTest, WorksWithByRefElementMatchers) { int a[] = { 0, 1, 2 }; - vector v(a, a + GMOCK_ARRAY_SIZE_(a)); + vector v(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(v, ElementsAre(Ref(v[0]), Ref(v[1]), Ref(v[2]))); EXPECT_THAT(v, Not(ElementsAre(Ref(v[0]), Ref(v[1]), Ref(a[2])))); @@ -485,7 +482,7 @@ TEST(ElementsAreTest, WorksWithByRefElementMatchers) { TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) { int a[] = { 0, 1, 2 }; - vector v(a, a + GMOCK_ARRAY_SIZE_(a)); + vector v(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(&v, Pointee(ElementsAre(0, 1, _))); EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3)))); @@ -582,7 +579,7 @@ TEST(ElementsAreTest, MakesCopyOfArguments) { TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) { const int a[] = { 1, 2, 3 }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, ElementsAreArray(a)); test_vector[2] = 0; @@ -592,18 +589,18 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) { TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) { const char* a[] = { "one", "two", "three" }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); - EXPECT_THAT(test_vector, ElementsAreArray(a, GMOCK_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; test_vector[0] = "1"; - EXPECT_THAT(test_vector, Not(ElementsAreArray(p, GMOCK_ARRAY_SIZE_(a)))); + EXPECT_THAT(test_vector, Not(ElementsAreArray(p, GTEST_ARRAY_SIZE_(a)))); } TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) { const char* a[] = { "one", "two", "three" }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, ElementsAreArray(a)); test_vector[0] = "1"; @@ -626,8 +623,8 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) { TEST(ElementsAreArrayTest, CanBeCreatedWithVector) { const int a[] = { 1, 2, 3 }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); - const vector expected(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); + const vector expected(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, ElementsAreArray(expected)); test_vector.push_back(4); EXPECT_THAT(test_vector, Not(ElementsAreArray(expected))); @@ -674,9 +671,9 @@ TEST(ElementsAreArrayTest, TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) { const int a[] = { 1, 2, 3 }; const Matcher kMatchers[] = { Eq(1), Eq(2), Eq(3) }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); const vector > expected( - kMatchers, kMatchers + GMOCK_ARRAY_SIZE_(kMatchers)); + kMatchers, kMatchers + GTEST_ARRAY_SIZE_(kMatchers)); EXPECT_THAT(test_vector, ElementsAreArray(expected)); test_vector.push_back(4); EXPECT_THAT(test_vector, Not(ElementsAreArray(expected))); @@ -684,11 +681,11 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) { TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) { const int a[] = { 1, 2, 3 }; - const vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); - const vector expected(a, a + GMOCK_ARRAY_SIZE_(a)); + const vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); + const vector expected(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end())); // Pointers are iterators, too. - EXPECT_THAT(test_vector, ElementsAreArray(a, a + GMOCK_ARRAY_SIZE_(a))); + 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; EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int))); @@ -708,8 +705,8 @@ TEST(ElementsAreArrayTest, WorksWithNativeArray) { TEST(ElementsAreArrayTest, SourceLifeSpan) { const int a[] = { 1, 2, 3 }; - vector test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); - vector expect(a, a + GMOCK_ARRAY_SIZE_(a)); + vector test_vector(a, a + GTEST_ARRAY_SIZE_(a)); + vector expect(a, a + GTEST_ARRAY_SIZE_(a)); ElementsAreArrayMatcher matcher_maker = ElementsAreArray(expect.begin(), expect.end()); EXPECT_THAT(test_vector, matcher_maker); diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc index 5de45c78..bd7a38a5 100644 --- a/test/gmock-matchers_test.cc +++ b/test/gmock-matchers_test.cc @@ -151,9 +151,6 @@ using testing::internal::linked_ptr; using testing::internal::scoped_ptr; using testing::internal::string; -// Evaluates to the number of elements in 'array'. -#define GMOCK_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0])) - // For testing ExplainMatchResultTo(). class GreaterThanMatcher : public MatcherInterface { public: @@ -3444,6 +3441,8 @@ double AClass::x_ = 0.0; // A derived class for testing Property(). class DerivedClass : public AClass { + public: + int k() const { return k_; } private: int k_; }; @@ -4424,14 +4423,14 @@ TEST(WhenSortedTest, WorksForStreamlike) { // Streamlike 'container' provides only minimal iterator support. // Its iterators are tagged with input_iterator_tag. const int a[5] = { 2, 1, 4, 5, 3 }; - Streamlike s(a, a + GMOCK_ARRAY_SIZE_(a)); + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(s, WhenSorted(ElementsAre(1, 2, 3, 4, 5))); EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); } TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) { const int a[] = { 2, 1, 4, 5, 3 }; - Streamlike s(a, a + GMOCK_ARRAY_SIZE_(a)); + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); Matcher&> vector_match = ElementsAre(1, 2, 3, 4, 5); EXPECT_THAT(s, WhenSorted(vector_match)); EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); @@ -4442,14 +4441,14 @@ TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) { TEST(ElemensAreStreamTest, WorksForStreamlike) { const int a[5] = { 1, 2, 3, 4, 5 }; - Streamlike s(a, a + GMOCK_ARRAY_SIZE_(a)); + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(s, ElementsAre(1, 2, 3, 4, 5)); EXPECT_THAT(s, Not(ElementsAre(2, 1, 4, 5, 3))); } TEST(ElemensAreArrayStreamTest, WorksForStreamlike) { const int a[5] = { 1, 2, 3, 4, 5 }; - Streamlike s(a, a + GMOCK_ARRAY_SIZE_(a)); + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); vector expected; expected.push_back(1); @@ -4467,7 +4466,7 @@ TEST(ElemensAreArrayStreamTest, WorksForStreamlike) { TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { const int a[] = { 0, 1, 2, 3, 4 }; - std::vector s(a, a + GMOCK_ARRAY_SIZE_(a)); + std::vector s(a, a + GTEST_ARRAY_SIZE_(a)); do { StringMatchResultListener listener; EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(a), @@ -4478,8 +4477,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { TEST(UnorderedElementsAreArrayTest, VectorBool) { const bool a[] = { 0, 1, 0, 1, 1 }; const bool b[] = { 1, 0, 1, 1, 0 }; - std::vector expected(a, a + GMOCK_ARRAY_SIZE_(a)); - std::vector actual(b, b + GMOCK_ARRAY_SIZE_(b)); + std::vector expected(a, a + GTEST_ARRAY_SIZE_(a)); + std::vector actual(b, b + GTEST_ARRAY_SIZE_(b)); StringMatchResultListener listener; EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(expected), actual, &listener)) << listener.str(); @@ -4490,7 +4489,7 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) { // Its iterators are tagged with input_iterator_tag, and it has no // size() or empty() methods. const int a[5] = { 2, 1, 4, 5, 3 }; - Streamlike s(a, a + GMOCK_ARRAY_SIZE_(a)); + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); ::std::vector expected; expected.push_back(1); @@ -4547,7 +4546,7 @@ class UnorderedElementsAreTest : public testing::Test { TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) { const int a[] = { 1, 2, 3 }; - std::vector s(a, a + GMOCK_ARRAY_SIZE_(a)); + std::vector s(a, a + GTEST_ARRAY_SIZE_(a)); do { StringMatchResultListener listener; EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), @@ -4557,7 +4556,7 @@ TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) { TEST_F(UnorderedElementsAreTest, FailsWhenAnElementMatchesNoMatcher) { const int a[] = { 1, 2, 3 }; - std::vector s(a, a + GMOCK_ARRAY_SIZE_(a)); + std::vector s(a, a + GTEST_ARRAY_SIZE_(a)); std::vector > mv; mv.push_back(1); mv.push_back(2); @@ -4573,7 +4572,7 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) { // Its iterators are tagged with input_iterator_tag, and it has no // size() or empty() methods. const int a[5] = { 2, 1, 4, 5, 3 }; - Streamlike s(a, a + GMOCK_ARRAY_SIZE_(a)); + Streamlike s(a, a + GTEST_ARRAY_SIZE_(a)); EXPECT_THAT(s, UnorderedElementsAre(1, 2, 3, 4, 5)); EXPECT_THAT(s, Not(UnorderedElementsAre(2, 2, 3, 4, 5))); @@ -4884,7 +4883,7 @@ TEST_F(BipartiteNonSquareTest, SimpleBacktracking) { // 0 1 2 MatchMatrix g(4, 3); static const int kEdges[][2] = { {0, 2}, {1, 1}, {2, 1}, {3, 0} }; - for (size_t i = 0; i < GMOCK_ARRAY_SIZE_(kEdges); ++i) { + for (size_t i = 0; i < GTEST_ARRAY_SIZE_(kEdges); ++i) { g.SetEdge(kEdges[i][0], kEdges[i][1], true); } EXPECT_THAT(FindBacktrackingMaxBPM(g),