Implements matcher IsEmpty(); also pulls in gtest r643.

This commit is contained in:
zhanyong.wan
2013-03-01 00:20:30 +00:00
parent edd4ab4945
commit 320814aca0
3 changed files with 95 additions and 2 deletions

View File

@@ -34,6 +34,7 @@
// This file tests some commonly used argument matchers.
#include "gmock/gmock-matchers.h"
#include "gmock/gmock-more-matchers.h"
#include <string.h>
#include <functional>
@@ -88,6 +89,7 @@ using testing::FloatEq;
using testing::Ge;
using testing::Gt;
using testing::HasSubstr;
using testing::IsEmpty;
using testing::IsNull;
using testing::Key;
using testing::Le;
@@ -3603,6 +3605,38 @@ TEST(ByRefTest, AllowsNotCopyableValueInMatchers) {
EXPECT_TRUE(m.Matches(n2));
}
TEST(IsEmptyTest, ImplementsIsEmpty) {
vector<int> container;
EXPECT_THAT(container, IsEmpty());
container.push_back(0);
EXPECT_THAT(container, Not(IsEmpty()));
container.push_back(1);
EXPECT_THAT(container, Not(IsEmpty()));
}
TEST(IsEmptyTest, WorksWithString) {
string text;
EXPECT_THAT(text, IsEmpty());
text = "foo";
EXPECT_THAT(text, Not(IsEmpty()));
text = string("\0", 1);
EXPECT_THAT(text, Not(IsEmpty()));
}
TEST(IsEmptyTest, CanDescribeSelf) {
Matcher<vector<int> > m = IsEmpty();
EXPECT_EQ("is empty", Describe(m));
EXPECT_EQ("isn't empty", DescribeNegation(m));
}
TEST(IsEmptyTest, ExplainsResult) {
Matcher<vector<int> > m = IsEmpty();
vector<int> container;
EXPECT_EQ("", Explain(m, container));
container.push_back(0);
EXPECT_EQ("whose size is 1", Explain(m, container));
}
#if GTEST_HAS_TYPED_TEST
// Tests ContainerEq with different container types, and
// different element types.