fix the spelling in whole piglit
[piglit.git] / tests / spec / glx_arb_create_context / invalid-attribute.c
blob27e8004025c25ed847cde9684bb2e6c57e42c5f1
1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
22 #include "piglit-util-gl.h"
23 #include "piglit-glx-util.h"
24 #include "common.h"
26 static bool try_attribute(int attribute)
28 /* If the attribute is GLX_CONTEXT_CORE_PROFILE_BIT_ARB, use a valid
29 * value for that attribute. This ensures that the attribute is
30 * rejected for the correct reason.
32 const int attribs[] = {
33 attribute,
34 (attribute == GLX_CONTEXT_PROFILE_MASK_ARB)
35 ? GLX_CONTEXT_CORE_PROFILE_BIT_ARB : 0,
36 None
38 GLXContext ctx;
39 bool pass = true;
41 ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs);
42 XSync(dpy, 0);
44 if (ctx != NULL) {
45 fprintf(stderr,
46 "Created OpenGL context with invalid attribute "
47 "0x%08x, but this should have failed.\n",
48 attribute);
49 glXDestroyContext(dpy, ctx);
50 pass = false;
53 /* The GLX_ARB_create_context spec says:
55 * "* If an attribute or attribute value in <attrib_list> is not
56 * recognized (including unrecognized bits in bitmask
57 * attributes), BadValue is generated."
59 if (!validate_glx_error_code(BadValue, -1)) {
60 fprintf(stderr, "Attribute = 0x%08x\n", attribute);
61 pass = false;
64 return pass;
67 int main(int argc, char **argv)
69 static const int bad_attributes[] = {
70 0xffff0000,
71 GLX_SAMPLE_BUFFERS
73 bool pass = true;
74 unsigned i;
76 for (int i = 1; i < argc; i++) {
77 if (!strcmp(argv[i], "-auto"))
78 piglit_automatic = 1;
79 else
80 fprintf(stderr, "Unknown option: %s\n", argv[i]);
83 GLX_ARB_create_context_setup();
85 for (i = 0; i < ARRAY_SIZE(bad_attributes); i++) {
86 pass = try_attribute(bad_attributes[i]) && pass;
89 /* The GLX_ARB_create_context spec says:
91 * "If GLX_ARB_create_context_profile is not supported, then the
92 * GLX_CONTEXT_PROFILE_MASK_ARB attribute [is] not defined, and
93 * specifying the attribute in <attribList> attribute will
94 * generate BadValue."
96 if (!piglit_is_glx_extension_supported(dpy, "GLX_ARB_create_context_profile")) {
97 pass = try_attribute(GLX_CONTEXT_PROFILE_MASK_ARB)
98 && pass;
101 GLX_ARB_create_context_teardown();
103 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
104 return 0;