|
1 // Copyright (c) 2005-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 "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 @internalComponent - Internal Symbian test code |
|
19 */ |
|
20 |
|
21 #include <coeaui.h> |
|
22 #include <coemain.h> |
|
23 #include <coecntrl.h> |
|
24 #include <coefont.h> |
|
25 #include <coedef.h> |
|
26 #include <coesndpy.h> |
|
27 #include <coefontprovider.h> |
|
28 #include <basched.h> |
|
29 #include <bassnd.h> |
|
30 #include <ecom/ecom.h> |
|
31 #include "TConeZoomFont.h" |
|
32 |
|
33 _LIT(KConeZoomFontText, "Zoom text!"); |
|
34 |
|
35 |
|
36 class CConeZoomFontControl : public CCoeControl |
|
37 { |
|
38 public: |
|
39 static CConeZoomFontControl* NewL(const TRect& aRect); |
|
40 CConeZoomFontControl(); |
|
41 ~CConeZoomFontControl(); |
|
42 void ConstructL(const TRect& aRect); |
|
43 TZoomFactor AccZoom(); |
|
44 private: |
|
45 // Inherited from CCoeControl |
|
46 void Draw(const TRect& /*aRect*/) const; |
|
47 |
|
48 private: |
|
49 HBufC* iConeZoomFontText; |
|
50 TCoeFont iFont; |
|
51 }; |
|
52 |
|
53 class CConeZoomFontView : public CCoeControl |
|
54 { |
|
55 public: |
|
56 static CConeZoomFontView* NewL(); |
|
57 CConeZoomFontView(); |
|
58 ~CConeZoomFontView(); |
|
59 void ConstructL(); |
|
60 |
|
61 void Test1L(); |
|
62 void Test2L(); |
|
63 void Test3L(); |
|
64 |
|
65 TInt CountComponentControls() const; |
|
66 CCoeControl* ComponentControl(TInt aIndex) const; |
|
67 |
|
68 private: |
|
69 // Inherited from CCoeControl |
|
70 void Draw(const TRect& /*aRect*/) const; |
|
71 void SizeChanged(); |
|
72 |
|
73 private: |
|
74 CConeZoomFontControl* iControl; |
|
75 }; |
|
76 |
|
77 |
|
78 // |
|
79 // |
|
80 // CConeZoomFontControl |
|
81 // |
|
82 // |
|
83 CConeZoomFontControl::CConeZoomFontControl(): |
|
84 iFont(TCoeFont::NormalFont()) |
|
85 { |
|
86 } |
|
87 |
|
88 CConeZoomFontControl* CConeZoomFontControl::NewL(const TRect& aRect) |
|
89 { |
|
90 CConeZoomFontControl* self = new(ELeave) CConeZoomFontControl(); |
|
91 CleanupStack::PushL(self); |
|
92 self->ConstructL(aRect); |
|
93 CleanupStack::Pop(self); |
|
94 return self; |
|
95 } |
|
96 |
|
97 CConeZoomFontControl::~CConeZoomFontControl() |
|
98 { |
|
99 delete iConeZoomFontText; |
|
100 } |
|
101 |
|
102 void CConeZoomFontControl::ConstructL(const TRect& /*aRect*/) |
|
103 { |
|
104 iConeZoomFontText = KConeZoomFontText().AllocL(); |
|
105 } |
|
106 |
|
107 void CConeZoomFontControl::Draw(const TRect& /*aRect*/) const |
|
108 { |
|
109 CWindowGc& gc = SystemGc(); |
|
110 TRect drawRect = Rect(); |
|
111 gc.Clear(); |
|
112 drawRect.Shrink(10,10); |
|
113 gc.DrawRect(drawRect); |
|
114 |
|
115 // Testing bit - get the correct font based on the current zoom factor. |
|
116 // NB, the Font() function takes a non-const reference to a TZoomFactor as |
|
117 // its second argument, so we can't pass the direct return from AccumulatedZoom() |
|
118 // as might seem to be the natural thing to do. |
|
119 TZoomFactor junk = AccumulatedZoom(); |
|
120 const CFont& fontUsed = FindFontProvider().Font(TCoeFont::TitleFont(), junk); |
|
121 gc.UseFont(&fontUsed); |
|
122 TInt baselineOffset=(drawRect.Height() + fontUsed.HeightInPixels())/2; |
|
123 gc.DrawText(*iConeZoomFontText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0); |
|
124 gc.DiscardFont(); |
|
125 } |
|
126 |
|
127 TZoomFactor CConeZoomFontControl::AccZoom() |
|
128 { |
|
129 return AccumulatedZoom(); |
|
130 } |
|
131 |
|
132 // |
|
133 // |
|
134 // CConeZoomFontView |
|
135 // |
|
136 // |
|
137 CConeZoomFontView::CConeZoomFontView() |
|
138 { |
|
139 } |
|
140 |
|
141 CConeZoomFontView* CConeZoomFontView::NewL() |
|
142 { |
|
143 CConeZoomFontView* self = new(ELeave) CConeZoomFontView(); |
|
144 CleanupStack::PushL(self); |
|
145 self->ConstructL(); |
|
146 CleanupStack::Pop(self); |
|
147 return self; |
|
148 } |
|
149 |
|
150 CConeZoomFontView::~CConeZoomFontView() |
|
151 { |
|
152 delete iControl; |
|
153 } |
|
154 |
|
155 TInt CConeZoomFontView::CountComponentControls() const |
|
156 { |
|
157 return 1; |
|
158 } |
|
159 |
|
160 /** |
|
161 @SYMTestCaseID UIF-TConeZoomFont-Test1L |
|
162 |
|
163 @SYMPREQ 857 |
|
164 |
|
165 @SYMTestCaseDesc |
|
166 The parent is set to have relative zoom factor of 1000, and the child a relative zoom |
|
167 of 500 using the CCoeControl:: SetZoomFactorL. This should give a cumulative zoom |
|
168 factor of 500. The child will draw text in its rectangle based this cumulative zoom factor. |
|
169 |
|
170 @SYMTestPriority High |
|
171 |
|
172 @SYMTestStatus Implemented |
|
173 |
|
174 @SYMTestActions |
|
175 Set the zoom factors of the parent and child objects |
|
176 Chect the accumulated zoom is calculated correctly |
|
177 finally call draw now to display zoomed text |
|
178 |
|
179 @SYMTestExpectedResults |
|
180 Will leave if accumulated zoom factor is incorrect, zoomed text is displayed. |
|
181 |
|
182 */ |
|
183 void CConeZoomFontView::Test1L() |
|
184 { |
|
185 TInt viewZoom = 1000; |
|
186 TInt controlZoom = 500; |
|
187 |
|
188 SetZoomFactorL(viewZoom, ERelativeZoom); |
|
189 iControl->SetZoomFactorL(controlZoom, ERelativeZoom); |
|
190 TZoomFactor viewZoomFactor = AccumulatedZoom(); |
|
191 TZoomFactor controlZoomFactor = iControl->AccZoom(); |
|
192 |
|
193 //Check to see if the AccumulatedZoom returns the correct values |
|
194 if ((viewZoomFactor.ZoomFactor() != viewZoom) || |
|
195 (controlZoomFactor.ZoomFactor() != ((viewZoom * controlZoom) /1000))) |
|
196 { |
|
197 User::Leave(-1); |
|
198 } |
|
199 |
|
200 DrawNow(); |
|
201 } |
|
202 |
|
203 /** |
|
204 @SYMTestCaseID UIF-TConeZoomFont-Test2L |
|
205 |
|
206 @SYMPREQ 857 |
|
207 |
|
208 @SYMTestCaseDesc |
|
209 The parent is set to have relative zoom factor of 500, and the child a absolute |
|
210 zoom of 1000. This should give a cumulative zoom factor of 1000 (because the |
|
211 child's zoom is absolute). The child will draw text in its rectangle based this |
|
212 cumulative zoom factor. |
|
213 |
|
214 @SYMTestPriority High |
|
215 |
|
216 @SYMTestStatus Implemented |
|
217 |
|
218 @SYMTestActions |
|
219 Set the zoom factors of the parent and child objects |
|
220 Chect the accumulated zoom is calculated correctly |
|
221 finally call draw now to display zoomed text |
|
222 |
|
223 @SYMTestExpectedResults |
|
224 Will leave if accumulated zoom factor is incorrect, zoomed text is displayed. |
|
225 |
|
226 */ |
|
227 void CConeZoomFontView::Test2L() |
|
228 { |
|
229 TInt viewZoom = 500; |
|
230 TInt controlZoom = 1000; |
|
231 |
|
232 SetZoomFactorL(viewZoom, ERelativeZoom); |
|
233 iControl->SetZoomFactorL(controlZoom, EAbsoluteZoom); |
|
234 TZoomFactor viewZoomFactor = AccumulatedZoom(); |
|
235 TZoomFactor controlZoomFactor = iControl->AccZoom(); |
|
236 |
|
237 //Check to see if the AccumulatedZoom returns the correct values |
|
238 if ((viewZoomFactor.ZoomFactor() != viewZoom) || |
|
239 (controlZoomFactor.ZoomFactor() != (controlZoom))) |
|
240 { |
|
241 User::Leave(-1); |
|
242 } |
|
243 |
|
244 DrawNow(); |
|
245 } |
|
246 |
|
247 /** |
|
248 @SYMTestCaseID UIF-TConeZoomFont-Test3L |
|
249 |
|
250 @SYMPREQ 857 |
|
251 |
|
252 @SYMTestCaseDesc |
|
253 The parent is set to have absolute zoom factor of 1500, and the child |
|
254 a relative zoom of 1500. This should give a cumulative zoom factor of |
|
255 2250. The child will draw text in its rectangle based this cumulative |
|
256 zoom factor. |
|
257 |
|
258 @SYMTestPriority High |
|
259 |
|
260 @SYMTestStatus Implemented |
|
261 |
|
262 @SYMTestActions |
|
263 Set the zoom factors of the parent and child objects |
|
264 Chect the accumulated zoom is calculated correctly |
|
265 finally call draw now to display zoomed text |
|
266 |
|
267 @SYMTestExpectedResults |
|
268 Will leave if accumulated zoom factor is incorrect, zoomed text is displayed. |
|
269 |
|
270 */ |
|
271 void CConeZoomFontView::Test3L() |
|
272 { |
|
273 |
|
274 TInt viewZoom = 1500; |
|
275 TInt controlZoom = 1500; |
|
276 |
|
277 SetZoomFactorL(viewZoom, EAbsoluteZoom); |
|
278 iControl->SetZoomFactorL(controlZoom, ERelativeZoom); |
|
279 TZoomFactor viewZoomFactor = AccumulatedZoom(); |
|
280 TZoomFactor controlZoomFactor = iControl->AccZoom(); |
|
281 |
|
282 //Check to see if the AccumulatedZoom returns the correct values |
|
283 if ((viewZoomFactor.ZoomFactor() != viewZoom) || |
|
284 (controlZoomFactor.ZoomFactor() != ((viewZoom * controlZoom) /1000))) |
|
285 { |
|
286 User::Leave(-1); |
|
287 } |
|
288 |
|
289 DrawNow(); |
|
290 } |
|
291 |
|
292 CCoeControl* CConeZoomFontView::ComponentControl(TInt /*aIndex*/) const |
|
293 { |
|
294 return iControl; |
|
295 } |
|
296 |
|
297 void CConeZoomFontView::ConstructL() |
|
298 { |
|
299 CreateWindowL(); |
|
300 |
|
301 iControl = CConeZoomFontControl::NewL(Rect()); |
|
302 iControl->SetContainerWindowL(*this); |
|
303 iControl->SetParent(this); |
|
304 |
|
305 SetExtent( TPoint(20,20),TSize(600,200) ); |
|
306 |
|
307 SetZoomFactorL(1000); |
|
308 iControl->SetZoomFactorL(1000, EAbsoluteZoom); |
|
309 |
|
310 ActivateL(); |
|
311 } |
|
312 |
|
313 void CConeZoomFontView::Draw(const TRect& /*aRect*/) const |
|
314 { |
|
315 |
|
316 CWindowGc& gc = SystemGc(); |
|
317 TRect drawRect = Rect(); |
|
318 gc.Clear(); |
|
319 drawRect.Shrink(10,10); |
|
320 gc.DrawRect(drawRect); |
|
321 |
|
322 } |
|
323 |
|
324 void CConeZoomFontView::SizeChanged() |
|
325 { |
|
326 ComponentControl(1)->SetRect( TRect(TPoint(20,20),TSize(560,160))) ; |
|
327 } |
|
328 |
|
329 // |
|
330 // |
|
331 // CConeZoomFontAppUi |
|
332 // |
|
333 // |
|
334 CConeZoomFontAppUi::CConeZoomFontAppUi(CTmsTestStep* aStep) : |
|
335 CTestCoeAppUi(aStep) |
|
336 {} |
|
337 |
|
338 CConeZoomFontAppUi::~CConeZoomFontAppUi() |
|
339 { |
|
340 delete iView; |
|
341 } |
|
342 |
|
343 |
|
344 void CConeZoomFontAppUi::ConstructL() |
|
345 { |
|
346 CTestCoeAppUi::ConstructL(); |
|
347 |
|
348 iView = CConeZoomFontView::NewL(); |
|
349 |
|
350 AutoTestManager().StartAutoTest(); |
|
351 } |
|
352 |
|
353 void CConeZoomFontAppUi::RunTestStepL(TInt aStepNum) |
|
354 { |
|
355 |
|
356 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
357 |
|
358 TInt err; |
|
359 |
|
360 switch(aStepNum) |
|
361 { |
|
362 case 1: |
|
363 SetTestStepID(_L("UIF-TConeZoomFont-Test1L")); |
|
364 _LIT(KTest1, "Zoom Relative 0.5"); |
|
365 INFO_PRINTF1(KTest1); |
|
366 TRAP(err, iView->Test1L()); |
|
367 RecordTestResultL(); |
|
368 break; |
|
369 case 2: |
|
370 SetTestStepID(_L("UIF-TConeZoomFont-Test2L")); |
|
371 _LIT(KTest2, "Zoom Absolute 2.0"); |
|
372 INFO_PRINTF1(KTest2); |
|
373 TRAP(err, iView->Test2L()); |
|
374 RecordTestResultL(); |
|
375 break; |
|
376 case 3: |
|
377 SetTestStepID(_L("UIF-TConeZoomFont-Test3L")); |
|
378 _LIT(KTest3, "Zoom Relative 1.5*1.5"); |
|
379 INFO_PRINTF1(KTest3); |
|
380 TRAP(err, iView->Test3L()); |
|
381 RecordTestResultL(); |
|
382 CloseTMSGraphicsStep(); |
|
383 break; |
|
384 case 4: |
|
385 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
386 break; |
|
387 |
|
388 } |
|
389 } |
|
390 |
|
391 // |
|
392 // |
|
393 // CConeZoomFontStep |
|
394 // |
|
395 // |
|
396 void CTConeZoomFontStep::ConstructAppL(CCoeEnv* aCoe) |
|
397 { // runs inside a TRAP harness |
|
398 aCoe->ConstructL(); |
|
399 CConeZoomFontAppUi* appUi= new (ELeave) CConeZoomFontAppUi(this); |
|
400 aCoe->SetAppUi(appUi); |
|
401 appUi->ConstructL(); |
|
402 } |
|
403 |
|
404 CTConeZoomFontStep::CTConeZoomFontStep() |
|
405 { |
|
406 SetTestStepName(KTConeZoomFontStep); |
|
407 } |
|
408 |
|
409 CTConeZoomFontStep::~CTConeZoomFontStep() |
|
410 {} |
|
411 |
|
412 |
|
413 TVerdict CTConeZoomFontStep::doTestStepL() // main function called by E32 |
|
414 { |
|
415 _LIT(KTestStart, "Test Started"); |
|
416 INFO_PRINTF1(KTestStart); |
|
417 |
|
418 PreallocateHALBuffer(); |
|
419 |
|
420 __UHEAP_MARK; |
|
421 |
|
422 CCoeEnv* coe=new(ELeave) CCoeEnv; |
|
423 TRAPD(err,ConstructAppL(coe)); |
|
424 |
|
425 if (!err) |
|
426 coe->ExecuteD(); |
|
427 else |
|
428 { |
|
429 SetTestStepResult(EFail); |
|
430 delete coe; |
|
431 } |
|
432 |
|
433 REComSession::FinalClose(); |
|
434 |
|
435 __UHEAP_MARKEND; |
|
436 |
|
437 _LIT(KTestFinished, "Test Finished"); |
|
438 INFO_PRINTF1(KTestFinished); |
|
439 return TestStepResult(); |
|
440 } |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |