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 3 commits
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
113 changes: 113 additions & 0 deletions tests/cpp/core/MultiScreenControllerTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*********************************************************************/
/* Copyright (c) 2018, 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)
{
std::vector<std::unique_ptr<ScreenController>> controllers;
controllers.emplace_back(new MockScreenController(ScreenState::UNDEF));
controllers.emplace_back(new MockScreenController(ScreenState::UNDEF));

MultiScreenController multiController(std::move(controllers));

BOOST_CHECK_EQUAL(multiController.getState(), ScreenState::UNDEF);

multiController.powerOn();

for (auto& controller : controllers)
{
BOOST_CHECK(
static_cast<MockScreenController&>(*controller).powerOnCalled);
}

BOOST_CHECK_EQUAL(multiController.getState(), ScreenState::ON);

multiController.powerOff();

for (auto& controller : controllers)
{
BOOST_CHECK(
static_cast<MockScreenController&>(*controller).powerOffCalled);
}
BOOST_CHECK_EQUAL(multiController.getState(), ScreenState::OFF);
}

BOOST_AUTO_TEST_CASE(testDifferentScreenStates)
{
std::vector<std::unique_ptr<ScreenController>> controllers;
controllers.emplace_back(new MockScreenController(ScreenState::ON));
controllers.emplace_back(new MockScreenController(ScreenState::OFF));

MultiScreenController multiController(std::move(controllers));

multiController.getState();
BOOST_CHECK_EQUAL(multiController.getState(), ScreenState::UNDEF);
}

BOOST_AUTO_TEST_CASE(testSignal)
{
std::vector<std::unique_ptr<ScreenController>> controllers;
controllers.emplace_back(new MockScreenController(ScreenState::ON));
MultiScreenController multiController(std::move(controllers));

bool emitted = false;

QObject::connect(&multiController, &MultiScreenController::powerStateChanged,
[&emitted]() { emitted = true; });

multiController.checkPowerState();
BOOST_CHECK(emitted);

emitted = false;
multiController.powerOff();
BOOST_CHECK(emitted);

emitted = false;
multiController.powerOn();
BOOST_CHECK_EQUAL(multiController.getState(), ScreenState::ON);
BOOST_CHECK(emitted);
}
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.

164 changes: 164 additions & 0 deletions tests/cpp/core/ScreenControllerFactoryTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*********************************************************************/
/* Copyright (c) 2018, 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)
{
switch (type)
{
case PlanarController::Type::Matrix:
str << "Matrix";
break;
case PlanarController::Type::TV_UR9850:
str << "TV_UR9850";
break;
case PlanarController::Type::TV_UR9851:
str << "TV_UR9851";
break;
}
return str;
}

BOOST_AUTO_TEST_CASE(testEmpty)
{
BOOST_CHECK(!ScreenControllerFactory::create(""));
}

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(testSingleController)
{
const QMap<QString, PlanarController::Type> expectedMatrix{
{"/dev/usb1", PlanarController::Type::Matrix}};

const auto processedMatrix =
ScreenControllerFactory::parseInputString("/dev/usb1");

BOOST_CHECK_EQUAL_COLLECTIONS(expectedMatrix.begin(), expectedMatrix.end(),
processedMatrix.begin(),
processedMatrix.end());

const QMap<QString, PlanarController::Type> expectedUR9850{
{"/dev/usb1", PlanarController::Type::TV_UR9850}};

const auto processedUR9850 =
ScreenControllerFactory::parseInputString("/dev/usb1#UR9850");

BOOST_CHECK_EQUAL_COLLECTIONS(expectedUR9850.begin(), expectedUR9850.end(),
processedUR9850.begin(),
processedUR9850.end());

const QMap<QString, PlanarController::Type> expectedUR9851{
{"/dev/usb1", PlanarController::Type::TV_UR9851}};

const auto processedUR9851 =
ScreenControllerFactory::parseInputString("/dev/usb1#UR9851");

BOOST_CHECK_EQUAL_COLLECTIONS(expectedUR9851.begin(), expectedUR9851.end(),
processedUR9851.begin(),
processedUR9851.end());
}

BOOST_AUTO_TEST_CASE(testMultipleConnectionsWithType)
{
const QMap<QString, PlanarController::Type> expected{
{"/dev/usb1", PlanarController::Type::Matrix},
{"/dev/usb2", PlanarController::Type::TV_UR9850},
{"/dev/usb3", PlanarController::Type::TV_UR9851}};

const auto processed = ScreenControllerFactory::parseInputString(
"/dev/usb1;/dev/usb2#UR9850;/dev/usb3#UR9851");

BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
processed.begin(), processed.end());
}

BOOST_AUTO_TEST_CASE(testMultipleConnectionsWithOneEmpty)
{
const QMap<QString, PlanarController::Type> expected{
{"/dev/usb1", PlanarController::Type::Matrix}};
const auto processed =
ScreenControllerFactory::parseInputString(";/dev/usb1");

BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
processed.begin(), processed.end());
}

BOOST_AUTO_TEST_CASE(testMultipleConnectionsWithOneEmptyDevice)
{
const QMap<QString, PlanarController::Type> expected{
{"/dev/usb1", PlanarController::Type::Matrix}};
const auto processed =
ScreenControllerFactory::parseInputString("#UR9850;/dev/usb1");

BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
processed.begin(), processed.end());
}

BOOST_AUTO_TEST_CASE(testConnectionsWithEmptyDeviceType)
{
const QMap<QString, PlanarController::Type> expected{
{"/dev/usb1", PlanarController::Type::Matrix}};
const auto processed =
ScreenControllerFactory::parseInputString("/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"
)
83 changes: 83 additions & 0 deletions tests/mock/MockScreenController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*********************************************************************/
/* Copyright (c) 2018, 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. */
/*********************************************************************/

#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 final { return _state; }
void checkPowerState() final { emit powerStateChanged(_state); }

bool powerOn() final
{
_state = ScreenState::ON;
emit powerStateChanged(_state);
powerOnCalled = true;
return true;
}

bool powerOff() final
{
_state = ScreenState::OFF;
emit powerStateChanged(_state);
powerOffCalled = true;
return true;
}

bool powerOffCalled = false;
bool powerOnCalled = false;

private:
ScreenState _state;
};

#endif
Loading