Electroneum
testing::internal::FunctionMockerBase< F > Class Template Reference

#include <gmock-generated-function-mockers.h>

Inheritance diagram for testing::internal::FunctionMockerBase< F >:
Collaboration diagram for testing::internal::FunctionMockerBase< F >:

Public Types

typedef Function< F >::Result Result
 
typedef Function< F >::ArgumentTuple ArgumentTuple
 
typedef Function< F >::ArgumentMatcherTuple ArgumentMatcherTuple
 

Public Member Functions

 FunctionMockerBase ()
 
virtual ~FunctionMockerBase () GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
const OnCallSpec< F > * FindOnCallSpec (const ArgumentTuple &args) const
 
Result PerformDefaultAction (const ArgumentTuple &args, const string &call_description) const
 
virtual UntypedActionResultHolderBaseUntypedPerformDefaultAction (const void *untyped_args, const string &call_description) const
 
virtual UntypedActionResultHolderBaseUntypedPerformAction (const void *untyped_action, const void *untyped_args) const
 
virtual void ClearDefaultActionsLocked () GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
- Public Member Functions inherited from testing::internal::UntypedFunctionMockerBase
 UntypedFunctionMockerBase ()
 
virtual ~UntypedFunctionMockerBase ()
 
bool VerifyAndClearExpectationsLocked () GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
 
void RegisterOwner (const void *mock_obj) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
void SetOwnerAndName (const void *mock_obj, const char *name) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
const void * MockObject () const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
const char * Name () const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
UntypedActionResultHolderBaseUntypedInvokeWith (const void *untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 

Protected Types

typedef ActionResultHolder< ResultResultHolder
 
- Protected Types inherited from testing::internal::UntypedFunctionMockerBase
typedef std::vector< const void * > UntypedOnCallSpecs
 
typedef std::vector< internal::linked_ptr< ExpectationBase > > UntypedExpectations
 

Protected Member Functions

Result InvokeWith (const ArgumentTuple &args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
OnCallSpec< F > & AddNewOnCallSpec (const char *file, int line, const ArgumentMatcherTuple &m) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
TypedExpectation< F > & AddNewExpectation (const char *file, int line, const string &source_text, const ArgumentMatcherTuple &m) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
MockSpec< F > & current_spec ()
 
- Protected Member Functions inherited from testing::internal::UntypedFunctionMockerBase
Expectation GetHandleOf (ExpectationBase *exp)
 

Friends

template<typename Function >
class MockSpec
 
template<typename Func >
class TypedExpectation
 

Additional Inherited Members

- Protected Attributes inherited from testing::internal::UntypedFunctionMockerBase
const void * mock_obj_
 
const char * name_
 
UntypedOnCallSpecs untyped_on_call_specs_
 
UntypedExpectations untyped_expectations_
 

Detailed Description

template<typename F>
class testing::internal::FunctionMockerBase< F >

Definition at line 54 of file gmock-generated-function-mockers.h.

Member Typedef Documentation

◆ ArgumentMatcherTuple

◆ ArgumentTuple

Definition at line 1459 of file gmock-spec-builders.h.

◆ Result

template<typename F>
typedef Function<F>::Result testing::internal::FunctionMockerBase< F >::Result

Definition at line 1458 of file gmock-spec-builders.h.

◆ ResultHolder

template<typename F>
typedef ActionResultHolder<Result> testing::internal::FunctionMockerBase< F >::ResultHolder
protected

Definition at line 1577 of file gmock-spec-builders.h.

Constructor & Destructor Documentation

◆ FunctionMockerBase()

template<typename F>
testing::internal::FunctionMockerBase< F >::FunctionMockerBase ( )
inline

Definition at line 1462 of file gmock-spec-builders.h.

1462 : current_spec_(this) {}

◆ ~FunctionMockerBase()

template<typename F>
virtual testing::internal::FunctionMockerBase< F >::~FunctionMockerBase ( )
inlinevirtual

Definition at line 1467 of file gmock-spec-builders.h.

1468  {
1469  MutexLock l(&g_gmock_mutex);
1471  Mock::UnregisterLocked(this);
1473  }
GTestMutexLock MutexLock
Definition: gtest-port.h:2159
bool VerifyAndClearExpectationsLocked() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
virtual void ClearDefaultActionsLocked() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)

Member Function Documentation

◆ AddNewExpectation()

template<typename F>
TypedExpectation<F>& testing::internal::FunctionMockerBase< F >::AddNewExpectation ( const char *  file,
int  line,
const string source_text,
const ArgumentMatcherTuple m 
)
inlineprotected

Definition at line 1601 of file gmock-spec-builders.h.

1606  {
1607  Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
1608  TypedExpectation<F>* const expectation =
1609  new TypedExpectation<F>(this, file, line, source_text, m);
1610  const linked_ptr<ExpectationBase> untyped_expectation(expectation);
1611  untyped_expectations_.push_back(untyped_expectation);
1612 
1613  // Adds this expectation into the implicit sequence if there is one.
1614  Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
1615  if (implicit_sequence != NULL) {
1616  implicit_sequence->AddExpectation(Expectation(untyped_expectation));
1617  }
1618 
1619  return *expectation;
1620  }
const void * MockObject() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
GTEST_API_ ThreadLocal< Sequence * > g_gmock_implicit_sequence

◆ AddNewOnCallSpec()

template<typename F>
OnCallSpec<F>& testing::internal::FunctionMockerBase< F >::AddNewOnCallSpec ( const char *  file,
int  line,
const ArgumentMatcherTuple m 
)
inlineprotected

Definition at line 1590 of file gmock-spec-builders.h.

1593  {
1594  Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
1595  OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
1596  untyped_on_call_specs_.push_back(on_call_spec);
1597  return *on_call_spec;
1598  }
const void * MockObject() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)

