diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 11 | ||||
-rw-r--r-- | tests/integration/indicator-sound-test-base.cpp | 24 | ||||
-rw-r--r-- | tests/integration/indicator-sound-test-base.h | 2 | ||||
-rw-r--r-- | tests/integration/test-indicator.cpp | 15 | ||||
-rw-r--r-- | tests/notifications-mock.h | 2 | ||||
-rw-r--r-- | tests/notifications-test.cc | 237 | ||||
-rw-r--r-- | tests/options-mock.vala | 28 | ||||
-rw-r--r-- | tests/pa-mock.cpp | 19 | ||||
-rw-r--r-- | tests/volume-control-mock.vala | 28 | ||||
-rw-r--r-- | tests/volume-control-test.cc | 7 | ||||
-rw-r--r-- | tests/volume-warning-mock.vala | 40 |
11 files changed, 360 insertions, 53 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bf0e051..e69c01e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -72,9 +72,17 @@ vala_add(vala-mocks ) vala_add(vala-mocks + options-mock.vala +) + +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 @@ -169,6 +177,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} @@ -209,7 +218,7 @@ target_link_libraries ( ${TEST_LIBRARIES} ) -#add_test(notifications-test notifications-test) +add_test(notifications-test notifications-test) ########################### # Accounts Service User diff --git a/tests/integration/indicator-sound-test-base.cpp b/tests/integration/indicator-sound-test-base.cpp index 3b9c58d..91abf42 100644 --- a/tests/integration/indicator-sound-test-base.cpp +++ b/tests/integration/indicator-sound-test-base.cpp @@ -163,13 +163,31 @@ bool IndicatorSoundTestBase::clearGSettingsPlayers() << "com.canonical.indicator.sound" << "interested-media-players" << "[]"); - if (!clearPlayers.waitForStarted()) + + return runProcess(clearPlayers); +} + +bool IndicatorSoundTestBase::resetAllowAmplifiedVolume() +{ + QProcess proc; + + proc.start("gsettings", QStringList() + << "reset" + << "com.ubuntu.sound" + << "allow-amplified-volume"); + + return runProcess(proc); +} + +bool IndicatorSoundTestBase::runProcess(QProcess& proc) +{ + if (!proc.waitForStarted()) return false; - if (!clearPlayers.waitForFinished()) + if (!proc.waitForFinished()) return false; - return clearPlayers.exitCode() == 0; + return proc.exitCode() == 0; } bool IndicatorSoundTestBase::startTestMprisPlayer(QString const& playerName) diff --git a/tests/integration/indicator-sound-test-base.h b/tests/integration/indicator-sound-test-base.h index 67f347f..d9d3289 100644 --- a/tests/integration/indicator-sound-test-base.h +++ b/tests/integration/indicator-sound-test-base.h @@ -77,6 +77,8 @@ protected: void startAccountsService(); bool clearGSettingsPlayers(); + bool resetAllowAmplifiedVolume(); + bool runProcess(QProcess&); bool startTestMprisPlayer(QString const& playerName); diff --git a/tests/integration/test-indicator.cpp b/tests/integration/test-indicator.cpp index 1f357d7..9224b73 100644 --- a/tests/integration/test-indicator.cpp +++ b/tests/integration/test-indicator.cpp @@ -32,7 +32,7 @@ class TestIndicator: public IndicatorSoundTestBase { }; -TEST_F(TestIndicator, PhoneChangeRoleVolume) +TEST_F(TestIndicator, DISABLED_PhoneChangeRoleVolume) { double INITIAL_VOLUME = 0.0; @@ -46,11 +46,11 @@ TEST_F(TestIndicator, PhoneChangeRoleVolume) // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); - // Generate a random volume + // Generate a random volume in the range [0...0.33] QTime now = QTime::currentTime(); qsrand(now.msec()); - int randInt = qrand() % 100; - double randomVolume = randInt / 100.0; + int randInt = qrand() % 33; + const double randomVolume = randInt / 100.0; QSignalSpy &userAccountsSpy = *signal_spy_volume_changed_; // set an initial volume to the alert role @@ -542,6 +542,7 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) { double INITIAL_VOLUME = 0.0; + EXPECT_TRUE(resetAllowAmplifiedVolume()); ASSERT_NO_THROW(startAccountsService()); ASSERT_NO_THROW(startPulseDesktop()); @@ -556,11 +557,11 @@ TEST_F(TestIndicator, DesktopChangeRoleVolume) // start now the indicator, so it picks the new volumes ASSERT_NO_THROW(startIndicator()); - // Generate a random volume + // Generate a random volume in the range [0...0.33] QTime now = QTime::currentTime(); qsrand(now.msec()); - int randInt = qrand() % 100; - double randomVolume = randInt / 100.0; + int randInt = qrand() % 33; + const double randomVolume = randInt / 100.0; // play a test sound, it should NOT change the role in the indicator EXPECT_TRUE(startTestSound("multimedia")); diff --git a/tests/notifications-mock.h b/tests/notifications-mock.h index b0f3b74..3cd8570 100644 --- a/tests/notifications-mock.h +++ b/tests/notifications-mock.h @@ -30,7 +30,7 @@ class NotificationsMock DbusTestDbusMockObject * baseobj = nullptr; public: - NotificationsMock (std::vector<std::string> capabilities = {"body", "body-markup", "icon-static", "image/svg+xml", "x-canonical-private-synchronous", "x-canonical-append", "x-canonical-private-icon-only", "x-canonical-truncation", "private-synchronous", "append", "private-icon-only", "truncation"}) { + NotificationsMock (std::vector<std::string> capabilities = {"actions", "body", "body-markup", "icon-static", "image/svg+xml", "x-canonical-private-synchronous", "x-canonical-append", "x-canonical-private-icon-only", "x-canonical-truncation", "private-synchronous", "append", "private-icon-only", "truncation"}) { mock = dbus_test_dbus_mock_new("org.freedesktop.Notifications"); dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SESSION); dbus_test_task_set_name(DBUS_TEST_TASK(mock), "Notify"); diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc index c5d9770..6f523f1 100644 --- a/tests/notifications-test.cc +++ b/tests/notifications-test.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2015 Canonical Ltd. + * Copyright © 2015-2016 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,8 +15,10 @@ * * Authors: * Ted Gould <ted@canonical.com> + * Charles Kerr <charles.kerr@canonical.com> */ +#include <algorithm> #include <memory> #include <gtest/gtest.h> @@ -105,6 +107,39 @@ class NotificationsTest : public ::testing::Test g_main_loop_unref(loop); } + void loop_until(const std::function<bool()>& test, unsigned int max_ms=50, unsigned int test_interval_ms=10) { + + // g_timeout's callback only allows a single pointer, + // so use a temporary stack struct to wedge everything into one pointer + struct CallbackData { + const std::function<bool()>& test; + const gint64 deadline; + GMainLoop* loop = g_main_loop_new(nullptr, false); + CallbackData (const std::function<bool()>& f, unsigned int max_ms): + test{f}, + deadline{g_get_monotonic_time() + (max_ms*1000)} {} + ~CallbackData() {g_main_loop_unref(loop);} + } data(test, max_ms); + + // tell the timer to stop looping on success or deadline + auto timerfunc = [](gpointer gdata) -> gboolean { + auto& data = *static_cast<CallbackData*>(gdata); + if (!data.test() && (g_get_monotonic_time() < data.deadline)) + return G_SOURCE_CONTINUE; + g_main_loop_quit(data.loop); + return G_SOURCE_REMOVE; + }; + + // start looping + g_timeout_add (std::min(max_ms, test_interval_ms), timerfunc, &data); + g_main_loop_run(data.loop); + } + + void loop_until_notifications(unsigned int max_seconds=1) { + auto test = [this]{ return !notifications->getNotifications().empty(); }; + loop_until(test, max_seconds); + } + static int unref_idle (gpointer user_data) { g_variant_unref(static_cast<GVariant *>(user_data)); return G_SOURCE_REMOVE; @@ -119,18 +154,40 @@ class NotificationsTest : public ::testing::Test return playerList; } - std::shared_ptr<VolumeControl> volumeControlMock () { + std::shared_ptr<IndicatorSoundOptions> optionsMock () { + auto options = std::shared_ptr<IndicatorSoundOptions>( + INDICATOR_SOUND_OPTIONS(options_mock_new()), + [](IndicatorSoundOptions * options){ + g_clear_object(&options); + }); + return options; + } + + std::shared_ptr<VolumeControl> volumeControlMock (const std::shared_ptr<IndicatorSoundOptions>& optionsMock) { auto volumeControl = std::shared_ptr<VolumeControl>( - 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<IndicatorSoundService> standardService (std::shared_ptr<VolumeControl> volumeControl, std::shared_ptr<MediaPlayerList> playerList) { + std::shared_ptr<VolumeWarning> volumeWarningMock (const std::shared_ptr<IndicatorSoundOptions>& optionsMock) { + auto volumeWarning = std::shared_ptr<VolumeWarning>( + VOLUME_WARNING(volume_warning_mock_new(optionsMock.get())), + [](VolumeWarning * warning){ + g_clear_object(&warning); + }); + return volumeWarning; + } + + std::shared_ptr<IndicatorSoundService> standardService ( + const std::shared_ptr<VolumeControl>& volumeControl, + const std::shared_ptr<MediaPlayerList>& playerList, + const std::shared_ptr<IndicatorSoundOptions>& options, + const std::shared_ptr<VolumeWarning>& warning) { auto soundService = std::shared_ptr<IndicatorSoundService>( - indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr), + indicator_sound_service_new(playerList.get(), volumeControl.get(), nullptr, options.get(), warning.get()), [](IndicatorSoundService * service){ g_clear_object(&service); }); @@ -165,10 +222,14 @@ class NotificationsTest : public ::testing::Test g_clear_object(&bus); } + }; TEST_F(NotificationsTest, BasicObject) { - auto soundService = standardService(volumeControlMock(), playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Give some time settle */ loop(50); @@ -177,8 +238,10 @@ TEST_F(NotificationsTest, BasicObject) { } TEST_F(NotificationsTest, VolumeChanges) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -216,8 +279,10 @@ TEST_F(NotificationsTest, VolumeChanges) { } TEST_F(NotificationsTest, StreamChanges) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -228,7 +293,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_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_ALARM); setMockVolume(volumeControl, 0.5, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE); loop(50); notev = notifications->getNotifications(); @@ -236,7 +301,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_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_ALERT); setMockVolume(volumeControl, 0.6, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE); loop(50); notev = notifications->getNotifications(); @@ -244,7 +309,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"); + volume_control_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_MULTIMEDIA); setMockVolume(volumeControl, 0.6, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE); loop(50); setMockVolume(volumeControl, 0.65); @@ -254,8 +319,10 @@ TEST_F(NotificationsTest, StreamChanges) { } TEST_F(NotificationsTest, IconTesting) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set an initial volume */ notifications->clearNotifications(); @@ -288,8 +355,10 @@ TEST_F(NotificationsTest, IconTesting) { } TEST_F(NotificationsTest, ServerRestart) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -335,8 +404,10 @@ TEST_F(NotificationsTest, ServerRestart) { } TEST_F(NotificationsTest, HighVolume) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -350,7 +421,7 @@ TEST_F(NotificationsTest, HighVolume) { /* Set high volume with volume change */ notifications->clearNotifications(); - volume_control_mock_set_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), true); + volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), true); setMockVolume(volumeControl, 0.90); loop(50); notev = notifications->getNotifications(); @@ -360,14 +431,14 @@ TEST_F(NotificationsTest, HighVolume) { EXPECT_GVARIANT_EQ("@s 'true'", notev[0].hints["x-canonical-value-bar-tint"]); /* Move it back */ - volume_control_mock_set_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), false); + volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), false); setMockVolume(volumeControl, 0.50); loop(50); /* Set high volume without level change */ /* NOTE: This can happen if headphones are plugged in */ notifications->clearNotifications(); - volume_control_mock_set_high_volume(VOLUME_CONTROL_MOCK(volumeControl.get()), TRUE); + volume_warning_mock_set_high_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), true); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -377,8 +448,10 @@ TEST_F(NotificationsTest, HighVolume) { } TEST_F(NotificationsTest, MenuHide) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -406,9 +479,11 @@ TEST_F(NotificationsTest, MenuHide) { EXPECT_EQ(1, notev.size()); } -TEST_F(NotificationsTest, DISABLED_ExtendendVolumeNotification) { - auto volumeControl = volumeControlMock(); - auto soundService = standardService(volumeControl, playerListMock()); +TEST_F(NotificationsTest, ExtendendVolumeNotification) { + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); /* Set a volume */ notifications->clearNotifications(); @@ -424,7 +499,8 @@ TEST_F(NotificationsTest, DISABLED_ExtendendVolumeNotification) { /* Allow an amplified volume */ notifications->clearNotifications(); - //indicator_sound_service_set_allow_amplified_volume(soundService.get(), TRUE); + volume_control_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_ALARM); + options_mock_mock_set_max_volume(OPTIONS_MOCK(options.get()), 1.5); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); @@ -440,9 +516,112 @@ TEST_F(NotificationsTest, DISABLED_ExtendendVolumeNotification) { /* Put back */ notifications->clearNotifications(); - //indicator_sound_service_set_allow_amplified_volume(soundService.get(), FALSE); + options_mock_mock_set_max_volume(OPTIONS_MOCK(options.get()), 1.0); loop(50); notev = notifications->getNotifications(); ASSERT_EQ(1, notev.size()); EXPECT_GVARIANT_EQ("@i 100", notev[0].hints["value"]); } + +TEST_F(NotificationsTest, TriggerWarning) { + + // Tests all the conditions needed to trigger a volume warning. + // There are many possible combinations, so this test is slow. :P + + const struct { + bool expected; + VolumeControlActiveOutput output; + } test_outputs[] = { + { false, VOLUME_CONTROL_ACTIVE_OUTPUT_SPEAKERS }, + { true, VOLUME_CONTROL_ACTIVE_OUTPUT_HEADPHONES }, + { true, VOLUME_CONTROL_ACTIVE_OUTPUT_BLUETOOTH_HEADPHONES }, + { false, VOLUME_CONTROL_ACTIVE_OUTPUT_BLUETOOTH_SPEAKER }, + { false, VOLUME_CONTROL_ACTIVE_OUTPUT_USB_SPEAKER }, + { true, VOLUME_CONTROL_ACTIVE_OUTPUT_USB_HEADPHONES }, + { false, VOLUME_CONTROL_ACTIVE_OUTPUT_HDMI_SPEAKER }, + { true, VOLUME_CONTROL_ACTIVE_OUTPUT_HDMI_HEADPHONES }, + { false, VOLUME_CONTROL_ACTIVE_OUTPUT_CALL_MODE } + }; + + const struct { + bool expected; + pa_volume_t volume; + pa_volume_t loud_volume; + } test_volumes[] = { + { false, 50, 100 }, + { false, 99, 100 }, + { true, 100, 100 }, + { true, 101, 100 } + }; + + const struct { + bool expected; + bool approved; + } test_approved[] = { + { true, false }, + { false, true } + }; + + const struct { + bool expected; + bool warnings_enabled; + } test_warnings_enabled[] = { + { true, true }, + { false, false } + }; + + const struct { + bool expected; + bool multimedia_active; + } test_multimedia_active[] = { + { true, true }, + { false, false } + }; + + for (const auto& outputs : test_outputs) { + for (const auto& volumes : test_volumes) { + for (const auto& approved : test_approved) { + for (const auto& warnings_enabled : test_warnings_enabled) { + for (const auto& multimedia_active : test_multimedia_active) { + + notifications->clearNotifications(); + + // instantiate the test subjects + auto options = optionsMock(); + auto volumeControl = volumeControlMock(options); + auto volumeWarning = volumeWarningMock(options); + auto soundService = standardService(volumeControl, playerListMock(), options, volumeWarning); + + // run the test + options_mock_mock_set_loud_volume(OPTIONS_MOCK(options.get()), volumes.loud_volume); + options_mock_mock_set_loud_warning_enabled(OPTIONS_MOCK(options.get()), warnings_enabled.warnings_enabled); + volume_warning_mock_set_approved(VOLUME_WARNING_MOCK(volumeWarning.get()), approved.approved); + volume_warning_mock_set_multimedia_volume(VOLUME_WARNING_MOCK(volumeWarning.get()), volumes.volume); + volume_warning_mock_set_multimedia_active(VOLUME_WARNING_MOCK(volumeWarning.get()), multimedia_active.multimedia_active); + volume_control_mock_mock_set_active_output(VOLUME_CONTROL_MOCK(volumeControl.get()), outputs.output); + + loop_until_notifications(); + + // check the result + auto notev = notifications->getNotifications(); + const bool warning_expected = outputs.expected && volumes.expected && approved.expected && warnings_enabled.expected && multimedia_active.expected; + if (warning_expected) { + EXPECT_TRUE(volume_warning_get_active(volumeWarning.get())); + ASSERT_EQ(1, notev.size()); + EXPECT_GVARIANT_EQ("@s 'true'", notev[0].hints["x-canonical-snap-decisions"]); + EXPECT_GVARIANT_EQ(nullptr, notev[0].hints["x-canonical-private-synchronous"]); + } + else { + EXPECT_FALSE(volume_warning_get_active(volumeWarning.get())); + ASSERT_EQ(1, notev.size()); + EXPECT_GVARIANT_EQ(nullptr, notev[0].hints["x-canonical-snap-decisions"]); + EXPECT_GVARIANT_EQ("@s 'true'", notev[0].hints["x-canonical-private-synchronous"]); + } + + } // multimedia_active + } // warnings_enabled + } // approved + } // volumes + } // outputs +} + diff --git a/tests/options-mock.vala b/tests/options-mock.vala new file mode 100644 index 0000000..cda9e24 --- /dev/null +++ b/tests/options-mock.vala @@ -0,0 +1,28 @@ +/* + * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*- + * Copyright © 2015 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +public class OptionsMock : IndicatorSound.Options +{ + public void mock_set_max_volume (double val) { max_volume = val; } + + public void mock_set_loud_volume (PulseAudio.Volume val) { loud_volume = val; } + + public void mock_set_loud_warning_enabled (bool val) { loud_warning_enabled = val; } +} diff --git a/tests/pa-mock.cpp b/tests/pa-mock.cpp index 5dd5c9b..7e7b70c 100644 --- a/tests/pa-mock.cpp +++ b/tests/pa-mock.cpp @@ -351,6 +351,25 @@ pa_context_set_source_volume_by_name (pa_context *c, const char * name, const pa return dummy_operation(); } +pa_operation* +pa_context_get_sink_input_info_list(pa_context *c, pa_sink_input_info_cb_t cb, void *userdata) +{ + reinterpret_cast<PAMockContext*>(c)->idleOnce( + [c, cb, userdata]() { + + pa_sink_input_info sink_input; + sink_input.name = "default-sink-input"; + sink_input.proplist = nullptr; + sink_input.has_volume = false; + + if (cb != nullptr) + cb(c, &sink_input, true, userdata); + }); + + return dummy_operation(); +} + + /* ******************************* * subscribe.h * *******************************/ diff --git a/tests/volume-control-mock.vala b/tests/volume-control-mock.vala index dc11fba..159df3b 100644 --- a/tests/volume-control-mock.vala +++ b/tests/volume-control-mock.vala @@ -20,27 +20,33 @@ public class VolumeControlMock : VolumeControl { - private bool _high_volume = false; - public override bool high_volume { get { return _high_volume; } protected set { _high_volume = value; } } - public void set_high_volume(bool b) { high_volume = b; } - - public string mock_stream { get; set; default = "multimedia"; } - public override string stream { get { return mock_stream; } } - public override bool ready { get; set; } + public void mock_set_is_ready(bool b) { ready = b; } + public void mock_set_active_stream(VolumeControl.Stream s) { active_stream = s; } + public void mock_set_is_playing(bool b) { is_playing = b; } public override bool active_mic { get; set; } public bool mock_mute { get; set; } 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; } } 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) { - } - public VolumeControlMock() { + private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS; + + public override VolumeControl.ActiveOutput active_output() { + return _active_output; + } + + public void mock_set_active_output (VolumeControl.ActiveOutput val) { + _active_output = val; + this.active_output_changed(val); + } + + 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..11fa4ff 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,9 @@ class VolumeControlTest : public ::testing::Test }; TEST_F(VolumeControlTest, BasicObject) { - VolumeControlPulse * control = volume_control_pulse_new(); + auto options = options_mock_new(); + auto pgloop = pa_glib_mainloop_new(NULL); + auto control = volume_control_pulse_new(INDICATOR_SOUND_OPTIONS(options), pgloop); /* Setup the PA backend */ loop(100); @@ -84,4 +87,6 @@ TEST_F(VolumeControlTest, BasicObject) { EXPECT_TRUE(volume_control_get_ready(VOLUME_CONTROL(control))); g_clear_object(&control); + g_clear_object(&options); + g_clear_pointer(&pgloop, pa_glib_mainloop_free); } diff --git a/tests/volume-warning-mock.vala b/tests/volume-warning-mock.vala new file mode 100644 index 0000000..f69688f --- /dev/null +++ b/tests/volume-warning-mock.vala @@ -0,0 +1,40 @@ +/* + * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*- + * Copyright © 2015 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Ted Gould <ted@canonical.com> + */ + +public class VolumeWarningMock : VolumeWarning +{ + public void set_high_volume(bool val) { high_volume = val; } + + public VolumeWarningMock(IndicatorSound.Options options) { + base(options); + } + + protected override void sound_system_set_multimedia_volume(PulseAudio.Volume volume) { + GLib.message("volume-warning-mock setting multimedia volume to %d", (int)volume); + } + + public void set_multimedia_active(bool val) { multimedia_active = val; } + + public void set_multimedia_volume(PulseAudio.Volume val) { multimedia_volume = val; } + + public void set_approved(bool val) { approved = val; } + + public bool is_approved() { return approved; } +} |