Fix warnings encountered with clang -Wall, and pull in gtest 670.

This commit is contained in:
kosak 2013-12-03 23:19:36 +00:00
parent b72d18ca55
commit 6414d806cd
2 changed files with 33 additions and 37 deletions

View File

@ -81,9 +81,6 @@ using testing::Value;
using testing::internal::ElementsAreArrayMatcher; using testing::internal::ElementsAreArrayMatcher;
using testing::internal::string; 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. // Returns the description of the given matcher.
template <typename T> template <typename T>
string Describe(const Matcher<T>& m) { string Describe(const Matcher<T>& m) {
@ -337,7 +334,7 @@ TEST(ElementsAreTest, ExplainsNonTrivialMatch) {
ElementsAre(GreaterThan(1), 0, GreaterThan(2)); ElementsAre(GreaterThan(1), 0, GreaterThan(2));
const int a[] = { 10, 0, 100 }; const int a[] = { 10, 0, 100 };
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n" EXPECT_EQ("whose element #0 matches, which is 9 more than 1,\n"
"and whose element #2 matches, which is 98 more than 2", "and whose element #2 matches, which is 98 more than 2",
Explain(m, test_vector)); Explain(m, test_vector));
@ -422,7 +419,7 @@ TEST(ElementsAreTest, MatchesThreeElementsMixedMatchers) {
TEST(ElementsAreTest, MatchesTenElementVector) { TEST(ElementsAreTest, MatchesTenElementVector) {
const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, EXPECT_THAT(test_vector,
// The element list can contain values and/or matchers // The element list can contain values and/or matchers
@ -465,7 +462,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
}; };
vector<list<char> > nested; vector<list<char> > 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<char>(strings[i], strings[i] + strlen(strings[i]))); nested.push_back(list<char>(strings[i], strings[i] + strlen(strings[i])));
} }
@ -477,7 +474,7 @@ TEST(ElementsAreTest, WorksForNestedContainer) {
TEST(ElementsAreTest, WorksWithByRefElementMatchers) { TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
int a[] = { 0, 1, 2 }; int a[] = { 0, 1, 2 };
vector<int> v(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(v, ElementsAre(Ref(v[0]), Ref(v[1]), Ref(v[2]))); 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])))); EXPECT_THAT(v, Not(ElementsAre(Ref(v[0]), Ref(v[1]), Ref(a[2]))));
@ -485,7 +482,7 @@ TEST(ElementsAreTest, WorksWithByRefElementMatchers) {
TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) { TEST(ElementsAreTest, WorksWithContainerPointerUsingPointee) {
int a[] = { 0, 1, 2 }; int a[] = { 0, 1, 2 };
vector<int> v(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> v(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(&v, Pointee(ElementsAre(0, 1, _))); EXPECT_THAT(&v, Pointee(ElementsAre(0, 1, _)));
EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3)))); EXPECT_THAT(&v, Not(Pointee(ElementsAre(0, _, 3))));
@ -582,7 +579,7 @@ TEST(ElementsAreTest, MakesCopyOfArguments) {
TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) { TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(a)); EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[2] = 0; test_vector[2] = 0;
@ -592,18 +589,18 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithValueArray) {
TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) { TEST(ElementsAreArrayTest, CanBeCreatedWithArraySize) {
const char* a[] = { "one", "two", "three" }; const char* a[] = { "one", "two", "three" };
vector<string> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(a, GMOCK_ARRAY_SIZE_(a))); EXPECT_THAT(test_vector, ElementsAreArray(a, GTEST_ARRAY_SIZE_(a)));
const char** p = a; const char** p = a;
test_vector[0] = "1"; 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) { TEST(ElementsAreArrayTest, CanBeCreatedWithoutArraySize) {
const char* a[] = { "one", "two", "three" }; const char* a[] = { "one", "two", "three" };
vector<string> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<string> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(a)); EXPECT_THAT(test_vector, ElementsAreArray(a));
test_vector[0] = "1"; test_vector[0] = "1";
@ -626,8 +623,8 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherArray) {
TEST(ElementsAreArrayTest, CanBeCreatedWithVector) { TEST(ElementsAreArrayTest, CanBeCreatedWithVector) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
const vector<int> expected(a, a + GMOCK_ARRAY_SIZE_(a)); const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected)); EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4); test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected))); EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@ -674,9 +671,9 @@ TEST(ElementsAreArrayTest,
TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) { TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) }; const Matcher<int> kMatchers[] = { Eq(1), Eq(2), Eq(3) };
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
const vector<Matcher<int> > expected( const vector<Matcher<int> > expected(
kMatchers, kMatchers + GMOCK_ARRAY_SIZE_(kMatchers)); kMatchers, kMatchers + GTEST_ARRAY_SIZE_(kMatchers));
EXPECT_THAT(test_vector, ElementsAreArray(expected)); EXPECT_THAT(test_vector, ElementsAreArray(expected));
test_vector.push_back(4); test_vector.push_back(4);
EXPECT_THAT(test_vector, Not(ElementsAreArray(expected))); EXPECT_THAT(test_vector, Not(ElementsAreArray(expected)));
@ -684,11 +681,11 @@ TEST(ElementsAreArrayTest, CanBeCreatedWithMatcherVector) {
TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) { TEST(ElementsAreArrayTest, CanBeCreatedWithIteratorRange) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
const vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); const vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
const vector<int> expected(a, a + GMOCK_ARRAY_SIZE_(a)); const vector<int> expected(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end())); EXPECT_THAT(test_vector, ElementsAreArray(expected.begin(), expected.end()));
// Pointers are iterators, too. // 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. // The empty range of NULL pointers should also be okay.
int* const null_int = NULL; int* const null_int = NULL;
EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int))); EXPECT_THAT(test_vector, Not(ElementsAreArray(null_int, null_int)));
@ -708,8 +705,8 @@ TEST(ElementsAreArrayTest, WorksWithNativeArray) {
TEST(ElementsAreArrayTest, SourceLifeSpan) { TEST(ElementsAreArrayTest, SourceLifeSpan) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
vector<int> test_vector(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> test_vector(a, a + GTEST_ARRAY_SIZE_(a));
vector<int> expect(a, a + GMOCK_ARRAY_SIZE_(a)); vector<int> expect(a, a + GTEST_ARRAY_SIZE_(a));
ElementsAreArrayMatcher<int> matcher_maker = ElementsAreArrayMatcher<int> matcher_maker =
ElementsAreArray(expect.begin(), expect.end()); ElementsAreArray(expect.begin(), expect.end());
EXPECT_THAT(test_vector, matcher_maker); EXPECT_THAT(test_vector, matcher_maker);

View File

@ -151,9 +151,6 @@ using testing::internal::linked_ptr;
using testing::internal::scoped_ptr; using testing::internal::scoped_ptr;
using testing::internal::string; 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(). // For testing ExplainMatchResultTo().
class GreaterThanMatcher : public MatcherInterface<int> { class GreaterThanMatcher : public MatcherInterface<int> {
public: public:
@ -3444,6 +3441,8 @@ double AClass::x_ = 0.0;
// A derived class for testing Property(). // A derived class for testing Property().
class DerivedClass : public AClass { class DerivedClass : public AClass {
public:
int k() const { return k_; }
private: private:
int k_; int k_;
}; };
@ -4424,14 +4423,14 @@ TEST(WhenSortedTest, WorksForStreamlike) {
// Streamlike 'container' provides only minimal iterator support. // Streamlike 'container' provides only minimal iterator support.
// Its iterators are tagged with input_iterator_tag. // Its iterators are tagged with input_iterator_tag.
const int a[5] = { 2, 1, 4, 5, 3 }; const int a[5] = { 2, 1, 4, 5, 3 };
Streamlike<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(s, WhenSorted(ElementsAre(1, 2, 3, 4, 5))); EXPECT_THAT(s, WhenSorted(ElementsAre(1, 2, 3, 4, 5)));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
} }
TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) { TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
const int a[] = { 2, 1, 4, 5, 3 }; const int a[] = { 2, 1, 4, 5, 3 };
Streamlike<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
Matcher<const std::vector<int>&> vector_match = ElementsAre(1, 2, 3, 4, 5); Matcher<const std::vector<int>&> vector_match = ElementsAre(1, 2, 3, 4, 5);
EXPECT_THAT(s, WhenSorted(vector_match)); EXPECT_THAT(s, WhenSorted(vector_match));
EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3)))); EXPECT_THAT(s, Not(WhenSorted(ElementsAre(2, 1, 4, 5, 3))));
@ -4442,14 +4441,14 @@ TEST(WhenSortedTest, WorksForVectorConstRefMatcherOnStreamlike) {
TEST(ElemensAreStreamTest, WorksForStreamlike) { TEST(ElemensAreStreamTest, WorksForStreamlike) {
const int a[5] = { 1, 2, 3, 4, 5 }; const int a[5] = { 1, 2, 3, 4, 5 };
Streamlike<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(s, ElementsAre(1, 2, 3, 4, 5)); EXPECT_THAT(s, ElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(ElementsAre(2, 1, 4, 5, 3))); EXPECT_THAT(s, Not(ElementsAre(2, 1, 4, 5, 3)));
} }
TEST(ElemensAreArrayStreamTest, WorksForStreamlike) { TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
const int a[5] = { 1, 2, 3, 4, 5 }; const int a[5] = { 1, 2, 3, 4, 5 };
Streamlike<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
vector<int> expected; vector<int> expected;
expected.push_back(1); expected.push_back(1);
@ -4467,7 +4466,7 @@ TEST(ElemensAreArrayStreamTest, WorksForStreamlike) {
TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) { TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
const int a[] = { 0, 1, 2, 3, 4 }; const int a[] = { 0, 1, 2, 3, 4 };
std::vector<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
do { do {
StringMatchResultListener listener; StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(a), EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(a),
@ -4478,8 +4477,8 @@ TEST(UnorderedElementsAreArrayTest, SucceedsWhenExpected) {
TEST(UnorderedElementsAreArrayTest, VectorBool) { TEST(UnorderedElementsAreArrayTest, VectorBool) {
const bool a[] = { 0, 1, 0, 1, 1 }; const bool a[] = { 0, 1, 0, 1, 1 };
const bool b[] = { 1, 0, 1, 1, 0 }; const bool b[] = { 1, 0, 1, 1, 0 };
std::vector<bool> expected(a, a + GMOCK_ARRAY_SIZE_(a)); std::vector<bool> expected(a, a + GTEST_ARRAY_SIZE_(a));
std::vector<bool> actual(b, b + GMOCK_ARRAY_SIZE_(b)); std::vector<bool> actual(b, b + GTEST_ARRAY_SIZE_(b));
StringMatchResultListener listener; StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(expected), EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAreArray(expected),
actual, &listener)) << listener.str(); actual, &listener)) << listener.str();
@ -4490,7 +4489,7 @@ TEST(UnorderedElementsAreArrayTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no // Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods. // size() or empty() methods.
const int a[5] = { 2, 1, 4, 5, 3 }; const int a[5] = { 2, 1, 4, 5, 3 };
Streamlike<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
::std::vector<int> expected; ::std::vector<int> expected;
expected.push_back(1); expected.push_back(1);
@ -4547,7 +4546,7 @@ class UnorderedElementsAreTest : public testing::Test {
TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) { TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
std::vector<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
do { do {
StringMatchResultListener listener; StringMatchResultListener listener;
EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3), EXPECT_TRUE(ExplainMatchResult(UnorderedElementsAre(1, 2, 3),
@ -4557,7 +4556,7 @@ TEST_F(UnorderedElementsAreTest, SucceedsWhenExpected) {
TEST_F(UnorderedElementsAreTest, FailsWhenAnElementMatchesNoMatcher) { TEST_F(UnorderedElementsAreTest, FailsWhenAnElementMatchesNoMatcher) {
const int a[] = { 1, 2, 3 }; const int a[] = { 1, 2, 3 };
std::vector<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); std::vector<int> s(a, a + GTEST_ARRAY_SIZE_(a));
std::vector<Matcher<int> > mv; std::vector<Matcher<int> > mv;
mv.push_back(1); mv.push_back(1);
mv.push_back(2); mv.push_back(2);
@ -4573,7 +4572,7 @@ TEST_F(UnorderedElementsAreTest, WorksForStreamlike) {
// Its iterators are tagged with input_iterator_tag, and it has no // Its iterators are tagged with input_iterator_tag, and it has no
// size() or empty() methods. // size() or empty() methods.
const int a[5] = { 2, 1, 4, 5, 3 }; const int a[5] = { 2, 1, 4, 5, 3 };
Streamlike<int> s(a, a + GMOCK_ARRAY_SIZE_(a)); Streamlike<int> s(a, a + GTEST_ARRAY_SIZE_(a));
EXPECT_THAT(s, UnorderedElementsAre(1, 2, 3, 4, 5)); EXPECT_THAT(s, UnorderedElementsAre(1, 2, 3, 4, 5));
EXPECT_THAT(s, Not(UnorderedElementsAre(2, 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 // 0 1 2
MatchMatrix g(4, 3); MatchMatrix g(4, 3);
static const int kEdges[][2] = { {0, 2}, {1, 1}, {2, 1}, {3, 0} }; 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); g.SetEdge(kEdges[i][0], kEdges[i][1], true);
} }
EXPECT_THAT(FindBacktrackingMaxBPM(g), EXPECT_THAT(FindBacktrackingMaxBPM(g),