| 1 |
#include <stdlib.h> |
| 2 |
|
| 3 |
#include <gdk/gdk.h> |
| 4 |
|
| 5 |
static void |
| 6 |
test_unset_display_subprocess1 (void) |
| 7 |
{ |
| 8 |
GdkDisplayManager *manager; |
| 9 |
|
| 10 |
g_unsetenv ("DISPLAY"); |
| 11 |
|
| 12 |
g_assert (!gdk_init_check (NULL, NULL)); |
| 13 |
manager = gdk_display_manager_get (); |
| 14 |
g_assert (manager != NULL); |
| 15 |
g_assert (gdk_display_manager_get_default_display (manager) == NULL); |
| 16 |
} |
| 17 |
|
| 18 |
static void |
| 19 |
test_unset_display_subprocess2 (void) |
| 20 |
{ |
| 21 |
g_unsetenv ("DISPLAY"); |
| 22 |
|
| 23 |
gdk_init (NULL, NULL); |
| 24 |
} |
| 25 |
|
| 26 |
static void |
| 27 |
test_unset_display (void) |
| 28 |
{ |
| 29 |
g_test_trap_subprocess ("/display/unset-display/subprocess/1", 0, 0); |
| 30 |
g_test_trap_assert_passed (); |
| 31 |
|
| 32 |
g_test_trap_subprocess ("/display/unset-display/subprocess/2", 0, 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 ("DISPLAY", "poo", TRUE); |
| 43 |
|
| 44 |
g_assert (!gdk_init_check (NULL, NULL)); |
| 45 |
manager = gdk_display_manager_get (); |
| 46 |
g_assert (manager != NULL); |
| 47 |
g_assert (gdk_display_manager_get_default_display (manager) == NULL); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
test_bad_display_subprocess2 (void) |
| 52 |
{ |
| 53 |
g_setenv ("DISPLAY", "poo", TRUE); |
| 54 |
gdk_init (NULL, NULL); |
| 55 |
} |
| 56 |
|
| 57 |
static void |
| 58 |
test_bad_display (void) |
| 59 |
{ |
| 60 |
g_test_trap_subprocess ("/display/bad-display/subprocess/1", 0, 0); |
| 61 |
g_test_trap_assert_passed (); |
| 62 |
|
| 63 |
g_test_trap_subprocess ("/display/bad-display/subprocess/2", 0, 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, &argv, NULL); |
| 72 |
|
| 73 |
gdk_set_allowed_backends ("x11"); |
| 74 |
|
| 75 |
g_test_add_func ("/display/unset-display", test_unset_display); |
| 76 |
g_test_add_func ("/display/unset-display/subprocess/1", test_unset_display_subprocess1); |
| 77 |
g_test_add_func ("/display/unset-display/subprocess/2", test_unset_display_subprocess2); |
| 78 |
g_test_add_func ("/display/bad-display", test_bad_display); |
| 79 |
g_test_add_func ("/display/bad-display/subprocess/1", test_bad_display_subprocess1); |
| 80 |
g_test_add_func ("/display/bad-display/subprocess/2", test_bad_display_subprocess2); |
| 81 |
|
| 82 |
return g_test_run (); |
| 83 |
} |