|
1 /* |
|
2 * Copyright (c) 2005-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 @test |
|
20 @internalComponent |
|
21 |
|
22 This contains CT_DataFbsFont |
|
23 */ |
|
24 |
|
25 #include "T_DataFbsFont.h" |
|
26 |
|
27 /*@{*/ |
|
28 /// Parameters |
|
29 _LIT(KText, "text"); |
|
30 _LIT(KExpectedBool, "expected_bool"); |
|
31 _LIT(KCharCode, "char_code"); |
|
32 _LIT(KNullBitmapPointerExpected, "null_bitmap_pointer_expected"); |
|
33 |
|
34 /// Commands |
|
35 _LIT(KCmdGetFontMetrics, "GetFontMetrics"); |
|
36 _LIT(KCmdTextWidthInPixelsWithCharWidth, "TextWidthInPixelsWithCharWidth"); |
|
37 _LIT(KCmdHandle, "Handle"); |
|
38 _LIT(KCmdCharacterMetrics, "CharacterMetrics"); |
|
39 _LIT(KCmdRawTextWidthInPixels, "RawTextWidthInPixels"); |
|
40 _LIT(KCmdGetFaceAttrib, "GetFaceAttrib"); |
|
41 _LIT(KCmdIsOpenFont, "IsOpenFont"); |
|
42 _LIT(KCmdHasCharacter, "HasCharacter"); |
|
43 /*@}*/ |
|
44 |
|
45 /** |
|
46 * Constructor |
|
47 */ |
|
48 CT_DataFbsFont* CT_DataFbsFont::NewL() |
|
49 { |
|
50 CT_DataFbsFont* ret = new (ELeave) CT_DataFbsFont(); |
|
51 return ret; |
|
52 } |
|
53 |
|
54 /** |
|
55 * Protected constructor. First phase construction |
|
56 */ |
|
57 CT_DataFbsFont::CT_DataFbsFont() |
|
58 : CT_DataFont() |
|
59 , iFbsFont(NULL) |
|
60 { |
|
61 } |
|
62 |
|
63 /** |
|
64 * Process a command read from the ini file |
|
65 * |
|
66 * @param aDataWrapper test step requiring command to be processed |
|
67 * @param aCommand the command to process |
|
68 * @param aSection the entry in the ini file requiring the command to be processed |
|
69 * |
|
70 * @return ETrue if the command is processed |
|
71 */ |
|
72 TBool CT_DataFbsFont::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
73 { |
|
74 TBool ret=ETrue; |
|
75 |
|
76 if (aCommand == KCmdGetFontMetrics) |
|
77 { |
|
78 DoCmdGetFontMetrics(aSection); |
|
79 } |
|
80 else if (aCommand == KCmdTextWidthInPixelsWithCharWidth) |
|
81 { |
|
82 DoCmdTextWidthInPixelsWithCharWidth(aSection); |
|
83 } |
|
84 else if (aCommand == KCmdHandle) |
|
85 { |
|
86 DoCmdHandle(); |
|
87 } |
|
88 else if (aCommand == KCmdCharacterMetrics) |
|
89 { |
|
90 DoCmdCharacterMetrics(aSection); |
|
91 } |
|
92 else if (aCommand == KCmdRawTextWidthInPixels) |
|
93 { |
|
94 DoCmdRawTextWidthInPixels(aSection); |
|
95 } |
|
96 else if (aCommand == KCmdGetFaceAttrib) |
|
97 { |
|
98 DoCmdGetFaceAttrib(aSection); |
|
99 } |
|
100 else if (aCommand == KCmdIsOpenFont) |
|
101 { |
|
102 DoCmdIsOpenFont(aSection); |
|
103 } |
|
104 else if (aCommand == KCmdHasCharacter) |
|
105 { |
|
106 DoCmdHasCharacter(aSection); |
|
107 } |
|
108 else |
|
109 { |
|
110 ret=CT_DataFont::DoCommandL(aCommand, aSection, aAsyncErrorIndex); |
|
111 } |
|
112 |
|
113 return ret; |
|
114 } |
|
115 |
|
116 |
|
117 CFont* CT_DataFbsFont::GetFont() const |
|
118 { |
|
119 return iFbsFont; |
|
120 } |
|
121 |
|
122 |
|
123 /** |
|
124 * Return a pointer to the object that the data wraps |
|
125 * |
|
126 * @return pointer to the object that the data wraps |
|
127 */ |
|
128 TAny* CT_DataFbsFont::GetObject() |
|
129 { |
|
130 return iFbsFont; |
|
131 } |
|
132 |
|
133 |
|
134 /** |
|
135 * Sets a fbs font |
|
136 * |
|
137 * @param aNewFont fbs font |
|
138 */ |
|
139 void CT_DataFbsFont::SetObjectL(TAny* aObject) |
|
140 { |
|
141 // no clean up needed, because fonts are managed by server side |
|
142 iFbsFont = static_cast<CFbsFont*>(aObject); |
|
143 } |
|
144 |
|
145 |
|
146 /** |
|
147 * Disown a fbs font |
|
148 * |
|
149 */ |
|
150 void CT_DataFbsFont::DisownObjectL() |
|
151 { |
|
152 // no clean up needed, because fonts are managed by server side |
|
153 iFbsFont=NULL; |
|
154 } |
|
155 |
|
156 |
|
157 /** Calls CFbsFont::GetFontMetrics() */ |
|
158 void CT_DataFbsFont::DoCmdGetFontMetrics(const TDesC& aSection) |
|
159 { |
|
160 TOpenFontMetrics metrics; |
|
161 TBool actual = iFbsFont->GetFontMetrics(metrics); |
|
162 INFO_PRINTF2(_L("Calls CFbsFont::GetFontMetrics() %d"), actual); |
|
163 |
|
164 // get if true expected flag from parameters |
|
165 TBool expected; |
|
166 if ( GetBoolFromConfig(aSection, KExpectedBool(), expected) ) |
|
167 { |
|
168 // check that the value is as expected |
|
169 if (actual != expected) |
|
170 { |
|
171 ERR_PRINTF3(_L("The value is not as expected! expected: %d, actual: %d"), expected, actual); |
|
172 SetBlockResult(EFail); |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 |
|
178 /** Calls CFbsFont::TextWidthInPixels() using SCharWidth output paramter */ |
|
179 void CT_DataFbsFont::DoCmdTextWidthInPixelsWithCharWidth(const TDesC& aSection) |
|
180 { |
|
181 INFO_PRINTF1(_L("Calls CFbsFont::TextWidthInPixels() using SCharWidth output paramter")); |
|
182 |
|
183 // get text from parameters |
|
184 TPtrC text; |
|
185 if (!GetStringFromConfig(aSection, KText(), text)) |
|
186 { |
|
187 ERR_PRINTF2(_L("No %S"), &KText()); |
|
188 SetBlockResult(EFail); |
|
189 } |
|
190 else |
|
191 { |
|
192 // call TextWidthInPixels() |
|
193 SCharWidth charWidth; |
|
194 iFbsFont->TextWidthInPixels(text, charWidth); |
|
195 |
|
196 // validate SCharWidth |
|
197 if (charWidth.iMove != charWidth.iLeftAdjust + charWidth.iWidth + charWidth.iRightAdjust) |
|
198 { |
|
199 ERR_PRINTF5(_L("Move is not equal to left adjust + width + right adjust!, move: %d, leftAdjust: %d, width: %d, rightAdjust: %d"), charWidth.iMove, charWidth.iLeftAdjust, charWidth.iWidth, charWidth.iRightAdjust); |
|
200 SetBlockResult(EFail); |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 |
|
206 /** Calls CFbsFont::Handle() */ |
|
207 void CT_DataFbsFont::DoCmdHandle() |
|
208 { |
|
209 // call Handle() |
|
210 TInt handle = iFbsFont->Handle(); |
|
211 INFO_PRINTF2(_L("Calls CFbsFont::Handle() %d"), handle); |
|
212 |
|
213 // validate hanle |
|
214 if (handle == 0) |
|
215 { |
|
216 ERR_PRINTF1(_L("Handle is zero!")); |
|
217 SetBlockResult(EFail); |
|
218 } |
|
219 } |
|
220 |
|
221 |
|
222 /** Calls CFbsFont::CharacterMetrics() */ |
|
223 void CT_DataFbsFont::DoCmdCharacterMetrics(const TDesC& aSection) |
|
224 { |
|
225 INFO_PRINTF1(_L("Calls CFbsFont::CharacterMetrics()")); |
|
226 |
|
227 // get character code from parameters |
|
228 TInt charCode = 0; |
|
229 if(!GetIntFromConfig(aSection, KCharCode(), charCode)) |
|
230 { |
|
231 ERR_PRINTF2(_L("No %S"), &KCharCode()); |
|
232 SetBlockResult(EFail); |
|
233 } |
|
234 else |
|
235 { |
|
236 // call CharacterMetrics() |
|
237 const TUint8* bitmapPointer; |
|
238 iFbsFont->CharacterMetrics(charCode, bitmapPointer); |
|
239 |
|
240 // get if NULL bitmap pointer expected flag from parameters |
|
241 TBool expectedNull = EFalse; |
|
242 if(GetBoolFromConfig(aSection, KNullBitmapPointerExpected(), expectedNull)) |
|
243 { |
|
244 // check that on retirn the bitmap pointer is not NULL |
|
245 if ( expectedNull ) |
|
246 { |
|
247 if ( bitmapPointer!=NULL ) |
|
248 { |
|
249 ERR_PRINTF1(_L("Bitmap pointer is NOT null!")); |
|
250 SetBlockResult(EFail); |
|
251 } |
|
252 } |
|
253 else |
|
254 { |
|
255 if ( bitmapPointer==NULL ) |
|
256 { |
|
257 ERR_PRINTF1(_L("Bitmap pointer is null!")); |
|
258 SetBlockResult(EFail); |
|
259 } |
|
260 } |
|
261 } |
|
262 } |
|
263 } |
|
264 |
|
265 |
|
266 /** Calls CFbsFont::RawTextWidthInPixels() */ |
|
267 void CT_DataFbsFont::DoCmdRawTextWidthInPixels(const TDesC& aSection) |
|
268 { |
|
269 INFO_PRINTF1(_L("Calls CFbsFont::RawTextWidthInPixels()")); |
|
270 |
|
271 // get text from parameters |
|
272 TPtrC text; |
|
273 if (!GetStringFromConfig(aSection, KText(), text)) |
|
274 { |
|
275 ERR_PRINTF2(_L("No %S"), &KText()); |
|
276 SetBlockResult(EFail); |
|
277 } |
|
278 else |
|
279 { |
|
280 // call RawTextWidthInPixels() |
|
281 TInt width = iFbsFont->RawTextWidthInPixels(text); |
|
282 |
|
283 // check result against MeasureText() |
|
284 TInt measureTextWidth = iFbsFont->MeasureText(text); |
|
285 if ( width != measureTextWidth) |
|
286 { |
|
287 ERR_PRINTF3(_L("The result of RawTextWidthInPixels() is not the same as for MeasureText(): %d, and %d"), width, measureTextWidth); |
|
288 SetBlockResult(EFail); |
|
289 } |
|
290 } |
|
291 } |
|
292 |
|
293 |
|
294 /** Calls CFbsFont::GetFaceAttrib() */ |
|
295 void CT_DataFbsFont::DoCmdGetFaceAttrib(const TDesC& aSection) |
|
296 { |
|
297 INFO_PRINTF1(_L("Calls CFbsFont::GetFaceAttrib()")); |
|
298 |
|
299 // call GetFaceAttrib() |
|
300 TOpenFontFaceAttrib attrib; |
|
301 TBool actual = iFbsFont->GetFaceAttrib(attrib); |
|
302 |
|
303 // get if true expected flag from parameters |
|
304 TBool expected; |
|
305 if(GetBoolFromConfig(aSection, KExpectedBool(), expected)) |
|
306 { |
|
307 // check that the value is as expected |
|
308 if (actual != expected) |
|
309 { |
|
310 ERR_PRINTF3(_L("The value is not as expected! expected: %d, actual: %d"), expected, actual); |
|
311 SetBlockResult(EFail); |
|
312 } |
|
313 } |
|
314 } |
|
315 |
|
316 |
|
317 /** Calls CFbsFont::IsOpenFont() */ |
|
318 void CT_DataFbsFont::DoCmdIsOpenFont(const TDesC& aSection) |
|
319 { |
|
320 INFO_PRINTF1(_L("Calls CFbsFont::IsOpenFont()")); |
|
321 |
|
322 // call IsOpenFont() |
|
323 TBool actual = iFbsFont->IsOpenFont(); |
|
324 |
|
325 // check that the value is as expected if there is a expected bool parameter |
|
326 TBool expected; |
|
327 if (GetBoolFromConfig(aSection, KExpectedBool(), expected) ) |
|
328 { |
|
329 // check that the value is as expected |
|
330 if (actual != expected) |
|
331 { |
|
332 ERR_PRINTF3(_L("The value is not as expected! expected: %d, actual: %d"), expected, actual); |
|
333 SetBlockResult(EFail); |
|
334 } |
|
335 } |
|
336 } |
|
337 |
|
338 |
|
339 /** Calls CFbsFont::HasCharacter() */ |
|
340 void CT_DataFbsFont::DoCmdHasCharacter(const TDesC& aSection) |
|
341 { |
|
342 INFO_PRINTF1(_L("Calls CFbsFont::HasCharacter()")); |
|
343 |
|
344 // get character code from parameters |
|
345 TInt charCode = 0; |
|
346 if(!GetIntFromConfig(aSection, KCharCode(), charCode)) |
|
347 { |
|
348 ERR_PRINTF2(_L("No %S"), &KCharCode()); |
|
349 SetBlockResult(EFail); |
|
350 } |
|
351 else |
|
352 { |
|
353 // call HasCharacter() |
|
354 TBool actual = iFbsFont->HasCharacter(charCode); |
|
355 |
|
356 TBool expected; |
|
357 if(GetBoolFromConfig(aSection, KExpectedBool(), expected)) |
|
358 { |
|
359 // check that the value is as expected |
|
360 if (actual != expected) |
|
361 { |
|
362 ERR_PRINTF3(_L("The value is not as expected! expected: %d, actual: %d"), expected, actual); |
|
363 SetBlockResult(EFail); |
|
364 } |
|
365 } |
|
366 } |
|
367 } |