cmake: Add X11 include path for tools
[platform/upstream/dbus.git] / test / test-utils-glib.h
1 /* Utility functions for tests that rely on GLib
2  *
3  * Copyright © 2010-2011 Nokia Corporation
4  * Copyright © 2013-2015 Collabora Ltd.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 #ifndef TEST_UTILS_GLIB_H
28 #define TEST_UTILS_GLIB_H
29
30 #include <dbus/dbus.h>
31
32 #include <glib.h>
33
34 #include "test-utils.h"
35
36 /*
37  * Multi-user support for regression tests run with root privileges in
38  * a continuous integration system.
39  *
40  * A developer would normally run the tests as their own uid. Tests run
41  * as TEST_USER_ME are run, and the others are skipped.
42  *
43  * In a CI system that has access to root privileges, most tests should still
44  * be run as an arbitrary non-root user, as above.
45  *
46  * Certain tests can usefully be run again, as root. When this is done,
47  * tests using TEST_USER_ROOT, TEST_USER_MESSAGEBUS and/or TEST_USER_OTHER
48  * can exercise situations that only arise when there's more than one uid.
49  */
50 typedef enum {
51     /* Whatever user happens to be running the regression test;
52      * such tests also work on Windows */
53     TEST_USER_ME,
54     /* Must be uid 0 on Unix; the test is skipped on Windows */
55     TEST_USER_ROOT,
56     /* The user who would normally run the system bus. This is the DBUS_USER
57      * from configure.ac, usually 'messagebus' but perhaps 'dbus' or
58      * '_dbus'. */
59     TEST_USER_MESSAGEBUS,
60     /* An unprivileged user who is neither root nor DBUS_USER.
61      * This is DBUS_TEST_USER from configure.ac, usually 'nobody'. */
62     TEST_USER_OTHER
63 } TestUser;
64
65 #define test_assert_no_error(e) _test_assert_no_error (e, __FILE__, __LINE__)
66 void _test_assert_no_error (const DBusError *e,
67     const char *file,
68     int line);
69
70 gchar *test_get_dbus_daemon (const gchar *config_file,
71     TestUser user,
72     const gchar *runtime_dir,
73     GPid *daemon_pid);
74
75 DBusConnection *test_connect_to_bus (TestMainContext *ctx,
76     const gchar *address);
77 DBusConnection *test_connect_to_bus_as_user (TestMainContext *ctx,
78     const char *address,
79     TestUser user);
80
81 void test_kill_pid (GPid pid);
82
83 void test_init (int *argcp, char ***argvp);
84
85 void test_progress (char symbol);
86
87 void test_remove_if_exists (const gchar *path);
88 void test_rmdir_must_exist (const gchar *path);
89 void test_rmdir_if_exists (const gchar *path);
90 void test_mkdir (const gchar *path, gint mode);
91
92 void test_timeout_reset (guint factor);
93
94 #if !GLIB_CHECK_VERSION(2, 44, 0)
95 #define g_steal_pointer(x) backported_g_steal_pointer (x)
96 /* A simplified version of g_steal_pointer without type-safety. */
97 static inline gpointer
98 backported_g_steal_pointer (gpointer pointer_to_pointer)
99 {
100   gpointer *pp = pointer_to_pointer;
101   gpointer ret;
102
103   ret = *pp;
104   *pp = NULL;
105   return ret;
106 }
107 #endif
108
109 gboolean test_check_tcp_works (void);
110
111 #endif