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 SetRolesTests : TrackerTest.TestCase
28 private GLib.MainLoop _main_loop;
29 private IndividualAggregator _aggregator;
30 private string _persona_fullname;
31 private bool _role_found;
32 private RoleFieldDetails _role_fd;
34 public SetRolesTests ()
36 base ("SetRolesTests");
38 this.add_test ("test setting roles ",
42 public void test_set_roles ()
44 this._main_loop = new GLib.MainLoop (null, false);
45 Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
46 this._persona_fullname = "persona #1";
48 c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
49 ((!) this.tracker_backend).add_contact (c1);
51 var role = new Role ("some title", "some organisation");
52 role.role = "some role";
53 this._role_fd = new RoleFieldDetails (role);
55 ((!) this.tracker_backend).set_up ();
57 this._role_found = false;
59 this._test_set_roles_async.begin ();
61 TestUtils.loop_run_with_timeout (this._main_loop);
63 assert (this._role_found);
66 private async void _test_set_roles_async ()
68 var store = BackendStore.dup ();
69 yield store.prepare ();
70 this._aggregator = new IndividualAggregator ();
71 this._aggregator.individuals_changed_detailed.connect
72 (this._individuals_changed_cb);
75 yield this._aggregator.prepare ();
79 GLib.warning ("Error when calling prepare: %s\n", e.message);
83 private void _individuals_changed_cb (
84 MultiMap<Individual?, Individual?> changes)
86 var added = changes.get_values ();
87 var removed = changes.get_keys ();
89 foreach (var i in added)
93 if (i.full_name == this._persona_fullname)
95 i.notify["roles"].connect (this._notify_roles_cb);
97 Gee.HashSet<RoleFieldDetails> role_fds =
98 new HashSet<RoleFieldDetails> (
99 AbstractFieldDetails<Role>.hash_static,
100 AbstractFieldDetails<Role>.equal_static);
101 var role = new Role ("some title", "some organisation");
102 role.role = "some role";
103 var role_fd = new RoleFieldDetails (role);
104 role_fds.add ((owned) role_fd);
106 foreach (var p in i.personas)
108 ((RoleDetails) p).roles = role_fds;
113 assert (removed.size == 1);
115 foreach (var i in removed)
121 private void _notify_roles_cb (Object individual_obj, ParamSpec ps)
123 Folks.Individual i = (Folks.Individual) individual_obj;
124 if (i.full_name == this._persona_fullname)
126 foreach (var role_fd in i.roles)
128 if (role_fd.equal (this._role_fd))
130 this._role_found = true;
131 this._main_loop.quit ();
138 public int main (string[] args)
140 Test.init (ref args);
142 var tests = new SetRolesTests ();
145 tests.final_tear_down ();