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 SetEmailsTests : 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 SetEmailsTests ()
37 this.add_test ("setting emails on e-d-s persona", this.test_set_emails);
40 public override void set_up ()
42 this._eds_backend = new EdsTest.Backend ();
43 this._eds_backend.set_up ();
45 /* We configure eds as the primary store */
46 var config_val = "eds:%s".printf (this._eds_backend.address_book_uid);
47 Environment.set_variable ("FOLKS_PRIMARY_STORE", config_val, true);
50 public override void tear_down ()
52 this._eds_backend.tear_down ();
55 void test_set_emails ()
57 Gee.HashMap<string, Value?> c1 = new Gee.HashMap<string, Value?> ();
58 this._main_loop = new GLib.MainLoop (null, false);
61 this._found_before_update = false;
62 this._found_after_update = false;
64 this._eds_backend.reset ();
66 v = Value (typeof (string));
67 v.set_string ("bernie h. innocenti");
68 c1.set ("full_name", (owned) v);
69 this._eds_backend.add_contact (c1);
71 this._test_set_emails_async.begin ();
73 Timeout.add_seconds (5, () => {
74 this._main_loop.quit ();
75 assert_not_reached ();
78 this._main_loop.run ();
80 assert (this._found_before_update);
81 assert (this._found_after_update);
84 private async void _test_set_emails_async ()
86 yield this._eds_backend.commit_contacts_to_addressbook ();
88 var store = BackendStore.dup ();
89 yield store.prepare ();
90 this._aggregator = new IndividualAggregator ();
91 this._aggregator.individuals_changed_detailed.connect
92 (this._individuals_changed_cb);
95 yield this._aggregator.prepare ();
99 GLib.warning ("Error when calling prepare: %s\n", e.message);
103 private void _individuals_changed_cb (
104 MultiMap<Individual?, Individual?> changes)
106 var added = changes.get_values ();
108 foreach (Individual i in added)
112 var name = (Folks.NameDetails) i;
114 if (name.full_name != "bernie h. innocenti")
117 /* Because we update a linkable property, we'll get a new individual
118 * because re-linking has to happen.
120 if (!this._found_before_update)
122 this._found_before_update = true;
124 foreach (var p in i.personas)
126 var emails = new HashSet<EmailFieldDetails> (
127 (GLib.HashFunc) EmailFieldDetails.hash,
128 (GLib.EqualFunc) EmailFieldDetails.equal);
129 var email_1 = new EmailFieldDetails ("bernie@example.org");
130 email_1.set_parameter (AbstractFieldDetails.PARAM_TYPE,
131 AbstractFieldDetails.PARAM_TYPE_OTHER);
132 emails.add (email_1);
133 ((EmailDetails) p).email_addresses = emails;
138 foreach (var e in i.email_addresses)
140 if (e.value == "bernie@example.org")
142 this._found_after_update = true;
143 this._main_loop.quit ();
151 public int main (string[] args)
153 Test.init (ref args);
155 TestSuite root = TestSuite.get_root ();
156 root.add_suite (new SetEmailsTests ().get_suite ());