1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/t_cachedeletionprocess.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,233 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Cache Deletion for fntstore multi-processed test code
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @test
1.26 + @internalComponent - Internal Symbian test code
1.27 +*/
1.28 +
1.29 +#include <e32base.h>
1.30 +#include <e32cons.h>
1.31 +#include <e32test.h>
1.32 +#include <e32std.h>
1.33 +#include <e32debug.h>
1.34 +#include "FNTSTORE.H"
1.35 +#include "FNTBODY.H"
1.36 +#include "FNTSTD.H"
1.37 +#include <fbs.h>
1.38 +#include <bitstd.h>
1.39 +#include <bitdev.h>
1.40 +
1.41 +_LIT(KOpenFont, "DejaVu Sans Condensed");
1.42 +
1.43 +#ifdef __WINSCW__
1.44 +//this is used for winscw breakpoints
1.45 +#define BR _asm( int 3);
1.46 +#endif
1.47 +
1.48 +
1.49 +/* it is expected that the main in this file will be called to test multiple
1.50 +process output at the same time a process is being deleted (font and bitmap server
1.51 +disconnection. There are normally two instances of this process. Two virtually
1.52 +identical processes are required to ensure that the session ID is the same.
1.53 +
1.54 +The first is with aThirdProcess set. This sets output to run in a loop until
1.55 +the timeout is completed. These values are input via program arguments.
1.56 +
1.57 +If aThirdProcess is false then only one font creation, draw text,
1.58 +font deletion cycle is completed. The test code will then repeatedly run
1.59 +this process with aThirdProcess set to false.
1.60 +*/
1.61 +class TRunProc2: public CBase
1.62 + {
1.63 +public:
1.64 + static TRunProc2* NewL();
1.65 + void RunTestL(TInt aThirdProcess, TInt aTimeout);
1.66 + ~TRunProc2();
1.67 +private:
1.68 + TRunProc2(){};
1.69 + void ConstructL();
1.70 + void DrawText();
1.71 + void CreateFont();
1.72 +
1.73 +private:
1.74 + RFbsSession* iFbs;
1.75 + CFbsBitGc* iGc;
1.76 + CFbsScreenDevice* iDev;
1.77 + };
1.78 +
1.79 +TRunProc2::~TRunProc2()
1.80 + {
1.81 + delete iGc;
1.82 + delete iDev;
1.83 + iFbs->Disconnect();
1.84 + }
1.85 +
1.86 +void TRunProc2::ConstructL()
1.87 + {
1.88 + TInt err = RFbsSession::Connect();
1.89 + User::LeaveIfError(err);
1.90 + iFbs = RFbsSession::GetSession();
1.91 + User::LeaveIfNull(iFbs);
1.92 +
1.93 + TDisplayMode mode[13];
1.94 + mode[0]=EGray2;
1.95 + mode[1]=EGray4;
1.96 + mode[2]=EGray16;
1.97 + mode[3]=EGray256;
1.98 + mode[4]=EColor16;
1.99 + mode[5]=EColor256;
1.100 + mode[6]=EColor64K;
1.101 + mode[7]=EColor16M;
1.102 + mode[8]=ERgb;
1.103 + mode[9]=EColor4K;
1.104 + mode[10]=EColor16MU;
1.105 + mode[11]=EColor16MA;
1.106 + mode[12]=EColor16MAP;
1.107 +
1.108 +
1.109 + TInt count;
1.110 + for (count=0;count<13;count++)
1.111 + {
1.112 + TRAP(err, iDev = CFbsScreenDevice::NewL(KNullDesC, mode[count]));
1.113 + if (err!=KErrNotSupported)
1.114 + {
1.115 + break;
1.116 + }
1.117 + }
1.118 +
1.119 + User::LeaveIfNull(iDev);
1.120 +
1.121 + if(err == KErrNone)
1.122 + {
1.123 + iDev->ChangeScreenDevice(NULL);
1.124 + iDev->SetAutoUpdate(ETrue);
1.125 + iDev->CreateContext(iGc);
1.126 + }
1.127 + User::LeaveIfNull(iGc);
1.128 + }
1.129 +
1.130 +TRunProc2* TRunProc2::NewL()
1.131 + {
1.132 + TRunProc2 *ptr = new (ELeave) TRunProc2;
1.133 + CleanupStack::PushL(ptr);
1.134 + ptr->ConstructL();
1.135 + CleanupStack::Pop();
1.136 + return ptr;
1.137 + }
1.138 +
1.139 +void TRunProc2::CreateFont()
1.140 + {
1.141 + //make sure that the font is large enough to ensure that the session
1.142 + //cache is used.
1.143 + TInt height=220;
1.144 +
1.145 + TOpenFontSpec openFontSpec;
1.146 + openFontSpec.SetName(KOpenFont);
1.147 + openFontSpec.SetHeight(height);
1.148 + openFontSpec.SetItalic(EFalse);
1.149 + openFontSpec.SetBold(EFalse);
1.150 +
1.151 + TTypeface Typeface;
1.152 + Typeface.iName = KOpenFont;
1.153 + TFontSpec fs;
1.154 + fs.iTypeface = Typeface;
1.155 +
1.156 + fs.iHeight = height;
1.157 + CFbsFont* font = NULL;
1.158 + TInt err = iDev->GetNearestFontToDesignHeightInPixels(font, fs);
1.159 +
1.160 + User::LeaveIfNull(font);
1.161 +
1.162 + // Use the font
1.163 + iGc->UseFont(font);
1.164 + iGc->Clear();
1.165 + }
1.166 +
1.167 +void TRunProc2::RunTestL(TInt aThirdProcess, TInt aTimeout)
1.168 + {
1.169 + if (aThirdProcess)
1.170 + {
1.171 + RTimer timer;
1.172 +
1.173 + timer.CreateLocal();
1.174 + TRequestStatus timerStatus=KRequestPending;
1.175 + TTimeIntervalMicroSeconds32 timeout(aTimeout);
1.176 + timer.After(timerStatus, timeout);
1.177 +
1.178 + CreateFont();
1.179 + do
1.180 + {
1.181 + DrawText();
1.182 + }
1.183 + while (timerStatus==KRequestPending);
1.184 + timer.Cancel();
1.185 + iGc->DiscardFont();
1.186 + RProcess::Rendezvous(10);
1.187 + }
1.188 + else
1.189 + {
1.190 + CreateFont();
1.191 + DrawText();
1.192 + iGc->DiscardFont();
1.193 + RProcess::Rendezvous(1);
1.194 + }
1.195 + }
1.196 +
1.197 +void TRunProc2::DrawText()
1.198 + {
1.199 + TText ch[2];
1.200 + ch[1]='\0';
1.201 + for (ch[0]='A';ch[0]<='Z';ch[0]++)
1.202 + {
1.203 + TBufC<2> buf(ch);
1.204 + iGc->DrawText(buf,TPoint(10,100));
1.205 + }
1.206 + for (ch[0]='a';ch[0]<='z';ch[0]++)
1.207 + {
1.208 + TBufC<2> buf(ch);
1.209 + iGc->DrawText(buf,TPoint(10,100));
1.210 + }
1.211 + }
1.212 +
1.213 +void MainL()
1.214 + {
1.215 + TRunProc2* test= TRunProc2::NewL();
1.216 + CleanupStack::PushL(test);
1.217 + TInt param;
1.218 + TInt timeoutParam;
1.219 + User::LeaveIfError(User::GetTIntParameter(1,param));
1.220 + User::LeaveIfError(User::GetTIntParameter(2,timeoutParam));
1.221 + test->RunTestL(param,timeoutParam);
1.222 + CleanupStack::PopAndDestroy();
1.223 + }
1.224 +
1.225 +// Cleanup stack harness
1.226 +GLDEF_C TInt E32Main()
1.227 + {
1.228 + __UHEAP_MARK;
1.229 + CTrapCleanup* cleanupStack = CTrapCleanup::New();
1.230 + TRAPD(error, MainL());
1.231 + _LIT(KTCacheDeletionProcess,"TCacheDeletionProcess");
1.232 + __ASSERT_ALWAYS(!error, User::Panic(KTCacheDeletionProcess, error));
1.233 + delete cleanupStack;
1.234 + __UHEAP_MARKEND;
1.235 + return 0;
1.236 + }