2 * Test to make sure that pending calls succeed when given a default,
3 * specific and infinite timeout.
8 #include <dbus/dbus-sysdeps.h>
14 _method_call (DBusConnection *conn,
15 int timeout_milliseconds)
17 DBusPendingCall *pending;
22 /* send the message */
23 method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
24 "/org/freedesktop/TestSuite",
25 "org.freedesktop.TestSuite",
28 dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
29 dbus_connection_send_with_reply (conn, method, &pending, timeout_milliseconds);
30 dbus_message_unref (method);
32 /* block on the message */
33 dbus_pending_call_block (pending);
35 /* check the reply only to make sure we
36 are not getting errors unrelated
37 to the block in poll bug */
38 reply = dbus_pending_call_steal_reply (pending);
42 printf ("Failed: Reply is NULL ***\n");
46 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
48 printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
52 dbus_message_unref (reply);
53 dbus_pending_call_unref (pending);
57 _run_iteration (DBusConnection *conn)
59 _method_call (conn, -1);
60 _method_call (conn, 10000);
61 _method_call (conn, INT_MAX);
65 main (int argc, char *argv[])
67 long start_tv_sec, start_tv_usec;
68 long end_tv_sec, end_tv_usec;
74 printf ("*** Testing pending call timeouts\n");
76 dbus_error_init (&error);
78 conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
80 /* run 100 times to make sure */
81 for (i = 0; i < 100; i++)
85 _dbus_get_current_time (&start_tv_sec, &start_tv_usec);
86 _run_iteration (conn);
87 _dbus_get_current_time (&end_tv_sec, &end_tv_usec);
89 /* we just care about seconds */
90 delta = end_tv_sec - start_tv_sec;
91 printf ("Iter %i: %lis\n", i, delta);
94 method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
95 "/org/freedesktop/TestSuite",
96 "org.freedesktop.TestSuite",
98 dbus_connection_send (conn, method, NULL);
99 dbus_message_unref (method);
101 printf ("Success ***\n");