|
1 // Copyright (c) 1995-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 // Manual window server tests |
|
15 // Note: Wherever possible tests should be put into the TAUTO automatic test |
|
16 // code test should only go here when manual operation is essential |
|
17 // |
|
18 // |
|
19 |
|
20 #include <e32std.h> |
|
21 #include "W32STD.H" |
|
22 #include <e32svr.h> |
|
23 #include "TMAN.H" |
|
24 |
|
25 #define LOG_TESTS |
|
26 |
|
27 class ErrorDialog : public CTDialog |
|
28 { |
|
29 public: |
|
30 ErrorDialog(CTestBase *aTest); |
|
31 void ButtonPressL(TInt aButton); |
|
32 private: |
|
33 CTestBase *iTest; |
|
34 }; |
|
35 |
|
36 class TestWindowGroup : public CTWindowGroup |
|
37 { |
|
38 public: |
|
39 TestWindowGroup(CTClient *aClient); |
|
40 void ConstructL(); |
|
41 void KeyL(const TKeyEvent &aKey,const TTime &aTime); |
|
42 void KeyDownL(const TKeyEvent &aKey,const TTime &aTime); |
|
43 void KeyUpL(const TKeyEvent &aKey,const TTime &aTime); |
|
44 }; |
|
45 |
|
46 class CTManScheduler : public CActiveScheduler |
|
47 { |
|
48 public: |
|
49 void SetClient(TestClient *aClient); |
|
50 void Error(TInt anError) const; |
|
51 private: |
|
52 void doErrorL(TInt anError) const; |
|
53 private: |
|
54 TestClient *iClient; |
|
55 }; |
|
56 |
|
57 typedef CTestBase *(*CTestBaseCreate)(); |
|
58 |
|
59 GLREF_C CTestBase *CreateScreenModeTest(); |
|
60 GLREF_C CTestBase *CreateScaleTest(); |
|
61 GLREF_C CTestBase *CreateTextTest(); |
|
62 GLREF_C CTestBase *CreateDummyTest(); |
|
63 GLREF_C CTestBase *CreateMultiConTest(); |
|
64 GLREF_C CTestBase *CreateMultiCaptureKeyTest(); |
|
65 GLREF_C CTestBase *CreateHotKeyTest(); |
|
66 GLREF_C CTestBase *CreatePointerTest(); |
|
67 GLREF_C CTestBase *CreatePointerCaptureTest(); |
|
68 GLREF_C CTestBase *CreatePointerBufferTest(); |
|
69 GLREF_C CTestBase *CreateModifiersChangedTest(); |
|
70 GLREF_C CTestBase *CreatePointerKeyTest(); |
|
71 GLREF_C CTestBase *CreatePasswordTest(); |
|
72 GLREF_C CTestBase *CreatePointerCursorTest(); |
|
73 GLREF_C CTestBase *CreateScreenModeTimes(); |
|
74 |
|
75 // Tests that have not been converted to tauto yet |
|
76 CTestBaseCreate CreateTestClass[]={ |
|
77 CreateScreenModeTimes, |
|
78 CreatePointerCursorTest, |
|
79 CreatePointerTest, //Mostly converted |
|
80 CreatePointerKeyTest, //Mostly converted |
|
81 CreateModifiersChangedTest, //Partially Conerted |
|
82 CreatePointerBufferTest, |
|
83 CreateTextTest, |
|
84 CreateScaleTest, |
|
85 CreateDummyTest, |
|
86 }; |
|
87 |
|
88 LogWindow *LogWin; |
|
89 |
|
90 void TManPanic(TInt aPanic) |
|
91 { |
|
92 User::Panic(_L("Auto"),aPanic); |
|
93 } |
|
94 |
|
95 // |
|
96 // Log window, logs testing // |
|
97 // |
|
98 |
|
99 LogWindow::LogWindow() : CTWin() |
|
100 { |
|
101 } |
|
102 |
|
103 void LogWindow::ConstructL(CTWinBase &parent) |
|
104 { |
|
105 CTWin::ConstructL(parent); |
|
106 iTitleHeight=iFont->HeightInPixels()+4; |
|
107 } |
|
108 |
|
109 void LogWindow::Draw() |
|
110 { |
|
111 iGc->SetPenColor(TRgb::Gray16(8)); |
|
112 iGc->SetPenColor(TRgb::Gray16(0)); |
|
113 DrawBorder(); |
|
114 iGc->DrawLine(TPoint(0,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight)); |
|
115 iGc->DrawText(iTestTitle, TPoint((iSize.iWidth-iFont->TextWidthInPixels(iTestTitle))/2,iFont->AscentInPixels()+2)); |
|
116 } |
|
117 |
|
118 void LogWindow::LogTest(TDesC &aTitle,TInt aNum) |
|
119 { |
|
120 iTestTitle.Format(TRefByValue<const TDesC>(_L("Test %d,%S")),aNum,&aTitle); |
|
121 iWin.Invalidate(); |
|
122 Client()->iWs.Flush(); |
|
123 } |
|
124 |
|
125 // |
|
126 // Test window, simple window used to do test graphics in // |
|
127 // |
|
128 TestWindow::TestWindow() : CTWin() |
|
129 { |
|
130 } |
|
131 |
|
132 void TestWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) |
|
133 { |
|
134 iBorderWin=new(ELeave) BorderWindow(); |
|
135 iBorderWin->SetUpL(pos,size,parent,aGc); |
|
136 CTWin::ConstructExtLD(*iBorderWin,TPoint(2,2),TSize(size.iWidth-4,size.iHeight-4)); |
|
137 Activate(); |
|
138 AssignGC(aGc); |
|
139 } |
|
140 |
|
141 void TestWindow::Draw() |
|
142 { |
|
143 iGc->Clear(); |
|
144 } |
|
145 |
|
146 // |
|
147 BorderWindow::BorderWindow() : CTWin() |
|
148 { |
|
149 } |
|
150 |
|
151 void BorderWindow::ConstructL(CTWinBase &parent) |
|
152 { |
|
153 CTWin::ConstructL(parent); |
|
154 } |
|
155 |
|
156 void BorderWindow::Draw() |
|
157 { |
|
158 iGc->SetBrushColor(TRgb::Gray16(0)); |
|
159 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
160 iGc->SetPenStyle(CGraphicsContext::ENullPen); |
|
161 iGc->DrawRect(TRect(Size())); |
|
162 } |
|
163 |
|
164 // |
|
165 |
|
166 TestWindowGroup::TestWindowGroup(CTClient *aClient) : CTWindowGroup(aClient) |
|
167 { |
|
168 } |
|
169 |
|
170 void TestWindowGroup::ConstructL() |
|
171 { |
|
172 CTWindowGroup::ConstructL(); |
|
173 GroupWin()->EnableScreenChangeEvents(); |
|
174 } |
|
175 |
|
176 void TestWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &aTime) |
|
177 { |
|
178 if (iCurWin) |
|
179 iCurWin->KeyDownL(aKey,aTime); |
|
180 } |
|
181 |
|
182 void TestWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &aTime) |
|
183 { |
|
184 if (iCurWin) |
|
185 iCurWin->KeyUpL(aKey,aTime); |
|
186 } |
|
187 |
|
188 void TestWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime) |
|
189 { |
|
190 if (aKey.iModifiers&EModifierFunc) |
|
191 { |
|
192 switch(aKey.iCode) |
|
193 { |
|
194 case 'f': |
|
195 ((TestClient *)Client())->Driver()->iTest->TriggerFail(); |
|
196 break; |
|
197 } |
|
198 } |
|
199 else if (iCurWin) |
|
200 iCurWin->WinKeyL(aKey,aTime); |
|
201 } |
|
202 |
|
203 // |
|
204 |
|
205 TestClient::TestClient() |
|
206 { |
|
207 } |
|
208 |
|
209 void TestClient::ConstructL() |
|
210 { |
|
211 CTClient::ConstructL(); |
|
212 |
|
213 iGroup=new(ELeave) TestWindowGroup(this); |
|
214 iGroup->ConstructL(); |
|
215 |
|
216 TSize screenSize=iGroup->Size(); |
|
217 TInt winWidth=(screenSize.iWidth/3)-10; |
|
218 TInt winHeight=screenSize.iHeight-10; |
|
219 LogWin=new(ELeave) LogWindow(); |
|
220 LogWin->SetUpL(TPoint(5+winWidth*2,5),TSize(winWidth,winHeight),iGroup,*iGc); |
|
221 iDriver=new(ELeave) TestDriver(this); |
|
222 } |
|
223 |
|
224 TestClient::~TestClient() |
|
225 { |
|
226 delete iDriver; |
|
227 } |
|
228 |
|
229 TestDriver *TestClient::Driver() |
|
230 { |
|
231 return(iDriver); |
|
232 } |
|
233 |
|
234 // |
|
235 // Error dialog // |
|
236 // |
|
237 |
|
238 ErrorDialog::ErrorDialog(CTestBase *aTest) : CTDialog(), iTest(aTest) |
|
239 {} |
|
240 |
|
241 void ErrorDialog::ButtonPressL(TInt aButton) |
|
242 { |
|
243 switch(aButton) |
|
244 { |
|
245 case 0: |
|
246 { |
|
247 CTestBase *test=iTest; |
|
248 CTDialog::Delete(this); |
|
249 if (test) |
|
250 test->Driver()->DestroyTest(); |
|
251 CActiveScheduler::Stop(); |
|
252 User::Leave(0); // Signals RunL not to do another request |
|
253 } |
|
254 break; |
|
255 case 1: |
|
256 CTestBase *test=iTest; |
|
257 CTDialog::Delete(this); |
|
258 if (test) |
|
259 { |
|
260 test->Driver()->TestComplete(); |
|
261 test->Driver()->DestroyTest(); |
|
262 } |
|
263 break; |
|
264 } |
|
265 } |
|
266 |
|
267 // |
|
268 // TestDriver, drives the test code // |
|
269 // |
|
270 |
|
271 TestDriver::TestDriver(TestClient *aClient) : CActive(-10), iClient(aClient) |
|
272 { |
|
273 CActiveScheduler::Add(this); |
|
274 Request(); |
|
275 } |
|
276 |
|
277 TestClient *TestDriver::Client() |
|
278 { |
|
279 return(iClient); |
|
280 } |
|
281 |
|
282 TestDriver::~TestDriver() |
|
283 { |
|
284 Cancel(); |
|
285 DestroyTest(); |
|
286 } |
|
287 |
|
288 void TestDriver::DoCancel() |
|
289 { |
|
290 TRequestStatus *pStat= &iStatus; |
|
291 RThread().RequestComplete(pStat,KErrCancel); |
|
292 } |
|
293 |
|
294 void TestDriver::Request() |
|
295 { |
|
296 TRequestStatus *pStat= &iStatus; |
|
297 RThread().RequestComplete(pStat,KErrNone); |
|
298 SetActive(); |
|
299 } |
|
300 |
|
301 void TestDriver::RunL() |
|
302 { |
|
303 iTest=(*CreateTestClass[iTestNum])(); |
|
304 iTest->StartTest(iTestNum,this); |
|
305 iTest->ConstructL(); |
|
306 } |
|
307 |
|
308 void TestDriver::TestComplete() |
|
309 { |
|
310 iTestNum++; |
|
311 if (iTestNum==sizeof(CreateTestClass)/sizeof(CreateTestClass[0])) |
|
312 { |
|
313 DisplayDialog(_L("Tests complete"),_L(""),_L("")); |
|
314 CActiveScheduler::Stop(); |
|
315 } |
|
316 else |
|
317 Request(); |
|
318 } |
|
319 |
|
320 void TestDriver::DestroyTest() |
|
321 { |
|
322 delete iTest; |
|
323 iTest=NULL; |
|
324 } |
|
325 |
|
326 // CTestBase // |
|
327 |
|
328 CTestBase::CTestBase(const TDesC &aTitle) : CActive(-10) |
|
329 { |
|
330 CActiveScheduler::Add(this); |
|
331 iTitle.Copy(aTitle); |
|
332 } |
|
333 |
|
334 CTestBase::~CTestBase() |
|
335 { |
|
336 User::Free(iBuf1); |
|
337 User::Free(iBuf2); |
|
338 Cancel(); |
|
339 } |
|
340 |
|
341 void CTestBase::DoCancel() |
|
342 { |
|
343 TRequestStatus *pStat= &iStatus; |
|
344 RThread().RequestComplete(pStat,KErrCancel); |
|
345 } |
|
346 |
|
347 void CTestBase::Request() |
|
348 { |
|
349 TRequestStatus *pStat= &iStatus; |
|
350 RThread().RequestComplete(pStat,KErrNone); |
|
351 SetActive(); |
|
352 } |
|
353 |
|
354 void CTestBase::TriggerFail() |
|
355 { |
|
356 iFail=ETrue; |
|
357 } |
|
358 |
|
359 TestClient *CTestBase::Client() |
|
360 { |
|
361 return(iDriver->Client()); |
|
362 } |
|
363 |
|
364 void CTestBase::LogLeave(TInt aErr) |
|
365 { |
|
366 #if defined(LOG_TESTS) |
|
367 TLogMessageText buf; |
|
368 _LIT(KLeave,"MAN Left with error code %d in sub-test %d: "); |
|
369 buf.AppendFormat(KLeave,aErr,iSubTestNum); |
|
370 buf.Append(iSubTitle); |
|
371 Client()->LogMessage(buf); |
|
372 #else |
|
373 aErr=KErrNone; //To stop a warning |
|
374 #endif |
|
375 } |
|
376 |
|
377 void CTestBase::RunL() |
|
378 { |
|
379 TInt ret=EInvalid; |
|
380 TRAPD(err,ret=DoTestL()); |
|
381 if (err!=KErrNone) |
|
382 { |
|
383 LogLeave(err); |
|
384 if (err!=ETestFailed) |
|
385 { |
|
386 User::Leave(err); |
|
387 } |
|
388 } |
|
389 else if (ret==EFinished) |
|
390 { |
|
391 iDriver->TestComplete(); |
|
392 iDriver->DestroyTest(); |
|
393 } |
|
394 else if (ret==ENext) |
|
395 Request(); |
|
396 } |
|
397 |
|
398 void CTestBase::StartTest(TInt aNum, TestDriver *aDriver) |
|
399 { |
|
400 iDriver=aDriver; |
|
401 iTestNum=aNum; |
|
402 LogWin->LogTest(iTitle,aNum); |
|
403 #if defined(LOG_TESTS) |
|
404 TLogMessageText buf; |
|
405 _LIT(ManNewTest,"MAN New Test %d: "); |
|
406 buf.AppendFormat(ManNewTest,aNum); |
|
407 buf.Append(iTitle); |
|
408 Client()->LogMessage(buf); |
|
409 #endif |
|
410 Request(); |
|
411 } |
|
412 |
|
413 void CTestBase::LogSubTest(const TDesC &aSubTitle,TInt aNum) |
|
414 { |
|
415 iSubTestNum=aNum; |
|
416 iSubTitle=aSubTitle; |
|
417 #if defined(LOG_TESTS) |
|
418 TLogMessageText buf; |
|
419 _LIT(ManSubTest,"MAN SubTest %d: "); |
|
420 buf.AppendFormat(ManSubTest,iSubTestNum); |
|
421 buf.Append(iSubTitle); |
|
422 Client()->LogMessage(buf); |
|
423 #endif |
|
424 } |
|
425 |
|
426 void CTestBase::AbortL() |
|
427 { |
|
428 TestDriver *driver=iDriver; |
|
429 iDriver->DestroyTest(); |
|
430 driver->TestComplete(); |
|
431 User::Leave(ETestFailed); |
|
432 } |
|
433 |
|
434 void CTestBase::TestL(TInt aCondition) |
|
435 { |
|
436 if (!aCondition || iFail) |
|
437 { |
|
438 iFail=EFalse; |
|
439 ErrorDialog *dialog=new ErrorDialog(this); |
|
440 if (dialog) |
|
441 { |
|
442 dialog->SetTitle(_L("Test failed")); |
|
443 dialog->SetNumButtons(2); |
|
444 dialog->SetButtonText(0,_L("Abort all tests")); |
|
445 dialog->SetButtonText(1,_L("Continue other tests")); |
|
446 dialog->ConstructLD(*Client()->iGroup,*Client()->iGc); |
|
447 dialog->Display(); |
|
448 } |
|
449 User::Leave(ETestFailed); |
|
450 } |
|
451 } |
|
452 |
|
453 void CTManScheduler::SetClient(TestClient *aClient) |
|
454 { |
|
455 iClient=aClient; |
|
456 } |
|
457 |
|
458 void CTManScheduler::Error(TInt aError) const |
|
459 { |
|
460 TRAP_IGNORE(doErrorL(aError)); |
|
461 CActiveScheduler::Stop(); |
|
462 } |
|
463 |
|
464 void CTManScheduler::doErrorL(TInt aError) const |
|
465 { |
|
466 CTDialog *dialog=new(ELeave) CTDialog(); |
|
467 if (dialog) |
|
468 { |
|
469 TWindowTitle title; |
|
470 title.Format(TRefByValue<const TDesC>(_L("Error %d")),aError); |
|
471 dialog->SetTitle(title); |
|
472 dialog->SetNumButtons(1); |
|
473 dialog->SetButtonText(0,_L("Abort tests")); |
|
474 dialog->ConstructLD(*iClient->iGroup,*iClient->iGc); |
|
475 dialog->Display(); |
|
476 } |
|
477 } |
|
478 |
|
479 // |
|
480 |
|
481 GLDEF_C CTClient *CreateClientL() |
|
482 { |
|
483 return(new(ELeave) TestClient()); |
|
484 } |
|
485 |
|
486 |
|
487 GLDEF_C TInt E32Main() |
|
488 { |
|
489 return(TestLibStartUp(CreateClientL)); |
|
490 } |