diff options
author | Xavi Garcia Mena <xavi.garcia.mena@canonical.com> | 2015-12-02 14:44:58 +0100 |
---|---|---|
committer | Xavi Garcia Mena <xavi.garcia.mena@canonical.com> | 2015-12-02 14:44:58 +0100 |
commit | d9a00604c1d8e3103444053da39a4af17230903b (patch) | |
tree | a58e2a32d3e7c9fd603be00262914612e2efb902 | |
parent | 7c69f81a079a08d58241cc50365dde7d37ad3345 (diff) | |
download | ayatana-indicator-sound-d9a00604c1d8e3103444053da39a4af17230903b.tar.gz ayatana-indicator-sound-d9a00604c1d8e3103444053da39a4af17230903b.tar.bz2 ayatana-indicator-sound-d9a00604c1d8e3103444053da39a4af17230903b.zip |
Added integration tests
-rw-r--r-- | src/service.vala | 6 | ||||
-rw-r--r-- | tests/dbus-types/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/dbus-types/dbus-action-result.cpp | 93 | ||||
-rw-r--r-- | tests/dbus-types/dbus-action-result.h | 50 | ||||
-rw-r--r-- | tests/dbus-types/dbus-types.h | 2 | ||||
-rw-r--r-- | tests/dbus-types/org.gtk.Actions.xml | 5 | ||||
-rw-r--r-- | tests/integration/indicator-sound-test-base.cpp | 66 | ||||
-rw-r--r-- | tests/integration/indicator-sound-test-base.h | 6 | ||||
-rw-r--r-- | tests/integration/test-indicator.cpp | 13 |
9 files changed, 239 insertions, 6 deletions
diff --git a/src/service.vala b/src/service.vala index 8f90547..3ac6b89 100644 --- a/src/service.vala +++ b/src/service.vala @@ -43,7 +43,7 @@ public class IndicatorSound.Service: Object { warn_notification.closed.connect((n) => { n.clear_actions(); waiting_user_approve_warn=false; - volume_sync_action.set_state(volume_sync_number_++); + volume_sync_action.set_state(new Variant.uint64 (++volume_sync_number_)); }); BusWatcher.watch_namespace (GLib.BusType.SESSION, "org.freedesktop.Notifications", @@ -639,7 +639,7 @@ public class IndicatorSound.Service: Object { warn_notification.add_action ("cancel", _("Cancel"), (n, a) => { _pre_warn_volume = null; waiting_user_approve_warn = false; - volume_sync_action.set_state(volume_sync_number_++); + volume_sync_action.set_state(new Variant.uint64 (++volume_sync_number_)); }); waiting_user_approve_warn = true; show_notification(warn_notification); @@ -827,7 +827,7 @@ public class IndicatorSound.Service: Object { SimpleAction volume_sync_action; uint64 volume_sync_number_ = 0; Action create_volume_sync_action () { - volume_sync_action = new SimpleAction.stateful("volume-sync", null, new Variant.uint64 (volume_sync_number_)); + volume_sync_action = new SimpleAction.stateful("volume-sync", VariantType.UINT64, new Variant.uint64 (volume_sync_number_)); return volume_sync_action; } diff --git a/tests/dbus-types/CMakeLists.txt b/tests/dbus-types/CMakeLists.txt index cb7f512..a50a5bb 100644 --- a/tests/dbus-types/CMakeLists.txt +++ b/tests/dbus-types/CMakeLists.txt @@ -26,7 +26,8 @@ set_source_files_properties(${dbusinterface_properties_xml} PROPERTIES set(dbusinterface_actions_xml "org.gtk.Actions.xml") set_source_files_properties(${dbusinterface_actions_xml} PROPERTIES - CLASSNAME MenusInterface) + CLASSNAME MenusInterface + INCLUDE "dbus-action-result.h") set(dbusinterface_notifications_xml "org.freedesktop.Notifications.xml") set_source_files_properties(${dbusinterface_notifications_xml} PROPERTIES @@ -44,6 +45,7 @@ add_library( STATIC ${interface_files} pulseaudio-volume.cpp + dbus-action-result.cpp ) qt5_use_modules( diff --git a/tests/dbus-types/dbus-action-result.cpp b/tests/dbus-types/dbus-action-result.cpp new file mode 100644 index 0000000..2ef812e --- /dev/null +++ b/tests/dbus-types/dbus-action-result.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 "dbus-action-result.h" + +DBusActionResult::DBusActionResult() + : enabled_(false) +{} + +DBusActionResult::~DBusActionResult() +{} + +DBusActionResult::DBusActionResult(bool enabled, QDBusSignature signature, QVariantList value) + : enabled_(enabled) + , signature_(signature) + , value_(value) +{ +} + +DBusActionResult::DBusActionResult(const DBusActionResult &other) + : enabled_(other.enabled_) + , signature_(other.signature_) + , value_(other.value_) +{ +} + +DBusActionResult& DBusActionResult::operator=(const DBusActionResult &other) +{ + enabled_ = other.enabled_; + signature_ = other.signature_; + value_ = other.value_; + + return *this; +} + +QVariantList DBusActionResult::getValue() const +{ + return value_; +} + +bool DBusActionResult::getEnabled() const +{ + return enabled_; +} + +QDBusSignature DBusActionResult::getSignature() const +{ + return signature_; +} + +//register Message with the Qt type system +void DBusActionResult::registerMetaType() +{ + qRegisterMetaType<DBusActionResult>("DBusActionResult"); + + qDBusRegisterMetaType<DBusActionResult>(); +} + +QDBusArgument &operator<<(QDBusArgument &argument, const DBusActionResult &result) +{ + argument.beginStructure(); + argument << result.enabled_; + argument << result.signature_; + argument << result.value_; + argument.endStructure(); + + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, DBusActionResult &result) +{ + argument.beginStructure(); + argument >> result.enabled_; + argument >> result.signature_; + argument >> result.value_; + argument.endStructure(); + + return argument; +} diff --git a/tests/dbus-types/dbus-action-result.h b/tests/dbus-types/dbus-action-result.h new file mode 100644 index 0000000..2fe732f --- /dev/null +++ b/tests/dbus-types/dbus-action-result.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 <QtDBus> +#include <QDBusSignature> + +class DBusActionResult +{ +public: + DBusActionResult(); + DBusActionResult(bool enabled, QDBusSignature signature, QVariantList value); + ~DBusActionResult(); + + DBusActionResult(const DBusActionResult &other); + DBusActionResult& operator=(const DBusActionResult &other); + + friend QDBusArgument &operator<<(QDBusArgument &argument, const DBusActionResult &result); + friend const QDBusArgument &operator>>(const QDBusArgument &argument, DBusActionResult &result); + + bool getEnabled() const; + QVariantList getValue() const; + QDBusSignature getSignature() const; + + //register Message with the Qt type system + static void registerMetaType(); + +private: + bool enabled_; + QDBusSignature signature_; + QVariantList value_; +}; + +Q_DECLARE_METATYPE(DBusActionResult) + diff --git a/tests/dbus-types/dbus-types.h b/tests/dbus-types/dbus-types.h index b75acf0..ac86027 100644 --- a/tests/dbus-types/dbus-types.h +++ b/tests/dbus-types/dbus-types.h @@ -19,6 +19,7 @@ #include <QDBusMetaType> #include "pulseaudio-volume.h" +#include "dbus-action-result.h" namespace DBusTypes { @@ -26,6 +27,7 @@ namespace DBusTypes { PulseaudioVolume::registerMetaType(); PulseaudioVolumeArray::registerMetaType(); + DBusActionResult::registerMetaType(); } static constexpr char const* DBUS_NAME = "com.canonical.indicator.sound"; diff --git a/tests/dbus-types/org.gtk.Actions.xml b/tests/dbus-types/org.gtk.Actions.xml index b691f1f..30780d5 100644 --- a/tests/dbus-types/org.gtk.Actions.xml +++ b/tests/dbus-types/org.gtk.Actions.xml @@ -9,5 +9,10 @@ <arg name="actionsAdded" type="a{s(bgav)}" direction="in" /> <annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QVariantMap"/> </signal> + <method name="Describe"> + <arg name="action" type="s" direction="in"/> + <arg name="result" type="(bgav)" direction="out"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="DBusActionResult"/> + </method> </interface> </node> diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 5005e2c..3b9c58d 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -821,3 +821,69 @@ bool IndicatorSoundTestBase::setVolumeUntilAccountsIsConnected(double volume) } return (signal_spy_volume_changed_->count() != 0); } + +QVariantList IndicatorSoundTestBase::getActionValue(QString const &action) +{ + if (!menu_interface_) + { + menu_interface_.reset(new MenusInterface("com.canonical.indicator.sound", + "/com/canonical/indicator/sound", + dbusTestRunner.sessionConnection(), 0)); + } + if (menu_interface_) + { + QDBusReply<DBusActionResult> resp = menu_interface_->call(QLatin1String("Describe"), + action); + if (!resp.isValid()) + { + qWarning() << "IndicatorSoundTestBase::getActionValue(): D-Bus error: " << resp.error().message(); + return QVariantList(); + } + else + { + return resp.value().getValue(); + } + } + + return QVariantList(); +} + +qlonglong IndicatorSoundTestBase::getVolumeSyncValue(bool *isValid) +{ + qlonglong result = 0; + + QVariantList varList = getActionValue("volume-sync"); + if (varList.size() == 1) + { + result = varList.at(0).toULongLong(isValid); + } + else + { + if (isValid) + { + *isValid = false; + } + } + + return result; +} + +float IndicatorSoundTestBase::getVolumeValue(bool *isValid) +{ + float result = 0.0; + + QVariantList varList = getActionValue("volume"); + if (varList.size() == 1) + { + result = varList.at(0).toFloat(isValid); + } + else + { + if (isValid) + { + *isValid = false; + } + } + + return result; +} diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 41dd1c7..67f347f 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -134,6 +134,12 @@ protected: bool setVolumeUntilAccountsIsConnected(double volume); + QVariantList getActionValue(QString const &action); + + qlonglong getVolumeSyncValue(bool *isValid = nullptr); + + float getVolumeValue(bool *isValid = nullptr); + QtDBusTest::DBusTestRunner dbusTestRunner; QtDBusMock::DBusMock dbusMock; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 33e62b5..54c56b5 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -182,6 +182,7 @@ TEST_F(TestIndicator, PhoneBasicInitialVolume) ).match()); } + TEST_F(TestIndicator, PhoneAddMprisPlayer) { double INITIAL_VOLUME = 0.0; @@ -783,7 +784,11 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) int idNotification = getNotificationID(notificationsSpy.at(5)); ASSERT_NE(-1, idNotification); - qWarning() << "XGM: id Notification: " << idNotification; + // check the sync value before cancelling the dialog + bool isValid; + qlonglong syncValue = getVolumeSyncValue(&isValid); + EXPECT_TRUE(isValid); + EXPECT_EQ(0, syncValue); // cancel the dialog pressNotificationButton(idNotification, "cancel"); @@ -805,6 +810,11 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) ) ).match()); + // verify that the sync value is increased + syncValue = getVolumeSyncValue(&isValid); + EXPECT_TRUE(isValid); + EXPECT_EQ(1, syncValue); + // try again... notificationsSpy.clear(); @@ -900,7 +910,6 @@ TEST_F(TestIndicator, PhoneNotificationWarningVolume) checkVolumeNotification(1.0, "Headphones", true, notificationsSpy.at(3)); } - TEST_F(TestIndicator, PhoneNotificationWarningVolumeAlertMode) { double INITIAL_VOLUME = 0.0; |