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 PhoneDetailsInterfaceTests : Folks.TestCase
28 private GLib.MainLoop _main_loop;
29 private IndividualAggregator _aggregator;
30 private TrackerTest.Backend _tracker_backend;
31 private int _num_phones = 0;
32 private bool _found_phone_1 = false;
33 private bool _found_phone_2 = false;
35 public PhoneDetailsInterfaceTests ()
37 base ("PhoneDetailsInterfaceTests");
39 this._tracker_backend = new TrackerTest.Backend ();
41 this.add_test ("test phone details interface",
42 this.test_phone_details_interface);
45 public override void set_up ()
49 public override void tear_down ()
53 public void test_phone_details_interface ()
55 this._main_loop = new GLib.MainLoop (null, false);
56 Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
58 c1.set (Trf.OntologyDefs.NCO_FULLNAME, "persona #1");
59 c1.set (Trf.OntologyDefs.NCO_PHONE_PROP, "12345,54321");
60 this._tracker_backend.add_contact (c1);
62 this._tracker_backend.set_up ();
65 this._found_phone_1 = false;
66 this._found_phone_2 = false;
68 this._test_phone_details_interface_async ();
70 Timeout.add_seconds (5, () =>
72 this._main_loop.quit ();
73 assert_not_reached ();
76 this._main_loop.run ();
78 assert (this._num_phones == 2);
79 assert (this._found_phone_1 == true);
80 assert (this._found_phone_2 == true);
82 this._tracker_backend.tear_down ();
85 private async void _test_phone_details_interface_async ()
87 var store = BackendStore.dup ();
88 yield store.prepare ();
89 this._aggregator = new IndividualAggregator ();
90 this._aggregator.individuals_changed.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 (Set<Individual> added,
104 Set<Individual> removed,
107 GroupDetails.ChangeReason reason)
109 foreach (var i in added)
111 string full_name = i.full_name;
112 if (full_name != null)
114 foreach (var phone in i.phone_numbers)
116 if (phone.equal (new PhoneFieldDetails ("12345")))
118 this._found_phone_1 = true;
121 else if (phone.equal (new PhoneFieldDetails ("54321")))
123 this._found_phone_2 = true;
130 assert (removed.size == 0);
132 if (this._num_phones == 2 &&
133 this._found_phone_1 == true &&
134 this._found_phone_2 == true)
135 this._main_loop.quit ();
139 public int main (string[] args)
141 Test.init (ref args);
143 TestSuite root = TestSuite.get_root ();
144 root.add_suite (new PhoneDetailsInterfaceTests ().get_suite ());