21 #ifndef HIPPOMOCKS_DEFAULTREPORTER_H 22 #define HIPPOMOCKS_DEFAULTREPORTER_H 26 extern "C" __declspec(dllimport)
int WINCALL IsDebuggerPresent();
27 extern "C" __declspec(dllimport)
void WINCALL DebugBreak();
28 #define DEBUGBREAK(e) if (IsDebuggerPresent()) DebugBreak(); else (void)0 34 #if !defined(HM_NO_EXCEPTIONS) 39 inline std::ostream &
operator<<(std::ostream &os,
const Call &call)
41 os << call.fileName <<
"(" << call.lineno <<
") ";
42 if (call.expectation == Once)
43 os <<
"Expectation for ";
45 os <<
"Result set for ";
51 os <<
" on the mock at 0x" << call.mock <<
" was ";
53 if (!call.isSatisfied())
56 if (call.expectation == Once)
57 os <<
"satisfied." << std::endl;
59 os <<
"used." << std::endl;
64 inline std::ostream &
operator<<(std::ostream &os,
const MockRepository &repo)
66 if (repo.expectations.size())
68 os <<
"Expectations set:" << std::endl;
69 for (
auto &exp : repo.expectations)
74 if (repo.neverCalls.size())
76 os <<
"Functions explicitly expected to not be called:" << std::endl;
77 for (
auto &nc : repo.neverCalls)
82 if (repo.optionals.size())
84 os <<
"Optional results set up:" << std::endl;
85 for (
auto &opt : repo.optionals)
93 #ifndef BASE_EXCEPTION 94 #define BASE_EXCEPTION std::exception 96 #define RAISEEXCEPTION(e) { DEBUGBREAK(e); if (std::uncaught_exception()) latentException = [=, &repo]{ throw e; }; else throw e; } 103 const char *
what()
const throw() {
return txt.c_str(); }
113 std::stringstream text;
114 text <<
"Function " << funcName << args <<
" called with mismatching expectation!" << std::endl;
121 #include <execinfo.h> 129 std::stringstream text;
130 text <<
"Function called without expectation!" << std::endl;
134 void *stacktrace[256];
135 size_t size = backtrace(stacktrace,
sizeof(stacktrace));
138 text <<
"Stackdump:" << std::endl;
139 char **symbols = backtrace_symbols(stacktrace, size);
140 for (
size_t i = 0; i <
size; i = i + 1)
142 text << symbols[i] << std::endl;
157 std::stringstream text;
158 text <<
"Function with expectation not called!" << std::endl;
169 std::stringstream text;
170 text <<
"Function called on mock that has already been destroyed!" << std::endl;
174 void *stacktrace[256];
175 size_t size = backtrace(stacktrace,
sizeof(stacktrace));
178 text <<
"Stackdump:" << std::endl;
179 char **symbols = backtrace_symbols(stacktrace, size);
180 for (
size_t i = 0; i <
size; i = i + 1)
182 text << symbols[i] << std::endl;
197 std::stringstream text;
198 text <<
"No result set up on call to " << funcName << args << std::endl << repo;
201 void *stacktrace[256];
202 size_t size = backtrace(stacktrace,
sizeof(stacktrace));
205 text <<
"Stackdump:" << std::endl;
206 char **symbols = backtrace_symbols(stacktrace, size);
207 for (
size_t i = 0; i <
size; i = i + 1)
209 text << symbols[i] << std::endl;
221 static struct DefaultReporter :
Reporter 223 DefaultReporter() : latentException([] {}) {}
224 std::function<void()> latentException;
225 void CallMissing(Call &call, MockRepository &repo)
override 267 latentException = [] {};
271 if (!std::uncaught_exception() && latentException)
277 return &defaultReporter;
NotImplementedException(MockRepository &repo)
virtual void InvalidBaseOffset(size_t baseOffset, MockRepository &repo)=0
virtual void CallMissing(Call &call, MockRepository &repo)=0
virtual void UnknownFunction(MockRepository &repo)=0
ExpectationException(MockRepository &repo, const std::string &args, const char *funcName)
constexpr const auto size
NoResultSetUpException(MockRepository &repo, const std::string &args, const char *funcName)
CallMissingException(MockRepository &repo)
constexpr const auto string
virtual void FunctionCallToZombie(MockRepository &repo, const std::string &args)=0
Reporter * GetDefaultReporter()
virtual void NoResultSetUp(Call &call, MockRepository &repo, const std::string &args, const char *funcName)=0
std::ostream & operator<<(std::ostream &os, const Call &call)
#define RAISEEXCEPTION(e)
ZombieMockException(MockRepository &repo)
virtual void TestFinished()=0
const char * what() const
virtual void NoExpectationMatches(MockRepository &repo, const std::string &args, const char *funcName)=0
virtual void TestStarted()=0
virtual void ExpectationExceeded(Call &call, MockRepository &repo, const std::string &args, const char *funcName)=0
virtual void InvalidFuncIndex(size_t funcIndex, MockRepository &repo)=0