sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "tcompressed.h" sl@0: sl@0: CTCompressed::CTCompressed(CTestStep* aStep) : sl@0: CTGraphicsBase(aStep) sl@0: { sl@0: } sl@0: sl@0: void CTCompressed::BlankBitmap(CFbsBitmapEx& aBitmap) sl@0: { sl@0: TSize size = aBitmap.SizeInPixels(); sl@0: TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight; sl@0: aBitmap.LockHeap(); sl@0: Mem::FillZ((TUint8*)aBitmap.DataAddress(),dataLength); sl@0: aBitmap.UnlockHeap(); sl@0: } sl@0: sl@0: void CTCompressed::RunTestCaseL(TInt aCurTestCase) sl@0: { sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(aCurTestCase) sl@0: { sl@0: case 1: sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0571")); sl@0: TRAPD(err, RunTestL()); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 2: sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0572")); sl@0: TRAP(err, DefectFix_EXT5DXGK6_L()); sl@0: TEST(err == KErrNone); sl@0: break; sl@0: case 3: sl@0: { sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0500")); sl@0: // Set size of bitmap large enough to warrant compression sl@0: const TSize KBitmapSize(200,200); sl@0: INFO_PRINTF1(_L("Test case for INC082713\r\n")); sl@0: TRAP(err, DefectFix_INC082713_L(EColor16MU, KBitmapSize)); sl@0: TEST(err == KErrNone); sl@0: TRAP(err, DefectFix_INC082713_L(EColor16MA, KBitmapSize)); sl@0: TEST(err == KErrNone); sl@0: } sl@0: break; sl@0: case 4: sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0573")); sl@0: TRAPD(err1, INC088856_TestL()); sl@0: TEST(err1 == KErrNone); sl@0: break; sl@0: case 5: sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0615")); sl@0: TestDestroyBitmapWhileBeingBackgroundCompressedL(); sl@0: break; sl@0: case 6: sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0616")); sl@0: TestBackgroundCompressionThreadPriorityInheritanceL(); sl@0: break; sl@0: case 7: sl@0: ((CTCompressedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: ((CTCompressedStep*)iStep)->CloseTMSGraphicsStep(); sl@0: TestComplete(); sl@0: break; sl@0: } sl@0: ((CTCompressedStep*)iStep)->RecordTestResultL(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FBSERV-0571 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests compression of bitmaps in RAM and ROM. sl@0: sl@0: @SYMTestActions sl@0: Four bitmaps are loaded. One compressed and one sl@0: uncompressed from ROM and from RAM. The bitmap sl@0: in RAM is tested if it can be compressed successfully. sl@0: The bitmap in ROM should fail when tried to be compressed. sl@0: All of the bitmaps are then tried to be BitBlt. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTCompressed::RunTestL() sl@0: { sl@0: TInt skipRomBitmapTests = EFalse; sl@0: TUint32* romAddress = NULL; sl@0: if(!CFbsBitmap::IsFileInRom(KRomNotCompressed, romAddress)) //any ROM bitmap sl@0: { sl@0: INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."), sl@0: &KRomNotCompressed); sl@0: INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported.")); sl@0: skipRomBitmapTests = ETrue; sl@0: } sl@0: sl@0: TBuf<64> romNotCompressed(KRomNotCompressed); sl@0: TBuf<64> romCompressed(KRomCompressed); sl@0: TBuf<64> fileNotCompressed(KFileNotCompressed); sl@0: TBuf<64> fileCompressed(KFileCompressed); sl@0: sl@0: TInt ret = KErrNone; sl@0: CFbsBitmap rom; sl@0: CFbsBitmap romcomp; sl@0: sl@0: if(!skipRomBitmapTests) sl@0: { sl@0: TEST(rom.Load(romNotCompressed, 0, EFalse)== KErrNone); sl@0: TEST(romcomp.Load(romCompressed, 0, EFalse)== KErrNone); sl@0: sl@0: INFO_PRINTF1(_L("Check compressing of ROM bitmaps causes error.\r\n")); sl@0: ret = rom.Compress(); sl@0: TEST(ret == KErrAccessDenied); //cannot compress bitmaps in ROM sl@0: TEST(rom.IsCompressedInRAM()); sl@0: } sl@0: sl@0: CFbsBitmap file; sl@0: CFbsBitmap filecomp; sl@0: TEST(file.Load(fileNotCompressed, 0, EFalse)== KErrNone); sl@0: TEST(filecomp.Load(fileCompressed, 0, EFalse)== KErrNone); sl@0: sl@0: INFO_PRINTF1(_L("Check compressing of RAM files is OK.\r\n")); sl@0: CFbsBitmap ram; sl@0: ret=ram.Load(fileNotCompressed,0,EFalse); sl@0: TEST(ret == KErrNone); sl@0: ret = ram.Compress(); sl@0: TEST(ret == KErrNone); //can compress bitmaps in RAM sl@0: TEST(ram.IsCompressedInRAM()); sl@0: sl@0: INFO_PRINTF1(_L("Check compressing a created EColor256 bitmap.\r\n")); sl@0: CFbsBitmapEx created; sl@0: ret=created.Create(TSize(200,200),EColor256); sl@0: TEST(ret==KErrNone); sl@0: sl@0: // This makes sure we can compress it... sl@0: BlankBitmap(created); sl@0: sl@0: ret = created.Compress(); sl@0: TEST(ret==KErrNone); sl@0: TEST(created.IsCompressedInRAM()); sl@0: sl@0: INFO_PRINTF1(_L("Check compressing a created EColor24MU bitmap.\r\n")); sl@0: CFbsBitmapEx created24MU; sl@0: ret=created24MU.Create(TSize(200,200),EColor16MU); sl@0: TEST(ret==KErrNone); sl@0: sl@0: // This makes sure we can compress it... sl@0: BlankBitmap(created24MU); sl@0: sl@0: ret = created24MU.Compress(); sl@0: TEST(ret==KErrNone); sl@0: TEST(created24MU.IsCompressedInRAM()); sl@0: sl@0: INFO_PRINTF1(_L("Try bitblt on all bitmaps")); sl@0: for (TInt mode = EGray2; mode < EColorLast; mode++) sl@0: { sl@0: if(!skipRomBitmapTests) sl@0: { sl@0: INFO_PRINTF2(_L("BitBlt rom with %d display mode.\r\n"), mode); sl@0: TestBitBltL(rom, TDisplayMode(mode)); sl@0: INFO_PRINTF2(_L("BitBlt romcomp with %d display mode.\r\n"), mode); sl@0: TestBitBltL(romcomp, TDisplayMode(mode)); sl@0: } sl@0: INFO_PRINTF2(_L("BitBlt file with %d display mode.\r\n"), mode); sl@0: TestBitBltL(file, TDisplayMode(mode)); sl@0: INFO_PRINTF2(_L("BitBlt filecomp with %d display mode.\r\n"), mode); sl@0: TestBitBltL(filecomp, TDisplayMode(mode)); sl@0: INFO_PRINTF2(_L("BitBlt ram with %d display mode.\r\n"), mode); sl@0: TestBitBltL(ram, TDisplayMode(mode)); sl@0: INFO_PRINTF2(_L("BitBlt created with %d display mode.\r\n"), mode); sl@0: TestBitBltL(created, TDisplayMode(mode)); sl@0: INFO_PRINTF2(_L("BitBlt 24MU created bitmap with %d display mode.\r\n"), mode); sl@0: TestBitBltL(created24MU, TDisplayMode(mode)); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FBSERV-0572 sl@0: sl@0: @SYMTestCaseDesc sl@0: Testcode to check for fix to defect EXT-5DXGK6 Bitmap sl@0: compression causes crash when loading skins. sl@0: Its not a conclusive test as it depends on where the sl@0: bitmap is loaded into memory and if there is sl@0: memory allocated at the end of the bitmap. sl@0: sl@0: @SYMTestActions sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTCompressed::DefectFix_EXT5DXGK6_L() sl@0: { sl@0: CFbsBitmapEx bmp1; sl@0: TSize size(1000,1); sl@0: TInt ret=bmp1.Create(size,EGray2); sl@0: TEST(ret==KErrNone); sl@0: BlankBitmap(bmp1); sl@0: // sl@0: // calculate the size of the destination scan line in bytes sl@0: // + 31 to pad to 4 byte boundary; 8 bits in a byte sl@0: TInt source_buffer_size = (size.iWidth + 31) / 8 ; sl@0: TUint8* buffer = new(ELeave) TUint8[source_buffer_size]; sl@0: TPtr8 source_ptr(buffer,source_buffer_size,source_buffer_size); sl@0: sl@0: for(TInt ii = 0; iiChangeScreenDevice(NULL); sl@0: CFbsBitGc* sgc; sl@0: if (scd->CreateContext((CGraphicsContext*&)sgc)==KErrNone) sl@0: { sl@0: CleanupStack::PushL(sgc); sl@0: sl@0: TSize halfScreen = scd->SizeInPixels(); sl@0: halfScreen.iWidth /= 2; sl@0: sl@0: INFO_PRINTF1(_L("BitBlt...")); sl@0: sgc->BitBlt(TPoint(halfScreen.iWidth,0),&aBmp); sl@0: INFO_PRINTF1(_L("worked\r\n")); sl@0: sl@0: CleanupStack::PopAndDestroy(sgc); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Could not create context in %d mode.\r\n"), aDispMode); sl@0: } sl@0: CleanupStack::PopAndDestroy(scd); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FBSERV-0573 sl@0: sl@0: @SYMDEF INC088856 sl@0: sl@0: @SYMTestCaseDesc sl@0: Verifies defect INC088856. Checks the sl@0: updated padding value before compression for sl@0: 256 gray scale and 64k colour. sl@0: sl@0: @SYMTestActions sl@0: Creates a bitmap. Gets the bitmaps scanline length. sl@0: Locks the heap. Retrieves the bitmaps data address. sl@0: Unlocks the heap. Then for both 256 gray scale and 64k colour sl@0: it checks the padding after compression matches before compression. sl@0: sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTCompressed::INC088856_TestL() sl@0: { sl@0: INFO_PRINTF1(_L("Check updated Padding value in before compression \r\n")); sl@0: sl@0: INFO_PRINTF1(_L("Check updated Padding value for EGray256 \r\n")); sl@0: DoUpdateOnPadding(TSize(5,3),EGray256); sl@0: DoUpdateOnPadding(TSize(25,43),EGray256); sl@0: sl@0: INFO_PRINTF1(_L("Check updated Padding value for EColor64K \r\n")); sl@0: DoUpdateOnPadding(TSize(5,3),EColor64K); sl@0: DoUpdateOnPadding(TSize(25,43),EColor64K); sl@0: } sl@0: sl@0: void CTCompressed::DoUpdateOnPadding(const TSize aSize, const TDisplayMode aDispMode) sl@0: { sl@0: CFbsBitmapEx bmp1; sl@0: TInt ret=bmp1.Create(aSize,aDispMode); sl@0: TEST(ret==KErrNone); sl@0: sl@0: TInt dataLength = CFbsBitmap::ScanLineLength(aSize.iWidth, bmp1.DisplayMode()) * aSize.iHeight; sl@0: sl@0: bmp1.LockHeap(); sl@0: TUint8* srcBits = (TUint8*)bmp1.DataAddress(); sl@0: bmp1.UnlockHeap(); sl@0: TInt val=1,pos=0; sl@0: switch (aDispMode) sl@0: { sl@0: case EGray256: sl@0: { sl@0: TUint8* bmpBits = srcBits; sl@0: TUint8* bmpBitsLimit = srcBits + dataLength; sl@0: while(bmpBitsCreate(KSize, KMode)); sl@0: } sl@0: sl@0: for (TInt idx=0; idxCompressInBackground()); sl@0: } sl@0: sl@0: // Delete bitmaps in reverse order sl@0: CleanupStack::PopAndDestroy(KNumOfBitmaps, bitmaps[0]); sl@0: sl@0: // TestCase #2 sl@0: // Create N bitmap instances, compress them in background and destroy them in the compression order sl@0: // without waiting compression to complete sl@0: INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in forward order"), KNumOfBitmaps); sl@0: sl@0: for (TInt idx=0; idxCreate(KSize, KMode)); sl@0: } sl@0: sl@0: for (TInt idx=0; idxCompressInBackground()); sl@0: } sl@0: sl@0: // Delete bitmaps in compression order sl@0: CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]); sl@0: for (TInt idx=0; idxCreate(KSize, KMode)); sl@0: randomOrder[idx] = idx; sl@0: } sl@0: // Randomise deletion order sl@0: for (TInt idx=0; idxCompressInBackground()); sl@0: } sl@0: sl@0: // Delete bitmaps in random order sl@0: CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]); sl@0: for (TInt idx=0; idxCreate(KSize, KMode)); sl@0: User::LeaveIfError(bitmap->CompressInBackground()); sl@0: CleanupStack::PopAndDestroy(bitmap); sl@0: } sl@0: sl@0: // TestCase #5 sl@0: // Similar from #4 but executed from two different threads sl@0: INFO_PRINTF2(_L("Create bitmap,compress in background and immediately destroyed from 2 different threads. Repeat %d times"), KNumOfBitmaps); sl@0: sl@0: const TInt KStackSize = 4096; sl@0: const TInt KMinHeapSize = 4096; sl@0: const TInt KMaxHeapSize = 1024*1024; sl@0: RThread t1; sl@0: User::LeaveIfError(t1.Create(_L("bgCompThreadFunc#1"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL)); sl@0: RThread t2; sl@0: User::LeaveIfError(t2.Create(_L("bgCompThreadFunc#2"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL)); sl@0: sl@0: TRequestStatus s1; sl@0: TRequestStatus s2; sl@0: t1.Logon(s1); sl@0: t2.Logon(s2); sl@0: sl@0: t1.Resume(); sl@0: t2.Resume(); sl@0: User::WaitForRequest(s1); sl@0: User::WaitForRequest(s2); sl@0: sl@0: t1.Close(); sl@0: t2.Close(); sl@0: } sl@0: sl@0: TInt CTCompressed::BgCompThreadFunc(TAny*) sl@0: { sl@0: const TInt KNumOfBitmaps = 1000; sl@0: const TSize KSize(1,1); sl@0: const TDisplayMode KMode = EColor64K; sl@0: sl@0: // No need to worries with cleanup stack and trap as resources will be freed if the thread sl@0: // running this functions dies, panics or leaves. sl@0: sl@0: RFbsSession::Connect(); sl@0: sl@0: for (TInt idx=0; idxCreate(KSize, KMode)); sl@0: User::LeaveIfError(bitmap->CompressInBackground()); sl@0: delete bitmap; sl@0: } sl@0: sl@0: RFbsSession::Disconnect(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: * @SYMTestCaseID GRAPHICS-FBSERV-0616 sl@0: * sl@0: * @SYMDEF INC123238 sl@0: * sl@0: * @SYMTestCaseDesc sl@0: * Test Fbserv bitmap's priority inversion when we use background compression against a long running thread sl@0: * sl@0: * @SYMTestPriority High sl@0: * sl@0: * @SYMTestStatus Implemented sl@0: * sl@0: * @SYMTestActions sl@0: * Create a thread which creates a bitmap and makes a call to background compression. Once this thread resumed, sl@0: * make the current thread as busy by doing some long running task and test the exit status of the bitmap compression thread. sl@0: * sl@0: * @SYMTestExpectedResults sl@0: * Fbserv does priority inheritance and therefore protect against priority inversion, so the thread function will sl@0: * do backgroud compression and the thread will exit successfully, which will pass the test. If it is not protect sl@0: * against priority inversion with in 30 seconds(approximately) the test will fail without doing background compression. sl@0: */ sl@0: void CTCompressed::TestBackgroundCompressionThreadPriorityInheritanceL() sl@0: { sl@0: const TInt KStackSize = 4096; sl@0: const TInt KMinHeapSize = 4096; sl@0: const TInt KMaxHeapSize = 1024*1024; sl@0: const TInt KMaxViewChangeTime = 2000; sl@0: sl@0: INFO_PRINTF1(_L("Test case for Background Compression Thread Priority Inheritance\r\n")); sl@0: //Create and start a thread which create a bitmap and calls CompressInBackground sl@0: RThread thread1; sl@0: User::LeaveIfError(thread1.Create(_L("CompressBgThreadFunc"), CTCompressed::CompressBgThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL)); sl@0: thread1.Resume(); sl@0: TUint startTime = User::TickCount(); sl@0: sl@0: //Start a infinite running loop to make current thread as a busy and long running thread... sl@0: for (;;) sl@0: { sl@0: TExitType exitType = thread1.ExitType(); sl@0: if(exitType != EExitPending) sl@0: { sl@0: TInt exitReason = thread1.ExitReason(); sl@0: TEST(exitType == EExitKill); sl@0: TEST(exitReason == KErrNone); sl@0: break; sl@0: } sl@0: TUint stopTime = User::TickCount(); sl@0: if((stopTime - startTime) > KMaxViewChangeTime) //Check for the busy task is running for more than 30 seconds... sl@0: { sl@0: TEST(EFalse); sl@0: thread1.Terminate(KErrGeneral); sl@0: break; sl@0: } sl@0: } sl@0: thread1.Close(); sl@0: } sl@0: sl@0: /* sl@0: Thread function used from the test case TestBackgroundCompressionThreadPriorityInheritanceL sl@0: */ sl@0: TInt CTCompressed::CompressBgThreadFunc(TAny*) sl@0: { sl@0: const TSize KSize(100, 100); sl@0: const TDisplayMode KMode = EColor64K; sl@0: sl@0: TInt err = RFbsSession::Connect(); sl@0: if (err != KErrNone) sl@0: return err; sl@0: CFbsBitmap* bitmap = new CFbsBitmap; sl@0: if (!bitmap) sl@0: return KErrNoMemory; sl@0: err = bitmap->Create(KSize, KMode); sl@0: if (err != KErrNone) sl@0: return err; sl@0: err = bitmap->CompressInBackground(); sl@0: if (err != KErrNone) sl@0: return err; sl@0: delete bitmap; sl@0: sl@0: RFbsSession::Disconnect(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: //-------------- sl@0: __CONSTRUCT_STEP__(Compressed)