From fff19d70649589b81a896e4deb032a7bd4bdca1e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 31 Mar 2015 18:54:04 -0500 Subject: add an Alarm class to represent ical valarm components; change the Appointment class to hold an arbitrary number of Alarms. --- tests/manual-test-snap.cpp | 10 +++++----- tests/test-live-actions.cpp | 6 ------ tests/test-snap.cpp | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 22ef137..cbe79cd 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -67,18 +67,18 @@ int main(int argc, const char* argv[]) Appointment a; a.color = "green"; a.summary = "Alarm"; - a.url = "alarm:///hello-world"; a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402"; a.type = Appointment::UBUNTU_ALARM; a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0); a.end = a.begin.end_of_day(); + a.alarms.push_back(Alarm{"Alarm Text", "", a.begin, std::chrono::seconds::zero()}); auto loop = g_main_loop_new(nullptr, false); - auto on_snooze = [loop](const Appointment& appt){ - g_message("You clicked 'Snooze' for appt url '%s'", appt.url.c_str()); + auto on_snooze = [loop](const Appointment& appt, const Alarm&){ + g_message("You clicked 'Snooze' for appt url '%s'", appt.summary.c_str()); g_idle_add(quit_idle, loop); }; - auto on_ok = [loop](const Appointment&){ + auto on_ok = [loop](const Appointment&, const Alarm&){ g_message("You clicked 'OK'"); g_idle_add(quit_idle, loop); }; @@ -93,7 +93,7 @@ int main(int argc, const char* argv[]) auto notification_engine = std::make_shared("indicator-datetime-service"); Snap snap (notification_engine, settings); - snap(a, on_snooze, on_ok); + snap(a, a.alarms.front(), on_snooze, on_ok); g_main_loop_run(loop); g_main_loop_unref(loop); diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 1a34511..4f84f25 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -319,10 +319,6 @@ TEST_F(LiveActionsFixture, PhoneOpenAppointment) a.type = Appointment::UBUNTU_ALARM; m_actions->phone_open_appointment(a); EXPECT_EQ(clock_app_url, m_live_actions->last_url); - - a.url = "appid://blah"; - m_actions->phone_open_appointment(a); - EXPECT_EQ(a.url, m_live_actions->last_url); } TEST_F(LiveActionsFixture, PhoneOpenCalendarApp) @@ -392,7 +388,6 @@ TEST_F(LiveActionsFixture, CalendarState) Appointment a1; a1.color = "green"; a1.summary = "write unit tests"; - a1.url = "http://www.ubuntu.com/"; a1.uid = "D4B57D50247291478ED31DED17FF0A9838DED402"; a1.begin = tomorrow_begin; a1.end = tomorrow_end; @@ -403,7 +398,6 @@ TEST_F(LiveActionsFixture, CalendarState) Appointment a2; a2.color = "orange"; a2.summary = "code review"; - a2.url = "http://www.ubuntu.com/"; a2.uid = "2756ff7de3745bbffd65d2e4779c37c7ca60d843"; a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 3dd4501..2e29132 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -106,12 +106,12 @@ protected: // init the Appointment appt.color = "green"; appt.summary = "Alarm"; - appt.url = "alarm:///hello-world"; appt.uid = "D4B57D50247291478ED31DED17FF0A9838DED402"; appt.type = Appointment::EVENT; const auto christmas = DateTime::Local(2015,12,25,0,0,0); appt.begin = christmas.start_of_day(); appt.end = christmas.end_of_day(); + appt.alarms.push_back(Alarm{"Alarm Text", "", appt.begin, std::chrono::seconds::zero()}); service = dbus_test_service_new(nullptr); @@ -343,8 +343,8 @@ TEST_F(SnapFixture, InteractiveDuration) make_interactive(); // call the Snap Decision - auto func = [this](const Appointment&){g_idle_add(quit_idle, loop);}; - snap(appt, func, func); + auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);}; + snap(appt, appt.alarms.front(), func, func); // confirm that Notify got called once guint len = 0; @@ -393,8 +393,8 @@ TEST_F(SnapFixture, InhibitSleep) make_interactive(); // invoke the notification - auto func = [this](const Appointment&){g_idle_add(quit_idle, loop);}; - (*snap)(appt, func, func); + auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);}; + (*snap)(appt, appt.alarms.front(), func, func); wait_msec(1000); @@ -448,8 +448,8 @@ TEST_F(SnapFixture, ForceScreen) make_interactive(); // invoke the notification - auto func = [this](const Appointment&){g_idle_add(quit_idle, loop);}; - (*snap)(appt, func, func); + auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);}; + (*snap)(appt, appt.alarms.front(), func, func); wait_msec(1000); @@ -484,14 +484,14 @@ TEST_F(SnapFixture, HapticModes) { auto settings = std::make_shared(); auto ne = std::make_shared(APP_NAME); - auto func = [this](const Appointment&){g_idle_add(quit_idle, loop);}; + auto func = [this](const Appointment&, const Alarm&){g_idle_add(quit_idle, loop);}; GError * error = nullptr; // invoke a snap decision while haptic feedback is set to "pulse", // confirm that VibratePattern got called settings->alarm_haptic.set("pulse"); auto snap = new Snap (ne, settings); - (*snap)(appt, func, func); + (*snap)(appt, appt.alarms.front(), func, func); wait_msec(100); EXPECT_TRUE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, haptic_obj, @@ -506,7 +506,7 @@ TEST_F(SnapFixture, HapticModes) dbus_test_dbus_mock_object_clear_method_calls (haptic_mock, haptic_obj, &error); settings->alarm_haptic.set("none"); snap = new Snap (ne, settings); - (*snap)(appt, func, func); + (*snap)(appt, appt.alarms.front(), func, func); wait_msec(100); EXPECT_FALSE (dbus_test_dbus_mock_object_check_method_call (haptic_mock, haptic_obj, -- cgit v1.2.3 From 8c7daeeb87abd0be1b96169da18baf018c4859c9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 3 Apr 2015 13:11:39 -0500 Subject: add the new Alarm class as an argument to the alarm queue class --- tests/test-alarm-queue.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index 3fdf787..fdab425 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -48,7 +48,7 @@ protected: m_range_planner.reset(new MockRangePlanner); m_upcoming.reset(new UpcomingPlanner(m_range_planner, m_state->clock->localtime())); m_watcher.reset(new SimpleAlarmQueue(m_state->clock, m_upcoming, m_wakeup_timer)); - m_watcher->alarm_reached().connect([this](const Appointment& appt){ + m_watcher->alarm_reached().connect([this](const Appointment& appt, const Alarm& /*alarm*/){ m_triggered.push_back(appt.uid); }); @@ -71,7 +71,7 @@ protected: const auto tomorrow_begin = now.add_days(1).start_of_day(); const auto tomorrow_end = tomorrow_begin.end_of_day(); - Appointment a1; // an alarm clock appointment + Appointment a1; // an ubuntu alarm a1.color = "red"; a1.summary = "Alarm"; a1.summary = "http://www.example.com/"; @@ -79,18 +79,20 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; + a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin, std::chrono::seconds::zero()}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); - Appointment a2; // a non-alarm appointment + Appointment a2; // something else 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 = ubermorgen_begin; a2.end = ubermorgen_end; + a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin, std::chrono::seconds::zero()}); return std::vector({a1, a2}); } @@ -105,7 +107,7 @@ TEST_F(AlarmQueueFixture, AppointmentsChanged) // Add some appointments to the planner. // One of these matches our state's localtime, so that should get triggered. std::vector a = build_some_appointments(); - a[0].begin = m_state->clock->localtime(); + a[0].begin = a[0].alarms.front().time = m_state->clock->localtime(); m_range_planner->appointments().set(a); // Confirm that it got fired @@ -135,7 +137,8 @@ TEST_F(AlarmQueueFixture, MoreThanOne) { const auto now = m_state->clock->localtime(); std::vector a = build_some_appointments(); - a[0].begin = a[1].begin = now; + a[0].alarms.front().time = now; + a[1].alarms.front().time = now; m_range_planner->appointments().set(a); ASSERT_EQ(2, m_triggered.size()); @@ -151,7 +154,7 @@ TEST_F(AlarmQueueFixture, NoDuplicates) const std::vector appointments = build_some_appointments(); std::vector a; a.push_back(appointments[0]); - a[0].begin = now; + a[0].alarms.front().time = now; m_range_planner->appointments().set(a); ASSERT_EQ(1, m_triggered.size()); EXPECT_EQ(a[0].uid, m_triggered[0]); -- cgit v1.2.3 From 62d68e6453c0ad69ff4d71099441a8151e9a9bea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 17:27:52 -0500 Subject: fix misuse of ECalComponentAlarmInstance's fields. --- tests/manual-test-snap.cpp | 2 +- tests/test-alarm-queue.cpp | 4 ++-- tests/test-snap.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index cbe79cd..d04cf14 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) a.type = Appointment::UBUNTU_ALARM; a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0); a.end = a.begin.end_of_day(); - a.alarms.push_back(Alarm{"Alarm Text", "", a.begin, std::chrono::seconds::zero()}); + a.alarms.push_back(Alarm{"Alarm Text", "", a.begin}); auto loop = g_main_loop_new(nullptr, false); auto on_snooze = [loop](const Appointment& appt, const Alarm&){ diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp index fdab425..aa35668 100644 --- a/tests/test-alarm-queue.cpp +++ b/tests/test-alarm-queue.cpp @@ -79,7 +79,7 @@ protected: a1.type = Appointment::UBUNTU_ALARM; a1.begin = tomorrow_begin; a1.end = tomorrow_end; - a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin, std::chrono::seconds::zero()}); + a1.alarms.push_back(Alarm{"Alarm Text", "", a1.begin}); const auto ubermorgen_begin = now.add_days(2).start_of_day(); const auto ubermorgen_end = ubermorgen_begin.end_of_day(); @@ -92,7 +92,7 @@ protected: a2.type = Appointment::EVENT; a2.begin = ubermorgen_begin; a2.end = ubermorgen_end; - a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin, std::chrono::seconds::zero()}); + a2.alarms.push_back(Alarm{"Alarm Text", "", a2.begin}); return std::vector({a1, a2}); } diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp index 2e29132..46fbd10 100644 --- a/tests/test-snap.cpp +++ b/tests/test-snap.cpp @@ -111,7 +111,7 @@ protected: const auto christmas = DateTime::Local(2015,12,25,0,0,0); appt.begin = christmas.start_of_day(); appt.end = christmas.end_of_day(); - appt.alarms.push_back(Alarm{"Alarm Text", "", appt.begin, std::chrono::seconds::zero()}); + appt.alarms.push_back(Alarm{"Alarm Text", "", appt.begin}); service = dbus_test_service_new(nullptr); -- cgit v1.2.3 From a0a6516e74f3b400058af01babfba61bdb1516eb Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 19:19:01 -0500 Subject: add EDS tests to confirm valarm attachments are loaded properly and trigger in the AlarmQueue --- tests/CMakeLists.txt | 37 ++++++- tests/run-eds-test.sh | 48 +++++++++ .../.config/evolution/sources/system-proxy.source | 21 ++++ .../share/evolution/calendar/system/calendar.ics | 47 +++++++++ tests/test-eds-valarms.cpp | 113 +++++++++++++++++++++ tests/timezone-mock.h | 1 + tests/wakeup-timer-mock.h | 78 ++++++++++++++ 7 files changed, 341 insertions(+), 4 deletions(-) create mode 100755 tests/run-eds-test.sh create mode 100644 tests/test-eds-valarms-config-files/.config/evolution/sources/system-proxy.source create mode 100644 tests/test-eds-valarms-config-files/.local/share/evolution/calendar/system/calendar.ics create mode 100644 tests/test-eds-valarms.cpp create mode 100644 tests/wakeup-timer-mock.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 25fe5dc..8b6ec5d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,12 +39,10 @@ include_directories (${DBUSTEST_INCLUDE_DIRS}) add_definitions (-DSANDBOX="${CMAKE_CURRENT_BINARY_DIR}") - function(add_test_by_name name) set (TEST_NAME ${name}) add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) add_test (${TEST_NAME} ${TEST_NAME}) - add_dependencies (${TEST_NAME} libindicatordatetimeservice) target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) endfunction() add_test_by_name(test-datetime) @@ -65,9 +63,41 @@ add_test_by_name(test-utils) set (TEST_NAME manual-test-snap) add_executable (${TEST_NAME} ${TEST_NAME}.cpp) -add_dependencies (${TEST_NAME} libindicatordatetimeservice) target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) +## +## EDS Tests +## + +find_program(DBUS_RUNNER dbus-test-runner) +find_program(EVOLUTION_CALENDAR_FACTORY evolution-calendar-factory PATHS /usr/lib/evolution/) +find_program(EVOLUTION_SOURCE_REGISTRY evolution-source-registry PATHS /usr/lib/evolution/) +find_program(GVFSD gvfsd PATHS /usr/lib/gvfs/) +OPTION(EVOLUTION_SOURCE_SERVICE_NAME "DBus name for source registry") +if(NOT EVOLUTION_SOURCE_SERVICE_NAME) + set(EVOLUTION_SOURCE_SERVICE_NAME "org.gnome.evolution.dataserver.Sources3") +endif() + +function(add_eds_test_by_name name) + set (TEST_NAME ${name}) + add_executable(${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) + target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) + add_test (${TEST_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/run-eds-test.sh + ${DBUS_RUNNER} # arg1: dbus-test-runner exec + ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} # arg2: test executable path + ${TEST_NAME} # arg3: test name + ${EVOLUTION_CALENDAR_FACTORY} # arg4: evolution-calendar-factory exec + ${EVOLUTION_SOURCE_SERVICE_NAME} # arg5: dbus name for source registry + ${EVOLUTION_SOURCE_REGISTRY} # arg6: evolution-source-registry exec + ${GVFSD} # arg7: gvfsd exec + ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}-config-files) # arg8: canned config files +endfunction() +add_eds_test_by_name(test-eds-valarms) + + + + # disabling the timezone unit tests because they require # https://code.launchpad.net/~ted/dbus-test-runner/multi-interface-test/+merge/199724 # which hasn't landed yet. These can be re-enabled as soon as that lands. @@ -75,7 +105,6 @@ target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEP # set (TEST_NAME ${name}) # add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) # add_test (${TEST_NAME} ${TEST_NAME}) -# add_dependencies (${TEST_NAME} libindicatordatetimeservice) # target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${SERVICE_DEPS_LIBRARIES} ${DBUSTEST_LIBRARIES} ${GTEST_LIBS}) #endfunction() #add_dbusmock_test_by_name(test-timezone-geoclue) diff --git a/tests/run-eds-test.sh b/tests/run-eds-test.sh new file mode 100755 index 0000000..6e6f575 --- /dev/null +++ b/tests/run-eds-test.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +echo ARG0=$0 # this script +echo ARG1=$1 # full executable path of dbus-test-runner +echo ARG2=$2 # full executable path of test app +echo ARG3=$3 # test name +echo ARG4=$4 # full executable path of evolution-calendar-factory +echo ARG5=$5 # bus service name of calendar factory +echo ARG6=$6 # full exectuable path of evolution-source-registry +echo ARG7=$7 # full executable path of gvfs +echo ARG8=$8 # config files + +export TEST_TMP_DIR=$(mktemp -p "${TMPDIR:-.}" -d $3-XXXXXXXXXX) || exit 1 +trap 'rm -rf $TEST_TMP_DIR' EXIT +echo "running test '$3' in ${TEST_TMP_DIR}" + +export QT_QPA_PLATFORM=minimal +export HOME=${TEST_TMP_DIR} +export XDG_RUNTIME_DIR=${TEST_TMP_DIR} +export XDG_CACHE_HOME=${TEST_TMP_DIR}/.cache +export XDG_CONFIG_HOME=${TEST_TMP_DIR}/.config +export XDG_DATA_HOME=${TEST_TMP_DIR}/.local/share +export XDG_DESKTOP_DIR=${TEST_TMP_DIR} +export XDG_DOCUMENTS_DIR=${TEST_TMP_DIR} +export XDG_DOWNLOAD_DIR=${TEST_TMP_DIR} +export XDG_MUSIC_DIR=${TEST_TMP_DIR} +export XDG_PICTURES_DIR=${TEST_TMP_DIR} +export XDG_PUBLICSHARE_DIR=${TEST_TMP_DIR} +export XDG_TEMPLATES_DIR=${TEST_TMP_DIR} +export XDG_VIDEOS_DIR=${TEST_TMP_DIR} +export QORGANIZER_EDS_DEBUG=On +export GIO_USE_VFS=local # needed to ensure GVFS shuts down cleanly after the test is over + +echo HOMEDIR=${HOME} +rm -rf ${XDG_DATA_HOME} + +# if there are canned config files for this test, move them into place now +if [ -d $8 ]; then + echo "copying files from $8 to $HOME" + cp --verbose --archive $8/. $HOME +fi + +$1 --keep-env --max-wait=90 \ +--task $2 --task-name $3 --wait-until-complete --wait-for=org.gnome.evolution.dataserver.Calendar4 \ +--task $4 --task-name "evolution" --wait-until-complete -r +#--task $6 --task-name "source-registry" --wait-for=org.gtk.vfs.Daemon -r \ +#--task $7 --task-name "gvfsd" -r +return $? diff --git a/tests/test-eds-valarms-config-files/.config/evolution/sources/system-proxy.source b/tests/test-eds-valarms-config-files/.config/evolution/sources/system-proxy.source new file mode 100644 index 0000000..4b2f666 --- /dev/null +++ b/tests/test-eds-valarms-config-files/.config/evolution/sources/system-proxy.source @@ -0,0 +1,21 @@ + +[Data Source] +DisplayName=Default Proxy Settings +Enabled=true +Parent= + +[Proxy] +Method=default +IgnoreHosts=localhost;127.0.0.0/8;::1; +AutoconfigUrl= +FtpHost= +FtpPort=0 +HttpAuthPassword= +HttpAuthUser= +HttpHost= +HttpPort=8080 +HttpUseAuth=false +HttpsHost= +HttpsPort=0 +SocksHost= +SocksPort=0 diff --git a/tests/test-eds-valarms-config-files/.local/share/evolution/calendar/system/calendar.ics b/tests/test-eds-valarms-config-files/.local/share/evolution/calendar/system/calendar.ics new file mode 100644 index 0000000..fe526f4 --- /dev/null +++ b/tests/test-eds-valarms-config-files/.local/share/evolution/calendar/system/calendar.ics @@ -0,0 +1,47 @@ +BEGIN:VCALENDAR +CALSCALE:GREGORIAN +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 +DTSTAMP:20150405T213247Z +DTSTART:20150424T183500Z +DTEND:20150424T193554Z +X-LIC-ERROR;X-LIC-ERRORTYPE=VALUE-PARSE-ERROR:Can't parse as RECUR value + in RRULE property. Removing entire property: ERROR: No Value +SUMMARY:London Sprint Flight +CREATED:20150405T213247Z +LAST-MODIFIED:20150405T213247Z +BEGIN:VALARM +X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-2@ubuntu-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 +ACTION:DISPLAY +DESCRIPTION:Time to pack! +TRIGGER;VALUE=DURATION;RELATED=START:-P1D +REPEAT:3 +DURATION:PT2M +END:VALARM +BEGIN:VALARM +X-EVOLUTION-ALARM-UID:20150405T213247Z-4371-32011-1698-5@ubuntu-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 +ACTION:DISPLAY +DESCRIPTION:Go to the airport! +TRIGGER;VALUE=DURATION;RELATED=START:-PT3H +REPEAT:3 +DURATION:PT2M +END:VALARM +END:VEVENT +END:VCALENDAR diff --git a/tests/test-eds-valarms.cpp b/tests/test-eds-valarms.cpp new file mode 100644 index 0000000..f30539a --- /dev/null +++ b/tests/test-eds-valarms.cpp @@ -0,0 +1,113 @@ +/* + * Copyright 2015 Canonical Ltd. + * + * 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 . + * + * Authors: + * Charles Kerr + */ + +#include + +#include + +#include +#include +#include +#include + +#include + +#include "glib-fixture.h" +#include "timezone-mock.h" +#include "wakeup-timer-mock.h" + + +using namespace unity::indicator::datetime; + +class VAlarmFixture: public GlibFixture +{ +private: + + typedef GlibFixture super; + +protected: + + void SetUp() + { + super::SetUp(); + } + + void TearDown() + { + super::TearDown(); + } +}; + +/*** +**** +***/ + +TEST_F(VAlarmFixture, MultipleAppointments) +{ + // start the EDS engine + auto engine = std::make_shared(); + + // make a planner that looks at the first half of 2015 in EDS + auto tz = std::make_shared("America/Chicago"); + auto planner = std::make_shared(engine, tz); + const auto range_begin = DateTime::Local(2015,1, 1, 0, 0, 0.0); + const auto range_end = DateTime::Local(2015,6,31,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_debug("waiting a moment for EDS to load..."); + auto on_appointments_changed = [this](const std::vector& appointments){ + g_debug("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); + } + + const auto appts = planner->appointments().get(); + ASSERT_EQ(1, appts.size()); + const auto& appt = appts.front(); + ASSERT_EQ(8, appt.alarms.size()); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,35,0)}), appt.alarms[0]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,37,0)}), appt.alarms[1]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,39,0)}), appt.alarms[2]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,41,0)}), appt.alarms[3]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,35,0)}), appt.alarms[4]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,37,0)}), appt.alarms[5]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,39,0)}), appt.alarms[6]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,41,0)}), appt.alarms[7]); + + // now let's try this out with AlarmQueue... + // hook the planner up to a SimpleAlarmQueue and confirm that it triggers for each of the reminders + auto mock_clock = std::make_shared(range_begin); + std::shared_ptr clock = mock_clock; + std::shared_ptr wakeup_timer = std::make_shared(clock); + auto alarm_queue = std::make_shared(clock, planner, wakeup_timer); + int triggered_count = 0; + alarm_queue->alarm_reached().connect([&triggered_count, appt](const Appointment&, const Alarm& active_alarm) { + EXPECT_TRUE(std::find(appt.alarms.begin(), appt.alarms.end(), active_alarm) != appt.alarms.end()); + ++triggered_count; + }); + for (auto now=range_begin; nowset_localtime(now); + EXPECT_EQ(appt.alarms.size(), triggered_count); +} diff --git a/tests/timezone-mock.h b/tests/timezone-mock.h index 67584cb..55151aa 100644 --- a/tests/timezone-mock.h +++ b/tests/timezone-mock.h @@ -30,6 +30,7 @@ class MockTimezone: public Timezone { public: MockTimezone() =default; + explicit MockTimezone(const std::string& zone) {timezone.set(zone);} ~MockTimezone() =default; }; diff --git a/tests/wakeup-timer-mock.h b/tests/wakeup-timer-mock.h new file mode 100644 index 0000000..8a59c97 --- /dev/null +++ b/tests/wakeup-timer-mock.h @@ -0,0 +1,78 @@ +/* + * Copyright 2015 Canonical Ltd. + * + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_WAKEUP_TIMER_MOCK_H +#define INDICATOR_DATETIME_WAKEUP_TIMER_MOCK_H + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +/** + * \brief A one-shot timer that emits a signal when its timeout is reached. + */ +class MockWakeupTimer: public WakeupTimer +{ +public: + explicit MockWakeupTimer(const std::shared_ptr& clock): + m_clock(clock) + { + m_clock->minute_changed.connect([this](){ + test_for_wakeup(); + }); + } + + virtual ~MockWakeupTimer() =default; + + virtual void set_wakeup_time (const DateTime& wakeup_time) override { + m_wakeup_time = wakeup_time; + test_for_wakeup(); + } + + virtual core::Signal<>& timeout() override { return m_timeout; } + +private: + + void test_for_wakeup() + { + if (DateTime::is_same_minute(m_clock->localtime(), m_wakeup_time)) + m_timeout(); + } + + core::Signal<> m_timeout; + const std::shared_ptr& m_clock; + DateTime m_wakeup_time; +}; + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_WAKEUP_TIMER_MOCK_H -- cgit v1.2.3 From 13999bfbed4916149af24be2dc504461c4bdf0e9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 21:10:53 -0500 Subject: in tests/run-eds-test.sh, improve the comments --- tests/run-eds-test.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/run-eds-test.sh b/tests/run-eds-test.sh index 6e6f575..1f020ef 100755 --- a/tests/run-eds-test.sh +++ b/tests/run-eds-test.sh @@ -10,10 +10,12 @@ echo ARG6=$6 # full exectuable path of evolution-source-registry echo ARG7=$7 # full executable path of gvfs echo ARG8=$8 # config files +# set up the tmpdir and tell the shell to purge it when we exit export TEST_TMP_DIR=$(mktemp -p "${TMPDIR:-.}" -d $3-XXXXXXXXXX) || exit 1 trap 'rm -rf $TEST_TMP_DIR' EXIT echo "running test '$3' in ${TEST_TMP_DIR}" +# set up the environment variables export QT_QPA_PLATFORM=minimal export HOME=${TEST_TMP_DIR} export XDG_RUNTIME_DIR=${TEST_TMP_DIR} @@ -40,6 +42,7 @@ if [ -d $8 ]; then cp --verbose --archive $8/. $HOME fi +# run dbus-test-runner $1 --keep-env --max-wait=90 \ --task $2 --task-name $3 --wait-until-complete --wait-for=org.gnome.evolution.dataserver.Calendar4 \ --task $4 --task-name "evolution" --wait-until-complete -r -- cgit v1.2.3 From 38a39c03d5b44c825afe0d10f67cc0802dcf2573 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 5 Apr 2015 21:12:01 -0500 Subject: remove some new bits that turned out to be unneeded after all --- tests/test-eds-valarms.cpp | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/test-eds-valarms.cpp b/tests/test-eds-valarms.cpp index f30539a..e9e07d8 100644 --- a/tests/test-eds-valarms.cpp +++ b/tests/test-eds-valarms.cpp @@ -19,8 +19,6 @@ #include -#include - #include #include #include @@ -32,27 +30,8 @@ #include "timezone-mock.h" #include "wakeup-timer-mock.h" - using namespace unity::indicator::datetime; - -class VAlarmFixture: public GlibFixture -{ -private: - - typedef GlibFixture super; - -protected: - - void SetUp() - { - super::SetUp(); - } - - void TearDown() - { - super::TearDown(); - } -}; +using VAlarmFixture = GlibFixture; /*** **** @@ -83,6 +62,7 @@ TEST_F(VAlarmFixture, MultipleAppointments) 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(); ASSERT_EQ(1, appts.size()); const auto& appt = appts.front(); -- cgit v1.2.3 From af81477b2f5d4ffc76c51c72bd3ac89a4c4cac64 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Apr 2015 10:20:49 -0500 Subject: in the unit tests, add a PrintTo function for Alarms so that GTest can represent it as a string --- tests/print-to.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ tests/test-eds-valarms.cpp | 1 + 2 files changed, 46 insertions(+) create mode 100644 tests/print-to.h (limited to 'tests') diff --git a/tests/print-to.h b/tests/print-to.h new file mode 100644 index 0000000..78cf574 --- /dev/null +++ b/tests/print-to.h @@ -0,0 +1,45 @@ +/* + * Copyright 2015 Canonical Ltd. + * + * 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 . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_TESTS_PRINT_TO +#define INDICATOR_DATETIME_TESTS_PRINT_TO + +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** PrintTo() functions for GTest to represent objects as strings +***/ + +void +PrintTo(const Alarm& alarm, std::ostream* os) +{ + *os << "{text:'" << alarm.text << "', audio_url:'" << alarm.audio_url << "', time:'"< #include "glib-fixture.h" +#include "print-to.h" #include "timezone-mock.h" #include "wakeup-timer-mock.h" -- cgit v1.2.3 From a3c896c8dd8c82b1d622a3a1220df0870f84d573 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Apr 2015 13:16:42 -0500 Subject: in new EDS tests, use timezones consistently --- tests/test-eds-valarms.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/test-eds-valarms.cpp b/tests/test-eds-valarms.cpp index b92d190..47f29e7 100644 --- a/tests/test-eds-valarms.cpp +++ b/tests/test-eds-valarms.cpp @@ -43,18 +43,22 @@ TEST_F(VAlarmFixture, MultipleAppointments) // start the EDS engine auto engine = std::make_shared(); + // we need a consistent timezone for the planner and our local DateTimes + constexpr char const * zone_str {"America/Chicago"}; + auto tz = std::make_shared(zone_str); + auto gtz = g_time_zone_new(zone_str); + // make a planner that looks at the first half of 2015 in EDS - auto tz = std::make_shared("America/Chicago"); auto planner = std::make_shared(engine, tz); - const auto range_begin = DateTime::Local(2015,1, 1, 0, 0, 0.0); - const auto range_end = DateTime::Local(2015,6,31,23,59,59.5); + const DateTime range_begin {gtz, 2015,1, 1, 0, 0, 0.0}; + const DateTime range_end {gtz, 2015,6,31,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_debug("waiting a moment for EDS to load..."); + g_message("waiting a moment for EDS to load..."); auto on_appointments_changed = [this](const std::vector& appointments){ - g_debug("ah, they loaded"); + g_message("ah, they loaded"); if (!appointments.empty()) g_main_loop_quit(loop); }; @@ -68,14 +72,14 @@ TEST_F(VAlarmFixture, MultipleAppointments) ASSERT_EQ(1, appts.size()); const auto& appt = appts.front(); ASSERT_EQ(8, appt.alarms.size()); - EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,35,0)}), appt.alarms[0]); - EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,37,0)}), appt.alarms[1]); - EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,39,0)}), appt.alarms[2]); - EXPECT_EQ(Alarm({"Time to pack!", "", DateTime::Local(2015,4,23,13,41,0)}), appt.alarms[3]); - EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,35,0)}), appt.alarms[4]); - EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,37,0)}), appt.alarms[5]); - EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,39,0)}), appt.alarms[6]); - EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime::Local(2015,4,24,10,41,0)}), appt.alarms[7]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,35,0)}), appt.alarms[0]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,37,0)}), appt.alarms[1]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,39,0)}), appt.alarms[2]); + EXPECT_EQ(Alarm({"Time to pack!", "", DateTime(gtz,2015,4,23,13,41,0)}), appt.alarms[3]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,35,0)}), appt.alarms[4]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,37,0)}), appt.alarms[5]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,39,0)}), appt.alarms[6]); + EXPECT_EQ(Alarm({"Go to the airport!", "", DateTime(gtz,2015,4,24,10,41,0)}), appt.alarms[7]); // now let's try this out with AlarmQueue... // hook the planner up to a SimpleAlarmQueue and confirm that it triggers for each of the reminders @@ -91,4 +95,7 @@ TEST_F(VAlarmFixture, MultipleAppointments) for (auto now=range_begin; nowset_localtime(now); EXPECT_EQ(appt.alarms.size(), triggered_count); + + // cleanup + g_time_zone_unref(gtz); } -- cgit v1.2.3 From 10c574cc26a4a55d63eed7f3b846efb4d766dd6b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Apr 2015 15:09:16 -0500 Subject: in tests/run-eds-test.sh, only delete the tmpdir if the test passed. --- tests/run-eds-test.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/run-eds-test.sh b/tests/run-eds-test.sh index 1f020ef..0183350 100755 --- a/tests/run-eds-test.sh +++ b/tests/run-eds-test.sh @@ -11,8 +11,7 @@ echo ARG7=$7 # full executable path of gvfs echo ARG8=$8 # config files # set up the tmpdir and tell the shell to purge it when we exit -export TEST_TMP_DIR=$(mktemp -p "${TMPDIR:-.}" -d $3-XXXXXXXXXX) || exit 1 -trap 'rm -rf $TEST_TMP_DIR' EXIT +export TEST_TMP_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d $3-XXXXXXXXXX) || exit 1 echo "running test '$3' in ${TEST_TMP_DIR}" # set up the environment variables @@ -48,4 +47,11 @@ $1 --keep-env --max-wait=90 \ --task $4 --task-name "evolution" --wait-until-complete -r #--task $6 --task-name "source-registry" --wait-for=org.gtk.vfs.Daemon -r \ #--task $7 --task-name "gvfsd" -r -return $? +rv=$? + +# if the test passed, blow away the tmpdir +if [ $rv -eq 0 ]; then + rm -rf $TEST_TMP_DIR +fi + +return $rv -- cgit v1.2.3