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 SetNotesTests : 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 _note_found;
35
public SetNotesTests ()
37
base ("SetNotesTests");
39
this._tracker_backend = new TrackerTest.Backend ();
41
this.add_test ("test setting notes ",
45
public override void set_up ()
49
public override void tear_down ()
53
public void test_set_notes ()
55
this._main_loop = new GLib.MainLoop (null, false);
56
Gee.HashMap<string, string> c1 = new Gee.HashMap<string, string> ();
57
this._persona_fullname = "persona #1";
59
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
60
this._tracker_backend.add_contact (c1);
62
this._note = new Note ("some note");
64
this._tracker_backend.set_up ();
66
this._note_found = false;
68
this._test_set_notes_async ();
70
Timeout.add_seconds (5, () =>
72
this._main_loop.quit ();
73
assert_not_reached ();
76
this._main_loop.run ();
78
assert (this._note_found);
80
this._tracker_backend.tear_down ();
83
private async void _test_set_notes_async ()
85
var store = BackendStore.dup ();
86
yield store.prepare ();
87
this._aggregator = new IndividualAggregator ();
88
this._aggregator.individuals_changed.connect
89
(this._individuals_changed_cb);
92
yield this._aggregator.prepare ();
96
GLib.warning ("Error when calling prepare: %s\n", e.message);
100
private void _individuals_changed_cb
101
(Set<Individual> added,
102
Set<Individual> removed,
105
GroupDetails.ChangeReason reason)
107
foreach (var i in added)
109
if (i.full_name == this._persona_fullname)
111
i.notify["notes"].connect (this._notify_notes_cb);
113
Gee.HashSet<Note> notes = new HashSet<Note>
114
((GLib.HashFunc) Note.hash, (GLib.EqualFunc) Note.equal);
115
var n = new Note ("some note");
116
notes.add ((owned) n);
118
foreach (var p in i.personas)
120
((NoteDetails) p).notes = notes;
125
assert (removed.size == 0);
128
private void _notify_notes_cb (Object individual_obj, ParamSpec ps)
130
Folks.Individual i = (Folks.Individual) individual_obj;
131
if (i.full_name == this._persona_fullname)
133
foreach (var n in i.notes)
135
if (Note.equal (n, this._note))
137
this._note_found = true;
138
this._main_loop.quit ();
145
public int main (string[] args)
147
Test.init (ref args);
149
TestSuite root = TestSuite.get_root ();
150
root.add_suite (new SetNotesTests ().get_suite ());