fixed some bug

This commit is contained in:
Jonas Zeunert
2018-07-10 20:30:39 +02:00
parent e55d15da24
commit c9e3b9e0c3
4 changed files with 137 additions and 12 deletions

View File

@@ -9,6 +9,111 @@
#include "../catch.hpp"
#include "../fakeit.hpp"
#include "../../src/utilities/LoggerFactory.hpp"
#include "../../src/utilities/IEventHandler.h"
// testing purposes
#define private public
#include "../../src/input/EventNotifier.h"
using namespace Input;
using namespace fakeit;
SCENARIO("An EventNotifier gets created", "[construction]")
{
LoggerFactory::CreateInputLogger();
WHEN("The EventNotifier gets created")
{
EventNotifier notifier;
THEN("It sets the running variable to true")
{
REQUIRE(notifier.is_running);
}
THEN("It creates a notify thread")
{
//REQUIRE(typeid(notifier.notify_thread).hash_code() == typeid(std::thread).hash_code());
}
}
}
SCENARIO("An EventHandler gets [un]registered at the notifier", "[un-register notifier]")
{
GIVEN("An EventHandler")
{
LoggerFactory::CreateInputLogger();
Mock<IEventHandler> event_handler_mock;
Fake(Method(event_handler_mock, handle));
Fake(Dtor(event_handler_mock));
EventNotifier notifier;
WHEN("The EventHandler gets registered at the eventNotifier")
{
notifier.register_event_handler(&event_handler_mock.get());
THEN("The EventHandler gets saved")
{
REQUIRE(*(notifier.event_handler.find(&event_handler_mock.get())) == &event_handler_mock.get());
}
}
WHEN("The EventHandler gets unregistered at the driver")
{
REQUIRE(!notifier.event_handler.empty());
notifier.unregister_event_handler(&event_handler_mock.get());
THEN("The unregister_event_handler at the event_notifier gets called")
{
REQUIRE(notifier.event_handler.empty());
}
}
}
}
SCENARIO("An event should be distributed", "[distribute]")
{
GIVEN("An event")
{
Event event(0, 0, "test");
EventNotifier notifier;
WHEN("The event comes in")
{
notifier.distribute_event(event);
THEN("The event gets queued")
{
REQUIRE(!notifier.event_queue.p_queue.empty());
}
}
}
}
SCENARIO("The EventHandler gets notified")
{
GIVEN("An Event and an EventHandler")
{
Event event(0, 0, "test");
Mock<IEventHandler> event_handler_mock;
Fake(Method(event_handler_mock, handle));
Fake(Dtor(event_handler_mock));
EventNotifier notifier;
WHEN("The event gets queued")
{
notifier.event_queue.push(event);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
THEN("The EventHandler gets called")
{
REQUIRE((bool) Verify(Method(event_handler_mock, handle)));
}
}
}
}