arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / egl / egl-query-surface.c
blob3b638a3a8f72f5fbc065ffa666f5c24709db863c
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 egl-query-drawable.c
26 * Test behavior of eglQuerySurface(). See EGL 1.4 spec, Section 3.5.6
27 * Surface Attributes.
29 * For usage information, see usage_error().
32 #include <EGL/egl.h>
33 #include "piglit-util-egl.h"
34 #include "egl-util.h"
36 static EGLint window_width = 119;
37 static EGLint window_height= 137;
39 static void
40 usage_error()
42 const char *message =
43 "usage:\n"
44 " egl-query-surface [-auto] --bad-surface\n"
45 " Call eglQuerySurface(surf=0) and expect that error\n"
46 " EGL_BAD_SURFACE is generated.\n"
47 "\n"
48 " egl-query-surface [-auto] --bad-attr\n"
49 " Call eglQuerySurface(attr=EGL_DONT_CARE) and expect that\n"
50 " error EGL_BAD_ATTRIBUTE is generated.\n"
51 "\n"
52 " egl-query-surface [-auto] --attr=EGL_WIDTH\n"
53 " egl-query-surface [-auto] --attr=EGL_HEIGHT\n"
54 " Call eglQueryDrawable() with the given attribute.\n";
55 printf("%s", message);
56 piglit_report_result(PIGLIT_FAIL);
59 static enum piglit_result
60 query_width(struct egl_state *state)
62 EGLint width;
63 EGLBoolean ok;
65 assert(state->width == window_width);
66 ok = eglQuerySurface(state->egl_dpy, state->surf, EGL_WIDTH, &width);
67 if (!piglit_check_egl_error(EGL_SUCCESS)) {
68 piglit_report_result(PIGLIT_FAIL);
70 if (!ok) {
71 fprintf(stderr, "error: eglQuerySurface() failed\n");
72 return PIGLIT_FAIL;
74 if (width != state->width) {
75 fprintf(stderr,
76 "error: width=%d but eglQuerySurface(EGL_WIDTH) "
77 "returned %d\n", state->width, width);
78 return PIGLIT_FAIL;
80 return PIGLIT_PASS;
83 static enum piglit_result
84 query_height(struct egl_state *state)
86 EGLint height;
87 EGLBoolean ok;
89 assert(state->height == window_height);
90 ok = eglQuerySurface(state->egl_dpy, state->surf, EGL_HEIGHT, &height);
91 if (!piglit_check_egl_error(EGL_SUCCESS)) {
92 piglit_report_result(PIGLIT_FAIL);
94 if (!ok) {
95 fprintf(stderr, "error: eglQuerySurface() failed\n");
96 return PIGLIT_FAIL;
98 if (height != state->height) {
99 fprintf(stderr,
100 "error: height=%d but eglQuerySurface(EGL_HEIGHT) "
101 "returned %d\n", state->height, height);
102 return PIGLIT_FAIL;
104 return PIGLIT_PASS;
107 static enum piglit_result
108 query_bad_surface(struct egl_state *state)
110 EGLint width;
111 EGLBoolean ok;
113 ok = eglQuerySurface(state->egl_dpy, 0, EGL_WIDTH, &width);
114 if (ok) {
115 fprintf(stderr,
116 "error: eglQuerySurface(surface=0) succeeded\n");
117 return PIGLIT_FAIL;
119 if (!piglit_check_egl_error(EGL_BAD_SURFACE)) {
120 piglit_report_result(PIGLIT_FAIL);
122 return PIGLIT_PASS;
125 static enum piglit_result
126 query_bad_parameter(struct egl_state *state)
128 EGLint junk;
129 EGLBoolean ok;
131 ok = eglQuerySurface(state->egl_dpy, state->surf, EGL_DONT_CARE,
132 &junk);
133 if (ok) {
134 fprintf(stderr,
135 "error: eglQuerySurface(attribute=EGL_DONT_CARE) "
136 "succeeded\n");
137 return PIGLIT_FAIL;
139 if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE))
140 piglit_report_result(PIGLIT_FAIL);
141 return PIGLIT_PASS;
144 static void
145 remove_arg(char **argv, int i)
147 int j;
148 for (j = i; argv[j] != NULL; ++j) {
149 argv[j] = argv[j + 1];
153 static void
154 parse_args(char **argv,
155 int *out_argc,
156 enum piglit_result (**out_test)(struct egl_state*))
158 int i;
160 /* Count of parsed args, excluding -auto. */
161 int num_parsed_args = 0;
163 for (i = 1; argv[i] != NULL;) {
164 const char *arg = argv[i];
165 if (!strncmp(arg, "--bad-surface", 13)) {
166 ++num_parsed_args;
167 remove_arg(argv, i);
168 *out_test = query_bad_surface;
169 } else if (!strncmp(arg, "--bad-attr", 10)) {
170 ++num_parsed_args;
171 remove_arg(argv, i);
172 *out_test = query_bad_parameter;
173 } else if (!strncmp(arg, "--attr=EGL_WIDTH", 16)) {
174 ++num_parsed_args;
175 remove_arg(argv, i);
176 *out_test = query_width;
177 } else if (!strncmp(arg, "--attr=EGL_HEIGHT", 17)) {
178 ++num_parsed_args;
179 remove_arg(argv, i);
180 *out_test = query_height;
181 } else {
182 /* Unrecognized argument. */
183 ++i;
187 if (num_parsed_args != 1) {
188 usage_error();
191 *out_argc -= num_parsed_args;
195 main(int argc, char *argv[])
197 struct egl_test test;
198 enum piglit_result (*test_func)(struct egl_state *state) = NULL;
200 parse_args(argv, &argc, &test_func);
202 egl_init_test(&test);
203 test.draw = test_func;
204 test.window_width = window_width;
205 test.window_height = window_height;
207 if (egl_util_run(&test, argc, argv) != PIGLIT_PASS)
208 return EXIT_FAILURE;
209 return EXIT_SUCCESS;