os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tgraphicsresourcesecondprocess.cpp
Update contrib.
1 // Copyright (c) 2007-2010 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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Graphics Resource API Conformance Test Suite
23 #include "tgraphicsresourcemultiprocessthread.h"
24 #include "tgraphicsresourceteststepbase.h"
27 Helper function to test the equivalence of two TSgImageInfo structures.
29 @param aInfo1 A TSgImageInfo structure to compare.
30 @param aInfo2 A TSgImageInfo structure to compare.
32 @return ETrue if the two are identical, EFalse otherwise.
34 TBool CompareInfos(TSgImageInfo& aInfo1, TSgImageInfo& aInfo2)
36 TBool result = EFalse;
37 if(aInfo1.iPixelFormat == aInfo2.iPixelFormat
38 && aInfo1.iSizeInPixels == aInfo2.iSizeInPixels
39 && aInfo1.iUsage == aInfo2.iUsage)
47 Opens an image in a different process.
48 @param aInfo The test information passed from outside the current thread
49 @return The test result indicating which tests passed
51 TInt TestOpenImageL(TSgProcessTestInfo& aInfo)
53 TSgDrawableId id = aInfo.iDrawableId;
54 TSgImageInfo imageInfo1 = aInfo.iImageInfo;
59 if(KErrNone == image.Open(id))
61 result |= EFirstTestPassed;
64 TSgImageInfo imageInfo2;
65 TInt attribVal = KMaxTInt;
66 if(KErrNone == image.GetInfo(imageInfo2))
68 result |= ESecondTestPassed;
70 if(CompareInfos(imageInfo1, imageInfo2))
72 result |= EThirdTestPassed;
74 if (image.Id() != KSgNullDrawableId)
76 result |= EFourthTestPassed;
80 result |= EFifthTestPassed;
82 TUid uid = { 0x12345678 };
83 if (KErrNotSupported == image.GetAttribute(uid, attribVal))
85 result |= ESixthTestPassed;
87 if (KErrArgument == image.GetAttribute(KNullUid, attribVal))
89 result |= ESeventhTestPassed;
97 Opens an image in a different process into a RSgDrawable object.
98 @param aInfo The test information passed from outside the current thread
99 @return The test result indicating which tests passed
101 TInt TestOpenDrawableL(TSgProcessTestInfo& aInfo)
103 TSgDrawableId id = aInfo.iDrawableId;
105 RSgDrawable drawable;
108 if(KErrNone == drawable.Open(id))
110 result |= EFirstTestPassed;
112 TSgDrawableId id2 = drawable.Id();
113 if(id2 != KSgNullDrawableId)
115 result |= ESecondTestPassed;
119 result |= EThirdTestPassed;
127 Opens an image in a different process with different invalid operations.
128 @param aInfo The test information passed from outside the current thread
129 @return The test result indicating which tests passed
131 TInt TestOpenImageInvalidL(TSgProcessTestInfo& aInfo)
133 TSgDrawableId id = aInfo.iDrawableId;
134 TSgImageInfo imageInfo = aInfo.iImageInfo;
140 if(KErrNone == image.Create(imageInfo, NULL, 0))
142 result |= EFirstTestPassed;
145 if(KErrInUse == image.Open(id))
147 result |= ESecondTestPassed;
152 if(KErrArgument == image.Open(KSgNullDrawableId))
154 result |= EThirdTestPassed;
158 // non-existing drawable id
159 TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU};
160 if(KErrNotFound == image.Open(fakeid))
162 result |= EFourthTestPassed;
167 if (KErrNone == image.Open(id))
169 result |= EFifthTestPassed;
176 Opens a drawable in a different process with different invalid operations.
177 @param aInfo The test information passed from outside the current thread
178 @return The test result indicating which tests passed
180 TInt TestOpenDrawableInvalidL()
182 RSgDrawable drawable;
186 if(KErrArgument == drawable.Open(KSgNullDrawableId))
188 result |= EFirstTestPassed;
192 //non-existing drawable id
193 TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU};
194 if(KErrNotFound == drawable.Open(fakeid))
196 result |= ESecondTestPassed;
203 info1.iSizeInPixels = TSize(8, 8);
204 info1.iUsage = ESgUsageBitOpenVgImage;
205 info1.iPixelFormat = EUidPixelFormatRGB_565;
209 TInt err = image.Create(info1, NULL, 0);
210 if(KErrNoMemory == err)
212 result = KErrNoMemory;
214 else if(KErrNone != err)
220 if(KErrNone == drawable.Open(image.Id()))
222 result |= EThirdTestPassed;
224 if (KErrInUse == drawable.Open(image.Id()))
226 result |= EFourthTestPassed;
235 TInt TestCloseDriverOpenResources(RSgDriver& aDriver)
239 info1.iSizeInPixels = TSize(8, 8);
240 info1.iUsage = ESgUsageBitOpenVgImage;
241 info1.iPixelFormat = EUidPixelFormatRGB_565;
243 TInt result = image.Create(info1, KCrossImageData, KCrossImageDataStride);
245 if (result == KErrNone)
247 //Close the driver without closing the image.
248 aDriver.Close(); //Should panic with SGRES2
255 Method executed by secondary thread for test TestOpenImageMulththreadedL
257 _LIT(KTestOpenImageMultithreadedSem1, "TestOpenImageMultithreadedSem1");
258 _LIT(KTestOpenImageMultithreadedSem2, "TestOpenImageMultithreadedSem2");
260 TInt OpenImageMultiSecondThread(TAny* aAny)
263 TSgProcessTestInfo* info = static_cast<TSgProcessTestInfo*>(aAny);
266 err = sem[0].OpenGlobal(KTestOpenImageMultithreadedSem1, EOwnerThread);
271 err = sem[1].OpenGlobal(KTestOpenImageMultithreadedSem2, EOwnerThread);
279 err = sgImage.Open(info->iDrawableId);
290 Creates a second thread which will initially open a handle to the passed TSgDrawableId.
291 The main thread then opens a new handle to the image.
292 The second thread will then close its handle to the image.
293 The main thread will then attempt to access the data of the image.
295 TInt TestOpenImageMultithreadedL(TSgProcessTestInfo& aInfo)
299 //create two semaphores
301 User::LeaveIfError(sem[0].CreateGlobal(KTestOpenImageMultithreadedSem1, 0, EOwnerThread));
302 CleanupClosePushL(sem[0]);
303 User::LeaveIfError(sem[1].CreateGlobal(KTestOpenImageMultithreadedSem2, 0, EOwnerThread));
304 CleanupClosePushL(sem[1]);
306 //create secondary thread
307 _LIT(KSecondaryThreadName, "TestOpenImageMultithreadedL");
309 User::LeaveIfError(thread.Create(KSecondaryThreadName, OpenImageMultiSecondThread, KDefaultStackSize, KSecondThreadMinHeapSize, KSecondThreadMaxHeapSize, &aInfo));
312 // Make the second thread open the image before this thread.
315 // Second thread has opened image, now primary thread opens image
317 TInt err = sgImage.Open(aInfo.iDrawableId);
318 CleanupClosePushL(sgImage);
322 // Second thread has closed image and terminated, now wait for thread to clean-up
327 // Do something that requires data access of sgImage, in this case, creating a copy.
328 result |= EFirstTestPassed;
329 RSgImage sgImageCopy;
330 err = sgImageCopy.Create(aInfo.iImageInfo, sgImage);
334 result |= ESecondTestPassed;
338 CleanupStack::PopAndDestroy(3); // sgImage, sem[0], sem[1]
344 TPckgBuf<TSgProcessTestInfo> infoPkg;
345 User::LeaveIfError(User::GetDesParameter(KSecondProcessParametersSlot, infoPkg));
346 TSgProcessTestInfo& info = infoPkg();
347 TSgresTestCase testCase = info.iTestCase;
351 CleanupClosePushL(sgDriver);
353 if(KErrNone == sgDriver.Open())
357 case ESgresSecondProcessOpenImage:
358 result = TestOpenImageL(info);
360 case ESgresSecondProcessOpenDrawable:
361 result = TestOpenDrawableL(info);
363 case ESgresSecondProcessOpenImageInvalid:
364 result = TestOpenImageInvalidL(info);
366 case ESgresSecondProcessOpenDrawableInvalid:
367 result = TestOpenDrawableInvalidL();
369 case ESgresSecondProcessPanicDriverCloseOpenResources:
370 result = TestCloseDriverOpenResources(sgDriver);
372 case ESgresSecondProcessOpenImageMultithreaded:
373 result = TestOpenImageMultithreadedL(info);
378 CleanupStack::PopAndDestroy(&sgDriver);
383 GLDEF_C TInt E32Main()
386 CTrapCleanup* cleanupStack = CTrapCleanup::New();
387 if(cleanupStack == NULL)
392 TRAP_IGNORE(ret=MainL());