summaryrefslogtreecommitdiff
path: root/dbus-gmain/tests
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2018-01-29 08:49:48 +0000
committerSimon McVittie <smcv@debian.org>2018-01-29 08:54:18 +0000
commitd354239ff42d972e6fe1448aae2db52e1af90aa7 (patch)
tree3c8ddaa11c7c36f5f1627b02293618ad7782db9a /dbus-gmain/tests
parentc80ae773e1cc50b6acde492b1b6f83f49f6e53c8 (diff)
Move dbus-gmain to root directory
Signed-off-by: Simon McVittie <smcv@debian.org>
Diffstat (limited to 'dbus-gmain/tests')
-rw-r--r--dbus-gmain/tests/30574.c139
-rw-r--r--dbus-gmain/tests/test-thread-client.c121
-rw-r--r--dbus-gmain/tests/test-thread-server.c233
-rw-r--r--dbus-gmain/tests/test-thread.h1
-rw-r--r--dbus-gmain/tests/util.c46
-rw-r--r--dbus-gmain/tests/util.h32
6 files changed, 0 insertions, 572 deletions
diff --git a/dbus-gmain/tests/30574.c b/dbus-gmain/tests/30574.c
deleted file mode 100644
index ca7b79f..0000000
--- a/dbus-gmain/tests/30574.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright © 2010-2012 Mike Gorse
- * Copyright © 2011-2018 Collabora Ltd.
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <dbus/dbus.h>
-#include <glib.h>
-#include <dbus-gmain/dbus-gmain.h>
-#include "util.h"
-
-DBusConnection *bus;
-GMainContext *main_context;
-
-typedef struct _SpiReentrantCallClosure
-{
- GMainLoop *loop;
- DBusMessage *reply;
-} SpiReentrantCallClosure;
-
-static void
-set_reply (DBusPendingCall * pending, void *user_data)
-{
- SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
-
- closure->reply = dbus_pending_call_steal_reply (pending);
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (bus, NULL);
-
- g_main_loop_quit (closure->loop);
-}
-
-static DBusMessage *
-send_and_allow_reentry (DBusConnection * bus, DBusMessage * message,
- dbus_bool_t switch_after_send)
-{
- DBusPendingCall *pending;
- SpiReentrantCallClosure closure;
-
- closure.loop = g_main_loop_new (main_context, FALSE);
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (bus,
- (switch_after_send ? NULL :
- main_context));
-
- if (!dbus_connection_send_with_reply (bus, message, &pending, 3000))
- {
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (bus, NULL);
- return NULL;
- }
- dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
- if (switch_after_send)
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (bus, main_context);
- g_main_loop_run (closure.loop);
-
- g_main_loop_unref (closure.loop);
- dbus_pending_call_unref (pending);
- return closure.reply;
-}
-
-static void
-send_test_message (dbus_bool_t switch_after_send)
-{
- DBusMessage *message, *reply;
- const char *str;
- DBusError error;
-
- dbus_error_init (&error);
- message = dbus_message_new_method_call ("org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- DBUS_INTERFACE_DBUS, "GetId");
- reply = send_and_allow_reentry (bus, message, switch_after_send);
- if (!reply)
- {
- fprintf(stderr, "Got no reply from send_and_allow_reentry\n");
- exit(1);
- }
- if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
- {
- char *err = NULL;
- dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &err, DBUS_TYPE_INVALID);
- fprintf (stderr, "Got error: %s\n", err);
- exit(1);
- }
- if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
- {
- fprintf(stderr, "Sorry; can't communicate: %s\n", error.message);
- exit(1);
- }
- dbus_message_unref (reply);
- dbus_message_unref (message);
-}
-
-int
-main(int argc, const char *argv[])
-{
- DBusError error;
-
- main_context = g_main_context_new ();
- dbus_error_init (&error);
- bus = dbus_bus_get_private (DBUS_BUS_SESSION, &error);
- if (!bus)
- {
- fprintf(stderr, "Couldn't connect to bus: %s\n", error.name);
- return 1;
- }
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (bus, NULL);
- send_test_message (FALSE);
- send_test_message (FALSE);
- send_test_message (TRUE);
-
- test_run_until_disconnected (bus, NULL);
- dbus_connection_unref (bus);
-
- dbus_shutdown ();
- g_main_context_unref (main_context);
-
- return 0;
-}
diff --git a/dbus-gmain/tests/test-thread-client.c b/dbus-gmain/tests/test-thread-client.c
deleted file mode 100644
index 79de541..0000000
--- a/dbus-gmain/tests/test-thread-client.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright © 2003 Red Hat Inc.
- * Copyright © 2006-2018 Collabora Ltd.
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <glib.h>
-#include <dbus-gmain/dbus-gmain.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "test-thread.h"
-
-DBusConnection *connection;
-
-static gpointer
-thread_func (gpointer data)
-{
- gint32 threadnr = GPOINTER_TO_INT (data);
- guint32 counter = 0;
- DBusMessageIter iter;
- DBusMessage *message;
- char *str;
-
- while (1)
- {
- message = dbus_message_new_method_call (NULL,
- "/org/freedesktop/DBus/GLib/ThreadTest",
- "org.freedesktop.DBus.GLib.ThreadTest",
- "TestMethod");
-
- dbus_message_iter_init_append (message, &iter);
-
- if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &threadnr))
- {
- g_print ("thread %d: append threadnr failed\n", threadnr);
- }
-
- if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &counter))
- {
- g_print ("thread %d: append counter (%d) failed\n", threadnr, counter);
- }
-
- str = g_strdup_printf ("Thread %d-%d\n", threadnr, counter);
- if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str))
- {
- g_print ("thread %d: append string (%s) failed\n", threadnr, str);
- }
- g_free (str);
-
- if (!dbus_connection_send (connection,
- message,
- NULL))
- {
- g_print ("thread %d: send message failed\n", threadnr);
- }
-
- dbus_message_unref (message);
-
- counter ++;
- }
-
- return NULL;
-}
-
-int
-main (int argc, char *argv[])
-{
- GMainLoop *loop;
- DBusError error;
- int i;
-
- if(argc < 2)
- {
- g_error("Need an address as argv[1]\n");
- return 1;
- }
-
- dbus_error_init (&error);
- connection = dbus_connection_open (argv[1], &error);
- if (connection == NULL)
- {
- g_printerr ("could not open connection: %s\n", error.message);
- dbus_error_free (&error);
- return 1;
- }
-
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (connection, NULL);
-
- for (i = 0; i < N_TEST_THREADS; i++)
- {
- g_thread_create (thread_func, GINT_TO_POINTER (i), FALSE, NULL);
- }
-
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
-
- return 0;
-}
-
diff --git a/dbus-gmain/tests/test-thread-server.c b/dbus-gmain/tests/test-thread-server.c
deleted file mode 100644
index c8839d1..0000000
--- a/dbus-gmain/tests/test-thread-server.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright © 2003-2006 Red Hat Inc.
- * Copyright © 2006-2018 Collabora Ltd.
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <glib.h>
-#include <dbus-gmain/dbus-gmain.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "test-thread.h"
-
-typedef struct {
- guint32 counters[N_TEST_THREADS];
-} ThreadTestData;
-
-static ThreadTestData *
-thread_test_data_new (void)
-{
- ThreadTestData *data;
-
- data = g_new0 (ThreadTestData, 1);
-
- return data;
-}
-
-static void
-thread_test_data_free (ThreadTestData *data)
-{
- g_free (data);
-}
-
-static DBusHandlerResult
-filter_test_message (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- ThreadTestData *data = user_data;
- DBusMessageIter iter;
- gint32 threadnr;
- guint32 counter;
- const char *str;
- char *expected_str;
- GString *counter_str;
- int i;
-
- if (!dbus_message_is_method_call (message, "org.freedesktop.DBus.GLib.ThreadTest",
- "TestMethod"))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- dbus_message_iter_init (message, &iter);
-
- if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32)
- {
- g_print ("First arg not right type\n");
- goto out;
- }
- dbus_message_iter_get_basic (&iter, &threadnr);
- if (threadnr < 0 || threadnr >= N_TEST_THREADS)
- {
- g_print ("Invalid thread nr\n");
- goto out;
- }
-
- if (! dbus_message_iter_next (&iter))
- {
- g_print ("Couldn't get second arg\n");
- goto out;
- }
-
- if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32)
- {
- g_print ("Second arg not right type\n");
- goto out;
- }
-
- dbus_message_iter_get_basic (&iter, &counter);
-
- if (counter != data->counters[threadnr])
- {
- g_print ("Thread %d, counter %d, expected %d\n", threadnr, counter, data->counters[threadnr]);
- goto out;
- }
- data->counters[threadnr]++;
-
- if (! dbus_message_iter_next (&iter))
- {
- g_print ("Couldn't get third arg\n");
- goto out;
- }
-
- if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
- {
- g_print ("Third arg not right type\n");
- goto out;
- }
-
- dbus_message_iter_get_basic (&iter, &str);
-
- if (str == NULL)
- {
- g_print ("No third arg\n");
- goto out;
- }
-
- expected_str = g_strdup_printf ("Thread %d-%d\n", threadnr, counter);
- if (strcmp (expected_str, str) != 0)
- {
- g_print ("Wrong string '%s', expected '%s'\n", str, expected_str);
- g_free (expected_str);
- goto out;
- }
- g_free (expected_str);
-
- if (dbus_message_iter_next (&iter))
- {
- g_print ("Extra args on end of message\n");
- goto out;
- }
-
- dbus_connection_flush (connection);
-
- counter_str = g_string_new ("");
- for (i = 0; i < N_TEST_THREADS; i++)
- {
- g_string_append_printf (counter_str, "%d ", data->counters[i]);
- }
- g_print ("%s\r", counter_str->str);
- g_string_free (counter_str, TRUE);
-
- out:
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult
-filter_disconnect (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- if (!dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL,
- "Disconnected"))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- g_print ("connection disconnected\n");
- dbus_connection_unref (connection);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static void
-new_connection_callback (DBusServer *server,
- DBusConnection *new_connection,
- void *user_data)
-{
- ThreadTestData * data;
-
- g_print ("new_connection_callback\n");
-
- dbus_connection_ref (new_connection);
- DBUS_GMAIN_FUNCTION_NAME (set_up_connection) (new_connection, NULL);
-
- data = thread_test_data_new ();
-
- if (!dbus_connection_add_filter (new_connection,
- filter_test_message, data,
- (DBusFreeFunction) thread_test_data_free))
- goto nomem;
-
- if (!dbus_connection_add_filter (new_connection,
- filter_disconnect, NULL, NULL))
- goto nomem;
-
- return;
-
- nomem:
- g_error ("no memory to setup new connection");
-}
-
-int
-main (int argc, char *argv[])
-{
- GMainLoop *loop;
- DBusServer *server;
- DBusError error;
-
- if (argc < 2)
- {
- fprintf (stderr, "Give the server address as an argument\n");
- return 1;
- }
-
- dbus_error_init (&error);
- server = dbus_server_listen (argv[1], &error);
- if (server == NULL)
- {
- fprintf (stderr, "Failed to start server on %s: %s\n",
- argv[1], error.message);
- dbus_error_free (&error);
- return 1;
- }
-
- dbus_server_set_new_connection_function (server,
- new_connection_callback,
- NULL, NULL);
-
- DBUS_GMAIN_FUNCTION_NAME (set_up_server) (server, NULL);
-
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
-
- return 0;
-}
diff --git a/dbus-gmain/tests/test-thread.h b/dbus-gmain/tests/test-thread.h
deleted file mode 100644
index 8c78fba..0000000
--- a/dbus-gmain/tests/test-thread.h
+++ /dev/null
@@ -1 +0,0 @@
-#define N_TEST_THREADS 5
diff --git a/dbus-gmain/tests/util.c b/dbus-gmain/tests/util.c
deleted file mode 100644
index d5fbe2f..0000000
--- a/dbus-gmain/tests/util.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Regression test utilities
- *
- * Copyright © 2009-2018 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright © 2009-2011 Nokia Corporation
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "util.h"
-
-void
-test_run_until_disconnected (DBusConnection *connection,
- GMainContext *context)
-{
- g_printerr ("Disconnecting... ");
-
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
- dbus_connection_close (connection);
-
- while (dbus_connection_get_is_connected (connection))
- {
- g_printerr (".");
- g_main_context_iteration (context, TRUE);
- }
-
- g_printerr (" disconnected\n");
-}
diff --git a/dbus-gmain/tests/util.h b/dbus-gmain/tests/util.h
deleted file mode 100644
index d9d7ced..0000000
--- a/dbus-gmain/tests/util.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Regression test utilities
- *
- * Copyright © 2009-2018 Collabora Ltd. <http://www.collabora.co.uk/>
- * Copyright © 2009-2011 Nokia Corporation
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#ifndef DBUS_GLIB_TEST_UTIL_H
-
-#include <dbus/dbus.h>
-#include <glib.h>
-
-void test_run_until_disconnected (DBusConnection *connection,
- GMainContext *context);
-
-#endif