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_uri;
32 private LoadableIcon _updated_avatar;
33 private string _individual_id;
34 private GLib.MainLoop _main_loop;
35 private bool _initial_avatar_found;
36 private string _initial_fullname;
37 private string _initial_avatar_uri;
38 private string _contact_urn;
39 private string _photo_urn;
41 public AvatarUpdatesTests ()
43 base ("AvatarUpdates");
45 this._tracker_backend = new TrackerTest.Backend ();
46 this._tracker_backend.debug = false;
48 this.add_test ("avatar updates", this.test_avatar_updates);
51 public override void set_up ()
55 public override void tear_down ()
59 public void test_avatar_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_avatar_uri = "file:///tmp/avatar-01";
65 this._contact_urn = "<urn:contact001>";
66 this._photo_urn = "<" + this._initial_avatar_uri + ">";
67 this._updated_avatar_uri = "file:///tmp/avatar-02";
68 this._updated_avatar =
69 new FileIcon (File.new_for_uri (this._updated_avatar_uri));
71 c1.set (TrackerTest.Backend.URN, this._contact_urn);
72 c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname);
73 c1.set (Trf.OntologyDefs.NCO_PHOTO, this._initial_avatar_uri);
74 this._tracker_backend.add_contact (c1);
76 this._tracker_backend.set_up ();
78 this._initial_avatar_found = false;
79 this._updated_avatar_found = false;
80 this._individual_id = "";
82 test_avatar_updates_async ();
84 Timeout.add_seconds (5, () =>
86 this._main_loop.quit ();
87 assert_not_reached ();
90 this._main_loop.run ();
92 assert (this._initial_avatar_found == true);
93 assert (this._updated_avatar_found == true);
95 this._tracker_backend.tear_down ();
98 private async void test_avatar_updates_async ()
100 var store = BackendStore.dup ();
101 yield store.prepare ();
102 this._aggregator = new IndividualAggregator ();
103 this._aggregator.individuals_changed.connect
104 (this._individuals_changed_cb);
107 yield this._aggregator.prepare ();
111 GLib.warning ("Error when calling prepare: %s\n", e.message);
115 private void _individuals_changed_cb
116 (Set<Individual> added,
117 Set<Individual> removed,
120 GroupDetails.ChangeReason reason)
122 foreach (var i in added)
124 if (i.full_name == this._initial_fullname)
126 i.notify["avatar"].connect (this._notify_avatar_cb);
127 this._individual_id = i.id;
130 new FileIcon (File.new_for_uri (this._initial_avatar_uri));
132 if (i.avatar != null && i.avatar.equal (initial_avatar) == true)
134 this._initial_avatar_found = true;
136 this._tracker_backend.remove_triplet (this._contact_urn,
137 Trf.OntologyDefs.NCO_PHOTO, this._photo_urn);
139 string photo_urn_2 = "<" + this._updated_avatar_uri;
141 this._tracker_backend.insert_triplet (photo_urn_2,
142 "a", "nfo:Image, nie:DataObject",
143 Trf.OntologyDefs.NIE_URL,
144 this._updated_avatar_uri);
146 this._tracker_backend.insert_triplet
148 Trf.OntologyDefs.NCO_PHOTO, photo_urn_2);
153 assert (removed.size == 0);
157 private void _notify_avatar_cb ()
159 var i = this._aggregator.individuals.get (this._individual_id);
163 if (i.avatar != null &&
164 i.avatar.equal (this._updated_avatar))
166 this._main_loop.quit ();
167 this._updated_avatar_found = true;
172 public int main (string[] args)
174 Test.init (ref args);
176 TestSuite root = TestSuite.get_root ();
177 root.add_suite (new AvatarUpdatesTests ().get_suite ());