summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-03-13 00:56:43 +0000
committerHavoc Pennington <hp@redhat.com>2003-03-13 00:56:43 +0000
commit29560adcc79a259a0be3511c056ee7453aa26c04 (patch)
tree57e72dd26b5876da48379e5ff910c63e66cb7001 /test
parent799a3ff443f5357ae7857ebe989a7f92f7bd84df (diff)
2003-03-12 Havoc Pennington <hp@redhat.com>
Mega-patch that gets the message bus daemon initially handling out-of-memory. Work still needed. Also lots of random moving stuff to DBusError instead of ResultCode. * dbus/dbus-list.c (_dbus_list_length_is_one): new function * dbus/dbus-connection.c (dbus_connection_send_with_reply_and_block): use DBusError * dbus/dbus-bus.c: adapt to API changes, make it use DBusError not DBusResultCode * dbus/dbus-connection.c (dbus_connection_send): drop the result code here, as the only failure possible is OOM. * bus/connection.c (bus_connection_disconnect): rename bus_connection_disconnected as it's a notification only * bus/driver.c (bus_driver_handle_acquire_service): don't free "name" on get_args failure, should be done by get_args; don't disconnect client for bad args, just return an error. (bus_driver_handle_service_exists): ditto * bus/services.c (bus_services_list): NULL-terminate returned array * bus/driver.c (bus_driver_send_service_lost) (bus_driver_send_service_acquired): send messages from driver to a specific client to the client's unique name, not to the broadcast service. * dbus/dbus-message.c (decode_header_data): reject messages that contain no name field (_dbus_message_get_client_serial): rename to dbus_message_get_serial and make public (_dbus_message_set_serial): rename from set_client_serial (_dbus_message_set_reply_serial): make public (_dbus_message_get_reply_serial): make public * bus/connection.c (bus_connection_foreach): allow stopping iteration by returning FALSE from foreach function. * dbus/dbus-connection.c (dbus_connection_send_preallocated) (dbus_connection_free_preallocated_send) (dbus_connection_preallocate_send): new API for sending a message without possibility of malloc failure. (dbus_connection_send_message): rename to just dbus_connection_send (and same for whole function family) * dbus/dbus-errors.c (dbus_error_free): make this reinit the error * dbus/dbus-sysdeps.c (_dbus_exit): new function * bus/activation.c: handle/return errors * dbus/dbus-errors.h: add more DBUS_ERROR #define * dbus/dbus-sysdeps.c (_dbus_directory_open) (_dbus_file_get_contents) (_dbus_directory_get_next_file): use DBusError instead of DBusResultCode (_dbus_result_from_errno): move to this file
Diffstat (limited to 'test')
-rw-r--r--test/bus-test.c56
-rw-r--r--test/data/valid-messages/dict-simple.message3
-rw-r--r--test/data/valid-messages/dict.message5
-rw-r--r--test/data/valid-messages/lots-of-arguments.message3
-rw-r--r--test/data/valid-messages/no-padding.message4
-rw-r--r--test/data/valid-messages/simplest-manual.message3
-rw-r--r--test/data/valid-messages/simplest.message3
-rw-r--r--test/echo-client.c8
-rw-r--r--test/unbase64.c10
-rw-r--r--test/watch.c8
10 files changed, 70 insertions, 33 deletions
diff --git a/test/bus-test.c b/test/bus-test.c
index 342e806b..e059e6cb 100644
--- a/test/bus-test.c
+++ b/test/bus-test.c
@@ -62,24 +62,34 @@ test_hello_client1_handler (DBusMessageHandler *handler,
if (!test_hello_succeeding)
goto out;
+
+#if 1
+ printf ("In stage %d got message %s\n",
+ client1_stage, dbus_message_get_name (message));
+#endif
if (dbus_message_name_is (message, DBUS_MESSAGE_HELLO))
{
TEST_HELLO_HANDLE_FAIL (client1_stage == 0);
- TEST_HELLO_HANDLE_FAIL ((dbus_message_get_args (message,
- DBUS_TYPE_STRING, &client1_name,
- 0) == DBUS_RESULT_SUCCESS));
+ TEST_HELLO_HANDLE_FAIL (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &client1_name,
+ 0));
client1_stage += 1;
}
else if (dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_CREATED))
{
- TEST_HELLO_HANDLE_FAIL (client1_stage == 1 || client1_stage == 3);
+ TEST_HELLO_HANDLE_FAIL (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &tmp,
+ 0));
- TEST_HELLO_HANDLE_FAIL ((dbus_message_get_args (message,
- DBUS_TYPE_STRING, &tmp,
- 0) == DBUS_RESULT_SUCCESS));
+#if 0
+ printf ("ServiceCreated is %s\n", tmp);
+#endif
+
+ TEST_HELLO_HANDLE_FAIL (client1_stage == 1 || client1_stage == 3);
+
if (client1_stage == 1)
TEST_HELLO_HANDLE_FAIL (strcmp (client1_name, tmp) == 0);
else
@@ -94,9 +104,9 @@ test_hello_client1_handler (DBusMessageHandler *handler,
{
TEST_HELLO_HANDLE_FAIL (client1_stage == 2);
- TEST_HELLO_HANDLE_FAIL ((dbus_message_get_args (message,
- DBUS_TYPE_STRING, &tmp,
- 0) == DBUS_RESULT_SUCCESS));
+ TEST_HELLO_HANDLE_FAIL (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &tmp,
+ 0));
TEST_HELLO_HANDLE_FAIL (strcmp (client1_name, tmp) == 0);
client1_stage += 1;
@@ -132,9 +142,9 @@ test_hello_client2_handler (DBusMessageHandler *handler,
{
TEST_HELLO_HANDLE_FAIL (client2_stage == 0);
- TEST_HELLO_HANDLE_FAIL ((dbus_message_get_args (message,
- DBUS_TYPE_STRING, &client2_name,
- 0) == DBUS_RESULT_SUCCESS));
+ TEST_HELLO_HANDLE_FAIL (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &client2_name,
+ 0));
client2_stage += 1;
}
@@ -142,9 +152,9 @@ test_hello_client2_handler (DBusMessageHandler *handler,
{
TEST_HELLO_HANDLE_FAIL (client2_stage == 1);
- TEST_HELLO_HANDLE_FAIL ((dbus_message_get_args (message,
- DBUS_TYPE_STRING, &tmp,
- 0) == DBUS_RESULT_SUCCESS));
+ TEST_HELLO_HANDLE_FAIL (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &tmp,
+ 0));
TEST_HELLO_HANDLE_FAIL (strcmp (client2_name, tmp) == 0);
client2_stage += 1;
@@ -153,9 +163,9 @@ test_hello_client2_handler (DBusMessageHandler *handler,
{
TEST_HELLO_HANDLE_FAIL (client2_stage == 2);
- TEST_HELLO_HANDLE_FAIL ((dbus_message_get_args (message,
- DBUS_TYPE_STRING, &tmp,
- 0) == DBUS_RESULT_SUCCESS));
+ TEST_HELLO_HANDLE_FAIL (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &tmp,
+ 0));
TEST_HELLO_HANDLE_FAIL (strcmp (client2_name, tmp) == 0);
client2_stage += 1;
@@ -177,9 +187,9 @@ static dbus_bool_t
test_hello_replies (void)
{
DBusConnection *connection;
- DBusResultCode result;
DBusMessage *message;
DBusMessageHandler *handler;
+ DBusResultCode result;
/* First start client 1 */
connection = dbus_connection_open ("debug:name=test-server", &result);
@@ -188,7 +198,8 @@ test_hello_replies (void)
DBUS_MESSAGE_HELLO);
handler = dbus_message_handler_new (test_hello_client1_handler, NULL, NULL);
dbus_connection_add_filter (connection, handler);
- dbus_connection_send_message (connection, message, NULL, NULL);
+ if (!dbus_connection_send (connection, message, NULL))
+ die ("no memory to send message");
dbus_message_unref (message);
/* Then start client 2 */
@@ -198,7 +209,8 @@ test_hello_replies (void)
DBUS_MESSAGE_HELLO);
handler = dbus_message_handler_new (test_hello_client2_handler, NULL, NULL);
dbus_connection_add_filter (connection, handler);
- dbus_connection_send_message (connection, message, NULL, NULL);
+ if (!dbus_connection_send (connection, message, NULL))
+ die ("no memory to send message");
dbus_message_unref (message);
bus_test_loop_run ();
diff --git a/test/data/valid-messages/dict-simple.message b/test/data/valid-messages/dict-simple.message
index 0b9d0186..0de1a782 100644
--- a/test/data/valid-messages/dict-simple.message
+++ b/test/data/valid-messages/dict-simple.message
@@ -1,6 +1,9 @@
# A simple dict
VALID_HEADER
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
END_LENGTH Header
ALIGN 8
START_LENGTH Body
diff --git a/test/data/valid-messages/dict.message b/test/data/valid-messages/dict.message
index 0532e682..ce99a282 100644
--- a/test/data/valid-messages/dict.message
+++ b/test/data/valid-messages/dict.message
@@ -1,8 +1,11 @@
# Dict with different values
VALID_HEADER
-END_LENGTH Header
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
ALIGN 8
+END_LENGTH Header
START_LENGTH Body
TYPE DICT
STRING_ARRAY { 'boolean', 'int32', 'uint32', 'double', 'string', 'boolean_array', 'int32_array', 'uint32_array', 'double_array', 'string_array' }
diff --git a/test/data/valid-messages/lots-of-arguments.message b/test/data/valid-messages/lots-of-arguments.message
index 6a7d5eba..cc9c5a75 100644
--- a/test/data/valid-messages/lots-of-arguments.message
+++ b/test/data/valid-messages/lots-of-arguments.message
@@ -1,6 +1,9 @@
# Message with lots of different argument types
VALID_HEADER
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
END_LENGTH Header
ALIGN 8
START_LENGTH Body
diff --git a/test/data/valid-messages/no-padding.message b/test/data/valid-messages/no-padding.message
index c21c84d3..ab5b5a80 100644
--- a/test/data/valid-messages/no-padding.message
+++ b/test/data/valid-messages/no-padding.message
@@ -3,6 +3,10 @@
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
+
## this byte array is filled with zeros to the natural length
## of the header
FIELD_NAME unkn
diff --git a/test/data/valid-messages/simplest-manual.message b/test/data/valid-messages/simplest-manual.message
index 3f002ed1..8eed1e5f 100644
--- a/test/data/valid-messages/simplest-manual.message
+++ b/test/data/valid-messages/simplest-manual.message
@@ -10,6 +10,9 @@ LENGTH Header
LENGTH Body
## client serial
INT32 7
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
ALIGN 8
END_LENGTH Header
START_LENGTH Body
diff --git a/test/data/valid-messages/simplest.message b/test/data/valid-messages/simplest.message
index a0283aa2..7bb1872d 100644
--- a/test/data/valid-messages/simplest.message
+++ b/test/data/valid-messages/simplest.message
@@ -2,6 +2,9 @@
## VALID_HEADER includes a LENGTH Header and LENGTH Body
VALID_HEADER
+FIELD_NAME name
+TYPE STRING
+STRING 'org.freedesktop.Foo'
ALIGN 8
END_LENGTH Header
START_LENGTH Body
diff --git a/test/echo-client.c b/test/echo-client.c
index 47d7314d..de32957f 100644
--- a/test/echo-client.c
+++ b/test/echo-client.c
@@ -28,10 +28,10 @@ main (int argc,
/* Send a message to get things going */
message = dbus_message_new ("org.freedesktop.DBus.Test", "org.freedesktop.DBus.Test");
- dbus_connection_send_message (connection,
- message,
- NULL,
- NULL);
+ if (!dbus_connection_send (connection,
+ message,
+ NULL))
+ fprintf (stderr, "No memory to send reply\n");
dbus_message_unref (message);
do_mainloop ();
diff --git a/test/unbase64.c b/test/unbase64.c
index cc123658..f3894bd8 100644
--- a/test/unbase64.c
+++ b/test/unbase64.c
@@ -14,6 +14,7 @@ main (int argc,
DBusString decoded;
DBusString filename;
const char *s;
+ DBusError error;
if (argc < 2)
{
@@ -29,8 +30,13 @@ main (int argc,
if (!_dbus_string_init (&decoded, _DBUS_INT_MAX))
return 1;
- if (_dbus_file_get_contents (&contents, &filename) != DBUS_RESULT_SUCCESS)
- return 1;
+ dbus_error_init (&error);
+ if (!_dbus_file_get_contents (&contents, &filename, &error))
+ {
+ fprintf (stderr, "Failed to load file: %s\n", error.message);
+ dbus_error_free (&error);
+ return 1;
+ }
if (!_dbus_string_base64_decode (&contents, 0,
&decoded, 0))
diff --git a/test/watch.c b/test/watch.c
index 1a31e64b..d8e91b78 100644
--- a/test/watch.c
+++ b/test/watch.c
@@ -168,10 +168,10 @@ check_messages (void)
fprintf (stderr, "Received message %d, sending reply\n", count);
reply = dbus_message_new ("org.freedesktop.DBus.Test", "org.freedesktop.DBus.Test");
- dbus_connection_send_message (connection,
- reply,
- NULL,
- NULL);
+ if (!dbus_connection_send (connection,
+ reply,
+ NULL))
+ fprintf (stderr, "No memory to send reply\n");
dbus_message_unref (reply);
dbus_message_unref (message);