aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/gmock-generated-matchers_test.cc109
-rw-r--r--test/gmock-internal-utils_test.cc2
-rw-r--r--test/gmock-matchers_test.cc21
-rw-r--r--test/gmock_output_test_golden.txt8
4 files changed, 122 insertions, 18 deletions
diff --git a/test/gmock-generated-matchers_test.cc b/test/gmock-generated-matchers_test.cc
index 26814463..7e716981 100644
--- a/test/gmock-generated-matchers_test.cc
+++ b/test/gmock-generated-matchers_test.cc
@@ -53,8 +53,11 @@ using std::pair;
using std::set;
using std::stringstream;
using std::vector;
+using std::tr1::get;
using std::tr1::make_tuple;
+using std::tr1::tuple;
using testing::_;
+using testing::Args;
using testing::Contains;
using testing::ElementsAre;
using testing::ElementsAreArray;
@@ -98,6 +101,107 @@ string Explain(const MatcherType& m, const Value& x) {
return ss.str();
}
+// Tests Args<k0, ..., kn>(m).
+
+TEST(ArgsTest, AcceptsZeroTemplateArg) {
+ const tuple<int, bool> t(5, true);
+ EXPECT_THAT(t, Args<>(Eq(tuple<>())));
+ EXPECT_THAT(t, Not(Args<>(Ne(tuple<>()))));
+}
+
+TEST(ArgsTest, AcceptsOneTemplateArg) {
+ const tuple<int, bool> 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)))));
+}
+
+TEST(ArgsTest, AcceptsTwoTemplateArgs) {
+ const tuple<short, int, long> t(4, 5, 6L); // NOLINT
+
+ EXPECT_THAT(t, (Args<0, 1>(Lt())));
+ EXPECT_THAT(t, (Args<1, 2>(Lt())));
+ EXPECT_THAT(t, Not(Args<0, 2>(Gt())));
+}
+
+TEST(ArgsTest, AcceptsRepeatedTemplateArgs) {
+ const tuple<short, int, long> 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<short, int, long> t(4, 5, 6L); // NOLINT
+ EXPECT_THAT(t, (Args<2, 0>(Gt())));
+ EXPECT_THAT(t, Not(Args<2, 1>(Lt())));
+}
+
+MATCHER(SumIsZero, "") {
+ return get<0>(arg) + get<1>(arg) + 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())));
+}
+
+TEST(ArgsTest, CanBeNested) {
+ const tuple<short, int, long, int> 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<char, int, int> Tuple3;
+ const Matcher<Tuple3> 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<char, char, int> Tuple3;
+ const Matcher<const Tuple3&> m = Args<0, 1>(Lt());
+ EXPECT_TRUE(m.Matches(Tuple3('a', 'b', 2)));
+ EXPECT_FALSE(m.Matches(Tuple3('b', 'b', 2)));
+}
+
+// Validates that arg is printed as str.
+MATCHER_P(PrintsAs, str, "") {
+ typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(arg_type)) RawTuple;
+ return
+ testing::internal::UniversalPrinter<RawTuple>::PrintToString(arg) == str;
+}
+
+TEST(ArgsTest, AcceptsTenTemplateArgs) {
+ EXPECT_THAT(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),
+ Not(Args<9, 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<tuple<int, bool, char> > m = Args<2, 0>(Lt());
+ EXPECT_EQ("are a tuple whose fields (#2, #0) are a pair (x, y) where x < y",
+ Describe(m));
+}
+
+TEST(ArgsTest, DescirbesNestedArgsCorrectly) {
+ const Matcher<const tuple<int, bool, char, int>&> 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 (x, y) where x < y",
+ Describe(m));
+}
+
+TEST(ArgsTest, DescribesNegationCorrectly) {
+ const Matcher<tuple<int, char> > m = Args<1, 0>(Gt());
+ EXPECT_EQ("are a tuple whose fields (#1, #0) are a pair (x, y) "
+ "where x > y is false",
+ DescribeNegation(m));
+}
+
// For testing ExplainMatchResultTo().
class GreaterThanMatcher : public MatcherInterface<int> {
public:
@@ -926,8 +1030,9 @@ TEST(ContainsTest, AcceptsMatcher) {
TEST(ContainsTest, WorksForNativeArrayAsTuple) {
const int a[] = { 1, 2 };
- EXPECT_THAT(make_tuple(a, 2), Contains(1));
- EXPECT_THAT(make_tuple(a, 2), Not(Contains(Gt(3))));
+ const int* const pointer = a;
+ EXPECT_THAT(make_tuple(pointer, 2), Contains(1));
+ EXPECT_THAT(make_tuple(pointer, 2), Not(Contains(Gt(3))));
}
TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
diff --git a/test/gmock-internal-utils_test.cc b/test/gmock-internal-utils_test.cc
index 73960df5..912ee357 100644
--- a/test/gmock-internal-utils_test.cc
+++ b/test/gmock-internal-utils_test.cc
@@ -941,7 +941,7 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
EXPECT_EQ(a1, a2.begin());
const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
- Copy(make_tuple(a1, 3));
+ Copy(make_tuple(static_cast<int*>(a1), 3));
ASSERT_EQ(3, a3.size());
EXPECT_EQ(0, a3.begin()[0]);
EXPECT_EQ(1, a3.begin()[1]);
diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc
index 1226a1d1..4ee6ea81 100644
--- a/test/gmock-matchers_test.cc
+++ b/test/gmock-matchers_test.cc
@@ -1335,7 +1335,7 @@ TEST(Eq2Test, MatchesEqualArguments) {
// Tests that Eq() describes itself properly.
TEST(Eq2Test, CanDescribeSelf) {
Matcher<const Tuple2&> m = Eq();
- EXPECT_EQ("argument #0 is equal to argument #1", Describe(m));
+ EXPECT_EQ("are a pair (x, y) where x == y", Describe(m));
}
// Tests that Ge() matches a 2-tuple where the first field >= the
@@ -1350,8 +1350,7 @@ TEST(Ge2Test, MatchesGreaterThanOrEqualArguments) {
// Tests that Ge() describes itself properly.
TEST(Ge2Test, CanDescribeSelf) {
Matcher<const Tuple2&> m = Ge();
- EXPECT_EQ("argument #0 is greater than or equal to argument #1",
- Describe(m));
+ EXPECT_EQ("are a pair (x, y) where x >= y", Describe(m));
}
// Tests that Gt() matches a 2-tuple where the first field > the
@@ -1366,7 +1365,7 @@ TEST(Gt2Test, MatchesGreaterThanArguments) {
// Tests that Gt() describes itself properly.
TEST(Gt2Test, CanDescribeSelf) {
Matcher<const Tuple2&> m = Gt();
- EXPECT_EQ("argument #0 is greater than argument #1", Describe(m));
+ EXPECT_EQ("are a pair (x, y) where x > y", Describe(m));
}
// Tests that Le() matches a 2-tuple where the first field <= the
@@ -1381,8 +1380,7 @@ TEST(Le2Test, MatchesLessThanOrEqualArguments) {
// Tests that Le() describes itself properly.
TEST(Le2Test, CanDescribeSelf) {
Matcher<const Tuple2&> m = Le();
- EXPECT_EQ("argument #0 is less than or equal to argument #1",
- Describe(m));
+ EXPECT_EQ("are a pair (x, y) where x <= y", Describe(m));
}
// Tests that Lt() matches a 2-tuple where the first field < the
@@ -1397,7 +1395,7 @@ TEST(Lt2Test, MatchesLessThanArguments) {
// Tests that Lt() describes itself properly.
TEST(Lt2Test, CanDescribeSelf) {
Matcher<const Tuple2&> m = Lt();
- EXPECT_EQ("argument #0 is less than argument #1", Describe(m));
+ EXPECT_EQ("are a pair (x, y) where x < y", Describe(m));
}
// Tests that Ne() matches a 2-tuple where the first field != the
@@ -1412,7 +1410,7 @@ TEST(Ne2Test, MatchesUnequalArguments) {
// Tests that Ne() describes itself properly.
TEST(Ne2Test, CanDescribeSelf) {
Matcher<const Tuple2&> m = Ne();
- EXPECT_EQ("argument #0 is not equal to argument #1", Describe(m));
+ EXPECT_EQ("are a pair (x, y) where x != y", Describe(m));
}
// Tests that Not(m) matches any value that doesn't match m.
@@ -2948,11 +2946,12 @@ TEST(ContainerEqExtraTest, WorksForNativeArrayAsTuple) {
const int a2[] = { 1, 2, 3 };
const int b[] = { 1, 2, 3, 4 };
- EXPECT_THAT(make_tuple(a1, 3), ContainerEq(a2));
- EXPECT_THAT(make_tuple(a1, 3), Not(ContainerEq(b)));
+ const int* const p1 = a1;
+ EXPECT_THAT(make_tuple(p1, 3), ContainerEq(a2));
+ EXPECT_THAT(make_tuple(p1, 3), Not(ContainerEq(b)));
const int c[] = { 1, 3, 2 };
- EXPECT_THAT(make_tuple(a1, 3), Not(ContainerEq(c)));
+ EXPECT_THAT(make_tuple(p1, 3), Not(ContainerEq(c)));
}
TEST(ContainerEqExtraTest, CopiesNativeArrayParameter) {
diff --git a/test/gmock_output_test_golden.txt b/test/gmock_output_test_golden.txt
index 887b7be7..b4d2ea06 100644
--- a/test/gmock_output_test_golden.txt
+++ b/test/gmock_output_test_golden.txt
@@ -183,8 +183,8 @@ Unexpected mock function call - returning default value.
Google Mock tried the following 1 expectation, but it didn't match:
FILE:#:
- Expected: argument #0 is greater than or equal to argument #1
- Actual: false
+ Expected args: are a pair (x, y) where x >= y
+ Actual: don't match
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] GMockOutputTest.MismatchWithArguments
@@ -199,8 +199,8 @@ Google Mock tried the following 1 expectation, but it didn't match:
FILE:#:
Expected arg #0: is greater than or equal to 2
Actual: 1
- Expected: argument #0 is greater than or equal to argument #1
- Actual: false
+ Expected args: are a pair (x, y) where x >= y
+ Actual: don't match
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWithArguments