chore(style): clean up line endings in event tests

This commit is contained in:
fallenoak 2025-11-20 21:24:16 -06:00
parent d98b5dc45b
commit 85590192d4
3 changed files with 708 additions and 713 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,29 +1,28 @@
#include "EventTest.hpp" #include "EventTest.hpp"
std::deque<EventHandlerCalledWith> EventHandlerCallResults; std::deque<EventHandlerCalledWith> EventHandlerCallResults;
void STORMAPI TestEventHandler1(void* data) {
void STORMAPI TestEventHandler1(void* data) { EventHandlerTest::RegisterCall(1, data);
EventHandlerTest::RegisterCall(1, data); }
}
void STORMAPI TestEventHandler2(void* data) {
void STORMAPI TestEventHandler2(void* data) { EventHandlerTest::RegisterCall(2, data);
EventHandlerTest::RegisterCall(2, data); }
}
void STORMAPI TestEventHandler3(void* data) {
void STORMAPI TestEventHandler3(void* data) { EventHandlerTest::RegisterCall(3, data);
EventHandlerTest::RegisterCall(3, data); }
}
void STORMAPI TestEventHandler4(void* data) {
void STORMAPI TestEventHandler4(void* data) { EventHandlerTest::RegisterCall(4, data);
EventHandlerTest::RegisterCall(4, data); }
}
std::ostream& operator <<(std::ostream& os, EventHandlerCalledWith const& value) {
std::ostream& operator <<(std::ostream& os, EventHandlerCalledWith const& value) { os << "{ TestEventHandler" << value.handler << ", " << value.data << " }";
os << "{ TestEventHandler" << value.handler << ", " << value.data << " }"; return os;
return os; }
}
EventHandlerCalledWithMatcher<EventHandlerCalledWith> MatchesCall(EventHandlerCalledWith arg) {
EventHandlerCalledWithMatcher<EventHandlerCalledWith> MatchesCall(EventHandlerCalledWith arg) { return { arg };
return { arg }; }
}

View file

@ -1,71 +1,68 @@
#include "test/Test.hpp" #include "test/Test.hpp"
#include "storm/Core.hpp" #include "storm/Core.hpp"
#include "storm/Event.hpp" #include "storm/Event.hpp"
#include <deque> #include <deque>
#include <sstream> #include <sstream>
struct EventHandlerCalledWith {
struct EventHandlerCalledWith { int handler;
int handler; void* data;
void* data; };
};
extern std::deque<EventHandlerCalledWith> EventHandlerCallResults;
extern std::deque<EventHandlerCalledWith> EventHandlerCallResults;
struct EventHandlerTest {
struct EventHandlerTest { EventHandlerTest() {
EventHandlerTest() { EventHandlerCallResults.clear();
EventHandlerCallResults.clear(); StormDestroy();
StormDestroy(); }
}
static void RegisterCall(int handler, void* data) {
static void RegisterCall(int handler, void* data) { EventHandlerCalledWith calledWith = {handler, data};
EventHandlerCalledWith calledWith = {handler, data}; EventHandlerCallResults.push_back(calledWith);
EventHandlerCallResults.push_back(calledWith); }
}
static size_t NumCalls() {
static size_t NumCalls() { return EventHandlerCallResults.size();
return EventHandlerCallResults.size(); }
}
static EventHandlerCalledWith CallResult() {
static EventHandlerCalledWith CallResult() { if (EventHandlerCallResults.empty()) {
if (EventHandlerCallResults.empty()) { return {-1, nullptr};
return {-1, nullptr}; }
}
EventHandlerCalledWith result = EventHandlerCallResults.front();
EventHandlerCalledWith result = EventHandlerCallResults.front(); EventHandlerCallResults.pop_front();
EventHandlerCallResults.pop_front(); return result;
return result; }
} };
};
void STORMAPI TestEventHandler1(void* data);
void STORMAPI TestEventHandler2(void* data);
void STORMAPI TestEventHandler1(void* data); void STORMAPI TestEventHandler3(void* data);
void STORMAPI TestEventHandler2(void* data); void STORMAPI TestEventHandler4(void* data);
void STORMAPI TestEventHandler3(void* data);
void STORMAPI TestEventHandler4(void* data); // Helpers for comparing EventHandlerCalledWith structs
std::ostream& operator <<(std::ostream& os, EventHandlerCalledWith const& value);
// Helpers for comparing EventHandlerCalledWith structs template <class T>
std::ostream& operator <<(std::ostream& os, EventHandlerCalledWith const& value); class EventHandlerCalledWithMatcher : public Catch::MatcherBase<T> {
private:
template <class T> T cmp;
class EventHandlerCalledWithMatcher : public Catch::MatcherBase<T> {
private: public:
T cmp; EventHandlerCalledWithMatcher(T arg) : cmp(arg) {}
public: bool match(T const& in) const override {
EventHandlerCalledWithMatcher(T arg) : cmp(arg) {} return cmp.handler == in.handler && cmp.data == in.data;
}
bool match(T const& in) const override {
return cmp.handler == in.handler && cmp.data == in.data; std::string describe() const override {
} std::ostringstream ss;
ss << "equals " << cmp;
std::string describe() const override { return ss.str();
std::ostringstream ss; }
ss << "equals " << cmp; };
return ss.str();
} EventHandlerCalledWithMatcher<EventHandlerCalledWith> MatchesCall(EventHandlerCalledWith arg);
};
EventHandlerCalledWithMatcher<EventHandlerCalledWith> MatchesCall(EventHandlerCalledWith arg);