First public contribution.
1 // Copyright (c) 1996-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"
19 #include "fbsmessage.h"
22 void CTClean::DeleteScanLineBuffer()
24 delete iFbs->iScanLineBuffer;
25 iFbs->iScanLineBuffer = NULL;
28 CTClean::CTClean(CTestStep* aStep):
29 CTGraphicsBase(aStep),
40 RFbsSession::GetSession()->SendCommand(EFbsMessShutdown);
41 RFbsSession::Disconnect();
44 void CTClean::ConstructL()
46 INFO_PRINTF1(_L("Font/Bitmap Server Thread Death Cleanup Testing"));
48 if(RFbsSession::Connect()==KErrNone)
50 RFbsSession::Disconnect();
51 iShutdownFbs = EFalse;
58 RFbsSession::Connect();
59 iFbs=RFbsSession::GetSession();
60 iStore=CFbsTypefaceStore::NewL(NULL);
63 void CTClean::RunTestCaseL(TInt aCurTestCase)
65 ((CTCleanStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
69 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0593"));
70 INFO_PRINTF1(_L("Thread Cleanup\r\n"));
75 INFO_PRINTF1(_L("Font\r\n"));
76 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0594"));
78 ((CTCleanStep*)iStep)->RecordTestResultL();
79 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0595"));
82 ((CTCleanStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
86 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0596"));
87 INFO_PRINTF1(_L("Bitmap\r\n"));
88 LaunchThread(EBitmap1);
91 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0597"));
92 INFO_PRINTF1(_L("Pile\r\n"));
96 INFO_PRINTF1(_L("Session\r\n"));
97 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0598"));
98 LaunchThread(ESession1);
99 ((CTCleanStep*)iStep)->RecordTestResultL();
100 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0599"));
101 LaunchThread(ESession2);
104 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0600"));
105 INFO_PRINTF1(_L("TypefaceStore\r\n"));
106 LaunchThread(ETypefaceStore1);
109 ((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0601"));
110 INFO_PRINTF1(_L("Bad Message\r\n"));
111 LaunchThread(EBadMessage);
113 ((CTCleanStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
114 ((CTCleanStep*)iStep)->CloseTMSGraphicsStep();
118 ((CTCleanStep*)iStep)->RecordTestResultL();
121 TInt CleanupTestThread(TAny* aAny)
123 CTClean* theTest = (CTClean*) aAny;
125 RFbsSession::Connect();
129 TInt ret=bmp1.Create(TSize(10,10),EGray2);
130 theTest->TEST(ret==KErrNone);
131 ret=bmp2.Create(TSize(100,100),EGray16);
132 theTest->TEST(ret==KErrNone);
133 ret=bmp3.Duplicate(bmp2.Handle());
134 theTest->TEST(ret==KErrNone);
137 CFbsTypefaceStore* tfs=NULL;
138 TRAP(ret,tfs=CFbsTypefaceStore::NewL(NULL));
139 theTest->TEST(ret==KErrNone);
140 ret=tfs->GetNearestFontToDesignHeightInPixels((CFont*&)fon1,TFontSpec(_L("Swiss"),12));
141 theTest->TEST(ret==KErrNone);
142 fon2=(CFbsFontEx*)User::Alloc(sizeof(CFbsFontEx));
143 theTest->TEST(fon2!=NULL);
144 new(fon2) CFbsFontEx;
145 ret=fon2->Duplicate(fon1->Handle());
146 theTest->TEST(ret==KErrNone);
147 TInt rc=RFbsSession::GetSession()->ResourceCount();
148 theTest->TEST(rc==5);
151 ret=tfs->AddFile(_L("z:\\resource\\fonts\\eon14.gdr"),id);
153 ret=tfs->AddFile(_L("z:\\resource\\fonts\\eon.gdr"),id);
155 theTest->TEST(ret==KErrNone);
157 RFbsSession::Disconnect();
158 User::Panic(_L("CleanupTest"),KErrNone);
167 Tests the cleaning when a thead is panicing.
170 Creates a bitmap. Checks the resource count. Creates
171 a thread with high priority. Unlocks the heap and locks
172 it back again. Disables just-in-time debugging. Waits for
173 he thead to complete its execution. The created thread creates
174 its own cleanup stack and connects to a FbsSession. It creates
175 three bitmaps and duplicates one of them to the other.
176 A FbsTypefaceStore object is created on the heap an
177 GetNearestFontToDesignHeightInPixel is called on it. Disconnect
178 from the FbsSession. The thread is paniced and terminated. The
179 function that created the thread now continues its execution by
180 checking the exit reason for the thread. Closes the thead. Enables
181 just-in-time again. Locks the heap and unlocks it again.
182 Checks the resource count. Deletes scan line buffer. The
183 heap is checked for memory leaks.
185 @SYMTestExpectedResults
188 void CTClean::DeadThread()
192 TInt ret=bmp.Create(TSize(100,100),EGray16);
194 TInt rc=iFbs->ResourceCount();
198 thrd.Create(_L("ctt"),CleanupTestThread,KDefaultStackSize,0x8000,0x8000,this);
199 thrd.SetPriority(EPriorityMuchMore);
201 User::SetJustInTime(EFalse);
205 User::WaitForRequest(stat);
206 ret = thrd.ExitReason();
208 User::SetJustInTime(ETrue);
209 TEST(ret == KErrNone);
210 INFO_PRINTF1(_L("About to lock heap\r\n"));
213 rc=iFbs->ResourceCount();
215 DeleteScanLineBuffer();
224 Tests a CFbsFontEx object in a thead function.
227 Connects to an FbsSession, creates a CFbsFontEx
228 object and gets the font address.
229 Thread returns with error code KErrNone.
231 @SYMTestExpectedResults
234 TInt Font1(TAny* aAny)
236 CTClean* theTest = static_cast <CTClean*> (aAny);
237 theTest->INFO_PRINTF1(_L("Font1"));
238 RFbsSession::Connect();
240 (void)font.Address();
241 theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
250 Tests a CFbsFontEx object in a thead function.
253 Connects to an FbsSession, creates a CFbsFontEx object,
254 sets the fonts handle, gets the fonts address.
255 Thread returns with error code KErrNone.
257 @SYMTestExpectedResults
260 TInt Font2(TAny* aAny)
262 CTClean* theTest = static_cast <CTClean*> (aAny);
263 theTest->INFO_PRINTF1(_L("Font2"));
264 RFbsSession::Connect();
267 (void)font.Address();
268 theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
277 Creates a bitmap in a thread function, locks the heap
278 and panics the thread.
281 Connects to an FbsSession, creates a CFbsBitmapEx object,
282 creates a bitmap on the stack. Creation is checked for errors
283 and thenb locks the heap. The thread is paniced.
285 @SYMTestExpectedResults
288 TInt Bitmap1(TAny* aAny)
290 CTClean* theTest = static_cast <CTClean*> (aAny);
291 theTest->INFO_PRINTF1(_L("Bitmap1"));
292 RFbsSession::Connect();
294 TInt ret=bitmap.Create(TSize(200,200),EGray16);
297 theTest->ERR_PRINTF1(_L("ERROR - BITMAP NOT CREATED"));
300 User::Panic(_L(""),KErrNone);
309 Tests creation of a chunk in a thread function.
312 Creates a chunk. The thread returns with error code KErrNone.
314 @SYMTestExpectedResults
317 TInt Pile1(TAny* aAny)
319 CTClean* theTest = static_cast <CTClean*> (aAny);
320 theTest->INFO_PRINTF1(_L("Pile1"));
322 CChunkPile::NewL(chunk);
323 theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
332 Tests sending a close command to a connected
333 server from a thread function.
336 Connects to a FbsSession and sends a
337 EFbsMessClose-command to the server. The thread
338 returns with error code KErrNone.
340 @SYMTestExpectedResults
343 TInt Session1(TAny* aAny)
345 CTClean* theTest = static_cast <CTClean*> (aAny);
346 RFbsSession::Connect();
347 RFbsSession::GetSession()->SendCommand(EFbsMessClose);
348 theTest->INFO_PRINTF1(_L("Session1"));
349 theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
358 Tests sending an init command to a connected
359 server from a thread function.
362 Connects to a FbsSession and sends a
363 EFbsMessInit-command to the server. The thread
364 returns with error code KErrNone.
366 @SYMTestExpectedResults
369 TInt Session2(TAny* aAny)
371 CTClean* theTest = static_cast <CTClean*> (aAny);
373 session.SendCommand(EFbsMessInit);
374 theTest->INFO_PRINTF1(_L("Session2"));
375 theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
384 Tests the creation of a CFbsTypefaceStore
385 object on the heap in a thread function.
388 Creates a CFbsTypefaceStore object on the heap
389 in a thread function and returns with error code
392 @SYMTestExpectedResults
395 TInt TypefaceStore1(TAny* aAny)
397 CTClean* theTest = static_cast <CTClean*> (aAny);
398 CFbsTypefaceStore::NewL(NULL);
399 theTest->INFO_PRINTF1(_L("TypefaceStore1"));
400 theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
409 Tests sending an invalid message from a thread function
410 to a connected FbsSession.
413 Connects to a FbsSession. Gets a pointer to the session
414 object. Sends an invalid command to the server. The thread
415 returns with error code KErrNone.
417 @SYMTestExpectedResults
420 TInt BadMessage(TAny* aAny)
422 CTClean* theTest = static_cast <CTClean*> (aAny);
424 RFbsSession::Connect();
425 RFbsSession* sess=RFbsSession::GetSession();
426 sess->SendCommand(TFbsMessage(0x0fffffff));
427 theTest->INFO_PRINTF1(_L("Bad Message Test Thread"));
428 theTest->ERR_PRINTF1(_L("ERROR - BAD MESSAGE DID NOT PANIC THREAD"));
437 Launches different threads for testing.
440 Creates a thread and gives it higher priority.
441 Disables just-in-time and starts the thread and
442 waits for the it to finish. Closes the thead,
443 enables just-in-time and checks the heap for
446 @SYMTestExpectedResults
449 void CTClean::LaunchThread(TTestType aType)
457 thrd.Create(_L("Font1"),Font1,KDefaultStackSize,0x2000,0x2000,this);
460 thrd.Create(_L("Font2"),Font2,KDefaultStackSize,0x2000,0x2000,this);
463 thrd.Create(_L("Bitmap1"),Bitmap1,KDefaultStackSize,0x2000,0x2000,this);
466 thrd.Create(_L("Pile1"),Pile1,KDefaultStackSize,0x2000,0x2000,this);
469 thrd.Create(_L("Session1"),Session1,KDefaultStackSize,0x2000,0x2000,this);
472 thrd.Create(_L("Session2"),Session2,KDefaultStackSize,0x2000,0x2000,this);
474 case ETypefaceStore1:
475 thrd.Create(_L("TypefaceStore1"),TypefaceStore1,KDefaultStackSize,0x2000,0x2000,this);
478 thrd.Create(_L("BadMessage"),BadMessage,KDefaultStackSize,0x2000,0x2000,this);
481 User::Panic(_L("TCLEAN"),KErrArgument);
483 thrd.SetPriority(EPriorityMuchMore);
485 User::SetJustInTime(EFalse);
487 User::WaitForRequest(stat);
489 User::SetJustInTime(ETrue);
494 __CONSTRUCT_STEP__(Clean)