Skip to content

Commit 9769ebb

Browse files
committed
Fixes to be compatible with the new versions of FakeIt.
1 parent 2b51c7c commit 9769ebb

File tree

6 files changed

+19
-20
lines changed

6 files changed

+19
-20
lines changed

include/fakeit/api_macros.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@
4848
(mock).template stub<STUB_ID(__COUNTER__)>(CONST_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
4949

5050
#define RefOverloadedMethod(mock, method, prototype) \
51-
(mock).template stub<__COUNTER__>(REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
51+
(mock).template stub<STUB_ID(__COUNTER__)>(REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
5252

5353
#define ConstRefOverloadedMethod(mock, method, prototype) \
54-
(mock).template stub<__COUNTER__>(CONST_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
54+
(mock).template stub<STUB_ID(__COUNTER__)>(CONST_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
5555

5656
#define RValRefOverloadedMethod(mock, method, prototype) \
57-
(mock).template stub<__COUNTER__>(R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
57+
(mock).template stub<STUB_ID(__COUNTER__)>(R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
5858

5959
#define ConstRValRefOverloadedMethod(mock, method, prototype) \
60-
(mock).template stub<__COUNTER__>(CONST_R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
60+
(mock).template stub<STUB_ID(__COUNTER__)>(CONST_R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
6161

6262
#define Verify(...) \
6363
Verify( __VA_ARGS__ ).setFileInfo(__FILE__, __LINE__, __func__)

include/mockutils/DynamicProxy.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
#include <vector>
1414
#include <array>
1515
#include <new>
16-
#include <limits>
1716

1817
#include "mockutils/VirtualTable.hpp"
19-
#include "mockutils/union_cast.hpp"
2018
#include "mockutils/MethodInvocationHandler.hpp"
2119
#include "mockutils/VTUtils.hpp"
2220
#include "mockutils/FakeObject.hpp"
@@ -34,7 +32,8 @@ namespace fakeit {
3432
{
3533
unsigned int offset = 0;
3634
for (; offset < _offsets.size(); offset++) {
37-
if (_offsets[offset] == id) {
35+
// Only check _offsets for methods that were mocked.
36+
if (_methodMocks[offset] != nullptr && _offsets[offset] == id) {
3837
break;
3938
}
4039
}
@@ -61,8 +60,8 @@ namespace fakeit {
6160

6261
DynamicProxy(C &inst) :
6362
_instancePtr(&inst),
64-
_methodMocks(VTUtils::getVTSize<C>()),
65-
_offsets(VTUtils::getVTSize<C>(), std::numeric_limits<int>::max()),
63+
_methodMocks(VTUtils::getVTSize<C>(), nullptr),
64+
_offsets(VTUtils::getVTSize<C>(), 0),
6665
_invocationHandlers(_methodMocks, _offsets) {
6766
_originalVt.copyFrom(VirtualTable<C, baseclasses...>::getVTable(*_instancePtr));
6867
_originalVt.setCookie(InvocationHandlerCollection::VtCookieIndex, &_invocationHandlers);
@@ -97,10 +96,10 @@ namespace fakeit {
9796

9897
void Reset() {
9998
_methodMocks = {};
100-
_methodMocks.resize(VTUtils::getVTSize<C>());
99+
_methodMocks.resize(VTUtils::getVTSize<C>(), nullptr);
101100
_members = {};
102101
_offsets = {};
103-
_offsets.resize(VTUtils::getVTSize<C>());
102+
_offsets.resize(VTUtils::getVTSize<C>(), 0);
104103
VirtualTable<C, baseclasses...>::getVTable(*_instancePtr).copyFrom(_originalVt);
105104
}
106105

include/mockutils/MethodProxyCreator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace fakeit {
3434
return MethodProxy(id, offset, union_cast<void *>(&MethodProxyCreator::methodProxyX < id > ));
3535
}
3636

37-
template<unsigned int id>
37+
template<size_t id>
3838
MethodProxy createMethodProxyStatic(unsigned int offset) {
3939
return MethodProxy(id, offset, union_cast<void *>(&MethodProxyCreator::methodProxyXStatic < id > ));
4040
}
@@ -55,7 +55,7 @@ namespace fakeit {
5555
return methodProxy(id, std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
5656
}
5757

58-
static R methodProxyStatic(void* instance, unsigned int id, const typename fakeit::production_arg<arglist>::type... args) {
58+
static R methodProxyStatic(void* instance, size_t id, const typename fakeit::production_arg<arglist>::type... args) {
5959
InvocationHandlerCollection *invocationHandlerCollection = InvocationHandlerCollection::getInvocationHandlerCollection(
6060
instance);
6161
MethodInvocationHandler<R, arglist...> *invocationHandler =
@@ -64,7 +64,7 @@ namespace fakeit {
6464
return invocationHandler->handleMethodInvocation(std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
6565
}
6666

67-
template<int id>
67+
template<size_t id>
6868
static R methodProxyXStatic(void* instance, arglist ... args) {
6969
return methodProxyStatic(instance, id, std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
7070
}

include/mockutils/VTUtils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace fakeit {
6565
}
6666

6767
template<typename C>
68-
static size_t getVTSize() {
68+
static unsigned int getVTSize() {
6969
struct Derrived : public C {
7070
virtual void endOfVt() {
7171
}

include/mockutils/gcc/VirtualTable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace fakeit {
131131

132132
private:
133133
static void **buildVTArray() {
134-
int size = VTUtils::getVTSize<C>();
134+
unsigned int size = VTUtils::getVTSize<C>();
135135
auto array = new void *[size + 2 + numOfCookies]{};
136136
array += numOfCookies; // skip cookies
137137
array++; // skip top_offset

include/mockutils/mscpp/VirtualTable.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace fakeit {
178178
}
179179

180180
void copyFrom(VirtualTable<C, baseclasses...> &from) {
181-
auto size = VTUtils::getVTSize<C>();
181+
unsigned int size = VTUtils::getVTSize<C>();
182182
for (unsigned int i = 0; i < size; i++) {
183183
_firstMethod[i] = from.getMethod(i);
184184
}
@@ -234,12 +234,12 @@ namespace fakeit {
234234
setCookie(dtorCookieIndex, method);
235235
}
236236

237-
size_t getSize() {
237+
unsigned int getSize() {
238238
return VTUtils::getVTSize<C>();
239239
}
240240

241241
void initAll(void *value) {
242-
auto size = getSize();
242+
unsigned int size = getSize();
243243
for (unsigned int i = 0; i < size; i++) {
244244
setMethod(i, value);
245245
}
@@ -256,7 +256,7 @@ namespace fakeit {
256256
static const unsigned int dtorCookieIndex = numOfCookies - 1; // use the last cookie
257257

258258
static void **buildVTArray() {
259-
auto vtSize = VTUtils::getVTSize<C>();
259+
unsigned int vtSize = VTUtils::getVTSize<C>();
260260
auto array = new void *[vtSize + numOfCookies + 1]{};
261261
RTTICompleteObjectLocator<C, baseclasses...> *objectLocator = new RTTICompleteObjectLocator<C, baseclasses...>(
262262
typeid(C));

0 commit comments

Comments
 (0)