[folks] tests: libsocialweb: new test infrastructure for libsocialweb



commit 2b314228f713803cf78c5f679f9e371ca7f47c9b
Author: Alban Crequy <alban crequy collabora co uk>
Date:   Mon Mar 14 11:49:56 2011 +0000

    tests: libsocialweb: new test infrastructure for libsocialweb

 configure.ac                                 |    7 +-
 tests/Makefile.am                            |    5 +
 tests/lib/Makefile.am                        |    5 +
 tests/lib/libsocialweb/Makefile.am           |   52 ++++
 tests/lib/libsocialweb/backend.vala          |  356 ++++++++++++++++++++++++++
 tests/lib/libsocialweb/session.conf.in       |   54 ++++
 tests/libsocialweb/Makefile.am               |   79 ++++++
 tests/libsocialweb/data/backend-lsw-only.ini |   12 +
 tests/libsocialweb/dummy-lsw.vala            |  170 ++++++++++++
 9 files changed, 739 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8199bf2..ad637a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -211,6 +211,8 @@ AC_SUBST([BACKEND_DIR])
 
 BACKEND_KF='$(top_builddir)/backends/key-file/.libs/libfolks-backend-key-file.so'
 AC_SUBST([BACKEND_KF])
+BACKEND_LIBSOCIALWEB='$(top_builddir)/backends/libsocialweb/.libs/libfolks-backend-libsocialweb.so'
+AC_SUBST([BACKEND_LIBSOCIALWEB])
 BACKEND_TP='$(top_builddir)/backends/telepathy/.libs/libfolks-backend-telepathy.so'
 AC_SUBST([BACKEND_TP])
 
@@ -220,7 +222,7 @@ if test x$enable_tracker_backend = xyes; then
 fi
 
 # All of the backend libraries in our tree; to be used by the tests
-BACKEND_UNINST_PATH='$(BACKEND_KF):$(BACKEND_TP)'
+BACKEND_UNINST_PATH='$(BACKEND_KF):$(BACKEND_TP):$(BACKEND_LIBSOCIALWEB)'
 if test x$enable_tracker_backend = xyes; then
   TRACKER_BACKEND_UNINST_PATH='$(BACKEND_TRACKER)'
   BACKEND_UNINST_PATH="$BACKEND_UNINST_PATH:$TRACKER_BACKEND_UNINST_PATH"
@@ -382,11 +384,14 @@ AC_CONFIG_FILES([
     tests/data/gconf.path
     tests/folks/Makefile
     tests/key-file/Makefile
+    tests/libsocialweb/Makefile
     tests/telepathy/Makefile
     tests/tracker/Makefile
     tests/lib/Makefile
     tests/lib/folks-test-uninstalled.pc
     tests/lib/key-file/Makefile
+    tests/lib/libsocialweb/Makefile
+    tests/lib/libsocialweb/session.conf
     tests/lib/telepathy/Makefile
     tests/lib/tracker/Makefile
     tests/lib/telepathy/contactlist/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ad1b2ea..9fcd77b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,6 +7,10 @@ SUBDIRS = \
     telepathy \
     $(NULL)
 
+if ENABLE_LIBSOCIALWEB
+SUBDIRS += libsocialweb
+endif
+
 if ENABLE_TRACKER
 SUBDIRS += tracker
 endif
@@ -18,6 +22,7 @@ DIST_SUBDIRS = \
     folks \
     key-file \
     telepathy \
+    libsocialweb \
     tracker \
     $(NULL)
 
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index c3da7a1..0b6296d 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -3,6 +3,10 @@ SUBDIRS = \
 	telepathy \
 	$(NULL)
 
+if ENABLE_LIBSOCIALWEB
+SUBDIRS += libsocialweb
+endif
+
 if ENABLE_TRACKER
 SUBDIRS += tracker
 endif
@@ -10,6 +14,7 @@ endif
 DIST_SUBDIRS = \
 	key-file \
 	telepathy \
+	libsocialweb \
 	tracker \
 	$(NULL)
 
diff --git a/tests/lib/libsocialweb/Makefile.am b/tests/lib/libsocialweb/Makefile.am
new file mode 100644
index 0000000..0d06d7c
--- /dev/null
+++ b/tests/lib/libsocialweb/Makefile.am
@@ -0,0 +1,52 @@
+VALAFLAGS += \
+	--library=libsocialweb-test \
+	--header=libsocialweb-test.h \
+	--vapidir=$(top_srcdir)/folks \
+	--vapidir=$(top_srcdir)/backends/libsocialweb/lib \
+	--vapidir=. \
+	--pkg gobject-2.0 \
+	--pkg gio-2.0 \
+	--pkg gee-1.0 \
+	--pkg folks \
+	--pkg libsocialweb-client \
+	--pkg folks-libsocialweb \
+	$(NULL)
+
+noinst_LTLIBRARIES = libsocialweb-test.la
+
+libsocialweb_test_la_SOURCES = \
+	backend.vala \
+	$(NULL)
+
+libsocialweb_test_la_CFLAGS = \
+	$(GLIB_CFLAGS) \
+	$(GIO_CFLAGS) \
+	$(GEE_CFLAGS) \
+	-I$(top_srcdir)/backends/libsocialweb/lib \
+	$(NULL)
+
+libsocialweb_test_la_LIBADD = \
+	$(GLIB_LIBS) \
+	$(GIO_LIBS) \
+	$(GEE_LIBS) \
+	$(top_builddir)/folks/libfolks.la \
+	$(top_builddir)/backends/libsocialweb/lib/libfolks-libsocialweb.la \
+	$(NULL)
+
+MAINTAINERCLEANFILES = \
+	libsocialweb-test.vapi \
+	libsocialweb-test.h \
+	$(NULL)
+
+EXTRA_DIST = \
+	libsocialweb-test.vapi \
+	libsocialweb-test.h \
+	session.conf \
+	$(NULL)
+
+GITIGNOREFILES = \
+	$(libsocialweb_test_la_SOURCES:.vala=.c) \
+	libsocialweb_test_la_vala.stamp \
+	$(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/lib/libsocialweb/backend.vala b/tests/lib/libsocialweb/backend.vala
new file mode 100644
index 0000000..c59dc6e
--- /dev/null
+++ b/tests/lib/libsocialweb/backend.vala
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * 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: Alban Crequy <alban crequy collabora co uk>
+ *
+ */
+
+using Gee;
+using GLib;
+
+[DBus (name = "com.meego.libsocialweb.ContactView")]
+public interface LibsocialwebTest.ContactView : DBusProxy
+{
+  public struct ContactsAddedElement
+    {
+      public string service;
+      public string id;
+      public int64 time;
+      [DBus (signature = "a{sas}")]
+      public Variant attrs;
+    }
+
+  public struct ContactsRemovedElement
+    {
+      public string service;
+      public string id;
+    }
+
+  public abstract async void Close () throws GLib.IOError;
+  public abstract async void Refresh () throws GLib.IOError;
+  public abstract async void Start () throws GLib.IOError;
+  public abstract async void Stop () throws GLib.IOError;
+
+  [DBus (signature = "a(ssxa{sas})")]
+  public signal void ContactsAdded (ContactsAddedElement[] contacts);
+  [DBus (signature = "a(ssxa{sas})")]
+  public signal void ContactsChanged (ContactsAddedElement[] contacts);
+  [DBus (signature = "a(ss)")]
+  public signal void ContactsRemoved (ContactsRemovedElement[] contacts);
+}
+
+[DBus (name = "com.meego.libsocialweb.ContactView")]
+public class LibsocialwebTest.LibsocialwebContactViewTest : Object
+{
+  public struct ContactsAddedElement
+    {
+      public string service;
+      public string id;
+      public int64 time;
+      [DBus (signature = "a{sas}")]
+      public Variant attrs;
+    }
+
+  public struct ContactsRemovedElement
+    {
+      public string service;
+      public string id;
+    }
+
+  public string query;
+  HashTable<string, string> p;
+  public string path;
+
+  public LibsocialwebContactViewTest (string query,
+      HashTable<string, string> p, string path)
+    {
+      this.query = query;
+      this.p = p;
+      this.path = path;
+    }
+
+  public void Close ()
+    {
+    }
+
+  public void Refresh ()
+    {
+    }
+
+  public void Start ()
+    {
+      debug ("Start() called.");
+      StartCalled (this.path);
+    }
+
+  public void Stop ()
+    {
+    }
+
+  [DBus (visible = false)]
+  public signal void CloseCalled (string path);
+  [DBus (visible = false)]
+  public signal void RefreshCalled (string path);
+  [DBus (visible = false)]
+  public signal void StartCalled (string path);
+  [DBus (visible = false)]
+  public signal void StopCalled (string path);
+
+  [DBus (signature = "a(ssxa{sas})")]
+  public signal void ContactsAdded (ContactsAddedElement[] contacts);
+  [DBus (signature = "a(ssxa{sas})")]
+  public signal void ContactsChanged (ContactsAddedElement[] contacts);
+  [DBus (signature = "a(ss)")]
+  public signal void ContactsRemoved (ContactsRemovedElement[] contacts);
+
+  /* The D-Bus signals cannot be emitted by just calling the function. See:
+   * https://bugzilla.gnome.org/show_bug.cgi?id=645528
+   * So we use the following methods for now.
+   */
+  [DBus (visible = false)]
+  public void EmitContactsAdded (string text)
+    {
+      try
+        {
+          var conn = Bus.get_sync (BusType.SESSION);
+          Variant v = new Variant.parsed (text);
+          conn.emit_signal (null, this.path,
+                LibsocialwebTest.Backend.LIBSOCIALWEB_IFACE + ".ContactView",
+                "ContactsAdded", v);
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+      catch (GLib.Error e)
+        {
+          assert_not_reached ();
+        }
+    }
+  [DBus (visible = false)]
+  public void EmitContactsChanged (string text)
+    {
+      try
+        {
+          var conn = Bus.get_sync (BusType.SESSION);
+          Variant v = new Variant.parsed (text);
+          conn.emit_signal (null, this.path,
+                LibsocialwebTest.Backend.LIBSOCIALWEB_IFACE + ".ContactView",
+                "ContactsChanged", v);
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+      catch (GLib.Error e)
+        {
+          assert_not_reached ();
+        }
+    }
+  [DBus (visible = false)]
+  public void EmitContactsRemoved (string text)
+    {
+      try
+        {
+          var conn = Bus.get_sync (BusType.SESSION);
+          Variant v = new Variant.parsed (text);
+          conn.emit_signal (null, this.path,
+                LibsocialwebTest.Backend.LIBSOCIALWEB_IFACE + ".ContactView",
+                "ContactsRemoved", v);
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+      catch (GLib.Error e)
+        {
+          assert_not_reached ();
+        }
+    }
+}
+
+[DBus (name = "com.meego.libsocialweb.Service")]
+public interface LibsocialwebTest.LibsocialwebServiceCapabilitiesTest : Object
+{
+  [DBus (name = "GetStaticCapabilities")]
+  public abstract string[] GetStaticCapabilities () throws GLib.IOError;
+}
+
+[DBus (name = "com.meego.libsocialweb.ContactsQuery")]
+public interface LibsocialwebTest.LibsocialwebServiceQueryTest : Object
+{
+  [DBus (name = "OpenView")]
+  public abstract ObjectPath OpenView (string query,
+      HashTable<string, string> p) throws GLib.IOError;
+}
+
+[DBus (name = "com.meego.libsocialweb.ContactsQuery")]
+public class LibsocialwebTest.LibsocialwebServiceTest : Object,
+    LibsocialwebTest.LibsocialwebServiceCapabilitiesTest,
+    LibsocialwebTest.LibsocialwebServiceQueryTest
+{
+  private int count = 0;
+  private string service_name;
+  public Gee.HashMap<string,LibsocialwebTest.LibsocialwebContactViewTest>
+      contact_views;
+
+  public LibsocialwebServiceTest (string service_name)
+    {
+      this.service_name = service_name;
+      this.contact_views = new Gee.HashMap<string,
+          LibsocialwebTest.LibsocialwebContactViewTest>();
+    }
+
+  public ObjectPath OpenView (string query, HashTable<string, string> p)
+    {
+      string path = LibsocialwebTest.Backend.LIBSOCIALWEB_PATH + "/View"
+          + count.to_string();
+      try
+        {
+          var conn = Bus.get_sync (BusType.SESSION);
+          LibsocialwebContactViewTest contact_view = new LibsocialwebContactViewTest
+              (query, p, path);
+          conn.register_object (path, contact_view);
+          contact_views[path] = contact_view;
+          this.count++;
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+
+      OpenViewCalled (query, p, path);
+      return new ObjectPath (path);
+    }
+
+  [DBus (visible = false)]
+  public signal void OpenViewCalled (string query, HashTable<string, string> p,
+                                     string path);
+
+  public string[] GetStaticCapabilities ()
+    {
+      var ret = new string[0];
+      ret += "has-contacts-query-iface";
+      return ret;
+    }
+}
+
+[DBus (name = "com.meego.libsocialweb")]
+public class LibsocialwebTest.LibsocialwebServerTest : Object
+{
+  private string[] services;
+
+  public LibsocialwebServerTest ()
+    {
+      services = new string[0];
+    }
+
+  [DBus (name = "IsOnline")]
+  public bool is_online ()
+    {
+      return true;
+    }
+  [DBus (name = "GetServices")]
+  public string[] get_services ()
+    {
+      return services;
+    }
+
+  [DBus (visible = false)]
+  public LibsocialwebTest.LibsocialwebServiceTest add_service
+      (string service_name)
+    {
+      LibsocialwebServiceTest service
+          = new LibsocialwebServiceTest (service_name);
+      try
+        {
+          var conn = Bus.get_sync (BusType.SESSION);
+          conn.register_object
+              <LibsocialwebTest.LibsocialwebServiceCapabilitiesTest>
+              (LibsocialwebTest.Backend.LIBSOCIALWEB_PATH + "/Service/"
+                  + service_name, service);
+          conn.register_object
+              <LibsocialwebTest.LibsocialwebServiceQueryTest>
+              (LibsocialwebTest.Backend.LIBSOCIALWEB_PATH + "/Service/"
+                  + service_name, service);
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+      this.services += service_name;
+      return service;
+    }
+}
+
+public class LibsocialwebTest.Backend
+{
+  public static const string LIBSOCIALWEB_IFACE = "com.meego.libsocialweb";
+  public static const string LIBSOCIALWEB_PATH = "/com/meego/libsocialweb";
+  public static const string LIBSOCIALWEB_BUS_NAME = "com.meego.libsocialweb";
+
+  public bool debug { get; set; }
+  private LibsocialwebServerTest lsw_server;
+
+  public signal void ready ();
+
+  public Backend ()
+    {
+      this.debug = false;
+    }
+
+  public void set_up ()
+    {
+      lsw_server = new LibsocialwebServerTest ();
+      try
+        {
+          var conn = Bus.get_sync (BusType.SESSION);
+          conn.register_object (LIBSOCIALWEB_PATH, lsw_server);
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+
+      Bus.own_name (
+        BusType.SESSION, LIBSOCIALWEB_BUS_NAME,
+        BusNameOwnerFlags.NONE,
+        on_bus_aquired,
+        () =>
+          {
+            this.ready ();
+          },
+        () =>
+          {
+            message ("Could not aquire D-Bus name\n");
+            assert_not_reached ();
+          });
+    }
+
+  private void on_bus_aquired (DBusConnection conn)
+    {
+    }
+
+  public LibsocialwebTest.LibsocialwebServiceTest add_service
+      (string service_name)
+    {
+      return lsw_server.add_service (service_name);
+    }
+
+  public void tear_down ()
+    {
+    }
+}
diff --git a/tests/lib/libsocialweb/session.conf.in b/tests/lib/libsocialweb/session.conf.in
new file mode 100644
index 0000000..0086c6e
--- /dev/null
+++ b/tests/lib/libsocialweb/session.conf.in
@@ -0,0 +1,54 @@
+<!DOCTYPE busconfig PUBLIC
+ "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd";>
+<busconfig>
+  <!-- Our well-known bus type, don't change this -->
+  <type>session</type>
+
+  <!-- If we fork, keep the user's original umask to avoid affecting
+       the behavior of child processes. -->
+  <keep_umask/>
+
+  <listen>unix:tmpdir=/tmp</listen>
+
+  <!-- Search for .service files in our special services dir -->
+  <servicedir>@abs_top_srcdir@/tests/lib/libsocialweb</servicedir>
+
+  <policy context="default">
+    <!-- Allow everything to be sent -->
+    <allow send_destination="*" eavesdrop="true"/>
+    <!-- Allow everything to be received -->
+    <allow eavesdrop="true"/>
+    <!-- Allow anyone to own anything -->
+    <allow own="*"/>
+  </policy>
+
+  <!-- raise the service start timeout to 40 seconds as it can timeout
+       on the live cd on slow machines -->
+  <limit name="service_start_timeout">60000</limit>
+
+  <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
+
+  <!-- For the session bus, override the default relatively-low limits
+       with essentially infinite limits, since the bus is just running
+       as the user anyway, using up bus resources is not something we need
+       to worry about. In some cases, we do set the limits lower than
+       "all available memory" if exceeding the limit is almost certainly a bug,
+       having the bus enforce a limit is nicer than a huge memory leak. But the
+       intent is that these limits should never be hit. -->
+
+  <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
+  <limit name="max_incoming_bytes">1000000000</limit>
+  <limit name="max_outgoing_bytes">1000000000</limit>
+  <limit name="max_message_size">1000000000</limit>
+  <limit name="service_start_timeout">120000</limit>
+  <limit name="auth_timeout">240000</limit>
+  <limit name="max_completed_connections">100000</limit>
+  <limit name="max_incomplete_connections">10000</limit>
+  <limit name="max_connections_per_user">100000</limit>
+  <limit name="max_pending_service_starts">10000</limit>
+  <limit name="max_names_per_connection">50000</limit>
+  <limit name="max_match_rules_per_connection">50000</limit>
+  <limit name="max_replies_per_connection">50000</limit>
+
+</busconfig>
diff --git a/tests/libsocialweb/Makefile.am b/tests/libsocialweb/Makefile.am
new file mode 100644
index 0000000..a94af28
--- /dev/null
+++ b/tests/libsocialweb/Makefile.am
@@ -0,0 +1,79 @@
+AM_CPPFLAGS = \
+	$(GLIB_CFLAGS) \
+	$(GIO_CFLAGS) \
+	$(GEE_CFLAGS) \
+	$(SW_CLIENT_CFLAGS) \
+	-I$(top_srcdir)/folks \
+	-I$(top_srcdir)/backends/libsocialweb/lib \
+	-I$(top_srcdir)/tests/lib \
+	-I$(top_srcdir)/tests/lib/libsocialweb \
+	-include $(CONFIG_HEADER) \
+	$(NULL)
+
+LDADD = \
+	$(top_builddir)/tests/lib/libfolks-test.la \
+	$(top_builddir)/tests/lib/libsocialweb/libsocialweb-test.la \
+	$(top_builddir)/backends/libsocialweb/lib/libfolks-libsocialweb.la \
+	$(top_builddir)/folks/libfolks.la \
+	$(GLIB_LIBS) \
+	$(GIO_LIBS) \
+	$(GEE_LIBS) \
+	$(SW_CLIENT_LIBS) \
+	-L$(top_srcdir)/backends/libsocialweb/lib \
+	$(NULL)
+
+RUN_WITH_PRIVATE_BUS = $(top_srcdir)/tests/tools/with-session-bus.sh
+
+AM_VALAFLAGS = \
+	--vapidir=. \
+	--vapidir=$(top_srcdir)/folks \
+	--vapidir=$(top_srcdir)/backends/libsocialweb/lib \
+	--vapidir=$(top_srcdir)/tests/lib \
+	--vapidir=$(top_srcdir)/tests/lib/libsocialweb \
+	--pkg gobject-2.0 \
+	--pkg gio-2.0 \
+	--pkg gee-1.0 \
+	--pkg folks \
+	--pkg folks-test \
+	--pkg folks-libsocialweb \
+	--pkg libsocialweb-client \
+	--pkg libsocialweb-test \
+	$(NULL)
+
+# in order from least to most complex
+noinst_PROGRAMS = \
+	dummy-lsw \
+	$(NULL)
+
+SESSION_CONF = $(top_builddir)/tests/lib/libsocialweb/session.conf
+backend_store_key_file=$(srcdir)/data/backend-lsw-only.ini
+TESTS_ENVIRONMENT = \
+	GCONF_DEFAULT_SOURCE_PATH= abs_top_srcdir@/tests/data/gconf.path \
+	FOLKS_BACKEND_PATH=$(BACKEND_UNINST_PATH) \
+	FOLKS_BACKEND_STORE_KEY_FILE_PATH=$(backend_store_key_file) \
+	$(RUN_WITH_PRIVATE_BUS) \
+	--config-file=$(SESSION_CONF) \
+	--
+TESTS = $(noinst_PROGRAMS)
+
+dummy_lsw_SOURCES = \
+	dummy-lsw.vala \
+	$(NULL)
+
+CLEANFILES = \
+        *.pid \
+        *.address \
+        $(TESTS) \
+        $(NULL)
+
+MAINTAINERCLEANFILES = \
+        $(addsuffix .c,$(noinst_PROGRAMS)) \
+        dummy_lsw_vala.stamp \
+        $(NULL)
+
+EXTRA_DIST = \
+	$(MAINTAINERCLEANFILES) \
+	$(backend_store_key_file) \
+	$(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/libsocialweb/data/backend-lsw-only.ini b/tests/libsocialweb/data/backend-lsw-only.ini
new file mode 100644
index 0000000..7804b94
--- /dev/null
+++ b/tests/libsocialweb/data/backend-lsw-only.ini
@@ -0,0 +1,12 @@
+
+[key-file]
+enabled=false
+
+[telepathy]
+enabled=false
+
+[tracker]
+enabled=false
+
+[libsocialweb]
+enabled=true
diff --git a/tests/libsocialweb/dummy-lsw.vala b/tests/libsocialweb/dummy-lsw.vala
new file mode 100644
index 0000000..0560ed5
--- /dev/null
+++ b/tests/libsocialweb/dummy-lsw.vala
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * 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: Alban Crequy <alban crequy collabora co uk>
+ *
+ */
+
+using LibsocialwebTest;
+using Folks;
+using Gee;
+using GLib;
+
+public class DummyLswTests : Folks.TestCase
+{
+  private LibsocialwebTest.Backend _lsw_backend;
+
+  public DummyLswTests ()
+    {
+      base ("DummyLsw");
+
+      this._lsw_backend = new LibsocialwebTest.Backend ();
+
+      this.add_test ("dummy libsocialweb", this.test_dummy_libsocialweb);
+    }
+
+  public override void set_up ()
+    {
+    }
+
+  public override void tear_down ()
+    {
+    }
+
+  public void test_dummy_libsocialweb ()
+    {
+      var main_loop = new GLib.MainLoop (null, false);
+
+      this._lsw_backend.ready.connect(() =>
+        {
+          main_loop.quit ();
+        });
+      uint timer_id = Timeout.add_seconds (5, () =>
+        {
+          assert_not_reached ();
+          return false;
+        });
+      this._lsw_backend.set_up ();
+      main_loop.run ();
+      Source.remove (timer_id);
+
+      var mysocialnetwork = this._lsw_backend.add_service ("mysocialnetwork");
+      var p = new GLib.HashTable<string,string> (null, null);
+
+      try
+        {
+          var view_path = mysocialnetwork.OpenView("feed", p);
+          var conn = Bus.get_sync (BusType.SESSION);
+          conn.get_proxy<LibsocialwebTest.ContactView>
+              .begin<LibsocialwebTest.ContactView> (
+              "com.meego.libsocialweb", view_path, 0, null, (v) =>
+            {
+              LibsocialwebTest.ContactView view
+                  = (LibsocialwebTest.ContactView)v;
+              view.Start();
+              mysocialnetwork.contact_views[view_path].ContactsAdded
+                  (new LibsocialwebTest.LibsocialwebContactViewTest
+                      .ContactsAddedElement[0]);
+              mysocialnetwork.contact_views[view_path].ContactsAdded
+                  (new LibsocialwebTest.LibsocialwebContactViewTest
+                      .ContactsAddedElement[0]);
+              main_loop.quit ();
+            });
+        }
+      catch (GLib.IOError e)
+        {
+          assert_not_reached ();
+        }
+
+
+      timer_id = Timeout.add_seconds (5, () =>
+        {
+          assert_not_reached ();
+        });
+      main_loop.run ();
+      Source.remove (timer_id);
+
+      /* Ok, real test now */
+      debug ("Ok, real test now");
+
+      mysocialnetwork.OpenViewCalled.connect((query, p, path) =>
+        {
+          debug ("mysocialnetwork.OpenViewCalled.connect");
+          mysocialnetwork.contact_views[path].StartCalled.connect ( (path) =>
+            {
+              debug ("OpenViewCalled.connect");
+              Idle.add (() =>
+                {
+                  string text = "([('mysocialnetwork', 'id01', %x, "
+                      + "{'id': ['id01'], 'name': ['Gargantua']}), "
+                     + "('mysocialnetwork', 'id02', %x, "
+                      + "{'id': ['id02'], 'name': ['Pantagruel']})],)";
+                  Variant v = new Variant.parsed (text, 1300792578, 1300792579);
+                  try
+                    {
+                      var conn = Bus.get_sync (BusType.SESSION);
+                      conn.emit_signal (null, path,
+                          "com.meego.libsocialweb.ContactView",
+                          "ContactsAdded", v);
+                    }
+                  catch (GLib.IOError e)
+                    {
+                      assert_not_reached ();
+                    }
+                  catch (GLib.Error e)
+                    {
+                      assert_not_reached ();
+                    }
+                  return false;
+                });
+            });
+        });
+
+      var aggregator = new IndividualAggregator ();
+      aggregator.individuals_changed.connect ((added, removed, m, a, r) =>
+        {
+          debug ("Aggregator got some data!");
+          foreach (Individual i in added)
+            {
+              string nickname = ((Folks.NameDetails) i).nickname;
+              debug ("nickname: %s", nickname);
+            }
+          main_loop.quit ();
+        });
+      aggregator.prepare ();
+
+      timer_id = Timeout.add_seconds (5, () =>
+        {
+          assert_not_reached ();
+        });
+      main_loop.run ();
+      Source.remove (timer_id);
+
+      this._lsw_backend.tear_down ();
+    }
+}
+
+public int main (string[] args)
+{
+  Test.init (ref args);
+
+  TestSuite root = TestSuite.get_root ();
+  root.add_suite (new DummyLswTests ().get_suite ());
+
+  Test.run ();
+
+  return 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]