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: Travis Reitter <travis.reitter@collabora.co.uk>
24 public class IndividualRetrievalTests : Folks.TestCase
26 private KfTest.Backend kf_backend;
27 private int _test_timeout = 3;
29 public IndividualRetrievalTests ()
31 base ("IndividualRetrieval");
33 this.kf_backend = new KfTest.Backend ();
35 this.add_test ("singleton individuals", this.test_singleton_individuals);
36 this.add_test ("aliases", this.test_aliases);
38 if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
39 this._test_timeout = 10;
42 public override void set_up ()
46 public override void tear_down ()
50 public void test_singleton_individuals ()
52 var main_loop = new GLib.MainLoop (null, false);
53 this.kf_backend.set_up (
55 "msn=foo@hotmail.com\n" +
57 "__alias=Bar McBadgerson\n" +
58 "jabber=bar@jabber.org\n");
60 /* Create a set of the individuals we expect to see */
61 HashSet<string> expected_individuals = new HashSet<string> ();
63 expected_individuals.add ("0");
64 expected_individuals.add ("1");
66 /* Set up the aggregator */
67 var aggregator = new IndividualAggregator ();
68 aggregator.individuals_changed_detailed.connect ((changes) =>
70 var added = changes.get_values ();
71 var removed = changes.get_keys ();
73 foreach (Individual i in added)
76 assert (i.personas.size == 1);
78 /* Using the display ID is a little hacky, since we strictly
79 * shouldn't assume anything about…but for the key-file backend,
80 * we know it's equal to the group name. */
81 foreach (var persona in i.personas)
83 expected_individuals.remove (persona.display_id);
87 assert (removed.size == 1);
89 foreach (var i in removed)
94 aggregator.prepare ();
96 /* Kill the main loop after a few seconds. If there are still individuals
97 * in the set of expected individuals, the aggregator has either failed
98 * or been too slow (which we can consider to be failure). */
99 Timeout.add_seconds (this._test_timeout, () =>
107 /* We should have enumerated exactly the individuals in the set */
108 assert (expected_individuals.size == 0);
110 this.kf_backend.tear_down ();
113 public void test_aliases ()
115 var main_loop = new GLib.MainLoop (null, false);
116 this.kf_backend.set_up (
118 "__alias=Brian Briansson\n" +
119 "msn=foo@hotmail.com\n");
121 /* Set up the aggregator */
122 var aggregator = new IndividualAggregator ();
123 uint individuals_changed_count = 0;
124 aggregator.individuals_changed_detailed.connect ((changes) =>
126 var added = changes.get_values ();
127 var removed = changes.get_keys ();
129 individuals_changed_count++;
131 assert (added.size == 1);
132 assert (removed.size == 1);
134 /* Check properties */
135 foreach (var i in added)
137 assert (i.alias == "Brian Briansson");
140 foreach (var i in removed)
145 aggregator.prepare ();
147 /* Kill the main loop after a few seconds. If there are still individuals
148 * in the set of expected individuals, the aggregator has either failed
149 * or been too slow (which we can consider to be failure). */
150 Timeout.add_seconds (this._test_timeout, () =>
158 /* We should have enumerated exactly one individual */
159 assert (individuals_changed_count == 1);
161 this.kf_backend.tear_down ();
165 public int main (string[] args)
167 Test.init (ref args);
169 TestSuite root = TestSuite.get_root ();
170 root.add_suite (new IndividualRetrievalTests ().get_suite ());