aboutsummaryrefslogtreecommitdiff
path: root/tests/test-sound.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-sound.cpp')
-rw-r--r--tests/test-sound.cpp57
1 files changed, 42 insertions, 15 deletions
diff --git a/tests/test-sound.cpp b/tests/test-sound.cpp
index f808db6..90c18eb 100644
--- a/tests/test-sound.cpp
+++ b/tests/test-sound.cpp
@@ -1,5 +1,6 @@
/*
* Copyright 2014-2016 Canonical Ltd.
+ * Copyright 2023 Robert Tari
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
@@ -15,6 +16,7 @@
*
* Authors:
* Charles Kerr <charles.kerr@canonical.com>
+ * Robert Tari <robert@tari.in>
*/
#include <datetime/appointment.h>
@@ -44,13 +46,17 @@ namespace
g_main_loop_quit(static_cast<GMainLoop*>(gloop));
return G_SOURCE_REMOVE;
};
+
+ class SoundNotificationFixture : public NotificationFixture
+ {
+ };
}
/***
****
***/
-TEST_F(NotificationFixture, InteractiveDuration)
+TEST_F(SoundNotificationFixture, InteractiveDuration)
{
static constexpr int duration_minutes = 120;
auto settings = std::make_shared<Settings>();
@@ -65,7 +71,12 @@ TEST_F(NotificationFixture, InteractiveDuration)
settings->cal_notification_bubbles.set(true);
settings->cal_notification_list.set(true);
- make_interactive();
+#ifdef LOMIRI_FEATURES_ENABLED
+ /* Here both values true|false should succeed. */
+ mock_capabilities(true);
+#else
+ mock_capabilities(false);
+#endif
// call the Snap Decision
auto func = [this](const Appointment&, const Alarm&, const Snap::Response&){g_idle_add(quit_idle, loop);};
@@ -89,19 +100,30 @@ TEST_F(NotificationFixture, InteractiveDuration)
g_variant_get_child (params, 0, "&s", &str);
ASSERT_STREQ(APP_NAME, str);
- // confirm that the icon passed to Notify was "alarm-clock"
+ // confirm that the icon passed to Notify was "calendar-app"
g_variant_get_child (params, 2, "&s", &str);
ASSERT_STREQ("calendar-app", str);
- // confirm that the hints passed to Notify included a timeout matching duration_minutes
+ // confirm that the timeout passed to Notify matches duration_minutes
int32_t i32;
- bool b;
- auto hints = g_variant_get_child_value (params, 6);
- b = g_variant_lookup (hints, HINT_TIMEOUT, "i", &i32);
- EXPECT_TRUE(b);
+ g_variant_get_child (params, 7, "i", &i32);
const auto duration = std::chrono::minutes(duration_minutes);
EXPECT_EQ(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(), i32);
- g_variant_unref(hints);
+
+#ifdef LOMIRI_FEATURES_ENABLED
+ /* If setting mock_capabilities to false, set the below to false, as well. */
+ if (true) {
+ // 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<std::chrono::milliseconds>(duration).count(), i32);
+ g_variant_unref(hints);
+ }
+#endif
+
ne.reset();
}
@@ -139,12 +161,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;
}
@@ -167,9 +194,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);