Update contrib.
1 // Copyright (c) 2005-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.
20 #include <graphics/gdi/gdiconsts.h>
21 #include "../sfbs/UTILS.H"
23 #include "fbsmessage.h"
26 // Define FBSTEST_SCREENSHOT to save the screen to a .mbm file
27 //#define FBSTEST_SCREENSHOT
29 const TInt KNumBitmap = 3;
30 const TDisplayMode KDisplayMode = EColor64K;
31 const TSize KLargeSize(128,128);
32 const TSize KMidSize(64,64);
33 const TSize KSmallSize(32,32);
36 _LIT(KRamFile1,"c:\\rf1.mbm");
37 _LIT(KRamFile2,"c:\\rf2.mbm");
38 _LIT(KRamFile3,"c:\\rf3.mbm");
39 _LIT(KRamFile4,"c:\\rf123.mbm");
40 _LIT(KRomFile1,"z:\\system\\data\\rf1.mbm");
41 _LIT(KRomFile2,"z:\\system\\data\\rf2.mbm");
42 _LIT(KRomFile3,"z:\\system\\data\\rf3.mbm");
43 _LIT(KRomFile4,"z:\\system\\data\\rf123.mbm");
46 CTFile::CTFile(CTestStep* aStep):
47 CTGraphicsBase(aStep),
57 iFbs->SendCommand(EFbsMessShutdown);
62 void CTFile::ConstructL()
64 if(RFbsSession::Connect()==KErrNone)
66 RFbsSession::Disconnect();
67 iShutdownFbs = EFalse;
75 TInt ret = RFbsSession::Connect();
77 iFbs = RFbsSession::GetSession();
82 // required to allow file handle to be adopted by another process
85 TUint32* romAddress = NULL;
86 if(!CFbsBitmap::IsFileInRom(KRomFile1, romAddress)) //any ROM bitmap
88 INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
90 INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
91 iSkipRomBitmapTests = ETrue;
95 void CTFile::CleanUp()
97 const TBufC<32> names[KNumBitmap] =
99 (const TDesC&)KRamFile1,
100 (const TDesC&)KRamFile2,
101 (const TDesC&)KRamFile3
104 for (i=0; i<KNumBitmap; ++i)
107 iFs.Delete(names[i]);
110 iFs.Delete(KRamFile4);
114 void CTFile::RunTestCaseL(TInt aCurTestCase)
116 ((CTFileStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
120 ((CTFileStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0588"));
124 ((CTFileStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0589"));
128 ((CTFileStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0590"));
132 ((CTFileStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0591"));
136 ((CTFileStep*)iStep)->SetTestStepID(_L(" GRAPHICS-FBSERV-0592"));
140 ((CTFileStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
141 ((CTFileStep*)iStep)->CloseTMSGraphicsStep();
145 ((CTFileStep*)iStep)->RecordTestResultL();
152 void CTFile::Draw(CFbsBitGc* aGc, const TSize& aSize)
154 const TSize thick(aSize.iWidth/4,aSize.iWidth/4);
155 const TSize thin(thick.iWidth/2,thick.iWidth/2);
158 aGc->SetBrushColor(KRgbBlue);
159 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
160 aGc->SetPenStyle(CGraphicsContext::ESolidPen);
161 aGc->DrawRect(aSize);
163 // corner to corner section
164 aGc->SetPenColor(KRgbWhite);
165 aGc->SetPenSize(thick);
166 aGc->DrawLine(TPoint(0,0),TPoint(aSize.iWidth,aSize.iHeight));
167 aGc->DrawLine(TPoint(aSize.iWidth,0),TPoint(0,aSize.iHeight));
168 aGc->SetPenColor(KRgbRed);
169 aGc->SetPenSize(thin);
170 aGc->DrawLine(TPoint(0,0),TPoint(aSize.iWidth,aSize.iHeight));
171 aGc->DrawLine(TPoint(aSize.iWidth,0),TPoint(0,aSize.iHeight));
174 aGc->SetPenColor(KRgbWhite);
175 aGc->SetPenSize(thick);
176 aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));
177 aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));
178 aGc->SetPenColor(KRgbRed);
179 aGc->SetPenSize(thin);
180 aGc->DrawLine(TPoint(aSize.iWidth/2,0),TPoint(aSize.iWidth/2,aSize.iHeight));
181 aGc->DrawLine(TPoint(0,aSize.iHeight/2),TPoint(aSize.iWidth,aSize.iHeight/2));
192 Create various size bitmap for testing (original bitmaps)
193 ie small (<4KB), mid (=4KB) and large (>4KB).
197 @SYMTestExpectedResults
200 void CTFile::CreateL()
202 const TSize sizes[KNumBitmap] =
209 for (i=0; i<KNumBitmap; ++i)
211 CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
212 CleanupStack::PushL(bmp);
213 User::LeaveIfError(bmp->Create(sizes[i],KDisplayMode));
215 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(bmp);
216 CleanupStack::PushL(dev);
219 User::LeaveIfError(dev->CreateContext(gc));
224 CleanupStack::PopAndDestroy(dev);
226 iSource.AppendL(bmp);
228 CleanupStack::Pop(bmp);
237 Save single bitmap to file using an opened file handle
240 Save original bitmap to file using file handle (saved bitmap)
241 Load saved bitmap using file name and compare against original
242 Leave saved bitmap files for next test (Load,LoadAndCompress)
244 @SYMTestExpectedResults
245 Saved bitmap match original bitmap
249 const TBufC<32> names[KNumBitmap] =
251 (const TDesC&)KRamFile1,
252 (const TDesC&)KRamFile2,
253 (const TDesC&)KRamFile3
256 INFO_PRINTF1(_L("Saving bitmap"));
258 for (i=0; i<KNumBitmap; ++i)
261 TInt mode = EFileWrite;
262 TInt ret = f.Open(iFs,names[i],mode);
263 if (ret==KErrNotFound)
264 ret = f.Create(iFs,names[i],mode);
267 TEST(iSource[i]->Save(f)==KErrNone);
271 TEST(bmp.Load(names[i])==KErrNone);
273 CFbsBitmap* orig = iSource[i];
274 TSize size = orig->SizeInPixels();
275 TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
278 TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
289 Save multi bitmaps to file using an opened file handle.
292 Save original bitmaps to file (saved bitmaps).
293 Load saved bitmaps and compare it against originals.
295 @SYMTestExpectedResults
296 Saved bitmaps match original bitmaps
298 void CTFile::StoreL()
300 const TBufC<32> names[KNumBitmap] =
302 (const TDesC&)KRamFile1,
303 (const TDesC&)KRamFile2,
304 (const TDesC&)KRamFile3
306 INFO_PRINTF1(_L("Storing bitmaps"));
308 TInt mode = EFileWrite;
309 TInt ret = f.Open(iFs,KRamFile4,mode);
310 if (ret==KErrNotFound)
311 ret = f.Create(iFs,KRamFile4,mode);
314 const TDesC* bmps[] = {&names[0],&names[1],&names[2]};
315 TInt32 ids[] = {0,0,0};
316 TRAP(ret,CFbsBitmap::StoreL(f,KNumBitmap,bmps,ids));
321 for (id=0; id<KNumBitmap; ++id)
324 TEST(bmp.Load(KRamFile4,id)==KErrNone);
326 CFbsBitmap* orig = iSource[id];
327 TSize size = orig->SizeInPixels();
328 TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
331 TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
342 Load bitmap from file using an opened file handle.
345 Load bitmap using file handle.
346 Compare loaded bitmaps against original.
348 @SYMTestExpectedResults
349 Loaded bitmap match original
353 // Load single bitmap file
354 const TBufC<32> names[2*KNumBitmap] =
356 (const TDesC&)KRamFile1, //keep ram files at the top to make it easier to skip rom bitmaps
357 (const TDesC&)KRamFile2,
358 (const TDesC&)KRamFile3,
359 (const TDesC&)KRomFile1,
360 (const TDesC&)KRomFile2,
361 (const TDesC&)KRomFile3
363 INFO_PRINTF1(_L("Loading bitmaps"));
365 TInt maxIndex = (iSkipRomBitmapTests ? KNumBitmap - 1 : 2 * KNumBitmap - 1);
366 for (i=0; i <= maxIndex; ++i)
369 TInt mode = EFileShareReadersOnly;
370 TInt ret = f.Open(iFs,names[i],mode);
373 TEST(bmp.Load(f)==KErrNone);
376 CFbsBitmap* orig = iSource[i%KNumBitmap];
377 TSize size = orig->SizeInPixels();
378 TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
381 TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
386 // Load multi bitmap file
387 const TBufC<32> mbm[] =
389 (const TDesC&)KRamFile4, //keep ram files at the top to make it easier to skip rom bitmaps
390 (const TDesC&)KRomFile4
392 maxIndex = (iSkipRomBitmapTests ? 0 : 1);
393 for (i=0; i <= maxIndex; ++i)
396 TInt mode = EFileShareReadersOnly;
397 TInt ret = f.Open(iFs,mbm[i],mode);
400 for (id=0; id<KNumBitmap; ++id)
403 TEST(bmp.Load(f,id)==KErrNone);
405 CFbsBitmap* orig = iSource[id];
406 TSize size = orig->SizeInPixels();
407 TInt bytes = orig->ScanLineLength(size.iWidth,KDisplayMode)*size.iHeight;
410 TEST(Mem::Compare((TUint8*)orig->DataAddress(),bytes,(TUint8*)bmp.DataAddress(),bytes)==0);
423 Load and compress bitmap from file using an opened file handle.
426 Compress original bitmap.
427 Load and compress bitmap using file handle.
428 Blit loaded+compressed bitmaps and compressed original to screen.
431 @SYMTestExpectedResults
432 LoadAndCompress ROM file return KErrAccessDenied.
433 Drawn bitmap on screen match.
435 void CTFile::LoadAndCompressL()
437 INFO_PRINTF1(_L("Loading and compressing bitmaps"));
441 if(!iSkipRomBitmapTests)
443 // load and compress ROM file
444 ret = f.Open(iFs,KRomFile1,EFileShareReadersOnly);
447 TEST(bmp.LoadAndCompress(f)==KErrAccessDenied);
451 // load single bitmap file
452 const TBufC<32> names[KNumBitmap] =
454 (const TDesC&)KRamFile1,
455 (const TDesC&)KRamFile2,
456 (const TDesC&)KRamFile3
459 for (i=0; i<KNumBitmap; ++i)
461 ret = f.Open(iFs,names[i],EFileShareReadersOnly);
464 TEST(bmp.LoadAndCompress(f)==KErrNone);
466 TEST(bmp.IsCompressedInRAM());
468 CFbsBitmap* orig = iSource[i];
469 TEST(orig->Compress()==KErrNone);
470 TEST(orig->IsCompressedInRAM());
472 TRAP(ret,BlitAndCompareL(orig,&bmp,orig->SizeInPixels()));
475 // Load multi bitmap KRamFile4
476 ret = f.Open(iFs,KRamFile4,EFileShareReadersOnly);
479 for (id=0; id<KNumBitmap; ++id)
482 TEST(bmp.LoadAndCompress(f,id)==KErrNone);
483 TEST(bmp.IsCompressedInRAM());
485 CFbsBitmap* orig = iSource[id];
486 TEST(orig->Compress()==KErrNone);
487 TEST(orig->IsCompressedInRAM());
489 TRAP(ret,BlitAndCompareL(orig,&bmp,orig->SizeInPixels()));
496 Blit two bitmap to screen device and compare if both match
498 void CTFile::BlitAndCompareL(CFbsBitmap* aBmpOrig,CFbsBitmap* aBmpTest,const TSize& aBmpSize)
500 CFbsScreenDevice* scd=NULL;
501 TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,KDisplayMode));
504 _LIT(KLog,"Failed to create screen device for mode %S err=%d");
505 INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode),err);
507 if (err==KErrNotSupported)
509 TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor256));
512 _LIT(KLog,"Failed to create Color256 screen device err=%d");
513 INFO_PRINTF2(KLog,err);
516 if (err==KErrNotSupported)
518 TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor16MA));
521 _LIT(KLog,"Failed to create Color16MA screen device err=%d");
522 INFO_PRINTF2(KLog,err);
525 if (err==KErrNotSupported)
527 TRAPD(err,scd=CFbsScreenDevice::NewL(KDefaultScreenNo,EColor16MAP));
530 _LIT(KLog,"Failed to create Color16MA screen device err=%d");
531 INFO_PRINTF2(KLog,err);
534 _LIT(KLog,"Create screen device with mode %S");
535 INFO_PRINTF2(KLog,&ColorModeName(scd->DisplayMode()));
536 CleanupStack::PushL(scd);
537 scd->ChangeScreenDevice(NULL);
539 User::LeaveIfError(scd->CreateContext((CGraphicsContext*&)sgc));
540 CleanupStack::PushL(sgc);
542 TSize scrSize = scd->SizeInPixels();
544 TPoint right(scrSize.iWidth/2,0);
545 TRect bmpRect(TPoint(0,0),aBmpSize);
547 // if bitmap width is greater than half screen width,
548 // try positioning right bitmap below original.
549 if (scrSize.iWidth < aBmpSize.iWidth*2)
551 if (scrSize.iHeight < aBmpSize.iHeight/2)
553 //That still doesn't work out, so restrict size of rect
554 // being blitted to half screen size.
555 INFO_PRINTF1(_L("Warning: the whole of the test images may not be compared"));
556 bmpRect = TRect(TPoint(0,0),TSize(scrSize.iWidth/2,aBmpSize.iHeight));
560 right = TPoint(0, scrSize.iHeight/2);
564 sgc->BitBlt(left, aBmpOrig, bmpRect);
565 sgc->BitBlt(right, aBmpTest, bmpRect);
568 #ifdef FBSTEST_SCREENSHOT
569 SaveScreenShotL(scd);
570 #endif //FBSTEST_SCREENSHOT
572 TBool match=scd->RectCompare(TRect(left,bmpRect.Size()),*scd,TRect(right,bmpRect.Size()));
575 _LIT(KLog,"Two areas of the screen don't match");
580 CleanupStack::PopAndDestroy(2,scd);
584 __CONSTRUCT_STEP__(File)