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 UrlDetailsInterfaceTests : TrackerTest.TestCase
28 private GLib.MainLoop _main_loop;
29 private IndividualAggregator _aggregator;
30 private string _blog_url;
31 private string _website_url;
33 private bool _found_blog;
34 private bool _found_website;
36 public UrlDetailsInterfaceTests ()
38 base ("UrlDetailsInterfaceTests");
40 ((!) this.tracker_backend).debug = false;
42 this.add_test ("test url details interface",
43 this.test_url_details_interface);
46 public void test_url_details_interface ()
48 this._main_loop = new GLib.MainLoop (null, false);
49 Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
50 this._blog_url = "http://blog.example.org";
51 this._website_url = "http://www.example.org";
52 this._urls = "%s,%s".printf (this._blog_url, this._website_url);
54 c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1");
55 c1.set (TrackerTest.Backend.URLS, this._urls);
56 ((!) this.tracker_backend).add_contact (c1);
58 ((!) this.tracker_backend).set_up ();
60 this._found_blog = false;
61 this._found_website = false;
63 this._test_url_details_interface_async.begin ();
65 Timeout.add_seconds (5, () =>
67 this._main_loop.quit ();
68 assert_not_reached ();
71 this._main_loop.run ();
73 assert (this._found_blog == true);
74 assert (this._found_website == true);
77 private async void _test_url_details_interface_async ()
79 var store = BackendStore.dup ();
80 yield store.prepare ();
81 this._aggregator = new IndividualAggregator ();
82 this._aggregator.individuals_changed_detailed.connect
83 (this._individuals_changed_cb);
86 yield this._aggregator.prepare ();
90 GLib.warning ("Error when calling prepare: %s\n", e.message);
94 private void _individuals_changed_cb (
95 MultiMap<Individual?, Individual?> changes)
97 var added = changes.get_values ();
98 var removed = changes.get_keys ();
100 foreach (var i in added)
104 string full_name = i.full_name;
105 if (full_name != null)
107 foreach (var url in i.urls)
109 if (url.value == this._blog_url)
111 this._found_blog = true;
113 else if (url.value == this._website_url)
115 this._found_website = true;
121 if (this._found_blog &&
123 this._main_loop.quit ();
125 assert (removed.size == 1);
127 foreach (var i in removed)
134 public int main (string[] args)
136 Test.init (ref args);
138 var tests = new UrlDetailsInterfaceTests ();
141 tests.final_tear_down ();