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/integration/indicator-sound-test-base.cpp | 17 +++++++++++++++-- tests/integration/indicator-sound-test-base.h | 5 +++++ tests/integration/test-indicator.cpp | 8 +++----- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 2bd71b6..dd5d4b5 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -407,11 +407,11 @@ void IndicatorSoundTestBase::initializeAccountsInterface() auto username = qgetenv("USER"); if (username != "") { - std::unique_ptr accountsInterface(new AccountsInterface("org.freedesktop.Accounts", + main_accounts_interface_.reset(new AccountsInterface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", dbusTestRunner.systemConnection(), 0)); - QDBusReply userResp = accountsInterface->call(QLatin1String("FindUserByName"), + QDBusReply userResp = main_accounts_interface_->call(QLatin1String("FindUserByName"), QLatin1String(username)); if (!userResp.isValid()) @@ -805,3 +805,16 @@ void IndicatorSoundTestBase::checkPortDevicesLabels(DevicePortType speakerPort, ) ).match()); } + +bool IndicatorSoundTestBase::setVolumeUntilAccountsIsConnected(double volume) +{ + int RETRY_TIME = 5000; + + setActionValue("volume", QVariant::fromValue(volume)); + while(!signal_spy_volume_changed_->wait(10) && RETRY_TIME) + { + RETRY_TIME -= 10; + setActionValue("volume", QVariant::fromValue(volume)); + } + return (signal_spy_volume_changed_->count() != 0); +} diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index f9df9bb..41dd1c7 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -31,6 +31,7 @@ class MenusInterface; class DBusPulseVolume; class DBusPropertiesInterface; +class AccountsInterface; class QSignalSpy; #define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\ @@ -131,6 +132,8 @@ protected: void checkPortDevicesLabels(DevicePortType speakerPort, DevicePortType headphonesPort); + bool setVolumeUntilAccountsIsConnected(double volume); + QtDBusTest::DBusTestRunner dbusTestRunner; QtDBusMock::DBusMock dbusMock; @@ -149,6 +152,8 @@ protected: std::unique_ptr accounts_interface_; + std::unique_ptr main_accounts_interface_; + std::unique_ptr signal_spy_volume_changed_; std::unique_ptr signal_spy_menu_changed_; diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index e79c9d4..d55222b 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -32,7 +32,7 @@ class TestIndicator: public IndicatorSoundTestBase { }; -TEST_F(TestIndicator, DISABLED_PhoneChangeRoleVolume) +TEST_F(TestIndicator, PhoneChangeRoleVolume) { double INITIAL_VOLUME = 0.0; @@ -55,9 +55,7 @@ TEST_F(TestIndicator, DISABLED_PhoneChangeRoleVolume) QSignalSpy &userAccountsSpy = *signal_spy_volume_changed_; // set an initial volume to the alert role userAccountsSpy.clear(); - setStreamRestoreVolume("alert", 1.0); - WAIT_AT_LEAST_SIGNALS(userAccountsSpy, 1); - + EXPECT_TRUE(setVolumeUntilAccountsIsConnected(1.0)); userAccountsSpy.clear(); // play a test sound, it should change the role in the indicator EXPECT_TRUE(startTestSound("multimedia")); @@ -69,7 +67,7 @@ TEST_F(TestIndicator, DISABLED_PhoneChangeRoleVolume) userAccountsSpy.clear(); // set the random volume to the multimedia role - EXPECT_TRUE(setStreamRestoreVolume("multimedia", randomVolume)); + setActionValue("volume", QVariant::fromValue(randomVolume)); if (randomVolume != INITIAL_VOLUME) { WAIT_FOR_SIGNALS(userAccountsSpy, 1); -- cgit v1.2.3