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 SetAvatarTests : Folks.TestCase
28
private GLib.MainLoop _main_loop;
29
private TrackerTest.Backend _tracker_backend;
30
private IndividualAggregator _aggregator;
31
private string _persona_fullname;
32
private LoadableIcon _avatar;
33
private bool _avatar_found;
35
public SetAvatarTests ()
37
base ("SetAvatarTests");
39
this._tracker_backend = new TrackerTest.Backend ();
41
this.add_test ("test setting avatar ", this.test_set_avatar);
44
public override void set_up ()
48
public override void tear_down ()
52
public void test_set_avatar ()
54
this._main_loop = new GLib.MainLoop (null, false);
55
Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
56
this._persona_fullname = "persona #1";
57
var _avatar_path = Environment.get_variable ("AVATAR_FILE_PATH");
58
this._avatar = new FileIcon (File.new_for_path (_avatar_path));
60
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
61
this._tracker_backend.add_contact (c1);
63
this._tracker_backend.set_up ();
65
this._avatar_found = false;
67
this._test_set_avatar_async ();
69
Timeout.add_seconds (5, () =>
71
this._main_loop.quit ();
72
assert_not_reached ();
75
this._main_loop.run ();
77
assert (this._avatar_found);
79
this._tracker_backend.tear_down ();
82
private async void _test_set_avatar_async ()
84
var store = BackendStore.dup ();
85
yield store.prepare ();
86
this._aggregator = new IndividualAggregator ();
87
this._aggregator.individuals_changed_detailed.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
MultiMap<Individual?, Individual?> changes)
102
var added = changes.get_values ();
103
var removed = changes.get_keys ();
105
foreach (var i in added)
109
if (i.full_name == this._persona_fullname)
111
i.notify["avatar"].connect (this._notify_avatar_cb);
113
foreach (var p in i.personas)
115
((AvatarDetails) p).avatar = this._avatar;
120
assert (removed.size == 1);
122
foreach (var i in removed)
128
private void _notify_avatar_cb (Object individual_obj, ParamSpec ps)
130
Folks.Individual i = (Folks.Individual) individual_obj;
131
if (i.full_name == this._persona_fullname)
133
/* arbitrary icon size, but it might as well be on the small side */
134
TestUtils.loadable_icons_content_equal.begin (i.avatar,
138
if (TestUtils.loadable_icons_content_equal.end (result))
140
this._avatar_found = true;
141
this._main_loop.quit ();
148
public int main (string[] args)
150
Test.init (ref args);
152
TestSuite root = TestSuite.get_root ();
153
root.add_suite (new SetAvatarTests ().get_suite ());