os/graphics/fbs/fontandbitmapserver/tfbs/TCLEAN.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "../sfbs/UTILS.H"
    17 #include "TFBS.H"
    18 #include "TCLEAN.H"
    19 #include "fbsmessage.h"
    20 #include "fbsdefs.h"
    21 
    22 void CTClean::DeleteScanLineBuffer()
    23 	{
    24 	delete iFbs->iScanLineBuffer;
    25 	iFbs->iScanLineBuffer = NULL;
    26 	}
    27 
    28 CTClean::CTClean(CTestStep* aStep):
    29 	CTGraphicsBase(aStep),
    30 	iFbs(NULL),
    31 	iStore(NULL),
    32 	iBitmap(NULL),
    33 	iTc(NULL)
    34 	{}
    35 
    36 CTClean::~CTClean()
    37 	{
    38 	delete iStore;
    39 	if(iShutdownFbs)
    40 		RFbsSession::GetSession()->SendCommand(EFbsMessShutdown);
    41 	RFbsSession::Disconnect();
    42 	}
    43 
    44 void CTClean::ConstructL()
    45 	{
    46 	INFO_PRINTF1(_L("Font/Bitmap Server Thread Death Cleanup Testing"));
    47 
    48 	if(RFbsSession::Connect()==KErrNone)
    49 		{
    50 		RFbsSession::Disconnect();
    51 		iShutdownFbs = EFalse;
    52 		}
    53 	else
    54 		{
    55 		FbsStartup();
    56 		iShutdownFbs = ETrue;
    57 		}
    58 	RFbsSession::Connect();
    59 	iFbs=RFbsSession::GetSession();
    60 	iStore=CFbsTypefaceStore::NewL(NULL);
    61 	}
    62 
    63 void CTClean::RunTestCaseL(TInt aCurTestCase)
    64 	{
    65 	((CTCleanStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    66 	switch(aCurTestCase)
    67 		{
    68 	case 1:
    69 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0593"));
    70 		INFO_PRINTF1(_L("Thread Cleanup\r\n"));
    71 		DeadThread();
    72 		break;
    73 	case 2:
    74 #if defined(_DEBUG)
    75 		INFO_PRINTF1(_L("Font\r\n"));
    76 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0594"));
    77 		LaunchThread(EFont1);
    78 		((CTCleanStep*)iStep)->RecordTestResultL();
    79 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0595"));
    80 		LaunchThread(EFont2);
    81 #else
    82 		((CTCleanStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    83 #endif
    84 		break;
    85 	case 3:
    86 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0596"));
    87 		INFO_PRINTF1(_L("Bitmap\r\n"));
    88 		LaunchThread(EBitmap1);
    89 		break;
    90 	case 4:
    91 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0597"));
    92 		INFO_PRINTF1(_L("Pile\r\n"));
    93 		LaunchThread(EPile1);
    94 		break;
    95 	case 5:
    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);
   102 		break;
   103 	case 6:
   104 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0600"));
   105 		INFO_PRINTF1(_L("TypefaceStore\r\n"));
   106 		LaunchThread(ETypefaceStore1);
   107 		break;
   108 	case 7:
   109 		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0601"));
   110 		INFO_PRINTF1(_L("Bad Message\r\n"));
   111 		LaunchThread(EBadMessage);
   112 	case 8:
   113 		((CTCleanStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   114 		((CTCleanStep*)iStep)->CloseTMSGraphicsStep();
   115 		TestComplete();		
   116 		break;
   117 		}
   118 	((CTCleanStep*)iStep)->RecordTestResultL();
   119 	}
   120 
   121 TInt CleanupTestThread(TAny* aAny)
   122 	{
   123 	CTClean* theTest = (CTClean*) aAny;
   124 	CTrapCleanup::New();
   125 	RFbsSession::Connect();
   126 	CFbsBitmapEx bmp1;
   127 	CFbsBitmapEx bmp2;
   128 	CFbsBitmapEx bmp3;
   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);
   135 	CFbsFontEx* fon1;
   136 	CFbsFontEx* fon2;
   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);
   149 	TInt id;
   150 #ifdef __WINS__
   151 	ret=tfs->AddFile(_L("z:\\resource\\fonts\\eon14.gdr"),id);
   152 #else
   153 	ret=tfs->AddFile(_L("z:\\resource\\fonts\\eon.gdr"),id);
   154 #endif
   155 	theTest->TEST(ret==KErrNone);
   156 	bmp2.LockHeap();
   157 	RFbsSession::Disconnect();
   158 	User::Panic(_L("CleanupTest"),KErrNone);
   159 	return(KErrNone);
   160 	}
   161 
   162 /**
   163 	@SYMTestCaseID
   164 	GRAPHICS-FBSERV-0593
   165 
   166 	@SYMTestCaseDesc
   167 	Tests the cleaning when a thead is panicing.
   168 
   169 	@SYMTestActions
   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.	
   184 	
   185 	@SYMTestExpectedResults
   186 	Test should pass
   187 */
   188 void CTClean::DeadThread()
   189 	{
   190 	__UHEAP_MARK;
   191 	CFbsBitmapEx bmp;
   192 	TInt ret=bmp.Create(TSize(100,100),EGray16);
   193 	TEST(ret==KErrNone);
   194 	TInt rc=iFbs->ResourceCount();
   195 	TEST(rc==1);
   196 	RThread thrd;
   197 	TRequestStatus stat;
   198 	thrd.Create(_L("ctt"),CleanupTestThread,KDefaultStackSize,0x8000,0x8000,this);
   199 	thrd.SetPriority(EPriorityMuchMore);
   200 	thrd.Logon(stat);
   201 	User::SetJustInTime(EFalse);
   202 	bmp.LockHeap();
   203 	bmp.UnlockHeap();
   204 	thrd.Resume();
   205 	User::WaitForRequest(stat);
   206 	ret = thrd.ExitReason();
   207 	thrd.Close();
   208 	User::SetJustInTime(ETrue);
   209 	TEST(ret == KErrNone);
   210 	INFO_PRINTF1(_L("About to lock heap\r\n"));
   211 	bmp.LockHeap();
   212 	bmp.UnlockHeap();
   213 	rc=iFbs->ResourceCount();
   214 	TEST(rc==1);
   215 	DeleteScanLineBuffer();
   216 	__UHEAP_MARKEND;
   217 	}
   218 
   219 /**
   220 	@SYMTestCaseID
   221 	GRAPHICS-FBSERV-0594
   222 
   223 	@SYMTestCaseDesc
   224 	Tests a CFbsFontEx object in a thead function.
   225 	
   226 	@SYMTestActions
   227 	Connects to an FbsSession, creates a CFbsFontEx
   228 	object and gets the font address.
   229 	Thread returns with error code KErrNone.
   230 	
   231 	@SYMTestExpectedResults
   232 	Test should pass
   233 */
   234 TInt Font1(TAny* aAny)
   235 	{
   236 	CTClean* theTest = static_cast <CTClean*> (aAny);
   237 	theTest->INFO_PRINTF1(_L("Font1"));
   238 	RFbsSession::Connect();
   239 	CFbsFontEx font;
   240 	(void)font.Address();
   241 	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   242 	return(KErrNone);
   243 	}
   244 
   245 /**
   246 	@SYMTestCaseID
   247 	GRAPHICS-FBSERV-0595
   248 
   249 	@SYMTestCaseDesc
   250 	Tests a CFbsFontEx object in a thead function.
   251 	
   252 	@SYMTestActions
   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.
   256 	
   257 	@SYMTestExpectedResults
   258 	Test should pass
   259 */
   260 TInt Font2(TAny* aAny)
   261 	{
   262 	CTClean* theTest = static_cast <CTClean*> (aAny);
   263 	theTest->INFO_PRINTF1(_L("Font2"));
   264 	RFbsSession::Connect();
   265 	CFbsFontEx font;
   266 	font.SetHandle();
   267 	(void)font.Address();
   268 	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   269 	return(KErrNone);
   270 	}
   271 
   272 /**
   273 	@SYMTestCaseID
   274 	GRAPHICS-FBSERV-0596
   275 
   276 	@SYMTestCaseDesc
   277 	Creates a bitmap in a thread function, locks the heap
   278 	and panics the thread.
   279 	
   280 	@SYMTestActions
   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.
   284 	
   285 	@SYMTestExpectedResults
   286 	Test should pass
   287 */
   288 TInt Bitmap1(TAny* aAny)
   289 	{
   290 	CTClean* theTest = static_cast <CTClean*> (aAny);
   291 	theTest->INFO_PRINTF1(_L("Bitmap1"));
   292 	RFbsSession::Connect();
   293 	CFbsBitmapEx bitmap;
   294 	TInt ret=bitmap.Create(TSize(200,200),EGray16);
   295 	if(ret!=KErrNone)
   296 		{
   297 		theTest->ERR_PRINTF1(_L("ERROR - BITMAP NOT CREATED"));
   298 		}
   299 	bitmap.LockHeap();
   300 	User::Panic(_L(""),KErrNone);
   301 	return(KErrNone);
   302 	}
   303 
   304 /**
   305 	@SYMTestCaseID
   306 	GRAPHICS-FBSERV-0597
   307 
   308 	@SYMTestCaseDesc
   309 	Tests creation of a chunk in a thread function. 
   310 
   311 	@SYMTestActions
   312 	Creates a chunk. The thread returns with error code KErrNone.
   313 	
   314 	@SYMTestExpectedResults
   315 	Test should pass
   316 */
   317 TInt Pile1(TAny* aAny)
   318 	{
   319 	CTClean* theTest = static_cast <CTClean*> (aAny);
   320 	theTest->INFO_PRINTF1(_L("Pile1"));
   321 	RChunk chunk;
   322 	CChunkPile::NewL(chunk);
   323 	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   324 	return(KErrNone);
   325 	}
   326 
   327 /**
   328 	@SYMTestCaseID
   329 	GRAPHICS-FBSERV-0598
   330 
   331 	@SYMTestCaseDesc
   332 	Tests sending a close command to a connected
   333 	server from a thread function.
   334 
   335 	@SYMTestActions
   336 	Connects to a FbsSession and sends a
   337 	EFbsMessClose-command to the server. The thread
   338 	returns with error code KErrNone.
   339 	
   340 	@SYMTestExpectedResults
   341 	Test should pass
   342 */
   343 TInt Session1(TAny* aAny)
   344 	{
   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"));
   350 	return(KErrNone);
   351 	}
   352 
   353 /**
   354 	@SYMTestCaseID
   355 	GRAPHICS-FBSERV-0599
   356 
   357 	@SYMTestCaseDesc
   358 	Tests sending an init command to a connected
   359 	server from a thread function.
   360 
   361 	@SYMTestActions
   362 	Connects to a FbsSession and sends a
   363 	EFbsMessInit-command to the server. The thread
   364 	returns with error code KErrNone.
   365 	
   366 	@SYMTestExpectedResults
   367 	Test should pass
   368 */
   369 TInt Session2(TAny* aAny)
   370 	{
   371 	CTClean* theTest = static_cast <CTClean*> (aAny);
   372 	RFbsSession session;
   373 	session.SendCommand(EFbsMessInit);
   374 	theTest->INFO_PRINTF1(_L("Session2"));
   375 	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   376 	return(KErrNone);
   377 	}
   378 
   379 /**
   380 	@SYMTestCaseID
   381 	GRAPHICS-FBSERV-0600
   382 
   383 	@SYMTestCaseDesc
   384 	Tests the creation of a CFbsTypefaceStore
   385 	object on the heap in a thread function.
   386 
   387 	@SYMTestActions
   388 	Creates a CFbsTypefaceStore object on the heap
   389 	in a thread function and returns with error code
   390 	KErrNone.
   391 	
   392 	@SYMTestExpectedResults
   393 	Test should pass
   394 */
   395 TInt TypefaceStore1(TAny* aAny)
   396 	{
   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"));
   401 	return(KErrNone);
   402 	}
   403 
   404 /**
   405 	@SYMTestCaseID
   406 	GRAPHICS-FBSERV-0601
   407 
   408 	@SYMTestCaseDesc
   409 	Tests sending an invalid message from a thread function
   410 	to a connected FbsSession.
   411 
   412 	@SYMTestActions
   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.	
   416 	
   417 	@SYMTestExpectedResults
   418 	Test should pass
   419 */
   420 TInt BadMessage(TAny* aAny)
   421 	{
   422 	CTClean* theTest = static_cast <CTClean*> (aAny);
   423 	CTrapCleanup::New();
   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"));
   429 	return(KErrNone);
   430 	}
   431 
   432 /**
   433 	@SYMTestCaseID
   434 	GRAPHICS-FBSERV-0602
   435 
   436 	@SYMTestCaseDesc
   437 	Launches different threads for testing.
   438 
   439 	@SYMTestActions
   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
   444 	memory leaks.	
   445 	
   446 	@SYMTestExpectedResults
   447 	Test should pass
   448 */
   449 void CTClean::LaunchThread(TTestType aType)
   450 	{
   451 	__UHEAP_MARK;
   452 	RThread thrd;
   453 	TRequestStatus stat;
   454 	switch(aType)
   455 		{
   456 	case EFont1:
   457 		thrd.Create(_L("Font1"),Font1,KDefaultStackSize,0x2000,0x2000,this);
   458 		break;
   459 	case EFont2:
   460 		thrd.Create(_L("Font2"),Font2,KDefaultStackSize,0x2000,0x2000,this);
   461 		break;
   462 	case EBitmap1:
   463 		thrd.Create(_L("Bitmap1"),Bitmap1,KDefaultStackSize,0x2000,0x2000,this);
   464 		break;
   465 	case EPile1:
   466 		thrd.Create(_L("Pile1"),Pile1,KDefaultStackSize,0x2000,0x2000,this);
   467 		break;
   468 	case ESession1:
   469 		thrd.Create(_L("Session1"),Session1,KDefaultStackSize,0x2000,0x2000,this);
   470 		break;
   471 	case ESession2:
   472 		thrd.Create(_L("Session2"),Session2,KDefaultStackSize,0x2000,0x2000,this);
   473 		break;
   474 	case ETypefaceStore1:
   475 		thrd.Create(_L("TypefaceStore1"),TypefaceStore1,KDefaultStackSize,0x2000,0x2000,this);
   476 		break;
   477 	case EBadMessage:
   478 		thrd.Create(_L("BadMessage"),BadMessage,KDefaultStackSize,0x2000,0x2000,this);
   479 		break;
   480 	default:
   481 		User::Panic(_L("TCLEAN"),KErrArgument);
   482 		}
   483 	thrd.SetPriority(EPriorityMuchMore);
   484 	thrd.Logon(stat);
   485 	User::SetJustInTime(EFalse);
   486 	thrd.Resume();
   487 	User::WaitForRequest(stat);
   488 	thrd.Close();
   489 	User::SetJustInTime(ETrue);
   490 	__UHEAP_MARKEND;
   491 	}
   492 
   493 //--------------
   494 __CONSTRUCT_STEP__(Clean)
   495