bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / test / name-test / test-ids.c
1 #include <config.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <dbus/dbus.h>
6 #include <dbus/dbus-connection-internal.h>
7 #ifdef HAVE_UNISTD_H
8 #include <unistd.h>
9 #endif
10
11 static void die (const char *message) _DBUS_GNUC_NORETURN;
12
13 static void
14 die (const char *message)
15 {
16   printf ("Bail out! test-ids: %s\n", message);
17   exit (1);
18 }
19
20 static int test_num = 0;
21
22 /* This test outputs TAP syntax: http://testanything.org/ */
23 int
24 main (int    argc,
25       char **argv)
26 {
27   DBusError error;
28   DBusConnection *connection;
29   char *id;
30   char *server_id;
31
32   dbus_error_init (&error);
33   connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
34   if (connection == NULL)
35     {
36       fprintf (stderr, "*** Failed to open connection to system bus: %s\n",
37                error.message);
38       dbus_error_free (&error);
39       return 1;
40     }
41   printf ("ok %d - connected to session bus\n", ++test_num);
42
43   server_id = dbus_connection_get_server_id (connection);
44
45   if (server_id == NULL)
46     die ("No bus server ID retrieved\n");
47
48   printf ("ok %d - session bus server ID is %s\n", ++test_num, server_id);
49
50   if (strlen (server_id) != 32)
51     die ("Bus server id should have length 32\n");
52
53   printf ("ok %d - session bus server ID length is 32\n", ++test_num);
54
55   dbus_free (server_id);
56
57   id = dbus_bus_get_id (connection, NULL);
58   if (id == NULL)
59     die ("No bus ID retrieved\n");
60
61   printf ("ok %d - session bus ID is %s\n", ++test_num, id);
62
63   if (strlen (id) != 32)
64     die ("Bus ID should have length 32\n");
65
66   printf ("ok %d - session bus ID length is 32\n", ++test_num);
67
68   dbus_free (id);  
69
70   printf ("1..%d\n", test_num);
71   return 0;
72 }