glx: don't call XMapWindow redundantly
[piglit.git] / tests / glx / glx-string-sanity.c
blob3a86f11b8f0a680b1d8dbf4a7f24402c4d9ab820
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.
25 /** @file glx-string-sanity.c
26 * Sanity check the various GLX extension strings that application can query.
28 * This test reproduces Mesa bug #56057.
31 #include <stdbool.h>
32 #include "piglit-util-gl.h"
33 #include "piglit-glx-util.h"
35 static const char *
36 eat_whitespace(const char *s)
38 /* Page 17 of the GLX 1.4 spec says:
40 * "The string is zero-terminated and contains a space-seperated
41 * list of extension names."
43 * It doesn't say whitespace. It just says space.
45 while (*s == ' ' && *s != '\0')
46 s++;
48 return s;
51 static const char *
52 eat_characters(const char *s)
54 while (*s != ' ' && *s != '\0')
55 s++;
57 return s;
60 static const char *
61 find_extension(const char *haystack, const char *needle, size_t needle_length)
63 while ((haystack = strstr(haystack, needle)) != NULL) {
64 if (haystack[needle_length] == '\0'
65 || haystack[needle_length] == ' ')
66 break;
69 return haystack;
72 static bool
73 validate_string(const char *string, const char *name)
75 bool pass = true;
77 while (*string != '\0') {
78 string = eat_whitespace(string);
79 if (*string == '\0')
80 break;
82 if (strncmp("GLX_", string, 4) != 0) {
83 char junk[15];
85 /* Since the extension string may be very long, just
86 * log a few characters.
88 strncpy(junk, string, sizeof(junk));
89 junk[sizeof(junk) - 1] = '\0';
90 fprintf(stderr, "%s contains junk: %s\n", name, junk);
91 pass = false;
94 string = eat_characters(string);
97 return pass;
101 main(int argc, char **argv)
103 bool pass = true;
104 const char *client_string;
105 const char *server_string;
106 const char *unified_string;
107 char *buf;
109 Display *dpy = XOpenDisplay(NULL);
110 if (dpy == NULL) {
111 fprintf(stderr, "couldn't open display\n");
112 piglit_report_result(PIGLIT_FAIL);
115 /* First, make sure that all the strings have the correct format.
117 server_string = glXQueryServerString(dpy, 0, GLX_EXTENSIONS);
118 pass = validate_string(server_string, "server extensions string")
119 && pass;
121 client_string = glXGetClientString(dpy, GLX_EXTENSIONS);
122 pass = validate_string(client_string, "client extensions string")
123 && pass;
125 unified_string = glXQueryExtensionsString(dpy, 0);
126 pass = validate_string(unified_string, "unified extensions string")
127 && pass;
129 /* Now make sure that any string listed in both the server string and
130 * the client string is listed in the unified string.
132 * Also make sure that any string *not* listed in the client string is
133 * *not* listed in the unified string. Since there are several
134 * "client only" extensions (e.g., GLX_ARB_get_proc_address), it is
135 * valid for a string to not be in the server string when it is listed
136 * in the unified string.
138 buf = malloc(strlen(server_string) + 1);
139 while (*server_string != '\0') {
140 const char *client;
141 const char *end;
142 size_t bytes;
145 server_string = eat_whitespace(server_string);
146 if (*server_string == '\0')
147 break;
149 end = eat_characters(server_string);
151 bytes = (size_t)(end - server_string);
152 memcpy(buf, server_string, bytes);
153 buf[bytes] = '\0';
155 /* Try to find the extension in the client extension list.
157 client = find_extension(client_string, buf, bytes);
158 if (client != NULL) {
159 if (find_extension(unified_string, buf, bytes) == NULL) {
160 fprintf(stderr,
161 "%s found in both client and server "
162 "extension strings, but missing from "
163 "unified string.\n",
164 buf);
165 pass = false;
167 } else {
168 if (find_extension(unified_string, buf, bytes) != NULL) {
169 fprintf(stderr,
170 "%s not found in client extension "
171 "string, but found in unified "
172 "string.\n",
173 buf);
174 pass = false;
178 server_string = end;
181 free(buf);
183 XCloseDisplay(dpy);
185 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
186 return 0;