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 SuffixNameUpdatesTests : Folks.TestCase
28
private GLib.MainLoop _main_loop;
29
private TrackerTest.Backend _tracker_backend;
30
private IndividualAggregator _aggregator;
31
private bool _updated_suffix_name_found;
32
private bool _deleted_suffix_name_found;
33
private bool _initial_suffix_name_found;
34
private string _updated_suffix_name;
35
private string _individual_id;
36
private string _initial_fullname;
37
private string _initial_suffix_name;
38
private string _contact_urn;
40
public SuffixNameUpdatesTests ()
42
base ("SuffixNameUpdates");
44
this._tracker_backend = new TrackerTest.Backend ();
45
this._tracker_backend.debug = false;
47
this.add_test ("suffix name updates", this.test_suffix_name_updates);
50
public override void set_up ()
54
public override void tear_down ()
58
public void test_suffix_name_updates ()
60
this._main_loop = new GLib.MainLoop (null, false);
61
Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
62
this._initial_fullname = "persona #1";
63
this._initial_suffix_name = "suffix name #1";
64
this._updated_suffix_name = "updated suffix #1";
65
this._contact_urn = "<urn:contact001>";
67
c1.set (TrackerTest.Backend.URN, this._contact_urn);
68
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._initial_fullname);
69
c1.set (Trf.OntologyDefs.NCO_SUFFIX, this._initial_suffix_name);
70
this._tracker_backend.add_contact (c1);
72
this._tracker_backend.set_up ();
74
this._initial_suffix_name_found = false;
75
this._updated_suffix_name_found = false;
76
this._deleted_suffix_name_found = false;
77
this._individual_id = "";
79
this._test_suffix_name_updates_async ();
81
Timeout.add_seconds (5, () =>
83
this._main_loop.quit ();
84
assert_not_reached ();
87
this._main_loop.run ();
89
assert (this._initial_suffix_name_found == true);
90
assert (this._updated_suffix_name_found == true);
92
this._tracker_backend.tear_down ();
95
private async void _test_suffix_name_updates_async ()
97
var store = BackendStore.dup ();
98
yield store.prepare ();
99
this._aggregator = new IndividualAggregator ();
100
this._aggregator.individuals_changed.connect
101
(this._individuals_changed_cb);
104
yield this._aggregator.prepare ();
108
GLib.warning ("Error when calling prepare: %s\n", e.message);
112
private void _individuals_changed_cb
113
(Set<Individual> added,
114
Set<Individual> removed,
117
GroupDetails.ChangeReason reason)
119
foreach (var i in added)
121
if (this._initial_fullname == i.full_name)
123
var suffix_name = i.structured_name.suffixes;
124
if (suffix_name == this._initial_suffix_name)
126
i.structured_name.notify["suffixes"].connect
127
(this._notify_suffix_name_cb);
128
this._individual_id = i.id;
129
this._initial_suffix_name_found = true;
130
this._tracker_backend.update_contact (this._contact_urn,
131
Trf.OntologyDefs.NCO_SUFFIX, this._updated_suffix_name);
136
assert (removed.size == 0);
139
private void _notify_suffix_name_cb (Object individual_obj, ParamSpec ps)
141
Folks.StructuredName sname = (Folks.StructuredName) individual_obj;
142
var suffix_name = sname.suffixes;
143
if (suffix_name == this._updated_suffix_name)
145
this._updated_suffix_name_found = true;
146
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 SuffixNameUpdatesTests ().get_suite ());