~dobey/indicator-datetime/build-parallel

« back to all changes in this revision

Viewing changes to tests/test-eds-ics-repeating-events-with-individual-change.cpp

  • Committer: Bileto Bot
  • Date: 2016-06-27 08:46:58 UTC
  • mfrom: (450.1.1 resync-trunk)
  • Revision ID: ci-train-bot@canonical.com-20160627084658-s17qv0l1agjpn1yk
No-change rebuild for libical soname change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2016 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authors:
17
 
 *   Renato Araujo Oliveira Filho <renato.filho@canonical.com>
18
 
 */
19
 
 
20
 
#include <algorithm>
21
 
 
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>
27
 
 
28
 
#include <gtest/gtest.h>
29
 
 
30
 
#include "glib-fixture.h"
31
 
#include "print-to.h"
32
 
#include "timezone-mock.h"
33
 
#include "wakeup-timer-mock.h"
34
 
 
35
 
using namespace unity::indicator::datetime;
36
 
using VAlarmFixture = GlibFixture;
37
 
 
38
 
/***
39
 
****
40
 
***/
41
 
 
42
 
TEST_F(VAlarmFixture, RepeatingEventsWithIndividualChange)
43
 
{
44
 
    // start the EDS engine
45
 
    auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
46
 
 
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);
51
 
 
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));
57
 
 
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);
65
 
        };
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);
69
 
    }
70
 
 
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)
85
 
    };
86
 
 
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];
92
 
        if (i != 4)
93
 
            EXPECT_EQ("Every day and every night", appt.summary);
94
 
        else
95
 
            EXPECT_EQ("At night", appt.summary);
96
 
        EXPECT_EQ(expected_times[i], appt.begin);
97
 
    }
98
 
 
99
 
    // cleanup
100
 
    g_time_zone_unref(gtz);
101
 
}