Skip to content

Commit

Permalink
Fixes to be compatible with the new versions of FakeIt.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed May 26, 2024
1 parent 2b51c7c commit 9769ebb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
8 changes: 4 additions & 4 deletions include/fakeit/api_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@
(mock).template stub<STUB_ID(__COUNTER__)>(CONST_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)

#define RefOverloadedMethod(mock, method, prototype) \
(mock).template stub<__COUNTER__>(REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
(mock).template stub<STUB_ID(__COUNTER__)>(REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)

#define ConstRefOverloadedMethod(mock, method, prototype) \
(mock).template stub<__COUNTER__>(CONST_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
(mock).template stub<STUB_ID(__COUNTER__)>(CONST_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)

#define RValRefOverloadedMethod(mock, method, prototype) \
(mock).template stub<__COUNTER__>(R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
(mock).template stub<STUB_ID(__COUNTER__)>(R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)

#define ConstRValRefOverloadedMethod(mock, method, prototype) \
(mock).template stub<__COUNTER__>(CONST_R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)
(mock).template stub<STUB_ID(__COUNTER__)>(CONST_R_VAL_REF_OVERLOADED_METHOD_PTR( mock , method, prototype )).setMethodDetails(#mock,#method)

#define Verify(...) \
Verify( __VA_ARGS__ ).setFileInfo(__FILE__, __LINE__, __func__)
Expand Down
13 changes: 6 additions & 7 deletions include/mockutils/DynamicProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
#include <vector>
#include <array>
#include <new>
#include <limits>

#include "mockutils/VirtualTable.hpp"
#include "mockutils/union_cast.hpp"
#include "mockutils/MethodInvocationHandler.hpp"
#include "mockutils/VTUtils.hpp"
#include "mockutils/FakeObject.hpp"
Expand All @@ -34,7 +32,8 @@ namespace fakeit {
{
unsigned int offset = 0;
for (; offset < _offsets.size(); offset++) {
if (_offsets[offset] == id) {
// Only check _offsets for methods that were mocked.
if (_methodMocks[offset] != nullptr && _offsets[offset] == id) {
break;
}
}
Expand All @@ -61,8 +60,8 @@ namespace fakeit {

DynamicProxy(C &inst) :
_instancePtr(&inst),
_methodMocks(VTUtils::getVTSize<C>()),
_offsets(VTUtils::getVTSize<C>(), std::numeric_limits<int>::max()),
_methodMocks(VTUtils::getVTSize<C>(), nullptr),
_offsets(VTUtils::getVTSize<C>(), 0),
_invocationHandlers(_methodMocks, _offsets) {
_originalVt.copyFrom(VirtualTable<C, baseclasses...>::getVTable(*_instancePtr));
_originalVt.setCookie(InvocationHandlerCollection::VtCookieIndex, &_invocationHandlers);
Expand Down Expand Up @@ -97,10 +96,10 @@ namespace fakeit {

void Reset() {
_methodMocks = {};
_methodMocks.resize(VTUtils::getVTSize<C>());
_methodMocks.resize(VTUtils::getVTSize<C>(), nullptr);
_members = {};
_offsets = {};
_offsets.resize(VTUtils::getVTSize<C>());
_offsets.resize(VTUtils::getVTSize<C>(), 0);
VirtualTable<C, baseclasses...>::getVTable(*_instancePtr).copyFrom(_originalVt);
}

Expand Down
6 changes: 3 additions & 3 deletions include/mockutils/MethodProxyCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace fakeit {
return MethodProxy(id, offset, union_cast<void *>(&MethodProxyCreator::methodProxyX < id > ));
}

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

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

template<int id>
template<size_t id>
static R methodProxyXStatic(void* instance, arglist ... args) {
return methodProxyStatic(instance, id, std::forward<const typename fakeit::production_arg<arglist>::type>(args)...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/mockutils/VTUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace fakeit {
}

template<typename C>
static size_t getVTSize() {
static unsigned int getVTSize() {
struct Derrived : public C {
virtual void endOfVt() {
}
Expand Down
2 changes: 1 addition & 1 deletion include/mockutils/gcc/VirtualTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace fakeit {

private:
static void **buildVTArray() {
int size = VTUtils::getVTSize<C>();
unsigned int size = VTUtils::getVTSize<C>();
auto array = new void *[size + 2 + numOfCookies]{};
array += numOfCookies; // skip cookies
array++; // skip top_offset
Expand Down
8 changes: 4 additions & 4 deletions include/mockutils/mscpp/VirtualTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace fakeit {
}

void copyFrom(VirtualTable<C, baseclasses...> &from) {
auto size = VTUtils::getVTSize<C>();
unsigned int size = VTUtils::getVTSize<C>();
for (unsigned int i = 0; i < size; i++) {
_firstMethod[i] = from.getMethod(i);
}
Expand Down Expand Up @@ -234,12 +234,12 @@ namespace fakeit {
setCookie(dtorCookieIndex, method);
}

size_t getSize() {
unsigned int getSize() {
return VTUtils::getVTSize<C>();
}

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

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

0 comments on commit 9769ebb

Please sign in to comment.