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
29using tcu::TestLog;
30
31namespace deqp
32{
33namespace egl
34{
35
36NegativeApiTests::NegativeApiTests (EglTestContext& eglTestCtx)
37	: TestCaseGroup(eglTestCtx, "negative_api", "Negative API Tests")
38{
39}
40
41NegativeApiTests::~NegativeApiTests (void)
42{
43}
44
45void 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_OPENVG_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_OPENVG_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_OPENVG_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			log << TestLog::EndSection;
438
439			expectTrue(eglGetConfigs(display, &anyConfig, 1, &unused));
440
441			log << TestLog::Section("Test4", "EGL_BAD_PARAMETER is generated if buffer is not valid OpenVG image");
442			expectNoSurface(eglCreatePbufferFromClientBuffer(display, EGL_OPENVG_IMAGE, (EGLClientBuffer)-1, anyConfig, DE_NULL));
443			expectError(EGL_BAD_PARAMETER);
444
445			log << TestLog::EndSection;
446		});
447
448	static const EGLint s_validGenericPbufferAttrib[] = { EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
449
450	static const EGLint s_invalidGenericPbufferAttrib0[] = { 0, EGL_NONE };
451	static const EGLint s_invalidGenericPbufferAttrib1[] = { (EGLint)0xffffffff };
452	static const EGLint s_invalidGenericPbufferAttrib2[] = { EGL_WIDTH, 64, EGL_HEIGHT, -1, EGL_NONE };
453	static const EGLint s_invalidGenericPbufferAttrib3[] = { EGL_WIDTH, -1, EGL_HEIGHT, 64, EGL_NONE };
454	static const EGLint* s_invalidGenericPbufferAttribs[] =
455	{
456		s_invalidGenericPbufferAttrib0,
457		s_invalidGenericPbufferAttrib1,
458		s_invalidGenericPbufferAttrib2,
459		s_invalidGenericPbufferAttrib3
460	};
461
462	static const EGLint s_invalidNoEsPbufferAttrib0[] = { EGL_MIPMAP_TEXTURE, EGL_TRUE, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
463	static const EGLint s_invalidNoEsPbufferAttrib1[] = { EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
464	static const EGLint s_invalidNoEsPbufferAttrib2[] = { EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
465	static const EGLint* s_invalidNoEsPbufferAttribs[] =
466	{
467		s_invalidNoEsPbufferAttrib0,
468		s_invalidNoEsPbufferAttrib1,
469		s_invalidNoEsPbufferAttrib2
470	};
471
472	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 };
473	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 };
474	static const EGLint* s_invalidEsPbufferAttribs[] =
475	{
476		s_invalidEsPbufferAttrib0,
477		s_invalidEsPbufferAttrib1
478	};
479
480	static const EGLint s_vgPreMultAlphaPbufferAttrib[] = { EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
481	static const EGLint s_vgLinearColorspacePbufferAttrib[] = { EGL_VG_COLORSPACE, EGL_VG_COLORSPACE_LINEAR, EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_NONE };
482
483	TEGL_ADD_API_CASE(create_pbuffer_surface, "eglCreatePbufferSurface() negative tests",
484		{
485			TestLog&	log			= m_testCtx.getLog();
486			EGLDisplay	display		= getDisplay();
487
488			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
489
490			expectNoSurface(eglCreatePbufferSurface(EGL_NO_DISPLAY, DE_NULL, s_emptyAttribList));
491			expectError(EGL_BAD_DISPLAY);
492
493			expectNoSurface(eglCreatePbufferSurface((EGLDisplay)-1, DE_NULL, s_emptyAttribList));
494			expectError(EGL_BAD_DISPLAY);
495
496			log << TestLog::EndSection;
497
498			log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
499
500			expectNoSurface(eglCreatePbufferSurface(display, (EGLConfig)-1, s_emptyAttribList));
501			expectError(EGL_BAD_CONFIG);
502
503			log << TestLog::EndSection;
504
505			log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attrib_list contains an invalid pixel buffer attribute");
506
507			// Generic pbuffer-capable config
508			EGLConfig genericConfig;
509			if (getConfig(&genericConfig, FilterList() << (ConfigSurfaceType() & EGL_PBUFFER_BIT)))
510			{
511				for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidGenericPbufferAttribs); ndx++)
512				{
513					expectNoSurface(eglCreatePbufferSurface(display, genericConfig, s_invalidGenericPbufferAttribs[ndx]));
514					expectError(EGL_BAD_ATTRIBUTE);
515				}
516			}
517
518			log << TestLog::EndSection;
519
520			log << TestLog::Section("Test4", "EGL_BAD_MATCH is generated if config does not support rendering to pixel buffers");
521
522			EGLConfig noPbufferConfig;
523			if (getConfig(&noPbufferConfig, FilterList() << (ConfigSurfaceType() ^ EGL_PBUFFER_BIT)))
524			{
525				expectNoSurface(eglCreatePbufferSurface(display, noPbufferConfig, s_validGenericPbufferAttrib));
526				expectError(EGL_BAD_MATCH);
527			}
528
529			log << TestLog::EndSection;
530
531			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");
532
533			EGLConfig noEsConfig;
534			if (getConfig(&noEsConfig, FilterList() << (ConfigRenderableType() ^ (EGL_OPENGL_ES_BIT|EGL_OPENGL_ES2_BIT))))
535			{
536				for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidNoEsPbufferAttribs); ndx++)
537				{
538					expectNoSurface(eglCreatePbufferSurface(display, noEsConfig, s_invalidNoEsPbufferAttribs[ndx]));
539					expectError(EGL_BAD_MATCH);
540				}
541			}
542
543			log << TestLog::EndSection;
544
545			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");
546
547			// ES1 or ES2 config.
548			EGLConfig	esConfig;
549			bool		gotEsConfig	= getConfig(&esConfig, FilterList() << (ConfigRenderableType() & EGL_OPENGL_ES_BIT)) ||
550									  getConfig(&esConfig, FilterList() << (ConfigRenderableType() & EGL_OPENGL_ES2_BIT));
551			if (gotEsConfig)
552			{
553				for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_invalidEsPbufferAttribs); ndx++)
554				{
555					expectNoSurface(eglCreatePbufferSurface(display, esConfig, s_invalidEsPbufferAttribs[ndx]));
556					expectError(EGL_BAD_MATCH);
557				}
558			}
559
560			log << TestLog::EndSection;
561
562			log << TestLog::Section("Test7", "EGL_BAD_MATCH is generated if config does not support the specified OpenVG alpha format attribute or colorspace attribute");
563
564			EGLConfig vgNoPreConfig;
565			if (getConfig(&vgNoPreConfig, FilterList() << (ConfigRenderableType() & EGL_OPENVG_BIT) << (ConfigSurfaceType() ^ EGL_VG_ALPHA_FORMAT_PRE)))
566			{
567				expectNoSurface(eglCreatePbufferSurface(display, vgNoPreConfig, s_vgPreMultAlphaPbufferAttrib));
568				expectError(EGL_BAD_MATCH);
569			}
570
571			EGLConfig vgNoLinearConfig;
572			if (getConfig(&vgNoLinearConfig, FilterList() << (ConfigRenderableType() & EGL_OPENVG_BIT) << (ConfigSurfaceType() ^ EGL_VG_COLORSPACE_LINEAR_BIT)))
573			{
574				expectNoSurface(eglCreatePbufferSurface(display, vgNoLinearConfig, s_vgLinearColorspacePbufferAttrib));
575				expectError(EGL_BAD_MATCH);
576			}
577
578			log << TestLog::EndSection;
579		});
580
581	TEGL_ADD_API_CASE(create_pixmap_surface, "eglCreatePixmapSurface() negative tests",
582		{
583			TestLog&	log			= m_testCtx.getLog();
584			EGLDisplay	display		= getDisplay();
585
586			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
587
588			expectNoSurface(eglCreatePixmapSurface(EGL_NO_DISPLAY, DE_NULL, DE_NULL, s_emptyAttribList));
589			expectError(EGL_BAD_DISPLAY);
590
591			expectNoSurface(eglCreatePixmapSurface((EGLDisplay)-1, DE_NULL, DE_NULL, s_emptyAttribList));
592			expectError(EGL_BAD_DISPLAY);
593
594			log << TestLog::EndSection;
595
596			log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
597
598			expectNoSurface(eglCreatePixmapSurface(display, (EGLConfig)-1, DE_NULL, s_emptyAttribList));
599			expectError(EGL_BAD_CONFIG);
600
601			log << TestLog::EndSection;
602
603			log << TestLog::Section("Test3", "EGL_BAD_NATIVE_PIXMAP may be generated if native_pixmap is not a valid native pixmap");
604
605			// Any pixmap-capable config.
606			EGLConfig pixmapConfig;
607			if (getConfig(&pixmapConfig, FilterList() << (ConfigSurfaceType() & EGL_PIXMAP_BIT)))
608			{
609				expectNoSurface(eglCreatePixmapSurface(display, pixmapConfig, DE_NULL, s_emptyAttribList));
610				expectError(EGL_BAD_NATIVE_PIXMAP);
611
612				expectNoSurface(eglCreatePixmapSurface(display, pixmapConfig, (EGLNativePixmapType)-1, s_emptyAttribList));
613				expectError(EGL_BAD_NATIVE_PIXMAP);
614			}
615
616			log << TestLog::EndSection;
617		});
618
619	TEGL_ADD_API_CASE(create_window_surface, "eglCreateWindowSurface() negative tests",
620		{
621			TestLog&	log			= m_testCtx.getLog();
622			EGLDisplay	display		= getDisplay();
623
624			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
625
626			expectNoSurface(eglCreateWindowSurface(EGL_NO_DISPLAY, DE_NULL, DE_NULL, s_emptyAttribList));
627			expectError(EGL_BAD_DISPLAY);
628
629			expectNoSurface(eglCreateWindowSurface((EGLDisplay)-1, DE_NULL, DE_NULL, s_emptyAttribList));
630			expectError(EGL_BAD_DISPLAY);
631
632			log << TestLog::EndSection;
633
634			log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
635
636			expectNoSurface(eglCreateWindowSurface(display, (EGLConfig)-1, DE_NULL, s_emptyAttribList));
637			expectError(EGL_BAD_CONFIG);
638
639			log << TestLog::EndSection;
640
641			log << TestLog::Section("Test3", "EGL_BAD_NATIVE_WINDOW may be generated if native_window is not a valid native window");
642
643			// Any window-capable config.
644			EGLConfig windowConfig;
645			if (getConfig(&windowConfig, FilterList() << (ConfigSurfaceType() & EGL_WINDOW_BIT)))
646			{
647				expectNoSurface(eglCreateWindowSurface(display, windowConfig, DE_NULL, s_emptyAttribList));
648				expectError(EGL_BAD_NATIVE_WINDOW);
649
650				expectNoSurface(eglCreateWindowSurface(display, windowConfig, (EGLNativeWindowType)-1, s_emptyAttribList));
651				expectError(EGL_BAD_NATIVE_WINDOW);
652			}
653
654			log << TestLog::EndSection;
655		});
656
657	TEGL_ADD_API_CASE(destroy_context, "eglDestroyContext() negative tests",
658		{
659			TestLog&	log			= m_testCtx.getLog();
660			EGLDisplay	display		= getDisplay();
661
662			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
663
664			expectFalse(eglDestroyContext(EGL_NO_DISPLAY, DE_NULL));
665			expectError(EGL_BAD_DISPLAY);
666
667			expectFalse(eglDestroyContext((EGLDisplay)-1, DE_NULL));
668			expectError(EGL_BAD_DISPLAY);
669
670			log << TestLog::EndSection;
671
672			log << TestLog::Section("Test2", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
673
674			expectFalse(eglDestroyContext(display, DE_NULL));
675			expectError(EGL_BAD_CONTEXT);
676
677			expectFalse(eglDestroyContext(display, (EGLContext)-1));
678			expectError(EGL_BAD_CONTEXT);
679
680			log << TestLog::EndSection;
681		});
682
683	TEGL_ADD_API_CASE(destroy_surface, "eglDestroySurface() negative tests",
684		{
685			TestLog&	log			= m_testCtx.getLog();
686			EGLDisplay	display		= getDisplay();
687
688			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
689
690			expectFalse(eglDestroySurface(EGL_NO_DISPLAY, DE_NULL));
691			expectError(EGL_BAD_DISPLAY);
692
693			expectFalse(eglDestroySurface((EGLDisplay)-1, DE_NULL));
694			expectError(EGL_BAD_DISPLAY);
695
696			log << TestLog::EndSection;
697
698			log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
699
700			expectFalse(eglDestroySurface(display, DE_NULL));
701			expectError(EGL_BAD_SURFACE);
702
703			expectFalse(eglDestroySurface(display, (EGLSurface)-1));
704			expectError(EGL_BAD_SURFACE);
705
706			log << TestLog::EndSection;
707		});
708
709	TEGL_ADD_API_CASE(get_config_attrib, "eglGetConfigAttrib() negative tests",
710		{
711			TestLog&	log			= m_testCtx.getLog();
712			EGLDisplay	display		= getDisplay();
713			EGLint		value		= 0;
714
715			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
716
717			expectFalse(eglGetConfigAttrib(EGL_NO_DISPLAY, DE_NULL, EGL_RED_SIZE, &value));
718			expectError(EGL_BAD_DISPLAY);
719
720			expectFalse(eglGetConfigAttrib((EGLDisplay)-1, DE_NULL, EGL_RED_SIZE, &value));
721			expectError(EGL_BAD_DISPLAY);
722
723			log << TestLog::EndSection;
724
725			log << TestLog::Section("Test2", "EGL_BAD_CONFIG is generated if config is not an EGL frame buffer configuration");
726
727			expectFalse(eglGetConfigAttrib(display, (EGLConfig)-1, EGL_RED_SIZE, &value));
728			expectError(EGL_BAD_CONFIG);
729
730			log << TestLog::EndSection;
731
732			// Any config.
733			EGLConfig	config		= DE_NULL;
734			bool		hasConfig	= getConfig(&config, FilterList());
735
736			log << TestLog::Section("Test3", "EGL_BAD_ATTRIBUTE is generated if attribute is not a valid frame buffer configuration attribute");
737
738			if (hasConfig)
739			{
740				expectFalse(eglGetConfigAttrib(display, config, 0, &value));
741				expectError(EGL_BAD_ATTRIBUTE);
742
743				expectFalse(eglGetConfigAttrib(display, config, -1, &value));
744				expectError(EGL_BAD_ATTRIBUTE);
745			}
746
747			log << TestLog::EndSection;
748		});
749
750	TEGL_ADD_API_CASE(get_configs, "eglGetConfigs() negative tests",
751		{
752			TestLog&	log			= m_testCtx.getLog();
753			EGLDisplay	display		= getDisplay();
754			EGLConfig	cfgs[1];
755			EGLint		numCfgs		= 0;
756
757			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
758
759			expectFalse(eglGetConfigs(EGL_NO_DISPLAY, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), &numCfgs));
760			expectError(EGL_BAD_DISPLAY);
761
762			expectFalse(eglGetConfigs((EGLDisplay)-1, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), &numCfgs));
763			expectError(EGL_BAD_DISPLAY);
764
765			log << TestLog::EndSection;
766
767			log << TestLog::Section("Test2", "EGL_BAD_PARAMETER is generated if num_config is NULL");
768
769			expectFalse(eglGetConfigs(display, &cfgs[0], DE_LENGTH_OF_ARRAY(cfgs), DE_NULL));
770			expectError(EGL_BAD_PARAMETER);
771
772			log << TestLog::EndSection;
773		});
774
775	TEGL_ADD_API_CASE(get_display, "eglGetDisplay() negative tests",
776		{
777			expectNoDisplay(eglGetDisplay((EGLNativeDisplayType)-1));
778			expectError(EGL_SUCCESS);
779		});
780
781	TEGL_ADD_API_CASE(initialize, "eglInitialize() negative tests",
782		{
783			TestLog&	log			= m_testCtx.getLog();
784			EGLint		major		= 0;
785			EGLint		minor		= 0;
786
787			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
788
789			expectFalse(eglInitialize(EGL_NO_DISPLAY, &major, &minor));
790			expectError(EGL_BAD_DISPLAY);
791
792			expectFalse(eglInitialize((EGLDisplay)-1, &major, &minor));
793			expectError(EGL_BAD_DISPLAY);
794
795			log << TestLog::EndSection;
796		});
797
798	TEGL_ADD_API_CASE(make_current, "eglMakeCurrent() negative tests",
799		{
800			TestLog&	log			= m_testCtx.getLog();
801			EGLDisplay	display		= getDisplay();
802
803			log << TestLog::Section("Test1", "EGL_BAD_DISPLAY is generated if display is not an EGL display connection");
804
805			expectFalse(eglMakeCurrent(EGL_NO_DISPLAY, DE_NULL, DE_NULL, DE_NULL));
806			expectError(EGL_BAD_DISPLAY);
807
808			expectFalse(eglMakeCurrent((EGLDisplay)-1, DE_NULL, DE_NULL, DE_NULL));
809			expectError(EGL_BAD_DISPLAY);
810
811			log << TestLog::EndSection;
812
813			// Create simple pbuffer surface.
814			EGLSurface surface = EGL_NO_SURFACE;
815			{
816				EGLConfig config;
817				if (getConfig(&config, FilterList() << (ConfigSurfaceType() & EGL_PBUFFER_BIT)))
818				{
819					surface = eglCreatePbufferSurface(display, config, s_validGenericPbufferAttrib);
820					expectError(EGL_SUCCESS);
821				}
822			}
823
824			log << TestLog::Section("Test2", "EGL_BAD_SURFACE is generated if surface is not an EGL surface");
825
826			expectFalse(eglMakeCurrent(display, (EGLSurface)-1, (EGLSurface)-1, DE_NULL));
827			expectError(EGL_BAD_SURFACE);
828
829			if (surface)
830			{
831				expectFalse(eglMakeCurrent(display, surface, (EGLSurface)-1, DE_NULL));
832				expectError(EGL_BAD_SURFACE);
833
834				expectFalse(eglMakeCurrent(display, (EGLSurface)-1, surface, DE_NULL));
835				expectError(EGL_BAD_SURFACE);
836			}
837
838			log << TestLog::EndSection;
839
840			log << TestLog::Section("Test3", "EGL_BAD_CONTEXT is generated if context is not an EGL rendering context");
841
842			if (surface)
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
1261