sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "T_GlyphTreeDel.h" sl@0: sl@0: const TDisplayMode testDisplayModes[] = sl@0: { sl@0: EGray2, sl@0: EGray4, sl@0: EGray16, sl@0: EGray256, sl@0: EColor16, sl@0: EColor256, sl@0: EColor64K, sl@0: EColor16M, sl@0: EColor4K, sl@0: EColor16MU, sl@0: EColor16MA, sl@0: EColor16MAP, sl@0: }; sl@0: sl@0: // This test is based on code from the TTAGMA test in form sl@0: sl@0: sl@0: CTGlyphTreeDel::CTGlyphTreeDel(CTestStep* aStep): sl@0: iStep(aStep) sl@0: { sl@0: } sl@0: sl@0: CTGlyphTreeDel::~CTGlyphTreeDel() sl@0: { sl@0: delete iGc; sl@0: delete iDev; sl@0: RFbsSession::Disconnect(); sl@0: } sl@0: sl@0: CTGlyphTreeDel* CTGlyphTreeDel::NewL(CTestStep* aStep) sl@0: { sl@0: CTGlyphTreeDel *theTest = new (ELeave) CTGlyphTreeDel(aStep); sl@0: sl@0: CleanupStack::PushL(theTest); sl@0: theTest->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return theTest; sl@0: } sl@0: sl@0: void CTGlyphTreeDel::ConstructL() sl@0: { sl@0: iStep -> INFO_PRINTF1(_L("DEF047283")); sl@0: RFbsSession::Connect(); sl@0: iFbs = RFbsSession::GetSession(); sl@0: if (iFbs == NULL) sl@0: User::Leave(KErrGeneral); sl@0: User::LeaveIfError(CreateScreenDevice()); sl@0: iDev->ChangeScreenDevice(NULL); sl@0: iDev->SetAutoUpdate(ETrue); sl@0: iDev->CreateContext(iGc); sl@0: } sl@0: sl@0: TInt CTGlyphTreeDel::CreateScreenDevice() sl@0: { sl@0: TInt err = KErrNone; sl@0: TInt sizeOfDisplayMode = sizeof (testDisplayModes) / sizeof(testDisplayModes[0]); sl@0: sl@0: for(TInt theScreenModeIndex = sizeOfDisplayMode - 1; theScreenModeIndex ; theScreenModeIndex--) sl@0: { sl@0: TDisplayMode disp = testDisplayModes[theScreenModeIndex]; sl@0: TRAP(err, iDev = CFbsScreenDevice::NewL(_L(""), disp)); //scdv sl@0: if(err == KErrNone) sl@0: { sl@0: iStep->INFO_PRINTF2(_L("Device %d has been created"), disp); sl@0: return KErrNone; sl@0: } sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: // Get System free Ram sl@0: sl@0: TInt CTGlyphTreeDel::GetRam() sl@0: { sl@0: TMemoryInfoV1Buf memory; sl@0: UserHal::MemoryInfo(memory); sl@0: return(TInt)(memory().iFreeRamInBytes); sl@0: } sl@0: sl@0: void CTGlyphTreeDel::CheckRam( TInt beforeFreeRam) sl@0: { sl@0: TInt freeRam=GetRam(); sl@0: if( beforeFreeRam < freeRam) sl@0: { sl@0: iStep -> INFO_PRINTF2( _L("Freed %08d bytes of RAM\n"), freeRam-beforeFreeRam); sl@0: } sl@0: else if( beforeFreeRam > freeRam) sl@0: { sl@0: iStep -> INFO_PRINTF2( _L("Leaked %08d bytes of RAM\n"), beforeFreeRam-freeRam); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID sl@0: GRAPHICS-FNTSTORE-0034 sl@0: sl@0: @SYMTestCaseDesc sl@0: Tests glyph cache. sl@0: sl@0: @SYMTestActions sl@0: 1. Sets pen style to null pen. sl@0: 2. Sets brush color to gray. sl@0: 3. Sets brush style to solid. sl@0: 4. Retrieves number of typefaces. sl@0: 5. Retrieves the details of the typeface family. sl@0: 6. Gets the font which is the nearest to the given font specification. sl@0: 7. Sets the retrieved font to be used into the graphic context. sl@0: 8. Draws a string to the display. sl@0: 9. Releases the font. sl@0: 10. Discards the font. sl@0: 11. Glyph cache is filled by looping. The glyph cache heap should be large enough sl@0: for all subsequent loops, if the glyph tree is successfully deleted after the font is sl@0: discarded. sl@0: 12. Waits three seconds after the loops complete for the first time. Then records the free RAM. sl@0: No extra RAM should be required to be allocated after this point. sl@0: 13. Check if there is any RAM loss. sl@0: sl@0: @SYMTestExpectedResults sl@0: Test should pass sl@0: */ sl@0: void CTGlyphTreeDel::TestGlyphTreeDeleteL() sl@0: { sl@0: iGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: iGc->SetBrushColor(KRgbGray); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: sl@0: TInt typefaces = iDev->NumTypefaces(); sl@0: TTypefaceSupport info; sl@0: TInt fontSize = 24; sl@0: sl@0: TInt beforeFreeRam = GetRam(); // Initialise here because of WINS warning sl@0: sl@0: for(TInt loop=0;loop<100;++loop) sl@0: { sl@0: if (loop&1) //if it is odd sl@0: fontSize+=12; sl@0: else sl@0: fontSize-=12; sl@0: sl@0: TInt count=0; sl@0: TInt forLoop = 0; sl@0: sl@0: for (count=0;count < typefaces; count++) sl@0: { sl@0: iDev->TypefaceSupport(info, count); sl@0: TFontSpec fs; sl@0: fs.iTypeface = info.iTypeface; sl@0: fs.iHeight = fontSize; sl@0: CFbsFont* font = NULL; sl@0: TInt err = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs); sl@0: sl@0: if( font == NULL) sl@0: { sl@0: iStep -> INFO_PRINTF6(_L("[Couldn't get font Loop % 2d, Iteration % 2d Font \"%S\", Size %d, err %d]\n"), forLoop, count, &fs.iTypeface.iName, fontSize, err); sl@0: continue; sl@0: } sl@0: sl@0: iGc->UseFont(font); sl@0: iGc->DrawText(_L("ABCDEFG123456789\n"), TPoint(10+loop, 200-(fontSize*2)+count)); sl@0: iDev->ReleaseFont(font); sl@0: iGc->DiscardFont(); sl@0: } sl@0: sl@0: forLoop=1; sl@0: for (count=typefaces-1;count>=0;--count) sl@0: { sl@0: iDev->TypefaceSupport(info, count); sl@0: sl@0: TFontSpec fs; sl@0: fs.iTypeface = info.iTypeface; sl@0: fs.iHeight = fontSize; sl@0: CFbsFont* font = NULL; sl@0: TInt err = iDev->GetNearestFontToDesignHeightInPixels((CFont*&)font, fs); sl@0: sl@0: if( font == NULL) sl@0: { sl@0: iStep -> INFO_PRINTF6(_L("[Couldn't get font Loop % 2d, Iteration % 2d Font \"%S\", Size %d, err %d]\n"), forLoop, count, &fs.iTypeface.iName, fontSize, err); sl@0: continue; sl@0: } sl@0: sl@0: iGc->UseFont(font); sl@0: iGc->DrawText(_L("ABCDEFG123456789\n"), TPoint(10+loop, 200-(fontSize*2)+count)); sl@0: iDev->ReleaseFont(font); sl@0: iGc->DiscardFont(); sl@0: } sl@0: sl@0: // When the 2 loops above have completed once, the glyph cache heap should be large enough sl@0: // for all subsequent loops, if the glyph tree is successfully deleted after the font is sl@0: // discarded. So we wait 3 seconds after the 2 loops complete for the 1st time and then sl@0: // record the free RAM. No extra RAM should be required to be allocated after this point. sl@0: sl@0: if( loop==0) sl@0: { sl@0: sl@0: // Wait to ensure font memory grabs are complete sl@0: User::After(3000000); sl@0: sl@0: // save initial free RAM figure sl@0: beforeFreeRam = GetRam(); sl@0: } sl@0: sl@0: } sl@0: // Wait for all requests to complete sl@0: User::After(2000000); sl@0: sl@0: // If there is any RAM loss print it out before call to iTest sl@0: CheckRam(beforeFreeRam); sl@0: TInt afterFreeRam = GetRam(); sl@0: // Add a safety buffer to accouunt for miscellaneous system changes sl@0: // affect the total ram. The defect this was set to catch was leaking sl@0: // of the order of a megabyte so this will still catch that. sl@0: afterFreeRam += 65536; sl@0: sl@0: // Any extra RAM grabbed for the glyph trees should be released by sl@0: // the calls to DiscardFont sl@0: sl@0: iStep-> testBooleanTrue((afterFreeRam>=beforeFreeRam), (TText8*)__FILE__, __LINE__); sl@0: } sl@0: sl@0: sl@0: //-------------- sl@0: CTGlyphTreeDelStep::CTGlyphTreeDelStep() sl@0: { sl@0: SetTestStepName(KTGlyphTreeDelStep); sl@0: } sl@0: sl@0: TVerdict CTGlyphTreeDelStep::doTestStepL() sl@0: { sl@0: #if defined(__SUPPORT_CPP_EXCEPTIONS__) sl@0: SetTestStepID(_L("GRAPHICS-FNTSTORE-0034")); sl@0: FbsStartup(); sl@0: CTrapCleanup* TrapCleanup = CTrapCleanup::New(); sl@0: TInt error = KErrNone; sl@0: try { sl@0: TTrapHandler* trapHandler = User::MarkCleanupStack(); sl@0: __UHEAP_MARK; sl@0: sl@0: User::After(10000000); sl@0: CTGlyphTreeDel* test_harness = CTGlyphTreeDel::NewL(this); sl@0: test_harness->TestGlyphTreeDeleteL(); sl@0: delete test_harness; sl@0: sl@0: __UHEAP_MARKEND; sl@0: User::UnMarkCleanupStack(trapHandler); sl@0: } sl@0: catch (XLeaveException& leave) sl@0: { sl@0: error = leave.GetReason(); sl@0: } sl@0: catch (...) sl@0: { sl@0: User::Invariant(); sl@0: } sl@0: delete TrapCleanup; sl@0: sl@0: if (error) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: RecordTestResultL(); sl@0: #endif //__SUPPORT_CPP_EXCEPTIONS__ sl@0: return TestStepResult(); sl@0: }