Added EventBroker Test from the other project

This commit is contained in:
verysecrethero
2015-12-11 16:17:23 +01:00
parent d8b1f4e514
commit b3bb0e543f
4 changed files with 76 additions and 2 deletions
+2 -1
View File
@@ -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);
}
+1 -1
View File
@@ -1,4 +1,4 @@
#include "Core/EventBroker.h"
#include "Core\EventBroker.h"
BaseEventRelay::~BaseEventRelay()
{
+54
View File
@@ -0,0 +1,54 @@
#ifndef EVENTFIXTURE_H
#define EVENTFIXTURE_H
#include <boost/test/unit_test.hpp>
#include "Core\EventBroker.h"
template <typename EventType>
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<EventFixture, EventType> 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<EventFixture>();
}
void Check()
{
BOOST_CHECK(m_EventRecieved);
}
};
#endif
+19
View File
@@ -0,0 +1,19 @@
#include <boost/test/unit_test.hpp>
#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<ETestEvent> 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);
}