finished Detector tests

This commit is contained in:
Neeflix
2018-06-28 19:03:17 +02:00
parent 54a0e0a5b8
commit bce5b12738
4 changed files with 22 additions and 11 deletions

View File

@@ -12,14 +12,15 @@
#include "../utilities/config.h"
using namespace Input;
namespace Input
{
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)
{
this->detect_thread = std::thread(&Detector::detect, this);
CLOG(WARNING, INPUT_LOGGER) << "Created Detector";
CLOG(INFO, INPUT_LOGGER) << "Created Detector";
}
Detector::~Detector()
@@ -68,3 +69,7 @@ bool Detector::check_inputs(char& address)
}
return false;
}
}

View File

@@ -6,7 +6,8 @@
*/
#include "Event.h"
using namespace Input;
namespace Input
{
Event::Event(char address, int priority, std::string 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;
}
bool Event::operator==(const Event& other)
bool operator==(const Event& left, const Event& right)
{
return this->name == other.name;
return left.name == right.name;
}
}

View File

@@ -20,7 +20,8 @@ class Event
{
public:
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)
{
return left.priority < right.priority;
@@ -32,10 +33,10 @@ private:
public:
int priority;
std::string name;
};
bool operator==(const Event& left, const Event& right);
}

View File

@@ -35,18 +35,20 @@ SCENARIO("Creating a Detector object", "")
Mock<IInputGPIOInterface> 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));
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("Detector is created")
{
@@ -58,9 +60,9 @@ SCENARIO("Creating a Detector object", "")
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)));
}
}
}