os/graphics/fbs/fontandbitmapserver/tfbs/tipctest.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1996-2010 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 "tipctest.h"
    18 #include "fbsdefs.h"
    19 #include "fbsmessage.h"
    20 
    21 // Invalid parameters to be passed in SendCommand() calls.
    22 const TInt KInvalidParam1 = 963955448;
    23 const TInt KInvalidParam2 = 963955368;
    24 const TInt KInvalidParam3 = 963955300;
    25 const TInt KInvalidParam4 = 963955232;
    26 
    27 CTIPCTest::CTIPCTest(CTestStep* aStep):
    28 	CTGraphicsBase(aStep),
    29 	iFbs(NULL),
    30 	iFs(NULL)
    31 	{}
    32 
    33 CTIPCTest::~CTIPCTest()
    34 	{
    35 	if(iShutdownFbs)
    36 		RFbsSession::GetSession()->SendCommand(EFbsMessShutdown);
    37 	RFbsSession::Disconnect();
    38 	delete iFs;
    39 	iHeap->Close();
    40 	}
    41 
    42 void CTIPCTest::ConstructL()
    43 	{
    44 	INFO_PRINTF1(_L("Font/Bitmap Server IPC Messages Testing"));
    45 
    46 	if(RFbsSession::Connect()==KErrNone)
    47 		{
    48 		RFbsSession::Disconnect();
    49 		iShutdownFbs = EFalse;
    50 		}
    51 	else
    52 		{
    53 		FbsStartup();
    54 		iShutdownFbs = ETrue;
    55 		}
    56 	RFbsSession::Connect();
    57 	iFbs=RFbsSession::GetSession();
    58 	
    59 	if(!iShutdownFbs)
    60 		{
    61 		if(iClient.Connect() == KErrNone)
    62 			{
    63 			iShutdownFbs = EFalse;
    64 			}
    65 		else
    66 			{
    67 			iShutdownFbs = ETrue;
    68 			}
    69 		}
    70 		
    71 	iHeap=UserHeap::ChunkHeap(NULL,0x10000,0x10000);
    72 	TRAPD(ret,iFs=CFontStore::NewL(iHeap));
    73 	TEST(ret==KErrNone);
    74 	TEST(iFs != NULL);
    75 	
    76 	}
    77 
    78 void CTIPCTest::RunTestCaseL(TInt aCurTestCase)
    79 	{
    80 	_LIT(KCaseNumber, "CaseNumber");
    81 	
    82 	TBool res = iStep->GetIntFromConfig(iStep->ConfigSection(), KCaseNumber, aCurTestCase);
    83 	
    84 	if(!res)
    85 		{
    86 		return;
    87 		}
    88 		
    89 	switch(aCurTestCase)
    90 		{
    91 	/**
    92 		@SYMTestCaseID
    93 		GRAPHICS-FBSERV-0603
    94 
    95 		@SYMTestCaseDesc
    96 		Tests the sending of commands to a FbsSession 
    97 		server thru Inter Process Communication. Sends
    98 		both valid and invalid commands.
    99 
   100 		@SYMTestActions
   101 		Commands sent to the server:
   102 		1. EFbsMessShutdown
   103 		2. EFbsMessFontHeightInTwips
   104 		3. EFbsMessFontHeightInTwips
   105 		4. EFbsMessFontHeightInPixels
   106 		5. EFbsMessFontHeightInPixels
   107 		6. EFbsMessAddFontStoreFile
   108 		7. EFbsMessAddFontStoreFile
   109 		8. EFbsMessInstallFontStoreFile
   110 		9. EFbsMessInstallFontStoreFile
   111 		10. EFbsMessInstallFontStoreFile
   112 		11. EFbsMessBitmapCreate
   113 		12. EFbsMessRasterize
   114 		13. EFbsMessFaceAttrib
   115 		14. EFbsMessHasCharacter
   116 		15. EFbsMessFontNameAlias
   117 		16. EFbsMessGetNearestFontToDesignHeightInTwips
   118 		17. EFbsMessGetNearestFontToMaxHeightInTwips
   119 		18. EFbsMessGetNearestFontToDesignHeightInPixels
   120 		19. EFbsMessGetNearestFontToMaxHeightInPixels
   121 		20. EFbsMessShapeText
   122 		21. EFbsMessShapeDelete
   123 		22. EFbsMessSetTwipsHeight
   124 		23. EFbsMessGetTwipsHeight
   125 		
   126 		@SYMTestExpectedResults
   127 		Test should pass
   128 	*/
   129 	case 1:
   130 		INFO_PRINTF1(_L("Shutdown"));
   131 		iFbs->SendCommand(EFbsMessShutdown);
   132 		TestComplete();
   133 		break;
   134 	case 2:
   135 		INFO_PRINTF1(_L("Height in twips with negative typeface index"));
   136 		iFbs->SendCommand(EFbsMessFontHeightInTwips, -1);	
   137 		TEST(EFalse); // Previous line should have paniced 
   138 		TestComplete();
   139 		break;	
   140 	case 3:
   141 		INFO_PRINTF1(_L("Height in twips with invalid size"));
   142 		iClient.SendInvalidSize(EFbsMessFontHeightInTwips);
   143 		TEST(EFalse);
   144 		TestComplete();
   145 		break;
   146 	case 4:
   147 		INFO_PRINTF1(_L("Height in pixels with negative typeface index"));
   148 		iFbs->SendCommand(EFbsMessFontHeightInPixels, -1);
   149 		TEST(EFalse);
   150 		TestComplete();
   151 		break;
   152 	case 5:
   153 		INFO_PRINTF1(_L("Height in pixels with invalid size"));
   154 		iClient.SendInvalidSize(EFbsMessFontHeightInPixels);
   155 		TEST(EFalse);
   156 		TestComplete();
   157 		break;
   158 	case 6:
   159 		INFO_PRINTF1(_L("Add font store file with negative length"));
   160 		iFbs->SendCommand(EFbsMessAddFontStoreFile, 0, -1);
   161 		TEST(EFalse);
   162 		TestComplete();
   163 		break;
   164 	case 7:
   165 		INFO_PRINTF1(_L("Add font store file with huge length"));
   166 		iFbs->SendCommand(EFbsMessAddFontStoreFile, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   167 		TEST(EFalse);
   168 		TestComplete();
   169 		break;
   170 	case 8:
   171 		INFO_PRINTF1(_L("Install font store file with negative length"));
   172 		iFbs->SendCommand(EFbsMessInstallFontStoreFile, 0, -1);
   173 		TEST(EFalse);
   174 		TestComplete();
   175 		break;
   176 	case 9:
   177 		INFO_PRINTF1(_L("Install font store file with huge length"));
   178 		iFbs->SendCommand(EFbsMessInstallFontStoreFile, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   179 		TEST(EFalse);
   180 		TestComplete();
   181 		break;
   182 	case 10:
   183 		INFO_PRINTF1(_L("Remove font store file with active references"));
   184 		iFbs->SendCommand(EFbsMessRemoveFontStoreFile, 11);
   185 		// With PDEF121246 (INC120690) fix in place, this test will always pass. Without the fix there will be a KERN 4 panic.
   186 		TEST(ETrue); 
   187 		TestComplete();
   188 		break;
   189 	case 11:
   190 		INFO_PRINTF1(_L("Bitmap create with invalid display mode"));
   191 		iClient.SendInvalidDisplayMode(EFbsMessBitmapCreate);
   192 		TEST(EFalse);
   193 		TestComplete();
   194 		break;
   195 	case 12:
   196 		INFO_PRINTF1(_L("Rasterize with invalid bitmap handle"));
   197 		iFbs->SendCommand(EFbsMessRasterize, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   198 		TEST(EFalse);
   199 		TestComplete();
   200 		break;
   201 	case 13:
   202 		INFO_PRINTF1(_L("Face Attribute with invalid bitmap handle"));
   203 		iFbs->SendCommand(EFbsMessFaceAttrib, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   204 		TEST(EFalse);
   205 		TestComplete();
   206 		break;
   207 	case 14:
   208 		INFO_PRINTF1(_L("Has Character with invalid bitmap handle"));
   209 		iFbs->SendCommand(EFbsMessHasCharacter, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   210 		TEST(EFalse);
   211 		TestComplete();
   212 		break;
   213 	case 15:
   214 		INFO_PRINTF1(_L("Name Alias with huge alias name length"));
   215 		iFbs->SendCommand(EFbsMessFontNameAlias, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   216 		TEST(EFalse);
   217 		TestComplete();
   218 		break;
   219 	case 16:
   220 		INFO_PRINTF1(_L("Get nearest font to design height in twips with invalid typeface name length"));
   221 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToDesignHeightInTwips);
   222 		TEST(EFalse);
   223 		TestComplete();
   224 		break;
   225 	case 17:
   226 		INFO_PRINTF1(_L("Get nearest font to max height in twips with invalid typeface name length"));
   227 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToMaxHeightInTwips);
   228 		TEST(EFalse);
   229 		TestComplete();
   230 		break;
   231 	case 18:
   232 		INFO_PRINTF1(_L("Get nearest font to design height in pixels with invalid typeface name length"));
   233 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToDesignHeightInPixels);
   234 		TEST(EFalse);
   235 		TestComplete();
   236 		break;
   237 	case 19:
   238 		INFO_PRINTF1(_L("Get nearest font to max height in pixels with invalid typeface name length"));
   239 		iClient.SendInvalidNameLength(EFbsMessGetNearestFontToMaxHeightInPixels);
   240 		TEST(EFalse);
   241 		TestComplete();
   242 		break;
   243 	case 20:
   244 		INFO_PRINTF1(_L("Shape text with invalid bitmap font handle"));
   245 		iFbs->SendCommand(EFbsMessShapeText, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   246 		TEST(EFalse);
   247 		TestComplete();
   248 		break;
   249 	case 21:
   250 		INFO_PRINTF1(_L("Shape delete with invalid bitmap font handle"));
   251 		iFbs->SendCommand(EFbsMessShapeDelete, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   252 		TEST(EFalse);
   253 		TestComplete();
   254 		break;
   255 	case 22:
   256 		INFO_PRINTF1(_L("Set twips height with invalid font handle"));
   257 		iFbs->SendCommand(EFbsMessSetTwipsHeight, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   258 		TEST(EFalse);
   259 		TestComplete();
   260 		break;
   261 	case 23:
   262 		INFO_PRINTF1(_L("Get twips height with invalid font handle"));
   263 		iFbs->SendCommand(EFbsMessGetTwipsHeight, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   264 		TEST(EFalse);
   265 		TestComplete();
   266 		break;	
   267 	case 24:
   268 		/**
   269 			@SYMTestCaseID	GRAPHICS-FBSERV-0630
   270 
   271 			@SYMTestCaseDesc
   272 			Tests that invalid font handle to EFbsMessGetGlyphs causes panic
   273 
   274 			@SYMTestExpectedResults
   275 			Client should panic with FBSERV -8
   276 		*/
   277 		INFO_PRINTF1(_L("Get glyphs from glyph atlas with invalid font handle"));
   278 		iFbs->SendCommand(EFbsMessGetGlyphs, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   279 		TEST(EFalse);
   280 		TestComplete();
   281 		break;
   282 	case 25:
   283 		/**
   284 			@SYMTestCaseID	GRAPHICS-FBSERV-0670
   285 
   286 			@SYMTestCaseDesc
   287 			Tests that invalid font handle to EFbsMessGetGlyphMetrics causes panic
   288 
   289 			@SYMTestExpectedResults
   290 			Client should panic with FBSERV -8
   291 		*/
   292 		INFO_PRINTF1(_L("Get glyph metrics with invalid font handle"));
   293 		iFbs->SendCommand(EFbsMessGetGlyphMetrics, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   294 		TEST(EFalse);
   295 		TestComplete();
   296 		break;
   297 	/**
   298 		@SYMTestCaseID
   299 		TI18N-GDI-CIT-4086
   300 
   301 		@SYMTestCaseDesc
   302 		Test if FBS can handle invalid messages correctly
   303 		and panic the client as needed.
   304 
   305 		@SYMTestActions
   306 		26. EFbsMessGetFontTable
   307 		27. EFbsMessReleaseFontTable
   308 		28. EFbsMessGetGlyphOutline
   309 		29. EFbsMessReleaseGlyphOutline
   310 	
   311 		@SYMTestExpectedResults
   312 		Test should pass
   313 	*/
   314 	case 26:
   315 		INFO_PRINTF1(_L("Get Font Table with wrong msg"));
   316 		iFbs->SendCommand(EFbsMessGetFontTable, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   317 		TEST(EFalse); 
   318 		TestComplete();
   319 		break;
   320 	case 27:
   321 		INFO_PRINTF1(_L("Release Font Table with wrong msg"));
   322 		iFbs->SendCommand(EFbsMessReleaseFontTable, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   323 		TEST(EFalse); 
   324 		TestComplete();
   325 		break;
   326 	case 28:
   327 		INFO_PRINTF1(_L("Get Glyph outline with wrong msg"));
   328 		iFbs->SendCommand(EFbsMessGetGlyphOutline,KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   329 		TEST(EFalse); 
   330 		TestComplete();
   331 		break;
   332 	case 29:
   333 		INFO_PRINTF1(_L("Release Glyph outline with wrong msg"));
   334 		iFbs->SendCommand(EFbsMessReleaseGlyphOutline, KInvalidParam1, KInvalidParam2, KInvalidParam3, KInvalidParam4);
   335 		TEST(EFalse); 
   336 		TestComplete();
   337 		break;
   338 	case 30:
   339 		TestComplete();
   340 		break;
   341 		}
   342 	}
   343 	
   344 RIPCTestFbservClient::RIPCTestFbservClient()
   345 	{
   346 	
   347 	}
   348 	
   349 RIPCTestFbservClient::~RIPCTestFbservClient()
   350 	{
   351 	
   352 	}
   353 	
   354 TInt RIPCTestFbservClient::Connect(void)
   355 	{
   356 	_LIT(KFbServerName, "!Fontbitmapserver");
   357 	TVersion version(0, 0, 0);
   358 	TInt ret = CreateSession(KFbServerName, version);
   359 	return ret;
   360 	}
   361 	
   362 void RIPCTestFbservClient::SendInvalidSize(TInt aFunctionNumber)
   363 	{
   364 	TPckgBuf<TSize> size;
   365 	size().iHeight = 0;
   366 	size().iWidth = 0;
   367 	TIpcArgs args;
   368 	args.Set(0, 1);
   369 	args.Set(2, &size);
   370 	
   371 	SendReceive(aFunctionNumber, args);
   372 	}
   373 	
   374 void RIPCTestFbservClient::SendInvalidDisplayMode(TInt aFunctionNumber)
   375 	{
   376 	TPckgBuf<TBmpSpec> bmpSpec;
   377 	bmpSpec().iDispMode = EColorLast;
   378 	TIpcArgs args = TIpcArgs();
   379 	args.Set(0, &bmpSpec);
   380 	
   381 	SendReceive(aFunctionNumber, args);
   382 	}
   383 
   384 void RIPCTestFbservClient::SendInvalidNameLength(TInt aFunctionNumber)	
   385 	{
   386 	TIpcArgs args = TIpcArgs();
   387 	_LIT(KDefault, "Default");
   388 	TInt size = 7;
   389 	HBufC8 *buf1 = HBufC8::NewLC(size);
   390 	TPtr8 ptr1 = buf1->Des();
   391 	ptr1.Copy(KDefault);
   392 	CleanupStack::PopAndDestroy(buf1);
   393 	args.Set(0, &ptr1);	
   394 	SendReceive(aFunctionNumber, args);
   395 	}
   396 
   397 
   398 //--------------
   399 __CONSTRUCT_STEP__(IPCTest)
   400