finished Detector tests
This commit is contained in:
@@ -12,14 +12,15 @@
|
|||||||
|
|
||||||
#include "../utilities/config.h"
|
#include "../utilities/config.h"
|
||||||
|
|
||||||
using namespace Input;
|
namespace Input
|
||||||
|
{
|
||||||
|
|
||||||
Detector::Detector(IInputGPIOInterface* input_gpio_interface, std::map<char, Event> events, IEventNotifier* event_notifier) :
|
Detector::Detector(IInputGPIOInterface* input_gpio_interface, std::map<char, Event> events, IEventNotifier* event_notifier) :
|
||||||
input_gpio_interface(input_gpio_interface), events(events), is_running(true), event_notifier(event_notifier)
|
input_gpio_interface(input_gpio_interface), events(events), is_running(true), event_notifier(event_notifier)
|
||||||
{
|
{
|
||||||
this->detect_thread = std::thread(&Detector::detect, this);
|
this->detect_thread = std::thread(&Detector::detect, this);
|
||||||
|
|
||||||
CLOG(WARNING, INPUT_LOGGER) << "Created Detector";
|
CLOG(INFO, INPUT_LOGGER) << "Created Detector";
|
||||||
}
|
}
|
||||||
|
|
||||||
Detector::~Detector()
|
Detector::~Detector()
|
||||||
@@ -68,3 +69,7 @@ bool Detector::check_inputs(char& address)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
using namespace Input;
|
namespace Input
|
||||||
|
{
|
||||||
|
|
||||||
Event::Event(char address, int priority, std::string name) :
|
Event::Event(char address, int priority, std::string name) :
|
||||||
address(address), priority(priority), name(name)
|
address(address), priority(priority), name(name)
|
||||||
@@ -14,7 +15,9 @@ Event::Event(char address, int priority, std::string name) :
|
|||||||
CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Event::operator==(const Event& other)
|
bool operator==(const Event& left, const Event& right)
|
||||||
{
|
{
|
||||||
return this->name == other.name;
|
return left.name == right.name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ class Event
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Event(char address, int priority, std::string name);
|
Event(char address, int priority, std::string name);
|
||||||
bool operator==(const Event& other);
|
|
||||||
|
friend bool operator==(const Event& left, const Event& right);
|
||||||
friend bool operator<(const Event& left, const Event& right)
|
friend bool operator<(const Event& left, const Event& right)
|
||||||
{
|
{
|
||||||
return left.priority < right.priority;
|
return left.priority < right.priority;
|
||||||
@@ -32,10 +33,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
int priority;
|
int priority;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool operator==(const Event& left, const Event& right);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,18 +35,20 @@ SCENARIO("Creating a Detector object", "")
|
|||||||
Mock<IInputGPIOInterface> gpio_interface_mock;
|
Mock<IInputGPIOInterface> gpio_interface_mock;
|
||||||
|
|
||||||
Fake(Dtor(gpio_interface_mock));
|
Fake(Dtor(gpio_interface_mock));
|
||||||
When(Method(gpio_interface_mock, read_input_data).Using('2')).Return(true);
|
When(Method(gpio_interface_mock, read_input_data)).AlwaysDo([](char c){return c==2;});
|
||||||
|
|
||||||
Fake(Dtor(event_notifier_mock));
|
Fake(Dtor(event_notifier_mock));
|
||||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||||
|
|
||||||
Event event1(1, '1', "event 1");
|
Event event1(1, '1', "event 1");
|
||||||
Event event2(2, '2', "event 2");
|
Event event2(2, '2', "event 2");
|
||||||
|
Event event3(3, '3', "event 3");
|
||||||
|
|
||||||
std::map<char, Event> events;
|
std::map<char, Event> events;
|
||||||
|
|
||||||
events.insert(std::make_pair(1, event1));
|
events.insert(std::make_pair(1, event1));
|
||||||
events.insert(std::make_pair(2, event2));
|
events.insert(std::make_pair(2, event2));
|
||||||
|
events.insert(std::make_pair(3, event3));
|
||||||
|
|
||||||
WHEN("Detector is created")
|
WHEN("Detector is created")
|
||||||
{
|
{
|
||||||
@@ -58,9 +60,9 @@ SCENARIO("Creating a Detector object", "")
|
|||||||
|
|
||||||
AND_WHEN("an event can be found at gpio interface")
|
AND_WHEN("an event can be found at gpio interface")
|
||||||
{
|
{
|
||||||
THEN("only the fitting event should be distributed the event notifier")
|
THEN("only the fitting event should be distributed by event notifier")
|
||||||
{
|
{
|
||||||
// REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
|
REQUIRE((bool)Verify(Method(event_notifier_mock, distribute_event).Using(event2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user