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 EmailDetailsInterfaceTests : TrackerTest.TestCase
28 private GLib.MainLoop _main_loop;
29 private IndividualAggregator _aggregator;
30 private int _num_emails;
31 private bool _found_email_1;
32 private bool _found_email_2;
34 public EmailDetailsInterfaceTests ()
36 base ("EmailDetailsInterfaceTests");
38 this.add_test ("test email details interface",
39 this.test_email_details_interface);
42 public void test_email_details_interface ()
44 this._main_loop = new GLib.MainLoop (null, false);
45 Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
47 c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1");
48 c1.set (Trf.OntologyDefs.NCO_EMAIL_PROP,
49 "test1@example.org,test2@example.org");
50 ((!) this.tracker_backend).add_contact (c1);
52 ((!) this.tracker_backend).set_up ();
55 this._found_email_1 = false;
56 this._found_email_2 = false;
58 this._test_email_details_interface_async.begin ();
60 TestUtils.loop_run_with_timeout (this._main_loop);
62 assert (this._num_emails == 2);
63 assert (this._found_email_1 == true);
64 assert (this._found_email_2 == true);
67 private async void _test_email_details_interface_async ()
69 var store = BackendStore.dup ();
70 yield store.prepare ();
71 this._aggregator = IndividualAggregator.dup ();
72 this._aggregator.individuals_changed_detailed.connect
73 (this._individuals_changed_cb);
76 yield this._aggregator.prepare ();
80 GLib.warning ("Error when calling prepare: %s\n", e.message);
84 private void _individuals_changed_cb (
85 MultiMap<Individual?, Individual?> changes)
87 var added = changes.get_values ();
88 var removed = changes.get_keys ();
90 foreach (var i in added)
94 string full_name = i.full_name;
95 if (full_name != null)
97 foreach (var email in i.email_addresses)
99 if (email.value == "test1@example.org")
101 this._found_email_1 = true;
104 else if (email.value == "test2@example.org")
106 this._found_email_2 = true;
113 if (this._found_email_1 &&
114 this._found_email_2 &&
115 this._num_emails == 2)
116 this._main_loop.quit ();
118 assert (removed.size == 1);
120 foreach (var i in removed)
127 public int main (string[] args)
129 Test.init (ref args);
131 var tests = new EmailDetailsInterfaceTests ();
134 tests.final_tear_down ();