adapted tests

This commit is contained in:
Neeflix
2018-07-11 16:54:33 +02:00
parent 3e08697607
commit a52f67de01
5 changed files with 63 additions and 64 deletions

View File

@@ -27,6 +27,7 @@ using namespace Input;
SCENARIO("Creating a Detector object", "")
{
return;
GIVEN("An IEventNofifier, three Events and an IInputGPIOInterface")
{
LoggerFactory::CreateInputLogger();
@@ -60,11 +61,11 @@ SCENARIO("Creating a Detector object", "")
AND_WHEN("an event can be found at gpio interface")
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
THEN("after some time the only the fitting event should be distributed by event notifier")
{
REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
THEN("after some time the only the fitting event should be distributed by event notifier")
{
REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
}
}
}
}

View File

@@ -8,8 +8,11 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.hpp"
#include "utilities/IEventHandler.h"
#include "utilities/IBlockingQueue.h"
// testing purposes
@@ -56,19 +59,18 @@ SCENARIO("An EventHandler gets [un]registered at the notifier", "[un-register no
THEN("The EventHandler gets saved")
{
REQUIRE(*(notifier.event_handler.find(&event_handler_mock.get())) == &event_handler_mock.get());
REQUIRE(*(notifier.event_handlers.find(&event_handler_mock.get())) == &event_handler_mock.get());
REQUIRE_FALSE(notifier.event_handlers.empty() );
}
}
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());
REQUIRE(notifier.event_handlers.empty());
}
}
}
@@ -80,13 +82,20 @@ SCENARIO("An event should be distributed", "[distribute]")
{
Event event(0, 0, "test");
Mock<IBlockingQueue<Event>> queue_mock;
When(Method(queue_mock, push)).AlwaysReturn();
Fake(Dtor(queue_mock));
EventNotifier notifier;
notifier.event_queue = &(queue_mock.get());
WHEN("The event comes in")
{
notifier.distribute_event(event);
THEN("The event gets queued")
{
REQUIRE(!notifier.event_queue.p_queue.empty());
REQUIRE((bool)Verify(Method(queue_mock, push).Using(event)));
}
}
}
@@ -99,20 +108,25 @@ SCENARIO("The EventHandler gets notified")
Event event(0, 0, "test");
Mock<IEventHandler> event_handler_mock;
Fake(Method(event_handler_mock, handle));
When(Method(event_handler_mock, handle)).AlwaysReturn();
Fake(Dtor(event_handler_mock));
Event test_event(0, 0, "test");
Mock<IBlockingQueue<Event>> queue_mock;
When(Method(queue_mock, pop)).AlwaysDo([test_event](void){return test_event;});
Fake(Dtor(queue_mock));
EventNotifier notifier;
notifier.event_queue = &(queue_mock.get());
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)));
REQUIRE((bool) Verify(Method(event_handler_mock, handle).Using(test_event)));
}
}
}