From fcd77b806a8826d5f694f78c63943d0f768ef6ec Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 Jul 2014 23:35:38 -0500 Subject: refactor the Notifications / sound / awake code --- tests/manual-test-snap.cpp | 11 +++---- tests/test-snap.cpp | 74 +++++++++++++++++++++++++++++----------------- 2 files changed, 53 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index cc24a67..7d4403d 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -22,13 +22,13 @@ #include #include #include +#include #include using namespace unity::indicator::datetime; -#define TIMEZONE_FILE ("/etc/timezone") - +namespace uin = unity::indicator::notifications; /*** **** @@ -94,11 +94,12 @@ int main(int argc, const char* argv[]) auto settings = std::make_shared(); settings->alarm_volume.set(volume); - auto timezones = std::make_shared(settings, TIMEZONE_FILE); - auto clock = std::make_shared(timezones); - Snap snap (clock, settings); + + auto notification_engine = std::make_shared("indicator-datetime-service"); + Snap snap (notification_engine, settings); snap(a, show, dismiss); g_main_loop_run(loop); + g_main_loop_unref(loop); return 0; } diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index f9e7a66..9a049fa 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -21,11 +21,11 @@ #include #include #include -#include -#include +#include +#include -#include +#include #include @@ -37,6 +37,11 @@ using namespace unity::indicator::datetime; **** ***/ +namespace +{ + static constexpr char const * APP_NAME {"indicator-datetime-service"}; +} + using namespace unity::indicator::datetime; class SnapFixture: public GlibFixture @@ -60,18 +65,19 @@ protected: static constexpr char const * POWERD_METHOD_REQUEST_SYS_STATE {"requestSysState"}; static constexpr char const * POWERD_METHOD_CLEAR_SYS_STATE {"clearSysState"}; - static constexpr int NOTIFY_ID {1234}; + static constexpr int FIRST_NOTIFY_ID {1000}; static constexpr int NOTIFICATION_CLOSED_EXPIRED {1}; static constexpr int NOTIFICATION_CLOSED_DISMISSED {2}; static constexpr int NOTIFICATION_CLOSED_API {3}; static constexpr int NOTIFICATION_CLOSED_UNDEFINED {4}; - static constexpr char const * APP_NAME {"indicator-datetime-service"}; - - static constexpr char const * METHOD_NOTIFY {"Notify"}; + static constexpr char const * METHOD_CLOSE {"CloseNotification"}; static constexpr char const * METHOD_GET_CAPS {"GetCapabilities"}; static constexpr char const * METHOD_GET_INFO {"GetServerInformation"}; + static constexpr char const * METHOD_NOTIFY {"Notify"}; + + static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"}; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; @@ -118,7 +124,8 @@ protected: NOTIFY_INTERFACE, &error); g_assert_no_error(error); - + + // METHOD_GET_INFO str = g_strdup("ret = ('mock-notify', 'test vendor', '1.0', '1.1')"); dbus_test_dbus_mock_object_add_method(notify_mock, notify_obj, @@ -130,7 +137,14 @@ protected: g_assert_no_error (error); g_free (str); - str = g_strdup_printf ("ret = %d", NOTIFY_ID); + // METHOD_NOTIFY + str = g_strdup_printf("try:\n" + " self.NextNotifyId\n" + "except AttributeError:\n" + " self.NextNotifyId = %d\n" + "ret = self.NextNotifyId\n" + "self.NextNotifyId += 1\n", + FIRST_NOTIFY_ID); dbus_test_dbus_mock_object_add_method(notify_mock, notify_obj, METHOD_NOTIFY, @@ -141,6 +155,21 @@ protected: g_assert_no_error (error); g_free (str); + // METHOD_CLOSE + str = g_strdup_printf("self.EmitSignal('%s', '%s', 'uu', [ args[0], %d ])", + NOTIFY_INTERFACE, + SIGNAL_CLOSED, + NOTIFICATION_CLOSED_API); + dbus_test_dbus_mock_object_add_method(notify_mock, + notify_obj, + METHOD_CLOSE, + G_VARIANT_TYPE("(u)"), + nullptr, + str, + &error); + g_assert_no_error (error); + g_free (str); + dbus_test_service_add_task(service, DBUS_TEST_TASK(notify_mock)); /// @@ -226,14 +255,10 @@ protected: ASSERT_NE(nullptr, system_bus); g_dbus_connection_set_exit_on_close(system_bus, FALSE); g_object_add_weak_pointer(G_OBJECT(system_bus), (gpointer *)&system_bus); - - notify_init(APP_NAME); } virtual void TearDown() { - notify_uninit(); - g_clear_object(&screen_mock); g_clear_object(&powerd_mock); g_clear_object(¬ify_mock); @@ -291,10 +316,8 @@ TEST_F(SnapFixture, InteractiveDuration) static constexpr int duration_minutes = 120; auto settings = std::make_shared(); settings->alarm_duration.set(duration_minutes); - auto timezones = std::make_shared(); - auto clock = std::make_shared(timezones); - - Snap snap (clock, settings); + auto ne = std::make_shared(APP_NAME); + Snap snap (ne, settings); make_interactive(); @@ -333,6 +356,7 @@ TEST_F(SnapFixture, InteractiveDuration) const auto duration = std::chrono::minutes(duration_minutes); EXPECT_EQ(std::chrono::duration_cast(duration).count(), i32); g_variant_unref(hints); + ne.reset(); } /*** @@ -341,12 +365,9 @@ TEST_F(SnapFixture, InteractiveDuration) TEST_F(SnapFixture, InhibitSleep) { - //static constexpr int duration_minutes = 120; auto settings = std::make_shared(); - //settings->alarm_duration.set(duration_minutes); - auto timezones = std::make_shared(); - auto clock = std::make_shared(timezones); - auto snap = new Snap (clock, settings); + auto ne = std::make_shared(APP_NAME); + auto snap = new Snap (ne, settings); make_interactive(); @@ -372,6 +393,7 @@ TEST_F(SnapFixture, InhibitSleep) &error)); // force-close the snap + wait_msec(100); delete snap; wait_msec(100); @@ -398,12 +420,9 @@ TEST_F(SnapFixture, InhibitSleep) TEST_F(SnapFixture, ForceScreen) { - //static constexpr int duration_minutes = 120; auto settings = std::make_shared(); - //settings->alarm_duration.set(duration_minutes); - auto timezones = std::make_shared(); - auto clock = std::make_shared(timezones); - auto snap = new Snap (clock, settings); + auto ne = std::make_shared(APP_NAME); + auto snap = new Snap (ne, settings); make_interactive(); @@ -423,6 +442,7 @@ TEST_F(SnapFixture, ForceScreen) g_assert_no_error(error); // force-close the snap + wait_msec(100); delete snap; wait_msec(100); -- cgit v1.2.3 From cbb4e95519f5127b152483b00731c260dc1a7670 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 30 Jul 2014 16:35:49 -0500 Subject: add haptic feedback to the manual tests --- tests/manual | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/manual b/tests/manual index be64863..c932004 100644 --- a/tests/manual +++ b/tests/manual @@ -30,6 +30,7 @@ Test-case indicator-datetime/new-alarm-wakeup (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)
Confirm that the screen comes on when the alarm is triggered.
+
If the device supports haptic feedback, confirm the alarm vibrates.
Test-case indicator-datetime/edited-alarm-wakeup @@ -40,6 +41,7 @@ Test-case indicator-datetime/edited-alarm-wakeup (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)
Confirm that the screen comes on when the alarm is triggered.
+
If the device supports haptic feedback, confirm the alarm vibrates.
Test-case indicator-datetime/tell-snap-decision-to-dismiss -- cgit v1.2.3 From e789710c2888b79e3abfbdcdda50d8334848ebc3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 15:25:15 -0500 Subject: add haptic feedback unit tests --- tests/test-snap.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 9a049fa..018d6f9 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -56,6 +56,8 @@ private: protected: + static constexpr char const * HAPTIC_METHOD_VIBRATE {"Vibrate"}; + static constexpr int SCREEN_COOKIE {8675309}; static constexpr char const * SCREEN_METHOD_KEEP_DISPLAY_ON {"keepDisplayOn"}; static constexpr char const * SCREEN_METHOD_REMOVE_DISPLAY_ON_REQUEST {"removeDisplayOnRequest"}; @@ -88,9 +90,11 @@ protected: DbusTestDbusMock * notify_mock = nullptr; DbusTestDbusMock * powerd_mock = nullptr; DbusTestDbusMock * screen_mock = nullptr; + DbusTestDbusMock * haptic_mock = nullptr; DbusTestDbusMockObject * notify_obj = nullptr; DbusTestDbusMockObject * powerd_obj = nullptr; DbusTestDbusMockObject * screen_obj = nullptr; + DbusTestDbusMockObject * haptic_obj = nullptr; void SetUp() { @@ -235,9 +239,28 @@ protected: "", &error); g_assert_no_error (error); - dbus_test_service_add_task(service, DBUS_TEST_TASK(screen_mock)); + /// + /// Add the haptic mock + /// + + haptic_mock = dbus_test_dbus_mock_new(BUS_HAPTIC_NAME); + haptic_obj = dbus_test_dbus_mock_get_object(haptic_mock, + BUS_HAPTIC_PATH, + BUS_HAPTIC_INTERFACE, + &error); + + dbus_test_dbus_mock_object_add_method(haptic_mock, + haptic_obj, + HAPTIC_METHOD_VIBRATE, + G_VARIANT_TYPE("(u)"), + nullptr, + "", + &error); + g_assert_no_error (error); + dbus_test_service_add_task(service, DBUS_TEST_TASK(haptic_mock)); + // start 'em up. // make the system bus work off the mock bus too, since that's @@ -259,6 +282,7 @@ protected: virtual void TearDown() { + g_clear_object(&haptic_mock); g_clear_object(&screen_mock); g_clear_object(&powerd_mock); g_clear_object(¬ify_mock); @@ -392,6 +416,13 @@ TEST_F(SnapFixture, InhibitSleep) nullptr, &error)); + // confirm that haptic feedback got called + EXPECT_TRUE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, + haptic_obj, + HAPTIC_METHOD_VIBRATE, + nullptr, + &error)); + // force-close the snap wait_msec(100); delete snap; -- cgit v1.2.3 From 43e0fb826aa3a5acfd8937438989231804b4c400 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 16:25:26 -0500 Subject: in haptic.cpp, better support for vibration patterns --- src/haptic.cpp | 57 ++++++++++++++++++++++++++++++++++++++++------------- tests/test-snap.cpp | 8 ++++---- 2 files changed, 47 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/src/haptic.cpp b/src/haptic.cpp index 2b1ee21..a27c334 100644 --- a/src/haptic.cpp +++ b/src/haptic.cpp @@ -22,6 +22,8 @@ #include +#include + namespace unity { namespace indicator { namespace notifications { @@ -81,38 +83,65 @@ private: void start_vibrating() { - /* We only support one vibrate mode for now: an on/off pulse at - one-second intervals. So set a looping 2-second timer that asks - the phone to vibrate for one second. */ - m_tag = g_timeout_add_seconds (2, on_timeout, this); + g_return_if_fail (m_tag == 0); + + switch (m_mode) + { + case MODE_PULSE: // the only mode currently supported... :) + // one second on, one second off. + m_vibrate_pattern_msec = std::vector({1000, 1000}); + break; + } + + // Set up a loop so that the pattern keeps repeating. + // NB: VibratePattern takes a repeat arg, but we avoid it because + // there's no way to cancel a pattern once it's started... + // The phone would keep vibrating long after the alarm was dismissed! + // So we stick to a short pattern and handle the repeat loop manually. + guint interval_msec = 0; + for (const auto& msec : m_vibrate_pattern_msec) + interval_msec += msec; + m_tag = g_timeout_add (interval_msec, on_timeout, this); on_timeout (this); } static gboolean on_timeout (gpointer gself) { - static_cast(gself)->vibrate_now(); - return G_SOURCE_CONTINUE; - } - - void vibrate_now() - { - g_dbus_connection_call (m_bus, + auto self = static_cast(gself); + + // build the pattern array of uint32s + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + for (const auto& msec : self->m_vibrate_pattern_msec) + g_variant_builder_add_value (&builder, g_variant_new_uint32(msec)); + auto pattern_array = g_variant_builder_end (&builder); + + // build the argument list + g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&builder, pattern_array); + g_variant_builder_add_value (&builder, g_variant_new_uint32(1u)); + auto args = g_variant_builder_end (&builder); + + g_dbus_connection_call (self->m_bus, BUS_HAPTIC_NAME, BUS_HAPTIC_PATH, BUS_HAPTIC_INTERFACE, - "Vibrate", - g_variant_new("(u)", 1000u), + "VibratePattern", + args, nullptr, G_DBUS_CALL_FLAGS_NONE, -1, - m_cancellable, + self->m_cancellable, nullptr, nullptr); + + return G_SOURCE_CONTINUE; } const Mode m_mode; GCancellable * m_cancellable = nullptr; GDBusConnection * m_bus = nullptr; + std::vector m_vibrate_pattern_msec; guint m_tag = 0; }; diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 018d6f9..06e0a80 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -56,7 +56,7 @@ private: protected: - static constexpr char const * HAPTIC_METHOD_VIBRATE {"Vibrate"}; + static constexpr char const * HAPTIC_METHOD_VIBRATE_PATTERN {"VibratePattern"}; static constexpr int SCREEN_COOKIE {8675309}; static constexpr char const * SCREEN_METHOD_KEEP_DISPLAY_ON {"keepDisplayOn"}; @@ -253,8 +253,8 @@ protected: dbus_test_dbus_mock_object_add_method(haptic_mock, haptic_obj, - HAPTIC_METHOD_VIBRATE, - G_VARIANT_TYPE("(u)"), + HAPTIC_METHOD_VIBRATE_PATTERN, + G_VARIANT_TYPE("(auu)"), nullptr, "", &error); @@ -419,7 +419,7 @@ TEST_F(SnapFixture, InhibitSleep) // confirm that haptic feedback got called EXPECT_TRUE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, haptic_obj, - HAPTIC_METHOD_VIBRATE, + HAPTIC_METHOD_VIBRATE_PATTERN, nullptr, &error)); -- cgit v1.2.3 From 4148750ea93e67e5d9aaa15ebc8e3c7a5a5554f1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 16:48:00 -0500 Subject: configurable haptic mode, part 1 of 3: add haptic feedback mode to the GSettings schema and to our Settings object --- data/com.canonical.indicator.datetime.gschema.xml.in | 8 ++++++++ include/datetime/settings-live.h | 1 + include/datetime/settings-shared.h | 1 + include/datetime/settings.h | 1 + src/settings-live.cpp | 14 ++++++++++++++ tests/test-settings.cpp | 1 + 6 files changed, 26 insertions(+) (limited to 'tests') diff --git a/data/com.canonical.indicator.datetime.gschema.xml.in b/data/com.canonical.indicator.datetime.gschema.xml.in index 62b42c1..4e4acd8 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml.in +++ b/data/com.canonical.indicator.datetime.gschema.xml.in @@ -123,6 +123,14 @@ Some timezones can be known by many different cities or names. This setting describes how the current zone prefers to be named. Format is "TIMEZONE NAME" (e.g. "America/New_York Boston" to name the New_York zone Boston). + + 'pulse' + <_summary>What kind of haptic feedback, if any, to trigger with an alarm. + <_description> + What kind of haptic feedback, if any, to trigger with an alarm. + Two modes are currently supported: 'pulse', 'none'. + + '/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg' <_summary>The alarm's default sound file. diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 4db2d40..4850e69 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -58,6 +58,7 @@ private: void update_alarm_sound(); void update_alarm_volume(); void update_alarm_duration(); + void update_alarm_haptic(); GSettings* m_settings; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index 23d2e1c..a211821 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -48,5 +48,6 @@ TimeFormatMode; #define SETTINGS_ALARM_SOUND_S "alarm-default-sound" #define SETTINGS_ALARM_VOLUME_S "alarm-default-volume" #define SETTINGS_ALARM_DURATION_S "alarm-duration-minutes" +#define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" #endif // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h index e5f885e..c6fe13b 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -57,6 +57,7 @@ public: core::Property time_format_mode; core::Property timezone_name; core::Property alarm_sound; + core::Property alarm_haptic; core::Property alarm_volume; core::Property alarm_duration; }; diff --git a/src/settings-live.cpp b/src/settings-live.cpp index 71bbd96..a8338ed 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -55,6 +55,7 @@ LiveSettings::LiveSettings(): update_alarm_sound(); update_alarm_volume(); update_alarm_duration(); + update_alarm_haptic(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -130,6 +131,10 @@ LiveSettings::LiveSettings(): alarm_duration.changed().connect([this](unsigned int value){ g_settings_set_uint(m_settings, SETTINGS_ALARM_DURATION_S, value); }); + + alarm_haptic.changed().connect([this](const std::string& value){ + g_settings_set_string(m_settings, SETTINGS_ALARM_HAPTIC_S, value.c_str()); + }); } /*** @@ -237,6 +242,13 @@ void LiveSettings::update_alarm_duration() alarm_duration.set(g_settings_get_uint(m_settings, SETTINGS_ALARM_DURATION_S)); } +void LiveSettings::update_alarm_haptic() +{ + auto val = g_settings_get_string(m_settings, SETTINGS_ALARM_HAPTIC_S); + alarm_haptic.set(val); + g_free(val); +} + /*** **** ***/ @@ -284,6 +296,8 @@ void LiveSettings::update_key(const std::string& key) update_alarm_volume(); else if (key == SETTINGS_ALARM_DURATION_S) update_alarm_duration(); + else if (key == SETTINGS_ALARM_HAPTIC_S) + update_alarm_haptic(); } /*** diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 44a0252..4fb0a08 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -159,6 +159,7 @@ TEST_F(SettingsFixture, StringProperties) TestStringProperty(m_settings->custom_time_format, SETTINGS_CUSTOM_TIME_FORMAT_S); TestStringProperty(m_settings->timezone_name, SETTINGS_TIMEZONE_NAME_S); TestStringProperty(m_settings->alarm_sound, SETTINGS_ALARM_SOUND_S); + TestStringProperty(m_settings->alarm_haptic, SETTINGS_ALARM_HAPTIC_S); } TEST_F(SettingsFixture, TimeFormatMode) -- cgit v1.2.3 From 8afa4ba3102138f245fba704eba03b907edefa2b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 17:06:50 -0500 Subject: configurable haptic mode, part 2 of 3: use the new haptic mode setting when popping up notifications; sync notification tests --- src/snap.cpp | 5 ++++- tests/test-snap.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/src/snap.cpp b/src/snap.cpp index beefa94..0b2322a 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -78,7 +78,10 @@ public: auto sound = std::make_shared(uri, volume, loop); // create the haptic feedback... - auto haptic = std::make_shared(); + const auto haptic_mode = m_settings->alarm_haptic.get(); + std::shared_ptr haptic; + if (haptic_mode == "pulse") + haptic = std::make_shared(uin::Haptic::MODE_PULSE); // show a notification... const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get()); diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 06e0a80..5afaab1 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -416,13 +416,6 @@ TEST_F(SnapFixture, InhibitSleep) nullptr, &error)); - // confirm that haptic feedback got called - EXPECT_TRUE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, - haptic_obj, - HAPTIC_METHOD_VIBRATE_PATTERN, - nullptr, - &error)); - // force-close the snap wait_msec(100); delete snap; @@ -485,3 +478,45 @@ TEST_F(SnapFixture, ForceScreen) &error)); g_assert_no_error(error); } + +/*** +**** +***/ + +TEST_F(SnapFixture, HapticModes) +{ + auto settings = std::make_shared(); + auto ne = std::make_shared(APP_NAME); + auto func = [this](const Appointment&){g_idle_add(quit_idle, loop);}; + GError * error = nullptr; + + // invoke a snap decision while haptic feedback is set to "pulse", + // confirm that VibratePattern got called + settings->alarm_haptic.set("pulse"); + auto snap = new Snap (ne, settings); + (*snap)(appt, func, func); + wait_msec(100); + EXPECT_TRUE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, + haptic_obj, + HAPTIC_METHOD_VIBRATE_PATTERN, + nullptr, + &error)); + delete snap; + + // invoke a snap decision while haptic feedback is set to "none", + // confirm that VibratePattern =didn't= get called + wait_msec(100); + dbus_test_dbus_mock_object_clear_method_calls (haptic_mock, haptic_obj, &error); + settings->alarm_haptic.set("none"); + snap = new Snap (ne, settings); + (*snap)(appt, func, func); + wait_msec(100); + EXPECT_FALSE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, + haptic_obj, + HAPTIC_METHOD_VIBRATE_PATTERN, + nullptr, + &error)); + delete snap; + + g_assert_no_error (error); +} -- cgit v1.2.3 From 56d881413ffaa171d4367bb968f5454988e2737e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 31 Jul 2014 17:17:53 -0500 Subject: configurable haptic mode, part 3 of 3: expose the new haptic mode setting as a DBus property; sync exporter tests --- data/com.canonical.indicator.datetime.AlarmProperties.xml | 9 +++++++++ src/exporter.cpp | 1 + tests/test-exporter.cpp | 12 ++++++++++++ 3 files changed, 22 insertions(+) (limited to 'tests') diff --git a/data/com.canonical.indicator.datetime.AlarmProperties.xml b/data/com.canonical.indicator.datetime.AlarmProperties.xml index d25fa82..9b38af9 100644 --- a/data/com.canonical.indicator.datetime.AlarmProperties.xml +++ b/data/com.canonical.indicator.datetime.AlarmProperties.xml @@ -11,6 +11,15 @@ + + + + What kind of haptic feedback, if any, to trigger with an alarm. + Two modes are currently supported: 'pulse', 'none'. + + + + diff --git a/src/exporter.cpp b/src/exporter.cpp index 88aee2f..1d45705 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -144,6 +144,7 @@ private: bind_uint_property(m_alarm_props, "duration", m_settings->alarm_duration); bind_uint_property(m_alarm_props, "default-volume", m_settings->alarm_volume); bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound); + bind_string_property(m_alarm_props, "haptic-feedback", m_settings->alarm_haptic); } /*** diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index 2e3411a..96665cf 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -186,26 +186,35 @@ TEST_F(ExporterFixture, AlarmProperties) auto expected_volume = 1; int expected_duration = 60; const char * expected_sound = "/tmp/foo.wav"; + const char * expected_haptic = "pulse"; settings->alarm_volume.set(expected_volume); settings->alarm_duration.set(expected_duration); settings->alarm_sound.set(expected_sound); + settings->alarm_haptic.set(expected_haptic); wait_msec(); static constexpr const char* const SOUND_PROP {"default-sound"}; static constexpr const char* const VOLUME_PROP {"default-volume"}; static constexpr const char* const DURATION_PROP {"duration"}; + static constexpr const char* const HAPTIC_PROP {"haptic-feedback"}; char* sound = nullptr; + char* haptic = nullptr; int volume = -1; int duration = -1; g_object_get(proxy, SOUND_PROP, &sound, + HAPTIC_PROP, &haptic, VOLUME_PROP, &volume, DURATION_PROP, &duration, nullptr); EXPECT_STREQ(expected_sound, sound); + EXPECT_STREQ(expected_haptic, haptic); EXPECT_EQ(expected_volume, volume); EXPECT_EQ(expected_duration, duration); + g_clear_pointer (&sound, g_free); + g_clear_pointer (&haptic, g_free); + /*** **** Try chaning the DBus properties -- do the Settings change to match it? ***/ @@ -213,13 +222,16 @@ TEST_F(ExporterFixture, AlarmProperties) expected_volume = 100; expected_duration = 30; expected_sound = "/tmp/bar.wav"; + expected_haptic = "none"; g_object_set(proxy, SOUND_PROP, expected_sound, + HAPTIC_PROP, expected_haptic, VOLUME_PROP, expected_volume, DURATION_PROP, expected_duration, nullptr); wait_msec(); EXPECT_STREQ(expected_sound, settings->alarm_sound.get().c_str()); + EXPECT_STREQ(expected_haptic, settings->alarm_haptic.get().c_str()); EXPECT_EQ(expected_volume, settings->alarm_volume.get()); EXPECT_EQ(expected_duration, settings->alarm_duration.get()); -- cgit v1.2.3