2
* Copyright 2015 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
* Charles Kerr <charles.kerr@canonical.com>
22
#include <datetime/alarm-queue-simple.h>
23
#include <datetime/clock-mock.h>
24
#include <datetime/engine-eds.h>
25
#include <datetime/planner-range.h>
27
#include <gtest/gtest.h>
29
#include "glib-fixture.h"
31
#include "timezone-mock.h"
32
#include "wakeup-timer-mock.h"
34
using namespace unity::indicator::datetime;
35
using VAlarmFixture = GlibFixture;
41
TEST_F(VAlarmFixture, MultipleAppointments)
43
// start the EDS engine
44
auto engine = std::make_shared<EdsEngine>();
46
// we need a consistent timezone for the planner and our local DateTimes
47
constexpr char const * zone_str {"America/Chicago"};
48
auto tz = std::make_shared<MockTimezone>(zone_str);
49
auto gtz = g_time_zone_new(zone_str);
51
// make a planner that looks at the first half of 2015 in EDS
52
auto planner = std::make_shared<SimpleRangePlanner>(engine, tz);
53
const DateTime range_begin {gtz, 2015,1, 1, 0, 0, 0.0};
54
const DateTime range_end {gtz, 2015,6,31,23,59,59.5};
55
planner->range().set(std::make_pair(range_begin, range_end));
57
// give EDS a moment to load
58
if (planner->appointments().get().empty()) {
59
g_message("waiting a moment for EDS to load...");
60
auto on_appointments_changed = [this](const std::vector<Appointment>& appointments){
61
g_message("ah, they loaded");
62
if (!appointments.empty())
63
g_main_loop_quit(loop);
65
core::ScopedConnection conn(planner->appointments().changed().connect(on_appointments_changed));
66
constexpr int max_wait_sec = 10;
67
wait_msec(max_wait_sec * G_TIME_SPAN_MILLISECOND);
70
// what we expect to get...
71
Appointment expected_appt;
72
expected_appt.uid = "20150507T211449Z-4262-32011-1418-1@ubuntu-phablet";
73
expected_appt.color = "#becedd";
74
expected_appt.summary = "Alarm";
75
std::array<Alarm,8> expected_alarms = {
76
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,5, 8,16,40,0)}),
77
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,5,15,16,40,0)}),
78
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,5,22,16,40,0)}),
79
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,5,29,16,40,0)}),
80
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,6, 5,16,40,0)}),
81
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,6,12,16,40,0)}),
82
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,6,19,16,40,0)}),
83
Alarm({"Alarm", "file:///usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg", DateTime(gtz,2015,6,26,16,40,0)})
86
// compare it to what we actually loaded...
87
const auto appts = planner->appointments().get();
88
EXPECT_EQ(expected_alarms.size(), appts.size());
89
for (size_t i=0, n=expected_alarms.size(); i<n; i++) {
90
const auto& appt = appts[i];
91
EXPECT_EQ(expected_appt.uid, appt.uid);
92
EXPECT_EQ(expected_appt.color, appt.color);
93
EXPECT_EQ(expected_appt.summary, appt.summary);
94
EXPECT_EQ(1, appt.alarms.size());
95
EXPECT_EQ(expected_alarms[i], appt.alarms[0]);
99
g_time_zone_unref(gtz);