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.add_test ("setting im addresses on e-d-s persona",
38 this.test_set_im_addresses);
41 public override void set_up ()
43 this._eds_backend = new EdsTest.Backend ();
44 this._eds_backend.set_up ();
46 /* We configure eds as the primary store */
47 var config_val = "eds:%s".printf (this._eds_backend.address_book_uid);
48 Environment.set_variable ("FOLKS_PRIMARY_STORE", config_val, true);
51 public override void tear_down ()
53 this._eds_backend.tear_down ();
56 void test_set_im_addresses ()
58 Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
59 this._main_loop = new GLib.MainLoop (null, false);
62 this._found_before_update = false;
63 this._found_after_update = false;
65 this._eds_backend.reset ();
67 v = Value (typeof (string));
68 v.set_string ("bernie h. innocenti");
69 c1.set ("full_name", (owned) v);
70 this._eds_backend.add_contact (c1);
72 this._test_set_im_addresses_async.begin ();
74 Timeout.add_seconds (5, () => {
75 this._main_loop.quit ();
76 assert_not_reached ();
79 this._main_loop.run ();
81 assert (this._found_before_update);
82 assert (this._found_after_update);
85 private async void _test_set_im_addresses_async ()
87 yield this._eds_backend.commit_contacts_to_addressbook ();
89 var store = BackendStore.dup ();
90 yield store.prepare ();
91 this._aggregator = new IndividualAggregator ();
92 this._aggregator.individuals_changed_detailed.connect
93 (this._individuals_changed_cb);
96 yield this._aggregator.prepare ();
100 GLib.warning ("Error when calling prepare: %s\n", e.message);
104 private void _individuals_changed_cb (
105 MultiMap<Individual?, Individual?> changes)
107 var added = changes.get_values ();
109 foreach (Individual i in added)
113 var name = (Folks.NameDetails) i;
115 if (name.full_name != "bernie h. innocenti")
118 /* Because we update a linkable property, we'll
119 get a new individual because re-linking has to
122 if (!this._found_before_update)
124 this._found_before_update = true;
126 foreach (var p in i.personas)
128 var im_addrs = new HashMultiMap<string, ImFieldDetails> (
131 AbstractFieldDetails<string>.hash_static,
133 AbstractFieldDetails<string>.equal_static);
134 im_addrs.set ("jabber",
135 new ImFieldDetails ("bernie@example.org"));
136 ((ImDetails) p).im_addresses = im_addrs;
141 foreach (var proto in i.im_addresses.get_keys ())
143 foreach (var im_fd in i.im_addresses.get (proto))
146 new ImFieldDetails ("bernie@example.org")))
148 this._found_after_update = true;
149 this._main_loop.quit ();
158 public int main (string[] args)
160 Test.init (ref args);
162 TestSuite root = TestSuite.get_root ();
163 root.add_suite (new SetIMAddressesTests ().get_suite ());