added 2 output_tests + some add to output_driver
This commit is contained in:
@@ -32,6 +32,10 @@ public:
|
||||
virtual void activate_displays() const = 0;
|
||||
virtual void deactivate_displays() const = 0;
|
||||
|
||||
virtual void deactivate_all_lamps() const;
|
||||
virtual void activate_all_lamps() const;
|
||||
virtual void rotate_all_lamps() const;
|
||||
|
||||
virtual std::vector<std::shared_ptr<items::Lamp>> get_lamps() const = 0;
|
||||
virtual std::vector<std::shared_ptr<items::Solenoid>> get_solenoids() const = 0;
|
||||
virtual std::vector<std::shared_ptr<items::Sound>> get_sounds() const = 0;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "OutputDriver.h"
|
||||
|
||||
@@ -37,6 +38,28 @@ void OutputDriver::deactivate_displays() const
|
||||
display_controller->deactivate_displays();
|
||||
}
|
||||
|
||||
|
||||
void OutputDriver::deactivate_all_lamps() const
|
||||
{
|
||||
std::for_each(lamps.begin(), lamps.end(), [](items::Lamp& lamp){lamp.deactivate();});
|
||||
}
|
||||
|
||||
void OutputDriver::activate_all_lamps() const
|
||||
{
|
||||
std::for_each(lamps.begin(), lamps.end(), [](items::Lamp& lamp){lamp.activate();});
|
||||
}
|
||||
|
||||
void OutputDriver::rotate_all_lamps() const
|
||||
{
|
||||
for(auto lamp = lamps.begin(); lamp != lamps.end(); lamp++)
|
||||
{
|
||||
lamp->second->activate();
|
||||
// ToDo sleep time + is this thread safe??
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
lamp->second->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Sound>> OutputDriver::get_sounds() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Sound>> sounds;
|
||||
@@ -93,6 +116,7 @@ boost::optional<std::shared_ptr<items::Display>> OutputDriver::get_display(uint8
|
||||
return this->displays.find(number)->second;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
|
||||
@@ -23,13 +23,20 @@ namespace detail
|
||||
class OutputDriver : public output::OutputDriver
|
||||
{
|
||||
public:
|
||||
OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids, std::map<std::string, std::shared_ptr<items::Lamp>> lamps, std::map<std::string, std::shared_ptr<items::Sound>> sounds, std::map<uint8_t, std::shared_ptr<output::items::Display>> displays);
|
||||
OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids,
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps, std::map<std::string, std::shared_ptr<items::Sound>> sounds,
|
||||
std::map<uint8_t, std::shared_ptr<output::items::Display>> displays);
|
||||
|
||||
~OutputDriver() override = default;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
void deactivate_all_lamps() const override;
|
||||
void activate_all_lamps() const override;
|
||||
void rotate_all_lamps() const override;
|
||||
|
||||
// todo driver board run for activate/deactivate?
|
||||
// todo what is flipper_relay ?
|
||||
std::vector<std::shared_ptr<items::Lamp>> get_lamps() const override;
|
||||
std::vector<std::shared_ptr<items::Solenoid>> get_solenoids() const override;
|
||||
|
||||
@@ -28,7 +28,7 @@ OutputRequestHandler::OutputRequestHandler(std::shared_ptr<output::OutputDriver>
|
||||
* address/{item_type}/[item_name]/[action]/[score]
|
||||
*
|
||||
* Where
|
||||
* {item_type} is either solenoids, lamps, sounds, displays
|
||||
* {item_type} is either solenoids, lamps, sounds, displays, or one of the two special events: activate and deactivate
|
||||
* [item_name] is the string name of an item (optional if you want to get the list of all available items)
|
||||
* [action] is the particular action for the item:
|
||||
* Solenoids: trigger
|
||||
@@ -43,15 +43,29 @@ void OutputRequestHandler::handleRequest(HTTPServerRequest &request,
|
||||
HTTPServerResponse &response)
|
||||
{
|
||||
auto path_segments = getPathSegments(URI(request.getURI()));
|
||||
// ToDo catch exception
|
||||
|
||||
// fill up vector
|
||||
for(int i = path_segments.size(); i < 4; i++)
|
||||
{
|
||||
path_segments.emplace_back("");
|
||||
}
|
||||
|
||||
std::string item_type = path_segments.at(0);
|
||||
std::string item_name = path_segments.at(1);
|
||||
std::string action = path_segments.at(2);
|
||||
std::string score = "";
|
||||
std::string score = path_segments.at(3);
|
||||
|
||||
if(item_type == "displays")
|
||||
if(item_type == "deactivate")
|
||||
{
|
||||
score = path_segments.at(3);
|
||||
this->output_driver->deactivate_displays();
|
||||
this->output_driver->deactivate_all_lamps();
|
||||
return;
|
||||
}
|
||||
|
||||
if(item_type == "activate")
|
||||
{
|
||||
this->output_driver->activate_displays();
|
||||
return;
|
||||
}
|
||||
|
||||
response.setContentType("text/json");
|
||||
@@ -105,7 +119,7 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseSolenoid(const st
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("solenoids", output_driver->get_solenoids());
|
||||
response.set("solenoids", this->output_driver->get_solenoids());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -135,7 +149,7 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseLamp(const std::s
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("lamps", output_driver->get_lamps());
|
||||
response.set("lamps", this->output_driver->get_lamps());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -169,7 +183,7 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseSound(const std::
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("sounds", output_driver->get_lamps());
|
||||
response.set("sounds", this->output_driver->get_lamps());
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -199,9 +213,10 @@ boost::optional<Poco::JSON::Object> OutputRequestHandler::parseDisplay(const std
|
||||
if(item_name == "")
|
||||
{
|
||||
Poco::JSON::Object response;
|
||||
response.set("displays", output_driver->get_displays());
|
||||
response.set("displays", this->output_driver->get_displays());
|
||||
return response;
|
||||
}
|
||||
|
||||
uint8_t display_number = std::stoi(item_name);
|
||||
auto opt_display = this->output_driver->get_display(display_number);
|
||||
|
||||
@@ -240,7 +255,6 @@ std::vector<std::string> OutputRequestHandler::getPathSegments(Poco::URI uri)
|
||||
return path_segments;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ SCENARIO("An EventHandler gets created", "[construction}")
|
||||
|
||||
THEN("It should register itself at the input_driver")
|
||||
{
|
||||
REQUIRE((bool)Verify(Method(input_driver_mock, register_event_handler).Using(&handler)));
|
||||
REQUIRE((bool)Verify(Method(input_driver_mock, register_event_handler).Using(&handler)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,16 +10,51 @@
|
||||
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
#define private public
|
||||
|
||||
#include "output/items/detail/Lamp.h"
|
||||
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
SCENARIO("A Lamp gets activated")
|
||||
{
|
||||
GIVEN("A Lamp")
|
||||
{
|
||||
Mock<DriverBoardPinController> pin_controller;
|
||||
Fake(Dtor(pin_controller));
|
||||
When(Method(pin_controller, activate)).AlwaysReturn();
|
||||
|
||||
items::detail::Lamp lamp(std::make_shared<DriverBoardPinController>(pin_controller), 0, 0);
|
||||
|
||||
WHEN("The lamp gets activated")
|
||||
{
|
||||
lamp.activate();
|
||||
|
||||
THEN("It should call the pin_controller with itself")
|
||||
{
|
||||
REQUIRE((bool) Verify(Method(pin_controller, activate).Using(&lamp)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("A Lamp gets deactivated")
|
||||
{
|
||||
GIVEN("A Lamp")
|
||||
{
|
||||
Mock<DriverBoardPinController> pin_controller;
|
||||
Fake(Dtor(pin_controller));
|
||||
When(Method(pin_controller, deactivate)).AlwaysReturn();
|
||||
|
||||
items::detail::Lamp lamp(std::make_shared<DriverBoardPinController>(pin_controller), 0, 0);
|
||||
|
||||
WHEN("The lamp gets deactivated")
|
||||
{
|
||||
lamp.deactivate();
|
||||
|
||||
THEN("It should call the pin_controller with itself")
|
||||
{
|
||||
REQUIRE((bool) Verify(Method(pin_controller, deactivate).Using(&lamp)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include <output/DisplayController.h>
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
@@ -14,13 +15,24 @@
|
||||
// testing purposes
|
||||
#define private public
|
||||
|
||||
#include "output/OutputDriver.h"
|
||||
#include "output/detail/OutputDriver.h"
|
||||
|
||||
using namespace flippR_driver::output;
|
||||
using namespace flippR_driver;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
SCENARIO("The OutputDriver should activate the displays")
|
||||
{
|
||||
GIVEN("An OutputDriver")
|
||||
{
|
||||
Mock<output::DisplayController> display_controller;
|
||||
When(Method(display_controller, activate_displays)).AlwaysReturn();
|
||||
output::detail::OutputDriver outputDriver(std::make_unique<output::DisplayController>(display_controller), nullptr, nullptr, nullptr, nullptr);
|
||||
output::detail::OutputDriver output_driver(std::make_unique<output::DisplayController>(display_controller), NULL, nullptr, nullptr, nullptr);
|
||||
WHEN("The displays get activated")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user