From 8ab16462724ab3108d1a16e3cea1c66a10ce775b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 13 Feb 2015 09:24:21 -0600 Subject: Clean up some of the boiler plate --- tests/notifications-test.cc | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'tests/notifications-test.cc') diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index 74be5d0..2aff7ae 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -109,12 +109,38 @@ class NotificationsTest : public ::testing::Test g_variant_unref(static_cast(user_data)); return G_SOURCE_REMOVE; } + + std::shared_ptr playerListMock () { + auto playerList = std::shared_ptr( + MEDIA_PLAYER_LIST(media_player_list_mock_new()), + [](MediaPlayerList * list) { + g_clear_object(&list); + }); + return playerList; + } + + std::shared_ptr volumeControlMock () { + auto volumeControl = std::shared_ptr( + VOLUME_CONTROL(volume_control_mock_new()), + [](VolumeControl * control){ + g_clear_object(&control); + }); + return volumeControl; + } + + std::shared_ptr standardService (std::shared_ptr volumeControl, std::shared_ptr playerList) { + auto soundService = std::shared_ptr( + indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr), + [](IndicatorSoundService * service){ + g_clear_object(&service); + }); + + return soundService; + } }; TEST_F(NotificationsTest, BasicObject) { - auto playerList = std::shared_ptr(MEDIA_PLAYER_LIST(media_player_list_mock_new()), [](MediaPlayerList * list){g_clear_object(&list);}); - auto volumeControl = std::shared_ptr(VOLUME_CONTROL(volume_control_mock_new()), [](VolumeControl * control){g_clear_object(&control);}); - auto soundService = std::shared_ptr(indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr), [](IndicatorSoundService * service){g_clear_object(&service);}); + auto soundService = standardService(volumeControlMock(), playerListMock()); /* Give some time settle */ loop(50); @@ -123,9 +149,8 @@ TEST_F(NotificationsTest, BasicObject) { } TEST_F(NotificationsTest, VolumeChanges) { - auto playerList = std::shared_ptr(MEDIA_PLAYER_LIST(media_player_list_mock_new()), [](MediaPlayerList * list){g_clear_object(&list);}); - auto volumeControl = std::shared_ptr(VOLUME_CONTROL(volume_control_mock_new()), [](VolumeControl * control){g_clear_object(&control);}); - auto soundService = std::shared_ptr(indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr), [](IndicatorSoundService * service){g_clear_object(&service);}); + auto volumeControl = volumeControlMock(); + auto soundService = standardService(volumeControl, playerListMock()); /* Set a volume */ notifications->clearNotifications(); -- cgit v1.2.3