fbs/fontandbitmapserver/tfbs/TFBS.CPP
changeset 187 9f66f99ee56f
parent 0 5d03bc08d59c
child 178 89bd4cfee505
equal deleted inserted replaced
103:2717213c588a 187:9f66f99ee56f
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    82 	}
    82 	}
    83 
    83 
    84 void CTFbs::ConstructL()
    84 void CTFbs::ConstructL()
    85 	{
    85 	{
    86 	ExpandCleanupStackL();
    86 	ExpandCleanupStackL();
    87 	
    87 	User::LeaveIfError(Logger().ShareAuto());
    88 	TestConstruction();
    88 	TestConstruction();
    89 	AllocScanLineBuf();
    89 	AllocScanLineBuf();
    90 	
    90 	
    91 	INFO_PRINTF1(_L("FBSERV testing"));
    91 	INFO_PRINTF1(_L("FBSERV testing"));
    92 	}
    92 	}
   185 	case 19:
   185 	case 19:
   186 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0508"));
   186 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0508"));
   187 		TestSingletonServer();
   187 		TestSingletonServer();
   188 		break;
   188 		break;
   189 	case 21:
   189 	case 21:
   190 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0620"));
   190 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0623"));
   191 		TestFontSessionCacheLookupL();
   191 		TestFontSessionCacheLookupL();
   192 		break;
   192 		break;
   193 	case 22:
   193 	case 22:
   194 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0650"));
   194 		((CTFbsStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0650"));
   195 		TestInvalidHandlesInIpcCallsL();
   195 		TestInvalidHandlesInIpcCallsL();
   647 	iResourceCount--;
   647 	iResourceCount--;
   648 	TEST(w==font3->TextWidthInPixels(_L(" ")));
   648 	TEST(w==font3->TextWidthInPixels(_L(" ")));
   649 	CheckResourceCount();
   649 	CheckResourceCount();
   650 	TEST(fbsalt->ResourceCount()==iResourceCount);
   650 	TEST(fbsalt->ResourceCount()==iResourceCount);
   651 	font3->Reset();
   651 	font3->Reset();
   652 	User::Free(font3);
   652 	delete font3;
   653 	iResourceCount--;
   653 	iResourceCount--;
   654 	CheckResourceCount();
   654 	CheckResourceCount();
   655 	TEST(fbsalt->ResourceCount()==iResourceCount);
   655 	TEST(fbsalt->ResourceCount()==iResourceCount);
   656 	User::Heap().Check();
   656 	User::Heap().Check();
   657 	}
   657 	}
  2131 	TEST(exitReason == EFbsPanicStartupFailed);
  2131 	TEST(exitReason == EFbsPanicStartupFailed);
  2132 	fbs.Close();
  2132 	fbs.Close();
  2133 	}
  2133 	}
  2134 
  2134 
  2135 /**
  2135 /**
  2136 @SYMTestCaseID      GRAPHICS-FBSERV-0620
  2136 @SYMTestCaseID      GRAPHICS-FBSERV-0623
  2137 @SYMTestPriority    High
  2137 @SYMTestPriority    High
  2138 @SYMTestStatus      Implemented
  2138 @SYMTestStatus      Implemented
  2139 @SYMDEF             DEF140138
  2139 @SYMDEF             DEF140138
  2140 
  2140 
  2141 @SYMTestCaseDesc
  2141 @SYMTestCaseDesc
  2143 	session cache becomes used, client-side CFbsFont calls that query the session cache 
  2143 	session cache becomes used, client-side CFbsFont calls that query the session cache 
  2144 	successfully find the glyph, proving that the session handles used client-side and server-side
  2144 	successfully find the glyph, proving that the session handles used client-side and server-side
  2145 	are the same, thereby avoiding any unneccessary IPC calls.
  2145 	are the same, thereby avoiding any unneccessary IPC calls.
  2146 
  2146 
  2147 @SYMTestActions
  2147 @SYMTestActions
       
  2148 	Try to open a global semaphore called "FBSSessionCacheSemaphore" (this is a temporary measure to
       
  2149 		ensure successful propagation of ou1cimx1#250526).
  2148 	Create a large font which consumes a lot of memory.
  2150 	Create a large font which consumes a lot of memory.
  2149 	Create a CFbsBitGc and a CFbsBitmap target.
  2151 	Create a CFbsBitGc and a CFbsBitmap target.
  2150 	Use the CFbsBitGc to render some text, thereby filling the font glyph cache. 
  2152 	Use the CFbsBitGc to render some text, thereby filling the font glyph cache. 
  2151 		Renders enough glyphs to fill up the font glyph cache, so that the session cache is used
  2153 		Renders enough glyphs to fill up the font glyph cache, so that the session cache is used
  2152 		for later characters.
  2154 		for later characters.
  2154 	Call CBitmapFont::CharacterNeedsToBeRasterized() with the RFbsSession handle.
  2156 	Call CBitmapFont::CharacterNeedsToBeRasterized() with the RFbsSession handle.
  2155 	Call CFbsFont::GetCharacterData() to retrieve a pointer to the bitmap data. Compare this with the data 
  2157 	Call CFbsFont::GetCharacterData() to retrieve a pointer to the bitmap data. Compare this with the data 
  2156 		returned from CBitmapFont::GetCharacterData().
  2158 		returned from CBitmapFont::GetCharacterData().
  2157 
  2159 
  2158 @SYMTestExpectedResults
  2160 @SYMTestExpectedResults
       
  2161 	No global semaphore called "FBSSessionCacheSemaphore" should exist.
  2159 	When using KNullHandle, CharacterNeedsToBeRasterized() with the first character, is expected to pass
  2162 	When using KNullHandle, CharacterNeedsToBeRasterized() with the first character, is expected to pass
  2160 		proving that the font cache is working as expected when glyphs can fit into it.
  2163 		proving that the font cache is working as expected when glyphs can fit into it.
  2161 	When using KNullHandle, CharacterNeedsToBeRasterized() with the last character, it expected to fail, 
  2164 	When using KNullHandle, CharacterNeedsToBeRasterized() with the last character, it expected to fail, 
  2162 		proving that the glyph has not been cached in the font glyph cache. (If it had, it would find a 
  2165 		proving that the glyph has not been cached in the font glyph cache. (If it had, it would find a 
  2163 		match regardless of the	session handle as it looks in the font cache before the session cache).
  2166 		match regardless of the	session handle as it looks in the font cache before the session cache).
  2170 */
  2173 */
  2171 void CTFbs::TestFontSessionCacheLookupL()
  2174 void CTFbs::TestFontSessionCacheLookupL()
  2172 	{
  2175 	{
  2173 	INFO_PRINTF1(_L("Test Font Session-cache Lookup"));
  2176 	INFO_PRINTF1(_L("Test Font Session-cache Lookup"));
  2174 
  2177 
       
  2178 	// Make sure the global semaphore is gone for good
       
  2179 	_LIT(KSessionCacheSemaphoreName, "FBSSessionCacheSemaphore");
       
  2180 	RSemaphore sem;
       
  2181 	TEST(sem.OpenGlobal(KSessionCacheSemaphoreName) == KErrNotFound);
       
  2182 
  2175 	User::LeaveIfError(RFbsSession::Connect());    
  2183 	User::LeaveIfError(RFbsSession::Connect());    
  2176 	RFbsSession* fbsSession = RFbsSession::GetSession();
  2184 	RFbsSession* fbsSession = RFbsSession::GetSession();
  2177 	CFbsTypefaceStore* ts = CFbsTypefaceStore::NewL(NULL);
  2185 	CFbsTypefaceStore* ts = CFbsTypefaceStore::NewL(NULL);
  2178 	CleanupStack::PushL(ts);
  2186 	CleanupStack::PushL(ts);
  2179 
  2187 
  2271 
  2279 
  2272 	// Send a IPC command to set the font's height with the font's handle
  2280 	// Send a IPC command to set the font's height with the font's handle
  2273 	TEST(KErrNone == iFbs->SendCommand(EFbsMessSetTwipsHeight, fontHandle, 49));
  2281 	TEST(KErrNone == iFbs->SendCommand(EFbsMessSetTwipsHeight, fontHandle, 49));
  2274 	// In a second thread, send a IPC command to set the font's height with the 
  2282 	// In a second thread, send a IPC command to set the font's height with the 
  2275 	// bitmap's handle.  Should panic with FBServ -6.
  2283 	// bitmap's handle.  Should panic with FBServ -6.
  2276 	TFbsTestThreadInfo threadInfo = {EFbsSecondThreadInvalidHandleInIpcCall};
       
  2277  	TExitCategoryName exitCategoryName(KFbsPanicCategory);
       
  2278 	_LIT(KTestName, "TestInvalidHandlesInIpcCall");
  2284 	_LIT(KTestName, "TestInvalidHandlesInIpcCall");
  2279  	CreateSecondThreadAndCheckPanicL(threadInfo, -6, exitCategoryName, KTestName);
  2285  	CreateSecondThreadAndCheckPanicL(SecondThreadPanicInvalidHandleInIpcCallL, KErrArgument, KFbsPanicCategory, KTestName);
  2280 
  2286 
  2281 	iTs->ReleaseFont(font);
  2287 	iTs->ReleaseFont(font);
  2282 	delete bmp;
  2288 	delete bmp;
  2283 	}
  2289 	}
  2284 
  2290 
  2285 /**
  2291 /**
  2286 Creates a second thread and do some panic tests in it.
  2292 Second thread function for test GRAPHICS-FBSERV-0650. It should panic with FBSERV -6 if the test is successful.
  2287 @param aTestInfo The information for the tests
  2293  */
  2288 @param aPanicCode The expected panic code
  2294 void CTFbs::SecondThreadPanicInvalidHandleInIpcCallL()
  2289 @param aExitCategory The expected panic category
  2295 	{
  2290 @param aThreadName The name of the new thread
  2296 	User::LeaveIfError(RFbsSession::Connect());
  2291 @leave Gets system wide error code
  2297 	RFbsSession* fbs = RFbsSession::GetSession();
  2292 */
  2298 	CFbsBitmapEx* bmp = new(ELeave) CFbsBitmapEx();
  2293 void CTFbs::CreateSecondThreadAndCheckPanicL(TFbsTestThreadInfo& aTestInfo, TInt aPanicCode, TExitCategoryName aExitCategory, const TDesC &aThreadName)
  2299 	CleanupStack::PushL(bmp);
       
  2300 	User::LeaveIfError(bmp->Create(TSize(1,1), EGray2));
       
  2301 	CFbsTypefaceStore* ts = CFbsTypefaceStore::NewL(NULL);
       
  2302 	CleanupStack::PushL(ts);
       
  2303 	CFbsFont* font=NULL;
       
  2304 	User::LeaveIfError(ts->GetNearestFontToDesignHeightInPixels((CFont*&)font, TFontSpec(KTypefaceName, 15)));
       
  2305 	TInt bitmapHandle = bmp->BitmapHandle();
       
  2306 
       
  2307 	// Send a IPC command to set twips height of font with a bitmap handle
       
  2308 	(void)fbs->SendCommand(EFbsMessSetTwipsHeight, bitmapHandle, 49);
       
  2309 
       
  2310 	ts->ReleaseFont(font);
       
  2311 	CleanupStack::PopAndDestroy(2);
       
  2312 	RFbsSession::Disconnect();
       
  2313 	}
       
  2314 
       
  2315 
       
  2316 struct TFbsTestDelegator
       
  2317 	{
       
  2318 	CTFbs* iTestBase;
       
  2319 	void (CTFbs::*iMethodPtr)();
       
  2320 	};
       
  2321 
       
  2322 /**
       
  2323 Creates a second thread and checks that it panics.
       
  2324 @param aMethodL The leaving method of CTFbs that the second thread is going to execute.
       
  2325 @param aPanicCode The expected panic code.
       
  2326 @param aPanicCategory The expected panic category.
       
  2327 @param aThreadName The name of the new thread.
       
  2328 */
       
  2329 void CTFbs::CreateSecondThreadAndCheckPanicL(void (CTFbs::*aMethodL)(), TInt aPanicCode, const TDesC& aPanicCategory, const TDesC& aThreadName)
  2294 	{
  2330 	{
  2295 	RThread secondThread;
  2331 	RThread secondThread;
  2296 	User::LeaveIfError(secondThread.Create(aThreadName, SecondThreadStart, KDefaultStackSize, 0x1000, 0x1000, &aTestInfo));
  2332 	TFbsTestDelegator delegator;
       
  2333 	delegator.iTestBase = this;
       
  2334 	delegator.iMethodPtr = aMethodL;
       
  2335 	User::LeaveIfError(secondThread.Create(aThreadName, MethodDelegatorThreadFunction, KDefaultStackSize, 0x1000, 0x1000, &delegator));
  2297 	// Launch second thread
  2336 	// Launch second thread
  2298 	TRequestStatus statusSecondThread;
  2337 	TRequestStatus statusSecondThread;
  2299 	secondThread.Logon(statusSecondThread);
  2338 	secondThread.Logon(statusSecondThread);
  2300 	secondThread.SetPriority(EPriorityLess);
  2339 	secondThread.Resume();
  2301 	secondThread.Resume();	
  2340 	// Wait until second thread is finished
  2302 	
       
  2303 	User::WaitForRequest(statusSecondThread);
  2341 	User::WaitForRequest(statusSecondThread);
  2304 	
  2342 	// Check results
  2305 	if(EExitPanic != secondThread.ExitType())
  2343 	if (EExitPanic != secondThread.ExitType())
  2306 		{
  2344 		{
  2307 		ERR_PRINTF3(_L("Expected exit type: %d, Actual exit type: %d"), EExitPanic, secondThread.ExitType());
  2345 		ERR_PRINTF2(_L("Expected exit type: EExitPanic, actual exit type: %d"), secondThread.ExitType());
  2308 		TEST(EFalse);
  2346 		TEST(EFalse);
  2309 		}
  2347 		}
  2310 	
  2348 	if (aPanicCode != secondThread.ExitReason())
  2311 	if(aPanicCode != secondThread.ExitReason())
       
  2312 		{
  2349 		{
  2313 		ERR_PRINTF3(_L("Expected panic code: %d, Actual panic code: %d"), aPanicCode, secondThread.ExitReason());
  2350 		ERR_PRINTF3(_L("Expected exit reason: %d, actual exit reason: %d"), aPanicCode, secondThread.ExitReason());
  2314         TEST(EFalse);
  2351         TEST(EFalse);
  2315 		}
  2352 		}
  2316 	
       
  2317 	TExitCategoryName secondThreadExitCategory = secondThread.ExitCategory();
  2353 	TExitCategoryName secondThreadExitCategory = secondThread.ExitCategory();
  2318 	if(aExitCategory != secondThreadExitCategory)
  2354 	if (aPanicCategory != secondThreadExitCategory)
  2319 		{
  2355 		{
  2320 		ERR_PRINTF3(_L("Expected panic category: %S, Actual panic category: %S"), &aExitCategory, &secondThreadExitCategory);
  2356 		ERR_PRINTF3(_L("Expected exit category: %S, actual exit category: %S"), &aPanicCategory, &secondThreadExitCategory);
  2321         TEST(EFalse);
  2357         TEST(EFalse);
  2322 		}
  2358 		}
  2323 	
  2359 	// Dispose of the remains of the second thread
  2324 	//Close the handle
       
  2325 	secondThread.Close();
  2360 	secondThread.Close();
  2326 	}
  2361 	}
  2327 
  2362 
  2328 /**
  2363 TInt CTFbs::MethodDelegatorThreadFunction(TAny* aDelegator)
  2329 Second thread entry function.
  2364 	{
  2330 */
       
  2331 TInt CTFbs::SecondThreadStart(TAny* aTestInfo)
       
  2332 	{
       
  2333 	
       
  2334 	__UHEAP_MARK;
       
  2335     TInt procHandles1  =0;
       
  2336     TInt threadHandles1=0;
       
  2337     RThread().HandleCount(procHandles1, threadHandles1);
       
  2338 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
  2365 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
  2339 	
       
  2340 	if (!cleanupStack)
  2366 	if (!cleanupStack)
  2341 	    {
  2367 	    {
  2342 	    __UHEAP_MARKEND;
       
  2343 	    return KErrNoMemory;
  2368 	    return KErrNoMemory;
  2344 	    }
  2369 	    }
  2345 	
  2370 	TFbsTestDelegator* delegator = static_cast<TFbsTestDelegator*>(aDelegator);
  2346 	TInt result = KErrNone;
  2371 	TRAPD(err, (delegator->iTestBase->*delegator->iMethodPtr)());
  2347 	TRAP(result, SecondThreadMainL(static_cast<TFbsTestThreadInfo*>(aTestInfo)));
       
  2348 	
       
  2349 	delete cleanupStack;
  2372 	delete cleanupStack;
  2350 
  2373 	return err;
  2351     TInt procHandles2  =0;
       
  2352     TInt threadHandles2=0;
       
  2353     RThread().HandleCount(procHandles2,threadHandles2);
       
  2354     if (threadHandles1 != threadHandles2)
       
  2355         {
       
  2356         result = KErrGeneral;  // Thread-owned handles not closed
       
  2357         }
       
  2358 	__UHEAP_MARKEND;
       
  2359 
       
  2360 	return result;
       
  2361 	}
       
  2362 
       
  2363 /**
       
  2364 Run the test contained within the TFbsTestThreadInfo object. A new thread is
       
  2365 created for each test and only one of the cases in the switch statements
       
  2366 below will be used.
       
  2367 
       
  2368 @param aTestInfo The parameters for the test
       
  2369 @return One of the system wide error codes or an enumeration of passed tests.
       
  2370  */
       
  2371 TInt CTFbs::SecondThreadMainL(TFbsTestThreadInfo* aTestInfo)
       
  2372     {
       
  2373     TInt result = 0;
       
  2374     TFbsMultiThreadTestCase testcase = aTestInfo->iTestCase;
       
  2375 
       
  2376     //test cases without the need of an initialised driver
       
  2377     switch (testcase)
       
  2378     	{
       
  2379     case EFbsSecondThreadInvalidHandleInIpcCall:
       
  2380     	result = SecondThreadPanicInvalidHandleInIpcCall();
       
  2381         break;
       
  2382     	}
       
  2383     return result;
       
  2384     }
       
  2385 
       
  2386 /**
       
  2387 Implementation of SecondThread test EFbsSecondThreadInvalidHandleInIpcCall
       
  2388 
       
  2389 @panic FBSERV -6 If the test is successful
       
  2390 
       
  2391 @return One of the system wide error codes.
       
  2392  */
       
  2393 TInt CTFbs::SecondThreadPanicInvalidHandleInIpcCall()
       
  2394 	{
       
  2395 	TInt result = RFbsSession::Connect();
       
  2396 	if (KErrNone != result)
       
  2397 		{
       
  2398 		return result;
       
  2399 		}
       
  2400 	RFbsSession* fbs = RFbsSession::GetSession();
       
  2401 	CFbsBitmapEx* bmp = new CFbsBitmapEx();
       
  2402 	if (!bmp)
       
  2403 		{
       
  2404 		return KErrGeneral;
       
  2405 		}
       
  2406 	result = bmp->Create(TSize(1,1),EGray2);
       
  2407 	if(KErrNone != result)
       
  2408 		{
       
  2409 		delete bmp;
       
  2410 		return KErrGeneral;
       
  2411 		}
       
  2412 
       
  2413 	CFbsTypefaceStore* ts = NULL;
       
  2414 	ts = (CFbsTypefaceStore*)CFbsTypefaceStore::NewL(NULL);
       
  2415 	if (!ts)
       
  2416 		{
       
  2417 		delete bmp;
       
  2418 		return KErrGeneral;
       
  2419 		}
       
  2420 
       
  2421 	CFbsFontEx* font=NULL;
       
  2422 	result = ts->GetNearestFontToDesignHeightInPixels((CFont*&)font, TFontSpec(KTypefaceName, 15));
       
  2423 	if (!font)
       
  2424 		{
       
  2425 		delete bmp;
       
  2426 		delete ts;
       
  2427 		return KErrGeneral;
       
  2428 		}
       
  2429 
       
  2430 	TInt fontHandle = font->FontHandle();
       
  2431 	TInt bitmapHandle = bmp->BitmapHandle();
       
  2432 
       
  2433 	// Send a IPC command to set twips height of font with a bitmap handle
       
  2434 	result = fbs->SendCommand(EFbsMessSetTwipsHeight, bitmapHandle, 49);
       
  2435 
       
  2436 	ts->ReleaseFont(font);
       
  2437 	delete bmp;
       
  2438 	delete ts;
       
  2439 	return result;
       
  2440 	}
  2374 	}
  2441 
  2375 
  2442 /**
  2376 /**
  2443 @SYMTestCaseID		GRAPHICS-FBSERV-0619
  2377 @SYMTestCaseID		GRAPHICS-FBSERV-0619
  2444 @SYMTestPriority	High
  2378 @SYMTestPriority	High