More copyright year updates
[platform/upstream/glib.git] / gio / tests / gdbus-exit-on-close.c
1 /* GLib testing framework examples and tests
2  *
3  * Copyright (C) 2008-2010 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: David Zeuthen <davidz@redhat.com>
21  */
22
23 #include <gio/gio.h>
24 #include <unistd.h>
25 #include <string.h>
26
27 #include "gdbus-tests.h"
28
29 /* all tests rely on a shared mainloop */
30 static GMainLoop *loop = NULL;
31
32 /* ---------------------------------------------------------------------------------------------------- */
33
34 static gboolean
35 nuke_session_bus_cb (gpointer data)
36 {
37   g_main_loop_quit (loop);
38   return FALSE;
39 }
40
41 static void
42 test_exit_on_close (void)
43 {
44   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
45     {
46       GDBusConnection *c;
47       session_bus_up ();
48       c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
49       g_assert (c != NULL);
50       g_assert (!g_dbus_connection_is_closed (c));
51       g_timeout_add (50,
52                      nuke_session_bus_cb,
53                      NULL);
54       g_main_loop_run (loop);
55       session_bus_down ();
56       g_main_loop_run (loop);
57     }
58   g_test_trap_assert_stdout ("*Remote peer vanished. Exiting.*");
59   g_test_trap_assert_failed();
60 }
61
62 /* ---------------------------------------------------------------------------------------------------- */
63
64 int
65 main (int   argc,
66       char *argv[])
67 {
68   g_type_init ();
69   g_test_init (&argc, &argv, NULL);
70
71   /* all the tests rely on a shared main loop */
72   loop = g_main_loop_new (NULL, FALSE);
73
74   /* all the tests use a session bus with a well-known address that we can bring up and down
75    * using session_bus_up() and session_bus_down().
76    */
77   g_unsetenv ("DISPLAY");
78   g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
79
80   g_test_add_func ("/gdbus/exit-on-close", test_exit_on_close);
81   return g_test_run();
82 }