Add new framebuffer fetch extension tests am: 2a609fb223
[platform/upstream/VK-GL-CTS.git] / modules / gles2 / functional / es2fNegativeVertexArrayApiTests.cpp
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
47 NegativeVertexArrayApiTests::NegativeVertexArrayApiTests (Context& context)
48         : TestCaseGroup(context, "vertex_array", "Negative Vertex Array API Cases")
49 {
50 }
51
52 NegativeVertexArrayApiTests::~NegativeVertexArrayApiTests (void)
53 {
54 }
55
56 void NegativeVertexArrayApiTests::init (void)
57 {
58         ES2F_ADD_API_CASE(vertex_attrib, "Invalid glVertexAttrib() usage",
59                 {
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;
71                 });
72         ES2F_ADD_API_CASE(vertex_attribv, "Invalid glVertexAttribv() usage",
73                 {
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);
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                 {
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;
93
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;
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                 {
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;
117                 });
118         ES2F_ADD_API_CASE(disable_vertex_attrib_array, "Invalid glDisableVertexAttribArray() usage",
119                 {
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;
125                 });
126         ES2F_ADD_API_CASE(draw_arrays, "Invalid glDrawArrays() usage",
127                 {
128                         glu::ShaderProgram program(m_context.getRenderContext(), 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 framebuffer is not framebuffer complete.");
142                         GLuint fbo;
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;
151
152                         glUseProgram(0);
153                 });
154         ES2F_ADD_API_CASE(draw_arrays_invalid_program, "Invalid glDrawArrays() usage",
155                 {
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 framebuffer is not framebuffer complete.");
169                         GLuint fbo;
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;
178                 });
179         ES2F_ADD_API_CASE(draw_arrays_incomplete_primitive, "Invalid glDrawArrays() usage",
180                 {
181                         glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
182                         glUseProgram(program.getProgram());
183
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;
188
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;
193
194                         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
195                         GLuint fbo;
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;
204
205                         glUseProgram(0);
206                 });
207         ES2F_ADD_API_CASE(draw_elements, "Invalid glDrawElements() usage",
208                 {
209                         glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
210                         glUseProgram(program.getProgram());
211                         GLfloat vertices[1] = { 0.0f };
212
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;
217
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;
222
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;
227
228                         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
229                         GLuint fbo;
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;
238
239                         glUseProgram(0);
240                 });
241         ES2F_ADD_API_CASE(draw_elements_invalid_program, "Invalid glDrawElements() usage",
242                 {
243                         glUseProgram(0);
244                         GLfloat vertices[1] = { 0.0f };
245
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;
250
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;
255
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;
260
261                         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
262                         GLuint fbo;
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;
271                 });
272         ES2F_ADD_API_CASE(draw_elements_incomplete_primitive, "Invalid glDrawElements() usage",
273                 {
274                         glu::ShaderProgram program(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
275                         glUseProgram(program.getProgram());
276                         GLfloat vertices[1] = { 0.0f };
277
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;
282
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;
287
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;
292
293                         m_log << tcu::TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
294                         GLuint fbo;
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;
303
304                         glUseProgram(0);
305                 });
306 }
307
308 } // Functional
309 } // gles2
310 } // deqp