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>
25 public class SetIMAddressesTests : Folks.TestCase
27 private EdsTest.Backend _eds_backend;
28 private IndividualAggregator _aggregator;
29 private GLib.MainLoop _main_loop;
30 private bool _found_before_update;
31 private bool _found_after_update;
33 public SetIMAddressesTests ()
35 base ("SetIMAddresses");
37 this._eds_backend = new EdsTest.Backend ();
39 this.add_test ("setting im addresses on e-d-s persona",
40 this.test_set_im_addresses);
43 public override void set_up ()
45 this._eds_backend.set_up ();
48 public override void tear_down ()
50 this._eds_backend.tear_down ();
53 void test_set_im_addresses ()
55 Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
56 this._main_loop = new GLib.MainLoop (null, false);
59 this._found_before_update = false;
60 this._found_after_update = false;
62 this._eds_backend.reset ();
64 v = Value (typeof (string));
65 v.set_string ("bernie h. innocenti");
66 c1.set ("full_name", (owned) v);
67 this._eds_backend.add_contact (c1);
69 this._test_set_im_addresses_async ();
71 Timeout.add_seconds (5, () => {
72 this._main_loop.quit ();
73 assert_not_reached ();
76 this._main_loop.run ();
78 assert (this._found_before_update);
79 assert (this._found_after_update);
82 private async void _test_set_im_addresses_async ()
84 yield this._eds_backend.commit_contacts_to_addressbook ();
86 var store = BackendStore.dup ();
87 yield store.prepare ();
88 this._aggregator = new IndividualAggregator ();
89 this._aggregator.individuals_changed_detailed.connect
90 (this._individuals_changed_cb);
93 yield this._aggregator.prepare ();
97 GLib.warning ("Error when calling prepare: %s\n", e.message);
101 private void _individuals_changed_cb (
102 MultiMap<Individual?, Individual?> changes)
104 var added = changes.get_values ();
106 foreach (Individual i in added)
110 var name = (Folks.NameDetails) i;
112 if (name.full_name != "bernie h. innocenti")
115 /* Because we update a linkable property, we'll
116 get a new individual because re-linking has to
119 if (!this._found_before_update)
121 this._found_before_update = true;
123 foreach (var p in i.personas)
125 var im_addrs = new HashMultiMap<string, ImFieldDetails> (
127 (GLib.HashFunc) ImFieldDetails.hash,
128 (GLib.EqualFunc) ImFieldDetails.equal);
129 im_addrs.set ("jabber",
130 new ImFieldDetails ("bernie@example.org"));
131 ((ImDetails) p).im_addresses = im_addrs;
136 foreach (var proto in i.im_addresses.get_keys ())
138 foreach (var im_fd in i.im_addresses.get (proto))
141 new ImFieldDetails ("bernie@example.org")))
143 this._found_after_update = true;
144 this._main_loop.quit ();
153 public int main (string[] args)
155 Test.init (ref args);
157 TestSuite root = TestSuite.get_root ();
158 root.add_suite (new SetIMAddressesTests ().get_suite ());