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;
20 const char *echo = "echo";
22 /* send the message */
23 method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
24 "/org/freedesktop/TestSuite",
25 "org.freedesktop.TestSuite",
29 !dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL) ||
30 !dbus_connection_send_with_reply (conn, method, &pending, timeout_milliseconds))
32 printf ("Bail out! OOM when building and sending message ***\n");
35 dbus_message_unref (method);
37 /* block on the message */
38 dbus_pending_call_block (pending);
40 /* check the reply only to make sure we
41 are not getting errors unrelated
42 to the block in poll bug */
43 reply = dbus_pending_call_steal_reply (pending);
47 printf ("Bail out! Reply is NULL ***\n");
51 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
53 printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply));
57 dbus_message_unref (reply);
58 dbus_pending_call_unref (pending);
62 _run_iteration (DBusConnection *conn)
64 _method_call (conn, -1);
65 _method_call (conn, 10000);
66 _method_call (conn, INT_MAX);
69 /* This test outputs TAP syntax: http://testanything.org/ */
71 main (int argc, char *argv[])
73 long start_tv_sec, start_tv_usec;
74 long end_tv_sec, end_tv_usec;
80 printf ("# Testing pending call timeouts\n");
82 dbus_error_init (&error);
84 conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
86 /* run 100 times to make sure */
87 for (i = 0; i < 100; i++)
91 _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec);
92 _run_iteration (conn);
93 _dbus_get_monotonic_time (&end_tv_sec, &end_tv_usec);
95 /* we just care about seconds */
96 delta = end_tv_sec - start_tv_sec;
97 printf ("ok %d - %lis\n", i + 1, delta);
100 method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
101 "/org/freedesktop/TestSuite",
102 "org.freedesktop.TestSuite",
104 dbus_connection_send (conn, method, NULL);
105 dbus_message_unref (method);
107 printf ("# Testing completed\n1..%d\n", i);