Skip to content

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed May 11, 2024
1 parent aed04a2 commit d8612dc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 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
6 changes: 4 additions & 2 deletions include/mockutils/DynamicProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ namespace fakeit {
{
unsigned int offset = 0;
for (; offset < _offsets.size(); offset++) {
if (_offsets[offset] == id) {
// "_methodMocks[offset] != nullptr" checked to guarantee that "_offsets[offset]" was really set and
// doesn't just contain the default id.
if (_offsets[offset] == id && _methodMocks[offset] != nullptr) {
break;
}
}
Expand Down Expand Up @@ -62,7 +64,7 @@ namespace fakeit {
DynamicProxy(C &inst) :
_instancePtr(&inst),
_methodMocks(VTUtils::getVTSize<C>()),
_offsets(VTUtils::getVTSize<C>(), std::numeric_limits<int>::max()), // TODO: should be size_t ?
_offsets(VTUtils::getVTSize<C>(), std::numeric_limits<size_t>::max()),
_invocationHandlers(_methodMocks, _offsets) {
_originalVt.copyFrom(VirtualTable<C, baseclasses...>::getVTable(*_instancePtr));
_originalVt.setCookie(InvocationHandlerCollection::VtCookieIndex, &_invocationHandlers);
Expand Down
17 changes: 10 additions & 7 deletions tests/multiple_translation_units_stub.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "multiple_translation_units_stub.h"

namespace multiple_tu {

void stubFunc2(fakeit::Mock<SomeInterface>& mock)
{
fakeit::When(Method(mock, func2)).AlwaysReturn("String");
}
void stubFunc(fakeit::Mock<SomeInterface>& mock)
{
fakeit::When(Method(mock, func)).AlwaysReturn(3);
}

void stubFunc2(fakeit::Mock<SomeInterface>& mock)
{
fakeit::When(Method(mock, func2)).AlwaysReturn("String");
}

void stubFunc(fakeit::Mock<SomeInterface>& mock)
{
fakeit::When(Method(mock, func)).AlwaysReturn(3);
}
16 changes: 10 additions & 6 deletions tests/multiple_translation_units_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

#include "fakeit.hpp"

struct SomeInterface {
virtual int func() = 0;
virtual std::string func2() = 0;
};
namespace multiple_tu {

void stubFunc2(fakeit::Mock<SomeInterface>& mock);
void stubFunc(fakeit::Mock<SomeInterface>& mock);
struct SomeInterface {
virtual int func() = 0;
virtual std::string func2() = 0;
};

void stubFunc(fakeit::Mock<SomeInterface>& mock);
void stubFunc2(fakeit::Mock<SomeInterface>& mock);

}
25 changes: 17 additions & 8 deletions tests/multiple_translation_units_stub_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@
#include "multiple_translation_units_stub.h"

using namespace fakeit;
using namespace multiple_tu;

struct MultipleTranslationUnitsStub : tpunit::TestFixture {
MultipleTranslationUnitsStub()
: tpunit::TestFixture(

MultipleTranslationUnitsStub() :
tpunit::TestFixture(
TEST(MultipleTranslationUnitsStub::NoCollidingIds)
)
{}
)
{
}

// TODO: more tests to be sure I didn't broke something by changing stuff.
// TODO: add option to revert to old ID generation and test that tests crash.

void NoCollidingIds() {
Mock<SomeInterface> mock;
SomeInterface &i = mock.get();

stubFunc2(mock);
When(Method(mock, func)).Return(1);
stubFunc(mock);
When(Method(mock, func2)).Return("Something");

SomeInterface &i = mock.get();

i.func2(); // Uncatchable write access violation if ids collide
// Uncatchable write access violation if ids collide.
i.func();
i.func2();
}

} __MultipleTranslationUnitsStub;

0 comments on commit d8612dc

Please sign in to comment.