Tests for EventBroker
This commit is contained in:
@@ -10,6 +10,7 @@ include_directories(
|
|||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
main.cpp
|
main.cpp
|
||||||
FileWatcherTest.cpp
|
FileWatcherTest.cpp
|
||||||
|
EventTest.cpp
|
||||||
ComponentCopyTest.cpp
|
ComponentCopyTest.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user