From b3bb0e543f666f31c1021efe063d477e3d29243f Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Fri, 11 Dec 2015 16:17:23 +0100 Subject: [PATCH] Added EventBroker Test from the other project --- include/Engine/Core/InputController.h | 3 +- src/Engine/Core/EventBroker.cpp | 2 +- src/Tests/EventFixture.h | 54 +++++++++++++++++++++++++++ src/Tests/EventTest.cpp | 19 ++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/Tests/EventFixture.h create mode 100644 src/Tests/EventTest.cpp diff --git a/include/Engine/Core/InputController.h b/include/Engine/Core/InputController.h index b91fb448..919d0e6e 100644 --- a/include/Engine/Core/InputController.h +++ b/include/Engine/Core/InputController.h @@ -17,7 +17,8 @@ public: virtual void Initialize() { - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::OnCommand); + EVENT_SUBSCRIBE_MEMBER( + _EInputCommand, &InputController::OnCommand); EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::OnMouseMove); } diff --git a/src/Engine/Core/EventBroker.cpp b/src/Engine/Core/EventBroker.cpp index 76c243e8..c12f915f 100644 --- a/src/Engine/Core/EventBroker.cpp +++ b/src/Engine/Core/EventBroker.cpp @@ -1,4 +1,4 @@ -#include "Core/EventBroker.h" +#include "Core\EventBroker.h" BaseEventRelay::~BaseEventRelay() { diff --git a/src/Tests/EventFixture.h b/src/Tests/EventFixture.h new file mode 100644 index 00000000..42258932 --- /dev/null +++ b/src/Tests/EventFixture.h @@ -0,0 +1,54 @@ +#ifndef EVENTFIXTURE_H +#define EVENTFIXTURE_H + +#include +#include "Core\EventBroker.h" + +template +struct EventFixture +{ + EventFixture() + { + this->ventBroker = new EventBroker(); + m_EEventType = decltype(m_EEventType)(std::bind(&EventFixture::OnEvent, this, std::placeholders::_1)); + this->ventBroker->Subscribe(m_EEventType); + Run(); + Check(); + } + ~EventFixture() + { + this->ventBroker->Unsubscribe(m_EEventType); + delete this->ventBroker; + } + + EventBroker* ventBroker = nullptr; + EventRelay m_EEventType; + bool m_EventRecieved = false; + EventType Before; + EventType After; + + bool OnEvent(const EventType& event) + { + m_EventRecieved = true; + After = event; + + return true; + } + + void Run() + { + // Publish the event + this->ventBroker->Publish(Before); + // Clear to swap buffers + this->ventBroker->Swap(); + // Process the event + this->ventBroker->template Process(); + } + + void Check() + { + BOOST_CHECK(m_EventRecieved); + } +}; + +#endif \ No newline at end of file diff --git a/src/Tests/EventTest.cpp b/src/Tests/EventTest.cpp new file mode 100644 index 00000000..4a030055 --- /dev/null +++ b/src/Tests/EventTest.cpp @@ -0,0 +1,19 @@ +#include +#include "EventFixture.h" + +struct ETestEvent : public Event +{ + int Int = 5; + float Float = 1.33333f; + double Double = 1.33333; + std::string String = "Hello World"; +}; + +BOOST_AUTO_TEST_CASE(EventBrokerTest) +{ + EventFixture f; + BOOST_CHECK(f.Before.Int == f.After.Int); + BOOST_CHECK_CLOSE(f.Before.Float, f.After.Float, 0.00001f); + BOOST_CHECK_CLOSE(f.Before.Double, f.After.Double, 0.00001f); + BOOST_CHECK(f.Before.String == f.After.String); +} \ No newline at end of file