Update contrib.
1 // Copyright (c) 2004-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 "../sfbs/UTILS.H"
17 #include "TFBSDefect.h"
18 #include "fbsmessage.h"
20 CTFbsDefect::CTFbsDefect(CTestStep* aStep) :
31 Checks for leaking thread handles during
37 Retrieves the process handle count and the
38 thread handle count. Creates a bitmap with
39 the specified size and display mode. The bitmap
40 is created on the font and bitmap server's shared
41 heap. The thread handle count is retrieved again
42 and compared against the first thread handle count
43 and they should match.
45 @SYMTestExpectedResults
48 void CTFbsDefect::CreateBitmapTestL()
50 INFO_PRINTF1(_L("CreateBitmapTestL (INC041784)"));
52 // and leaking thread handles
53 TInt startProcessHandleCount;
54 TInt startThreadHandleCount;
55 TInt endProcessHandleCount;
56 TInt endThreadHandleCount;
59 thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
64 const TSize size(100, 100);
66 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
67 CleanupStack::PushL(bitmap);
69 TEST (bitmap->Create(size, ERgb) == KErrArgument);
70 TEST (bitmap->Create(size, ENone) == KErrArgument);
71 TEST (bitmap->Create(size, EColor16) == KErrNone);
73 CleanupStack::PopAndDestroy(bitmap);
78 // Check for open handles
79 thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
81 TEST(startThreadHandleCount == endThreadHandleCount);
91 Tests replacing initial display with all the
92 possible higher display mode and tests replacing
93 initial display with all the possible lower display mode.
96 Creates a bitmap. Creates an array containing display modes.
97 For each display mode it sets the display mode to a higher
98 display mode and checks for errors. Then for each display mode
99 it sets the display mode to a lower display mode and checks
102 @SYMTestExpectedResults
105 void CTFbsDefect::TestDisplayModeL()
107 INFO_PRINTF1(_L("TestDisplayModeL (DEF042528)"));
109 const TSize size(10,10);
110 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
111 //TDisplayMode value= { 1 , 2 , 3 , 4 , 5 6 10 7 8 11 12 13
112 TDisplayMode mode[] = {EGray2,EGray4,EGray16,EGray256,EColor16,EColor256,EColor4K,EColor64K,EColor16M,EColor16MU,EColor16MA,EColor16MAP};
114 TInt arraysize=sizeof(mode)/sizeof(mode[0]);
115 INFO_PRINTF2(_L("Array size=%d\n"),arraysize);
118 //Test for replacing initial display with all the possible higher display mode
119 //This should not work and all the values returned by SetDisplayMode()==KErrArgument
120 for (TInt i=0;i<arraysize;i++)
122 ret=bitmap->Create(size,mode[i]);
123 INFO_PRINTF2(_L("Initial mode: %d\n"),mode[i]);
125 for (TInt j=i+1;j<arraysize;j++)
127 if ((mode[i]==EColor16MU && (mode[j]==EColor16MA || mode[j]==EColor16MAP)) || (mode[i]==EColor16MA && mode[j]==EColor16MAP))
129 //special cases where we can change from EColor16MU to either EColor16MA or EColor16MAP and from EColor16MA to EColor16MAP.
130 ret=bitmap->SetDisplayMode(mode[j]);
131 INFO_PRINTF3(_L("Changing to display mode=%d with ret value=%d\n "),mode[j],ret);
136 ret=bitmap->SetDisplayMode(mode[j]);
137 INFO_PRINTF3(_L("Changing to display mode %d with ret value %d \n"),mode[j],ret);
138 TEST(ret==KErrArgument);
141 INFO_PRINTF1(_L("End of mode \n"));
144 //Test for replacing initial display with all the possible lower display mode
145 //This should work fine and all the values returned by SetDisplayMode()==KErrNone
146 INFO_PRINTF1(_L("\n\n"));
147 for (TInt k=arraysize-1;k>=0;k--)
149 ret=bitmap->Create(size,mode[k]);
150 INFO_PRINTF2(_L("Initial mode=%d\n"),mode[k]);
152 for (TInt l=k-1;l>=0;l--)
155 if (mode[k]==EColor16 && mode[l]==EGray256)
157 //special case where we cannot change from EColor16 to EGray256
158 ret=bitmap->SetDisplayMode(mode[l]);
159 INFO_PRINTF3(_L("Changing to display mode=%d with ret value=%d\n "),mode[l],ret);
160 TEST(ret==KErrArgument);
165 ret=bitmap->SetDisplayMode(mode[l]);
166 INFO_PRINTF3(_L("Changing to display mode=%d with ret value=%d\n "),mode[l],ret);
177 /* Creates and destroys large bitmaps */
178 TInt BitmapCreate(TAny* /* aAny */)
181 TInt err = fbs.Connect();
182 User::LeaveIfError(err);
183 RFbsSession* fbs2 = RFbsSession::GetSession();
188 bitmap.Create(TSize(300,200), EColor16MU);
190 fbs2->SendCommand(EFbsCompress, 0);
195 void CleanupFbsConnection(TAny* aPtr)
197 RFbsSession* fbs = static_cast<RFbsSession*>(aPtr);
201 void CleanupLoadedBitmap(TAny* aPtr)
203 RPointerArray<CFbsBitmap>* ptrArray = (static_cast<RPointerArray<CFbsBitmap>*>(aPtr));
204 ptrArray->ResetAndDestroy();
208 void FillBitmapArray(RPointerArray<CFbsBitmap>& aArray)
210 for(TInt count=100; count>=0; --count)
212 CFbsBitmap* bitmap = new CFbsBitmap;
216 TInt err = bitmap->Create(TSize(100,100), EColor16MU);
220 err = aArray.Append(bitmap);
234 TInt err = fbs.Connect();
235 User::LeaveIfError(err);
236 TCleanupItem fbsConnectionCleanup(CleanupFbsConnection, &fbs);
237 CleanupStack::PushL(fbsConnectionCleanup);
239 RPointerArray<CFbsBitmap> stressBitmaps;
240 TCleanupItem loadedBitmapCleanup(CleanupLoadedBitmap, &stressBitmaps);
241 CleanupStack::PushL(loadedBitmapCleanup);
242 FillBitmapArray(stressBitmaps);
244 CFbsBitmap* outputBitmap=new(ELeave) CFbsBitmap;
245 CleanupStack::PushL(outputBitmap);
246 User::LeaveIfError(outputBitmap->Create(TSize(200,200),EColor16MU));
247 CFbsBitmapDevice *bgDevice=CFbsBitmapDevice::NewL(outputBitmap);
248 CleanupStack::PushL(bgDevice);
249 CFbsBitGc* bgGc=NULL;
250 User::LeaveIfError(bgDevice->CreateContext(bgGc));
251 CleanupStack::PushL(bgGc);
253 CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
254 CleanupStack::PushL(bitmap);
255 User::LeaveIfError(bitmap->Create(TSize(100,100),EColor16MU));
256 for (TInt count = 1000; count > 0; count--)
262 User::LeaveIfError(bitmap->Create(TSize(100,100),EColor16MU));
266 stressBitmaps.ResetAndDestroy();
270 stressBitmaps.ResetAndDestroy();
271 FillBitmapArray(stressBitmaps);
273 bgGc->DrawBitmap(TPoint(10,10),bitmap);
277 CleanupStack::PopAndDestroy(bitmap);
278 CleanupStack::PopAndDestroy(bgGc);
279 CleanupStack::PopAndDestroy(bgDevice);
280 CleanupStack::PopAndDestroy(outputBitmap);
281 CleanupStack::PopAndDestroy(/*&loadedBitmapCleanup*/);
282 CleanupStack::PopAndDestroy(/*&fbsConnectionCleanup*/);
285 void TestBitmapUseL(CTFbsDefect* aFbsDefect)
287 TRAPD(err,DoBitmapUseL());
288 aFbsDefect->TEST(err==KErrNone || err==KErrNoMemory); // Out-of-memory doesn't constitute a test failure
292 TInt BitmapUse(TAny* aAny)
294 CTrapCleanup* CleanUpStack=CTrapCleanup::New();
295 CTFbsDefect* theTest = static_cast <CTFbsDefect*> (aAny);
298 TRAP_IGNORE(TestBitmapUseL(theTest));
310 Verifies defect DEF079124.
315 Creates two threads. One threads keeps creating
316 and destroying large bitmaps. The second thread
317 draws bitmaps. The exit reason of the threads
318 are checked. The thread handles are closed.
320 @SYMTestExpectedResults
323 void CTFbsDefect::TestFbservChunkLockingL()
325 INFO_PRINTF1(_L("TestDisplayModeL (DEF079124)"));
329 RThread bitmapCreate;
331 bitmapCreate.Create(_L("BitmapCreate"),BitmapCreate,KDefaultStackSize,0x2200,0x2200,this);
332 bitmapUse.Create(_L("BitmapUse"),BitmapUse,KDefaultStackSize,0x2200,0x2200,this);
334 bitmapUse.Logon(stat);
335 bitmapCreate.Resume();
337 User::WaitForRequest(stat);
339 INFO_PRINTF2(_L("bitmapCreate ExitReason: %d"),bitmapCreate.ExitReason());
340 INFO_PRINTF2(_L("bitmapUse ExitReason: %d"),bitmapUse.ExitReason());
341 TEST(bitmapCreate.ExitReason() == KErrNone);
342 TEST(bitmapUse.ExitReason() == KErrNone);
343 bitmapCreate.Close();
349 * @SYMTestCaseID GRAPHICS-FBSERV-0621
351 * @SYMDEF INC112542, PDEF113158
353 * @SYMTestCaseDesc A test to check KErrEof is returned when a bitmap index greater than the
354 * number of bitmaps present in the .mbm is requested from a ROM bitamp
356 * @SYMTestPriority Normal
358 * @SYMTestStatus Implemented
360 * @SYMTestActions Loads a bitmap from rom where the index is greater than the numer of bitmaps actually in the mbm
361 * Checks that KErrEof is returned when this happens.
364 void CTFbsDefect::TestKErrEof()
366 INFO_PRINTF1(_L("TestKErrEof - testing error code returned from CFbsBitmap::Load()"));
367 _LIT(KTestBitmapOnZZ,"z:\\system\\data\\tfbs.rbm"); // this contains 2 bitmaps
370 TUint32* romAddress = NULL;
371 if(!CFbsBitmap::IsFileInRom(KTestBitmapOnZZ, romAddress))
373 INFO_PRINTF2(_L("Skipping test of ROM bitmaps since file \"%S\" is reported to not be a ROM bitmap."),
375 INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
380 TInt bitmapIndex = 2; // this bmp index is one greater than the bitmap contains
381 TInt errCode = rom.Load(KTestBitmapOnZZ,bitmapIndex,EFalse);
386 INFO_PRINTF2(_L("TestKErrEof - Accessing ROM bitmap index greater than # contained returned %d instead of KErrEof"),errCode);
390 /* Creates bitmaps under OOM conditions (PDEF129780)*/
391 void CTFbsDefect::CreateBitmapOOMTestL()
393 INFO_PRINTF1(_L("CreateBitmapOOMTestL (PDEF129780) - Creating Bitmap under OOM conditions"));
395 RFbsSession* fbs = RFbsSession::GetSession();
397 RPointerArray<CFbsBitmap> bitmaps;
398 TCleanupItem bitmapsCleanupItem (CleanupLoadedBitmap, &bitmaps);
399 CleanupStack::PushL(bitmapsCleanupItem);
401 // Loop here is to fill CFbTop::iBitmapObjectIndex and force it reallocate memory inside CBitmapObject::ConstructL
402 // The upper bound of the loop depends on how CFbTop::iBitmapObjectIndex is expended and how many pointers are in it by the start of this subtest
403 // The upper bound may require to be increased if previous subtests are changed
404 for(TInt i=0; i<500; i++)
408 // Rate starts from 2 to allow allocate memory at least for new CBitmapObject and leave during next attempt to allocate memory
409 // The Loop is to make sure that the situation won't be missed if something in code is changed
410 // and it is more memory allocations before ConstructL. Currently it is enough 2.
411 for(TInt leaveRate = 2; leaveRate<10; leaveRate++)
413 CFbsBitmap* testBitmap = new(ELeave) CFbsBitmap;
415 fbs->SendCommand(EFbsMessSetHeapFail, RFbsSession::EHeapFailTypeServerMemory, leaveRate);
417 //Try to create bitmap
418 testBitmap->Create(size, EColor16MAP);
422 fbs->SendCommand(EFbsMessSetHeapReset, RFbsSession::EHeapFailTypeServerMemory, 0);
424 // Create bitmap to fill FbTop::iBitmapObjectIndex
425 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
426 CleanupStack::PushL(bitmap);
427 User::LeaveIfError(bitmaps.Append(bitmap));
428 CleanupStack::Pop(bitmap);
429 User::LeaveIfError(bitmap->Create(size, EColor16MAP));
431 INFO_PRINTF2(_L("Created %d bitmaps."), bitmaps.Count());
432 CleanupStack::PopAndDestroy(&bitmaps);
433 // If it was no Panic in fbserv and we have got here test pass
437 void CTFbsDefect::RunTestCaseL(TInt aCurTestCase)
439 ((CTFbsDefectStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
443 ((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0574"));
447 ((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0575"));
451 ((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0576"));
452 TestFbservChunkLockingL();
455 ((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0621"));
460 @SYMTestCaseID GRAPHICS-FBSERV-0620
462 ((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0620"));
463 CreateBitmapOOMTestL();
466 ((CTFbsDefectStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
467 ((CTFbsDefectStep*)iStep)->CloseTMSGraphicsStep();
471 ((CTFbsDefectStep*)iStep)->RecordTestResultL();
475 __CONSTRUCT_STEP__(FbsDefect)