From 9e54db50c17504289792ee12e4d785a69f2742ec Mon Sep 17 00:00:00 2001 From: charles kerr Date: Sat, 19 Dec 2015 21:11:09 -0600 Subject: instantiate volume-warning and pass it to the service --- src/main.c | 5 ++++- src/service.vala | 10 ++++++---- tests/CMakeLists.txt | 4 ++++ tests/notifications-test.cc | 41 +++++++++++++++++++++++++++++++---------- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main.c b/src/main.c index 01cadf1..11eaa06 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,7 @@ on_bus_acquired(GDBusConnection *connection, IndicatorSoundOptions * options = NULL; VolumeControlPulse * volume = NULL; AccountsServiceUser * accounts = NULL; + VolumeWarning * warning = NULL; if (g_strcmp0("lightdm", g_get_user_name()) == 0) { @@ -60,13 +61,15 @@ on_bus_acquired(GDBusConnection *connection, options = indicator_sound_options_gsettings_new(); volume = volume_control_pulse_new(options); + warning = volume_warning_new(options); - service = indicator_sound_service_new (playerlist, volume, accounts, options); + service = indicator_sound_service_new (playerlist, volume, accounts, options, warning); g_clear_object(&playerlist); g_clear_object(&options); g_clear_object(&volume); g_clear_object(&accounts); + g_clear_object(&warning); } int diff --git a/src/service.vala b/src/service.vala index c94deb2..ed0fc74 100644 --- a/src/service.vala +++ b/src/service.vala @@ -27,9 +27,10 @@ public class IndicatorSound.Service: Object { */ VolumeControl.Volume _pre_warn_volume = null; - public Service (MediaPlayerList playerlist, VolumeControl volume, AccountsServiceUser? accounts, Options options) { + public Service (MediaPlayerList playerlist, VolumeControl volume, AccountsServiceUser? accounts, Options options, VolumeWarning volume_warning) { _options = options; + _volume_warning = volume_warning; try { bus = Bus.get_sync(GLib.BusType.SESSION); @@ -43,8 +44,8 @@ public class IndicatorSound.Service: Object { warn_notification.set_hint ("x-canonical-non-shaped-icon", "true"); warn_notification.set_hint ("x-canonical-snap-decisions", "true"); warn_notification.set_hint ("x-canonical-private-affirmative-tint", "true"); - warn_notification.closed.connect((n) => { - n.clear_actions(); + warn_notification.closed.connect((n) => { + n.clear_actions(); waiting_user_approve_warn=false; increment_volume_sync_action(); }); @@ -208,7 +209,8 @@ public class IndicatorSound.Service: Object { bool export_to_accounts_service = false; private Notify.Notification info_notification; private Notify.Notification warn_notification; - private Options _options = null; + private Options _options; + private VolumeWarning _volume_warning; const double volume_step_percentage = 0.06; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c11e288..7099d20 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,6 +79,10 @@ vala_add(vala-mocks volume-control-mock.vala ) +vala_add(vala-mocks + volume-warning-mock.vala +) + vala_finish(vala-mocks SOURCES vala_mocks_VALA_SOURCES diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index 26864cd..ec9d915 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -137,9 +137,22 @@ class NotificationsTest : public ::testing::Test return volumeControl; } - std::shared_ptr standardService (std::shared_ptr volumeControl, std::shared_ptr playerList, const std::shared_ptr& options) { + std::shared_ptr volumeWarningMock (const std::shared_ptr& optionsMock) { + auto volumeWarning = std::shared_ptr( + VOLUME_WARNING(volume_warning_mock_new(optionsMock.get())), + [](VolumeWarning * warning){ + g_clear_object(&warning); + }); + return volumeWarning; + } + + std::shared_ptr standardService ( + const std::shared_ptr& volumeControl, + const std::shared_ptr& playerList, + const std::shared_ptr& options, + const std::shared_ptr& warning) { auto soundService = std::shared_ptr( - indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr, options.get()), + indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr, options.get(), warning.get()), [](IndicatorSoundService * service){ g_clear_object(&service); }); @@ -179,7 +192,8 @@ class NotificationsTest : public ::testing::Test TEST_F(NotificationsTest, BasicObject) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Give some time settle */ loop(50); @@ -190,7 +204,8 @@ TEST_F(NotificationsTest, BasicObject) { TEST_F(NotificationsTest, VolumeChanges) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -230,7 +245,8 @@ TEST_F(NotificationsTest, VolumeChanges) { TEST_F(NotificationsTest, StreamChanges) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -269,7 +285,8 @@ TEST_F(NotificationsTest, StreamChanges) { TEST_F(NotificationsTest, IconTesting) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set an initial volume */ notifications->clearNotifications(); @@ -304,7 +321,8 @@ TEST_F(NotificationsTest, IconTesting) { TEST_F(NotificationsTest, ServerRestart) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -352,7 +370,8 @@ TEST_F(NotificationsTest, ServerRestart) { TEST_F(NotificationsTest, HighVolume) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -395,7 +414,8 @@ TEST_F(NotificationsTest, HighVolume) { TEST_F(NotificationsTest, MenuHide) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -426,7 +446,8 @@ TEST_F(NotificationsTest, MenuHide) { TEST_F(NotificationsTest, DISABLED_ExtendendVolumeNotification) { auto options = optionsMock(); auto volumeControl = volumeControlMock(options); - auto soundService = standardService(volumeControl, playerListMock(), options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); -- cgit v1.2.3