[dconf/wip/reorg: 489/498] tests/: add a test for DConfEngine



commit 8b91a50942bca2ae295ee5dd166be0fe873a231d
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jul 5 23:58:43 2012 -0400

    tests/: add a test for DConfEngine
    
    So far just a simple test to make sure the threadsafety logic in
    dconf_engine_unref() is working properly.

 tests/.gitignore  |    1 +
 tests/Makefile.am |    4 +++
 tests/engine.c    |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index 2298217..fcafc43 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,6 +1,7 @@
 libdconf-dbus-stub.a
 
 dbus1
+engine
 gdbus-filter
 gdbus-thread
 gsettings
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6de67b5..f4f374a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,3 +52,7 @@ gdbus_filter_LDADD = $(gio_LIBS)
 gdbus_filter_SOURCES = \
 	../gdbus/dconf-gdbus-filter.c	\
 	dbus.c
+
+TEST_PROGS += engine
+engine_LDADD = $(engine_with_stub_LIBS) $(glib_LIBS)
+engine_SOURCES = engine.c
diff --git a/tests/engine.c b/tests/engine.c
new file mode 100644
index 0000000..be57265
--- /dev/null
+++ b/tests/engine.c
@@ -0,0 +1,68 @@
+#define _BSD_SOURCE
+
+#include <dconf-engine.h>
+
+static GThread *main_thread;
+
+void
+dconf_engine_change_notify (DConfEngine         *engine,
+                            const gchar         *prefix,
+                            const gchar * const *changes,
+                            const gchar         *tag,
+                            gpointer             user_data)
+{
+  /* ignore */
+}
+
+static gpointer
+test_signal_threadsafety_worker (gpointer user_data)
+{
+  gint *finished = user_data;
+  gint i;
+
+  for (i = 0; i < 20000; i++)
+    {
+      DConfEngine *engine;
+
+      engine = dconf_engine_new (NULL, NULL);
+      dconf_engine_unref (engine);
+    }
+
+  g_atomic_int_inc (finished);
+
+  return NULL;
+}
+
+static void
+test_signal_threadsafety (void)
+{
+#define N_WORKERS 4
+  GVariant *parameters;
+  gint finished = 0;
+  gint i;
+
+  parameters = g_variant_new_parsed ("('/test/key', [''], 'tag')");
+  g_variant_ref_sink (parameters);
+
+  for (i = 0; i < N_WORKERS; i++)
+    g_thread_unref (g_thread_new ("testcase worker", test_signal_threadsafety_worker, &finished));
+
+  while (g_atomic_int_get (&finished) < N_WORKERS)
+    dconf_engine_handle_dbus_signal (G_BUS_TYPE_SESSION,
+                                     ":1.2.3",
+                                     "/ca/desrt/dconf/Writer/user",
+                                     "Notify", parameters);
+  g_variant_unref (parameters);
+}
+
+int
+main (int argc, char **argv)
+{
+  main_thread = g_thread_self ();
+
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/engine/signal-threadsafety", test_signal_threadsafety);
+
+  return g_test_run ();
+}



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