dascandy / hippomocks

GNU Lesser General Public License v2.1
196 stars 67 forks source link

Dkgs return const ref #37

Closed dkgs closed 9 years ago

dkgs commented 9 years ago

I propose the following modifications tu support return const ref values.

At first, I did the modification bu overloading the return function the following way :

template <typename T>
class AsRef
{
    AsRef(T & value) : _v(value) {}
    operator T& () { return _v; }
    T & _v;
}:
...
Call &Return(AsRef<Y> obj)

But It was fastidious to use :

InterfaceReturned * ir = mocks.Mock<InterfaceReturned>();
mocks.OnCall(myMock, Interface::myFunction).Return(AsRef<const InterfaceReturned &>(*ir));

Then I prefered adding a new Return function named ReturnByRef() it is more explicit to me.

dascandy commented 9 years ago

Looks like it does not build. Can you check what's up with that?

From an API point of view the change sounds good. I'll look into the details a bit more to see what's going on with the build error. Thanks!

dkgs commented 9 years ago

On my side, I only tested under msvc10 on an other machine which doesn't have a direct internet connection, then I may have made a mistake reporting my modifications. Errors seems to come from clang and gcc compilers. I'll look into it.

dascandy commented 9 years ago

Code change looks fine too; I think Clang/GCC complain about the inline pure-virtual-with-initializer syntax you use. I think it's not valid but that MSVC accepts it regardless.

dkgs commented 9 years ago

Destructors corrected, clang is now fine. But gcc does complain about "forming reference to reference" that should be due to my edits in hippomocks.h. I'll check.

dkgs commented 9 years ago

Yeah it passed :)

dascandy commented 9 years ago

Merged - thanks!