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