aboutsummaryrefslogtreecommitdiff
path: root/tests/service-mocks
diff options
context:
space:
mode:
authorXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-10-21 15:16:58 +0200
committerXavi Garcia Mena <xavi.garcia.mena@canonical.com>2015-10-21 15:16:58 +0200
commit4dbdcf30a0ed10019d3350293c4ac52040393640 (patch)
treefa01e697dee299506a91d1d9f41c2a61f429fcc9 /tests/service-mocks
parent6ee23e401d3847e609f1ef50e1736f69e6253608 (diff)
parent86c449a7125f3ff90dcac353c8a4ad5a8c2cc46e (diff)
downloadayatana-indicator-sound-4dbdcf30a0ed10019d3350293c4ac52040393640.tar.gz
ayatana-indicator-sound-4dbdcf30a0ed10019d3350293c4ac52040393640.tar.bz2
ayatana-indicator-sound-4dbdcf30a0ed10019d3350293c4ac52040393640.zip
Fixed conflict. Updated changelog to be in sync with trunk
Diffstat (limited to 'tests/service-mocks')
-rw-r--r--tests/service-mocks/CMakeLists.txt2
-rw-r--r--tests/service-mocks/DBusPropertiesNotifier.cpp41
-rw-r--r--tests/service-mocks/DBusPropertiesNotifier.h48
-rw-r--r--tests/service-mocks/accounts-mock/AccountsDefs.h37
-rw-r--r--tests/service-mocks/accounts-mock/AccountsMock.cpp40
-rw-r--r--tests/service-mocks/accounts-mock/AccountsMock.h50
-rw-r--r--tests/service-mocks/accounts-mock/AccountsServiceSoundMock.cpp48
-rw-r--r--tests/service-mocks/accounts-mock/AccountsServiceSoundMock.h58
-rw-r--r--tests/service-mocks/accounts-mock/CMakeLists.txt42
-rw-r--r--tests/service-mocks/accounts-mock/com.ubuntu.AccountsService.Sound.Mock.xml6
-rw-r--r--tests/service-mocks/accounts-mock/main.cpp63
-rw-r--r--tests/service-mocks/accounts-mock/org.freedesktop.Accounts.Mock.xml13
-rw-r--r--tests/service-mocks/media-player-mpris-mock/CMakeLists.txt63
-rw-r--r--tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h37
-rw-r--r--tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp103
-rw-r--r--tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h77
-rw-r--r--tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop21
-rw-r--r--tests/service-mocks/media-player-mpris-mock/main.cpp64
-rw-r--r--tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml24
-rw-r--r--tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml6
-rw-r--r--tests/service-mocks/media-player-mpris-mock/player-update.cpp93
21 files changed, 936 insertions, 0 deletions
diff --git a/tests/service-mocks/CMakeLists.txt b/tests/service-mocks/CMakeLists.txt
new file mode 100644
index 0000000..9cd8acb
--- /dev/null
+++ b/tests/service-mocks/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(accounts-mock)
+add_subdirectory(media-player-mpris-mock)
diff --git a/tests/service-mocks/DBusPropertiesNotifier.cpp b/tests/service-mocks/DBusPropertiesNotifier.cpp
new file mode 100644
index 0000000..686e4e9
--- /dev/null
+++ b/tests/service-mocks/DBusPropertiesNotifier.cpp
@@ -0,0 +1,41 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+
+#include "DBusPropertiesNotifier.h"
+
+#include <QDBusMessage>
+
+using namespace ubuntu::indicators::testing;
+
+void DBusPropertiesNotifier::notifyPropertyChanged(QDBusConnection const & connection,
+ QString const & interface,
+ QString const & path,
+ QString const & propertyName,
+ QVariant const & propertyValue)
+{
+ QDBusMessage signal = QDBusMessage::createSignal(
+ path,
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged");
+ signal << interface;
+ QVariantMap changedProps;
+ changedProps.insert(propertyName, propertyValue);
+ signal << changedProps;
+ signal << QStringList();
+ connection.send(signal);
+}
diff --git a/tests/service-mocks/DBusPropertiesNotifier.h b/tests/service-mocks/DBusPropertiesNotifier.h
new file mode 100644
index 0000000..9fa013b
--- /dev/null
+++ b/tests/service-mocks/DBusPropertiesNotifier.h
@@ -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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+#include <QDBusConnection>
+
+namespace ubuntu
+{
+
+namespace indicators
+{
+
+namespace testing
+{
+
+class DBusPropertiesNotifier
+{
+public:
+ DBusPropertiesNotifier() = default;
+ ~DBusPropertiesNotifier() = default;
+
+ void notifyPropertyChanged(QDBusConnection const & connection,
+ QString const & interface,
+ QString const & path,
+ QString const & propertyName,
+ QVariant const & propertyValue);
+};
+
+} // namespace testing
+
+} // namespace indicators
+
+} // namespace ubuntu
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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QDebug>
+
+#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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+#include <QDBusContext>
+#include <QDBusObjectPath>
+#include <QObject>
+
+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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QDebug>
+#include <QDBusMessage>
+#include <QDBusConnection>
+
+#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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+#include <QDBusContext>
+#include <QObject>
+
+#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 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="com.ubuntu.AccountsService.Sound">
+ <property name="Volume" type="d" access="readwrite"/>
+ </interface>
+</node> \ 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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusConnectionInterface>
+
+#include <string>
+
+#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 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.freedesktop.Accounts">
+ <method name="FindUserByName">
+ <arg direction="in" type="s" name="user" />
+ <arg direction="out" type="o" name="path" />
+ </method>
+ <method name="FindUserById">
+ <arg direction="in" type="x" name="uid" />
+ <arg direction="out" type="o" name="path" />
+ </method>
+ </interface>
+</node>
diff --git a/tests/service-mocks/media-player-mpris-mock/CMakeLists.txt b/tests/service-mocks/media-player-mpris-mock/CMakeLists.txt
new file mode 100644
index 0000000..b5f5861
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/CMakeLists.txt
@@ -0,0 +1,63 @@
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fPIC -pthread")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -Wextra -fPIC -pthread")
+
+find_package(Qt5DBus REQUIRED)
+include_directories(${Qt5DBus_INCLUDE_DIRS}
+ "${CMAKE_SOURCE_DIR}/tests/service-mocks")
+
+add_definitions(-DQT_NO_KEYWORDS=1)
+
+set(dbusinterface_mediaplayermpris_xml "org.mpris.MediaPlayer2.Player.xml")
+set_source_files_properties(${dbusinterface_mediaplayermpris_xml} PROPERTIES
+ CLASSNAME MediaPlayerMprisMockInterface)
+
+qt5_add_dbus_interface(interface_files ${dbusinterface_mediaplayermpris_xml} MediaPlayerMprisMockInterface)
+
+qt5_add_dbus_adaptor(adaptor_files
+ org.mpris.MediaPlayer2.Player.xml
+ MediaPlayerMprisMock.h
+ ubuntu::indicators::testing::MediaPlayerMprisMock
+ MediaPlayerMprisMockAdaptor)
+
+qt5_add_dbus_adaptor(adaptor_files
+ org.mpris.MediaPlayer2.xml
+ MediaPlayerMprisMock.h
+ ubuntu::indicators::testing::MediaPlayerMprisMock
+ MediaPlayer2MockAdaptor)
+
+add_executable(
+ media-player-mpris-mock
+ ${adaptor_files}
+ MediaPlayerMprisMock.cpp
+ ${CMAKE_SOURCE_DIR}/tests/service-mocks/DBusPropertiesNotifier.cpp
+ main.cpp
+ testplayers
+)
+
+add_executable(
+ media-player-mpris-mock-update
+ ${interface_files}
+ player-update.cpp
+ testplayers
+)
+
+qt5_use_modules(
+ media-player-mpris-mock
+ Core
+ DBus
+)
+
+qt5_use_modules(
+ media-player-mpris-mock-update
+ Core
+ DBus
+)
+
+# test players desktop files
+add_custom_command (OUTPUT testplayers
+ DEPENDS ${CMAKE_SOURCE_DIR}/tests/service-mocks/media-player-mpris-mock/applications
+ COMMAND mkdir -p ${XDG_DATA_DIRS}
+ COMMAND cp -r ${CMAKE_SOURCE_DIR}/tests/service-mocks/media-player-mpris-mock/applications ${XDG_DATA_DIRS})
diff --git a/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.h
new file mode 100644
index 0000000..4d28b38
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisDefs.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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+namespace ubuntu
+{
+
+namespace indicators
+{
+
+namespace testing
+{
+ constexpr const char MEDIA_PLAYER_MPRIS_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/media-player-mpris-mock/MediaPlayerMprisMock.cpp b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp
new file mode 100644
index 0000000..25fe0b7
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.cpp
@@ -0,0 +1,103 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QDebug>
+
+#include "MediaPlayerMprisMock.h"
+
+using namespace ubuntu::indicators::testing;
+
+MediaPlayerMprisMock::MediaPlayerMprisMock(QString const &playerName, QObject* parent)
+ : QObject(parent)
+ , can_play_(true)
+ , can_pause_(true)
+ , can_gonext_(true)
+ , can_goprevious_(true)
+ , player_name_(playerName)
+{
+}
+
+MediaPlayerMprisMock::~MediaPlayerMprisMock() = default;
+
+bool MediaPlayerMprisMock::canPlay() const
+{
+ return can_play_;
+}
+
+void MediaPlayerMprisMock::setCanPlay(bool canPlay)
+{
+ can_play_ = canPlay;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanPlay",
+ property("CanPlay"));
+}
+
+bool MediaPlayerMprisMock::canPause() const
+{
+ return can_pause_;
+}
+
+void MediaPlayerMprisMock::setCanPause(bool canPause)
+{
+ can_pause_ = canPause;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanPause",
+ property("CanPause"));
+}
+
+bool MediaPlayerMprisMock::canGoNext() const
+{
+ return can_gonext_;
+}
+
+void MediaPlayerMprisMock::setCanGoNext(bool canGoNext)
+{
+ can_gonext_ = canGoNext;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanGoNext",
+ property("CanGoNext"));
+}
+
+bool MediaPlayerMprisMock::canGoPrevious() const
+{
+ return can_goprevious_;
+}
+
+void MediaPlayerMprisMock::setCanGoPrevious(bool canGoPrevious)
+{
+ can_goprevious_ = canGoPrevious;
+ notifier_.notifyPropertyChanged(QDBusConnection::sessionBus(),
+ "org.mpris.MediaPlayer2.Player",
+ "/org/mpris/MediaPlayer2",
+ "CanGoPrevious",
+ property("CanGoPrevious"));
+}
+
+QString MediaPlayerMprisMock::desktopEntry() const
+{
+ return player_name_;
+}
+
+void MediaPlayerMprisMock::setDesktopEntry(QString const &)
+{
+}
diff --git a/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h
new file mode 100644
index 0000000..58dce8d
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/MediaPlayerMprisMock.h
@@ -0,0 +1,77 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#pragma once
+
+#include <QDBusContext>
+#include <QDBusObjectPath>
+#include <QObject>
+
+#include "DBusPropertiesNotifier.h"
+
+namespace ubuntu
+{
+
+namespace indicators
+{
+
+namespace testing
+{
+
+class MediaPlayerMprisMock : public QObject, protected QDBusContext
+{
+ Q_OBJECT
+ Q_PROPERTY(bool CanPlay READ canPlay WRITE setCanPlay)
+ Q_PROPERTY(bool CanPause READ canPause WRITE setCanPause)
+ Q_PROPERTY(bool CanGoNext READ canGoNext WRITE setCanGoNext)
+ Q_PROPERTY(bool CanGoPrevious READ canGoPrevious WRITE setCanGoPrevious)
+ Q_PROPERTY(QString DesktopEntry READ desktopEntry WRITE setDesktopEntry)
+
+public Q_SLOTS:
+ bool canPlay() const;
+ void setCanPlay(bool canPlay);
+
+ bool canPause() const;
+ void setCanPause(bool canPause);
+
+ bool canGoNext() const;
+ void setCanGoNext(bool canGoNext);
+
+ bool canGoPrevious() const;
+ void setCanGoPrevious(bool canGoPrevious);
+
+ QString desktopEntry() const;
+ void setDesktopEntry(QString const &destopEntry);
+
+public:
+ MediaPlayerMprisMock(QString const &playerName, QObject* parent = 0);
+ virtual ~MediaPlayerMprisMock();
+
+private:
+ bool can_play_;
+ bool can_pause_;
+ bool can_gonext_;
+ bool can_goprevious_;
+ DBusPropertiesNotifier notifier_;
+ QString player_name_;
+};
+
+} // namespace testing
+
+} // namespace indicators
+
+} // namespace ubuntu
diff --git a/tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop b/tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop
new file mode 100644
index 0000000..2ed5008
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/applications/testplayer1.desktop
@@ -0,0 +1,21 @@
+[Desktop Entry]
+Name=TestPlayer1
+GenericName=Test Player 1
+X-GNOME-FullName=Test Player 1
+Comment=Play and organize your music collection
+Keywords=Audio;Song;MP3;CD;Podcast;MTP;iPod;Playlist;Last.fm;UPnP;DLNA;Radio;
+Exec=echo %U
+Terminal=false
+Type=Application
+Icon=testplayer
+X-GNOME-DocPath=testplayer/testplayer.xml
+Categories=GNOME;GTK;AudioVideo;Audio;Player;
+MimeType=application/x-ogg;application/ogg;audio/x-vorbis+ogg;audio/x-scpls;audio/x-mp3;audio/x-mpeg;audio/mpeg;audio/x-mpegurl;audio/x-flac;audio/mp4;x-scheme-handler/itms;x-scheme-handler/itmss;
+StartupNotify=true
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=testplayer
+X-GNOME-Bugzilla-Component=general
+X-GNOME-Bugzilla-OtherBinaries=rhythmbox-client;rhythmbox-metadata;
+X-GNOME-Bugzilla-Version=3.1
+X-GNOME-UsesNotifications=true
+
diff --git a/tests/service-mocks/media-player-mpris-mock/main.cpp b/tests/service-mocks/media-player-mpris-mock/main.cpp
new file mode 100644
index 0000000..8945673
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/main.cpp
@@ -0,0 +1,64 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusConnectionInterface>
+
+#include <string>
+
+#include "MediaPlayerMprisDefs.h"
+#include "MediaPlayerMprisMock.h"
+#include "MediaPlayerMprisMockAdaptor.h"
+#include "MediaPlayer2MockAdaptor.h"
+
+using namespace ubuntu::indicators::testing;
+
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ qWarning() << "usage: " << argv[0] << "TEST_PLAYER_NAME";
+ return 1;
+ }
+ QString playerName = QString(argv[1]);
+
+ QCoreApplication app(argc, argv);
+ QString playerService = QString("org.mpris.MediaPlayer2.") + playerName;
+ QDBusConnection connection = QDBusConnection::sessionBus();
+ if (!connection.interface()->isServiceRegistered(playerService))
+ {
+ auto service = new MediaPlayerMprisMock(playerName, &app);
+ new PlayerAdaptor(service);
+ new MediaPlayer2Adaptor(service);
+
+ if (!connection.registerService(playerService))
+ {
+ qDebug() << connection.lastError();
+ qFatal("Could not register MediaPlayerMprisMock service.");
+ }
+
+ if (!connection.registerObject("/org/mpris/MediaPlayer2", service))
+ {
+ qFatal("Could not register MediaPlayerMprisMock object.");
+ }
+ }
+ else
+ {
+ qDebug() << "Service is already registered!.";
+ }
+ return app.exec();
+}
diff --git a/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml
new file mode 100644
index 0000000..3efd002
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.Player.xml
@@ -0,0 +1,24 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.mpris.MediaPlayer2.Player">
+ <property name="CanPlay" type="b" access="read"/>
+ <method name="setCanPlay">
+ <arg direction="in" type="b" name="canPlay" />
+ </method>
+
+ <property name="CanPause" type="b" access="read"/>
+ <method name="setCanPause">
+ <arg direction="in" type="b" name="canPause" />
+ </method>
+
+ <property name="CanGoNext" type="b" access="read"/>
+ <method name="setCanGoNext">
+ <arg direction="in" type="b" name="canGoNext" />
+ </method>
+
+ <property name="CanGoPrevious" type="b" access="read"/>
+ <method name="setCanGoPrevious">
+ <arg direction="in" type="b" name="canGoPrevious" />
+ </method>
+ </interface>
+</node>
diff --git a/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml
new file mode 100644
index 0000000..489c68a
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/org.mpris.MediaPlayer2.xml
@@ -0,0 +1,6 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="org.mpris.MediaPlayer2">
+ <property name="DesktopEntry" type="s" access="read"/>
+ </interface>
+</node>
diff --git a/tests/service-mocks/media-player-mpris-mock/player-update.cpp b/tests/service-mocks/media-player-mpris-mock/player-update.cpp
new file mode 100644
index 0000000..5768372
--- /dev/null
+++ b/tests/service-mocks/media-player-mpris-mock/player-update.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
+ */
+#include "MediaPlayerMprisMockInterface.h"
+
+#include <memory>
+
+QMap<QString, QString> getPropertiesMap()
+{
+ QMap<QString, QString> retMap;
+
+ retMap["CANPLAY"] = "setCanPlay";
+ retMap["CANPAUSE"] = "setCanPause";
+ retMap["CANGONEXT"] = "setCanGoNext";
+ retMap["CANGOPREVIOUS"] = "setCanGoPrevious";
+
+ return retMap;
+}
+
+bool getBoolValue(QString const & str)
+{
+ if (str == "TRUE")
+ {
+ return true;
+ }
+ return false;
+}
+
+QTextStream& qStdErr()
+{
+ static QTextStream ts( stderr );
+ return ts;
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ if (argc != 4)
+ {
+ qStdErr() << "usage: " << argv[0] << "TEST_PLAYER_NAME PropertyName true|false\n";
+ return 1;
+ }
+
+ QString state = QString(argv[3]).toUpper();
+ QString property = QString(argv[2]).toUpper();
+ QString playerName = QString(argv[1]);
+
+ auto propertiesMap = getPropertiesMap();
+
+ std::shared_ptr<MediaPlayerMprisMockInterface> iface(
+ new MediaPlayerMprisMockInterface("org.mpris.MediaPlayer2." + playerName,
+ "/org/mpris/MediaPlayer2",
+ QDBusConnection::sessionBus()));
+ if (!iface)
+ {
+ qWarning() << argv[0] << ": error creating interface";
+ return 1;
+ }
+
+ QMap<QString, QString>::iterator iter = propertiesMap.find(property);
+ if (iter == propertiesMap.end())
+ {
+ qWarning() << argv[0] << ": property " << property << " was not found.";
+ return 1;
+ }
+
+ QDBusReply<void> set_prop = iface->call(QLatin1String((*iter).toStdString().c_str()),
+ QVariant::fromValue(getBoolValue(state)));
+
+ if (!set_prop.isValid())
+ {
+ qWarning() << argv[0] << ": D-Bus error: " << set_prop.error().message();
+ return 1;
+ }
+
+ return 0;
+}
+