Consistently include <config.h> in all C source files and never in header files.
[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
12 die (const char *message)
13 {
14   fprintf (stderr, "*** test-ids: %s", message);
15   exit (1);
16 }
17
18 int
19 main (int    argc,
20       char **argv)
21 {
22   DBusError error;
23   DBusConnection *connection;
24   char *id;
25   char *server_id;
26   
27   dbus_error_init (&error);
28   connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
29   if (connection == NULL)
30     {
31       fprintf (stderr, "*** Failed to open connection to system bus: %s\n",
32                error.message);
33       dbus_error_free (&error);
34       return 1;
35     }
36
37   server_id = dbus_connection_get_server_id (connection);
38   if (server_id == NULL)
39     die ("No bus server ID retrieved\n");
40   /* printf("'%s'\n", server_id); */
41   if (strlen (server_id) != 32)
42     die ("Bus server id should have length 32\n");
43   dbus_free (server_id);
44
45   id = dbus_bus_get_id (connection, NULL);
46   if (id == NULL)
47     die ("No bus ID retrieved\n");
48   /* printf("'%s'\n", id); */
49   if (strlen (id) != 32)
50     die ("Bus ID should have length 32\n");
51   dbus_free (id);  
52   
53   _dbus_verbose ("*** Test IDs exiting\n");
54   
55   return 0;
56 }