os/graphics/fbs/fontandbitmapserver/tfbs/TCLEAN.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/TCLEAN.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,495 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "../sfbs/UTILS.H"
    1.20 +#include "TFBS.H"
    1.21 +#include "TCLEAN.H"
    1.22 +#include "fbsmessage.h"
    1.23 +#include "fbsdefs.h"
    1.24 +
    1.25 +void CTClean::DeleteScanLineBuffer()
    1.26 +	{
    1.27 +	delete iFbs->iScanLineBuffer;
    1.28 +	iFbs->iScanLineBuffer = NULL;
    1.29 +	}
    1.30 +
    1.31 +CTClean::CTClean(CTestStep* aStep):
    1.32 +	CTGraphicsBase(aStep),
    1.33 +	iFbs(NULL),
    1.34 +	iStore(NULL),
    1.35 +	iBitmap(NULL),
    1.36 +	iTc(NULL)
    1.37 +	{}
    1.38 +
    1.39 +CTClean::~CTClean()
    1.40 +	{
    1.41 +	delete iStore;
    1.42 +	if(iShutdownFbs)
    1.43 +		RFbsSession::GetSession()->SendCommand(EFbsMessShutdown);
    1.44 +	RFbsSession::Disconnect();
    1.45 +	}
    1.46 +
    1.47 +void CTClean::ConstructL()
    1.48 +	{
    1.49 +	INFO_PRINTF1(_L("Font/Bitmap Server Thread Death Cleanup Testing"));
    1.50 +
    1.51 +	if(RFbsSession::Connect()==KErrNone)
    1.52 +		{
    1.53 +		RFbsSession::Disconnect();
    1.54 +		iShutdownFbs = EFalse;
    1.55 +		}
    1.56 +	else
    1.57 +		{
    1.58 +		FbsStartup();
    1.59 +		iShutdownFbs = ETrue;
    1.60 +		}
    1.61 +	RFbsSession::Connect();
    1.62 +	iFbs=RFbsSession::GetSession();
    1.63 +	iStore=CFbsTypefaceStore::NewL(NULL);
    1.64 +	}
    1.65 +
    1.66 +void CTClean::RunTestCaseL(TInt aCurTestCase)
    1.67 +	{
    1.68 +	((CTCleanStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    1.69 +	switch(aCurTestCase)
    1.70 +		{
    1.71 +	case 1:
    1.72 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0593"));
    1.73 +		INFO_PRINTF1(_L("Thread Cleanup\r\n"));
    1.74 +		DeadThread();
    1.75 +		break;
    1.76 +	case 2:
    1.77 +#if defined(_DEBUG)
    1.78 +		INFO_PRINTF1(_L("Font\r\n"));
    1.79 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0594"));
    1.80 +		LaunchThread(EFont1);
    1.81 +		((CTCleanStep*)iStep)->RecordTestResultL();
    1.82 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0595"));
    1.83 +		LaunchThread(EFont2);
    1.84 +#else
    1.85 +		((CTCleanStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
    1.86 +#endif
    1.87 +		break;
    1.88 +	case 3:
    1.89 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0596"));
    1.90 +		INFO_PRINTF1(_L("Bitmap\r\n"));
    1.91 +		LaunchThread(EBitmap1);
    1.92 +		break;
    1.93 +	case 4:
    1.94 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0597"));
    1.95 +		INFO_PRINTF1(_L("Pile\r\n"));
    1.96 +		LaunchThread(EPile1);
    1.97 +		break;
    1.98 +	case 5:
    1.99 +		INFO_PRINTF1(_L("Session\r\n"));
   1.100 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0598"));
   1.101 +		LaunchThread(ESession1);
   1.102 +		((CTCleanStep*)iStep)->RecordTestResultL();
   1.103 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0599"));
   1.104 +		LaunchThread(ESession2);
   1.105 +		break;
   1.106 +	case 6:
   1.107 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0600"));
   1.108 +		INFO_PRINTF1(_L("TypefaceStore\r\n"));
   1.109 +		LaunchThread(ETypefaceStore1);
   1.110 +		break;
   1.111 +	case 7:
   1.112 +		((CTCleanStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0601"));
   1.113 +		INFO_PRINTF1(_L("Bad Message\r\n"));
   1.114 +		LaunchThread(EBadMessage);
   1.115 +	case 8:
   1.116 +		((CTCleanStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.117 +		((CTCleanStep*)iStep)->CloseTMSGraphicsStep();
   1.118 +		TestComplete();		
   1.119 +		break;
   1.120 +		}
   1.121 +	((CTCleanStep*)iStep)->RecordTestResultL();
   1.122 +	}
   1.123 +
   1.124 +TInt CleanupTestThread(TAny* aAny)
   1.125 +	{
   1.126 +	CTClean* theTest = (CTClean*) aAny;
   1.127 +	CTrapCleanup::New();
   1.128 +	RFbsSession::Connect();
   1.129 +	CFbsBitmapEx bmp1;
   1.130 +	CFbsBitmapEx bmp2;
   1.131 +	CFbsBitmapEx bmp3;
   1.132 +	TInt ret=bmp1.Create(TSize(10,10),EGray2);
   1.133 +	theTest->TEST(ret==KErrNone);
   1.134 +	ret=bmp2.Create(TSize(100,100),EGray16);
   1.135 +	theTest->TEST(ret==KErrNone);
   1.136 +	ret=bmp3.Duplicate(bmp2.Handle());
   1.137 +	theTest->TEST(ret==KErrNone);
   1.138 +	CFbsFontEx* fon1;
   1.139 +	CFbsFontEx* fon2;
   1.140 +	CFbsTypefaceStore* tfs=NULL;
   1.141 +	TRAP(ret,tfs=CFbsTypefaceStore::NewL(NULL));
   1.142 +	theTest->TEST(ret==KErrNone);
   1.143 +	ret=tfs->GetNearestFontToDesignHeightInPixels((CFont*&)fon1,TFontSpec(_L("Swiss"),12));
   1.144 +	theTest->TEST(ret==KErrNone);
   1.145 +	fon2=(CFbsFontEx*)User::Alloc(sizeof(CFbsFontEx));
   1.146 +	theTest->TEST(fon2!=NULL);
   1.147 +	new(fon2) CFbsFontEx;
   1.148 +	ret=fon2->Duplicate(fon1->Handle());
   1.149 +	theTest->TEST(ret==KErrNone);
   1.150 +	TInt rc=RFbsSession::GetSession()->ResourceCount();
   1.151 +	theTest->TEST(rc==5);
   1.152 +	TInt id;
   1.153 +#ifdef __WINS__
   1.154 +	ret=tfs->AddFile(_L("z:\\resource\\fonts\\eon14.gdr"),id);
   1.155 +#else
   1.156 +	ret=tfs->AddFile(_L("z:\\resource\\fonts\\eon.gdr"),id);
   1.157 +#endif
   1.158 +	theTest->TEST(ret==KErrNone);
   1.159 +	bmp2.LockHeap();
   1.160 +	RFbsSession::Disconnect();
   1.161 +	User::Panic(_L("CleanupTest"),KErrNone);
   1.162 +	return(KErrNone);
   1.163 +	}
   1.164 +
   1.165 +/**
   1.166 +	@SYMTestCaseID
   1.167 +	GRAPHICS-FBSERV-0593
   1.168 +
   1.169 +	@SYMTestCaseDesc
   1.170 +	Tests the cleaning when a thead is panicing.
   1.171 +
   1.172 +	@SYMTestActions
   1.173 +	Creates a bitmap. Checks the resource count. Creates
   1.174 +	a thread with high priority. Unlocks the heap and locks
   1.175 +	it back again. Disables just-in-time debugging. Waits for 
   1.176 +	he thead to complete its execution. The created thread creates
   1.177 +	its own cleanup stack and connects to a FbsSession. It creates 
   1.178 +	three bitmaps and duplicates one of them to the other. 
   1.179 +	A FbsTypefaceStore object is created on the heap an 
   1.180 +	GetNearestFontToDesignHeightInPixel is called on it. Disconnect
   1.181 +	from the FbsSession. The thread is paniced and terminated. The
   1.182 +	function that created the thread now continues its execution by
   1.183 +	checking the exit reason for the thread. Closes the thead. Enables
   1.184 +	just-in-time again. Locks the heap and unlocks it again.
   1.185 +	Checks the resource count. Deletes scan line buffer. The
   1.186 +	heap is checked for memory leaks.	
   1.187 +	
   1.188 +	@SYMTestExpectedResults
   1.189 +	Test should pass
   1.190 +*/
   1.191 +void CTClean::DeadThread()
   1.192 +	{
   1.193 +	__UHEAP_MARK;
   1.194 +	CFbsBitmapEx bmp;
   1.195 +	TInt ret=bmp.Create(TSize(100,100),EGray16);
   1.196 +	TEST(ret==KErrNone);
   1.197 +	TInt rc=iFbs->ResourceCount();
   1.198 +	TEST(rc==1);
   1.199 +	RThread thrd;
   1.200 +	TRequestStatus stat;
   1.201 +	thrd.Create(_L("ctt"),CleanupTestThread,KDefaultStackSize,0x8000,0x8000,this);
   1.202 +	thrd.SetPriority(EPriorityMuchMore);
   1.203 +	thrd.Logon(stat);
   1.204 +	User::SetJustInTime(EFalse);
   1.205 +	bmp.LockHeap();
   1.206 +	bmp.UnlockHeap();
   1.207 +	thrd.Resume();
   1.208 +	User::WaitForRequest(stat);
   1.209 +	ret = thrd.ExitReason();
   1.210 +	thrd.Close();
   1.211 +	User::SetJustInTime(ETrue);
   1.212 +	TEST(ret == KErrNone);
   1.213 +	INFO_PRINTF1(_L("About to lock heap\r\n"));
   1.214 +	bmp.LockHeap();
   1.215 +	bmp.UnlockHeap();
   1.216 +	rc=iFbs->ResourceCount();
   1.217 +	TEST(rc==1);
   1.218 +	DeleteScanLineBuffer();
   1.219 +	__UHEAP_MARKEND;
   1.220 +	}
   1.221 +
   1.222 +/**
   1.223 +	@SYMTestCaseID
   1.224 +	GRAPHICS-FBSERV-0594
   1.225 +
   1.226 +	@SYMTestCaseDesc
   1.227 +	Tests a CFbsFontEx object in a thead function.
   1.228 +	
   1.229 +	@SYMTestActions
   1.230 +	Connects to an FbsSession, creates a CFbsFontEx
   1.231 +	object and gets the font address.
   1.232 +	Thread returns with error code KErrNone.
   1.233 +	
   1.234 +	@SYMTestExpectedResults
   1.235 +	Test should pass
   1.236 +*/
   1.237 +TInt Font1(TAny* aAny)
   1.238 +	{
   1.239 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.240 +	theTest->INFO_PRINTF1(_L("Font1"));
   1.241 +	RFbsSession::Connect();
   1.242 +	CFbsFontEx font;
   1.243 +	(void)font.Address();
   1.244 +	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   1.245 +	return(KErrNone);
   1.246 +	}
   1.247 +
   1.248 +/**
   1.249 +	@SYMTestCaseID
   1.250 +	GRAPHICS-FBSERV-0595
   1.251 +
   1.252 +	@SYMTestCaseDesc
   1.253 +	Tests a CFbsFontEx object in a thead function.
   1.254 +	
   1.255 +	@SYMTestActions
   1.256 +	Connects to an FbsSession, creates a CFbsFontEx object,
   1.257 +	sets the fonts handle, gets the fonts address.
   1.258 +	Thread returns with error code KErrNone.
   1.259 +	
   1.260 +	@SYMTestExpectedResults
   1.261 +	Test should pass
   1.262 +*/
   1.263 +TInt Font2(TAny* aAny)
   1.264 +	{
   1.265 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.266 +	theTest->INFO_PRINTF1(_L("Font2"));
   1.267 +	RFbsSession::Connect();
   1.268 +	CFbsFontEx font;
   1.269 +	font.SetHandle();
   1.270 +	(void)font.Address();
   1.271 +	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   1.272 +	return(KErrNone);
   1.273 +	}
   1.274 +
   1.275 +/**
   1.276 +	@SYMTestCaseID
   1.277 +	GRAPHICS-FBSERV-0596
   1.278 +
   1.279 +	@SYMTestCaseDesc
   1.280 +	Creates a bitmap in a thread function, locks the heap
   1.281 +	and panics the thread.
   1.282 +	
   1.283 +	@SYMTestActions
   1.284 +	Connects to an FbsSession, creates a CFbsBitmapEx object,
   1.285 +	creates a bitmap on the stack. Creation is checked for errors
   1.286 +	and thenb locks the heap. The thread is paniced.
   1.287 +	
   1.288 +	@SYMTestExpectedResults
   1.289 +	Test should pass
   1.290 +*/
   1.291 +TInt Bitmap1(TAny* aAny)
   1.292 +	{
   1.293 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.294 +	theTest->INFO_PRINTF1(_L("Bitmap1"));
   1.295 +	RFbsSession::Connect();
   1.296 +	CFbsBitmapEx bitmap;
   1.297 +	TInt ret=bitmap.Create(TSize(200,200),EGray16);
   1.298 +	if(ret!=KErrNone)
   1.299 +		{
   1.300 +		theTest->ERR_PRINTF1(_L("ERROR - BITMAP NOT CREATED"));
   1.301 +		}
   1.302 +	bitmap.LockHeap();
   1.303 +	User::Panic(_L(""),KErrNone);
   1.304 +	return(KErrNone);
   1.305 +	}
   1.306 +
   1.307 +/**
   1.308 +	@SYMTestCaseID
   1.309 +	GRAPHICS-FBSERV-0597
   1.310 +
   1.311 +	@SYMTestCaseDesc
   1.312 +	Tests creation of a chunk in a thread function. 
   1.313 +
   1.314 +	@SYMTestActions
   1.315 +	Creates a chunk. The thread returns with error code KErrNone.
   1.316 +	
   1.317 +	@SYMTestExpectedResults
   1.318 +	Test should pass
   1.319 +*/
   1.320 +TInt Pile1(TAny* aAny)
   1.321 +	{
   1.322 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.323 +	theTest->INFO_PRINTF1(_L("Pile1"));
   1.324 +	RChunk chunk;
   1.325 +	CChunkPile::NewL(chunk);
   1.326 +	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   1.327 +	return(KErrNone);
   1.328 +	}
   1.329 +
   1.330 +/**
   1.331 +	@SYMTestCaseID
   1.332 +	GRAPHICS-FBSERV-0598
   1.333 +
   1.334 +	@SYMTestCaseDesc
   1.335 +	Tests sending a close command to a connected
   1.336 +	server from a thread function.
   1.337 +
   1.338 +	@SYMTestActions
   1.339 +	Connects to a FbsSession and sends a
   1.340 +	EFbsMessClose-command to the server. The thread
   1.341 +	returns with error code KErrNone.
   1.342 +	
   1.343 +	@SYMTestExpectedResults
   1.344 +	Test should pass
   1.345 +*/
   1.346 +TInt Session1(TAny* aAny)
   1.347 +	{
   1.348 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.349 +	RFbsSession::Connect();
   1.350 +	RFbsSession::GetSession()->SendCommand(EFbsMessClose);
   1.351 +	theTest->INFO_PRINTF1(_L("Session1"));
   1.352 +	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   1.353 +	return(KErrNone);
   1.354 +	}
   1.355 +
   1.356 +/**
   1.357 +	@SYMTestCaseID
   1.358 +	GRAPHICS-FBSERV-0599
   1.359 +
   1.360 +	@SYMTestCaseDesc
   1.361 +	Tests sending an init command to a connected
   1.362 +	server from a thread function.
   1.363 +
   1.364 +	@SYMTestActions
   1.365 +	Connects to a FbsSession and sends a
   1.366 +	EFbsMessInit-command to the server. The thread
   1.367 +	returns with error code KErrNone.
   1.368 +	
   1.369 +	@SYMTestExpectedResults
   1.370 +	Test should pass
   1.371 +*/
   1.372 +TInt Session2(TAny* aAny)
   1.373 +	{
   1.374 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.375 +	RFbsSession session;
   1.376 +	session.SendCommand(EFbsMessInit);
   1.377 +	theTest->INFO_PRINTF1(_L("Session2"));
   1.378 +	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   1.379 +	return(KErrNone);
   1.380 +	}
   1.381 +
   1.382 +/**
   1.383 +	@SYMTestCaseID
   1.384 +	GRAPHICS-FBSERV-0600
   1.385 +
   1.386 +	@SYMTestCaseDesc
   1.387 +	Tests the creation of a CFbsTypefaceStore
   1.388 +	object on the heap in a thread function.
   1.389 +
   1.390 +	@SYMTestActions
   1.391 +	Creates a CFbsTypefaceStore object on the heap
   1.392 +	in a thread function and returns with error code
   1.393 +	KErrNone.
   1.394 +	
   1.395 +	@SYMTestExpectedResults
   1.396 +	Test should pass
   1.397 +*/
   1.398 +TInt TypefaceStore1(TAny* aAny)
   1.399 +	{
   1.400 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.401 +	CFbsTypefaceStore::NewL(NULL);
   1.402 +	theTest->INFO_PRINTF1(_L("TypefaceStore1"));
   1.403 +	theTest->ERR_PRINTF1(_L("ERROR - NO PANIC"));
   1.404 +	return(KErrNone);
   1.405 +	}
   1.406 +
   1.407 +/**
   1.408 +	@SYMTestCaseID
   1.409 +	GRAPHICS-FBSERV-0601
   1.410 +
   1.411 +	@SYMTestCaseDesc
   1.412 +	Tests sending an invalid message from a thread function
   1.413 +	to a connected FbsSession.
   1.414 +
   1.415 +	@SYMTestActions
   1.416 +	Connects to a FbsSession. Gets a pointer to the session
   1.417 +	object. Sends an invalid command to the server. The thread
   1.418 +	returns with error code KErrNone.	
   1.419 +	
   1.420 +	@SYMTestExpectedResults
   1.421 +	Test should pass
   1.422 +*/
   1.423 +TInt BadMessage(TAny* aAny)
   1.424 +	{
   1.425 +	CTClean* theTest = static_cast <CTClean*> (aAny);
   1.426 +	CTrapCleanup::New();
   1.427 +	RFbsSession::Connect();
   1.428 +	RFbsSession* sess=RFbsSession::GetSession();
   1.429 +	sess->SendCommand(TFbsMessage(0x0fffffff));
   1.430 +	theTest->INFO_PRINTF1(_L("Bad Message Test Thread"));
   1.431 +	theTest->ERR_PRINTF1(_L("ERROR - BAD MESSAGE DID NOT PANIC THREAD"));
   1.432 +	return(KErrNone);
   1.433 +	}
   1.434 +
   1.435 +/**
   1.436 +	@SYMTestCaseID
   1.437 +	GRAPHICS-FBSERV-0602
   1.438 +
   1.439 +	@SYMTestCaseDesc
   1.440 +	Launches different threads for testing.
   1.441 +
   1.442 +	@SYMTestActions
   1.443 +	Creates a thread and gives it higher priority.
   1.444 +	Disables just-in-time and starts the thread and 
   1.445 +	waits for the it to finish. Closes the thead,
   1.446 +	enables just-in-time and checks the heap for
   1.447 +	memory leaks.	
   1.448 +	
   1.449 +	@SYMTestExpectedResults
   1.450 +	Test should pass
   1.451 +*/
   1.452 +void CTClean::LaunchThread(TTestType aType)
   1.453 +	{
   1.454 +	__UHEAP_MARK;
   1.455 +	RThread thrd;
   1.456 +	TRequestStatus stat;
   1.457 +	switch(aType)
   1.458 +		{
   1.459 +	case EFont1:
   1.460 +		thrd.Create(_L("Font1"),Font1,KDefaultStackSize,0x2000,0x2000,this);
   1.461 +		break;
   1.462 +	case EFont2:
   1.463 +		thrd.Create(_L("Font2"),Font2,KDefaultStackSize,0x2000,0x2000,this);
   1.464 +		break;
   1.465 +	case EBitmap1:
   1.466 +		thrd.Create(_L("Bitmap1"),Bitmap1,KDefaultStackSize,0x2000,0x2000,this);
   1.467 +		break;
   1.468 +	case EPile1:
   1.469 +		thrd.Create(_L("Pile1"),Pile1,KDefaultStackSize,0x2000,0x2000,this);
   1.470 +		break;
   1.471 +	case ESession1:
   1.472 +		thrd.Create(_L("Session1"),Session1,KDefaultStackSize,0x2000,0x2000,this);
   1.473 +		break;
   1.474 +	case ESession2:
   1.475 +		thrd.Create(_L("Session2"),Session2,KDefaultStackSize,0x2000,0x2000,this);
   1.476 +		break;
   1.477 +	case ETypefaceStore1:
   1.478 +		thrd.Create(_L("TypefaceStore1"),TypefaceStore1,KDefaultStackSize,0x2000,0x2000,this);
   1.479 +		break;
   1.480 +	case EBadMessage:
   1.481 +		thrd.Create(_L("BadMessage"),BadMessage,KDefaultStackSize,0x2000,0x2000,this);
   1.482 +		break;
   1.483 +	default:
   1.484 +		User::Panic(_L("TCLEAN"),KErrArgument);
   1.485 +		}
   1.486 +	thrd.SetPriority(EPriorityMuchMore);
   1.487 +	thrd.Logon(stat);
   1.488 +	User::SetJustInTime(EFalse);
   1.489 +	thrd.Resume();
   1.490 +	User::WaitForRequest(stat);
   1.491 +	thrd.Close();
   1.492 +	User::SetJustInTime(ETrue);
   1.493 +	__UHEAP_MARKEND;
   1.494 +	}
   1.495 +
   1.496 +//--------------
   1.497 +__CONSTRUCT_STEP__(Clean)
   1.498 +