d6eb2675909c825d398cb43b45270beea0500587
[platform/upstream/VK-GL-CTS.git] / modules / egl / teglNegativeApiTests.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL 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 API Tests.
22  *//*--------------------------------------------------------------------*/
23
24 #include "teglNegativeApiTests.hpp"
25 #include "teglApiCase.hpp"
26
27 #include "egluNativeDisplay.hpp"
28 #include "egluNativeWindow.hpp"
29 #include "egluUtil.hpp"
30 #include "egluUnique.hpp"
31
32 #include <memory>
33
34 using tcu::TestLog;
35
36 namespace deqp
37 {
38 namespace egl
39 {
40
41 using namespace eglw;
42
43 template <deUint32 Type>
44 static bool renderable (const eglu::CandidateConfig& c)
45 {
46         return (c.renderableType() & Type) == Type;
47 }
48
49 template <deUint32 Type>
50 static bool notRenderable (const eglu::CandidateConfig& c)
51 {
52         return (c.renderableType() & Type) == 0;
53 }
54
55 template <deUint32 Bits>
56 static bool surfaceBits (const eglu::CandidateConfig& c)
57 {
58         return (c.surfaceType() & Bits) == Bits;
59 }
60
61 template <deUint32 Bits>
62 static bool notSurfaceBits (const eglu::CandidateConfig& c)
63 {
64         return (c.surfaceType() & Bits) == 0;
65 }
66
67 NegativeApiTests::NegativeApiTests (EglTestContext& eglTestCtx)
68         : TestCaseGroup(eglTestCtx, "negative_api", "Negative API Tests")
69 {
70 }
71
72 NegativeApiTests::~NegativeApiTests (void)
73 {
74 }
75
76 void NegativeApiTests::init (void)
77 {
78         // \todo [2012-10-02 pyry] Add tests for EGL_NOT_INITIALIZED to all functions taking in EGLDisplay
79         // \todo [2012-10-02 pyry] Implement negative cases for following non-trivial cases:
80         //  * eglBindTexImage()
81         //    - EGL_BAD_ACCESS is generated if buffer is already bound to a texture
82         //    - EGL_BAD_MATCH is generated if the surface attribute EGL_TEXTURE_FORMAT is set to EGL_NO_TEXTURE
83         //    - EGL_BAD_MATCH is generated if buffer is not a valid buffer (currently only EGL_BACK_BUFFER may be specified)
84         //    - EGL_BAD_SURFACE is generated if surface is not a pbuffer surface supporting texture binding
85         //  * eglCopyBuffers()
86         //    - EGL_BAD_NATIVE_PIXMAP is generated if the implementation does not support native pixmaps
87         //    - EGL_BAD_NATIVE_PIXMAP may be generated if native_pixmap is not a valid native pixmap
88         //    - EGL_BAD_MATCH is generated if the format of native_pixmap is not compatible with the color buffer of surface
89         //  * eglCreateContext()
90         //    - EGL_BAD_MATCH is generated if the current rendering API is EGL_NONE
91         //        - EGL_BAD_MATCH is generated if the server context state for share_context exists in an address space which cannot be shared with the newly created context
92         //        - EGL_BAD_CONTEXT is generated if share_context is not an EGL rendering context of the same client API type as the newly created context and is not EGL_NO_CONTEXT
93         //  * eglCreatePbufferFromClientBuffer()
94         //    - various BAD_MATCH, BAD_ACCESS etc. conditions
95         //  * eglCreatePbufferSurface()
96         //    - EGL_BAD_MATCH is generated if the EGL_TEXTURE_FORMAT attribute is not EGL_NO_TEXTURE, and EGL_WIDTH and/or EGL_HEIGHT specify an invalid size
97         //  * eglCreatePixmapSurface()
98         //    - EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid pixmap attribute
99         //    - EGL_BAD_MATCH is generated if the attributes of native_pixmap do not correspond to config or if config does not support rendering to pixmaps
100         //    - EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute or colorspace attribute
101         //  * eglCreateWindowSurface()
102         //    - EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid window attribute
103         //    - EGL_BAD_MATCH is generated if the attributes of native_window do not correspond to config or if config does not support rendering to windows
104         //    - EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute or colorspace attribute
105         //  * eglMakeCurrent()
106         //    - EGL_BAD_MATCH is generated if draw or read are not compatible with context
107         //    - EGL_BAD_MATCH is generated if context is set to EGL_NO_CONTEXT and draw or read are not set to EGL_NO_SURFACE
108         //    - EGL_BAD_MATCH is generated if draw or read are set to EGL_NO_SURFACE and context is not set to EGL_NO_CONTEXT
109         //    - EGL_BAD_ACCESS is generated if context is current to some other thread
110         //    - EGL_BAD_NATIVE_PIXMAP may be generated if a native pixmap underlying either draw or read is no longer valid
111         //    - EGL_BAD_NATIVE_WINDOW may be generated if a native window underlying either draw or read is no longer valid
112         //  * eglReleaseTexImage()
113         //    - EGL_BAD_MATCH is generated if buffer is not a valid buffer (currently only EGL_BACK_BUFFER may be specified)
114         //  * eglSwapInterval()
115         //    - EGL_BAD_SURFACE is generated if there is no surface bound to the current context
116         //  * eglWaitNative()
117         //    - EGL_BAD_CURRENT_SURFACE is generated if the surface associated with the current context has a native window or pixmap, and that window or pixmap is no longer valid
118
119         using namespace eglw;
120         using namespace eglu;
121
122         static const EGLint s_emptyAttribList[]                 = { EGL_NONE };
123         static const EGLint s_es1ContextAttribList[]    = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
124         static const EGLint s_es2ContextAttribList[]    = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
125
126         static const EGLenum s_renderAPIs[]                             = { EGL_OPENGL_API, EGL_OPENGL_ES_API, EGL_OPENVG_API };
127
128         TEGL_ADD_API_CASE(bind_api, "eglBindAPI() negative tests",
129                 {
130                         TestLog& log = m_testCtx.getLog();
131                         log << TestLog::Section("Test1", "EGL_BAD_PARAMETER is generated if api is not one of the accepted tokens");
132
133                         expectFalse(eglBindAPI(0));
134                         expectError(EGL_BAD_PARAMETER);
135
136                         expectFalse(eglBindAPI(0xfdfdfdfd));
137                         expectError(EGL_BAD_PARAMETER);
138
139                         expectFalse(eglBindAPI((EGLenum)0xffffffff));
140                         expectError(EGL_BAD_PARAMETER);
141
142                         log << TestLog::EndSection;
143
144                         log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if the specified client API is not supported by the EGL implementation");
145
146                         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderAPIs); ndx++)
147                         {
148                                 if (!isAPISupported(s_renderAPIs[ndx]))
149                                 {
150                                         expectFalse(eglBindAPI(s_renderAPIs[ndx]));
151                                         expectError(EGL_BAD_PARAMETER);
152                                 }
153                         }
154
155                         log << TestLog::EndSection;
156                 });
157
158         TEGL_ADD_API_CASE(bind_tex_image, "eglBindTexImage() negative tests",
159                 {
160                         TestLog&        log                     = m_testCtx.getLog();
161                         EGLDisplay      display         = getDisplay();
162
163                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
164
165                         expectFalse(eglBindTexImage(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_BACK_BUFFER));
166                         expectError(EGL_BAD_DISPLAY);
167
168                         expectFalse(eglBindTexImage((EGLDisplay)-1, EGL_NO_SURFACE, EGL_BACK_BUFFER));
169                         expectError(EGL_BAD_DISPLAY);
170
171                         log << TestLog::EndSection;
172
173                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
174
175                         expectFalse(eglBindTexImage(display, EGL_NO_SURFACE, EGL_BACK_BUFFER));
176                         expectError(EGL_BAD_SURFACE);
177
178                         expectFalse(eglBindTexImage(display, (EGLSurface)-1, EGL_BACK_BUFFER));
179                         expectError(EGL_BAD_SURFACE);
180
181                         log << TestLog::EndSection;
182                 });
183
184         TEGL_ADD_API_CASE(copy_buffers, "eglCopyBuffers() negative tests",
185                 {
186                         TestLog&        log                     = m_testCtx.getLog();
187                         EGLDisplay      display         = getDisplay();
188
189                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
190
191                         expectFalse(eglCopyBuffers(EGL_NO_DISPLAY, EGL_NO_SURFACE, (EGLNativePixmapType)0));
192                         expectError(EGL_BAD_DISPLAY);
193
194                         expectFalse(eglCopyBuffers((EGLDisplay)-1, EGL_NO_SURFACE, (EGLNativePixmapType)0));
195                         expectError(EGL_BAD_DISPLAY);
196
197                         log << TestLog::EndSection;
198
199                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
200
201                         expectFalse(eglCopyBuffers(display, EGL_NO_SURFACE, (EGLNativePixmapType)0));
202                         expectError(EGL_BAD_SURFACE);
203
204                         expectFalse(eglCopyBuffers(display, (EGLSurface)-1, (EGLNativePixmapType)0));
205                         expectError(EGL_BAD_SURFACE);
206
207                         log << TestLog::EndSection;
208                 });
209
210         static const EGLint s_invalidChooseConfigAttribList0[]  = { 0, EGL_NONE };
211         static const EGLint s_invalidChooseConfigAttribList1[]  = { (EGLint)0xffffffff };
212         static const EGLint s_invalidChooseConfigAttribList2[]  = { EGL_BIND_TO_TEXTURE_RGB, 4, EGL_NONE };
213         static const EGLint s_invalidChooseConfigAttribList3[]  = { EGL_BIND_TO_TEXTURE_RGBA, 5, EGL_NONE };
214         static const EGLint s_invalidChooseConfigAttribList4[]  = { EGL_COLOR_BUFFER_TYPE, 0, EGL_NONE };
215         static const EGLint s_invalidChooseConfigAttribList5[]  = { EGL_MATCH_NATIVE_PIXMAP, -1, EGL_NONE };
216         static const EGLint s_invalidChooseConfigAttribList6[]  = { EGL_NATIVE_RENDERABLE, 6, EGL_NONE };
217         static const EGLint s_invalidChooseConfigAttribList7[]  = { EGL_TRANSPARENT_TYPE, 6, EGL_NONE };
218         static const EGLint* s_invalidChooseConfigAttribLists[] =
219         {
220                 &s_invalidChooseConfigAttribList0[0],
221                 &s_invalidChooseConfigAttribList1[0],
222                 &s_invalidChooseConfigAttribList2[0],
223                 &s_invalidChooseConfigAttribList3[0],
224                 &s_invalidChooseConfigAttribList4[0],
225                 &s_invalidChooseConfigAttribList5[0],
226                 &s_invalidChooseConfigAttribList6[0],
227                 &s_invalidChooseConfigAttribList7[0]
228         };
229
230         TEGL_ADD_API_CASE(choose_config, "eglChooseConfig() negative tests",
231                 {
232                         TestLog&        log                     = m_testCtx.getLog();
233                         EGLDisplay      display         = getDisplay();
234                         EGLConfig       configs[1];
235                         EGLint          numConfigs;
236
237                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
238
239                         expectFalse(eglChooseConfig(EGL_NO_DISPLAY, s_emptyAttribList, &configs[0], DE_LENGTH_OF_ARRAY(configs), &numConfigs));
240                         expectError(EGL_BAD_DISPLAY);
241
242                         expectFalse(eglChooseConfig((EGLDisplay)-1, s_emptyAttribList, &configs[0], DE_LENGTH_OF_ARRAY(configs), &numConfigs));
243                         expectError(EGL_BAD_DISPLAY);
244
245                         log << TestLog::EndSection;
246
247                         log << TestLog::Section("Test2", "EGL_BAD_ATTRIBUTE is generated if attribute_list contains an invalid frame buffer configuration attribute");
248
249                         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidChooseConfigAttribLists); ndx++)
250                         {
251                                 expectFalse(eglChooseConfig(display, s_invalidChooseConfigAttribLists[ndx], &configs[0], DE_LENGTH_OF_ARRAY(configs), &numConfigs));
252                                 expectError(EGL_BAD_ATTRIBUTE);
253                         }
254
255                         log << TestLog::EndSection;
256
257                         log << TestLog::Section("Test3", "EGL_BAD_PARAMETER is generated if num_config is NULL");
258
259                         expectFalse(eglChooseConfig(display, s_emptyAttribList, &configs[0], DE_LENGTH_OF_ARRAY(configs), DE_NULL));
260                         expectError(EGL_BAD_PARAMETER);
261
262                         log << TestLog::EndSection;
263                 });
264
265         static const EGLint s_invalidCreateContextAttribList0[] = { 0, EGL_NONE };
266         static const EGLint s_invalidCreateContextAttribList1[] = { (EGLint)0xffffffff };
267
268         TEGL_ADD_API_CASE(create_context, "eglCreateContext() negative tests",
269                 {
270                         TestLog&        log                     = m_testCtx.getLog();
271                         EGLDisplay      display         = getDisplay();
272
273                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
274
275                         expectNoContext(eglCreateContext(EGL_NO_DISPLAY, DE_NULL, EGL_NO_CONTEXT, s_emptyAttribList));
276                         expectError(EGL_BAD_DISPLAY);
277
278                         expectNoContext(eglCreateContext((EGLDisplay)-1, DE_NULL, EGL_NO_CONTEXT, s_emptyAttribList));
279                         expectError(EGL_BAD_DISPLAY);
280
281                         log << TestLog::EndSection;
282
283                         log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
284
285                         expectNoContext(eglCreateContext(display, (EGLConfig)-1, EGL_NO_CONTEXT, s_emptyAttribList));
286                         expectError(EGL_BAD_CONFIG);
287
288                         log << TestLog::EndSection;
289
290                         log << TestLog::Section("Test3", "EGL_BAD_CONFIG is generated if config does not support the current rendering API");
291
292                         if (isAPISupported(EGL_OPENGL_API))
293                         {
294                                 EGLConfig es1OnlyConfig;
295                                 if (getConfig(&es1OnlyConfig, FilterList() << renderable<EGL_OPENGL_ES_BIT> << notRenderable<EGL_OPENGL_BIT>))
296                                 {
297                                         expectTrue(eglBindAPI(EGL_OPENGL_API));
298                                         expectNoContext(eglCreateContext(display, es1OnlyConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
299                                         expectError(EGL_BAD_CONFIG);
300                                 }
301
302                                 EGLConfig es2OnlyConfig;
303                                 if (getConfig(&es2OnlyConfig, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << notRenderable<EGL_OPENGL_BIT>))
304                                 {
305                                         expectTrue(eglBindAPI(EGL_OPENGL_API));
306                                         expectNoContext(eglCreateContext(display, es2OnlyConfig, EGL_NO_CONTEXT, s_es2ContextAttribList));
307                                         expectError(EGL_BAD_CONFIG);
308                                 }
309
310                                 EGLConfig vgOnlyConfig;
311                                 if (getConfig(&vgOnlyConfig, FilterList() << renderable<EGL_OPENVG_BIT> << notRenderable<EGL_OPENGL_BIT>))
312                                 {
313                                         expectTrue(eglBindAPI(EGL_OPENGL_API));
314                                         expectNoContext(eglCreateContext(display, vgOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
315                                         expectError(EGL_BAD_CONFIG);
316                                 }
317                         }
318
319                         if (isAPISupported(EGL_OPENGL_ES_API))
320                         {
321                                 EGLConfig glOnlyConfig;
322                                 if (getConfig(&glOnlyConfig, FilterList() << renderable<EGL_OPENGL_BIT> << notRenderable<EGL_OPENGL_ES_BIT|EGL_OPENGL_ES2_BIT>))
323                                 {
324                                         expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
325                                         expectNoContext(eglCreateContext(display, glOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
326                                         expectError(EGL_BAD_CONFIG);
327                                 }
328
329                                 EGLConfig vgOnlyConfig;
330                                 if (getConfig(&vgOnlyConfig, FilterList() << renderable<EGL_OPENVG_BIT> << notRenderable<EGL_OPENGL_ES_BIT|EGL_OPENGL_ES2_BIT>))
331                                 {
332                                         expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
333                                         expectNoContext(eglCreateContext(display, vgOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
334                                         expectError(EGL_BAD_CONFIG);
335                                 }
336                         }
337
338                         if (isAPISupported(EGL_OPENVG_API))
339                         {
340                                 EGLConfig glOnlyConfig;
341                                 if (getConfig(&glOnlyConfig, FilterList() << renderable<EGL_OPENGL_BIT> << notRenderable<EGL_OPENVG_BIT>))
342                                 {
343                                         expectTrue(eglBindAPI(EGL_OPENVG_API));
344                                         expectNoContext(eglCreateContext(display, glOnlyConfig, EGL_NO_CONTEXT, s_emptyAttribList));
345                                         expectError(EGL_BAD_CONFIG);
346                                 }
347
348                                 EGLConfig es1OnlyConfig;
349                                 if (getConfig(&es1OnlyConfig, FilterList() << renderable<EGL_OPENGL_ES_BIT> << notRenderable<EGL_OPENVG_BIT>))
350                                 {
351                                         expectTrue(eglBindAPI(EGL_OPENVG_API));
352                                         expectNoContext(eglCreateContext(display, es1OnlyConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
353                                         expectError(EGL_BAD_CONFIG);
354                                 }
355
356                                 EGLConfig es2OnlyConfig;
357                                 if (getConfig(&es2OnlyConfig, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << notRenderable<EGL_OPENVG_BIT>))
358                                 {
359                                         expectTrue(eglBindAPI(EGL_OPENVG_API));
360                                         expectNoContext(eglCreateContext(display, es2OnlyConfig, EGL_NO_CONTEXT, s_es2ContextAttribList));
361                                         expectError(EGL_BAD_CONFIG);
362                                 }
363                         }
364
365                         log << TestLog::EndSection;
366
367                         log << TestLog::Section("Test4", "EGL_BAD_CONFIG is generated if OpenGL ES 1.x context is requested and EGL_RENDERABLE_TYPE attribute of config does not contain EGL_OPENGL_ES_BIT");
368
369                         if (isAPISupported(EGL_OPENGL_ES_API))
370                         {
371                                 EGLConfig notES1Config;
372                                 if (getConfig(&notES1Config, FilterList() << notRenderable<EGL_OPENGL_ES_BIT>))
373                                 {
374                                         expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
375                                         expectNoContext(eglCreateContext(display, notES1Config, EGL_NO_CONTEXT, s_es1ContextAttribList));
376                                         expectError(EGL_BAD_CONFIG);
377                                 }
378                         }
379
380                         log << TestLog::EndSection;
381
382                         log << TestLog::Section("Test5", "EGL_BAD_CONFIG is generated if OpenGL ES 2.x context is requested and EGL_RENDERABLE_TYPE attribute of config does not contain EGL_OPENGL_ES2_BIT");
383
384                         if (isAPISupported(EGL_OPENGL_ES_API))
385                         {
386                                 EGLConfig notES2Config;
387                                 if (getConfig(&notES2Config, FilterList() << notRenderable<EGL_OPENGL_ES2_BIT>))
388                                 {
389                                         expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
390                                         expectNoContext(eglCreateContext(display, notES2Config, EGL_NO_CONTEXT, s_es2ContextAttribList));
391                                         expectError(EGL_BAD_CONFIG);
392                                 }
393                         }
394
395                         log << TestLog::EndSection;
396
397                         log << TestLog::Section("Test6", "EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid context attribute");
398
399                         if (isAPISupported(EGL_OPENGL_API))
400                         {
401                                 EGLConfig glConfig;
402                                 if (getConfig(&glConfig, FilterList() << renderable<EGL_OPENGL_BIT>))
403                                 {
404                                         expectTrue(eglBindAPI(EGL_OPENGL_API));
405                                         expectNoContext(eglCreateContext(display, glConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
406                                         expectError(EGL_BAD_ATTRIBUTE);
407                                 }
408                         }
409
410                         if (isAPISupported(EGL_OPENVG_API))
411                         {
412                                 EGLConfig vgConfig;
413                                 if (getConfig(&vgConfig, FilterList() << renderable<EGL_OPENVG_BIT>))
414                                 {
415                                         expectTrue(eglBindAPI(EGL_OPENVG_API));
416                                         expectNoContext(eglCreateContext(display, vgConfig, EGL_NO_CONTEXT, s_es1ContextAttribList));
417                                         expectError(EGL_BAD_ATTRIBUTE);
418                                 }
419                         }
420
421                         if (isAPISupported(EGL_OPENGL_ES_API))
422                         {
423                                 bool            gotConfig       = false;
424                                 EGLConfig       esConfig;
425
426                                 gotConfig = getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES_BIT>) ||
427                                                         getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES2_BIT>);
428
429                                 if (gotConfig)
430                                 {
431                                         expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
432                                         expectNoContext(eglCreateContext(display, esConfig, EGL_NO_CONTEXT, s_invalidCreateContextAttribList0));
433                                         expectError(EGL_BAD_ATTRIBUTE);
434                                         expectNoContext(eglCreateContext(display, esConfig, EGL_NO_CONTEXT, s_invalidCreateContextAttribList1));
435                                         expectError(EGL_BAD_ATTRIBUTE);
436                                 }
437                         }
438
439                         log << TestLog::EndSection;
440                 });
441
442         TEGL_ADD_API_CASE(create_pbuffer_from_client_buffer, "eglCreatePbufferFromClientBuffer() negative tests",
443                 {
444                         TestLog&        log                     = m_testCtx.getLog();
445                         EGLDisplay      display         = getDisplay();
446                         EGLConfig       anyConfig;
447                         EGLint          unused          = 0;
448
449                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
450
451                         expectNoSurface(eglCreatePbufferFromClientBuffer(EGL_NO_DISPLAY, EGL_OPENVG_IMAGE, 0, (EGLConfig)0, DE_NULL));
452                         expectError(EGL_BAD_DISPLAY);
453
454                         expectNoSurface(eglCreatePbufferFromClientBuffer((EGLDisplay)-1, EGL_OPENVG_IMAGE, 0, (EGLConfig)0, DE_NULL));
455                         expectError(EGL_BAD_DISPLAY);
456
457                         log << TestLog::EndSection;
458
459                         log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
460
461                         expectNoSurface(eglCreatePbufferFromClientBuffer(display, EGL_OPENVG_IMAGE, 0, (EGLConfig)-1, DE_NULL));
462                         expectError(EGL_BAD_CONFIG);
463
464                         log << TestLog::EndSection;
465
466                         log << TestLog::Section("Test3", "EGL_BAD_PARAMETER is generated if buftype is not EGL_OPENVG_IMAGE");
467
468                         log << TestLog::EndSection;
469
470                         expectTrue(eglGetConfigs(display, &anyConfig, 1, &unused));
471
472                         log << TestLog::Section("Test4", "EGL_BAD_PARAMETER is generated if buffer is not valid OpenVG image");
473                         expectNoSurface(eglCreatePbufferFromClientBuffer(display, EGL_OPENVG_IMAGE, (EGLClientBuffer)-1, anyConfig, DE_NULL));
474                         expectError(EGL_BAD_PARAMETER);
475
476                         log << TestLog::EndSection;
477                 });
478
479         static const EGLint s_validGenericPbufferAttrib[] = { EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
480
481         static const EGLint s_invalidGenericPbufferAttrib0[] = { 0, EGL_NONE };
482         static const EGLint s_invalidGenericPbufferAttrib1[] = { (EGLint)0xffffffff };
483         static const EGLint s_negativeWidthPbufferAttrib[] = { EGL_WIDTH, -1, EGL_HEIGHT, 64, EGL_NONE };
484         static const EGLint s_negativeHeightPbufferAttrib[] = { EGL_WIDTH, 64, EGL_HEIGHT, -1, EGL_NONE };
485         static const EGLint s_negativeWidthAndHeightPbufferAttrib[] = { EGL_WIDTH, -1, EGL_HEIGHT, -1, EGL_NONE };
486         static const EGLint* s_invalidGenericPbufferAttribs[] =
487         {
488                 s_invalidGenericPbufferAttrib0,
489                 s_invalidGenericPbufferAttrib1,
490         };
491
492         static const EGLint s_invalidNoEsPbufferAttrib0[] = { EGL_MIPMAP_TEXTURE, EGL_TRUE, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
493         static const EGLint s_invalidNoEsPbufferAttrib1[] = { EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
494         static const EGLint s_invalidNoEsPbufferAttrib2[] = { EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
495         static const EGLint* s_invalidNoEsPbufferAttribs[] =
496         {
497                 s_invalidNoEsPbufferAttrib0,
498                 s_invalidNoEsPbufferAttrib1,
499                 s_invalidNoEsPbufferAttrib2
500         };
501
502         static const EGLint s_invalidEsPbufferAttrib0[] = { EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE, EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
503         static const EGLint s_invalidEsPbufferAttrib1[] = { EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_TEXTURE_TARGET, EGL_NO_TEXTURE, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
504         static const EGLint* s_invalidEsPbufferAttribs[] =
505         {
506                 s_invalidEsPbufferAttrib0,
507                 s_invalidEsPbufferAttrib1
508         };
509
510         static const EGLint s_vgPreMultAlphaPbufferAttrib[] = { EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
511         static const EGLint s_vgLinearColorspacePbufferAttrib[] = { EGL_COLORSPACE, EGL_VG_COLORSPACE_LINEAR, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
512
513         TEGL_ADD_API_CASE(create_pbuffer_surface, "eglCreatePbufferSurface() negative tests",
514                 {
515                         TestLog&        log                     = m_testCtx.getLog();
516                         EGLDisplay      display         = getDisplay();
517
518                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
519
520                         expectNoSurface(eglCreatePbufferSurface(EGL_NO_DISPLAY, DE_NULL, s_emptyAttribList));
521                         expectError(EGL_BAD_DISPLAY);
522
523                         expectNoSurface(eglCreatePbufferSurface((EGLDisplay)-1, DE_NULL, s_emptyAttribList));
524                         expectError(EGL_BAD_DISPLAY);
525
526                         log << TestLog::EndSection;
527
528                         log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
529
530                         expectNoSurface(eglCreatePbufferSurface(display, (EGLConfig)-1, s_emptyAttribList));
531                         expectError(EGL_BAD_CONFIG);
532
533                         log << TestLog::EndSection;
534
535                         log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid pixel buffer attribute");
536
537                         // Generic pbuffer-capable config
538                         EGLConfig genericConfig;
539                         if (getConfig(&genericConfig, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
540                         {
541                                 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidGenericPbufferAttribs); ndx++)
542                                 {
543                                         expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_invalidGenericPbufferAttribs[ndx]));
544                                         expectError(EGL_BAD_ATTRIBUTE);
545                                 }
546                         }
547
548                         log << TestLog::EndSection;
549
550                         log << TestLog::Section("Test4", "EGL_BAD_MATCH is generated if config does not support rendering to pixel buffers");
551
552                         EGLConfig noPbufferConfig;
553                         if (getConfig(&noPbufferConfig, FilterList() << notSurfaceBits<EGL_PBUFFER_BIT>))
554                         {
555                                 expectNoSurface(eglCreatePbufferSurface(display, noPbufferConfig, s_validGenericPbufferAttrib));
556                                 expectError(EGL_BAD_MATCH);
557                         }
558
559                         log << TestLog::EndSection;
560
561                         log << TestLog::Section("Test5", "EGL_BAD_ATTRIBUTE is generated if attrib_list contains any of the attributes EGL_MIPMAP_TEXTURE, EGL_TEXTURE_FORMAT, or EGL_TEXTURE_TARGET, and config does not support OpenGL ES rendering");
562
563                         EGLConfig noEsConfig;
564                         if (getConfig(&noEsConfig, FilterList() << notRenderable<EGL_OPENGL_ES_BIT|EGL_OPENGL_ES2_BIT>))
565                         {
566                                 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidNoEsPbufferAttribs); ndx++)
567                                 {
568                                         expectNoSurface(eglCreatePbufferSurface(display, noEsConfig, s_invalidNoEsPbufferAttribs[ndx]));
569                                         expectError(EGL_BAD_MATCH);
570                                 }
571                         }
572
573                         log << TestLog::EndSection;
574
575                         log << TestLog::Section("Test6", "EGL_BAD_MATCH is generated if the EGL_TEXTURE_FORMAT attribute is EGL_NO_TEXTURE, and EGL_TEXTURE_TARGET is something other than EGL_NO_TEXTURE; or, EGL_TEXTURE_FORMAT is something other than EGL_NO_TEXTURE, and EGL_TEXTURE_TARGET is EGL_NO_TEXTURE");
576
577                         // ES1 or ES2 config.
578                         EGLConfig       esConfig;
579                         bool            gotEsConfig     = getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES_BIT>) ||
580                                                                           getConfig(&esConfig, FilterList() << renderable<EGL_OPENGL_ES2_BIT>);
581                         if (gotEsConfig)
582                         {
583                                 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidEsPbufferAttribs); ndx++)
584                                 {
585                                         expectNoSurface(eglCreatePbufferSurface(display, esConfig, s_invalidEsPbufferAttribs[ndx]));
586                                         expectError(EGL_BAD_MATCH);
587                                 }
588                         }
589
590                         log << TestLog::EndSection;
591
592                         log << TestLog::Section("Test7", "EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute or colorspace attribute");
593
594                         EGLConfig vgNoPreConfig;
595                         if (getConfig(&vgNoPreConfig, FilterList() << renderable<EGL_OPENVG_BIT> << notSurfaceBits<EGL_VG_ALPHA_FORMAT_PRE_BIT>))
596                         {
597                                 expectNoSurface(eglCreatePbufferSurface(display, vgNoPreConfig, s_vgPreMultAlphaPbufferAttrib));
598                                 expectError(EGL_BAD_MATCH);
599                         }
600
601                         EGLConfig vgNoLinearConfig;
602                         if (getConfig(&vgNoLinearConfig, FilterList() << renderable<EGL_OPENVG_BIT> << notSurfaceBits<EGL_VG_COLORSPACE_LINEAR_BIT>))
603                         {
604                                 expectNoSurface(eglCreatePbufferSurface(display, vgNoLinearConfig, s_vgLinearColorspacePbufferAttrib));
605                                 expectError(EGL_BAD_MATCH);
606                         }
607
608                         log << TestLog::EndSection;
609
610                         log << TestLog::Section("Test8", "EGL_BAD_PARAMETER is generated if EGL_WIDTH or EGL_HEIGHT is negative");
611
612                         if (getConfig(&genericConfig, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
613                         {
614                                 expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_negativeWidthPbufferAttrib));
615                                 expectError(EGL_BAD_PARAMETER);
616
617                                 expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_negativeHeightPbufferAttrib));
618                                 expectError(EGL_BAD_PARAMETER);
619
620                                 expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_negativeWidthAndHeightPbufferAttrib));
621                                 expectError(EGL_BAD_PARAMETER);
622                         }
623
624                         log << TestLog::EndSection;
625
626                 });
627
628         TEGL_ADD_API_CASE(create_pixmap_surface, "eglCreatePixmapSurface() negative tests",
629                 {
630                         TestLog&        log                     = m_testCtx.getLog();
631                         EGLDisplay      display         = getDisplay();
632
633                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
634
635                         expectNoSurface(eglCreatePixmapSurface(EGL_NO_DISPLAY, DE_NULL, DE_NULL, s_emptyAttribList));
636                         expectError(EGL_BAD_DISPLAY);
637
638                         expectNoSurface(eglCreatePixmapSurface((EGLDisplay)-1, DE_NULL, DE_NULL, s_emptyAttribList));
639                         expectError(EGL_BAD_DISPLAY);
640
641                         log << TestLog::EndSection;
642
643                         log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
644
645                         expectNoSurface(eglCreatePixmapSurface(display, (EGLConfig)-1, DE_NULL, s_emptyAttribList));
646                         expectError(EGL_BAD_CONFIG);
647
648                         log << TestLog::EndSection;
649
650                         log << TestLog::Section("Test3", "EGL_BAD_NATIVE_PIXMAP may be generated if native_pixmap is not a valid native pixmap");
651
652                         // Any pixmap-capable config.
653                         EGLConfig pixmapConfig;
654                         if (getConfig(&pixmapConfig, FilterList() << surfaceBits<EGL_PIXMAP_BIT>))
655                         {
656                                 expectNoSurface(eglCreatePixmapSurface(display, pixmapConfig, DE_NULL, s_emptyAttribList));
657                                 expectError(EGL_BAD_NATIVE_PIXMAP);
658                         }
659
660                         log << TestLog::EndSection;
661                 });
662
663         TEGL_ADD_API_CASE(create_window_surface, "eglCreateWindowSurface() negative tests",
664                 {
665                         TestLog&        log                     = m_testCtx.getLog();
666                         EGLDisplay      display         = getDisplay();
667
668                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
669
670                         expectNoSurface(eglCreateWindowSurface(EGL_NO_DISPLAY, DE_NULL, DE_NULL, s_emptyAttribList));
671                         expectError(EGL_BAD_DISPLAY);
672
673                         expectNoSurface(eglCreateWindowSurface((EGLDisplay)-1, DE_NULL, DE_NULL, s_emptyAttribList));
674                         expectError(EGL_BAD_DISPLAY);
675
676                         log << TestLog::EndSection;
677
678                         log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
679
680                         expectNoSurface(eglCreateWindowSurface(display, (EGLConfig)-1, DE_NULL, s_emptyAttribList));
681                         expectError(EGL_BAD_CONFIG);
682
683                         log << TestLog::EndSection;
684
685                         log << TestLog::Section("Test3", "EGL_BAD_NATIVE_WINDOW may be generated if native_window is not a valid native window");
686
687                         // Any window-capable config.
688                         EGLConfig windowConfig;
689                         if (getConfig(&windowConfig, FilterList() << surfaceBits<EGL_WINDOW_BIT>))
690                         {
691                                 expectNoSurface(eglCreateWindowSurface(display, windowConfig, DE_NULL, s_emptyAttribList));
692                                 expectError(EGL_BAD_NATIVE_WINDOW);
693                         }
694
695                         log << TestLog::EndSection;
696                 });
697
698         TEGL_ADD_API_CASE(destroy_context, "eglDestroyContext() negative tests",
699                 {
700                         TestLog&        log                     = m_testCtx.getLog();
701                         EGLDisplay      display         = getDisplay();
702
703                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
704
705                         expectFalse(eglDestroyContext(EGL_NO_DISPLAY, DE_NULL));
706                         expectError(EGL_BAD_DISPLAY);
707
708                         expectFalse(eglDestroyContext((EGLDisplay)-1, DE_NULL));
709                         expectError(EGL_BAD_DISPLAY);
710
711                         log << TestLog::EndSection;
712
713                         log << TestLog::Section("Test2", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
714
715                         expectFalse(eglDestroyContext(display, DE_NULL));
716                         expectError(EGL_BAD_CONTEXT);
717
718                         expectFalse(eglDestroyContext(display, (EGLContext)-1));
719                         expectError(EGL_BAD_CONTEXT);
720
721                         log << TestLog::EndSection;
722                 });
723
724         TEGL_ADD_API_CASE(destroy_surface, "eglDestroySurface() negative tests",
725                 {
726                         TestLog&        log                     = m_testCtx.getLog();
727                         EGLDisplay      display         = getDisplay();
728
729                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
730
731                         expectFalse(eglDestroySurface(EGL_NO_DISPLAY, DE_NULL));
732                         expectError(EGL_BAD_DISPLAY);
733
734                         expectFalse(eglDestroySurface((EGLDisplay)-1, DE_NULL));
735                         expectError(EGL_BAD_DISPLAY);
736
737                         log << TestLog::EndSection;
738
739                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
740
741                         expectFalse(eglDestroySurface(display, DE_NULL));
742                         expectError(EGL_BAD_SURFACE);
743
744                         expectFalse(eglDestroySurface(display, (EGLSurface)-1));
745                         expectError(EGL_BAD_SURFACE);
746
747                         log << TestLog::EndSection;
748                 });
749
750         TEGL_ADD_API_CASE(get_config_attrib, "eglGetConfigAttrib() negative tests",
751                 {
752                         TestLog&        log                     = m_testCtx.getLog();
753                         EGLDisplay      display         = getDisplay();
754                         EGLint          value           = 0;
755
756                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
757
758                         expectFalse(eglGetConfigAttrib(EGL_NO_DISPLAY, DE_NULL, EGL_RED_SIZE, &value));
759                         expectError(EGL_BAD_DISPLAY);
760
761                         expectFalse(eglGetConfigAttrib((EGLDisplay)-1, DE_NULL, EGL_RED_SIZE, &value));
762                         expectError(EGL_BAD_DISPLAY);
763
764                         log << TestLog::EndSection;
765
766                         log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
767
768                         expectFalse(eglGetConfigAttrib(display, (EGLConfig)-1, EGL_RED_SIZE, &value));
769                         expectError(EGL_BAD_CONFIG);
770
771                         log << TestLog::EndSection;
772
773                         // Any config.
774                         EGLConfig       config          = DE_NULL;
775                         bool            hasConfig       = getConfig(&config, FilterList());
776
777                         log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid frame buffer configuration attribute");
778
779                         if (hasConfig)
780                         {
781                                 expectFalse(eglGetConfigAttrib(display, config, 0, &value));
782                                 expectError(EGL_BAD_ATTRIBUTE);
783
784                                 expectFalse(eglGetConfigAttrib(display, config, -1, &value));
785                                 expectError(EGL_BAD_ATTRIBUTE);
786                         }
787
788                         log << TestLog::EndSection;
789                 });
790
791         TEGL_ADD_API_CASE(get_configs, "eglGetConfigs() negative tests",
792                 {
793                         TestLog&        log                     = m_testCtx.getLog();
794                         EGLDisplay      display         = getDisplay();
795                         EGLConfig       cfgs[1];
796                         EGLint          numCfgs         = 0;
797
798                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
799
800                         expectFalse(eglGetConfigs(EGL_NO_DISPLAY, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), &numCfgs));
801                         expectError(EGL_BAD_DISPLAY);
802
803                         expectFalse(eglGetConfigs((EGLDisplay)-1, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), &numCfgs));
804                         expectError(EGL_BAD_DISPLAY);
805
806                         log << TestLog::EndSection;
807
808                         log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if num_config is NULL");
809
810                         expectFalse(eglGetConfigs(display, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), DE_NULL));
811                         expectError(EGL_BAD_PARAMETER);
812
813                         log << TestLog::EndSection;
814                 });
815
816         TEGL_ADD_API_CASE(get_display, "eglGetDisplay() negative tests",
817                 {
818                         expectNoDisplay(eglGetDisplay((EGLNativeDisplayType)-1));
819                         expectError(EGL_SUCCESS);
820                 });
821
822         TEGL_ADD_API_CASE(initialize, "eglInitialize() negative tests",
823                 {
824                         TestLog&        log                     = m_testCtx.getLog();
825                         EGLint          major           = 0;
826                         EGLint          minor           = 0;
827
828                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
829
830                         expectFalse(eglInitialize(EGL_NO_DISPLAY, &major, &minor));
831                         expectError(EGL_BAD_DISPLAY);
832
833                         expectFalse(eglInitialize((EGLDisplay)-1, &major, &minor));
834                         expectError(EGL_BAD_DISPLAY);
835
836                         log << TestLog::EndSection;
837                 });
838
839         TEGL_ADD_API_CASE(make_current, "eglMakeCurrent() negative tests",
840                 {
841                         TestLog&        log                     = m_testCtx.getLog();
842                         EGLDisplay      display         = getDisplay();
843
844                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
845
846                         expectFalse(eglMakeCurrent(EGL_NO_DISPLAY, DE_NULL, DE_NULL, DE_NULL));
847                         expectError(EGL_BAD_DISPLAY);
848
849                         expectFalse(eglMakeCurrent((EGLDisplay)-1, DE_NULL, DE_NULL, DE_NULL));
850                         expectError(EGL_BAD_DISPLAY);
851
852                         log << TestLog::EndSection;
853
854                         // Create simple pbuffer surface.
855                         EGLSurface surface = EGL_NO_SURFACE;
856                         {
857                                 EGLConfig config;
858                                 if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
859                                 {
860                                         surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
861                                         expectError(EGL_SUCCESS);
862                                 }
863                         }
864
865                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
866
867                         expectFalse(eglMakeCurrent(display, (EGLSurface)-1, (EGLSurface)-1, DE_NULL));
868                         expectError(EGL_BAD_SURFACE);
869
870                         if (surface)
871                         {
872                                 expectFalse(eglMakeCurrent(display, surface, (EGLSurface)-1, DE_NULL));
873                                 expectError(EGL_BAD_SURFACE);
874
875                                 expectFalse(eglMakeCurrent(display, (EGLSurface)-1, surface, DE_NULL));
876                                 expectError(EGL_BAD_SURFACE);
877                         }
878
879                         log << TestLog::EndSection;
880
881                         log << TestLog::Section("Test3", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
882
883                         if (surface)
884                         {
885                                 expectFalse(eglMakeCurrent(display, surface, surface, (EGLContext)-1));
886                                 expectError(EGL_BAD_CONTEXT);
887                         }
888
889                         log << TestLog::EndSection;
890
891                         if (surface)
892                         {
893                                 eglDestroySurface(display, surface);
894                                 expectError(EGL_SUCCESS);
895                         }
896                 });
897
898         TEGL_ADD_API_CASE(get_current_context, "eglGetCurrentContext() negative tests",
899                 {
900                         expectNoContext(eglGetCurrentContext());
901
902                         if (isAPISupported(EGL_OPENGL_ES_API))
903                         {
904                                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
905                                 expectError(EGL_SUCCESS);
906
907                                 expectNoContext(eglGetCurrentContext());
908                                 expectError(EGL_SUCCESS);
909                         }
910                 });
911
912         TEGL_ADD_API_CASE(get_current_surface, "eglGetCurrentSurface() negative tests",
913                 {
914                         TestLog&        log                     = m_testCtx.getLog();
915                         EGLDisplay      display         = getDisplay();
916                         EGLConfig       config          = DE_NULL;
917                         EGLContext      context         = EGL_NO_CONTEXT;
918                         EGLSurface      surface         = EGL_NO_SURFACE;
919                         bool            gotConfig       = getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << surfaceBits<EGL_PBUFFER_BIT>);
920
921                         if (gotConfig)
922                         {
923                                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
924                                 expectError(EGL_SUCCESS);
925
926                                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
927                                 expectError(EGL_SUCCESS);
928
929                                 // Create simple pbuffer surface.
930                                 surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
931                                 expectError(EGL_SUCCESS);
932
933                                 expectTrue(eglMakeCurrent(display, surface, surface, context));
934                                 expectError(EGL_SUCCESS);
935
936                                 log << TestLog::Section("Test1", "EGL_BAD_PARAMETER is generated if readdraw is neither EGL_READ nor EGL_DRAW");
937
938                                 expectNoSurface(eglGetCurrentSurface(EGL_NONE));
939                                 expectError(EGL_BAD_PARAMETER);
940
941                                 log << TestLog::EndSection;
942
943                                 expectTrue(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
944                                 expectError(EGL_SUCCESS);
945
946                                 if (surface != EGL_NO_SURFACE)
947                                 {
948                                         expectTrue(eglDestroySurface(display, surface));
949                                         expectError(EGL_SUCCESS);
950                                 }
951
952                                 if (context != EGL_NO_CONTEXT)
953                                 {
954                                         expectTrue(eglDestroyContext(display, context));
955                                         expectError(EGL_SUCCESS);
956                                 }
957                         }
958                 });
959
960         TEGL_ADD_API_CASE(query_context, "eglQueryContext() negative tests",
961                 {
962                         TestLog&        log                     = m_testCtx.getLog();
963                         EGLDisplay      display         = getDisplay();
964                         EGLint          value           = 0;
965
966                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
967
968                         expectFalse(eglQueryContext(EGL_NO_DISPLAY, DE_NULL, EGL_CONFIG_ID, &value));
969                         expectError(EGL_BAD_DISPLAY);
970
971                         expectFalse(eglQueryContext((EGLDisplay)-1, DE_NULL, EGL_CONFIG_ID, &value));
972                         expectError(EGL_BAD_DISPLAY);
973
974                         log << TestLog::EndSection;
975
976                         log << TestLog::Section("Test2", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
977
978                         expectFalse(eglQueryContext(display, DE_NULL, EGL_CONFIG_ID, &value));
979                         expectError(EGL_BAD_CONTEXT);
980
981                         expectFalse(eglQueryContext(display, DE_NULL, EGL_CONFIG_ID, &value));
982                         expectError(EGL_BAD_CONTEXT);
983
984                         log << TestLog::EndSection;
985
986                         // Create ES2 context.
987                         EGLConfig       config          = DE_NULL;
988                         EGLContext      context         = DE_NULL;
989                         bool            gotConfig       = getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT>);
990
991                         if (gotConfig)
992                         {
993                                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
994                                 expectError(EGL_SUCCESS);
995
996                                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
997                                 expectError(EGL_SUCCESS);
998                         }
999
1000                         log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid context attribute");
1001
1002                         if (context)
1003                         {
1004                                 expectFalse(eglQueryContext(display, context, 0, &value));
1005                                 expectError(EGL_BAD_ATTRIBUTE);
1006                                 expectFalse(eglQueryContext(display, context, -1, &value));
1007                                 expectError(EGL_BAD_ATTRIBUTE);
1008                                 expectFalse(eglQueryContext(display, context, EGL_RED_SIZE, &value));
1009                                 expectError(EGL_BAD_ATTRIBUTE);
1010                         }
1011
1012                         log << TestLog::EndSection;
1013
1014                         if (context)
1015                         {
1016                                 expectTrue(eglDestroyContext(display, context));
1017                                 expectError(EGL_SUCCESS);
1018                         }
1019                 });
1020
1021         TEGL_ADD_API_CASE(query_string, "eglQueryString() negative tests",
1022                 {
1023                         TestLog&        log                     = m_testCtx.getLog();
1024                         EGLDisplay      display         = getDisplay();
1025
1026                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1027
1028                         expectNull(eglQueryString(EGL_NO_DISPLAY, EGL_VENDOR));
1029                         expectError(EGL_BAD_DISPLAY);
1030
1031                         expectNull(eglQueryString((EGLDisplay)-1, EGL_VENDOR));
1032                         expectError(EGL_BAD_DISPLAY);
1033
1034                         log << TestLog::EndSection;
1035
1036                         log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if name is not an accepted value");
1037
1038                         expectNull(eglQueryString(display, 0));
1039                         expectError(EGL_BAD_PARAMETER);
1040                         expectNull(eglQueryString(display, -1));
1041                         expectError(EGL_BAD_PARAMETER);
1042
1043                         log << TestLog::EndSection;
1044                 });
1045
1046         TEGL_ADD_API_CASE(query_surface, "eglQuerySurface() negative tests",
1047                 {
1048                         TestLog&        log                     = m_testCtx.getLog();
1049                         EGLDisplay      display         = getDisplay();
1050                         EGLint          value           = 0;
1051
1052                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1053
1054                         expectFalse(eglQuerySurface(EGL_NO_DISPLAY, DE_NULL, EGL_CONFIG_ID, &value));
1055                         expectError(EGL_BAD_DISPLAY);
1056
1057                         expectFalse(eglQuerySurface((EGLDisplay)-1, DE_NULL, EGL_CONFIG_ID, &value));
1058                         expectError(EGL_BAD_DISPLAY);
1059
1060                         log << TestLog::EndSection;
1061
1062                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1063
1064                         expectFalse(eglQuerySurface(display, DE_NULL, EGL_CONFIG_ID, &value));
1065                         expectError(EGL_BAD_SURFACE);
1066
1067                         expectFalse(eglQuerySurface(display, (EGLSurface)-1, EGL_CONFIG_ID, &value));
1068                         expectError(EGL_BAD_SURFACE);
1069
1070                         log << TestLog::EndSection;
1071
1072                         // Create pbuffer surface.
1073                         EGLSurface surface = EGL_NO_SURFACE;
1074                         {
1075                                 EGLConfig config;
1076                                 if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
1077                                 {
1078                                         surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1079                                         expectError(EGL_SUCCESS);
1080                                 }
1081                                 else
1082                                         log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete" << TestLog::EndMessage;
1083                         }
1084
1085                         log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid surface attribute");
1086
1087                         if (surface)
1088                         {
1089                                 expectFalse(eglQuerySurface(display, surface, 0, &value));
1090                                 expectError(EGL_BAD_ATTRIBUTE);
1091
1092                                 expectFalse(eglQuerySurface(display, surface, -1, &value));
1093                                 expectError(EGL_BAD_ATTRIBUTE);
1094                         }
1095
1096                         log << TestLog::EndSection;
1097
1098                         if (surface)
1099                         {
1100                                 eglDestroySurface(display, surface);
1101                                 expectError(EGL_SUCCESS);
1102                         }
1103                 });
1104
1105         TEGL_ADD_API_CASE(release_tex_image, "eglReleaseTexImage() negative tests",
1106                 {
1107                         TestLog&        log                     = m_testCtx.getLog();
1108                         EGLDisplay      display         = getDisplay();
1109
1110                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1111
1112                         expectFalse(eglReleaseTexImage(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_BACK_BUFFER));
1113                         expectError(EGL_BAD_DISPLAY);
1114
1115                         expectFalse(eglReleaseTexImage((EGLDisplay)-1, EGL_NO_SURFACE, EGL_BACK_BUFFER));
1116                         expectError(EGL_BAD_DISPLAY);
1117
1118                         log << TestLog::EndSection;
1119
1120                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1121
1122                         expectFalse(eglReleaseTexImage(display, EGL_NO_SURFACE, EGL_BACK_BUFFER));
1123                         expectError(EGL_BAD_SURFACE);
1124
1125                         expectFalse(eglReleaseTexImage(display, (EGLSurface)-1, EGL_BACK_BUFFER));
1126                         expectError(EGL_BAD_SURFACE);
1127
1128                         log << TestLog::EndSection;
1129                 });
1130
1131         TEGL_ADD_API_CASE(surface_attrib, "eglSurfaceAttrib() negative tests",
1132                 {
1133                         TestLog&        log                     = m_testCtx.getLog();
1134                         EGLDisplay      display         = getDisplay();
1135
1136                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1137
1138                         expectFalse(eglSurfaceAttrib(EGL_NO_DISPLAY, DE_NULL, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1139                         expectError(EGL_BAD_DISPLAY);
1140
1141                         expectFalse(eglSurfaceAttrib((EGLDisplay)-1, DE_NULL, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1142                         expectError(EGL_BAD_DISPLAY);
1143
1144                         log << TestLog::EndSection;
1145
1146                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1147
1148                         expectFalse(eglSurfaceAttrib(display, DE_NULL, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1149                         expectError(EGL_BAD_SURFACE);
1150
1151                         expectFalse(eglSurfaceAttrib(display, (EGLSurface)-1, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED));
1152                         expectError(EGL_BAD_SURFACE);
1153
1154                         log << TestLog::EndSection;
1155
1156                         {
1157                                 // Create pbuffer surface.
1158                                 EGLSurface surface = EGL_NO_SURFACE;
1159                                 {
1160                                         EGLConfig config;
1161                                         if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT>))
1162                                         {
1163                                                 surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1164                                                 expectError(EGL_SUCCESS);
1165                                         }
1166                                         else
1167                                                 log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete" << TestLog::EndMessage;
1168                                 }
1169
1170                                 log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid surface attribute");
1171
1172                                 if (surface)
1173                                 {
1174                                         expectFalse(eglSurfaceAttrib(display, surface, 0, 0));
1175                                         expectError(EGL_BAD_ATTRIBUTE);
1176
1177                                         expectFalse(eglSurfaceAttrib(display, surface, -1, 0));
1178                                         expectError(EGL_BAD_ATTRIBUTE);
1179                                 }
1180
1181                                 log << TestLog::EndSection;
1182
1183                                 if (surface)
1184                                 {
1185                                         eglDestroySurface(display, surface);
1186                                         expectError(EGL_SUCCESS);
1187                                 }
1188                         }
1189
1190                         {
1191                                 // Create pbuffer surface without EGL_MULTISAMPLE_RESOLVE_BOX_BIT.
1192                                 EGLSurface surface = EGL_NO_SURFACE;
1193                                 {
1194                                         EGLConfig config;
1195                                         if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT> << notSurfaceBits<EGL_MULTISAMPLE_RESOLVE_BOX_BIT>))
1196                                         {
1197                                                 surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1198                                                 expectError(EGL_SUCCESS);
1199                                         }
1200                                         else
1201                                                 log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete" << TestLog::EndMessage;
1202                                 }
1203
1204                                 log << TestLog::Section("Test4", "EGL_BAD_MATCH is generated if attribute is EGL_MULTISAMPLE_RESOLVE, value is EGL_MULTISAMPLE_RESOLVE_BOX, and the EGL_SURFACE_TYPE attribute of the EGLConfig used to create surface does not contain EGL_MULTISAMPLE_RESOLVE_BOX_BIT");
1205
1206                                 if (surface)
1207                                 {
1208                                         expectFalse(eglSurfaceAttrib(display, surface, EGL_MULTISAMPLE_RESOLVE, EGL_MULTISAMPLE_RESOLVE_BOX));
1209                                         expectError(EGL_BAD_MATCH);
1210                                 }
1211
1212                                 log << TestLog::EndSection;
1213
1214                                 if (surface)
1215                                 {
1216                                         eglDestroySurface(display, surface);
1217                                         expectError(EGL_SUCCESS);
1218                                 }
1219                         }
1220
1221                         {
1222                                 // Create pbuffer surface without EGL_SWAP_BEHAVIOR_PRESERVED_BIT.
1223                                 EGLSurface surface = EGL_NO_SURFACE;
1224                                 {
1225                                         EGLConfig config;
1226                                         if (getConfig(&config, FilterList() << surfaceBits<EGL_PBUFFER_BIT> << notSurfaceBits<EGL_SWAP_BEHAVIOR_PRESERVED_BIT>))
1227                                         {
1228                                                 surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
1229                                                 expectError(EGL_SUCCESS);
1230                                         }
1231                                         else
1232                                                 log << TestLog::Message << "// WARNING: No suitable config found, testing will be incomplete" << TestLog::EndMessage;
1233                                 }
1234
1235                                 log << TestLog::Section("Test5", "EGL_BAD_MATCH is generated if attribute is EGL_SWAP_BEHAVIOR, value is EGL_BUFFER_PRESERVED, and the EGL_SURFACE_TYPE attribute of the EGLConfig used to create surface does not contain EGL_SWAP_BEHAVIOR_PRESERVED_BIT");
1236
1237                                 if (surface)
1238                                 {
1239                                         expectFalse(eglSurfaceAttrib(display, surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED));
1240                                         expectError(EGL_BAD_MATCH);
1241                                 }
1242
1243                                 log << TestLog::EndSection;
1244
1245                                 if (surface)
1246                                 {
1247                                         eglDestroySurface(display, surface);
1248                                         expectError(EGL_SUCCESS);
1249                                 }
1250                         }
1251                 });
1252
1253         TEGL_ADD_API_CASE(swap_buffers, "eglSwapBuffers() negative tests",
1254                 {
1255                         TestLog&        log                     = m_testCtx.getLog();
1256                         EGLDisplay      display         = getDisplay();
1257
1258                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1259
1260                         expectFalse(eglSwapBuffers(EGL_NO_DISPLAY, DE_NULL));
1261                         expectError(EGL_BAD_DISPLAY);
1262
1263                         expectFalse(eglSwapBuffers((EGLDisplay)-1, DE_NULL));
1264                         expectError(EGL_BAD_DISPLAY);
1265
1266                         log << TestLog::EndSection;
1267
1268                         log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
1269
1270                         expectFalse(eglSwapBuffers(display, DE_NULL));
1271                         expectError(EGL_BAD_SURFACE);
1272
1273                         expectFalse(eglSwapBuffers(display, (EGLSurface)-1));
1274                         expectError(EGL_BAD_SURFACE);
1275
1276                         log << TestLog::EndSection;
1277                 });
1278
1279         TEGL_ADD_API_CASE(swap_interval, "eglSwapInterval() negative tests",
1280                 {
1281                         TestLog&        log                     = m_testCtx.getLog();
1282                         EGLDisplay      display         = getDisplay();
1283
1284                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1285
1286                         expectFalse(eglSwapInterval(EGL_NO_DISPLAY, 0));
1287                         expectError(EGL_BAD_DISPLAY);
1288
1289                         expectFalse(eglSwapInterval((EGLDisplay)-1, 0));
1290                         expectError(EGL_BAD_DISPLAY);
1291
1292                         log << TestLog::EndSection;
1293
1294                         log << TestLog::Section("Test2", "EGL_BAD_CONTEXT is generated if there is no current context on the calling thread");
1295
1296                         expectFalse(eglSwapInterval(display, 0));
1297                         expectError(EGL_BAD_CONTEXT);
1298
1299                         log << TestLog::EndSection;
1300                 });
1301
1302         TEGL_ADD_API_CASE(terminate, "eglTerminate() negative tests",
1303                 {
1304                         TestLog&        log                     = m_testCtx.getLog();
1305
1306                         log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
1307
1308                         expectFalse(eglTerminate(EGL_NO_DISPLAY));
1309                         expectError(EGL_BAD_DISPLAY);
1310
1311                         expectFalse(eglTerminate((EGLDisplay)-1));
1312                         expectError(EGL_BAD_DISPLAY);
1313
1314                         log << TestLog::EndSection;
1315                 });
1316
1317         TEGL_ADD_API_CASE(wait_native, "eglWaitNative() negative tests",
1318                 {
1319                         EGLConfig                               config                  = DE_NULL;
1320                         bool                                    gotConfig               = getConfig(&config, FilterList() << renderable<EGL_OPENGL_ES2_BIT> << surfaceBits<EGL_WINDOW_BIT>);
1321
1322                         if (gotConfig)
1323                         {
1324                                 TestLog&                                                        log                             = m_testCtx.getLog();
1325                                 const Library&                                          egl                             = m_eglTestCtx.getLibrary();
1326                                 EGLDisplay                                                      display                 = getDisplay();
1327                                 const eglu::NativeWindowFactory&        factory                 = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine());
1328                                 de::UniquePtr<eglu::NativeWindow>       window                  (factory.createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, eglu::WindowParams(256, 256, eglu::parseWindowVisibility(m_testCtx.getCommandLine()))));
1329                                 eglu::UniqueSurface                                     surface                 (egl, display, eglu::createWindowSurface(m_eglTestCtx.getNativeDisplay(), *window, display, config, DE_NULL));
1330                                 EGLContext                                                      context                 = EGL_NO_CONTEXT;
1331
1332                                 expectTrue(eglBindAPI(EGL_OPENGL_ES_API));
1333                                 expectError(EGL_SUCCESS);
1334
1335                                 context = eglCreateContext(display, config, EGL_NO_CONTEXT, s_es2ContextAttribList);
1336                                 expectError(EGL_SUCCESS);
1337
1338                                 expectTrue(eglMakeCurrent(display, *surface, *surface, context));
1339                                 expectError(EGL_SUCCESS);
1340
1341                                 log << TestLog::Section("Test1", "EGL_BAD_PARAMETER is generated if engine is not a recognized marking engine");
1342
1343                                 expectFalse(eglWaitNative(-1));
1344                                 expectError(EGL_BAD_PARAMETER);
1345
1346                                 log << TestLog::EndSection;
1347
1348                                 expectTrue(eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
1349                                 expectError(EGL_SUCCESS);
1350
1351                                 if (context != EGL_NO_CONTEXT)
1352                                 {
1353                                         expectTrue(eglDestroyContext(display, context));
1354                                         expectError(EGL_SUCCESS);
1355                                 }
1356                         }
1357                 });
1358 }
1359
1360 } // egl
1361 } // deqp