1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Red Hat, Inc.
3 * Author: Matthias Clasen
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.
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.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
25 test_error_trapping (GdkDisplay *gdk_display)
31 d = GDK_DISPLAY_XDISPLAY (gdk_display);
33 /* verify that we can catch errors */
34 gdk_error_trap_push ();
35 XListProperties (d, 0, &dummy); /* round trip */
36 error = gdk_error_trap_pop ();
37 g_assert (error == BadWindow);
39 gdk_error_trap_push ();
40 XSetCloseDownMode (d, 12345); /* not a round trip */
41 XSetCloseDownMode (d, DestroyAll);
42 error = gdk_error_trap_pop ();
43 g_assert (error == BadValue);
45 /* try the same without sync */
46 gdk_error_trap_push ();
47 XListProperties (d, 0, &dummy);
48 gdk_error_trap_pop_ignored ();
50 gdk_error_trap_push ();
51 XSetCloseDownMode (d, 12345);
52 XSetCloseDownMode (d, DestroyAll);
53 gdk_error_trap_pop_ignored ();
57 /* verify that we can catch with nested traps; inner-most
58 * active trap gets the error */
59 gdk_error_trap_push ();
60 gdk_error_trap_push ();
61 XSetCloseDownMode (d, 12345);
62 error = gdk_error_trap_pop ();
63 g_assert (error == BadValue);
64 error = gdk_error_trap_pop ();
65 g_assert (error == Success);
67 gdk_error_trap_push ();
68 XSetCloseDownMode (d, 12345);
69 gdk_error_trap_push ();
70 error = gdk_error_trap_pop ();
71 g_assert (error == Success);
72 error = gdk_error_trap_pop ();
73 g_assert (error == BadValue);
75 /* try nested, without sync */
76 gdk_error_trap_push ();
77 gdk_error_trap_push ();
78 gdk_error_trap_push ();
79 XSetCloseDownMode (d, 12345);
80 gdk_error_trap_pop_ignored ();
81 gdk_error_trap_pop_ignored ();
82 gdk_error_trap_pop_ignored ();
86 /* try nested, without sync, with interleaved calls */
87 gdk_error_trap_push ();
88 XSetCloseDownMode (d, 12345);
89 gdk_error_trap_push ();
90 XSetCloseDownMode (d, 12345);
91 gdk_error_trap_push ();
92 XSetCloseDownMode (d, 12345);
93 gdk_error_trap_pop_ignored ();
94 XSetCloseDownMode (d, 12345);
95 gdk_error_trap_pop_ignored ();
96 XSetCloseDownMode (d, 12345);
97 gdk_error_trap_pop_ignored ();
101 /* don't want to get errors that weren't in our push range */
102 gdk_error_trap_push ();
103 XSetCloseDownMode (d, 12345);
104 gdk_error_trap_push ();
105 XSync (d, TRUE); /* not an error */
106 error = gdk_error_trap_pop ();
107 g_assert (error == Success);
108 error = gdk_error_trap_pop ();
109 g_assert (error == BadValue);
111 /* non-roundtrip non-error request after error request, inside trap */
112 gdk_error_trap_push ();
113 XSetCloseDownMode (d, 12345);
114 XMapWindow (d, DefaultRootWindow (d));
115 error = gdk_error_trap_pop ();
116 g_assert (error == BadValue);
118 /* a non-roundtrip non-error request before error request, inside trap */
119 gdk_error_trap_push ();
120 XMapWindow (d, DefaultRootWindow (d));
121 XSetCloseDownMode (d, 12345);
122 error = gdk_error_trap_pop ();
123 g_assert (error == BadValue);
125 /* Not part of any test, just a double-check
126 * that all errors have arrived
132 main (gint argc, gchar *argv[])
134 GdkDisplay *extra_display;
136 gtk_init (&argc, &argv);
138 test_error_trapping (gdk_display_get_default ());
140 extra_display = gdk_display_open (NULL);
141 test_error_trapping (extra_display);
142 gdk_display_close (extra_display);
144 test_error_trapping (gdk_display_get_default ());
146 /* open a display with a trap pushed and see if we
149 gdk_error_trap_push ();
150 gdk_error_trap_push ();
152 extra_display = gdk_display_open (NULL);
153 test_error_trapping (extra_display);
154 gdk_display_close (extra_display);
156 gdk_error_trap_pop_ignored ();
157 gdk_error_trap_pop_ignored ();
159 test_error_trapping (gdk_display_get_default ());
161 /* reassure us that the tests ran. */
162 g_print("All errors properly trapped.\n");