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