mirror of
https://github.com/google/googletest.git
synced 2025-03-10 09:16:48 +00:00
Expressed the thread-safety annotations in code, replacing the existing comment-based system (by Aaron Jacobs).
This commit is contained in:
parent
f44bdc7398
commit
4d60a596b4
@ -127,12 +127,12 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||||||
// Verifies that all expectations on this mock function have been
|
// Verifies that all expectations on this mock function have been
|
||||||
// satisfied. Reports one or more Google Test non-fatal failures
|
// satisfied. Reports one or more Google Test non-fatal failures
|
||||||
// and returns false if not.
|
// and returns false if not.
|
||||||
// L >= g_gmock_mutex
|
bool VerifyAndClearExpectationsLocked()
|
||||||
bool VerifyAndClearExpectationsLocked();
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Clears the ON_CALL()s set on this mock function.
|
// Clears the ON_CALL()s set on this mock function.
|
||||||
// L >= g_gmock_mutex
|
virtual void ClearDefaultActionsLocked()
|
||||||
virtual void ClearDefaultActionsLocked() = 0;
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) = 0;
|
||||||
|
|
||||||
// In all of the following Untyped* functions, it's the caller's
|
// In all of the following Untyped* functions, it's the caller's
|
||||||
// responsibility to guarantee the correctness of the arguments'
|
// responsibility to guarantee the correctness of the arguments'
|
||||||
@ -157,9 +157,10 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||||||
// 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
|
||||||
// ostream.
|
// ostream.
|
||||||
// L < g_gmock_mutex
|
virtual void UntypedDescribeUninterestingCall(
|
||||||
virtual void UntypedDescribeUninterestingCall(const void* untyped_args,
|
const void* untyped_args,
|
||||||
::std::ostream* os) const = 0;
|
::std::ostream* os) const
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
|
||||||
|
|
||||||
// Returns the expectation that matches the given function arguments
|
// Returns the expectation that matches the given function arguments
|
||||||
// (or NULL is there's no match); when a match is found,
|
// (or NULL is there's no match); when a match is found,
|
||||||
@ -167,11 +168,11 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||||||
// performed (or NULL if the action is "do default"), and
|
// performed (or NULL if the action is "do default"), and
|
||||||
// is_excessive is modified to indicate whether the call exceeds the
|
// is_excessive is modified to indicate whether the call exceeds the
|
||||||
// expected number.
|
// expected number.
|
||||||
// L < g_gmock_mutex
|
|
||||||
virtual const ExpectationBase* UntypedFindMatchingExpectation(
|
virtual const ExpectationBase* UntypedFindMatchingExpectation(
|
||||||
const void* untyped_args,
|
const void* untyped_args,
|
||||||
const void** untyped_action, bool* is_excessive,
|
const void** untyped_action, bool* is_excessive,
|
||||||
::std::ostream* what, ::std::ostream* why) = 0;
|
::std::ostream* what, ::std::ostream* why)
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) = 0;
|
||||||
|
|
||||||
// Prints the given function arguments to the ostream.
|
// Prints the given function arguments to the ostream.
|
||||||
virtual void UntypedPrintArgs(const void* untyped_args,
|
virtual void UntypedPrintArgs(const void* untyped_args,
|
||||||
@ -182,33 +183,33 @@ class GTEST_API_ UntypedFunctionMockerBase {
|
|||||||
// 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().
|
// TODO(wan@google.com): rename to SetAndRegisterOwner().
|
||||||
// L < g_gmock_mutex
|
void RegisterOwner(const void* mock_obj)
|
||||||
void RegisterOwner(const void* mock_obj);
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Sets the mock object this mock method belongs to, and sets the
|
// Sets the mock object this mock method belongs to, and sets the
|
||||||
// name of the mock function. Will be called upon each invocation
|
// name of the mock function. Will be called upon each invocation
|
||||||
// of this mock function.
|
// of this mock function.
|
||||||
// L < g_gmock_mutex
|
void SetOwnerAndName(const void* mock_obj, const char* name)
|
||||||
void SetOwnerAndName(const void* mock_obj, const char* name);
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Returns the mock object this mock method belongs to. Must be
|
// Returns the mock object this mock method belongs to. Must be
|
||||||
// called after RegisterOwner() or SetOwnerAndName() has been
|
// called after RegisterOwner() or SetOwnerAndName() has been
|
||||||
// called.
|
// called.
|
||||||
// L < g_gmock_mutex
|
const void* MockObject() const
|
||||||
const void* MockObject() const;
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Returns the name of this mock method. Must be called after
|
// Returns the name of this mock method. Must be called after
|
||||||
// SetOwnerAndName() has been called.
|
// SetOwnerAndName() has been called.
|
||||||
// L < g_gmock_mutex
|
const char* Name() const
|
||||||
const char* Name() const;
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||||
|
|
||||||
// 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. The caller is responsible for deleting the
|
// threads concurrently. The caller is responsible for deleting the
|
||||||
// result.
|
// result.
|
||||||
// L < g_gmock_mutex
|
|
||||||
const UntypedActionResultHolderBase* UntypedInvokeWith(
|
const UntypedActionResultHolderBase* UntypedInvokeWith(
|
||||||
const void* untyped_args);
|
const void* untyped_args)
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::vector<const void*> UntypedOnCallSpecs;
|
typedef std::vector<const void*> UntypedOnCallSpecs;
|
||||||
@ -369,17 +370,20 @@ class GTEST_API_ Mock {
|
|||||||
|
|
||||||
// Tells Google Mock to ignore mock_obj when checking for leaked
|
// Tells Google Mock to ignore mock_obj when checking for leaked
|
||||||
// mock objects.
|
// mock objects.
|
||||||
static void AllowLeak(const void* mock_obj);
|
static void AllowLeak(const void* mock_obj)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Verifies and clears all expectations on the given mock object.
|
// Verifies and clears all expectations on the given mock object.
|
||||||
// If the expectations aren't satisfied, generates one or more
|
// If the expectations aren't satisfied, generates one or more
|
||||||
// Google Test non-fatal failures and returns false.
|
// Google Test non-fatal failures and returns false.
|
||||||
static bool VerifyAndClearExpectations(void* mock_obj);
|
static bool VerifyAndClearExpectations(void* mock_obj)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Verifies all expectations on the given mock object and clears its
|
// Verifies all expectations on the given mock object and clears its
|
||||||
// default actions and expectations. Returns true iff the
|
// default actions and expectations. Returns true iff the
|
||||||
// verification was successful.
|
// verification was successful.
|
||||||
static bool VerifyAndClear(void* mock_obj);
|
static bool VerifyAndClear(void* mock_obj)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
private:
|
private:
|
||||||
friend class internal::UntypedFunctionMockerBase;
|
friend class internal::UntypedFunctionMockerBase;
|
||||||
|
|
||||||
@ -396,58 +400,59 @@ class GTEST_API_ Mock {
|
|||||||
|
|
||||||
// Tells Google Mock to allow uninteresting calls on the given mock
|
// Tells Google Mock to allow uninteresting calls on the given mock
|
||||||
// object.
|
// object.
|
||||||
// L < g_gmock_mutex
|
static void AllowUninterestingCalls(const void* mock_obj)
|
||||||
static void AllowUninterestingCalls(const void* mock_obj);
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Tells Google Mock to warn the user about uninteresting calls on
|
// Tells Google Mock to warn the user about uninteresting calls on
|
||||||
// the given mock object.
|
// the given mock object.
|
||||||
// L < g_gmock_mutex
|
static void WarnUninterestingCalls(const void* mock_obj)
|
||||||
static void WarnUninterestingCalls(const void* mock_obj);
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Tells Google Mock to fail uninteresting calls on the given mock
|
// Tells Google Mock to fail uninteresting calls on the given mock
|
||||||
// object.
|
// object.
|
||||||
// L < g_gmock_mutex
|
static void FailUninterestingCalls(const void* mock_obj)
|
||||||
static void FailUninterestingCalls(const void* mock_obj);
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Tells Google Mock the given mock object is being destroyed and
|
// Tells Google Mock the given mock object is being destroyed and
|
||||||
// its entry in the call-reaction table should be removed.
|
// its entry in the call-reaction table should be removed.
|
||||||
// L < g_gmock_mutex
|
static void UnregisterCallReaction(const void* mock_obj)
|
||||||
static void UnregisterCallReaction(const void* mock_obj);
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Returns the reaction Google Mock will have on uninteresting calls
|
// Returns the reaction Google Mock will have on uninteresting calls
|
||||||
// made on the given mock object.
|
// made on the given mock object.
|
||||||
// L < g_gmock_mutex
|
|
||||||
static internal::CallReaction GetReactionOnUninterestingCalls(
|
static internal::CallReaction GetReactionOnUninterestingCalls(
|
||||||
const void* mock_obj);
|
const void* mock_obj);
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Verifies that all expectations on the given mock object have been
|
// Verifies that all expectations on the given mock object have been
|
||||||
// satisfied. Reports one or more Google Test non-fatal failures
|
// satisfied. Reports one or more Google Test non-fatal failures
|
||||||
// and returns false if not.
|
// and returns false if not.
|
||||||
// L >= g_gmock_mutex
|
static bool VerifyAndClearExpectationsLocked(void* mock_obj)
|
||||||
static bool VerifyAndClearExpectationsLocked(void* mock_obj);
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Clears all ON_CALL()s set on the given mock object.
|
// Clears all ON_CALL()s set on the given mock object.
|
||||||
// L >= g_gmock_mutex
|
static void ClearDefaultActionsLocked(void* mock_obj)
|
||||||
static void ClearDefaultActionsLocked(void* mock_obj);
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Registers a mock object and a mock method it owns.
|
// Registers a mock object and a mock method it owns.
|
||||||
// L < g_gmock_mutex
|
static void Register(
|
||||||
static void Register(const void* mock_obj,
|
const void* mock_obj,
|
||||||
internal::UntypedFunctionMockerBase* mocker);
|
internal::UntypedFunctionMockerBase* mocker)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Tells Google Mock where in the source code mock_obj is used in an
|
// Tells Google Mock where in the source code mock_obj is used in an
|
||||||
// ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
|
// ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
|
||||||
// information helps the user identify which object it is.
|
// information helps the user identify which object it is.
|
||||||
// L < g_gmock_mutex
|
|
||||||
static void RegisterUseByOnCallOrExpectCall(
|
static void RegisterUseByOnCallOrExpectCall(
|
||||||
const void* mock_obj, const char* file, int line);
|
const void* mock_obj, const char* file, int line)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex);
|
||||||
|
|
||||||
// Unregisters a mock method; removes the owning mock object from
|
// Unregisters a mock method; removes the owning mock object from
|
||||||
// the registry when the last mock method associated with it has
|
// the registry when the last mock method associated with it has
|
||||||
// been unregistered. This is called only in the destructor of
|
// been unregistered. This is called only in the destructor of
|
||||||
// FunctionMockerBase.
|
// FunctionMockerBase.
|
||||||
// L >= g_gmock_mutex
|
static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
|
||||||
static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker);
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex);
|
||||||
}; // class Mock
|
}; // class Mock
|
||||||
|
|
||||||
// An abstract handle of an expectation. Useful in the .After()
|
// An abstract handle of an expectation. Useful in the .After()
|
||||||
@ -695,8 +700,8 @@ class GTEST_API_ ExpectationBase {
|
|||||||
|
|
||||||
// Describes how many times a function call matching this
|
// Describes how many times a function call matching this
|
||||||
// expectation has occurred.
|
// expectation has occurred.
|
||||||
// L >= g_gmock_mutex
|
void DescribeCallCountTo(::std::ostream* os) const
|
||||||
void DescribeCallCountTo(::std::ostream* os) const;
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
|
||||||
|
|
||||||
// If this mock method has an extra matcher (i.e. .With(matcher)),
|
// If this mock method has an extra matcher (i.e. .With(matcher)),
|
||||||
// describes it to the ostream.
|
// describes it to the ostream.
|
||||||
@ -752,62 +757,62 @@ class GTEST_API_ ExpectationBase {
|
|||||||
// the current thread.
|
// the current thread.
|
||||||
|
|
||||||
// Retires all pre-requisites of this expectation.
|
// Retires all pre-requisites of this expectation.
|
||||||
// L >= g_gmock_mutex
|
void RetireAllPreRequisites()
|
||||||
void RetireAllPreRequisites();
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Returns true iff this expectation is retired.
|
// Returns true iff this expectation is retired.
|
||||||
// L >= g_gmock_mutex
|
bool is_retired() const
|
||||||
bool is_retired() const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
return retired_;
|
return retired_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retires this expectation.
|
// Retires this expectation.
|
||||||
// L >= g_gmock_mutex
|
void Retire()
|
||||||
void Retire() {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
retired_ = true;
|
retired_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff this expectation is satisfied.
|
// Returns true iff this expectation is satisfied.
|
||||||
// L >= g_gmock_mutex
|
bool IsSatisfied() const
|
||||||
bool IsSatisfied() const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
return cardinality().IsSatisfiedByCallCount(call_count_);
|
return cardinality().IsSatisfiedByCallCount(call_count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff this expectation is saturated.
|
// Returns true iff this expectation is saturated.
|
||||||
// L >= g_gmock_mutex
|
bool IsSaturated() const
|
||||||
bool IsSaturated() const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
return cardinality().IsSaturatedByCallCount(call_count_);
|
return cardinality().IsSaturatedByCallCount(call_count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff this expectation is over-saturated.
|
// Returns true iff this expectation is over-saturated.
|
||||||
// L >= g_gmock_mutex
|
bool IsOverSaturated() const
|
||||||
bool IsOverSaturated() const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
return cardinality().IsOverSaturatedByCallCount(call_count_);
|
return cardinality().IsOverSaturatedByCallCount(call_count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff all pre-requisites of this expectation are satisfied.
|
// Returns true iff all pre-requisites of this expectation are satisfied.
|
||||||
// L >= g_gmock_mutex
|
bool AllPrerequisitesAreSatisfied() const
|
||||||
bool AllPrerequisitesAreSatisfied() const;
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Adds unsatisfied pre-requisites of this expectation to 'result'.
|
// Adds unsatisfied pre-requisites of this expectation to 'result'.
|
||||||
// L >= g_gmock_mutex
|
void FindUnsatisfiedPrerequisites(ExpectationSet* result) const
|
||||||
void FindUnsatisfiedPrerequisites(ExpectationSet* result) const;
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex);
|
||||||
|
|
||||||
// Returns the number this expectation has been invoked.
|
// Returns the number this expectation has been invoked.
|
||||||
// L >= g_gmock_mutex
|
int call_count() const
|
||||||
int call_count() const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
return call_count_;
|
return call_count_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increments the number this expectation has been invoked.
|
// Increments the number this expectation has been invoked.
|
||||||
// L >= g_gmock_mutex
|
void IncrementCallCount()
|
||||||
void IncrementCallCount() {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
call_count_++;
|
call_count_++;
|
||||||
}
|
}
|
||||||
@ -816,8 +821,8 @@ class GTEST_API_ ExpectationBase {
|
|||||||
// WillRepeatedly() clauses) against the cardinality if this hasn't
|
// WillRepeatedly() clauses) against the cardinality if this hasn't
|
||||||
// been done before. Prints a warning if there are too many or too
|
// been done before. Prints a warning if there are too many or too
|
||||||
// few actions.
|
// few actions.
|
||||||
// L < mutex_
|
void CheckActionCountIfNotDone() const
|
||||||
void CheckActionCountIfNotDone() const;
|
GTEST_LOCK_EXCLUDED_(mutex_);
|
||||||
|
|
||||||
friend class ::testing::Sequence;
|
friend class ::testing::Sequence;
|
||||||
friend class ::testing::internal::ExpectationTester;
|
friend class ::testing::internal::ExpectationTester;
|
||||||
@ -1069,15 +1074,15 @@ class TypedExpectation : public ExpectationBase {
|
|||||||
// g_gmock_mutex.
|
// g_gmock_mutex.
|
||||||
|
|
||||||
// Returns true iff this expectation matches the given arguments.
|
// Returns true iff this expectation matches the given arguments.
|
||||||
// L >= g_gmock_mutex
|
bool Matches(const ArgumentTuple& args) const
|
||||||
bool Matches(const ArgumentTuple& args) const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
|
return TupleMatches(matchers_, args) && extra_matcher_.Matches(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true iff this expectation should handle the given arguments.
|
// Returns true iff this expectation should handle the given arguments.
|
||||||
// L >= g_gmock_mutex
|
bool ShouldHandleArguments(const ArgumentTuple& args) const
|
||||||
bool ShouldHandleArguments(const ArgumentTuple& args) const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
|
|
||||||
// In case the action count wasn't checked when the expectation
|
// In case the action count wasn't checked when the expectation
|
||||||
@ -1090,9 +1095,10 @@ class TypedExpectation : public ExpectationBase {
|
|||||||
|
|
||||||
// Describes the result of matching the arguments against this
|
// Describes the result of matching the arguments against this
|
||||||
// expectation to the given ostream.
|
// expectation to the given ostream.
|
||||||
// L >= g_gmock_mutex
|
void ExplainMatchResultTo(
|
||||||
void ExplainMatchResultTo(const ArgumentTuple& args,
|
const ArgumentTuple& args,
|
||||||
::std::ostream* os) const {
|
::std::ostream* os) const
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
|
|
||||||
if (is_retired()) {
|
if (is_retired()) {
|
||||||
@ -1134,9 +1140,10 @@ class TypedExpectation : public ExpectationBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the action that should be taken for the current invocation.
|
// Returns the action that should be taken for the current invocation.
|
||||||
// L >= g_gmock_mutex
|
const Action<F>& GetCurrentAction(
|
||||||
const Action<F>& GetCurrentAction(const FunctionMockerBase<F>* mocker,
|
const FunctionMockerBase<F>* mocker,
|
||||||
const ArgumentTuple& args) const {
|
const ArgumentTuple& args) const
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
const int count = call_count();
|
const int count = call_count();
|
||||||
Assert(count >= 1, __FILE__, __LINE__,
|
Assert(count >= 1, __FILE__, __LINE__,
|
||||||
@ -1170,11 +1177,12 @@ class TypedExpectation : public ExpectationBase {
|
|||||||
// Mock does it to 'why'. This method is not const as it calls
|
// Mock does it to 'why'. This method is not const as it calls
|
||||||
// IncrementCallCount(). A return value of NULL means the default
|
// IncrementCallCount(). A return value of NULL means the default
|
||||||
// action.
|
// action.
|
||||||
// L >= g_gmock_mutex
|
const Action<F>* GetActionForArguments(
|
||||||
const Action<F>* GetActionForArguments(const FunctionMockerBase<F>* mocker,
|
const FunctionMockerBase<F>* mocker,
|
||||||
const ArgumentTuple& args,
|
const ArgumentTuple& args,
|
||||||
::std::ostream* what,
|
::std::ostream* what,
|
||||||
::std::ostream* why) {
|
::std::ostream* why)
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
if (IsSaturated()) {
|
if (IsSaturated()) {
|
||||||
// We have an excessive call.
|
// We have an excessive call.
|
||||||
@ -1393,8 +1401,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
// 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
|
||||||
// non-fatal failures for the violations.
|
// non-fatal failures for the violations.
|
||||||
// L < g_gmock_mutex
|
virtual ~FunctionMockerBase()
|
||||||
virtual ~FunctionMockerBase() {
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
MutexLock l(&g_gmock_mutex);
|
MutexLock l(&g_gmock_mutex);
|
||||||
VerifyAndClearExpectationsLocked();
|
VerifyAndClearExpectationsLocked();
|
||||||
Mock::UnregisterLocked(this);
|
Mock::UnregisterLocked(this);
|
||||||
@ -1464,8 +1472,8 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
|
|
||||||
// Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
|
// Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
|
||||||
// clears the ON_CALL()s set on this mock function.
|
// clears the ON_CALL()s set on this mock function.
|
||||||
// L >= g_gmock_mutex
|
virtual void ClearDefaultActionsLocked()
|
||||||
virtual void ClearDefaultActionsLocked() {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
for (UntypedOnCallSpecs::const_iterator it =
|
for (UntypedOnCallSpecs::const_iterator it =
|
||||||
untyped_on_call_specs_.begin();
|
untyped_on_call_specs_.begin();
|
||||||
@ -1484,17 +1492,17 @@ 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.
|
||||||
// L < g_gmock_mutex
|
Result InvokeWith(const ArgumentTuple& args)
|
||||||
Result InvokeWith(const ArgumentTuple& args) {
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
return static_cast<const ResultHolder*>(
|
return static_cast<const ResultHolder*>(
|
||||||
this->UntypedInvokeWith(&args))->GetValueAndDelete();
|
this->UntypedInvokeWith(&args))->GetValueAndDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds and returns a default action spec for this mock function.
|
// Adds and returns a default action spec for this mock function.
|
||||||
// L < g_gmock_mutex
|
|
||||||
OnCallSpec<F>& AddNewOnCallSpec(
|
OnCallSpec<F>& AddNewOnCallSpec(
|
||||||
const char* file, int line,
|
const char* file, int line,
|
||||||
const ArgumentMatcherTuple& m) {
|
const ArgumentMatcherTuple& m)
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
|
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
|
||||||
OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
|
OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
|
||||||
untyped_on_call_specs_.push_back(on_call_spec);
|
untyped_on_call_specs_.push_back(on_call_spec);
|
||||||
@ -1502,12 +1510,12 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adds and returns an expectation spec for this mock function.
|
// Adds and returns an expectation spec for this mock function.
|
||||||
// L < g_gmock_mutex
|
|
||||||
TypedExpectation<F>& AddNewExpectation(
|
TypedExpectation<F>& AddNewExpectation(
|
||||||
const char* file,
|
const char* file,
|
||||||
int line,
|
int line,
|
||||||
const string& source_text,
|
const string& source_text,
|
||||||
const ArgumentMatcherTuple& m) {
|
const ArgumentMatcherTuple& m)
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
|
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
|
||||||
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);
|
||||||
@ -1552,9 +1560,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
// 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
|
||||||
// ostream.
|
// ostream.
|
||||||
// L < g_gmock_mutex
|
virtual void UntypedDescribeUninterestingCall(
|
||||||
virtual void UntypedDescribeUninterestingCall(const void* untyped_args,
|
const void* untyped_args,
|
||||||
::std::ostream* os) const {
|
::std::ostream* os) const
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
const ArgumentTuple& args =
|
const ArgumentTuple& args =
|
||||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||||
*os << "Uninteresting mock function call - ";
|
*os << "Uninteresting mock function call - ";
|
||||||
@ -1579,11 +1588,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
// section. The reason is that we have no control on what the
|
// section. The reason is that we have no control on what the
|
||||||
// action does (it can invoke an arbitrary user function or even a
|
// action does (it can invoke an arbitrary user function or even a
|
||||||
// mock function) and excessive locking could cause a dead lock.
|
// mock function) and excessive locking could cause a dead lock.
|
||||||
// L < g_gmock_mutex
|
|
||||||
virtual const ExpectationBase* UntypedFindMatchingExpectation(
|
virtual const ExpectationBase* UntypedFindMatchingExpectation(
|
||||||
const void* untyped_args,
|
const void* untyped_args,
|
||||||
const void** untyped_action, bool* is_excessive,
|
const void** untyped_action, bool* is_excessive,
|
||||||
::std::ostream* what, ::std::ostream* why) {
|
::std::ostream* what, ::std::ostream* why)
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
const ArgumentTuple& args =
|
const ArgumentTuple& args =
|
||||||
*static_cast<const ArgumentTuple*>(untyped_args);
|
*static_cast<const ArgumentTuple*>(untyped_args);
|
||||||
MutexLock l(&g_gmock_mutex);
|
MutexLock l(&g_gmock_mutex);
|
||||||
@ -1614,9 +1623,9 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
|
|
||||||
// Returns the expectation that matches the arguments, or NULL if no
|
// Returns the expectation that matches the arguments, or NULL if no
|
||||||
// expectation matches them.
|
// expectation matches them.
|
||||||
// L >= g_gmock_mutex
|
|
||||||
TypedExpectation<F>* FindMatchingExpectationLocked(
|
TypedExpectation<F>* FindMatchingExpectationLocked(
|
||||||
const ArgumentTuple& args) const {
|
const ArgumentTuple& args) const
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
for (typename UntypedExpectations::const_reverse_iterator it =
|
for (typename UntypedExpectations::const_reverse_iterator it =
|
||||||
untyped_expectations_.rbegin();
|
untyped_expectations_.rbegin();
|
||||||
@ -1631,10 +1640,11 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a message that the arguments don't match any expectation.
|
// Returns a message that the arguments don't match any expectation.
|
||||||
// L >= g_gmock_mutex
|
void FormatUnexpectedCallMessageLocked(
|
||||||
void FormatUnexpectedCallMessageLocked(const ArgumentTuple& args,
|
const ArgumentTuple& args,
|
||||||
::std::ostream* os,
|
::std::ostream* os,
|
||||||
::std::ostream* why) const {
|
::std::ostream* why) const
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
*os << "\nUnexpected mock function call - ";
|
*os << "\nUnexpected mock function call - ";
|
||||||
DescribeDefaultActionTo(args, os);
|
DescribeDefaultActionTo(args, os);
|
||||||
@ -1643,9 +1653,10 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
|
|
||||||
// Prints a list of expectations that have been tried against the
|
// Prints a list of expectations that have been tried against the
|
||||||
// current mock function call.
|
// current mock function call.
|
||||||
// L >= g_gmock_mutex
|
void PrintTriedExpectationsLocked(
|
||||||
void PrintTriedExpectationsLocked(const ArgumentTuple& args,
|
const ArgumentTuple& args,
|
||||||
::std::ostream* why) const {
|
::std::ostream* why) const
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
const int count = static_cast<int>(untyped_expectations_.size());
|
const int count = static_cast<int>(untyped_expectations_.size());
|
||||||
*why << "Google Mock tried the following " << count << " "
|
*why << "Google Mock tried the following " << count << " "
|
||||||
@ -1694,7 +1705,6 @@ class FunctionMockerBase : public UntypedFunctionMockerBase {
|
|||||||
// Verifies that all expectations on this mock function have been
|
// Verifies that all expectations on this mock function have been
|
||||||
// satisfied. Reports one or more Google Test non-fatal failures and
|
// satisfied. Reports one or more Google Test non-fatal failures and
|
||||||
// returns false if not.
|
// returns false if not.
|
||||||
// L >= g_gmock_mutex
|
|
||||||
|
|
||||||
// Reports an uninteresting call (whose description is in msg) in the
|
// Reports an uninteresting call (whose description is in msg) in the
|
||||||
// manner specified by 'reaction'.
|
// manner specified by 'reaction'.
|
||||||
|
@ -92,7 +92,8 @@ void ExpectationBase::SpecifyCardinality(const Cardinality& a_cardinality) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retires all pre-requisites of this expectation.
|
// Retires all pre-requisites of this expectation.
|
||||||
void ExpectationBase::RetireAllPreRequisites() {
|
void ExpectationBase::RetireAllPreRequisites()
|
||||||
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
if (is_retired()) {
|
if (is_retired()) {
|
||||||
// We can take this short-cut as we never retire an expectation
|
// We can take this short-cut as we never retire an expectation
|
||||||
// until we have retired all its pre-requisites.
|
// until we have retired all its pre-requisites.
|
||||||
@ -111,8 +112,8 @@ void ExpectationBase::RetireAllPreRequisites() {
|
|||||||
|
|
||||||
// Returns true iff all pre-requisites of this expectation have been
|
// Returns true iff all pre-requisites of this expectation have been
|
||||||
// satisfied.
|
// satisfied.
|
||||||
// L >= g_gmock_mutex
|
bool ExpectationBase::AllPrerequisitesAreSatisfied() const
|
||||||
bool ExpectationBase::AllPrerequisitesAreSatisfied() const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
||||||
it != immediate_prerequisites_.end(); ++it) {
|
it != immediate_prerequisites_.end(); ++it) {
|
||||||
@ -124,9 +125,8 @@ bool ExpectationBase::AllPrerequisitesAreSatisfied() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adds unsatisfied pre-requisites of this expectation to 'result'.
|
// Adds unsatisfied pre-requisites of this expectation to 'result'.
|
||||||
// L >= g_gmock_mutex
|
void ExpectationBase::FindUnsatisfiedPrerequisites(ExpectationSet* result) const
|
||||||
void ExpectationBase::FindUnsatisfiedPrerequisites(
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
ExpectationSet* result) const {
|
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin();
|
||||||
it != immediate_prerequisites_.end(); ++it) {
|
it != immediate_prerequisites_.end(); ++it) {
|
||||||
@ -147,8 +147,8 @@ void ExpectationBase::FindUnsatisfiedPrerequisites(
|
|||||||
|
|
||||||
// Describes how many times a function call matching this
|
// Describes how many times a function call matching this
|
||||||
// expectation has occurred.
|
// expectation has occurred.
|
||||||
// L >= g_gmock_mutex
|
void ExpectationBase::DescribeCallCountTo(::std::ostream* os) const
|
||||||
void ExpectationBase::DescribeCallCountTo(::std::ostream* os) const {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
|
|
||||||
// Describes how many times the function is expected to be called.
|
// Describes how many times the function is expected to be called.
|
||||||
@ -170,8 +170,8 @@ void ExpectationBase::DescribeCallCountTo(::std::ostream* os) const {
|
|||||||
// WillRepeatedly() clauses) against the cardinality if this hasn't
|
// WillRepeatedly() clauses) against the cardinality if this hasn't
|
||||||
// been done before. Prints a warning if there are too many or too
|
// been done before. Prints a warning if there are too many or too
|
||||||
// few actions.
|
// few actions.
|
||||||
// L < mutex_
|
void ExpectationBase::CheckActionCountIfNotDone() const
|
||||||
void ExpectationBase::CheckActionCountIfNotDone() const {
|
GTEST_LOCK_EXCLUDED_(mutex_) {
|
||||||
bool should_check = false;
|
bool should_check = false;
|
||||||
{
|
{
|
||||||
MutexLock l(&mutex_);
|
MutexLock l(&mutex_);
|
||||||
@ -266,8 +266,8 @@ UntypedFunctionMockerBase::~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.
|
||||||
// L < g_gmock_mutex
|
void UntypedFunctionMockerBase::RegisterOwner(const void* mock_obj)
|
||||||
void UntypedFunctionMockerBase::RegisterOwner(const void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
{
|
{
|
||||||
MutexLock l(&g_gmock_mutex);
|
MutexLock l(&g_gmock_mutex);
|
||||||
mock_obj_ = mock_obj;
|
mock_obj_ = mock_obj;
|
||||||
@ -278,9 +278,9 @@ void UntypedFunctionMockerBase::RegisterOwner(const void* mock_obj) {
|
|||||||
// Sets the mock object this mock method belongs to, and sets the name
|
// Sets the mock object this mock method belongs to, and sets the name
|
||||||
// of the mock function. Will be called upon each invocation of this
|
// of the mock function. Will be called upon each invocation of this
|
||||||
// mock function.
|
// mock function.
|
||||||
// L < g_gmock_mutex
|
void UntypedFunctionMockerBase::SetOwnerAndName(const void* mock_obj,
|
||||||
void UntypedFunctionMockerBase::SetOwnerAndName(
|
const char* name)
|
||||||
const void* mock_obj, const char* name) {
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
// We protect name_ under g_gmock_mutex in case this mock function
|
// We protect name_ under g_gmock_mutex in case this mock function
|
||||||
// is called from two threads concurrently.
|
// is called from two threads concurrently.
|
||||||
MutexLock l(&g_gmock_mutex);
|
MutexLock l(&g_gmock_mutex);
|
||||||
@ -290,8 +290,8 @@ void UntypedFunctionMockerBase::SetOwnerAndName(
|
|||||||
|
|
||||||
// Returns the name of the function being mocked. Must be called
|
// Returns the name of the function being mocked. Must be called
|
||||||
// after RegisterOwner() or SetOwnerAndName() has been called.
|
// after RegisterOwner() or SetOwnerAndName() has been called.
|
||||||
// L < g_gmock_mutex
|
const void* UntypedFunctionMockerBase::MockObject() const
|
||||||
const void* UntypedFunctionMockerBase::MockObject() const {
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
const void* mock_obj;
|
const void* mock_obj;
|
||||||
{
|
{
|
||||||
// We protect mock_obj_ under g_gmock_mutex in case this mock
|
// We protect mock_obj_ under g_gmock_mutex in case this mock
|
||||||
@ -307,8 +307,8 @@ const void* UntypedFunctionMockerBase::MockObject() const {
|
|||||||
|
|
||||||
// Returns the name of this mock method. Must be called after
|
// Returns the name of this mock method. Must be called after
|
||||||
// SetOwnerAndName() has been called.
|
// SetOwnerAndName() has been called.
|
||||||
// L < g_gmock_mutex
|
const char* UntypedFunctionMockerBase::Name() const
|
||||||
const char* UntypedFunctionMockerBase::Name() const {
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
const char* name;
|
const char* name;
|
||||||
{
|
{
|
||||||
// We protect name_ under g_gmock_mutex in case this mock
|
// We protect name_ under g_gmock_mutex in case this mock
|
||||||
@ -325,9 +325,9 @@ const char* UntypedFunctionMockerBase::Name() const {
|
|||||||
// Calculates the result of invoking this mock function with the given
|
// Calculates the result of invoking this mock function with the given
|
||||||
// arguments, prints it, and returns it. The caller is responsible
|
// arguments, prints it, and returns it. The caller is responsible
|
||||||
// for deleting the result.
|
// for deleting the result.
|
||||||
// L < g_gmock_mutex
|
|
||||||
const UntypedActionResultHolderBase*
|
const UntypedActionResultHolderBase*
|
||||||
UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) {
|
UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args)
|
||||||
|
GTEST_LOCK_EXCLUDED_(g_gmock_mutex) {
|
||||||
if (untyped_expectations_.size() == 0) {
|
if (untyped_expectations_.size() == 0) {
|
||||||
// No expectation is set on this mock method - we have an
|
// No expectation is set on this mock method - we have an
|
||||||
// uninteresting call.
|
// uninteresting call.
|
||||||
@ -453,8 +453,8 @@ Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) {
|
|||||||
// Verifies that all expectations on this mock function have been
|
// Verifies that all expectations on this mock function have been
|
||||||
// satisfied. Reports one or more Google Test non-fatal failures
|
// satisfied. Reports one or more Google Test non-fatal failures
|
||||||
// and returns false if not.
|
// and returns false if not.
|
||||||
// L >= g_gmock_mutex
|
bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked()
|
||||||
bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex) {
|
||||||
g_gmock_mutex.AssertHeld();
|
g_gmock_mutex.AssertHeld();
|
||||||
bool expectations_met = true;
|
bool expectations_met = true;
|
||||||
for (UntypedExpectations::const_iterator it =
|
for (UntypedExpectations::const_iterator it =
|
||||||
@ -578,9 +578,9 @@ std::map<const void*, internal::CallReaction> g_uninteresting_call_reaction;
|
|||||||
|
|
||||||
// Sets the reaction Google Mock should have when an uninteresting
|
// Sets the reaction Google Mock should have when an uninteresting
|
||||||
// method of the given mock object is called.
|
// method of the given mock object is called.
|
||||||
// L < g_gmock_mutex
|
|
||||||
void SetReactionOnUninterestingCalls(const void* mock_obj,
|
void SetReactionOnUninterestingCalls(const void* mock_obj,
|
||||||
internal::CallReaction reaction) {
|
internal::CallReaction reaction)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
g_uninteresting_call_reaction[mock_obj] = reaction;
|
g_uninteresting_call_reaction[mock_obj] = reaction;
|
||||||
}
|
}
|
||||||
@ -589,38 +589,38 @@ void SetReactionOnUninterestingCalls(const void* mock_obj,
|
|||||||
|
|
||||||
// Tells Google Mock to allow uninteresting calls on the given mock
|
// Tells Google Mock to allow uninteresting calls on the given mock
|
||||||
// object.
|
// object.
|
||||||
// L < g_gmock_mutex
|
void Mock::AllowUninterestingCalls(const void* mock_obj)
|
||||||
void Mock::AllowUninterestingCalls(const void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
SetReactionOnUninterestingCalls(mock_obj, internal::ALLOW);
|
SetReactionOnUninterestingCalls(mock_obj, internal::ALLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tells Google Mock to warn the user about uninteresting calls on the
|
// Tells Google Mock to warn the user about uninteresting calls on the
|
||||||
// given mock object.
|
// given mock object.
|
||||||
// L < g_gmock_mutex
|
void Mock::WarnUninterestingCalls(const void* mock_obj)
|
||||||
void Mock::WarnUninterestingCalls(const void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
SetReactionOnUninterestingCalls(mock_obj, internal::WARN);
|
SetReactionOnUninterestingCalls(mock_obj, internal::WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tells Google Mock to fail uninteresting calls on the given mock
|
// Tells Google Mock to fail uninteresting calls on the given mock
|
||||||
// object.
|
// object.
|
||||||
// L < g_gmock_mutex
|
void Mock::FailUninterestingCalls(const void* mock_obj)
|
||||||
void Mock::FailUninterestingCalls(const void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
SetReactionOnUninterestingCalls(mock_obj, internal::FAIL);
|
SetReactionOnUninterestingCalls(mock_obj, internal::FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tells Google Mock the given mock object is being destroyed and its
|
// Tells Google Mock the given mock object is being destroyed and its
|
||||||
// entry in the call-reaction table should be removed.
|
// entry in the call-reaction table should be removed.
|
||||||
// L < g_gmock_mutex
|
void Mock::UnregisterCallReaction(const void* mock_obj)
|
||||||
void Mock::UnregisterCallReaction(const void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
g_uninteresting_call_reaction.erase(mock_obj);
|
g_uninteresting_call_reaction.erase(mock_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the reaction Google Mock will have on uninteresting calls
|
// Returns the reaction Google Mock will have on uninteresting calls
|
||||||
// made on the given mock object.
|
// made on the given mock object.
|
||||||
// L < g_gmock_mutex
|
|
||||||
internal::CallReaction Mock::GetReactionOnUninterestingCalls(
|
internal::CallReaction Mock::GetReactionOnUninterestingCalls(
|
||||||
const void* mock_obj) {
|
const void* mock_obj)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
|
return (g_uninteresting_call_reaction.count(mock_obj) == 0) ?
|
||||||
internal::WARN : g_uninteresting_call_reaction[mock_obj];
|
internal::WARN : g_uninteresting_call_reaction[mock_obj];
|
||||||
@ -628,8 +628,8 @@ internal::CallReaction Mock::GetReactionOnUninterestingCalls(
|
|||||||
|
|
||||||
// Tells Google Mock to ignore mock_obj when checking for leaked mock
|
// Tells Google Mock to ignore mock_obj when checking for leaked mock
|
||||||
// objects.
|
// objects.
|
||||||
// L < g_gmock_mutex
|
void Mock::AllowLeak(const void* mock_obj)
|
||||||
void Mock::AllowLeak(const void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
g_mock_object_registry.states()[mock_obj].leakable = true;
|
g_mock_object_registry.states()[mock_obj].leakable = true;
|
||||||
}
|
}
|
||||||
@ -637,8 +637,8 @@ void Mock::AllowLeak(const void* mock_obj) {
|
|||||||
// Verifies and clears all expectations on the given mock object. If
|
// Verifies and clears all expectations on the given mock object. If
|
||||||
// the expectations aren't satisfied, generates one or more Google
|
// the expectations aren't satisfied, generates one or more Google
|
||||||
// Test non-fatal failures and returns false.
|
// Test non-fatal failures and returns false.
|
||||||
// L < g_gmock_mutex
|
bool Mock::VerifyAndClearExpectations(void* mock_obj)
|
||||||
bool Mock::VerifyAndClearExpectations(void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
return VerifyAndClearExpectationsLocked(mock_obj);
|
return VerifyAndClearExpectationsLocked(mock_obj);
|
||||||
}
|
}
|
||||||
@ -646,8 +646,8 @@ bool Mock::VerifyAndClearExpectations(void* mock_obj) {
|
|||||||
// Verifies all expectations on the given mock object and clears its
|
// Verifies all expectations on the given mock object and clears its
|
||||||
// default actions and expectations. Returns true iff the
|
// default actions and expectations. Returns true iff the
|
||||||
// verification was successful.
|
// verification was successful.
|
||||||
// L < g_gmock_mutex
|
bool Mock::VerifyAndClear(void* mock_obj)
|
||||||
bool Mock::VerifyAndClear(void* mock_obj) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
ClearDefaultActionsLocked(mock_obj);
|
ClearDefaultActionsLocked(mock_obj);
|
||||||
return VerifyAndClearExpectationsLocked(mock_obj);
|
return VerifyAndClearExpectationsLocked(mock_obj);
|
||||||
@ -656,8 +656,8 @@ bool Mock::VerifyAndClear(void* mock_obj) {
|
|||||||
// Verifies and clears all expectations on the given mock object. If
|
// Verifies and clears all expectations on the given mock object. If
|
||||||
// the expectations aren't satisfied, generates one or more Google
|
// the expectations aren't satisfied, generates one or more Google
|
||||||
// Test non-fatal failures and returns false.
|
// Test non-fatal failures and returns false.
|
||||||
// L >= g_gmock_mutex
|
bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj)
|
||||||
bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex) {
|
||||||
internal::g_gmock_mutex.AssertHeld();
|
internal::g_gmock_mutex.AssertHeld();
|
||||||
if (g_mock_object_registry.states().count(mock_obj) == 0) {
|
if (g_mock_object_registry.states().count(mock_obj) == 0) {
|
||||||
// No EXPECT_CALL() was set on the given mock object.
|
// No EXPECT_CALL() was set on the given mock object.
|
||||||
@ -682,9 +682,9 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Registers a mock object and a mock method it owns.
|
// Registers a mock object and a mock method it owns.
|
||||||
// L < g_gmock_mutex
|
|
||||||
void Mock::Register(const void* mock_obj,
|
void Mock::Register(const void* mock_obj,
|
||||||
internal::UntypedFunctionMockerBase* mocker) {
|
internal::UntypedFunctionMockerBase* mocker)
|
||||||
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
g_mock_object_registry.states()[mock_obj].function_mockers.insert(mocker);
|
g_mock_object_registry.states()[mock_obj].function_mockers.insert(mocker);
|
||||||
}
|
}
|
||||||
@ -692,9 +692,9 @@ void Mock::Register(const void* mock_obj,
|
|||||||
// Tells Google Mock where in the source code mock_obj is used in an
|
// Tells Google Mock where in the source code mock_obj is used in an
|
||||||
// ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
|
// ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this
|
||||||
// information helps the user identify which object it is.
|
// information helps the user identify which object it is.
|
||||||
// L < g_gmock_mutex
|
void Mock::RegisterUseByOnCallOrExpectCall(const void* mock_obj,
|
||||||
void Mock::RegisterUseByOnCallOrExpectCall(
|
const char* file, int line)
|
||||||
const void* mock_obj, const char* file, int line) {
|
GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) {
|
||||||
internal::MutexLock l(&internal::g_gmock_mutex);
|
internal::MutexLock l(&internal::g_gmock_mutex);
|
||||||
MockObjectState& state = g_mock_object_registry.states()[mock_obj];
|
MockObjectState& state = g_mock_object_registry.states()[mock_obj];
|
||||||
if (state.first_used_file == NULL) {
|
if (state.first_used_file == NULL) {
|
||||||
@ -716,8 +716,8 @@ void Mock::RegisterUseByOnCallOrExpectCall(
|
|||||||
// registry when the last mock method associated with it has been
|
// registry when the last mock method associated with it has been
|
||||||
// unregistered. This is called only in the destructor of
|
// unregistered. This is called only in the destructor of
|
||||||
// FunctionMockerBase.
|
// FunctionMockerBase.
|
||||||
// L >= g_gmock_mutex
|
void Mock::UnregisterLocked(internal::UntypedFunctionMockerBase* mocker)
|
||||||
void Mock::UnregisterLocked(internal::UntypedFunctionMockerBase* mocker) {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex) {
|
||||||
internal::g_gmock_mutex.AssertHeld();
|
internal::g_gmock_mutex.AssertHeld();
|
||||||
for (MockObjectRegistry::StateMap::iterator it =
|
for (MockObjectRegistry::StateMap::iterator it =
|
||||||
g_mock_object_registry.states().begin();
|
g_mock_object_registry.states().begin();
|
||||||
@ -734,8 +734,8 @@ void Mock::UnregisterLocked(internal::UntypedFunctionMockerBase* mocker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clears all ON_CALL()s set on the given mock object.
|
// Clears all ON_CALL()s set on the given mock object.
|
||||||
// L >= g_gmock_mutex
|
void Mock::ClearDefaultActionsLocked(void* mock_obj)
|
||||||
void Mock::ClearDefaultActionsLocked(void* mock_obj) {
|
GTEST_EXCLUSIVE_LOCK_REQUIRED_(internal::g_gmock_mutex) {
|
||||||
internal::g_gmock_mutex.AssertHeld();
|
internal::g_gmock_mutex.AssertHeld();
|
||||||
|
|
||||||
if (g_mock_object_registry.states().count(mock_obj) == 0) {
|
if (g_mock_object_registry.states().count(mock_obj) == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user