Tests for EventBroker

This commit is contained in:
2015-09-16 12:59:50 +02:00
parent 4cfa0ef624
commit 9396f9391f
3 changed files with 76 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ include_directories(
set(SOURCE_FILES
main.cpp
FileWatcherTest.cpp
EventTest.cpp
ComponentCopyTest.cpp
)
+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->EventBroker = new dd::EventBroker();
m_EEventType = decltype(m_EEventType)(std::bind(&OnEvent, this, std::placeholders::_1));
this->EventBroker->Subscribe(m_EEventType);
Run();
Check();
}
~EventFixture()
{
this->EventBroker->Unsubscribe(m_EEventType);
delete this->EventBroker;
}
dd::EventBroker* EventBroker = nullptr;
dd::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->EventBroker->Publish(Before);
// Clear to swap buffers
this->EventBroker->Clear();
// Process the event
this->EventBroker->template Process<EventFixture>();
}
void Check()
{
BOOST_CHECK(m_EventRecieved);
}
};
#endif
+21
View File
@@ -0,0 +1,21 @@
#include <boost/test/unit_test.hpp>
#include "EventFixture.h"
using namespace dd;
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);
}