dascandy / hippomocks

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

Add support for creating std::unique_ptr mocks #81

Closed APokorny closed 7 years ago

APokorny commented 7 years ago

Before passing ownership to the final destination, capture the pointer to declare your expectations. I.e in your fixture:

   std::unique_ptr<Type> thing{mocks.UniqueMock<Type>()};
   Type* mock_thing{thing.get()};

.. in your test ..

   MoreComplexThing obj{move(thing)};
   mocks.ExpectCall(mock_thing, Type::beTypy);

Or write a 'tee' function along the lines of:

template <typename T>
auto tee(T &* out, std::unique_ptr<T> && v) -> std::unique_ptr<T>
{
    out = v.get();
    return v;
}

The new code requires unique_ptr to exist - disable with HM_NO_UNIQUE_PTR

Signed-off-by: Andreas Pokorny andreas.pokorny@siemens.com

dascandy commented 7 years ago

Maybe it's a better idea to add this to the cpp11 branch?

APokorny commented 7 years ago

Agreed .. also I should write some tests for that facility.