graphicsresourceservices/graphicsresource/test/tsgdrawablegeneric.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include "tsgdrawablegeneric.h"
       
    23 #include <graphics/sgresourceinternal.h>
       
    24 
       
    25 CTSgDrawableGeneric::CTSgDrawableGeneric()
       
    26 	{
       
    27 	INFO_PRINTF1(_L("Graphics resource component test - RSgDrawable Generic Tests.\r\n"));
       
    28 	}
       
    29 
       
    30 CTSgDrawableGeneric::~CTSgDrawableGeneric()
       
    31 	{
       
    32 	}
       
    33 
       
    34 /** 
       
    35 Overrides of base class pure virtual
       
    36 Our implementation only gets called if the base class doTestStepPreambleL() did
       
    37 not leave. That being the case, the current test result value will be EPass.
       
    38 @leave Gets system wide error code
       
    39 @return TVerdict code
       
    40 */
       
    41 TVerdict CTSgDrawableGeneric::doTestStepL()
       
    42 	{
       
    43 	SetTestStepID(_L("GRAPHICS-RESOURCE-0013"));
       
    44 	INFO_PRINTF1(_L("Opening an image in RSgDrawable.\r\n"));
       
    45 	TestOpenImageAsDrawableL();
       
    46 	RecordTestResultL();
       
    47 		
       
    48 	SetTestStepID(_L("GRAPHICS-RESOURCE-0014"));
       
    49 	INFO_PRINTF1(_L("Retrieving drawable id of an RSgDrawable object.\r\n"));
       
    50 	TestGetDrawableDrawableIdL();
       
    51 	RecordTestResultL();
       
    52 	
       
    53 	SetTestStepID(_L("GRAPHICS-RESOURCE-0032"));
       
    54 	INFO_PRINTF1(_L("RSgDrawable::Open() with invalid parameters.\r\n"));
       
    55 	TestOpenDrawableInvalidL();
       
    56 	RecordTestResultL();
       
    57 
       
    58 	SetTestStepID(_L("GRAPHICS-RESOURCE-0033"));
       
    59 	INFO_PRINTF1(_L("Releasing reference to the image in RSgDrawable without first opening it.\r\n"));
       
    60 	TestCloseDrawableWithoutOpenL();
       
    61 	RecordTestResultL();
       
    62 	
       
    63 #ifdef _DEBUG
       
    64 /**
       
    65 @SYMTestCaseID			GRAPHICS-RESOURCE-0081
       
    66 */
       
    67 	SetTestStepID(_L("GRAPHICS-RESOURCE-0081"));		
       
    68 	INFO_PRINTF1(_L("RSgDrawable generic out of memory tests.\r\n"));
       
    69 	TestOOM();
       
    70 	RecordTestResultL();
       
    71 	
       
    72 	SetTestStepID(_L("GRAPHICS-RESOURCE-0080"));	
       
    73 	INFO_PRINTF1(_L("RSgDrawable generic panic test - Open() when the driver is not initialised.\r\n"));
       
    74 	TestPanicDrawableOpenNoDriverL();
       
    75 	RecordTestResultL();
       
    76 #else
       
    77 	INFO_PRINTF1(_L("Warning: Skipping the panic tests in release build. \r\n"));
       
    78 #endif
       
    79 
       
    80 	return TestStepResult();
       
    81 	}
       
    82 
       
    83 
       
    84 /**
       
    85 @SYMTestCaseID			GRAPHICS-RESOURCE-0013
       
    86 @SYMTestCaseDesc		Opens an RSgImage as an RSgDrawable.
       
    87 @SYMPREQ				PREQ39
       
    88 @SYMREQ 				REQ9225
       
    89 @SYMREQ					REQ9224 
       
    90 @SYMREQ					REQ9233  
       
    91 @SYMREQ					REQ9234
       
    92 @SYMFssID				RSgImage::Id()\n 
       
    93 						RSgDrawable::Open(const TSgDrawableId&)
       
    94 @SYMTestPriority		Critical
       
    95 @SYMTestType			Unit Test
       
    96 @SYMTestPurpose			To ensure an RSgDrawable object can reference an image.
       
    97 @SYMTestActions			Initialise the graphics resource component. Create an image. Declare an
       
    98 						RSgDrawable object. Call Open() on the object with the resource ID of the
       
    99 						image.
       
   100 @SYMTestExpectedResults	The function should return KErrNone. The RSgDrawable now references an
       
   101 						image.
       
   102 @SYMTestStatus			Implemented 
       
   103  */	
       
   104 void CTSgDrawableGeneric::TestOpenImageAsDrawableL()
       
   105 	{
       
   106 	TestOpenDriverL();
       
   107 	RSgImage image;
       
   108 	CreateImageL(image);
       
   109 	CleanupClosePushL(image);
       
   110 	const TSgDrawableId id = image.Id();
       
   111 	TSgImageInfo imageinfo;
       
   112 	image.GetInfo(imageinfo);
       
   113 	
       
   114 	//opening an image as a drawable in the current thread
       
   115 	RSgImage drawable;
       
   116 	TEST(drawable.IsNull());
       
   117 	CheckErrorL(KErrNone, drawable.Open(id), (TText8*)__FILE__, __LINE__);
       
   118 	TEST(!drawable.IsNull());
       
   119 	drawable.Close();
       
   120 	
       
   121 	//opening an image as a drawable in another thread in the same process
       
   122 	TSgresTestInfo threadInfo = {id, imageinfo, 0, ESgresSecondThreadOpenDrawable};
       
   123 	TInt testResult = CreateSecondThreadAndDoTestL(threadInfo);
       
   124 	User::LeaveIfError(testResult);	
       
   125 	TEST(testResult & EFirstTestPassed);
       
   126 	TEST(testResult & ESecondTestPassed);
       
   127 	TEST(testResult & EThirdTestPassed);
       
   128 	
       
   129 	//opening an image as drawbale in a different process
       
   130 	TSgresTestInfo processInfo = {id, imageinfo, 0, ESgresSecondProcessOpenDrawable};
       
   131 	testResult = CreateSecondProcessAndDoTestL(KSecondProcess, processInfo);	
       
   132 	User::LeaveIfError(testResult);
       
   133 	TEST(testResult & EFirstTestPassed);	
       
   134 	TEST(testResult & ESecondTestPassed);	
       
   135 	TEST(testResult & EThirdTestPassed);	
       
   136 
       
   137 	CleanupStack::PopAndDestroy();
       
   138 	TestCloseDriver();
       
   139 	}
       
   140 
       
   141 /**
       
   142 @SYMTestCaseID			GRAPHICS-RESOURCE-0014
       
   143 @SYMTestCaseDesc		Retrieves drawable id of an RSgDrawable.
       
   144 @SYMPREQ				PREQ39
       
   145 @SYMREQ 				REQ9225
       
   146 @SYMREQ					REQ9224 
       
   147 @SYMREQ					REQ9233  
       
   148 @SYMREQ					REQ9234
       
   149 @SYMFssID				RSgImage::Id()\n 
       
   150 						RSgDrawable::Open(const TSgDrawableId&)\n 
       
   151 						RSgDrawable::Id()
       
   152 @SYMTestPriority		Critical
       
   153 @SYMTestType			Unit Test
       
   154 @SYMTestPurpose			To ensure the globally unique drawable id of the RSgDrawable object can be retrieved.
       
   155 @SYMTestActions			Initialise the graphics resource component. Create an image. Call Id() on the image.
       
   156 						Construct an RSgDrawable object and open an image in it. Call Id() on the
       
   157 						RSgDrawable object. Compare the two ids.
       
   158 @SYMTestExpectedResults	The two drawable ids should be identical.
       
   159 @SYMTestStatus			Implemented 
       
   160  */	
       
   161 void CTSgDrawableGeneric::TestGetDrawableDrawableIdL()
       
   162 	{
       
   163 	TestOpenDriverL();
       
   164 	RSgImage image;
       
   165 	CreateImageL(image);
       
   166 	CleanupClosePushL(image);
       
   167 	TSgDrawableId id1 = image.Id();
       
   168 	TEST(id1 != KSgNullDrawableId);
       
   169 	
       
   170 	RSgDrawable drawable;
       
   171 	TEST(KErrNone == drawable.Open(id1));
       
   172 	TSgDrawableId id2 = drawable.Id();
       
   173 	TEST(id2 != KSgNullDrawableId);
       
   174 	TEST(id1 == id2);	
       
   175 	
       
   176 	drawable.Close();
       
   177 	CleanupStack::PopAndDestroy();
       
   178 	TestCloseDriver();
       
   179 	}
       
   180 
       
   181 
       
   182 /**
       
   183 @SYMTestCaseID			GRAPHICS-RESOURCE-0032
       
   184 @SYMTestCaseDesc		Calls RSgDrawable::Open() with invalid parameters.
       
   185 @SYMPREQ				PREQ39
       
   186 @SYMREQ 				REQ9225
       
   187 @SYMREQ					REQ9224 
       
   188 @SYMREQ					REQ9233  
       
   189 @SYMREQ					REQ9234
       
   190 @SYMFssID				RSgImage::Id()\n 
       
   191 						RSgDrawable::Open(const TSgDrawableId&)
       
   192 @SYMTestPriority		Critical
       
   193 @SYMTestType			Unit Test
       
   194 @SYMTestPurpose			To check the correct error codes are returned if Open() uses invalid parameters.
       
   195 @SYMTestActions			Initialise the graphics resource component. Create an image. Declare an RSgDrawable 
       
   196 						object. Call Open() with:\n
       
   197 						\t 1. null drawable id\n
       
   198 						\t 2. a non-existing \n
       
   199 						\t 3. drawable id of a non-sharable image\n 
       
   200 						\t 4. on a RSgDrawable handle that is not null\n
       
   201 						Do the same tests in a second thread in the same process and in a second process.
       
   202 @SYMTestExpectedResults	The function should return:\n
       
   203 						\t 1. KErrArgument\n
       
   204 						\t 2. KErrNotFound\n
       
   205 						\t 3. KErrNone in the same process and KErrPermissionDenied or KErrNotFound in the second process\n
       
   206 						\t 4. KErrInUse
       
   207 @SYMTestStatus			Implemented 
       
   208  */	
       
   209 void CTSgDrawableGeneric::TestOpenDrawableInvalidL()
       
   210 	{		
       
   211 	TestOpenDriverL();	
       
   212 	//same thread
       
   213 	//  null drawable id
       
   214 	RSgDrawable drawable;
       
   215 	CheckErrorL(KErrArgument, drawable.Open(KSgNullDrawableId), (TText8*)__FILE__, __LINE__);
       
   216 	drawable.Close();
       
   217 	
       
   218 	//  non-existing drawable id
       
   219 	TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
       
   220 	CheckErrorL(KErrNotFound, drawable.Open(fakeid), (TText8*)__FILE__, __LINE__);
       
   221 	drawable.Close();
       
   222 	
       
   223 	//create a non-sharable image
       
   224 	TSgImageInfo info;
       
   225 	info.iSizeInPixels = TSize(8, 8);
       
   226 	info.iUsage = ESgUsageDirectGdiTarget;
       
   227 	info.iPixelFormat = EUidPixelFormatRGB_565;
       
   228 	info.iCpuAccess = ESgCpuAccessNone;
       
   229 	info.iShareable = EFalse;
       
   230 	
       
   231 	RSgImage image;
       
   232 	CheckErrorL(KErrNone, image.Create(info, KImageData, 16), (TText8*)__FILE__, __LINE__);
       
   233 	CleanupClosePushL(image);
       
   234 	const TSgDrawableId id = image.Id();	
       
   235 	
       
   236 	//  open a non-sharable image - should succeed
       
   237 	TEST(KErrNone == drawable.Open(id));
       
   238 	
       
   239 	//  open on a non-null RSgDrawable handle
       
   240 	TEST(KErrInUse == drawable.Open(id));
       
   241 	drawable.Close();	
       
   242 	
       
   243 	//different thread in the same process
       
   244 	TSgresTestInfo threadInfo = {id, info, 0, ESgresSecondThreadOpenDrawableInvalid};
       
   245 	TInt testResult = CreateSecondThreadAndDoTestL(threadInfo);
       
   246 	User::LeaveIfError(testResult);
       
   247 	TEST(testResult & EFirstTestPassed);
       
   248 	TEST(testResult & ESecondTestPassed);
       
   249 	TEST(testResult & EThirdTestPassed);
       
   250 	TEST(testResult & EFourthTestPassed);	
       
   251 	
       
   252 	//different process
       
   253 	TSgresTestInfo processInfo = {id, info, 0, ESgresSecondProcessOpenDrawableInvalid};
       
   254 	testResult = CreateSecondProcessAndDoTestL(KSecondProcess, processInfo);
       
   255 	User::LeaveIfError(testResult);
       
   256 	TEST(testResult & EFirstTestPassed);
       
   257 	TEST(testResult & ESecondTestPassed);
       
   258 	TEST(testResult & EThirdTestPassed);
       
   259 	TEST(testResult & EFourthTestPassed);
       
   260 	TEST(testResult & EFifthTestPassed);
       
   261 
       
   262 	drawable.Close();
       
   263 	CleanupStack::PopAndDestroy();
       
   264 	TestCloseDriver();
       
   265 	}
       
   266 
       
   267 /**
       
   268 @SYMTestCaseID			GRAPHICS-RESOURCE-0033
       
   269 @SYMTestCaseDesc		Closes RSgDrawable without first opening it.
       
   270 @SYMPREQ				PREQ39
       
   271 @SYMREQ 				REQ9225
       
   272 @SYMREQ					REQ9224 
       
   273 @SYMREQ					REQ9233  
       
   274 @SYMREQ					REQ9234
       
   275 @SYMFssID				RSgDrawable::Close()
       
   276 @SYMTestPriority		Critical
       
   277 @SYMTestType			Unit Test
       
   278 @SYMTestPurpose			To check the function does nothing if Open() was not called.
       
   279 @SYMTestActions			Initialise the graphics resource component. Declare an RSgDrawable object. Call Close().
       
   280 @SYMTestExpectedResults	The function should not panic or return any error.
       
   281 @SYMTestStatus			Implemented 
       
   282  */	
       
   283 void CTSgDrawableGeneric::TestCloseDrawableWithoutOpenL()
       
   284 	{
       
   285 	TestOpenDriverL();	
       
   286 	RSgDrawable drawable;
       
   287 	drawable.Close();
       
   288 	drawable.Close();
       
   289 	drawable.Close();	
       
   290 	TestCloseDriver();
       
   291 	}
       
   292 
       
   293 /**
       
   294 @SYMTestCaseID			GRAPHICS-RESOURCE-0080
       
   295 @SYMTestCaseDesc		Calls RSgDrawable::Open() when the driver was not initialised.
       
   296 @SYMPREQ				PREQ39
       
   297 @SYMREQ 				REQ8809
       
   298 @SYMREQ 				REQ9175
       
   299 @SYMFssID				RSgImage::Open()\n 
       
   300 @SYMTestPriority		Critical
       
   301 @SYMTestType			Unit Test
       
   302 @SYMTestPurpose			To ensure calling RSgDrawable::Open() with an uninitialised driver will cause a panic.
       
   303 @SYMTestActions			Do not Initialise the graphics resource component and call RSgDrawable::Open() in a second thread.
       
   304 @SYMTestExpectedResults The function should panic in the second thread with panic code SGRES 5 (ESgPanicNoDriver).
       
   305 @SYMTestStatus			Implemented 
       
   306  */
       
   307 void CTSgDrawableGeneric::TestPanicDrawableOpenNoDriverL()
       
   308 	{
       
   309 	TSgImageInfo info;
       
   310 	TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicDrawableOpenNoDriver, ETrue};
       
   311  	TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
       
   312 	_LIT(KTestName, "TestPanicDrawableOpenNoDriverL");
       
   313  	CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName);
       
   314 	}
       
   315 
       
   316 void CTSgDrawableGeneric::DoMemoryTestsL()
       
   317 	{
       
   318 	__UHEAP_MARK; SgDriver::AllocMarkStart();
       
   319 	TestOpenImageAsDrawableL();
       
   320 	__UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
       
   321 	
       
   322 	__UHEAP_MARK; SgDriver::AllocMarkStart();
       
   323 	TestGetDrawableDrawableIdL();
       
   324 	__UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
       
   325 	
       
   326 	__UHEAP_MARK; SgDriver::AllocMarkStart();
       
   327 	TestOpenDrawableInvalidL();
       
   328 	__UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
       
   329 	
       
   330 	__UHEAP_MARK; SgDriver::AllocMarkStart();
       
   331 	TestCloseDrawableWithoutOpenL();
       
   332 	__UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
       
   333 	}