noinst_LTLIBRARIES = libfolks-test.la
libfolks_test_la_SOURCES = test-case.vala test-utils.vala
-libfolks_test_la_CFLAGS = $(GLIB_CFLAGS) $(GIO_CFLAGS)
-libfolks_test_la_LIBADD = $(GLIB_LIBS) $(GIO_LIBS)
+
+libfolks_test_la_CFLAGS = \
+ $(AM_CFLAGS) \
+ $(GLIB_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(GEE_CFLAGS) \
+ $(NULL)
+
+libfolks_test_la_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir)/folks \
+ $(NULL)
+
+libfolks_test_la_LIBADD = \
+ $(AM_LIBADD) \
+ $(top_builddir)/folks/libfolks.la \
+ $(GLIB_LIBS) \
+ $(GIO_LIBS) \
+ $(GEE_LIBS) \
+ $(NULL)
libfolks_test_la_VALAFLAGS = \
$(ERROR_VALAFLAGS) \
$(VALAFLAGS) \
+ --vapidir=$(top_srcdir)/folks \
--pkg gobject-2.0 \
--pkg gio-2.0 \
+ --pkg gee-1.0 \
+ --pkg folks \
--library folks-test \
-H folks-test.h \
-g \
/*
* Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2012 Philip Withnall
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Travis Reitter <travis.reitter@collabora.com>
+ * Philip Withnall <philip@tecnocode.co.uk>
*
*/
+using Folks;
using GLib;
public class Folks.TestUtils
return retval;
}
+
+ /**
+ * Prepare an aggregator and wait for it to reach quiescence.
+ *
+ * This will prepare the given {@link IndividualAggregator} then yield until
+ * it reaches quiescence. No timeout is used, so if the aggregator never
+ * reaches quiescence, this function will never return; callers must add their
+ * own timeout to avoid this if necessary.
+ *
+ * When this returns, the aggregator is guaranteed to be quiescent.
+ *
+ * @param aggregator the aggregator to prepare
+ */
+ public static async void aggregator_prepare_and_wait_for_quiescence (
+ IndividualAggregator aggregator) throws GLib.Error
+ {
+ var has_yielded = false;
+ var signal_id = aggregator.notify["is-quiescent"].connect ((obj, pspec) =>
+ {
+ if (has_yielded == true)
+ {
+ TestUtils.aggregator_prepare_and_wait_for_quiescence.callback ();
+ }
+ });
+
+ try
+ {
+ yield aggregator.prepare ();
+
+ if (aggregator.is_quiescent == false)
+ {
+ has_yielded = true;
+ yield;
+ }
+ }
+ finally
+ {
+ aggregator.disconnect (signal_id);
+ assert (aggregator.is_quiescent == true);
+ }
+ }
}
-g \
$(NULL)
-# in order from least to most complex
noinst_PROGRAMS = \
fake-tp-backend \
persona-store-capabilities \
individual-retrieval \
individual-properties \
+ init \
$(NULL)
SESSION_CONF = $(top_builddir)/tests/lib/telepathy/contactlist/session.conf
individual-properties.vala \
$(NULL)
+init_SOURCES = \
+ init.vala \
+ $(NULL)
+
persona_store_capabilities_SOURCES = \
persona-store-capabilities.vala \
$(NULL)
fake_tp_backend_vala.stamp \
individual_properties_vala.stamp \
individual_retrieval_vala.stamp \
+ init_vala.stamp \
persona_store_capabilities_vala.stamp \
$(NULL)
--- /dev/null
+/*
+ * Copyright (C) 2012 Philip Withnall
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Philip Withnall <philip@tecnocode.co.uk>
+ */
+
+using Gee;
+using Folks;
+
+public class InitTests : Folks.TestCase
+{
+ private TpTest.Backend _tp_backend;
+ private int _test_timeout = 5;
+
+ public InitTests ()
+ {
+ base ("Init");
+
+ this._tp_backend = new TpTest.Backend ();
+
+ /* Set up the tests */
+ this.add_test ("quiescence", this.test_quiescence);
+ }
+
+ public override void set_up ()
+ {
+ this._tp_backend.set_up ();
+ }
+
+ public override void tear_down ()
+ {
+ this._tp_backend.tear_down ();
+ }
+
+ /* Prepare an aggregator and wait for quiescence, then quit. Error if reaching
+ * quiescence takes too long. */
+ public void test_quiescence ()
+ {
+ var main_loop = new GLib.MainLoop (null, false);
+
+ void* account_handle = this._tp_backend.add_account ("protocol",
+ "me@example.com", "cm", "account");
+
+ /* Main test code. */
+ var aggregator = new IndividualAggregator ();
+
+ Idle.add (() =>
+ {
+ TestUtils.aggregator_prepare_and_wait_for_quiescence.begin (
+ aggregator, (obj, res) =>
+ {
+ try
+ {
+ TestUtils.aggregator_prepare_and_wait_for_quiescence.end (
+ res);
+ }
+ catch (GLib.Error e1)
+ {
+ GLib.critical ("Error preparing aggregator: %s", e1.message);
+ }
+
+ main_loop.quit ();
+ });
+
+ return false;
+ });
+
+ /* Add a timeout for failure. */
+ Timeout.add_seconds (this._test_timeout, () =>
+ {
+ main_loop.quit ();
+ return false;
+ });
+
+ main_loop.run ();
+
+ /* Check results. */
+ assert (aggregator.is_quiescent == true);
+ assert (aggregator.individuals.size > 0);
+
+ /* Clean up for the next test */
+ this._tp_backend.remove_account (account_handle);
+ }
+}
+
+public int main (string[] args)
+{
+ Test.init (ref args);
+
+ TestSuite root = TestSuite.get_root ();
+ root.add_suite (new InitTests ().get_suite ());
+
+ Test.run ();
+
+ return 0;
+}