wrote display stuff and refactored thousend things

This commit is contained in:
Johannes Wendel
2018-11-08 00:42:31 +01:00
parent b94fb345c1
commit 8e4b7391b0
35 changed files with 203 additions and 119 deletions

View File

@@ -18,13 +18,14 @@
#include "input/IEventNotifier.h"
#include "input/DistributingEvent.h"
#include "input/Detector.h"
#include "utilities/LoggerFactory.h"
#include "utilities/InputGPIOInterface.h"
#include "utility/LoggerFactory.h"
#include "utility/InputGPIOInterface.h"
using namespace fakeit;
using namespace FlippR_Driver;
using namespace Input;
using namespace utility;
SCENARIO("Creating a Detector object", "")
@@ -42,11 +43,11 @@ SCENARIO("Creating a Detector object", "")
Fake(Dtor(event_notifier_mock));
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
std::map<char, std::shared_ptr<DistributingEvent>> events;
std::vector<std::shared_ptr<DistributingEvent>> events;
WHEN("Detector is created")
{
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events);
THEN("a thread should be created")
{
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
@@ -75,16 +76,16 @@ SCENARIO("There are events at the input", "")
DistributingEvent event2(2, '2', "event 2", std::chrono::milliseconds(0), event_notifier);
DistributingEvent event3(3, '3', "event 3", std::chrono::milliseconds(0), event_notifier);
std::map<char, std::shared_ptr<DistributingEvent>> events;
std::vector<std::shared_ptr<DistributingEvent>> events;
auto event2ptr = std::make_shared<DistributingEvent>(event2);
events.insert(std::make_pair(1, std::make_shared<DistributingEvent>(event1)));
events.insert(std::make_pair(2, event2ptr));
events.insert(std::make_pair(3, std::make_shared<DistributingEvent>(event3)));
events.push_back(std::make_shared<DistributingEvent>(event1));
events.push_back(event2ptr);
events.push_back(std::make_shared<DistributingEvent>(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()));
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
THEN("the event should be distributed")
{
@@ -116,15 +117,15 @@ SCENARIO("There are events at the input but no suitable event in map", "")
DistributingEvent event2(2, '2', "event 2", std::chrono::milliseconds(0), event_notifier);
DistributingEvent event3(3, '3', "event 3", std::chrono::milliseconds(0), event_notifier);
std::map<char, std::shared_ptr<DistributingEvent>> events;
std::vector<std::shared_ptr<DistributingEvent>> events;
events.insert(std::make_pair(1, std::make_shared<DistributingEvent>(event1)));
events.insert(std::make_pair(2, std::make_shared<DistributingEvent>(event2)));
events.insert(std::make_pair(3, std::make_shared<DistributingEvent>(event3)));
events.push_back(std::make_shared<DistributingEvent>(event1));
events.push_back(std::make_shared<DistributingEvent>(event2));
events.push_back(std::make_shared<DistributingEvent>(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()));
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
THEN("the event should be distributed")
{

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
#include "EventHandler.h"
#include "IInputDriver.h"
@@ -18,6 +18,7 @@
using namespace fakeit;
using namespace FlippR_Driver::utility;
SCENARIO("An EventHandler gets created", "[construction}")
{

View File

@@ -10,9 +10,9 @@
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
#include "IEventHandler.h"
#include "utilities/IBlockingQueue.h"
#include "utility/IBlockingQueue.h"
// testing purposes
@@ -23,6 +23,7 @@
using namespace FlippR_Driver;
using namespace Input;
using namespace fakeit;
using namespace utility;
SCENARIO("An EventNotifier gets created", "[construction]")
{

View File

@@ -7,7 +7,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
#define private public
@@ -21,6 +21,7 @@
using namespace fakeit;
using namespace FlippR_Driver;
using namespace Input;
using namespace utility;
SCENARIO("An InputDriver gets created", "[construction}")
{

View File

@@ -11,7 +11,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -19,7 +19,7 @@
#include "output/CabinetItem.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")

View File

@@ -11,7 +11,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -19,11 +19,47 @@
#include "output/Display.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")
SCENARIO("Creating a Display object", "")
{
GIVEN("Just a Display with 7 digits")
{
Display<7> display(5,5);
WHEN("A content is set for the display")
{
std::string content_string = "1234567";
std::array<char,7> content;
std::copy(content_string.begin(), content_string.end(), content.data());
display.write_content(content);
THEN("This content should be set for the display")
{
REQUIRE(content == display.content);
}
}
WHEN("A score (12345) within the size of the display is written")
{
display.write_score(12345);
THEN("The content should look like: \" 12345\" ")
{
std::string content_string = " 12345";
std::array<char,7> content;
std::copy(content_string.begin(), content_string.end(), content.data());
REQUIRE(display.content == content);
}
}
WHEN("A score (12345678), which is longer than the digit is written")
display.write_score(12345678);
THEN("The content should look like: \"2345678\" ")
{
std::string content_string = "2345678";
std::array<char,7> content;
std::copy(content_string.begin(), content_string.end(), content.data());
REQUIRE(display.content == content);
}
}
}

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -16,7 +16,7 @@
#include "output/DisplayController.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -16,7 +16,7 @@
#include "output/Lamp.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -16,7 +16,7 @@
#include "output/OutputDriver.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")

View File

@@ -10,7 +10,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -18,7 +18,7 @@
#include "output/Solenoid.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")

View File

@@ -8,7 +8,7 @@
#include "catch.hpp"
#include "fakeit.hpp"
#include "utilities/LoggerFactory.h"
#include "utility/LoggerFactory.h"
// testing purposes
@@ -16,7 +16,7 @@
#include "output/Sound.h"
using namespace output;
using namespace FlippR_Driver::output;
using namespace fakeit;
SCENARIO("")