-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ScreenController able to manage different type of Planar TV #229
Changes from 1 commit
78a0437
8c76f78
cee7f39
5f276f6
efd947c
6f3fb9d
75d3cbd
262a82a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/*********************************************************************/ | ||
/* Copyright (c) 2017, EPFL/Blue Brain Project */ | ||
/* Pawel Podhajski <pawel.podhajski@epfl.ch> */ | ||
/* All rights reserved. */ | ||
/* */ | ||
/* Redistribution and use in source and binary forms, with or */ | ||
/* without modification, are permitted provided that the following */ | ||
/* conditions are met: */ | ||
/* */ | ||
/* 1. Redistributions of source code must retain the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer. */ | ||
/* */ | ||
/* 2. Redistributions in binary form must reproduce the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer in the documentation and/or other materials */ | ||
/* provided with the distribution. */ | ||
/* */ | ||
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ | ||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ | ||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ | ||
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ | ||
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ | ||
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ | ||
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ | ||
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ | ||
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ | ||
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ | ||
/* POSSIBILITY OF SUCH DAMAGE. */ | ||
/* */ | ||
/* The views and conclusions contained in the software and */ | ||
/* documentation are those of the authors and should not be */ | ||
/* interpreted as representing official policies, either expressed */ | ||
/* or implied, of Ecole polytechnique federale de Lausanne. */ | ||
/*********************************************************************/ | ||
|
||
#define BOOST_TEST_MODULE MutliScreenControllerTest | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "MockScreenController.h" | ||
#include "MultiScreenController.h" | ||
#include "ScreenController.h" | ||
#include "types.h" | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(testUniformScreenStates) | ||
{ | ||
auto mockController1 = new MockScreenController(ScreenState::ON); | ||
auto mockController2 = new MockScreenController(ScreenState::ON); | ||
std::vector<std::unique_ptr<ScreenController>> controllers; | ||
|
||
controllers.push_back(std::unique_ptr<ScreenController>(mockController1)); | ||
controllers.push_back(std::unique_ptr<ScreenController>(mockController2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. controllers.emplace_back(new MockScreenController(ScreenState::ON)); |
||
|
||
auto multiController = new MultiScreenController(std::move(controllers)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...and here you have a good reason why: this multiController is never deleted! You could have used make_unique() instead, but in fact there is no reason to allocate one on the heap. Just create one on the stack. |
||
multiController->getState(); | ||
BOOST_CHECK_EQUAL(multiController->getState(), ScreenState::ON); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testDifferentScreenStates) | ||
{ | ||
auto mockControllerOn = new MockScreenController(ScreenState::ON); | ||
auto mockControllerOff = new MockScreenController(ScreenState::OFF); | ||
std::vector<std::unique_ptr<ScreenController>> controllers; | ||
|
||
controllers.push_back(std::unique_ptr<ScreenController>(mockControllerOn)); | ||
controllers.push_back(std::unique_ptr<ScreenController>(mockControllerOff)); | ||
|
||
auto multiController = new MultiScreenController(std::move(controllers)); | ||
multiController->getState(); | ||
|
||
BOOST_CHECK_EQUAL(multiController->getState(), ScreenState::UNDEF); | ||
|
||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testSignals) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which signals? I am not seeing the powerStateChanged signal being tested and that's the only one that this class has..? |
||
{ | ||
auto mockController = new MockScreenController(ScreenState::ON); | ||
std::vector<std::unique_ptr<ScreenController>> controllers; | ||
controllers.push_back(std::unique_ptr<ScreenController>(mockController)); | ||
|
||
auto multiController = new MultiScreenController(std::move(controllers)); | ||
|
||
multiController->checkPowerState(); | ||
BOOST_CHECK_EQUAL(multiController->getState(), ScreenState::ON); | ||
|
||
multiController->powerOff(); | ||
BOOST_CHECK_EQUAL(multiController->getState(), ScreenState::OFF); | ||
|
||
multiController->powerOn(); | ||
BOOST_CHECK_EQUAL(multiController->getState(), ScreenState::ON); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a check that when any of checkPowerState / powerOff / powerOn are called, the MultiController is indeed calling the same functions on all the MockControllers that were passed to it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/*********************************************************************/ | ||
/* Copyright (c) 2017, EPFL/Blue Brain Project */ | ||
/* Pawel Podhajski <pawel.podhajski@epfl.ch> */ | ||
/* All rights reserved. */ | ||
/* */ | ||
/* Redistribution and use in source and binary forms, with or */ | ||
/* without modification, are permitted provided that the following */ | ||
/* conditions are met: */ | ||
/* */ | ||
/* 1. Redistributions of source code must retain the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer. */ | ||
/* */ | ||
/* 2. Redistributions in binary form must reproduce the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer in the documentation and/or other materials */ | ||
/* provided with the distribution. */ | ||
/* */ | ||
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ | ||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ | ||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ | ||
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ | ||
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ | ||
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ | ||
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ | ||
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ | ||
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ | ||
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ | ||
/* POSSIBILITY OF SUCH DAMAGE. */ | ||
/* */ | ||
/* The views and conclusions contained in the software and */ | ||
/* documentation are those of the authors and should not be */ | ||
/* interpreted as representing official policies, either expressed */ | ||
/* or implied, of Ecole polytechnique federale de Lausanne. */ | ||
/*********************************************************************/ | ||
|
||
#define BOOST_TEST_MODULE ScreenControllerFactoryTest | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "MultiScreenController.h" | ||
#include "PlanarController.h" | ||
#include "ScreenControllerFactory.h" | ||
|
||
#include <QMap> | ||
|
||
inline std::ostream& operator<<(std::ostream& str, | ||
const PlanarController::Type& type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no & for POD types, pass by value |
||
{ | ||
switch (type) | ||
{ | ||
case PlanarController::Type::TV_UR9850: | ||
str << "TV_UR9850"; | ||
break; | ||
case PlanarController::Type::TV_UR9851: | ||
str << "TV_UR9851"; | ||
break; | ||
case PlanarController::Type::Matrix: | ||
str << "Matrix"; | ||
break; | ||
default: | ||
break; | ||
} | ||
return str; | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testException) | ||
{ | ||
BOOST_CHECK_THROW(ScreenControllerFactory::create("/dev/null;/dev/das"), | ||
std::runtime_error); | ||
BOOST_CHECK_THROW(ScreenControllerFactory::create( | ||
"/dev/null#UR9850;/dev/null#UR9851"), | ||
std::runtime_error); | ||
BOOST_CHECK_THROW(ScreenControllerFactory::create("/dev/null#UR9850"), | ||
std::runtime_error); | ||
BOOST_CHECK_THROW(ScreenControllerFactory::create("/dev/null"), | ||
std::runtime_error) | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testNonseparatedSerial) | ||
{ | ||
QMap<QString, PlanarController::Type> expectedMatrix; | ||
expectedMatrix.insert("/dev/usb1", PlanarController::Type::Matrix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of doing map.insert(), use the map's initialiser list constructor, which allows to make the object const. |
||
|
||
const auto processedMatrix = | ||
ScreenControllerFactory::processInputString("/dev/usb1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename processInputString() to parseInputString() |
||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expectedMatrix.begin(), expectedMatrix.end(), | ||
processedMatrix.begin(), | ||
processedMatrix.end()); | ||
|
||
QMap<QString, PlanarController::Type> expectedUR9850; | ||
expectedUR9850.insert("/dev/usb1", PlanarController::Type::TV_UR9850); | ||
|
||
const auto processedUR9850 = | ||
ScreenControllerFactory::processInputString("/dev/usb1#UR9850"); | ||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expectedUR9850.begin(), expectedUR9850.end(), | ||
processedUR9850.begin(), | ||
processedUR9850.end()); | ||
|
||
QMap<QString, PlanarController::Type> expectedUR9851; | ||
expectedUR9851.insert("/dev/usb1", PlanarController::Type::TV_UR9851); | ||
|
||
const auto processedUR9851 = | ||
ScreenControllerFactory::processInputString("/dev/usb1#UR9851"); | ||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expectedUR9851.begin(), expectedUR9851.end(), | ||
processedUR9851.begin(), | ||
processedUR9851.end()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testSeparatedSerials) | ||
{ | ||
QMap<QString, PlanarController::Type> expected; | ||
expected.insert("/dev/usb1", PlanarController::Type::Matrix); | ||
expected.insert("/dev/usb2", PlanarController::Type::TV_UR9850); | ||
expected.insert("/dev/usb3", PlanarController::Type::TV_UR9851); | ||
const auto processed = ScreenControllerFactory::processInputString( | ||
"/dev/usb1;/dev/usb2#UR9850;/dev/usb3#UR9851"); | ||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), | ||
processed.begin(), processed.end()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testEmptySerial) | ||
{ | ||
QMap<QString, PlanarController::Type> expected; | ||
expected.insert("/dev/usb1", PlanarController::Type::Matrix); | ||
const auto processed = | ||
ScreenControllerFactory::processInputString(";/dev/usb1"); | ||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), | ||
processed.begin(), processed.end()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testEmptySerialDeviceWithHash) | ||
{ | ||
QMap<QString, PlanarController::Type> expected; | ||
expected.insert("/dev/usb1", PlanarController::Type::Matrix); | ||
const auto processed = | ||
ScreenControllerFactory::processInputString("#UR9850;/dev/usb1"); | ||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), | ||
processed.begin(), processed.end()); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(testEmptySerialTypeWithHash) | ||
{ | ||
QMap<QString, PlanarController::Type> expected; | ||
expected.insert("/dev/usb1", PlanarController::Type::Matrix); | ||
const auto processed = | ||
ScreenControllerFactory::processInputString("/dev/usb1#"); | ||
|
||
BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), | ||
processed.begin(), processed.end()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*********************************************************************/ | ||
/* Copyright (c) 2017, EPFL/Blue Brain Project */ | ||
/* Raphael Dumusc <raphael.dumusc@epfl.ch> */ | ||
/* All rights reserved. */ | ||
/* */ | ||
/* Redistribution and use in source and binary forms, with or */ | ||
/* without modification, are permitted provided that the following */ | ||
/* conditions are met: */ | ||
/* */ | ||
/* 1. Redistributions of source code must retain the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer. */ | ||
/* */ | ||
/* 2. Redistributions in binary form must reproduce the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer in the documentation and/or other materials */ | ||
/* provided with the distribution. */ | ||
/* */ | ||
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ | ||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ | ||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ | ||
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ | ||
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ | ||
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ | ||
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ | ||
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ | ||
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ | ||
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ | ||
/* POSSIBILITY OF SUCH DAMAGE. */ | ||
/* */ | ||
/* The views and conclusions contained in the software and */ | ||
/* documentation are those of the authors and should not be */ | ||
/* interpreted as representing official policies, either expressed */ | ||
/* or implied, of Ecole polytechnique federale de Lausanne. */ | ||
/*********************************************************************/ | ||
|
||
#ifndef MOCKSCREENCONTROLLER_H | ||
#define MOCKSCREENCONTROLLER_H | ||
|
||
#include "ScreenController.h" | ||
#include "types.h" | ||
|
||
#include <QObject> | ||
|
||
class MockScreenController : public ScreenController | ||
{ | ||
Q_OBJECT | ||
public: | ||
MockScreenController(ScreenState state) | ||
: _state(state) | ||
{ | ||
} | ||
ScreenState getState() const { return _state; } | ||
void checkPowerState() { emit powerStateChanged(_state); } | ||
bool powerOn() | ||
{ | ||
_state = ScreenState::ON; | ||
return true; | ||
} | ||
bool powerOff() | ||
{ | ||
_state = ScreenState::OFF; | ||
return true; | ||
} | ||
|
||
private: | ||
ScreenState _state; | ||
}; | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,22 @@ inline std::ostream& operator<<(std::ostream& str, const QPointF& p) | |
return str; | ||
} | ||
|
||
inline std::ostream& operator<<(std::ostream& str, const ScreenState state) | ||
{ | ||
switch (state) | ||
{ | ||
case ScreenState::ON: | ||
str << "ON"; | ||
return str; | ||
case ScreenState::OFF: | ||
str << "OFF"; | ||
return str; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use breaks; in the switch case, having multiple identical return statements is not good. Also, the case ScreenState::UNDEF should be listed explicitly, don't use the default. |
||
default: | ||
str << "UNDEF"; | ||
} | ||
return str; | ||
} | ||
|
||
inline std::ostream& operator<<(std::ostream& str, const QRectF& r) | ||
{ | ||
str << r.x() << ',' << r.y() << ' ' << r.width() << 'x' << r.height(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2018 ;-)