From 2269139ef937dfd92c39cef15b5385b0070c7883 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Wed, 16 Mar 2016 15:00:47 +0100 Subject: Changed code to get root icon, tests added --- src/service.vala | 50 +++++-------------------- tests/integration/indicator-sound-test-base.cpp | 43 +++++++++++++++++++++ tests/integration/indicator-sound-test-base.h | 2 + tests/integration/test-indicator.cpp | 40 ++++++++++++++++++++ 4 files changed, 94 insertions(+), 41 deletions(-) diff --git a/src/service.vala b/src/service.vala index bdc4d40..651ec73 100644 --- a/src/service.vala +++ b/src/service.vala @@ -290,48 +290,16 @@ public class IndicatorSound.Service: Object { private bool block_info_notifications = false; - private static unowned string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output) { - switch (active_output) { - case VolumeControl.ActiveOutput.SPEAKERS: - case VolumeControl.ActiveOutput.HEADPHONES: - case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES: - case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER: - case VolumeControl.ActiveOutput.USB_SPEAKER: - case VolumeControl.ActiveOutput.USB_HEADPHONES: - case VolumeControl.ActiveOutput.HDMI_SPEAKER: - case VolumeControl.ActiveOutput.HDMI_HEADPHONES: - if (volume <= 0.0) - return "audio-volume-muted-panel"; - if (volume <= 0.3) - return "audio-volume-low-panel"; - if (volume <= 0.7) - return "audio-volume-medium-panel"; - return "audio-volume-high-panel"; - - default: - return ""; - } - } - private unowned string get_volume_root_icon (double volume, bool mute, VolumeControl.ActiveOutput active_output) { - switch (active_output) { - case VolumeControl.ActiveOutput.SPEAKERS: - case VolumeControl.ActiveOutput.HEADPHONES: - case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES: - case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER: - case VolumeControl.ActiveOutput.USB_SPEAKER: - case VolumeControl.ActiveOutput.USB_HEADPHONES: - case VolumeControl.ActiveOutput.HDMI_SPEAKER: - case VolumeControl.ActiveOutput.HDMI_HEADPHONES: - if (mute || volume <= 0.0) - return this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; - if (this.accounts_service != null && this.accounts_service.silentMode) - return "audio-volume-muted-panel"; - return get_volume_root_icon_by_volume (volume, active_output); - - default: - return ""; - } + if (mute || volume <= 0.0) + return this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; + if (this.accounts_service != null && this.accounts_service.silentMode) + return "audio-volume-muted-panel"; + if (volume <= 0.3) + return "audio-volume-low-panel"; + if (volume <= 0.7) + return "audio-volume-medium-panel"; + return "audio-volume-high-panel"; } private void update_notification () { diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 9225c1d..b8608f6 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -989,6 +989,49 @@ QVariantList IndicatorSoundTestBase::getActionValue(QString const &action) return QVariantList(); } +QStringList IndicatorSoundTestBase::getRootIconValue(bool *isValid) +{ + QString result = 0; + + QVariantList varList = getActionValue("root"); + if (isValid != nullptr) + { + *isValid = false; + } + if (varList.at(0).canConvert()) + { + const QDBusArgument dbusArg = qvariant_cast(varList.at(0)); + if (dbusArg.currentType() == QDBusArgument::MapType) + { + QVariantMap map; + dbusArg >> map; + QVariantMap::const_iterator iter = map.find("icon"); + if (iter != map.end()) + { + const QDBusArgument iconArg = qvariant_cast((*iter)); + if (iconArg.currentType() == QDBusArgument::StructureType) + { + QString name; + QVariant iconValue; + iconArg.beginStructure(); + iconArg >> name; + iconArg >> iconValue; + if (name == "themed" && iconValue.type() == QVariant::StringList) + { + if (isValid != nullptr) + { + *isValid = true; + } + } + iconArg.endStructure(); + return iconValue.toStringList(); + } + } + } + } + return QStringList(); +} + qlonglong IndicatorSoundTestBase::getVolumeSyncValue(bool *isValid) { qlonglong result = 0; diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 5b3545a..7942bd5 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -148,6 +148,8 @@ protected: qlonglong getVolumeSyncValue(bool *isValid = nullptr); + QStringList getRootIconValue(bool *isValid = nullptr); + float getVolumeValue(bool *isValid = nullptr); static QVariant waitPropertyChanged(QSignalSpy * signalSpy, QString property); diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index eff1516..fb62d4e 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -32,6 +32,46 @@ class TestIndicator: public IndicatorSoundTestBase { }; +TEST_F(TestIndicator, PhoneCheckRootIcon) +{ + 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()); + + QStringList mutedIcon = {"audio-volume-muted-panel", "audio-volume-muted", "audio-volume", "audio"}; + EXPECT_EQ(getRootIconValue(), mutedIcon); + + QStringList lowVolumeIcon = {"audio-volume-low-panel", "audio-volume-low", "audio-volume", "audio"}; + for( double volume = 0.1; volume <= 0.3; volume+=0.1) + { + EXPECT_TRUE(setStreamRestoreVolume("alert", volume)); + EXPECT_EQ(getRootIconValue(), lowVolumeIcon); + } + EXPECT_TRUE(setStreamRestoreVolume("alert", 0.4)); + + QStringList mediumVolumeIcon = {"audio-volume-medium-panel", "audio-volume-medium", "audio-volume", "audio"}; + for( double volume = 0.4; volume <= 0.7; volume+=0.1) + { + EXPECT_TRUE(setStreamRestoreVolume("alert", volume)); + EXPECT_EQ(getRootIconValue(), mediumVolumeIcon); + } + + QStringList highVolumeIcon = {"audio-volume-high-panel", "audio-volume-high", "audio-volume", "audio"}; + for( double volume = 0.8; volume <= 1.0; volume+=0.1) + { + EXPECT_TRUE(setStreamRestoreVolume("alert", volume)); + EXPECT_EQ(getRootIconValue(), highVolumeIcon); + } +} + TEST_F(TestIndicator, PhoneTestExternalMicInOut) { double INITIAL_VOLUME = 0.0; -- cgit v1.2.3 From 2acd4961a7e5af93f863503eca90f51d28e6603d Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Thu, 17 Mar 2016 11:04:53 +0100 Subject: Added volume check to root icon test --- tests/integration/test-indicator.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index fb62d4e..bb08c40 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -46,6 +46,28 @@ TEST_F(TestIndicator, PhoneCheckRootIcon) // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); + // check that the volume is set and give + // time to the indicator to start + 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, "Volume")) + ) + .item(mh::MenuItemMatcher() + .label("Sound Settingsā€¦") + .action("indicator.phone-settings") + ) + ).match()); + QStringList mutedIcon = {"audio-volume-muted-panel", "audio-volume-muted", "audio-volume", "audio"}; EXPECT_EQ(getRootIconValue(), mutedIcon); -- cgit v1.2.3