diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1eb1e61..a66c299 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,6 +3,7 @@ SET(CLI_TESTS test_color test_color_constexpr test_error + test_eventhandler test_optional test_pointrect test_pointrect_constexpr diff --git a/tests/test_eventhandler.cc b/tests/test_eventhandler.cc new file mode 100644 index 0000000..b76893f --- /dev/null +++ b/tests/test_eventhandler.cc @@ -0,0 +1,69 @@ +#include + +#include + +using namespace SDL2pp::Private; + +void EventHandlerFunction(const SDL_Event &); + +struct EventHandlerOperator { + void operator()(SDL_Event); +}; + +struct EventHandler { + void HandleEvent(const SDL_Event &); +}; + +struct InvalidEventHandler { + void HandleEvent(SDL_Event); +}; + +int main(int, char*[]) { + auto lambda = [](const SDL_Event &) { }; + + // Test IsEventHandlerFunctor + static_assert( + IsEventHandlerFunctor::value, + "IsEventHandlerFunctor<> should accept functions like void(const SDL_Event &)" + ); + static_assert( + IsEventHandlerFunctor::value, + "IsEventHandlerFunctor<> should accept functions like void(const SDL_Event &)" + ); + static_assert( + !IsEventHandlerFunctor::value, + "IsEventHandlerFunctor<> shouldn't accept a class with operator(const SDL_Event &)" + ); + + // Test IsEventHandlerObject + static_assert( + IsEventHandlerObject::value, + "IsEventHandlerObject<> should accept a class with HandleEvent(const SDL_Event &)" + ); + static_assert( + !IsEventHandlerObject::value, + "IsEventHandlerObject<> shouldn't accept a class with a different HandleEvent() signature" + ); + + // Test IsEventHandler + static_assert( + IsEventHandler::value, + "IsEventHandler<> should accept functions like void(const SDL_Event &)" + ); + static_assert( + IsEventHandler::value, + "IsEventHandler<> should accept functions like void(const SDL_Event &)" + ); + static_assert( + IsEventHandler::value, + "IsEventHandler<> should accept a class with HandleEvent(const SDL_Event &)" + ); + static_assert( + !IsEventHandler::value, + "IsEventHandler<> shouldn't accept a class with operator(const SDL_Event &)" + ); + static_assert( + !IsEventHandler::value, + "IsEventHandler<> shouldn't accept a class with a different HandleEvent() signature" + ); +}