2 * Test to make sure that pending calls succeed when given a default,
3 * specific and infinite timeout.
7 #include <dbus/dbus-sysdeps.h>
13 _method_call (DBusConnection *conn,
14 int timeout_milliseconds)
16 DBusPendingCall *pending;
21 /* send the message */
22 method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
23 "/org/freedesktop/TestSuite",
24 "org.freedesktop.TestSuite",
27 dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
28 dbus_connection_send_with_reply (conn, method, &pending, timeout_milliseconds);
29 dbus_message_unref (method);
31 /* block on the message */
32 dbus_pending_call_block (pending);
34 /* check the reply only to make sure we
35 are not getting errors unrelated
36 to the block in poll bug */
37 reply = dbus_pending_call_steal_reply (pending);
41 printf ("Failed: Reply is NULL ***\n");
45 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
47 printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
51 dbus_message_unref (reply);
52 dbus_pending_call_unref (pending);
56 _run_iteration (DBusConnection *conn)
58 _method_call (conn, -1);
59 _method_call (conn, 10000);
60 _method_call (conn, INT_MAX);
64 main (int argc, char *argv[])
66 long start_tv_sec, start_tv_usec;
67 long end_tv_sec, end_tv_usec;
73 printf ("*** Testing pending call timeouts\n");
75 dbus_error_init (&error);
77 conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
79 /* run 100 times to make sure */
80 for (i = 0; i < 100; i++)
84 _dbus_get_current_time (&start_tv_sec, &start_tv_usec);
85 _run_iteration (conn);
86 _dbus_get_current_time (&end_tv_sec, &end_tv_usec);
88 /* we just care about seconds */
89 delta = end_tv_sec - start_tv_sec;
90 printf ("Iter %i: %lis\n", i, delta);
93 method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
94 "/org/freedesktop/TestSuite",
95 "org.freedesktop.TestSuite",
97 dbus_connection_send (conn, method, NULL);
98 dbus_message_unref (method);
100 printf ("Success ***\n");