From 4b695bacf20b7247f6b16483ede5e5d8b51dd355 Mon Sep 17 00:00:00 2001 From: charles kerr Date: Sat, 19 Dec 2015 16:01:46 -0600 Subject: move max_volume into a reusable 'options' class --- tests/CMakeLists.txt | 5 ++++ tests/notifications-test.cc | 56 ++++++++++++++++++++++++++++-------------- tests/volume-control-mock.vala | 4 ++- tests/volume-control-test.cc | 5 +++- 4 files changed, 49 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bf0e051..c11e288 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -71,6 +71,10 @@ vala_add(vala-mocks media-player-list-mock.vala ) +vala_add(vala-mocks + options-mock.vala +) + vala_add(vala-mocks volume-control-mock.vala ) @@ -169,6 +173,7 @@ add_executable (volume-control-test volume-control-test.cc gschemas.compiled) target_link_libraries ( volume-control-test indicator-sound-service-lib + vala-mocks-lib pulse-mock gtest-static ${TEST_LIBRARIES} diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index c5d9770..26864cd 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -119,18 +119,27 @@ class NotificationsTest : public ::testing::Test return playerList; } - std::shared_ptr volumeControlMock () { + std::shared_ptr optionsMock () { + auto options = std::shared_ptr( + INDICATOR_SOUND_OPTIONS(options_mock_new()), + [](IndicatorSoundOptions * options){ + g_clear_object(&options); + }); + return options; + } + + std::shared_ptr volumeControlMock (const std::shared_ptr& optionsMock) { auto volumeControl = std::shared_ptr( - VOLUME_CONTROL(volume_control_mock_new()), + VOLUME_CONTROL(volume_control_mock_new(optionsMock.get())), [](VolumeControl * control){ g_clear_object(&control); }); return volumeControl; } - std::shared_ptr standardService (std::shared_ptr volumeControl, std::shared_ptr playerList) { + std::shared_ptr standardService (std::shared_ptr volumeControl, std::shared_ptr playerList, const std::shared_ptr& options) { auto soundService = std::shared_ptr( - indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr), + indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr, options.get()), [](IndicatorSoundService * service){ g_clear_object(&service); }); @@ -168,7 +177,9 @@ class NotificationsTest : public ::testing::Test }; TEST_F(NotificationsTest, BasicObject) { - auto soundService = standardService(volumeControlMock(), playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Give some time settle */ loop(50); @@ -177,8 +188,9 @@ TEST_F(NotificationsTest, BasicObject) { } TEST_F(NotificationsTest, VolumeChanges) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set a volume */ notifications->clearNotifications(); @@ -216,8 +228,9 @@ TEST_F(NotificationsTest, VolumeChanges) { } TEST_F(NotificationsTest, StreamChanges) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set a volume */ notifications->clearNotifications(); @@ -254,8 +267,9 @@ TEST_F(NotificationsTest, StreamChanges) { } TEST_F(NotificationsTest, IconTesting) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set an initial volume */ notifications->clearNotifications(); @@ -288,8 +302,9 @@ TEST_F(NotificationsTest, IconTesting) { } TEST_F(NotificationsTest, ServerRestart) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set a volume */ notifications->clearNotifications(); @@ -335,8 +350,9 @@ TEST_F(NotificationsTest, ServerRestart) { } TEST_F(NotificationsTest, HighVolume) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set a volume */ notifications->clearNotifications(); @@ -377,8 +393,9 @@ TEST_F(NotificationsTest, HighVolume) { } TEST_F(NotificationsTest, MenuHide) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set a volume */ notifications->clearNotifications(); @@ -407,8 +424,9 @@ TEST_F(NotificationsTest, MenuHide) { } TEST_F(NotificationsTest, DISABLED_ExtendendVolumeNotification) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options); /* Set a volume */ notifications->clearNotifications(); diff --git a/tests/volume-control-mock.vala b/tests/volume-control-mock.vala index dc11fba..7f958b2 100644 --- a/tests/volume-control-mock.vala +++ b/tests/volume-control-mock.vala @@ -40,7 +40,9 @@ public class VolumeControlMock : VolumeControl } - public VolumeControlMock() { + public VolumeControlMock(IndicatorSound.Options options) { + base(options); + ready = true; this.notify["mock-stream"].connect(() => this.notify_property("stream")); this.notify["mock-high-volume"].connect(() => this.notify_property("high-volume")); diff --git a/tests/volume-control-test.cc b/tests/volume-control-test.cc index 5022245..2d07746 100644 --- a/tests/volume-control-test.cc +++ b/tests/volume-control-test.cc @@ -23,6 +23,7 @@ extern "C" { #include "indicator-sound-service.h" +#include "vala-mocks.h" } class VolumeControlTest : public ::testing::Test @@ -75,7 +76,8 @@ class VolumeControlTest : public ::testing::Test }; TEST_F(VolumeControlTest, BasicObject) { - VolumeControlPulse * control = volume_control_pulse_new(); + auto options = options_mock_new(); + auto control = volume_control_pulse_new(INDICATOR_SOUND_OPTIONS(options)); /* Setup the PA backend */ loop(100); @@ -84,4 +86,5 @@ TEST_F(VolumeControlTest, BasicObject) { EXPECT_TRUE(volume_control_get_ready(VOLUME_CONTROL(control))); g_clear_object(&control); + g_clear_object(&options); } -- cgit v1.2.3