added tests
This commit is contained in:
68
FlippR-Driver/tests/input/TestDetector.cpp
Normal file
68
FlippR-Driver/tests/input/TestDetector.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* TestDetector.cpp
|
||||
*
|
||||
* Created on: Jun 27, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
|
||||
|
||||
#include "../catch.hpp"
|
||||
#include "../fakeit.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
#define private public
|
||||
|
||||
#include "../../../src/input/IEventNotifier.h"
|
||||
#include "../../../src/input/Event.h"
|
||||
#include "../../../src/input/Detector.h"
|
||||
#include "../../../src/utilities/LoggerFactory.hpp"
|
||||
#include "../../../src/utilities/InputGPIOInterface.h"
|
||||
|
||||
|
||||
using namespace fakeit;
|
||||
using namespace Input;
|
||||
|
||||
SCENARIO("Creating a Detector object", "")
|
||||
{
|
||||
GIVEN("An IEventNofifier, two Events and an IInputGPIOInterface")
|
||||
{
|
||||
LoggerFactory::CreateInputLogger();
|
||||
|
||||
Mock<IEventNotifier> event_notifier_mock;
|
||||
Mock<IInputGPIOInterface> gpio_interface_mock;
|
||||
|
||||
Fake(Dtor(gpio_interface_mock));
|
||||
When(Method(gpio_interface_mock, read_input_data).Using(2)).Return(true);
|
||||
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||
|
||||
Event event1(1, '1', "event 1");
|
||||
Event event2(2, '2', "event 2");
|
||||
|
||||
std::map<char, Event> events;
|
||||
|
||||
events.insert(std::make_pair(1, event1));
|
||||
events.insert(std::make_pair(2, event2));
|
||||
|
||||
WHEN("Detector is created")
|
||||
{
|
||||
Detector detector(&gpio_interface_mock.get(), events, &event_notifier_mock.get());
|
||||
THEN("a thread should be created")
|
||||
{
|
||||
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
|
||||
}
|
||||
|
||||
AND_WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
THEN("only the fitting event should be distributed the event notifier")
|
||||
{
|
||||
// REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user