Update contrib.
1 // Copyright (c) 2008-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 "textendedbitmapcommon.h"
23 #include "textendedbitmap.h"
24 #include "examplerasterizer.h"
25 #include <graphics/fbsrasterizerclearcache.h>
28 const TUint8 KRepeatTestData[] = "(This pattern is 32 bytes long!)";
29 const TInt KRepeatTestDataSize = 32;
30 const TInt KLargeDataSize = 0x8000 * KRepeatTestDataSize;
32 CTExtendedBitmap::CTExtendedBitmap(CTestStep* aStep):
33 CTFbsBase(aStep, ETrue)
37 CTExtendedBitmap::~CTExtendedBitmap()
39 ((CTExtendedBitmapStep*)iStep)->CloseTMSGraphicsStep();
40 User::Free(iLargeData);
43 void CTExtendedBitmap::ConstructL()
45 TRAPD(err, iLargeData = static_cast<TUint8*>(User::AllocL(KLargeDataSize)));
48 INFO_PRINTF3(_L("Error allocating large data buffer (size %d) in CTExtendedBitmap::ConstructL(), %d"), KLargeDataSize, err);
51 for (TInt i = 0; i < KLargeDataSize; i += KRepeatTestDataSize)
53 Mem::Copy(PtrAdd(iLargeData, i), KRepeatTestData, KRepeatTestDataSize);
56 // Save a pointer to the example rasterizer's MFbsRasterizerClearCache interface
57 if (CFbsRasterizer* rasterizer = CFbsBitmap::Rasterizer())
59 err = rasterizer->GetInterface(TUid::Uid(KUidFbsRasterizerClearCache), (TAny*&)iRasterizerClearCache);
62 WARN_PRINTF1(_L("Failed to get a MFbsRasterizerClearCache interface for the current rasterizer, tests will panic during OOM testing due to the rasterizer cache not being cleared"));
67 void CTExtendedBitmap::RunFbsTestL(TInt aCurTestCase)
69 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
73 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0001"));
74 CreateExtendedBitmapL();
77 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0002"));
78 CreateLargeExtendedBitmapL();
81 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0003"));
82 CreateUsingInitializerL();
85 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0004"));
89 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0004"));
93 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0040"));
94 TestGetPixelL(EFalse);
97 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0040"));
101 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0042"));
102 TestGetVerticalScanLineL(EFalse);
105 ((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-EXTENDEDBITMAP-0042"));
106 TestGetVerticalScanLineL(ETrue);
108 // Fall through as last test case
113 ((CTExtendedBitmapStep*)iStep)->RecordTestResultL();
119 GRAPHICS-FBSERV-EXTENDEDBITMAP-0001
122 Create an extended bitmap and retrieve data
144 Creates an extended bitmap using test data and test Uid;
145 Retrieves and validates the data size, data and Uid.
147 @SYMTestExpectedResults
148 Extended bitmap created and information correctly retrieved.
150 void CTExtendedBitmap::CreateExtendedBitmapL()
152 INFO_PRINTF1(_L("Create an extended bitmap"));
154 const TUint8 KTestData[] = "Extended bitmap test data 123456";
155 const TInt KTestDataSize = sizeof(KTestData);
156 const TSize KSizeInPixels = TSize(50,50);
157 const TDisplayMode KDisplayMode = EColor64K;
159 CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
160 CleanupStack::PushL(bmp);
161 TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KTestData, KTestDataSize);
164 bmp->BeginDataAccess();
166 TInt returnedDataSize = bmp->DataSize();
167 TESTEQUALL(KTestDataSize, returnedDataSize);
168 INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KTestDataSize, returnedDataSize);
170 const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
171 res = Mem::Compare(returnedDataAddress,returnedDataSize, KTestData, KTestDataSize);
174 TUid returnedUid = bmp->ExtendedBitmapType();
175 TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
177 bmp->EndDataAccess(ETrue);
179 CleanupStack::PopAndDestroy(bmp);
185 GRAPHICS-FBSERV-EXTENDEDBITMAP-0002
188 Create an extended bitmap with data sized 1MB
204 Create an extended bitmap with a buffer that is 1MB.
206 @SYMTestExpectedResults
207 No errors or panics should occur.
209 void CTExtendedBitmap::CreateLargeExtendedBitmapL()
211 INFO_PRINTF1(_L("Create an extended bitmap with data size 1MB"));
213 const TSize KSizeInPixels = TSize(50,50);
214 const TDisplayMode KDisplayMode = EColor64K;
216 CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
217 CleanupStack::PushL(bmp);
218 TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, iLargeData, KLargeDataSize);
221 bmp->BeginDataAccess();
223 TInt returnedDataSize = bmp->DataSize();
224 TESTEQUALL(KLargeDataSize, returnedDataSize);
225 INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KLargeDataSize, returnedDataSize);
227 const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
228 res = Mem::Compare(returnedDataAddress, returnedDataSize, iLargeData, KLargeDataSize);
231 TUid returnedUid = bmp->ExtendedBitmapType();
232 TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
234 bmp->EndDataAccess(ETrue);
236 CleanupStack::PopAndDestroy(bmp);
242 GRAPHICS-FBSERV-EXTENDEDBITMAP-0003
245 Create an extended bitmap using an MFbsExtendedBitmapInitializer
259 Create an extended bitmap using an MFbsExtendedBitmapInitializer, with a buffer that is 1MB.
261 @SYMTestExpectedResults
262 Extended bitmap created and information correctly retrieved.
264 void CTExtendedBitmap::CreateUsingInitializerL()
266 INFO_PRINTF1(_L("Create an extended bitmap using an MFbsExtendedBitmapInitializer"));
268 const TSize KSizeInPixels = TSize(50,50);
269 const TDisplayMode KDisplayMode = EColor64K;
271 CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
272 CleanupStack::PushL(bmp);
273 CTestExtendedBitmapInitializer* initializer = new(ELeave) CTestExtendedBitmapInitializer(iLargeData, KLargeDataSize);
274 CleanupStack::PushL(initializer);
275 TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidTestExtendedBitmap, KLargeDataSize, *initializer);
276 CleanupStack::PopAndDestroy(initializer);
279 bmp->BeginDataAccess();
281 TInt returnedDataSize = bmp->DataSize();
282 TESTEQUALL(KLargeDataSize, returnedDataSize);
283 INFO_PRINTF3(_L("Test data size on creation: %i. Test data size returned: %i"), KLargeDataSize, returnedDataSize);
285 const TUint8* returnedDataAddress = reinterpret_cast<TUint8*>(bmp->DataAddress());
286 res = Mem::Compare(returnedDataAddress, returnedDataSize, iLargeData, KLargeDataSize);
289 TUid returnedUid = bmp->ExtendedBitmapType();
290 TESTEQUALL(KUidTestExtendedBitmap, returnedUid);
292 bmp->EndDataAccess(ETrue);
294 CleanupStack::PopAndDestroy(bmp);
299 GRAPHICS-FBSERV-EXTENDEDBITMAP-0004
302 Create an extended bitmap and retrieve scanline
317 Creates an extended bitmap using data compatible with the
319 If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
320 to create a duplicate of the extended bitmap just created and
321 complete the test using the duplicate extended bitmap.
322 Get a scanline using CFbsBitmap::GetScanLine() and check if
323 it is correct, depending on the presence of the rasterizer.
325 @SYMTestExpectedResults
326 Extended bitmap created and scanline correctly retrieved.
328 void CTExtendedBitmap::ScanLineL(TBool aUseDuplicateBitmap)
330 INFO_PRINTF1(_L("Get a scanline from an extended bitmap"));
332 const TRgb KColors[] = {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
333 // Small size needed for this test O(x^2 * y) iterations run every time
334 const TSize KSizeInPixels = TSize(8,5);
335 const TDisplayMode KDisplayMode = EColor64K;
336 const TUint8 horizontalStripes = 1;
338 // Check to see if we have an example bitmap rasterizer available for this test run
339 iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
340 if (iRasterizerAvailable)
342 INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));
346 INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
349 CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
351 TInt dataSize = sizeof(KColors)+sizeof(horizontalStripes); // estimate the data size
352 TUint8* data = new(ELeave) TUint8[dataSize];
353 CleanupStack::PushL(data);
355 // Write the colours to be used in the extended bitmap to the data
357 ws.Open(data, dataSize);
358 CleanupClosePushL(ws);
359 ws << KColors[0] << KColors[1] << KColors[2] << horizontalStripes;
360 dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
361 CleanupStack::PopAndDestroy(1, &ws);
363 // Create the extended bitmap to be used a a brush
364 CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
365 CleanupStack::PushL(bmp);
366 TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
369 if (aUseDuplicateBitmap)
371 INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
372 CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
373 CleanupStack::PushL(duplicateBmp);
374 res = duplicateBmp->Duplicate(bmp->Handle());
379 TInt byteWidth = CFbsBitmap::ScanLineLength(KSizeInPixels.iWidth, KDisplayMode);
380 TUint8* buffer = new(ELeave) TUint8[byteWidth + 1];
381 CleanupArrayDeletePushL(buffer);
383 const TUint8 KCheckValue = 0x69; // Pixel value used as guard at the end of the buffer used
384 buffer[byteWidth] = KCheckValue;
385 TPtr8 scanLine(buffer,byteWidth,byteWidth);
388 TInt firstStripe, lastStripe;
390 if(horizontalStripes)
392 firstStripe = KSizeInPixels.iHeight/3;
393 lastStripe = KSizeInPixels.iHeight - firstStripe;
398 firstStripe = KSizeInPixels.iWidth/3;
399 lastStripe = KSizeInPixels.iWidth - firstStripe;
403 for(y = 0; y < KSizeInPixels.iHeight; ++y)
405 for(TInt length = 1; length <= KSizeInPixels.iWidth; ++length)
407 for(TInt pos = KSizeInPixels.iWidth - length; pos >= 0; --pos)
409 bmp->GetScanLine(scanLine, TPoint(pos,y), length, KDisplayMode);
410 for(x = pos + length - 1; x >= pos; --x)
412 TRgb bufferColor = ExtractRgb(buffer, x-pos, KDisplayMode);
414 if(!iRasterizerAvailable)
416 TESTCOLOREQUALL(bufferColor, KRgbWhite);
418 else if (*s < firstStripe)
421 TESTCOLOREQUALL(bufferColor, KColors[0]);
423 else if (*s >= lastStripe)
426 TESTCOLOREQUALL(bufferColor, KColors[2]);
431 TESTCOLOREQUALL(bufferColor, KColors[1]);
438 // Check that the guard byte is still intact now that the tests have been run
439 TEST(buffer[byteWidth] == KCheckValue);
441 if (aUseDuplicateBitmap)
443 CleanupStack::PopAndDestroy(1);
445 CleanupStack::PopAndDestroy(4);
451 GRAPHICS-FBSERV-EXTENDEDBITMAP-0040
454 Create an extended bitmap and retrieve pixels
469 Creates an extended bitmap using data compatible with the
471 If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
472 to create a duplicate of the extended bitmap just created and
473 complete the test using the duplicate extended bitmap.
474 Get pixel values using CFbsBitmap::GetPixel() and check if
475 they are correct, depending on the presence of the rasterizer.
477 @SYMTestExpectedResults
478 Extended bitmap created and pixels correctly retrieved.
480 void CTExtendedBitmap::TestGetPixelL(TBool aUseDuplicateBitmap)
482 INFO_PRINTF1(_L("Get pixel values from an extended bitmap"));
484 const TRgb KColors[] = {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
485 const TSize KSizeInPixels = TSize(8,5);
486 const TDisplayMode KDisplayMode = EColor64K;
487 const TUint8 KHorizontalStripes = 1;
489 // Check to see if we have an example bitmap rasterizer available for this test run
490 iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
491 if (iRasterizerAvailable)
493 INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));
497 INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
500 CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
502 TInt dataSize = sizeof(KColors)+sizeof(KHorizontalStripes); // estimate the data size
503 TUint8* data = new(ELeave) TUint8[dataSize];
504 CleanupStack::PushL(data);
506 // Write the colours to be used in the extended bitmap to the data
508 ws.Open(data, dataSize);
509 CleanupClosePushL(ws);
510 ws << KColors[0] << KColors[1] << KColors[2] << KHorizontalStripes;
511 dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
512 CleanupStack::PopAndDestroy(1, &ws);
514 // Create the extended bitmap
515 CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
516 CleanupStack::PushL(bmp);
517 TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
520 if (aUseDuplicateBitmap)
522 INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
523 CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
524 CleanupStack::PushL(duplicateBmp);
525 res = duplicateBmp->Duplicate(bmp->Handle());
530 TInt firstStripe = KSizeInPixels.iHeight/3;
531 TInt lastStripe = KSizeInPixels.iHeight - firstStripe;
533 for(TInt y = 0; y < KSizeInPixels.iHeight; ++y)
535 for(TInt x = 0; x < KSizeInPixels.iWidth; ++x)
537 bmp->GetPixel(color, TPoint(x,y));
539 if(!iRasterizerAvailable)
541 TESTCOLOREQUALL(color, KRgbWhite);
543 else if (y < firstStripe)
546 TESTCOLOREQUALL(color, KColors[0]);
548 else if (y >= lastStripe)
551 TESTCOLOREQUALL(color, KColors[2]);
556 TESTCOLOREQUALL(color, KColors[1]);
561 if (aUseDuplicateBitmap)
563 CleanupStack::PopAndDestroy(1);
565 CleanupStack::PopAndDestroy(3);
572 GRAPHICS-FBSERV-EXTENDEDBITMAP-0042
575 Create an extended bitmap and retrieve vertical scanline
587 Create an extended bitmap using data compatible with the
589 If (aUseDuplicateBitmap == ETrue) use CFbsBitmap::Duplicate()
590 to create a duplicate of the extended bitmap just created and
591 complete the test using the duplicate extended bitmap.
592 Get a vertical scanline using CFbsBitmap::GetVerticalScanLine() and check
593 if it is correct, depending on the presence of the rasterizer.
595 @SYMTestExpectedResults
596 Extended bitmap created and scanline correctly retrieved.
598 void CTExtendedBitmap::TestGetVerticalScanLineL(TBool aUseDuplicateBitmap)
600 INFO_PRINTF1(_L("Get a vertical scanline from an extended bitmap"));
602 const TRgb KColors[] = {TRgb(0,0,0), TRgb(255,0,0), TRgb(255,255,0)};
603 const TSize KSizeInPixels = TSize(5,8);
604 const TDisplayMode KDisplayMode = EColor64K;
605 const TUint8 KHorizontalStripes = 1;
607 // Check to see if we have an example bitmap rasterizer available for this test run
608 iRasterizerAvailable = (CFbsBitmap::Rasterizer() != NULL);
609 if (iRasterizerAvailable)
611 INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));
615 INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
618 CleanupStack::PushL(TCleanupItem(ClearRasterizerCache, iRasterizerClearCache));
620 TInt dataSize = sizeof(KColors)+sizeof(KHorizontalStripes); // estimate the data size
621 TUint8* data = new(ELeave) TUint8[dataSize];
622 CleanupStack::PushL(data);
624 // Write the colours to be used in the extended bitmap to the data
626 ws.Open(data, dataSize);
627 CleanupClosePushL(ws);
628 ws << KColors[0] << KColors[1] << KColors[2] << KHorizontalStripes;
629 dataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
630 CleanupStack::PopAndDestroy(1, &ws);
632 // Create the extended bitmap
633 CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
634 CleanupStack::PushL(bmp);
635 TInt res = bmp->CreateExtendedBitmap(KSizeInPixels, KDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
638 if (aUseDuplicateBitmap)
640 INFO_PRINTF1(_L("Testing using a duplicated extended bitmap"));
641 CFbsBitmap* duplicateBmp = new(ELeave) CFbsBitmap;
642 CleanupStack::PushL(duplicateBmp);
643 res = duplicateBmp->Duplicate(bmp->Handle());
648 TInt byteWidth = CFbsBitmap::ScanLineLength(KSizeInPixels.iHeight, KDisplayMode);
649 TUint8* buffer = new(ELeave) TUint8[byteWidth + 1];
650 CleanupArrayDeletePushL(buffer);
652 const TUint8 KCheckValue = 0x69; // Pixel value used as guard at the end of the buffer used
653 buffer[byteWidth] = KCheckValue;
654 TPtr8 scanLine(buffer,byteWidth,byteWidth);
656 TInt firstStripe = KSizeInPixels.iHeight/3;
657 TInt lastStripe = KSizeInPixels.iHeight - firstStripe;
659 for(TInt x = 0; x < KSizeInPixels.iWidth; ++x)
661 bmp->GetVerticalScanLine(scanLine, x, KDisplayMode);
662 for(TInt y = 0; y < KSizeInPixels.iHeight; ++y)
664 TRgb bufferColor = ExtractRgb(buffer, y, KDisplayMode);
665 if(!iRasterizerAvailable)
667 TESTCOLOREQUALL(bufferColor, KRgbWhite);
669 else if (y < firstStripe)
672 TESTCOLOREQUALL(bufferColor, KColors[0]);
674 else if (y >= lastStripe)
677 TESTCOLOREQUALL(bufferColor, KColors[2]);
682 TESTCOLOREQUALL(bufferColor, KColors[1]);
687 // Check that the guard byte is still intact now that the tests have been run
688 TEST(buffer[byteWidth] == KCheckValue);
690 if (aUseDuplicateBitmap)
692 CleanupStack::PopAndDestroy(1);
694 CleanupStack::PopAndDestroy(4);
698 __CONSTRUCT_STEP__(ExtendedBitmap)
700 /** Method to be used with a TCleanupItem for clearing the extended bitmap rasterizer cache
701 from the cleanup stack. Calls the MExampleRasterizerClearCache::ClearCache() method on the
702 passed CFbsRasterizer object if the MExampleRasterizerClearCache extension interface is available
704 @param aPtr A pointer to the current CFbsRasterizer object, or NULL if no rasterizer
707 void CTExtendedBitmap::ClearRasterizerCache(TAny* aPtr)
711 static_cast<MFbsRasterizerClearCache*>(aPtr)->ClearCache();