1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/fontstore/tfs/T_fontsessioncache.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,276 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2010 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 +*
1.19 +*/
1.20 +
1.21 +/**
1.22 + @file
1.23 + @test
1.24 + @internalComponent Internal Symbian test code
1.25 +*/
1.26 +
1.27 +#include "FNTSTORE.H"
1.28 +#include "t_fontsessioncache.h"
1.29 +#include "T_IsolatedFontStore.h"
1.30 +
1.31 +_LIT(KWorkerProcess,"tfontsessioncacheproc");
1.32 +_LIT(KSharedChunk,"TestSharedChunk_T_FontSessionCache");
1.33 +
1.34 +const TInt KNumOfProc = 4;
1.35 +const TInt KRunningTime = 1000 * 1000 * 5;
1.36 +
1.37 +//Make sure font is large enough that font and session caches are used sufficiently.
1.38 +const TInt KFontHeight = 250;
1.39 +
1.40 +// This class is a data mirror to CBitmapFont in order to check its private
1.41 +// member iOpenFont. It is only used by TestOpenFontForQtL().
1.42 +class CBitmapFontDummy:public CFont
1.43 + {
1.44 +public:
1.45 + TFontSpec iFontSpecInTwips;
1.46 + TAlgStyle iAlgStyle;
1.47 + RHeap* iHeap;
1.48 + TInt iFontBitmapOffset;
1.49 + COpenFont* iOpenFont;
1.50 + TUint32 iReserved;
1.51 + TUint32 iUniqueFontId;
1.52 + };
1.53 +
1.54 +class CTFontSessionCache : public CTGraphicsBase
1.55 + {
1.56 +public:
1.57 + CTFontSessionCache(CTestStep* aStep);
1.58 + ~CTFontSessionCache();
1.59 + TInt Base();
1.60 +
1.61 +protected:
1.62 +// From CTGraphicsStep
1.63 + virtual void RunTestCaseL(TInt aCurTestCase);
1.64 + virtual void ConstructL();
1.65 +private:
1.66 + void TestOpenFontForQtL();
1.67 + void RunMultiWorkerProcessL();
1.68 +
1.69 + void FlushCaches();
1.70 +
1.71 +private:
1.72 + CTIsolatedFontStore *iIFontStore;
1.73 + RHeap *iSharedHeap;
1.74 + RChunk iChunk;
1.75 + CFont *iFont;
1.76 + };
1.77 +
1.78 +CTFontSessionCache::CTFontSessionCache(CTestStep* aStep)
1.79 + : CTGraphicsBase(aStep)
1.80 + {
1.81 +
1.82 + }
1.83 +
1.84 +CTFontSessionCache::~CTFontSessionCache()
1.85 + {
1.86 + iIFontStore->iFs->ReleaseFont(iFont);
1.87 + delete iIFontStore;
1.88 + iChunk.Close();
1.89 + }
1.90 +
1.91 +inline TInt CTFontSessionCache::Base()
1.92 + {
1.93 + return reinterpret_cast<TInt>(iChunk.Base());
1.94 + }
1.95 +
1.96 +void CTFontSessionCache::ConstructL()
1.97 + {
1.98 + User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,0x10000,0x10000));
1.99 + iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0);
1.100 + if(iSharedHeap == NULL)
1.101 + {
1.102 + RDebug::Print(_L("iSharedHeap = NULL"));
1.103 + User::Leave(KErrNoMemory);
1.104 + }
1.105 + iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap);
1.106 + iIFontStore->LoadRasterizersL();
1.107 + iIFontStore->iFs->LoadFontsAtStartupL();
1.108 +
1.109 + _LIT(KTypefaceName, "DejaVu Sans Condensed");
1.110 + TFontSpec spec(KTypefaceName, KFontHeight);
1.111 +
1.112 + TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec);
1.113 + TEST(ret == KErrNone);
1.114 +
1.115 + }
1.116 +
1.117 +void CTFontSessionCache::FlushCaches()
1.118 + {
1.119 + TText ch;
1.120 + TOpenFontGlyphData *glyphData = NULL;
1.121 + for (TInt sHandle = 0; sHandle < KNumOfProc; sHandle++)
1.122 + {
1.123 + for (ch = 'A'; ch <= 'z'; ch++)
1.124 + {
1.125 + static_cast<CBitmapFont*> (iFont)->Rasterize(sHandle, ch, glyphData);
1.126 + }
1.127 + }
1.128 + }
1.129 +
1.130 +/**
1.131 + @SYMTestCaseID
1.132 + TI18N-FNTSTORE-UT--4003
1.133 +
1.134 + @SYMTestCaseDesc
1.135 + Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain
1.136 + its compatibility across difference Symbian OS versions.
1.137 +
1.138 + @SYMTestActions
1.139 + 1. Get a CBitmapFont in the constructor
1.140 + 2. Check the LSB of its iOpenFont by using CBitmapFontDummy
1.141 +
1.142 + @SYMTestExpectedResults
1.143 + Test should pass
1.144 +*/
1.145 +
1.146 +void CTFontSessionCache::TestOpenFontForQtL()
1.147 + {
1.148 + TEST(reinterpret_cast<TInt>(reinterpret_cast<CBitmapFontDummy*>(iFont)->iOpenFont) & 1);
1.149 + }
1.150 +
1.151 +/**
1.152 + @SYMTestCaseID
1.153 + TI18N-FNTSTORE-CIT-4002
1.154 +
1.155 + @SYMTestCaseDesc
1.156 + This case is to test the safty of actions over the shared heap.
1.157 +
1.158 + @SYMTestActions
1.159 + 1. Shared heap is initialised in the constructor
1.160 + 2. Run rasterizing function to Flush the font caches(glyph tree and session cache).
1.161 + 3. Launch KNumOfProc worker processes running with random latency at beginning, which
1.162 + is to seach the cache from different processes. The globle chunk and font handles are
1.163 + passed via process environment variables.
1.164 + 4. Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, re-launch it.
1.165 +
1.166 + @SYMTestExpectedResults
1.167 + Test should pass without any Panic.
1.168 +*/
1.169 +void CTFontSessionCache::RunMultiWorkerProcessL()
1.170 + {
1.171 + RProcess ProcArray[KNumOfProc];
1.172 + TRequestStatus *completeStatus[KNumOfProc];
1.173 +
1.174 + FlushCaches();
1.175 +
1.176 + for (TInt i = 0; i < KNumOfProc; i++)
1.177 + {
1.178 + RDebug::Print(_L(">>> Launching %d..."),i);
1.179 + TInt err;
1.180 + err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
1.181 + User::LeaveIfError(err);
1.182 +
1.183 + TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
1.184 + ProcArray[i].SetParameter(1,iChunk);
1.185 + ProcArray[i].SetParameter(2,FontOffset);
1.186 + ProcArray[i].SetParameter(3,i);
1.187 +
1.188 + completeStatus[i] = new(ELeave) TRequestStatus;
1.189 + CleanupStack::PushL(completeStatus[i]);
1.190 + *completeStatus[i] = KRequestPending;
1.191 +
1.192 + ProcArray[i].Logon(*completeStatus[i]);
1.193 + ProcArray[i].Resume(); //start the process
1.194 + }
1.195 +
1.196 + RTimer timer;
1.197 + timer.CreateLocal();
1.198 + TRequestStatus timerStatus = KRequestPending;
1.199 + TTimeIntervalMicroSeconds32 timeout(KRunningTime);
1.200 + timer.After(timerStatus, timeout);
1.201 +
1.202 + do
1.203 + {
1.204 + User::WaitForNRequest(completeStatus, KNumOfProc);
1.205 + TInt i = 0;
1.206 + for(;i < KNumOfProc;i++ )
1.207 + {
1.208 + if (*completeStatus[i] != KRequestPending)
1.209 + {
1.210 + break;
1.211 + }
1.212 + }
1.213 +
1.214 + TExitType exit = ProcArray[i].ExitType();
1.215 + TEST(exit == EExitKill);
1.216 + TInt reason = ProcArray[i].ExitReason();
1.217 + TEST (reason == 0);
1.218 +
1.219 + RDebug::Print(_L("<<< Close %d..."), i);
1.220 + ProcArray[i].Close();
1.221 +
1.222 + RDebug::Print(_L(">>> Launching %d..."), i);
1.223 + TInt err;
1.224 + err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
1.225 + User::LeaveIfError(err);
1.226 +
1.227 + TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
1.228 + ProcArray[i].SetParameter(1,iChunk);
1.229 + ProcArray[i].SetParameter(2,FontOffset);
1.230 + ProcArray[i].SetParameter(3,i);
1.231 +
1.232 + //run process 1
1.233 + *completeStatus[i] = KRequestPending;
1.234 + ProcArray[i].Logon(*completeStatus[i]);
1.235 + ProcArray[i].Resume(); //start the process
1.236 + }
1.237 + while (timerStatus == KRequestPending);
1.238 +
1.239 + for (TInt i = 0; i < KNumOfProc; i++)
1.240 + {
1.241 + if(*completeStatus[i] == KRequestPending)
1.242 + {
1.243 + User::WaitForRequest(*completeStatus[i]);
1.244 + }
1.245 + RDebug::Print(_L("<<< Tear down Close %d..."),i);
1.246 + ProcArray[i].Close(); //tear down
1.247 + }
1.248 + CleanupStack::PopAndDestroy(KNumOfProc);
1.249 + }
1.250 +
1.251 +void CTFontSessionCache::RunTestCaseL( TInt aCurTestCase )
1.252 + {
1.253 + ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.254 +
1.255 + switch (aCurTestCase)
1.256 + {
1.257 + case 1:
1.258 + ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-UT--4003"));
1.259 + INFO_PRINTF1(_L("Test CBitmapFont::iOpenFont last bit for Qt\n"));
1.260 + TestOpenFontForQtL();
1.261 + break;
1.262 +
1.263 + case 2:
1.264 + ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-CIT-4002"));
1.265 + INFO_PRINTF1(_L("Test GetCharacterData() in muti-process client\n"));
1.266 + RunMultiWorkerProcessL();
1.267 + break;
1.268 +
1.269 + case 3:
1.270 + ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.271 + ((CTFontSessionCacheStep*) iStep)->CloseTMSGraphicsStep();
1.272 + TestComplete();
1.273 + break;
1.274 + }
1.275 + ((CTFontSessionCacheStep*)iStep)->RecordTestResultL();
1.276 + }
1.277 +
1.278 +// --------------
1.279 +__CONSTRUCT_STEP__(FontSessionCache)