sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
@test
|
sl@0
|
21 |
@internalComponent Internal Symbian test code
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "FNTSTORE.H"
|
sl@0
|
25 |
#include "t_fontsessioncache.h"
|
sl@0
|
26 |
#include "T_IsolatedFontStore.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT(KWorkerProcess,"tfontsessioncacheproc");
|
sl@0
|
29 |
_LIT(KSharedChunk,"TestSharedChunk_T_FontSessionCache");
|
sl@0
|
30 |
|
sl@0
|
31 |
const TInt KNumOfProc = 4;
|
sl@0
|
32 |
const TInt KRunningTime = 1000 * 1000 * 5;
|
sl@0
|
33 |
|
sl@0
|
34 |
//Make sure font is large enough that font and session caches are used sufficiently.
|
sl@0
|
35 |
const TInt KFontHeight = 250;
|
sl@0
|
36 |
|
sl@0
|
37 |
// This class is a data mirror to CBitmapFont in order to check its private
|
sl@0
|
38 |
// member iOpenFont. It is only used by TestOpenFontForQtL().
|
sl@0
|
39 |
class CBitmapFontDummy:public CFont
|
sl@0
|
40 |
{
|
sl@0
|
41 |
public:
|
sl@0
|
42 |
TFontSpec iFontSpecInTwips;
|
sl@0
|
43 |
TAlgStyle iAlgStyle;
|
sl@0
|
44 |
RHeap* iHeap;
|
sl@0
|
45 |
TInt iFontBitmapOffset;
|
sl@0
|
46 |
COpenFont* iOpenFont;
|
sl@0
|
47 |
TUint32 iReserved;
|
sl@0
|
48 |
TUint32 iUniqueFontId;
|
sl@0
|
49 |
};
|
sl@0
|
50 |
|
sl@0
|
51 |
class CTFontSessionCache : public CTGraphicsBase
|
sl@0
|
52 |
{
|
sl@0
|
53 |
public:
|
sl@0
|
54 |
CTFontSessionCache(CTestStep* aStep);
|
sl@0
|
55 |
~CTFontSessionCache();
|
sl@0
|
56 |
TInt Base();
|
sl@0
|
57 |
|
sl@0
|
58 |
protected:
|
sl@0
|
59 |
// From CTGraphicsStep
|
sl@0
|
60 |
virtual void RunTestCaseL(TInt aCurTestCase);
|
sl@0
|
61 |
virtual void ConstructL();
|
sl@0
|
62 |
private:
|
sl@0
|
63 |
void TestOpenFontForQtL();
|
sl@0
|
64 |
void RunMultiWorkerProcessL();
|
sl@0
|
65 |
|
sl@0
|
66 |
void FlushCaches();
|
sl@0
|
67 |
|
sl@0
|
68 |
private:
|
sl@0
|
69 |
CTIsolatedFontStore *iIFontStore;
|
sl@0
|
70 |
RHeap *iSharedHeap;
|
sl@0
|
71 |
RChunk iChunk;
|
sl@0
|
72 |
CFont *iFont;
|
sl@0
|
73 |
};
|
sl@0
|
74 |
|
sl@0
|
75 |
CTFontSessionCache::CTFontSessionCache(CTestStep* aStep)
|
sl@0
|
76 |
: CTGraphicsBase(aStep)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
CTFontSessionCache::~CTFontSessionCache()
|
sl@0
|
82 |
{
|
sl@0
|
83 |
iIFontStore->iFs->ReleaseFont(iFont);
|
sl@0
|
84 |
delete iIFontStore;
|
sl@0
|
85 |
iChunk.Close();
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
inline TInt CTFontSessionCache::Base()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
return reinterpret_cast<TInt>(iChunk.Base());
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
void CTFontSessionCache::ConstructL()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
User::LeaveIfError(iChunk.CreateGlobal(KNullDesC,0x10000,0x10000));
|
sl@0
|
96 |
iSharedHeap = UserHeap::ChunkHeap(iChunk,0x10000,0x1000,0x10000,0,EFalse,0);
|
sl@0
|
97 |
if(iSharedHeap == NULL)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
RDebug::Print(_L("iSharedHeap = NULL"));
|
sl@0
|
100 |
User::Leave(KErrNoMemory);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
iIFontStore = CTIsolatedFontStore::NewL(iSharedHeap);
|
sl@0
|
103 |
iIFontStore->LoadRasterizersL();
|
sl@0
|
104 |
iIFontStore->iFs->LoadFontsAtStartupL();
|
sl@0
|
105 |
|
sl@0
|
106 |
_LIT(KTypefaceName, "DejaVu Sans Condensed");
|
sl@0
|
107 |
TFontSpec spec(KTypefaceName, KFontHeight);
|
sl@0
|
108 |
|
sl@0
|
109 |
TInt ret = iIFontStore->iFs->GetNearestFontToDesignHeightInPixels(iFont,spec);
|
sl@0
|
110 |
TEST(ret == KErrNone);
|
sl@0
|
111 |
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
void CTFontSessionCache::FlushCaches()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TText ch;
|
sl@0
|
117 |
TOpenFontGlyphData *glyphData = NULL;
|
sl@0
|
118 |
for (TInt sHandle = 0; sHandle < KNumOfProc; sHandle++)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
for (ch = 'A'; ch <= 'z'; ch++)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
static_cast<CBitmapFont*> (iFont)->Rasterize(sHandle, ch, glyphData);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
}
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
/**
|
sl@0
|
128 |
@SYMTestCaseID
|
sl@0
|
129 |
TI18N-FNTSTORE-UT--4003
|
sl@0
|
130 |
|
sl@0
|
131 |
@SYMTestCaseDesc
|
sl@0
|
132 |
Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain
|
sl@0
|
133 |
its compatibility across difference Symbian OS versions.
|
sl@0
|
134 |
|
sl@0
|
135 |
@SYMTestActions
|
sl@0
|
136 |
1. Get a CBitmapFont in the constructor
|
sl@0
|
137 |
2. Check the LSB of its iOpenFont by using CBitmapFontDummy
|
sl@0
|
138 |
|
sl@0
|
139 |
@SYMTestExpectedResults
|
sl@0
|
140 |
Test should pass
|
sl@0
|
141 |
*/
|
sl@0
|
142 |
|
sl@0
|
143 |
void CTFontSessionCache::TestOpenFontForQtL()
|
sl@0
|
144 |
{
|
sl@0
|
145 |
TEST(reinterpret_cast<TInt>(reinterpret_cast<CBitmapFontDummy*>(iFont)->iOpenFont) & 1);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
/**
|
sl@0
|
149 |
@SYMTestCaseID
|
sl@0
|
150 |
TI18N-FNTSTORE-CIT-4002
|
sl@0
|
151 |
|
sl@0
|
152 |
@SYMTestCaseDesc
|
sl@0
|
153 |
This case is to test the safty of actions over the shared heap.
|
sl@0
|
154 |
|
sl@0
|
155 |
@SYMTestActions
|
sl@0
|
156 |
1. Shared heap is initialised in the constructor
|
sl@0
|
157 |
2. Run rasterizing function to Flush the font caches(glyph tree and session cache).
|
sl@0
|
158 |
3. Launch KNumOfProc worker processes running with random latency at beginning, which
|
sl@0
|
159 |
is to seach the cache from different processes. The globle chunk and font handles are
|
sl@0
|
160 |
passed via process environment variables.
|
sl@0
|
161 |
4. Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, re-launch it.
|
sl@0
|
162 |
|
sl@0
|
163 |
@SYMTestExpectedResults
|
sl@0
|
164 |
Test should pass without any Panic.
|
sl@0
|
165 |
*/
|
sl@0
|
166 |
void CTFontSessionCache::RunMultiWorkerProcessL()
|
sl@0
|
167 |
{
|
sl@0
|
168 |
RProcess ProcArray[KNumOfProc];
|
sl@0
|
169 |
TRequestStatus *completeStatus[KNumOfProc];
|
sl@0
|
170 |
|
sl@0
|
171 |
FlushCaches();
|
sl@0
|
172 |
|
sl@0
|
173 |
for (TInt i = 0; i < KNumOfProc; i++)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
RDebug::Print(_L(">>> Launching %d..."),i);
|
sl@0
|
176 |
TInt err;
|
sl@0
|
177 |
err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
|
sl@0
|
178 |
User::LeaveIfError(err);
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
|
sl@0
|
181 |
ProcArray[i].SetParameter(1,iChunk);
|
sl@0
|
182 |
ProcArray[i].SetParameter(2,FontOffset);
|
sl@0
|
183 |
ProcArray[i].SetParameter(3,i);
|
sl@0
|
184 |
|
sl@0
|
185 |
completeStatus[i] = new(ELeave) TRequestStatus;
|
sl@0
|
186 |
CleanupStack::PushL(completeStatus[i]);
|
sl@0
|
187 |
*completeStatus[i] = KRequestPending;
|
sl@0
|
188 |
|
sl@0
|
189 |
ProcArray[i].Logon(*completeStatus[i]);
|
sl@0
|
190 |
ProcArray[i].Resume(); //start the process
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
RTimer timer;
|
sl@0
|
194 |
timer.CreateLocal();
|
sl@0
|
195 |
TRequestStatus timerStatus = KRequestPending;
|
sl@0
|
196 |
TTimeIntervalMicroSeconds32 timeout(KRunningTime);
|
sl@0
|
197 |
timer.After(timerStatus, timeout);
|
sl@0
|
198 |
|
sl@0
|
199 |
do
|
sl@0
|
200 |
{
|
sl@0
|
201 |
User::WaitForNRequest(completeStatus, KNumOfProc);
|
sl@0
|
202 |
TInt i = 0;
|
sl@0
|
203 |
for(;i < KNumOfProc;i++ )
|
sl@0
|
204 |
{
|
sl@0
|
205 |
if (*completeStatus[i] != KRequestPending)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
break;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
}
|
sl@0
|
210 |
|
sl@0
|
211 |
TExitType exit = ProcArray[i].ExitType();
|
sl@0
|
212 |
TEST(exit == EExitKill);
|
sl@0
|
213 |
TInt reason = ProcArray[i].ExitReason();
|
sl@0
|
214 |
TEST (reason == 0);
|
sl@0
|
215 |
|
sl@0
|
216 |
RDebug::Print(_L("<<< Close %d..."), i);
|
sl@0
|
217 |
ProcArray[i].Close();
|
sl@0
|
218 |
|
sl@0
|
219 |
RDebug::Print(_L(">>> Launching %d..."), i);
|
sl@0
|
220 |
TInt err;
|
sl@0
|
221 |
err = ProcArray[i].Create(KWorkerProcess, KNullDesC);
|
sl@0
|
222 |
User::LeaveIfError(err);
|
sl@0
|
223 |
|
sl@0
|
224 |
TInt FontOffset = reinterpret_cast<TInt>(iFont) - Base();
|
sl@0
|
225 |
ProcArray[i].SetParameter(1,iChunk);
|
sl@0
|
226 |
ProcArray[i].SetParameter(2,FontOffset);
|
sl@0
|
227 |
ProcArray[i].SetParameter(3,i);
|
sl@0
|
228 |
|
sl@0
|
229 |
//run process 1
|
sl@0
|
230 |
*completeStatus[i] = KRequestPending;
|
sl@0
|
231 |
ProcArray[i].Logon(*completeStatus[i]);
|
sl@0
|
232 |
ProcArray[i].Resume(); //start the process
|
sl@0
|
233 |
}
|
sl@0
|
234 |
while (timerStatus == KRequestPending);
|
sl@0
|
235 |
|
sl@0
|
236 |
for (TInt i = 0; i < KNumOfProc; i++)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
if(*completeStatus[i] == KRequestPending)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
User::WaitForRequest(*completeStatus[i]);
|
sl@0
|
241 |
}
|
sl@0
|
242 |
RDebug::Print(_L("<<< Tear down Close %d..."),i);
|
sl@0
|
243 |
ProcArray[i].Close(); //tear down
|
sl@0
|
244 |
}
|
sl@0
|
245 |
CleanupStack::PopAndDestroy(KNumOfProc);
|
sl@0
|
246 |
}
|
sl@0
|
247 |
|
sl@0
|
248 |
void CTFontSessionCache::RunTestCaseL( TInt aCurTestCase )
|
sl@0
|
249 |
{
|
sl@0
|
250 |
((CTFontSessionCacheStep*) iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
|
sl@0
|
251 |
|
sl@0
|
252 |
switch (aCurTestCase)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
case 1:
|
sl@0
|
255 |
((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-UT--4003"));
|
sl@0
|
256 |
INFO_PRINTF1(_L("Test CBitmapFont::iOpenFont last bit for Qt\n"));
|
sl@0
|
257 |
TestOpenFontForQtL();
|
sl@0
|
258 |
break;
|
sl@0
|
259 |
|
sl@0
|
260 |
case 2:
|
sl@0
|
261 |
((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-CIT-4002"));
|
sl@0
|
262 |
INFO_PRINTF1(_L("Test GetCharacterData() in muti-process client\n"));
|
sl@0
|
263 |
RunMultiWorkerProcessL();
|
sl@0
|
264 |
break;
|
sl@0
|
265 |
|
sl@0
|
266 |
case 3:
|
sl@0
|
267 |
((CTFontSessionCacheStep*) iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
|
sl@0
|
268 |
((CTFontSessionCacheStep*) iStep)->CloseTMSGraphicsStep();
|
sl@0
|
269 |
TestComplete();
|
sl@0
|
270 |
break;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
((CTFontSessionCacheStep*)iStep)->RecordTestResultL();
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
// --------------
|
sl@0
|
276 |
__CONSTRUCT_STEP__(FontSessionCache)
|