From 1f90c34cc74b9122eb90c53093df8ddc15aa2b07 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Feb 2015 10:54:53 -0600 Subject: Migrate tests to new interface --- tests/notifications-test.cc | 43 +++++++++++++++++++++++++----------------- tests/volume-control-mock.vala | 3 ++- 2 files changed, 28 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index 79b6e8e..2893531 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -137,6 +137,15 @@ class NotificationsTest : public ::testing::Test return soundService; } + + void setMockVolume (std::shared_ptr volumeControl, double volume, VolumeControlVolumeReasons reason = VOLUME_CONTROL_VOLUME_REASONS_USER_KEYPRESS) { + VolumeControlVolume * vol = volume_control_volume_new(); + vol->volume = volume; + vol->reason = reason; + + volume_control_set_volume(volumeControl.get(), vol); + g_object_unref(vol); + } }; TEST_F(NotificationsTest, BasicObject) { @@ -154,7 +163,7 @@ TEST_F(NotificationsTest, VolumeChanges) { /* Set a volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.50); + setMockVolume(volumeControl, 0.50); loop(50); auto notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -166,7 +175,7 @@ TEST_F(NotificationsTest, VolumeChanges) { /* Set a different volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.60); + setMockVolume(volumeControl, 0.60); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -174,14 +183,14 @@ TEST_F(NotificationsTest, VolumeChanges) { /* Set the same volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.60); + setMockVolume(volumeControl, 0.60); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(0, notev.size()); /* Change just a little */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.60001); + setMockVolume(volumeControl, 0.60001); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(0, notev.size()); @@ -193,7 +202,7 @@ TEST_F(NotificationsTest, StreamChanges) { /* Set a volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.5); + setMockVolume(volumeControl, 0.5); loop(50); auto notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -201,7 +210,7 @@ TEST_F(NotificationsTest, StreamChanges) { /* Change Streams, no volume change */ notifications->clearNotifications(); volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "alarm"); - volume_control_set_volume(volumeControl.get(), 0.5); + setMockVolume(volumeControl, 0.5); loop(50); notev = notifications->getNotifications(); EXPECT_EQ(0, notev.size()); @@ -209,7 +218,7 @@ TEST_F(NotificationsTest, StreamChanges) { /* Change Streams, volume change */ notifications->clearNotifications(); volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "alert"); - volume_control_set_volume(volumeControl.get(), 0.60); + setMockVolume(volumeControl, 0.60); loop(50); notev = notifications->getNotifications(); EXPECT_EQ(0, notev.size()); @@ -217,9 +226,9 @@ TEST_F(NotificationsTest, StreamChanges) { /* Change Streams, no volume change, volume up */ notifications->clearNotifications(); volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "multimedia"); - volume_control_set_volume(volumeControl.get(), 0.60); + setMockVolume(volumeControl, 0.60); loop(50); - volume_control_set_volume(volumeControl.get(), 0.65); + setMockVolume(volumeControl, 0.65); notev = notifications->getNotifications(); EXPECT_EQ(1, notev.size()); EXPECT_GVARIANT_EQ("@i 65", notev[0].hints["value"]); @@ -231,7 +240,7 @@ TEST_F(NotificationsTest, IconTesting) { /* Set an initial volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.5); + setMockVolume(volumeControl, 0.5); loop(50); auto notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -239,7 +248,7 @@ TEST_F(NotificationsTest, IconTesting) { /* Generate a set of notifications */ notifications->clearNotifications(); for (float i = 0.0; i < 1.01; i += 0.1) { - volume_control_set_volume(volumeControl.get(), i); + setMockVolume(volumeControl, i); } loop(50); @@ -265,7 +274,7 @@ TEST_F(NotificationsTest, ServerRestart) { /* Set a volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.50); + setMockVolume(volumeControl, 0.50); loop(50); auto notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -283,7 +292,7 @@ TEST_F(NotificationsTest, ServerRestart) { /* Change the volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.60); + setMockVolume(volumeControl, 0.60); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(0, notev.size()); @@ -300,7 +309,7 @@ TEST_F(NotificationsTest, ServerRestart) { /* Change the volume again */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.70); + setMockVolume(volumeControl, 0.70); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -312,7 +321,7 @@ TEST_F(NotificationsTest, HighVolume) { /* Set a volume */ notifications->clearNotifications(); - volume_control_set_volume(volumeControl.get(), 0.50); + setMockVolume(volumeControl, 0.50); loop(50); auto notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -323,7 +332,7 @@ TEST_F(NotificationsTest, HighVolume) { /* Set high volume with volume change */ notifications->clearNotifications(); volume_control_mock_set_mock_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), TRUE); - volume_control_set_volume(volumeControl.get(), 0.90); + setMockVolume(volumeControl, 0.90); loop(50); notev = notifications->getNotifications(); ASSERT_LT(0, notev.size()); /* This passes with one or two since it would just be an update to the first if a second was sent */ @@ -333,7 +342,7 @@ TEST_F(NotificationsTest, HighVolume) { /* Move it back */ volume_control_mock_set_mock_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), FALSE); - volume_control_set_volume(volumeControl.get(), 0.50); + setMockVolume(volumeControl, 0.50); loop(50); /* Set high volume without level change */ diff --git a/tests/volume-control-mock.vala b/tests/volume-control-mock.vala index 4b846bf..4c96518 100644 --- a/tests/volume-control-mock.vala +++ b/tests/volume-control-mock.vala @@ -30,7 +30,8 @@ public class VolumeControlMock : VolumeControl public override bool mute { get { return mock_mute; } } public bool mock_is_playing { get; set; } public override bool is_playing { get { return mock_is_playing; } } - public override double volume { get; set; } + private VolumeControl.Volume _vol = new VolumeControl.Volume(); + public override VolumeControl.Volume volume { get { return _vol; } set { _vol = value; }} public override double mic_volume { get; set; } public override void set_mute (bool mute) { -- cgit v1.2.3 From 7069d4f3edf885c59bebd7956a0d68adb2b99748 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Feb 2015 11:07:45 -0600 Subject: Adjusting the tests so they're testing what we need --- tests/notifications-test.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index 2893531..88ed6c6 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -181,16 +181,16 @@ TEST_F(NotificationsTest, VolumeChanges) { ASSERT_EQ(1, notev.size()); EXPECT_GVARIANT_EQ("@i 60", notev[0].hints["value"]); - /* Set the same volume */ + /* Have pulse set a volume */ notifications->clearNotifications(); - setMockVolume(volumeControl, 0.60); + setMockVolume(volumeControl, 0.70, VOLUME_CONTROL_VOLUME_REASONS_PULSE_CHANGE); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(0, notev.size()); - /* Change just a little */ + /* Have AS set the volume */ notifications->clearNotifications(); - setMockVolume(volumeControl, 0.60001); + setMockVolume(volumeControl, 0.80, VOLUME_CONTROL_VOLUME_REASONS_ACCOUNTS_SERVICE_SET); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(0, notev.size()); @@ -210,7 +210,7 @@ TEST_F(NotificationsTest, StreamChanges) { /* Change Streams, no volume change */ notifications->clearNotifications(); volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "alarm"); - setMockVolume(volumeControl, 0.5); + setMockVolume(volumeControl, 0.5, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE); loop(50); notev = notifications->getNotifications(); EXPECT_EQ(0, notev.size()); @@ -218,7 +218,7 @@ TEST_F(NotificationsTest, StreamChanges) { /* Change Streams, volume change */ notifications->clearNotifications(); volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "alert"); - setMockVolume(volumeControl, 0.60); + setMockVolume(volumeControl, 0.6, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE); loop(50); notev = notifications->getNotifications(); EXPECT_EQ(0, notev.size()); @@ -226,7 +226,7 @@ TEST_F(NotificationsTest, StreamChanges) { /* Change Streams, no volume change, volume up */ notifications->clearNotifications(); volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "multimedia"); - setMockVolume(volumeControl, 0.60); + setMockVolume(volumeControl, 0.6, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE); loop(50); setMockVolume(volumeControl, 0.65); notev = notifications->getNotifications(); -- cgit v1.2.3