|
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 // test code for the clock DLL |
|
15 // $Workfile: TCLCK1.CPP $ |
|
16 // $Revision: 1.7 $ |
|
17 // $Author: DougF $ |
|
18 // $Date: 07 Jul 1999 16:16:30 $ |
|
19 // |
|
20 // |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent - Internal Symbian test code |
|
25 */ |
|
26 #include <e32keys.h> |
|
27 #include <coemain.h> |
|
28 #include <coedef.h> |
|
29 #include <coeaui.h> |
|
30 #include <coecntrl.h> |
|
31 #include <clock.h> |
|
32 #include <basched.h> |
|
33 |
|
34 #include <mbs1.mbg> |
|
35 #include "TCLCK1STEP.h" |
|
36 |
|
37 |
|
38 |
|
39 #define TCLCK1_MBM _L("z:\\system\\data\\MBS1.MBM") |
|
40 #define CLOCK EMbmMbs1Clock |
|
41 #define CLOCKMSK EMbmMbs1Clockmsk |
|
42 |
|
43 // classes |
|
44 // main functions |
|
45 |
|
46 CTestClck1Ui::CTestClck1Ui(CTmsTestStep* aStep) : |
|
47 CTestCoeAppUi(aStep) |
|
48 {} |
|
49 |
|
50 |
|
51 void CTestClck1Ui::ConstructL() |
|
52 { |
|
53 CTestCoeAppUi::ConstructL(); |
|
54 iControl=new(ELeave) CClk1Control; |
|
55 AddToStackL(iControl,ECoeStackPriorityDefault,ECoeStackFlagOwnershipTransfered); |
|
56 // appUi->AddToStackL(control,ECoeStackPriorityDefault,ECoeStackFlagOwnershipTransfered); |
|
57 iControl->ConstructL(); |
|
58 |
|
59 AutoTestManager().StartAutoTest(); |
|
60 } |
|
61 |
|
62 /** |
|
63 @SYMTestCaseID UIF-Clock-TClock1 |
|
64 */ |
|
65 |
|
66 void CTestClck1Ui::RunTestStepL(TInt aNumStep) |
|
67 { |
|
68 TKeyEvent theKeyEvent; |
|
69 TEventCode theType = EEventKey; |
|
70 |
|
71 //only for debug |
|
72 User::After(TTimeIntervalMicroSeconds32(1000000)); |
|
73 |
|
74 |
|
75 switch(aNumStep) |
|
76 { |
|
77 case 1: |
|
78 SetTestStepID(_L("UIF-Clock-TClock1")); |
|
79 theKeyEvent.iCode = EKeyEnter; |
|
80 theKeyEvent.iModifiers = 0; |
|
81 |
|
82 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
83 INFO_PRINTF1(_L("Show analog & digital clocks")); |
|
84 break; |
|
85 |
|
86 case 2: case 3: case 4: case 5: |
|
87 theKeyEvent.iCode = EKeyLeftArrow; |
|
88 theKeyEvent.iModifiers = 0; |
|
89 |
|
90 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
91 INFO_PRINTF1(_L("Change universal time backward")); |
|
92 break; |
|
93 |
|
94 case 6: case 7: case 8: case 9: |
|
95 theKeyEvent.iCode = EKeyRightArrow; |
|
96 theKeyEvent.iModifiers = 0; |
|
97 |
|
98 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
99 INFO_PRINTF1(_L("Change universal time forward")); |
|
100 break; |
|
101 |
|
102 case 10: |
|
103 theKeyEvent.iCode = '*'; |
|
104 theKeyEvent.iModifiers = 0; |
|
105 |
|
106 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
107 INFO_PRINTF1(_L("Change clock separator")); |
|
108 break; |
|
109 |
|
110 case 11: |
|
111 theKeyEvent.iCode = EKeySpace; |
|
112 theKeyEvent.iModifiers = EModifierShift; |
|
113 |
|
114 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
115 INFO_PRINTF1(_L("Set a new background color")); |
|
116 break; |
|
117 |
|
118 case 12: |
|
119 theKeyEvent.iCode = EKeySpace; |
|
120 theKeyEvent.iModifiers = 0; |
|
121 |
|
122 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
123 INFO_PRINTF1(_L("Restore previos background color")); |
|
124 break; |
|
125 |
|
126 case 13: |
|
127 theKeyEvent.iCode = EKeyEnter; |
|
128 theKeyEvent.iModifiers = EModifierShift; |
|
129 |
|
130 iControl->OfferKeyEventL(theKeyEvent, theType); |
|
131 INFO_PRINTF1(_L("hide clocks")); |
|
132 RecordTestResultL(); |
|
133 CloseTMSGraphicsStep(); |
|
134 break; |
|
135 |
|
136 case 14: |
|
137 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
138 } |
|
139 } |
|
140 |
|
141 |
|
142 void CTClck1Step::ConstructAppL(CCoeEnv* aCoeEnv) |
|
143 { |
|
144 aCoeEnv->ConstructL(); |
|
145 CTestClck1Ui* appUi=new(ELeave) CTestClck1Ui(this); |
|
146 appUi->ConstructL(); |
|
147 aCoeEnv->SetAppUi(appUi); |
|
148 } |
|
149 |
|
150 CTClck1Step::~CTClck1Step() |
|
151 /** |
|
152 Destructor |
|
153 */ |
|
154 { |
|
155 } |
|
156 |
|
157 CTClck1Step::CTClck1Step() |
|
158 /** |
|
159 Constructor |
|
160 */ |
|
161 { |
|
162 // Call base class method to set up the human readable name for logging |
|
163 SetTestStepName(KTClck1Step); |
|
164 } |
|
165 |
|
166 TVerdict CTClck1Step::doTestStepL() |
|
167 { |
|
168 INFO_PRINTF1(_L("Test Started")); |
|
169 CCoeEnv* coeEnv=new CCoeEnv; |
|
170 if (coeEnv==NULL) |
|
171 { |
|
172 SetTestStepResult(EFail); |
|
173 return TestStepResult(); |
|
174 } |
|
175 TRAPD(error, ConstructAppL(coeEnv)); |
|
176 if (error!=KErrNone) |
|
177 { |
|
178 delete coeEnv; |
|
179 SetTestStepResult(EFail); |
|
180 return TestStepResult(); |
|
181 } |
|
182 coeEnv->ExecuteD(); |
|
183 INFO_PRINTF1(_L("Test Finished")); |
|
184 return TestStepResult(); |
|
185 } |
|
186 |
|
187 |
|
188 // CClck1DestructableFont |
|
189 |
|
190 CClck1DestructableFont::CClck1DestructableFont(CWsScreenDevice* aScreenDevice) |
|
191 :iScreenDevice(aScreenDevice) |
|
192 { |
|
193 } |
|
194 |
|
195 void CClck1DestructableFont::ConstructL(const TFontSpec& aFontSpec) |
|
196 { |
|
197 User::LeaveIfError(iScreenDevice->GetNearestFontInTwips((CFont*&)iFont, aFontSpec)); |
|
198 } |
|
199 |
|
200 CClck1DestructableFont::~CClck1DestructableFont() |
|
201 { |
|
202 iScreenDevice->ReleaseFont(iFont); // N.B. do not need to do "delete iFont" |
|
203 } |
|
204 |
|
205 TInt CClck1DestructableFont::Handle() const |
|
206 { |
|
207 return iFont->Handle(); |
|
208 } |
|
209 |
|
210 // CClk1Control |
|
211 |
|
212 CClk1Control::CClk1Control() |
|
213 :iBackgroundColor(85, 85, 85), |
|
214 iAnimDll(iCoeEnv->WsSession()), |
|
215 iDigitalClock0Position(350, 125), |
|
216 iDigitalClock0Size(180, 70), |
|
217 iAnalogClock0Position(10, 0), |
|
218 iAnalogClock0Size(300, 222), |
|
219 iUniversalTimeOffset(0) |
|
220 { |
|
221 __DECLARE_NAME(_S("CClk1Control")); |
|
222 |
|
223 __ASSERT_DEBUG(iDigitalClock0==NULL, User::Panic(_L("Clock test-code"), 1)); |
|
224 __ASSERT_DEBUG(iAnalogClock0==NULL, User::Panic(_L("Clock test-code"), 2)); |
|
225 } |
|
226 |
|
227 void CClk1Control::ConstructL() |
|
228 { |
|
229 // CONE construction stuff |
|
230 CreateBackedUpWindowL(iCoeEnv->RootWin()); |
|
231 SetExtent(TPoint(10, 10), TSize(620, 220)); |
|
232 ActivateL(); |
|
233 iCoeEnv->WsSession().Flush(); |
|
234 |
|
235 User::LeaveIfError(iAnimDll.Load(_L("CLOCKA.DLL"))); |
|
236 |
|
237 // clock construction stuff |
|
238 CreateDigitalClocksL(); |
|
239 CreateAnalogClocksL(); |
|
240 } |
|
241 |
|
242 CClk1Control::~CClk1Control() |
|
243 { |
|
244 if (iDigitalClock0!=NULL) |
|
245 iDigitalClock0->Destroy(); |
|
246 if (iAnalogClock0!=NULL) |
|
247 iAnalogClock0->Destroy(); |
|
248 iAnimDll.Close(); |
|
249 } |
|
250 |
|
251 TKeyResponse CClk1Control::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
252 { |
|
253 if (aType==EEventKey) |
|
254 { |
|
255 TInt adjust=0; |
|
256 switch (aKeyEvent.iCode) |
|
257 { |
|
258 case CTRL('e'): |
|
259 iCoeEnv->Flush(); |
|
260 CBaActiveScheduler::Exit(); |
|
261 break; |
|
262 case EKeySpace: |
|
263 if (aKeyEvent.iModifiers&EModifierShift) |
|
264 iDigitalClock0->SetBackgroundColor(TRgb(85, 85, 85), TRgb(0, 0, 0)); |
|
265 else |
|
266 iDigitalClock0->SetBackgroundColor(TRgb(170, 170, 170), TRgb(85, 85, 85)); |
|
267 break; |
|
268 case EKeyEnter: |
|
269 if (aKeyEvent.iModifiers&EModifierShift) |
|
270 { |
|
271 iDigitalClock0->SetVisible(EFalse); |
|
272 iAnalogClock0->SetVisible(EFalse); |
|
273 } |
|
274 else |
|
275 { |
|
276 iDigitalClock0->SetVisible(ETrue); |
|
277 iAnalogClock0->SetVisible(ETrue); |
|
278 } |
|
279 break; |
|
280 case '$': |
|
281 case '%': |
|
282 case '^': |
|
283 case '&': |
|
284 case '+': |
|
285 case '-': |
|
286 case '*': |
|
287 case '/': |
|
288 case 'S': |
|
289 case 's': |
|
290 case '\\': |
|
291 case ':': |
|
292 { |
|
293 TLocale locale; |
|
294 locale.Refresh(); |
|
295 #pragma warning (disable: 4710) |
|
296 locale.SetTimeSeparator(aKeyEvent.iCode, 1); |
|
297 locale.SetTimeSeparator(aKeyEvent.iCode, 2); |
|
298 #pragma warning (default: 4710) |
|
299 locale.Set(); |
|
300 } |
|
301 break; |
|
302 case EKeyLeftArrow: |
|
303 case EKeyUpArrow: |
|
304 adjust=-3600; |
|
305 goto adjustClock; |
|
306 case EKeyRightArrow: |
|
307 case EKeyDownArrow: |
|
308 adjust=3600; |
|
309 goto adjustClock; |
|
310 adjustClock: |
|
311 iUniversalTimeOffset+=adjust; |
|
312 iDigitalClock0->SetUniversalTimeOffset(iUniversalTimeOffset); |
|
313 iAnalogClock0->SetUniversalTimeOffset(iUniversalTimeOffset); |
|
314 break; |
|
315 case 'U': |
|
316 case 'u': |
|
317 iDigitalClock0->UpdateDisplay(); |
|
318 iAnalogClock0->UpdateDisplay(); |
|
319 break; |
|
320 case 'D': |
|
321 case 'd': |
|
322 iDigitalClock0->Draw(); |
|
323 iAnalogClock0->Draw(); |
|
324 break; |
|
325 } |
|
326 } |
|
327 |
|
328 return EKeyWasConsumed; |
|
329 } |
|
330 |
|
331 void CClk1Control::Draw(const TRect&) const |
|
332 { |
|
333 CGraphicsContext& systemGc=SystemGc(); |
|
334 systemGc.SetPenStyle(CGraphicsContext::ENullPen); |
|
335 systemGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
336 systemGc.SetBrushColor(iBackgroundColor); |
|
337 systemGc.DrawRect(Rect()); |
|
338 } |
|
339 |
|
340 void CClk1Control::CreateDigitalClocksL() |
|
341 { |
|
342 TMargins margins; |
|
343 margins.iLeft=0; |
|
344 margins.iRight=0; |
|
345 margins.iTop=0; |
|
346 margins.iBottom=0; |
|
347 // construct digital clock |
|
348 STimeDeviceShadow digitalClock0Shadow; |
|
349 digitalClock0Shadow.iIsOn=ETrue; |
|
350 digitalClock0Shadow.iColor=TRgb(85, 85, 85); |
|
351 digitalClock0Shadow.iOffset.SetXY(2, 2); |
|
352 // |
|
353 iDigitalClock0=new(ELeave) RDigitalClock(iAnimDll, BackedUpWindow()); |
|
354 iDigitalClock0->ConstructL(TTimeIntervalSeconds(30*60), iDigitalClock0Position, iDigitalClock0Size, margins, digitalClock0Shadow, TRgb(170, 170, 170), 1); |
|
355 // |
|
356 TBuf<64> digitalClock0Format0=_L("%-B%J%:1%T%+B"); |
|
357 CClck1DestructableFont* digitalClock0Font0=new(ELeave) CClck1DestructableFont(iCoeEnv->ScreenDevice()); |
|
358 CleanupStack::PushL(digitalClock0Font0); |
|
359 TFontSpec digitalClock0FontSpec0(_L("arial"), iCoeEnv->ScreenDevice()->VerticalPixelsToTwips(25)); |
|
360 digitalClock0FontSpec0.iFontStyle.SetPosture(EPostureItalic); |
|
361 digitalClock0FontSpec0.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
362 digitalClock0Font0->ConstructL(digitalClock0FontSpec0); |
|
363 iDigitalClock0->AddTextSectionL(TDigitalDisplayTextSection(digitalClock0Font0->Handle(), TRgb(0, 0, 0), |
|
364 EDigitalDisplayHorizontalTextAlignmentCenter, |
|
365 EDigitalDisplayVerticalTextAlignmentCenterExclDescent, |
|
366 0, 0, digitalClock0Format0)); |
|
367 // |
|
368 CleanupStack::PopAndDestroy(); // pop and destroy digitalClock0Font0 |
|
369 } |
|
370 |
|
371 void CClk1Control::CreateAnalogClocksL() |
|
372 { |
|
373 CWsScreenDevice* screenDevice=iCoeEnv->ScreenDevice(); |
|
374 TMargins margins; |
|
375 margins.iLeft=0; |
|
376 margins.iRight=0; |
|
377 margins.iTop=0; |
|
378 margins.iBottom=0; |
|
379 // construct analog clock |
|
380 // |
|
381 STimeDeviceShadow analogClock0Shadow; |
|
382 analogClock0Shadow.iIsOn=ETrue; |
|
383 analogClock0Shadow.iColor=TRgb(85, 85, 85); |
|
384 analogClock0Shadow.iOffset.SetXY(4, 4); |
|
385 // |
|
386 CFbsBitmap* analogClock0Face=new(ELeave) CFbsBitmap; |
|
387 CleanupStack::PushL(analogClock0Face); |
|
388 User::LeaveIfError(analogClock0Face->Load(TCLCK1_MBM, CLOCK)); |
|
389 analogClock0Face->SetSizeInTwips(screenDevice); |
|
390 CFbsBitmap* analogClock0FaceMask=new(ELeave) CFbsBitmap; |
|
391 CleanupStack::PushL(analogClock0FaceMask); |
|
392 User::LeaveIfError(analogClock0FaceMask->Load(TCLCK1_MBM, CLOCKMSK)); |
|
393 analogClock0Face->SetSizeInTwips(screenDevice); |
|
394 // |
|
395 iAnalogClock0=new(ELeave) RAnalogClock(iAnimDll, BackedUpWindow()); |
|
396 iAnalogClock0->ConstructL(TTimeIntervalSeconds(30*60), iAnalogClock0Position, iAnalogClock0Size, margins, analogClock0Shadow, |
|
397 analogClock0Face->Handle(), analogClock0FaceMask->Handle(), 2); |
|
398 // |
|
399 TRgb black(0, 0, 0); |
|
400 CArrayFix<TPoint>* pointList=new(ELeave) CArrayFixFlat<TPoint>(4); |
|
401 CleanupStack::PushL(pointList); |
|
402 // |
|
403 // N.B. the dimensions/positions of the hand features (i.e. lines and circles) are specified with the hand assumed to be in the |
|
404 // 12 o'clock position, with TPoint(0, 0) being the center of the clock |
|
405 TAnalogDisplayHand analogClock0HourHand(EAnalogDisplayHandOneRevPer12Hours); |
|
406 analogClock0HourHand.AddLine(CGraphicsContext::ESolidPen, black, TSize(4, 4), TPoint(0, 10), TPoint(0, -55)); |
|
407 iAnalogClock0->AddHandL(analogClock0HourHand); |
|
408 // |
|
409 TAnalogDisplayHand analogClock0MinuteHand(EAnalogDisplayHandOneRevPerHour); |
|
410 analogClock0MinuteHand.AddLine(CGraphicsContext::ESolidPen, black, TSize(4, 4), TPoint(0, 10), TPoint(0, -70)); |
|
411 iAnalogClock0->AddHandL(analogClock0MinuteHand); |
|
412 // |
|
413 CleanupStack::PopAndDestroy(); // pop and destroy pointList |
|
414 CleanupStack::PopAndDestroy(); // pop and destroy analogClock0FaceMask |
|
415 CleanupStack::PopAndDestroy(); // pop and destroy analogClock0Face |
|
416 } |
|
417 |