Updated patch
Matthew Johnson
dbus at matthew.ath.cx
Mon Dec 5 05:33:48 PST 2005
I think I've finally managed to figure out enough autocrack to integrate
the test into the build system. At the moment its only testing
dbus_connection_read_write, rather than the dispatching version.
The other issue I noticed is that in 0.6 one of the other functions has
been updated so that I get an assert failure:
8853: assertion failed "(*(const char*)_DBUS_FUNCTION_NAME) != '_'" file "dbus-connection.c" line 2877 function _dbus_connection_read_write_dispatch
Which appears to enforce that _dbus_return_val_if_fail can only be
called from functions that don't start with an underscore. I have no
idea why this is, but have accordingly moved the calls to that into the
wrapper functions.
This diff is against CVS as of a couple of days ago, and needs -p1.
Matt
--
Matthew Johnson
http://www.matthew.ath.cx/
-------------- next part --------------
diff -urN dbus-unpatched/dbus/dbus-connection.c dbus-patched/dbus/dbus-connection.c
--- dbus-unpatched/dbus/dbus-connection.c 2005-12-05 12:07:48.000000000 +0000
+++ dbus-patched/dbus/dbus-connection.c 2005-12-05 10:48:17.000000000 +0000
@@ -2874,8 +2874,6 @@
DBusDispatchStatus dstatus;
dbus_bool_t dispatched_disconnected;
- _dbus_return_val_if_fail (connection != NULL, FALSE);
- _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
dstatus = dbus_connection_get_dispatch_status (connection);
if (dispatch && dstatus == DBUS_DISPATCH_DATA_REMAINS)
@@ -2947,7 +2945,9 @@
dbus_connection_read_write_dispatch (DBusConnection *connection,
int timeout_milliseconds)
{
- return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, TRUE);
+ _dbus_return_val_if_fail (connection != NULL, FALSE);
+ _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
+ return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, TRUE);
}
/**
@@ -2970,7 +2970,9 @@
dbus_connection_read_write (DBusConnection *connection,
int timeout_milliseconds)
{
- return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, FALSE);
+ _dbus_return_val_if_fail (connection != NULL, FALSE);
+ _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
+ return _dbus_connection_read_write_dispatch(connection, timeout_milliseconds, FALSE);
}
/**
diff -urN dbus-unpatched/test/Makefile.am dbus-patched/test/Makefile.am
--- dbus-unpatched/test/Makefile.am 2005-12-05 12:36:10.000000000 +0000
+++ dbus-patched/test/Makefile.am 2005-12-05 12:51:43.000000000 +0000
@@ -17,10 +17,11 @@
if DBUS_BUILD_TESTS
## break-loader removed for now
-TEST_BINARIES=test-service test-names test-shell-service shell-test spawn-test test-segfault test-exit test-sleep-forever
+TEST_BINARIES=test-service test-names test-shell-service shell-test spawn-test test-segfault test-exit test-sleep-forever test-readwrite
#enable stand alone make check test
-TESTS=shell-test
+TESTS=shell-test test-readwrite
+TESTS_ENVIRONMENT=../tools/run-with-tmp-session-bus.sh
else
TEST_BINARIES=
TESTS=
@@ -55,6 +56,9 @@
shell_test_SOURCES= \
shell-test.c
+test_readwrite_SOURCES= \
+ test-readwrite.c
+
spawn_test_SOURCES= \
spawn-test.c
@@ -77,6 +81,7 @@
## break_loader_LDADD= $(TEST_LIBS)
test_shell_service_LDADD=$(TEST_LIBS)
shell_test_LDADD=$(TEST_LIBS)
+test_readwrite_LDADD=$(TEST_LIBS)
spawn_test_LDADD=$(TEST_LIBS)
decode_gcov_LDADD=$(TEST_LIBS)
diff -urN dbus-unpatched/test/test-readwrite.c dbus-patched/test/test-readwrite.c
--- dbus-unpatched/test/test-readwrite.c 1970-01-01 01:00:00.000000000 +0100
+++ dbus-patched/test/test-readwrite.c 2005-12-05 11:59:53.000000000 +0000
@@ -0,0 +1,180 @@
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define STAT_CONST true
+#define LEVEL_CONST 25616
+
+void reply_to_method_call(DBusMessage* msg, DBusConnection* conn)
+{
+ DBusMessage* reply;
+ DBusMessageIter args;
+ bool stat = STAT_CONST;
+ dbus_uint32_t level = LEVEL_CONST;
+ dbus_uint32_t serial = 0;
+ char* param = "";
+
+
+ // create a reply from the message
+ reply = dbus_message_new_method_return(msg);
+
+ // add the arguments to the reply
+ dbus_message_iter_init_append(reply, &args);
+ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &stat)) {
+ fprintf(stderr, "Out Of Memory!\n");
+ exit(1);
+ }
+ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &level)) {
+ fprintf(stderr, "Out Of Memory!\n");
+ exit(1);
+ }
+
+ // send the reply && flush the connection
+ if (!dbus_connection_send(conn, reply, &serial)) {
+ fprintf(stderr, "Out Of Memory!\n");
+ exit(1);
+ }
+ dbus_connection_flush(conn);
+
+ // free the reply
+ dbus_message_unref(reply);
+}
+
+
+/**
+ * Server that exposes a method call and waits for it to be called
+ */
+int main(int argc, char** argv)
+{
+ DBusMessage* msg;
+ DBusMessage* reply;
+ DBusMessageIter args;
+ DBusConnection* conn;
+ DBusPendingCall* pending;
+ DBusError err;
+ int ret;
+ char* param;
+ dbus_bool_t stat;
+ int level;
+
+
+ // initialise the error
+ dbus_error_init(&err);
+
+ // connect to the bus and check for errors
+ conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ fprintf(stderr, "Connection Error (%s)\n", err.message);
+ dbus_error_free(&err);
+ }
+ if (NULL == conn) {
+ fprintf(stderr, "Connection Null\n");
+ exit(1);
+ }
+
+
+ // request our name on the bus and check for errors
+ ret = dbus_bus_request_name(conn, "org.freedesktop.DBus.TestSuiteReadWrite", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+ if (dbus_error_is_set(&err)) {
+ fprintf(stderr, "Name Error (%s)\n", err.message);
+ dbus_error_free(&err);
+ }
+ if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
+ fprintf(stderr, "Not Primary Owner (%d)\n", ret);
+ exit(1);
+ }
+
+
+// create a new method call and check for errors
+ msg = dbus_message_new_method_call("org.freedesktop.DBus.TestSuiteReadWrite", // target for the method call
+ "/org/freedesktop/DBus/TestSuite", // object to call on
+ "org.freedesktop.DBus.TestSuite", // interface to call on
+ "ReadWriteTest"); // method name
+
+ if (NULL == msg) {
+ fprintf(stderr, "Message Null\n");
+ exit(1);
+ }
+
+ // send message and get a handle for a reply
+ if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
+ fprintf(stderr, "Out Of Memory!\n");
+ exit(1);
+ }
+ if (NULL == pending) {
+ fprintf(stderr, "Pending Call Null\n");
+ exit(1);
+ }
+ dbus_connection_flush(conn);
+
+ // free message
+ dbus_message_unref(msg);
+
+
+ // loop, testing for new messages
+ while (true) {
+ // non blocking read of the next available message
+ dbus_connection_read_write(conn, 0);
+ msg = dbus_connection_pop_message(conn);
+
+ // loop again if we haven't got a message
+ if (NULL == msg) {
+ sleep(1);
+ continue;
+ }
+
+ // check this is a method call for the right interface & method
+ if (dbus_message_is_method_call(msg, "org.freedesktop.DBus.TestSuite", "ReadWriteTest")) {
+ reply_to_method_call(msg, conn);
+ break;
+ }
+
+ // free the message
+ dbus_message_unref(msg);
+ }
+
+ //
+ // block until we recieve a reply
+ dbus_pending_call_block(pending);
+
+ // get the reply message
+ msg = dbus_pending_call_steal_reply(pending);
+ if (NULL == msg) {
+ fprintf(stderr, "Reply Null\n");
+ exit(1);
+ }
+ // free the pending message handle
+ dbus_pending_call_unref(pending);
+
+ // read the parameters
+ if (!dbus_message_iter_init(msg, &args))
+ fprintf(stderr, "Message has no arguments!\n");
+ else if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&args))
+ fprintf(stderr, "Argument is not boolean!\n");
+ else
+ dbus_message_iter_get_basic(&args, &stat);
+
+ if (!dbus_message_iter_next(&args))
+ fprintf(stderr, "Message has too few arguments!\n");
+ else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args))
+ fprintf(stderr, "Argument is not int!\n");
+ else
+ dbus_message_iter_get_basic(&args, &level);
+
+ if (STAT_CONST != stat || LEVEL_CONST != level) {
+ fprintf(stderr, "Incorrect Reply to test method call\n");
+ exit(1);
+ }
+
+ // free reply and close connection
+ dbus_message_unref(msg);
+
+ // close the connection
+ dbus_connection_close(conn);
+
+ exit(0);
+}
+
More information about the dbus
mailing list