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 AvatarUpdatesTests : Folks.TestCase
28
private TrackerTest.Backend _tracker_backend;
29
private IndividualAggregator _aggregator;
30
private bool _updated_avatar_found;
31
private string _updated_avatar;
32
private string _individual_id;
33
private GLib.MainLoop _main_loop;
34
private bool _initial_avatar_found;
35
private string _initial_fullname;
36
private string _initial_avatar;
37
private string _contact_urn;
38
private string _photo_urn;
40
public AvatarUpdatesTests ()
42
base ("AvatarUpdates");
44
this._tracker_backend = new TrackerTest.Backend ();
45
this._tracker_backend.debug = false;
47
this.add_test ("avatar updates", this.test_avatar_updates);
50
public override void set_up ()
54
public override void tear_down ()
58
public void test_avatar_updates ()
60
this._main_loop = new GLib.MainLoop (null, false);
61
Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
62
this._initial_fullname = "persona #1";
63
this._initial_avatar = "file:///tmp/avatar-01";
64
this._contact_urn = "<urn:contact001>";
65
this._photo_urn = "<" + this._initial_avatar + ">";
66
this._updated_avatar = "file:///tmp/avatar-02";
68
c1.set (TrackerTest.Backend.URN, this._contact_urn);
69
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname);
70
c1.set (Trf.OntologyDefs.NCO_PHOTO, this._initial_avatar);
71
this._tracker_backend.add_contact (c1);
73
this._tracker_backend.set_up ();
75
this._initial_avatar_found = false;
76
this._updated_avatar_found = false;
77
this._individual_id = "";
79
test_avatar_updates_async ();
81
Timeout.add_seconds (5, () =>
83
this._main_loop.quit ();
84
assert_not_reached ();
87
this._main_loop.run ();
89
assert (this._initial_avatar_found == true);
90
assert (this._updated_avatar_found == true);
92
this._tracker_backend.tear_down ();
95
private async void test_avatar_updates_async ()
97
var store = BackendStore.dup ();
98
yield store.prepare ();
99
this._aggregator = new IndividualAggregator ();
100
this._aggregator.individuals_changed.connect
101
(this._individuals_changed_cb);
104
yield this._aggregator.prepare ();
108
GLib.warning ("Error when calling prepare: %s\n", e.message);
112
private void _individuals_changed_cb
113
(Set<Individual> added,
114
Set<Individual> removed,
117
GroupDetails.ChangeReason reason)
119
foreach (var i in added)
121
if (i.full_name == this._initial_fullname)
123
i.notify["avatar"].connect (this._notify_avatar_cb);
124
this._individual_id = i.id;
126
if (i.avatar != null &&
127
i.avatar.get_uri () == this._initial_avatar)
129
this._initial_avatar_found = true;
131
this._tracker_backend.remove_triplet (this._contact_urn,
132
Trf.OntologyDefs.NCO_PHOTO, this._photo_urn);
134
string photo_urn_2 = "<" + this._updated_avatar;
136
this._tracker_backend.insert_triplet (photo_urn_2,
137
"a", "nfo:Image, nie:DataObject",
138
Trf.OntologyDefs.NIE_URL,
139
this._updated_avatar);
141
this._tracker_backend.insert_triplet
143
Trf.OntologyDefs.NCO_PHOTO, photo_urn_2);
148
assert (removed.size == 0);
152
private void _notify_avatar_cb ()
154
var i = this._aggregator.individuals.get (this._individual_id);
158
if (i.avatar != null &&
159
i.avatar.get_uri () == this._updated_avatar)
161
this._main_loop.quit ();
162
this._updated_avatar_found = true;
167
public int main (string[] args)
169
Test.init (ref args);
171
TestSuite root = TestSuite.get_root ();
172
root.add_suite (new AvatarUpdatesTests ().get_suite ());