|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include "FNTSTORE.H" |
|
25 #include "OPENFONT.H" |
|
26 #include "FNTBODY.H" |
|
27 #include "FNTSTD.H" |
|
28 #include "t_fontsessioncache.h" |
|
29 #include <hal.h> |
|
30 #include <s32file.h> |
|
31 #include <graphics/shapeimpl.h> |
|
32 |
|
33 _LIT(KWorkerProcess,"tfontsessioncacheproc"); |
|
34 |
|
35 const TInt KNumOfProc = 4; |
|
36 const TInt KRunningTime = 1000 * 1000 * 5; |
|
37 |
|
38 class CTFontSessionCache : public CTGraphicsBase |
|
39 { |
|
40 public: |
|
41 CTFontSessionCache(CTestStep* aStep); |
|
42 ~CTFontSessionCache(); |
|
43 |
|
44 static void TimerCleanup(TAny *); |
|
45 protected: |
|
46 // From CTGraphicsStep |
|
47 virtual void RunTestCaseL(TInt aCurTestCase); |
|
48 private: |
|
49 void TestOpenFontForQtL(); |
|
50 void RunMultiWorkerProcessL(); |
|
51 }; |
|
52 |
|
53 // This class is a data mirror to CBitmapFont in order to check its private |
|
54 // member iOpenFont. It is only used by TestOpenFontForQtL(). |
|
55 class CBitmapFontDummy:public CFont |
|
56 { |
|
57 public: |
|
58 TFontSpec iFontSpecInTwips; |
|
59 TAlgStyle iAlgStyle; |
|
60 RHeap* iHeap; |
|
61 TInt iFontBitmapOffset; |
|
62 COpenFont* iOpenFont; |
|
63 TUint32 iReserved; |
|
64 TUint32 iUniqueFontId; |
|
65 }; |
|
66 |
|
67 class CFbsFontUtil:public CFbsFont |
|
68 { |
|
69 public: |
|
70 static CBitmapFontDummy *getBitmapFont(CFbsFont *aFbsfont) |
|
71 { |
|
72 return reinterpret_cast<CBitmapFontDummy*>(static_cast<CFbsFontUtil*>(aFbsfont)->Address()); |
|
73 } |
|
74 }; |
|
75 |
|
76 |
|
77 CTFontSessionCache::CTFontSessionCache(CTestStep* aStep) |
|
78 : CTGraphicsBase(aStep) |
|
79 { |
|
80 |
|
81 } |
|
82 |
|
83 CTFontSessionCache::~CTFontSessionCache() |
|
84 { |
|
85 // no action needed |
|
86 } |
|
87 |
|
88 void CTFontSessionCache::TimerCleanup(TAny *aTimer) |
|
89 { |
|
90 ((RTimer*)aTimer)->Cancel(); |
|
91 } |
|
92 |
|
93 /** |
|
94 Qt needs the last bit of iOpenFont to be set 1 as a workaround to maintain |
|
95 its compatibility across difference Symbian OS versions. |
|
96 */ |
|
97 void CTFontSessionCache::TestOpenFontForQtL() |
|
98 { |
|
99 _LIT(KTypefaceName, "DejaVu Sans Condensed"); |
|
100 TFontSpec spec(KTypefaceName, 15); |
|
101 CFbsTypefaceStore *tfs = CFbsTypefaceStore::NewL(NULL); |
|
102 |
|
103 CFont* font = NULL; |
|
104 TInt ret = tfs->GetNearestFontToDesignHeightInPixels(font,spec); |
|
105 TEST(ret == KErrNone); |
|
106 |
|
107 CFbsFont *fbs_font = static_cast<CFbsFont*>(font); |
|
108 TEST(reinterpret_cast<TInt>((CFbsFontUtil::getBitmapFont(fbs_font))->iOpenFont) & 1); |
|
109 |
|
110 tfs->ReleaseFont(font); |
|
111 delete tfs; |
|
112 } |
|
113 |
|
114 /* |
|
115 * Launch 4 worker processes running with random latency at beginning. |
|
116 * Each one lasts about 1 sec. Within duration of 5 sec, if one terminates, |
|
117 * re-launch it. |
|
118 * |
|
119 */ |
|
120 void CTFontSessionCache::RunMultiWorkerProcessL() |
|
121 { |
|
122 RProcess ProcArray[KNumOfProc]; |
|
123 TRequestStatus *completeStatus[KNumOfProc]; |
|
124 |
|
125 for (TInt i = 0; i < KNumOfProc; i++) |
|
126 { |
|
127 RDebug::Print(_L(">>> Launching %d..."),i); |
|
128 TInt err; |
|
129 err = ProcArray[i].Create(KWorkerProcess, KNullDesC); |
|
130 User::LeaveIfError(err); |
|
131 |
|
132 completeStatus[i] = new(ELeave) TRequestStatus; |
|
133 CleanupStack::PushL(completeStatus[i]); |
|
134 *completeStatus[i] = KRequestPending; |
|
135 |
|
136 ProcArray[i].Logon(*completeStatus[i]); |
|
137 ProcArray[i].Resume(); //start the process |
|
138 } |
|
139 |
|
140 RTimer timer; |
|
141 timer.CreateLocal(); |
|
142 TRequestStatus timerStatus = KRequestPending; |
|
143 TTimeIntervalMicroSeconds32 timeout(KRunningTime); |
|
144 timer.After(timerStatus, timeout); |
|
145 |
|
146 do |
|
147 { |
|
148 User::WaitForNRequest(completeStatus, KNumOfProc); |
|
149 TInt i = 0; |
|
150 for(;i < KNumOfProc;i++ ) |
|
151 { |
|
152 if (*completeStatus[i] != KRequestPending) |
|
153 { |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 TExitType exit = ProcArray[i].ExitType(); |
|
159 TEST(exit == EExitKill); |
|
160 TInt reason = ProcArray[i].ExitReason(); |
|
161 TEST (reason == 0); |
|
162 |
|
163 RDebug::Print(_L("<<< Close %d..."), i); |
|
164 ProcArray[i].Close(); |
|
165 |
|
166 RDebug::Print(_L(">>> Launching %d..."), i); |
|
167 TInt err; |
|
168 err = ProcArray[i].Create(KWorkerProcess, KNullDesC); |
|
169 User::LeaveIfError(err); |
|
170 |
|
171 //run process 1 |
|
172 *completeStatus[i] = KRequestPending; |
|
173 ProcArray[i].Logon(*completeStatus[i]); |
|
174 ProcArray[i].Resume(); //start the process |
|
175 } |
|
176 while (timerStatus == KRequestPending); |
|
177 |
|
178 for (TInt i = 0; i < KNumOfProc; i++) |
|
179 { |
|
180 if(*completeStatus[i] == KRequestPending) |
|
181 { |
|
182 User::WaitForRequest(*completeStatus[i]); |
|
183 } |
|
184 RDebug::Print(_L("<<< Tear down Close %d..."),i); |
|
185 ProcArray[i].Close(); //tear down |
|
186 } |
|
187 CleanupStack::PopAndDestroy(4); |
|
188 } |
|
189 |
|
190 void CTFontSessionCache::RunTestCaseL( TInt aCurTestCase ) |
|
191 { |
|
192 #if defined __WINS__ || defined __WINSCW__ |
|
193 aCurTestCase = aCurTestCase; //to avoid unused warning |
|
194 // TestComplete(); //only run test on hardware, always passes on winscw |
|
195 // return; |
|
196 #endif |
|
197 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
198 |
|
199 switch (aCurTestCase) |
|
200 { |
|
201 case 1: |
|
202 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-UT--4003")); |
|
203 INFO_PRINTF1(_L("Test CBitmapFont::iOpenFont last bit for Qt\n")); |
|
204 TestOpenFontForQtL(); |
|
205 break; |
|
206 |
|
207 case 2: |
|
208 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(_L("TI18N-FNTSTORE-CIT-4002")); |
|
209 INFO_PRINTF1(_L("Test GetCharacterData() in muti-process client\n")); |
|
210 RunMultiWorkerProcessL(); |
|
211 break; |
|
212 |
|
213 case 3: |
|
214 ((CTFontSessionCacheStep*) iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
215 ((CTFontSessionCacheStep*) iStep)->CloseTMSGraphicsStep(); |
|
216 TestComplete(); |
|
217 break; |
|
218 } |
|
219 ((CTFontSessionCacheStep*)iStep)->RecordTestResultL(); |
|
220 } |
|
221 |
|
222 // -------------- |
|
223 __CONSTRUCT_STEP__(FontSessionCache) |