Skip to content

Commit

Permalink
Merge 6f4e97c into 78ca536
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmdavey committed Aug 10, 2022
2 parents 78ca536 + 6f4e97c commit 9492cbb
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -32,6 +32,7 @@ Debug/
ipch/
TestResults/
tests/cmake-build-debug/
tests/x64/
*/.vs/

# Eclipse
Expand Down Expand Up @@ -59,3 +60,4 @@ bii/

*.*~
*.nupkg

8 changes: 8 additions & 0 deletions appveyor.yml
@@ -1,2 +1,10 @@
image:
- Visual Studio 2019
- Visual Studio 2015

configuration:
- Debug
- Release

build:
project: tests\all_tests.sln
6 changes: 3 additions & 3 deletions include/fakeit/StubbingProgress.hpp
Expand Up @@ -373,7 +373,7 @@ namespace fakeit {
template <typename ...T, int ...N>
static void CheckPositions(const std::tuple<ArgValue<T, N>...> arg_vals)
{
#if __cplusplus >= 201402L
#if __cplusplus >= 201402L && !defined(_WIN32)
static_assert(std::get<tuple_index>(arg_vals).pos <= max_index,
"Argument index out of range");
ArgValidator<max_index, tuple_index - 1>::CheckPositions(arg_vals);
Expand Down Expand Up @@ -425,7 +425,7 @@ namespace fakeit {
struct ArgLocator {
template<typename current_arg, typename ...T, int ...N>
static void AssignArg(current_arg &&p, std::tuple<ArgValue<T, N>...> arg_vals) {
#if __cplusplus >= 201703L
#if __cplusplus >= 201703L && !defined (_WIN32)
if constexpr (std::get<check_index>(arg_vals).pos == arg_index)
GetArg(std::forward<current_arg>(p)) = std::get<check_index>(arg_vals).value;
#else
Expand All @@ -436,7 +436,7 @@ namespace fakeit {
ArgLocator<arg_index, check_index - 1>::AssignArg(std::forward<current_arg>(p), arg_vals);
}

#if __cplusplus < 201703L
#if __cplusplus < 201703L || defined (_WIN32)
private:
template<typename T, typename U>
static
Expand Down
8 changes: 7 additions & 1 deletion tests/all_tests.vcxproj
Expand Up @@ -120,6 +120,12 @@
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile Condition="'$(PlatformToolset)' != 'v140'">
<AdditionalOptions>/Zc:__cplusplus</AdditionalOptions>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="argument_matching_tests.cpp" />
<ClCompile Include="cpp14_tests.cpp" />
Expand Down Expand Up @@ -156,4 +162,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
8 changes: 5 additions & 3 deletions tests/cpp14_tests.cpp
Expand Up @@ -71,10 +71,12 @@ struct Cpp14Tests : tpunit::TestFixture {
), fakeit::VerificationException);
}

struct ApiInterface {
virtual bool apiMethod(int a, int b, int& result) = 0;
};

void assingOutParamsWithLambdaCpp14(){
struct ApiInterface {
virtual bool apiMethod(int a, int b, int& result) = 0;
};


Mock<ApiInterface> mock;
When(Method(mock, apiMethod)).AlwaysDo([](auto a, auto b, auto& result) {
Expand Down
36 changes: 19 additions & 17 deletions tests/miscellaneous_tests.cpp
Expand Up @@ -48,16 +48,17 @@ struct Miscellaneous : tpunit::TestFixture
Fake(Method(mock, foo));
}

void can_mock_class_with_protected_constructor()
struct SomeClass
{
struct SomeClass
virtual void foo() = 0;
protected:
SomeClass(int)
{
virtual void foo() = 0;
protected:
SomeClass(int)
{
}
};
}
};

void can_mock_class_with_protected_constructor()
{
Mock<SomeClass> mock;
Fake(Method(mock, foo));
}
Expand Down Expand Up @@ -121,14 +122,15 @@ struct Miscellaneous : tpunit::TestFixture
ASSERT_EQUAL(4, mock().a2());
}

struct FooReturnInt {
virtual int bar(int&&) = 0;
};

void testStubFuncWithRightValueParameter() {

struct Foo {
virtual int bar(int &&) = 0;
};

Mock<Foo> foo_mock;

Mock<FooReturnInt> foo_mock;
When(Method(foo_mock, bar)).AlwaysReturn(100);
When(Method(foo_mock, bar).Using(1)).AlwaysReturn(1);
When(Method(foo_mock, bar).Using(2)).AlwaysDo([](int &){return 2; });
Expand All @@ -142,17 +144,17 @@ struct Miscellaneous : tpunit::TestFixture
ASSERT_EQUAL(4, foo_mock.get().bar(4));
}

void testStubProcWithRightValueParameter() {
struct FooReturnVoid {
virtual void bar(int&&) = 0;
};

struct Foo {
virtual void bar(int &&) = 0;
};
void testStubProcWithRightValueParameter() {

int rv3 = 0;
int rv4 = 0;
int rv5 = 0;

Mock<Foo> foo_mock;
Mock<FooReturnVoid> foo_mock;
When(Method(foo_mock, bar).Using(1)).Return();
When(Method(foo_mock, bar)).AlwaysReturn();
When(Method(foo_mock, bar).Using(3)).AlwaysDo([&](int &){rv3 = 3; });
Expand Down
32 changes: 18 additions & 14 deletions tests/stubbing_tests.cpp
Expand Up @@ -765,20 +765,21 @@ struct BasicStubbing : tpunit::TestFixture {
ASSERT_THROW(i.func(1), fakeit::UnexpectedMethodCallException);
}

struct SomeInterfaceWithMember {
virtual int func(int) = 0;

std::string state;
};

void reset_mock_to_initial_state() {
struct SomeInterface {
virtual int func(int) = 0;

std::string state;
};

Mock<SomeInterface> mock;
Mock<SomeInterfaceWithMember> mock;
When(Method(mock, func)).AlwaysReturn(0);
When(Method(mock, func).Using(1)).AlwaysReturn(1);
mock.Stub(&SomeInterface::state, "state");
mock.Stub(&SomeInterfaceWithMember::state, "state");
//
SomeInterface &i = mock.get();
SomeInterfaceWithMember&i = mock.get();
i.func(0);
i.func(1);

Expand All @@ -805,10 +806,12 @@ struct BasicStubbing : tpunit::TestFixture {
Verify(Method(mock, func).Using(1));
}

struct SomeClass {
virtual int foo(int* x) = 0;
};

void use_lambda_to_change_ptr_value() {
struct SomeClass {
virtual int foo(int *x) = 0;
};


Mock<SomeClass> mock;

Expand All @@ -823,10 +826,11 @@ struct BasicStubbing : tpunit::TestFixture {
ASSERT_EQUAL(1, num);
}

void assingOutParamsWithLambda(){
struct ApiInterface {
virtual bool apiMethod(int a, int b, int& result) = 0;
};
struct ApiInterface {
virtual bool apiMethod(int a, int b, int& result) = 0;
};
void assingOutParamsWithLambda(){


Mock<ApiInterface> mock;
When(Method(mock, apiMethod)).AlwaysDo([](int a, int b, int& result) {
Expand Down
25 changes: 9 additions & 16 deletions tests/verification_tests.cpp
Expand Up @@ -494,12 +494,11 @@ struct BasicVerification: tpunit::TestFixture {
Verify(2 * call_to_proc2_with_state_1);
}

struct AnInterface {
virtual int func(int) = 0;
};

void verifyWithUnverifiedFunctor(){

struct AnInterface {
virtual int func(int) = 0;
};

Mock<AnInterface> mock;
When(Method(mock, func)).AlwaysReturn(0);
Expand All @@ -523,10 +522,6 @@ struct BasicVerification: tpunit::TestFixture {

void verifyWithUnverifiedFunctorWithUsing() {

struct AnInterface {
virtual int func(int) = 0;
};

Mock<AnInterface> mock;
When(Method(mock, func)).AlwaysReturn(0);

Expand All @@ -539,10 +534,6 @@ struct BasicVerification: tpunit::TestFixture {

void verificationProgressShouldBeConvertibleToBool(){

struct AnInterface {
virtual int func(int) = 0;
};

Mock<AnInterface> mock;
When(Method(mock, func)).AlwaysReturn(0);

Expand Down Expand Up @@ -574,11 +565,13 @@ struct BasicVerification: tpunit::TestFixture {
ASSERT_FALSE(!VerifyNoOtherInvocations(Method(mock, func)));
}

struct RefEater {
virtual int eatChar(char*) = 0;
virtual int eatConstChar(const char*) = 0;
};

void verificationShouldTolerateNullString(){
struct RefEater {
virtual int eatChar(char*) = 0;
virtual int eatConstChar(const char*) = 0;
};


Mock<RefEater> mock;
When( Method( mock, eatChar ) ).AlwaysReturn( 0 );
Expand Down

0 comments on commit 9492cbb

Please sign in to comment.