2010-09-18 22:18:36 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
* Author: Matthias Clasen
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-09-18 22:18:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "x11/gdkx.h"
|
|
|
|
|
2010-09-19 03:03:31 +00:00
|
|
|
static void
|
|
|
|
test_error_trapping (GdkDisplay *gdk_display)
|
2010-09-18 22:18:36 +00:00
|
|
|
{
|
|
|
|
Display *d;
|
|
|
|
int dummy;
|
|
|
|
int error;
|
|
|
|
|
2010-09-19 03:03:31 +00:00
|
|
|
d = GDK_DISPLAY_XDISPLAY (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
|
|
|
|
/* verify that we can catch errors */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XListProperties (d, 0, &dummy); /* round trip */
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
g_assert (error == BadWindow);
|
|
|
|
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345); /* not a round trip */
|
2010-09-18 22:18:36 +00:00
|
|
|
XSetCloseDownMode (d, DestroyAll);
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
g_assert (error == BadValue);
|
|
|
|
|
|
|
|
/* try the same without sync */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
XListProperties (d, 0, &dummy);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
|
|
|
XSetCloseDownMode (d, DestroyAll);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-18 22:18:36 +00:00
|
|
|
|
|
|
|
XSync (d, TRUE);
|
|
|
|
|
2010-09-20 20:12:11 +00:00
|
|
|
/* verify that we can catch with nested traps; inner-most
|
|
|
|
* active trap gets the error */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
g_assert (error == BadValue);
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-20 20:12:11 +00:00
|
|
|
g_assert (error == Success);
|
|
|
|
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-20 20:12:11 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-20 20:12:11 +00:00
|
|
|
g_assert (error == Success);
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
g_assert (error == BadValue);
|
|
|
|
|
|
|
|
/* try nested, without sync */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
|
|
|
|
XSync (d, TRUE);
|
|
|
|
|
|
|
|
/* try nested, without sync, with interleaved calls */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
|
|
|
|
XSync (d, TRUE);
|
|
|
|
|
|
|
|
/* don't want to get errors that weren't in our push range */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSync (d, TRUE); /* not an error */
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
g_assert (error == Success);
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
g_assert (error == BadValue);
|
|
|
|
|
|
|
|
/* non-roundtrip non-error request after error request, inside trap */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XSetCloseDownMode (d, 12345);
|
|
|
|
XMapWindow (d, DefaultRootWindow (d));
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
g_assert (error == BadValue);
|
|
|
|
|
|
|
|
/* a non-roundtrip non-error request before error request, inside trap */
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
XMapWindow (d, DefaultRootWindow (d));
|
|
|
|
XSetCloseDownMode (d, 12345);
|
2017-11-17 05:07:36 +00:00
|
|
|
error = gdk_x11_display_error_trap_pop (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
g_assert (error == BadValue);
|
|
|
|
|
|
|
|
/* Not part of any test, just a double-check
|
|
|
|
* that all errors have arrived
|
|
|
|
*/
|
|
|
|
XSync (d, TRUE);
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
int
|
2020-07-24 18:40:36 +00:00
|
|
|
main (int argc, char *argv[])
|
2010-09-19 03:03:31 +00:00
|
|
|
{
|
2017-11-17 05:07:36 +00:00
|
|
|
GdkDisplay *gdk_display;
|
2010-09-19 03:03:31 +00:00
|
|
|
GdkDisplay *extra_display;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2010-09-19 03:03:31 +00:00
|
|
|
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_display = gdk_display_get_default ();
|
|
|
|
test_error_trapping (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
|
|
|
|
extra_display = gdk_display_open (NULL);
|
|
|
|
test_error_trapping (extra_display);
|
|
|
|
gdk_display_close (extra_display);
|
|
|
|
|
|
|
|
test_error_trapping (gdk_display_get_default ());
|
|
|
|
|
|
|
|
/* open a display with a trap pushed and see if we
|
|
|
|
* get confused
|
|
|
|
*/
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_push (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
|
|
|
|
extra_display = gdk_display_open (NULL);
|
|
|
|
test_error_trapping (extra_display);
|
|
|
|
gdk_display_close (extra_display);
|
|
|
|
|
2017-11-17 05:07:36 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (gdk_display);
|
2010-09-19 03:03:31 +00:00
|
|
|
|
|
|
|
test_error_trapping (gdk_display_get_default ());
|
|
|
|
|
|
|
|
/* reassure us that the tests ran. */
|
|
|
|
g_print("All errors properly trapped.\n");
|
|
|
|
|
2010-09-18 22:18:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|