bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / test / name-test / test-shutdown.c
1
2 #include <config.h>
3 #include "../test-utils.h"
4
5 static DBusLoop *loop;
6
7 static void die (const char *message) _DBUS_GNUC_NORETURN;
8
9 static void
10 die (const char *message)
11 {
12   printf ("Bail out! test-shutdown: %s", message);
13   exit (1);
14 }
15
16 static void
17 open_destroy_shared_session_bus_connection (void)
18 {
19   DBusError error;
20   DBusConnection *connection;
21   char *session_addr_no_guid;
22   char *comma;
23   
24   dbus_error_init (&error);
25
26   session_addr_no_guid = strdup (getenv ("DBUS_SESSION_BUS_ADDRESS"));
27   comma = strchr (session_addr_no_guid, ',');
28   if (comma == NULL)
29     die ("Couldn't find GUID in session bus address");
30   *comma = '\0';
31     
32   connection = dbus_connection_open (session_addr_no_guid, &error);
33   free (session_addr_no_guid);
34   if (connection == NULL)
35     die ("Failed to open connection to temp session bus\n");
36
37   loop = _dbus_loop_new ();
38   if (loop == NULL)
39     die ("No memory\n");
40   
41   if (!test_connection_setup (loop, connection))
42     die ("No memory\n");
43
44   test_connection_shutdown (loop, connection);
45  
46   _dbus_loop_unref (loop);
47
48   dbus_connection_unref (connection); 
49 }
50
51 /* This test outputs TAP syntax: http://testanything.org/ */
52 int
53 main (int    argc,
54       char **argv)
55 {
56   int test_num = 0;
57
58   open_destroy_shared_session_bus_connection ();
59
60   dbus_shutdown ();
61   printf ("ok %d\n", ++test_num);
62
63   open_destroy_shared_session_bus_connection ();
64
65   dbus_shutdown ();
66   printf ("ok %d\n", ++test_num);
67
68   open_destroy_shared_session_bus_connection ();
69
70   dbus_shutdown ();
71   printf ("ok %d\n", ++test_num);
72
73   printf ("1..%d\n", test_num);
74   return 0;
75 }