unity-system-compositor-0.4.3+16.04.20160323/ 0000755 0000156 0000165 00000000000 12674474477 020773 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/cmake/ 0000755 0000156 0000165 00000000000 12674474477 022053 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/cmake/FindGLESv2.cmake 0000644 0000156 0000165 00000001573 12674474272 024657 0 ustar pbuser pbgroup 0000000 0000000 # - Try to find GLESv2
# Once done this will define
# GLESv2_FOUND - System has GLESv2
# GLESv2_INCLUDE_DIRS - The GLESv2 include directories
# GLESv2_LIBRARIES - The libraries needed to use GLESv2
find_package(PkgConfig)
pkg_check_modules(PC_GLESv2 QUIET glesv2)
find_path(GLESv2_INCLUDE_DIR GLES2/gl2.h
HINTS ${PC_GLESv2_INCLUDEDIR} ${PC_GLESv2_INCLUDE_DIRS})
find_library(GLESv2_LIBRARY GLESv2
HINTS ${PC_GLESv2_LIBDIR} ${PC_GLESv2_LIBRARY_DIRS})
set(GLESv2_LIBRARIES ${GLESv2_LIBRARY})
set(GLESv2_INCLUDE_DIRS ${GLESv2_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set GLESv2_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(GLESv2 DEFAULT_MSG
GLESv2_LIBRARY GLESv2_INCLUDE_DIR)
mark_as_advanced(GLESv2_INCLUDE_DIR GLESv2_LIBRARY)
unity-system-compositor-0.4.3+16.04.20160323/cmake/FindGtest.cmake 0000644 0000156 0000165 00000003370 12674474272 024740 0 ustar pbuser pbgroup 0000000 0000000 include(ExternalProject)
include(FindPackageHandleStandardArgs)
#gtest
set(GTEST_INSTALL_DIR /usr/src/gmock/gtest/include)
find_path(GTEST_INCLUDE_DIR gtest/gtest.h
HINTS ${GTEST_INSTALL_DIR})
#gmock
find_path(GMOCK_INSTALL_DIR gmock/CMakeLists.txt
HINTS /usr/src)
if(${GMOCK_INSTALL_DIR} STREQUAL "GMOCK_INSTALL_DIR-NOTFOUND")
message(FATAL_ERROR "google-mock package not found")
endif()
set(GMOCK_INSTALL_DIR ${GMOCK_INSTALL_DIR}/gmock)
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h)
set(GMOCK_PREFIX gmock)
set(GMOCK_BINARY_DIR ${CMAKE_BINARY_DIR}/${GMOCK_PREFIX}/libs)
set(GTEST_BINARY_DIR ${GMOCK_BINARY_DIR}/gtest)
set(GTEST_CMAKE_ARGS "")
if (${CMAKE_CROSSCOMPILING})
set(GTEST_CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_MODULE_PATH}/LinuxCrossCompile.cmake)
endif()
ExternalProject_Add(
GMock
#where to build in source tree
PREFIX ${GMOCK_PREFIX}
#where the source is external to the project
SOURCE_DIR ${GMOCK_INSTALL_DIR}
#forward the compilers to the subproject so cross-arch builds work
CMAKE_ARGS ${GTEST_CMAKE_ARGS}
BINARY_DIR ${GMOCK_BINARY_DIR}
#we don't need to install, so skip
INSTALL_COMMAND ""
)
set(GMOCK_LIBRARY ${GMOCK_BINARY_DIR}/libgmock.a)
set(GMOCK_MAIN_LIBRARY ${GMOCK_BINARY_DIR}/libgmock_main.a)
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY})
set(GTEST_LIBRARY ${GTEST_BINARY_DIR}/libgtest.a)
set(GTEST_MAIN_LIBRARY ${GTEST_BINARY_DIR}/libgtest_main.a)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY})
set(GTEST_ALL_LIBRARIES ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
find_package_handle_standard_args(GTest DEFAULT_MSG
GMOCK_INCLUDE_DIR
GTEST_INCLUDE_DIR)
unity-system-compositor-0.4.3+16.04.20160323/cmake/FindPIL.cmake 0000644 0000156 0000165 00000000300 12674474272 024264 0 ustar pbuser pbgroup 0000000 0000000 execute_process(
COMMAND python -c "from PIL import Image"
RESULT_VARIABLE HAVE_PIL
)
if (NOT ${HAVE_PIL} EQUAL 0)
message(FATAL_ERROR "Python Imaging Library (PIL) not found")
endif()
unity-system-compositor-0.4.3+16.04.20160323/tests/ 0000755 0000156 0000165 00000000000 12674474477 022135 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/ 0000755 0000156 0000165 00000000000 12674474477 024254 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/test_mir_input_configuration.cpp 0000644 0000156 0000165 00000007460 12674474272 032754 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#include "src/mir_input_configuration.h"
#include "mir/input/input_device_hub.h"
#include "mir/input/device_capability.h"
#include "mir/input/input_device_observer.h"
#include "mir/input/device.h"
#include
#include
namespace mi = mir::input;
using namespace ::testing;
namespace
{
struct MockDevice : mi::Device
{
MOCK_CONST_METHOD0(id, MirInputDeviceId());
MOCK_CONST_METHOD0(capabilities, mi::DeviceCapabilities());
MOCK_CONST_METHOD0(name, std::string());
MOCK_CONST_METHOD0(unique_id, std::string());
MOCK_CONST_METHOD0(pointer_configuration, mir::optional_value());
MOCK_METHOD1(apply_pointer_configuration, void(mi::PointerConfiguration const&));
MOCK_CONST_METHOD0(touchpad_configuration, mir::optional_value ());
MOCK_METHOD1(apply_touchpad_configuration, void(mi::TouchpadConfiguration const&));
MockDevice(mi::DeviceCapabilities caps)
: caps(caps)
{
ON_CALL(*this, capabilities()).WillByDefault(Return(this->caps));
}
mi::DeviceCapabilities caps;
};
struct MockInputDeviceHub : mi::InputDeviceHub
{
MOCK_METHOD1(add_observer,void(std::shared_ptr const&));
MOCK_METHOD1(remove_observer,void(std::weak_ptr const&));
};
struct MirInputConfiguration : ::testing::Test
{
template
using shared_mock = std::shared_ptr<::testing::NiceMock>;
shared_mock mock_hub{std::make_shared<::testing::NiceMock>()};
shared_mock mock_mouse{
std::make_shared<::testing::NiceMock>(mi::DeviceCapability::pointer)};
shared_mock mock_touchpad{std::make_shared<::testing::NiceMock>(
mi::DeviceCapability::pointer | mi::DeviceCapability::touchpad)};
shared_mock mock_keyboard{std::make_shared<::testing::NiceMock>(
mi::DeviceCapability::keyboard | mi::DeviceCapability::alpha_numeric)};
std::shared_ptr obs;
MirInputConfiguration()
{
ON_CALL(*mock_hub, add_observer(_)).WillByDefault(SaveArg<0>(&obs));
}
};
}
TEST_F(MirInputConfiguration, registers_something_as_device_observer)
{
EXPECT_CALL(*mock_hub, add_observer(_));
usc::MirInputConfiguration config(mock_hub);
}
TEST_F(MirInputConfiguration, configures_device_on_add)
{
usc::MirInputConfiguration config(mock_hub);
EXPECT_CALL(*mock_touchpad, apply_pointer_configuration(_));
EXPECT_CALL(*mock_touchpad, apply_touchpad_configuration(_));
obs->device_added(mock_touchpad);
}
TEST_F(MirInputConfiguration, configures_mouse_on_add)
{
usc::MirInputConfiguration config(mock_hub);
EXPECT_CALL(*mock_mouse, apply_pointer_configuration(_));
obs->device_added(mock_mouse);
}
TEST_F(MirInputConfiguration, ignores_keyboard_when_added)
{
usc::MirInputConfiguration config(mock_hub);
EXPECT_CALL(*mock_keyboard, apply_touchpad_configuration(_)).Times(0);
EXPECT_CALL(*mock_keyboard, apply_pointer_configuration(_)).Times(0);
obs->device_added(mock_keyboard);
}
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/test_mir_screen.cpp 0000644 0000156 0000165 00000101357 12674474277 030152 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "src/mir_screen.h"
#include "src/performance_booster.h"
#include "src/screen_hardware.h"
#include "src/power_state_change_reason.h"
#include "advanceable_timer.h"
#include "usc/test/mock_display.h"
#include
#include
#include
#include
#include
#include
#include
namespace mg = mir::graphics;
namespace ut = usc::test;
namespace
{
struct MockCompositor : mir::compositor::Compositor
{
MOCK_METHOD0(start, void());
MOCK_METHOD0(stop, void());
};
struct MockPerformanceBooster : usc::PerformanceBooster
{
MOCK_METHOD0(enable_performance_boost_during_user_interaction, void());
MOCK_METHOD0(disable_performance_boost_during_user_interaction, void());
};
struct MockScreenHardware : usc::ScreenHardware
{
MOCK_METHOD0(set_dim_backlight, void());
MOCK_METHOD0(set_normal_backlight, void());
MOCK_METHOD0(turn_off_backlight, void());
void change_backlight_values(int dim_brightness, int normal_brightness) override {}
MOCK_METHOD0(allow_suspend, void());
MOCK_METHOD0(disable_suspend, void());
MOCK_METHOD1(enable_auto_brightness, void(bool));
bool auto_brightness_supported() override { return true; }
MOCK_METHOD1(set_brightness, void(int));
int min_brightness() override { return 100; }
int max_brightness() override { return 0; }
enum class Proximity {near, far};
void enable_proximity(bool enable) override
{
proximity_enabled = enable;
set_proximity(current_proximity);
}
void set_proximity(Proximity proximity)
{
current_proximity = proximity;
if (proximity_enabled)
on_proximity_changed(current_proximity);
}
std::function on_proximity_changed = [](Proximity){};
Proximity current_proximity{Proximity::far};
bool proximity_enabled{false};
};
struct MockTouchVisualizer : mir::input::TouchVisualizer
{
MOCK_METHOD0(enable, void());
MOCK_METHOD0(disable, void());
// Visualize a given set of touches statelessly.
void visualize_touches(std::vector const& touches) override {}
};
struct AMirScreen : testing::Test
{
AMirScreen()
{
using namespace testing;
screen_hardware->on_proximity_changed =
[this] (MockScreenHardware::Proximity p) { defer_proximity_event(p); };
}
void defer_proximity_event(MockScreenHardware::Proximity proximity)
{
deferred_actions.push_back(
[this, proximity]
{
mir_screen.set_screen_power_mode(
proximity == MockScreenHardware::Proximity::far ?
MirPowerMode::mir_power_mode_on :
MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
});
}
void process_deferred_actions()
{
for (auto const& a : deferred_actions)
a();
deferred_actions.clear();
}
std::vector> deferred_actions;
std::chrono::seconds const power_off_timeout{60};
std::chrono::seconds const dimmer_timeout{50};
std::chrono::seconds const notification_power_off_timeout{15};
std::chrono::seconds const notification_dimmer_timeout{12};
std::chrono::seconds const call_power_off_timeout{30};
std::chrono::seconds const call_dimmer_timeout{25};
std::chrono::seconds const five_seconds{5};
std::chrono::seconds const ten_seconds{10};
std::chrono::seconds const fifteen_seconds{15};
std::chrono::seconds const thirty_seconds{30};
std::chrono::seconds const fourty_seconds{40};
std::chrono::seconds const fifty_seconds{50};
void expect_performance_boost_is_enabled()
{
using namespace testing;
EXPECT_CALL(*performance_booster, enable_performance_boost_during_user_interaction());
}
void expect_performance_boost_is_disabled()
{
using namespace testing;
EXPECT_CALL(*performance_booster, disable_performance_boost_during_user_interaction());
}
void expect_screen_is_turned_off()
{
using namespace testing;
EXPECT_CALL(*screen_hardware, turn_off_backlight());
EXPECT_CALL(*screen_hardware, allow_suspend());
InSequence s;
EXPECT_CALL(*compositor, stop());
EXPECT_CALL(*display, configure(_));
}
void expect_screen_is_turned_on()
{
using namespace testing;
EXPECT_CALL(*screen_hardware, disable_suspend());
EXPECT_CALL(*screen_hardware, set_normal_backlight());
InSequence s;
EXPECT_CALL(*compositor, stop());
EXPECT_CALL(*display, configure(_));
EXPECT_CALL(*compositor, start());
}
void expect_screen_is_turned_dim()
{
using namespace testing;
EXPECT_CALL(*screen_hardware, set_dim_backlight());
}
void expect_no_reconfiguration()
{
using namespace testing;
EXPECT_CALL(*display, configure(_)).Times(0);
EXPECT_CALL(*screen_hardware, set_dim_backlight()).Times(0);
}
void verify_proximity_enabled()
{
verify_and_clear_expectations();
if (screen_hardware->current_proximity == MockScreenHardware::Proximity::far)
{
expect_screen_is_turned_off();
cover_screen();
verify_and_clear_expectations();
expect_screen_is_turned_on();
uncover_screen();
verify_and_clear_expectations();
}
if (screen_hardware->current_proximity == MockScreenHardware::Proximity::near)
{
expect_screen_is_turned_on();
uncover_screen();
verify_and_clear_expectations();
expect_screen_is_turned_off();
cover_screen();
verify_and_clear_expectations();
}
}
void verify_proximity_disabled()
{
verify_and_clear_expectations();
expect_no_reconfiguration();
uncover_screen();
cover_screen();
uncover_screen();
verify_and_clear_expectations();
}
void turn_screen_off()
{
using namespace testing;
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key);
verify_and_clear_expectations();
}
void turn_screen_on()
{
using namespace testing;
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
verify_and_clear_expectations();
}
void receive_notification()
{
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::notification);
process_deferred_actions();
}
void receive_call()
{
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::snap_decision);
process_deferred_actions();
}
void receive_call_done()
{
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::call_done);
process_deferred_actions();
}
void cover_screen()
{
screen_hardware->set_proximity(MockScreenHardware::Proximity::near);
process_deferred_actions();
}
void uncover_screen()
{
screen_hardware->set_proximity(MockScreenHardware::Proximity::far);
process_deferred_actions();
}
void verify_and_clear_expectations()
{
using namespace testing;
Mock::VerifyAndClearExpectations(screen_hardware.get());
Mock::VerifyAndClearExpectations(display.get());
Mock::VerifyAndClearExpectations(compositor.get());
}
std::shared_ptr performance_booster{
std::make_shared>()};
std::shared_ptr screen_hardware{
std::make_shared>()};
std::shared_ptr compositor{
std::make_shared>()};
std::shared_ptr display{
std::make_shared>()};
std::shared_ptr touch_visualizer{
std::make_shared>()};
std::shared_ptr timer{
std::make_shared()};
usc::MirScreen mir_screen{
performance_booster,
screen_hardware,
compositor,
display,
touch_visualizer,
timer,
timer,
{power_off_timeout, dimmer_timeout},
{notification_power_off_timeout, notification_dimmer_timeout},
{call_power_off_timeout, call_dimmer_timeout}};
};
struct AParameterizedMirScreen : public AMirScreen, public ::testing::WithParamInterface {};
struct ImmediatePowerOnMirScreen : public AParameterizedMirScreen {};
struct DeferredPowerOnMirScreen : public AParameterizedMirScreen {};
}
TEST_P(ImmediatePowerOnMirScreen, enables_performance_boost_for_screen_on)
{
turn_screen_off();
expect_performance_boost_is_enabled();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, GetParam());
}
TEST_P(DeferredPowerOnMirScreen, enables_performance_boost_for_screen_on_with_reason_proximity)
{
turn_screen_off();
expect_performance_boost_is_enabled();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, GetParam());
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, PowerStateChangeReason::proximity);
}
TEST_P(AParameterizedMirScreen, disables_performance_boost_for_screen_off)
{
turn_screen_on();
expect_performance_boost_is_disabled();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off, GetParam());
}
INSTANTIATE_TEST_CASE_P(
AParameterizedMirScreen,
AParameterizedMirScreen,
::testing::Values(PowerStateChangeReason::unknown, PowerStateChangeReason::inactivity, PowerStateChangeReason::power_key,
PowerStateChangeReason::proximity, PowerStateChangeReason::notification, PowerStateChangeReason::snap_decision,
PowerStateChangeReason::call_done));
INSTANTIATE_TEST_CASE_P(
ImmediatePowerOnMirScreen,
ImmediatePowerOnMirScreen,
::testing::Values(PowerStateChangeReason::unknown, PowerStateChangeReason::inactivity, PowerStateChangeReason::power_key));
INSTANTIATE_TEST_CASE_P(
DeferredPowerOnMirScreen,
DeferredPowerOnMirScreen,
::testing::Values(PowerStateChangeReason::notification, PowerStateChangeReason::snap_decision, PowerStateChangeReason::call_done));
TEST_F(AMirScreen, turns_screen_off_after_power_off_timeout)
{
expect_screen_is_turned_off();
timer->advance_by(power_off_timeout);
}
TEST_F(AMirScreen, dims_screen_after_dim_timeout)
{
expect_screen_is_turned_dim();
timer->advance_by(dimmer_timeout);
}
TEST_F(AMirScreen, keeps_display_on_while_already_on)
{
using namespace testing;
expect_no_reconfiguration();
mir_screen.keep_display_on(true);
timer->advance_by(power_off_timeout);
}
TEST_F(AMirScreen, turns_and_keeps_display_on_while_off)
{
using namespace testing;
turn_screen_off();
expect_screen_is_turned_on();
mir_screen.keep_display_on(true);
verify_and_clear_expectations();
expect_no_reconfiguration();
timer->advance_by(power_off_timeout);
}
TEST_F(AMirScreen, does_not_turn_on_screen_temporarily_when_off)
{
using namespace testing;
turn_screen_off();
expect_no_reconfiguration();
mir_screen.keep_display_on_temporarily();
}
TEST_F(AMirScreen, keeps_screen_on_temporarily_when_already_on)
{
using namespace testing;
std::chrono::seconds const fourty_seconds{40};
std::chrono::seconds const ten_seconds{10};
expect_no_reconfiguration();
// After keep_display_on_temporarily the timeouts should
// be reset...
timer->advance_by(fourty_seconds);
mir_screen.keep_display_on_temporarily();
// ... so 40 seconds after the reset (total 80 from start)
// should trigger neither dim nor power off
timer->advance_by(fourty_seconds);
verify_and_clear_expectations();
// Tens seconds more, 50 seconds from reset, the screen should dim
expect_screen_is_turned_dim();
timer->advance_by(ten_seconds);
verify_and_clear_expectations();
// Ten seconds second more, 60 seconds from reset, the screen should power off
expect_screen_is_turned_off();
timer->advance_by(ten_seconds);
verify_and_clear_expectations();
}
TEST_F(AMirScreen, disabling_inactivity_timers_disables_dim_and_power_off)
{
using namespace testing;
expect_no_reconfiguration();
mir_screen.enable_inactivity_timers(false);
timer->advance_by(power_off_timeout);
}
TEST_F(AMirScreen, set_screen_power_mode_from_on_to_off)
{
expect_screen_is_turned_off();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key);
}
TEST_F(AMirScreen, set_screen_power_mode_from_off_to_on)
{
turn_screen_off();
expect_screen_is_turned_on();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
}
TEST_F(AMirScreen, sets_hardware_brightness)
{
int const brightness{10};
EXPECT_CALL(*screen_hardware, set_brightness(brightness));
mir_screen.set_brightness(brightness);
}
TEST_F(AMirScreen, sets_hardware_auto_brightness)
{
bool const enable{true};
EXPECT_CALL(*screen_hardware, enable_auto_brightness(enable));
mir_screen.enable_auto_brightness(enable);
}
TEST_F(AMirScreen, forwards_touch_visualizations_requests_to_touch_visualizer)
{
using namespace testing;
InSequence s;
EXPECT_CALL(*touch_visualizer, enable());
EXPECT_CALL(*touch_visualizer, disable());
mir_screen.set_touch_visualization_enabled(true);
mir_screen.set_touch_visualization_enabled(false);
}
TEST_F(AMirScreen, invokes_handler_when_power_state_changes)
{
using namespace testing;
auto handler_reason = PowerStateChangeReason::unknown;
auto handler_mode = mir_power_mode_standby;
auto handler =
[&] (MirPowerMode mode, PowerStateChangeReason reason)
{
handler_mode = mode;
handler_reason = reason;
};
mir_screen.register_power_state_change_handler(handler);
auto const toggle_reason = PowerStateChangeReason::power_key;
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key);
EXPECT_THAT(handler_reason, Eq(toggle_reason));
EXPECT_THAT(handler_mode, Eq(MirPowerMode::mir_power_mode_off));
}
TEST_F(AMirScreen, turns_screen_off_after_notification_timeout)
{
turn_screen_off();
expect_screen_is_turned_on();
receive_notification();
verify_and_clear_expectations();
expect_screen_is_turned_off();
timer->advance_by(notification_power_off_timeout);
}
TEST_F(AMirScreen, keep_display_on_temporarily_overrides_notification_timeout)
{
turn_screen_off();
expect_screen_is_turned_on();
receive_notification();
verify_and_clear_expectations();
// At T=10 we request a temporary keep display on (e.g. user has touched
// the screen)
timer->advance_by(ten_seconds);
mir_screen.keep_display_on_temporarily();
// At T=20 nothing should happen since keep display on temporarily
// has reset the timers (so the notification timeout of 15s is overriden).
expect_no_reconfiguration();
timer->advance_by(ten_seconds);
verify_and_clear_expectations();
// At T=70 (10 + 60) the screen should turn off due to the normal
// inactivity timeout
expect_screen_is_turned_off();
timer->advance_by(fifty_seconds);
}
TEST_F(AMirScreen, notification_timeout_extends_active_timeout)
{
// At T=0 we turn the screen on, and normal inactivity timeouts
// are reset
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
// At T=50 we get a notification
timer->advance_by(fifty_seconds);
receive_notification();
verify_and_clear_expectations();
// At T=60 the screen should still be active because the notification
// has extended the timeout.
expect_no_reconfiguration();
timer->advance_by(ten_seconds);
verify_and_clear_expectations();
// At T=65 (50 + 15) the screen should turn off due to the notification
// inactivity timeout
expect_screen_is_turned_off();
timer->advance_by(five_seconds);
}
TEST_F(AMirScreen, notification_timeout_does_not_reduce_active_timeout)
{
// At T=0 we turn the screen on, and normal inactivity timeouts
// are reset
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
// At T=30 we get a notification
timer->advance_by(thirty_seconds);
receive_notification();
verify_and_clear_expectations();
// At T=45 the screen should still be active because the notification
// has not reduced the active timeout.
expect_no_reconfiguration();
timer->advance_by(fifteen_seconds);
verify_and_clear_expectations();
// At T=50 the screen should be dimmed
expect_screen_is_turned_dim();
timer->advance_by(five_seconds);
verify_and_clear_expectations();
// At T=60 the screen should turn off due to the normal
// inactivity timeout
expect_screen_is_turned_off();
timer->advance_by(ten_seconds);
}
TEST_F(AMirScreen, notification_timeout_can_extend_only_dimming)
{
std::chrono::seconds const two_seconds{2};
std::chrono::seconds const eight_seconds{8};
// At T=0 we turn the screen on, and normal inactivity timeouts
// are reset
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
// At T=40 we get a notification
timer->advance_by(fourty_seconds);
receive_notification();
verify_and_clear_expectations();
// At T=50 nothing should happen since the notification has
// extended the dimming timeout
expect_no_reconfiguration();
timer->advance_by(ten_seconds);
verify_and_clear_expectations();
// At T=52 (40 + 12) screen should be dimmed due to the notification
// dimming timeout
expect_screen_is_turned_dim();
timer->advance_by(two_seconds);
verify_and_clear_expectations();
// At T=60 the screen should turn off due to the normal
// inactivity timeout
expect_screen_is_turned_off();
timer->advance_by(eight_seconds);
}
TEST_F(AMirScreen, proximity_requests_affect_screen_state)
{
expect_screen_is_turned_off();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_screen_is_turned_on();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
}
TEST_F(AMirScreen, proximity_requests_use_short_timeouts)
{
// At T=0 we turn the screen on, and normal inactivity timeouts
// are reset
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
// At T=30 we get a screen off request due to proximity
timer->advance_by(thirty_seconds);
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
// At T=40 we get a screen on request due to proximity
timer->advance_by(ten_seconds);
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
// At T=52 screen should be dimmed due to the short inactivity
// dimming timeout
expect_screen_is_turned_dim();
timer->advance_by(notification_dimmer_timeout);
verify_and_clear_expectations();
// At T=55 the screen should turn off due to the short
// inactivity timeout
expect_screen_is_turned_off();
timer->advance_by(std::chrono::seconds{3});
}
TEST_F(AMirScreen, does_not_turn_on_screen_when_notification_arrives_with_phone_covered)
{
turn_screen_off();
cover_screen();
expect_no_reconfiguration();
receive_notification();
}
TEST_F(AMirScreen, turns_screen_on_when_phone_is_uncovered_after_notification_arrives)
{
turn_screen_off();
cover_screen();
expect_no_reconfiguration();
receive_notification();
verify_and_clear_expectations();
expect_screen_is_turned_on();
uncover_screen();
}
TEST_F(AMirScreen, cancels_proximity_handling_when_phone_is_turned_off_after_notification)
{
turn_screen_off();
cover_screen();
receive_notification();
timer->advance_by(notification_power_off_timeout);
verify_and_clear_expectations();
expect_no_reconfiguration();
uncover_screen();
cover_screen();
}
TEST_F(AMirScreen, cancels_proximity_handling_when_screen_is_touched_after_notification)
{
turn_screen_off();
receive_notification();
mir_screen.keep_display_on_temporarily();
verify_and_clear_expectations();
expect_no_reconfiguration();
cover_screen();
uncover_screen();
}
TEST_F(AMirScreen, does_not_enable_proximity_handling_for_notification_when_screen_is_already_on)
{
expect_no_reconfiguration();
receive_notification();
verify_and_clear_expectations();
expect_no_reconfiguration();
cover_screen();
uncover_screen();
}
TEST_F(AMirScreen, does_not_allow_proximity_to_turn_on_screen_not_turned_off_by_proximity)
{
turn_screen_off();
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
}
TEST_F(AMirScreen, does_not_allow_proximity_to_turn_on_screen_not_turned_off_by_proximity_2)
{
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key);
verify_and_clear_expectations();
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
}
TEST_F(AMirScreen, proximity_can_affect_screen_after_keep_display_on)
{
mir_screen.keep_display_on(true);
expect_screen_is_turned_off();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_screen_is_turned_on();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
}
TEST_F(AMirScreen, disables_active_timeout_when_setting_zero_inactivity_timeouts)
{
std::chrono::hours const ten_hours{10};
expect_no_reconfiguration();
mir_screen.set_inactivity_timeouts(0, 0);
timer->advance_by(ten_hours);
verify_and_clear_expectations();
}
TEST_F(AMirScreen, notification_timeout_is_ignored_if_inactivity_timeouts_are_zero)
{
std::chrono::hours const ten_hours{10};
expect_no_reconfiguration();
mir_screen.set_inactivity_timeouts(0, 0);
receive_notification();
timer->advance_by(ten_hours);
verify_and_clear_expectations();
}
TEST_F(AMirScreen, notification_timeout_is_respected_when_screen_is_off_if_inactivity_timeouts_are_zero)
{
mir_screen.set_inactivity_timeouts(0, 0);
turn_screen_off();
receive_notification();
verify_and_clear_expectations();
expect_screen_is_turned_off();
timer->advance_by(notification_power_off_timeout);
verify_and_clear_expectations();
}
TEST_F(AMirScreen, keep_display_on_temporarily_after_notification_keeps_display_on_forever_if_inactivity_timeouts_are_zero)
{
std::chrono::hours const ten_hours{10};
mir_screen.set_inactivity_timeouts(0, 0);
turn_screen_off();
receive_notification();
verify_and_clear_expectations();
expect_no_reconfiguration();
mir_screen.keep_display_on_temporarily();
timer->advance_by(ten_hours);
verify_and_clear_expectations();
}
TEST_F(AMirScreen, proximity_can_turn_on_screen_after_power_off_timeout_occurs_when_screen_is_off)
{
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
timer->advance_by(power_off_timeout);
expect_screen_is_turned_on();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_screen_is_turned_off();
timer->advance_by(power_off_timeout);
}
TEST_F(AMirScreen, proximity_can_turn_on_screen_after_power_off_timeout_occurs_when_screen_is_on)
{
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_screen_is_turned_off();
timer->advance_by(power_off_timeout);
verify_and_clear_expectations();
expect_screen_is_turned_on();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_screen_is_turned_off();
timer->advance_by(notification_power_off_timeout);
}
TEST_F(AMirScreen, proximity_cannot_turn_on_screen_if_power_key_turned_it_off)
{
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key);
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key);
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(
MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::proximity);
verify_and_clear_expectations();
expect_no_reconfiguration();
mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::proximity);
}
TEST_F(AMirScreen, turns_screen_off_after_call_timeout)
{
turn_screen_off();
expect_screen_is_turned_on();
receive_call();
verify_and_clear_expectations();
expect_screen_is_turned_off();
timer->advance_by(call_power_off_timeout);
}
TEST_F(AMirScreen, keep_display_on_temporarily_overrides_call_timeout)
{
turn_screen_off();
expect_screen_is_turned_on();
receive_call();
verify_and_clear_expectations();
// At T=20 we request a temporary keep display on (e.g. user has touched
// the screen)
timer->advance_by(ten_seconds);
timer->advance_by(ten_seconds);
mir_screen.keep_display_on_temporarily();
// At T=30 nothing should happen since keep display on temporarily
// has reset the timers (so the call timeout is overriden).
expect_no_reconfiguration();
timer->advance_by(ten_seconds);
verify_and_clear_expectations();
// At T=110 (50 + 60) the screen should turn off due to the normal
// inactivity timeout
expect_screen_is_turned_off();
timer->advance_by(fifty_seconds);
}
TEST_F(AMirScreen, does_not_turn_on_screen_when_call_arrives_with_phone_covered)
{
turn_screen_off();
cover_screen();
expect_no_reconfiguration();
receive_call();
}
TEST_F(AMirScreen, enables_proximity_when_call_arrives)
{
turn_screen_off();
cover_screen();
expect_no_reconfiguration();
receive_call();
verify_and_clear_expectations();
verify_proximity_enabled();
}
TEST_F(AMirScreen, cancels_proximity_handling_when_screen_is_turned_off_by_call_timeout)
{
turn_screen_off();
cover_screen();
receive_call();
timer->advance_by(call_power_off_timeout);
verify_proximity_disabled();
}
TEST_F(AMirScreen, cancels_proximity_handling_when_screen_is_touched_after_call)
{
turn_screen_off();
receive_call();
mir_screen.keep_display_on_temporarily();
verify_proximity_disabled();
}
TEST_F(AMirScreen, does_not_enable_proximity_handling_for_call_when_screen_is_already_on)
{
expect_no_reconfiguration();
receive_call();
verify_and_clear_expectations();
verify_proximity_disabled();
}
TEST_F(AMirScreen, retains_proximity_handling_when_call_done_arrives_when_screen_is_off_after_call)
{
turn_screen_off();
cover_screen();
receive_call();
receive_call_done();
verify_proximity_enabled();
}
TEST_F(AMirScreen,
turns_off_screen_and_proximity_soon_after_call_when_screen_not_covered)
{
turn_screen_off();
// Call
receive_call();
timer->advance_by(ten_seconds);
receive_call_done();
verify_and_clear_expectations();
// After the notification timeout the screen should be off
// and proximity should be disabled
expect_screen_is_turned_off();
timer->advance_by(notification_power_off_timeout);
verify_proximity_disabled();
}
TEST_F(AMirScreen,
turns_proximity_off_soon_after_call_when_screen_covered)
{
turn_screen_off();
cover_screen();
expect_no_reconfiguration();
// call
receive_call();
timer->advance_by(ten_seconds);
receive_call_done();
timer->advance_by(notification_power_off_timeout);
verify_and_clear_expectations();
verify_proximity_disabled();
}
TEST_F(AMirScreen,
turns_off_screen_and_proximity_soon_after_call_when_screen_uncovered_after_call_is_received)
{
turn_screen_off();
cover_screen();
// Uncover screen while in call
receive_call();
timer->advance_by(five_seconds);
uncover_screen();
timer->advance_by(five_seconds);
receive_call_done();
verify_and_clear_expectations();
// After the notification timeout the screen should be off
// and proximity should be disabled
expect_screen_is_turned_off();
timer->advance_by(notification_power_off_timeout);
verify_proximity_disabled();
}
TEST_F(AMirScreen,
keeps_screen_on_for_full_timeout_after_call_received_when_screen_was_turned_on_manually)
{
// Turn screen on manually (i.e. with power key)
turn_screen_off();
turn_screen_on();
expect_no_reconfiguration();
// call
receive_call();
timer->advance_by(ten_seconds);
receive_call_done();
// Call done notification timeout should be ignored since
// user had turned on the screen manually
timer->advance_by(notification_power_off_timeout);
verify_and_clear_expectations();
verify_proximity_disabled();
}
TEST_F(AMirScreen,
sets_normal_backlight_when_notification_arrives_while_screen_already_on)
{
turn_screen_on();
EXPECT_CALL(*screen_hardware, set_normal_backlight());
receive_notification();
}
TEST_F(AMirScreen,
sets_normal_backlight_when_call_arrives_while_screen_already_on)
{
turn_screen_on();
EXPECT_CALL(*screen_hardware, set_normal_backlight());
receive_call();
}
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/fake_shared.h 0000644 0000156 0000165 00000001625 12674474272 026656 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2013-2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alan Griffiths
*/
#ifndef USC_TEST_FAKE_SHARED_H_
#define USC_TEST_FAKE_SHARED_H_
#include
namespace usc
{
namespace test
{
template
std::shared_ptr fake_shared(Type& t) { return {&t, [](void*){}}; }
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/test_screen_event_handler.cpp 0000644 0000156 0000165 00000024367 12674474272 032201 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "src/screen_event_handler.h"
#include "src/power_state_change_reason.h"
#include "src/screen.h"
#include "advanceable_timer.h"
#include "fake_shared.h"
#include
#include
#include
#include "linux/input.h"
#include
namespace
{
struct MockScreen : usc::Screen
{
MOCK_METHOD1(enable_inactivity_timers, void(bool enable));
MOCK_METHOD0(keep_display_on_temporarily, void());
MirPowerMode get_screen_power_mode() override {return mock_mode;}
MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason));
MOCK_METHOD1(keep_display_on, void(bool on));
MOCK_METHOD1(set_brightness, void(int brightness));
MOCK_METHOD1(enable_auto_brightness, void(bool enable));
MOCK_METHOD2(set_inactivity_timeouts, void(int power_off_timeout, int dimmer_timeout));
MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled));
MOCK_METHOD1(register_power_state_change_handler, void(
usc::PowerStateChangeHandler const& handler));
MirPowerMode mock_mode = MirPowerMode::mir_power_mode_off;
};
struct AScreenEventHandler : testing::Test
{
void press_power_key()
{
screen_event_handler.handle(*power_key_down_event);
}
void release_power_key()
{
screen_event_handler.handle(*power_key_up_event);
}
void press_a_key()
{
screen_event_handler.handle(*another_key_down_event);
}
void press_volume_keys()
{
screen_event_handler.handle(*vol_plus_key_down_event);
screen_event_handler.handle(*vol_plus_key_up_event);
screen_event_handler.handle(*vol_minus_key_down_event);
screen_event_handler.handle(*vol_minus_key_up_event);
}
void touch_screen()
{
screen_event_handler.handle(*touch_event);
}
void move_pointer()
{
screen_event_handler.handle(*pointer_event);
}
mir::EventUPtr power_key_down_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_down,
0, KEY_POWER, mir_input_event_modifier_none);
mir::EventUPtr power_key_up_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_up,
0, KEY_POWER, mir_input_event_modifier_none);
mir::EventUPtr vol_plus_key_down_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_down,
0, KEY_VOLUMEUP, mir_input_event_modifier_none);
mir::EventUPtr vol_plus_key_up_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_up,
0, KEY_VOLUMEUP, mir_input_event_modifier_none);
mir::EventUPtr vol_minus_key_down_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_down,
0, KEY_VOLUMEDOWN, mir_input_event_modifier_none);
mir::EventUPtr vol_minus_key_up_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_up,
0, KEY_VOLUMEDOWN, mir_input_event_modifier_none);
mir::EventUPtr another_key_down_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_down,
0, KEY_A, mir_input_event_modifier_none);
mir::EventUPtr another_key_up_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_keyboard_action_up,
0, KEY_A, mir_input_event_modifier_none);
mir::EventUPtr touch_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_input_event_modifier_none);
mir::EventUPtr pointer_event = mir::events::make_event(
MirInputDeviceId{1}, std::chrono::nanoseconds(0),
std::vector{}, mir_input_event_modifier_none,
mir_pointer_action_motion,
{}, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
AdvanceableTimer timer;
std::chrono::milliseconds const power_key_ignore_timeout{5000};
std::chrono::milliseconds const shutdown_timeout{10000};
std::chrono::milliseconds const normal_press_duration{100};
testing::NiceMock mock_screen;
std::atomic shutdown_called{false};
usc::ScreenEventHandler screen_event_handler{
usc::test::fake_shared(mock_screen),
usc::test::fake_shared(timer),
power_key_ignore_timeout,
shutdown_timeout,
[&] { shutdown_called = true; }};
};
}
TEST_F(AScreenEventHandler, turns_screen_on_immediately_on_press)
{
auto const long_press_duration = power_key_ignore_timeout;
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key));
press_power_key();
}
TEST_F(AScreenEventHandler, shuts_down_system_when_power_key_pressed_for_long_enough)
{
using namespace testing;
std::chrono::milliseconds const one_ms{1};
press_power_key();
timer.advance_by(shutdown_timeout - one_ms);
ASSERT_FALSE(shutdown_called);
timer.advance_by(one_ms);
ASSERT_TRUE(shutdown_called);
}
TEST_F(AScreenEventHandler, turns_screen_off_when_shutting_down)
{
press_power_key();
testing::InSequence s;
// First, screen turns on from long press
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key));
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key));
timer.advance_by(shutdown_timeout);
}
TEST_F(AScreenEventHandler, keeps_display_on_temporarily_on_touch_event)
{
EXPECT_CALL(mock_screen, keep_display_on_temporarily());
touch_screen();
}
TEST_F(AScreenEventHandler, turns_on_screen_and_filters_first_pointer_event_when_screen_is_off)
{
mock_screen.mock_mode = MirPowerMode::mir_power_mode_off;
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::unknown));
auto const event_filtered = screen_event_handler.handle(*pointer_event);
EXPECT_TRUE(event_filtered);
}
TEST_F(AScreenEventHandler, turns_on_screen_and_propagates_keys_when_screen_is_off)
{
mock_screen.mock_mode = MirPowerMode::mir_power_mode_off;
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::unknown));
auto const event_filtered = screen_event_handler.handle(*another_key_down_event);
EXPECT_FALSE(event_filtered);
}
TEST_F(AScreenEventHandler, keeps_display_on_temporarily_for_pointer_event_when_screen_is_on)
{
mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
EXPECT_CALL(mock_screen, keep_display_on_temporarily());
move_pointer();
}
TEST_F(AScreenEventHandler, keeps_display_on_temporarily_key_event_when_screen_is_on)
{
mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
EXPECT_CALL(mock_screen, keep_display_on_temporarily());
press_a_key();
}
TEST_F(AScreenEventHandler, does_not_affect_screen_state_for_volume_keys)
{
using namespace testing;
EXPECT_CALL(mock_screen, keep_display_on_temporarily()).Times(0);
EXPECT_CALL(mock_screen, set_screen_power_mode(_,_)).Times(0);
press_volume_keys();
}
TEST_F(AScreenEventHandler, sets_screen_mode_off_normal_press_release)
{
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_off,
PowerStateChangeReason::power_key));
mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
press_power_key();
timer.advance_by(normal_press_duration);
release_power_key();
}
TEST_F(AScreenEventHandler, does_not_set_screen_mode_off_long_press_release)
{
using namespace testing;
auto const long_press_duration = power_key_ignore_timeout;
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_on,
PowerStateChangeReason::power_key));
EXPECT_CALL(mock_screen,
set_screen_power_mode(MirPowerMode::mir_power_mode_off, _))
.Times(0);
mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
press_power_key();
timer.advance_by(long_press_duration);
release_power_key();
}
TEST_F(AScreenEventHandler, passes_through_all_handled_events_when_screen_is_on)
{
using namespace testing;
mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
EXPECT_FALSE(screen_event_handler.handle(*power_key_down_event));
EXPECT_FALSE(screen_event_handler.handle(*power_key_up_event));
EXPECT_FALSE(screen_event_handler.handle(*touch_event));
EXPECT_FALSE(screen_event_handler.handle(*pointer_event));
}
TEST_F(AScreenEventHandler, disables_inactivity_timers_on_power_key_down)
{
EXPECT_CALL(mock_screen, enable_inactivity_timers(false));
press_power_key();
}
TEST_F(AScreenEventHandler, enables_inactivity_timers_on_power_key_up_when_turning_screen_on)
{
press_power_key();
timer.advance_by(normal_press_duration);
EXPECT_CALL(mock_screen, enable_inactivity_timers(true));
release_power_key();
}
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/advanceable_timer.h 0000644 0000156 0000165 00000003253 12674474272 030046 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef USC_TESTS_ADVANCEABLE_TIMER_H_
#define USC_TESTS_ADVANCEABLE_TIMER_H_
#include
#include "src/clock.h"
#include
#include
#include
namespace detail
{
class AdvanceableAlarm;
}
class AdvanceableTimer : public mir::time::AlarmFactory, public usc::Clock
{
public:
// mir::time::AlarmFactory
std::unique_ptr create_alarm(
std::function const& callback) override;
std::unique_ptr create_alarm(
std::shared_ptr const& callback) override;
// usc::Clock
mir::time::Timestamp now() const override;
void advance_by(std::chrono::milliseconds advance);
private:
void register_alarm(std::shared_ptr const& alarm);
void trigger_alarms();
mutable std::mutex now_mutex;
mir::time::Timestamp now_{};
std::mutex alarms_mutex;
std::vector> alarms;
};
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/advanceable_timer.cpp 0000644 0000156 0000165 00000013333 12674474272 030401 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "advanceable_timer.h"
#include
#include
namespace
{
struct AlarmWrapper : mir::time::Alarm
{
AlarmWrapper(
std::shared_ptr const& alarm)
: wrapped_alarm{alarm}
{
}
bool cancel() override
{
return wrapped_alarm->cancel();
}
mir::time::Alarm::State state() const override
{
return wrapped_alarm->state();
}
bool reschedule_in(std::chrono::milliseconds delay) override
{
return wrapped_alarm->reschedule_in(delay);
}
bool reschedule_for(mir::time::Timestamp t) override
{
return wrapped_alarm->reschedule_for(t);
}
std::shared_ptr const wrapped_alarm;
};
};
struct detail::AdvanceableAlarm : mir::time::Alarm
{
AdvanceableAlarm(
mir::time::Timestamp now,
std::shared_ptr const& callback)
: now{now}, callback{callback}
{
}
bool cancel() override
{
std::lock_guard lock{mutex};
state_ = mir::time::Alarm::cancelled;
return true;
}
mir::time::Alarm::State state() const override
{
std::lock_guard lock{mutex};
return state_;
}
bool reschedule_in(std::chrono::milliseconds delay) override
{
std::lock_guard lock{mutex};
next_trigger_ = now + delay;
state_ = mir::time::Alarm::pending;
return true;
}
bool reschedule_for(mir::time::Timestamp t) override
{
std::lock_guard lock{mutex};
next_trigger_ = t;
state_ = mir::time::Alarm::pending;
return true;
}
void update_now(mir::time::Timestamp t)
{
std::unique_lock lock{mutex};
now = t;
if (state_ == mir::time::Alarm::pending && now >= next_trigger_)
{
state_ = mir::time::Alarm::triggered;
lock.unlock();
callback->lock();
(*callback)();
callback->unlock();
}
}
mir::time::Timestamp next_trigger()
{
std::lock_guard lock{mutex};
return next_trigger_;
}
private:
mir::time::Timestamp now;
std::shared_ptr const callback;
mir::time::Timestamp next_trigger_;
mutable std::mutex mutex;
mir::time::Alarm::State state_ = mir::time::Alarm::triggered;
};
std::unique_ptr AdvanceableTimer::create_alarm(
std::function const& callback)
{
struct SimpleLockableCallback : public mir::LockableCallback
{
SimpleLockableCallback(std::function const& callback)
: callback{callback}
{
}
void operator()() override { callback(); }
void lock() override {}
void unlock() override {}
std::function const callback;
};
return create_alarm(std::make_shared(callback));
}
std::unique_ptr AdvanceableTimer::create_alarm(
std::shared_ptr const& callback)
{
auto const adv_alarm =
std::make_shared(now(), callback);
register_alarm(adv_alarm);
return std::unique_ptr(new AlarmWrapper{adv_alarm});
}
void AdvanceableTimer::advance_by(std::chrono::milliseconds advance)
{
{
std::lock_guard lock{now_mutex};
now_ += advance;
}
trigger_alarms();
}
void AdvanceableTimer::register_alarm(
std::shared_ptr const& alarm)
{
std::lock_guard lock{alarms_mutex};
alarms.push_back(alarm);
}
void AdvanceableTimer::trigger_alarms()
{
std::unique_lock lock{alarms_mutex};
// sort by trigger time
std::sort(begin(alarms), end(alarms),
[] (std::weak_ptr const& weak_a1,
std::weak_ptr const& weak_a2)
{
auto a1 = weak_a1.lock();
auto a2 = weak_a2.lock();
if (a1 && a2)
{
if (a1->next_trigger() == a2->next_trigger())
return weak_a1.owner_before(weak_a2);
else
return a1->next_trigger() < a2->next_trigger();
}
else
return weak_a1.owner_before(weak_a2);
});
for (auto& weak_alarm : alarms)
{
auto const alarm = weak_alarm.lock();
if (alarm)
{
lock.unlock();
alarm->update_now(now());
lock.lock();
}
}
alarms.erase(
std::remove_if(
begin(alarms), end(alarms),
[](std::weak_ptr const& alarm)
{
return alarm.expired();
}),
end(alarms));
}
mir::time::Timestamp AdvanceableTimer::now() const
{
std::lock_guard lock{now_mutex};
return now_;
}
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/CMakeLists.txt 0000644 0000156 0000165 00000002212 12674474272 027002 0 ustar pbuser pbgroup 0000000 0000000 # Copyright © 2014 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# Authored by: Alexandros Frantzis
include_directories(
${CMAKE_SOURCE_DIR}
${MIRSERVER_INCLUDE_DIRS}
)
add_executable(
usc_unit_tests
test_session_switcher.cpp
test_screen_event_handler.cpp
test_mir_screen.cpp
test_mir_input_configuration.cpp
advanceable_timer.cpp
)
target_link_libraries(
usc_unit_tests
usc
${GTEST_BOTH_LIBRARIES}
${GMOCK_LIBRARY}
${GMOCK_MAIN_LIBRARY}
)
add_test(usc_unit_tests ${EXECUTABLE_OUTPUT_PATH}/usc_unit_tests)
add_dependencies(usc_unit_tests GMock)
unity-system-compositor-0.4.3+16.04.20160323/tests/unit-tests/test_session_switcher.cpp 0000644 0000156 0000165 00000050362 12674474272 031411 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2014-2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "src/session_switcher.h"
#include "src/spinner.h"
#include "mir/frontend/session.h"
#include
#include
#include
#include
#include
namespace
{
class FakeScene
{
public:
void add(usc::Session* session)
{
sessions.emplace_back(session, false);
}
void remove(usc::Session* session)
{
sessions.erase(find(session));
}
void show(usc::Session* session)
{
find(session)->second = true;
}
void hide(usc::Session* session)
{
find(session)->second = false;
}
void raise(usc::Session* session)
{
auto const iter = find(session);
auto const pair = *iter;
sessions.erase(iter);
sessions.push_back(pair);
}
std::vector displayed_sessions()
{
std::vector ret;
for (auto const& pair : sessions)
{
bool session_visible = pair.second;
if (session_visible)
ret.push_back(pair.first->name());
}
return ret;
}
private:
std::vector> sessions;
decltype(sessions)::iterator find(usc::Session* session)
{
return std::find_if(
sessions.begin(), sessions.end(),
[session] (decltype(sessions)::value_type const& p)
{
return p.first == session;
});
}
};
class StubMirSession : public mir::frontend::Session
{
public:
StubMirSession(std::string const& name)
: name_{name}
{}
std::shared_ptr get_surface(mir::frontend::SurfaceId surface) const override { return nullptr; }
mir::frontend::BufferStreamId create_buffer_stream(mir::graphics::BufferProperties const& /*props*/) override { return {}; }
std::shared_ptr get_buffer_stream(mir::frontend::BufferStreamId /*stream*/) const override { return nullptr; }
void destroy_buffer_stream(mir::frontend::BufferStreamId /*stream*/) override {}
std::string name() const override { return name_; }
private:
std::string const name_;
};
class StubSession : public usc::Session
{
public:
StubSession(FakeScene& fake_scene, std::string const& name)
: mir_stub_session{std::make_shared(name)},
fake_scene(fake_scene)
{
fake_scene.add(this);
}
~StubSession()
{
fake_scene.remove(this);
}
std::string name() override
{
return mir_stub_session->name();
}
void show() override
{
fake_scene.show(this);
}
void hide() override
{
fake_scene.hide(this);
}
void raise_and_focus() override
{
fake_scene.raise(this);
}
bool corresponds_to(mir::frontend::Session const* s) override
{
return s == mir_stub_session.get();
}
std::shared_ptr corresponding_session()
{
return mir_stub_session;
}
private:
std::shared_ptr const mir_stub_session;
FakeScene& fake_scene;
};
struct StubSpinner : usc::Spinner
{
void ensure_running() override { is_running_ = true; }
void kill() override { is_running_ = false; }
pid_t pid() override { return pid_; }
void set_pid(pid_t new_pid) { pid_ = new_pid; }
bool is_running() { return is_running_; }
private:
bool is_running_ = false;
pid_t pid_ = 666;
};
struct ASessionSwitcher : testing::Test
{
std::shared_ptr create_stub_session(std::string const& name)
{
return std::make_shared(fake_scene, name);
}
std::tuple,std::shared_ptr> boot()
{
std::string const boot_active_name{"boot_active"};
std::string const boot_next_name{"boot_next"};
auto const boot_active = create_stub_session(boot_active_name);
auto const boot_next = create_stub_session(boot_next_name);
switcher.add(boot_active, active_pid);
switcher.add(boot_next, next_pid);
switcher.set_next_session(boot_next_name);
switcher.set_active_session(boot_active_name);
switcher.mark_ready(boot_active->corresponding_session().get());
switcher.mark_ready(boot_next->corresponding_session().get());
return std::make_tuple(boot_active, boot_next);
}
FakeScene fake_scene;
std::shared_ptr const stub_spinner{std::make_shared()};
usc::SessionSwitcher switcher{stub_spinner};
std::string const active_name{"active"};
std::string const next_name{"next"};
std::string const spinner_name{"spinner"};
pid_t const invalid_pid{0};
pid_t const active_pid{1000};
pid_t const next_pid{1001};
pid_t const other_pid{1002};
};
}
TEST_F(ASessionSwitcher, does_not_display_any_session_if_active_and_next_not_set)
{
using namespace testing;
switcher.add(create_stub_session("s1"), invalid_pid);
switcher.add(create_stub_session("s2"), invalid_pid);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, does_not_display_not_ready_active_session)
{
using namespace testing;
auto const active = create_stub_session(active_name);
switcher.add(active, active_pid);
switcher.set_active_session(active_name);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, does_not_display_not_ready_next_session)
{
using namespace testing;
auto const next = create_stub_session(next_name);
switcher.add(next, next_pid);
switcher.set_next_session(next_name);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, does_not_display_ready_next_session_without_ready_active_session)
{
using namespace testing;
auto const next = create_stub_session(next_name);
switcher.add(next, next_pid);
switcher.set_next_session(next_name);
switcher.mark_ready(next->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher,
does_not_display_any_session_on_boot_if_not_both_active_and_next_are_ready)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.set_active_session(active_name);
switcher.set_next_session(next_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher,
displays_the_active_session_on_boot_if_it_is_ready_and_there_is_no_next_session)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(active_name));
}
TEST_F(ASessionSwitcher, displays_the_active_session_after_boot_if_it_is_ready)
{
using namespace testing;
boot();
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.set_next_session(next_name);
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(active_name));
}
TEST_F(ASessionSwitcher, displays_active_over_next_if_both_are_ready)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.set_next_session(next_name);
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
switcher.mark_ready(next->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(next_name, active_name));
}
TEST_F(ASessionSwitcher, displays_only_active_if_next_equals_active)
{
using namespace testing;
auto const active = create_stub_session(active_name);
switcher.add(active, active_pid);
switcher.set_next_session(active_name);
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(active_name));
}
TEST_F(ASessionSwitcher, displays_only_active_and_next_sessions)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
auto const other = create_stub_session("other");
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.add(other, other_pid);
switcher.set_next_session(next_name);
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
switcher.mark_ready(next->corresponding_session().get());
switcher.mark_ready(other->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(next_name, active_name));
}
TEST_F(ASessionSwitcher, displays_spinner_if_active_is_not_ready)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(spinner_name));
}
TEST_F(ASessionSwitcher, does_not_display_spinner_if_next_is_not_ready)
{
using namespace testing;
auto const next = create_stub_session(next_name);
auto const spinner = create_stub_session(spinner_name);
switcher.add(next, next_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_next_session(next_name);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, displays_only_spinner_when_active_is_not_ready_but_next_is_ready)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
auto const spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
switcher.set_next_session(next_name);
switcher.mark_ready(next->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(spinner_name));
}
TEST_F(ASessionSwitcher,
displays_only_spinner_when_booting_if_not_both_active_and_next_are_ready)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
auto const spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
switcher.set_next_session(next_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(spinner_name));
}
TEST_F(ASessionSwitcher,
displays_spinner_behind_active_after_boot_if_active_is_ready_but_next_is_not_ready)
{
using namespace testing;
boot();
auto const active = create_stub_session(active_name);
auto const next = create_stub_session(next_name);
auto const spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(next, next_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
switcher.set_next_session(next_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(spinner_name, active_name));
}
TEST_F(ASessionSwitcher, starts_and_stops_spinner_as_needed)
{
using namespace testing;
auto const active = create_stub_session(active_name);
switcher.add(active, active_pid);
switcher.set_active_session(active_name);
EXPECT_TRUE(stub_spinner->is_running());
switcher.mark_ready(active->corresponding_session().get());
EXPECT_FALSE(stub_spinner->is_running());
}
TEST_F(ASessionSwitcher, does_not_display_next_when_active_is_removed)
{
using namespace testing;
std::string const no_session_name;
std::shared_ptr boot_active;
std::shared_ptr boot_next;
std::tie(boot_active, boot_next) = boot();
auto const spinner = create_stub_session(spinner_name);
switcher.add(spinner, stub_spinner->pid());
switcher.remove(boot_active->corresponding_session());
switcher.set_active_session(no_session_name);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, displays_only_active_not_spinner_when_next_is_removed)
{
using namespace testing;
std::string const no_session_name;
std::shared_ptr boot_active;
std::shared_ptr boot_next;
std::tie(boot_active, boot_next) = boot();
auto const spinner = create_stub_session(spinner_name);
switcher.add(spinner, stub_spinner->pid());
switcher.remove(boot_next->corresponding_session());
switcher.set_next_session(no_session_name);
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(boot_active->name()));
}
TEST_F(ASessionSwitcher, displays_spinner_when_active_is_removed_unexpectedly)
{
using namespace testing;
std::string const no_session_name;
std::shared_ptr boot_active;
std::shared_ptr boot_next;
std::tie(boot_active, boot_next) = boot();
auto const spinner = create_stub_session(spinner_name);
switcher.add(spinner, stub_spinner->pid());
switcher.remove(boot_active->corresponding_session());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(spinner_name));
}
TEST_F(ASessionSwitcher, displays_spinner_under_active_if_next_is_removed_unexpectedly)
{
using namespace testing;
std::string const no_session_name;
std::shared_ptr boot_active;
std::shared_ptr boot_next;
std::tie(boot_active, boot_next) = boot();
auto const spinner = create_stub_session(spinner_name);
switcher.add(spinner, stub_spinner->pid());
switcher.remove(boot_next->corresponding_session());
EXPECT_THAT(fake_scene.displayed_sessions(),
ElementsAre(spinner_name, boot_active->name()));
}
TEST_F(ASessionSwitcher,
does_not_display_any_session_when_spinner_is_removed_and_no_sessions_are_ready)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(spinner_name));
switcher.remove(spinner->corresponding_session());
spinner.reset();
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, can_handle_spinner_resurrection_under_different_name)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(spinner_name));
switcher.remove(spinner->corresponding_session());
spinner.reset();
std::string const new_spinner_name{"new_spinner_name"};
spinner = create_stub_session(new_spinner_name);
switcher.add(spinner, stub_spinner->pid());
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(new_spinner_name));
}
TEST_F(ASessionSwitcher, can_handle_spinner_resurrection_under_different_pid)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(spinner_name));
switcher.remove(spinner->corresponding_session());
spinner.reset();
pid_t const new_pid{1234};
stub_spinner->set_pid(new_pid);
spinner = create_stub_session(spinner_name);
switcher.add(spinner, stub_spinner->pid());
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(spinner_name));
}
TEST_F(ASessionSwitcher, is_not_confused_by_other_session_with_name_of_dead_spinner)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
switcher.remove(spinner->corresponding_session());
spinner.reset();
stub_spinner->set_pid(invalid_pid);
auto const other = create_stub_session(spinner_name);
switcher.add(other, other_pid);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, is_not_confused_by_other_session_with_pid_of_dead_spinner)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto spinner = create_stub_session(spinner_name);
switcher.add(active, active_pid);
switcher.add(spinner, stub_spinner->pid());
switcher.set_active_session(active_name);
auto const old_spinner_pid = stub_spinner->pid();
stub_spinner->set_pid(invalid_pid);
switcher.remove(spinner->corresponding_session());
spinner.reset();
auto const other = create_stub_session(spinner_name);
switcher.add(other, old_spinner_pid);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
}
TEST_F(ASessionSwitcher, replaces_tracked_session_if_same_session_name_is_used)
{
using namespace testing;
auto const active = create_stub_session(active_name);
auto const other = create_stub_session(active_name);
pid_t const other_pid{2000};
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
switcher.add(active, active_pid);
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(active_name));
switcher.add(other, other_pid);
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(active_name));
}
TEST_F(ASessionSwitcher, ignores_removal_of_untracked_session)
{
using namespace testing;
auto const active = create_stub_session(active_name);
EXPECT_THAT(fake_scene.displayed_sessions(), IsEmpty());
switcher.add(active, active_pid);
switcher.set_active_session(active_name);
switcher.mark_ready(active->corresponding_session().get());
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(active_name));
auto const other = create_stub_session(active_name);
switcher.remove(other->corresponding_session());
EXPECT_THAT(fake_scene.displayed_sessions(), ElementsAre(active_name));
}
unity-system-compositor-0.4.3+16.04.20160323/tests/include/ 0000755 0000156 0000165 00000000000 12674474477 023560 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/include/usc/ 0000755 0000156 0000165 00000000000 12674474477 024352 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/include/usc/test/ 0000755 0000156 0000165 00000000000 12674474477 025331 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/include/usc/test/mock_screen.h 0000644 0000156 0000165 00000003317 12674474272 027767 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#ifndef USC_TEST_MOCK_SCREEN_H_
#define USC_TEST_MOCK_SCREEN_H_
#include "src/screen.h"
#include
#include
namespace usc
{
namespace test
{
struct MockScreen : usc::Screen
{
MOCK_METHOD1(enable_inactivity_timers, void(bool enable));
MOCK_METHOD0(keep_display_on_temporarily, void());
MOCK_METHOD0(get_screen_power_mode, MirPowerMode());
MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason));
MOCK_METHOD1(keep_display_on, void(bool on));
MOCK_METHOD1(set_brightness, void(int brightness));
MOCK_METHOD1(enable_auto_brightness, void(bool enable));
MOCK_METHOD2(set_inactivity_timeouts, void(int power_off_timeout, int dimmer_timeout));
MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled));
void register_power_state_change_handler(
usc::PowerStateChangeHandler const& handler)
{
power_state_change_handler = handler;
}
usc::PowerStateChangeHandler power_state_change_handler;
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/include/usc/test/mock_input_configuration.h 0000644 0000156 0000165 00000003041 12674474272 032570 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#ifndef USC_TEST_MOCK_INPUT_CONFIGURATION_H_
#define USC_TEST_MOCK_INPUT_CONFIGURATION_H_
#include "src/input_configuration.h"
#include
#include
namespace usc
{
namespace test
{
struct MockInputConfiguration : usc::InputConfiguration
{
public:
MOCK_METHOD1(set_mouse_primary_button, void(int32_t));
MOCK_METHOD1(set_mouse_cursor_speed, void(double));
MOCK_METHOD1(set_mouse_scroll_speed, void(double));
MOCK_METHOD1(set_touchpad_primary_button, void(int32_t));
MOCK_METHOD1(set_touchpad_cursor_speed, void(double));
MOCK_METHOD1(set_touchpad_scroll_speed, void(double));
MOCK_METHOD1(set_two_finger_scroll, void(bool));
MOCK_METHOD1(set_tap_to_click, void(bool));
MOCK_METHOD1(set_disable_touchpad_with_mouse, void(bool));
MOCK_METHOD1(set_disable_touchpad_while_typing, void(bool));
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/include/usc/test/mock_display.h 0000644 0000156 0000165 00000004467 12674474272 030164 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef USC_TEST_MOCK_DISPLAY_H
#define USC_TEST_MOCK_DISPLAY_H
#include "usc/test/stub_display_configuration.h"
#include
#include
#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 20, 0)
#include
#endif
#include
namespace usc
{
namespace test
{
struct MockDisplay : mir::graphics::Display
{
void for_each_display_sync_group(std::function const& f) override
{
}
std::unique_ptr configuration() const override
{ return std::make_unique(); }
MOCK_METHOD1(configure, void(mir::graphics::DisplayConfiguration const& conf));
void register_configuration_change_handler(
mir::graphics::EventHandlerRegister& ,
mir::graphics::DisplayConfigurationChangeHandler const& ) override {};
void register_pause_resume_handlers(
mir::graphics::EventHandlerRegister&,
mir::graphics::DisplayPauseHandler const&,
mir::graphics::DisplayResumeHandler const&) override
{
}
void pause() override {};
void resume() override {};
std::shared_ptr create_hardware_cursor(
std::shared_ptr const&) override
{
return {};
};
std::unique_ptr create_gl_context() override
{ return std::unique_ptr{};};
#if MIR_SERVER_VERSION >= MIR_VERSION_NUMBER(0, 20, 0)
std::unique_ptr create_virtual_output(int, int) override
{ return std::unique_ptr{}; }
#endif
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/include/usc/test/stub_display_configuration.h 0000644 0000156 0000165 00000003442 12674474272 033127 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef USC_TEST_STUB_DISPLAY_CONFIGURATION_H_
#define USC_TEST_STUB_DISPLAY_CONFIGURATION_H_
#include
namespace usc
{
namespace test
{
struct StubDisplayConfiguration : mir::graphics::DisplayConfiguration
{
StubDisplayConfiguration()
{
conf_output.power_mode = MirPowerMode::mir_power_mode_on;
}
StubDisplayConfiguration(mir::graphics::DisplayConfigurationOutput const& output)
: conf_output(output)
{
}
void for_each_card(std::function) const override
{
}
void for_each_output(std::function f) const override
{
f(conf_output);
}
void for_each_output(std::function f)
{
mir::graphics::UserDisplayConfigurationOutput user{conf_output};
f(user);
}
std::unique_ptr clone() const override
{
return std::make_unique(conf_output);
}
mir::graphics::DisplayConfigurationOutput conf_output;
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/ 0000755 0000156 0000165 00000000000 12674474477 025620 5 ustar pbuser pbgroup 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/test_unity_services.cpp 0000644 0000156 0000165 00000005414 12674474272 032433 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2016 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#include "src/unity_input_service.h"
#include "src/dbus_connection_handle.h"
#include "src/dbus_connection_thread.h"
#include "src/dbus_event_loop.h"
#include "src/dbus_message_handle.h"
#include "src/unity_screen_service.h"
#include "src/unity_input_service_introspection.h"
#include "src/unity_screen_service_introspection.h"
#include "wait_condition.h"
#include "dbus_bus.h"
#include "dbus_client.h"
#include "unity_input_dbus_client.h"
#include "unity_screen_dbus_client.h"
#include "usc/test/mock_input_configuration.h"
#include "usc/test/mock_screen.h"
namespace ut = usc::test;
using namespace testing;
namespace
{
struct UnityServices : testing::Test
{
std::chrono::seconds const default_timeout{3};
ut::DBusBus bus;
ut::UnityScreenDBusClient screen_client{bus.address()};
ut::UnityInputDBusClient input_client{bus.address()};
std::shared_ptr const mock_screen =
std::make_shared>();
std::shared_ptr const mock_input_configuration =
std::make_shared>();
std::shared_ptr const dbus_loop=
std::make_shared();
usc::UnityScreenService screen_service{dbus_loop, bus.address(), mock_screen};
usc::UnityInputService input_service{dbus_loop, bus.address(), mock_input_configuration};
std::shared_ptr const dbus_thread =
std::make_shared(dbus_loop);
};
}
TEST_F(UnityServices, offer_screen_introspection)
{
auto reply = screen_client.request_introspection();
EXPECT_THAT(reply.get(), Eq(unity_screen_service_introspection));
}
TEST_F(UnityServices, offer_input_introspection)
{
auto reply = input_client.request_introspection();
EXPECT_THAT(reply.get(), Eq(unity_input_service_introspection));
}
TEST_F(UnityServices, provides_access_to_input_methods)
{
double const speed = 8.0;
EXPECT_CALL(*mock_input_configuration, set_mouse_scroll_speed(speed));
input_client.request_set_mouse_scroll_speed(speed);
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/dbus_bus.cpp 0000644 0000156 0000165 00000002522 12674474272 030124 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "dbus_bus.h"
#include "run_command.h"
#include
#include
#include
usc::test::DBusBus::DBusBus()
: pid{0}
{
auto launch = usc::test::run_command(
"dbus-daemon --session --print-address=1 --print-pid=1 --fork");
std::stringstream ss{launch};
std::getline(ss, address_);
ss >> pid;
if (address_.empty())
throw std::runtime_error("Failed to get dbus bus address");
if (pid == 0)
throw std::runtime_error("Failed to get dbus bus pid");
}
usc::test::DBusBus::~DBusBus()
{
kill(pid, SIGTERM);
}
std::string usc::test::DBusBus::address()
{
return address_;
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/run_command.cpp 0000644 0000156 0000165 00000002313 12674474272 030616 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "run_command.h"
#include
#include
#include
std::string usc::test::run_command(std::string const& cmd)
{
auto fp = ::popen(cmd.c_str(), "r");
if (!fp)
BOOST_THROW_EXCEPTION(std::runtime_error("Failed to execute command: " + cmd));
std::string output;
char buffer[64];
while (!std::feof(fp))
{
auto nread = std::fread(buffer, 1, 64, fp);
output.append(buffer, nread);
}
::pclose(fp);
return output;
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/dbus_client.h 0000644 0000156 0000165 00000005015 12674474272 030256 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef USC_TEST_DBUS_CLIENT_H_
#define USC_TEST_DBUS_CLIENT_H_
#include "src/dbus_connection_handle.h"
#include
#include
namespace usc
{
class DBusMessageHandle;
namespace test
{
class DBusAsyncReply
{
public:
DBusAsyncReply(DBusAsyncReply const&) = delete;
DBusAsyncReply& operator=(DBusAsyncReply const&) = delete;
DBusAsyncReply(DBusPendingCall* pending_reply);
DBusAsyncReply(DBusAsyncReply&& other);
~DBusAsyncReply();
usc::DBusMessageHandle get();
protected:
void throw_on_error_reply(::DBusMessage* reply);
void throw_on_invalid_reply(::DBusMessage* reply);
private:
DBusPendingCall* pending_reply = nullptr;
};
class DBusAsyncReplyVoid : DBusAsyncReply
{
public:
using DBusAsyncReply::DBusAsyncReply;
void get();
};
class DBusAsyncReplyInt : DBusAsyncReply
{
public:
using DBusAsyncReply::DBusAsyncReply;
int get();
};
class DBusAsyncReplyBool : DBusAsyncReply
{
public:
using DBusAsyncReply::DBusAsyncReply;
bool get();
};
class DBusAsyncReplyString : DBusAsyncReply
{
public:
using DBusAsyncReply::DBusAsyncReply;
std::string get();
};
class DBusClient
{
public:
DBusClient(
std::string const& bus_address,
std::string const& destination,
std::string const& path);
void disconnect();
template
T invoke_with_reply(
char const* interface, char const* method, int first_arg_type, Args... args)
{
return T{invoke_with_pending(interface, method, first_arg_type, args...)};
}
protected:
DBusPendingCall* invoke_with_pending(
char const* interface, char const* method, int first_arg_type, ...);
usc::DBusConnectionHandle connection;
std::string const destination;
std::string const path;
std::string const interface;
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/test_powerd_mediator.cpp 0000644 0000156 0000165 00000056673 12674474272 032561 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "src/powerd_mediator.h"
#include "src/dbus_connection_handle.h"
#include "src/dbus_message_handle.h"
#include "src/dbus_event_loop.h"
#include "wait_condition.h"
#include "dbus_bus.h"
#include
#include
namespace ut = usc::test;
namespace
{
class PowerdService
{
public:
enum class StartNow { no, yes };
PowerdService(
std::string const& address,
dbus_bool_t auto_brightness_supported,
StartNow start_now)
: auto_brightness_supported{auto_brightness_supported},
connection{std::make_shared(address)},
dbus_event_loop{}
{
dbus_event_loop.add_connection(connection);
if (start_now == StartNow::yes)
start();
}
~PowerdService()
{
dbus_event_loop.stop();
if (dbus_loop_thread.joinable())
dbus_loop_thread.join();
}
void start()
{
ON_CALL(*this, dbus_setUserBrightness(normal_brightness))
.WillByDefault(WakeUp(&initial_setup_done));
connection->request_name(powerd_service_name);
connection->add_filter(handle_dbus_message_thunk, this);
std::promise event_loop_started;
auto event_loop_started_future = event_loop_started.get_future();
dbus_loop_thread = std::thread(
[this,&event_loop_started]
{
dbus_event_loop.run(event_loop_started);
});
event_loop_started_future.wait();
}
void wait_for_initial_setup()
{
initial_setup_done.wait_for(std::chrono::seconds{5});
}
MOCK_METHOD1(dbus_setUserBrightness, void(int brightness));
MOCK_METHOD1(dbus_userAutobrightnessEnable, void(dbus_bool_t enable));
MOCK_METHOD2(dbus_requestSysState, std::string(char const* name, int state));
MOCK_METHOD1(dbus_clearSysState, void(char const* cookie));
MOCK_METHOD1(dbus_enableProximityHandling, void(char const* name));
MOCK_METHOD1(dbus_disableProximityHandling, void(char const* name));
int32_t const dim_brightness = 13;
int32_t const min_brightness = 5;
int32_t const max_brightness = 42;
int32_t const normal_brightness = 24;
dbus_bool_t const auto_brightness_supported;
const char* const default_cookie = "monster";
void emit_SysPowerStateChange(int32_t state)
{
usc::DBusMessageHandle signal{
dbus_message_new_signal(
powerd_service_path,
powerd_service_interface,
"SysPowerStateChange"),
DBUS_TYPE_INT32, &state,
DBUS_TYPE_INVALID};
dbus_connection_send(*connection, signal, nullptr);
}
private:
static ::DBusHandlerResult handle_dbus_message_thunk(
::DBusConnection* connection, DBusMessage* message, void* user_data)
{
auto const powerd_service = static_cast(user_data);
return powerd_service->handle_dbus_message(connection, message, user_data);
}
::DBusHandlerResult handle_dbus_message(
::DBusConnection* connection, DBusMessage* message, void* user_data)
{
if (dbus_message_is_method_call(message, powerd_service_name, "getBrightnessParams"))
{
usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
DBusMessageIter iter;
dbus_message_iter_init_append(reply, &iter);
DBusMessageIter iter_struct;
dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, nullptr, &iter_struct);
dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_INT32, &dim_brightness);
dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_INT32, &min_brightness);
dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_INT32, &max_brightness);
dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_INT32, &normal_brightness);
dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_BOOLEAN, &auto_brightness_supported);
dbus_message_iter_close_container(&iter, &iter_struct);
dbus_connection_send(connection, reply, nullptr);
}
else if (dbus_message_is_method_call(message, powerd_service_name, "setUserBrightness"))
{
int32_t brightness{0};
dbus_message_get_args(
message, nullptr, DBUS_TYPE_INT32, &brightness, DBUS_TYPE_INVALID);
dbus_setUserBrightness(brightness);
usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
dbus_connection_send(connection, reply, nullptr);
}
else if (dbus_message_is_method_call(message, powerd_service_name, "userAutobrightnessEnable"))
{
dbus_bool_t enable{FALSE};
dbus_message_get_args(
message, nullptr, DBUS_TYPE_BOOLEAN, &enable, DBUS_TYPE_INVALID);
dbus_userAutobrightnessEnable(enable);
usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
dbus_connection_send(connection, reply, nullptr);
}
else if (dbus_message_is_method_call(message, powerd_service_name, "requestSysState"))
{
char const* name{nullptr};
int32_t state{-1};
dbus_message_get_args(
message, nullptr,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INT32, &state,
DBUS_TYPE_INVALID);
auto cookie = dbus_requestSysState(name, state);
if (cookie.empty())
cookie = default_cookie;
auto cookie_cstr = cookie.c_str();
usc::DBusMessageHandle reply{
dbus_message_new_method_return(message),
DBUS_TYPE_STRING, &cookie_cstr,
DBUS_TYPE_INVALID};
dbus_connection_send(connection, reply, nullptr);
emit_SysPowerStateChange(state);
}
else if (dbus_message_is_method_call(message, powerd_service_name, "clearSysState"))
{
char const* cookie{nullptr};
dbus_message_get_args(
message, nullptr,
DBUS_TYPE_STRING, &cookie,
DBUS_TYPE_INVALID);
dbus_clearSysState(cookie);
usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
dbus_connection_send(connection, reply, nullptr);
emit_SysPowerStateChange(0);
}
else if (dbus_message_is_method_call(message, powerd_service_name, "enableProximityHandling"))
{
char const* name{nullptr};
dbus_message_get_args(
message, nullptr,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
dbus_enableProximityHandling(name);
usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
dbus_connection_send(connection, reply, nullptr);
}
else if (dbus_message_is_method_call(message, powerd_service_name, "disableProximityHandling"))
{
char const* name{nullptr};
dbus_message_get_args(
message, nullptr,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
dbus_disableProximityHandling(name);
usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
dbus_connection_send(connection, reply, nullptr);
}
return DBUS_HANDLER_RESULT_HANDLED;
}
char const* const powerd_service_name = "com.canonical.powerd";
char const* const powerd_service_path = "/com/canonical/powerd";
char const* const powerd_service_interface = "com.canonical.powerd";
ut::WaitCondition initial_setup_done;
std::shared_ptr connection;
usc::DBusEventLoop dbus_event_loop;
std::thread dbus_loop_thread;
};
struct APowerdMediatorBaseFixture : testing::Test
{
std::chrono::seconds const default_timeout{3};
APowerdMediatorBaseFixture(
dbus_bool_t auto_brightness_supported,
PowerdService::StartNow start_powerd_service_now)
: powerd_service{bus.address(), auto_brightness_supported, start_powerd_service_now}
{
}
~APowerdMediatorBaseFixture()
{
expect_shutdown_requests();
}
void expect_shutdown_requests()
{
using namespace testing;
Mock::VerifyAndClearExpectations(&powerd_service);
EXPECT_CALL(powerd_service, dbus_setUserBrightness(0)).Times(AtMost(1));
EXPECT_CALL(powerd_service, dbus_clearSysState(_)).Times(AtMost(1));
}
static dbus_bool_t const auto_brightness_is_supported{TRUE};
static dbus_bool_t const auto_brightness_not_supported{FALSE};
ut::DBusBus bus;
testing::NiceMock powerd_service;
std::shared_ptr mediator{
std::make_shared(bus.address())};
};
}
namespace
{
struct APowerdMediator : APowerdMediatorBaseFixture
{
APowerdMediator()
: APowerdMediatorBaseFixture{
auto_brightness_is_supported, PowerdService::StartNow::yes}
{
}
};
}
TEST_F(APowerdMediator, gets_initial_brightness_values_from_service)
{
using namespace testing;
EXPECT_THAT(mediator->min_brightness(), Eq(powerd_service.min_brightness));
EXPECT_THAT(mediator->max_brightness(), Eq(powerd_service.max_brightness));
EXPECT_THAT(mediator->auto_brightness_supported(),
Eq(powerd_service.auto_brightness_supported == TRUE));
}
TEST_F(APowerdMediator, sets_dim_brightness_for_dim_backlight)
{
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
mediator->set_dim_backlight();
}
TEST_F(APowerdMediator, does_not_set_dim_brightness_if_not_needed)
{
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
mediator->set_dim_backlight();
mediator->set_dim_backlight();
}
TEST_F(APowerdMediator, sets_normal_brightness_for_normal_backlight)
{
using namespace testing;
InSequence s;
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.normal_brightness));
// Start-up brightness is normal, so we need to change to some other value
// first before resetting normal brightness.
mediator->set_dim_backlight();
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, does_not_set_normal_brightness_if_not_needed)
{
using namespace testing;
EXPECT_CALL(powerd_service, dbus_setUserBrightness(_)).Times(0);
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, sets_zero_brightness_for_off_backlight)
{
EXPECT_CALL(powerd_service, dbus_setUserBrightness(0));
mediator->turn_off_backlight();
}
TEST_F(APowerdMediator, uses_user_specified_brightness_values_if_set)
{
using namespace testing;
auto const dim_brightness = powerd_service.dim_brightness + 1;
auto const normal_brightness = powerd_service.normal_brightness + 1;
InSequence s;
EXPECT_CALL(powerd_service, dbus_setUserBrightness(dim_brightness));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(normal_brightness));
mediator->change_backlight_values(dim_brightness, normal_brightness);
mediator->set_dim_backlight();
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, ignores_out_of_range_user_specified_brightness_values)
{
using namespace testing;
InSequence s;
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.normal_brightness));
mediator->change_backlight_values(mediator->max_brightness() + 1,
mediator->max_brightness() + 1);
mediator->change_backlight_values(mediator->min_brightness() - 1,
mediator->min_brightness() - 1);
mediator->set_dim_backlight();
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, enables_auto_brightness_on_request)
{
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE));
mediator->enable_auto_brightness(true);
}
TEST_F(APowerdMediator, sets_normal_brightness_when_disabling_auto_brightness)
{
using namespace testing;
InSequence s;
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.normal_brightness));
mediator->enable_auto_brightness(true);
mediator->enable_auto_brightness(false);
}
TEST_F(APowerdMediator, retains_auto_brightness_mode_when_setting_normal_backlight)
{
using namespace testing;
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(_)).Times(0);
mediator->enable_auto_brightness(true);
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, retains_auto_brightness_mode_when_setting_normal_backlight_after_off)
{
using namespace testing;
InSequence s;
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(0));
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE));
mediator->enable_auto_brightness(true);
mediator->turn_off_backlight();
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, sets_explicit_brightness_value)
{
ut::WaitCondition request_processed;
int const brightness{30};
EXPECT_CALL(powerd_service, dbus_setUserBrightness(brightness));
mediator->set_brightness(brightness);
}
TEST_F(APowerdMediator, changes_normal_brightness_when_explicitly_setting_brightness)
{
using namespace testing;
int const brightness{30};
InSequence s;
EXPECT_CALL(powerd_service, dbus_setUserBrightness(brightness));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(brightness));
mediator->set_brightness(brightness);
mediator->set_dim_backlight();
// Normal backlight should use value set by explicit set_brightness() call
mediator->set_normal_backlight();
}
TEST_F(APowerdMediator, retains_auto_brightness_mode_when_explicitly_setting_brightness)
{
using namespace testing;
int const brightness{30};
InSequence s;
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(brightness)).Times(0);
mediator->enable_auto_brightness(true);
// set_brightness() shouldn't change mode since auto brightness is enabled
// (i.e. it shouldn't contact powerd)
mediator->set_brightness(brightness);
}
TEST_F(APowerdMediator, ignores_disable_suspend_request_if_suspend_already_disabled)
{
using namespace testing;
EXPECT_CALL(powerd_service, dbus_requestSysState(_, _)).Times(0);
mediator->disable_suspend();
}
TEST_F(APowerdMediator, waits_for_state_change_when_disabling_suspend)
{
using namespace testing;
mediator->allow_suspend();
while (!mediator->is_system_suspended())
std::this_thread::sleep_for(std::chrono::milliseconds{1});
mediator->disable_suspend();
EXPECT_TRUE(!mediator->is_system_suspended());
}
TEST_F(APowerdMediator, uses_correct_cookie_when_allowing_suspend)
{
using namespace testing;
EXPECT_CALL(powerd_service, dbus_clearSysState(StrEq(powerd_service.default_cookie)));
mediator->allow_suspend();
}
TEST_F(APowerdMediator, enables_and_disables_proximity_handling)
{
using namespace testing;
auto const proximity_name = "unity-system-compositor";
InSequence s;
EXPECT_CALL(powerd_service, dbus_enableProximityHandling(StrEq(proximity_name)));
EXPECT_CALL(powerd_service, dbus_disableProximityHandling(StrEq(proximity_name)));
mediator->enable_proximity(true);
mediator->enable_proximity(false);
}
TEST_F(APowerdMediator, ignores_requests_for_redundant_proximity_handling)
{
using namespace testing;
auto const proximity_name = "unity-system-compositor";
InSequence s;
EXPECT_CALL(powerd_service, dbus_enableProximityHandling(StrEq(proximity_name)));
EXPECT_CALL(powerd_service, dbus_disableProximityHandling(StrEq(proximity_name)));
// Should be ignore, proximity already disabled
mediator->enable_proximity(false);
// Should be handled only once
mediator->enable_proximity(true);
mediator->enable_proximity(true);
// Should be handled only once
mediator->enable_proximity(false);
mediator->enable_proximity(false);
}
namespace
{
struct APowerdMediatorWithoutAutoBrightnessSupport : APowerdMediatorBaseFixture
{
APowerdMediatorWithoutAutoBrightnessSupport()
: APowerdMediatorBaseFixture{
auto_brightness_not_supported, PowerdService::StartNow::yes}
{
}
};
}
TEST_F(APowerdMediatorWithoutAutoBrightnessSupport,
sets_normal_brightness_for_enable_auto_brightness)
{
using namespace testing;
InSequence s;
// (1)
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
// (2) Since auto brightness is not supported, when trying to enable it we should see
// we should just get normal brightness.
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.normal_brightness));
mediator->set_dim_backlight(); // (1)
mediator->enable_auto_brightness(true); // (2)
}
TEST_F(APowerdMediatorWithoutAutoBrightnessSupport,
sets_normal_brightness_for_normal_backlight_when_auto_brightness_not_supported)
{
using namespace testing;
InSequence s;
// (1)
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.dim_brightness));
// (2) Since auto brightness is not supported, when setting normal backlight we should
// get normal brightness, even though the user has previously tried to enable
// auto brightness (call marked (*) below).
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.normal_brightness));
// This call should have no effect, since we are already in normal backlight state
mediator->enable_auto_brightness(true); // (*)
mediator->set_dim_backlight(); // (1)
mediator->set_normal_backlight(); // (2)
}
namespace
{
struct APowerdMediatorWithoutInitialService : APowerdMediatorBaseFixture
{
APowerdMediatorWithoutInitialService()
: APowerdMediatorBaseFixture{
auto_brightness_is_supported, PowerdService::StartNow::no}
{
}
};
}
TEST_F(APowerdMediatorWithoutInitialService, has_sensible_brightness_values)
{
using namespace testing;
EXPECT_THAT(mediator->min_brightness(), Ge(0));
EXPECT_THAT(mediator->max_brightness(), Ge(mediator->min_brightness()));
EXPECT_THAT(mediator->auto_brightness_supported(), Eq(false));
}
TEST_F(APowerdMediatorWithoutInitialService,
updates_brightness_values_when_service_connects)
{
using namespace testing;
powerd_service.start();
powerd_service.wait_for_initial_setup();
EXPECT_THAT(mediator->min_brightness(), Eq(powerd_service.min_brightness));
EXPECT_THAT(mediator->max_brightness(), Eq(powerd_service.max_brightness));
EXPECT_THAT(mediator->auto_brightness_supported(),
Eq(powerd_service.auto_brightness_supported == TRUE));
}
TEST_F(APowerdMediatorWithoutInitialService,
disables_suspend_if_suspend_not_allowed_when_service_connects)
{
using namespace testing;
int const sys_state_active{1};
ut::WaitCondition request_processed;
EXPECT_CALL(powerd_service, dbus_requestSysState(_, sys_state_active))
.WillOnce(DoAll(WakeUp(&request_processed), Return("")));
powerd_service.start();
powerd_service.wait_for_initial_setup();
request_processed.wait_for(default_timeout);
EXPECT_TRUE(request_processed.woken());
}
TEST_F(APowerdMediatorWithoutInitialService,
does_not_disable_suspend_if_suspend_is_allowed_when_service_connects)
{
using namespace testing;
mediator->allow_suspend();
ut::WaitCondition request_processed;
EXPECT_CALL(powerd_service, dbus_requestSysState(_, _)).Times(0);
powerd_service.start();
powerd_service.wait_for_initial_setup();
}
TEST_F(APowerdMediatorWithoutInitialService,
reenables_auto_brightness_if_it_is_enabled_when_service_connects)
{
using namespace testing;
// Connect powerd service, enable auto brightness, disconnect service
{
NiceMock another_powerd_service{
bus.address(), TRUE, PowerdService::StartNow::yes};
another_powerd_service.wait_for_initial_setup();
EXPECT_CALL(another_powerd_service, dbus_userAutobrightnessEnable(TRUE));
mediator->enable_auto_brightness(true);
}
// Connect service again
ut::WaitCondition request_processed;
EXPECT_CALL(powerd_service, dbus_userAutobrightnessEnable(TRUE))
.WillOnce(WakeUp(&request_processed));
powerd_service.start();
// We don't wait for initial default setup, since it won't happen
// in this case.
request_processed.wait_for(default_timeout);
EXPECT_TRUE(request_processed.woken());
}
TEST(APowerdMediatorAtStartup, turns_on_backlight_and_disables_suspend)
{
using namespace testing;
const char* const name{"com.canonical.Unity.Screen"};
int const sys_state_active{1};
dbus_bool_t const auto_brightness_supported{TRUE};
ut::DBusBus bus;
NiceMock powerd_service{
bus.address(), auto_brightness_supported, PowerdService::StartNow::yes};
EXPECT_CALL(powerd_service, dbus_setUserBrightness(powerd_service.normal_brightness));
EXPECT_CALL(powerd_service, dbus_requestSysState(StrEq(name), sys_state_active));
usc::PowerdMediator mediator{bus.address()};
powerd_service.wait_for_initial_setup();
Mock::VerifyAndClearExpectations(&powerd_service);
EXPECT_CALL(powerd_service, dbus_clearSysState(_)).Times(AtMost(1));
EXPECT_CALL(powerd_service, dbus_setUserBrightness(0)).Times(AtMost(1));
}
TEST(APowerdMediatorAtStartup, disables_proximity_handling)
{
using namespace testing;
dbus_bool_t const auto_brightness_supported{TRUE};
ut::DBusBus bus;
NiceMock powerd_service{
bus.address(), auto_brightness_supported, PowerdService::StartNow::yes};
EXPECT_CALL(powerd_service, dbus_disableProximityHandling(_));
usc::PowerdMediator mediator{bus.address()};
powerd_service.wait_for_initial_setup();
Mock::VerifyAndClearExpectations(&powerd_service);
}
TEST(APowerdMediatorAtShutdown, turns_off_backlight)
{
using namespace testing;
ut::DBusBus bus;
dbus_bool_t const auto_brightness_supported{TRUE};
NiceMock powerd_service{
bus.address(), auto_brightness_supported, PowerdService::StartNow::yes};
usc::PowerdMediator mediator{bus.address()};
powerd_service.wait_for_initial_setup();
Mock::VerifyAndClearExpectations(&powerd_service);
EXPECT_CALL(powerd_service, dbus_setUserBrightness(0));
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/unity_screen_dbus_client.h 0000644 0000156 0000165 00000003446 12674474272 033053 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#ifndef USC_TEST_UNITY_SCREEN_DBUS_CLIENT_H_
#define USC_TEST_UNITY_SCREEN_DBUS_CLIENT_H_
#include "dbus_client.h"
namespace usc
{
namespace test
{
class UnityScreenDBusClient : public DBusClient
{
public:
UnityScreenDBusClient(std::string const& address);
DBusAsyncReplyString request_introspection();
DBusAsyncReplyVoid request_set_user_brightness(int32_t brightness);
DBusAsyncReplyVoid request_user_auto_brightness_enable(bool enabled);
DBusAsyncReplyVoid request_set_inactivity_timeouts(
int32_t poweroff_timeout, int32_t dimmer_timeout);
DBusAsyncReplyVoid request_set_touch_visualization_enabled(bool enabled);
DBusAsyncReplyBool request_set_screen_power_mode(
std::string const& mode, int reason);
DBusAsyncReplyInt request_keep_display_on();
DBusAsyncReplyVoid request_remove_display_on_request(int id);
DBusAsyncReply request_invalid_method();
DBusAsyncReply request_method_with_invalid_arguments();
usc::DBusMessageHandle listen_for_power_state_change_signal();
char const* const unity_screen_interface = "com.canonical.Unity.Screen";
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/dbus_bus.h 0000644 0000156 0000165 00000001734 12674474272 027575 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef USC_TEST_DBUS_BUS_H_
#define USC_TEST_DBUS_BUS_H_
#include
#include
namespace usc
{
namespace test
{
class DBusBus
{
public:
DBusBus();
~DBusBus();
std::string address();
private:
std::string address_;
pid_t pid;
};
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/unity_input_dbus_client.cpp 0000644 0000156 0000165 00000006777 12674474272 033300 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#include "unity_input_dbus_client.h"
namespace ut = usc::test;
ut::UnityInputDBusClient::UnityInputDBusClient(std::string const& address)
: ut::DBusClient{
address,
"com.canonical.Unity.Input",
"/com/canonical/Unity/Input"}
{
}
ut::DBusAsyncReplyString ut::UnityInputDBusClient::request_introspection()
{
return invoke_with_reply(
"org.freedesktop.DBus.Introspectable", "Introspect",
DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, int32_t value)
{
return invoke_with_reply(
unity_input_interface, requestName,
DBUS_TYPE_INT32, &value,
DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_primary_button(int32_t button)
{
return request("setMousePrimaryButton", button);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_primary_button(int32_t button)
{
return request("setTouchpadPrimaryButton", button);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, double value)
{
return invoke_with_reply(
unity_input_interface, requestName,
DBUS_TYPE_DOUBLE, &value,
DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_cursor_speed(double speed)
{
return request("setMouseCursorSpeed", speed);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_mouse_scroll_speed(double speed)
{
return request("setMouseScrollSpeed", speed);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_cursor_speed(double speed)
{
return request("setTouchpadCursorSpeed", speed);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_scroll_speed(double speed)
{
return request("setTouchpadScrollSpeed", speed);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request(char const* requestName, bool value)
{
dbus_bool_t copied = value;
return invoke_with_reply(
unity_input_interface, requestName,
DBUS_TYPE_BOOLEAN, &copied,
DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_two_finger_scroll(bool enabled)
{
return request("setTouchpadTwoFingerScroll", enabled);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_tap_to_click(bool enabled)
{
return request("setTouchpadTapToClick", enabled);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_disable_with_mouse(bool enabled)
{
return request("setTouchpadDisableWithMouse", enabled);
}
ut::DBusAsyncReplyVoid ut::UnityInputDBusClient::request_set_touchpad_disable_while_typing(bool enabled)
{
return request("setTouchpadDisableWhileTyping", enabled);
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/dbus_client.cpp 0000644 0000156 0000165 00000007530 12674474272 030615 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "dbus_client.h"
#include "src/dbus_message_handle.h"
#include
namespace ut = usc::test;
ut::DBusAsyncReply::DBusAsyncReply(DBusPendingCall* pending_reply)
: pending_reply{pending_reply}
{
}
ut::DBusAsyncReply::DBusAsyncReply(DBusAsyncReply&& other)
: pending_reply{other.pending_reply}
{
other.pending_reply = nullptr;
}
ut::DBusAsyncReply::~DBusAsyncReply()
{
throw_on_error_reply(get());
}
usc::DBusMessageHandle ut::DBusAsyncReply::get()
{
if (pending_reply)
{
dbus_pending_call_block(pending_reply);
auto reply = usc::DBusMessageHandle{
dbus_pending_call_steal_reply(pending_reply)};
dbus_pending_call_unref(pending_reply);
pending_reply = nullptr;
return reply;
}
else
{
return usc::DBusMessageHandle{nullptr};
}
}
void ut::DBusAsyncReply::throw_on_error_reply(::DBusMessage* reply)
{
if (reply && dbus_message_get_error_name(reply) != nullptr)
throw std::runtime_error("Got an error reply");
}
void ut::DBusAsyncReply::throw_on_invalid_reply(::DBusMessage* reply)
{
if (!reply)
throw std::runtime_error("Async reply is invalid");
}
void ut::DBusAsyncReplyVoid::get()
{
auto reply = ut::DBusAsyncReply::get();
throw_on_invalid_reply(reply);
throw_on_error_reply(reply);
}
int ut::DBusAsyncReplyInt::get()
{
auto reply = ut::DBusAsyncReply::get();
throw_on_invalid_reply(reply);
throw_on_error_reply(reply);
int32_t val{-1};
dbus_message_get_args(reply, nullptr, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
return val;
}
bool ut::DBusAsyncReplyBool::get()
{
auto reply = ut::DBusAsyncReply::get();
throw_on_invalid_reply(reply);
throw_on_error_reply(reply);
dbus_bool_t val{FALSE};
dbus_message_get_args(reply, nullptr, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID);
return val == TRUE;
}
std::string ut::DBusAsyncReplyString::get()
{
auto reply = ut::DBusAsyncReply::get();
throw_on_invalid_reply(reply);
throw_on_error_reply(reply);
char* val{nullptr};
dbus_message_get_args(reply, nullptr, DBUS_TYPE_STRING, &val, DBUS_TYPE_INVALID);
return std::string{val};
}
ut::DBusClient::DBusClient(
std::string const& bus_address,
std::string const& destination,
std::string const& path)
: connection{bus_address.c_str()},
destination{destination},
path{path}
{
}
void ut::DBusClient::DBusClient::disconnect()
{
if (dbus_connection_get_is_connected(connection))
dbus_connection_close(connection);
}
::DBusPendingCall* ut::DBusClient::invoke_with_pending(
char const* interface, char const* method, int first_arg_type, ...)
{
static int const timeout_ms = 5000;
va_list args;
va_start(args, first_arg_type);
usc::DBusMessageHandle msg{
dbus_message_new_method_call(
destination.c_str(),
path.c_str(),
interface,
method),
first_arg_type, args};
va_end(args);
DBusPendingCall* pending_reply;
dbus_connection_send_with_reply(
connection, msg, &pending_reply, timeout_ms);
dbus_connection_flush(connection);
return pending_reply;
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/test_unity_screen_service.cpp 0000644 0000156 0000165 00000022431 12674474272 033605 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "src/unity_screen_service.h"
#include "src/dbus_connection_handle.h"
#include "src/dbus_connection_thread.h"
#include "src/dbus_event_loop.h"
#include "src/dbus_message_handle.h"
#include "src/screen.h"
#include "src/power_state_change_reason.h"
#include "src/unity_screen_service_introspection.h"
#include "wait_condition.h"
#include "dbus_bus.h"
#include "unity_screen_dbus_client.h"
#include "usc/test/mock_screen.h"
#include
#include
#include
#include
namespace ut = usc::test;
namespace
{
struct AUnityScreenService : testing::Test
{
std::chrono::seconds const default_timeout{3};
ut::DBusBus bus;
std::shared_ptr const mock_screen =
std::make_shared>();
ut::UnityScreenDBusClient client{bus.address()};
std::shared_ptr const dbus_loop=
std::make_shared();
usc::UnityScreenService service{dbus_loop, bus.address(), mock_screen};
std::shared_ptr const dbus_thread =
std::make_shared(dbus_loop);
};
}
TEST_F(AUnityScreenService, replies_to_introspection_request)
{
using namespace testing;
auto reply = client.request_introspection();
EXPECT_THAT(reply.get(), Eq(unity_screen_service_introspection));
}
TEST_F(AUnityScreenService, forwards_set_user_brightness_request)
{
int const brightness = 10;
EXPECT_CALL(*mock_screen, set_brightness(brightness));
client.request_set_user_brightness(brightness);
}
TEST_F(AUnityScreenService, forwards_user_auto_brightness_enable_request)
{
bool const enable = true;
EXPECT_CALL(*mock_screen, enable_auto_brightness(enable));
client.request_user_auto_brightness_enable(enable);
}
TEST_F(AUnityScreenService, forwards_set_inactivity_timeouts_request)
{
int const poweroff_timeout = 1000;
int const dimmer_timeout = 500;
EXPECT_CALL(*mock_screen, set_inactivity_timeouts(poweroff_timeout, dimmer_timeout));
client.request_set_inactivity_timeouts(poweroff_timeout, dimmer_timeout);
}
TEST_F(AUnityScreenService, forwards_set_touch_visualization_enabled_request)
{
bool const enabled = true;
EXPECT_CALL(*mock_screen, set_touch_visualization_enabled(enabled));
client.request_set_touch_visualization_enabled(enabled);
}
TEST_F(AUnityScreenService, forwards_set_screen_power_mode_request)
{
auto const mode = MirPowerMode::mir_power_mode_standby;
std::string const mode_str = "standby";
auto const reason = PowerStateChangeReason::proximity;
auto const reason_int = static_cast(reason);
EXPECT_CALL(*mock_screen, set_screen_power_mode(mode, reason));
client.request_set_screen_power_mode(mode_str, reason_int);
}
TEST_F(AUnityScreenService, replies_to_set_screen_power_mode_request)
{
using namespace testing;
std::string const mode_str = "standby";
auto const reason_int = static_cast(PowerStateChangeReason::proximity);
auto reply = client.request_set_screen_power_mode(mode_str, reason_int);
EXPECT_THAT(reply.get(), Eq(true));
}
TEST_F(AUnityScreenService, forwards_keep_display_on_request)
{
EXPECT_CALL(*mock_screen, keep_display_on(true));
client.request_keep_display_on();
}
TEST_F(AUnityScreenService, replies_with_different_ids_to_keep_display_on_requests)
{
using namespace testing;
auto reply1 = client.request_keep_display_on();
auto reply2 = client.request_keep_display_on();
auto const id1 = reply1.get();
auto const id2 = reply2.get();
EXPECT_THAT(id1, Ne(id2));
}
TEST_F(AUnityScreenService, disables_keep_display_on_when_single_request_is_removed)
{
using namespace testing;
InSequence s;
EXPECT_CALL(*mock_screen, keep_display_on(true));
EXPECT_CALL(*mock_screen, keep_display_on(false));
auto reply1 = client.request_keep_display_on();
client.request_remove_display_on_request(reply1.get());
}
TEST_F(AUnityScreenService, disables_keep_display_on_when_all_requests_are_removed)
{
using namespace testing;
EXPECT_CALL(*mock_screen, keep_display_on(true)).Times(3);
EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0);
auto reply1 = client.request_keep_display_on();
auto reply2 = client.request_keep_display_on();
auto reply3 = client.request_keep_display_on();
client.request_remove_display_on_request(reply1.get());
client.request_remove_display_on_request(reply2.get());
auto id3 = reply3.get();
// Display should still be kept on at this point
Mock::VerifyAndClearExpectations(mock_screen.get());
// keep_display_on should be disable only when the last request is removed
EXPECT_CALL(*mock_screen, keep_display_on(false));
client.request_remove_display_on_request(id3);
}
TEST_F(AUnityScreenService, disables_keep_display_on_when_single_client_disconnects)
{
ut::WaitCondition request_processed;
EXPECT_CALL(*mock_screen, keep_display_on(true)).Times(3);
EXPECT_CALL(*mock_screen, keep_display_on(false))
.WillOnce(WakeUp(&request_processed));
client.request_keep_display_on();
client.request_keep_display_on();
client.request_keep_display_on();
client.disconnect();
request_processed.wait_for(default_timeout);
EXPECT_TRUE(request_processed.woken());
}
TEST_F(AUnityScreenService, disables_keep_display_on_when_all_clients_disconnect_or_remove_requests)
{
using namespace testing;
ut::UnityScreenDBusClient other_client{bus.address()};
EXPECT_CALL(*mock_screen, keep_display_on(true)).Times(4);
EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0);
auto reply1 = client.request_keep_display_on();
auto reply2 = client.request_keep_display_on();
other_client.request_keep_display_on();
other_client.request_keep_display_on();
other_client.disconnect();
client.request_remove_display_on_request(reply1.get());
auto id2 = reply2.get();
// Display should still be kept on at this point
Mock::VerifyAndClearExpectations(mock_screen.get());
// keep_display_on should be disabled only when the last request is removed
ut::WaitCondition request_processed;
EXPECT_CALL(*mock_screen, keep_display_on(false))
.WillOnce(WakeUp(&request_processed));
client.request_remove_display_on_request(id2);
request_processed.wait_for(default_timeout);
EXPECT_TRUE(request_processed.woken());
}
TEST_F(AUnityScreenService, ignores_invalid_display_on_removal_request)
{
ut::WaitCondition request_processed;
int32_t const invalid_id{-1};
EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0);
client.request_remove_display_on_request(invalid_id);
client.disconnect();
// Allow some time for dbus calls to reach UnityScreenService
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
TEST_F(AUnityScreenService, ignores_disconnects_from_clients_without_display_on_request)
{
ut::WaitCondition request_processed;
EXPECT_CALL(*mock_screen, keep_display_on(false)).Times(0);
client.disconnect();
// Allow some time for disconnect notification to reach UnityScreenService
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
TEST_F(AUnityScreenService, emits_power_state_change_signal)
{
using namespace testing;
auto async_message = std::async(std::launch::async,
[&] { return client.listen_for_power_state_change_signal(); });
mock_screen->power_state_change_handler(
MirPowerMode::mir_power_mode_off, PowerStateChangeReason::power_key);
auto message = async_message.get();
int32_t state{-1};
int32_t reason{-1};
dbus_message_get_args(message, nullptr,
DBUS_TYPE_INT32, &state,
DBUS_TYPE_INT32, &reason,
DBUS_TYPE_INVALID);
int32_t const off_state{0};
EXPECT_THAT(state, Eq(off_state));
EXPECT_THAT(reason, Eq(static_cast(PowerStateChangeReason::power_key)));
}
TEST_F(AUnityScreenService, returns_error_reply_for_unsupported_method)
{
using namespace testing;
auto reply = client.request_invalid_method();
auto reply_msg = reply.get();
EXPECT_THAT(dbus_message_get_type(reply_msg), Eq(DBUS_MESSAGE_TYPE_ERROR));
EXPECT_THAT(dbus_message_get_error_name(reply_msg), StrEq(DBUS_ERROR_FAILED));
}
TEST_F(AUnityScreenService, returns_error_reply_for_method_with_invalid_arguments)
{
using namespace testing;
auto reply = client.request_method_with_invalid_arguments();
auto reply_msg = reply.get();
EXPECT_THAT(dbus_message_get_type(reply_msg), Eq(DBUS_MESSAGE_TYPE_ERROR));
EXPECT_THAT(dbus_message_get_error_name(reply_msg), StrEq(DBUS_ERROR_FAILED));
}
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/usc_test_helper_wait_for_signal.c unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/usc_test_helper_wait_for_signal0000644 0000156 0000165 00000001360 12674474272 034153 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include
int main()
{
pause();
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/test_unity_input_service.cpp 0000644 0000156 0000165 00000010570 12674474272 033466 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#include "src/unity_input_service.h"
#include "src/dbus_connection_handle.h"
#include "src/dbus_connection_thread.h"
#include "src/dbus_event_loop.h"
#include "src/dbus_message_handle.h"
#include "src/unity_input_service_introspection.h"
#include "wait_condition.h"
#include "dbus_bus.h"
#include "dbus_client.h"
#include "unity_input_dbus_client.h"
#include "usc/test/mock_input_configuration.h"
#include
#include
namespace ut = usc::test;
namespace
{
struct AUnityInputService : testing::Test
{
std::chrono::seconds const default_timeout{3};
ut::DBusBus bus;
std::shared_ptr const mock_input_configuration =
std::make_shared>();
ut::UnityInputDBusClient client{bus.address()};
std::shared_ptr const dbus_loop=
std::make_shared();
usc::UnityInputService service{dbus_loop, bus.address(), mock_input_configuration};
std::shared_ptr const dbus_thread =
std::make_shared(dbus_loop);
};
}
TEST_F(AUnityInputService, replies_to_introspection_request)
{
using namespace testing;
auto reply = client.request_introspection();
EXPECT_THAT(reply.get(), Eq(unity_input_service_introspection));
}
TEST_F(AUnityInputService, forwards_set_mouse_primary_button)
{
int32_t const primary_button = 2;
EXPECT_CALL(*mock_input_configuration, set_mouse_primary_button(primary_button));
client.request_set_mouse_primary_button(primary_button);
}
TEST_F(AUnityInputService, forwards_set_mouse_cursor_speed)
{
double const speed = 10.0;
EXPECT_CALL(*mock_input_configuration, set_mouse_cursor_speed(speed));
client.request_set_mouse_cursor_speed(speed);
}
TEST_F(AUnityInputService, forwards_set_mouse_scroll_speed)
{
double const speed = 8.0;
EXPECT_CALL(*mock_input_configuration, set_mouse_scroll_speed(speed));
client.request_set_mouse_scroll_speed(speed);
}
TEST_F(AUnityInputService, forwards_set_touchpad_primary_button)
{
int32_t const primary_button = 1;
EXPECT_CALL(*mock_input_configuration, set_touchpad_primary_button(primary_button));
client.request_set_touchpad_primary_button(primary_button);
}
TEST_F(AUnityInputService, forwards_set_touchpad_cursor_speed)
{
double const speed = 10.0;
EXPECT_CALL(*mock_input_configuration, set_touchpad_cursor_speed(speed));
client.request_set_touchpad_cursor_speed(speed);
}
TEST_F(AUnityInputService, forwards_set_touchpad_scroll_speed)
{
double const speed = 8.0;
EXPECT_CALL(*mock_input_configuration, set_touchpad_scroll_speed(speed));
client.request_set_touchpad_scroll_speed(speed);
}
TEST_F(AUnityInputService, forwards_set_disable_touchpad_while_typing)
{
bool const disable_it = false;
EXPECT_CALL(*mock_input_configuration, set_disable_touchpad_while_typing(disable_it));
client.request_set_touchpad_disable_while_typing(disable_it);
}
TEST_F(AUnityInputService, forwards_set_disable_touchpad_with_mouse)
{
bool const enable_it = true;
EXPECT_CALL(*mock_input_configuration, set_disable_touchpad_with_mouse(enable_it));
client.request_set_touchpad_disable_with_mouse(enable_it);
}
TEST_F(AUnityInputService, forwards_set_two_finger_scroll)
{
bool const enable_it = true;
EXPECT_CALL(*mock_input_configuration, set_two_finger_scroll(enable_it));
client.request_set_touchpad_two_finger_scroll(enable_it);
}
TEST_F(AUnityInputService, forwards_set_touchpad_tap_to_click)
{
bool const enable_it = true;
EXPECT_CALL(*mock_input_configuration, set_tap_to_click(enable_it));
client.request_set_touchpad_tap_to_click(enable_it);
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/wait_condition.h 0000644 0000156 0000165 00000003063 12674474272 030776 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef USC_WAIT_CONDITION_H_
#define USC_WAIT_CONDITION_H_
#include
#include
#include
#include
namespace usc
{
namespace test
{
struct WaitCondition
{
void wait_for(std::chrono::milliseconds msec)
{
std::unique_lock ul(guard);
condition.wait_for(ul, msec, [this] { return woken_; });
}
void wake_up()
{
std::lock_guard ul(guard);
woken_ = true;
condition.notify_all();
}
bool woken()
{
std::lock_guard ul(guard);
return woken_;
}
private:
std::mutex guard;
std::condition_variable condition;
bool woken_ = false;
};
ACTION_P(WakeUp, wait_condition)
{
wait_condition->wake_up();
}
ACTION_P2(WaitFor, wait_condition, delay)
{
wait_condition->wait_for(delay);
}
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/spin_wait.h 0000644 0000156 0000165 00000002024 12674474272 027755 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#ifndef USC_SPIN_WAIT_H_
#define USC_SPIN_WAIT_H_
#include
#include
namespace usc
{
namespace test
{
bool spin_wait_for_condition_or_timeout(
std::function const& condition,
std::chrono::milliseconds timeout,
std::chrono::milliseconds spin_period = std::chrono::milliseconds{10});
}
}
#endif
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/unity_screen_dbus_client.cpp 0000644 0000156 0000165 00000011167 12674474272 033405 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Andreas Pokorny
*/
#include "unity_screen_dbus_client.h"
#include "src/dbus_message_handle.h"
namespace ut = usc::test;
ut::UnityScreenDBusClient::UnityScreenDBusClient(std::string const& address)
: ut::DBusClient{
address,
"com.canonical.Unity.Screen",
"/com/canonical/Unity/Screen"}
{
connection.add_match(
"type='signal',"
"interface='com.canonical.Unity.Screen',"
"member='DisplayPowerStateChange'");
}
ut::DBusAsyncReplyString ut::UnityScreenDBusClient::request_introspection()
{
return invoke_with_reply("org.freedesktop.DBus.Introspectable", "Introspect",
DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_user_brightness(int32_t brightness)
{
return invoke_with_reply(unity_screen_interface, "setUserBrightness", DBUS_TYPE_INT32,
&brightness, DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_user_auto_brightness_enable(bool enabled)
{
dbus_bool_t const e = enabled ? TRUE : FALSE;
return invoke_with_reply(unity_screen_interface, "userAutobrightnessEnable",
DBUS_TYPE_BOOLEAN, &e, DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_inactivity_timeouts(int32_t poweroff_timeout,
int32_t dimmer_timeout)
{
return invoke_with_reply(unity_screen_interface, "setInactivityTimeouts", DBUS_TYPE_INT32,
&poweroff_timeout, DBUS_TYPE_INT32, &dimmer_timeout,
DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_set_touch_visualization_enabled(bool enabled)
{
dbus_bool_t const e = enabled ? TRUE : FALSE;
return invoke_with_reply(unity_screen_interface, "setTouchVisualizationEnabled",
DBUS_TYPE_BOOLEAN, &e, DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyBool ut::UnityScreenDBusClient::request_set_screen_power_mode(std::string const& mode, int reason)
{
auto mode_cstr = mode.c_str();
return invoke_with_reply(unity_screen_interface, "setScreenPowerMode", DBUS_TYPE_STRING,
&mode_cstr, DBUS_TYPE_INT32, &reason, DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyInt ut::UnityScreenDBusClient::request_keep_display_on()
{
return invoke_with_reply(unity_screen_interface, "keepDisplayOn", DBUS_TYPE_INVALID);
}
ut::DBusAsyncReplyVoid ut::UnityScreenDBusClient::request_remove_display_on_request(int id)
{
return invoke_with_reply(unity_screen_interface, "removeDisplayOnRequest", DBUS_TYPE_INT32,
&id, DBUS_TYPE_INVALID);
}
ut::DBusAsyncReply ut::UnityScreenDBusClient::request_invalid_method()
{
return invoke_with_reply(unity_screen_interface, "invalidMethod", DBUS_TYPE_INVALID);
}
ut::DBusAsyncReply ut::UnityScreenDBusClient::request_method_with_invalid_arguments()
{
char const* const str = "abcd";
return invoke_with_reply(unity_screen_interface, "setUserBrightness", DBUS_TYPE_STRING, &str,
DBUS_TYPE_INVALID);
}
usc::DBusMessageHandle ut::UnityScreenDBusClient::listen_for_power_state_change_signal()
{
while (true)
{
dbus_connection_read_write(connection, 1);
auto msg = usc::DBusMessageHandle{dbus_connection_pop_message(connection)};
if (msg && dbus_message_is_signal(msg, "com.canonical.Unity.Screen", "DisplayPowerStateChange"))
{
return msg;
}
}
}
unity-system-compositor-0.4.3+16.04.20160323/tests/integration-tests/test_external_spinner.cpp 0000644 0000156 0000165 00000011532 12674474272 032736 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright © 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Authored by: Alexandros Frantzis
*/
#include "src/external_spinner.h"
#include "run_command.h"
#include "spin_wait.h"
#include
#include