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
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
24 /** @file egl-query-drawable.c
26 * Test behavior of eglQuerySurface(). See EGL 1.4 spec, Section 3.5.6
29 * For usage information, see usage_error().
33 #include "piglit-util-egl.h"
36 static EGLint window_width
= 119;
37 static EGLint window_height
= 137;
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"
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"
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
)
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
);
71 fprintf(stderr
, "error: eglQuerySurface() failed\n");
74 if (width
!= state
->width
) {
76 "error: width=%d but eglQuerySurface(EGL_WIDTH) "
77 "returned %d\n", state
->width
, width
);
83 static enum piglit_result
84 query_height(struct egl_state
*state
)
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
);
95 fprintf(stderr
, "error: eglQuerySurface() failed\n");
98 if (height
!= state
->height
) {
100 "error: height=%d but eglQuerySurface(EGL_HEIGHT) "
101 "returned %d\n", state
->height
, height
);
107 static enum piglit_result
108 query_bad_surface(struct egl_state
*state
)
113 ok
= eglQuerySurface(state
->egl_dpy
, 0, EGL_WIDTH
, &width
);
116 "error: eglQuerySurface(surface=0) succeeded\n");
119 if (!piglit_check_egl_error(EGL_BAD_SURFACE
)) {
120 piglit_report_result(PIGLIT_FAIL
);
125 static enum piglit_result
126 query_bad_parameter(struct egl_state
*state
)
131 ok
= eglQuerySurface(state
->egl_dpy
, state
->surf
, EGL_DONT_CARE
,
135 "error: eglQuerySurface(attribute=EGL_DONT_CARE) "
139 if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE
))
140 piglit_report_result(PIGLIT_FAIL
);
145 remove_arg(char **argv
, int i
)
148 for (j
= i
; argv
[j
] != NULL
; ++j
) {
149 argv
[j
] = argv
[j
+ 1];
154 parse_args(char **argv
,
156 enum piglit_result (**out_test
)(struct egl_state
*))
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)) {
168 *out_test
= query_bad_surface
;
169 } else if (!strncmp(arg
, "--bad-attr", 10)) {
172 *out_test
= query_bad_parameter
;
173 } else if (!strncmp(arg
, "--attr=EGL_WIDTH", 16)) {
176 *out_test
= query_width
;
177 } else if (!strncmp(arg
, "--attr=EGL_HEIGHT", 17)) {
180 *out_test
= query_height
;
182 /* Unrecognized argument. */
187 if (num_parsed_args
!= 1) {
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
)