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 AvatarDetailsInterfaceTests : Folks.TestCase
28 private TrackerTest.Backend _tracker_backend;
29 private string _avatar_uri;
30 private bool _avatars_are_equal;
31 private GLib.MainLoop _main_loop;
32 IndividualAggregator _aggregator;
34 public AvatarDetailsInterfaceTests ()
36 base ("AvatarDetailsInterfaceTests");
38 this._tracker_backend = new TrackerTest.Backend ();
40 this.add_test ("test avatar details interface",
41 this.test_avatar_details_interface);
44 public override void set_up ()
48 public override void tear_down ()
52 public void test_avatar_details_interface ()
54 this._main_loop = new GLib.MainLoop (null, false);
55 Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
56 string avatar_path = Environment.get_variable ("AVATAR_FILE_PATH");
57 var temp_file = GLib.File.new_for_path (avatar_path);
58 var full_avatar_path = temp_file.get_path ();
59 this._avatar_uri = "file://" + full_avatar_path;
60 this._avatars_are_equal = false;
62 c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1");
63 c1.set (Trf.OntologyDefs.NCO_PHOTO, this._avatar_uri);
64 this._tracker_backend.add_contact (c1);
65 this._tracker_backend.set_up ();
67 test_avatar_details_interface_async ();
69 Timeout.add_seconds (5, () =>
71 this._main_loop.quit ();
72 assert_not_reached ();
75 this._main_loop.run ();
76 assert (this._avatars_are_equal);
77 this._tracker_backend.tear_down ();
80 private async void test_avatar_details_interface_async ()
82 var store = BackendStore.dup ();
83 yield store.prepare ();
85 /* Set up the aggregator */
86 this._aggregator = new IndividualAggregator ();
87 this._aggregator.individuals_changed.connect
88 (this._individuals_changed_cb);
91 yield this._aggregator.prepare ();
95 GLib.warning ("Error when calling prepare: %s\n", e.message);
99 private void _individuals_changed_cb
100 (Set<Individual> added,
101 Set<Individual> removed,
104 GroupDetails.ChangeReason reason)
106 foreach (var i in added)
108 string full_name = ((Folks.NameDetails) i).full_name;
109 if (full_name != null)
111 i.notify["avatar"].connect (this._notify_avatar_cb);
112 if (i.avatar != null)
114 var src_avatar = File.new_for_uri (this._avatar_uri);
115 this._avatars_are_equal =
116 this._compare_files (src_avatar, i.avatar);
117 this._main_loop.quit ();
123 private void _notify_avatar_cb (Object individual_obj, ParamSpec ps)
125 Folks.Individual individual = (Folks.Individual) individual_obj;
126 var src_avatar = File.new_for_uri (this._avatar_uri);
127 this._avatars_are_equal = this._compare_files (src_avatar,
129 this._main_loop.quit ();
132 private bool _compare_files (File a, File b)
139 a.load_contents (null, out content_a);
143 GLib.warning ("couldn't load file a");
148 b.load_contents (null, out content_b);
152 GLib.warning ("couldn't load file b");
155 return ((string) content_a) == ((string) content_b);
159 public int main (string[] args)
161 Test.init (ref args);
163 TestSuite root = TestSuite.get_root ();
164 root.add_suite (new AvatarDetailsInterfaceTests ().get_suite ());