graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourcesecondprocess.cpp
changeset 103 2717213c588a
parent 36 01a6848ebfd7
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    34 TBool CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
    34 TBool CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
    35 	{
    35 	{
    36 	TBool result = EFalse;
    36 	TBool result = EFalse;
    37 	if(aInfo1.iPixelFormat == aInfo2.iPixelFormat
    37 	if(aInfo1.iPixelFormat == aInfo2.iPixelFormat
    38 		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
    38 		&& aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
    39 		&& aInfo1.iUsage | aInfo2.iUsage)
    39 		&& aInfo1.iUsage == aInfo2.iUsage)
    40 		{
    40 		{
    41 		result = ETrue;
    41 		result = ETrue;
    42 		}
    42 		}
    43 	return result;
    43 	return result;
    44 	}
    44 	}
    77 		}
    77 		}
    78 	if(image.Id() == id)
    78 	if(image.Id() == id)
    79 		{
    79 		{
    80 		result |= EFifthTestPassed;
    80 		result |= EFifthTestPassed;
    81 		}
    81 		}
    82 	if (id == aInfo.iDrawableId)
       
    83 		{
       
    84 		result |= ESixthTestPassed;
       
    85 		}	
       
    86 	TUid uid = { 0x12345678 };
    82 	TUid uid = { 0x12345678 };
    87 	if (KErrNotSupported == image.GetAttribute(uid, attribVal))
    83 	if (KErrNotSupported == image.GetAttribute(uid, attribVal))
    88 	    {
    84 	    {
    89 	    result |= ESeventhTestPassed;
    85 	    result |= ESixthTestPassed;
    90 	    }
    86 	    }
    91 	if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
    87 	if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
    92 	    {
    88 	    {
    93 	    result |= EEighthTestPassed;
    89 	    result |= ESeventhTestPassed;
    94 	    }
    90 	    }
    95 	image.Close();
    91 	image.Close();
    96 
    92 
    97 	return result;
    93 	return result;
    98 	}
    94 	}
   256 	}
   252 	}
   257 
   253 
   258 /**
   254 /**
   259 Method executed by secondary thread for test TestOpenImageMulththreadedL
   255 Method executed by secondary thread for test TestOpenImageMulththreadedL
   260 */
   256 */
   261 _LIT(KTestOpenImageMultithreadedSem1, "TestOpenImageMulththreadedSem1");
   257 _LIT(KTestOpenImageMultithreadedSem1, "TestOpenImageMultithreadedSem1");
   262 _LIT(KTestOpenImageMultithreadedSem2, "TestOpenImageMulththreadedSem2");
   258 _LIT(KTestOpenImageMultithreadedSem2, "TestOpenImageMultithreadedSem2");
   263 
   259 
   264 TInt OpenImageMultiSecondThread(TAny* aAny)
   260 TInt OpenImageMultiSecondThread(TAny* aAny)
   265 	{
   261 	{
   266 	TInt err = KErrNone;
   262 	TInt err = KErrNone;
   267 	TSgProcessTestInfo* info = static_cast<TSgProcessTestInfo*>(aAny);	
   263 	TSgProcessTestInfo* info = static_cast<TSgProcessTestInfo*>(aAny);	
   294 Creates a second thread which will initially open a handle to the passed TSgDrawableId.
   290 Creates a second thread which will initially open a handle to the passed TSgDrawableId.
   295 The main thread then opens a new handle to the image.
   291 The main thread then opens a new handle to the image.
   296 The second thread will then close its handle to the image.
   292 The second thread will then close its handle to the image.
   297 The main thread will then attempt to access the data of the image.
   293 The main thread will then attempt to access the data of the image.
   298  */
   294  */
   299 TInt TestOpenImageMulththreadedL(TSgProcessTestInfo& aInfo)
   295 TInt TestOpenImageMultithreadedL(TSgProcessTestInfo& aInfo)
   300 	{
   296 	{
   301 	TInt result = 0;
   297 	TInt result = 0;
   302 	
   298 	
   303 	//create a semaphore
   299 	//create two semaphores
   304 	RSemaphore sem[2];
   300 	RSemaphore sem[2];
   305 	User::LeaveIfError(sem[0].CreateGlobal(KTestOpenImageMultithreadedSem1, 0, EOwnerThread));
   301 	User::LeaveIfError(sem[0].CreateGlobal(KTestOpenImageMultithreadedSem1, 0, EOwnerThread));
   306 	CleanupClosePushL(sem[0]);
   302 	CleanupClosePushL(sem[0]);
   307 	User::LeaveIfError(sem[1].CreateGlobal(KTestOpenImageMultithreadedSem2, 0, EOwnerThread));
   303 	User::LeaveIfError(sem[1].CreateGlobal(KTestOpenImageMultithreadedSem2, 0, EOwnerThread));
   308 	CleanupClosePushL(sem[1]);
   304 	CleanupClosePushL(sem[1]);
   309 		
   305 		
   310 	//create secondary thread
   306 	//create secondary thread
   311 	_LIT(KMultipleThreadName, "TestOpenImageMulththreadedL");
   307 	_LIT(KSecondaryThreadName, "TestOpenImageMultithreadedL");
   312 	RThread thread;
   308 	RThread thread;
   313 	TBuf<50> threadName(KMultipleThreadName);
   309 	User::LeaveIfError(thread.Create(KSecondaryThreadName, OpenImageMultiSecondThread, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aInfo));
   314 	User::LeaveIfError(thread.Create(threadName, OpenImageMultiSecondThread, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aInfo));
       
   315 	thread.Resume();
   310 	thread.Resume();
   316 	
   311 	
   317 	// Make the second thread open the image before this thread.
   312 	// Make the second thread open the image before this thread.
   318 	sem[0].Wait();
   313 	sem[0].Wait();
   319 
   314 
   373 				break;
   368 				break;
   374 			case ESgresSecondProcessPanicDriverCloseOpenResources:
   369 			case ESgresSecondProcessPanicDriverCloseOpenResources:
   375 				result = TestCloseDriverOpenResources(sgDriver);
   370 				result = TestCloseDriverOpenResources(sgDriver);
   376 				break;
   371 				break;
   377 			case ESgresSecondProcessOpenImageMultithreaded:
   372 			case ESgresSecondProcessOpenImageMultithreaded:
   378 				result = TestOpenImageMulththreadedL(info);
   373 				result = TestOpenImageMultithreadedL(info);
   379 				break;
   374 				break;
   380 			}
   375 			}
   381 		}	
   376 		}	
   382 	
   377 	
   383 	CleanupStack::PopAndDestroy(&sgDriver);
   378 	CleanupStack::PopAndDestroy(&sgDriver);