diff options
Diffstat (limited to 'tests')
24 files changed, 411 insertions, 297 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 247761f..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} ${COMPILE_FLAGS}") - # dbustest pkg_check_modules(DBUSTEST REQUIRED dbustest-1>=14.04.0) @@ -43,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 @@ -110,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/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 3eeb919..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@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 }, @@ -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-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-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-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-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-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-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); |