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