[folks] Add some initial key-file backend tests
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Add some initial key-file backend tests
- Date: Thu, 4 Nov 2010 00:41:24 +0000 (UTC)
commit 714e0d69ec716e80f48dfbb000bda5f9dacb0aa5
Author: Philip Withnall <philip withnall collabora co uk>
Date: Thu Sep 16 15:00:04 2010 +0100
Add some initial key-file backend tests
Fixes bgo#629862.
NEWS | 1 +
configure.ac | 1 +
tests/Makefile.am | 1 +
tests/key-file/Makefile.am | 50 ++++++++++
tests/key-file/individual-retrieval.vala | 156 ++++++++++++++++++++++++++++++
5 files changed, 209 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6d558be..bc949d8 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ API changes:
Bugs fixed:
* Bug 629081 â?? Add API to allow specific backends to be disabled
+* Bug 629862 â?? Add tests for the key-file backend
Overview of changes from libfolks 0.3.0 to libfolks 0.3.1
==========================================================
diff --git a/configure.ac b/configure.ac
index 1233342..d748a89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -220,6 +220,7 @@ AC_CONFIG_FILES([
docs/Makefile
tests/Makefile
tests/folks/Makefile
+ tests/key-file/Makefile
tests/telepathy/Makefile
tests/lib/Makefile
tests/lib/folks-test-uninstalled.pc
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a53fa52..dafbd35 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,6 +2,7 @@ SUBDIRS = \
lib \
tools \
folks \
+ key-file \
telepathy \
$(NULL)
diff --git a/tests/key-file/Makefile.am b/tests/key-file/Makefile.am
new file mode 100644
index 0000000..1df71cb
--- /dev/null
+++ b/tests/key-file/Makefile.am
@@ -0,0 +1,50 @@
+AM_CPPFLAGS = \
+ $(GLIB_CFLAGS) \
+ $(GEE_CFLAGS) \
+ -I$(top_srcdir)/folks \
+ -I$(top_srcdir)/tests/lib \
+ -I$(top_srcdir)/tests/lib/key-file \
+ -include $(CONFIG_HEADER) \
+ $(NULL)
+
+LDADD = \
+ $(top_builddir)/tests/lib/key-file/libkf-test.la \
+ $(top_builddir)/tests/lib/libfolks-test.la \
+ $(top_builddir)/folks/libfolks.la \
+ $(GLIB_LIBS) \
+ $(GEE_LIBS) \
+ $(NULL)
+
+AM_VALAFLAGS = \
+ --vapidir=. \
+ --vapidir=$(top_srcdir)/folks \
+ --vapidir=$(top_srcdir)/tests/lib \
+ --vapidir=$(top_srcdir)/tests/lib/key-file \
+ --pkg gobject-2.0 \
+ --pkg gio-2.0 \
+ --pkg gee-1.0 \
+ --pkg folks \
+ --pkg folks-test \
+ --pkg kf-test \
+ $(NULL)
+
+# in order from least to most complex
+noinst_PROGRAMS = \
+ individual-retrieval \
+ $(NULL)
+
+TESTS = $(noinst_PROGRAMS)
+
+individual_retrieval_SOURCES = \
+ individual-retrieval.vala \
+ $(NULL)
+
+CLEANFILES = \
+ $(addsuffix .c,$(noinst_PROGRAMS)) \
+ individual_retrieval_vala.stamp \
+ *.pid \
+ *.address \
+ $(TESTS) \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/key-file/individual-retrieval.vala b/tests/key-file/individual-retrieval.vala
new file mode 100644
index 0000000..1776366
--- /dev/null
+++ b/tests/key-file/individual-retrieval.vala
@@ -0,0 +1,156 @@
+using Gee;
+using Folks;
+using KfTest;
+
+public class IndividualRetrievalTests : Folks.TestCase
+{
+ private KfTest.Backend kf_backend;
+ private MainLoop main_loop;
+
+ public IndividualRetrievalTests ()
+ {
+ base ("IndividualRetrieval");
+
+ this.kf_backend = new KfTest.Backend ();
+
+ this.add_test ("singleton individuals", this.test_singleton_individuals);
+ this.add_test ("aliases", this.test_aliases);
+ }
+
+ public override void set_up ()
+ {
+ this.main_loop = new GLib.MainLoop (null, false);
+ }
+
+ public override void tear_down ()
+ {
+ Timeout.add_seconds (5, () =>
+ {
+ this.main_loop.quit ();
+ this.main_loop = null;
+ return false;
+ });
+
+ /* Run the main loop to process the carnage and destruction */
+ this.main_loop.run ();
+ }
+
+ public void test_singleton_individuals ()
+ {
+ var main_loop = new GLib.MainLoop (null, false);
+ this.kf_backend.set_up (
+ "[0]\n" +
+ "msn=foo hotmail com\n" +
+ "[1]\n" +
+ "__alias=Bar McBadgerson\n" +
+ "jabber=bar jabber org\n");
+
+ /* Ignore the error caused by not running the logger */
+ Test.log_set_fatal_handler ((d, l, m) =>
+ {
+ return !m.has_suffix ("couldn't get list of favourite individuals: " +
+ "The name org.freedesktop.Telepathy.Logger was not provided by " +
+ "any .service files");
+ });
+
+ /* Create a set of the individuals we expect to see */
+ HashSet<string> expected_individuals = new HashSet<string> (str_hash,
+ str_equal);
+
+ expected_individuals.add ("0");
+ expected_individuals.add ("1");
+
+ /* Set up the aggregator */
+ var aggregator = new IndividualAggregator ();
+ aggregator.individuals_changed.connect ((added, removed, m, a, r) =>
+ {
+ foreach (Individual i in added)
+ {
+ assert (i.personas.length () == 1);
+ /* Using the display ID is a little hacky, since we strictly
+ * shouldn't assume anything aboutâ?¦but for the key-file backend,
+ * we know it's equal to the group name. */
+ expected_individuals.remove (i.personas.data.display_id);
+ }
+
+ assert (removed == null);
+ });
+ aggregator.prepare ();
+
+ /* Kill the main loop after a few seconds. If there are still individuals
+ * in the set of expected individuals, the aggregator has either failed
+ * or been too slow (which we can consider to be failure). */
+ Timeout.add_seconds (3, () =>
+ {
+ main_loop.quit ();
+ return false;
+ });
+
+ main_loop.run ();
+
+ /* We should have enumerated exactly the individuals in the set */
+ assert (expected_individuals.size == 0);
+
+ this.kf_backend.tear_down ();
+ }
+
+ public void test_aliases ()
+ {
+ var main_loop = new GLib.MainLoop (null, false);
+ this.kf_backend.set_up (
+ "[0]\n" +
+ "__alias=Brian Briansson\n" +
+ "msn=foo hotmail com\n");
+
+ /* Ignore the error caused by not running the logger */
+ Test.log_set_fatal_handler ((d, l, m) =>
+ {
+ return !m.has_suffix ("couldn't get list of favourite individuals: " +
+ "The name org.freedesktop.Telepathy.Logger was not provided by " +
+ "any .service files");
+ });
+
+ /* Set up the aggregator */
+ var aggregator = new IndividualAggregator ();
+ uint individuals_changed_count = 0;
+ aggregator.individuals_changed.connect ((added, removed, m, a, r) =>
+ {
+ individuals_changed_count++;
+
+ assert (added.length () == 1);
+ assert (removed == null);
+
+ /* Check properties */
+ assert (added.data.alias == "Brian Briansson");
+ });
+ aggregator.prepare ();
+
+ /* Kill the main loop after a few seconds. If there are still individuals
+ * in the set of expected individuals, the aggregator has either failed
+ * or been too slow (which we can consider to be failure). */
+ Timeout.add_seconds (3, () =>
+ {
+ main_loop.quit ();
+ return false;
+ });
+
+ main_loop.run ();
+
+ /* We should have enumerated exactly one individual */
+ assert (individuals_changed_count == 1);
+
+ this.kf_backend.tear_down ();
+ }
+}
+
+public int main (string[] args)
+{
+ Test.init (ref args);
+
+ TestSuite root = TestSuite.get_root ();
+ root.add_suite (new IndividualRetrievalTests ().get_suite ());
+
+ Test.run ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]