brainstorming: how to implement the test mock injection
This commit is contained in:
parent
739a473f7e
commit
24792c1f19
1 changed files with 28 additions and 9 deletions
|
|
@ -84,15 +84,34 @@ namespace lib {
|
|||
|
||||
|
||||
|
||||
// struct TemporarySwitch
|
||||
// {
|
||||
// void* originalInstance;
|
||||
// InstanceConstructor originalCtor;
|
||||
// };
|
||||
//
|
||||
// static TemporarySwitch temporarySwitch;
|
||||
|
||||
|
||||
class TemporaryShadowedInstanceFactory
|
||||
: boost::noncopyable
|
||||
{
|
||||
typedef DependencyFactory::InstanceConstructor Ctor;
|
||||
|
||||
void* originalInstance_;
|
||||
Ctor originalCtor_;
|
||||
|
||||
public:
|
||||
TemporaryShadowedInstanceFactory(void* instance, Ctor ctor)
|
||||
: originalInstance_(instance)
|
||||
, originalCtor_(ctor)
|
||||
{ }
|
||||
|
||||
void*
|
||||
constructorInvocation()
|
||||
{
|
||||
REQUIRE (originalCtor_);
|
||||
|
||||
if (!originalInstance_)
|
||||
return originalCtor_();
|
||||
|
||||
void* existingInstance = originalInstance_;
|
||||
originalInstance_ = NULL;
|
||||
return existingInstance;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue