1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Negative Vertex Array API tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fNegativeVertexArrayApiTests.hpp"
25 #include "es2fApiCase.hpp"
26 #include "gluShaderProgram.hpp"
27 #include "gluContextInfo.hpp"
30 #include "glwEnums.hpp"
31 #include "glwDefs.hpp"
33 using namespace glw; // GL types
42 static const char* vertexShaderSource = "void main (void) { gl_Position = vec4(0.0); }\n\0";
43 static const char* fragmentShaderSource = "void main (void) { gl_FragColor = vec4(0.0); }\n\0";
47 NegativeVertexArrayApiTests::NegativeVertexArrayApiTests (Context& context)
48 : TestCaseGroup(context, "vertex_array", "Negative Vertex Array API Cases")
52 NegativeVertexArrayApiTests::~NegativeVertexArrayApiTests (void)
56 void NegativeVertexArrayApiTests::init (void)
58 ES2F_ADD_API_CASE(vertex_attrib, "Invalid glVertexAttrib() usage",
60 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
61 int maxVertexAttribs = m_context.getContextInfo().getInt(GL_MAX_VERTEX_ATTRIBS);
62 glVertexAttrib1f(maxVertexAttribs, 0.0f);
63 expectError(GL_INVALID_VALUE);
64 glVertexAttrib2f(maxVertexAttribs, 0.0f, 0.0f);
65 expectError(GL_INVALID_VALUE);
66 glVertexAttrib3f(maxVertexAttribs, 0.0f, 0.0f, 0.0f);
67 expectError(GL_INVALID_VALUE);
68 glVertexAttrib4f(maxVertexAttribs, 0.0f, 0.0f, 0.0f, 0.0f);
69 expectError(GL_INVALID_VALUE);
70 m_log << tcu::TestLog::EndSection;
72 ES2F_ADD_API_CASE(vertex_attribv, "Invalid glVertexAttribv() usage",
74 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
75 int maxVertexAttribs = m_context.getContextInfo().getInt(GL_MAX_VERTEX_ATTRIBS);
77 glVertexAttrib1fv(maxVertexAttribs, &v[0]);
78 expectError(GL_INVALID_VALUE);
79 glVertexAttrib2fv(maxVertexAttribs, &v[0]);
80 expectError(GL_INVALID_VALUE);
81 glVertexAttrib3fv(maxVertexAttribs, &v[0]);
82 expectError(GL_INVALID_VALUE);
83 glVertexAttrib4fv(maxVertexAttribs, &v[0]);
84 expectError(GL_INVALID_VALUE);
85 m_log << tcu::TestLog::EndSection;
87 ES2F_ADD_API_CASE(vertex_attrib_pointer, "Invalid glVertexAttribPointer() usage",
89 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if type is not an accepted value.");
90 glVertexAttribPointer(0, 1, 0, GL_TRUE, 0, 0);
91 expectError(GL_INVALID_ENUM);
92 m_log << tcu::TestLog::EndSection;
94 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
95 int maxVertexAttribs = m_context.getContextInfo().getInt(GL_MAX_VERTEX_ATTRIBS);
96 glVertexAttribPointer(maxVertexAttribs, 1, GL_BYTE, GL_TRUE, 0, 0);
97 expectError(GL_INVALID_VALUE);
98 m_log << tcu::TestLog::EndSection;
100 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if size is not 1, 2, 3, or 4.");
101 glVertexAttribPointer(0, 0, GL_BYTE, GL_TRUE, 0, 0);
102 expectError(GL_INVALID_VALUE);
103 m_log << tcu::TestLog::EndSection;
105 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if stride is negative.");
106 glVertexAttribPointer(0, 1, GL_BYTE, GL_TRUE, -1, 0);
107 expectError(GL_INVALID_VALUE);
108 m_log << tcu::TestLog::EndSection;
110 ES2F_ADD_API_CASE(enable_vertex_attrib_array, "Invalid glEnableVertexAttribArray() usage",
112 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
113 int maxVertexAttribs = m_context.getContextInfo().getInt(GL_MAX_VERTEX_ATTRIBS);
114 glEnableVertexAttribArray(maxVertexAttribs);
115 expectError(GL_INVALID_VALUE);
116 m_log << tcu::TestLog::EndSection;
118 ES2F_ADD_API_CASE(disable_vertex_attrib_array, "Invalid glDisableVertexAttribArray() usage",
120 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
121 int maxVertexAttribs = m_context.getContextInfo().getInt(GL_MAX_VERTEX_ATTRIBS);
122 glDisableVertexAttribArray(maxVertexAttribs);
123 expectError(GL_INVALID_VALUE);
124 m_log << tcu::TestLog::EndSection;
126 ES2F_ADD_API_CASE(draw_arrays, "Invalid glDrawArrays() usage",
128 glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
129 glUseProgram(program.getProgram());
131 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
132 glDrawArrays(-1, 0, 1);
133 expectError(GL_INVALID_ENUM);
134 m_log << tcu::TestLog::EndSection;
136 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
137 glDrawArrays(GL_POINTS, 0, -1);
138 expectError(GL_INVALID_VALUE);
139 m_log << tcu::TestLog::EndSection;
141 m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
143 glGenFramebuffers(1, &fbo);
144 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
145 glCheckFramebufferStatus(GL_FRAMEBUFFER);
146 glDrawArrays(GL_POINTS, 0, 1);
147 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
148 glBindFramebuffer(GL_FRAMEBUFFER, 0);
149 glDeleteFramebuffers(1, &fbo);
150 m_log << tcu::TestLog::EndSection;
154 ES2F_ADD_API_CASE(draw_arrays_invalid_program, "Invalid glDrawArrays() usage",
158 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
159 glDrawArrays(-1, 0, 1);
160 expectError(GL_INVALID_ENUM);
161 m_log << tcu::TestLog::EndSection;
163 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
164 glDrawArrays(GL_POINTS, 0, -1);
165 expectError(GL_INVALID_VALUE);
166 m_log << tcu::TestLog::EndSection;
168 m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
170 glGenFramebuffers(1, &fbo);
171 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
172 glCheckFramebufferStatus(GL_FRAMEBUFFER);
173 glDrawArrays(GL_POINTS, 0, 1);
174 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
175 glBindFramebuffer(GL_FRAMEBUFFER, 0);
176 glDeleteFramebuffers(1, &fbo);
177 m_log << tcu::TestLog::EndSection;
179 ES2F_ADD_API_CASE(draw_arrays_incomplete_primitive, "Invalid glDrawArrays() usage",
181 glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
182 glUseProgram(program.getProgram());
184 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
185 glDrawArrays(-1, 0, 1);
186 expectError(GL_INVALID_ENUM);
187 m_log << tcu::TestLog::EndSection;
189 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
190 glDrawArrays(GL_TRIANGLES, 0, -1);
191 expectError(GL_INVALID_VALUE);
192 m_log << tcu::TestLog::EndSection;
194 m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
196 glGenFramebuffers(1, &fbo);
197 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
198 glCheckFramebufferStatus(GL_FRAMEBUFFER);
199 glDrawArrays(GL_TRIANGLES, 0, 1);
200 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
201 glBindFramebuffer(GL_FRAMEBUFFER, 0);
202 glDeleteFramebuffers(1, &fbo);
203 m_log << tcu::TestLog::EndSection;
207 ES2F_ADD_API_CASE(draw_elements, "Invalid glDrawElements() usage",
209 glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
210 glUseProgram(program.getProgram());
211 GLfloat vertices[1] = { 0.0f };
213 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
214 glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
215 expectError(GL_INVALID_ENUM);
216 m_log << tcu::TestLog::EndSection;
218 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.");
219 glDrawElements(GL_POINTS, 1, -1, vertices);
220 expectError(GL_INVALID_ENUM);
221 m_log << tcu::TestLog::EndSection;
223 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
224 glDrawElements(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices);
225 expectError(GL_INVALID_VALUE);
226 m_log << tcu::TestLog::EndSection;
228 m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
230 glGenFramebuffers(1, &fbo);
231 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
232 glCheckFramebufferStatus(GL_FRAMEBUFFER);
233 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
234 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
235 glBindFramebuffer(GL_FRAMEBUFFER, 0);
236 glDeleteFramebuffers(1, &fbo);
237 m_log << tcu::TestLog::EndSection;
241 ES2F_ADD_API_CASE(draw_elements_invalid_program, "Invalid glDrawElements() usage",
244 GLfloat vertices[1] = { 0.0f };
246 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
247 glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
248 expectError(GL_INVALID_ENUM);
249 m_log << tcu::TestLog::EndSection;
251 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.");
252 glDrawElements(GL_POINTS, 1, -1, vertices);
253 expectError(GL_INVALID_ENUM);
254 m_log << tcu::TestLog::EndSection;
256 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
257 glDrawElements(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices);
258 expectError(GL_INVALID_VALUE);
259 m_log << tcu::TestLog::EndSection;
261 m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
263 glGenFramebuffers(1, &fbo);
264 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
265 glCheckFramebufferStatus(GL_FRAMEBUFFER);
266 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
267 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
268 glBindFramebuffer(GL_FRAMEBUFFER, 0);
269 glDeleteFramebuffers(1, &fbo);
270 m_log << tcu::TestLog::EndSection;
272 ES2F_ADD_API_CASE(draw_elements_incomplete_primitive, "Invalid glDrawElements() usage",
274 glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
275 glUseProgram(program.getProgram());
276 GLfloat vertices[1] = { 0.0f };
278 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
279 glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
280 expectError(GL_INVALID_ENUM);
281 m_log << tcu::TestLog::EndSection;
283 m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.");
284 glDrawElements(GL_TRIANGLES, 1, -1, vertices);
285 expectError(GL_INVALID_ENUM);
286 m_log << tcu::TestLog::EndSection;
288 m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
289 glDrawElements(GL_TRIANGLES, -1, GL_UNSIGNED_BYTE, vertices);
290 expectError(GL_INVALID_VALUE);
291 m_log << tcu::TestLog::EndSection;
293 m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
295 glGenFramebuffers(1, &fbo);
296 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
297 glCheckFramebufferStatus(GL_FRAMEBUFFER);
298 glDrawElements(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices);
299 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
300 glBindFramebuffer(GL_FRAMEBUFFER, 0);
301 glDeleteFramebuffers(1, &fbo);
302 m_log << tcu::TestLog::EndSection;