glsl-1.10: test mesa bug with forward declaration
[piglit.git] / tests / glx / glx-make-current-bad-context.c
blob55b3c98493a6d6bfe3ea7b5e20dfd51f6f377592
1 /*
2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /** @file glx-make-current-bad-context.c
26 * Test that glXMakeCurrent() with a bad context correctly returns
27 * GLXBadContext.
30 #include "piglit-util-gl.h"
31 #include "piglit-glx-util.h"
33 int piglit_width = 50, piglit_height = 50;
35 bool found_badvalue = false;
36 int expect_badvalue(Display *dpy, XErrorEvent *e)
38 if (e->error_code == BadValue)
39 found_badvalue = true;
41 return 0;
44 int
45 main(int argc, char **argv)
47 Display *dpy;
48 Window win;
49 XVisualInfo *visinfo;
50 int i;
51 int (*old_handler)(Display *, XErrorEvent *);
52 GLXContext ctx;
53 int attrib[] = {
54 GLX_RGBA,
55 GLX_RED_SIZE, 1,
56 GLX_GREEN_SIZE, 1,
57 GLX_BLUE_SIZE, 1,
58 GLX_DOUBLEBUFFER,
59 None
61 GLXFBConfig config, *configs;
62 int nconfigs;
64 for(i = 1; i < argc; ++i) {
65 if (!strcmp(argv[i], "-auto"))
66 piglit_automatic = 1;
67 else
68 fprintf(stderr, "Unknown option: %s\n", argv[i]);
71 dpy = XOpenDisplay(NULL);
72 if (dpy == NULL) {
73 fprintf(stderr, "couldn't open display\n");
74 piglit_report_result(PIGLIT_FAIL);
76 visinfo = piglit_get_glx_visual(dpy);
77 win = piglit_get_glx_window(dpy, visinfo);
79 configs = glXChooseFBConfig(dpy, DefaultScreen(dpy),
80 attrib, &nconfigs);
81 assert(nconfigs > 0);
82 config = configs[0];
83 XFree(configs);
85 old_handler = XSetErrorHandler(expect_badvalue);
86 ctx = glXCreateNewContext(dpy, config, 0x1010, NULL, True);
87 XSync(dpy, 0);
88 XSetErrorHandler(old_handler);
90 if (!found_badvalue) {
91 printf("Failed to get BadValue from glXCreateContext().\n");
92 piglit_report_result(PIGLIT_FAIL);
95 if (ctx != NULL) {
96 glXMakeCurrent(dpy, win, ctx);
97 piglit_report_result(PIGLIT_PASS);
98 } else {
99 piglit_report_result(PIGLIT_SKIP);
102 return 0;