os/graphics/graphicsresourceservices/graphicsresourceimplementation/test/src/tsgdrawablegeneric.cpp
First public contribution.
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.
18 @internalComponent - Graphics Resource API Conformance Test Suite
20 #include "tsgdrawablegeneric.h"
23 Construct the CTsgDrawableGeneric tests; set whether the tests are being used as conformance
26 @param TBool ETrue to run the conformance tests, EFalse to run the OOM tests.
28 CTSgDrawableGeneric::CTSgDrawableGeneric(TBool aConformanceTests) :
29 CTSgTestStepBase(aConformanceTests)
31 INFO_PRINTF1(_L("Graphics resource component test - RSgDrawable Generic Tests.\r\n"));
34 CTSgDrawableGeneric::~CTSgDrawableGeneric()
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
45 TVerdict CTSgDrawableGeneric::doTestStepL()
47 SetTestStepID(_L("GRAPHICS-RESOURCE-0013"));
48 INFO_PRINTF1(_L("Opening an image in RSgDrawable.\r\n"));
49 TestOpenImageAsDrawableL();
52 SetTestStepID(_L("GRAPHICS-RESOURCE-0014"));
53 INFO_PRINTF1(_L("Retrieving drawable id of an RSgDrawable object.\r\n"));
54 TestGetDrawableDrawableIdL();
57 SetTestStepID(_L("GRAPHICS-RESOURCE-0032"));
58 INFO_PRINTF1(_L("RSgDrawable::Open() with invalid parameters.\r\n"));
59 TestOpenDrawableInvalidL();
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();
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();
73 INFO_PRINTF1(_L("Warning: Skipping the panic tests in release build. \r\n"));
76 return TestStepResult();
81 @SYMTestCaseID GRAPHICS-RESOURCE-0013
82 @SYMTestCaseDesc Opens an RSgImage as an RSgDrawable.
84 @SYMFssID RSgImage::Id()
85 RSgDrawable::Open(const TSgDrawableId&)
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.
95 void CTSgDrawableGeneric::TestOpenImageAsDrawableL()
100 CleanupClosePushL(image);
101 const TSgDrawableId id = image.Id();
102 TSgImageInfo imageinfo;
103 image.GetInfo(imageinfo);
105 //opening an image as a drawable in the current thread
107 TEST(image2.IsNull());
108 CheckErrorL(KErrNone, image2.Open(id), (TText8*)__FILE__, __LINE__);
109 TEST(!image2.IsNull());
111 if (iEnableConformanceTests)
113 //opening an image as a drawable in another thread in the same process
114 TSgThreadTestInfo threadInfo(id, imageinfo, ESgresSecondThreadOpenDrawable);
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);
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);
133 CleanupStack::PopAndDestroy();
138 @SYMTestCaseID GRAPHICS-RESOURCE-0014
139 @SYMTestCaseDesc Retrieves drawable id of an RSgDrawable.
141 @SYMFssID RSgImage::Id()
142 RSgDrawable::Open(const TSgDrawableId&)
144 @SYMTestPriority Critical
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.
152 void CTSgDrawableGeneric::TestGetDrawableDrawableIdL()
157 CleanupClosePushL(image);
158 TSgDrawableId id1 = image.Id();
159 TEST(id1 != KSgNullDrawableId);
161 RSgDrawable drawable;
162 TEST(KErrNone == drawable.Open(id1));
163 TSgDrawableId id2 = drawable.Id();
164 TEST(id2 != KSgNullDrawableId);
168 CleanupStack::PopAndDestroy();
174 @SYMTestCaseID GRAPHICS-RESOURCE-0032
175 @SYMTestCaseDesc Calls RSgDrawable::Open() with invalid parameters.
177 @SYMFssID RSgImage::Id()
178 RSgDrawable::Open(const TSgDrawableId&)
179 @SYMTestPriority Medium
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:
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:
195 void CTSgDrawableGeneric::TestOpenDrawableInvalidL()
200 RSgDrawable drawable;
201 CheckErrorL(KErrArgument, drawable.Open(KSgNullDrawableId), (TText8*)__FILE__, __LINE__);
204 // non-existing drawable id
205 TSgDrawableId fakeid = {0xFFFFFFFFFFFFFFFFU};
206 CheckErrorL(KErrNotFound, drawable.Open(fakeid), (TText8*)__FILE__, __LINE__);
209 //create a valid image
211 info.iSizeInPixels = TSize(8, 8);
212 info.iUsage = ESgUsageBitOpenVgImage;
213 info.iPixelFormat = EUidPixelFormatRGB_565;
216 CheckErrorL(KErrNone, image.Create(info, KCrossImageData, KCrossImageDataStride), (TText8*)__FILE__, __LINE__);
217 CleanupClosePushL(image);
218 const TSgDrawableId id = image.Id();
220 // open an image - should succeed
221 TEST(KErrNone == drawable.Open(id));
223 // open on a non-null RSgDrawable handle
224 TEST(KErrInUse == drawable.Open(id));
227 if (iEnableConformanceTests)
229 //different thread in the same process
230 TSgThreadTestInfo threadInfo(id, info, ESgresSecondThreadOpenDrawableInvalid);
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);
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);
250 CleanupStack::PopAndDestroy(&image);
255 @SYMTestCaseID GRAPHICS-RESOURCE-0033
256 @SYMTestCaseDesc Closes RSgDrawable without first opening it.
258 @SYMFssID RSgDrawable::Close()
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.
265 void CTSgDrawableGeneric::TestCloseDrawableWithoutOpenL()
268 RSgDrawable drawable;
276 @SYMTestCaseID GRAPHICS-RESOURCE-0080
277 @SYMTestCaseDesc Calls RSgDrawable::Open() when the driver was not initialised.
279 @SYMFssID RSgImage::Open()
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).
286 void CTSgDrawableGeneric::TestPanicDrawableOpenNoDriverL()
289 TSgThreadTestInfo threadInfo(KSgNullDrawableId, info, ESgresSecondThreadPanicDrawableOpenNoDriver);
290 TExitCategoryName exitCategoryName(KSgTestGenericPanicCategory);
291 _LIT(KTestName, "TestPanicDrawableOpenNoDriverL");
292 CreateSecondThreadAndCheckPanicL(threadInfo, 1, exitCategoryName, KTestName);