aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/gmock-generated-matchers_test.cc2
-rw-r--r--test/gmock-matchers_test.cc30
-rw-r--r--test/gmock-spec-builders_test.cc67
-rw-r--r--test/gmock_link_test.h1
-rw-r--r--test/gmock_output_test_.cc12
-rw-r--r--test/gmock_output_test_golden.txt12
6 files changed, 91 insertions, 33 deletions
diff --git a/test/gmock-generated-matchers_test.cc b/test/gmock-generated-matchers_test.cc
index 7e716981..19024d0d 100644
--- a/test/gmock-generated-matchers_test.cc
+++ b/test/gmock-generated-matchers_test.cc
@@ -457,7 +457,7 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
NativeArrayPassedAsPointerAndSize helper;
EXPECT_CALL(helper, Helper(_, _))
- .WithArguments(ElementsAre(0, 1));
+ .With(ElementsAre(0, 1));
helper.Helper(array, 2);
}
diff --git a/test/gmock-matchers_test.cc b/test/gmock-matchers_test.cc
index 4ee6ea81..3541eef7 100644
--- a/test/gmock-matchers_test.cc
+++ b/test/gmock-matchers_test.cc
@@ -62,6 +62,7 @@ namespace gmock_matchers_test {
using std::stringstream;
using std::tr1::make_tuple;
using testing::A;
+using testing::AllArgs;
using testing::AllOf;
using testing::An;
using testing::AnyOf;
@@ -1689,6 +1690,35 @@ TEST(ValueTest, WorksWithMonomorphicMatcher) {
EXPECT_FALSE(Value(1, ref_n));
}
+TEST(AllArgsTest, WorksForTuple) {
+ EXPECT_THAT(make_tuple(1, 2L), AllArgs(Lt()));
+ EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt())));
+}
+
+TEST(AllArgsTest, WorksForNonTuple) {
+ EXPECT_THAT(42, AllArgs(Gt(0)));
+ EXPECT_THAT('a', Not(AllArgs(Eq('b'))));
+}
+
+class AllArgsHelper {
+ public:
+ MOCK_METHOD2(Helper, int(char x, int y));
+};
+
+TEST(AllArgsTest, WorksInWithClause) {
+ AllArgsHelper helper;
+ ON_CALL(helper, Helper(_, _))
+ .With(AllArgs(Lt()))
+ .WillByDefault(Return(1));
+ EXPECT_CALL(helper, Helper(_, _));
+ EXPECT_CALL(helper, Helper(_, _))
+ .With(AllArgs(Gt()))
+ .WillOnce(Return(2));
+
+ EXPECT_EQ(1, helper.Helper('\1', 2));
+ EXPECT_EQ(2, helper.Helper('a', 1));
+}
+
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the value
// matches the matcher.
TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) {
diff --git a/test/gmock-spec-builders_test.cc b/test/gmock-spec-builders_test.cc
index 4711899d..24621371 100644
--- a/test/gmock-spec-builders_test.cc
+++ b/test/gmock-spec-builders_test.cc
@@ -72,6 +72,7 @@ using testing::Const;
using testing::DoAll;
using testing::DoDefault;
using testing::GMOCK_FLAG(verbose);
+using testing::Gt;
using testing::InSequence;
using testing::Invoke;
using testing::InvokeWithoutArgs;
@@ -96,6 +97,7 @@ class MockA {
MOCK_METHOD1(DoA, void(int n)); // NOLINT
MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT
MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT
+ MOCK_METHOD2(ReturnInt, int(int x, int y)); // NOLINT
};
class MockB {
@@ -171,25 +173,40 @@ TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
// Tests that the syntax of ON_CALL() is enforced at run time.
-TEST(OnCallSyntaxTest, WithArgumentsIsOptional) {
+TEST(OnCallSyntaxTest, WithIsOptional) {
MockA a;
ON_CALL(a, DoA(5))
.WillByDefault(Return());
ON_CALL(a, DoA(_))
- .WithArguments(_)
+ .With(_)
.WillByDefault(Return());
}
-TEST(OnCallSyntaxTest, WithArgumentsCanAppearAtMostOnce) {
+TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT
ON_CALL(a, ReturnResult(_))
- .WithArguments(_)
- .WithArguments(_)
+ .With(_)
+ .With(_)
.WillByDefault(Return(Result()));
- }, ".WithArguments() cannot appear more than once in an ON_CALL()");
+ }, ".With() cannot appear more than once in an ON_CALL()");
+}
+
+TEST(OnCallSyntaxTest, WithArgumentsIsSynonymOfWith) {
+ MockA a;
+ ON_CALL(a, ReturnInt(_, _))
+ .WithArguments(Lt())
+ .WillByDefault(Return(1));
+ ON_CALL(a, ReturnInt(_, _))
+ .WithArguments(Gt())
+ .WillByDefault(Return(2));
+ EXPECT_CALL(a, ReturnInt(_, _))
+ .Times(AnyNumber());
+
+ EXPECT_EQ(1, a.ReturnInt(1, 2));
+ EXPECT_EQ(2, a.ReturnInt(2, 1));
}
#if GTEST_HAS_DEATH_TEST
@@ -237,51 +254,61 @@ TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
// Tests that the syntax of EXPECT_CALL() is enforced at run time.
-TEST(ExpectCallSyntaxTest, WithArgumentsIsOptional) {
+TEST(ExpectCallSyntaxTest, WithIsOptional) {
MockA a;
EXPECT_CALL(a, DoA(5))
.Times(0);
EXPECT_CALL(a, DoA(6))
- .WithArguments(_)
+ .With(_)
.Times(0);
}
-TEST(ExpectCallSyntaxTest, WithArgumentsCanAppearAtMostOnce) {
+TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_CALL(a, DoA(6))
- .WithArguments(_)
- .WithArguments(_);
- }, ".WithArguments() cannot appear more than once in "
- "an EXPECT_CALL()");
+ .With(_)
+ .With(_);
+ }, ".With() cannot appear more than once in an EXPECT_CALL()");
a.DoA(6);
}
-TEST(ExpectCallSyntaxTest, WithArgumentsMustBeFirstClause) {
+TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
MockA a;
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_CALL(a, DoA(1))
.Times(1)
- .WithArguments(_);
- }, ".WithArguments() must be the first clause in an "
- "EXPECT_CALL()");
+ .With(_);
+ }, ".With() must be the first clause in an EXPECT_CALL()");
a.DoA(1);
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_CALL(a, DoA(2))
.WillOnce(Return())
- .WithArguments(_);
- }, ".WithArguments() must be the first clause in an "
- "EXPECT_CALL()");
+ .With(_);
+ }, ".With() must be the first clause in an EXPECT_CALL()");
a.DoA(2);
}
+TEST(ExpectCallSyntaxTest, WithArgumentsIsSynonymOfWith) {
+ MockA a;
+ EXPECT_CALL(a, ReturnInt(_, _))
+ .WithArguments(Lt())
+ .WillOnce(Return(1));
+ EXPECT_CALL(a, ReturnInt(_, _))
+ .WithArguments(Gt())
+ .WillOnce(Return(2));
+
+ EXPECT_EQ(1, a.ReturnInt(1, 2));
+ EXPECT_EQ(2, a.ReturnInt(2, 1));
+}
+
TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
MockA a;
diff --git a/test/gmock_link_test.h b/test/gmock_link_test.h
index 4e0adb71..b903f3cb 100644
--- a/test/gmock_link_test.h
+++ b/test/gmock_link_test.h
@@ -120,6 +120,7 @@
#include <errno.h>
#endif
+#include <gmock/internal/gmock-port.h>
#include <gtest/gtest.h>
#include <iostream>
#include <vector>
diff --git a/test/gmock_output_test_.cc b/test/gmock_output_test_.cc
index 97619af1..8244f10b 100644
--- a/test/gmock_output_test_.cc
+++ b/test/gmock_output_test_.cc
@@ -177,19 +177,19 @@ TEST_F(GMockOutputTest, MismatchArguments) {
foo_.Bar(s, 0, 0);
}
-TEST_F(GMockOutputTest, MismatchWithArguments) {
+TEST_F(GMockOutputTest, MismatchWith) {
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
- .WithArguments(Ge());
+ .With(Ge());
- foo_.Bar2(2, 3); // Mismatch WithArguments()
+ foo_.Bar2(2, 3); // Mismatch With()
foo_.Bar2(2, 1);
}
-TEST_F(GMockOutputTest, MismatchArgumentsAndWithArguments) {
+TEST_F(GMockOutputTest, MismatchArgumentsAndWith) {
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
- .WithArguments(Ge());
+ .With(Ge());
- foo_.Bar2(1, 3); // Mismatch arguments and mismatch WithArguments()
+ foo_.Bar2(1, 3); // Mismatch arguments and mismatch With()
foo_.Bar2(2, 1);
}
diff --git a/test/gmock_output_test_golden.txt b/test/gmock_output_test_golden.txt
index b4d2ea06..aeec660f 100644
--- a/test/gmock_output_test_golden.txt
+++ b/test/gmock_output_test_golden.txt
@@ -174,7 +174,7 @@ FILE:#:
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] GMockOutputTest.MismatchArguments
-[ RUN ] GMockOutputTest.MismatchWithArguments
+[ RUN ] GMockOutputTest.MismatchWith
unknown file: Failure
Unexpected mock function call - returning default value.
@@ -187,8 +187,8 @@ FILE:#:
Actual: don't match
Expected: to be called once
Actual: never called - unsatisfied and active
-[ FAILED ] GMockOutputTest.MismatchWithArguments
-[ RUN ] GMockOutputTest.MismatchArgumentsAndWithArguments
+[ FAILED ] GMockOutputTest.MismatchWith
+[ RUN ] GMockOutputTest.MismatchArgumentsAndWith
unknown file: Failure
Unexpected mock function call - returning default value.
@@ -203,7 +203,7 @@ FILE:#:
Actual: don't match
Expected: to be called once
Actual: never called - unsatisfied and active
-[ FAILED ] GMockOutputTest.MismatchArgumentsAndWithArguments
+[ FAILED ] GMockOutputTest.MismatchArgumentsAndWith
[ RUN ] GMockOutputTest.UnexpectedCallWithDefaultAction
unknown file: Failure
@@ -290,8 +290,8 @@ Stack trace:
[ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites
[ FAILED ] GMockOutputTest.UnsatisfiedExpectation
[ FAILED ] GMockOutputTest.MismatchArguments
-[ FAILED ] GMockOutputTest.MismatchWithArguments
-[ FAILED ] GMockOutputTest.MismatchArgumentsAndWithArguments
+[ FAILED ] GMockOutputTest.MismatchWith
+[ FAILED ] GMockOutputTest.MismatchArgumentsAndWith
[ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction
[ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction