[folks] tests: Add a quiescence test for the Telepathy backend
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] tests: Add a quiescence test for the Telepathy backend
- Date: Sun, 8 Jan 2012 23:40:05 +0000 (UTC)
commit 7ee89fb9376af9aa671e86c5ef4116819c5a0cdf
Author: Philip Withnall <philip tecnocode co uk>
Date: Sun Jan 8 19:19:03 2012 +0000
tests: Add a quiescence test for the Telepathy backend
This just checks that an aggregator with a single Tpf.PersonaStore reaches
quiescence in a reasonable time.
tests/lib/Makefile.am | 25 +++++++++-
tests/lib/test-utils.vala | 44 +++++++++++++++++
tests/telepathy/Makefile.am | 7 ++-
tests/telepathy/init.vala | 109 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 182 insertions(+), 3 deletions(-)
---
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 54ac42d..885c5de 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -26,14 +26,35 @@ DIST_SUBDIRS = \
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 \
diff --git a/tests/lib/test-utils.vala b/tests/lib/test-utils.vala
index 0318f86..e2c7661 100644
--- a/tests/lib/test-utils.vala
+++ b/tests/lib/test-utils.vala
@@ -1,5 +1,6 @@
/*
* 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
@@ -15,9 +16,11 @@
* 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
@@ -91,4 +94,45 @@ 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);
+ }
+ }
}
diff --git a/tests/telepathy/Makefile.am b/tests/telepathy/Makefile.am
index ced3a7e..5bb593c 100644
--- a/tests/telepathy/Makefile.am
+++ b/tests/telepathy/Makefile.am
@@ -44,12 +44,12 @@ AM_VALAFLAGS = \
-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
@@ -76,6 +76,10 @@ individual_properties_SOURCES = \
individual-properties.vala \
$(NULL)
+init_SOURCES = \
+ init.vala \
+ $(NULL)
+
persona_store_capabilities_SOURCES = \
persona-store-capabilities.vala \
$(NULL)
@@ -84,6 +88,7 @@ BUILT_SOURCES = \
fake_tp_backend_vala.stamp \
individual_properties_vala.stamp \
individual_retrieval_vala.stamp \
+ init_vala.stamp \
persona_store_capabilities_vala.stamp \
$(NULL)
diff --git a/tests/telepathy/init.vala b/tests/telepathy/init.vala
new file mode 100644
index 0000000..bf8aef6
--- /dev/null
+++ b/tests/telepathy/init.vala
@@ -0,0 +1,109 @@
+/*
+ * 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;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]