From 30b2de458752ad0855b508eb2f8ffeee85628cea Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Thu, 21 Dec 2023 19:16:35 +0700 Subject: src, tests: enable notification code path without Lomiri deps With the recent change, the notification code path is no longer Lomiri (or Ubuntu Touch) specific. Theres still some if-def's in the code to avoid adding dependendies in non-Lomiri case. --- tests/test-sound.cpp | 59 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 16 deletions(-) (limited to 'tests/test-sound.cpp') diff --git a/tests/test-sound.cpp b/tests/test-sound.cpp index db1402a..eaf76ac 100644 --- a/tests/test-sound.cpp +++ b/tests/test-sound.cpp @@ -46,13 +46,22 @@ namespace g_main_loop_quit(static_cast(gloop)); return G_SOURCE_REMOVE; }; + + class SoundNotificationFixture : public NotificationFixture, + public testing::WithParamInterface + { + public: + bool IsLomiri() { + return GetParam(); + } + }; } /*** **** ***/ -TEST_F(NotificationFixture, InteractiveDuration) +TEST_P(SoundNotificationFixture, InteractiveDuration) { static constexpr int duration_minutes = 120; auto settings = std::make_shared(); @@ -67,7 +76,7 @@ TEST_F(NotificationFixture, InteractiveDuration) settings->cal_notification_bubbles.set(true); settings->cal_notification_list.set(true); - make_interactive(); + mock_capabilities(IsLomiri()); // call the Snap Decision auto func = [this](const Appointment&, const Alarm&, const Snap::Response&){g_idle_add(quit_idle, loop);}; @@ -101,18 +110,31 @@ TEST_F(NotificationFixture, InteractiveDuration) const auto duration = std::chrono::minutes(duration_minutes); EXPECT_EQ(std::chrono::duration_cast(duration).count(), i32); - // Due to custom logic in Lomiri, also make sure custom timeout hint is set. - bool b; - auto hints = g_variant_get_child_value (params, 6); - i32 = 0; - b = g_variant_lookup (hints, HINT_LOMIRI_TIMEOUT, "i", &i32); - EXPECT_TRUE(b); - EXPECT_EQ(std::chrono::duration_cast(duration).count(), i32); - g_variant_unref(hints); +#ifdef LOMIRI_FEATURES_ENABLED + if (IsLomiri()) { + // Due to custom logic in Lomiri, also make sure custom timeout hint is set. + bool b; + auto hints = g_variant_get_child_value (params, 6); + i32 = 0; + b = g_variant_lookup (hints, HINT_LOMIRI_TIMEOUT, "i", &i32); + EXPECT_TRUE(b); + EXPECT_EQ(std::chrono::duration_cast(duration).count(), i32); + g_variant_unref(hints); + } +#endif ne.reset(); } +INSTANTIATE_TEST_SUITE_P(SoundNotificationTest, + SoundNotificationFixture, + testing::Values( +#ifdef LOMIRI_FEATURES_ENABLED + true, +#endif + false + )); + /*** **** ***/ @@ -147,12 +169,17 @@ private: uin::DefaultSoundBuilder m_impl; }; -std::string path_to_uri(const std::string& path) +std::string path_to_uri_if_exists(const std::string& path) { + std::string uri; auto file = g_file_new_for_path(path.c_str()); - auto uri_cstr = g_file_get_uri(file); - std::string uri = uri_cstr; - g_free(uri_cstr); + + if (g_file_query_exists(file, /* cancellable */ nullptr)) { + auto uri_cstr = g_file_get_uri(file); + uri = std::string(uri_cstr); + g_free(uri_cstr); + } + g_clear_pointer(&file, g_object_unref); return uri; } @@ -175,9 +202,9 @@ TEST_F(NotificationFixture,DefaultSounds) std::string expected_role; std::string expected_uri; } test_cases[] = { - { ualarm, "alarm", path_to_uri(ALARM_DEFAULT_SOUND) } + { ualarm, "alarm", path_to_uri_if_exists(ALARM_DEFAULT_SOUND) } // No sound for appointments - // { appt, "alert", path_to_uri(CALENDAR_DEFAULT_SOUND) } + // { appt, "alert", path_to_uri_if_exists(CALENDAR_DEFAULT_SOUND) } }; auto snap = create_snap(ne, sb, settings); -- cgit v1.2.3