aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-01-31 19:08:17 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-01-31 19:08:17 +0100
commit2a2db70bedf0c4a96282e417be433d2f23f6c465 (patch)
treefebd31ea544a376d1fd04c0e830463d31d028dd9 /tests
parentd8debd706fe92de09e5c654c4ea2cc5dd5ce0529 (diff)
parent30b2de458752ad0855b508eb2f8ffeee85628cea (diff)
downloadayatana-indicator-datetime-2a2db70bedf0c4a96282e417be433d2f23f6c465.tar.gz
ayatana-indicator-datetime-2a2db70bedf0c4a96282e417be433d2f23f6c465.tar.bz2
ayatana-indicator-datetime-2a2db70bedf0c4a96282e417be433d2f23f6c465.zip
Merge branch 'personal/peat-psuwit/bring-back-lomiri-hints'
Attributes GH PR #115: https://github.com/AyatanaIndicators/ayatana-indicator-datetime/pull/115
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt22
-rw-r--r--tests/notification-fixture.h23
-rw-r--r--tests/test-notification-response.cpp2
-rw-r--r--tests/test-sound.cpp53
4 files changed, 73 insertions, 27 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a0687f4..60e7864 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -42,13 +42,9 @@ function(add_test_by_name name)
target_link_libraries (${TEST_NAME} indicatordatetimeservice ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES})
endfunction()
add_test_by_name(test-datetime)
-
-if (ENABLE_LOMIRI_FEATURES)
- add_test_by_name(test-sound)
- add_test_by_name(test-notification)
- add_test_by_name(test-notification-response)
-endif()
-
+add_test_by_name(test-sound)
+add_test_by_name(test-notification)
+add_test_by_name(test-notification-response)
add_test_by_name(test-actions)
add_test_by_name(test-alarm-queue)
add_test(NAME dear-reader-the-next-test-takes-60-seconds COMMAND true)
@@ -64,13 +60,11 @@ add_test_by_name(test-settings)
add_test_by_name(test-timezone-timedated)
add_test_by_name(test-utils)
-if (ENABLE_LOMIRI_FEATURES)
- set (TEST_NAME manual-test-snap)
- set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME})
- add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
- target_link_options(${TEST_NAME} PRIVATE -no-pie)
- target_link_libraries (${TEST_NAME} indicatordatetimeservice ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES})
-endif()
+set (TEST_NAME manual-test-snap)
+set (COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME})
+add_executable (${TEST_NAME} ${TEST_NAME}.cpp)
+target_link_options(${TEST_NAME} PRIVATE -no-pie)
+target_link_libraries (${TEST_NAME} indicatordatetimeservice ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES})
##
## EDS Tests
diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h
index 33bcd7e..5aedadc 100644
--- a/tests/notification-fixture.h
+++ b/tests/notification-fixture.h
@@ -77,6 +77,10 @@ protected:
static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"};
+#ifdef LOMIRI_FEATURES_ENABLED
+ static constexpr char const * HINT_LOMIRI_TIMEOUT {"x-lomiri-snap-decisions-timeout"};
+#endif
+
static constexpr char const * AS_BUSNAME {"org.freedesktop.Accounts"};
static constexpr char const * AS_INTERFACE {"com.lomiri.touch.AccountsService.Sound"};
static constexpr char const * PROP_OTHER_VIBRATIONS {"OtherVibrate"};
@@ -310,20 +314,31 @@ protected:
super::TearDown();
}
- void make_interactive()
+ void mock_capabilities(bool mock_lomiri_caps = false)
{
// GetCapabilities returns an array containing 'actions',
// so our notifications will be interactive.
- // For this test, it means we should get an expire_timeout
- // that matches duration_minutes
+
+ #ifndef LOMIRI_FEATURES_ENABLED
+ g_assert_false(mock_lomiri_caps);
+ #endif
+
+ std::string python_code =
+ std::string("ret = ['actions', 'body'") +
+ #ifdef LOMIRI_FEATURES_ENABLED
+ (mock_lomiri_caps ? std::string(", '") + HINT_LOMIRI_TIMEOUT + "'" : "") +
+ #endif
+ "]";
+
GError * error = nullptr;
dbus_test_dbus_mock_object_add_method(notify_mock,
notify_obj,
METHOD_GET_CAPS,
nullptr,
G_VARIANT_TYPE_STRING_ARRAY,
- "ret = ['actions', 'body']",
+ python_code.c_str(),
&error);
+
g_assert_no_error (error);
}
diff --git a/tests/test-notification-response.cpp b/tests/test-notification-response.cpp
index fd40ed8..d3e9c00 100644
--- a/tests/test-notification-response.cpp
+++ b/tests/test-notification-response.cpp
@@ -47,7 +47,7 @@ namespace
TEST_F(NotificationFixture,Response)
{
// create the world
- make_interactive();
+ mock_capabilities();
auto ne = std::make_shared<ayatana::indicator::notifications::Engine>(APP_NAME);
auto sb = std::make_shared<ayatana::indicator::notifications::DefaultSoundBuilder>();
auto settings = std::make_shared<Settings>();
diff --git a/tests/test-sound.cpp b/tests/test-sound.cpp
index 19dffe3..eaf76ac 100644
--- a/tests/test-sound.cpp
+++ b/tests/test-sound.cpp
@@ -46,13 +46,22 @@ namespace
g_main_loop_quit(static_cast<GMainLoop*>(gloop));
return G_SOURCE_REMOVE;
};
+
+ class SoundNotificationFixture : public NotificationFixture,
+ public testing::WithParamInterface<bool>
+ {
+ public:
+ bool IsLomiri() {
+ return GetParam();
+ }
+ };
}
/***
****
***/
-TEST_F(NotificationFixture, InteractiveDuration)
+TEST_P(SoundNotificationFixture, InteractiveDuration)
{
static constexpr int duration_minutes = 120;
auto settings = std::make_shared<Settings>();
@@ -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);};
@@ -100,9 +109,32 @@ TEST_F(NotificationFixture, InteractiveDuration)
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);
+
+#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<std::chrono::milliseconds>(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
+ ));
+
/***
****
***/
@@ -137,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;
}
@@ -165,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);