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