Skip to content

Commit

Permalink
Added a bit more content for #298 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Nov 23, 2022
1 parent 11cae4f commit 58b7933
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
15 changes: 11 additions & 4 deletions tests/argument_matching_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include "tpunit++.hpp"
#include "fakeit.hpp"
#include "testutils.hpp"

using namespace fakeit;

Expand Down Expand Up @@ -58,7 +59,7 @@ struct ArgumentMatchingTests: tpunit::TestFixture {
TEST(ArgumentMatchingTests::format_ApproxEq),
TEST(ArgumentMatchingTests::test_move_only_type),
TEST(ArgumentMatchingTests::test_vector_of_move_only_type),
TEST(ArgumentMatchingTests::test_no_slicing)
TEST(ArgumentMatchingTests::test_no_slicing)
) //
{
}
Expand Down Expand Up @@ -625,9 +626,15 @@ struct ArgumentMatchingTests: tpunit::TestFixture {
void test_vector_of_move_only_type() {
Mock<SomeInterface> mock;

// Won't compile if parameters of type std::vector<MoveOnly> are not handled properly
Fake(Method(mock, funcVectorOfMoveOnly));
When(Method(mock, funcVectorOfMoveOnly));
When(Method(mock, funcVectorOfMoveOnly).Using(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{10}, MoveOnlyType{15}))).Return(1);
When(Method(mock, funcVectorOfMoveOnly).Using(Eq(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{20}, MoveOnlyType{25})))).Return(2);

SomeInterface& i = mock.get();
ASSERT_EQUAL(1, i.funcVectorOfMoveOnly(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{10}, MoveOnlyType{15})));
ASSERT_EQUAL(2, i.funcVectorOfMoveOnly(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{20}, MoveOnlyType{25})));

Verify(Method(mock, funcVectorOfMoveOnly).Using(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{10}, MoveOnlyType{15}))).Once();
Verify(Method(mock, funcVectorOfMoveOnly).Using(Eq(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{20}, MoveOnlyType{25})))).Once();
}

void test_no_slicing() {
Expand Down
8 changes: 5 additions & 3 deletions tests/spying_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "tpunit++.hpp"
#include "fakeit.hpp"
#include "testutils.hpp"

using namespace fakeit;

Expand Down Expand Up @@ -255,9 +256,10 @@ struct SpyingTests: tpunit::TestFixture {
{
SomeClass obj;
Mock<SomeClass> mock(obj);

// Won't compile if parameters of type std::vector<MoveOnly> are not handled properly
SpyWithoutVerify(Method(mock, funcVectorOfMoveOnly));
SpyWithoutVerify(Method(mock,funcVectorOfMoveOnly));

SomeClass &i = mock.get();
ASSERT_EQUAL(15, i.funcVectorOfMoveOnly(testutils::multi_emplace(std::vector<MoveOnlyType>{}, MoveOnlyType{5}, MoveOnlyType{10})));
}

} __SpyingTests;
30 changes: 30 additions & 0 deletions tests/testutils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

namespace testutils
{
template<typename VecType>
std::vector<VecType>& multi_emplace(std::vector<VecType>& vec)
{
return vec;
}

template<typename VecType>
std::vector<VecType>&& multi_emplace(std::vector<VecType>&& vec)
{
return std::move(vec);
}

template<typename VecType, typename Head, typename... Tail>
std::vector<VecType>& multi_emplace(std::vector<VecType>& vec, Head&& head, Tail&&... tail)
{
vec.emplace_back(std::move(head));
return multi_emplace(vec, tail...);
}

template<typename VecType, typename Head, typename... Tail>
std::vector<VecType>&& multi_emplace(std::vector<VecType>&& vec, Head&& head, Tail&&... tail)
{
vec.emplace_back(std::move(head));
return std::move(multi_emplace(vec, tail...));
}
}

0 comments on commit 58b7933

Please sign in to comment.