Skip to content
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

Merged
merged 8 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog {#changelog}

# Release 1.5 (git master)

* [229](https://github.com/BlueBrain/Tide/pull/229):
Different models of Planar TV can be controlled now.
* [226](https://github.com/BlueBrain/Tide/pull/226):
New pyramidify tool to simplify the creation of multiple TIFF image pyramids.
* [224](https://github.com/BlueBrain/Tide/pull/224):
Expand Down
96 changes: 96 additions & 0 deletions tests/cpp/core/MultiScreenControllerTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*********************************************************************/
/* Copyright (c) 2017, EPFL/Blue Brain Project */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2018 ;-)

/* 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));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

controllers.emplace_back(new MockScreenController(ScreenState::ON));
Naked "new" as you did above are forbidden... :-)


auto multiController = new MultiScreenController(std::move(controllers));
Copy link

Choose a reason for hiding this comment

The 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)
Copy link

Choose a reason for hiding this comment

The 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);
}
Copy link

Choose a reason for hiding this comment

The 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.

160 changes: 160 additions & 0 deletions tests/cpp/core/ScreenControllerFactoryTests.cpp
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)
Copy link

Choose a reason for hiding this comment

The 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);
Copy link

Choose a reason for hiding this comment

The 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");
Copy link

Choose a reason for hiding this comment

The 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());
}
1 change: 1 addition & 0 deletions tests/mock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ target_sources(TideMock INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/MinimalGlobalQtApp.h"
"${CMAKE_CURRENT_SOURCE_DIR}/MockNetworkBarrier.h"
"${CMAKE_CURRENT_SOURCE_DIR}/MockTouchEvents.h"
"${CMAKE_CURRENT_SOURCE_DIR}/MockScreenController.h"
"${CMAKE_CURRENT_SOURCE_DIR}/QGuiAppFixture.h"
)
73 changes: 73 additions & 0 deletions tests/mock/MockScreenController.h
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
16 changes: 16 additions & 0 deletions tide/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

Choose a reason for hiding this comment

The 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();
Expand Down
4 changes: 2 additions & 2 deletions tide/master/MultiScreenController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "PlanarController.h"

MultiScreenController::MultiScreenController(
std::vector<std::unique_ptr<PlanarController>>&& controllers)
std::vector<std::unique_ptr<ScreenController>>&& controllers)
: _controllers{std::move(controllers)}
{
for (auto& controller : _controllers)
Expand Down Expand Up @@ -84,7 +84,7 @@ bool MultiScreenController::powerOff()
bool success = true;
for (auto& controller : _controllers)
{
if (controller->powerOff())
if (!controller->powerOff())
success = false;
}
return success;
Expand Down
Loading