Merge remote-tracking branch 'origin/master' into GLrenderer

This commit is contained in:
tleety
2015-09-16 16:17:39 +02:00
6 changed files with 124 additions and 9 deletions
-9
View File
@@ -121,8 +121,6 @@ public:
int Process(std::string contextTypeName);
void Clear();
void Unsubscribe(BaseEventRelay &relay);
template <typename ContextType>
void UnsubscribeAll();
private:
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
@@ -156,13 +154,6 @@ int EventBroker::Process()
return Process(contextTypeName);
}
template <typename ContextType>
void EventBroker::UnsubscribeAll()
{
const std::string contextTypeName = typeid(ContextType).name();
m_ContextRelays.erase(contextTypeName);
}
}
#endif // MessageRelay_h__
+1
View File
@@ -40,6 +40,7 @@ void dd::EventBroker::Unsubscribe(BaseEventRelay &relay) // ?
{
if (it->second == &relay)
{
relay.m_Broker = nullptr;
eventRelays.erase(it);
break;
}
+2
View File
@@ -10,7 +10,9 @@ include_directories(
set(SOURCE_FILES
main.cpp
FileWatcherTest.cpp
EventTest.cpp
ComponentCopyTest.cpp
EntityCloneTest.cpp
)
if(CMAKE_COMPILER_IS_GNUCXX)
+46
View File
@@ -0,0 +1,46 @@
#include <boost/test/unit_test.hpp>
#include "Core/EventBroker.h"
#include "Core/World.h"
#include "Core/CTemplate.h"
using namespace dd;
struct TestComponent : public Component
{
int Int = 5;
float Float = 1.33333f;
double Double = 1.33333;
std::string String = "Hello World";
};
BOOST_AUTO_TEST_CASE(EntityCloneTest)
{
// Setup world
std::shared_ptr<EventBroker> eventBroker = std::make_shared<EventBroker>();
World world(eventBroker);
world.ComponentFactory.Register<Components::Template>();
world.ComponentFactory.Register<TestComponent>();
// Create our original entity
EntityID entOriginal = world.CreateEntity();
world.AddComponent<Components::Template>(entOriginal);
world.AddComponent<TestComponent>(entOriginal);
// Clone it
EntityID entClone = world.CloneEntity(entOriginal);
// Check
// EntityID of clone should not be same as original (obviously)
BOOST_CHECK(entOriginal != entClone);
// Template component SHOULD be in clone
auto templateComponentClone = world.GetComponent<Components::Template>(entClone);
BOOST_REQUIRE(templateComponentClone != nullptr);
// Values should be the same across the clone
auto testComponentOriginal = world.GetComponent<TestComponent>(entOriginal);
BOOST_REQUIRE(testComponentOriginal != nullptr);
auto testComponentClone = world.GetComponent<TestComponent>(entClone);
BOOST_REQUIRE(testComponentClone != nullptr);
BOOST_CHECK(testComponentClone->Int == testComponentOriginal->Int);
BOOST_CHECK(testComponentClone->Float == testComponentOriginal->Float);
BOOST_CHECK(testComponentClone->Double == testComponentOriginal->Double);
BOOST_CHECK(testComponentClone->String == testComponentOriginal->String);
}
+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);
}