Implements .With() as a synonym of .WithArguments(); implements AllArgs(m) as a synonym of m; relies on gtest-port to #include tuple; fixes a compatibility with Symbian.
This commit is contained in:
parent
2661c6821a
commit
bf55085d45
|
@ -2354,6 +2354,16 @@ inline bool Value(const T& value, M matcher) {
|
||||||
return testing::Matches(matcher)(value);
|
return testing::Matches(matcher)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllArgs(m) is a synonym of m. This is useful in
|
||||||
|
//
|
||||||
|
// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
|
||||||
|
//
|
||||||
|
// which is easier to read than
|
||||||
|
//
|
||||||
|
// EXPECT_CALL(foo, Bar(_, _)).With(Eq());
|
||||||
|
template <typename InnerMatcher>
|
||||||
|
inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
|
||||||
|
|
||||||
// These macros allow using matchers to check values in Google Test
|
// These macros allow using matchers to check values in Google Test
|
||||||
// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
|
// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
|
||||||
// succeed iff the value matches the matcher. If the assertion fails,
|
// succeed iff the value matches the matcher. If the assertion fails,
|
||||||
|
|
|
@ -37,16 +37,16 @@
|
||||||
// a mock method. The syntax is:
|
// a mock method. The syntax is:
|
||||||
//
|
//
|
||||||
// ON_CALL(mock_object, Method(argument-matchers))
|
// ON_CALL(mock_object, Method(argument-matchers))
|
||||||
// .WithArguments(multi-argument-matcher)
|
// .With(multi-argument-matcher)
|
||||||
// .WillByDefault(action);
|
// .WillByDefault(action);
|
||||||
//
|
//
|
||||||
// where the .WithArguments() clause is optional.
|
// where the .With() clause is optional.
|
||||||
//
|
//
|
||||||
// A user can use the EXPECT_CALL() macro to specify an expectation on
|
// A user can use the EXPECT_CALL() macro to specify an expectation on
|
||||||
// a mock method. The syntax is:
|
// a mock method. The syntax is:
|
||||||
//
|
//
|
||||||
// EXPECT_CALL(mock_object, Method(argument-matchers))
|
// EXPECT_CALL(mock_object, Method(argument-matchers))
|
||||||
// .WithArguments(multi-argument-matchers)
|
// .With(multi-argument-matchers)
|
||||||
// .Times(cardinality)
|
// .Times(cardinality)
|
||||||
// .InSequence(sequences)
|
// .InSequence(sequences)
|
||||||
// .WillOnce(action)
|
// .WillOnce(action)
|
||||||
|
@ -144,31 +144,39 @@ class DefaultActionSpec {
|
||||||
// bug in Symbian's C++ compiler (cannot decide between two
|
// bug in Symbian's C++ compiler (cannot decide between two
|
||||||
// overloaded constructors of Matcher<const ArgumentTuple&>).
|
// overloaded constructors of Matcher<const ArgumentTuple&>).
|
||||||
extra_matcher_(A<const ArgumentTuple&>()),
|
extra_matcher_(A<const ArgumentTuple&>()),
|
||||||
last_clause_(NONE) {
|
last_clause_(kNone) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where in the source file was the default action spec defined?
|
// Where in the source file was the default action spec defined?
|
||||||
const char* file() const { return file_; }
|
const char* file() const { return file_; }
|
||||||
int line() const { return line_; }
|
int line() const { return line_; }
|
||||||
|
|
||||||
// Implements the .WithArguments() clause.
|
// Implements the .With() clause.
|
||||||
DefaultActionSpec& WithArguments(const Matcher<const ArgumentTuple&>& m) {
|
DefaultActionSpec& With(const Matcher<const ArgumentTuple&>& m) {
|
||||||
// Makes sure this is called at most once.
|
// Makes sure this is called at most once.
|
||||||
ExpectSpecProperty(last_clause_ < WITH_ARGUMENTS,
|
ExpectSpecProperty(last_clause_ < kWith,
|
||||||
".WithArguments() cannot appear "
|
".With() cannot appear "
|
||||||
"more than once in an ON_CALL().");
|
"more than once in an ON_CALL().");
|
||||||
last_clause_ = WITH_ARGUMENTS;
|
last_clause_ = kWith;
|
||||||
|
|
||||||
extra_matcher_ = m;
|
extra_matcher_ = m;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements the .WithArguments() clause as a synonym of .With()
|
||||||
|
// for backward compatibility. WithArguments() is deprecated and
|
||||||
|
// new code should always use With(), as .With(Args<1, 2>(m)) is
|
||||||
|
// clearer than .WithArguments(Args<1, 2>(m)).
|
||||||
|
DefaultActionSpec& WithArguments(const Matcher<const ArgumentTuple&>& m) {
|
||||||
|
return With(m);
|
||||||
|
}
|
||||||
|
|
||||||
// Implements the .WillByDefault() clause.
|
// Implements the .WillByDefault() clause.
|
||||||
DefaultActionSpec& WillByDefault(const Action<F>& action) {
|
DefaultActionSpec& WillByDefault(const Action<F>& action) {
|
||||||
ExpectSpecProperty(last_clause_ < WILL_BY_DEFAULT,
|
ExpectSpecProperty(last_clause_ < kWillByDefault,
|
||||||
".WillByDefault() must appear "
|
".WillByDefault() must appear "
|
||||||
"exactly once in an ON_CALL().");
|
"exactly once in an ON_CALL().");
|
||||||
last_clause_ = WILL_BY_DEFAULT;
|
last_clause_ = kWillByDefault;
|
||||||
|
|
||||||
ExpectSpecProperty(!action.IsDoDefault(),
|
ExpectSpecProperty(!action.IsDoDefault(),
|
||||||
"DoDefault() cannot be used in ON_CALL().");
|
"DoDefault() cannot be used in ON_CALL().");
|
||||||
|
@ -183,7 +191,7 @@ class DefaultActionSpec {
|
||||||
|
|
||||||
// Returns the action specified by the user.
|
// Returns the action specified by the user.
|
||||||
const Action<F>& GetAction() const {
|
const Action<F>& GetAction() const {
|
||||||
AssertSpecProperty(last_clause_ == WILL_BY_DEFAULT,
|
AssertSpecProperty(last_clause_ == kWillByDefault,
|
||||||
".WillByDefault() must appear exactly "
|
".WillByDefault() must appear exactly "
|
||||||
"once in an ON_CALL().");
|
"once in an ON_CALL().");
|
||||||
return action_;
|
return action_;
|
||||||
|
@ -193,9 +201,9 @@ class DefaultActionSpec {
|
||||||
enum Clause {
|
enum Clause {
|
||||||
// Do not change the order of the enum members! The run-time
|
// Do not change the order of the enum members! The run-time
|
||||||
// syntax checking relies on it.
|
// syntax checking relies on it.
|
||||||
NONE,
|
kNone,
|
||||||
WITH_ARGUMENTS,
|
kWith,
|
||||||
WILL_BY_DEFAULT,
|
kWillByDefault,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Asserts that the ON_CALL() statement has a certain property.
|
// Asserts that the ON_CALL() statement has a certain property.
|
||||||
|
@ -211,7 +219,7 @@ class DefaultActionSpec {
|
||||||
// The information in statement
|
// The information in statement
|
||||||
//
|
//
|
||||||
// ON_CALL(mock_object, Method(matchers))
|
// ON_CALL(mock_object, Method(matchers))
|
||||||
// .WithArguments(multi-argument-matcher)
|
// .With(multi-argument-matcher)
|
||||||
// .WillByDefault(action);
|
// .WillByDefault(action);
|
||||||
//
|
//
|
||||||
// is recorded in the data members like this:
|
// is recorded in the data members like this:
|
||||||
|
@ -228,7 +236,7 @@ class DefaultActionSpec {
|
||||||
Action<F> action_;
|
Action<F> action_;
|
||||||
|
|
||||||
// The last clause in the ON_CALL() statement as seen so far.
|
// The last clause in the ON_CALL() statement as seen so far.
|
||||||
// Initially NONE and changes as the statement is parsed.
|
// Initially kNone and changes as the statement is parsed.
|
||||||
Clause last_clause_;
|
Clause last_clause_;
|
||||||
}; // class DefaultActionSpec
|
}; // class DefaultActionSpec
|
||||||
|
|
||||||
|
@ -437,13 +445,13 @@ class ExpectationBase {
|
||||||
|
|
||||||
enum Clause {
|
enum Clause {
|
||||||
// Don't change the order of the enum members!
|
// Don't change the order of the enum members!
|
||||||
NONE,
|
kNone,
|
||||||
WITH_ARGUMENTS,
|
kWith,
|
||||||
TIMES,
|
kTimes,
|
||||||
IN_SEQUENCE,
|
kInSequence,
|
||||||
WILL_ONCE,
|
kWillOnce,
|
||||||
WILL_REPEATEDLY,
|
kWillRepeatedly,
|
||||||
RETIRES_ON_SATURATION,
|
kRetiresOnSaturation,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Asserts that the EXPECT_CALL() statement has the given property.
|
// Asserts that the EXPECT_CALL() statement has the given property.
|
||||||
|
@ -581,7 +589,7 @@ class Expectation : public ExpectationBase {
|
||||||
repeated_action_specified_(false),
|
repeated_action_specified_(false),
|
||||||
repeated_action_(DoDefault()),
|
repeated_action_(DoDefault()),
|
||||||
retires_on_saturation_(false),
|
retires_on_saturation_(false),
|
||||||
last_clause_(NONE),
|
last_clause_(kNone),
|
||||||
action_count_checked_(false) {}
|
action_count_checked_(false) {}
|
||||||
|
|
||||||
virtual ~Expectation() {
|
virtual ~Expectation() {
|
||||||
|
@ -590,36 +598,42 @@ class Expectation : public ExpectationBase {
|
||||||
CheckActionCountIfNotDone();
|
CheckActionCountIfNotDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements the .WithArguments() clause.
|
// Implements the .With() clause.
|
||||||
Expectation& WithArguments(const Matcher<const ArgumentTuple&>& m) {
|
Expectation& With(const Matcher<const ArgumentTuple&>& m) {
|
||||||
if (last_clause_ == WITH_ARGUMENTS) {
|
if (last_clause_ == kWith) {
|
||||||
ExpectSpecProperty(false,
|
ExpectSpecProperty(false,
|
||||||
".WithArguments() cannot appear "
|
".With() cannot appear "
|
||||||
"more than once in an EXPECT_CALL().");
|
"more than once in an EXPECT_CALL().");
|
||||||
} else {
|
} else {
|
||||||
ExpectSpecProperty(last_clause_ < WITH_ARGUMENTS,
|
ExpectSpecProperty(last_clause_ < kWith,
|
||||||
".WithArguments() must be the first "
|
".With() must be the first "
|
||||||
"clause in an EXPECT_CALL().");
|
"clause in an EXPECT_CALL().");
|
||||||
}
|
}
|
||||||
last_clause_ = WITH_ARGUMENTS;
|
last_clause_ = kWith;
|
||||||
|
|
||||||
extra_matcher_ = m;
|
extra_matcher_ = m;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements the .WithArguments() clause as a synonym of .With().
|
||||||
|
// This is deprecated and new code should always use With().
|
||||||
|
Expectation& WithArguments(const Matcher<const ArgumentTuple&>& m) {
|
||||||
|
return With(m);
|
||||||
|
}
|
||||||
|
|
||||||
// Implements the .Times() clause.
|
// Implements the .Times() clause.
|
||||||
Expectation& Times(const Cardinality& cardinality) {
|
Expectation& Times(const Cardinality& cardinality) {
|
||||||
if (last_clause_ ==TIMES) {
|
if (last_clause_ ==kTimes) {
|
||||||
ExpectSpecProperty(false,
|
ExpectSpecProperty(false,
|
||||||
".Times() cannot appear "
|
".Times() cannot appear "
|
||||||
"more than once in an EXPECT_CALL().");
|
"more than once in an EXPECT_CALL().");
|
||||||
} else {
|
} else {
|
||||||
ExpectSpecProperty(last_clause_ < TIMES,
|
ExpectSpecProperty(last_clause_ < kTimes,
|
||||||
".Times() cannot appear after "
|
".Times() cannot appear after "
|
||||||
".InSequence(), .WillOnce(), .WillRepeatedly(), "
|
".InSequence(), .WillOnce(), .WillRepeatedly(), "
|
||||||
"or .RetiresOnSaturation().");
|
"or .RetiresOnSaturation().");
|
||||||
}
|
}
|
||||||
last_clause_ = TIMES;
|
last_clause_ = kTimes;
|
||||||
|
|
||||||
ExpectationBase::SpecifyCardinality(cardinality);
|
ExpectationBase::SpecifyCardinality(cardinality);
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -632,11 +646,11 @@ class Expectation : public ExpectationBase {
|
||||||
|
|
||||||
// Implements the .InSequence() clause.
|
// Implements the .InSequence() clause.
|
||||||
Expectation& InSequence(const Sequence& s) {
|
Expectation& InSequence(const Sequence& s) {
|
||||||
ExpectSpecProperty(last_clause_ <= IN_SEQUENCE,
|
ExpectSpecProperty(last_clause_ <= kInSequence,
|
||||||
".InSequence() cannot appear after .WillOnce(),"
|
".InSequence() cannot appear after .WillOnce(),"
|
||||||
" .WillRepeatedly(), or "
|
" .WillRepeatedly(), or "
|
||||||
".RetiresOnSaturation().");
|
".RetiresOnSaturation().");
|
||||||
last_clause_ = IN_SEQUENCE;
|
last_clause_ = kInSequence;
|
||||||
|
|
||||||
s.AddExpectation(owner_->GetLinkedExpectationBase(this));
|
s.AddExpectation(owner_->GetLinkedExpectationBase(this));
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -660,10 +674,10 @@ class Expectation : public ExpectationBase {
|
||||||
|
|
||||||
// Implements the .WillOnce() clause.
|
// Implements the .WillOnce() clause.
|
||||||
Expectation& WillOnce(const Action<F>& action) {
|
Expectation& WillOnce(const Action<F>& action) {
|
||||||
ExpectSpecProperty(last_clause_ <= WILL_ONCE,
|
ExpectSpecProperty(last_clause_ <= kWillOnce,
|
||||||
".WillOnce() cannot appear after "
|
".WillOnce() cannot appear after "
|
||||||
".WillRepeatedly() or .RetiresOnSaturation().");
|
".WillRepeatedly() or .RetiresOnSaturation().");
|
||||||
last_clause_ = WILL_ONCE;
|
last_clause_ = kWillOnce;
|
||||||
|
|
||||||
actions_.push_back(action);
|
actions_.push_back(action);
|
||||||
if (!cardinality_specified()) {
|
if (!cardinality_specified()) {
|
||||||
|
@ -674,16 +688,16 @@ class Expectation : public ExpectationBase {
|
||||||
|
|
||||||
// Implements the .WillRepeatedly() clause.
|
// Implements the .WillRepeatedly() clause.
|
||||||
Expectation& WillRepeatedly(const Action<F>& action) {
|
Expectation& WillRepeatedly(const Action<F>& action) {
|
||||||
if (last_clause_ == WILL_REPEATEDLY) {
|
if (last_clause_ == kWillRepeatedly) {
|
||||||
ExpectSpecProperty(false,
|
ExpectSpecProperty(false,
|
||||||
".WillRepeatedly() cannot appear "
|
".WillRepeatedly() cannot appear "
|
||||||
"more than once in an EXPECT_CALL().");
|
"more than once in an EXPECT_CALL().");
|
||||||
} else {
|
} else {
|
||||||
ExpectSpecProperty(last_clause_ < WILL_REPEATEDLY,
|
ExpectSpecProperty(last_clause_ < kWillRepeatedly,
|
||||||
".WillRepeatedly() cannot appear "
|
".WillRepeatedly() cannot appear "
|
||||||
"after .RetiresOnSaturation().");
|
"after .RetiresOnSaturation().");
|
||||||
}
|
}
|
||||||
last_clause_ = WILL_REPEATEDLY;
|
last_clause_ = kWillRepeatedly;
|
||||||
repeated_action_specified_ = true;
|
repeated_action_specified_ = true;
|
||||||
|
|
||||||
repeated_action_ = action;
|
repeated_action_ = action;
|
||||||
|
@ -699,10 +713,10 @@ class Expectation : public ExpectationBase {
|
||||||
|
|
||||||
// Implements the .RetiresOnSaturation() clause.
|
// Implements the .RetiresOnSaturation() clause.
|
||||||
Expectation& RetiresOnSaturation() {
|
Expectation& RetiresOnSaturation() {
|
||||||
ExpectSpecProperty(last_clause_ < RETIRES_ON_SATURATION,
|
ExpectSpecProperty(last_clause_ < kRetiresOnSaturation,
|
||||||
".RetiresOnSaturation() cannot appear "
|
".RetiresOnSaturation() cannot appear "
|
||||||
"more than once.");
|
"more than once.");
|
||||||
last_clause_ = RETIRES_ON_SATURATION;
|
last_clause_ = kRetiresOnSaturation;
|
||||||
retires_on_saturation_ = true;
|
retires_on_saturation_ = true;
|
||||||
|
|
||||||
// Now that no more action clauses can be specified, we check
|
// Now that no more action clauses can be specified, we check
|
||||||
|
@ -717,7 +731,7 @@ class Expectation : public ExpectationBase {
|
||||||
return matchers_;
|
return matchers_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the matcher specified by the .WithArguments() clause.
|
// Returns the matcher specified by the .With() clause.
|
||||||
const Matcher<const ArgumentTuple&>& extra_matcher() const {
|
const Matcher<const ArgumentTuple&>& extra_matcher() const {
|
||||||
return extra_matcher_;
|
return extra_matcher_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,14 +39,14 @@
|
||||||
// This file implements the following syntax:
|
// This file implements the following syntax:
|
||||||
//
|
//
|
||||||
// ON_CALL(mock_object.Method(...))
|
// ON_CALL(mock_object.Method(...))
|
||||||
// .WithArguments(...) ?
|
// .With(...) ?
|
||||||
// .WillByDefault(...);
|
// .WillByDefault(...);
|
||||||
//
|
//
|
||||||
// where WithArguments() is optional and WillByDefault() must appear
|
// where With() is optional and WillByDefault() must appear exactly
|
||||||
// exactly once.
|
// once.
|
||||||
//
|
//
|
||||||
// EXPECT_CALL(mock_object.Method(...))
|
// EXPECT_CALL(mock_object.Method(...))
|
||||||
// .WithArguments(...) ?
|
// .With(...) ?
|
||||||
// .Times(...) ?
|
// .Times(...) ?
|
||||||
// .InSequence(...) *
|
// .InSequence(...) *
|
||||||
// .WillOnce(...) *
|
// .WillOnce(...) *
|
||||||
|
|
|
@ -47,18 +47,8 @@
|
||||||
|
|
||||||
// To avoid conditional compilation everywhere, we make it
|
// To avoid conditional compilation everywhere, we make it
|
||||||
// gmock-port.h's responsibility to #include the header implementing
|
// gmock-port.h's responsibility to #include the header implementing
|
||||||
// tr1/tuple.
|
// tr1/tuple. gmock-port.h does this via gtest-port.h, which is
|
||||||
#if defined(__GNUC__) && GTEST_GCC_VER_ >= 40000
|
// guaranteed to pull in the tuple header.
|
||||||
// GTEST_GCC_VER_ is defined in gtest-port.h and 40000 corresponds to
|
|
||||||
// version 4.0.0.
|
|
||||||
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
|
|
||||||
// not conform to the TR1 spec, which requires the header to be <tuple>.
|
|
||||||
#include <tr1/tuple>
|
|
||||||
#else
|
|
||||||
// If the compiler is not GCC 4.0+, we assume the user is using a
|
|
||||||
// spec-conforming TR1 implementation.
|
|
||||||
#include <tuple>
|
|
||||||
#endif // __GNUC__
|
|
||||||
|
|
||||||
#if GTEST_OS_LINUX
|
#if GTEST_OS_LINUX
|
||||||
|
|
||||||
|
|
|
@ -131,16 +131,19 @@ void Log(LogSeverity severity, const string& message,
|
||||||
|
|
||||||
// Ensures that logs from different threads don't interleave.
|
// Ensures that logs from different threads don't interleave.
|
||||||
MutexLock l(&g_log_mutex);
|
MutexLock l(&g_log_mutex);
|
||||||
using ::std::cout;
|
|
||||||
|
// "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a
|
||||||
|
// macro.
|
||||||
|
|
||||||
if (severity == WARNING) {
|
if (severity == WARNING) {
|
||||||
// Prints a GMOCK WARNING marker to make the warnings easily searchable.
|
// Prints a GMOCK WARNING marker to make the warnings easily searchable.
|
||||||
cout << "\nGMOCK WARNING:";
|
std::cout << "\nGMOCK WARNING:";
|
||||||
}
|
}
|
||||||
// Pre-pends a new-line to message if it doesn't start with one.
|
// Pre-pends a new-line to message if it doesn't start with one.
|
||||||
if (message.empty() || message[0] != '\n') {
|
if (message.empty() || message[0] != '\n') {
|
||||||
cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
cout << message;
|
std::cout << message;
|
||||||
if (stack_frames_to_skip >= 0) {
|
if (stack_frames_to_skip >= 0) {
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
// In opt mode, we have to be conservative and skip no stack frame.
|
// In opt mode, we have to be conservative and skip no stack frame.
|
||||||
|
@ -153,13 +156,13 @@ void Log(LogSeverity severity, const string& message,
|
||||||
|
|
||||||
// Appends a new-line to message if it doesn't end with one.
|
// Appends a new-line to message if it doesn't end with one.
|
||||||
if (!message.empty() && *message.rbegin() != '\n') {
|
if (!message.empty() && *message.rbegin() != '\n') {
|
||||||
cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
cout << "Stack trace:\n"
|
std::cout << "Stack trace:\n"
|
||||||
<< ::testing::internal::GetCurrentOsStackTraceExceptTop(
|
<< ::testing::internal::GetCurrentOsStackTraceExceptTop(
|
||||||
::testing::UnitTest::GetInstance(), actual_to_skip);
|
::testing::UnitTest::GetInstance(), actual_to_skip);
|
||||||
}
|
}
|
||||||
cout << ::std::flush;
|
std::cout << ::std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
|
@ -457,7 +457,7 @@ TEST(ElementsAreTest, WorksWithNativeArrayPassedAsPointerAndSize) {
|
||||||
|
|
||||||
NativeArrayPassedAsPointerAndSize helper;
|
NativeArrayPassedAsPointerAndSize helper;
|
||||||
EXPECT_CALL(helper, Helper(_, _))
|
EXPECT_CALL(helper, Helper(_, _))
|
||||||
.WithArguments(ElementsAre(0, 1));
|
.With(ElementsAre(0, 1));
|
||||||
helper.Helper(array, 2);
|
helper.Helper(array, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ namespace gmock_matchers_test {
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
using std::tr1::make_tuple;
|
using std::tr1::make_tuple;
|
||||||
using testing::A;
|
using testing::A;
|
||||||
|
using testing::AllArgs;
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::An;
|
using testing::An;
|
||||||
using testing::AnyOf;
|
using testing::AnyOf;
|
||||||
|
@ -1689,6 +1690,35 @@ TEST(ValueTest, WorksWithMonomorphicMatcher) {
|
||||||
EXPECT_FALSE(Value(1, ref_n));
|
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
|
// Tests that ASSERT_THAT() and EXPECT_THAT() work when the value
|
||||||
// matches the matcher.
|
// matches the matcher.
|
||||||
TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) {
|
TEST(MatcherAssertionTest, WorksWhenMatcherIsSatisfied) {
|
||||||
|
|
|
@ -72,6 +72,7 @@ using testing::Const;
|
||||||
using testing::DoAll;
|
using testing::DoAll;
|
||||||
using testing::DoDefault;
|
using testing::DoDefault;
|
||||||
using testing::GMOCK_FLAG(verbose);
|
using testing::GMOCK_FLAG(verbose);
|
||||||
|
using testing::Gt;
|
||||||
using testing::InSequence;
|
using testing::InSequence;
|
||||||
using testing::Invoke;
|
using testing::Invoke;
|
||||||
using testing::InvokeWithoutArgs;
|
using testing::InvokeWithoutArgs;
|
||||||
|
@ -96,6 +97,7 @@ class MockA {
|
||||||
MOCK_METHOD1(DoA, void(int n)); // NOLINT
|
MOCK_METHOD1(DoA, void(int n)); // NOLINT
|
||||||
MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT
|
MOCK_METHOD1(ReturnResult, Result(int n)); // NOLINT
|
||||||
MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT
|
MOCK_METHOD2(Binary, bool(int x, int y)); // NOLINT
|
||||||
|
MOCK_METHOD2(ReturnInt, int(int x, int y)); // NOLINT
|
||||||
};
|
};
|
||||||
|
|
||||||
class MockB {
|
class MockB {
|
||||||
|
@ -171,25 +173,40 @@ TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
|
||||||
|
|
||||||
// Tests that the syntax of ON_CALL() is enforced at run time.
|
// Tests that the syntax of ON_CALL() is enforced at run time.
|
||||||
|
|
||||||
TEST(OnCallSyntaxTest, WithArgumentsIsOptional) {
|
TEST(OnCallSyntaxTest, WithIsOptional) {
|
||||||
MockA a;
|
MockA a;
|
||||||
|
|
||||||
ON_CALL(a, DoA(5))
|
ON_CALL(a, DoA(5))
|
||||||
.WillByDefault(Return());
|
.WillByDefault(Return());
|
||||||
ON_CALL(a, DoA(_))
|
ON_CALL(a, DoA(_))
|
||||||
.WithArguments(_)
|
.With(_)
|
||||||
.WillByDefault(Return());
|
.WillByDefault(Return());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(OnCallSyntaxTest, WithArgumentsCanAppearAtMostOnce) {
|
TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
|
||||||
MockA a;
|
MockA a;
|
||||||
|
|
||||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||||
ON_CALL(a, ReturnResult(_))
|
ON_CALL(a, ReturnResult(_))
|
||||||
.WithArguments(_)
|
.With(_)
|
||||||
.WithArguments(_)
|
.With(_)
|
||||||
.WillByDefault(Return(Result()));
|
.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
|
#if GTEST_HAS_DEATH_TEST
|
||||||
|
@ -237,51 +254,61 @@ TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
|
||||||
|
|
||||||
// Tests that the syntax of EXPECT_CALL() is enforced at run time.
|
// Tests that the syntax of EXPECT_CALL() is enforced at run time.
|
||||||
|
|
||||||
TEST(ExpectCallSyntaxTest, WithArgumentsIsOptional) {
|
TEST(ExpectCallSyntaxTest, WithIsOptional) {
|
||||||
MockA a;
|
MockA a;
|
||||||
|
|
||||||
EXPECT_CALL(a, DoA(5))
|
EXPECT_CALL(a, DoA(5))
|
||||||
.Times(0);
|
.Times(0);
|
||||||
EXPECT_CALL(a, DoA(6))
|
EXPECT_CALL(a, DoA(6))
|
||||||
.WithArguments(_)
|
.With(_)
|
||||||
.Times(0);
|
.Times(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ExpectCallSyntaxTest, WithArgumentsCanAppearAtMostOnce) {
|
TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
|
||||||
MockA a;
|
MockA a;
|
||||||
|
|
||||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||||
EXPECT_CALL(a, DoA(6))
|
EXPECT_CALL(a, DoA(6))
|
||||||
.WithArguments(_)
|
.With(_)
|
||||||
.WithArguments(_);
|
.With(_);
|
||||||
}, ".WithArguments() cannot appear more than once in "
|
}, ".With() cannot appear more than once in an EXPECT_CALL()");
|
||||||
"an EXPECT_CALL()");
|
|
||||||
|
|
||||||
a.DoA(6);
|
a.DoA(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ExpectCallSyntaxTest, WithArgumentsMustBeFirstClause) {
|
TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
|
||||||
MockA a;
|
MockA a;
|
||||||
|
|
||||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||||
EXPECT_CALL(a, DoA(1))
|
EXPECT_CALL(a, DoA(1))
|
||||||
.Times(1)
|
.Times(1)
|
||||||
.WithArguments(_);
|
.With(_);
|
||||||
}, ".WithArguments() must be the first clause in an "
|
}, ".With() must be the first clause in an EXPECT_CALL()");
|
||||||
"EXPECT_CALL()");
|
|
||||||
|
|
||||||
a.DoA(1);
|
a.DoA(1);
|
||||||
|
|
||||||
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
||||||
EXPECT_CALL(a, DoA(2))
|
EXPECT_CALL(a, DoA(2))
|
||||||
.WillOnce(Return())
|
.WillOnce(Return())
|
||||||
.WithArguments(_);
|
.With(_);
|
||||||
}, ".WithArguments() must be the first clause in an "
|
}, ".With() must be the first clause in an EXPECT_CALL()");
|
||||||
"EXPECT_CALL()");
|
|
||||||
|
|
||||||
a.DoA(2);
|
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) {
|
TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
|
||||||
MockA a;
|
MockA a;
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <gmock/internal/gmock-port.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -177,19 +177,19 @@ TEST_F(GMockOutputTest, MismatchArguments) {
|
||||||
foo_.Bar(s, 0, 0);
|
foo_.Bar(s, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GMockOutputTest, MismatchWithArguments) {
|
TEST_F(GMockOutputTest, MismatchWith) {
|
||||||
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
|
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);
|
foo_.Bar2(2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GMockOutputTest, MismatchArgumentsAndWithArguments) {
|
TEST_F(GMockOutputTest, MismatchArgumentsAndWith) {
|
||||||
EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))
|
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);
|
foo_.Bar2(2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ FILE:#:
|
||||||
Expected: to be called once
|
Expected: to be called once
|
||||||
Actual: never called - unsatisfied and active
|
Actual: never called - unsatisfied and active
|
||||||
[ FAILED ] GMockOutputTest.MismatchArguments
|
[ FAILED ] GMockOutputTest.MismatchArguments
|
||||||
[ RUN ] GMockOutputTest.MismatchWithArguments
|
[ RUN ] GMockOutputTest.MismatchWith
|
||||||
unknown file: Failure
|
unknown file: Failure
|
||||||
|
|
||||||
Unexpected mock function call - returning default value.
|
Unexpected mock function call - returning default value.
|
||||||
|
@ -187,8 +187,8 @@ FILE:#:
|
||||||
Actual: don't match
|
Actual: don't match
|
||||||
Expected: to be called once
|
Expected: to be called once
|
||||||
Actual: never called - unsatisfied and active
|
Actual: never called - unsatisfied and active
|
||||||
[ FAILED ] GMockOutputTest.MismatchWithArguments
|
[ FAILED ] GMockOutputTest.MismatchWith
|
||||||
[ RUN ] GMockOutputTest.MismatchArgumentsAndWithArguments
|
[ RUN ] GMockOutputTest.MismatchArgumentsAndWith
|
||||||
unknown file: Failure
|
unknown file: Failure
|
||||||
|
|
||||||
Unexpected mock function call - returning default value.
|
Unexpected mock function call - returning default value.
|
||||||
|
@ -203,7 +203,7 @@ FILE:#:
|
||||||
Actual: don't match
|
Actual: don't match
|
||||||
Expected: to be called once
|
Expected: to be called once
|
||||||
Actual: never called - unsatisfied and active
|
Actual: never called - unsatisfied and active
|
||||||
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWithArguments
|
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWith
|
||||||
[ RUN ] GMockOutputTest.UnexpectedCallWithDefaultAction
|
[ RUN ] GMockOutputTest.UnexpectedCallWithDefaultAction
|
||||||
unknown file: Failure
|
unknown file: Failure
|
||||||
|
|
||||||
|
@ -290,8 +290,8 @@ Stack trace:
|
||||||
[ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites
|
[ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites
|
||||||
[ FAILED ] GMockOutputTest.UnsatisfiedExpectation
|
[ FAILED ] GMockOutputTest.UnsatisfiedExpectation
|
||||||
[ FAILED ] GMockOutputTest.MismatchArguments
|
[ FAILED ] GMockOutputTest.MismatchArguments
|
||||||
[ FAILED ] GMockOutputTest.MismatchWithArguments
|
[ FAILED ] GMockOutputTest.MismatchWith
|
||||||
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWithArguments
|
[ FAILED ] GMockOutputTest.MismatchArgumentsAndWith
|
||||||
[ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction
|
[ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction
|
||||||
[ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction
|
[ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user