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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
27 test_error_trapping (GdkDisplay *gdk_display)
33 d = GDK_DISPLAY_XDISPLAY (gdk_display);
35 /* verify that we can catch errors */
36 gdk_error_trap_push ();
37 XListProperties (d, 0, &dummy); /* round trip */
38 error = gdk_error_trap_pop ();
39 g_assert (error == BadWindow);
41 gdk_error_trap_push ();
42 XSetCloseDownMode (d, 12345); /* not a round trip */
43 XSetCloseDownMode (d, DestroyAll);
44 error = gdk_error_trap_pop ();
45 g_assert (error == BadValue);
47 /* try the same without sync */
48 gdk_error_trap_push ();
49 XListProperties (d, 0, &dummy);
50 gdk_error_trap_pop_ignored ();
52 gdk_error_trap_push ();
53 XSetCloseDownMode (d, 12345);
54 XSetCloseDownMode (d, DestroyAll);
55 gdk_error_trap_pop_ignored ();
59 /* verify that we can catch with nested traps; inner-most
60 * active trap gets the error */
61 gdk_error_trap_push ();
62 gdk_error_trap_push ();
63 XSetCloseDownMode (d, 12345);
64 error = gdk_error_trap_pop ();
65 g_assert (error == BadValue);
66 error = gdk_error_trap_pop ();
67 g_assert (error == Success);
69 gdk_error_trap_push ();
70 XSetCloseDownMode (d, 12345);
71 gdk_error_trap_push ();
72 error = gdk_error_trap_pop ();
73 g_assert (error == Success);
74 error = gdk_error_trap_pop ();
75 g_assert (error == BadValue);
77 /* try nested, without sync */
78 gdk_error_trap_push ();
79 gdk_error_trap_push ();
80 gdk_error_trap_push ();
81 XSetCloseDownMode (d, 12345);
82 gdk_error_trap_pop_ignored ();
83 gdk_error_trap_pop_ignored ();
84 gdk_error_trap_pop_ignored ();
88 /* try nested, without sync, with interleaved calls */
89 gdk_error_trap_push ();
90 XSetCloseDownMode (d, 12345);
91 gdk_error_trap_push ();
92 XSetCloseDownMode (d, 12345);
93 gdk_error_trap_push ();
94 XSetCloseDownMode (d, 12345);
95 gdk_error_trap_pop_ignored ();
96 XSetCloseDownMode (d, 12345);
97 gdk_error_trap_pop_ignored ();
98 XSetCloseDownMode (d, 12345);
99 gdk_error_trap_pop_ignored ();
103 /* don't want to get errors that weren't in our push range */
104 gdk_error_trap_push ();
105 XSetCloseDownMode (d, 12345);
106 gdk_error_trap_push ();
107 XSync (d, TRUE); /* not an error */
108 error = gdk_error_trap_pop ();
109 g_assert (error == Success);
110 error = gdk_error_trap_pop ();
111 g_assert (error == BadValue);
113 /* non-roundtrip non-error request after error request, inside trap */
114 gdk_error_trap_push ();
115 XSetCloseDownMode (d, 12345);
116 XMapWindow (d, DefaultRootWindow (d));
117 error = gdk_error_trap_pop ();
118 g_assert (error == BadValue);
120 /* a non-roundtrip non-error request before error request, inside trap */
121 gdk_error_trap_push ();
122 XMapWindow (d, DefaultRootWindow (d));
123 XSetCloseDownMode (d, 12345);
124 error = gdk_error_trap_pop ();
125 g_assert (error == BadValue);
127 /* Not part of any test, just a double-check
128 * that all errors have arrived
134 main (gint argc, gchar *argv[])
136 GdkDisplay *extra_display;
138 gtk_init (&argc, &argv);
140 test_error_trapping (gdk_display_get_default ());
142 extra_display = gdk_display_open (NULL);
143 test_error_trapping (extra_display);
144 gdk_display_close (extra_display);
146 test_error_trapping (gdk_display_get_default ());
148 /* open a display with a trap pushed and see if we
151 gdk_error_trap_push ();
152 gdk_error_trap_push ();
154 extra_display = gdk_display_open (NULL);
155 test_error_trapping (extra_display);
156 gdk_display_close (extra_display);
158 gdk_error_trap_pop_ignored ();
159 gdk_error_trap_pop_ignored ();
161 test_error_trapping (gdk_display_get_default ());
163 /* reassure us that the tests ran. */
164 g_print("All errors properly trapped.\n");