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 --- src/volume-control-pulse.vala | 3 +- tests/CMakeLists.txt | 3 +- tests/accounts-mock/AccountsDefs.h | 26 ++++++++++ tests/accounts-mock/AccountsMock.cpp | 38 ++++++++++++++ tests/accounts-mock/AccountsMock.h | 35 +++++++++++++ tests/accounts-mock/AccountsServiceSoundMock.cpp | 60 ++++++++++++++++++++++ tests/accounts-mock/AccountsServiceSoundMock.h | 44 ++++++++++++++++ tests/accounts-mock/CMakeLists.txt | 40 +++++++++++++++ .../com.ubuntu.AccountsService.Sound.Mock.xml | 6 +++ tests/accounts-mock/main.cpp | 58 +++++++++++++++++++++ .../org.freedesktop.Accounts.Mock.xml | 13 +++++ tests/dbus-types/dbus-types.h | 2 + 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 + 16 files changed, 352 insertions(+), 9 deletions(-) create mode 100644 tests/accounts-mock/AccountsDefs.h create mode 100644 tests/accounts-mock/AccountsMock.cpp create mode 100644 tests/accounts-mock/AccountsMock.h create mode 100644 tests/accounts-mock/AccountsServiceSoundMock.cpp create mode 100644 tests/accounts-mock/AccountsServiceSoundMock.h create mode 100644 tests/accounts-mock/CMakeLists.txt create mode 100644 tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml create mode 100644 tests/accounts-mock/main.cpp create mode 100644 tests/accounts-mock/org.freedesktop.Accounts.Mock.xml diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index b60d97e..950cdaf 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -479,7 +479,6 @@ public class VolumeControlPulse : VolumeControl this.context.set_state_callback (context_state_callback); var server_string = Environment.get_variable("PULSE_SERVER"); - warning("XGM: PULSE_SERVER=%s", server_string); if (context.connect(server_string, Context.Flags.NOFAIL, null) < 0) warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno())); } @@ -629,7 +628,7 @@ public class VolumeControlPulse : VolumeControl } set { var volume_changed = (value.volume != _volume.volume); - warning("Setting volume to %f for profile %d because %d", value.volume, _active_sink_input, value.reason); + debug("Setting volume to %f for profile %d because %d", value.volume, _active_sink_input, value.reason); _volume = value; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4c28cdf..d818a2d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -280,4 +280,5 @@ add_test(indcator-test ) add_subdirectory(integration) -add_subdirectory(dbus-types) \ No newline at end of file +add_subdirectory(dbus-types) +add_subdirectory(accounts-mock) \ No newline at end of file diff --git a/tests/accounts-mock/AccountsDefs.h b/tests/accounts-mock/AccountsDefs.h new file mode 100644 index 0000000..e2b24ab --- /dev/null +++ b/tests/accounts-mock/AccountsDefs.h @@ -0,0 +1,26 @@ +/* + * 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 + +namespace +{ + constexpr const char ACCOUNTS_SERVICE[] = "org.freedesktop.Accounts"; + constexpr const char USER_PATH[] = "/org/freedesktop/Accounts/UserTest"; + constexpr const char ACCOUNTS_PATH[] = "/org/freedesktop/Accounts"; + constexpr const char ACCOUNTS_SOUND_INTERFACE[] = "com.ubuntu.AccountsService.Sound"; +} diff --git a/tests/accounts-mock/AccountsMock.cpp b/tests/accounts-mock/AccountsMock.cpp new file mode 100644 index 0000000..72f86a6 --- /dev/null +++ b/tests/accounts-mock/AccountsMock.cpp @@ -0,0 +1,38 @@ +/* + * 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 "AccountsMock.h" +#include "AccountsDefs.h" + +AccountsMock::AccountsMock(QObject* parent) + : QObject(parent) +{ +} + +AccountsMock::~AccountsMock() = default; + +QDBusObjectPath AccountsMock::FindUserByName(QString const & username) const +{ + return QDBusObjectPath(USER_PATH); +} + +QDBusObjectPath AccountsMock::FindUserById(int64_t uid) const +{ + return QDBusObjectPath(USER_PATH); +} diff --git a/tests/accounts-mock/AccountsMock.h b/tests/accounts-mock/AccountsMock.h new file mode 100644 index 0000000..759443c --- /dev/null +++ b/tests/accounts-mock/AccountsMock.h @@ -0,0 +1,35 @@ +/* + * 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 + +class AccountsMock : public QObject, protected QDBusContext +{ + Q_OBJECT + +public Q_SLOTS: + QDBusObjectPath FindUserByName(QString const & username) const; + QDBusObjectPath FindUserById(int64_t uid) const; + +public: + AccountsMock(QObject* parent = 0); + virtual ~AccountsMock(); +}; diff --git a/tests/accounts-mock/AccountsServiceSoundMock.cpp b/tests/accounts-mock/AccountsServiceSoundMock.cpp new file mode 100644 index 0000000..10f4f8d --- /dev/null +++ b/tests/accounts-mock/AccountsServiceSoundMock.cpp @@ -0,0 +1,60 @@ +/* + * 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 "AccountsServiceSoundMock.h" +#include "AccountsDefs.h" + +AccountsServiceSoundMock::AccountsServiceSoundMock(QObject* parent) + : QObject(parent) + , volume_(0.0) +{ +} + +AccountsServiceSoundMock::~AccountsServiceSoundMock() = default; + +double AccountsServiceSoundMock::volume() const +{ + return volume_; +} + +void AccountsServiceSoundMock::setVolume(double volume) +{ + volume_ = volume; + notifyPropertyChanged(ACCOUNTS_SOUND_INTERFACE, + USER_PATH, + "Volume"); +} + +void AccountsServiceSoundMock::notifyPropertyChanged(QString const & interface, + QString const & path, + QString const & propertyName) +{ + QDBusMessage signal = QDBusMessage::createSignal( + path, + "org.freedesktop.DBus.Properties", + "PropertiesChanged"); + signal << interface; + QVariantMap changedProps; + changedProps.insert(propertyName, property(propertyName.toStdString().c_str())); + signal << changedProps; + signal << QStringList(); + QDBusConnection::systemBus().send(signal); +} diff --git a/tests/accounts-mock/AccountsServiceSoundMock.h b/tests/accounts-mock/AccountsServiceSoundMock.h new file mode 100644 index 0000000..2be996f --- /dev/null +++ b/tests/accounts-mock/AccountsServiceSoundMock.h @@ -0,0 +1,44 @@ +/* + * 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 + +class AccountsServiceSoundMock : public QObject, protected QDBusContext +{ + Q_OBJECT +// Q_CLASSINFO("D-Bus Interface", "test.com.ubuntu.AccountsService.Sound") + Q_PROPERTY(double Volume READ volume WRITE setVolume) + +public Q_SLOTS: + double volume() const; + void setVolume(double volume); + +public: + AccountsServiceSoundMock(QObject* parent = 0); + virtual ~AccountsServiceSoundMock(); + +protected: + void notifyPropertyChanged(QString const & interface, + QString const & path, + QString const & propertyName); + +private: + double volume_; +}; diff --git a/tests/accounts-mock/CMakeLists.txt b/tests/accounts-mock/CMakeLists.txt new file mode 100644 index 0000000..fcfab2d --- /dev/null +++ b/tests/accounts-mock/CMakeLists.txt @@ -0,0 +1,40 @@ +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +find_package(Qt5DBus REQUIRED) +include_directories(${Qt5DBus_INCLUDE_DIRS}) + +add_definitions(-DQT_NO_KEYWORDS=1) + +set(dbusinterface_sound_xml "com.ubuntu.AccountsService.Sound.Mock.xml") +set_source_files_properties(${dbusinterface_sound_xml} PROPERTIES + CLASSNAME AccountsServiceSoundMockInterface) + +qt5_add_dbus_interface(interface_files ${dbusinterface_sound_xml} accountsservice_sound_interface) + +qt5_add_dbus_adaptor(adaptor_files + com.ubuntu.AccountsService.Sound.Mock.xml + AccountsServiceSoundMock.h + AccountsServiceSoundMock + AccountsServiceSoundMockAdaptor) + +qt5_add_dbus_adaptor(adaptor_files + org.freedesktop.Accounts.Mock.xml + AccountsMock.h + AccountsMock + AccountsMockAdaptor) + +add_executable( + accounts-service-sound + ${interface_files} + ${adaptor_files} + AccountsServiceSoundMock.cpp + AccountsMock.cpp + main.cpp +) + +qt5_use_modules( + accounts-service-sound + Core + DBus +) diff --git a/tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml b/tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml new file mode 100644 index 0000000..859cd46 --- /dev/null +++ b/tests/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/accounts-mock/main.cpp b/tests/accounts-mock/main.cpp new file mode 100644 index 0000000..ca1a426 --- /dev/null +++ b/tests/accounts-mock/main.cpp @@ -0,0 +1,58 @@ +/* + * 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 "AccountsDefs.h" +#include "AccountsServiceSoundMock.h" +#include "AccountsServiceSoundMockAdaptor.h" +#include "AccountsMock.h" +#include "AccountsMockAdaptor.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QDBusConnection connection = QDBusConnection::systemBus(); + if (!connection.interface()->isServiceRegistered(ACCOUNTS_SERVICE)) + { + auto service = new AccountsServiceSoundMock(&app); + new SoundAdaptor(service); + + auto accounts_service = new AccountsMock(&app); + new AccountsAdaptor(accounts_service); + + if (!connection.registerService(ACCOUNTS_SERVICE)) + { + qFatal("Could not register AccountsService Volume service."); + } + + if (!connection.registerObject(USER_PATH, service)) + { + qFatal("Could not register AccountsService Volume object."); + } + + if (!connection.registerObject(ACCOUNTS_PATH, accounts_service)) + { + qFatal("Could not register Accounts object."); + } + } + qDebug() << "Service is already registered!."; + return app.exec(); +} diff --git a/tests/accounts-mock/org.freedesktop.Accounts.Mock.xml b/tests/accounts-mock/org.freedesktop.Accounts.Mock.xml new file mode 100644 index 0000000..f284d54 --- /dev/null +++ b/tests/accounts-mock/org.freedesktop.Accounts.Mock.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/tests/dbus-types/dbus-types.h b/tests/dbus-types/dbus-types.h index f747458..8c7f253 100644 --- a/tests/dbus-types/dbus-types.h +++ b/tests/dbus-types/dbus-types.h @@ -32,6 +32,8 @@ namespace DBusTypes static constexpr char const* DBUS_PULSE = "org.PulseAudio1"; + static constexpr char const* ACCOUNTS_SERVICE = "org.freedesktop.Accounts"; + static constexpr char const* STREAM_RESTORE_NAME = "org.PulseAudio.Ext.StreamRestore1"; static constexpr char const* STREAM_RESTORE_PATH = "/org/pulseaudio/stream_restore1"; 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