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.
16 #include "tpanictests.h"
17 #include <graphics/directgdicontext.h>
18 #include <graphics/directgdiimagetarget.h>
20 _LIT(KPanicCategory, "DGDI");
22 CTPanicTests::CTPanicTests()
24 SetTestStepName(KTDirectGdiPanicTestsStep);
27 CTPanicTests::~CTPanicTests()
33 GRAPHICS-DIRECTGDI-PANIC-0001
51 Tests if DirectGDI methods panic when called on a inactivated context.
54 Construct CDirectGdiDriver.
55 Construct CDirectGdiContext.
57 Construct MDirectGdiImageTarget.
58 Create MDirectGdiImageTarget, using RSgImage.
60 Do not Activate CDirectGdiContext.
61 Call any API on the context.
64 Destroy MDirectGdiImageTarget.
65 Destroy CDirectGdiContext.
66 Close CDirectGdiDriver.
68 @SYMTestExpectedResults
69 It should panic with panic code DGDI 7, EDirectGdiPanicContextNotActivated
74 void CTPanicTests::TestContextNotActivatedL()
78 TInt result = CDirectGdiDriver::Open();
81 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
82 TEST(dgdiDriver != NULL);
83 CleanupClosePushL(*dgdiDriver);
85 CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
87 RSgImage* rsgImage1 = new RSgImage();
88 TESTL(rsgImage1 != NULL);
90 // Set the bitmap up...
91 TSgImageInfo imageInfo;
92 imageInfo.iSizeInPixels = TSize (320, 240);
93 imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
95 imageInfo.iUsage = ESgUsageDirectGdiTarget;
96 result = rsgImage1->Create(imageInfo, NULL,0);
99 RDirectGdiImageTarget* dgdiImageTarget1 = new RDirectGdiImageTarget(*dgdiDriver);
100 TESTL(dgdiImageTarget1 != NULL);
101 result = dgdiImageTarget1->Create(*rsgImage1);
102 TESTNOERRORL(result);
104 TRect rect(10, 15, 100, 100);
105 gc->DrawEllipse(rect);
107 dgdiImageTarget1->Close();
108 delete(dgdiImageTarget1);
112 CleanupStack::PopAndDestroy(1);
115 User::Panic(KPanicCategory, 7);
120 GRAPHICS-DIRECTGDI-PANIC-0002
138 Testing if a panic is raised during text drawing functions usage without valid font set.
141 Context is created and activated.
144 Call any DrawText() API on the context.
146 Reset font in context.
147 Call any DrawText() API on the context.
149 @SYMTestExpectedResults
150 It should panic with panic code DGDI 11, EDirectGdiPanicNoFontSelected.
156 void CTPanicTests::TestFontNotSetL()
164 CFont* font = GetFont();
167 iGc->SetPenColor(TRgb(0, 0, 0));
170 iGc->DrawText(KText, NULL, TPoint(10, 30));
173 iGc->DrawText(KText, NULL, TPoint(10, 50));
178 User::Panic( KPanicCategory, 11);
183 GRAPHICS-DIRECTGDI-PANIC-0003
201 Tests the negative conditions that can only be reached by creating RSgImage with an invalid pixel type, to
202 improve the code coverage.
205 Construct CDirectGdiDriver.
206 Construct CDirectGdiContext.
208 Construct RSgImage with unsupported pixel type and do not check for the return error code.
209 Construct MDirectGdiImageTarget.
210 Create MDirectGdiImageTarget, using RSgImage, ignoring the return error code.
212 Activate CDirectGdiContext using MDirectGdiImageTarget.
215 Destroy MDirectGdiImageTarget.
217 Destroy CDirectGdiContext.
218 Close CDirectGdiDriver.
220 @SYMTestExpectedResults
221 It should panic with panic code DGDI 21, EDirectGdiImageTargetInfoError
226 void CTPanicTests::TestInvalidTargetL()
230 TInt err = CDirectGdiDriver::Open();
233 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
234 TESTL(dgdiDriver != NULL);
235 CleanupClosePushL(*dgdiDriver);
237 CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
240 // Set the bitmap up...
241 TSgImageInfo imageInfo;
242 imageInfo.iSizeInPixels = TSize (320, 240);
243 imageInfo.iPixelFormat = EUidPixelFormatA_8;
244 imageInfo.iUsage = ESgUsageDirectGdiTarget;
245 rsgImage.Create(imageInfo, NULL,0);
247 RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);
248 dgdiImageTarget.Create(rsgImage);
249 gc->Activate (dgdiImageTarget);
252 dgdiImageTarget.Close();
254 CleanupStack::PopAndDestroy(1);
257 User::Panic( KPanicCategory, 21);
262 GRAPHICS-DIRECTGDI-PANIC-0004
280 Test that the adapter panics when an attempt is made to activate a target with an invalid handle.
284 Make it a target for the driver.
285 Change the target's handle so it has an erroneous handle.
286 Attempt to activate the target.
287 (This test only works in _DEBUG mode as the handle check only happens in _DEBUG mode)
289 @SYMTestExpectedResults
290 The test should panic when the target is activated DGDIAdapter 32, EDirectGdiPanicResourceHandleNotFound.
295 void CTPanicTests::TestImageInvalidTargetHandleL()
298 TInt err = CDirectGdiDriver::Open();
301 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
302 TESTL(dgdiDriver != NULL);
303 CleanupClosePushL(*dgdiDriver);
305 CDirectGdiContext* gc = CDirectGdiContext::NewL(*dgdiDriver);
308 // Set the bitmap up...
309 TSgImageInfo imageInfo;
310 imageInfo.iSizeInPixels = TSize (320, 240);
311 imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat;
312 imageInfo.iUsage = ESgUsageDirectGdiTarget;
313 rsgImage.Create(imageInfo, NULL,0);
315 RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);
316 dgdiImageTarget.Create(rsgImage);
318 // Set the target's handle to a non-null invalid handle.
319 dgdiImageTarget.iHandle = 0x12345678;
321 // Activate should panic (DGDIAdapter EDirectGdiTargetHandleNotFound 32)
322 gc->Activate (dgdiImageTarget);
325 dgdiImageTarget.Close();
327 CleanupStack::PopAndDestroy(1);
329 User::Panic(KPanicCategory, 32);
335 GRAPHICS-DIRECTGDI-PANIC-0005
344 Tests the negative conditions that the same RDirectGdiImageTarget object
348 Construct CDirectGdiDriver.
349 Construct RDirectGdiImageTarget twice.
351 @SYMTestExpectedResults
352 It should panic with panic code DGDIAdapter 17, EDirectGdiImageTargetAlreadyExists
357 void CTPanicTests::TestImageTargetActivatedTwiceL()
361 TInt err = CDirectGdiDriver::Open();
363 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
364 TESTL(dgdiDriver != NULL);
365 CleanupClosePushL(*dgdiDriver);
368 info2.iSizeInPixels = TSize(8, 8);
369 info2.iUsage = ESgUsageDirectGdiTarget;
370 info2.iPixelFormat = EUidPixelFormatRGB_565;
371 info2.iCpuAccess = ESgCpuAccessNone;
372 info2.iShareable = ETrue;
374 User::LeaveIfError(image2.Create(info2, NULL, 0));
375 CleanupClosePushL(image2);
377 RDirectGdiImageTarget dgdiImageTarget(*dgdiDriver);
378 TESTNOERRORL(dgdiImageTarget.Create(image2));
379 CleanupClosePushL(dgdiImageTarget);
380 dgdiImageTarget.Create(image2); //should panic here
381 CleanupClosePushL(dgdiImageTarget);
383 CleanupStack::PopAndDestroy(4, dgdiDriver);
387 User::Panic( KPanicCategory, 17);
393 GRAPHICS-DIRECTGDI-PANIC-0006
402 Tests the negative conditions that the same RDirectGdiDrawableSource object
406 Construct CDirectGdiDriver.
407 Construct RDirectGdiDrawableSource twice.
409 @SYMTestExpectedResults
410 It should panic with panic code DGDI 18, EDirectGdiImageSourceAlreadyExists
415 void CTPanicTests::TestImageSourceActivatedTwiceL()
419 TInt err = CDirectGdiDriver::Open();
421 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
422 TESTL(dgdiDriver != NULL);
423 CleanupClosePushL(*dgdiDriver);
426 info1.iSizeInPixels = TSize(8, 8);
427 info1.iUsage = ESgUsageDirectGdiSource;
428 info1.iPixelFormat = EUidPixelFormatRGB_565;
429 info1.iCpuAccess = ESgCpuAccessReadWrite;
430 info1.iShareable = ETrue;
432 User::LeaveIfError(image1.Create(info1, NULL, 0));
433 CleanupClosePushL(image1);
435 RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);
436 TESTNOERRORL(dgdiImageSource.Create(image1));
437 CleanupClosePushL(dgdiImageSource);
438 dgdiImageSource.Create(image1); //should panic here
439 CleanupClosePushL(dgdiImageSource);
441 CleanupStack::PopAndDestroy(4, dgdiDriver);
445 User::Panic( KPanicCategory, 18);
451 GRAPHICS-DIRECTGDI-PANIC-0007
469 Tests the negative conditions that the same RDirectGdiDrawableSource object
473 Construct CDirectGdiDriver.
474 Construct RDirectGdiDrawableSource twice.
476 @SYMTestExpectedResults
477 It should panic with panic code DGDIAdapter 19, EDirectGdiDrawableSourceAlreadyExists
482 void CTPanicTests::TestDrawableSourceActivatedTwiceL()
486 TInt err = CDirectGdiDriver::Open();
488 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
489 TESTL(dgdiDriver != NULL);
490 CleanupClosePushL(*dgdiDriver);
493 info1.iSizeInPixels = TSize(8, 8);
494 info1.iUsage = ESgUsageDirectGdiSource;
495 info1.iPixelFormat = EUidPixelFormatARGB_8888_PRE;
496 info1.iCpuAccess = ESgCpuAccessReadWrite;
497 info1.iShareable = ETrue;
499 TESTNOERRORL(image1.Create(info1, NULL, 0));
500 CleanupClosePushL(image1);
502 RDirectGdiDrawableSource dgdiDrawableSource(*dgdiDriver);
503 TESTNOERRORL(dgdiDrawableSource.Create(image1));
504 CleanupClosePushL(dgdiDrawableSource);
505 dgdiDrawableSource.Create(image1); //should panic here
506 CleanupClosePushL(dgdiDrawableSource);
508 CleanupStack::PopAndDestroy(4, dgdiDriver);
512 User::Panic( KPanicCategory, 19);
518 GRAPHICS-DIRECTGDI-PANIC-0008
536 Make sure a panic occurs when calling SetBrushStyle() with EPatternedBrush when no brush pattern has been set.
539 Set brush style to EPatternedBrush.
541 @SYMTestExpectedResults
542 It should panic with panic code DGDI 9, EDirectGdiBrushPatternNotSet.
547 void CTPanicTests::TestBrushPatternNotSetL()
552 iGc->SetBrushStyle(DirectGdi::EPatternedBrush);
555 User::Panic( KPanicCategory, 9);
559 Override of base class virtual
560 @leave Gets system wide error code
561 @return - TVerdict code
563 TVerdict CTPanicTests::doTestStepPreambleL()
565 CTDirectGdiStepBase::doTestStepPreambleL();
566 return TestStepResult();
570 Override of base class pure virtual
571 Our implementation only gets called if the base class doTestStepPreambleL() did
572 not leave. That being the case, the current test result value will be EPass.
573 @leave Gets system wide error code
574 @return TVerdict code
576 TVerdict CTPanicTests::doTestStepL()
578 // Test for each pixel format
579 for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
581 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
582 SetTargetL(iTestParams.iTargetPixelFormat);
587 return TestStepResult();
591 Override of base class pure virtual
592 Lists the tests to be run
594 void CTPanicTests::RunTestsL()
596 INFO_PRINTF1(_L("DirectGdi Panic Tests" ));
598 //Read the case number from the ini file
599 TBool res = GetIntFromConfig(ConfigSection(), KCaseNumber, aCurTestCase);
604 SetTestStepID(KUnknownSYMTestCaseIDName);
608 INFO_PRINTF1(_L("TestContextNotActivatedL\n"));
609 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0001"));
610 TestContextNotActivatedL();
613 INFO_PRINTF1(_L("TestFontNotSetL\r\n"));
614 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0002"));
618 INFO_PRINTF1(_L("TestInvalidTargetL\r\n"));
619 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0003"));
620 TestInvalidTargetL();
623 INFO_PRINTF1(_L("TestImageInvalidTargetHandleL\r\n"));
624 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0004"));
625 TestImageInvalidTargetHandleL();
628 INFO_PRINTF1(_L("TestImageTargetActivatedTwiceL\r\n"));
629 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0005"));
630 TestImageTargetActivatedTwiceL();
633 INFO_PRINTF1(_L("TestImageSourceActivatedTwiceL\r\n"));
634 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0006"));
635 TestImageSourceActivatedTwiceL();
638 INFO_PRINTF1(_L("TestDrawableSourceActivatedTwiceL\r\n"));
639 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0007"));
640 TestDrawableSourceActivatedTwiceL();
643 INFO_PRINTF1(_L("TestBrushPatternNotSetL\r\n"));
644 SetTestStepID(_L("GRAPHICS-DIRECTGDI-PANIC-0008"));
645 TestBrushPatternNotSetL();