|
1 // Copyright (c) 1996-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 Wserv password features |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32hal.h> |
|
20 #include "W32STD.H" |
|
21 #include "../tlib/testbase.h" |
|
22 #include "TMAN.H" |
|
23 |
|
24 //#define LOG_TESTS |
|
25 |
|
26 #define THE_PASSWORD _L("pass") |
|
27 |
|
28 enum TPasswordState |
|
29 { |
|
30 ENotStarted, |
|
31 EWaitForSwitchOff, |
|
32 EWaitForEnter, |
|
33 EWaitForA, |
|
34 EWaitForSwitchOff2, |
|
35 EWaitForSwitchOff3, |
|
36 EWaitForSwitchOff4, |
|
37 EWaitForSwitchOff5, |
|
38 EWaitForEnter2, |
|
39 EPasswordFinished, |
|
40 }; |
|
41 |
|
42 class CPasswordTest; |
|
43 |
|
44 class CPasswordWindowGroup : public CTWindowGroup |
|
45 { |
|
46 public: |
|
47 CPasswordWindowGroup(CTClient *aClient, CPasswordTest *aTest); |
|
48 void ConstructL(); |
|
49 void PasswordL(const TTime &aTime); |
|
50 void KeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
51 void SwitchOn(const TTime &aTime); |
|
52 private: |
|
53 CPasswordTest *iTest; |
|
54 }; |
|
55 |
|
56 class CPasswordWindowGroup2 : public CTWindowGroup |
|
57 { |
|
58 public: |
|
59 CPasswordWindowGroup2(CTClient *aClient, CPasswordTest *aTest); |
|
60 void ConstructL(); |
|
61 void KeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
62 private: |
|
63 CPasswordTest *iTest; |
|
64 }; |
|
65 |
|
66 class CPasswordWindow : public CTWin |
|
67 { |
|
68 public: |
|
69 CPasswordWindow(CPasswordTest *aTest); |
|
70 void Draw(); |
|
71 private: |
|
72 CPasswordTest *iTest; |
|
73 }; |
|
74 |
|
75 class CPasswordTest : public CTestBase |
|
76 { |
|
77 public: |
|
78 CPasswordTest(); |
|
79 ~CPasswordTest(); |
|
80 TestState DoTestL(); |
|
81 void ConstructL(); |
|
82 void Fail(TInt aWhere); |
|
83 void EnterKeyPressed(TPasswordState aNewState); |
|
84 void SwitchOn(); |
|
85 void TestComplete(TPasswordState aNewState); |
|
86 void PasswordMsgReceivedL(); |
|
87 TPasswordState PasswordState() const; |
|
88 void SetPassState(TPasswordState aPassState); |
|
89 void StartMainPasswordTestL(); |
|
90 void StartOnceADayPasswordTestL(); |
|
91 void TurnOffAndOn(); |
|
92 private: |
|
93 CPasswordWindowGroup *iGroup; |
|
94 CPasswordWindowGroup2 *iGroup2; |
|
95 CPasswordWindow *iPassWin; |
|
96 CTBlankWindow *iBlankWin; |
|
97 TSize iWinSize; |
|
98 TInt iState; |
|
99 TPasswordState iPassState; |
|
100 TBool iPasswordTestFailed; |
|
101 }; |
|
102 |
|
103 GLDEF_C CTestBase *CreatePasswordTest() |
|
104 { |
|
105 return(new(ELeave) CPasswordTest()); |
|
106 } |
|
107 |
|
108 // |
|
109 |
|
110 CPasswordWindowGroup::CPasswordWindowGroup(CTClient *aClient, CPasswordTest *aTest) : |
|
111 CTWindowGroup(aClient), |
|
112 iTest(aTest) |
|
113 { |
|
114 __DECLARE_NAME(_S("CPasswordWindowGroup")); |
|
115 } |
|
116 |
|
117 void CPasswordWindowGroup::ConstructL() |
|
118 { |
|
119 CTWindowGroup::ConstructL(); |
|
120 GroupWin()->EnableOnEvents(); |
|
121 } |
|
122 |
|
123 void CPasswordWindowGroup::SwitchOn(const TTime &) |
|
124 { |
|
125 iTest->SwitchOn(); |
|
126 } |
|
127 |
|
128 void CPasswordWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &) |
|
129 { |
|
130 if (aKey.iCode==EKeyEscape) |
|
131 iTest->TestComplete(EPasswordFinished); |
|
132 switch(iTest->PasswordState()) |
|
133 { |
|
134 case EWaitForEnter: |
|
135 if (aKey.iCode==EKeyEnter) |
|
136 iTest->EnterKeyPressed(EWaitForA); |
|
137 break; |
|
138 case EWaitForEnter2: |
|
139 if (aKey.iCode==EKeyEnter) |
|
140 iTest->TestComplete(EPasswordFinished); |
|
141 break; |
|
142 default:; |
|
143 } |
|
144 } |
|
145 |
|
146 void CPasswordWindowGroup::PasswordL(const TTime &) |
|
147 { |
|
148 iTest->TestL(iGroupWin.OrdinalPosition()==0); |
|
149 iTest->PasswordMsgReceivedL(); |
|
150 } |
|
151 |
|
152 // |
|
153 |
|
154 CPasswordWindowGroup2::CPasswordWindowGroup2(CTClient *aClient, CPasswordTest *aTest) : |
|
155 CTWindowGroup(aClient), |
|
156 iTest(aTest) |
|
157 { |
|
158 __DECLARE_NAME(_S("CPasswordWindowGroup")); |
|
159 } |
|
160 |
|
161 void CPasswordWindowGroup2::ConstructL() |
|
162 { |
|
163 CTWindowGroup::ConstructL(); |
|
164 iGroupWin.CaptureKey('a',0,0); |
|
165 } |
|
166 |
|
167 void CPasswordWindowGroup2::KeyL(const TKeyEvent &aKey,const TTime &) |
|
168 { |
|
169 if (iTest->PasswordState()!=EPasswordFinished) |
|
170 { |
|
171 if (iTest->PasswordState()!=EWaitForA) |
|
172 { |
|
173 #if defined(LOG_TESTS) |
|
174 TLogMessageText buf; |
|
175 _LIT(KBadKey,"Bad Key Code=%d(%c) Scan=%d(%c) Rep=%d"); |
|
176 buf.AppendFormat(KBadKey,aKey.iCode,aKey.iCode,aKey.iScanCode,aKey.iScanCode,aKey.iRepeats); |
|
177 Client()->LogMessage(buf); |
|
178 #endif |
|
179 if (aKey.iRepeats==0) |
|
180 iTest->Fail(1); |
|
181 } |
|
182 else |
|
183 { |
|
184 if (aKey.iCode!='a') |
|
185 iTest->Fail(2); |
|
186 iTest->TestComplete(EWaitForSwitchOff2); |
|
187 } |
|
188 } |
|
189 } |
|
190 |
|
191 // |
|
192 |
|
193 CPasswordWindow::CPasswordWindow(CPasswordTest *aTest) : |
|
194 iTest(aTest) |
|
195 { |
|
196 } |
|
197 |
|
198 void CPasswordWindow::Draw() |
|
199 { |
|
200 iGc->Clear(); |
|
201 switch(iTest->PasswordState()) |
|
202 { |
|
203 case EWaitForSwitchOff: |
|
204 iGc->DrawText(_L("Please wait, turning off & on [1]"),TPoint(10,20)); |
|
205 break; |
|
206 case EWaitForSwitchOff2: |
|
207 iGc->DrawText(_L("Please wait, turning off & on [2]"),TPoint(10,20)); |
|
208 break; |
|
209 case EWaitForSwitchOff3: |
|
210 iGc->DrawText(_L("Please wait, turning off & on [3]"),TPoint(10,20)); |
|
211 break; |
|
212 case EWaitForSwitchOff4: |
|
213 iGc->DrawText(_L("Please wait, turning off & on [4]"),TPoint(10,20)); |
|
214 break; |
|
215 case EWaitForSwitchOff5: |
|
216 iGc->DrawText(_L("Please wait, turning off & on [5]"),TPoint(10,20)); |
|
217 break; |
|
218 case EWaitForEnter: |
|
219 iGc->DrawText(_L("Try the key of death, then..."),TPoint(10,20)); |
|
220 iGc->DrawText(_L("Press 'a', then..."),TPoint(10,40)); |
|
221 iGc->DrawText(_L("Press Enter"),TPoint(10,60)); |
|
222 break; |
|
223 case EWaitForEnter2: |
|
224 iGc->DrawText(_L("Press Enter"),TPoint(10,20)); |
|
225 break; |
|
226 case EWaitForA: |
|
227 iGc->DrawText(_L("Press 'a'"),TPoint(10,20)); |
|
228 case EPasswordFinished: |
|
229 break; |
|
230 default:; |
|
231 } |
|
232 } |
|
233 |
|
234 // |
|
235 |
|
236 CPasswordTest::CPasswordTest() : CTestBase(_L("Password")) |
|
237 {} |
|
238 |
|
239 CPasswordTest::~CPasswordTest() |
|
240 { |
|
241 delete iBlankWin; |
|
242 delete iPassWin; |
|
243 delete iGroup; |
|
244 delete iGroup2; |
|
245 } |
|
246 |
|
247 #if defined(LOG_TESTS) |
|
248 void CPasswordTest::Fail(TInt aWhere) |
|
249 #else |
|
250 void CPasswordTest::Fail(TInt /*aWhere*/) |
|
251 #endif |
|
252 { |
|
253 #if defined(LOG_TESTS) |
|
254 TLogMessageText buf; |
|
255 _LIT(KFailed,"Password Failed at %d (%d,%d)"); |
|
256 buf.AppendFormat(KFailed,aWhere,iState,iPassState); |
|
257 Client()->LogMessage(buf); |
|
258 #endif |
|
259 iPasswordTestFailed=ETrue; |
|
260 Request(); |
|
261 } |
|
262 |
|
263 void CPasswordTest::TurnOffAndOn() |
|
264 { |
|
265 /*#if defined(LOG_TESTS) |
|
266 TLogMessageText buf; |
|
267 _LIT(KSettingTime,"Setting Off Timer"); |
|
268 buf.Append(KSettingTime); |
|
269 Client()->LogMessage(buf); |
|
270 #endif*/ |
|
271 RTimer timer; |
|
272 timer.CreateLocal(); |
|
273 TTime time; |
|
274 time.HomeTime(); |
|
275 time+=TTimeIntervalSeconds(7); // For some reason the O/S won't switch off for less than 6 seconds |
|
276 TRequestStatus status; |
|
277 timer.At(status,time); |
|
278 UserHal::SwitchOff(); |
|
279 User::WaitForRequest(status); |
|
280 #if !defined(__WINS__) |
|
281 TRawEvent event; |
|
282 event.Set(TRawEvent::ESwitchOn); |
|
283 UserSvr::AddEvent(event); |
|
284 #endif |
|
285 /*#if defined(LOG_TESTS) |
|
286 TLogMessageText buf; |
|
287 _LIT(KTimerOff,"Timer Gone Off (P=%d,S=%d)"); |
|
288 buf.AppendFormat(KTimerOff,iState,iPassState); |
|
289 Client()->LogMessage(buf); |
|
290 #endif*/ |
|
291 } |
|
292 |
|
293 TPasswordState CPasswordTest::PasswordState() const |
|
294 { |
|
295 return(iPassState); |
|
296 } |
|
297 |
|
298 void CPasswordTest::SetPassState(TPasswordState aPassState) |
|
299 { |
|
300 iPassState=aPassState; |
|
301 iPassWin->DrawNow(); |
|
302 Client()->iWs.Flush(); |
|
303 /*#if defined(LOG_TESTS) |
|
304 TLogMessageText buf; |
|
305 _LIT(PassTestState,"Password Test(%d), State=%d"); |
|
306 buf.AppendFormat(PassTestState,iState,aPassState); |
|
307 Client()->LogMessage(buf); |
|
308 #endif*/ |
|
309 switch(aPassState) |
|
310 { |
|
311 case EWaitForSwitchOff: |
|
312 case EWaitForSwitchOff2: |
|
313 case EWaitForSwitchOff3: |
|
314 case EWaitForSwitchOff4: |
|
315 case EWaitForSwitchOff5: |
|
316 TurnOffAndOn(); |
|
317 break; |
|
318 default:; |
|
319 } |
|
320 } |
|
321 |
|
322 void CPasswordTest::SwitchOn() |
|
323 { |
|
324 /*#if defined(LOG_TESTS) |
|
325 TLogMessageText buf; |
|
326 _LIT(KTimerOff,"Switch On (P=%d,S=%d)"); |
|
327 buf.AppendFormat(KTimerOff,iState,iPassState); |
|
328 Client()->LogMessage(buf); |
|
329 #endif*/ |
|
330 switch (iPassState) |
|
331 { |
|
332 case EWaitForSwitchOff: |
|
333 SetPassState(EWaitForEnter); |
|
334 break; |
|
335 case EWaitForSwitchOff2: |
|
336 SetPassState(EWaitForSwitchOff3); |
|
337 break; |
|
338 case EWaitForSwitchOff3: |
|
339 SetPassState(EWaitForSwitchOff4); |
|
340 break; |
|
341 case EWaitForSwitchOff4: |
|
342 { |
|
343 SetPassState(EWaitForSwitchOff5); |
|
344 TTime time; |
|
345 time.HomeTime(); |
|
346 time+=TTimeIntervalHours(24); |
|
347 User::SetHomeTime(time); |
|
348 } |
|
349 break; |
|
350 case EWaitForSwitchOff5: |
|
351 SetPassState(EWaitForEnter2); |
|
352 break; |
|
353 default:; |
|
354 } |
|
355 } |
|
356 |
|
357 void CPasswordTest::PasswordMsgReceivedL() |
|
358 { |
|
359 TestL(iPassWin->BaseWin()->OrdinalPosition()==0); |
|
360 if (iPassState==EWaitForSwitchOff3 || iPassState==EWaitForSwitchOff4) |
|
361 Fail(3); |
|
362 } |
|
363 |
|
364 void CPasswordTest::EnterKeyPressed(TPasswordState aNewState) |
|
365 { |
|
366 iPassWin->BaseWin()->SetOrdinalPosition(-1); |
|
367 SetPassState(aNewState); |
|
368 Client()->iWs.PasswordEntered(); |
|
369 } |
|
370 |
|
371 void CPasswordTest::TestComplete(TPasswordState aNewState) |
|
372 { |
|
373 Request(); |
|
374 SetPassState(aNewState); |
|
375 iPassState=aNewState; |
|
376 } |
|
377 |
|
378 void CPasswordTest::ConstructL() |
|
379 { |
|
380 iGroup2=new(ELeave) CPasswordWindowGroup2(Client(),this); |
|
381 iGroup2->ConstructL(); |
|
382 iGroup=new(ELeave) CPasswordWindowGroup(Client(),this); |
|
383 iGroup->ConstructL(); |
|
384 iPassWin=new(ELeave) CPasswordWindow(this); |
|
385 iPassWin->ConstructL(*iGroup); |
|
386 iPassWin->AssignGC(*Client()->iGc); |
|
387 iPassWin->Activate(); |
|
388 iBlankWin=new(ELeave) CTBlankWindow(); |
|
389 iBlankWin->ConstructL(*iGroup); |
|
390 iBlankWin->SetVisible(EFalse); |
|
391 iBlankWin->Activate(); |
|
392 iState=ENotStarted; |
|
393 } |
|
394 |
|
395 void CPasswordTest::StartMainPasswordTestL() |
|
396 { |
|
397 if (iPassWin->BaseWin()->PasswordWindow(EPasswordAlways)!=KErrNone) |
|
398 { |
|
399 DisplayDialog(_L("Can't do password tests"),_L("Password window"),_L("already exists"), Client()->iGroup->GroupWin()); |
|
400 AbortL(); |
|
401 } |
|
402 SetPassState(EWaitForSwitchOff); |
|
403 } |
|
404 |
|
405 void CPasswordTest::StartOnceADayPasswordTestL() |
|
406 { |
|
407 TestL(iPassWin->BaseWin()->PasswordWindow(EPasswordOnceADay)==KErrNone); |
|
408 } |
|
409 |
|
410 TestState CPasswordTest::DoTestL() |
|
411 { |
|
412 if (iPasswordTestFailed) |
|
413 TestL(ETrue); |
|
414 switch(iState) |
|
415 { |
|
416 case 0: |
|
417 LogSubTest(_L("Password 1"),1); |
|
418 StartMainPasswordTestL(); |
|
419 iState++; |
|
420 return(EContinue); |
|
421 case 1: |
|
422 LogSubTest(_L("Password 2"),2); |
|
423 StartOnceADayPasswordTestL(); |
|
424 iState++; |
|
425 return(EContinue); |
|
426 default: |
|
427 return(EFinished); |
|
428 } |
|
429 } |