Unverified Commit f3a9fa6a authored by Gennadiy Civil's avatar Gennadiy Civil Committed by GitHub
Browse files

Merge branch 'master' into master

parents 6c093a23 490554aa
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: marcus.boerger@google.com (Marcus Boerger)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -36,13 +35,27 @@ ...@@ -36,13 +35,27 @@
// Note that tests are implemented in gmock-matchers_test.cc rather than // Note that tests are implemented in gmock-matchers_test.cc rather than
// gmock-more-matchers-test.cc. // gmock-more-matchers-test.cc.
#ifndef GMOCK_GMOCK_MORE_MATCHERS_H_ // GOOGLETEST_CM0002 DO NOT DELETE
#define GMOCK_GMOCK_MORE_MATCHERS_H_
#ifndef GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
#include "gmock/gmock-generated-matchers.h" #include "gmock/gmock-generated-matchers.h"
namespace testing { namespace testing {
// Silence C4100 (unreferenced formal
// parameter) for MSVC
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4100)
#if (_MSC_VER == 1900)
// and silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 14
# pragma warning(disable:4800)
#endif
#endif
// Defines a matcher that matches an empty container. The container must // Defines a matcher that matches an empty container. The container must
// support both size() and empty(), which all STL-like containers provide. // support both size() and empty(), which all STL-like containers provide.
MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
...@@ -53,6 +66,27 @@ MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") { ...@@ -53,6 +66,27 @@ MATCHER(IsEmpty, negation ? "isn't empty" : "is empty") {
return false; return false;
} }
// Define a matcher that matches a value that evaluates in boolean
// context to true. Useful for types that define "explicit operator
// bool" operators and so can't be compared for equality with true
// and false.
MATCHER(IsTrue, negation ? "is false" : "is true") {
return static_cast<bool>(arg);
}
// Define a matcher that matches a value that evaluates in boolean
// context to false. Useful for types that define "explicit operator
// bool" operators and so can't be compared for equality with true
// and false.
MATCHER(IsFalse, negation ? "is true" : "is false") {
return !static_cast<bool>(arg);
}
#ifdef _MSC_VER
# pragma warning(pop)
#endif
} // namespace testing } // namespace testing
#endif // GMOCK_GMOCK_MORE_MATCHERS_H_ #endif // GMOCK_INCLUDE_GMOCK_MORE_MATCHERS_H_
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -57,6 +56,8 @@ ...@@ -57,6 +56,8 @@
// where all clauses are optional, and .InSequence()/.After()/ // where all clauses are optional, and .InSequence()/.After()/
// .WillOnce() can appear any number of times. // .WillOnce() can appear any number of times.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
...@@ -65,11 +66,6 @@ ...@@ -65,11 +66,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#if GTEST_HAS_EXCEPTIONS
# include <stdexcept> // NOLINT
#endif
#include "gmock/gmock-actions.h" #include "gmock/gmock-actions.h"
#include "gmock/gmock-cardinalities.h" #include "gmock/gmock-cardinalities.h"
#include "gmock/gmock-matchers.h" #include "gmock/gmock-matchers.h"
...@@ -77,6 +73,10 @@ ...@@ -77,6 +73,10 @@
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_HAS_EXCEPTIONS
# include <stdexcept> // NOLINT
#endif
namespace testing { namespace testing {
// An abstract handle of an expectation. // An abstract handle of an expectation.
...@@ -148,14 +148,13 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -148,14 +148,13 @@ class GTEST_API_ UntypedFunctionMockerBase {
// action fails. // action fails.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
const void* untyped_args, const std::string& call_description) const = 0; void* untyped_args, const std::string& call_description) const = 0;
// Performs the given action with the given arguments and returns // Performs the given action with the given arguments and returns
// the action's result. // the action's result.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformAction( virtual UntypedActionResultHolderBase* UntypedPerformAction(
const void* untyped_action, const void* untyped_action, void* untyped_args) const = 0;
const void* untyped_args) const = 0;
// Writes a message that the call is uninteresting (i.e. neither // Writes a message that the call is uninteresting (i.e. neither
// explicitly expected nor explicitly unexpected) to the given // explicitly expected nor explicitly unexpected) to the given
...@@ -185,7 +184,7 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -185,7 +184,7 @@ class GTEST_API_ UntypedFunctionMockerBase {
// this information in the global mock registry. Will be called // this information in the global mock registry. Will be called
// whenever an EXPECT_CALL() or ON_CALL() is executed on this mock // whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
// method. // method.
// TODO(wan@google.com): rename to SetAndRegisterOwner(). // FIXME: rename to SetAndRegisterOwner().
void RegisterOwner(const void* mock_obj) void RegisterOwner(const void* mock_obj)
GTEST_LOCK_EXCLUDED_(g_gmock_mutex); GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
...@@ -210,9 +209,8 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -210,9 +209,8 @@ class GTEST_API_ UntypedFunctionMockerBase {
// arguments. This function can be safely called from multiple // arguments. This function can be safely called from multiple
// threads concurrently. The caller is responsible for deleting the // threads concurrently. The caller is responsible for deleting the
// result. // result.
UntypedActionResultHolderBase* UntypedInvokeWith( UntypedActionResultHolderBase* UntypedInvokeWith(void* untyped_args)
const void* untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
protected: protected:
typedef std::vector<const void*> UntypedOnCallSpecs; typedef std::vector<const void*> UntypedOnCallSpecs;
...@@ -237,6 +235,14 @@ class GTEST_API_ UntypedFunctionMockerBase { ...@@ -237,6 +235,14 @@ class GTEST_API_ UntypedFunctionMockerBase {
UntypedOnCallSpecs untyped_on_call_specs_; UntypedOnCallSpecs untyped_on_call_specs_;
// All expectations for this function mocker. // All expectations for this function mocker.
//
// It's undefined behavior to interleave expectations (EXPECT_CALLs
// or ON_CALLs) and mock function calls. Also, the order of
// expectations is important. Therefore it's a logic race condition
// to read/write untyped_expectations_ concurrently. In order for
// tools like tsan to catch concurrent read/write accesses to
// untyped_expectations, we deliberately leave accesses to it
// unprotected.
UntypedExpectations untyped_expectations_; UntypedExpectations untyped_expectations_;
}; // class UntypedFunctionMockerBase }; // class UntypedFunctionMockerBase
...@@ -1201,7 +1207,7 @@ class TypedExpectation : public ExpectationBase { ...@@ -1201,7 +1207,7 @@ class TypedExpectation : public ExpectationBase {
mocker->DescribeDefaultActionTo(args, what); mocker->DescribeDefaultActionTo(args, what);
DescribeCallCountTo(why); DescribeCallCountTo(why);
// TODO(wan@google.com): allow the user to control whether // FIXME: allow the user to control whether
// unexpected calls should fail immediately or continue using a // unexpected calls should fail immediately or continue using a
// flag --gmock_unexpected_calls_are_fatal. // flag --gmock_unexpected_calls_are_fatal.
return NULL; return NULL;
...@@ -1253,8 +1259,9 @@ class MockSpec { ...@@ -1253,8 +1259,9 @@ class MockSpec {
// Constructs a MockSpec object, given the function mocker object // Constructs a MockSpec object, given the function mocker object
// that the spec is associated with. // that the spec is associated with.
explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker) MockSpec(internal::FunctionMockerBase<F>* function_mocker,
: function_mocker_(function_mocker) {} const ArgumentMatcherTuple& matchers)
: function_mocker_(function_mocker), matchers_(matchers) {}
// Adds a new default action spec to the function mocker and returns // Adds a new default action spec to the function mocker and returns
// the newly created spec. // the newly created spec.
...@@ -1276,14 +1283,17 @@ class MockSpec { ...@@ -1276,14 +1283,17 @@ class MockSpec {
file, line, source_text, matchers_); file, line, source_text, matchers_);
} }
// This operator overload is used to swallow the superfluous parameter list
// introduced by the ON/EXPECT_CALL macros. See the macro comments for more
// explanation.
MockSpec<F>& operator()(const internal::WithoutMatchers&, void* const) {
return *this;
}
private: private:
template <typename Function> template <typename Function>
friend class internal::FunctionMocker; friend class internal::FunctionMocker;
void SetMatchers(const ArgumentMatcherTuple& matchers) {
matchers_ = matchers;
}
// The function mocker that owns this spec. // The function mocker that owns this spec.
internal::FunctionMockerBase<F>* const function_mocker_; internal::FunctionMockerBase<F>* const function_mocker_;
// The argument matchers specified in the spec. // The argument matchers specified in the spec.
...@@ -1391,19 +1401,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase { ...@@ -1391,19 +1401,20 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
template <typename F> template <typename F>
static ActionResultHolder* PerformDefaultAction( static ActionResultHolder* PerformDefaultAction(
const FunctionMockerBase<F>* func_mocker, const FunctionMockerBase<F>* func_mocker,
const typename Function<F>::ArgumentTuple& args, typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
const std::string& call_description) { const std::string& call_description) {
return new ActionResultHolder(Wrapper( return new ActionResultHolder(Wrapper(func_mocker->PerformDefaultAction(
func_mocker->PerformDefaultAction(args, call_description))); internal::move(args), call_description)));
} }
// Performs the given action and returns the result in a new-ed // Performs the given action and returns the result in a new-ed
// ActionResultHolder. // ActionResultHolder.
template <typename F> template <typename F>
static ActionResultHolder* static ActionResultHolder* PerformAction(
PerformAction(const Action<F>& action, const Action<F>& action,
const typename Function<F>::ArgumentTuple& args) { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
return new ActionResultHolder(Wrapper(action.Perform(args))); return new ActionResultHolder(
Wrapper(action.Perform(internal::move(args))));
} }
private: private:
...@@ -1431,9 +1442,9 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { ...@@ -1431,9 +1442,9 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
template <typename F> template <typename F>
static ActionResultHolder* PerformDefaultAction( static ActionResultHolder* PerformDefaultAction(
const FunctionMockerBase<F>* func_mocker, const FunctionMockerBase<F>* func_mocker,
const typename Function<F>::ArgumentTuple& args, typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
const std::string& call_description) { const std::string& call_description) {
func_mocker->PerformDefaultAction(args, call_description); func_mocker->PerformDefaultAction(internal::move(args), call_description);
return new ActionResultHolder; return new ActionResultHolder;
} }
...@@ -1442,8 +1453,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase { ...@@ -1442,8 +1453,8 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
template <typename F> template <typename F>
static ActionResultHolder* PerformAction( static ActionResultHolder* PerformAction(
const Action<F>& action, const Action<F>& action,
const typename Function<F>::ArgumentTuple& args) { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args) {
action.Perform(args); action.Perform(internal::move(args));
return new ActionResultHolder; return new ActionResultHolder;
} }
...@@ -1462,7 +1473,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1462,7 +1473,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
FunctionMockerBase() : current_spec_(this) {} FunctionMockerBase() {}
// The destructor verifies that all expectations on this mock // The destructor verifies that all expectations on this mock
// function have been satisfied. If not, it will report Google Test // function have been satisfied. If not, it will report Google Test
...@@ -1498,12 +1509,13 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1498,12 +1509,13 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// mutable state of this object, and thus can be called concurrently // mutable state of this object, and thus can be called concurrently
// without locking. // without locking.
// L = * // L = *
Result PerformDefaultAction(const ArgumentTuple& args, Result PerformDefaultAction(
const std::string& call_description) const { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args,
const std::string& call_description) const {
const OnCallSpec<F>* const spec = const OnCallSpec<F>* const spec =
this->FindOnCallSpec(args); this->FindOnCallSpec(args);
if (spec != NULL) { if (spec != NULL) {
return spec->GetAction().Perform(args); return spec->GetAction().Perform(internal::move(args));
} }
const std::string message = const std::string message =
call_description + call_description +
...@@ -1525,11 +1537,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1525,11 +1537,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// action fails. The caller is responsible for deleting the result. // action fails. The caller is responsible for deleting the result.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
const void* untyped_args, // must point to an ArgumentTuple void* untyped_args, // must point to an ArgumentTuple
const std::string& call_description) const { const std::string& call_description) const {
const ArgumentTuple& args = ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
*static_cast<const ArgumentTuple*>(untyped_args); return ResultHolder::PerformDefaultAction(this, internal::move(*args),
return ResultHolder::PerformDefaultAction(this, args, call_description); call_description);
} }
// Performs the given action with the given arguments and returns // Performs the given action with the given arguments and returns
...@@ -1537,13 +1549,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1537,13 +1549,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// result. // result.
// L = * // L = *
virtual UntypedActionResultHolderBase* UntypedPerformAction( virtual UntypedActionResultHolderBase* UntypedPerformAction(
const void* untyped_action, const void* untyped_args) const { const void* untyped_action, void* untyped_args) const {
// Make a copy of the action before performing it, in case the // Make a copy of the action before performing it, in case the
// action deletes the mock object (and thus deletes itself). // action deletes the mock object (and thus deletes itself).
const Action<F> action = *static_cast<const Action<F>*>(untyped_action); const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
const ArgumentTuple& args = ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
*static_cast<const ArgumentTuple*>(untyped_args); return ResultHolder::PerformAction(action, internal::move(*args));
return ResultHolder::PerformAction(action, args);
} }
// Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
...@@ -1583,10 +1594,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1583,10 +1594,14 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
// Returns the result of invoking this mock function with the given // Returns the result of invoking this mock function with the given
// arguments. This function can be safely called from multiple // arguments. This function can be safely called from multiple
// threads concurrently. // threads concurrently.
Result InvokeWith(const ArgumentTuple& args) Result InvokeWith(
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) { typename RvalueRef<typename Function<F>::ArgumentTuple>::type args)
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
// const_cast is required since in C++98 we still pass ArgumentTuple around
// by const& instead of rvalue reference.
void* untyped_args = const_cast<void*>(static_cast<const void*>(&args));
scoped_ptr<ResultHolder> holder( scoped_ptr<ResultHolder> holder(
DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args))); DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args)));
return holder->Unwrap(); return holder->Unwrap();
} }
...@@ -1610,6 +1625,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1610,6 +1625,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
TypedExpectation<F>* const expectation = TypedExpectation<F>* const expectation =
new TypedExpectation<F>(this, file, line, source_text, m); new TypedExpectation<F>(this, file, line, source_text, m);
const linked_ptr<ExpectationBase> untyped_expectation(expectation); const linked_ptr<ExpectationBase> untyped_expectation(expectation);
// See the definition of untyped_expectations_ for why access to
// it is unprotected here.
untyped_expectations_.push_back(untyped_expectation); untyped_expectations_.push_back(untyped_expectation);
// Adds this expectation into the implicit sequence if there is one. // Adds this expectation into the implicit sequence if there is one.
...@@ -1621,10 +1638,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1621,10 +1638,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
return *expectation; return *expectation;
} }
// The current spec (either default action spec or expectation spec)
// being described on this function mocker.
MockSpec<F>& current_spec() { return current_spec_; }
private: private:
template <typename Func> friend class TypedExpectation; template <typename Func> friend class TypedExpectation;
...@@ -1717,6 +1730,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1717,6 +1730,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
const ArgumentTuple& args) const const ArgumentTuple& args) const
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) { GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
// See the definition of untyped_expectations_ for why access to
// it is unprotected here.
for (typename UntypedExpectations::const_reverse_iterator it = for (typename UntypedExpectations::const_reverse_iterator it =
untyped_expectations_.rbegin(); untyped_expectations_.rbegin();
it != untyped_expectations_.rend(); ++it) { it != untyped_expectations_.rend(); ++it) {
...@@ -1767,10 +1782,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { ...@@ -1767,10 +1782,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
} }
} }
// The current spec (either default action spec or expectation spec)
// being described on this function mocker.
MockSpec<F> current_spec_;
// There is no generally useful and implementable semantics of // There is no generally useful and implementable semantics of
// copying a mock object, so copying a mock is usually a user error. // copying a mock object, so copying a mock is usually a user error.
// Thus we disallow copying function mockers. If the user really // Thus we disallow copying function mockers. If the user really
...@@ -1833,17 +1844,76 @@ inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT ...@@ -1833,17 +1844,76 @@ inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT
} // namespace testing } // namespace testing
// A separate macro is required to avoid compile errors when the name // Implementation for ON_CALL and EXPECT_CALL macros. A separate macro is
// of the method used in call is a result of macro expansion. // required to avoid compile errors when the name of the method used in call is
// See CompilesWithMethodNameExpandedFromMacro tests in // a result of macro expansion. See CompilesWithMethodNameExpandedFromMacro
// internal/gmock-spec-builders_test.cc for more details. // tests in internal/gmock-spec-builders_test.cc for more details.
#define GMOCK_ON_CALL_IMPL_(obj, call) \ //
((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \ // This macro supports statements both with and without parameter matchers. If
#obj, #call) // the parameter list is omitted, gMock will accept any parameters, which allows
#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call) // tests to be written that don't need to encode the number of method
// parameter. This technique may only be used for non-overloaded methods.
#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \ //
((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) // // These are the same:
#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) // ON_CALL(mock, NoArgsMethod()).WillByDefault(...);
// ON_CALL(mock, NoArgsMethod).WillByDefault(...);
//
// // As are these:
// ON_CALL(mock, TwoArgsMethod(_, _)).WillByDefault(...);
// ON_CALL(mock, TwoArgsMethod).WillByDefault(...);
//
// // Can also specify args if you want, of course:
// ON_CALL(mock, TwoArgsMethod(_, 45)).WillByDefault(...);
//
// // Overloads work as long as you specify parameters:
// ON_CALL(mock, OverloadedMethod(_)).WillByDefault(...);
// ON_CALL(mock, OverloadedMethod(_, _)).WillByDefault(...);
//
// // Oops! Which overload did you want?
// ON_CALL(mock, OverloadedMethod).WillByDefault(...);
// => ERROR: call to member function 'gmock_OverloadedMethod' is ambiguous
//
// How this works: The mock class uses two overloads of the gmock_Method
// expectation setter method plus an operator() overload on the MockSpec object.
// In the matcher list form, the macro expands to:
//
// // This statement:
// ON_CALL(mock, TwoArgsMethod(_, 45))...
//
// // ...expands to:
// mock.gmock_TwoArgsMethod(_, 45)(WithoutMatchers(), nullptr)...
// |-------------v---------------||------------v-------------|
// invokes first overload swallowed by operator()
//
// // ...which is essentially:
// mock.gmock_TwoArgsMethod(_, 45)...
//
// Whereas the form without a matcher list:
//
// // This statement:
// ON_CALL(mock, TwoArgsMethod)...
//
// // ...expands to:
// mock.gmock_TwoArgsMethod(WithoutMatchers(), nullptr)...
// |-----------------------v--------------------------|
// invokes second overload
//
// // ...which is essentially:
// mock.gmock_TwoArgsMethod(_, _)...
//
// The WithoutMatchers() argument is used to disambiguate overloads and to
// block the caller from accidentally invoking the second overload directly. The
// second argument is an internal type derived from the method signature. The
// failure to disambiguate two overloads of this method in the ON_CALL statement
// is how we block callers from setting expectations on overloaded methods.
#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \
((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), NULL) \
.Setter(__FILE__, __LINE__, #mock_expr, #call)
#define ON_CALL(obj, call) \
GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call)
#define EXPECT_CALL(obj, call) \
GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call)
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
...@@ -26,13 +26,14 @@ ...@@ -26,13 +26,14 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This is the main header file a user should include. // This is the main header file a user should include.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_H_
...@@ -59,8 +60,8 @@ ...@@ -59,8 +60,8 @@
#include "gmock/gmock-cardinalities.h" #include "gmock/gmock-cardinalities.h"
#include "gmock/gmock-generated-actions.h" #include "gmock/gmock-generated-actions.h"
#include "gmock/gmock-generated-function-mockers.h" #include "gmock/gmock-generated-function-mockers.h"
#include "gmock/gmock-generated-nice-strict.h"
#include "gmock/gmock-generated-matchers.h" #include "gmock/gmock-generated-matchers.h"
#include "gmock/gmock-generated-nice-strict.h"
#include "gmock/gmock-matchers.h" #include "gmock/gmock-matchers.h"
#include "gmock/gmock-more-actions.h" #include "gmock/gmock-more-actions.h"
#include "gmock/gmock-more-matchers.h" #include "gmock/gmock-more-matchers.h"
......
# Customization Points
The custom directory is an injection point for custom user configurations.
## Header `gmock-port.h`
The following macros can be defined:
### Flag related macros:
* `GMOCK_DECLARE_bool_(name)`
* `GMOCK_DECLARE_int32_(name)`
* `GMOCK_DECLARE_string_(name)`
* `GMOCK_DEFINE_bool_(name, default_val, doc)`
* `GMOCK_DEFINE_int32_(name, default_val, doc)`
* `GMOCK_DEFINE_string_(name, default_val, doc)`
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// pump.py gmock-generated-actions.h.pump // pump.py gmock-generated-actions.h.pump
// DO NOT EDIT BY HAND!!! // DO NOT EDIT BY HAND!!!
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
......
$$ -*- mode: c++; -*- $$ -*- mode: c++; -*-
$$ This is a Pump source file (http://go/pump). Please use Pump to convert $$ This is a Pump source file. Please use Pump to convert
$$ it to callback-actions.h. $$ it to callback-actions.h.
$$ $$
$var max_callback_arity = 5 $var max_callback_arity = 5
$$}} This meta comment fixes auto-indentation in editors. $$}} This meta comment fixes auto-indentation in editors.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_GENERATED_ACTIONS_H_
......
...@@ -27,13 +27,10 @@ ...@@ -27,13 +27,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// ============================================================ // Injection point for custom user configurations. See README for details
// An installation-specific extension point for gmock-matchers.h.
// ============================================================
// //
// Adds google3 callback support to CallableTraits. // GOOGLETEST_CM0002 DO NOT DELETE
//
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_CALLBACK_MATCHERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_MATCHERS_H_
...@@ -27,19 +27,12 @@ ...@@ -27,19 +27,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// Injection point for custom user configurations. // Injection point for custom user configurations. See README for details
// The following macros can be defined:
//
// Flag related macros:
// GMOCK_DECLARE_bool_(name)
// GMOCK_DECLARE_int32_(name)
// GMOCK_DECLARE_string_(name)
// GMOCK_DEFINE_bool_(name, default_val, doc)
// GMOCK_DEFINE_int32_(name, default_val, doc)
// GMOCK_DEFINE_string_(name, default_val, doc)
// //
// ** Custom implementation starts here ** // ** Custom implementation starts here **
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_CUSTOM_GMOCK_PORT_H_
......
...@@ -31,14 +31,15 @@ $var n = 10 $$ The maximum arity we support. ...@@ -31,14 +31,15 @@ $var n = 10 $$ The maximum arity we support.
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file contains template meta-programming utility classes needed // This file contains template meta-programming utility classes needed
// for implementing Google Mock. // for implementing Google Mock.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// //
// Google C++ Mocking Framework (Google Mock) // Google C++ Mocking Framework (Google Mock)
// //
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment