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