Skip to content

Commit 6e04fff

Browse files
committed
Add default class for Prototype in case compiler can't deduce it.
1 parent 580bf27 commit 6e04fff

File tree

3 files changed

+82
-32
lines changed

3 files changed

+82
-32
lines changed

include/fakeit/Prototype.hpp

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,64 @@ namespace fakeit {
2121
template<class C>
2222
using ConstRValRefType = R (C::*)(Args...) const&&;
2323

24-
template<class C>
25-
static constexpr Type<C> get(Type<C> t) {
26-
return t;
27-
}
24+
template <typename DefaultC>
25+
struct MemberType {
2826

29-
template<class C>
30-
static constexpr ConstType<C> getConst(ConstType<C> t) {
31-
return t;
32-
}
27+
template<class C>
28+
static constexpr Type<C> get(Type<C> t) {
29+
return t;
30+
}
3331

34-
template<class C>
35-
static constexpr RefType<C> getRef(RefType<C> t) {
36-
return t;
37-
}
32+
static constexpr Type<DefaultC> get(Type<DefaultC> t) {
33+
return t;
34+
}
3835

39-
template<class C>
40-
static constexpr ConstRefType<C> getConstRef(ConstRefType<C> t) {
41-
return t;
42-
}
36+
template<class C>
37+
static constexpr ConstType<C> getConst(ConstType<C> t) {
38+
return t;
39+
}
4340

44-
template<class C>
45-
static constexpr RValRefType<C> getRValRef(RValRefType<C> t) {
46-
return t;
47-
}
41+
static constexpr ConstType<DefaultC> getConst(ConstType<DefaultC> t) {
42+
return t;
43+
}
4844

49-
template<class C>
50-
static constexpr ConstRValRefType<C> getConstRValRef(ConstRValRefType<C> t) {
51-
return t;
52-
}
45+
template<class C>
46+
static constexpr RefType<C> getRef(RefType<C> t) {
47+
return t;
48+
}
49+
50+
static constexpr RefType<DefaultC> getRef(RefType<DefaultC> t) {
51+
return t;
52+
}
53+
54+
template<class C>
55+
static constexpr ConstRefType<C> getConstRef(ConstRefType<C> t) {
56+
return t;
57+
}
58+
59+
static constexpr ConstRefType<DefaultC> getConstRef(ConstRefType<DefaultC> t) {
60+
return t;
61+
}
62+
63+
template<class C>
64+
static constexpr RValRefType<C> getRValRef(RValRefType<C> t) {
65+
return t;
66+
}
67+
68+
static constexpr RValRefType<DefaultC> getRValRef(RValRefType<DefaultC> t) {
69+
return t;
70+
}
71+
72+
template<class C>
73+
static constexpr ConstRValRefType<C> getConstRValRef(ConstRValRefType<C> t) {
74+
return t;
75+
}
76+
77+
static constexpr ConstRValRefType<DefaultC> getConstRValRef(ConstRValRefType<DefaultC> t) {
78+
return t;
79+
}
80+
81+
};
5382

5483
};
5584

include/fakeit/api_macros.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
std::remove_reference<decltype((mock).get())>::type
1111

1212
#define OVERLOADED_METHOD_PTR(mock, method, prototype) \
13-
fakeit::Prototype<prototype>::get(&MOCK_TYPE(mock)::method)
13+
fakeit::Prototype<prototype>::template MemberType<typename MOCK_TYPE(mock)>::get(&MOCK_TYPE(mock)::method)
1414

1515
#define CONST_OVERLOADED_METHOD_PTR(mock, method, prototype) \
16-
fakeit::Prototype<prototype>::getConst(&MOCK_TYPE(mock)::method)
16+
fakeit::Prototype<prototype>::template MemberType<typename MOCK_TYPE(mock)>::getConst(&MOCK_TYPE(mock)::method)
1717

1818
#define REF_OVERLOADED_METHOD_PTR(mock, method, prototype) \
19-
fakeit::Prototype<prototype>::getRef(&MOCK_TYPE(mock)::method)
19+
fakeit::Prototype<prototype>::template MemberType<typename MOCK_TYPE(mock)>::getRef(&MOCK_TYPE(mock)::method)
2020

2121
#define CONST_REF_OVERLOADED_METHOD_PTR(mock, method, prototype) \
22-
fakeit::Prototype<prototype>::getConstRef(&MOCK_TYPE(mock)::method)
22+
fakeit::Prototype<prototype>::template MemberType<typename MOCK_TYPE(mock)>::getConstRef(&MOCK_TYPE(mock)::method)
2323

2424
#define R_VAL_REF_OVERLOADED_METHOD_PTR(mock, method, prototype) \
25-
fakeit::Prototype<prototype>::getRValRef(&MOCK_TYPE(mock)::method)
25+
fakeit::Prototype<prototype>::template MemberType<typename MOCK_TYPE(mock)>::getRValRef(&MOCK_TYPE(mock)::method)
2626

2727
#define CONST_R_VAL_REF_OVERLOADED_METHOD_PTR(mock, method, prototype) \
28-
fakeit::Prototype<prototype>::getConstRValRef(&MOCK_TYPE(mock)::method)
28+
fakeit::Prototype<prototype>::template MemberType<typename MOCK_TYPE(mock)>::getConstRValRef(&MOCK_TYPE(mock)::method)
2929

3030
#define Dtor(mock) \
3131
(mock).dtor().setMethodDetails(#mock,"destructor")

tests/inherited_funcs_tests.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct InheritedFuncsTests : tpunit::TestFixture
1616

1717
InheritedFuncsTests() :
1818
TestFixture(
19-
TEST(InheritedFuncsTests::mock_base_functions)
19+
TEST(InheritedFuncsTests::mock_base_overloaded_functions),
20+
TEST(InheritedFuncsTests::mock_base_and_child_overloaded_functions)
2021
)
2122
{
2223
}
@@ -29,15 +30,18 @@ struct InheritedFuncsTests : tpunit::TestFixture
2930
virtual double nonOverloadedMethod() = 0;
3031
virtual double overloadedMethod() = 0;
3132
virtual double overloadedMethod() const = 0;
33+
virtual double overloadedInChildMethod() = 0;
3234
};
3335

3436
class Interface : public BaseInterface
3537
{
3638
public:
3739
~Interface() override = default;
40+
using BaseInterface::overloadedInChildMethod;
41+
virtual double overloadedInChildMethod() const = 0;
3842
};
3943

40-
void mock_base_functions()
44+
void mock_base_overloaded_functions()
4145
{
4246
Mock<Interface> mock;
4347

@@ -57,4 +61,21 @@ struct InheritedFuncsTests : tpunit::TestFixture
5761
Verify(ConstOverloadedMethod(mock, overloadedMethod, double())).Exactly(1);
5862
}
5963

64+
void mock_base_and_child_overloaded_functions()
65+
{
66+
Mock<Interface> mock;
67+
68+
When(OverloadedMethod(mock, overloadedInChildMethod, double())).Return(4.5);
69+
When(ConstOverloadedMethod(mock, overloadedInChildMethod, double())).Return(5.5);
70+
71+
Interface& interface = mock.get();
72+
const Interface& constInterface = mock.get();
73+
74+
EXPECT_EQUAL(interface.overloadedInChildMethod(), 4.5);
75+
EXPECT_EQUAL(constInterface.overloadedInChildMethod(), 5.5);
76+
77+
Verify(OverloadedMethod(mock, overloadedInChildMethod, double())).Exactly(1);
78+
Verify(ConstOverloadedMethod(mock, overloadedInChildMethod, double())).Exactly(1);
79+
}
80+
6081
} __InheritedFuncsTests;

0 commit comments

Comments
 (0)