Hello
assume the following mocked method:
MOCK_CONST_METHOD1(fun, void ( OtherMock& ret));
The return value is by reference and type is another mock object.
Assigning a value to ret always involves making a copy. Unfortunately,
I have no ide how to copy mock objects in the sense that all
expectation will be copied too.
How can I achieve this?
Regards
Daniel
> MOCK_CONST_METHOD1(fun, void ( OtherDomainType& ret));
When declared this way, it becomes more obvious that assigning to "ret" will use the OtherDomainType's assignment operator. That assignment will invoke C++'s "slicing problem" (copying base class data, not subclass data). Unless you make operator= a virtual function, which still won't work because mock objects are explicity not copyable.
What you MIGHT be able to do to get around this is to use smart pointers.
> MOCK_CONST_METHOD1(fun, void ( shared_ptr<OtherDomainType>& ret));
But I expect making that work will involve rewriting your code a great deal. You would need a factory function in your domain code that can be overridden in your test code. The factory function creates OtherDomainType objects using "new" and your test version of the factory function creates OtherMock objects using "new".
C. Keith Ray
http://agilesolutionspace.blogspot.com/
twitter: @ckeithray