Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::internal::FunctionMockerBase< F > Class Template Reference

#include <gmock-spec-builders.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 (typename RvalueRef< typename Function< F >::ArgumentTuple >::type args, const std::string &call_description) const
 
virtual UntypedActionResultHolderBaseUntypedPerformDefaultAction (void *untyped_args, const std::string &call_description) const
 
virtual UntypedActionResultHolderBaseUntypedPerformAction (const void *untyped_action, 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 (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 (typename RvalueRef< typename Function< F >::ArgumentTuple >::type 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 std::string &source_text, const ArgumentMatcherTuple &m) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
 
- 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 1469 of file gmock-spec-builders.h.

Member Typedef Documentation

◆ ArgumentMatcherTuple

template<typename F >
Function<F>::ArgumentMatcherTuple testing::internal::FunctionMockerBase< F >::ArgumentMatcherTuple

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

◆ ArgumentTuple

template<typename F >
Function<F>::ArgumentTuple testing::internal::FunctionMockerBase< F >::ArgumentTuple

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

◆ Result

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

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

◆ ResultHolder

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

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

Constructor & Destructor Documentation

◆ FunctionMockerBase()

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

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

1475{}

◆ ~FunctionMockerBase()

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

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

1481 {
1482 MutexLock l(&g_gmock_mutex);
1484 Mock::UnregisterLocked(this);
1486 }
virtual void ClearDefaultActionsLocked() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
bool VerifyAndClearExpectationsLocked() GTEST_EXCLUSIVE_LOCK_REQUIRED_(g_gmock_mutex)
GTestMutexLock MutexLock
int l

Member Function Documentation

◆ AddNewExpectation()

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

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

1622 {
1623 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
1624 TypedExpectation<F>* const expectation =
1625 new TypedExpectation<F>(this, file, line, source_text, m);
1626 const linked_ptr<ExpectationBase> untyped_expectation(expectation);
1627 // See the definition of untyped_expectations_ for why access to
1628 // it is unprotected here.
1629 untyped_expectations_.push_back(untyped_expectation);
1630
1631 // Adds this expectation into the implicit sequence if there is one.
1632 Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
1633 if (implicit_sequence != NULL) {
1634 implicit_sequence->AddExpectation(Expectation(untyped_expectation));
1635 }
1636
1637 return *expectation;
1638 }
const void * MockObject() const GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
GTEST_API_ ThreadLocal< Sequence * > g_gmock_implicit_sequence
Here is the call graph for this function:

◆ AddNewOnCallSpec()

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

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

1611 {
1612 Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
1613 OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
1614 untyped_on_call_specs_.push_back(on_call_spec);
1615 return *on_call_spec;
1616 }

◆ ClearDefaultActionsLocked()

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

Implements testing::internal::UntypedFunctionMockerBase.

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

1562 {
1563 g_gmock_mutex.AssertHeld();
1564
1565 // Deleting our default actions may trigger other mock objects to be
1566 // deleted, for example if an action contains a reference counted smart
1567 // pointer to that mock object, and that is the last reference. So if we
1568 // delete our actions within the context of the global mutex we may deadlock
1569 // when this method is called again. Instead, make a copy of the set of
1570 // actions to delete, clear our set within the mutex, and then delete the
1571 // actions outside of the mutex.
1572 UntypedOnCallSpecs specs_to_delete;
1573 untyped_on_call_specs_.swap(specs_to_delete);
1574
1575 g_gmock_mutex.Unlock();
1576 for (UntypedOnCallSpecs::const_iterator it =
1577 specs_to_delete.begin();
1578 it != specs_to_delete.end(); ++it) {
1579 delete static_cast<const OnCallSpec<F>*>(*it);
1580 }
1581
1582 // Lock the mutex again, since the caller expects it to be locked when we
1583 // return.
1584 g_gmock_mutex.Lock();
1585 }

◆ FindOnCallSpec()

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

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

1492 {
1493 for (UntypedOnCallSpecs::const_reverse_iterator it
1494 = untyped_on_call_specs_.rbegin();
1495 it != untyped_on_call_specs_.rend(); ++it) {
1496 const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
1497 if (spec->Matches(args))
1498 return spec;
1499 }
1500
1501 return NULL;
1502 }
Here is the call graph for this function:

◆ InvokeWith()

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

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

1598 {
1599 // const_cast is required since in C++98 we still pass ArgumentTuple around
1600 // by const& instead of rvalue reference.
1601 void* untyped_args = const_cast<void*>(static_cast<const void*>(&args));
1602 scoped_ptr<ResultHolder> holder(
1603 DownCast_<ResultHolder*>(this->UntypedInvokeWith(untyped_args)));
1604 return holder->Unwrap();
1605 }
UntypedActionResultHolderBase * UntypedInvokeWith(void *untyped_args) GTEST_LOCK_EXCLUDED_(g_gmock_mutex)
To DownCast_(From *f)

◆ PerformDefaultAction()

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

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

1513 {
1514 const OnCallSpec<F>* const spec =
1515 this->FindOnCallSpec(args);
1516 if (spec != NULL) {
1517 return spec->GetAction().Perform(internal::move(args));
1518 }
1519 const std::string message =
1520 call_description +
1521 "\n The mock function has no default action "
1522 "set, and its return type has no default value set.";
1523#if GTEST_HAS_EXCEPTIONS
1525 throw std::runtime_error(message);
1526 }
1527#else
1528 Assert(DefaultValue<Result>::Exists(), "", -1, message);
1529#endif
1531 }
const OnCallSpec< F > * FindOnCallSpec(const ArgumentTuple &args) const
void Assert(bool condition, const char *file, int line)
const T & move(const T &t)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UntypedPerformAction()

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

Implements testing::internal::UntypedFunctionMockerBase.

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

1551 {
1552 // Make a copy of the action before performing it, in case the
1553 // action deletes the mock object (and thus deletes itself).
1554 const Action<F> action = *static_cast<const Action<F>*>(untyped_action);
1555 ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
1557 }
static ActionResultHolder * PerformAction(const Action< F > &action, typename RvalueRef< typename Function< F >::ArgumentTuple >::type args)
Function< F >::ArgumentTuple ArgumentTuple

◆ UntypedPerformDefaultAction()

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

Implements testing::internal::UntypedFunctionMockerBase.

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

1540 {
1541 ArgumentTuple* args = static_cast<ArgumentTuple*>(untyped_args);
1543 call_description);
1544 }
static ActionResultHolder * PerformDefaultAction(const FunctionMockerBase< F > *func_mocker, typename RvalueRef< typename Function< F >::ArgumentTuple >::type args, const std::string &call_description)

Friends And Related Symbol Documentation

◆ MockSpec

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

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

◆ TypedExpectation

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

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


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