From ce4fd314c6be9bfee16a172d5ca34e5097d309fc Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Tue, 25 Mar 2003 04:37:08 +0000 Subject: 2003-03-24 Havoc Pennington * dbus/dbus-sysdeps.c (_dbus_set_fd_nonblocking): move to this file * dbus/dbus-errors.c (dbus_set_error, dbus_set_error_const): allow NULL argument for "message" if the error is a well-known one, fill in a generic message in this case. * dbus/dbus-errors.h (DBusResultCode): Kill DBusResultCode in favor of DBusError * bus/test.c (bus_test_flush_bus): add * bus/policy.c (bus_policy_test): test code stub --- bus/bus.c | 10 ++-------- bus/dispatch.c | 37 +++++++++++-------------------------- bus/policy.c | 16 ++++++++++++++++ bus/test.c | 18 ++++++++++++++++++ bus/test.h | 2 ++ 5 files changed, 49 insertions(+), 34 deletions(-) (limited to 'bus') diff --git a/bus/bus.c b/bus/bus.c index 304faa99..468d820b 100644 --- a/bus/bus.c +++ b/bus/bus.c @@ -143,7 +143,6 @@ bus_context_new (const char *address, DBusError *error) { BusContext *context; - DBusResultCode result; context = dbus_new0 (BusContext, 1); if (context == NULL) @@ -161,14 +160,9 @@ bus_context_new (const char *address, goto failed; } - context->server = dbus_server_listen (address, &result); + context->server = dbus_server_listen (address, error); if (context->server == NULL) - { - dbus_set_error (error, DBUS_ERROR_FAILED, - "Failed to start server on %s: %s\n", - address, dbus_result_to_string (result)); - goto failed; - } + goto failed; context->activation = bus_activation_new (context, address, service_dirs, error); diff --git a/bus/dispatch.c b/bus/dispatch.c index 33289e1f..490ecf24 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -441,22 +441,6 @@ typedef dbus_bool_t (* Check2Func) (BusContext *context, static dbus_bool_t check_no_leftovers (BusContext *context); -static void -flush_bus (BusContext *context) -{ - /* This is race condition city, obviously. since we're all in one - * process we can't block, we just have to wait for data we put in - * one end of the debug pipe to come out the other end... - * a more robust setup would be good. - */ - - while (bus_loop_iterate (FALSE)) - ; - _dbus_sleep_milliseconds (15); - while (bus_loop_iterate (FALSE)) - ; -} - typedef struct { const char *expected_service_name; @@ -549,7 +533,7 @@ kill_client_connection (BusContext *context, /* kick in the disconnect handler that unrefs the connection */ dbus_connection_disconnect (connection); - flush_bus (context); + bus_test_flush_bus (context); _dbus_assert (bus_test_client_listed (connection)); @@ -742,7 +726,7 @@ check_hello_message (BusContext *context, dbus_message_unref (message); message = NULL; - flush_bus (context); + bus_test_flush_bus (context); if (!dbus_connection_get_is_connected (connection)) { @@ -891,13 +875,15 @@ static dbus_bool_t check_hello_connection (BusContext *context) { DBusConnection *connection; - DBusResultCode result; + DBusError error; - result = DBUS_RESULT_SUCCESS; - connection = dbus_connection_open ("debug-pipe:name=test-server", &result); + dbus_error_init (&error); + + connection = dbus_connection_open ("debug-pipe:name=test-server", &error); if (connection == NULL) { - _dbus_assert (result != DBUS_RESULT_SUCCESS); + _DBUS_ASSERT_ERROR_IS_SET (&error); + dbus_error_free (&error); return TRUE; } @@ -980,7 +966,6 @@ bus_dispatch_test (const DBusString *test_data_dir) DBusConnection *foo; DBusConnection *bar; DBusConnection *baz; - DBusResultCode result; dbus_error_init (&error); context = bus_context_new ("debug-pipe:name=test-server", @@ -989,7 +974,7 @@ bus_dispatch_test (const DBusString *test_data_dir) if (context == NULL) _dbus_assert_not_reached ("could not alloc context"); - foo = dbus_connection_open ("debug-pipe:name=test-server", &result); + foo = dbus_connection_open ("debug-pipe:name=test-server", &error); if (foo == NULL) _dbus_assert_not_reached ("could not alloc connection"); @@ -999,7 +984,7 @@ bus_dispatch_test (const DBusString *test_data_dir) if (!check_hello_message (context, foo)) _dbus_assert_not_reached ("hello message failed"); - bar = dbus_connection_open ("debug-pipe:name=test-server", &result); + bar = dbus_connection_open ("debug-pipe:name=test-server", &error); if (bar == NULL) _dbus_assert_not_reached ("could not alloc connection"); @@ -1009,7 +994,7 @@ bus_dispatch_test (const DBusString *test_data_dir) if (!check_hello_message (context, bar)) _dbus_assert_not_reached ("hello message failed"); - baz = dbus_connection_open ("debug-pipe:name=test-server", &result); + baz = dbus_connection_open ("debug-pipe:name=test-server", &error); if (baz == NULL) _dbus_assert_not_reached ("could not alloc connection"); diff --git a/bus/policy.c b/bus/policy.c index 75013c85..b5187715 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -23,6 +23,7 @@ #include "policy.h" #include "services.h" +#include "test.h" #include #include @@ -421,3 +422,18 @@ bus_policy_check_can_own (BusPolicy *policy, return allowed; } + +#ifdef DBUS_BUILD_TESTS + +dbus_bool_t +bus_policy_test (const DBusString *test_data_dir) +{ + /* This doesn't do anything for now because I decided to do it in + * dispatch.c instead by having some of the clients in dispatch.c + * have particular policies applied to them. + */ + + return TRUE; +} + +#endif /* DBUS_BUILD_TESTS */ diff --git a/bus/test.c b/bus/test.c index bc195ef1..24cc6efa 100644 --- a/bus/test.c +++ b/bus/test.c @@ -267,4 +267,22 @@ bus_test_client_listed (DBusConnection *connection) return FALSE; } + +void +bus_test_flush_bus (BusContext *context) +{ + /* This is race condition city, obviously. since we're all in one + * process we can't block, we just have to wait for data we put in + * one end of the debug pipe to come out the other end... + * a more robust setup would be good. Blocking on the other + * end of pipes we've pushed data into or something. + */ + + while (bus_loop_iterate (FALSE)) + ; + _dbus_sleep_milliseconds (15); + while (bus_loop_iterate (FALSE)) + ; +} + #endif diff --git a/bus/test.h b/bus/test.h index 1cd580bf..e39ef296 100644 --- a/bus/test.h +++ b/bus/test.h @@ -33,10 +33,12 @@ #include "connection.h" dbus_bool_t bus_dispatch_test (const DBusString *test_data_dir); +dbus_bool_t bus_policy_test (const DBusString *test_data_dir); dbus_bool_t bus_setup_debug_client (DBusConnection *connection); void bus_test_clients_foreach (BusConnectionForeachFunction function, void *data); dbus_bool_t bus_test_client_listed (DBusConnection *connection); +void bus_test_flush_bus (BusContext *context); #endif -- cgit