From 58f10c864fd301fbe509c232488cab7b5c99a6b8 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Mon, 7 Sep 2015 15:11:19 +0200 Subject: test version for gmenuharness --- tests/integration/CMakeLists.txt | 128 ++++++++++++ tests/integration/Copy of test-sound.wav | Bin 0 -> 191989 bytes tests/integration/indicator-sound-test-base.cpp | 263 ++++++++++++++++++++++++ tests/integration/indicator-sound-test-base.h | 83 ++++++++ tests/integration/main.cpp | 58 ++++++ tests/integration/test-indicator.cpp | 182 ++++++++++++++++ tests/integration/test-sound.wav | Bin 0 -> 7665640 bytes tests/integration/touch-stream-restore.table | 4 + tests/integration/utils/dbus-pulse-volume.cpp | 252 +++++++++++++++++++++++ tests/integration/utils/dbus-pulse-volume.h | 57 +++++ tests/integration/utils/get-volume.cpp | 33 +++ tests/integration/utils/set-volume.cpp | 36 ++++ 12 files changed, 1096 insertions(+) create mode 100644 tests/integration/CMakeLists.txt create mode 100644 tests/integration/Copy of test-sound.wav create mode 100644 tests/integration/indicator-sound-test-base.cpp create mode 100644 tests/integration/indicator-sound-test-base.h create mode 100644 tests/integration/main.cpp create mode 100644 tests/integration/test-indicator.cpp create mode 100644 tests/integration/test-sound.wav create mode 100755 tests/integration/touch-stream-restore.table create mode 100644 tests/integration/utils/dbus-pulse-volume.cpp create mode 100644 tests/integration/utils/dbus-pulse-volume.h create mode 100644 tests/integration/utils/get-volume.cpp create mode 100644 tests/integration/utils/set-volume.cpp (limited to 'tests/integration') diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt new file mode 100644 index 0000000..2e4004a --- /dev/null +++ b/tests/integration/CMakeLists.txt @@ -0,0 +1,128 @@ +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +include(FindGMock) + +#pkg_check_modules(GMENUHARNESS REQUIRED libgmenuharness REQUIRED) +#include_directories(${GMENUHARNESS_INCLUDE_DIRS}) +include_directories("${CMAKE_SOURCE_DIR}/include") + +pkg_check_modules(QTDBUSTEST REQUIRED libqtdbustest-1 REQUIRED) +include_directories(${QTDBUSTEST_INCLUDE_DIRS}) + +pkg_check_modules(QTDBUSMOCK REQUIRED libqtdbusmock-1 REQUIRED) +include_directories(${QTDBUSMOCK_INCLUDE_DIRS}) + +find_package(Qt5Test REQUIRED) +include_directories(${Qt5Test_INCLUDE_DIRS}) + +find_package(Qt5DBus REQUIRED) +include_directories(${Qt5DBus_INCLUDE_DIRS}) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${GMOCK_INCLUDE_DIRS}) +include_directories(${GTEST_INCLUDE_DIRS}) + +include_directories("${CMAKE_SOURCE_DIR}/tests/dbus-types") +include_directories("${CMAKE_BINARY_DIR}/tests/dbus-types") + +add_definitions(-DSOUND_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator-sound-service" + -DSTREAM_RESTORE_TABLE="${CMAKE_SOURCE_DIR}/tests/integration/touch-stream-restore.table" + -DVOLUME_SET_BIN="${CMAKE_BINARY_DIR}/tests/integration/set-volume" + -DTEST_SOUND="${CMAKE_SOURCE_DIR}/tests/integration/test-sound.wav" + -DQT_NO_KEYWORDS=1 +) + +set(GLIB_REQUIRED_VERSION 2.26) + +pkg_check_modules( + GLIB REQUIRED + glib-2.0>=${GLIB_REQUIRED_VERSION} + gio-2.0>=${GLIB_REQUIRED_VERSION} +) +include_directories(${GLIB_INCLUDE_DIRS}) + +set( + INTEGRATION_TESTS_SRC + indicator-sound-test-base.cpp + test-indicator.cpp + utils/dbus-pulse-volume.cpp + main.cpp +) + +add_executable( + integration-tests + ${INTEGRATION_TESTS_SRC} +) + +qt5_use_modules( + integration-tests + Core + DBus + Test +) + +target_link_libraries( + integration-tests + sound-indicator-dbus-interfaces + ${QTDBUSMOCK_LDFLAGS} + ${QTDBUSTEST_LDFLAGS} + ${GTEST_LIBRARIES} + ${GMOCK_LIBRARIES} +# ${GMENUHARNESS_LDFLAGS} + ${GLIB_LDFLAGS} + gmenuharness-shared +) + +add_test( + integration-tests + integration-tests +) + +set( + SET-VOLUME-SRC + utils/dbus-pulse-volume.cpp + utils/set-volume.cpp +) + +set( + GET-VOLUME-SRC + utils/dbus-pulse-volume.cpp + utils/get-volume.cpp +) + +add_executable( + set-volume + ${SET-VOLUME-SRC} +) + +add_executable( + get-volume + ${GET-VOLUME-SRC} +) + +qt5_use_modules( + set-volume + Core + DBus + Test +) + +qt5_use_modules( + get-volume + Core + DBus + Test +) + +target_link_libraries( + get-volume + sound-indicator-dbus-interfaces +) + +target_link_libraries( + set-volume + sound-indicator-dbus-interfaces +) + +#add_subdirectory(utils) \ No newline at end of file diff --git a/tests/integration/Copy of test-sound.wav b/tests/integration/Copy of test-sound.wav new file mode 100644 index 0000000..709c6eb Binary files /dev/null and b/tests/integration/Copy of test-sound.wav differ diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp new file mode 100644 index 0000000..6e05efe --- /dev/null +++ b/tests/integration/indicator-sound-test-base.cpp @@ -0,0 +1,263 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ + +#include "indicator-sound-test-base.h" + +#include "dbus_menus_interface.h" +#include "dbus_properties_interface.h" +#include "dbus_accounts_interface.h" +#include "dbus_accountssound_interface.h" +#include "dbus-types.h" + +#include + +#include +#include "utils/dbus-pulse-volume.h" + +using namespace QtDBusTest; +using namespace QtDBusMock; +using namespace std; +using namespace testing; +namespace mh = unity::gmenuharness; + +IndicatorSoundTestBase::IndicatorSoundTestBase() : + dbusMock(dbusTestRunner) +{ +} + +IndicatorSoundTestBase::~IndicatorSoundTestBase() +{ + +} + +bool IndicatorSoundTestBase::setVolume(QString const &role, double volume) +{ + QProcess setVolume; + setVolume.start(VOLUME_SET_BIN, QStringList() + << role + << QString("%1").arg(volume)); + if (!setVolume.waitForStarted()) + return false; + + if (!setVolume.waitForFinished()) + return false; + + return setVolume.exitCode() == 0; +} + +bool IndicatorSoundTestBase::startTestSound(QString const &role) +{ + testSoundProcess.terminate(); + testSoundProcess.start("paplay", QStringList() + << "-s" + << "127.0.0.1" + << TEST_SOUND + << QString("--property=media.role=%1").arg(role)); + + if (!testSoundProcess.waitForStarted()) + return false; + +// sleep(1); + return true; +} + +void IndicatorSoundTestBase::stopTestSound() +{ + testSoundProcess.terminate(); +} + +void IndicatorSoundTestBase::startPulse() +{ + try + { + pulseaudio.reset( + new QProcessDBusService(DBusTypes::DBUS_PULSE, + QDBusConnection::SessionBus, + "pulseaudio", + QStringList() << "--start" + << "-vvvv" + << "--disable-shm=true" + << "--daemonize=false" + << "--use-pid-file=false" + << "--system=false" + << "--exit-idle-time=-1" + << "-n" + << "--load=module-null-sink" + << "--log-target=file:/tmp/pulse-daemon.log" + << QString("--load=module-stream-restore restore_device=false restore_muted=false fallback_table=%1").arg(STREAM_RESTORE_TABLE) + << "--load=module-dbus-protocol" + << "--load=module-native-protocol-tcp auth-ip-acl=127.0.0.1" + )); + pulseaudio->start(dbusTestRunner.sessionConnection()); + } + catch (exception const& e) + { + cout << "pulseaudio(): " << e.what() << endl; + throw; + } +} + +void IndicatorSoundTestBase::startIndicator() +{ + try + { + setenv("PULSE_SERVER", "127.0.0.1", true); + setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); + indicator.reset( + new QProcessDBusService(DBusTypes::DBUS_NAME, + QDBusConnection::SessionBus, + SOUND_SERVICE_BIN, + QStringList())); + indicator->start(dbusTestRunner.sessionConnection()); + } + catch (exception const& e) + { + cout << "startIndicator(): " << e.what() << endl; + throw; + } +} + +// /usr/bin/pulseaudio --start -vvvv --disable-shm=true --daemonize=false --use-pid-file=false --system=false --exit-idle-time=-1 -n "--load=module-null-sink sink_name=multimedia" --load=module-stream-restore + +mh::MenuMatcher::Parameters IndicatorSoundTestBase::desktopParameters() +{ + return mh::MenuMatcher::Parameters( + "com.canonical.indicator.sound", + { { "indicator", "/com/canonical/indicator/sound" } }, + "/com/canonical/indicator/sound/desktop"); +} + +void IndicatorSoundTestBase::SetUp() +{ + initializeAccountsInterface(); +} + +void IndicatorSoundTestBase::TearDown() +{ + unsetenv("PULSE_SERVER"); +} + +void gvariant_deleter(GVariant* varptr) +{ + if (varptr != nullptr) + { + g_variant_unref(varptr); + } +} + +std::shared_ptr IndicatorSoundTestBase::volume_variant(double volume) +{ + GVariantBuilder builder; + + g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&builder, + "{sv}", + "title", + g_variant_new_string("_Sound")); + + g_variant_builder_add(&builder, + "{sv}", + "accessible-desc", + g_variant_new_string("_Sound")); + + auto icon = g_themed_icon_new("icon"); + g_variant_builder_add(&builder, + "{sv}", + "icon", + g_icon_serialize(icon)); + + g_variant_builder_add(&builder, + "{sv}", + "visible", + g_variant_new_boolean(true)); + return shared_ptr(g_variant_builder_end(&builder), &gvariant_deleter); +} + +unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double volume) +{ + return mh::MenuItemMatcher().radio() + .label("Volume") + .round_doubles(0.1) + .pass_through_double_attribute("action", volume); +} + +bool IndicatorSoundTestBase::waitMenuChange() +{ + if (!menu_interface_) + { + menu_interface_.reset(new MenusInterface("com.canonical.indicator.sound", + "/com/canonical/indicator/sound/desktop", + QDBusConnection::sessionBus(), 0)); + } + if (menu_interface_) + { + qDebug() << "Waiting for signal"; + QSignalSpy spy(menu_interface_.get(), &MenusInterface::Changed); + qDebug() << "Signal count " << spy.count(); + return spy.wait(); + } + return false; +} + +bool IndicatorSoundTestBase::waitVolumeChangedInIndicator() +{ + qDebug() << "IndicatorSoundTestBase::waitVolumeChangedInIndicator() signal " << (void *)signal_spy_volume_changed_.get(); + if (signal_spy_volume_changed_) + { + return signal_spy_volume_changed_->wait(); + } + return false; +} + +void IndicatorSoundTestBase::initializeAccountsInterface() +{ + auto username = qgetenv("USER"); + if (username != "") + { + qDebug() << "Setting Accounts interface for user: " << username; + std::unique_ptr setInterface(new AccountsInterface("org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + QDBusConnection::systemBus(), 0)); + qDebug() << "Interface: " << setInterface.get(); + + QDBusReply userResp = setInterface->call(QLatin1String("FindUserByName"), + QLatin1String(username)); + + if (!userResp.isValid()) + { + qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << userResp.error().message(); + } + auto userPath = userResp.value().path(); + if (userPath != "") + { + std::unique_ptr soundInterface(new AccountsSoundInterface("org.freedesktop.Accounts", + userPath, + QDBusConnection::systemBus(), 0)); + + accounts_interface_.reset(new DBusPropertiesInterface("org.freedesktop.Accounts", + userPath, + soundInterface->connection(), 0)); + qDebug() << "Interface for setting volume: " << accounts_interface_.get(); + if (!accounts_interface_->isValid()) + { + qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << accounts_interface_->lastError().message(); + } + signal_spy_volume_changed_.reset(new QSignalSpy(accounts_interface_.get(),&DBusPropertiesInterface::PropertiesChanged)); + } + } +} diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h new file mode 100644 index 0000000..81d8204 --- /dev/null +++ b/tests/integration/indicator-sound-test-base.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ + +#pragma once + +#include +#include +#include + +#include +#include + +#include +#include + +class MenusInterface; +class DBusPulseVolume; +class DBusPropertiesInterface; +class QSignalSpy; + +class IndicatorSoundTestBase: public testing::Test +{ +public: + IndicatorSoundTestBase(); + + ~IndicatorSoundTestBase(); + +protected: + void SetUp() override; + void TearDown() override; + + void startIndicator(); + void startPulse(); + + bool setVolume(QString const &role, double volume); + + bool startTestSound(QString const &role); + + void stopTestSound(); + + static std::shared_ptr volume_variant(double volume); + + static unity::gmenuharness::MenuMatcher::Parameters desktopParameters(); + + static unity::gmenuharness::MenuItemMatcher volumeSlider(double volume); + + bool waitMenuChange(); + + bool waitVolumeChangedInIndicator(); + + void initializeAccountsInterface(); + + QtDBusTest::DBusTestRunner dbusTestRunner; + + QtDBusMock::DBusMock dbusMock; + + QtDBusTest::DBusServicePtr indicator; + + QtDBusTest::DBusServicePtr pulseaudio; + + QProcess testSoundProcess; + + std::unique_ptr menu_interface_; + + std::unique_ptr accounts_interface_; + + std::unique_ptr signal_spy_volume_changed_; +}; diff --git a/tests/integration/main.cpp b/tests/integration/main.cpp new file mode 100644 index 0000000..a29b3b6 --- /dev/null +++ b/tests/integration/main.cpp @@ -0,0 +1,58 @@ +/* + * Copyright © 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authors: + * Pete Woods + */ + +//#include + +#include +#include +#include + +#include + +#include "dbus-types.h" + +using namespace QtDBusMock; + +class Runner: public QObject +{ + Q_OBJECT +public Q_SLOTS: + void run() + { + QCoreApplication::exit(RUN_ALL_TESTS()); + } +}; + +int main(int argc, char **argv) +{ + qputenv("LANG", "C.UTF-8"); + unsetenv("LC_ALL"); + + QCoreApplication application(argc, argv); + DBusMock::registerMetaTypes(); + DBusTypes::registerMetaTypes(); + ::testing::InitGoogleTest(&argc, argv); + + Runner runner; + QTimer::singleShot(0, &runner, SLOT(run())); + + return application.exec(); +} + +#include "main.moc" diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp new file mode 100644 index 0000000..8803f91 --- /dev/null +++ b/tests/integration/test-indicator.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ + +#include + +#include +#include +#include + +using namespace std; +using namespace testing; +namespace mh = unity::gmenuharness; +namespace +{ + +class TestIndicator: public IndicatorSoundTestBase +{ +}; + +TEST_F(TestIndicator, ChangeRoleVolume) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startPulse()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setVolume("mutimedia", INITIAL_VOLUME)); + EXPECT_TRUE(setVolume("alert", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // Generate a random volume + QTime now = QTime::currentTime(); + qsrand(now.msec()); + int randInt = qrand() % 100; + double randomVolume = randInt / 100.0; + + // set an initial volume to the alert role + setVolume("alert", 1.0); + EXPECT_TRUE(waitVolumeChangedInIndicator()); + + // play a test sound, it should change the role in the indicator + EXPECT_TRUE(startTestSound("multimedia")); + EXPECT_TRUE(waitVolumeChangedInIndicator()); + + // set the random volume to the multimedia role + EXPECT_TRUE(setVolume("multimedia", randomVolume)); + if (randomVolume != INITIAL_VOLUME) + { + EXPECT_TRUE(waitVolumeChangedInIndicator()); + } + + // check the indicator + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(randomVolume)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); + + // stop the test sound, the role should change again to alert + stopTestSound(); + if (randomVolume != 1.0) + { + // we only wait if the volume in the alert and the + // one set in the multimedia roles differ + EXPECT_TRUE(waitVolumeChangedInIndicator()); + } + + // check the initial volume for the alert role + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(1.0)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); +} + +TEST_F(TestIndicator, BasicInitialVolume) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startPulse()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setVolume("alert", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // check the initial volume for the alert role + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(INITIAL_VOLUME)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); +} + +} // namespace diff --git a/tests/integration/test-sound.wav b/tests/integration/test-sound.wav new file mode 100644 index 0000000..f696657 Binary files /dev/null and b/tests/integration/test-sound.wav differ diff --git a/tests/integration/touch-stream-restore.table b/tests/integration/touch-stream-restore.table new file mode 100755 index 0000000..146b02e --- /dev/null +++ b/tests/integration/touch-stream-restore.table @@ -0,0 +1,4 @@ +sink-input-by-media-role:multimedia -8 +sink-input-by-media-role:alert -8 +sink-input-by-media-role:alarm -8 +sink-input-by-media-role:phone -15 diff --git a/tests/integration/utils/dbus-pulse-volume.cpp b/tests/integration/utils/dbus-pulse-volume.cpp new file mode 100644 index 0000000..6989754 --- /dev/null +++ b/tests/integration/utils/dbus-pulse-volume.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ + +#include "dbus_properties_interface.h" +#include "dbus_accounts_interface.h" +#include "dbus_accountssound_interface.h" +#include "stream_restore_interface.h" + +#include +#include "dbus-pulse-volume.h" + +#include + +unsigned int volumeDoubleToUint(double volume) +{ + double tmp = (double)(PA_VOLUME_NORM - PA_VOLUME_MUTED) * volume; + return (unsigned int)tmp + PA_VOLUME_MUTED; +} + +double volumeUIntToDoulbe(uint volume) +{ + double tmp = (double)(volume - PA_VOLUME_MUTED); + return tmp / (double)(PA_VOLUME_NORM - PA_VOLUME_MUTED); +} + +DBusPulseVolume::DBusPulseVolume() : + QObject() +{ + std::unique_ptr basicConnectionInterface(new DBusPropertiesInterface("org.PulseAudio1", + "/org/pulseaudio/server_lookup1", + QDBusConnection::sessionBus(), 0)); + + QDBusReply connection_string = basicConnectionInterface->call(QLatin1String("Get"), + QLatin1String("org.PulseAudio.ServerLookup1"), + QLatin1String("Address")); + + if (!connection_string.isValid()) + { + qWarning() << "DBusPulseVolume::DBusPulseVolume(): D-Bus error: " << connection_string.error().message(); + } + + qDebug() << "********************************Connetion: " << connection_string.value().toString(); + +// connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer(connection_string.value().toString(), "set-volume"))); + + connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer("unix:path=/run/user/1000/pulse/dbus-socket", "set-volume"))); + qDebug() << "Is connected " << connection_->isConnected(); + + if (connection_->isConnected()) + { + interface_paths_.reset(new StreamRestoreInterface("org.PulseAudio.Ext.StreamRestore1", + "/org/pulseaudio/stream_restore1", + *(connection_.get()), 0)); + qDebug() << "Interface " << (void *)interface_paths_.get(); + + if (interface_paths_) + { + // get the role paths + fillRolePath("multimedia"); + fillRolePath("alert"); + fillRolePath("alarm"); + fillRolePath("phone"); + } + + initializeAccountsInterface(); + } + else + { + qWarning() << "DBusPulseVolume::DBusPulseVolume(): Error connecting: " << connection_->lastError().message(); + } +} + +DBusPulseVolume::~DBusPulseVolume() +{ + connection_->disconnectFromPeer("unix:path=/run/user/1000/pulse/dbus-socket"); +} + +QString DBusPulseVolume::fillRolePath(QString const &role) +{ + QString role_complete_name = QString("sink-input-by-media-role:") + role; + // get the role paths + QDBusReply objectPath = interface_paths_->call(QLatin1String("GetEntryByName"), role_complete_name); + if (!objectPath.isValid()) + { + qWarning() << "SetVolume::fillRolePath(): D-Bus error: " << objectPath.error().message(); + return ""; + } + qDebug() << "XGM: path for role " << role << "=" << objectPath.value().path(); + auto role_info = std::make_shared(); + role_info->interface_.reset(new DBusPropertiesInterface("org.PulseAudio.Ext.StreamRestore1.RestoreEntry", + objectPath.value().path(), + *(connection_.get()), 0)); + if (!role_info->interface_) + { + qWarning() << "SetVolume::fillRolePath() - Error obtaining properties interface"; + return ""; + } + role_info->path_ = objectPath.value().path(); + roles_map_[role] = role_info; + return role_info->path_; +} + +bool DBusPulseVolume::setVolume(QString const & role, double volume) +{ + if (!interface_paths_) + { + qWarning() << "SetVolume::setVolume(): error: Volume interfaces are not initialized"; + return false; + } + RolesMap::const_iterator iter = roles_map_.find(role); + if (iter != roles_map_.end()) + { + QDBusReply prev_vol = (*iter).second->interface_->call(QLatin1String("Get"), + QLatin1String("org.PulseAudio.Ext.StreamRestore1.RestoreEntry"), + QLatin1String("Volume")); + + if (!prev_vol.isValid()) + { + qWarning() << "SetVolume::setVolume(): D-Bus error: " << prev_vol.error().message(); + return false; + } + QDBusArgument arg = prev_vol.value().value(); + PulseaudioVolumeArray element; + arg >> element; + + PulseaudioVolume signal_vol(0, 4000); + PulseaudioVolumeArray vol_array; + vol_array.addItem(signal_vol); + + QVariant var; + PulseaudioVolumeArray t; + PulseaudioVolume vv(0, volumeDoubleToUint(volume)); + t.addItem(vv); + var.setValue(t); + QDBusVariant dbusVar(var); + QDBusReply set_vol = (*iter).second->interface_->call(QLatin1String("Set"), + QVariant::fromValue(QString("org.PulseAudio.Ext.StreamRestore1.RestoreEntry")), + QVariant::fromValue(QString("Volume")), + QVariant::fromValue(dbusVar)); + + if (!set_vol.isValid()) + { + qWarning() << "SetVolume::setVolume(): D-Bus error: " << set_vol.error().message(); + return false; + } + + if (accounts_interface_) + { + QDBusVariant dbusVar(QVariant::fromValue(volume)); + QDBusReply set_vol = accounts_interface_->call(QLatin1String("Set"), + QVariant::fromValue(QString("com.ubuntu.AccountsService.Sound")), + QVariant::fromValue(QString("Volume")), + QVariant::fromValue(dbusVar)); + if (!set_vol.isValid()) + { + qWarning() << "SetVolume::setVolume(): D-Bus error: " << set_vol.error().message(); + return false; + } + } + } + return true; +} + +double DBusPulseVolume::getVolume(QString const & role) +{ + if (interface_paths_) + { + RolesMap::const_iterator iter = roles_map_.find(role); + if (iter != roles_map_.end()) + { + QDBusReply prev_vol = (*iter).second->interface_->call(QLatin1String("Get"), + QLatin1String("org.PulseAudio.Ext.StreamRestore1.RestoreEntry"), + QLatin1String("Volume")); + + if (!prev_vol.isValid()) + { + qWarning() << "SetVolume::setVolume(): D-Bus error: " << prev_vol.error().message(); + } + QDBusArgument arg = prev_vol.value().value(); + PulseaudioVolumeArray element; + arg >> element; + return volumeUIntToDoulbe(element.getItem(0).getVolume()); + } + } + return -1.0; +} + +void DBusPulseVolume::initializeAccountsInterface() +{ + auto username = qgetenv("USER"); + if (username != "") + { + qDebug() << "Setting Accounts interface for user: " << username; + std::unique_ptr setInterface(new AccountsInterface("org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + QDBusConnection::systemBus(), 0)); + qDebug() << "Interface: " << setInterface.get(); + + QDBusReply userResp = setInterface->call(QLatin1String("FindUserByName"), + QLatin1String(username)); + + if (!userResp.isValid()) + { + qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << userResp.error().message(); + } + auto userPath = userResp.value().path(); + if (userPath != "") + { + std::unique_ptr soundInterface(new AccountsSoundInterface("org.freedesktop.Accounts", + userPath, + QDBusConnection::systemBus(), 0)); + + accounts_interface_.reset(new DBusPropertiesInterface("org.freedesktop.Accounts", + userPath, + soundInterface->connection(), 0)); + qDebug() << "Interface for setting volume: " << accounts_interface_.get(); + if (!accounts_interface_->isValid()) + { + qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << accounts_interface_->lastError().message(); + } + signal_spy_volume_changed_.reset(new QSignalSpy(accounts_interface_.get(),&DBusPropertiesInterface::PropertiesChanged)); + } + } +} + +bool DBusPulseVolume::waitForVolumeChangedInAccountsService() +{ + if (signal_spy_volume_changed_) + { + return signal_spy_volume_changed_->wait(); + } + else + { + qWarning() << "DBusPulseVolume::waitForVolumeChangedInAccountsService(): signal was not instantiated"; + } + return false; +} diff --git a/tests/integration/utils/dbus-pulse-volume.h b/tests/integration/utils/dbus-pulse-volume.h new file mode 100644 index 0000000..2d55e89 --- /dev/null +++ b/tests/integration/utils/dbus-pulse-volume.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ +#pragma once + +#include +#include + +#include +#include + +class StreamRestoreInterface; +class DBusPropertiesInterface; +class AccountsInterface; +class AccountsSoundInterface; +class QSignalSpy; + +struct RoleInformation +{ + std::unique_ptr interface_; + QString path_; +}; + +class DBusPulseVolume : public QObject +{ +public: + DBusPulseVolume(); + ~DBusPulseVolume(); + + bool setVolume(QString const & role, double volume); + double getVolume(QString const & role); + bool waitForVolumeChangedInAccountsService(); + +protected: + QString fillRolePath(QString const &role); + void initializeAccountsInterface(); + std::unique_ptr connection_; + std::unique_ptr interface_paths_; + typedef std::map> RolesMap; + RolesMap roles_map_; + std::unique_ptr accounts_interface_; + std::unique_ptr signal_spy_volume_changed_; +}; diff --git a/tests/integration/utils/get-volume.cpp b/tests/integration/utils/get-volume.cpp new file mode 100644 index 0000000..309da36 --- /dev/null +++ b/tests/integration/utils/get-volume.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ + +#include "dbus-types.h" + +#include +#include "dbus-pulse-volume.h" + +int main(int argc, char **argv) +{ + DBusTypes::registerMetaTypes(); + if (argc == 2) + { + DBusPulseVolume volume; + volume.getVolume(argv[1]); + } + return 0; +} diff --git a/tests/integration/utils/set-volume.cpp b/tests/integration/utils/set-volume.cpp new file mode 100644 index 0000000..d29e5ef --- /dev/null +++ b/tests/integration/utils/set-volume.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Xavi Garcia + */ + +#include "dbus-types.h" + +#include +#include "dbus-pulse-volume.h" + +int main(int argc, char **argv) +{ + DBusTypes::registerMetaTypes(); + if (argc == 3) + { + DBusPulseVolume volume; + if(!volume.setVolume(argv[1], std::stod(argv[2]))) + { + return 1; + } + } + return 0; +} -- cgit v1.2.3 From 09fc613f1ce55910698aca6b8b5d909ac3ae77a0 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Fri, 18 Sep 2015 15:15:59 +0200 Subject: Added AccountsService Mock to the integration tests --- tests/integration/CMakeLists.txt | 1 + tests/integration/indicator-sound-test-base.cpp | 27 +++++++++++++++++++------ tests/integration/indicator-sound-test-base.h | 3 +++ tests/integration/test-indicator.cpp | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 2e4004a..ace155a 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -29,6 +29,7 @@ include_directories("${CMAKE_BINARY_DIR}/tests/dbus-types") add_definitions(-DSOUND_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator-sound-service" -DSTREAM_RESTORE_TABLE="${CMAKE_SOURCE_DIR}/tests/integration/touch-stream-restore.table" -DVOLUME_SET_BIN="${CMAKE_BINARY_DIR}/tests/integration/set-volume" + -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/accounts-mock/accounts-service-sound" -DTEST_SOUND="${CMAKE_SOURCE_DIR}/tests/integration/test-sound.wav" -DQT_NO_KEYWORDS=1 ) diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 6e05efe..10717c7 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -112,12 +112,31 @@ void IndicatorSoundTestBase::startPulse() } } +void IndicatorSoundTestBase::startAccountsService() +{ + try + { + accountsService.reset( + new QProcessDBusService(DBusTypes::ACCOUNTS_SERVICE, + QDBusConnection::SystemBus, + ACCOUNTS_SERVICE_BIN, + QStringList() )); + accountsService->start(dbusTestRunner.systemConnection()); + + initializeAccountsInterface(); + } + catch (exception const& e) + { + cout << "accountsService(): " << e.what() << endl; + throw; + } +} + void IndicatorSoundTestBase::startIndicator() { try { setenv("PULSE_SERVER", "127.0.0.1", true); - setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); indicator.reset( new QProcessDBusService(DBusTypes::DBUS_NAME, QDBusConnection::SessionBus, @@ -144,7 +163,7 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::desktopParameters() void IndicatorSoundTestBase::SetUp() { - initializeAccountsInterface(); + setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); } void IndicatorSoundTestBase::TearDown() @@ -216,7 +235,6 @@ bool IndicatorSoundTestBase::waitMenuChange() bool IndicatorSoundTestBase::waitVolumeChangedInIndicator() { - qDebug() << "IndicatorSoundTestBase::waitVolumeChangedInIndicator() signal " << (void *)signal_spy_volume_changed_.get(); if (signal_spy_volume_changed_) { return signal_spy_volume_changed_->wait(); @@ -229,11 +247,9 @@ void IndicatorSoundTestBase::initializeAccountsInterface() auto username = qgetenv("USER"); if (username != "") { - qDebug() << "Setting Accounts interface for user: " << username; std::unique_ptr setInterface(new AccountsInterface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", QDBusConnection::systemBus(), 0)); - qDebug() << "Interface: " << setInterface.get(); QDBusReply userResp = setInterface->call(QLatin1String("FindUserByName"), QLatin1String(username)); @@ -252,7 +268,6 @@ void IndicatorSoundTestBase::initializeAccountsInterface() accounts_interface_.reset(new DBusPropertiesInterface("org.freedesktop.Accounts", userPath, soundInterface->connection(), 0)); - qDebug() << "Interface for setting volume: " << accounts_interface_.get(); if (!accounts_interface_->isValid()) { qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << accounts_interface_->lastError().message(); diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 81d8204..04a579f 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -46,6 +46,7 @@ protected: void startIndicator(); void startPulse(); + void startAccountsService(); bool setVolume(QString const &role, double volume); @@ -73,6 +74,8 @@ protected: QtDBusTest::DBusServicePtr pulseaudio; + QtDBusTest::DBusServicePtr accountsService; + QProcess testSoundProcess; std::unique_ptr menu_interface_; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 8803f91..bb5adec 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -36,6 +36,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) { double INITIAL_VOLUME = 0.0; + ASSERT_NO_THROW(startAccountsService()); ASSERT_NO_THROW(startPulse()); // initialize volumes in pulseaudio @@ -140,6 +141,7 @@ TEST_F(TestIndicator, BasicInitialVolume) { double INITIAL_VOLUME = 0.0; + ASSERT_NO_THROW(startAccountsService()); ASSERT_NO_THROW(startPulse()); // initialize volumes in pulseaudio -- cgit v1.2.3 From 83e68a4d2b9e40d7d4f047a2e58c70c484cbd916 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Fri, 18 Sep 2015 16:29:32 +0200 Subject: Updated schema dir for integration tests --- tests/integration/CMakeLists.txt | 1 + tests/integration/indicator-sound-test-base.cpp | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'tests/integration') diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index ace155a..52c4e70 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -32,6 +32,7 @@ add_definitions(-DSOUND_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator-sound-ser -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/accounts-mock/accounts-service-sound" -DTEST_SOUND="${CMAKE_SOURCE_DIR}/tests/integration/test-sound.wav" -DQT_NO_KEYWORDS=1 + -DSCHEMA_DIR="${SCHEMA_DIR}" ) set(GLIB_REQUIRED_VERSION 2.26) diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 10717c7..49e2ec5 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -163,11 +163,15 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::desktopParameters() void IndicatorSoundTestBase::SetUp() { + setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true); + setenv("GSETTINGS_BACKEND", "memory", true); setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); } void IndicatorSoundTestBase::TearDown() { + unsetenv("GSETTINGS_SCHEMA_DIR"); + unsetenv("GSETTINGS_BACKEND"); unsetenv("PULSE_SERVER"); } -- cgit v1.2.3 From 913282e093a723b7e3a7bb899a77a068edafcd01 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Sun, 20 Sep 2015 20:16:27 +0200 Subject: Updated set-volume utility --- tests/integration/utils/dbus-pulse-volume.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/utils/dbus-pulse-volume.cpp b/tests/integration/utils/dbus-pulse-volume.cpp index 6989754..b42ea15 100644 --- a/tests/integration/utils/dbus-pulse-volume.cpp +++ b/tests/integration/utils/dbus-pulse-volume.cpp @@ -56,9 +56,9 @@ DBusPulseVolume::DBusPulseVolume() : qDebug() << "********************************Connetion: " << connection_string.value().toString(); -// connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer(connection_string.value().toString(), "set-volume"))); + connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer(connection_string.value().toString(), "set-volume"))); - connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer("unix:path=/run/user/1000/pulse/dbus-socket", "set-volume"))); +// connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer("unix:path=/run/user/1000/pulse/dbus-socket", "set-volume"))); qDebug() << "Is connected " << connection_->isConnected(); if (connection_->isConnected()) -- cgit v1.2.3 From ae0602ca11090c6c70cdf289ce3871766d36519c Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Mon, 21 Sep 2015 11:53:31 +0200 Subject: code cleanup --- tests/integration/utils/dbus-pulse-volume.cpp | 33 ++++----------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/utils/dbus-pulse-volume.cpp b/tests/integration/utils/dbus-pulse-volume.cpp index b42ea15..a282f77 100644 --- a/tests/integration/utils/dbus-pulse-volume.cpp +++ b/tests/integration/utils/dbus-pulse-volume.cpp @@ -16,13 +16,14 @@ * Author: Xavi Garcia */ +#include "dbus-pulse-volume.h" + #include "dbus_properties_interface.h" #include "dbus_accounts_interface.h" #include "dbus_accountssound_interface.h" #include "stream_restore_interface.h" #include -#include "dbus-pulse-volume.h" #include @@ -54,20 +55,13 @@ DBusPulseVolume::DBusPulseVolume() : qWarning() << "DBusPulseVolume::DBusPulseVolume(): D-Bus error: " << connection_string.error().message(); } - qDebug() << "********************************Connetion: " << connection_string.value().toString(); - connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer(connection_string.value().toString(), "set-volume"))); -// connection_.reset(new QDBusConnection(QDBusConnection::connectToPeer("unix:path=/run/user/1000/pulse/dbus-socket", "set-volume"))); - qDebug() << "Is connected " << connection_->isConnected(); - if (connection_->isConnected()) { interface_paths_.reset(new StreamRestoreInterface("org.PulseAudio.Ext.StreamRestore1", "/org/pulseaudio/stream_restore1", *(connection_.get()), 0)); - qDebug() << "Interface " << (void *)interface_paths_.get(); - if (interface_paths_) { // get the role paths @@ -87,7 +81,6 @@ DBusPulseVolume::DBusPulseVolume() : DBusPulseVolume::~DBusPulseVolume() { - connection_->disconnectFromPeer("unix:path=/run/user/1000/pulse/dbus-socket"); } QString DBusPulseVolume::fillRolePath(QString const &role) @@ -100,7 +93,7 @@ QString DBusPulseVolume::fillRolePath(QString const &role) qWarning() << "SetVolume::fillRolePath(): D-Bus error: " << objectPath.error().message(); return ""; } - qDebug() << "XGM: path for role " << role << "=" << objectPath.value().path(); + auto role_info = std::make_shared(); role_info->interface_.reset(new DBusPropertiesInterface("org.PulseAudio.Ext.StreamRestore1.RestoreEntry", objectPath.value().path(), @@ -122,26 +115,10 @@ bool DBusPulseVolume::setVolume(QString const & role, double volume) qWarning() << "SetVolume::setVolume(): error: Volume interfaces are not initialized"; return false; } + RolesMap::const_iterator iter = roles_map_.find(role); if (iter != roles_map_.end()) { - QDBusReply prev_vol = (*iter).second->interface_->call(QLatin1String("Get"), - QLatin1String("org.PulseAudio.Ext.StreamRestore1.RestoreEntry"), - QLatin1String("Volume")); - - if (!prev_vol.isValid()) - { - qWarning() << "SetVolume::setVolume(): D-Bus error: " << prev_vol.error().message(); - return false; - } - QDBusArgument arg = prev_vol.value().value(); - PulseaudioVolumeArray element; - arg >> element; - - PulseaudioVolume signal_vol(0, 4000); - PulseaudioVolumeArray vol_array; - vol_array.addItem(signal_vol); - QVariant var; PulseaudioVolumeArray t; PulseaudioVolume vv(0, volumeDoubleToUint(volume)); @@ -209,7 +186,6 @@ void DBusPulseVolume::initializeAccountsInterface() std::unique_ptr setInterface(new AccountsInterface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", QDBusConnection::systemBus(), 0)); - qDebug() << "Interface: " << setInterface.get(); QDBusReply userResp = setInterface->call(QLatin1String("FindUserByName"), QLatin1String(username)); @@ -228,7 +204,6 @@ void DBusPulseVolume::initializeAccountsInterface() accounts_interface_.reset(new DBusPropertiesInterface("org.freedesktop.Accounts", userPath, soundInterface->connection(), 0)); - qDebug() << "Interface for setting volume: " << accounts_interface_.get(); if (!accounts_interface_->isValid()) { qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << accounts_interface_->lastError().message(); -- cgit v1.2.3 From 22de41f3cc382adbf06be8642af5cfa7ec664c8e Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Mon, 21 Sep 2015 16:01:33 +0200 Subject: Added separated integration tests for desktop and phone, with different instances of pulseaudio --- tests/integration/indicator-sound-test-base.cpp | 76 +++++++++- tests/integration/indicator-sound-test-base.h | 11 +- tests/integration/test-indicator.cpp | 186 +++++++++++++++++++++--- tests/integration/utils/dbus-pulse-volume.cpp | 5 + 4 files changed, 255 insertions(+), 23 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 49e2ec5..a839fbc 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -45,7 +45,7 @@ IndicatorSoundTestBase::~IndicatorSoundTestBase() } -bool IndicatorSoundTestBase::setVolume(QString const &role, double volume) +bool IndicatorSoundTestBase::setStreamRestoreVolume(QString const &role, double volume) { QProcess setVolume; setVolume.start(VOLUME_SET_BIN, QStringList() @@ -60,6 +60,25 @@ bool IndicatorSoundTestBase::setVolume(QString const &role, double volume) return setVolume.exitCode() == 0; } +bool IndicatorSoundTestBase::setSinkVolume(double volume) +{ + QString volume_percentage = QString("%1\%").arg(volume*100); + QProcess setVolume; + setVolume.start("pactl", QStringList() + << "-s" + << "127.0.0.1" + << "set-sink-volume" + << "0" + << volume_percentage); + if (!setVolume.waitForStarted()) + return false; + + if (!setVolume.waitForFinished()) + return false; + + return setVolume.exitCode() == 0; +} + bool IndicatorSoundTestBase::startTestSound(QString const &role) { testSoundProcess.terminate(); @@ -81,7 +100,37 @@ void IndicatorSoundTestBase::stopTestSound() testSoundProcess.terminate(); } -void IndicatorSoundTestBase::startPulse() +void IndicatorSoundTestBase::startPulseDesktop() +{ + try + { + pulseaudio.reset( + new QProcessDBusService(DBusTypes::DBUS_PULSE, + QDBusConnection::SessionBus, + "pulseaudio", + QStringList() << "--start" + << "-vvvv" + << "--disable-shm=true" + << "--daemonize=false" + << "--use-pid-file=false" + << "--system=false" + << "--exit-idle-time=-1" + << "-n" + << "--load=module-null-sink" + << "--log-target=file:/tmp/pulse-daemon.log" + << "--load=module-dbus-protocol" + << "--load=module-native-protocol-tcp auth-ip-acl=127.0.0.1" + )); + pulseaudio->start(dbusTestRunner.sessionConnection()); + } + catch (exception const& e) + { + cout << "pulseaudio(): " << e.what() << endl; + throw; + } +} + +void IndicatorSoundTestBase::startPulsePhone() { try { @@ -151,8 +200,6 @@ void IndicatorSoundTestBase::startIndicator() } } -// /usr/bin/pulseaudio --start -vvvv --disable-shm=true --daemonize=false --use-pid-file=false --system=false --exit-idle-time=-1 -n "--load=module-null-sink sink_name=multimedia" --load=module-stream-restore - mh::MenuMatcher::Parameters IndicatorSoundTestBase::desktopParameters() { return mh::MenuMatcher::Parameters( @@ -161,6 +208,14 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::desktopParameters() "/com/canonical/indicator/sound/desktop"); } +mh::MenuMatcher::Parameters IndicatorSoundTestBase::phoneParameters() +{ + return mh::MenuMatcher::Parameters( + "com.canonical.indicator.sound", + { { "indicator", "/com/canonical/indicator/sound" } }, + "/com/canonical/indicator/sound/phone"); +} + void IndicatorSoundTestBase::SetUp() { setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true); @@ -216,9 +271,22 @@ unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double return mh::MenuItemMatcher().radio() .label("Volume") .round_doubles(0.1) + .int32_attribute("target", 0) + .double_attribute("min-value", 0.0) + .double_attribute("max-value", 1.0) + .double_attribute("step", 0.01) + .string_attribute("x-canonical-type", "com.canonical.unity.slider") .pass_through_double_attribute("action", volume); } +unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::silentModeSwitch(bool toggled) +{ + return mh::MenuItemMatcher::checkbox() + .label("Silent Mode") + .action("indicator.silent-mode") + .toggled(toggled); +} + bool IndicatorSoundTestBase::waitMenuChange() { if (!menu_interface_) diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 04a579f..019efc9 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -45,10 +45,13 @@ protected: void TearDown() override; void startIndicator(); - void startPulse(); + void startPulseDesktop(); + void startPulsePhone(); void startAccountsService(); - bool setVolume(QString const &role, double volume); + bool setStreamRestoreVolume(QString const &role, double volume); + + bool setSinkVolume(double volume); bool startTestSound(QString const &role); @@ -58,8 +61,12 @@ protected: static unity::gmenuharness::MenuMatcher::Parameters desktopParameters(); + static unity::gmenuharness::MenuMatcher::Parameters phoneParameters(); + static unity::gmenuharness::MenuItemMatcher volumeSlider(double volume); + static unity::gmenuharness::MenuItemMatcher silentModeSwitch(bool toggled); + bool waitMenuChange(); bool waitVolumeChangedInIndicator(); diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index bb5adec..a248658 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -32,16 +32,15 @@ class TestIndicator: public IndicatorSoundTestBase { }; -TEST_F(TestIndicator, ChangeRoleVolume) +TEST_F(TestIndicator, PhoneChangeRoleVolume) { double INITIAL_VOLUME = 0.0; ASSERT_NO_THROW(startAccountsService()); - ASSERT_NO_THROW(startPulse()); + ASSERT_NO_THROW(startPulsePhone()); // initialize volumes in pulseaudio - EXPECT_TRUE(setVolume("mutimedia", INITIAL_VOLUME)); - EXPECT_TRUE(setVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); @@ -53,7 +52,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) double randomVolume = randInt / 100.0; // set an initial volume to the alert role - setVolume("alert", 1.0); + setStreamRestoreVolume("alert", 1.0); EXPECT_TRUE(waitVolumeChangedInIndicator()); // play a test sound, it should change the role in the indicator @@ -61,31 +60,31 @@ TEST_F(TestIndicator, ChangeRoleVolume) EXPECT_TRUE(waitVolumeChangedInIndicator()); // set the random volume to the multimedia role - EXPECT_TRUE(setVolume("multimedia", randomVolume)); + EXPECT_TRUE(setStreamRestoreVolume("multimedia", randomVolume)); if (randomVolume != INITIAL_VOLUME) { EXPECT_TRUE(waitVolumeChangedInIndicator()); } // check the indicator - EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") .mode(mh::MenuItemMatcher::Mode::starts_with) .submenu() .item(mh::MenuItemMatcher() .section() - .item(mh::MenuItemMatcher().checkbox() - .label("Mute") - ) + .item(silentModeSwitch(false)) .item(volumeSlider(randomVolume)) ) ).match()); // check that the last item is Sound Settings - EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") .string_attribute("x-canonical-type", "com.canonical.indicator.root") @@ -94,6 +93,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) .submenu() .item(mh::MenuItemMatcher() .label("Sound Settings…") + .action("indicator.phone-settings") ) ).match()); @@ -106,6 +106,97 @@ TEST_F(TestIndicator, ChangeRoleVolume) EXPECT_TRUE(waitVolumeChangedInIndicator()); } + // check the initial volume for the alert role + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(1.0)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); +} + +TEST_F(TestIndicator, PhoneBasicInitialVolume) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulsePhone()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // check the initial volume for the alert role + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(INITIAL_VOLUME)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); +} + +TEST_F(TestIndicator, DesktopBasicInitialVolume) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulseDesktop()); + + // initialize volumes in pulseaudio + EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + // check the initial volume for the alert role EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() @@ -119,7 +210,7 @@ TEST_F(TestIndicator, ChangeRoleVolume) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(1.0)) + .item(volumeSlider(INITIAL_VOLUME)) ) ).match()); @@ -137,20 +228,42 @@ TEST_F(TestIndicator, ChangeRoleVolume) ).match()); } -TEST_F(TestIndicator, BasicInitialVolume) +TEST_F(TestIndicator, DesktopChangeRoleVolume) { double INITIAL_VOLUME = 0.0; ASSERT_NO_THROW(startAccountsService()); - ASSERT_NO_THROW(startPulse()); + ASSERT_NO_THROW(startPulseDesktop()); // initialize volumes in pulseaudio - EXPECT_TRUE(setVolume("alert", INITIAL_VOLUME)); + // expect false for stream restore, because the module + // is not loaded in the desktop pulseaudio instance + EXPECT_FALSE(setStreamRestoreVolume("mutimedia", INITIAL_VOLUME)); + EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + + EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); - // check the initial volume for the alert role + // Generate a random volume + QTime now = QTime::currentTime(); + qsrand(now.msec()); + int randInt = qrand() % 100; + double randomVolume = randInt / 100.0; + +// // play a test sound, it should NOT change the role in the indicator + EXPECT_TRUE(startTestSound("multimedia")); + EXPECT_FALSE(waitVolumeChangedInIndicator()); + + // set the random volume + EXPECT_TRUE(setSinkVolume(randomVolume)); + if (randomVolume != INITIAL_VOLUME) + { + EXPECT_FALSE(waitVolumeChangedInIndicator()); + } + + // check the indicator EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") @@ -163,7 +276,7 @@ TEST_F(TestIndicator, BasicInitialVolume) .item(mh::MenuItemMatcher().checkbox() .label("Mute") ) - .item(volumeSlider(INITIAL_VOLUME)) + .item(volumeSlider(randomVolume)) ) ).match()); @@ -179,6 +292,45 @@ TEST_F(TestIndicator, BasicInitialVolume) .label("Sound Settings…") ) ).match()); + + // stop the test sound, the role should change again to alert + stopTestSound(); + + // although we were playing something in the multimedia role + // the server does not have the streamrestore module, so + // the volume does not change (the role does not change) + EXPECT_FALSE(waitVolumeChangedInIndicator()); + + // check the initial volume for the alert role + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(randomVolume)) + ) + ).match()); + + // check that the last item is Sound Settings + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::ends_with) + .submenu() + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); } } // namespace diff --git a/tests/integration/utils/dbus-pulse-volume.cpp b/tests/integration/utils/dbus-pulse-volume.cpp index a282f77..c8b6ae6 100644 --- a/tests/integration/utils/dbus-pulse-volume.cpp +++ b/tests/integration/utils/dbus-pulse-volume.cpp @@ -150,6 +150,11 @@ bool DBusPulseVolume::setVolume(QString const & role, double volume) } } } + else + { + qWarning() << "SetVolume::setVolume(): role " << role << " was not found."; + return false; + } return true; } -- cgit v1.2.3 From b9ef4f6abdefb7b1d31d34f35b742016f1b5b87f Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Tue, 22 Sep 2015 11:52:43 +0200 Subject: Added themed_icon to integration tests --- tests/integration/indicator-sound-test-base.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index a839fbc..bbede82 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -276,6 +276,8 @@ unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double .double_attribute("max-value", 1.0) .double_attribute("step", 0.01) .string_attribute("x-canonical-type", "com.canonical.unity.slider") + .themed_icon("max-icon", {"audio-volume-high-panel", "audio-volume-high", "audio-volume", "audio"}) + .themed_icon("min-icon", {"audio-volume-low-zero-panel", "audio-volume-low-zero", "audio-volume-low", "audio-volume", "audio"}) .pass_through_double_attribute("action", volume); } -- cgit v1.2.3 From eb22c54e4587e5941378b066ec8220a56d26db4b Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Wed, 23 Sep 2015 16:10:54 +0200 Subject: Added test MPRIS player integration test --- tests/integration/CMakeLists.txt | 5 +- tests/integration/indicator-sound-test-base.cpp | 36 ++++++++++-- tests/integration/indicator-sound-test-base.h | 6 ++ tests/integration/test-indicator.cpp | 74 +++++++++++++++++++------ 4 files changed, 97 insertions(+), 24 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 52c4e70..5798f14 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -29,10 +29,11 @@ include_directories("${CMAKE_BINARY_DIR}/tests/dbus-types") add_definitions(-DSOUND_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator-sound-service" -DSTREAM_RESTORE_TABLE="${CMAKE_SOURCE_DIR}/tests/integration/touch-stream-restore.table" -DVOLUME_SET_BIN="${CMAKE_BINARY_DIR}/tests/integration/set-volume" - -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/accounts-mock/accounts-service-sound" + -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/accounts-mock/accounts-service-sound" + -DMEDIA_PLAYER_MPRIS_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/media-player-mpris-mock/media-player-mpris-mock" -DTEST_SOUND="${CMAKE_SOURCE_DIR}/tests/integration/test-sound.wav" -DQT_NO_KEYWORDS=1 - -DSCHEMA_DIR="${SCHEMA_DIR}" + -DXDG_DATA_DIRS="${XDG_DATA_DIRS}" ) set(GLIB_REQUIRED_VERSION 2.26) diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index bbede82..2b6b3d7 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -79,6 +79,36 @@ bool IndicatorSoundTestBase::setSinkVolume(double volume) return setVolume.exitCode() == 0; } +bool IndicatorSoundTestBase::clearGSettingsPlayers() +{ + QProcess clearPlayers; + + clearPlayers.start("gsettings", QStringList() + << "set" + << "com.canonical.indicator.sound" + << "interested-media-players" + << "[]"); + if (!clearPlayers.waitForStarted()) + return false; + + if (!clearPlayers.waitForFinished()) + return false; + + return clearPlayers.exitCode() == 0; +} + +bool IndicatorSoundTestBase::startTestMprisPlayer(QString const& playerName) +{ + testPlayer1.terminate(); + testPlayer1.start(MEDIA_PLAYER_MPRIS_BIN, QStringList() + << playerName); + if (!testPlayer1.waitForStarted()) + return false; + + + return true; +} + bool IndicatorSoundTestBase::startTestSound(QString const &role) { testSoundProcess.terminate(); @@ -218,15 +248,13 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::phoneParameters() void IndicatorSoundTestBase::SetUp() { - setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true); - setenv("GSETTINGS_BACKEND", "memory", true); + setenv("XDG_DATA_DIRS", XDG_DATA_DIRS, true); setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); } void IndicatorSoundTestBase::TearDown() { - unsetenv("GSETTINGS_SCHEMA_DIR"); - unsetenv("GSETTINGS_BACKEND"); + unsetenv("XDG_DATA_DIRS"); unsetenv("PULSE_SERVER"); } diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 019efc9..741580b 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -49,6 +49,10 @@ protected: void startPulsePhone(); void startAccountsService(); + bool clearGSettingsPlayers(); + + bool startTestMprisPlayer(QString const& playerName); + bool setStreamRestoreVolume(QString const &role, double volume); bool setSinkVolume(double volume); @@ -85,6 +89,8 @@ protected: QProcess testSoundProcess; + QProcess testPlayer1; + std::unique_ptr menu_interface_; std::unique_ptr accounts_interface_; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index a248658..ca3d298 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -143,6 +143,7 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume) double INITIAL_VOLUME = 0.0; ASSERT_NO_THROW(startAccountsService()); + EXPECT_TRUE(clearGSettingsPlayers()); ASSERT_NO_THROW(startPulsePhone()); // initialize volumes in pulseaudio @@ -151,7 +152,6 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume) // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); - // check the initial volume for the alert role EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") @@ -159,23 +159,17 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume) .string_attribute("x-canonical-scroll-action", "indicator.scroll") .string_attribute("x-canonical-secondary-action", "indicator.mute") .string_attribute("submenu-action", "indicator.indicator-shown") - .mode(mh::MenuItemMatcher::Mode::starts_with) + .mode(mh::MenuItemMatcher::Mode::all) .submenu() .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) .item(volumeSlider(INITIAL_VOLUME)) ) - ).match()); - - // check that the last item is Sound Settings - EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) - .item(mh::MenuItemMatcher() - .action("indicator.root") - .string_attribute("x-canonical-type", "com.canonical.indicator.root") - .string_attribute("x-canonical-secondary-action", "indicator.mute") - .mode(mh::MenuItemMatcher::Mode::ends_with) - .submenu() +// .item(mh::MenuItemMatcher() +// .section() +// .action("indicator.testplayer1.desktop") +// ) .item(mh::MenuItemMatcher() .label("Sound Settings…") .action("indicator.phone-settings") @@ -188,6 +182,7 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume) double INITIAL_VOLUME = 0.0; ASSERT_NO_THROW(startAccountsService()); + EXPECT_TRUE(clearGSettingsPlayers()); ASSERT_NO_THROW(startPulseDesktop()); // initialize volumes in pulseaudio @@ -197,13 +192,12 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume) // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); - // check the initial volume for the alert role EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") .string_attribute("x-canonical-type", "com.canonical.indicator.root") .string_attribute("x-canonical-secondary-action", "indicator.mute") - .mode(mh::MenuItemMatcher::Mode::starts_with) + .mode(mh::MenuItemMatcher::Mode::all) .submenu() .item(mh::MenuItemMatcher() .section() @@ -212,19 +206,63 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume) ) .item(volumeSlider(INITIAL_VOLUME)) ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) ).match()); +} - // check that the last item is Sound Settings +TEST_F(TestIndicator, DesktopAddPlayer) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + EXPECT_TRUE(clearGSettingsPlayers()); + ASSERT_NO_THROW(startPulseDesktop()); + + // initialize volumes in pulseaudio + EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); + + // start the test player + EXPECT_TRUE(startTestMprisPlayer("testplayer1")); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // check that the player is added EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") .string_attribute("x-canonical-type", "com.canonical.indicator.root") .string_attribute("x-canonical-secondary-action", "indicator.mute") - .mode(mh::MenuItemMatcher::Mode::ends_with) + .mode(mh::MenuItemMatcher::Mode::all) .submenu() .item(mh::MenuItemMatcher() - .label("Sound Settings…") + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(INITIAL_VOLUME)) ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .string_attribute("x-canonical-next-action","indicator.next.testplayer1.desktop") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) ).match()); } @@ -252,7 +290,7 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) int randInt = qrand() % 100; double randomVolume = randInt / 100.0; -// // play a test sound, it should NOT change the role in the indicator + // play a test sound, it should NOT change the role in the indicator EXPECT_TRUE(startTestSound("multimedia")); EXPECT_FALSE(waitVolumeChangedInIndicator()); -- cgit v1.2.3 From 5d88ce9836c1d32abfd369e650354ed855ec4654 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Fri, 25 Sep 2015 10:31:24 +0200 Subject: Added attribute_not_set to gmenuharness, added tests for player control buttons --- tests/integration/CMakeLists.txt | 1 + tests/integration/indicator-sound-test-base.cpp | 19 ++ tests/integration/indicator-sound-test-base.h | 2 + tests/integration/test-indicator.cpp | 228 +++++++++++++++++++++++- 4 files changed, 245 insertions(+), 5 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt index 5798f14..939e329 100644 --- a/tests/integration/CMakeLists.txt +++ b/tests/integration/CMakeLists.txt @@ -31,6 +31,7 @@ add_definitions(-DSOUND_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator-sound-ser -DVOLUME_SET_BIN="${CMAKE_BINARY_DIR}/tests/integration/set-volume" -DACCOUNTS_SERVICE_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/accounts-mock/accounts-service-sound" -DMEDIA_PLAYER_MPRIS_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/media-player-mpris-mock/media-player-mpris-mock" + -DMEDIA_PLAYER_MPRIS_UPDATE_BIN="${CMAKE_BINARY_DIR}/tests/service-mocks/media-player-mpris-mock/media-player-mpris-mock-update" -DTEST_SOUND="${CMAKE_SOURCE_DIR}/tests/integration/test-sound.wav" -DQT_NO_KEYWORDS=1 -DXDG_DATA_DIRS="${XDG_DATA_DIRS}" diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 2b6b3d7..16f0bd6 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -109,6 +109,25 @@ bool IndicatorSoundTestBase::startTestMprisPlayer(QString const& playerName) return true; } +bool IndicatorSoundTestBase::setTestMprisPlayerProperty(QString const &testPlayer, QString const &property, bool value) +{ + QProcess setProperty; + QString strValue; + strValue = value ? "true" : "false"; + + setProperty.start(MEDIA_PLAYER_MPRIS_UPDATE_BIN, QStringList() + << testPlayer + << property + << strValue); + if (!setProperty.waitForStarted()) + return false; + + if (!setProperty.waitForFinished()) + return false; + + return setProperty.exitCode() == 0; +} + bool IndicatorSoundTestBase::startTestSound(QString const &role) { testSoundProcess.terminate(); diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 741580b..00ccf1a 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -53,6 +53,8 @@ protected: bool startTestMprisPlayer(QString const& playerName); + bool setTestMprisPlayerProperty(QString const &testPlayer, QString const &property, bool value); + bool setStreamRestoreVolume(QString const &role, double volume); bool setSinkVolume(double volume); diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index ca3d298..82f06a4 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -166,10 +166,41 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume) .item(silentModeSwitch(false)) .item(volumeSlider(INITIAL_VOLUME)) ) -// .item(mh::MenuItemMatcher() -// .section() -// .action("indicator.testplayer1.desktop") -// ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); +} + +TEST_F(TestIndicator, PhoneAddMprisPlayer) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + EXPECT_TRUE(clearGSettingsPlayers()); + ASSERT_NO_THROW(startPulsePhone()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(INITIAL_VOLUME)) + ) .item(mh::MenuItemMatcher() .label("Sound Settings…") .action("indicator.phone-settings") @@ -189,9 +220,66 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume) EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); + // start the test player + EXPECT_TRUE(startTestMprisPlayer("testplayer1")); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(INITIAL_VOLUME)) + ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .string_attribute("x-canonical-next-action","indicator.next.testplayer1.desktop") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); +} + +TEST_F(TestIndicator, DesktopAddMprisPlayer) +{ + double INITIAL_VOLUME = 0.0; + + ASSERT_NO_THROW(startAccountsService()); + EXPECT_TRUE(clearGSettingsPlayers()); + ASSERT_NO_THROW(startPulseDesktop()); + + // initialize volumes in pulseaudio + EXPECT_FALSE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setSinkVolume(INITIAL_VOLUME)); + + // start the test player + EXPECT_TRUE(startTestMprisPlayer("testplayer1")); + // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); + // check that the player is added EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) .item(mh::MenuItemMatcher() .action("indicator.root") @@ -206,13 +294,28 @@ TEST_F(TestIndicator, DesktopBasicInitialVolume) ) .item(volumeSlider(INITIAL_VOLUME)) ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .string_attribute("x-canonical-next-action","indicator.next.testplayer1.desktop") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) .item(mh::MenuItemMatcher() .label("Sound Settings…") ) ).match()); } -TEST_F(TestIndicator, DesktopAddPlayer) +TEST_F(TestIndicator, DesktopMprisPlayerButtonsState) { double INITIAL_VOLUME = 0.0; @@ -264,6 +367,121 @@ TEST_F(TestIndicator, DesktopAddPlayer) .label("Sound Settings…") ) ).match()); + + // change the state of CanGoNext + EXPECT_TRUE(setTestMprisPlayerProperty("testplayer1", "CanGoNext", false)); + + // verify that the action changes + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(INITIAL_VOLUME)) + ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .attribute_not_set("x-canonical-next-action") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); + + + // change the state of CanGoPrevious + EXPECT_TRUE(setTestMprisPlayerProperty("testplayer1", "CanGoPrevious", false)); + + // verify that the action changes + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(INITIAL_VOLUME)) + ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .attribute_not_set("x-canonical-previous-action") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .attribute_not_set("x-canonical-next-action") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); + + // set back both to true + EXPECT_TRUE(setTestMprisPlayerProperty("testplayer1", "CanGoNext", true)); + EXPECT_TRUE(setTestMprisPlayerProperty("testplayer1", "CanGoPrevious", true)); + + EXPECT_MATCHRESULT(mh::MenuMatcher(desktopParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher().checkbox() + .label("Mute") + ) + .item(volumeSlider(INITIAL_VOLUME)) + ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .string_attribute("x-canonical-next-action","indicator.next.testplayer1.desktop") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + ) + ).match()); } TEST_F(TestIndicator, DesktopChangeRoleVolume) -- cgit v1.2.3 From 2dba91ca24ce98f866498333c7a39e20d68813f7 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Thu, 1 Oct 2015 15:15:16 +0200 Subject: added mechanism to wait for the gmenu to change. Added player test for the phone profile --- tests/integration/indicator-sound-test-base.cpp | 38 +++++++++++++------- tests/integration/indicator-sound-test-base.h | 4 +++ tests/integration/test-indicator.cpp | 47 ++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 14 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 16f0bd6..a8d41a0 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -140,7 +140,6 @@ bool IndicatorSoundTestBase::startTestSound(QString const &role) if (!testSoundProcess.waitForStarted()) return false; -// sleep(1); return true; } @@ -218,7 +217,7 @@ void IndicatorSoundTestBase::startAccountsService() new QProcessDBusService(DBusTypes::ACCOUNTS_SERVICE, QDBusConnection::SystemBus, ACCOUNTS_SERVICE_BIN, - QStringList() )); + QStringList())); accountsService->start(dbusTestRunner.systemConnection()); initializeAccountsInterface(); @@ -275,6 +274,7 @@ void IndicatorSoundTestBase::TearDown() { unsetenv("XDG_DATA_DIRS"); unsetenv("PULSE_SERVER"); + unsetenv("DBUS_SYSTEM_BUS_ADDRESS"); } void gvariant_deleter(GVariant* varptr) @@ -337,21 +337,32 @@ unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::silentModeSwitch(bo } bool IndicatorSoundTestBase::waitMenuChange() +{ + if (signal_spy_menu_changed_) + { + return signal_spy_menu_changed_->wait(); + } + return false; +} + +bool IndicatorSoundTestBase::initializeMenuChangedSignal() { if (!menu_interface_) { menu_interface_.reset(new MenusInterface("com.canonical.indicator.sound", - "/com/canonical/indicator/sound/desktop", - QDBusConnection::sessionBus(), 0)); + "/com/canonical/indicator/sound", + dbusTestRunner.sessionConnection(), 0)); } if (menu_interface_) { qDebug() << "Waiting for signal"; - QSignalSpy spy(menu_interface_.get(), &MenusInterface::Changed); - qDebug() << "Signal count " << spy.count(); - return spy.wait(); + signal_spy_menu_changed_.reset(new QSignalSpy(menu_interface_.get(), &MenusInterface::Changed)); } - return false; + if (!menu_interface_ || !signal_spy_menu_changed_) + { + return false; + } + return true; } bool IndicatorSoundTestBase::waitVolumeChangedInIndicator() @@ -368,27 +379,28 @@ void IndicatorSoundTestBase::initializeAccountsInterface() auto username = qgetenv("USER"); if (username != "") { - std::unique_ptr setInterface(new AccountsInterface("org.freedesktop.Accounts", + std::unique_ptr accountsInterface(new AccountsInterface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", - QDBusConnection::systemBus(), 0)); + dbusTestRunner.systemConnection(), 0)); - QDBusReply userResp = setInterface->call(QLatin1String("FindUserByName"), + QDBusReply userResp = accountsInterface->call(QLatin1String("FindUserByName"), QLatin1String(username)); if (!userResp.isValid()) { qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << userResp.error().message(); } + auto userPath = userResp.value().path(); if (userPath != "") { std::unique_ptr soundInterface(new AccountsSoundInterface("org.freedesktop.Accounts", userPath, - QDBusConnection::systemBus(), 0)); + dbusTestRunner.systemConnection(), 0)); accounts_interface_.reset(new DBusPropertiesInterface("org.freedesktop.Accounts", userPath, - soundInterface->connection(), 0)); + dbusTestRunner.systemConnection(), 0)); if (!accounts_interface_->isValid()) { qWarning() << "SetVolume::initializeAccountsInterface(): D-Bus error: " << accounts_interface_->lastError().message(); diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 00ccf1a..0dc0052 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -75,6 +75,8 @@ protected: bool waitMenuChange(); + bool initializeMenuChangedSignal(); + bool waitVolumeChangedInIndicator(); void initializeAccountsInterface(); @@ -98,4 +100,6 @@ protected: std::unique_ptr accounts_interface_; std::unique_ptr signal_spy_volume_changed_; + + std::unique_ptr signal_spy_menu_changed_; }; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 82f06a4..22c0041 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -206,6 +206,51 @@ TEST_F(TestIndicator, PhoneAddMprisPlayer) .action("indicator.phone-settings") ) ).match()); + + // initialize the signal spy + EXPECT_TRUE(initializeMenuChangedSignal()); + + // start the test player + EXPECT_TRUE(startTestMprisPlayer("testplayer1")); + + // wait fot the menu change + EXPECT_TRUE(waitMenuChange()); + + // finally verify that the player is added + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(INITIAL_VOLUME)) + ) + .item(mh::MenuItemMatcher() + .section() + .item(mh::MenuItemMatcher() + .action("indicator.testplayer1.desktop") + .label("TestPlayer1") + .themed_icon("icon", {"testplayer"}) + .string_attribute("x-canonical-type", "com.canonical.unity.media-player") + ) + .item(mh::MenuItemMatcher() + .string_attribute("x-canonical-previous-action","indicator.previous.testplayer1.desktop") + .string_attribute("x-canonical-play-action","indicator.play.testplayer1.desktop") + .string_attribute("x-canonical-next-action","indicator.next.testplayer1.desktop") + .string_attribute("x-canonical-type","com.canonical.unity.playback-item") + ) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); } TEST_F(TestIndicator, DesktopBasicInitialVolume) @@ -516,7 +561,7 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) EXPECT_TRUE(setSinkVolume(randomVolume)); if (randomVolume != INITIAL_VOLUME) { - EXPECT_FALSE(waitVolumeChangedInIndicator()); + EXPECT_TRUE(waitVolumeChangedInIndicator()); } // check the indicator -- cgit v1.2.3 From 8402eadfcbd96b753f7cf2402956c100812de54e Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Thu, 1 Oct 2015 15:45:30 +0200 Subject: fixed typo in comment --- tests/integration/test-indicator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/integration') diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 22c0041..5a4b4ee 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -213,7 +213,7 @@ TEST_F(TestIndicator, PhoneAddMprisPlayer) // start the test player EXPECT_TRUE(startTestMprisPlayer("testplayer1")); - // wait fot the menu change + // wait for the menu change EXPECT_TRUE(waitMenuChange()); // finally verify that the player is added -- cgit v1.2.3 From 828fae630464f2eae96145cffcf97e5791497264 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Tue, 13 Oct 2015 09:49:55 +0200 Subject: Added notifications tests integrated with the test instance of pulseAudio and gmenuharness --- tests/integration/indicator-sound-test-base.cpp | 319 ++++++++++++++++++++---- tests/integration/indicator-sound-test-base.h | 29 +++ tests/integration/test-indicator.cpp | 288 +++++++++++++++++++++ 3 files changed, 585 insertions(+), 51 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index a8d41a0..f9db365 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -22,6 +22,7 @@ #include "dbus_properties_interface.h" #include "dbus_accounts_interface.h" #include "dbus_accountssound_interface.h" +#include "dbus_notifications_interface.h" #include "dbus-types.h" #include @@ -42,7 +43,67 @@ IndicatorSoundTestBase::IndicatorSoundTestBase() : IndicatorSoundTestBase::~IndicatorSoundTestBase() { +} + +void IndicatorSoundTestBase::SetUp() +{ + setenv("XDG_DATA_DIRS", XDG_DATA_DIRS, true); + setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); + setenv("DBUS_SESSION_BUS_ADDRESS", dbusTestRunner.sessionBus().toStdString().c_str(), true); + dbusMock.registerNotificationDaemon(); + + dbusTestRunner.startServices(); + + auto& notifications = notificationsMockInterface(); + notifications.AddMethod("org.freedesktop.Notifications", + "GetCapabilities", + "", + "as", + "ret = ['actions', 'body', 'body-markup', 'icon-static', 'image/svg+xml', 'x-canonical-private-synchronous', 'x-canonical-append', 'x-canonical-private-icon-only', 'x-canonical-truncation', 'private-synchronous', 'append', 'private-icon-only', 'truncation']" + ).waitForFinished(); +} + +void IndicatorSoundTestBase::TearDown() +{ + unsetenv("XDG_DATA_DIRS"); + unsetenv("PULSE_SERVER"); + unsetenv("DBUS_SYSTEM_BUS_ADDRESS"); +} + +void gvariant_deleter(GVariant* varptr) +{ + if (varptr != nullptr) + { + g_variant_unref(varptr); + } +} +std::shared_ptr IndicatorSoundTestBase::volume_variant(double volume) +{ + GVariantBuilder builder; + + g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&builder, + "{sv}", + "title", + g_variant_new_string("_Sound")); + + g_variant_builder_add(&builder, + "{sv}", + "accessible-desc", + g_variant_new_string("_Sound")); + + auto icon = g_themed_icon_new("icon"); + g_variant_builder_add(&builder, + "{sv}", + "icon", + g_icon_serialize(icon)); + + g_variant_builder_add(&builder, + "{sv}", + "visible", + g_variant_new_boolean(true)); + return shared_ptr(g_variant_builder_end(&builder), &gvariant_deleter); } bool IndicatorSoundTestBase::setStreamRestoreVolume(QString const &role, double volume) @@ -164,7 +225,8 @@ void IndicatorSoundTestBase::startPulseDesktop() << "--system=false" << "--exit-idle-time=-1" << "-n" - << "--load=module-null-sink" + << QString("--load=module-null-sink sink_name=indicator_sound_test_speaker") + << QString("--load=module-null-sink sink_name=indicator_sound_test_headphones") << "--log-target=file:/tmp/pulse-daemon.log" << "--load=module-dbus-protocol" << "--load=module-native-protocol-tcp auth-ip-acl=127.0.0.1" @@ -194,7 +256,8 @@ void IndicatorSoundTestBase::startPulsePhone() << "--system=false" << "--exit-idle-time=-1" << "-n" - << "--load=module-null-sink" + << QString("--load=module-null-sink sink_name=indicator_sound_test_speaker") + << QString("--load=module-null-sink sink_name=indicator_sound_test_headphones") << "--log-target=file:/tmp/pulse-daemon.log" << QString("--load=module-stream-restore restore_device=false restore_muted=false fallback_table=%1").arg(STREAM_RESTORE_TABLE) << "--load=module-dbus-protocol" @@ -264,55 +327,6 @@ mh::MenuMatcher::Parameters IndicatorSoundTestBase::phoneParameters() "/com/canonical/indicator/sound/phone"); } -void IndicatorSoundTestBase::SetUp() -{ - setenv("XDG_DATA_DIRS", XDG_DATA_DIRS, true); - setenv("DBUS_SYSTEM_BUS_ADDRESS", dbusTestRunner.systemBus().toStdString().c_str(), true); -} - -void IndicatorSoundTestBase::TearDown() -{ - unsetenv("XDG_DATA_DIRS"); - unsetenv("PULSE_SERVER"); - unsetenv("DBUS_SYSTEM_BUS_ADDRESS"); -} - -void gvariant_deleter(GVariant* varptr) -{ - if (varptr != nullptr) - { - g_variant_unref(varptr); - } -} - -std::shared_ptr IndicatorSoundTestBase::volume_variant(double volume) -{ - GVariantBuilder builder; - - g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT); - g_variant_builder_add(&builder, - "{sv}", - "title", - g_variant_new_string("_Sound")); - - g_variant_builder_add(&builder, - "{sv}", - "accessible-desc", - g_variant_new_string("_Sound")); - - auto icon = g_themed_icon_new("icon"); - g_variant_builder_add(&builder, - "{sv}", - "icon", - g_icon_serialize(icon)); - - g_variant_builder_add(&builder, - "{sv}", - "visible", - g_variant_new_boolean(true)); - return shared_ptr(g_variant_builder_end(&builder), &gvariant_deleter); -} - unity::gmenuharness::MenuItemMatcher IndicatorSoundTestBase::volumeSlider(double volume) { return mh::MenuItemMatcher().radio() @@ -409,3 +423,206 @@ void IndicatorSoundTestBase::initializeAccountsInterface() } } } + +OrgFreedesktopDBusMockInterface& IndicatorSoundTestBase::notificationsMockInterface() +{ + return dbusMock.mockInterface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::SessionBus); +} + +bool IndicatorSoundTestBase::setActionValue(const QString & action, QVariant value) +{ + QDBusInterface actionsInterface(DBusTypes::DBUS_NAME, + DBusTypes::MAIN_SERVICE_PATH, + DBusTypes::ACTIONS_INTERFACE, + dbusTestRunner.sessionConnection()); + + QDBusVariant dbusVar(value); + auto resp = actionsInterface.call("SetState", + action, + QVariant::fromValue(dbusVar), + QVariant::fromValue(QVariantMap())); + + if (resp.type() == QDBusMessage::ErrorMessage) + { + qCritical() << "IndicatorSoundTestBase::setActionValue(): Failed to set value for action " + << action + << " " + << resp.errorMessage(); + return false; + } + else + { + return true; + } +} + +bool IndicatorSoundTestBase::pressNotificationButton(int id, const QString & button) +{ + OrgFreedesktopDBusMockInterface actionsInterface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + dbusTestRunner.sessionConnection()); + + actionsInterface.EmitSignal( + "org.freedesktop.Notifications", + "ActionInvoked", "us", QVariantList() << id << button); + + return true; +} + +bool IndicatorSoundTestBase::qDBusArgumentToMap(QVariant const& variant, QVariantMap& map) +{ + if (variant.canConvert()) + { + QDBusArgument value(variant.value()); + if (value.currentType() == QDBusArgument::MapType) + { + value >> map; + return true; + } + } + return false; +} + +void IndicatorSoundTestBase::checkVolumeNotification(double volume, QString const& label, bool isLoud, QVariantList call) +{ + QString icon; + if (volume <= 0.0) + { + icon = "audio-volume-muted"; + } + else if (volume <= 0.3) + { + icon = "audio-volume-low"; + } + else if (volume <= 0.7) + { + icon = "audio-volume-medium"; + } + else + { + icon = "audio-volume-high"; + } + + ASSERT_NE(call.size(), 0); + EXPECT_EQ("Notify", call.at(0)); + + QVariantList const& args(call.at(1).toList()); + ASSERT_EQ(8, args.size()); + EXPECT_EQ("indicator-sound", args.at(0)); + EXPECT_EQ(icon, args.at(2)); + EXPECT_EQ("Volume", args.at(3)); + EXPECT_EQ(label, args.at(4)); + EXPECT_EQ(QStringList(), args.at(5)); + + QVariantMap hints; + ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints)); + ASSERT_TRUE(hints.contains("value")); + ASSERT_TRUE(hints.contains("x-canonical-non-shaped-icon")); + ASSERT_TRUE(hints.contains("x-canonical-value-bar-tint")); + ASSERT_TRUE(hints.contains("x-canonical-private-synchronous")); + + EXPECT_EQ(volume*100, hints["value"]); + EXPECT_EQ(true, hints["x-canonical-non-shaped-icon"]); + EXPECT_EQ(isLoud, hints["x-canonical-value-bar-tint"]); + EXPECT_EQ(true, hints["x-canonical-private-synchronous"]); +} + +void IndicatorSoundTestBase::checkHighVolumeNotification(QVariantList call) +{ + ASSERT_NE(call.size(), 0); + EXPECT_EQ("Notify", call.at(0)); + + QVariantList const& args(call.at(1).toList()); + ASSERT_EQ(8, args.size()); + EXPECT_EQ("indicator-sound", args.at(0)); + EXPECT_EQ("Volume", args.at(3)); +} + +void IndicatorSoundTestBase::checkCloseNotification(int id, QVariantList call) +{ + EXPECT_EQ("CloseNotification", call.at(0)); + QVariantList const& args(call.at(1).toList()); + ASSERT_EQ(1, args.size()); +} + +void IndicatorSoundTestBase::checkNotificationWithNoArgs(QString const& method, QVariantList call) +{ + EXPECT_EQ(method, call.at(0)); + QVariantList const& args(call.at(1).toList()); + ASSERT_EQ(0, args.size()); +} + +int IndicatorSoundTestBase::getNotificationID(QVariantList call) +{ + if (call.size() == 0) + { + return -1; + } + QVariantList const& args(call.at(1).toList()); + if (args.size() != 8) + { + return -1; + } + if (args.at(0) != "indicator-sound") + { + return -1; + } + + bool isInt; + int id = args.at(1).toInt(&isInt); + if (!isInt) + { + return -1; + } + return id; +} + +bool IndicatorSoundTestBase::activateHeadphones(bool headphonesActive) +{ + QProcess pacltProcess; + + QString defaultSinkName = "indicator_sound_test_speaker"; + QString suspendedSinkName = "indicator_sound_test_headphones"; + if (headphonesActive) + { + defaultSinkName = "indicator_sound_test_headphones"; + suspendedSinkName = "indicator_sound_test_speaker"; + } + + pacltProcess.start("pactl", QStringList() << "-s" + << "127.0.0.1" + << "set-default-sink" + << defaultSinkName); + if (!pacltProcess.waitForStarted()) + return false; + + if (!pacltProcess.waitForFinished()) + return false; + + pacltProcess.start("pactl", QStringList() << "-s" + << "127.0.0.1" + << "suspend-sink" + << defaultSinkName + << "0"); + if (!pacltProcess.waitForStarted()) + return false; + + if (!pacltProcess.waitForFinished()) + return false; + + pacltProcess.start("pactl", QStringList() << "-s" + << "127.0.0.1" + << "suspend-sink" + << suspendedSinkName + << "1"); + if (!pacltProcess.waitForStarted()) + return false; + + if (!pacltProcess.waitForFinished()) + return false; + + return pacltProcess.exitCode() == 0; +} diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 0dc0052..20e44fc 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -33,6 +33,15 @@ class DBusPulseVolume; class DBusPropertiesInterface; class QSignalSpy; +#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\ +{\ + while (signalSpy.size() < signalsExpected)\ + {\ + ASSERT_TRUE(signalSpy.wait());\ + }\ + ASSERT_EQ(signalsExpected, signalSpy.size());\ +} + class IndicatorSoundTestBase: public testing::Test { public: @@ -81,6 +90,26 @@ protected: void initializeAccountsInterface(); + OrgFreedesktopDBusMockInterface& notificationsMockInterface(); + + bool setActionValue(const QString & action, QVariant value); + + bool pressNotificationButton(int id, const QString & button); + + bool qDBusArgumentToMap(QVariant const& variant, QVariantMap& map); + + void checkVolumeNotification(double volume, QString const& label, bool isLoud, QVariantList call); + + void checkHighVolumeNotification(QVariantList call); + + void checkCloseNotification(int id, QVariantList call); + + void checkNotificationWithNoArgs(QString const& method, QVariantList call); + + int getNotificationID(QVariantList call); + + bool activateHeadphones(bool headphonesActive); + QtDBusTest::DBusTestRunner dbusTestRunner; QtDBusMock::DBusMock dbusMock; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 5a4b4ee..1607367 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -634,4 +634,292 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) ).match()); } +TEST_F(TestIndicator, PhoneNotificationVolume) +{ + double INITIAL_VOLUME = 0.0; + + QSignalSpy notificationsSpy(¬ificationsMockInterface(), + SIGNAL(MethodCalled(const QString &, const QVariantList &))); + + ASSERT_NO_THROW(startAccountsService()); + EXPECT_TRUE(clearGSettingsPlayers()); + ASSERT_NO_THROW(startPulsePhone()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // check the initial state + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::all) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(INITIAL_VOLUME)) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settings…") + .action("indicator.phone-settings") + ) + ).match()); + + // change volume to 1.0 + setActionValue("volume", QVariant::fromValue(1.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 3); + + // the first time we also have the calls to + // GetServerInformation and GetCapabilities + checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); + checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); + checkVolumeNotification(1.0, "", false, notificationsSpy.at(2)); + + notificationsSpy.clear(); + setActionValue("volume", QVariant::fromValue(0.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 1) + + checkVolumeNotification(0.0, "", false, notificationsSpy.at(0)); + + notificationsSpy.clear(); + setActionValue("volume", QVariant::fromValue(0.5)); + + WAIT_FOR_SIGNALS(notificationsSpy, 1) + + checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); +} + +TEST_F(TestIndicator, PhoneNotificationWarningVolume) +{ + double INITIAL_VOLUME = 0.0; + + QSignalSpy notificationsSpy(¬ificationsMockInterface(), + SIGNAL(MethodCalled(const QString &, const QVariantList &))); + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulsePhone()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setStreamRestoreVolume("multimedia", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // activate the headphones + EXPECT_TRUE(activateHeadphones(true)); + + // set an initial volume to the alert role + setStreamRestoreVolume("alert", 1.0); + EXPECT_TRUE(waitVolumeChangedInIndicator()); + + // play a test sound, it should change the role in the indicator + EXPECT_TRUE(startTestSound("multimedia")); + EXPECT_TRUE(waitVolumeChangedInIndicator()); + + // change volume to 0.0... no warning should be emitted + setActionValue("volume", QVariant::fromValue(0.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 3); + + // the first time we also have the calls to + // GetServerInformation and GetCapabilities + checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); + checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); + checkVolumeNotification(0.0, "", false, notificationsSpy.at(2)); + notificationsSpy.clear(); + + // change volume to 0.5... no warning should be emitted + setActionValue("volume", QVariant::fromValue(0.5)); + + WAIT_FOR_SIGNALS(notificationsSpy, 1); + + checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); + notificationsSpy.clear(); + + // change volume to 1.0... warning should be emitted + setActionValue("volume", QVariant::fromValue(1.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 4); + + // the notification is sent twice (TODO check why) + checkCloseNotification(1, notificationsSpy.at(0)); + checkHighVolumeNotification(notificationsSpy.at(1)); + checkCloseNotification(1, notificationsSpy.at(2)); + checkHighVolumeNotification(notificationsSpy.at(3)); + + // get the last notification ID + int idNotification = getNotificationID(notificationsSpy.at(3)); + ASSERT_NE(-1, idNotification); + + qWarning() << "XGM: id Notification: " << idNotification; + + // cancel the dialog + pressNotificationButton(idNotification, "cancel"); + + // check that the volume was clamped + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(0.74)) + ) + ).match()); + + // try again... + notificationsSpy.clear(); + // change volume to 1.0... warning should be emitted + setActionValue("volume", QVariant::fromValue(1.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 4); + + checkCloseNotification(1, notificationsSpy.at(0)); + checkHighVolumeNotification(notificationsSpy.at(1)); + checkCloseNotification(1, notificationsSpy.at(2)); + checkHighVolumeNotification(notificationsSpy.at(3)); + + // get the last notification ID + idNotification = getNotificationID(notificationsSpy.at(3)); + ASSERT_NE(-1, idNotification); + + qWarning() << "XGM: id Notification: " << idNotification; + + // this time we approve + pressNotificationButton(idNotification, "ok"); + + // check that the volume was applied + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(1.0)) + .item(mh::MenuItemMatcher() + .action("indicator.high-volume-warning-item") + .label("High volume can damage your hearing.") + ) + ) + ).match()); + + // after the warning was approved we should be able to modify the volume + // and don't get the warning + notificationsSpy.clear(); + + // change volume to 0.5... no warning should be emitted + setActionValue("volume", QVariant::fromValue(0.5)); + + WAIT_FOR_SIGNALS(notificationsSpy, 2); + + // check the notification TODO check why the sound indicator sends it twice + checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); + checkVolumeNotification(0.5, "", false, notificationsSpy.at(1)); + + // check that the volume was applied + // and that we don't have the warning item + EXPECT_MATCHRESULT(mh::MenuMatcher(phoneParameters()) + .item(mh::MenuItemMatcher() + .action("indicator.root") + .string_attribute("x-canonical-type", "com.canonical.indicator.root") + .string_attribute("x-canonical-scroll-action", "indicator.scroll") + .string_attribute("x-canonical-secondary-action", "indicator.mute") + .string_attribute("submenu-action", "indicator.indicator-shown") + .mode(mh::MenuItemMatcher::Mode::starts_with) + .submenu() + .item(mh::MenuItemMatcher() + .section() + .item(silentModeSwitch(false)) + .item(volumeSlider(0.5)) + ) + ).match()); + + // now set high volume again, we should not get the warning dialog + // as we already approved it + notificationsSpy.clear(); + + setActionValue("volume", QVariant::fromValue(1.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 2); + + // check the notification TODO check why the sound indicator sends it twice + checkVolumeNotification(1.0, "High volume can damage your hearing.", true, notificationsSpy.at(0)); + checkVolumeNotification(1.0, "High volume can damage your hearing.", true, notificationsSpy.at(1)); +} + +TEST_F(TestIndicator, PhoneNotificationWarningVolumeAlertMode) +{ + double INITIAL_VOLUME = 0.0; + + QSignalSpy notificationsSpy(¬ificationsMockInterface(), + SIGNAL(MethodCalled(const QString &, const QVariantList &))); + + ASSERT_NO_THROW(startAccountsService()); + ASSERT_NO_THROW(startPulsePhone()); + + // initialize volumes in pulseaudio + EXPECT_TRUE(setStreamRestoreVolume("alert", INITIAL_VOLUME)); + EXPECT_TRUE(setStreamRestoreVolume("multimedia", INITIAL_VOLUME)); + + // start now the indicator, so it picks the new volumes + ASSERT_NO_THROW(startIndicator()); + + // activate the headphones + EXPECT_TRUE(activateHeadphones(true)); + + // set an initial volume to the alert role + setStreamRestoreVolume("alert", 1.0); + EXPECT_TRUE(waitVolumeChangedInIndicator()); + + // change volume to 0.0... no warning should be emitted + setActionValue("volume", QVariant::fromValue(0.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 3); + + // the first time we also have the calls to + // GetServerInformation and GetCapabilities + checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); + checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); + checkVolumeNotification(0.0, "", false, notificationsSpy.at(2)); + notificationsSpy.clear(); + + // change volume to 0.5... no warning should be emitted + setActionValue("volume", QVariant::fromValue(0.5)); + + WAIT_FOR_SIGNALS(notificationsSpy, 1); + + checkVolumeNotification(0.5, "", false, notificationsSpy.at(0)); + notificationsSpy.clear(); + + // change volume to 1.0... no warning should be emitted, we are in alert mode + setActionValue("volume", QVariant::fromValue(1.0)); + + WAIT_FOR_SIGNALS(notificationsSpy, 1); + + checkVolumeNotification(1.0, "", false, notificationsSpy.at(0)); + notificationsSpy.clear(); +} + } // namespace -- cgit v1.2.3 From cc77ef3dd05a0e52a74b1ac073b95bd041a2f0d1 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Fri, 16 Oct 2015 16:49:28 +0200 Subject: Fixed race condition connection to the Notifications interface --- tests/integration/indicator-sound-test-base.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index c261fcf..3c6e52a 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -26,6 +26,8 @@ #include "dbus-types.h" #include +#include +#include #include #include "utils/dbus-pulse-volume.h" @@ -36,6 +38,11 @@ using namespace std; using namespace testing; namespace mh = unity::gmenuharness; +namespace +{ + const int MAX_TIME_WAITING_FOR_NOTIFICATIONS = 2000; +} + IndicatorSoundTestBase::IndicatorSoundTestBase() : dbusMock(dbusTestRunner) { @@ -61,6 +68,13 @@ void IndicatorSoundTestBase::SetUp() "as", "ret = ['actions', 'body', 'body-markup', 'icon-static', 'image/svg+xml', 'x-canonical-private-synchronous', 'x-canonical-append', 'x-canonical-private-icon-only', 'x-canonical-truncation', 'private-synchronous', 'append', 'private-icon-only', 'truncation']" ).waitForFinished(); + + int waitedTime = 0; + while (!dbusTestRunner.sessionConnection().interface()->isServiceRegistered("org.freedesktop.Notifications") && waitedTime < MAX_TIME_WAITING_FOR_NOTIFICATIONS) + { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + waitedTime += 10; + } } void IndicatorSoundTestBase::TearDown() -- cgit v1.2.3 From 86c449a7125f3ff90dcac353c8a4ad5a8c2cc46e Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Wed, 21 Oct 2015 14:53:42 +0200 Subject: Fixed issue with warning notification. Fixed race conditions in tests --- tests/integration/indicator-sound-test-base.cpp | 14 +++---- tests/integration/test-indicator.cpp | 56 +++++++++++++++++-------- 2 files changed, 46 insertions(+), 24 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 3c6e52a..2bd71b6 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -669,7 +669,7 @@ QString IndicatorSoundTestBase::getDevicePortString(DevicePortType port) void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, DevicePortType headphonesPort) { - double INITIAL_VOLUME = 1.0; + double INITIAL_VOLUME = 0.0; QString speakerString; QString speakerStringMenu; @@ -739,7 +739,7 @@ void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, // GetServerInformation and GetCapabilities checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); - checkVolumeNotification(1.0, speakerString, false, notificationsSpy.at(2)); + checkVolumeNotification(INITIAL_VOLUME, speakerString, false, notificationsSpy.at(2)); notificationsSpy.clear(); } @@ -754,13 +754,13 @@ void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, // GetServerInformation and GetCapabilities checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); - checkVolumeNotification(1.0, headphonesString, false, notificationsSpy.at(2)); + checkVolumeNotification(INITIAL_VOLUME, headphonesString, false, notificationsSpy.at(2)); notificationsSpy.clear(); } else { WAIT_FOR_SIGNALS(notificationsSpy, 1); - checkVolumeNotification(1.0, headphonesString, false, notificationsSpy.at(0)); + checkVolumeNotification(INITIAL_VOLUME, headphonesString, false, notificationsSpy.at(0)); notificationsSpy.clear(); } @@ -777,7 +777,7 @@ void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(1.0, headphonesStringMenu)) + .item(volumeSlider(INITIAL_VOLUME, headphonesStringMenu)) ) ).match()); @@ -785,7 +785,7 @@ void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, EXPECT_TRUE(activateHeadphones(false)); WAIT_FOR_SIGNALS(notificationsSpy, 1); - checkVolumeNotification(1.0, speakerString, false, notificationsSpy.at(0)); + checkVolumeNotification(INITIAL_VOLUME, speakerString, false, notificationsSpy.at(0)); notificationsSpy.clear(); // check the label in the menu @@ -801,7 +801,7 @@ void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, .item(mh::MenuItemMatcher() .section() .item(silentModeSwitch(false)) - .item(volumeSlider(1.0, speakerStringMenu)) + .item(volumeSlider(INITIAL_VOLUME, speakerStringMenu)) ) ).match()); } diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index fccaf84..b301586 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -52,19 +52,27 @@ TEST_F(TestIndicator, PhoneChangeRoleVolume) int randInt = qrand() % 100; double randomVolume = randInt / 100.0; + QSignalSpy &userAccountsSpy = *signal_spy_volume_changed_; // set an initial volume to the alert role + userAccountsSpy.clear(); setStreamRestoreVolume("alert", 1.0); - EXPECT_TRUE(waitVolumeChangedInIndicator()); + WAIT_FOR_SIGNALS(userAccountsSpy, 2); + userAccountsSpy.clear(); // play a test sound, it should change the role in the indicator EXPECT_TRUE(startTestSound("multimedia")); - EXPECT_TRUE(waitVolumeChangedInIndicator()); + // this time we only expect 1 signal as it's only the indicator + // updating the value + WAIT_FOR_SIGNALS(userAccountsSpy, 1); + //EXPECT_TRUE(waitVolumeChangedInIndicator()); + + userAccountsSpy.clear(); // set the random volume to the multimedia role EXPECT_TRUE(setStreamRestoreVolume("multimedia", randomVolume)); if (randomVolume != INITIAL_VOLUME) { - EXPECT_TRUE(waitVolumeChangedInIndicator()); + WAIT_FOR_SIGNALS(userAccountsSpy, 1); } // check the indicator @@ -98,13 +106,14 @@ TEST_F(TestIndicator, PhoneChangeRoleVolume) ) ).match()); + userAccountsSpy.clear(); // stop the test sound, the role should change again to alert stopTestSound(); if (randomVolume != 1.0) { // we only wait if the volume in the alert and the // one set in the multimedia roles differ - EXPECT_TRUE(waitVolumeChangedInIndicator()); + WAIT_FOR_SIGNALS(userAccountsSpy, 1); } // check the initial volume for the alert role @@ -727,21 +736,26 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) EXPECT_TRUE(startTestSound("multimedia")); EXPECT_TRUE(waitVolumeChangedInIndicator()); - // change volume to 0.0... no warning should be emitted - setActionValue("volume", QVariant::fromValue(0.0)); - - WAIT_FOR_SIGNALS(notificationsSpy, 4); - + WAIT_FOR_SIGNALS(notificationsSpy, 3); // the first time we also have the calls to // GetServerInformation and GetCapabilities checkNotificationWithNoArgs("GetServerInformation", notificationsSpy.at(0)); checkNotificationWithNoArgs("GetCapabilities", notificationsSpy.at(1)); checkVolumeNotification(0.0, "Headphones", false, notificationsSpy.at(2)); - checkVolumeNotification(0.0, "Headphones", false, notificationsSpy.at(3)); + notificationsSpy.clear(); + + // change volume to 0.3... no warning should be emitted + setActionValue("volume", QVariant::fromValue(0.3)); + EXPECT_TRUE(waitVolumeChangedInIndicator()); + + WAIT_FOR_SIGNALS(notificationsSpy, 1); + + checkVolumeNotification(0.3, "Headphones", false, notificationsSpy.at(0)); notificationsSpy.clear(); // change volume to 0.5... no warning should be emitted setActionValue("volume", QVariant::fromValue(0.5)); + EXPECT_TRUE(waitVolumeChangedInIndicator()); WAIT_FOR_SIGNALS(notificationsSpy, 1); @@ -750,6 +764,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) // change volume to 1.0... warning should be emitted setActionValue("volume", QVariant::fromValue(1.0)); + EXPECT_TRUE(waitVolumeChangedInIndicator()); WAIT_FOR_SIGNALS(notificationsSpy, 4); @@ -787,18 +802,21 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) // try again... notificationsSpy.clear(); + + qWarning() << "-----------------------------------------------------------"; // change volume to 1.0... warning should be emitted setActionValue("volume", QVariant::fromValue(1.0)); + EXPECT_TRUE(waitVolumeChangedInIndicator()); - WAIT_FOR_SIGNALS(notificationsSpy, 4); + WAIT_FOR_SIGNALS(notificationsSpy, 2); - checkCloseNotification(1, notificationsSpy.at(0)); +// checkCloseNotification(1, notificationsSpy.at(0)); + checkHighVolumeNotification(notificationsSpy.at(0)); +// checkCloseNotification(1, notificationsSpy.at(2)); checkHighVolumeNotification(notificationsSpy.at(1)); - checkCloseNotification(1, notificationsSpy.at(2)); - checkHighVolumeNotification(notificationsSpy.at(3)); // get the last notification ID - idNotification = getNotificationID(notificationsSpy.at(3)); + idNotification = getNotificationID(notificationsSpy.at(1)); ASSERT_NE(-1, idNotification); qWarning() << "XGM: id Notification: " << idNotification; @@ -833,12 +851,15 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) // change volume to 0.5... no warning should be emitted setActionValue("volume", QVariant::fromValue(0.5)); + EXPECT_TRUE(waitVolumeChangedInIndicator()); - WAIT_FOR_SIGNALS(notificationsSpy, 2); + WAIT_FOR_SIGNALS(notificationsSpy, 4); // check the notification TODO check why the sound indicator sends it twice - checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(0)); + checkCloseNotification(idNotification, notificationsSpy.at(0)); checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(1)); + checkCloseNotification(idNotification, notificationsSpy.at(2)); + checkVolumeNotification(0.5, "Headphones", false, notificationsSpy.at(3)); // check that the volume was applied // and that we don't have the warning item @@ -863,6 +884,7 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) notificationsSpy.clear(); setActionValue("volume", QVariant::fromValue(1.0)); + EXPECT_TRUE(waitVolumeChangedInIndicator()); WAIT_FOR_SIGNALS(notificationsSpy, 2); -- cgit v1.2.3