dbus/test/glib Makefile.am,1.2,1.3 test-dbus-glib.c,1.2,1.3
Havoc Pennington
hp@pdx.freedesktop.org
Sat, 11 Oct 2003 22:59:41 -0700
Update of /cvs/dbus/dbus/test/glib
In directory pdx:/tmp/cvs-serv535/test/glib
Modified Files:
Makefile.am test-dbus-glib.c
Log Message:
2003-10-12 Havoc Pennington <hp@pobox.com>
Added test code that 1) starts an actual bus daemon and 2) uses
DBusGProxy; fixed bugs that were revealed by the test. Lots
more testing possible, but this is the basic framework.
* glib/dbus-gproxy.c (dbus_gproxy_manager_unregister): remove
empty proxy lists from the proxy list hash
* dbus/dbus-message.c (dbus_message_iter_get_args_valist): add a
couple of return_if_fail checks
* dbus/dbus-pending-call.c (_dbus_pending_call_new): use dbus_new0
to allocate, so everything is cleared to NULL as it should be.
* glib/dbus-gmain.c (dbus_connection_setup_with_g_main): pass
source as data to dbus_connection_set_timeout_functions() as the
timeout functions expected
* test/glib/run-test.sh: add a little script to start up a message
bus and run tests using it
* tools/dbus-launch.1: updates
* tools/dbus-launch.c (main): add --config-file option
* tools/dbus-launch.c (main): remove confusing else if (runprog)
that could never be reached.
* dbus/dbus-message.c (dbus_message_new_method_return)
(dbus_message_new_error, dbus_message_new_signal): set the
no-reply-expected flag on all these. Redundant, but may
as well be consistent.
Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile.am 30 Sep 2003 02:43:21 -0000 1.2
+++ Makefile.am 12 Oct 2003 05:59:39 -0000 1.3
@@ -1,5 +1,17 @@
INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) -I$(top_srcdir)/glib
+## note that TESTS has special meaning (stuff to use in make check)
+## so if adding tests not to be run in make check, don't add them to
+## TESTS
+if DBUS_BUILD_TESTS
+TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=$(top_builddir) DBUS_TEST_HOMEDIR=$(top_builddir)/dbus
+TESTS=run-test.sh
+else
+TESTS=
+endif
+
+EXTRA_DIST=run-test.sh
+
if DBUS_BUILD_TESTS
if HAVE_GLIB_THREADS
Index: test-dbus-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-dbus-glib.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test-dbus-glib.c 30 Sep 2003 02:43:21 -0000 1.2
+++ test-dbus-glib.c 12 Oct 2003 05:59:39 -0000 1.3
@@ -1,52 +1,74 @@
/* -*- mode: C; c-file-style: "gnu" -*- */
#include "dbus-glib.h"
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
int
main (int argc, char **argv)
{
DBusConnection *connection;
- DBusMessage *message, *reply;
GMainLoop *loop;
- DBusError error;
-
- if (argc < 2)
- {
- g_printerr ("Give the server address as an argument\n");
- return 1;
- }
+ GError *error;
+ DBusGProxy *driver;
+ DBusPendingCall *call;
+ char **service_list;
+ int service_list_len;
+ int i;
+ g_type_init ();
+
loop = g_main_loop_new (NULL, FALSE);
- dbus_error_init (&error);
- connection = dbus_connection_open (argv[1], &error);
+ error = NULL;
+ connection = dbus_bus_get_with_g_main (DBUS_BUS_SESSION,
+ &error);
if (connection == NULL)
{
- g_printerr ("Failed to open connection to %s: %s\n", argv[1],
- error.message);
- dbus_error_free (&error);
- return 1;
+ g_printerr ("Failed to open connection to bus: %s\n",
+ error->message);
+ g_error_free (error);
+ exit (1);
}
- dbus_connection_setup_with_g_main (connection, NULL);
+ /* Create a proxy object for the "bus driver" */
+
+ driver = dbus_gproxy_new_for_service (connection,
+ DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
+ DBUS_PATH_ORG_FREEDESKTOP_DBUS,
+ DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS);
- message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
- DBUS_PATH_ORG_FREEDESKTOP_DBUS,
- DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
- "Hello");
+ /* Call ListServices method */
+
+ call = dbus_gproxy_begin_call (driver, "ListServices", DBUS_TYPE_INVALID);
- dbus_error_init (&error);
- reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
- if (reply == NULL)
+ error = NULL;
+ if (!dbus_gproxy_end_call (driver, call, &error,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &service_list, &service_list_len,
+ DBUS_TYPE_INVALID))
{
- g_printerr ("Error on hello message: %s\n", error.message);
- dbus_error_free (&error);
- return 1;
+ g_printerr ("Failed to complete ListServices call: %s\n",
+ error->message);
+ g_error_free (error);
+ exit (1);
}
+
+ g_print ("Services on the message bus:\n");
+ i = 0;
+ while (i < service_list_len)
+ {
+ g_assert (service_list[i] != NULL);
+ g_print (" %s\n", service_list[i]);
+ ++i;
+ }
+ g_assert (service_list[i] == NULL);
- g_print ("reply received\n");
+ dbus_free_string_array (service_list);
+
+ g_object_unref (G_OBJECT (driver));
- g_main_loop_run (loop);
+ g_print ("Successfully completed %s\n", argv[0]);
return 0;
}