1 | #include <stdlib.h> |
2 | |
3 | #include <gtk/gtk.h> |
4 | |
5 | static void |
6 | test_unset_display_subprocess1 (void) |
7 | { |
8 | GdkDisplayManager *manager; |
9 | |
10 | g_unsetenv (variable: "DISPLAY" ); |
11 | |
12 | g_assert_false (gtk_init_check ()); |
13 | manager = gdk_display_manager_get (); |
14 | g_assert_nonnull (manager); |
15 | g_assert_null (gdk_display_manager_get_default_display (manager)); |
16 | } |
17 | |
18 | static void |
19 | test_unset_display_subprocess2 (void) |
20 | { |
21 | g_unsetenv (variable: "DISPLAY" ); |
22 | |
23 | gtk_init (); |
24 | } |
25 | |
26 | static void |
27 | test_unset_display (void) |
28 | { |
29 | g_test_trap_subprocess (test_path: "/display/unset-display/subprocess/1" , usec_timeout: 0, test_flags: 0); |
30 | g_test_trap_assert_passed (); |
31 | |
32 | g_test_trap_subprocess (test_path: "/display/unset-display/subprocess/2" , usec_timeout: 0, test_flags: 0); |
33 | g_test_trap_assert_failed (); |
34 | g_test_trap_assert_stderr ("*cannot open display*" ); |
35 | } |
36 | |
37 | static void |
38 | test_bad_display_subprocess1 (void) |
39 | { |
40 | GdkDisplayManager *manager; |
41 | |
42 | g_setenv (variable: "DISPLAY" , value: "poo" , TRUE); |
43 | |
44 | g_assert_false (gtk_init_check ()); |
45 | manager = gdk_display_manager_get (); |
46 | g_assert_nonnull (manager); |
47 | g_assert_null (gdk_display_manager_get_default_display (manager)); |
48 | } |
49 | |
50 | static void |
51 | test_bad_display_subprocess2 (void) |
52 | { |
53 | g_setenv (variable: "DISPLAY" , value: "poo" , TRUE); |
54 | gtk_init (); |
55 | } |
56 | |
57 | static void |
58 | test_bad_display (void) |
59 | { |
60 | g_test_trap_subprocess (test_path: "/display/bad-display/subprocess/1" , usec_timeout: 0, test_flags: 0); |
61 | g_test_trap_assert_passed (); |
62 | |
63 | g_test_trap_subprocess (test_path: "/display/bad-display/subprocess/2" , usec_timeout: 0, test_flags: 0); |
64 | g_test_trap_assert_failed (); |
65 | g_test_trap_assert_stderr ("*cannot open display*" ); |
66 | } |
67 | |
68 | int |
69 | main (int argc, char *argv[]) |
70 | { |
71 | (g_test_init) (argc: &argc, argv: &argv, NULL); |
72 | |
73 | gdk_set_allowed_backends (backends: "x11" ); |
74 | |
75 | g_test_add_func (testpath: "/display/unset-display" , test_func: test_unset_display); |
76 | g_test_add_func (testpath: "/display/unset-display/subprocess/1" , test_func: test_unset_display_subprocess1); |
77 | g_test_add_func (testpath: "/display/unset-display/subprocess/2" , test_func: test_unset_display_subprocess2); |
78 | g_test_add_func (testpath: "/display/bad-display" , test_func: test_bad_display); |
79 | g_test_add_func (testpath: "/display/bad-display/subprocess/1" , test_func: test_bad_display_subprocess1); |
80 | g_test_add_func (testpath: "/display/bad-display/subprocess/2" , test_func: test_bad_display_subprocess2); |
81 | |
82 | return g_test_run (); |
83 | } |
84 | |