os/graphics/graphicsresourceservices/graphicsresource/test/tsgdrawablegeneric.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
22 #include "tsgdrawablegeneric.h"
23 #include <graphics/sgresourceinternal.h>
25 CTSgDrawableGeneric::CTSgDrawableGeneric()
27 INFO_PRINTF1(_L("Graphics resource component test - RSgDrawable Generic Tests.\r\n"));
30 CTSgDrawableGeneric::~CTSgDrawableGeneric()
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
41 TVerdict CTSgDrawableGeneric::doTestStepL()
43 SetTestStepID(_L("GRAPHICS-RESOURCE-0013"));
44 INFO_PRINTF1(_L("Opening an image in RSgDrawable.\r\n"));
45 TestOpenImageAsDrawableL();
48 SetTestStepID(_L("GRAPHICS-RESOURCE-0014"));
49 INFO_PRINTF1(_L("Retrieving drawable id of an RSgDrawable object.\r\n"));
50 TestGetDrawableDrawableIdL();
53 SetTestStepID(_L("GRAPHICS-RESOURCE-0032"));
54 INFO_PRINTF1(_L("RSgDrawable::Open() with invalid parameters.\r\n"));
55 TestOpenDrawableInvalidL();
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();
65 @SYMTestCaseID GRAPHICS-RESOURCE-0081
67 SetTestStepID(_L("GRAPHICS-RESOURCE-0081"));
68 INFO_PRINTF1(_L("RSgDrawable generic out of memory tests.\r\n"));
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();
77 INFO_PRINTF1(_L("Warning: Skipping the panic tests in release build. \r\n"));
80 return TestStepResult();
85 @SYMTestCaseID GRAPHICS-RESOURCE-0013
86 @SYMTestCaseDesc Opens an RSgImage as an RSgDrawable.
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
100 @SYMTestExpectedResults The function should return KErrNone. The RSgDrawable now references an
102 @SYMTestStatus Implemented
104 void CTSgDrawableGeneric::TestOpenImageAsDrawableL()
109 CleanupClosePushL(image);
110 const TSgDrawableId id = image.Id();
111 TSgImageInfo imageinfo;
112 image.GetInfo(imageinfo);
114 //opening an image as a drawable in the current thread
116 TEST(drawable.IsNull());
117 CheckErrorL(KErrNone, drawable.Open(id), (TText8*)__FILE__, __LINE__);
118 TEST(!drawable.IsNull());
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);
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);
137 CleanupStack::PopAndDestroy();
142 @SYMTestCaseID GRAPHICS-RESOURCE-0014
143 @SYMTestCaseDesc Retrieves drawable id of an RSgDrawable.
149 @SYMFssID RSgImage::Id()\n
150 RSgDrawable::Open(const TSgDrawableId&)\n
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
161 void CTSgDrawableGeneric::TestGetDrawableDrawableIdL()
166 CleanupClosePushL(image);
167 TSgDrawableId id1 = image.Id();
168 TEST(id1 != KSgNullDrawableId);
170 RSgDrawable drawable;
171 TEST(KErrNone == drawable.Open(id1));
172 TSgDrawableId id2 = drawable.Id();
173 TEST(id2 != KSgNullDrawableId);
177 CleanupStack::PopAndDestroy();
183 @SYMTestCaseID GRAPHICS-RESOURCE-0032
184 @SYMTestCaseDesc Calls RSgDrawable::Open() with invalid parameters.
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
205 \t 3. KErrNone in the same process and KErrPermissionDenied or KErrNotFound in the second process\n
207 @SYMTestStatus Implemented
209 void CTSgDrawableGeneric::TestOpenDrawableInvalidL()
214 RSgDrawable drawable;
215 CheckErrorL(KErrArgument, drawable.Open(KSgNullDrawableId), (TText8*)__FILE__, __LINE__);
218 // non-existing drawable id
219 TSgDrawableId fakeid = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
220 CheckErrorL(KErrNotFound, drawable.Open(fakeid), (TText8*)__FILE__, __LINE__);
223 //create a non-sharable image
225 info.iSizeInPixels = TSize(8, 8);
226 info.iUsage = ESgUsageDirectGdiTarget;
227 info.iPixelFormat = EUidPixelFormatRGB_565;
228 info.iCpuAccess = ESgCpuAccessNone;
229 info.iShareable = EFalse;
232 CheckErrorL(KErrNone, image.Create(info, KImageData, 16), (TText8*)__FILE__, __LINE__);
233 CleanupClosePushL(image);
234 const TSgDrawableId id = image.Id();
236 // open a non-sharable image - should succeed
237 TEST(KErrNone == drawable.Open(id));
239 // open on a non-null RSgDrawable handle
240 TEST(KErrInUse == drawable.Open(id));
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);
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);
263 CleanupStack::PopAndDestroy();
268 @SYMTestCaseID GRAPHICS-RESOURCE-0033
269 @SYMTestCaseDesc Closes RSgDrawable without first opening it.
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
283 void CTSgDrawableGeneric::TestCloseDrawableWithoutOpenL()
286 RSgDrawable drawable;
294 @SYMTestCaseID GRAPHICS-RESOURCE-0080
295 @SYMTestCaseDesc Calls RSgDrawable::Open() when the driver was not initialised.
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
307 void CTSgDrawableGeneric::TestPanicDrawableOpenNoDriverL()
310 TSgresTestInfo threadInfo = {KSgNullDrawableId, info, 0, ESgresSecondThreadPanicDrawableOpenNoDriver, ETrue};
311 TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
312 _LIT(KTestName, "TestPanicDrawableOpenNoDriverL");
313 CreateSecondThreadAndCheckPanicL(threadInfo, 5, exitCategoryName, KTestName);
316 void CTSgDrawableGeneric::DoMemoryTestsL()
318 __UHEAP_MARK; SgDriver::AllocMarkStart();
319 TestOpenImageAsDrawableL();
320 __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
322 __UHEAP_MARK; SgDriver::AllocMarkStart();
323 TestGetDrawableDrawableIdL();
324 __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
326 __UHEAP_MARK; SgDriver::AllocMarkStart();
327 TestOpenDrawableInvalidL();
328 __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);
330 __UHEAP_MARK; SgDriver::AllocMarkStart();
331 TestCloseDrawableWithoutOpenL();
332 __UHEAP_MARKEND; SgDriver::AllocMarkEnd(0);