fix the spelling in whole piglit
[piglit.git] / tests / general / object_purgeable.c
blob7c758c948e21826e2063a6abb9f493bc95cab9fa
1 /*
2 * Copyright © 2010 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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Shuang He <shuang.he@intel.com>
25 * Ian Romanick <ian.d.romanick@intel.com>
28 #include "piglit-util-gl.h"
29 #include "object_purgeable.h"
31 #define FAIL_ON_ERROR(string) \
32 do { \
33 const GLenum err = glGetError(); \
34 if (err != GL_NO_ERROR) { \
35 fprintf(stderr, "%s generated error 0x%04x\n", \
36 string, err); \
37 pass = GL_FALSE; \
38 } \
39 } while (0)
41 #define EXPECT_AN_ERROR(string, expected) \
42 do { \
43 const GLenum err = glGetError(); \
44 if (err != expected) { \
45 fprintf(stderr, "%s generated error 0x%04x, " \
46 "but error 0x%04x (%s) was expected\n", \
47 string, err, expected, # expected); \
48 pass = GL_FALSE; \
49 } \
50 } while (0)
52 void
53 init_ObjectPurgeableAPI(void)
55 piglit_require_extension("GL_APPLE_object_purgeable");
59 #define NO_ENUM 0xffffffff
60 static void
61 print_result(const char *fname, const GLenum option, const GLenum result,
62 const GLenum expected_1, const GLenum expected_2)
64 fprintf(stderr, "%s:%s: ", fname, piglit_get_gl_enum_name(option));
65 fprintf(stderr, "expected 0x%04x (%s)",
66 expected_1, piglit_get_gl_enum_name(expected_1));
67 if (expected_2 != NO_ENUM)
68 fprintf(stderr, " or 0x%04x (%s), ",
69 expected_2, piglit_get_gl_enum_name(expected_2));
70 fprintf(stderr, ", got 0x%04x (%s).",
71 result, piglit_get_gl_enum_name(result));
75 /**
76 * Check the setting and querying purgeability on object 0 generates errors.
78 GLboolean
79 test_DefaultObject(GLenum objectType)
81 GLboolean pass = GL_TRUE;
82 GLint param;
84 /* From the GL_APPLE_object_purgeable spec:
86 * "INVALID_VALUE is generated if the <name> parameter of
87 * ObjectUnpurgeableAPPLE or ObjectUnpurgeableAPPLE is zero."
89 glObjectPurgeableAPPLE(objectType, 0, GL_VOLATILE_APPLE);
90 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_VALUE);
92 glObjectUnpurgeableAPPLE(objectType, 0, GL_RETAINED_APPLE);
93 EXPECT_AN_ERROR("glObjectUnpurgeableAPPLE", GL_INVALID_VALUE);
95 /* From the GL_APPLE_object_purgeable spec:
97 * "INVALID_VALUE is generated if the <name> parameter of
98 * GetObjectParameterivAPPLE is zero."
100 glGetObjectParameterivAPPLE(objectType, 0, GL_PURGEABLE_APPLE,
101 &param);
102 EXPECT_AN_ERROR("glGetObjectParameterivAPPLE", GL_INVALID_VALUE);
104 return pass;
108 GLboolean
109 test_ObjectpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
111 GLboolean pass = GL_TRUE;
112 GLenum ret;
114 ret = glObjectPurgeableAPPLE(objectType, name, option);
115 FAIL_ON_ERROR("glObjectPurgeableAPPLE");
117 switch (option) {
118 case GL_VOLATILE_APPLE:
119 /* From the GL_APPLE_object_purgeable spec:
121 * "If ObjectPurgeableAPPLE is called with an <option> of
122 * VOLATILE_APPLE, then ObjectPurgeableAPPLE will also
123 * return the value VOLATILE_APPLE."
125 if (ret != GL_VOLATILE_APPLE) {
126 print_result("glObjectPurgeableAPPLE", option, ret,
127 GL_VOLATILE_APPLE, NO_ENUM);
128 pass = GL_FALSE;
130 break;
132 case GL_RELEASED_APPLE:
133 /* From the GL_APPLE_object_purgeable spec:
135 * "If ObjectPurgeableAPPLE is called with an <option> of
136 * RELEASED_APPLE, then ObjectPurgeableAPPLE may return
137 * either the value RELEASED_APPLE or the value
138 * VOLATILE_APPLE."
140 if (ret != GL_VOLATILE_APPLE && ret != GL_RELEASED_APPLE) {
141 print_result("glObjectPurgeableAPPLE", option, ret,
142 GL_RELEASED_APPLE,
143 GL_VOLATILE_APPLE);
144 pass = GL_FALSE;
146 break;
149 /* From the GL_APPLE_object_purgeable spec:
151 * "Calling ObjectPurgeableAPPLE with either option sets
152 * PURGEABLE_APPLE to TRUE..."
154 if (!test_GetObjectParameterivAPPLE(objectType, name, GL_TRUE)) {
155 fprintf(stderr,
156 "Object marked purgeable is not set to purgeable\n");
157 pass = GL_FALSE;
160 /* From the GL_APPLE_object_purgeable spec:
162 * "If ObjectPurgeableAPPLE is called and PURGEABLE_APPLE is
163 * already TRUE, the error INVALID_OPERATION is generated."
165 glObjectPurgeableAPPLE(objectType, name, option);
166 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION);
168 return pass;
172 GLboolean
173 test_ObjectunpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
175 GLboolean pass = GL_TRUE;
176 GLenum ret;
178 ret = glObjectUnpurgeableAPPLE(objectType, name, option);
179 FAIL_ON_ERROR("glObjectUnpurgeableAPPLE");
181 switch (option) {
182 case GL_RETAINED_APPLE:
183 /* From the GL_APPLE_object_purgeable spec:
185 * "If ObjectUnpurgeableAPPLE is called with an <option> of
186 * RETAINED_APPLE, then ObjectPurgeableAPPLE may return
187 * either the value RETAINED_APPLE or the value
188 * UNDEFINED_APPLE."
190 if (ret != GL_RETAINED_APPLE && ret != GL_UNDEFINED_APPLE) {
191 print_result("glObjectUnpurgeableAPPLE", option, ret,
192 GL_RETAINED_APPLE,
193 GL_UNDEFINED_APPLE);
194 pass = GL_FALSE;
196 break;
198 case GL_UNDEFINED_APPLE:
199 /* From the GL_APPLE_object_purgeable spec:
201 * "If ObjectUnpurgeableAPPLE is called with the <option>
202 * set to UNDEFINED_APPLE, then ObjectUnpurgeableAPPLE will
203 * return the value UNDEFINED_APPLE."
205 if (ret != GL_UNDEFINED_APPLE) {
206 print_result("glObjectUnpurgeableAPPLE", option, ret,
207 GL_UNDEFINED_APPLE, NO_ENUM);
208 pass = GL_FALSE;
210 break;
213 /* From the GL_APPLE_object_purgeable spec:
215 * "Calling ObjectUnpurgeableAPPLE with either option sets
216 * PURGEABLE_APPLE to FALSE..."
218 if (!test_GetObjectParameterivAPPLE(objectType, name, GL_FALSE)) {
219 fprintf(stderr, "Object marked unpurgeable is not set to "
220 "unpurgeable\n");
221 pass = GL_FALSE;
224 /* From the GL_APPLE_object_purgeable spec:
226 * "If ObjectUnpurgeableAPPLE is called and PURGEABLE_APPLE is
227 * already FALSE, the error INVALID_OPERATION is returned."
229 glObjectUnpurgeableAPPLE(objectType, name, option);
230 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION);
232 return pass;
236 GLboolean
237 test_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum expect)
239 GLboolean pass = GL_TRUE;
240 GLint param;
242 glGetObjectParameterivAPPLE(objectType, name, GL_PURGEABLE_APPLE,
243 &param);
244 FAIL_ON_ERROR("glGetObjectParameterivAPPLE");
246 if (param != expect) {
247 print_result("glObjectParameterivAPPLE", GL_PURGEABLE_APPLE,
248 param, expect, NO_ENUM);
249 pass = GL_FALSE;
252 return pass;
256 GLboolean test_Purgeable(GLuint object, GLenum type)
258 GLboolean pass = GL_TRUE;
260 glGetError();
262 if (!test_DefaultObject(type)) {
263 fprintf(stderr, "Default object tests failed.\n");
264 pass = GL_FALSE;
267 if (!test_GetObjectParameterivAPPLE(type, object, GL_FALSE)) {
268 fprintf(stderr, "Default state test failed.\n");
269 pass = GL_FALSE;
272 if (!test_ObjectpurgeableAPPLE(type, object, GL_VOLATILE_APPLE)) {
273 pass = GL_FALSE;
276 if (!test_ObjectunpurgeableAPPLE(type, object, GL_RETAINED_APPLE)) {
277 pass = GL_FALSE;
280 if (!test_ObjectpurgeableAPPLE(type, object, GL_RELEASED_APPLE)) {
281 pass = GL_FALSE;
284 if (!test_ObjectunpurgeableAPPLE(type, object, GL_UNDEFINED_APPLE)) {
285 pass = GL_FALSE;
288 return pass;