diff options
Diffstat (limited to 'tests')
31 files changed, 527 insertions, 418 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 52f5d61..13dd0d8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,5 @@ find_package(GMock REQUIRED) -SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${COMPILE_FLAGS}") - # dbustest pkg_check_modules(DBUSTEST REQUIRED dbustest-1>=14.04.0) @@ -41,44 +39,37 @@ function(add_test_by_name name) add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) target_link_options(${TEST_NAME} PRIVATE -no-pie) add_test (${TEST_NAME} ${TEST_NAME}) - target_link_libraries (${TEST_NAME} indicatordatetimeservice ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ${URLDISPATCHER_LIBRARIES}) + target_link_libraries (${TEST_NAME} indicatordatetimeservice ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) endfunction() + add_test_by_name(test-datetime) -if(HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS) - add_test_by_name(test-sound) +add_test_by_name(test-sound) + +if (ENABLE_LOMIRI_FEATURES) add_test_by_name(test-notification) - add_test_by_name(test-notification-response) -endif() +endif () + +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) add_test_by_name(test-clock) - -if (NOT DEFINED ENV{CI}) - #add_test_by_name(test-exporter) -endif() - +add_test_by_name(test-exporter) add_test_by_name(test-formatter) add_test_by_name(test-live-actions) add_test_by_name(test-locations) add_test_by_name(test-menu-appointments) - -if (NOT DEFINED ENV{CI}) - #add_test_by_name(test-menus) -endif() - +add_test_by_name(test-menus) add_test_by_name(test-planner) add_test_by_name(test-settings) add_test_by_name(test-timezone-timedated) add_test_by_name(test-utils) -if(HAVE_UT_ACCTSERVICE_SYSTEMSOUND_SETTINGS) - 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} ${URLDISPATCHER_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 @@ -113,6 +104,7 @@ add_eds_ics_test_by_name(test-eds-ics-tzids-2) add_eds_ics_test_by_name(test-eds-ics-tzids-utc) add_eds_ics_test_by_name(test-eds-ics-non-attending-alarms) add_eds_ics_test_by_name(test-eds-ics-repeating-events-with-individual-change) +add_eds_ics_test_by_name(test-eds-ics-alarm-custom-sound) function(add_dbusmock_test_by_name name) set (TEST_NAME ${name}) diff --git a/tests/manual b/tests/manual index 3294699..cafc292 100644 --- a/tests/manual +++ b/tests/manual @@ -1,25 +1,25 @@ -Test-case ayatana-indicator-datetime/unity7-items-check +Test-case ayatana-indicator-datetime/mate-items-check <dl> - <dt>Log in to a Unity 7 user session</dt> - <dt>Go to the panel and click on the DateTime indicator</dt> - <dd>Ensure there are items in the menu</dd> + <dt>Log in to a desktop user session</dt> + <dt>Go to the panel and click on the DateTime indicator</dt> + <dd>Ensure there are items in the menu</dd> </dl> -Test-case ayatana-indicator-datetime/unity7-greeter-items-check +Test-case ayatana-indicator-datetime/arctica-greeter-items-check <dl> - <dt>Start a system and wait for the greeter or logout of the current user session</dt> - <dt>Go to the panel and click on the DateTime indicator</dt> - <dd>Ensure there are items in the menu</dd> + <dt>Start a system and wait for the greeter or logout of the current user session</dt> + <dt>Go to the panel and click on the DateTime indicator</dt> + <dd>Ensure there are items in the menu</dd> </dl> -Test-case ayatana-indicator-datetime/unity8-items-check +Test-case ayatana-indicator-datetime/lomiri-items-check <dl> - <dt>Login to a user session running Unity 8</dt> - <dt>Pull down the top panel until it sticks open</dt> - <dt>Navigate through the tabs until "Time and Date" is shown</dt> - <dd>Upcoming is at the top of the menu</dd> - <dd>The menu is populated with items</dd> + <dt>Login to a user session running Lomiri</dt> + <dt>Pull down the top panel until it sticks open</dt> + <dt>Navigate through the tabs until "Time and Date" is shown</dt> + <dd>Upcoming is at the top of the menu</dd> + <dd>The menu is populated with items</dd> </dl> Test-case ayatana-indicator-datetime/timestamp-wakeup @@ -31,116 +31,116 @@ Test-case ayatana-indicator-datetime/timestamp-wakeup Test-case ayatana-indicator-datetime/new-alarm-wakeup <dl> - <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt> - <dt>Unplug the phone from any USB connection and put it to sleep</dt> - <dd>Confirm that the alarm sounds on time even if the phone is asleep. (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)</dd> - <dd>Confirm that the screen comes on when the alarm is triggered.<dd> - <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd> + <dt>Create and save an upcoming alarm in lomiri-clock-app</dt> + <dt>Unplug the phone from any USB connection and put it to sleep</dt> + <dd>Confirm that the alarm sounds on time even if the phone is asleep. (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)</dd> + <dd>Confirm that the screen comes on when the alarm is triggered.<dd> + <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd> </dl> Test-case ayatana-indicator-datetime/disabled-alarms <dl> - <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt> - <dd>Confirm that the alarm icon appears next to the current time in unity's indicator display</dd> - <dt>Disable the alarm in ubuntu-clock-app</dt> - <dd>When all alarms are disabled or removed, the alarm icon should disappear.</dd> - <dt>Re-enable the alarm in ubuntu-clock-app</dt> - <dd>When the alarm is enabled, the alarm icon should reappear.</dd> + <dt>Create and save an upcoming alarm in lomiri-clock-app</dt> + <dd>Confirm that the alarm icon appears next to the current time in Lomiri's indicator display</dd> + <dt>Disable the alarm in lomiri-clock-app</dt> + <dd>When all alarms are disabled or removed, the alarm icon should disappear.</dd> + <dt>Re-enable the alarm in lomiri-clock-app</dt> + <dd>When the alarm is enabled, the alarm icon should reappear.</dd> </dl> Test-case ayatana-indicator-datetime/disable-one-time-alarms-after-notification <dl> - <dt>Create and save an upcoming nonrepeating alarm in ubuntu-clock-app</dt> - <dd>Confirm that the alarm icon appears next to the current time in unity's indicator display</dd> - <dt>Wait until the alarm time is reached</dt> - <dd>Confirm that the alarm notification is shown</dd> - <dd>Confirm that the alarm's sound is played while the alarm notification is present</dd> - <dd>Confirm that the one-time alarm is disabled after the notification is shown. NOTE: due to a refresh bug in clock-app you may need to refresh its alarms page (by swapping back to the main page, then the alarm page again, this is tracked in #1362341) in order to see the alarm change from enabled to disabled.</dd> - <dt>Create and save an upcoming repeating alarm in ubuntu-clock-app</dt> - <dd>Confirm that the alarm icon appears next to the current time in unity's indicator display</dd> - <dt>Wait until the alarm time is reached</dt> - <dd>Confirm that the alarm notification is shown</dd> - <dd>Confirm that the alarm's sound is played while the alarm notification is present</dd> - <dd>Confirm that the repeating alarm is not disabled after the notification is shown. NOTE: due to a refresh bug in clock-app you may need to refresh its alarms page (by swapping back to the main page, then the alarm page again, this is tracked in #1362341) in order to see the alarm change from enabled to disabled.</dd> + <dt>Create and save an upcoming nonrepeating alarm in lomiri-clock-app</dt> + <dd>Confirm that the alarm icon appears next to the current time in Lomiri's indicator display</dd> + <dt>Wait until the alarm time is reached</dt> + <dd>Confirm that the alarm notification is shown</dd> + <dd>Confirm that the alarm's sound is played while the alarm notification is present</dd> + <dd>Confirm that the one-time alarm is disabled after the notification is shown. NOTE: due to a refresh bug in clock-app you may need to refresh its alarms page (by swapping back to the main page, then the alarm page again, this is tracked in #1362341) in order to see the alarm change from enabled to disabled.</dd> + <dt>Create and save an upcoming repeating alarm in lomiri-clock-app</dt> + <dd>Confirm that the alarm icon appears next to the current time in Lomiri's indicator display</dd> + <dt>Wait until the alarm time is reached</dt> + <dd>Confirm that the alarm notification is shown</dd> + <dd>Confirm that the alarm's sound is played while the alarm notification is present</dd> + <dd>Confirm that the repeating alarm is not disabled after the notification is shown. NOTE: due to a refresh bug in clock-app you may need to refresh its alarms page (by swapping back to the main page, then the alarm page again, this is tracked in #1362341) in order to see the alarm change from enabled to disabled.</dd> </dl> Test-case ayatana-indicator-datetime/calendar-event-notification <dl> - <dt>In the calendar app, create and save a new upcoming calendar event that will occur in the next few minutes.</dt> - <dd>The datetime indicator's event list should update itself to show this new event.</dd> - <dd>Calendar events do not get the alarm icon, so no alarm icon should be shown in the header unless there is also an upcoming alarm set.</dd> - <dt>Wait for the event's time to be reached</dt> - <dd>The datetime indicator should pop up a non-interactive notification that plays a nonlooping sound.</dd> - <dd>The notification should disappear after a moment without requiring user intervention.</dd> + <dt>In the calendar app, create and save a new upcoming calendar event that will occur in the next few minutes.</dt> + <dd>The datetime indicator's event list should update itself to show this new event.</dd> + <dd>Calendar events do not get the alarm icon, so no alarm icon should be shown in the header unless there is also an upcoming alarm set.</dd> + <dt>Wait for the event's time to be reached</dt> + <dd>The datetime indicator should pop up a non-interactive notification that plays a nonlooping sound.</dd> + <dd>The notification should disappear after a moment without requiring user intervention.</dd> </dl> Test-case ayatana-indicator-datetime/alarm-timezone <dl> - <dt>In ubuntu-system-settings, change your timezone to a zone you're not in</dt> - <dt>In ubuntu-clock-app, create and save an upcoming alarm</dt> - <dd>The indicator's menu should show the alarm to click at the specified time</dd> - <dt>In ubuntu-system-settings, change back to your correct timezone</dt> - <dd>The indicator's menu should still show the alarm to click at the specified time</dd> + <dt>In lomiri-system-settings, change your timezone to a zone you're not in</dt> + <dt>In lomiri-clock-app, create and save an upcoming alarm</dt> + <dd>The indicator's menu should show the alarm to click at the specified time</dd> + <dt>In lomiri-system-settings, change back to your correct timezone</dt> + <dd>The indicator's menu should still show the alarm to click at the specified time</dd> </dl> Test-case ayatana-indicator-datetime/snooze <dl> - <dt>Create and save an upcoming alarm in ubuntu-clock-app</dt> - <dt>When the alarm goes off, press the 'Snooze' button</dt> - <dd>The alarm should go away, then reappear N minutes later. By default the N is 5 minutes but will be configurable from ubuntu-clock-app.</dd> - <dt>When the snoozed alarm reappears, press the 'OK' button</dt> - <dd>This time when the alarm is dismissed, it should not reappear.</dd> + <dt>Create and save an upcoming alarm in lomiri-clock-app</dt> + <dt>When the alarm goes off, press the 'Snooze' button</dt> + <dd>The alarm should go away, then reappear N minutes later. By default the N is 5 minutes but will be configurable from lomiri-clock-app.</dd> + <dt>When the snoozed alarm reappears, press the 'OK' button</dt> + <dd>This time when the alarm is dismissed, it should not reappear.</dd> </dl> Test-case ayatana-indicator-datetime/edited-alarm-wakeup <dl> - <dt>Edit an alarm that's already passed. (see previous test)</dt> - <dt>Unplug the phone from any USB connection and put it to sleep</dt> - <dd>Confirm that the alarm sounds on time even if the phone is asleep. (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)</dd> - <dd>Confirm that the screen comes on when the alarm is triggered.<dd> - <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd> + <dt>Edit an alarm that's already passed. (see previous test)</dt> + <dt>Unplug the phone from any USB connection and put it to sleep</dt> + <dd>Confirm that the alarm sounds on time even if the phone is asleep. (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)</dd> + <dd>Confirm that the screen comes on when the alarm is triggered.<dd> + <dd>If the device supports haptic feedback, confirm the alarm vibrates.</dd> </dl> Test-case ayatana-indicator-datetime/tell-snap-decision-to-dismiss <dl> - <dt>Set an alarm and wait for it to arrive.</dt> - <dd>Alarm should go off at the specified time</dd> - <dt>Press the 'Dismiss' button in the alarm's snap decision popup before the sound stops.</dt> - <dd>Popup should disappear</dd> - <dd>Sound should stop at the same time, rather than playing til the end of the file.</dd> + <dt>Set an alarm and wait for it to arrive.</dt> + <dd>Alarm should go off at the specified time</dd> + <dt>Press the 'Dismiss' button in the alarm's snap decision popup before the sound stops.</dt> + <dd>Popup should disappear</dd> + <dd>Sound should stop at the same time, rather than playing til the end of the file.</dd> </dl> Test-case ayatana-indicator-datetime/change-alarm-sound <dl> - <dt>Open the clock app</dt> - <dt>Swipe up from the bottom</dt> - <dt>Click on the + symbol</dt> - <dt>Save an alarm for a few minutes time leave everything on default settings</dt> - <dt>Click on save</dt> - <dt>Click on the alarm</dt> - <dt>Change the sound of the alarm</dt> - <dt>Click on save</dt> - <dt>Let the alarm go off</dt> - <dd>The newly-selected sound should play, rather than the previous sound.</dd> + <dt>Open the clock app</dt> + <dt>Swipe up from the bottom</dt> + <dt>Click on the + symbol</dt> + <dt>Save an alarm for a few minutes time leave everything on default settings</dt> + <dt>Click on save</dt> + <dt>Click on the alarm</dt> + <dt>Change the sound of the alarm</dt> + <dt>Click on save</dt> + <dt>Let the alarm go off</dt> + <dd>The newly-selected sound should play, rather than the previous sound.</dd> </dl> Test-case ayatana-indicator-datetime/silent-mode <dl> - <dt>Set an alarm and wait for it to arrive.</dt> - <dt>From the sound indicator, turn on silent mode.</dt> - <dd>Alarm should go off at the specified time and play its sound regardless of silent mode.</dd> - <dt>From the sound indicator, turn on silent mode.</dt> - <dt>Create a calendar event from the calendar app and wait for it to arrive.</dt> - <dd>The calendar event notification should be silent.</dd> - <dt>From the sound indicator, turn off silent mode.</dt> - <dt>Create a calendar event from the calendar app and wait for it to arrive.</dt> - <dd>The calendar event notification should play a sound.</dd> + <dt>Set an alarm and wait for it to arrive.</dt> + <dt>From the sound indicator, turn on silent mode.</dt> + <dd>Alarm should go off at the specified time and play its sound regardless of silent mode.</dd> + <dt>From the sound indicator, turn on silent mode.</dt> + <dt>Create a calendar event from the calendar app and wait for it to arrive.</dt> + <dd>The calendar event notification should be silent.</dd> + <dt>From the sound indicator, turn off silent mode.</dt> + <dt>Create a calendar event from the calendar app and wait for it to arrive.</dt> + <dd>The calendar event notification should play a sound.</dd> </dl> Test-case ayatana-indicator-datetime/manual-time <dl> - <dt>In System Settings > Time and Date, manually change the time to an arbitrary time.</dt> - <dd>The indicator's timestamp should change right after the time manual time is set.</dd> + <dt>In your system's Time and Date Settings, manually change the time to an arbitrary time.</dt> + <dd>The indicator's timestamp should change right after the time manual time is set.</dd> </dl> <strong> diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h index 5024792..5aedadc 100644 --- a/tests/notification-fixture.h +++ b/tests/notification-fixture.h @@ -1,6 +1,6 @@ /* * Copyright 2014-2016 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-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 @@ -52,7 +52,7 @@ protected: static constexpr char const * NOTIFY_INTERFACE {"org.freedesktop.Notifications"}; static constexpr char const * NOTIFY_PATH {"/org/freedesktop/Notifications"}; - static constexpr char const * HAPTIC_METHOD_VIBRATE_PATTERN {"VibratePattern"}; + static constexpr char const * HAPTIC_METHOD_VIBRATE {"vibrate"}; static constexpr int SCREEN_COOKIE {8675309}; static constexpr char const * SCREEN_METHOD_KEEP_DISPLAY_ON {"keepDisplayOn"}; @@ -77,10 +77,12 @@ protected: static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"}; - static constexpr char const * HINT_TIMEOUT {"x-ayatana-snap-decisions-timeout"}; +#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.ubuntu.touch.AccountsService.Sound"}; + static constexpr char const * AS_INTERFACE {"com.lomiri.touch.AccountsService.Sound"}; static constexpr char const * PROP_OTHER_VIBRATIONS {"OtherVibrate"}; static constexpr char const * PROP_SILENT_MODE {"SilentMode"}; @@ -279,8 +281,6 @@ protected: g_assert_no_error (error); dbus_test_service_add_task(service, DBUS_TEST_TASK(screen_mock)); - //TODO: Reimplement using hfd-service - /* /// /// Add the haptic mock /// @@ -292,13 +292,13 @@ protected: &error); dbus_test_dbus_mock_object_add_method(haptic_mock, haptic_obj, - HAPTIC_METHOD_VIBRATE_PATTERN, - G_VARIANT_TYPE("(auu)"), + HAPTIC_METHOD_VIBRATE, + G_VARIANT_TYPE("i"), nullptr, "", &error); g_assert_no_error (error); - dbus_test_service_add_task(service, DBUS_TEST_TASK(haptic_mock));*/ + dbus_test_service_add_task(service, DBUS_TEST_TASK(haptic_mock)); startDbusMock(); } @@ -314,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 snap decision will be interactive. - // For this test, it means we should get a timeout Notify Hint - // that matches duration_minutes + // so our notifications will be interactive. + + #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/print-to.h b/tests/print-to.h deleted file mode 100644 index 7cd6c2a..0000000 --- a/tests/print-to.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2015 Canonical Ltd. - * Copyright 2021 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 - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, 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> - * Robert Tari <robert@tari.in> - */ - -#ifndef INDICATOR_DATETIME_TESTS_PRINT_TO -#define INDICATOR_DATETIME_TESTS_PRINT_TO - -#include <algorithm> -#include <vector> - -#include <datetime/appointment.h> - -namespace ayatana { -namespace indicator { -namespace datetime { - -/*** -**** PrintTo() functions for GTest to represent objects as strings -***/ - -void -PrintTo(const DateTime& datetime, std::ostream* os) -{ - *os << "{time:'" << datetime.format("%F %T %z") << '}'; -} - -void -PrintTo(const Alarm& alarm, std::ostream* os) -{ - *os << '{'; - *os << "{text:" << alarm.text << '}'; - PrintTo(alarm.time, os); - *os << '}'; -} - -void -PrintTo(const Appointment& appointment, std::ostream* os) -{ - *os << '{'; - - *os << "{uid:'" << appointment.uid << "'}" - << "{color:'" << appointment.color << "'}" - << "{summary:'" << appointment.summary << "'}"; - - *os << "{begin:"; - PrintTo(appointment.begin, os); - *os << '}'; - - *os << "{end:"; - PrintTo(appointment.end, os); - *os << '}'; - - for(const auto& alarm : appointment.alarms) - PrintTo(alarm, os); - - *os << '}'; -} - -void -PrintTo(const std::vector<Appointment>& appointments, std::ostream* os) -{ - *os << '{'; - for (const auto& appointment : appointments) - PrintTo(appointment, os); - *os << '}'; -} - -} // namespace datetime -} // namespace indicator -} // namespace ayatana - -#endif diff --git a/tests/run-eds-ics-test.sh b/tests/run-eds-ics-test.sh index 5654034..4cbc0d3 100755 --- a/tests/run-eds-ics-test.sh +++ b/tests/run-eds-ics-test.sh @@ -72,3 +72,6 @@ if [ $rv -eq 0 ]; then sleep 5 rm -rf $TEST_TMP_DIR fi + +# pass the test's return code to the caller. +exit "$rv" diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 09f3a5d..8316357 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -36,7 +36,6 @@ class ActionsFixture: public StateFixture Appointment a1; // an alarm clock appointment a1.color = "red"; - a1.summary = "Alarm"; a1.summary = "http://www.example.com/"; a1.uid = "example"; a1.type = Appointment::ALARM; @@ -44,10 +43,9 @@ class ActionsFixture: public StateFixture Appointment a2; // a non-alarm appointment a2.color = "green"; - a2.summary = "Other Text"; a2.summary = "http://www.monkey.com/"; a2.uid = "monkey"; - a1.type = Appointment::EVENT; + a2.type = Appointment::EVENT; a2.begin = a2.end = tomorrow; return std::vector<Appointment>({a1, a2}); diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index aad93e9..b2aeb49 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -42,7 +42,7 @@ protected: std::shared_ptr<RangePlanner> m_range_planner; std::shared_ptr<UpcomingPlanner> m_upcoming; - void SetUp() + void SetUp() override { super::SetUp(); @@ -57,7 +57,7 @@ protected: EXPECT_TRUE(m_triggered.empty()); } - void TearDown() + void TearDown() override { m_triggered.clear(); m_watcher.reset(); @@ -75,7 +75,6 @@ protected: Appointment a1; // an alarm a1.color = "red"; - a1.summary = "Alarm"; a1.summary = "http://www.example.com/"; a1.uid = "example"; a1.type = Appointment::ALARM; @@ -88,7 +87,6 @@ protected: Appointment a2; // something else a2.color = "green"; - a2.summary = "Other Text"; a2.summary = "http://www.monkey.com/"; a2.uid = "monkey"; a2.type = Appointment::EVENT; diff --git a/tests/test-dbus-fixture.h b/tests/test-dbus-fixture.h index 0f19b50..7525e06 100644 --- a/tests/test-dbus-fixture.h +++ b/tests/test-dbus-fixture.h @@ -1,5 +1,6 @@ /* * Copyright 2013 Canonical Ltd. + * Copyright 2021 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> */ #ifndef INDICATOR_DATETIME_TESTS_DBUS_FIXTURE_H @@ -65,8 +67,8 @@ class TestDBusFixture: public GlibFixture protected: - GTestDBus * test_dbus; - GDBusConnection * system_bus; + GTestDBus * test_dbus = NULL; + GDBusConnection * system_bus = NULL; const std::vector<std::string> service_dirs; virtual void SetUp() override diff --git a/tests/test-eds-ics-alarm-custom-sound.cpp b/tests/test-eds-ics-alarm-custom-sound.cpp new file mode 100644 index 0000000..9f63c29 --- /dev/null +++ b/tests/test-eds-ics-alarm-custom-sound.cpp @@ -0,0 +1,92 @@ +/* + * Copyright 2015 Canonical Ltd. + * Copyright 2021 Robert Tari + * Copyright 2023 UBports Foundation. + * + * 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 + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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> + * Robert Tari <robert@tari.in> + * Ratchanan Srirattanamet <ratchanan@ubports.com> + */ + +#include <algorithm> + +#include <datetime/alarm-queue-simple.h> +#include <datetime/clock-mock.h> +#include <datetime/engine-eds.h> +#include <datetime/myself.h> +#include <datetime/planner-range.h> + +#include <gtest/gtest.h> + +#include "glib-fixture.h" +#include "timezone-mock.h" +#include "wakeup-timer-mock.h" + +using namespace ayatana::indicator::datetime; +using VAlarmFixture = GlibFixture; + +/*** +**** +***/ + +TEST_F(VAlarmFixture, AlarmCustomSound) +{ + // start the EDS engine + auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>()); + + // we need a consistent timezone for the planner and our local DateTimes + constexpr char const * zone_str {"America/Recife"}; + auto tz = std::make_shared<MockTimezone>(zone_str); + + #if GLIB_CHECK_VERSION(2, 68, 0) + auto gtz = g_time_zone_new_identifier(zone_str); + + if (gtz == NULL) + { + gtz = g_time_zone_new_utc(); + } + #else + auto gtz = g_time_zone_new(zone_str); + #endif + + // make a planner that looks at the first half of 2023 in EDS + auto planner = std::make_shared<SimpleRangePlanner>(engine, tz); + const DateTime range_begin {gtz, 2023,1, 1, 0, 0, 0.0}; + const DateTime range_end {gtz, 2023,6,30,23,59,59.5}; + planner->range().set(std::make_pair(range_begin, range_end)); + + // give EDS a moment to load + if (planner->appointments().get().empty()) { + g_message("waiting a moment for EDS to load..."); + auto on_appointments_changed = [this](const std::vector<Appointment>& appointments){ + g_message("ah, they loaded"); + if (!appointments.empty()) + g_main_loop_quit(loop); + }; + core::ScopedConnection conn(planner->appointments().changed().connect(on_appointments_changed)); + constexpr int max_wait_sec = 10; + wait_msec(max_wait_sec * G_TIME_SPAN_MILLISECOND); + } + + // the planner should match what we've got in the calendar.ics file + const auto appts = planner->appointments().get(); + EXPECT_EQ(1, appts.size()); + EXPECT_EQ(1, appts[0].alarms.size()); + EXPECT_EQ(appts[0].alarms[0].audio_url, "file:///usr/share/sounds/lomiri/ringtones/Entropy.ogg"); + + // cleanup + g_time_zone_unref(gtz); +} diff --git a/tests/test-eds-ics-alarm-custom-sound.ics.in b/tests/test-eds-ics-alarm-custom-sound.ics.in new file mode 100644 index 0000000..5354a71 --- /dev/null +++ b/tests/test-eds-ics-alarm-custom-sound.ics.in @@ -0,0 +1,32 @@ +BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Ximian//NONSGML Evolution Calendar//EN
+VERSION:2.0
+X-EVOLUTION-DATA-REVISION:2023-06-06T17:25:48.265942Z(42)
+BEGIN:VTODO
+UID:882a6a702f87a3afde203e5609d2626ba144a3c2
+DTSTAMP:20230606T172548Z
+DTSTART:20230607T165701
+PRIORITY:0
+SUMMARY:Alarm
+CATEGORIES:x-lomiri-alarm
+SEQUENCE:1
+LAST-MODIFIED:20230606T172548Z
+BEGIN:VALARM
+X-EVOLUTION-ALARM-UID:eceda45c7493b76e41cdb2369ce8160b75e53f98
+ACTION:AUDIO
+TRIGGER;RELATED=START:PT0S
+REPEAT:0
+DURATION:PT0S
+ATTACH:file:///usr/share/sounds/lomiri/ringtones/Entropy.ogg
+END:VALARM
+BEGIN:VALARM
+X-EVOLUTION-ALARM-UID:8eec04befc2876fb13a6726181fed33b9f7810c8
+ACTION:DISPLAY
+DESCRIPTION:Alarm
+TRIGGER;RELATED=START:PT0S
+REPEAT:0
+DURATION:PT0S
+END:VALARM
+END:VTODO
+END:VCALENDAR
diff --git a/tests/test-eds-ics-all-day-events.cpp b/tests/test-eds-ics-all-day-events.cpp index 5d7cdc6..0fa40fd 100644 --- a/tests/test-eds-ics-all-day-events.cpp +++ b/tests/test-eds-ics-all-day-events.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 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 @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -82,7 +81,6 @@ TEST_F(VAlarmFixture, MultipleAppointments) // what we expect to get... Appointment expected_appt; expected_appt.uid = "20150521T111538Z-7449-1000-3572-0@ghidorah"; - expected_appt.color = "#becedd"; expected_appt.summary = "Memorial Day"; expected_appt.begin = DateTime{gtz,2015,5,25,0,0,0}; expected_appt.end = DateTime{gtz,2015,5,26,0,0,0}; @@ -94,10 +92,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) EXPECT_EQ(expected_appt.begin, appt.begin); EXPECT_EQ(expected_appt.end, appt.end); EXPECT_EQ(expected_appt.uid, appt.uid); - EXPECT_EQ(expected_appt.color, appt.color); EXPECT_EQ(expected_appt.summary, appt.summary); EXPECT_EQ(0, appt.alarms.size()); + EXPECT_PRED3([](auto sColourIn, auto sColourExpected1, auto sColourExpected2) + { + return sColourIn == sColourExpected1 || sColourIn == sColourExpected2; + }, appt.color, "#becedd", "#62a0ea"); + // cleanup g_time_zone_unref(gtz); } diff --git a/tests/test-eds-ics-missing-trigger.cpp b/tests/test-eds-ics-missing-trigger.cpp index e5a0bdf..4030999 100644 --- a/tests/test-eds-ics-missing-trigger.cpp +++ b/tests/test-eds-ics-missing-trigger.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 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 @@ -20,7 +20,7 @@ */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -63,7 +62,7 @@ TEST_F(VAlarmFixture, MissingTriggers) // make a planner that looks at the first half of 2015 in EDS auto planner = std::make_shared<SimpleRangePlanner>(engine, tz); const DateTime range_begin {gtz, 2015,1, 1, 0, 0, 0.0}; - const DateTime range_end {gtz, 2015,7,1,23,59,59.5}; + const DateTime range_end {gtz, 2015,6,30,23,59,59.5}; planner->range().set(std::make_pair(range_begin, range_end)); // give EDS a moment to load @@ -79,25 +78,25 @@ TEST_F(VAlarmFixture, MissingTriggers) wait_msec(max_wait_sec * G_TIME_SPAN_MILLISECOND); } - // build expected: one-time alarm - std::vector<Appointment> expected; - Appointment a; - a.type = Appointment::ALARM; - a.uid = "20150617T211838Z-6217-32011-2036-1@ubuntu-phablet"; - a.color = "#becedd"; - a.summary = "One Time Alarm"; - a.begin = DateTime { gtz, 2015, 6, 18, 10, 0, 0}; - a.end = a.begin; - a.alarms.resize(1); - a.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND; - a.alarms[0].time = a.begin; - a.alarms[0].text = a.summary; - expected.push_back(a); - - // build expected: recurring alarm - a.uid = "20150617T211913Z-6217-32011-2036-5@ubuntu-phablet"; - a.summary = "Recurring Alarm"; - a.alarms[0].text = a.summary; + // build expected: one-time alarm 1 + std::vector<Appointment> expected1; + Appointment a1; + a1.type = Appointment::ALARM; + a1.uid = "20150617T211838Z-6217-32011-2036-1@lomiri-phablet"; + a1.color = "#becedd"; + a1.summary = "One Time Alarm"; + a1.begin = DateTime { gtz, 2015, 6, 18, 10, 0, 0}; + a1.end = a1.begin; + a1.alarms.resize(1); + a1.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND; + a1.alarms[0].time = a1.begin; + a1.alarms[0].text = a1.summary; + expected1.push_back(a1); + + // build expected: recurring alarm 1 + a1.uid = "20150617T211913Z-6217-32011-2036-5@lomiri-phablet"; + a1.summary = "Recurring Alarm"; + a1.alarms[0].text = a1.summary; std::array<DateTime,13> recurrences { DateTime{ gtz, 2015, 6, 18, 10, 1, 0 }, DateTime{ gtz, 2015, 6, 19, 10, 1, 0 }, @@ -114,13 +113,41 @@ TEST_F(VAlarmFixture, MissingTriggers) DateTime{ gtz, 2015, 6, 30, 10, 1, 0 }, }; for (const auto& time : recurrences) { - a.begin = a.end = a.alarms[0].time = time; - expected.push_back(a); + a1.begin = a1.end = a1.alarms[0].time = time; + expected1.push_back(a1); + } + + // build expected: one-time alarm 2 + std::vector<Appointment> expected2; + Appointment a2; + a2.type = Appointment::ALARM; + a2.uid = "20150617T211838Z-6217-32011-2036-1@lomiri-phablet"; + a2.color = "#62a0ea"; + a2.summary = "One Time Alarm"; + a2.begin = DateTime { gtz, 2015, 6, 18, 10, 0, 0}; + a2.end = a2.begin; + a2.alarms.resize(1); + a2.alarms[0].audio_url = "file://" ALARM_DEFAULT_SOUND; + a2.alarms[0].time = a2.begin; + a2.alarms[0].text = a2.summary; + expected2.push_back(a2); + + // build expected: recurring alarm 2 + a2.uid = "20150617T211913Z-6217-32011-2036-5@lomiri-phablet"; + a2.summary = "Recurring Alarm"; + a2.alarms[0].text = a2.summary; + for (const auto& time : recurrences) { + a2.begin = a2.end = a2.alarms[0].time = time; + expected2.push_back(a2); } // the planner should match what we've got in the calendar.ics file const auto appts = planner->appointments().get(); - EXPECT_EQ(expected, appts); + + EXPECT_PRED3([](auto lAppointmentsIn, auto lAppointmentsExpected1, auto lAppointmentsExpected2) + { + return lAppointmentsIn == lAppointmentsExpected1 || lAppointmentsIn == lAppointmentsExpected2; + }, appts, expected1, expected2); // cleanup g_time_zone_unref(gtz); diff --git a/tests/test-eds-ics-missing-trigger.ics.in b/tests/test-eds-ics-missing-trigger.ics.in index 01a306c..de38ba5 100644 --- a/tests/test-eds-ics-missing-trigger.ics.in +++ b/tests/test-eds-ics-missing-trigger.ics.in @@ -4,40 +4,40 @@ PRODID:-//Ximian//NONSGML Evolution Calendar//EN VERSION:2.0
X-EVOLUTION-DATA-REVISION:2015-06-17T21:19:13.980613Z(3)
BEGIN:VTODO
-UID:20150617T211838Z-6217-32011-2036-1@ubuntu-phablet
+UID:20150617T211838Z-6217-32011-2036-1@lomiri-phablet
DTSTAMP:20150617T211838Z
DTSTART:20150618T100000
SUMMARY:One Time Alarm
-CATEGORIES:x-ayatana-alarm
+CATEGORIES:x-lomiri-alarm
CREATED:20150617T211838Z
LAST-MODIFIED:20150617T211838Z
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150617T211838Z-6217-32011-2036-2@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150617T211838Z-6217-32011-2036-2@lomiri-phablet
ACTION:AUDIO
ATTACH:file://@ALARM_DEFAULT_SOUND@
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150617T211838Z-6217-32011-2036-3@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150617T211838Z-6217-32011-2036-3@lomiri-phablet
ACTION:DISPLAY
DESCRIPTION:One Time Alarm
END:VALARM
END:VTODO
BEGIN:VTODO
-UID:20150617T211913Z-6217-32011-2036-5@ubuntu-phablet
+UID:20150617T211913Z-6217-32011-2036-5@lomiri-phablet
DTSTAMP:20150617T211913Z
DTSTART:20150618T100100
RRULE:FREQ=DAILY
SUMMARY:Recurring Alarm
-CATEGORIES:x-ayatana-alarm
+CATEGORIES:x-lomiri-alarm
CREATED:20150617T211913Z
LAST-MODIFIED:20150617T211913Z
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150617T211913Z-6217-32011-2036-6@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150617T211913Z-6217-32011-2036-6@lomiri-phablet
ACTION:AUDIO
ATTACH:file://@ALARM_DEFAULT_SOUND@
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150617T211913Z-6217-32011-2036-7@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150617T211913Z-6217-32011-2036-7@lomiri-phablet
ACTION:DISPLAY
DESCRIPTION:Recurring Alarm
END:VALARM
diff --git a/tests/test-eds-ics-non-attending-alarms.cpp b/tests/test-eds-ics-non-attending-alarms.cpp index bfa3ac3..629c1fc 100644 --- a/tests/test-eds-ics-non-attending-alarms.cpp +++ b/tests/test-eds-ics-non-attending-alarms.cpp @@ -1,5 +1,6 @@ /* * Copyright 2015 Canonical Ltd. + * Copyright 2021-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 <algorithm> @@ -28,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -80,9 +81,10 @@ TEST_F(VAlarmFixture, NonAttendingEvent) // the planner should match what we've got in the calendar.ics file const auto appts = planner->appointments().get(); - EXPECT_EQ(2, appts.size()); + EXPECT_EQ(3, appts.size()); EXPECT_EQ(appts[0].begin, DateTime(gtz, 2016, 4, 4, 16, 0, 0)); - EXPECT_EQ(appts[1].begin, DateTime(gtz, 2016, 4, 6, 16, 0, 0)); + EXPECT_EQ(appts[1].begin, DateTime(gtz, 2016, 4, 5, 16, 0, 0)); + EXPECT_EQ(appts[2].begin, DateTime(gtz, 2016, 4, 6, 16, 0, 0)); // cleanup g_time_zone_unref(gtz); diff --git a/tests/test-eds-ics-non-selected-source.ics.in b/tests/test-eds-ics-non-selected-source.ics.in index 3ae584f..19f93d7 100644 --- a/tests/test-eds-ics-non-selected-source.ics.in +++ b/tests/test-eds-ics-non-selected-source.ics.in @@ -9,7 +9,7 @@ DTSTAMP:20150508T211449Z DTSTART:20150508T164000 RRULE:FREQ=WEEKLY;BYDAY=FR SUMMARY:Alarm -CATEGORIES:x-ayatana-alarm +CATEGORIES:x-lomiri-alarm CREATED:20150507T211449Z LAST-MODIFIED:20150507T211449Z BEGIN:VALARM diff --git a/tests/test-eds-ics-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp index 8aa2b82..49fc9be 100644 --- a/tests/test-eds-ics-nonrepeating-events.cpp +++ b/tests/test-eds-ics-nonrepeating-events.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 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 @@ -20,7 +20,7 @@ */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -82,7 +81,6 @@ TEST_F(VAlarmFixture, MultipleAppointments) // what we expect to get... Appointment expected_appt; expected_appt.uid = "20150520T000726Z-3878-32011-1770-81@lomiri-phablet"; - expected_appt.color = "#becedd"; expected_appt.summary = "Alarm"; std::array<Alarm,1> expected_alarms = { Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5,20,20,00,0)}) @@ -94,10 +92,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) for (size_t i=0, n=expected_alarms.size(); i<n; i++) { const auto& appt = appts[i]; EXPECT_EQ(expected_appt.uid, appt.uid); - EXPECT_EQ(expected_appt.color, appt.color); EXPECT_EQ(expected_appt.summary, appt.summary); EXPECT_EQ(1, appt.alarms.size()); EXPECT_EQ(expected_alarms[i], appt.alarms[0]); + + EXPECT_PRED3([](auto sColourIn, auto sColourExpected1, auto sColourExpected2) + { + return sColourIn == sColourExpected1 || sColourIn == sColourExpected2; + }, appt.color, "#becedd", "#62a0ea"); } // cleanup diff --git a/tests/test-eds-ics-nonrepeating-events.ics.in b/tests/test-eds-ics-nonrepeating-events.ics.in index 6e45450..a01fdab 100644 --- a/tests/test-eds-ics-nonrepeating-events.ics.in +++ b/tests/test-eds-ics-nonrepeating-events.ics.in @@ -4,21 +4,21 @@ PRODID:-//Ximian//NONSGML Evolution Calendar//EN VERSION:2.0
X-EVOLUTION-DATA-REVISION:2015-05-20T22:39:32.685099Z(1)
BEGIN:VTODO
-UID:20150520T000726Z-3878-32011-1770-81@ubuntu-phablet
+UID:20150520T000726Z-3878-32011-1770-81@lomiri-phablet
DTSTAMP:20150520T223932Z
DTSTART:20150520T200000
SUMMARY:Alarm
-CATEGORIES:x-ayatana-alarm
+CATEGORIES:x-lomiri-alarm
SEQUENCE:1
LAST-MODIFIED:20150520T223932Z
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150520T223932Z-22506-32011-1771-2@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150520T223932Z-22506-32011-1771-2@lomiri-phablet
ACTION:AUDIO
ATTACH:file://@ALARM_DEFAULT_SOUND@
TRIGGER;VALUE=DURATION;RELATED=START:PT0S
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150520T223932Z-22506-32011-1771-3@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150520T223932Z-22506-32011-1771-3@lomiri-phablet
ACTION:DISPLAY
DESCRIPTION:Alarm
TRIGGER;VALUE=DURATION;RELATED=START:PT0S
diff --git a/tests/test-eds-ics-repeating-events-with-individual-change.cpp b/tests/test-eds-ics-repeating-events-with-individual-change.cpp index a4a85c0..c83c8d2 100644 --- a/tests/test-eds-ics-repeating-events-with-individual-change.cpp +++ b/tests/test-eds-ics-repeating-events-with-individual-change.cpp @@ -1,5 +1,6 @@ /* * Copyright 2016 Canonical Ltd. + * Copyright 2021-2022 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,10 +16,11 @@ * * Authors: * Renato Araujo Oliveira Filho <renato.filho@canonical.com> + * Robert Tari <robert@tari.in> */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -28,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" diff --git a/tests/test-eds-ics-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp index 4125623..a570d0f 100644 --- a/tests/test-eds-ics-repeating-events.cpp +++ b/tests/test-eds-ics-repeating-events.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 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 @@ -20,7 +20,7 @@ */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -82,7 +81,6 @@ TEST_F(VAlarmFixture, MultipleAppointments) // what we expect to get... Appointment expected_appt; expected_appt.uid = "20150507T211449Z-4262-32011-1418-1@lomiri-phablet"; - expected_appt.color = "#becedd"; expected_appt.summary = "Alarm"; std::array<Alarm,8> expected_alarms = { Alarm({"Alarm", "file://" ALARM_DEFAULT_SOUND, DateTime(gtz,2015,5, 8,16,40,0)}), @@ -101,10 +99,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) for (size_t i=0, n=expected_alarms.size(); i<n; i++) { const auto& appt = appts[i]; EXPECT_EQ(expected_appt.uid, appt.uid); - EXPECT_EQ(expected_appt.color, appt.color); EXPECT_EQ(expected_appt.summary, appt.summary); EXPECT_EQ(1, appt.alarms.size()); EXPECT_EQ(expected_alarms[i], appt.alarms[0]); + + EXPECT_PRED3([](auto sColourIn, auto sColourExpected1, auto sColourExpected2) + { + return sColourIn == sColourExpected1 || sColourIn == sColourExpected2; + }, appt.color, "#becedd", "#62a0ea"); } // cleanup diff --git a/tests/test-eds-ics-repeating-events.ics.in b/tests/test-eds-ics-repeating-events.ics.in index 51679a3..dfd3c9b 100644 --- a/tests/test-eds-ics-repeating-events.ics.in +++ b/tests/test-eds-ics-repeating-events.ics.in @@ -4,22 +4,22 @@ PRODID:-//Ximian//NONSGML Evolution Calendar//EN VERSION:2.0
X-EVOLUTION-DATA-REVISION:2015-05-07T21:14:49.315443Z(0)
BEGIN:VTODO
-UID:20150507T211449Z-4262-32011-1418-1@ubuntu-phablet
+UID:20150507T211449Z-4262-32011-1418-1@lomiri-phablet
DTSTAMP:20150508T211449Z
DTSTART:20150508T164000
RRULE:FREQ=WEEKLY;BYDAY=FR
SUMMARY:Alarm
-CATEGORIES:x-ayatana-alarm
+CATEGORIES:x-lomiri-alarm
CREATED:20150507T211449Z
LAST-MODIFIED:20150507T211449Z
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-2@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-2@lomiri-phablet
ACTION:AUDIO
ATTACH:file://@ALARM_DEFAULT_SOUND@
TRIGGER;VALUE=DURATION;RELATED=START:PT0S
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-3@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-3@lomiri-phablet
ACTION:DISPLAY
DESCRIPTION:Alarm
TRIGGER;VALUE=DURATION;RELATED=START:PT0S
diff --git a/tests/test-eds-ics-repeating-valarms.cpp b/tests/test-eds-ics-repeating-valarms.cpp index 1584983..ba44662 100644 --- a/tests/test-eds-ics-repeating-valarms.cpp +++ b/tests/test-eds-ics-repeating-valarms.cpp @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" diff --git a/tests/test-eds-ics-repeating-valarms.ics.in b/tests/test-eds-ics-repeating-valarms.ics.in index fe526f4..1a80432 100644 --- a/tests/test-eds-ics-repeating-valarms.ics.in +++ b/tests/test-eds-ics-repeating-valarms.ics.in @@ -4,7 +4,7 @@ PRODID:-//Ximian//NONSGML Evolution Calendar//EN VERSION:2.0
X-EVOLUTION-DATA-REVISION:2015-04-05T21:32:47.354433Z(2)
BEGIN:VEVENT
-UID:20150405T213247Z-4371-32011-1698-1@ubuntu-phablet
+UID:20150405T213247Z-4371-32011-1698-1@lomiri-phablet
DTSTAMP:20150405T213247Z
DTSTART:20150424T183500Z
DTEND:20150424T193554Z
@@ -14,14 +14,14 @@ SUMMARY:London Sprint Flight CREATED:20150405T213247Z
LAST-MODIFIED:20150405T213247Z
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-2@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-2@lomiri-phablet
ACTION:AUDIO
TRIGGER;VALUE=DURATION;RELATED=START:-P1D
REPEAT:3
DURATION:PT2M
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-3@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-3@lomiri-phablet
ACTION:DISPLAY
DESCRIPTION:Time to pack!
TRIGGER;VALUE=DURATION;RELATED=START:-P1D
@@ -29,14 +29,14 @@ REPEAT:3 DURATION:PT2M
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-5@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-5@lomiri-phablet
ACTION:AUDIO
TRIGGER;VALUE=DURATION;RELATED=START:-PT3H
REPEAT:3
DURATION:PT2M
END:VALARM
BEGIN:VALARM
-X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-6@ubuntu-phablet
+X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-6@lomiri-phablet
ACTION:DISPLAY
DESCRIPTION:Go to the airport!
TRIGGER;VALUE=DURATION;RELATED=START:-PT3H
diff --git a/tests/test-eds-ics-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp index a1d2f5a..1bef68b 100644 --- a/tests/test-eds-ics-tzids-2.cpp +++ b/tests/test-eds-ics-tzids-2.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 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 @@ -20,7 +20,7 @@ */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -80,20 +79,35 @@ TEST_F(VAlarmFixture, MultipleAppointments) } // what we expect to get... - std::array<Appointment,1> expected_appts; - auto appt = &expected_appts[0]; - appt->uid = "109264742"; - appt->color = "#becedd"; - appt->summary = "National Incubator Initiative for Clean Energy (NIICE) FOA: Pre-Concept Paper Informational Webinar"; - appt->begin = DateTime{gtz,2014,1,21,11,0,0}; - appt->end = DateTime{gtz,2014,1,21,13,0,0}; - appt->alarms = std::vector<Alarm>{ Alarm({"Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; + std::array<Appointment,1> expected_appts1; + auto appt1 = &expected_appts1[0]; + appt1->uid = "109264742"; + appt1->color = "#becedd"; + appt1->summary = "National Incubator Initiative for Clean Energy (NIICE) FOA: Pre-Concept Paper Informational Webinar"; + appt1->begin = DateTime{gtz,2014,1,21,11,0,0}; + appt1->end = DateTime{gtz,2014,1,21,13,0,0}; + appt1->alarms = std::vector<Alarm>{ Alarm({"Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; + + std::array<Appointment,1> expected_appts2; + auto appt2 = &expected_appts2[0]; + appt2->uid = "109264742"; + appt2->color = "#62a0ea"; + appt2->summary = "National Incubator Initiative for Clean Energy (NIICE) FOA: Pre-Concept Paper Informational Webinar"; + appt2->begin = DateTime{gtz,2014,1,21,11,0,0}; + appt2->end = DateTime{gtz,2014,1,21,13,0,0}; + appt2->alarms = std::vector<Alarm>{ Alarm({"Reminder", "", DateTime(gtz,2014,1,21,10,45,0)}) }; // compare it to what we actually loaded... const auto appts = planner->appointments().get(); - EXPECT_EQ(expected_appts.size(), appts.size()); - for (size_t i=0, n=std::min(appts.size(),expected_appts.size()); i<n; i++) - EXPECT_EQ(expected_appts[i], appts[i]); + EXPECT_EQ(expected_appts1.size(), appts.size()); + EXPECT_EQ(expected_appts2.size(), appts.size()); + for (size_t i=0, n=std::min(appts.size(),expected_appts1.size()); i<n; i++) + { + EXPECT_PRED3([](auto pAppointmentIn, auto pAppointmentExpected1, auto pAppointmentExpected2) + { + return pAppointmentIn == pAppointmentExpected1 || pAppointmentIn == pAppointmentExpected2; + }, appts[i], expected_appts1[i], expected_appts2[i]); + } // cleanup g_time_zone_unref(gtz); diff --git a/tests/test-eds-ics-tzids-utc.cpp b/tests/test-eds-ics-tzids-utc.cpp index f79bf3e..d88e95d 100644 --- a/tests/test-eds-ics-tzids-utc.cpp +++ b/tests/test-eds-ics-tzids-utc.cpp @@ -1,5 +1,6 @@ /* * Copyright 2015 Canonical Ltd. + * Copyright 2021-2024 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,10 +16,11 @@ * * Authors: * Charles Kerr <charles.kerr@canonical.com> + * Robert Tari <robert@tari.in> */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -28,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -79,19 +80,33 @@ TEST_F(VAlarmFixture, UTCAppointments) } // what we expect to get... - std::array<Appointment,1> expected_appts; - auto appt = &expected_appts[0]; - appt->uid = "20160322T132738Z"; - appt->color = "#becedd"; - appt->summary = "UTC event"; - appt->begin = DateTime{gtz,2016,3,22,15,0,0}; - appt->end = DateTime{gtz,2016,3,22,16,0,0}; + std::array<Appointment,1> expected_appts1; + auto appt1 = &expected_appts1[0]; + appt1->uid = "20160322T132738Z"; + appt1->color = "#becedd"; + appt1->summary = "UTC event"; + appt1->begin = DateTime{gtz,2016,3,22,15,0,0}; + appt1->end = DateTime{gtz,2016,3,22,16,0,0}; + + std::array<Appointment,1> expected_appts2; + auto appt2 = &expected_appts2[0]; + appt2->uid = "20160322T132738Z"; + appt2->color = "#62a0ea"; + appt2->summary = "UTC event"; + appt2->begin = DateTime{gtz,2016,3,22,15,0,0}; + appt2->end = DateTime{gtz,2016,3,22,16,0,0}; // compare it to what we actually loaded... const auto appts = planner->appointments().get(); - EXPECT_EQ(expected_appts.size(), appts.size()); - for (size_t i=0, n=std::min(appts.size(),expected_appts.size()); i<n; i++) - EXPECT_EQ(expected_appts[i], appts[i]); + EXPECT_EQ(expected_appts1.size(), appts.size()); + EXPECT_EQ(expected_appts2.size(), appts.size()); + for (size_t i=0, n=std::min(appts.size(),expected_appts1.size()); i<n; i++) + { + EXPECT_PRED3([](auto pAppointmentIn, auto pAppointmentExpected1, auto pAppointmentExpected2) + { + return pAppointmentIn == pAppointmentExpected1 || pAppointmentIn == pAppointmentExpected2; + }, appts[i], expected_appts1[i], expected_appts2[i]); + } // cleanup g_time_zone_unref(gtz); diff --git a/tests/test-eds-ics-tzids.cpp b/tests/test-eds-ics-tzids.cpp index 11d44b7..4999e66 100644 --- a/tests/test-eds-ics-tzids.cpp +++ b/tests/test-eds-ics-tzids.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021 Robert Tari + * Copyright 2021-2024 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 @@ -20,7 +20,7 @@ */ #include <algorithm> - +#include <array> #include <datetime/alarm-queue-simple.h> #include <datetime/clock-mock.h> #include <datetime/engine-eds.h> @@ -30,7 +30,6 @@ #include <gtest/gtest.h> #include "glib-fixture.h" -#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" @@ -80,19 +79,34 @@ TEST_F(VAlarmFixture, MultipleAppointments) } // what we expect to get... - std::array<Appointment,1> expected_appts; - auto appt = &expected_appts[0]; - appt->uid = "8ggc30kh89qql8vjumgtug7l14@google.com"; - appt->color = "#becedd"; - appt->summary = "Hello"; - appt->begin = DateTime{gtz,2015,7,1,20,0,0}; - appt->end = DateTime{gtz,2015,7,1,22,0,0}; + std::array<Appointment,1> expected_appts1; + auto appt1 = &expected_appts1[0]; + appt1->uid = "8ggc30kh89qql8vjumgtug7l14@google.com"; + appt1->color = "#becedd"; + appt1->summary = "Hello"; + appt1->begin = DateTime{gtz,2015,7,1,20,0,0}; + appt1->end = DateTime{gtz,2015,7,1,22,0,0}; + + std::array<Appointment,1> expected_appts2; + auto appt2 = &expected_appts2[0]; + appt2->uid = "8ggc30kh89qql8vjumgtug7l14@google.com"; + appt2->color = "#62a0ea"; + appt2->summary = "Hello"; + appt2->begin = DateTime{gtz,2015,7,1,20,0,0}; + appt2->end = DateTime{gtz,2015,7,1,22,0,0}; // compare it to what we actually loaded... const auto appts = planner->appointments().get(); - EXPECT_EQ(expected_appts.size(), appts.size()); - for (size_t i=0, n=std::min(appts.size(),expected_appts.size()); i<n; i++) - EXPECT_EQ(expected_appts[i], appts[i]); + EXPECT_EQ(expected_appts1.size(), appts.size()); + EXPECT_EQ(expected_appts2.size(), appts.size()); + + for (size_t i=0, n=std::min(appts.size(),expected_appts1.size()); i<n; i++) + { + EXPECT_PRED3([](auto pAppointmentIn, auto pAppointmentExpected1, auto pAppointmentExpected2) + { + return pAppointmentIn == pAppointmentExpected1 || pAppointmentIn == pAppointmentExpected2; + }, appts[i], expected_appts1[i], expected_appts2[i]); + } // cleanup g_time_zone_unref(gtz); diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index a8d798b..d8c0afb 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -1,9 +1,10 @@ - /* * Copyright 2013 Canonical Ltd. + * Copyright 2021 Robert Tari * * Authors: * Charles Kerr <charles.kerr@canonical.com> + * Robert Tari <robert@tari.in> * * 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 @@ -143,10 +144,9 @@ TEST_F(FormatterFixture, DISABLED_TestDesktopHeader) auto now = DateTime::Local(2020, 10, 31, 18, 30, 59); auto clock = std::make_shared<MockClock>(now); - bool locale_set = false; for(const auto& test_case : test_cases) { - test_case.is_12h ? locale_set = Set12hLocale() : locale_set = Set24hLocale(); + bool locale_set = test_case.is_12h ? Set12hLocale() : Set24hLocale(); DesktopFormatter f(clock, m_settings); m_settings->show_day.set(test_case.show_day); diff --git a/tests/test-menu-appointments.cpp b/tests/test-menu-appointments.cpp index 4d15b9f..ed02395 100644 --- a/tests/test-menu-appointments.cpp +++ b/tests/test-menu-appointments.cpp @@ -20,11 +20,10 @@ */ #include "glib-fixture.h" -#include "print-to.h" #include <datetime/appointment.h> #include <datetime/menu.h> - +#include <algorithm> #include <vector> using MenuAppointmentFixture = GlibFixture; @@ -117,70 +116,6 @@ TEST_F(MenuAppointmentFixture, DisplayEvents) DateTime::Local(2017,1,1,0,0,0) ); - const auto nye_party = create_appointment( - Appointment::EVENT, - "uid-new-years-party", - "New Year Party at Ted's", - DateTime::Local(2016,12,31,19,0,0), - DateTime::Local(2017, 1, 1, 2,0,0) - ); - - const auto new_years_day = create_appointment( - Appointment::EVENT, - "uid-new-years-day", - "New Years' Day", - DateTime::Local(2017,1,1,0,0,0), - DateTime::Local(2017,1,2,0,0,0) - ); - - const auto weekday_wakeup_alarm = create_appointment( - Appointment::ALARM, - "wakeup-alarm", - "Wake Up", - DateTime::Local(2017,1,3,6,0,0), - DateTime::Local(2017,1,3,6,0,0) - ); - - const auto dentist_appointment = create_appointment( - Appointment::EVENT, - "dentist", - "Dentist", - DateTime::Local(2017,1,5,14,0,0), - DateTime::Local(2017,1,5,15,0,0) - ); - - const auto marcus_birthday = create_appointment( - Appointment::EVENT, - "uid-mlk", - "Marcus' Birthday", - DateTime::Local(2017,1,8,0,0,0), - DateTime::Local(2017,1,9,0,0,0) - ); - - const auto mlk_day = create_appointment( - Appointment::EVENT, - "uid-mlk", - "Martin Luther King Day", - DateTime::Local(2017,1,16,0,0,0), - DateTime::Local(2017,1,17,0,0,0) - ); - - const auto rodney_party = create_appointment( - Appointment::EVENT, - "uid-rodney", - "Rodney's Party", - DateTime::Local(2017,1,30,19,0,0), - DateTime::Local(2017,1,30,23,0,0) - ); - - const auto pub_with_pawel = create_appointment( - Appointment::ALARM, - "uid-pawel", - "Meet Pawel at the Pub", - DateTime::Local(2017,2,4,19,0,0), - DateTime::Local(2017,2,4,19,0,0) - ); - const struct { const char* const description; diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index de323d3..ea8cb30 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -186,7 +186,6 @@ private: Appointment a1; // an alarm clock appointment a1.color = "red"; - a1.summary = "Alarm"; a1.summary = "http://www.example.com/"; a1.uid = "example"; a1.type = Appointment::ALARM; @@ -194,10 +193,9 @@ private: Appointment a2; // a non-alarm appointment a2.color = "green"; - a2.summary = "Other Text"; a2.summary = "http://www.monkey.com/"; a2.uid = "monkey"; - a1.type = Appointment::EVENT; + a2.type = Appointment::EVENT; a2.begin = a2.end = tomorrow; return std::vector<Appointment>({a1, a2}); @@ -274,12 +272,35 @@ private: for (int i=0, n=appointments.size(); i<n; i++) InspectAppointmentMenuItem(section, first_appt_index+i, appointments[i]); + // there shouldn't be any alarms when "show alarms" is false + bool has_alarms = false; + m_state->settings->show_alarms.set(false); + wait_msec(); + + std::vector<Appointment> display_appointments = Menu::get_display_appointments(appointments, m_state->clock->localtime(), 5, m_state->settings->show_alarms.get()); + for (int i=0, n=display_appointments.size(); i<n; i++) + if ((has_alarms = display_appointments[i].is_alarm())) + break; + + EXPECT_FALSE(has_alarms); + + m_state->settings->show_alarms.set(true); + wait_msec(); + + display_appointments = Menu::get_display_appointments(appointments, m_state->clock->localtime(), 5, m_state->settings->show_alarms.get()); + for (int i=0, n=display_appointments.size(); i<n; i++) + if ((has_alarms = display_appointments[i].is_alarm())) + break; + + EXPECT_TRUE(has_alarms); + //g_clear_object(§ion); //g_clear_object(&submenu); } void InspectDesktopAppointments(GMenuModel* menu_model, bool can_open_planner) { + m_state->settings->show_alarms.set(true); const int n_add_event_buttons = can_open_planner ? 1 : 0; // get the Appointments section @@ -326,15 +347,24 @@ private: void InspectPhoneAppointments(GMenuModel* menu_model, bool can_open_planner) { + m_state->settings->show_alarms.set(true); auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); + + // there shouldn't be any menuitems when "show events" is false + m_state->settings->show_events.set(false); + wait_msec(); + auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); + EXPECT_EQ(0, g_menu_model_get_n_items(section)); + g_clear_object(§ion); // clear all the appointments std::vector<Appointment> appointments; + m_state->settings->show_events.set(true); m_state->calendar_upcoming->appointments().set(appointments); wait_msec(); // wait a moment for the menu to update // check that there's a "clock app" menuitem even when there are no appointments - auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); + section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); const char* expected_action = "phone.open-alarm-app"; EXPECT_EQ(1, g_menu_model_get_n_items(section)); gchar* action = nullptr; 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-notification.cpp b/tests/test-notification.cpp index 80eb04c..7dccb96 100644 --- a/tests/test-notification.cpp +++ b/tests/test-notification.cpp @@ -158,9 +158,9 @@ TEST_F(NotificationFixture,Notification) // confirm that the vibration was as expected if (expected_vibrate_called) { - EXPECT_METHOD_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE_PATTERN); + EXPECT_METHOD_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE); } else { - EXPECT_METHOD_NOT_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE_PATTERN); + EXPECT_METHOD_NOT_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE); } // confirm that the notification was as expected 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); |