fbs/fontandbitmapserver/tfbs/tipctest.CPP
changeset 0 5d03bc08d59c
child 36 01a6848ebfd7
child 163 bbf46f59e123
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 "fbsmessage.h"
       
    17 #include "../sfbs/UTILS.H"
       
    18 #include "tipctest.h"
       
    19 #include "fbsdefs.h"
       
    20 
       
    21 
       
    22 CTIPCTest::CTIPCTest(CTestStep* aStep):
       
    23 	CTGraphicsBase(aStep),
       
    24 	iFbs(NULL),
       
    25 	iFs(NULL)
       
    26 	{}
       
    27 
       
    28 CTIPCTest::~CTIPCTest()
       
    29 	{
       
    30 	if(iShutdownFbs)
       
    31 		RFbsSession::GetSession()->SendCommand(EFbsMessShutdown);
       
    32 	RFbsSession::Disconnect();
       
    33 	delete iFs;
       
    34 	iHeap->Close();
       
    35 	}
       
    36 
       
    37 void CTIPCTest::ConstructL()
       
    38 	{
       
    39 	INFO_PRINTF1(_L("Font/Bitmap Server IPC Messages Testing"));
       
    40 
       
    41 	if(RFbsSession::Connect()==KErrNone)
       
    42 		{
       
    43 		RFbsSession::Disconnect();
       
    44 		iShutdownFbs = EFalse;
       
    45 		}
       
    46 	else
       
    47 		{
       
    48 		FbsStartup();
       
    49 		iShutdownFbs = ETrue;
       
    50 		}
       
    51 	RFbsSession::Connect();
       
    52 	iFbs=RFbsSession::GetSession();
       
    53 	
       
    54 	if(!iShutdownFbs)
       
    55 		{
       
    56 		if(iClient.Connect() == KErrNone)
       
    57 			{
       
    58 			iShutdownFbs = EFalse;
       
    59 			}
       
    60 		else
       
    61 			{
       
    62 			iShutdownFbs = ETrue;
       
    63 			}
       
    64 		}
       
    65 		
       
    66 	iHeap=UserHeap::ChunkHeap(NULL,0x10000,0x10000);
       
    67 	TRAPD(ret,iFs=CFontStore::NewL(iHeap));
       
    68 	TEST(ret==KErrNone);
       
    69 	TEST(iFs != NULL);
       
    70 	
       
    71 	}
       
    72 
       
    73 /**
       
    74 	@SYMTestCaseID
       
    75 	GRAPHICS-FBSERV-0603
       
    76 
       
    77 	@SYMTestCaseDesc
       
    78 	Tests the sending of commands to a FbsSession 
       
    79 	server thru Inter Process Communication. Sends
       
    80 	both valid and invalid commands.
       
    81 
       
    82 	@SYMTestActions
       
    83 	Commands sent to the server:
       
    84 	1. EFbsMessShutdown
       
    85 	2. EFbsMessFontHeightInTwips
       
    86 	3. EFbsMessFontHeightInTwips
       
    87 	4. EFbsMessFontHeightInPixels
       
    88 	5. EFbsMessFontHeightInPixels
       
    89 	6. EFbsMessAddFontStoreFile
       
    90 	7. EFbsMessAddFontStoreFile
       
    91 	8. EFbsMessInstallFontStoreFile
       
    92 	9. EFbsMessInstallFontStoreFile
       
    93 	10. EFbsMessInstallFontStoreFile
       
    94 	11. EFbsMessBitmapCreate
       
    95 	12. EFbsMessRasterize
       
    96 	13. EFbsMessFaceAttrib
       
    97 	14. EFbsMessHasCharacter
       
    98 	15. EFbsMessFontNameAlias
       
    99 	16. EFbsMessGetNearestFontToDesignHeightInTwips
       
   100 	17. EFbsMessGetNearestFontToMaxHeightInTwips
       
   101 	18. EFbsMessGetNearestFontToDesignHeightInPixels
       
   102 	19. EFbsMessGetNearestFontToMaxHeightInPixels
       
   103 	20. EFbsMessShapeText
       
   104 	21. EFbsMessShapeDelete
       
   105 	22. EFbsMessSetTwipsHeight
       
   106 	23. EFbsMessGetTwipsHeight	
       
   107 	
       
   108 	@SYMTestExpectedResults
       
   109 	Test should pass
       
   110 */
       
   111 void CTIPCTest::RunTestCaseL(TInt aCurTestCase)
       
   112 	{
       
   113 	_LIT(KCaseNumber, "CaseNumber");
       
   114 	
       
   115 	TBool res = iStep->GetIntFromConfig(iStep->ConfigSection(), KCaseNumber, aCurTestCase);
       
   116 	
       
   117 	if(!res)
       
   118 		{
       
   119 		return;
       
   120 		}
       
   121 		
       
   122 	switch(aCurTestCase)
       
   123 		{
       
   124 	case 1:
       
   125 		INFO_PRINTF1(_L("Shutdown\r\n"));
       
   126 		iFbs->SendCommand(EFbsMessShutdown);
       
   127 		TestComplete();
       
   128 		break;
       
   129 	case 2:
       
   130 		INFO_PRINTF1(_L("Height in twips with negative typeface index\r\n"));
       
   131 		iFbs->SendCommand(EFbsMessFontHeightInTwips, -1);	
       
   132 		TEST(EFalse); // Previous line should have paniced 
       
   133 		TestComplete();
       
   134 		break;	
       
   135 	case 3:
       
   136 		INFO_PRINTF1(_L("Height in twips with invalid size\r\n"));
       
   137 		iClient.SendInvalidSize(EFbsMessFontHeightInTwips);
       
   138 		TEST(EFalse);
       
   139 		TestComplete();
       
   140 		break;
       
   141 	case 4:
       
   142 		INFO_PRINTF1(_L("Height in pixels with negative typeface index\r\n"));
       
   143 		iFbs->SendCommand(EFbsMessFontHeightInPixels, -1);
       
   144 		TEST(EFalse);
       
   145 		TestComplete();
       
   146 		break;
       
   147 	case 5:
       
   148 		INFO_PRINTF1(_L("Height in pixels with invalid size\r\n"));
       
   149 		iClient.SendInvalidSize(EFbsMessFontHeightInPixels);
       
   150 		TEST(EFalse);
       
   151 		TestComplete();
       
   152 		break;
       
   153 	case 6:
       
   154 		INFO_PRINTF1(_L("Add font store file with negative length\r\n"));
       
   155 		iFbs->SendCommand(EFbsMessAddFontStoreFile, 0, -1);
       
   156 		TEST(EFalse);
       
   157 		TestComplete();
       
   158 		break;
       
   159 	case 7:
       
   160 		INFO_PRINTF1(_L("Add font store file with huge length\r\n"));
       
   161 		iFbs->SendCommand(EFbsMessAddFontStoreFile, 963955448, 963955368, 963955300, 963955232);
       
   162 		TEST(EFalse);
       
   163 		TestComplete();
       
   164 		break;
       
   165 	case 8:
       
   166 		INFO_PRINTF1(_L("Install font store file with negative length\r\n"));
       
   167 		iFbs->SendCommand(EFbsMessInstallFontStoreFile, 0, -1);
       
   168 		TEST(EFalse);
       
   169 		TestComplete();
       
   170 		break;
       
   171 	case 9:
       
   172 		INFO_PRINTF1(_L("Install font store file with huge length\r\n"));
       
   173 		iFbs->SendCommand(EFbsMessInstallFontStoreFile, 963955448, 963955368, 963955300, 963955232);
       
   174 		TEST(EFalse);
       
   175 		TestComplete();
       
   176 		break;
       
   177 	case 10:
       
   178 		INFO_PRINTF1(_L("Remove font store file with active references\r\n"));
       
   179 		iFbs->SendCommand(EFbsMessRemoveFontStoreFile, 11);
       
   180 		// With PDEF121246 (INC120690) fix in place, this test will always pass. Without the fix there will be a KERN 4 panic.
       
   181 		TEST(ETrue); 
       
   182 		TestComplete();
       
   183 		break;
       
   184 	case 11:
       
   185 		INFO_PRINTF1(_L("Bitmap create with invalid display mode\r\n"));
       
   186 		iClient.SendInvalidDisplayMode(EFbsMessBitmapCreate);
       
   187 		TEST(EFalse);
       
   188 		TestComplete();
       
   189 		break;
       
   190 	case 12:
       
   191 		INFO_PRINTF1(_L("Rasterize with invalid bitmap handle\r\n"));
       
   192 		iFbs->SendCommand(EFbsMessRasterize, 963955448, 963955368, 963955300, 963955232);
       
   193 		TEST(EFalse);
       
   194 		TestComplete();
       
   195 		break;
       
   196 	case 13:
       
   197 		INFO_PRINTF1(_L("Face Attribute with invalid bitmap handle\r\n"));
       
   198 		iFbs->SendCommand(EFbsMessFaceAttrib, 963955448, 963955368, 963955300, 963955232);
       
   199 		TEST(EFalse);
       
   200 		TestComplete();
       
   201 		break;
       
   202 	case 14:
       
   203 		INFO_PRINTF1(_L("Has Character with invalid bitmap handle\r\n"));
       
   204 		iFbs->SendCommand(EFbsMessHasCharacter, 963955448, 963955368, 963955300, 963955232);
       
   205 		TEST(EFalse);
       
   206 		TestComplete();
       
   207 		break;
       
   208 	case 15:
       
   209 		INFO_PRINTF1(_L("Name Alias with huge alias name length\r\n"));
       
   210 		iFbs->SendCommand(EFbsMessFontNameAlias, 963955448, 963955368, 963955300, 963955232);
       
   211 		TEST(EFalse);
       
   212 		TestComplete();
       
   213 		break;
       
   214 	case 16:
       
   215 		INFO_PRINTF1(_L("Get nearest font to design height in twips with invalid typeface name length\r\n"));
       
   216 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToDesignHeightInTwips);
       
   217 		TEST(EFalse);
       
   218 		TestComplete();
       
   219 		break;
       
   220 	case 17:
       
   221 		INFO_PRINTF1(_L("Get nearest font to max height in twips with invalid typeface name length\r\n"));
       
   222 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToMaxHeightInTwips);
       
   223 		TEST(EFalse);
       
   224 		TestComplete();
       
   225 		break;
       
   226 	case 18:
       
   227 		INFO_PRINTF1(_L("Get nearest font to design height in pixels with invalid typeface name length\r\n"));
       
   228 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToDesignHeightInPixels);
       
   229 		TEST(EFalse);
       
   230 		TestComplete();
       
   231 		break;
       
   232 	case 19:
       
   233 		INFO_PRINTF1(_L("Get nearest font to max height in pixels with invalid typeface name length\r\n"));
       
   234 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToMaxHeightInPixels);
       
   235 		TEST(EFalse);
       
   236 		TestComplete();
       
   237 		break;
       
   238 	case 20:
       
   239 		INFO_PRINTF1(_L("Shape text with invalid bitmap font handle\r\n"));
       
   240 		iFbs->SendCommand(EFbsMessShapeText, 963955448, 963955368, 963955300, 963955232);
       
   241 		TEST(EFalse);
       
   242 		TestComplete();
       
   243 		break;
       
   244 	case 21:
       
   245 		INFO_PRINTF1(_L("Shape delete with invalid bitmap font handle\r\n"));
       
   246 		iFbs->SendCommand(EFbsMessShapeDelete, 963955448, 963955368, 963955300, 963955232);
       
   247 		TEST(EFalse);
       
   248 		TestComplete();
       
   249 		break;
       
   250 	case 22:
       
   251 		INFO_PRINTF1(_L("Set twips height with invalid font handle\r\n"));
       
   252 		iFbs->SendCommand(EFbsMessSetTwipsHeight, 963955448, 963955368, 963955300, 963955232);
       
   253 		TEST(EFalse);
       
   254 		TestComplete();
       
   255 		break;
       
   256 	case 23:
       
   257 		INFO_PRINTF1(_L("Get twips height with invalid font handle\r\n"));
       
   258 		((CTIPCTestStep*)iStep)->SetOverallTestStepID(_L("GRAPHICS-FBSERV-0603"));
       
   259 		((CTIPCTestStep*)iStep)->RecordTestResultL();
       
   260 		((CTIPCTestStep*)iStep)->CloseTMSGraphicsStep();
       
   261 		iFbs->SendCommand(EFbsMessGetTwipsHeight, 963955448, 963955368, 963955300, 963955232);
       
   262 		TEST(EFalse);
       
   263 		TestComplete();
       
   264 		break;	
       
   265 	case 24:
       
   266 		TestComplete();
       
   267 		break;
       
   268 		}
       
   269 	}
       
   270 	
       
   271 RIPCTestFbservClient::RIPCTestFbservClient()
       
   272 	{
       
   273 	
       
   274 	}
       
   275 	
       
   276 RIPCTestFbservClient::~RIPCTestFbservClient()
       
   277 	{
       
   278 	
       
   279 	}
       
   280 	
       
   281 TInt RIPCTestFbservClient::Connect(void)
       
   282 	{
       
   283 	_LIT(KFbServerName, "!Fontbitmapserver");
       
   284 	TVersion version(0, 0, 0);
       
   285 	TInt ret = CreateSession(KFbServerName, version);
       
   286 	return ret;
       
   287 	}
       
   288 	
       
   289 void RIPCTestFbservClient::SendInvalidSize(TInt aFunctionNumber)
       
   290 	{
       
   291 	TPckgBuf<TSize> size;
       
   292 	size().iHeight = 0;
       
   293 	size().iWidth = 0;
       
   294 	TIpcArgs args;
       
   295 	args.Set(0, 1);
       
   296 	args.Set(2, &size);
       
   297 	
       
   298 	SendReceive(aFunctionNumber, args);
       
   299 	}
       
   300 	
       
   301 void RIPCTestFbservClient::SendInvalidDisplayMode(TInt aFunctionNumber)
       
   302 	{
       
   303 	TPckgBuf<TBmpSpec> bmpSpec;
       
   304 	bmpSpec().iDispMode = EColorLast;
       
   305 	TIpcArgs args = TIpcArgs();
       
   306 	args.Set(0, &bmpSpec);
       
   307 	
       
   308 	SendReceive(aFunctionNumber, args);
       
   309 	}
       
   310 
       
   311 void RIPCTestFbservClient::SendInvalidNameLength(TInt aFunctionNumber)	
       
   312 	{
       
   313 	TIpcArgs args = TIpcArgs();
       
   314 	_LIT(KDefault, "Default");
       
   315 	TInt size = 7;
       
   316 	HBufC8 *buf1 = HBufC8::NewLC(size);
       
   317 	TPtr8 ptr1 = buf1->Des();
       
   318 	ptr1.Copy(KDefault);
       
   319 	CleanupStack::PopAndDestroy(buf1);
       
   320 	args.Set(0, &ptr1);	
       
   321 	SendReceive(aFunctionNumber, args);
       
   322 	}
       
   323 	
       
   324 	
       
   325 void CTIPCTest::LoadFontsL(const TDesC& aFontsDir)
       
   326 	{
       
   327 	RFs fileSys;
       
   328 	User::LeaveIfError(fileSys.Connect());
       
   329 
       
   330 	TFindFile fileFinder(fileSys);
       
   331 	CDir* foundFileList = NULL;
       
   332 	
       
   333 	_LIT(KFBSERVFontFilePattern, "*");
       
   334 	TInt findFileComplete = fileFinder.FindWildByDir(KFBSERVFontFilePattern,aFontsDir,foundFileList);
       
   335 
       
   336 	TRAPD(addFileError, LoadFontFromFilelistL(findFileComplete, foundFileList, fileFinder));
       
   337 	TEST(addFileError == KErrNone);
       
   338 		
       
   339 	fileSys.Close();
       
   340 	}
       
   341 
       
   342 void CTIPCTest::LoadFontFromFilelistL(TInt aFindFileComplete, CDir* aFoundFileList, TFindFile& aFileFinder)
       
   343 	{
       
   344 	TUid id1 = TUid::Uid(0);
       
   345 	while (!aFindFileComplete)
       
   346 		{
       
   347 		CleanupStack::PushL(aFoundFileList);
       
   348 
       
   349 		const TInt foundFileCount = aFoundFileList->Count();
       
   350 		for (TInt i = 0; i < foundFileCount; i++)
       
   351 			{			
       
   352 			TParse parse;
       
   353 			if (parse.Set((*aFoundFileList)[i].iName,&aFileFinder.File(),NULL) == KErrNone)
       
   354 				{
       
   355 				// Get filename and extension of font proposing to be loaded
       
   356 				TPtrC fontFilename = parse.NameAndExt();
       
   357 				id1=iFs->AddFileL(parse.FullName());
       
   358 				
       
   359 				iFs->RemoveFile(KNullUid);
       
   360 				
       
   361 				}
       
   362 			}
       
   363 		CleanupStack::PopAndDestroy(aFoundFileList); 
       
   364 		aFindFileComplete = aFileFinder.FindWild(aFoundFileList);
       
   365 		}
       
   366 	}
       
   367 
       
   368 //--------------
       
   369 __CONSTRUCT_STEP__(IPCTest)
       
   370