diff --git a/include/fakeit/StubbingProgress.hpp b/include/fakeit/StubbingProgress.hpp index c4f7a5e6..ef7dee06 100644 --- a/include/fakeit/StubbingProgress.hpp +++ b/include/fakeit/StubbingProgress.hpp @@ -100,11 +100,11 @@ namespace fakeit { return DoImpl(new Repeat(method, q.quantity)); } - template + template MethodStubbingProgress & - Return(const first &f, const second &s, const tail &... t) { - Return(f); - return Return(s, t...); + Return(First&& f, Second&& s, Tail&&... t) { + Return(std::forward(f)); + return Return(std::forward(s), std::forward(t)...); } diff --git a/tests/move_only_return_tests.cpp b/tests/move_only_return_tests.cpp index 44d72e37..802f2cb9 100644 --- a/tests/move_only_return_tests.cpp +++ b/tests/move_only_return_tests.cpp @@ -34,7 +34,7 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { struct MoveOnlyInterface { virtual std::string returnCopyable() = 0; virtual std::unique_ptr returnMoveOnlyUniqueString() = 0; - virtual MoveOnlyType returnMoveOnlyConcreteType() = 0; + virtual MoveOnlyType returnMoveOnlyType() = 0; virtual std::vector returnVectorOfMoveOnly() = 0; }; @@ -48,7 +48,8 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { tpunit::TestFixture( // TEST(MoveOnlyReturnTests::explicitStubbingReturnValuesFromTemporary), - TEST(MoveOnlyReturnTests::explicitStubbingReturnValuesFromMove) + TEST(MoveOnlyReturnTests::explicitStubbingReturnValuesFromMove), + TEST(MoveOnlyReturnTests::explicitStubbingReturnMultipleValuesMoveAndCopy) // ) { } @@ -57,13 +58,13 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { Mock mock; When(Method(mock, returnMoveOnlyUniqueString)).Return(std::unique_ptr(new std::string("value"))); - When(Method(mock, returnMoveOnlyConcreteType)).Return(MoveOnlyType(10)); + When(Method(mock, returnMoveOnlyType)).Return(MoveOnlyType(10)); When(Method(mock, returnVectorOfMoveOnly)).Return(constructVectorOfMoveOnly(5)); MoveOnlyInterface & i = mock.get(); ASSERT_EQUAL("value", *i.returnMoveOnlyUniqueString()); - ASSERT_EQUAL(MoveOnlyType(10), i.returnMoveOnlyConcreteType()); + ASSERT_EQUAL(MoveOnlyType(10), i.returnMoveOnlyType()); ASSERT_EQUAL(constructVectorOfMoveOnly(5), i.returnVectorOfMoveOnly()); } @@ -71,13 +72,13 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { Mock mock; std::string str{"copyable"}; - MoveOnlyType moveOnly(10); std::unique_ptr strPtr(new std::string("value")); + MoveOnlyType moveOnly(10); std::vector vectorOfMoveOnly = constructVectorOfMoveOnly(5); When(Method(mock, returnCopyable)).Return(std::move(str)); When(Method(mock, returnMoveOnlyUniqueString)).Return(std::move(strPtr)); - When(Method(mock, returnMoveOnlyConcreteType)).Return(std::move(moveOnly)); + When(Method(mock, returnMoveOnlyType)).Return(std::move(moveOnly)); When(Method(mock, returnVectorOfMoveOnly)).Return(std::move(vectorOfMoveOnly)); // check move did happen @@ -89,7 +90,39 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { ASSERT_EQUAL(std::string("copyable"), i.returnCopyable()); ASSERT_EQUAL(std::string("value"), *i.returnMoveOnlyUniqueString()); - ASSERT_EQUAL(MoveOnlyType(10), i.returnMoveOnlyConcreteType()); + ASSERT_EQUAL(MoveOnlyType(10), i.returnMoveOnlyType()); + ASSERT_EQUAL(constructVectorOfMoveOnly(5), i.returnVectorOfMoveOnly()); + } + + void explicitStubbingReturnMultipleValuesMoveAndCopy() { + Mock mock; + + std::string copiedStr{"copied"}; + std::string movedStr{"moved"}; + std::unique_ptr strPtr(new std::string("strPtrMove")); + MoveOnlyType moveOnly(100); + std::vector vectorOfMoveOnly = constructVectorOfMoveOnly(50); + + When(Method(mock, returnCopyable)).Return(copiedStr, std::move(movedStr)); + When(Method(mock, returnMoveOnlyUniqueString)).Return(std::unique_ptr(new std::string("strPtrRval")), std::move(strPtr)); + When(Method(mock, returnMoveOnlyType)).Return(MoveOnlyType(10), std::move(moveOnly)); + When(Method(mock, returnVectorOfMoveOnly)).Return(constructVectorOfMoveOnly(5), std::move(vectorOfMoveOnly)); + + ASSERT_EQUAL(copiedStr, "copied"); // check move did NOT happen + // check move did happen + ASSERT_TRUE(movedStr.empty()); + ASSERT_EQUAL(strPtr, nullptr); + ASSERT_TRUE(vectorOfMoveOnly.empty()); + + MoveOnlyInterface& i = mock.get(); + + ASSERT_EQUAL(std::string("copied"), i.returnCopyable()); + ASSERT_EQUAL(std::string("moved"), i.returnCopyable()); + ASSERT_EQUAL(std::string("strPtrRval"), *i.returnMoveOnlyUniqueString()); + ASSERT_EQUAL(std::string("strPtrMove"), *i.returnMoveOnlyUniqueString()); + ASSERT_EQUAL(MoveOnlyType(10), i.returnMoveOnlyType()); + ASSERT_EQUAL(MoveOnlyType(100), i.returnMoveOnlyType()); ASSERT_EQUAL(constructVectorOfMoveOnly(5), i.returnVectorOfMoveOnly()); + ASSERT_EQUAL(constructVectorOfMoveOnly(50), i.returnVectorOfMoveOnly()); } } __MoveOnlyReturnTests;