2
* Copyright (C) 2011 Collabora Ltd.
4
* This library is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation, either version 2.1 of the License, or
7
* (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library. If not, see <http://www.gnu.org/licenses/>.
17
* Authors: Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
26
public class BirthdayUpdatesTests : Folks.TestCase
28
private TrackerTest.Backend _tracker_backend;
29
private IndividualAggregator _aggregator;
30
private string _initial_birthday;
31
private string _updated_birthday;
32
private string _individual_id;
33
private bool _initial_birthday_found;
34
private bool _updated_birthday_found;
35
private string _contact_urn;
36
private DateTime _initial_bday_obj;
37
private DateTime _updated_bday_obj;
38
private string _initial_fullname;
39
private GLib.MainLoop _main_loop;
41
public BirthdayUpdatesTests ()
43
base ("BirthdayUpdates");
45
this._tracker_backend = new TrackerTest.Backend ();
46
this._tracker_backend.debug = false;
48
this.add_test ("birthday updates", this.test_birthday_updates);
51
public override void set_up ()
55
public override void tear_down ()
59
public void test_birthday_updates ()
61
this._main_loop = new GLib.MainLoop (null, false);
62
Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
63
this._initial_fullname = "persona #1";
64
this._initial_birthday = "2001-10-26T20:32:52Z";
65
this._updated_birthday = "1991-10-26T20:32:52Z";
66
this._contact_urn = "<urn:contact001>";
68
TimeVal t1 = TimeVal ();
69
t1.from_iso8601 (this._initial_birthday);
70
this._initial_bday_obj = new DateTime.from_timeval_utc (t1);
72
TimeVal t2 = TimeVal ();
73
t2.from_iso8601 (this._updated_birthday);
74
this._updated_bday_obj = new DateTime.from_timeval_utc (t2);
76
c1.set (TrackerTest.Backend.URN, this._contact_urn);
77
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname);
78
c1.set (Trf.OntologyDefs.NCO_BIRTHDAY, this._initial_birthday);
79
this._tracker_backend.add_contact (c1);
81
this._tracker_backend.set_up ();
83
this._initial_birthday_found = false;
84
this._updated_birthday_found = false;
85
this._individual_id = "";
87
test_birthday_updates_async ();
90
Timeout.add_seconds (5, () =>
92
this._main_loop.quit ();
93
assert_not_reached ();
96
this._main_loop.run ();
98
assert (this._initial_birthday_found == true);
99
assert (this._updated_birthday_found == true);
101
this._tracker_backend.tear_down ();
104
private async void test_birthday_updates_async ()
106
var store = BackendStore.dup ();
107
yield store.prepare ();
108
/* Set up the aggregator */
109
this._aggregator = new IndividualAggregator ();
110
this._aggregator.individuals_changed.connect
111
(this._individuals_changed_cb);
114
yield this._aggregator.prepare ();
118
GLib.warning ("Error when calling prepare: %s\n", e.message);
122
private void _individuals_changed_cb
123
(Set<Individual> added,
124
Set<Individual> removed,
127
GroupDetails.ChangeReason reason)
129
foreach (var i in added)
131
if (i.full_name == this._initial_fullname)
133
i.notify["birthday"].connect (this._notify_birthday_cb);
134
if (i.birthday != null &&
135
i.birthday.compare (this._initial_bday_obj) == 0)
137
this._individual_id = i.id;
138
this._initial_birthday_found = true;
139
this._tracker_backend.update_contact (this._contact_urn,
140
Trf.OntologyDefs.NCO_BIRTHDAY, this._updated_birthday);
144
assert (removed.size == 0);
147
void _notify_birthday_cb (Object individual_obj, ParamSpec ps)
149
Folks.Individual i = (Folks.Individual) individual_obj;
151
if (i.birthday == null)
156
if (i.birthday.compare (this._initial_bday_obj) == 0)
158
this._individual_id = i.id;
159
this._initial_birthday_found = true;
160
this._tracker_backend.update_contact (this._contact_urn,
161
Trf.OntologyDefs.NCO_BIRTHDAY, this._updated_birthday);
163
else if (i.birthday.compare (this._updated_bday_obj) == 0)
165
this._updated_birthday_found = true;
166
this._main_loop.quit ();
171
public int main (string[] args)
173
Test.init (ref args);
175
TestSuite root = TestSuite.get_root ();
176
root.add_suite (new BirthdayUpdatesTests ().get_suite ());