summaryrefslogtreecommitdiff
path: root/test/name-test/test-shutdown.c
blob: 526c1cbc52c049c454d479a8869077cb786649c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include <config.h>
#include "../test-utils.h"

static DBusLoop *loop;

static void
die (const char *message)
{
  fprintf (stderr, "*** test-shutdown: %s", message);
  exit (1);
}

static void
open_destroy_shared_session_bus_connection (void)
{
  DBusError error;
  DBusConnection *connection;
  char *session_addr_no_guid;
  char *comma;
  
  dbus_error_init (&error);

  session_addr_no_guid = strdup (getenv ("DBUS_SESSION_BUS_ADDRESS"));
  comma = strchr (session_addr_no_guid, ',');
  if (comma == NULL)
    die ("Couldn't find GUID in session bus address");
  *comma = '\0';
    
  connection = dbus_connection_open (session_addr_no_guid, &error);
  free (session_addr_no_guid);
  if (connection == NULL)
    die ("Failed to open connection to temp session bus\n");

  loop = _dbus_loop_new ();
  if (loop == NULL)
    die ("No memory\n");
  
  if (!test_connection_setup (loop, connection))
    die ("No memory\n");

  test_connection_shutdown (loop, connection);
 
  _dbus_loop_unref (loop);

  dbus_connection_unref (connection); 
}

int
main (int    argc,
      char **argv)
{
  open_destroy_shared_session_bus_connection ();

  dbus_shutdown ();

  open_destroy_shared_session_bus_connection ();

  dbus_shutdown ();

  open_destroy_shared_session_bus_connection ();

  dbus_shutdown ();

  _dbus_verbose ("*** Test shutdown exiting\n");
  
  return 0;
}