mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
45 lines
869 B
C++
45 lines
869 B
C++
//
|
|
// Created by Stepan Usatiuk on 26.07.2025.
|
|
//
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "Event.hpp"
|
|
|
|
struct EventOne : public Event {
|
|
std::string name;
|
|
};
|
|
|
|
struct EventTwo : public Event {
|
|
int value;
|
|
};
|
|
|
|
template<typename Derived>
|
|
using TestEventHandler = EventHandler<Derived, EventOne, EventTwo>;
|
|
|
|
class EventHandlerTest : public TestEventHandler<EventHandlerTest> {
|
|
public:
|
|
template<typename T>
|
|
void handle(const T& event) {
|
|
seen_unknown = true;
|
|
}
|
|
|
|
void handle(const EventOne& event) {
|
|
seen_event_one = true;
|
|
}
|
|
|
|
bool seen_event_one = false;
|
|
bool seen_unknown = false;
|
|
};
|
|
|
|
TEST(Event, Basic) {
|
|
EventHandlerTest handler;
|
|
EventOne event_one;
|
|
EventTwo event_two;
|
|
handler.handle(event_one);
|
|
ASSERT_TRUE(handler.seen_event_one);
|
|
handler.handle(event_two);
|
|
ASSERT_TRUE(handler.seen_unknown);
|
|
}
|