[dconf] tests/: improve DBus mock interface



commit 01c439208a2a37271f462cd5531db3b7c3496c32
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Jul 16 10:17:16 2012 -0400

    tests/: improve DBus mock interface
    
    Put the queue of the outstanding async calls in the header and add an
    interface for defining handlers for sync calls.

 tests/client.c          |    8 ++++----
 tests/dconf-mock-dbus.c |   12 +++++++++---
 tests/dconf-mock.h      |   13 +++++++++++++
 3 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/tests/client.c b/tests/client.c
index ad0115d..ea6e4d9 100644
--- a/tests/client.c
+++ b/tests/client.c
@@ -1,10 +1,10 @@
 #define _BSD_SOURCE
 #include "../client/dconf-client.h"
 #include "../engine/dconf-engine.h"
+#include "dconf-mock.h"
 #include <string.h>
 #include <stdlib.h>
 
-extern GQueue outstanding_call_handles;
 static GThread *main_thread;
 
 static void
@@ -70,7 +70,7 @@ queue_up_100_writes (DConfClient *client)
       check_and_free (dconf_client_read (client, "/test/value"), g_variant_new_int32 (i));
     }
 
-  g_assert_cmpint (g_queue_get_length (&outstanding_call_handles), ==, 2);
+  g_assert_cmpint (g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles), ==, 2);
 }
 
 static void
@@ -80,7 +80,7 @@ fail_one_call (void)
   GError *error;
 
   error = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_NOENT, "--expected error from testcase--");
-  handle = g_queue_pop_head (&outstanding_call_handles);
+  handle = g_queue_pop_head (&dconf_mock_dbus_outstanding_call_handles);
   dconf_engine_call_handle_reply (handle, NULL, error);
   g_error_free (error);
 }
@@ -133,7 +133,7 @@ test_fast (void)
    * Each time, we should see a change notify.
    */
 
-  for (i = 0; g_queue_get_length (&outstanding_call_handles) > 1; i++)
+  for (i = 0; g_queue_get_length (&dconf_mock_dbus_outstanding_call_handles) > 1; i++)
     {
       changed_was_called = FALSE;
       fail_one_call ();
diff --git a/tests/dconf-mock-dbus.c b/tests/dconf-mock-dbus.c
index 772e9ed..82eff41 100644
--- a/tests/dconf-mock-dbus.c
+++ b/tests/dconf-mock-dbus.c
@@ -20,8 +20,9 @@
  */
 
 #include "../engine/dconf-engine.h"
+#include "dconf-mock.h"
 
-GQueue outstanding_call_handles;
+GQueue dconf_mock_dbus_outstanding_call_handles;
 
 gboolean
 dconf_engine_dbus_call_async_func (GBusType                bus_type,
@@ -33,11 +34,13 @@ dconf_engine_dbus_call_async_func (GBusType                bus_type,
                                    DConfEngineCallHandle  *handle,
                                    GError                **error)
 {
-  g_queue_push_tail (&outstanding_call_handles, handle);
+  g_queue_push_tail (&dconf_mock_dbus_outstanding_call_handles, handle);
 
   return TRUE;
 }
 
+DConfMockDBusSyncCallHandler dconf_mock_dbus_sync_call_handler;
+
 GVariant *
 dconf_engine_dbus_call_sync_func (GBusType             bus_type,
                                   const gchar         *bus_name,
@@ -48,5 +51,8 @@ dconf_engine_dbus_call_sync_func (GBusType             bus_type,
                                   const GVariantType  *reply_type,
                                   GError             **error)
 {
-  g_assert_not_reached ();
+  g_assert (dconf_mock_dbus_sync_call_handler != NULL);
+
+  return (* dconf_mock_dbus_sync_call_handler) (bus_type, bus_name, object_path, interface_name,
+                                                method_name, parameters, reply_type, error);
 }
diff --git a/tests/dconf-mock.h b/tests/dconf-mock.h
index 7c8fc0b..e01bcb5 100644
--- a/tests/dconf-mock.h
+++ b/tests/dconf-mock.h
@@ -2,6 +2,19 @@
 #define __dconf_mock_h__
 
 #include "../gvdb/gvdb-reader.h"
+#include <gio/gio.h>
+
+typedef GVariant *   (* DConfMockDBusSyncCallHandler)                   (GBusType             bus_type,
+                                                                         const gchar         *bus_name,
+                                                                         const gchar         *object_path,
+                                                                         const gchar         *interface_name,
+                                                                         const gchar         *method_name,
+                                                                         GVariant            *parameters,
+                                                                         const GVariantType  *expected_type,
+                                                                         GError             **error);
+
+extern DConfMockDBusSyncCallHandler                         dconf_mock_dbus_sync_call_handler;
+extern GQueue                                               dconf_mock_dbus_outstanding_call_handles;
 
 void                    dconf_mock_shm_reset                            (void);
 gint                    dconf_mock_shm_flag                             (const gchar *name);



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