os/graphics/egl/egltest/src/egltest_general.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19 */
    20 
    21 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    22 #include <sgresource/sgimage.h>
    23 #else
    24 #include <graphics/sgimage.h>
    25 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    26 #include <test/tefunit.h> // for ASSERT macros
    27 #include <GLES/gl.h>
    28 
    29 #include "egltest_general.h"
    30 
    31 #include <test/egltestcommonconversion.h>
    32 #include <test/egltestcommoninisettings.h>
    33 #include <test/egltestcommonsgimageinfo.h>
    34 
    35 
    36 /**
    37 @SYMTestCaseID GRAPHICS-EGL-0005
    38 
    39 @SYMTestPriority 1
    40 
    41 @SYMPREQ 39
    42 
    43 @SYMREQ See SGL.GT0386.401 document
    44 
    45 @SYMTestCaseDesc
    46 Dump diagnostic information that may help in debugging any issues found in the other tests.
    47 This is not really a test in itself, but can be listed in the test script as a specific test step.
    48 It is expected always to pass.
    49 
    50 @SYMTestActions
    51 Repeatedly call eglQueryString() with each of the following parameters:
    52 	*	EGL_CLIENT_APIS
    53 	*	EGL_EXTENSIONS
    54 	*	EGL_VENDOR
    55 	*	EGL_VERSION
    56 For each call, dump the resulting string to the test log file.
    57 If the result of EGL_CLIENT_APIS includes "OpenVG" then bind to the OpenVG API and repeatedly call vgGetString() with each of the following parameters
    58 	*	VG_VENDOR
    59 	*	VG_RENDERER
    60 	*	VG_VERSION
    61 	*	VG_EXTENSIONS
    62 If the result of EGL_CLIENT_APIS includes "OpenGLES" then bind to the OpenGLES API and repeatedly call GetString() with each of the following parameters
    63 	*	VENDOR
    64 	*	RENDERER
    65 	*	VERSION
    66 	*	EXTENSIONS.
    67 
    68 @SYMTestExpectedResults
    69 All data will be dumped to the test log file.
    70 There are no specific pass criteria for this test case.
    71 */
    72 TVerdict CEglTest_DumpStrings::doTestStepL()
    73 	{
    74 	SetTestStepID(_L("GRAPHICS-EGL-0005"));
    75 	INFO_PRINTF1(_L("CEglTest_DumpStrings::doTestStepL"));
    76 
    77 	// Create display object
    78 	GetDisplayL();
    79 
    80 	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
    81 
    82 	// Initialise the display object
    83 	eglSess->InitializeL();
    84 
    85 	// EGL Strings
    86 	INFO_PRINTF1(_L("Dumping EGL strings"));
    87 
    88 	// Note that eglQueryString() MUST be called AFTER eglInitialize() for iDisplay
    89 	TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
    90 	DumpString(_L("EGL_CLIENT_APIS"),ptrEglClientApis);
    91 
    92 	const char* strEglExtensions = eglQueryString(iDisplay, EGL_EXTENSIONS);
    93 	ASSERT_EGL_TRUE(strEglExtensions!=NULL);
    94 	DumpString(_L("EGL_EXTENSIONS"), TPtrC8((const TText8 *)strEglExtensions));
    95 
    96 	const char* strEglVendor = eglQueryString(iDisplay, EGL_VENDOR);
    97 	ASSERT_EGL_TRUE(strEglVendor!=NULL);
    98 	DumpString(_L("EGL_VENDOR"), TPtrC8((const TText8 *)strEglVendor));
    99 
   100 	const char* strEglVersion = eglQueryString(iDisplay, EGL_VERSION);
   101 	ASSERT_EGL_TRUE(strEglVersion!=NULL);
   102 	DumpString(_L("EGL_VERSION"), TPtrC8((const TText8 *)strEglVersion));
   103 
   104 	// OpenVG Strings
   105 	if (ptrEglClientApis.Find(_L8("OpenVG")) >= 0)
   106 		{
   107 		INFO_PRINTF1(_L("Dumping OpenVG strings"));
   108 
   109 		// OpenVG needs a current VG context before it will allow the call to vgGetString
   110         EGLConfig currentConfig = eglSess->GetConfigExactMatchL(EPBufferAttribsColor64K);
   111         eglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSize, EGL_OPENVG_API);
   112 
   113 		TPtrC8 ptrVgVendor((const TText8 *)vgGetString(VG_VENDOR));
   114 		DumpString(_L("VG_VENDOR"), ptrVgVendor);
   115 
   116 		TPtrC8 ptrVgRenderer((const TText8 *)vgGetString(VG_RENDERER));
   117 		DumpString(_L("VG_RENDERER"), ptrVgRenderer);
   118 
   119 		TPtrC8 ptrVgVersion((const TText8 *)vgGetString(VG_VERSION));
   120 		DumpString(_L("VERSION"), ptrVgVersion);
   121 
   122 		TPtrC8 ptrVgExtensions((const TText8 *)vgGetString(VG_EXTENSIONS));
   123 		DumpString(_L("VG_EXTENSIONS"), ptrVgExtensions);
   124 		
   125 		//cleanup the context & surface
   126 		eglSess->CleanupSurfaceSgImageL();
   127 		}
   128 
   129 	// OpenGLES Strings
   130 	if (ptrEglClientApis.Find(_L8("OpenGL_ES")) >= 0)
   131 		{
   132 		INFO_PRINTF1(_L("Dumping OpenGLES strings"));
   133 
   134 		// OpenGLES needs a current GLES context before it will allow the call to glGetString
   135         EGLConfig currentConfig = eglSess->GetConfigExactMatchL(EPBufferAttribsColor64K);
   136         eglSess->CreatePbufferSurfaceAndMakeCurrentL(currentConfig, KPixmapSize, EGL_OPENGL_ES_API);
   137 
   138 		TPtrC8 ptrGlesVendor((const TText8 *)glGetString(GL_VENDOR));
   139 		DumpString(_L("GL_VENDOR"), ptrGlesVendor);
   140 
   141 		TPtrC8 ptrGlesRenderer((const TText8 *)glGetString(GL_RENDERER));
   142 		DumpString(_L("GL_RENDERER"), ptrGlesRenderer);
   143 
   144 		TPtrC8 ptrGlesVersion((const TText8 *)glGetString(GL_VERSION));
   145 		DumpString(_L("GL_VERSION"), ptrGlesVersion);
   146 
   147 		TPtrC8 ptrGlesExtensions((const TText8 *)glGetString(GL_EXTENSIONS));
   148 		DumpString(_L("GL_EXTENSIONS"), ptrGlesExtensions);
   149 		
   150 		//cleanup the context & surface
   151 		eglSess->CleanupSurfaceSgImageL();
   152 		}
   153 
   154 	CleanupStack::PopAndDestroy(eglSess);
   155 	TerminateDisplayL();
   156 	RecordTestResultL();
   157 	CloseTMSGraphicsStep();
   158 	return TestStepResult();
   159 	}
   160 
   161 void CEglTest_DumpStrings::DumpString(const TDesC& aField, const TDesC8& aValue)
   162 	{
   163 	const TInt KMaxValueLength = 256;
   164 	TBuf16<KMaxValueLength> bufValue;
   165 	bufValue.Copy(aValue.Left(KMaxValueLength));
   166 	INFO_PRINTF3(_L("%S: \"%S\""), &aField, &bufValue);
   167 	}
   168 
   169 /**
   170 @SYMTestCaseID GRAPHICS-EGL-0010
   171 
   172 @SYMTestPriority 1
   173 
   174 @SYMPREQ 39
   175 
   176 @SYMREQ See SGL.GT0386.401 document
   177 
   178 @SYMTestCaseDesc
   179 To ensure that eglQueryString() returns the correct information.
   180 
   181 @SYMTestActions
   182 Call eglQueryString() with the EGL_EXTENSIONS parameter
   183 
   184 @SYMTestExpectedResults
   185 The returned space separated list is expected to include the items as defined in the .ini file.
   186 This list is implementation specific, so the .ini file can be configured depending on each implementation.
   187 As an example, the following ones are expected in most EGL implementations:
   188 	*	EGL_NOK_pixmap_type_rsgimage
   189 	*	EGL_SYMBIAN_COMPOSITION
   190 	*	EGL_KHR_image_base
   191 	*	EGL_KHR_image_pixmap 	
   192 	*	EGL_KHR_reusable_sync
   193 The above list will be configurable on a per-platform basis, via an INI file.  If a platform does not support
   194 any of the above extensions then it may opt not to test for it via the INI file.
   195 */
   196 TVerdict CEglTest_QueryString_Extensions::doTestStepL()
   197 	{
   198 	SetTestStepID(_L("GRAPHICS-EGL-0010"));
   199 	INFO_PRINTF1(_L("CEglTest_QueryString_Extensions::doTestStepL"));
   200 
   201 	TInt numExtensions=0;
   202 	if (!GetIntFromConfig(ConfigSection(), KKeyCountExtensionsEGL, numExtensions))
   203 		{
   204 		ERR_PRINTF2(_L("Cannot find key '%S' in INI file"), &KKeyCountExtensionsEGL);
   205 		User::Leave(KErrArgument);
   206 		}
   207 	INFO_PRINTF2(_L("Looking for %d EGL extensions"), numExtensions);
   208 	TBuf<32> bufExtensionNameKey;
   209 	TBuf16<128> bufExtensionNameValue16;
   210 	TPtrC16 ptrExtensionNameValue16(bufExtensionNameValue16);
   211 	for(TInt i=0; i<numExtensions; i++)
   212 		{
   213 		bufExtensionNameKey.Format(KKeyExtensionEGLX, i);
   214 		if (!GetStringFromConfig(ConfigSection(), bufExtensionNameKey, ptrExtensionNameValue16))
   215 			{
   216 			ERR_PRINTF2(_L("Cannot find key '%S' in INI file"), &bufExtensionNameKey);
   217 			User::Leave(KErrArgument);
   218 			}
   219 		INFO_PRINTF2(_L("Checking for extension \"%S\""), &ptrExtensionNameValue16);
   220 		TEST(CheckForExtensionL(0, ptrExtensionNameValue16));
   221 		}
   222 
   223 	numExtensions=0;
   224 	if (!GetIntFromConfig(ConfigSection(), KKeyCountExtensionsVG, numExtensions))
   225 		{
   226 		ERR_PRINTF2(_L("Cannot find key '%S' in INI file"), &KKeyCountExtensionsVG);
   227 		User::Leave(KErrArgument);
   228 		}
   229 	INFO_PRINTF2(_L("Looking for %d VG extensions"), numExtensions);
   230 	for(TUint i=0; i<numExtensions; i++)
   231 		{
   232 		bufExtensionNameKey.Format(KKeyExtensionVGX, i);
   233 		if (!GetStringFromConfig(ConfigSection(), bufExtensionNameKey, ptrExtensionNameValue16))
   234 			{
   235 			ERR_PRINTF2(_L("Cannot find key '%S' in INI file"), &bufExtensionNameKey);
   236 			User::Leave(KErrArgument);
   237 			}
   238 		INFO_PRINTF2(_L("Checking for extension \"%S\""), &ptrExtensionNameValue16);
   239 		TEST(CheckForExtensionL(0, ptrExtensionNameValue16));
   240 		}
   241 
   242 	RecordTestResultL();
   243 	CloseTMSGraphicsStep();
   244 	return TestStepResult();
   245 	}
   246 
   247 /**
   248 @SYMTestCaseID GRAPHICS-EGL-0012
   249 
   250 @SYMTestPriority 3
   251 
   252 @SYMPREQ 39
   253 
   254 @SYMREQ ReqNum
   255 
   256 @SYMTestCaseDesc
   257 Ensure that eglGetProcAddress() returns NULL when given invalid data.
   258 
   259 @SYMTestActions
   260 Call eglGetProcAddress() with a <procname> that is known not to be supported - e.g. "qwerty"
   261 Call eglGetProcAddress() with an empty <procname> - i.e. ""
   262 Call eglGetProcAddress() with a null <procname> - i.e. NULL
   263 
   264 @SYMTestExpectedResults
   265 For each case, eglGetProcAddress() should return NULL, without raising an EGL error.
   266 */
   267 TVerdict CEglTest_General_Negative_ProcAddress::doTestStepL()
   268     {
   269     SetTestStepID(_L("GRAPHICS-EGL-0012"));
   270     INFO_PRINTF1(_L("CEglTest_General_Negative_ProcAddress::doTestStepL"));
   271 
   272     // Create display object
   273     GetDisplayL();
   274 
   275     // Initialize display object
   276     INFO_PRINTF1(_L("Calling eglInitialize"));
   277     TEST_EGL_ERROR(eglInitialize(iDisplay, NULL, NULL), EGL_SUCCESS);
   278 
   279     INFO_PRINTF1(_L("Calling eglGetProcAddress() with a 'procname' that is known not to be supported"));
   280     TEST_EGL_ERROR(eglGetProcAddress("qwerty") == NULL, EGL_SUCCESS);
   281 
   282     INFO_PRINTF1(_L("Calling eglGetProcAddress() with an empty 'procname'"));
   283     TEST_EGL_ERROR(eglGetProcAddress("") == NULL, EGL_SUCCESS);
   284 
   285     INFO_PRINTF1(_L("Calling eglGetProcAddress() with a null 'procname'"));
   286     TEST_EGL_ERROR(eglGetProcAddress(NULL) == NULL, EGL_SUCCESS);
   287 
   288     TerminateDisplayL();
   289     RecordTestResultL();
   290     CloseTMSGraphicsStep();
   291     return TestStepResult();
   292     }
   293 
   294 
   295 /**
   296 @SYMTestCaseID GRAPHICS-EGL-0309
   297 
   298 @SYMPREQ 			PREQ2650
   299 
   300 @SYMTestCaseDesc 	
   301 1. EglTerminate() with an invalid/non-existant display
   302 2. Double eglTerminate() with an uninitialised display
   303 3. Double eglTerminate() with an initialised display
   304 
   305 @SYMTestPriority 	High
   306 
   307 @SYMTestStatus 		Implemented
   308 
   309 @SYMTestActions		
   310 1. Call eglTerminate with an invalid display handle argument. Call eglTerminate with EGL_NO_DISPLAY argument
   311 2. Create an uninitialised display and call eglTerminate() twice. Re-create and terminate the display to check for memory leaks.
   312 3. Create an initialised display and call eglTerminate() twice. Re-create and terminate the display to check for memory leaks.
   313 
   314 @SYMTestExpectedResults		
   315 1. eglTerminate should return EGL_FALSE on both calls with error EGL_BAD_DISPLAY
   316 2. eglTerminate should return EGL_TRUE on all calls and the display should not be set to EGL_NO_DISPLAY.
   317 3. eglTerminate should return EGL_TRUE on all calls and the display should not be set to EGL_NO_DISPLAY.
   318 The UHEAP markers should indicate no memory leaks after this test case has run.
   319 */
   320 TVerdict CEglTest_EglTerminate_Negative::doTestStepL()
   321 	{
   322 	INFO_PRINTF1(_L("CEglTest_EglTerminate_Negative::doTestStepL"));
   323 	SetTestStepID(_L("GRAPHICS-EGL-0309"));
   324 
   325     //Test 1 - Arbitrary invalid display handle
   326     const EGLDisplay invalidDisplay = 77;
   327 
   328     //Call eglTerminate with the invalid display handle
   329     TEST(eglTerminate(invalidDisplay) == EGL_FALSE);
   330     ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   331 
   332     //Call eglTerminate with argument EGL_NO_DISPLAY
   333     TEST(eglTerminate(EGL_NO_DISPLAY) == EGL_FALSE);
   334     ASSERT_EGL_ERROR(EGL_BAD_DISPLAY);
   335 
   336     //Test 2 - Create display object
   337     iDisplay = EGL_NO_DISPLAY;
   338     GetDisplayL();
   339 
   340 	//Call eglTerminate twice
   341     ASSERT_EGL_TRUE(eglTerminate(iDisplay));
   342     TEST(eglGetError() == EGL_SUCCESS);
   343 
   344     ASSERT_EGL_TRUE(eglTerminate(iDisplay));
   345     TEST(eglGetError() == EGL_SUCCESS);
   346 
   347     //Recreate display object and call eglTerminate()
   348     iDisplay = EGL_NO_DISPLAY;
   349     GetDisplayL();
   350     ASSERT_EGL_TRUE(eglTerminate(iDisplay));
   351     TEST(eglGetError() == EGL_SUCCESS);
   352 
   353     //Test 3
   354     iDisplay = EGL_NO_DISPLAY;
   355     GetDisplayL();
   356     CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, 0);
   357 
   358     // Initialise the display object
   359     eglSess->InitializeL();
   360 
   361     //Call eglTerminate twice
   362     ASSERT_EGL_TRUE(eglTerminate(iDisplay));
   363     TEST(eglGetError() == EGL_SUCCESS);
   364 
   365     ASSERT_EGL_TRUE(eglTerminate(iDisplay));
   366     TEST(eglGetError() == EGL_SUCCESS);
   367 
   368     //Recreate display object
   369     iDisplay = EGL_NO_DISPLAY;
   370     GetDisplayL();
   371 
   372     //Call eglTerminate
   373     ASSERT_EGL_TRUE(eglTerminate(iDisplay));
   374     TEST(eglGetError() == EGL_SUCCESS);
   375 
   376     //cleanup and stuff...
   377     CleanupStack::PopAndDestroy(1, eglSess);
   378     ASSERT_EGL_TRUE(eglReleaseThread());
   379 
   380     RecordTestResultL();
   381     CloseTMSGraphicsStep();
   382     return TestStepResult();
   383 	}