diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 29 | ||||
-rw-r--r-- | tests/notification-fixture.h | 27 | ||||
-rwxr-xr-x | tests/run-eds-ics-test.sh | 3 | ||||
-rw-r--r-- | tests/test-eds-ics-alarm-custom-sound.cpp | 92 | ||||
-rw-r--r-- | tests/test-eds-ics-alarm-custom-sound.ics.in | 32 | ||||
-rw-r--r-- | tests/test-eds-ics-all-day-events.cpp | 9 | ||||
-rw-r--r-- | tests/test-eds-ics-missing-trigger.cpp | 76 | ||||
-rw-r--r-- | tests/test-eds-ics-non-attending-alarms.cpp | 7 | ||||
-rw-r--r-- | tests/test-eds-ics-nonrepeating-events.cpp | 9 | ||||
-rw-r--r-- | tests/test-eds-ics-repeating-events.cpp | 9 | ||||
-rw-r--r-- | tests/test-eds-ics-tzids-2.cpp | 39 | ||||
-rw-r--r-- | tests/test-eds-ics-tzids-utc.cpp | 36 | ||||
-rw-r--r-- | tests/test-eds-ics-tzids.cpp | 37 | ||||
-rw-r--r-- | tests/test-menus.cpp | 34 | ||||
-rw-r--r-- | tests/test-notification-response.cpp | 2 | ||||
-rw-r--r-- | tests/test-sound.cpp | 57 |
16 files changed, 388 insertions, 110 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b9b1d7..13dd0d8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,39 +41,35 @@ function(add_test_by_name name) add_test (${TEST_NAME} ${TEST_NAME}) target_link_libraries (${TEST_NAME} indicatordatetimeservice ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) endfunction() + add_test_by_name(test-datetime) +add_test_by_name(test-sound) if (ENABLE_LOMIRI_FEATURES) - add_test_by_name(test-sound) - # This one only succeeds on Lomiri because it needs hfd-service - # add_test_by_name(test-notification) - add_test_by_name(test-notification-response) -endif() + add_test_by_name(test-notification) +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) -# This one is fine, but hangs on Travis CI -# add_test_by_name(test-exporter) +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) -# This one is fine, but hangs on Travis CI -# add_test_by_name(test-menus) +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 (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 @@ -108,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/notification-fixture.h b/tests/notification-fixture.h index 2349bab..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 @@ -77,7 +77,9 @@ protected: static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"}; - static constexpr char const * HINT_TIMEOUT {"x-lomiri-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.lomiri.touch.AccountsService.Sound"}; @@ -312,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/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-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 93bc9e3..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 @@ -81,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}; @@ -93,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 5d98f81..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-2022 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 @@ -62,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 @@ -78,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@lomiri-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@lomiri-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 }, @@ -113,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-non-attending-alarms.cpp b/tests/test-eds-ics-non-attending-alarms.cpp index ca1c8ed..629c1fc 100644 --- a/tests/test-eds-ics-non-attending-alarms.cpp +++ b/tests/test-eds-ics-non-attending-alarms.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 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 @@ -81,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-nonrepeating-events.cpp b/tests/test-eds-ics-nonrepeating-events.cpp index 06b6b95..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-2022 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 @@ -81,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)}) @@ -93,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-repeating-events.cpp b/tests/test-eds-ics-repeating-events.cpp index 2be5aa5..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-2022 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 @@ -81,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)}), @@ -100,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-tzids-2.cpp b/tests/test-eds-ics-tzids-2.cpp index 36ef0fe..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-2022 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 @@ -79,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 3a79485..d88e95d 100644 --- a/tests/test-eds-ics-tzids-utc.cpp +++ b/tests/test-eds-ics-tzids-utc.cpp @@ -1,6 +1,6 @@ /* * Copyright 2015 Canonical Ltd. - * Copyright 2021-2022 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 @@ -80,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 c6b4dc4..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-2022 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 @@ -79,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-menus.cpp b/tests/test-menus.cpp index 1f73193..ea8cb30 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -272,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 @@ -324,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-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); |