xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fNegativeVertexArrayApiTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 Vertex Array API tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es2fNegativeVertexArrayApiTests.hpp"
25 #include "es2fApiCase.hpp"
26 #include "gluShaderProgram.hpp"
27 #include "gluContextInfo.hpp"
28 #include "deString.h"
29 
30 #include "glwEnums.hpp"
31 #include "glwDefs.hpp"
32 
33 using namespace glw; // GL types
34 
35 namespace deqp
36 {
37 namespace gles2
38 {
39 namespace Functional
40 {
41 
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";
44 
45 using tcu::TestLog;
46 
NegativeVertexArrayApiTests(Context & context)47 NegativeVertexArrayApiTests::NegativeVertexArrayApiTests(Context &context)
48     : TestCaseGroup(context, "vertex_array", "Negative Vertex Array API Cases")
49 {
50 }
51 
~NegativeVertexArrayApiTests(void)52 NegativeVertexArrayApiTests::~NegativeVertexArrayApiTests(void)
53 {
54 }
55 
init(void)56 void NegativeVertexArrayApiTests::init(void)
57 {
58     ES2F_ADD_API_CASE(vertex_attrib, "Invalid glVertexAttrib() usage", {
59         m_log << tcu::TestLog::Section(
60             "", "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;
71     });
72     ES2F_ADD_API_CASE(vertex_attribv, "Invalid glVertexAttribv() usage", {
73         m_log << tcu::TestLog::Section(
74             "", "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);
76         float v[4]           = {0.0f};
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;
86     });
87     ES2F_ADD_API_CASE(vertex_attrib_pointer, "Invalid glVertexAttribPointer() usage", {
88         m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if type is not an accepted value.");
89         glVertexAttribPointer(0, 1, 0, GL_TRUE, 0, 0);
90         expectError(GL_INVALID_ENUM);
91         m_log << tcu::TestLog::EndSection;
92 
93         m_log << tcu::TestLog::Section(
94             "", "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;
99 
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;
104 
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;
109     });
110     ES2F_ADD_API_CASE(enable_vertex_attrib_array, "Invalid glEnableVertexAttribArray() usage", {
111         m_log << tcu::TestLog::Section(
112             "", "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;
117     });
118     ES2F_ADD_API_CASE(disable_vertex_attrib_array, "Invalid glDisableVertexAttribArray() usage", {
119         m_log << tcu::TestLog::Section(
120             "", "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;
125     });
126     ES2F_ADD_API_CASE(draw_arrays, "Invalid glDrawArrays() usage", {
127         glu::ShaderProgram program(m_context.getRenderContext(),
128                                    glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
129         glUseProgram(program.getProgram());
130 
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;
135 
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;
140 
141         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound "
142                                            "framebuffer is not framebuffer complete.");
143         GLuint fbo;
144         glGenFramebuffers(1, &fbo);
145         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
146         glCheckFramebufferStatus(GL_FRAMEBUFFER);
147         glDrawArrays(GL_POINTS, 0, 1);
148         expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
149         glBindFramebuffer(GL_FRAMEBUFFER, 0);
150         glDeleteFramebuffers(1, &fbo);
151         m_log << tcu::TestLog::EndSection;
152 
153         glUseProgram(0);
154     });
155     ES2F_ADD_API_CASE(draw_arrays_invalid_program, "Invalid glDrawArrays() usage", {
156         glUseProgram(0);
157 
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;
162 
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;
167 
168         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound "
169                                            "framebuffer is not framebuffer complete.");
170         GLuint fbo;
171         glGenFramebuffers(1, &fbo);
172         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
173         glCheckFramebufferStatus(GL_FRAMEBUFFER);
174         glDrawArrays(GL_POINTS, 0, 1);
175         expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
176         glBindFramebuffer(GL_FRAMEBUFFER, 0);
177         glDeleteFramebuffers(1, &fbo);
178         m_log << tcu::TestLog::EndSection;
179     });
180     ES2F_ADD_API_CASE(draw_arrays_incomplete_primitive, "Invalid glDrawArrays() usage", {
181         glu::ShaderProgram program(m_context.getRenderContext(),
182                                    glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
183         glUseProgram(program.getProgram());
184 
185         m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
186         glDrawArrays(-1, 0, 1);
187         expectError(GL_INVALID_ENUM);
188         m_log << tcu::TestLog::EndSection;
189 
190         m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
191         glDrawArrays(GL_TRIANGLES, 0, -1);
192         expectError(GL_INVALID_VALUE);
193         m_log << tcu::TestLog::EndSection;
194 
195         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound "
196                                            "framebuffer is not framebuffer complete.");
197         GLuint fbo;
198         glGenFramebuffers(1, &fbo);
199         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
200         glCheckFramebufferStatus(GL_FRAMEBUFFER);
201         glDrawArrays(GL_TRIANGLES, 0, 1);
202         expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
203         glBindFramebuffer(GL_FRAMEBUFFER, 0);
204         glDeleteFramebuffers(1, &fbo);
205         m_log << tcu::TestLog::EndSection;
206 
207         glUseProgram(0);
208     });
209     ES2F_ADD_API_CASE(draw_elements, "Invalid glDrawElements() usage", {
210         glu::ShaderProgram program(m_context.getRenderContext(),
211                                    glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
212         glUseProgram(program.getProgram());
213         GLfloat vertices[1] = {0.0f};
214 
215         m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
216         glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
217         expectError(GL_INVALID_ENUM);
218         m_log << tcu::TestLog::EndSection;
219 
220         m_log << tcu::TestLog::Section(
221             "", "GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.");
222         glDrawElements(GL_POINTS, 1, -1, vertices);
223         expectError(GL_INVALID_ENUM);
224         m_log << tcu::TestLog::EndSection;
225 
226         m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
227         glDrawElements(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices);
228         expectError(GL_INVALID_VALUE);
229         m_log << tcu::TestLog::EndSection;
230 
231         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound "
232                                            "framebuffer is not framebuffer complete.");
233         GLuint fbo;
234         glGenFramebuffers(1, &fbo);
235         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
236         glCheckFramebufferStatus(GL_FRAMEBUFFER);
237         glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
238         expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
239         glBindFramebuffer(GL_FRAMEBUFFER, 0);
240         glDeleteFramebuffers(1, &fbo);
241         m_log << tcu::TestLog::EndSection;
242 
243         glUseProgram(0);
244     });
245     ES2F_ADD_API_CASE(draw_elements_invalid_program, "Invalid glDrawElements() usage", {
246         glUseProgram(0);
247         GLfloat vertices[1] = {0.0f};
248 
249         m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
250         glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
251         expectError(GL_INVALID_ENUM);
252         m_log << tcu::TestLog::EndSection;
253 
254         m_log << tcu::TestLog::Section(
255             "", "GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.");
256         glDrawElements(GL_POINTS, 1, -1, vertices);
257         expectError(GL_INVALID_ENUM);
258         m_log << tcu::TestLog::EndSection;
259 
260         m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
261         glDrawElements(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices);
262         expectError(GL_INVALID_VALUE);
263         m_log << tcu::TestLog::EndSection;
264 
265         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound "
266                                            "framebuffer is not framebuffer complete.");
267         GLuint fbo;
268         glGenFramebuffers(1, &fbo);
269         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
270         glCheckFramebufferStatus(GL_FRAMEBUFFER);
271         glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
272         expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
273         glBindFramebuffer(GL_FRAMEBUFFER, 0);
274         glDeleteFramebuffers(1, &fbo);
275         m_log << tcu::TestLog::EndSection;
276     });
277     ES2F_ADD_API_CASE(draw_elements_incomplete_primitive, "Invalid glDrawElements() usage", {
278         glu::ShaderProgram program(m_context.getRenderContext(),
279                                    glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
280         glUseProgram(program.getProgram());
281         GLfloat vertices[1] = {0.0f};
282 
283         m_log << tcu::TestLog::Section("", "GL_INVALID_ENUM is generated if mode is not an accepted value.");
284         glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
285         expectError(GL_INVALID_ENUM);
286         m_log << tcu::TestLog::EndSection;
287 
288         m_log << tcu::TestLog::Section(
289             "", "GL_INVALID_ENUM is generated if type is not GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.");
290         glDrawElements(GL_TRIANGLES, 1, -1, vertices);
291         expectError(GL_INVALID_ENUM);
292         m_log << tcu::TestLog::EndSection;
293 
294         m_log << tcu::TestLog::Section("", "GL_INVALID_VALUE is generated if count is negative.");
295         glDrawElements(GL_TRIANGLES, -1, GL_UNSIGNED_BYTE, vertices);
296         expectError(GL_INVALID_VALUE);
297         m_log << tcu::TestLog::EndSection;
298 
299         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound "
300                                            "framebuffer is not framebuffer complete.");
301         GLuint fbo;
302         glGenFramebuffers(1, &fbo);
303         glBindFramebuffer(GL_FRAMEBUFFER, fbo);
304         glCheckFramebufferStatus(GL_FRAMEBUFFER);
305         glDrawElements(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices);
306         expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
307         glBindFramebuffer(GL_FRAMEBUFFER, 0);
308         glDeleteFramebuffers(1, &fbo);
309         m_log << tcu::TestLog::EndSection;
310 
311         glUseProgram(0);
312     });
313 }
314 
315 } // namespace Functional
316 } // namespace gles2
317 } // namespace deqp
318