|
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 #include "tdirectgdidriver.h" |
|
17 #include <graphics/directgdicontext.h> |
|
18 |
|
19 CTDirectGdiDriver::CTDirectGdiDriver() |
|
20 { |
|
21 SetTestStepName(KTDirectGdiDriverStep); |
|
22 } |
|
23 |
|
24 CTDirectGdiDriver::~CTDirectGdiDriver() |
|
25 { |
|
26 } |
|
27 |
|
28 /** |
|
29 @SYMTestCaseID |
|
30 GRAPHICS-DIRECTGDI-DRIVER-0001 |
|
31 |
|
32 @SYMPREQ |
|
33 PREQ39 |
|
34 |
|
35 @SYMREQ |
|
36 REQ9211 |
|
37 REQ9226 |
|
38 REQ9195 |
|
39 REQ9201 |
|
40 REQ9202 |
|
41 REQ9222 |
|
42 REQ9223 |
|
43 REQ9236 |
|
44 REQ9237 |
|
45 |
|
46 @SYMTestCaseDesc |
|
47 Construction and destruction of a CDirectGdiDriver object. |
|
48 Only one object should be created as its a singleton. |
|
49 Open() should create the CDirectGdiDriverInternal object and increment the |
|
50 reference count. |
|
51 Close() should decrement the reference count and when it becomes zero, destroy |
|
52 the CDirectGdiDriver & CDirectGdiDriverInternal object. |
|
53 |
|
54 @SYMTestActions |
|
55 Open a driver. |
|
56 Open a driver again. |
|
57 Close a driver then open it again. |
|
58 Close a driver, check that it is still open. |
|
59 Close a driver, check that it is now closed. |
|
60 |
|
61 @SYMTestExpectedResults |
|
62 A driver can be opened and closed successfully with no errors. |
|
63 |
|
64 @SYMTestStatus |
|
65 Implemented |
|
66 */ |
|
67 void CTDirectGdiDriver::TestDriverL() |
|
68 { |
|
69 _LIT(KTestName, "Driver-TestDriver"); |
|
70 if(!iRunningOomTests) |
|
71 { |
|
72 INFO_PRINTF1(KTestName); |
|
73 } |
|
74 |
|
75 // Check the driver returns NULL |
|
76 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static(); |
|
77 TESTL(dgdiDriver == NULL); |
|
78 |
|
79 // Open the driver once |
|
80 TInt res = CDirectGdiDriver::Open(); |
|
81 TESTNOERRORL(res); |
|
82 |
|
83 dgdiDriver = CDirectGdiDriver::Static(); |
|
84 TESTL(dgdiDriver != NULL); |
|
85 |
|
86 // Open the driver a second time |
|
87 res = CDirectGdiDriver::Open(); |
|
88 TESTNOERRORL(res); |
|
89 |
|
90 // Close the driver once |
|
91 dgdiDriver->Close(); |
|
92 |
|
93 // Open the driver again |
|
94 res = CDirectGdiDriver::Open(); |
|
95 TESTNOERRORL(res); |
|
96 |
|
97 // Close the driver twice, on the second close, the driver should delete |
|
98 // itself when its internal open count reaches zero |
|
99 dgdiDriver->Close(); |
|
100 TESTL(CDirectGdiDriver::Static() != NULL); |
|
101 dgdiDriver->Close(); |
|
102 TESTL(CDirectGdiDriver::Static() == NULL); |
|
103 } |
|
104 |
|
105 /** |
|
106 @SYMTestCaseID |
|
107 GRAPHICS-DIRECTGDI-DRIVER-0002 |
|
108 |
|
109 @SYMPREQ |
|
110 PREQ39 |
|
111 |
|
112 @SYMREQ |
|
113 REQ9211 |
|
114 REQ9226 |
|
115 REQ9195 |
|
116 REQ9201 |
|
117 REQ9202 |
|
118 REQ9222 |
|
119 REQ9223 |
|
120 REQ9236 |
|
121 REQ9237 |
|
122 |
|
123 @SYMTestCaseDesc |
|
124 Out of memory test. Test that opening a driver does not cause memory leaks. |
|
125 |
|
126 @SYMTestActions |
|
127 Repeatedly call the "Driver-ErrorCodes" test (below) in OOM conditions to make |
|
128 sure no memory leaks occur. |
|
129 |
|
130 @SYMTestExpectedResults |
|
131 No memory leaks. |
|
132 |
|
133 @SYMTestStatus |
|
134 Implemented |
|
135 */ |
|
136 void CTDirectGdiDriver::TestDriverOOM() |
|
137 { |
|
138 TInt err, tryCount = 0; |
|
139 INFO_PRINTF1(_L("Driver-TestDriverOOM")); |
|
140 |
|
141 do |
|
142 { |
|
143 __UHEAP_FAILNEXT(++tryCount); |
|
144 __UHEAP_MARK; |
|
145 { |
|
146 err = TestDriverErrorCodes(); |
|
147 } |
|
148 __UHEAP_MARKEND; |
|
149 } |
|
150 while(err == KErrNoMemory); |
|
151 if(err == KErrNone) |
|
152 { |
|
153 __UHEAP_RESET; |
|
154 } |
|
155 else |
|
156 { |
|
157 TEST(err == KErrNone); |
|
158 } |
|
159 INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount); |
|
160 } |
|
161 |
|
162 /** |
|
163 @SYMTestCaseID |
|
164 GRAPHICS-DIRECTGDI-DRIVER-0003 |
|
165 |
|
166 @SYMPREQ |
|
167 PREQ39 |
|
168 |
|
169 @SYMREQ |
|
170 REQ9211 |
|
171 REQ9226 |
|
172 REQ9195 |
|
173 REQ9201 |
|
174 REQ9202 |
|
175 REQ9222 |
|
176 REQ9223 |
|
177 REQ9236 |
|
178 REQ9237 |
|
179 |
|
180 @SYMTestCaseDesc |
|
181 Checks the error code returned by GetError() after Construction and |
|
182 destruction of a CDirectGdiDriver object. |
|
183 |
|
184 @SYMTestActions |
|
185 Create and destroy a CDirectGdiDriver. |
|
186 |
|
187 @SYMTestExpectedResults |
|
188 Test that the only errors returned when opening a driver are KErrNone and |
|
189 KErrNoMemory. Test that GetError() returns KErrNone after a driver has been opened. |
|
190 |
|
191 @SYMTestStatus |
|
192 Implemented |
|
193 */ |
|
194 TInt CTDirectGdiDriver::TestDriverErrorCodes() |
|
195 { |
|
196 _LIT(KTestName, "Driver-ErrorCodes"); |
|
197 if(!iRunningOomTests) |
|
198 { |
|
199 INFO_PRINTF1(KTestName); |
|
200 } |
|
201 |
|
202 TInt errOpen = CDirectGdiDriver::Open(); |
|
203 TEST( errOpen == KErrNone || errOpen == KErrNoMemory ); |
|
204 if( errOpen != KErrNone ) |
|
205 return errOpen; |
|
206 |
|
207 CDirectGdiDriver* gdiDriver = CDirectGdiDriver::Static(); |
|
208 if( !gdiDriver ) |
|
209 return KErrNoMemory; |
|
210 |
|
211 TInt err = gdiDriver->GetError(); |
|
212 TESTNOERROR(err); |
|
213 gdiDriver->Close(); //Ref count should now be 0 |
|
214 |
|
215 return err; |
|
216 } |
|
217 |
|
218 /** |
|
219 @SYMTestCaseID |
|
220 GRAPHICS-DIRECTGDI-0004 |
|
221 |
|
222 @SYMPREQ PREQ39 |
|
223 |
|
224 @SYMTestCaseDesc |
|
225 Sets the error code and then checks the error code by calling GetError(). |
|
226 Setting the error code should not affect the actual error code, unless GetError() is first called to reset the error code. |
|
227 |
|
228 @SYMTestActions |
|
229 Test the error setting and reporting functionality of the driver. |
|
230 Set the error code twice with different errors each time, |
|
231 get the error - the error returned should be the first error set, not the second. |
|
232 |
|
233 @SYMTestExpectedResults |
|
234 Error code should be KErrGeneral and not KErrNoMemory. |
|
235 */ |
|
236 void CTDirectGdiDriver::TestSetError() |
|
237 { |
|
238 _LIT(KTestName, "Driver-SetError"); |
|
239 if(!iRunningOomTests) |
|
240 { |
|
241 INFO_PRINTF1(KTestName); |
|
242 } |
|
243 |
|
244 TInt errOpen = CDirectGdiDriver::Open(); |
|
245 TEST( errOpen == KErrNone || errOpen == KErrNoMemory ); |
|
246 |
|
247 CDirectGdiDriver* gdiDriver = CDirectGdiDriver::Static(); |
|
248 TEST(gdiDriver!=NULL); |
|
249 |
|
250 gdiDriver->SetError(KErrGeneral); |
|
251 gdiDriver->SetError(KErrNoMemory); |
|
252 |
|
253 TInt err = gdiDriver->GetError(); |
|
254 TEST(err == KErrGeneral); |
|
255 |
|
256 gdiDriver->Close(); //Ref count should now be 0 |
|
257 } |
|
258 |
|
259 /** |
|
260 @SYMTestCaseID |
|
261 GRAPHICS-DIRECTGDI-0005 |
|
262 |
|
263 @SYMPREQ PREQ39 |
|
264 |
|
265 @SYMTestCaseDesc |
|
266 Tests the function Flush() |
|
267 |
|
268 @SYMTestActions |
|
269 Open a DirectGDI driver |
|
270 Call Flush() |
|
271 Close the driver. |
|
272 |
|
273 @SYMTestExpectedResults |
|
274 On software DirectGDI, Flush() does not do anything but on hardware DirectGDI, it calls vgFlush(). |
|
275 No error should occur. |
|
276 */ |
|
277 void CTDirectGdiDriver::TestFlush() |
|
278 { |
|
279 _LIT(KTestName, "Driver-TestFlush"); |
|
280 if(!iRunningOomTests) |
|
281 { |
|
282 INFO_PRINTF1(KTestName); |
|
283 } |
|
284 TInt errOpen = CDirectGdiDriver::Open(); |
|
285 TEST(errOpen == KErrNone); |
|
286 CDirectGdiDriver* gdiDriver = CDirectGdiDriver::Static(); |
|
287 TEST(gdiDriver!=NULL); |
|
288 gdiDriver->Flush(); |
|
289 TInt err = gdiDriver->GetError(); |
|
290 TEST(err == KErrNone); |
|
291 gdiDriver->Close(); //Ref count should now be 0 |
|
292 } |
|
293 |
|
294 /** |
|
295 @SYMTestCaseID |
|
296 GRAPHICS-DIRECTGDI-0006 |
|
297 |
|
298 @SYMPREQ PREQ39 |
|
299 |
|
300 @SYMTestCaseDesc |
|
301 Test that CDirectGdiDriver::GetInterface() returns KErrExtensionNotSupported |
|
302 when a non-existent extension interface is requested. |
|
303 |
|
304 @SYMTestActions |
|
305 Open a DirectGDI driver. |
|
306 Request a extension interface using the Uif 0xFFFFFFFF. |
|
307 |
|
308 @SYMTestExpectedResults |
|
309 KErrExtensionNotSupported should be returned and the requested interface pointer |
|
310 should be set to NULL. |
|
311 */ |
|
312 void CTDirectGdiDriver::TestGetInterfaceL() |
|
313 { |
|
314 _LIT(KTestName, "Driver-TestGetInterfaceL"); |
|
315 if(!iRunningOomTests) |
|
316 { |
|
317 INFO_PRINTF1(KTestName); |
|
318 } |
|
319 |
|
320 TInt err = CDirectGdiDriver::Open(); |
|
321 TESTNOERRORL(err); |
|
322 |
|
323 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
324 TESTL(driver != NULL); |
|
325 |
|
326 // Set badInterface to something other than NULL to make sure GetInterface is setting it to NULL |
|
327 TAny* badInterface = &err; |
|
328 err = driver->GetInterface(TUid::Uid(0xFFFFFFFF), badInterface); |
|
329 TEST(err == KErrExtensionNotSupported); |
|
330 TEST(badInterface == NULL); |
|
331 |
|
332 driver->Close(); |
|
333 } |
|
334 |
|
335 /** |
|
336 @SYMTestCaseID |
|
337 GRAPHICS-DIRECTGDI-0007 |
|
338 |
|
339 @SYMPREQ PREQ39 |
|
340 |
|
341 @SYMTestCaseDesc |
|
342 Tests the MDirectGdiDriverCacheSize extension interface implementation provided |
|
343 by CDirectGdiDriver. Note that this extension is only implemented by the hardware |
|
344 DirectGdi adaptation, it is not provided by the software adaptation. |
|
345 |
|
346 @SYMTestActions |
|
347 if testing on hardware DirectGdi: |
|
348 Open a DirectGDI driver. |
|
349 Attempt to get the extension interface for MDirectGdiDriverCacheSize from the driver. |
|
350 - This should succeed. |
|
351 Get the currently set maximum image cache and glyph cache size. |
|
352 Set the new image and glyph cache sizes to less than the current size. |
|
353 Set the new image and glyph cache sizes to greater than the current size. |
|
354 Check that the reported image/glyph cache sizes are correctly set. |
|
355 |
|
356 if testing on software DirectGdi: |
|
357 Open a DirectGdi driver. |
|
358 Attempt to get the extension interface for MDirectGdiDriverCacheSize from the driver. |
|
359 - This should fail. |
|
360 |
|
361 @SYMTestExpectedResults |
|
362 Setting the caches to a smaller size that the existing size should cause KErrArgument to be returned. |
|
363 All other APIs should succeed. |
|
364 If using Software DirectGDI, it should skip the tests. |
|
365 */ |
|
366 void CTDirectGdiDriver::TestCacheSizesL() |
|
367 { |
|
368 _LIT(KTestName, "Driver-TestCacheSizes"); |
|
369 if(!iRunningOomTests) |
|
370 { |
|
371 INFO_PRINTF1(KTestName); |
|
372 } |
|
373 |
|
374 TInt err = CDirectGdiDriver::Open(); |
|
375 TESTNOERRORL(err); |
|
376 |
|
377 CDirectGdiDriver* driver = CDirectGdiDriver::Static(); |
|
378 TESTL(driver != NULL); |
|
379 CleanupClosePushL(*driver); |
|
380 |
|
381 MDirectGdiDriverCacheSize* driverCacheInterface = NULL; |
|
382 err = driver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheInterface); |
|
383 if (err == KErrNone) |
|
384 { |
|
385 // MDirectGdiDriverCacheSize is implemented in the hardware (VG) adaptation |
|
386 TESTL(driverCacheInterface != NULL); |
|
387 |
|
388 // This number must be > the default image cache size for this test to pass. |
|
389 const TInt KLargeImageCacheSize = 0x500000; |
|
390 // This number must be > the default glyph cache size for this test to pass. |
|
391 const TInt KLargeGlyphCacheSize = 0x500000; |
|
392 |
|
393 TESTNOERROR(driverCacheInterface->SetMaxImageCacheSize(KLargeImageCacheSize)); |
|
394 TESTNOERROR(driverCacheInterface->SetMaxGlyphCacheSize(KLargeGlyphCacheSize)); |
|
395 |
|
396 // Test the image cache size |
|
397 TEST(KErrArgument == driverCacheInterface->SetMaxImageCacheSize(-1)); |
|
398 TESTNOERROR(driverCacheInterface->SetMaxImageCacheSize(KLargeImageCacheSize+1)); |
|
399 TEST(driverCacheInterface->MaxImageCacheSize() == KLargeImageCacheSize+1); |
|
400 |
|
401 // Test the glyph cache size |
|
402 TEST(KErrArgument == driverCacheInterface->SetMaxGlyphCacheSize(-1)); |
|
403 TESTNOERROR(driverCacheInterface->SetMaxGlyphCacheSize(KLargeGlyphCacheSize+1)); |
|
404 TEST(driverCacheInterface->MaxGlyphCacheSize() == KLargeGlyphCacheSize+1); |
|
405 } |
|
406 else |
|
407 { |
|
408 // MDirectGdiDriverCacheSize is not implemented in the software adaptation of DirectGDI. |
|
409 // The only error code that should be returned is KErrExtensionNotSupported. |
|
410 TEST(err == KErrExtensionNotSupported); |
|
411 TEST(driverCacheInterface == NULL); |
|
412 INFO_PRINTF1(_L("Extension MDirectGdiDriverCacheSize not supported, skipping test.")); |
|
413 } |
|
414 |
|
415 CleanupStack::PopAndDestroy(1, driver); |
|
416 } |
|
417 |
|
418 /** |
|
419 Override of base class virtual |
|
420 |
|
421 @return - TVerdict code |
|
422 */ |
|
423 TVerdict CTDirectGdiDriver::doTestStepPreambleL() |
|
424 { |
|
425 CTDirectGdiStepBase::doTestStepPreambleL(); |
|
426 INFO_PRINTF1(_L("DirectGdi Driver pre-test setup")); |
|
427 return TestStepResult(); |
|
428 } |
|
429 |
|
430 /** |
|
431 Override of base class pure virtual |
|
432 Our implementation only gets called if the base class doTestStepPreambleL() did |
|
433 not leave. That being the case, the current test result value will be EPass. |
|
434 |
|
435 Creates background window with black & white checker board. |
|
436 This background windows is used for each test case in this file |
|
437 |
|
438 @return TVerdict code |
|
439 */ |
|
440 TVerdict CTDirectGdiDriver::doTestStepL() |
|
441 { |
|
442 INFO_PRINTF1(_L("DirectGdi Driver Test" )); |
|
443 if (iUseDirectGdi) |
|
444 { |
|
445 RunTestsL(); |
|
446 } |
|
447 return TestStepResult(); |
|
448 } |
|
449 |
|
450 void CTDirectGdiDriver::RunTestsL() |
|
451 { |
|
452 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRIVER-0001")); |
|
453 TestDriverL(); |
|
454 RecordTestResultL(); |
|
455 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRIVER-0003")); |
|
456 TestDriverErrorCodes(); |
|
457 RecordTestResultL(); |
|
458 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRIVER-0002")); |
|
459 TestDriverOOM(); |
|
460 RecordTestResultL(); |
|
461 SetTestStepID(_L("GRAPHICS-DIRECTGDI-0004")); |
|
462 TestSetError(); |
|
463 RecordTestResultL(); |
|
464 SetTestStepID(_L("GRAPHICS-DIRECTGDI-0005")); |
|
465 TestFlush(); |
|
466 RecordTestResultL(); |
|
467 SetTestStepID(_L("GRAPHICS-DIRECTGDI-0006")); |
|
468 TestGetInterfaceL(); |
|
469 RecordTestResultL(); |
|
470 SetTestStepID(_L("GRAPHICS-DIRECTGDI-0007")); |
|
471 TestCacheSizesL(); |
|
472 RecordTestResultL(); |
|
473 CloseTMSGraphicsStep(); |
|
474 } |