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/service-mocks/accounts-mock/AccountsDefs.h | 37 +++++++++++++ tests/service-mocks/accounts-mock/AccountsMock.cpp | 40 ++++++++++++++ tests/service-mocks/accounts-mock/AccountsMock.h | 50 +++++++++++++++++ .../accounts-mock/AccountsServiceSoundMock.cpp | 48 +++++++++++++++++ .../accounts-mock/AccountsServiceSoundMock.h | 58 ++++++++++++++++++++ tests/service-mocks/accounts-mock/CMakeLists.txt | 42 +++++++++++++++ .../com.ubuntu.AccountsService.Sound.Mock.xml | 6 +++ tests/service-mocks/accounts-mock/main.cpp | 63 ++++++++++++++++++++++ .../org.freedesktop.Accounts.Mock.xml | 13 +++++ 9 files changed, 357 insertions(+) create mode 100644 tests/service-mocks/accounts-mock/AccountsDefs.h create mode 100644 tests/service-mocks/accounts-mock/AccountsMock.cpp create mode 100644 tests/service-mocks/accounts-mock/AccountsMock.h create mode 100644 tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp create mode 100644 tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h create mode 100644 tests/service-mocks/accounts-mock/CMakeLists.txt create mode 100644 tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml create mode 100644 tests/service-mocks/accounts-mock/main.cpp create mode 100644 tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml (limited to 'tests/service-mocks/accounts-mock') diff --git a/tests/service-mocks/accounts-mock/AccountsDefs.h b/tests/service-mocks/accounts-mock/AccountsDefs.h new file mode 100644 index 0000000..0e4f270 --- /dev/null +++ b/tests/service-mocks/accounts-mock/AccountsDefs.h @@ -0,0 +1,37 @@ +/* + * 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 ubuntu +{ + +namespace indicators +{ + +namespace testing +{ + 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"; +} // namespace testing + +} // namespace indicators + +} // namespace ubuntu + diff --git a/tests/service-mocks/accounts-mock/AccountsMock.cpp b/tests/service-mocks/accounts-mock/AccountsMock.cpp new file mode 100644 index 0000000..5c92dc5 --- /dev/null +++ b/tests/service-mocks/accounts-mock/AccountsMock.cpp @@ -0,0 +1,40 @@ +/* + * 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" + +using namespace ubuntu::indicators::testing; + +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/service-mocks/accounts-mock/AccountsMock.h b/tests/service-mocks/accounts-mock/AccountsMock.h new file mode 100644 index 0000000..72372e0 --- /dev/null +++ b/tests/service-mocks/accounts-mock/AccountsMock.h @@ -0,0 +1,50 @@ +/* + * 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 + +namespace ubuntu +{ + +namespace indicators +{ + +namespace testing +{ + +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(); +}; + +} // namespace testing + +} // namespace indicators + +} // namespace ubuntu diff --git a/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp new file mode 100644 index 0000000..37de377 --- /dev/null +++ b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp @@ -0,0 +1,48 @@ +/* + * 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" + +using namespace ubuntu::indicators::testing; + +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; + notifier_.notifyPropertyChanged(QDBusConnection::systemBus(), + ACCOUNTS_SOUND_INTERFACE, + USER_PATH, + "Volume", + property("Volume")); +} diff --git a/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h new file mode 100644 index 0000000..bb3dbe8 --- /dev/null +++ b/tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h @@ -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 + */ +#pragma once + +#include +#include + +#include "DBusPropertiesNotifier.h" + +namespace ubuntu +{ + +namespace indicators +{ + +namespace testing +{ + +class DBusPropertiesNotifier; + +class AccountsServiceSoundMock : public QObject, protected QDBusContext +{ + Q_OBJECT + 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(); + +private: + double volume_; + DBusPropertiesNotifier notifier_; +}; + +} // namespace testing + +} // namespace indicators + +} // namespace ubuntu diff --git a/tests/service-mocks/accounts-mock/CMakeLists.txt b/tests/service-mocks/accounts-mock/CMakeLists.txt new file mode 100644 index 0000000..bc71a8b --- /dev/null +++ b/tests/service-mocks/accounts-mock/CMakeLists.txt @@ -0,0 +1,42 @@ +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +find_package(Qt5DBus REQUIRED) +include_directories(${Qt5DBus_INCLUDE_DIRS} + "${CMAKE_SOURCE_DIR}/tests/service-mocks") + +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 + ubuntu::indicators::testing::AccountsServiceSoundMock + AccountsServiceSoundMockAdaptor) + +qt5_add_dbus_adaptor(adaptor_files + org.freedesktop.Accounts.Mock.xml + AccountsMock.h + ubuntu::indicators::testing::AccountsMock + AccountsMockAdaptor) + +add_executable( + accounts-service-sound + ${interface_files} + ${adaptor_files} + AccountsServiceSoundMock.cpp + AccountsMock.cpp + ${CMAKE_SOURCE_DIR}/tests/service-mocks/DBusPropertiesNotifier.cpp + main.cpp +) + +qt5_use_modules( + accounts-service-sound + Core + DBus +) diff --git a/tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml b/tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml new file mode 100644 index 0000000..859cd46 --- /dev/null +++ b/tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/service-mocks/accounts-mock/main.cpp b/tests/service-mocks/accounts-mock/main.cpp new file mode 100644 index 0000000..d6cd1d3 --- /dev/null +++ b/tests/service-mocks/accounts-mock/main.cpp @@ -0,0 +1,63 @@ +/* + * 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" + +using namespace ubuntu::indicators::testing; + +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."); + } + } + else + { + qDebug() << "Service is already registered!."; + } + return app.exec(); +} diff --git a/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml b/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml new file mode 100644 index 0000000..f284d54 --- /dev/null +++ b/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + -- cgit v1.2.3 From 698baf72cd6a606d9c8101c31e0d40b38d48a8bb Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Mon, 26 Oct 2015 12:01:16 +0100 Subject: Changed unit test to wait for the indicator to connect the user accounts --- tests/service-mocks/accounts-mock/CMakeLists.txt | 2 +- tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/service-mocks/accounts-mock') diff --git a/tests/service-mocks/accounts-mock/CMakeLists.txt b/tests/service-mocks/accounts-mock/CMakeLists.txt index bc71a8b..ad858bd 100644 --- a/tests/service-mocks/accounts-mock/CMakeLists.txt +++ b/tests/service-mocks/accounts-mock/CMakeLists.txt @@ -20,7 +20,7 @@ qt5_add_dbus_adaptor(adaptor_files AccountsServiceSoundMockAdaptor) qt5_add_dbus_adaptor(adaptor_files - org.freedesktop.Accounts.Mock.xml + ${CMAKE_SOURCE_DIR}/tests/dbus-types/org.freedesktop.Accounts.xml AccountsMock.h ubuntu::indicators::testing::AccountsMock AccountsMockAdaptor) diff --git a/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml b/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml index f284d54..f977e7c 100644 --- a/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml +++ b/tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml @@ -9,5 +9,7 @@ + + -- cgit v1.2.3