sl@0: /* sl@0: * Copyright (c) 2007-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: * Cache Deletion for fntstore multi-processed test code sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "FNTSTORE.H" sl@0: #include "FNTBODY.H" sl@0: #include "FNTSTD.H" sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: _LIT(KOpenFont, "DejaVu Sans Condensed"); sl@0: sl@0: #ifdef __WINSCW__ sl@0: //this is used for winscw breakpoints sl@0: #define BR _asm( int 3); sl@0: #endif sl@0: sl@0: sl@0: /* it is expected that the main in this file will be called to test multiple sl@0: process output at the same time a process is being deleted (font and bitmap server sl@0: disconnection. There are normally two instances of this process. Two virtually sl@0: identical processes are required to ensure that the session ID is the same. sl@0: sl@0: The first is with aThirdProcess set. This sets output to run in a loop until sl@0: the timeout is completed. These values are input via program arguments. sl@0: sl@0: If aThirdProcess is false then only one font creation, draw text, sl@0: font deletion cycle is completed. The test code will then repeatedly run sl@0: this process with aThirdProcess set to false. sl@0: */ sl@0: class TRunProc2: public CBase sl@0: { sl@0: public: sl@0: static TRunProc2* NewL(); sl@0: void RunTestL(TInt aThirdProcess, TInt aTimeout); sl@0: ~TRunProc2(); sl@0: private: sl@0: TRunProc2(){}; sl@0: void ConstructL(); sl@0: void DrawText(); sl@0: void CreateFont(); sl@0: sl@0: private: sl@0: RFbsSession* iFbs; sl@0: CFbsBitGc* iGc; sl@0: CFbsScreenDevice* iDev; sl@0: }; sl@0: sl@0: TRunProc2::~TRunProc2() sl@0: { sl@0: delete iGc; sl@0: delete iDev; sl@0: iFbs->Disconnect(); sl@0: } sl@0: sl@0: void TRunProc2::ConstructL() sl@0: { sl@0: TInt err = RFbsSession::Connect(); sl@0: User::LeaveIfError(err); sl@0: iFbs = RFbsSession::GetSession(); sl@0: User::LeaveIfNull(iFbs); sl@0: sl@0: TDisplayMode mode[13]; sl@0: mode[0]=EGray2; sl@0: mode[1]=EGray4; sl@0: mode[2]=EGray16; sl@0: mode[3]=EGray256; sl@0: mode[4]=EColor16; sl@0: mode[5]=EColor256; sl@0: mode[6]=EColor64K; sl@0: mode[7]=EColor16M; sl@0: mode[8]=ERgb; sl@0: mode[9]=EColor4K; sl@0: mode[10]=EColor16MU; sl@0: mode[11]=EColor16MA; sl@0: mode[12]=EColor16MAP; sl@0: sl@0: sl@0: TInt count; sl@0: for (count=0;count<13;count++) sl@0: { sl@0: TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count])); sl@0: if (err!=KErrNotSupported) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: User::LeaveIfNull(iDev); sl@0: sl@0: if(err == KErrNone) sl@0: { sl@0: iDev->ChangeScreenDevice(NULL); sl@0: iDev->SetAutoUpdate(ETrue); sl@0: iDev->CreateContext(iGc); sl@0: } sl@0: User::LeaveIfNull(iGc); sl@0: } sl@0: sl@0: TRunProc2* TRunProc2::NewL() sl@0: { sl@0: TRunProc2 *ptr = new (ELeave) TRunProc2; sl@0: CleanupStack::PushL(ptr); sl@0: ptr->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return ptr; sl@0: } sl@0: sl@0: void TRunProc2::CreateFont() sl@0: { sl@0: //make sure that the font is large enough to ensure that the session sl@0: //cache is used. sl@0: TInt height=220; sl@0: sl@0: TOpenFontSpec openFontSpec; sl@0: openFontSpec.SetName(KOpenFont); sl@0: openFontSpec.SetHeight(height); sl@0: openFontSpec.SetItalic(EFalse); sl@0: openFontSpec.SetBold(EFalse); sl@0: sl@0: TTypeface Typeface; sl@0: Typeface.iName = KOpenFont; sl@0: TFontSpec fs; sl@0: fs.iTypeface = Typeface; sl@0: sl@0: fs.iHeight = height; sl@0: CFbsFont* font = NULL; sl@0: TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs); sl@0: sl@0: User::LeaveIfNull(font); sl@0: sl@0: // Use the font sl@0: iGc->UseFont(font); sl@0: iGc->Clear(); sl@0: } sl@0: sl@0: void TRunProc2::RunTestL(TInt aThirdProcess, TInt aTimeout) sl@0: { sl@0: if (aThirdProcess) sl@0: { sl@0: RTimer timer; sl@0: sl@0: timer.CreateLocal(); sl@0: TRequestStatus timerStatus=KRequestPending; sl@0: TTimeIntervalMicroSeconds32 timeout(aTimeout); sl@0: timer.After(timerStatus, timeout); sl@0: sl@0: CreateFont(); sl@0: do sl@0: { sl@0: DrawText(); sl@0: } sl@0: while (timerStatus==KRequestPending); sl@0: timer.Cancel(); sl@0: iGc->DiscardFont(); sl@0: RProcess::Rendezvous(10); sl@0: } sl@0: else sl@0: { sl@0: CreateFont(); sl@0: DrawText(); sl@0: iGc->DiscardFont(); sl@0: RProcess::Rendezvous(1); sl@0: } sl@0: } sl@0: sl@0: void TRunProc2::DrawText() sl@0: { sl@0: TText ch[2]; sl@0: ch[1]='\0'; sl@0: for (ch[0]='A';ch[0]<='Z';ch[0]++) sl@0: { sl@0: TBufC<2> buf(ch); sl@0: iGc->DrawText(buf,TPoint(10,100)); sl@0: } sl@0: for (ch[0]='a';ch[0]<='z';ch[0]++) sl@0: { sl@0: TBufC<2> buf(ch); sl@0: iGc->DrawText(buf,TPoint(10,100)); sl@0: } sl@0: } sl@0: sl@0: void MainL() sl@0: { sl@0: TRunProc2* test= TRunProc2::NewL(); sl@0: CleanupStack::PushL(test); sl@0: TInt param; sl@0: TInt timeoutParam; sl@0: User::LeaveIfError(User::GetTIntParameter(1,param)); sl@0: User::LeaveIfError(User::GetTIntParameter(2,timeoutParam)); sl@0: test->RunTestL(param,timeoutParam); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: // Cleanup stack harness sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanupStack = CTrapCleanup::New(); sl@0: TRAPD(error, MainL()); sl@0: _LIT(KTCacheDeletionProcess,"TCacheDeletionProcess"); sl@0: __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error)); sl@0: delete cleanupStack; sl@0: __UHEAP_MARKEND; sl@0: return 0; sl@0: }