added some detector tests
This commit is contained in:
@@ -25,9 +25,37 @@
|
||||
using namespace fakeit;
|
||||
using namespace Input;
|
||||
|
||||
|
||||
SCENARIO("Creating a Detector object", "")
|
||||
{
|
||||
return;
|
||||
GIVEN("An IEventNofifier, 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)).AlwaysReturn(false);
|
||||
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||
|
||||
std::map<char, Event> events;
|
||||
|
||||
WHEN("Detector is created")
|
||||
{
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
|
||||
THEN("a thread should be created")
|
||||
{
|
||||
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("There are events at the input", "")
|
||||
{
|
||||
GIVEN("An IEventNofifier, three Events and an IInputGPIOInterface")
|
||||
{
|
||||
LoggerFactory::CreateInputLogger();
|
||||
@@ -51,21 +79,54 @@ SCENARIO("Creating a Detector object", "")
|
||||
events.insert(std::make_pair(2, event2));
|
||||
events.insert(std::make_pair(3, event3));
|
||||
|
||||
WHEN("Detector is created")
|
||||
WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
|
||||
THEN("a thread should be created")
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
THEN("the event should be distributed")
|
||||
{
|
||||
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
detector.is_running = false;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("There are events at the input but no suitable event in map", "")
|
||||
{
|
||||
GIVEN("An IEventNofifier, three 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)).AlwaysDo([](char c){return c==4;});
|
||||
|
||||
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");
|
||||
Event event3(3, '3', "event 3");
|
||||
|
||||
std::map<char, Event> events;
|
||||
|
||||
events.insert(std::make_pair(1, event1));
|
||||
events.insert(std::make_pair(2, event2));
|
||||
events.insert(std::make_pair(3, event3));
|
||||
|
||||
WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
THEN("the event should be distributed")
|
||||
{
|
||||
detector.is_running = false;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
REQUIRE_FALSE((bool)Verify(Method(event_notifier_mock, distribute_event)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user