diff options
-rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/accounts.db | bin | 0 -> 19456 bytes | |||
-rwxr-xr-x | tests/run-eds-ics-test.sh | 8 | ||||
-rw-r--r-- | tests/test-eds-ics-non-attending-alarms.cpp | 103 | ||||
-rw-r--r-- | tests/test-eds-ics-non-attending-alarms.ics.in | 22 |
5 files changed, 136 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 48e2004..4b9a804 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -90,7 +90,8 @@ function(add_eds_ics_test_by_name name) ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} # arg2: test executable path ${TEST_NAME} # arg3: test name ${CMAKE_CURRENT_SOURCE_DIR}/test-eds-ics-config-files # arg4: base directory for config file template - ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.ics) # arg5: the ical file for this test + ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.ics # arg5: the ical file for this test + ${CMAKE_CURRENT_SOURCE_DIR}/accounts.db) # arg6: online accounts database endfunction() add_eds_ics_test_by_name(test-eds-ics-all-day-events) add_eds_ics_test_by_name(test-eds-ics-repeating-events) @@ -100,6 +101,7 @@ add_eds_ics_test_by_name(test-eds-ics-missing-trigger) add_eds_ics_test_by_name(test-eds-ics-tzids) 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) # disabling the timezone unit tests because they require # https://code.launchpad.net/~ted/dbus-test-runner/multi-interface-test/+merge/199724 diff --git a/tests/accounts.db b/tests/accounts.db Binary files differnew file mode 100644 index 0000000..ece5b2f --- /dev/null +++ b/tests/accounts.db diff --git a/tests/run-eds-ics-test.sh b/tests/run-eds-ics-test.sh index 13c1617..b38fe77 100755 --- a/tests/run-eds-ics-test.sh +++ b/tests/run-eds-ics-test.sh @@ -6,6 +6,7 @@ TEST_EXEC=$2 # full executable path of test app TEST_NAME=$3 # test name CONFIG_DIR=$4 # config files ICS_FILE=$5 # ical file holding test data +ACCOUNTS_DB=$6 # online account database echo "this script: ${SELF}" echo "test-runner: ${TEST_RUNNER}" @@ -55,6 +56,13 @@ if [ -e ${ICS_FILE} ]; then cp --verbose --archive ${ICS_FILE} ${XDG_DATA_HOME}/evolution/tasks/system/tasks.ics fi +# prepare online accounts database +if [ -e ${ACCOUNTS_DB} ]; then + echo "copying ${ACCOUNTS_DB} into $HOME" + mkdir -p ${XDG_CONFIG_HOME}/libaccounts-glib/ + cp --verbose --archive ${ACCOUNTS_DB} ${XDG_CONFIG_HOME}/libaccounts-glib/accounts.db +fi + # run the test ${TEST_RUNNER} --keep-env --max-wait=90 --task ${TEST_EXEC} --task-name ${TEST_NAME} --wait-until-complete rv=$? diff --git a/tests/test-eds-ics-non-attending-alarms.cpp b/tests/test-eds-ics-non-attending-alarms.cpp new file mode 100644 index 0000000..c2c7933 --- /dev/null +++ b/tests/test-eds-ics-non-attending-alarms.cpp @@ -0,0 +1,103 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Charles Kerr <charles.kerr@canonical.com> + */ + +#include <algorithm> + +#include <datetime/alarm-queue-simple.h> +#include <datetime/clock-mock.h> +#include <datetime/engine-eds.h> +#include <datetime/planner-range.h> + +#include <gtest/gtest.h> + +#include "glib-fixture.h" +#include "print-to.h" +#include "timezone-mock.h" +#include "wakeup-timer-mock.h" + +using namespace ayatana::indicator::datetime; +using VAlarmFixture = GlibFixture; + +/*** +**** +***/ + +TEST_F(VAlarmFixture, NonAttendingEvent) +{ + // start the EDS engine + auto engine = std::make_shared<EdsEngine>(); + + // 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 2016 in EDS + auto planner = std::make_shared<SimpleRangePlanner>(engine, tz); + const DateTime range_begin {gtz, 2016,1, 1, 0, 0, 0.0}; + const DateTime range_end {gtz, 2016,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_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(); + ASSERT_EQ(0, appts.size()); + + /* + // 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<MockClock>(range_begin); + std::shared_ptr<Clock> clock = mock_clock; + std::shared_ptr<WakeupTimer> wakeup_timer = std::make_shared<MockWakeupTimer>(clock); + auto alarm_queue = std::make_shared<SimpleAlarmQueue>(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; now<range_end; now+=std::chrono::minutes{1}) + mock_clock->set_localtime(now); + EXPECT_EQ(appt.alarms.size(), triggered_count); + */ + + // cleanup + g_time_zone_unref(gtz); +} diff --git a/tests/test-eds-ics-non-attending-alarms.ics.in b/tests/test-eds-ics-non-attending-alarms.ics.in new file mode 100644 index 0000000..444b2d1 --- /dev/null +++ b/tests/test-eds-ics-non-attending-alarms.ics.in @@ -0,0 +1,22 @@ +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:g9nur97k1pmj4uop7n3q994rdo +DTSTAMP:20160328T183018Z +DTSTART:20160328T170000Z +DTEND:20160328T180000Z +SUMMARY:Meeting +ATTENDEE;MEMBER=;ROLE=REQ-PARTICIPANT;PARTSTAT=DECLINED;RSVP=FALSE; + CN=Uphablet:mailto:uphablet@lomiri.com +SEQUENCE:1 +LAST-MODIFIED:20160328T183018Z +BEGIN:VALARM +X-EVOLUTION-ALARM-UID:20160328T183018Z-29840-32011-1844-2 +ACTION:AUDIO +TRIGGER;VALUE=DURATION;RELATED=START:-PT30M +END:VALARM +END:VEVENT +END:VCALENDAR |