◆ ClearDefaultActionsLocked()

template<typename F>
virtual void testing::internal::FunctionMockerBase< F >::ClearDefaultActionsLocked ( )
inlinevirtual

Implements testing::internal::UntypedFunctionMockerBase.

Definition at line 1547 of file gmock-spec-builders.h.

1548  {
1549  g_gmock_mutex.AssertHeld();
1550 
1551  // Deleting our default actions may trigger other mock objects to be
1552  // deleted, for example if an action contains a reference counted smart
1553  // pointer to that mock object, and that is the last reference. So if we
1554  // delete our actions within the context of the global mutex we may deadlock
1555  // when this method is called again. Instead, make a copy of the set of
1556  // actions to delete, clear our set within the mutex, and then delete the
1557  // actions outside of the mutex.
1558  UntypedOnCallSpecs specs_to_delete;
1559  untyped_on_call_specs_.swap(specs_to_delete);
1560 
1561  g_gmock_mutex.Unlock();
1562  for (UntypedOnCallSpecs::const_iterator it =
1563  specs_to_delete.begin();
1564  it != specs_to_delete.end(); ++it) {
1565  delete static_cast<const OnCallSpec<F>*>(*it);
1566  }
1567 
1568  // Lock the mutex again, since the caller expects it to be locked when we
1569  // return.
1570  g_gmock_mutex.Lock();
1571  }

◆ current_spec()

template<typename F>
MockSpec<F>& testing::internal::FunctionMockerBase< F >::current_spec ( )
inlineprotected

Definition at line 1624 of file gmock-spec-builders.h.

1624 { return current_spec_; }

◆ FindOnCallSpec()

template<typename F>
const OnCallSpec<F>* testing::internal::FunctionMockerBase< F >::FindOnCallSpec ( const ArgumentTuple args) const
inline

Definition at line 1478 of file gmock-spec-builders.h.

