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 SetUrlsTests : EdsTest.TestCase
27 private IndividualAggregator _aggregator;
28 private GLib.MainLoop _main_loop;
29 private bool _found_before_update;
30 private bool _found_url_extra_1;
31 private bool _found_url_extra_2;
32 private bool _found_url_home;
33 private bool _found_url_blog;
34 private string _url_extra_1 = "http://example.org";
35 private string _url_extra_2 = "http://extra.example.org";
36 private string _url_home = "http://home.example.org";
37 private string _url_blog = "http://blog.example.org";
40 public SetUrlsTests ()
44 this.add_test ("setting urls on e-d-s persona",
50 Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
51 this._main_loop = new GLib.MainLoop (null, false);
54 this._found_before_update = false;
55 this._found_url_extra_1 = false;
56 this._found_url_extra_2 = false;
57 this._found_url_home = false;
58 this._found_url_blog = false;
60 this.eds_backend.reset ();
62 v = Value (typeof (string));
63 v.set_string ("Albus Percival Wulfric Brian Dumbledore");
64 c1.set ("full_name", (owned) v);
65 this.eds_backend.add_contact (c1);
67 this._test_set_urls_async.begin ();
69 Timeout.add_seconds (5, () => {
70 this._main_loop.quit ();
71 assert_not_reached ();
74 this._main_loop.run ();
76 assert (this._found_before_update);
77 assert (this._found_url_extra_1);
78 assert (this._found_url_extra_2);
79 assert (this._found_url_home);
80 assert (this._found_url_blog);
83 private async void _test_set_urls_async ()
85 yield this.eds_backend.commit_contacts_to_addressbook ();
87 var store = BackendStore.dup ();
88 yield store.prepare ();
89 this._aggregator = new IndividualAggregator ();
90 this._aggregator.individuals_changed_detailed.connect
91 (this._individuals_changed_cb);
94 yield this._aggregator.prepare ();
98 GLib.warning ("Error when calling prepare: %s\n", e.message);
102 private void _individuals_changed_cb (
103 MultiMap<Individual?, Individual?> changes)
105 var added = changes.get_values ();
106 var removed = changes.get_keys ();
108 foreach (Individual i in added)
112 var name = (Folks.NameDetails) i;
114 if (name.full_name == "Albus Percival Wulfric Brian Dumbledore")
116 i.notify["urls"].connect (this._notify_urls_cb);
117 this._found_before_update = true;
119 foreach (var p in i.personas)
121 var urls = new HashSet<UrlFieldDetails> ();
123 var p1 = new UrlFieldDetails (this._url_extra_1);
125 var p2 = new UrlFieldDetails (this._url_extra_2);
127 var p3 = new UrlFieldDetails (this._url_home);
128 p3.set_parameter(AbstractFieldDetails.PARAM_TYPE,
129 UrlFieldDetails.PARAM_TYPE_HOME_PAGE);
131 var p4 = new UrlFieldDetails (this._url_blog);
132 p4.set_parameter(AbstractFieldDetails.PARAM_TYPE,
133 UrlFieldDetails.PARAM_TYPE_BLOG);
136 ((UrlDetails) p).urls = urls;
141 assert (removed.size == 1);
143 foreach (var i in removed)
149 private void _notify_urls_cb (Object individual_obj, ParamSpec ps)
151 Folks.Individual i = (Folks.Individual) individual_obj;
152 foreach (var url in i.urls)
154 if (url.value == this._url_extra_1)
156 this._found_url_extra_1 = true;
158 else if (url.value == this._url_extra_2)
160 this._found_url_extra_2 = true;
162 else if (url.value == this._url_home)
164 this._found_url_home = true;
166 else if (url.value == this._url_blog)
168 this._found_url_blog = true;
172 if (this._found_url_extra_1 &&
173 this._found_url_extra_2 &&
174 this._found_url_home &&
175 this._found_url_blog)
177 this._main_loop.quit ();
182 public int main (string[] args)
184 Test.init (ref args);
186 var tests = new SetUrlsTests ();
189 tests.final_tear_down ();