Update contrib.
2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 @internalComponent Internal Symbian test code
25 #include "t_fontsessioncache.h"
26 #include "T_IsolatedFontStore.h"
28 _LIT(KWorkerProcess,"tfontsessioncacheproc");
29 _LIT(KSharedChunk,"TestSharedChunk_T_FontSessionCache");
31 const TInt KNumOfProc = 4;
32 const TInt KRunningTime = 1000 * 1000 * 5;
34 //Make sure font is large enough that font and session caches are used sufficiently.
35 const TInt KFontHeight = 250;
37 // This class is a data mirror to CBitmapFont in order to check its private
38 // member iOpenFont. It is only used by TestOpenFontForQtL().
39 class CBitmapFontDummy:public CFont
42 TFontSpec iFontSpecInTwips;
45 TInt iFontBitmapOffset;
48 TUint32 iUniqueFontId;
51 class CTFontSessionCache : public CTGraphicsBase
54 CTFontSessionCache(CTestStep* aStep);
55 ~CTFontSessionCache();
59 // From CTGraphicsStep
60 virtual void RunTestCaseL(TInt aCurTestCase);
61 virtual void ConstructL();
63 void TestOpenFontForQtL();
64 void RunMultiWorkerProcessL();
69 CTIsolatedFontStore *iIFontStore;
75 CTFontSessionCache::CTFontSessionCache(CTestStep* aStep)
76 : CTGraphicsBase(aStep)
81 CTFontSessionCache::~CTFontSessionCache()
83 iIFontStore->iFs->ReleaseFont(iFont);
88 inline TInt CTFontSessionCache::Base()
90 return reinterpret_cast<TInt>(iChunk.Base());
93 void CTFontSessionCache::ConstructL()
95 User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,0x10000,0x10000));
96 iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0);
97 if(iSharedHeap == NULL)
99 RDebug::Print(_L("iSharedHeap = NULL"));
100 User::Leave(KErrNoMemory);
102 iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap);
103 iIFontStore->LoadRasterizersL();
104 iIFontStore->iFs->LoadFontsAtStartupL();
106 _LIT(KTypefaceName, "DejaVu Sans Condensed");
107 TFontSpec spec(KTypefaceName, KFontHeight);
109 TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec);
110 TEST(ret == KErrNone);
114 void CTFontSessionCache::FlushCaches()
117 TOpenFontGlyphData *glyphData = NULL;
118 for (TInt sHandle = 0; sHandle < KNumOfProc; sHandle++)
120 for (ch = 'A'; ch <= 'z'; ch++)
122 static_cast<CBitmapFont*> (iFont)->Rasterize(sHandle, ch, glyphData);
129 TI18N-FNTSTORE-UT--4003
132 Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain
133 its compatibility across difference Symbian OS versions.
136 1. Get a CBitmapFont in the constructor
137 2. Check the LSB of its iOpenFont by using CBitmapFontDummy
139 @SYMTestExpectedResults
143 void CTFontSessionCache::TestOpenFontForQtL()
145 TEST(reinterpret_cast<TInt>(reinterpret_cast<CBitmapFontDummy*>(iFont)->iOpenFont) & 1);
150 TI18N-FNTSTORE-CIT-4002
153 This case is to test the safty of actions over the shared heap.
156 1. Shared heap is initialised in the constructor
157 2. Run rasterizing function to Flush the font caches(glyph tree and session cache).
158 3. Launch KNumOfProc worker processes running with random latency at beginning, which
159 is to seach the cache from different processes. The globle chunk and font handles are
160 passed via process environment variables.
161 4. Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, re-launch it.
163 @SYMTestExpectedResults
164 Test should pass without any Panic.
166 void CTFontSessionCache::RunMultiWorkerProcessL()
168 RProcess ProcArray[KNumOfProc];
169 TRequestStatus *completeStatus[KNumOfProc];
173 for (TInt i = 0; i < KNumOfProc; i++)
175 RDebug::Print(_L(">>> Launching %d..."),i);
177 err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
178 User::LeaveIfError(err);
180 TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
181 ProcArray[i].SetParameter(1,iChunk);
182 ProcArray[i].SetParameter(2,FontOffset);
183 ProcArray[i].SetParameter(3,i);
185 completeStatus[i] = new(ELeave) TRequestStatus;
186 CleanupStack::PushL(completeStatus[i]);
187 *completeStatus[i] = KRequestPending;
189 ProcArray[i].Logon(*completeStatus[i]);
190 ProcArray[i].Resume(); //start the process
195 TRequestStatus timerStatus = KRequestPending;
196 TTimeIntervalMicroSeconds32 timeout(KRunningTime);
197 timer.After(timerStatus, timeout);
201 User::WaitForNRequest(completeStatus, KNumOfProc);
203 for(;i < KNumOfProc;i++ )
205 if (*completeStatus[i] != KRequestPending)
211 TExitType exit = ProcArray[i].ExitType();
212 TEST(exit == EExitKill);
213 TInt reason = ProcArray[i].ExitReason();
216 RDebug::Print(_L("<<< Close %d..."), i);
217 ProcArray[i].Close();
219 RDebug::Print(_L(">>> Launching %d..."), i);
221 err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
222 User::LeaveIfError(err);
224 TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
225 ProcArray[i].SetParameter(1,iChunk);
226 ProcArray[i].SetParameter(2,FontOffset);
227 ProcArray[i].SetParameter(3,i);
230 *completeStatus[i] = KRequestPending;
231 ProcArray[i].Logon(*completeStatus[i]);
232 ProcArray[i].Resume(); //start the process
234 while (timerStatus == KRequestPending);
236 for (TInt i = 0; i < KNumOfProc; i++)
238 if(*completeStatus[i] == KRequestPending)
240 User::WaitForRequest(*completeStatus[i]);
242 RDebug::Print(_L("<<< Tear down Close %d..."),i);
243 ProcArray[i].Close(); //tear down
245 CleanupStack::PopAndDestroy(KNumOfProc);
248 void CTFontSessionCache::RunTestCaseL( TInt aCurTestCase )
250 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
252 switch (aCurTestCase)
255 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-UT--4003"));
256 INFO_PRINTF1(_L("Test CBitmapFont::iOpenFont last bit for Qt\n"));
257 TestOpenFontForQtL();
261 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-CIT-4002"));
262 INFO_PRINTF1(_L("Test GetCharacterData() in muti-process client\n"));
263 RunMultiWorkerProcessL();
267 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
268 ((CTFontSessionCacheStep*) iStep)->CloseTMSGraphicsStep();
272 ((CTFontSessionCacheStep*)iStep)->RecordTestResultL();
276 __CONSTRUCT_STEP__(FontSessionCache)