-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'otrempe-fakeit/Fix-CollidingMockingCont…
…extIds' into otrempe-Fix-CollidingMockingContextIds
- Loading branch information
Showing
13 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
namespace fakeit { | ||
|
||
constexpr size_t _FNV_prime = sizeof(size_t) == 4 ? 16777619ULL : 1099511628211ULL; | ||
constexpr size_t _FNV_offset_basis = sizeof(size_t) == 4 ? 2166136261ULL : 14695981039346656037ULL; | ||
|
||
constexpr size_t _constExprHashImpl(const char* str, size_t count) { | ||
return count ? (_constExprHashImpl(str, count - 1) ^ str[count - 1]) * _FNV_prime : _FNV_offset_basis; | ||
} | ||
|
||
template<size_t N> | ||
constexpr size_t constExprHash(const char(&str)[N]) { | ||
return _constExprHashImpl(str, N); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "multiple_translation_units_stub.h" | ||
|
||
|
||
void stubFunc2(fakeit::Mock<SomeInterface>& mock) | ||
{ | ||
fakeit::When(Method(mock, func2)).AlwaysReturn<std::string>("String"); | ||
} | ||
|
||
void stubFunc(fakeit::Mock<SomeInterface>& mock) | ||
{ | ||
fakeit::When(Method(mock, func)).AlwaysReturn<int>(3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "fakeit.hpp" | ||
|
||
struct SomeInterface { | ||
virtual int func() = 0; | ||
virtual std::string func2() = 0; | ||
}; | ||
|
||
void stubFunc2(fakeit::Mock<SomeInterface>& mock); | ||
void stubFunc(fakeit::Mock<SomeInterface>& mock); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "tpunit++.hpp" | ||
#include "fakeit.hpp" | ||
#include "multiple_translation_units_stub.h" | ||
|
||
using namespace fakeit; | ||
|
||
struct MultipleTranslationUnitsStub : tpunit::TestFixture { | ||
MultipleTranslationUnitsStub() | ||
: tpunit::TestFixture( | ||
TEST(MultipleTranslationUnitsStub::NoCollidingIds) | ||
) | ||
{} | ||
|
||
void NoCollidingIds() { | ||
Mock<SomeInterface> mock; | ||
SomeInterface &i = mock.get(); | ||
|
||
stubFunc2(mock); | ||
When(Method(mock, func)).Return<int>(1); | ||
|
||
mock.get().func2(); // Uncatchable write access violation if ids collide | ||
} | ||
|
||
} __MultipleTranslationUnitsStub; |