1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Negative Buffer API tests.
22 *//*--------------------------------------------------------------------*/
23
24 #include "es2fNegativeBufferApiTests.hpp"
25 #include "es2fApiCase.hpp"
26
27 #include "glwEnums.hpp"
28 #include "glwDefs.hpp"
29
30 using namespace glw; // GL types
31
32 namespace deqp
33 {
34 namespace gles2
35 {
36 namespace Functional
37 {
38
39 using tcu::TestLog;
40
NegativeBufferApiTests(Context & context)41 NegativeBufferApiTests::NegativeBufferApiTests (Context& context)
42 : TestCaseGroup(context, "buffer", "Negative Buffer API Cases")
43 {
44 }
45
~NegativeBufferApiTests(void)46 NegativeBufferApiTests::~NegativeBufferApiTests (void)
47 {
48 }
49
init(void)50 void NegativeBufferApiTests::init (void)
51 {
52 ES2F_ADD_API_CASE(bind_buffer, "Invalid glBindBuffer() usage",
53 {
54 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not one of the allowable values.");
55 glBindBuffer(-1, 0);
56 expectError(GL_INVALID_ENUM);
57 m_log << TestLog::EndSection;
58 });
59 ES2F_ADD_API_CASE(delete_buffers, "Invalid glDeleteBuffers() usage",
60 {
61 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
62 glDeleteBuffers(-1, 0);
63 expectError(GL_INVALID_VALUE);
64 m_log << TestLog::EndSection;
65 });
66 ES2F_ADD_API_CASE(gen_buffers, "Invalid glGenBuffers() usage",
67 {
68 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
69 glGenBuffers(-1, 0);
70 expectError(GL_INVALID_VALUE);
71 m_log << TestLog::EndSection;
72 });
73 ES2F_ADD_API_CASE(buffer_data, "Invalid glBufferData() usage",
74 {
75 GLuint buffer;
76 glGenBuffers(1, &buffer);
77 glBindBuffer(GL_ARRAY_BUFFER, buffer);
78
79 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.");
80 glBufferData(-1, 0, NULL, GL_STREAM_DRAW);
81 expectError(GL_INVALID_ENUM);
82 m_log << TestLog::EndSection;
83
84 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if usage is not GL_STREAM_DRAW, GL_STATIC_DRAW, or GL_DYNAMIC_DRAW.");
85 glBufferData(GL_ARRAY_BUFFER, 0, NULL, -1);
86 expectError(GL_INVALID_ENUM);
87 m_log << TestLog::EndSection;
88
89 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if size is negative.");
90 glBufferData(GL_ARRAY_BUFFER, -1, NULL, GL_STREAM_DRAW);
91 expectError(GL_INVALID_VALUE);
92 m_log << TestLog::EndSection;
93
94 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the reserved buffer object name 0 is bound to target.");
95 glBindBuffer(GL_ARRAY_BUFFER, 0);
96 glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_STREAM_DRAW);
97 expectError(GL_INVALID_OPERATION);
98 m_log << TestLog::EndSection;
99
100 glDeleteBuffers(1, &buffer);
101 });
102 ES2F_ADD_API_CASE(buffer_sub_data, "Invalid glBufferSubData() usage",
103 {
104 GLuint buffer;
105 glGenBuffers(1, &buffer);
106 glBindBuffer(GL_ARRAY_BUFFER, buffer);
107 glBufferData(GL_ARRAY_BUFFER, 10, 0, GL_STREAM_DRAW);
108
109 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.");
110 glBufferSubData(-1, 1, 1, 0);
111 expectError(GL_INVALID_ENUM);
112 m_log << TestLog::EndSection;
113
114 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the reserved buffer object name 0 is bound to target.");
115 glBindBuffer(GL_ARRAY_BUFFER, 0);
116 glBufferSubData(GL_ARRAY_BUFFER, 1, 1, 0);
117 expectError(GL_INVALID_OPERATION);
118 m_log << TestLog::EndSection;
119
120 glDeleteBuffers(1, &buffer);
121 });
122 ES2F_ADD_API_CASE(buffer_sub_data_size_offset, "Invalid glBufferSubData() usage",
123 {
124 GLuint buffer;
125 glGenBuffers(1, &buffer);
126 glBindBuffer(GL_ARRAY_BUFFER, buffer);
127 glBufferData(GL_ARRAY_BUFFER, 10, 0, GL_STREAM_DRAW);
128
129 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if offset or size is negative, or if together they define a region of memory that extends beyond the buffer object's allocated data store.");
130 glBufferSubData(GL_ARRAY_BUFFER, -1, 1, 0);
131 expectError(GL_INVALID_VALUE);
132 glBufferSubData(GL_ARRAY_BUFFER, -1, -1, 0);
133 expectError(GL_INVALID_VALUE);
134 glBufferSubData(GL_ARRAY_BUFFER, 1, -1, 0);
135 expectError(GL_INVALID_VALUE);
136 glBufferSubData(GL_ARRAY_BUFFER, 15, 1, 0);
137 expectError(GL_INVALID_VALUE);
138 glBufferSubData(GL_ARRAY_BUFFER, 1, 15, 0);
139 expectError(GL_INVALID_VALUE);
140 glBufferSubData(GL_ARRAY_BUFFER, 8, 8, 0);
141 expectError(GL_INVALID_VALUE);
142 m_log << TestLog::EndSection;
143
144 glDeleteBuffers(1, &buffer);
145 });
146 ES2F_ADD_API_CASE(clear, "Invalid glClear() usage",
147 {
148 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if any bit other than the three defined bits is set in mask.");
149 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
150 expectError(GL_NO_ERROR);
151 glClear(0x00000200);
152 expectError(GL_INVALID_VALUE);
153 glClear(0x00001000);
154 expectError(GL_INVALID_VALUE);
155 glClear(0x00000010);
156 expectError(GL_INVALID_VALUE);
157 m_log << TestLog::EndSection;
158 });
159 ES2F_ADD_API_CASE(read_pixels, "Invalid glReadPixels() usage",
160 {
161 std::vector<GLubyte> ubyteData(4);
162
163 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the combination of format and type is unsupported.");
164 glReadPixels(0, 0, 1, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_SHORT_4_4_4_4, &ubyteData[0]);
165 expectError(GL_INVALID_OPERATION);
166 m_log << TestLog::EndSection;
167
168 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if either width or height is negative.");
169 glReadPixels(0, 0, -1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
170 expectError(GL_INVALID_VALUE);
171 glReadPixels(0, 0, 1, -1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
172 expectError(GL_INVALID_VALUE);
173 glReadPixels(0, 0, -1, -1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
174 expectError(GL_INVALID_VALUE);
175 m_log << TestLog::EndSection;
176
177 m_log << TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
178 GLuint fbo;
179 glGenFramebuffers(1, &fbo);
180 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
181 glCheckFramebufferStatus(GL_FRAMEBUFFER);
182 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
183 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
184 m_log << TestLog::EndSection;
185 });
186 ES2F_ADD_API_CASE(read_pixels_format_mismatch, "Invalid glReadPixels() usage",
187 {
188 std::vector<GLubyte> ubyteData(4);
189 std::vector<GLushort> ushortData(4);
190
191 m_log << TestLog::Section("", "Unsupported combinations of format and type will generate an INVALID_OPERATION error.");
192 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, &ushortData[0]);
193 expectError(GL_INVALID_OPERATION);
194 glReadPixels(0, 0, 1, 1, GL_ALPHA, GL_UNSIGNED_SHORT_5_6_5, &ushortData[0]);
195 expectError(GL_INVALID_OPERATION);
196 glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, &ushortData[0]);
197 expectError(GL_INVALID_OPERATION);
198 glReadPixels(0, 0, 1, 1, GL_ALPHA, GL_UNSIGNED_SHORT_4_4_4_4, &ushortData[0]);
199 expectError(GL_INVALID_OPERATION);
200 glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, &ushortData[0]);
201 expectError(GL_INVALID_OPERATION);
202 glReadPixels(0, 0, 1, 1, GL_ALPHA, GL_UNSIGNED_SHORT_5_5_5_1, &ushortData[0]);
203 expectError(GL_INVALID_OPERATION);
204 m_log << TestLog::EndSection;
205
206 m_log << TestLog::Section("", "GL_RGBA/GL_UNSIGNED_BYTE is always accepted and the other acceptable pair can be discovered by querying GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE.");
207 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
208 expectError(GL_NO_ERROR);
209 GLint readFormat;
210 GLint readType;
211 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &readFormat);
212 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &readType);
213 glReadPixels(0, 0, 1, 1, readFormat, readType, &ubyteData[0]);
214 expectError(GL_NO_ERROR);
215 m_log << TestLog::EndSection;
216 });
217
218 // Framebuffer Objects
219
220 ES2F_ADD_API_CASE(bind_framebuffer, "Invalid glBindFramebuffer() usage",
221 {
222 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
223 glBindFramebuffer(-1, 0);
224 expectError(GL_INVALID_ENUM);
225 glBindFramebuffer(GL_RENDERBUFFER, 0);
226 expectError(GL_INVALID_ENUM);
227 m_log << TestLog::EndSection;
228 });
229 ES2F_ADD_API_CASE(bind_renderbuffer, "Invalid glBindRenderbuffer() usage",
230 {
231 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_RENDERBUFFER.");
232 glBindRenderbuffer(-1, 0);
233 expectError(GL_INVALID_ENUM);
234 glBindRenderbuffer(GL_FRAMEBUFFER, 0);
235 expectError(GL_INVALID_ENUM);
236 m_log << TestLog::EndSection;
237 });
238 ES2F_ADD_API_CASE(check_framebuffer_status, "Invalid glCheckFramebufferStatus() usage",
239 {
240 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
241 glCheckFramebufferStatus(-1);
242 expectError(GL_INVALID_ENUM);
243 glCheckFramebufferStatus(GL_RENDERBUFFER);
244 expectError(GL_INVALID_ENUM);
245 m_log << TestLog::EndSection;
246 });
247 ES2F_ADD_API_CASE(gen_framebuffers, "Invalid glGenFramebuffers() usage",
248 {
249 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
250 glGenFramebuffers(-1, 0);
251 expectError(GL_INVALID_VALUE);
252 m_log << TestLog::EndSection;
253 });
254 ES2F_ADD_API_CASE(gen_renderbuffers, "Invalid glGenRenderbuffers() usage",
255 {
256 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
257 glGenRenderbuffers(-1, 0);
258 expectError(GL_INVALID_VALUE);
259 m_log << TestLog::EndSection;
260 });
261 ES2F_ADD_API_CASE(delete_framebuffers, "Invalid glDeleteFramebuffers() usage",
262 {
263 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
264 glDeleteFramebuffers(-1, 0);
265 expectError(GL_INVALID_VALUE);
266 m_log << TestLog::EndSection;
267 });
268 ES2F_ADD_API_CASE(delete_renderbuffers, "Invalid glDeleteRenderbuffers() usage",
269 {;
270 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
271 glDeleteRenderbuffers(-1, 0);
272 expectError(GL_INVALID_VALUE);
273 m_log << TestLog::EndSection;
274 });
275 ES2F_ADD_API_CASE(framebuffer_renderbuffer, "Invalid glFramebufferRenderbuffer() usage",
276 {
277 GLuint fbo;
278 GLuint rbo;
279 glGenFramebuffers(1, &fbo);
280 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
281 glGenRenderbuffers(1, &rbo);
282
283 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
284 glFramebufferRenderbuffer(-1, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
285 expectError(GL_INVALID_ENUM);
286 m_log << TestLog::EndSection;
287
288 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if attachment is not an accepted attachment point.");
289 glFramebufferRenderbuffer(GL_FRAMEBUFFER, -1, GL_RENDERBUFFER, 0);
290 expectError(GL_INVALID_ENUM);
291 m_log << TestLog::EndSection;
292
293 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if renderbuffertarget is not GL_RENDERBUFFER.");
294 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
295 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, -1, rbo);
296 expectError(GL_INVALID_ENUM);
297 glBindRenderbuffer(GL_RENDERBUFFER, 0);
298 m_log << TestLog::EndSection;
299
300 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if renderbuffer is neither 0 nor the name of an existing renderbuffer object.");
301 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, -1);
302 expectError(GL_INVALID_OPERATION);
303 m_log << TestLog::EndSection;
304
305 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the default framebuffer object name 0 is bound.");
306 glBindFramebuffer(GL_FRAMEBUFFER, 0);
307 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
308 expectError(GL_INVALID_OPERATION);
309 m_log << TestLog::EndSection;
310
311 glDeleteRenderbuffers(1, &rbo);
312 glDeleteFramebuffers(1, &fbo);
313 });
314 ES2F_ADD_API_CASE(framebuffer_texture2d, "Invalid glFramebufferTexture2D() usage",
315 {
316 GLuint fbo;
317 GLuint tex2D;
318 GLuint texCube;
319 glGenFramebuffers(1, &fbo);
320 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
321 glGenTextures(1, &tex2D);
322 glBindTexture(GL_TEXTURE_2D, tex2D);
323 glGenTextures(1, &texCube);
324 glBindTexture(GL_TEXTURE_CUBE_MAP, texCube);
325 expectError(GL_NO_ERROR);
326
327 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
328 glFramebufferTexture2D(-1, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
329 expectError(GL_INVALID_ENUM);
330 m_log << TestLog::EndSection;
331
332 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if textarget is not an accepted texture target.");
333 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, -1, tex2D, 0);
334 expectError(GL_INVALID_ENUM);
335 m_log << TestLog::EndSection;
336
337 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if attachment is not an accepted attachment point.");
338 glFramebufferTexture2D(GL_FRAMEBUFFER, -1, GL_TEXTURE_2D, 0, 0);
339 expectError(GL_INVALID_ENUM);
340 m_log << TestLog::EndSection;
341
342 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if level is not 0.");
343 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex2D, 3);
344 expectError(GL_INVALID_VALUE);
345 m_log << TestLog::EndSection;
346
347 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if texture is neither 0 nor the name of an existing texture object.");
348 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, -1, 0);
349 expectError(GL_INVALID_OPERATION);
350 m_log << TestLog::EndSection;
351
352 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if texture is the name of an existing two-dimensional texture object but textarget is not GL_TEXTURE_2D.");
353
354 expectError(GL_NO_ERROR);
355 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, tex2D, 0);
356 expectError(GL_INVALID_OPERATION);
357 glDeleteTextures(1, &tex2D);
358 m_log << TestLog::EndSection;
359
360 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if texture is the name of an existing cube map texture object but textarget is GL_TEXTURE_2D.");
361 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texCube, 0);
362 expectError(GL_INVALID_OPERATION);
363 glDeleteTextures(1, &texCube);
364 m_log << TestLog::EndSection;
365
366 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the default framebuffer object name 0 is bound.");
367 glBindFramebuffer(GL_FRAMEBUFFER, 0);
368 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
369 expectError(GL_INVALID_OPERATION);
370 m_log << TestLog::EndSection;
371
372 glDeleteFramebuffers(1, &fbo);
373 });
374 ES2F_ADD_API_CASE(renderbuffer_storage, "Invalid glRenderbufferStorage() usage",
375 {
376 GLuint rbo;
377 glGenRenderbuffers(1, &rbo);
378 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
379
380 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_RENDERBUFFER.");
381 glRenderbufferStorage(-1, GL_RGBA4, 1, 1);
382 expectError(GL_INVALID_ENUM);
383 glRenderbufferStorage(GL_FRAMEBUFFER, GL_RGBA4, 1, 1);
384 expectError(GL_INVALID_ENUM);
385 m_log << TestLog::EndSection;
386
387 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if internalformat is not an accepted format.");
388 glRenderbufferStorage(GL_RENDERBUFFER, -1, 1, 1);
389 expectError(GL_INVALID_ENUM);
390 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 1, 1);
391 expectError(GL_INVALID_ENUM);
392 m_log << TestLog::EndSection;
393
394 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if width or height is less than zero.");
395 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, -1, 1);
396 expectError(GL_INVALID_VALUE);
397 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, -1);
398 expectError(GL_INVALID_VALUE);
399 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, -1, -1);
400 expectError(GL_INVALID_VALUE);
401 m_log << TestLog::EndSection;
402
403 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if width or height is greater than GL_MAX_RENDERBUFFER_SIZE.");
404 GLint maxSize;
405 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxSize);
406 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, maxSize+1);
407 expectError(GL_INVALID_VALUE);
408 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, maxSize+1, 1);
409 expectError(GL_INVALID_VALUE);
410 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, maxSize+1, maxSize+1);
411 expectError(GL_INVALID_VALUE);
412 m_log << TestLog::EndSection;
413
414 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the reserved renderbuffer object name 0 is bound.");
415 glBindRenderbuffer(GL_RENDERBUFFER, 0);
416 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
417 expectError(GL_INVALID_OPERATION);
418 m_log << TestLog::EndSection;
419
420 glDeleteRenderbuffers(1, &rbo);
421 });
422 }
423
424 } // Functional
425 } // gles2
426 } // deqp
427