2
* Copyright 2016 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Renato Araujo Oliveira Filho <renato.filho@canonical.com>
22
#include <datetime/alarm-queue-simple.h>
23
#include <datetime/clock-mock.h>
24
#include <datetime/engine-eds.h>
25
#include <datetime/myself.h>
26
#include <datetime/planner-range.h>
28
#include <gtest/gtest.h>
30
#include "glib-fixture.h"
32
#include "timezone-mock.h"
33
#include "wakeup-timer-mock.h"
35
using namespace unity::indicator::datetime;
36
using VAlarmFixture = GlibFixture;
42
TEST_F(VAlarmFixture, RepeatingEventsWithIndividualChange)
44
// start the EDS engine
45
auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
47
// we need a consistent timezone for the planner and our local DateTimes
48
constexpr char const * zone_str {"America/Recife"};
49
auto tz = std::make_shared<MockTimezone>(zone_str);
50
auto gtz = g_time_zone_new(zone_str);
52
// make a planner that looks at the year of 2016 in EDS
53
auto planner = std::make_shared<SimpleRangePlanner>(engine, tz);
54
const DateTime range_begin {gtz, 2016,1, 1, 0, 0, 0.0};
55
const DateTime range_end {gtz, 2016,12,31,23,59,59.5};
56
planner->range().set(std::make_pair(range_begin, range_end));
58
// give EDS a moment to load
59
if (planner->appointments().get().empty()) {
60
g_message("waiting a moment for EDS to load...");
61
auto on_appointments_changed = [this](const std::vector<Appointment>& appointments){
62
g_message("ah, they loaded");
63
if (!appointments.empty())
64
g_main_loop_quit(loop);
66
core::ScopedConnection conn(planner->appointments().changed().connect(on_appointments_changed));
67
constexpr int max_wait_sec = 10;
68
wait_msec(max_wait_sec * G_TIME_SPAN_MILLISECOND);
71
// what we expect to get...
72
Appointment expected_appt;
73
expected_appt.summary = "Alarm";
74
std::array<DateTime,10> expected_times = {
75
DateTime(gtz,2016,6, 20,10,00,0),
76
DateTime(gtz,2016,6, 21,10,00,0),
77
DateTime(gtz,2016,6, 22,10,00,0),
78
DateTime(gtz,2016,6, 23,10,00,0),
79
DateTime(gtz,2016,6, 24,20,00,0),
80
DateTime(gtz,2016,6, 25,10,00,0),
81
DateTime(gtz,2016,6, 26,10,00,0),
82
DateTime(gtz,2016,6, 27,10,00,0),
83
DateTime(gtz,2016,6, 28,10,00,0),
84
DateTime(gtz,2016,6, 29,10,00,0)
87
// compare it to what we actually loaded...
88
const auto appts = planner->appointments().get();
89
EXPECT_EQ(expected_times.size(), appts.size());
90
for (size_t i=0, n=expected_times.size(); i<n; i++) {
91
const auto& appt = appts[i];
93
EXPECT_EQ("Every day and every night", appt.summary);
95
EXPECT_EQ("At night", appt.summary);
96
EXPECT_EQ(expected_times[i], appt.begin);
100
g_time_zone_unref(gtz);