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 SetStructuredNameTests : Folks.TestCase
28 private GLib.MainLoop _main_loop;
29 private TrackerTest.Backend _tracker_backend;
30 private IndividualAggregator _aggregator;
31 private string _persona_fullname;
32 private bool _sname_found;
33 private StructuredName _sname;
34 private string _family_name;
35 private string _given_name;
36 private string _additional_names;
37 private string _prefixes;
38 private string _suffixes;
40 public SetStructuredNameTests ()
42 base ("SetStructuredNameTests");
44 this._tracker_backend = new TrackerTest.Backend ();
46 this.add_test ("test setting structured name ",
47 this.test_set_structured_name);
50 public override void set_up ()
54 public override void tear_down ()
58 public void test_set_structured_name ()
60 this._main_loop = new GLib.MainLoop (null, false);
61 Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
62 this._persona_fullname = "persona #1";
63 this._family_name = "family name";
64 this._given_name = "given name";
65 this._additional_names = "additional name";
66 this._prefixes = "prefixes";
67 this._suffixes = "suffixes";
69 this._sname = new StructuredName (this._family_name, this._given_name,
70 this._additional_names, this._prefixes, this._suffixes);
72 c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
73 this._tracker_backend.add_contact (c1);
75 this._tracker_backend.set_up ();
77 this._sname_found = false;
79 this._test_set_structured_name_async.begin ();
81 Timeout.add_seconds (5, () =>
83 this._main_loop.quit ();
84 assert_not_reached ();
87 this._main_loop.run ();
89 assert (this._sname_found);
91 this._tracker_backend.tear_down ();
94 private async void _test_set_structured_name_async ()
96 var store = BackendStore.dup ();
97 yield store.prepare ();
98 this._aggregator = new IndividualAggregator ();
99 this._aggregator.individuals_changed_detailed.connect
100 (this._individuals_changed_cb);
103 yield this._aggregator.prepare ();
107 GLib.warning ("Error when calling prepare: %s\n", e.message);
111 private void _individuals_changed_cb (
112 MultiMap<Individual?, Individual?> changes)
114 var added = changes.get_values ();
115 var removed = changes.get_keys ();
117 foreach (var i in added)
121 if (i.full_name == this._persona_fullname)
123 foreach (var p in i.personas)
125 p.notify["structured-name"].connect (this._notify_sname_cb);
126 ((NameDetails) p).structured_name = this._sname;
131 assert (removed.size == 1);
133 foreach (var i in removed)
139 private void _notify_sname_cb (Object persona, ParamSpec ps)
141 Trf.Persona p = (Trf.Persona) persona;
142 if (p.full_name == this._persona_fullname)
144 if (p.structured_name.is_empty () == false &&
145 p.structured_name.equal (this._sname) == true)
147 this._sname_found = true;
148 this._main_loop.quit ();
154 public int main (string[] args)
156 Test.init (ref args);
158 TestSuite root = TestSuite.get_root ();
159 root.add_suite (new SetStructuredNameTests ().get_suite ());