1#include <config.h>
2#include "test-utils.h"
3
4static DBusLoop *loop;
5
6static void
7die (const char *message)
8{
9  fprintf (stderr, "*** test-names: %s", message);
10  exit (1);
11}
12
13static void
14TestName(DBusConnection *connection, const char *name, int expectedSuccess)
15{
16  DBusError error;
17  dbus_error_init (&error);
18
19  (void) dbus_bus_request_name (connection, name, 0, &error);
20  if (dbus_error_is_set (&error))
21    {
22      if (expectedSuccess)
23        fprintf (stderr, "Error acquiring name '%s': %s\n", name, error.message);
24      else
25        fprintf (stdout, "Expected Error acquiring name '%s': %s\n", name, error.message);
26      _dbus_verbose ("*** Failed to acquire name '%s': %s\n", name,
27                     error.message);
28      dbus_error_free (&error);
29      if (expectedSuccess)
30        exit (1);
31    }
32  else
33    {
34      if (!expectedSuccess)
35        fprintf (stderr, "Unexpected Success acquiring name '%s'\n", name);
36      else
37        fprintf (stdout, "Successfully acquired name '%s'\n", name);
38      _dbus_verbose ("*** Managed to acquire name '%s'\n", name);
39      if (!expectedSuccess)
40        exit (1);
41    }
42}
43
44int
45main (int    argc,
46      char **argv)
47{
48  DBusError error;
49  DBusConnection *connection;
50
51  dbus_error_init (&error);
52  connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
53  if (connection == NULL)
54    {
55      fprintf (stderr, "*** Failed to open connection to system bus: %s\n",
56               error.message);
57      dbus_error_free (&error);
58      return 1;
59    }
60
61  loop = _dbus_loop_new ();
62  if (loop == NULL)
63    die ("No memory\n");
64
65  if (!test_connection_setup (loop, connection))
66    die ("No memory\n");
67
68  TestName(connection, "org.freedesktop.DBus.Test", TRUE);
69  TestName(connection, "org.freedesktop.DBus.Test-2", TRUE);
70  TestName(connection, "org.freedesktop.DBus.Test_2", TRUE);
71#if 0
72  TestName(connection, "Test_2", TRUE);
73#endif
74
75  _dbus_verbose ("*** Test service name exiting\n");
76
77  return 0;
78}
79