Add more structure constructor tests.
[piglit/hramrach.git] / tests / general / object_purgeable.c
blob9793cffefa0b63675d1206a0263daf0d844b7d6e
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.h"
29 #include "object_purgeable.h"
31 PFNGLOBJECTPURGEABLEAPPLEPROC pglObjectPurgeableAPPLE = NULL;
32 PFNGLOBJECTUNPURGEABLEAPPLEPROC pglObjectUnpurgeableAPPLE = NULL;
33 PFNGLGETOBJECTPARAMETERIVAPPLEPROC pglGetObjectParameterivAPPLE = NULL;
35 #define FAIL_ON_ERROR(string) \
36 do { \
37 const GLenum err = glGetError(); \
38 if (err != GL_NO_ERROR) { \
39 fprintf(stderr, "%s generated error 0x%04x\n", \
40 string, err); \
41 pass = GL_FALSE; \
42 } \
43 } while (0)
45 #define EXPECT_AN_ERROR(string, expected) \
46 do { \
47 const GLenum err = glGetError(); \
48 if (err != expected) { \
49 fprintf(stderr, "%s generated error 0x%04x, " \
50 "but error 0x%04x (%s) was expected\n", \
51 string, err, expected, # expected); \
52 pass = GL_FALSE; \
53 } \
54 } while (0)
56 void
57 init_ObjectPurgeableAPI(void)
59 piglit_require_extension("GL_APPLE_object_purgeable");
61 pglObjectPurgeableAPPLE = (PFNGLOBJECTPURGEABLEAPPLEPROC)
62 piglit_get_proc_address("glObjectPurgeableAPPLE");
63 pglObjectUnpurgeableAPPLE = (PFNGLOBJECTUNPURGEABLEAPPLEPROC)
64 piglit_get_proc_address("glObjectUnpurgeableAPPLE");
65 pglGetObjectParameterivAPPLE = (PFNGLGETOBJECTPARAMETERIVAPPLEPROC)
66 piglit_get_proc_address("glGetObjectParameterivAPPLE");
70 /**
71 * Format for error messages when an unexpected value is received.
73 static const char expected_fmt[] =
74 "%s:%s: expected 0x%04x (%s), got 0x%04x\n";
77 /**
78 * Check the setting and querying purgeability on object 0 generates errors.
80 GLboolean
81 test_DefaultObject(GLenum objectType)
83 GLboolean pass = GL_TRUE;
84 GLint param;
86 /* From the GL_APPLE_object_purgeable spec:
88 * "INVALID_VALUE is generated if the <name> parameter of
89 * ObjectUnpurgeableAPPLE or ObjectUnpurgeableAPPLE is zero."
91 (void) (*pglObjectPurgeableAPPLE)(objectType, 0, GL_VOLATILE_APPLE);
92 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_VALUE);
94 (void) (*pglObjectUnpurgeableAPPLE)(objectType, 0, GL_RETAINED_APPLE);
95 EXPECT_AN_ERROR("glObjectUnpurgeableAPPLE", GL_INVALID_VALUE);
97 /* From the GL_APPLE_object_purgeable spec:
99 * "INVALID_VALUE is generated if the <name> parameter of
100 * GetObjectParameterivAPPLE is zero."
102 (*pglGetObjectParameterivAPPLE)(objectType, 0, GL_PURGEABLE_APPLE,
103 &param);
104 EXPECT_AN_ERROR("glGetObjectParameterivAPPLE", GL_INVALID_VALUE);
106 return pass;
110 GLboolean
111 test_ObjectpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
113 GLboolean pass = GL_TRUE;
114 GLenum ret;
116 ret = (*pglObjectPurgeableAPPLE)(objectType, name, option);
117 FAIL_ON_ERROR("glObjectPurgeableAPPLE");
119 switch (option) {
120 case GL_VOLATILE_APPLE:
121 /* From the GL_APPLE_object_purgeable spec:
123 * "If ObjectPurgeableAPPLE is called with an <option> of
124 * VOLATILE_APPLE, then ObjectPurgeableAPPLE will also
125 * return the value VOLATILE_APPLE."
127 if (ret != GL_VOLATILE_APPLE) {
128 fprintf(stderr, expected_fmt,
129 "glObjectPurgeableAPPLE", "GL_VOLATILE_APPLE",
130 GL_VOLATILE_APPLE, "GL_VOLATILE_APPLE",
131 ret);
132 pass = GL_FALSE;
134 break;
136 case GL_RELEASED_APPLE:
137 /* From the GL_APPLE_object_purgeable spec:
139 * "If ObjectPurgeableAPPLE is called with an <option> of
140 * RELEASED_APPLE, then ObjectPurgeableAPPLE may return
141 * either the value RELEASED_APPLE or the value
142 * VOLATILE_APPLE."
144 if (ret != GL_VOLATILE_APPLE && ret != GL_RELEASED_APPLE) {
145 fprintf(stderr, expected_fmt,
146 "glObjectPurgeableAPPLE", "GL_RELEASED_APPLE",
147 GL_VOLATILE_APPLE,
148 "GL_VOLATILE_APPLE or GL_RELEASED_APPLE",
149 ret);
150 pass = GL_FALSE;
152 break;
155 /* From the GL_APPLE_object_purgeable spec:
157 * "Calling ObjectPurgeableAPPLE with either option sets
158 * PURGEABLE_APPLE to TRUE..."
160 if (!test_GetObjectParameterivAPPLE(objectType, name, GL_TRUE)) {
161 fprintf(stderr,
162 "Object marked purgeable is not set to purgeable\n");
163 pass = GL_FALSE;
166 /* From the GL_APPLE_object_purgeable spec:
168 * "If ObjectPurgeableAPPLE is called and PURGEABLE_APPLE is
169 * already TRUE, the error INVALID_OPERATION is generated."
171 (void) (*pglObjectPurgeableAPPLE)(objectType, name, option);
172 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION);
174 return pass;
178 GLboolean
179 test_ObjectunpurgeableAPPLE(GLenum objectType, GLuint name, GLenum option)
181 GLboolean pass = GL_TRUE;
182 GLenum ret;
184 ret = (*pglObjectUnpurgeableAPPLE)(objectType, name, option);
185 FAIL_ON_ERROR("glObjectUnpurgeableAPPLE");
187 switch (option) {
188 case GL_RETAINED_APPLE:
189 /* From the GL_APPLE_object_purgeable spec:
191 * "If ObjectUnpurgeableAPPLE is called with an <option> of
192 * RETAINED_APPLE, then ObjectPurgeableAPPLE may return
193 * either the value RETAINED_APPLE or the value
194 * UNDEFINED_APPLE."
196 if (ret != GL_RETAINED_APPLE && ret != GL_UNDEFINED_APPLE) {
197 fprintf(stderr, expected_fmt,
198 "glObjectUnpurgeableAPPLE", "GL_RETAINED_APPLE",
199 GL_RETAINED_APPLE,
200 "GL_RETAINED_APPLE or GL_UNDEFINED_APPLE",
201 ret);
202 pass = GL_FALSE;
204 break;
206 case GL_UNDEFINED_APPLE:
207 /* From the GL_APPLE_object_purgeable spec:
209 * "If ObjectUnpurgeableAPPLE is called with the <option>
210 * set to UNDEFINED_APPLE, then ObjectUnpurgeableAPPLE will
211 * return the value UNDEFINED_APPLE."
213 if (ret != GL_UNDEFINED_APPLE) {
214 fprintf(stderr, expected_fmt,
215 "glObjectUnpurgeableAPPLE", "GL_UNDEFINED_APPLE",
216 GL_UNDEFINED_APPLE, "GL_UNDEFINED_APPLE",
217 ret);
218 pass = GL_FALSE;
220 break;
223 /* From the GL_APPLE_object_purgeable spec:
225 * "Calling ObjectUnpurgeableAPPLE with either option sets
226 * PURGEABLE_APPLE to FALSE..."
228 if (!test_GetObjectParameterivAPPLE(objectType, name, GL_FALSE)) {
229 fprintf(stderr, "Object marked unpurgeable is not set to "
230 "unpurgeable\n");
231 pass = GL_FALSE;
234 /* From the GL_APPLE_object_purgeable spec:
236 * "If ObjectUnpurgeableAPPLE is called and PURGEABLE_APPLE is
237 * already FALSE, the error INVALID_OPERATION is returned."
239 (void) (*pglObjectUnpurgeableAPPLE)(objectType, name, option);
240 EXPECT_AN_ERROR("glObjectPurgeableAPPLE", GL_INVALID_OPERATION);
242 return pass;
246 GLboolean
247 test_GetObjectParameterivAPPLE(GLenum objectType, GLuint name, GLenum expect)
249 GLboolean pass = GL_TRUE;
250 GLint param;
252 (*pglGetObjectParameterivAPPLE)(objectType, name, GL_PURGEABLE_APPLE,
253 &param);
254 FAIL_ON_ERROR("glGetObjectParameterivAPPLE");
256 if (param != expect) {
257 fprintf(stderr, expected_fmt,
258 "glGetObjectParameterivAPPLE", "GL_PURGEABLE_APPLE",
259 expect, expect ? "GL_TRUE" : "GL_FALSE",
260 param);
261 pass = GL_FALSE;
264 return pass;
268 GLboolean test_Purgeable(GLuint object, GLenum type)
270 GLboolean pass = GL_TRUE;
272 glGetError();
274 if (!test_DefaultObject(type)) {
275 fprintf(stderr, "Default object tests failed.\n");
276 pass = GL_FALSE;
279 if (!test_GetObjectParameterivAPPLE(type, object, GL_FALSE)) {
280 fprintf(stderr, "Default state test failed.\n");
281 pass = GL_FALSE;
284 if (!test_ObjectpurgeableAPPLE(type, object, GL_VOLATILE_APPLE)) {
285 pass = GL_FALSE;
288 if (!test_ObjectunpurgeableAPPLE(type, object, GL_RETAINED_APPLE)) {
289 pass = GL_FALSE;
292 if (!test_ObjectpurgeableAPPLE(type, object, GL_RELEASED_APPLE)) {
293 pass = GL_FALSE;
296 if (!test_ObjectunpurgeableAPPLE(type, object, GL_UNDEFINED_APPLE)) {
297 pass = GL_FALSE;
300 return pass;