1479  {
1480  for (UntypedOnCallSpecs::const_reverse_iterator it
1481  = untyped_on_call_specs_.rbegin();
1482  it != untyped_on_call_specs_.rend(); ++it) {
1483  const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
1484  if (spec->Matches(args))
1485  return spec;
1486  }
1487 
1488  return NULL;
1489  }

◆ InvokeWith()

template<typename F>
Result testing::internal::FunctionMockerBase< F >::InvokeWith ( const ArgumentTuple args)
inlineprotected

Definition at line 1582 of file gmock-spec-builders.h.

1583  {
1584  scoped_ptr<ResultHolder> holder(
1585  DownCast_<ResultHolder*>(this->UntypedInvokeWith(&args)));
1586  return holder->Unwrap();
1587  }
UntypedActionResultHolderBase * UntypedInvokeWith(const void *untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)

◆ PerformDefaultAction()

template<typename F>
Result testing::internal::FunctionMockerBase< F >::PerformDefaultAction ( const ArgumentTuple args,
const string call_description 
) const
inline

Definition at line 1498 of file gmock-spec-builders.h.

1499  {
1500  const OnCallSpec<F>* const spec =
1501  this->FindOnCallSpec(args);
1502  if (spec != NULL) {
1503  return spec->GetAction().Perform(args);
1504  }
1505  const string message = call_description +
1506  "\n The mock function has no default action "
1507  "set, and its return type has no default value set.";
1508 #if GTEST_HAS_EXCEPTIONS
1510  throw std::runtime_error(message);
1511  }
1512 #else
1514 #endif
1515  return DefaultValue<Result>::Get();
1516  }
static bool Exists()
const OnCallSpec< F > * FindOnCallSpec(const ArgumentTuple &args) const
std::string message("Message requiring signing")
void Assert(bool condition, const char *file, int line)
Here is the caller graph for this function:

◆ UntypedPerformAction()

template<typename F>
virtual UntypedActionResultHolderBase* testing::internal::FunctionMockerBase< F >::UntypedPerformAction ( const void *  untyped_action,
const void *  untyped_args 
) const
inlinevirtual

Implements testing::internal::UntypedFunctionMockerBase.

Definition at line 1535 of file gmock-spec-builders.h.

1536  {
1537  // Make a copy of the action before performing it, in case the
1538  // action deletes the mock object (and thus deletes itself).
1539  const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
1540  const ArgumentTuple& args =
1541  *static_cast<const ArgumentTuple*>(untyped_args);
1542  return ResultHolder::PerformAction(action, args);
1543  }
Function< F >::ArgumentTuple ArgumentTuple
static ActionResultHolder * PerformAction(const Action< F > &action, const typename Function< F >::ArgumentTuple &args)

◆ UntypedPerformDefaultAction()

template<typename F>
virtual UntypedActionResultHolderBase* testing::internal::FunctionMockerBase< F >::UntypedPerformDefaultAction ( const void *  untyped_args,
const string call_description 
) const
inlinevirtual

Implements testing::internal::UntypedFunctionMockerBase.

Definition at line 1523 of file gmock-spec-builders.h.

1525  {
1526  const ArgumentTuple& args =
1527  *static_cast<const ArgumentTuple*>(untyped_args);
1528  return ResultHolder::PerformDefaultAction(this, args, call_description);
1529  }
static ActionResultHolder * PerformDefaultAction(const FunctionMockerBase< F > *func_mocker, const typename Function< F >::ArgumentTuple &args, const string &call_description)
Function< F >::ArgumentTuple ArgumentTuple

Friends And Related Function Documentation

◆ MockSpec

template<typename F>
template<typename Function >
friend class MockSpec
friend

Definition at line 1575 of file gmock-spec-builders.h.

◆ TypedExpectation

template<typename F>
template<typename Func >
friend class TypedExpectation
friend

Definition at line 1627 of file gmock-spec-builders.h.


The documentation for this class was generated from the following files: