g_type_init ();
g_test_init (&argc, &argv, NULL);
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
g_test_add_func ("/actions/basic", test_basic);
g_test_add_func ("/actions/simplegroup", test_simple_group);
g_test_add_func ("/actions/stateful", test_stateful);
g_main_loop_run (main_loop);
- session_bus_down ();
- _g_object_wait_for_single_ref_do (c);
g_object_unref (c);
-
- g_assert (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL) == NULL);
+ session_bus_down ();
}
g_application_quit (G_APPLICATION (app));
+ g_object_unref (c);
g_object_unref (app);
g_free (id);
session_bus_down ();
- _g_object_wait_for_single_ref (c);
- g_object_unref (c);
-
- g_assert (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL) == NULL);
}
static void
g_signal_connect (app, "activate", G_CALLBACK (quit_activate), NULL);
g_application_run (app, 1, argv);
g_object_unref (app);
+ g_object_unref (c);
g_assert (quit_activated);
session_bus_down ();
-
- _g_object_wait_for_single_ref (c);
- g_object_unref (c);
-
- g_assert (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL) == NULL);
}
static void
g_test_init (&argc, &argv, NULL);
- /* all the tests use a session bus with a well-known address
- * that we can bring up and down using session_bus_up() and
- * session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
g_test_add_func ("/gapplication/no-dbus", test_nodbus);
g_test_add_func ("/gapplication/basic", basic);
g_type_init ();
g_test_init (&argc, &argv, NULL);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
session_bus_up ();
g_test_add_func ("/gdbus/auth/client/EXTERNAL", auth_client_external);
g_type_init ();
g_test_init (&argc, &argv, NULL);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
g_test_add_func ("/gdbus/bz627724", test_bz627724);
return g_test_run();
on_timeout (gpointer user_data)
{
/* tear down bus */
- session_bus_down ();
+ session_bus_stop ();
return FALSE; /* remove source */
}
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
session_bus_up ();
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
/* this is safe; testserver will exit once the bus goes away */
g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
}
g_dbus_connection_signal_unsubscribe (connection, signal_handler_id);
- _g_object_wait_for_single_ref (connection);
g_object_unref (connection);
session_bus_down ();
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
g_test_add_func ("/gdbus/connection/flush", test_connection_flush);
g_test_add_func ("/gdbus/connection/large_message", test_connection_large_message);
*/
g_assert (!g_dbus_connection_is_closed (c));
g_dbus_connection_set_exit_on_close (c, FALSE);
- session_bus_down ();
+ session_bus_stop ();
_g_assert_signal_received (c, "closed");
g_assert (g_dbus_connection_is_closed (c));
-
- _g_object_wait_for_single_ref (c);
g_object_unref (c);
+
+ session_bus_down ();
}
/* ---------------------------------------------------------------------------------------------------- */
* Check that we get an error when sending to a connection that is disconnected.
*/
g_dbus_connection_set_exit_on_close (c, FALSE);
- session_bus_down ();
+ session_bus_stop ();
_g_assert_signal_received (c, "closed");
g_assert (g_dbus_connection_is_closed (c));
NULL);
g_main_loop_run (loop);
- _g_object_wait_for_single_ref (c);
g_object_unref (c);
+
+ session_bus_down ();
}
/* ---------------------------------------------------------------------------------------------------- */
g_dbus_connection_signal_unsubscribe (c1, s3);
g_dbus_connection_signal_unsubscribe (c1, s1b);
- _g_object_wait_for_single_ref (c1);
- _g_object_wait_for_single_ref (c2);
- _g_object_wait_for_single_ref (c3);
-
g_object_unref (c1);
g_object_unref (c2);
g_object_unref (c3);
g_dbus_connection_remove_filter (c, filter_id);
- _g_object_wait_for_single_ref (c);
g_object_unref (c);
g_object_unref (m);
g_free (name);
g_free (guid);
- _g_object_wait_for_single_ref (connection);
g_object_unref (connection);
session_bus_down ();
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
g_test_add_func ("/gdbus/connection/basic", test_connection_basic);
g_test_add_func ("/gdbus/connection/life-cycle", test_connection_life_cycle);
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
if (g_test_verbose ())
silence = 0;
}
else
{
- session_bus_down ();
+ session_bus_stop ();
}
g_main_loop_run (loop);
/* this is only reached when we turn off exit-on-close */
g_main_loop_unref (loop);
+ g_object_unref (c);
+
+ session_bus_down ();
+
exit (0);
}
/* To prevent from exiting and attaching a D-Bus tool like D-Feet; uncomment: */
#if 0
- g_debug ("Point D-feet or other tool at: %s", session_bus_get_temporary_address());
+ g_debug ("Point D-feet or other tool at: %s", g_test_dbus_get_temporary_address());
g_main_loop_run (loop);
#endif
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
session_bus_up ();
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
g_test_add_func ("/gdbus/object-registration", test_object_registration);
g_test_add_func ("/gdbus/registered-interfaces", test_registered_interfaces);
GDBusConnection *connection;
GError *error;
- session_bus_up ();
-
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
NULL,
main (int argc,
char *argv[])
{
+ gint ret;
+
g_type_init ();
g_test_init (&argc, &argv, NULL);
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ session_bus_up ();
g_test_add_func ("/gdbus/introspection-parser", test_introspection_parser);
g_test_add_func ("/gdbus/introspection-generate", test_generate);
g_test_add_func ("/gdbus/introspection-extra-data", test_extra_data);
#endif
- return g_test_run();
+ ret = g_test_run ();
+
+ session_bus_down ();
+
+ return ret;
}
*
*/
data.expect_null_connection = TRUE;
- session_bus_down ();
+ session_bus_stop ();
while (data.num_lost != 2)
g_main_loop_run (loop);
g_assert_cmpint (data.num_acquired, ==, 2);
g_bus_unown_name (id);
g_assert_cmpint (data.num_free_func, ==, 5);
- _g_object_wait_for_single_ref (c);
g_object_unref (c);
g_object_unref (c2);
+
+ session_bus_down ();
}
/* ---------------------------------------------------------------------------------------------------- */
* Nuke the bus and check that the name vanishes and is lost.
*/
data.expect_null_connection = TRUE;
- session_bus_down ();
+ session_bus_stop ();
g_main_loop_run (loop);
g_assert_cmpint (data.num_lost, ==, 1);
g_assert_cmpint (data.num_vanished, ==, 2);
g_bus_unown_name (owner_id);
g_assert_cmpint (data.num_free_func, ==, 2);
+ session_bus_down ();
}
/* ---------------------------------------------------------------------------------------------------- */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
g_test_add_func ("/gdbus/validate-names", test_validate_names);
g_test_add_func ("/gdbus/bus-own-name", test_bus_own_name);
g_type_init ();
g_test_init (&argc, &argv, NULL);
- g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
-
introspection_data = g_dbus_node_info_new_for_xml (test_interface_introspection_xml, NULL);
g_assert (introspection_data != NULL);
test_interface_introspection_data = introspection_data->interfaces[0];
session_bus_up ();
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
loop = g_main_loop_new (NULL, TRUE);
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
g_object_unref (connection);
g_main_loop_unref (loop);
+
+ /* TODO: should call session_bus_down() but that requires waiting
+ * for all the oustanding method calls to complete...
+ */
}
int
main (int argc,
char *argv[])
{
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
g_type_init ();
g_test_init (&argc, &argv, NULL);
+ g_test_dbus_unset ();
+
g_test_add_func ("/gdbus/proxy/vs-threads", test_proxy);
return g_test_run();
session_bus_up ();
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ g_test_dbus_unset ();
g_test_add_func ("/gdbus/proxy-well-known-name", test_proxy_well_known_name);
GDBusConnection *connection;
GError *error;
- session_bus_up ();
-
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
NULL,
/* all the tests rely on a shared main loop */
loop = g_main_loop_new (NULL, FALSE);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+ session_bus_up ();
g_test_add_func ("/gdbus/proxy", test_proxy);
g_test_add_func ("/gdbus/proxy/no-properties", test_no_properties);
ret = g_test_run();
g_dbus_node_info_unref (introspection_data);
+
+ session_bus_down ();
return ret;
}
/* GLib testing framework examples and tests
*
- * Copyright (C) 2008-2010 Red Hat, Inc.
+ * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: David Zeuthen <davidz@redhat.com>
+ * Author: Xavier Claessens <xavier.claessens@collabora.co.uk>
*/
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <stdio.h>
-
-#include <gio/gio.h>
-
#include "gdbus-sessionbus.h"
-/* ---------------------------------------------------------------------------------------------------- */
-/* Utilities for bringing up and tearing down session message bus instances */
-
-static void
-watch_parent (gint fd)
-{
- GPollFD fds[1];
- gint num_events;
- gchar buf[512];
- gssize bytes_read;
- GArray *buses_to_kill_array;
-
- fds[0].fd = fd;
- fds[0].events = G_IO_HUP | G_IO_IN;
- fds[0].revents = 0;
-
- buses_to_kill_array = g_array_new (FALSE, TRUE, sizeof (guint));
-
- do
- {
- guint pid;
- guint n;
-
- num_events = g_poll (fds, 1, -1);
- if (num_events == 0)
- continue;
-
- if (fds[0].revents == G_IO_HUP)
- {
- for (n = 0; n < buses_to_kill_array->len; n++)
- {
- pid = g_array_index (buses_to_kill_array, guint, n);
- g_print ("cleaning up bus with pid %d\n", pid);
- kill (pid, SIGTERM);
- }
- g_array_free (buses_to_kill_array, TRUE);
- exit (0);
- }
-
- //g_debug ("data from parent");
-
- memset (buf, '\0', sizeof buf);
- again:
- bytes_read = read (fds[0].fd, buf, sizeof buf);
- if (bytes_read < 0 && (errno == EAGAIN || errno == EINTR))
- goto again;
-
- if (sscanf (buf, "add %d\n", &pid) == 1)
- {
- g_array_append_val (buses_to_kill_array, pid);
- }
- else if (sscanf (buf, "remove %d\n", &pid) == 1)
- {
- for (n = 0; n < buses_to_kill_array->len; n++)
- {
- if (g_array_index (buses_to_kill_array, guint, n) == pid)
- {
- g_array_remove_index (buses_to_kill_array, n);
- pid = 0;
- break;
- }
- }
- if (pid != 0)
- {
- g_warning ("unknown pid %d to remove", pid);
- }
- }
- else
- {
- g_warning ("unknown command from parent '%s'", buf);
- }
- }
- while (TRUE);
-
-}
-
-static GHashTable *session_bus_address_to_pid = NULL;
-static gint pipe_fds[2];
-
-const gchar *
-session_bus_up_with_address (const gchar *given_address)
-{
- gchar *address;
- int stdout_fd;
- GError *error;
- gchar *argv[] = {"dbus-daemon", "--print-address", "--config-file=foo", NULL};
- GPid pid;
- gchar buf[512];
- ssize_t bytes_read;
- gchar *config_file_name;
- gint config_file_fd;
- GString *config_file_contents;
-
- address = NULL;
- error = NULL;
- config_file_name = NULL;
- config_file_fd = -1;
- argv[2] = NULL;
-
- config_file_fd = g_file_open_tmp ("g-dbus-tests-XXXXXX",
- &config_file_name,
- &error);
- if (config_file_fd < 0)
- {
- g_warning ("Error creating temporary config file: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- config_file_contents = g_string_new (NULL);
- g_string_append (config_file_contents, "<busconfig>\n");
- g_string_append (config_file_contents, " <type>session</type>\n");
- g_string_append_printf (config_file_contents, " <listen>%s</listen>\n", given_address);
- g_string_append (config_file_contents,
- " <policy context=\"default\">\n"
- " <!-- Allow everything to be sent -->\n"
- " <allow send_destination=\"*\" eavesdrop=\"true\"/>\n"
- " <!-- Allow everything to be received -->\n"
- " <allow eavesdrop=\"true\"/>\n"
- " <!-- Allow anyone to own anything -->\n"
- " <allow own=\"*\"/>\n"
- " </policy>\n");
- g_string_append (config_file_contents, "</busconfig>\n");
-
- if (write (config_file_fd, config_file_contents->str, config_file_contents->len) != (gssize) config_file_contents->len)
- {
- g_warning ("Error writing %d bytes to config file: %m", (gint) config_file_contents->len);
- g_string_free (config_file_contents, TRUE);
- goto out;
- }
- g_string_free (config_file_contents, TRUE);
-
- argv[2] = g_strdup_printf ("--config-file=%s", config_file_name);
-
- if (session_bus_address_to_pid == NULL)
- {
- /* keep a mapping from session bus address to the pid */
- session_bus_address_to_pid = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
- /* fork a child to clean up session buses when we are killed */
- if (pipe (pipe_fds) != 0)
- {
- g_warning ("pipe() failed: %m");
- g_assert_not_reached ();
- }
- switch (fork ())
- {
- case -1:
- g_warning ("fork() failed: %m");
- g_assert_not_reached ();
- break;
-
- case 0:
- /* child */
- close (pipe_fds[1]);
- watch_parent (pipe_fds[0]);
- break;
-
- default:
- /* parent */
- close (pipe_fds[0]);
- break;
- }
-
- //atexit (cleanup_session_buses);
- /* TODO: need to handle the cases where we crash */
- }
- else
- {
- /* check if we already have a bus running for this address */
- if (g_hash_table_lookup (session_bus_address_to_pid, given_address) != NULL)
- {
- g_warning ("Already have a bus instance for the given address %s", given_address);
- goto out;
- }
- }
-
- if (!g_spawn_async_with_pipes (NULL,
- argv,
- NULL,
- G_SPAWN_SEARCH_PATH,
- NULL,
- NULL,
- &pid,
- NULL,
- &stdout_fd,
- NULL,
- &error))
- {
- g_warning ("Error spawning dbus-daemon: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- memset (buf, '\0', sizeof buf);
- again:
- bytes_read = read (stdout_fd, buf, sizeof buf);
- if (bytes_read < 0 && (errno == EAGAIN || errno == EINTR))
- goto again;
- close (stdout_fd);
-
- if (bytes_read == 0 || bytes_read == sizeof buf)
- {
- g_warning ("Error reading address from dbus daemon, %d bytes read", (gint) bytes_read);
- kill (SIGTERM, pid);
- goto out;
- }
-
- address = g_strdup (buf);
- g_strstrip (address);
-
- /* write the pid to the child so it can kill it when we die */
- g_snprintf (buf, sizeof buf, "add %d\n", (guint) pid);
- write (pipe_fds[1], buf, strlen (buf));
-
- /* start dbus-monitor */
- if (g_getenv ("G_DBUS_MONITOR") != NULL)
- {
- g_spawn_command_line_async ("dbus-monitor --session", NULL);
- usleep (500 * 1000);
- }
-
- g_hash_table_insert (session_bus_address_to_pid, address, GUINT_TO_POINTER (pid));
-
- out:
- if (config_file_fd > 0)
- {
- if (close (config_file_fd) != 0)
- {
- g_warning ("Error closing fd for config file %s: %m", config_file_name);
- }
- g_assert (config_file_name != NULL);
- if (unlink (config_file_name) != 0)
- {
- g_warning ("Error unlinking config file %s: %m", config_file_name);
- }
- }
- g_free (argv[2]);
- g_free (config_file_name);
- return address;
-}
+static GTestDBus *singleton = NULL;
void
-session_bus_down_with_address (const gchar *address)
-{
- gpointer value;
- GPid pid;
- gchar buf[512];
-
- g_assert (address != NULL);
- g_assert (session_bus_address_to_pid != NULL);
-
- value = g_hash_table_lookup (session_bus_address_to_pid, address);
- g_assert (value != NULL);
-
- pid = GPOINTER_TO_UINT (g_hash_table_lookup (session_bus_address_to_pid, address));
-
- kill (pid, SIGTERM);
-
- /* write the pid to the child so it won't kill it when we die */
- g_snprintf (buf, sizeof buf, "remove %d\n", (guint) pid);
- write (pipe_fds[1], buf, strlen (buf));
-
- g_hash_table_remove (session_bus_address_to_pid, address);
-}
-
-static gchar *temporary_address = NULL;
-static gchar *temporary_address_used_by_bus = NULL;
-
-const gchar *
-session_bus_get_temporary_address (void)
+session_bus_up (void)
{
- if (temporary_address == NULL)
- {
- temporary_address = g_strdup_printf ("unix:path=/tmp/g-dbus-tests-pid-%d", getpid ());
- }
-
- return temporary_address;
+ g_assert (singleton == NULL);
+ singleton = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_up (singleton);
}
-const gchar *
-session_bus_up (void)
+void
+session_bus_stop (void)
{
- if (temporary_address_used_by_bus != NULL)
- {
- g_warning ("There is already a session bus up");
- goto out;
- }
-
- temporary_address_used_by_bus = g_strdup (session_bus_up_with_address (session_bus_get_temporary_address ()));
-
- out:
- return temporary_address_used_by_bus;
+ g_assert (singleton != NULL);
+ g_test_dbus_stop (singleton);
}
void
session_bus_down (void)
{
- if (temporary_address_used_by_bus == NULL)
- {
- g_warning ("There is not a session bus up");
- }
- else
- {
- session_bus_down_with_address (temporary_address_used_by_bus);
- g_free (temporary_address_used_by_bus);
- temporary_address_used_by_bus = NULL;
- }
+ g_assert (singleton != NULL);
+ g_test_dbus_down (singleton);
+ g_clear_object (&singleton);
}
+
/* GLib testing framework examples and tests
*
- * Copyright (C) 2008-2009 Red Hat, Inc.
+ * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: David Zeuthen <davidz@redhat.com>
+ * Author: Xavier Claessens <xavier.claessens@collabora.co.uk>
*/
#ifndef __SESSION_BUS_H__
G_BEGIN_DECLS
-const gchar *session_bus_up_with_address (const gchar *given_address);
-void session_bus_down_with_address (const gchar *address);
-const gchar *session_bus_get_temporary_address (void);
-const gchar *session_bus_up (void);
-void session_bus_down (void);
+void session_bus_up (void);
+void session_bus_stop (void);
+void session_bus_down (void);
G_END_DECLS
g_type_init ();
g_test_init (&argc, &argv, NULL);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
session_bus_up ();
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
g_test_add_func ("/gdbus/codegen/annotations", test_annotations);
g_test_add_func ("/gdbus/codegen/interface_stability", test_interface_stability);
g_test_add_func ("/gdbus/codegen/object-manager", test_object_manager);
}
/* ---------------------------------------------------------------------------------------------------- */
-
-#if 0
-/* toggle refs are not easy to use (maybe not even safe) when multiple
- * threads are involved so implement this by busy-waiting for now
- */
-gboolean
-_g_object_wait_for_single_ref_do (gpointer object)
-{
- guint num_ms_elapsed;
- gboolean timed_out;
-
- timed_out = FALSE;
- num_ms_elapsed = 0;
-
- while (TRUE)
- {
- if (G_OBJECT (object)->ref_count == 1)
- goto out;
-
- if (num_ms_elapsed > 30000)
- {
- timed_out = TRUE;
- goto out;
- }
-
- usleep (10 * 1000);
- num_ms_elapsed += 10;
- }
-
- out:
- return timed_out;
-}
-
-#else
-
-typedef struct
-{
- GMainLoop *loop;
- gboolean timed_out;
-} WaitSingleRefData;
-
-static gboolean
-on_wait_single_ref_timeout (gpointer user_data)
-{
- WaitSingleRefData *data = user_data;
- data->timed_out = TRUE;
- g_main_loop_quit (data->loop);
- return TRUE;
-}
-
-static void
-on_wait_for_single_ref_toggled (gpointer user_data,
- GObject *object,
- gboolean is_last_ref)
-{
- WaitSingleRefData *data = user_data;
- g_main_loop_quit (data->loop);
-}
-
-gboolean
-_g_object_wait_for_single_ref_do (gpointer object)
-{
- WaitSingleRefData data;
- guint timeout_id;
-
- data.timed_out = FALSE;
-
- if (G_OBJECT (object)->ref_count == 1)
- goto out;
-
- data.loop = g_main_loop_new (NULL, FALSE);
- timeout_id = g_timeout_add (30 * 1000,
- on_wait_single_ref_timeout,
- &data);
-
- g_object_add_toggle_ref (G_OBJECT (object),
- on_wait_for_single_ref_toggled,
- &data);
- /* the reference could have been removed between us checking the
- * ref_count and the toggle ref being added
- */
- if (G_OBJECT (object)->ref_count == 2)
- goto single_ref_already;
-
- g_object_unref (object);
- g_main_loop_run (data.loop);
- g_object_ref (object);
-
-single_ref_already:
- g_object_remove_toggle_ref (object,
- on_wait_for_single_ref_toggled,
- &data);
-
- g_source_remove (timeout_id);
- g_main_loop_unref (data.loop);
-
- out:
- if (data.timed_out)
- {
- g_printerr ("b ref_count is %d\n", G_OBJECT (object)->ref_count);
- }
- return data.timed_out;
-}
-#endif
-
-/* ---------------------------------------------------------------------------------------------------- */
GCancellable *cancellable,
GError **error);
-
-#define _g_object_wait_for_single_ref(object) \
- do \
- { \
- if (!G_IS_OBJECT (object)) \
- { \
- g_assertion_message (G_LOG_DOMAIN, \
- __FILE__, \
- __LINE__, \
- G_STRFUNC, \
- "Not a GObject instance"); \
- } \
- if (_g_object_wait_for_single_ref_do (object)) \
- { \
- g_assertion_message (G_LOG_DOMAIN, \
- __FILE__, \
- __LINE__, \
- G_STRFUNC, \
- "Timed out waiting for single ref"); \
- } \
- } \
- while (FALSE)
-
-gboolean _g_object_wait_for_single_ref_do (gpointer object);
-
G_END_DECLS
#endif /* __TESTS_H__ */
g_type_init ();
g_test_init (&argc, &argv, NULL);
- /* all the tests use a session bus with a well-known address that we can bring up and down
- * using session_bus_up() and session_bus_down().
- */
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
session_bus_up ();
- /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
- * until one can connect to the bus but that's not how things work right now
- */
- usleep (500 * 1000);
-
/* this is safe; testserver will exit once the bus goes away */
g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
g_test_init (&argc, &argv, NULL);
g_type_init ();
- g_unsetenv ("DISPLAY");
- g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
session_bus_up ();
g_test_add_func ("/gmenu/equality", test_equality);