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 BirthdayDetailsInterfaceTests : Folks.TestCase
28
private TrackerTest.Backend _tracker_backend;
29
private bool _found_birthday;
30
private DateTime _dobj;
31
private GLib.MainLoop _main_loop;
32
private IndividualAggregator _aggregator;
33
private string _fullname;
35
public BirthdayDetailsInterfaceTests ()
37
base ("BirthdayDetailsInterfaceTests");
39
this._tracker_backend = new TrackerTest.Backend ();
40
this._tracker_backend.debug = false;
42
this.add_test ("test birthday details interface",
43
this.test_birthay_details_interface);
46
public override void set_up ()
50
public override void tear_down ()
54
public void test_birthay_details_interface ()
56
this._main_loop = new GLib.MainLoop (null, false);
57
Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
58
this._fullname = "persona #1";
59
string birthday = "2001-10-26T20:32:52Z";
60
TimeVal t = TimeVal ();
61
t.from_iso8601 (birthday);
62
this._dobj = new DateTime.from_timeval_utc (t);
64
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._fullname);
65
c1.set (Trf.OntologyDefs.NCO_BIRTHDAY, birthday);
66
this._tracker_backend.add_contact (c1);
67
this._tracker_backend.set_up ();
69
this._found_birthday = false;
71
this._test_birthay_details_interface ();
73
Timeout.add_seconds (5, () =>
75
this._main_loop.quit ();
76
assert_not_reached ();
79
this._main_loop.run ();
81
assert (this._found_birthday == true);
83
this._tracker_backend.tear_down ();
86
private async void _test_birthay_details_interface ()
88
var store = BackendStore.dup ();
89
yield store.prepare ();
91
this._aggregator = new IndividualAggregator ();
92
this._aggregator.individuals_changed.connect
93
(this._individuals_changed_cb);
96
yield this._aggregator.prepare ();
100
GLib.warning ("Error when calling prepare: %s\n", e.message);
104
private void _individuals_changed_cb
105
(Set<Individual> added,
106
Set<Individual> removed,
109
GroupDetails.ChangeReason reason)
111
foreach (var i in added)
113
if (i.full_name == this._fullname)
115
i.notify["birthday"].connect (this._notify_birthday_cb);
116
if (i.birthday != null)
118
if (i.birthday.compare (this._dobj) == 0)
120
this._found_birthday = true;
121
this._main_loop.quit ();
126
assert (removed.size == 0);
129
void _notify_birthday_cb (Object individual_obj, ParamSpec ps)
131
Folks.Individual individual = (Folks.Individual) individual_obj;
132
if (individual.birthday != null &&
133
individual.birthday.compare (this._dobj) == 0)
135
this._found_birthday = true;
140
public int main (string[] args)
142
Test.init (ref args);
144
TestSuite root = TestSuite.get_root ();
145
root.add_suite (new BirthdayDetailsInterfaceTests ().get_suite ());