|
1 // Copyright (c) 2010 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 // YShifting, Wserv gradual reduction of YOffset test code |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include "PARSEINIDATA.H" |
|
25 #include "tptroffset.h" |
|
26 #include <e32cmn.h> |
|
27 #include <hal.h> |
|
28 |
|
29 //#define FAILLOG 1 // Uncomment this code to get detailed log |
|
30 |
|
31 //CTPointerOffsetBuffer |
|
32 CTPointerOffsetBuffer::CTPointerOffsetBuffer(RWsSession *aWs, CTPointerOffsetTest *aTest, CTPointerOffsetClient* aClient) |
|
33 : CTEvent(aWs), iTest(aTest), iClient(aClient) |
|
34 { |
|
35 } |
|
36 |
|
37 CTPointerOffsetBuffer::~CTPointerOffsetBuffer() |
|
38 { |
|
39 } |
|
40 |
|
41 void CTPointerOffsetBuffer::ConstructL() |
|
42 { |
|
43 CTEventBase::Construct(); |
|
44 iEventBuffer.SetLengthL(EEventBufferSize); |
|
45 } |
|
46 |
|
47 void CTPointerOffsetBuffer::AddExpectedEvent(TWsEvent &aEvent) |
|
48 { |
|
49 iEventBuffer.Add(&aEvent); |
|
50 } |
|
51 |
|
52 TInt CTPointerOffsetBuffer::EventsRemaining() |
|
53 { |
|
54 return iEventBuffer.Count(); |
|
55 } |
|
56 |
|
57 |
|
58 // Main function which gets the event, checks with the event in buffer |
|
59 // Then calls function NextSetOfEventsL for running other tests of a particualar test case |
|
60 void CTPointerOffsetBuffer::doRunL() |
|
61 { |
|
62 // Get the event from wserv |
|
63 TWsEvent wsEvent; |
|
64 iWs->GetEvent(wsEvent); |
|
65 |
|
66 TWsEvent expectedEvent; |
|
67 TInt wsType=wsEvent.Type(); |
|
68 |
|
69 // if this is called accidentally |
|
70 TInt count=iEventBuffer.Count(); |
|
71 if (count==0 && wsType==EEventFocusGained) |
|
72 { |
|
73 goto End; |
|
74 } |
|
75 |
|
76 iEventBuffer.Remove(&expectedEvent); |
|
77 iEventCount++; |
|
78 |
|
79 #if defined(FAILLOG) |
|
80 TLogMessageText logText; |
|
81 _LIT(KEventCountCheck, "Checking event number = %d"); |
|
82 logText.Format(KEventCountCheck, iEventCount); |
|
83 iTest->LOG_MESSAGE(logText); |
|
84 _LIT(KEventType, "Actual Event type from Wserv = %d Expected Event Type = %d "); |
|
85 logText.Format(KEventType, wsEvent.Type(), expectedEvent.Type()); |
|
86 iTest->LOG_MESSAGE(logText); |
|
87 #endif |
|
88 |
|
89 TestL(wsEvent.Type() == expectedEvent.Type()); |
|
90 |
|
91 #if defined(FAILLOG) |
|
92 _LIT(KEventHandle, "Actual Window Handle from Wserv = %d Expected Window Handle = %d "); |
|
93 logText.Format(KEventHandle, wsEvent.Handle(), expectedEvent.Handle()); |
|
94 iTest->LOG_MESSAGE(logText); |
|
95 #endif |
|
96 TestL(wsEvent.Handle() == expectedEvent.Handle()); |
|
97 |
|
98 TAdvancedPointerEvent *expectedPointerEvent = expectedEvent.Pointer(); |
|
99 TAdvancedPointerEvent *actualPointerEvent = wsEvent.Pointer(); |
|
100 |
|
101 if (wsType == EEventPointer) |
|
102 { |
|
103 #if defined(FAILLOG) |
|
104 _LIT(KPointerType, "Actual PointerType from Wserv = %d Expected PointerType = %d "); |
|
105 logText.Format(KPointerType, actualPointerEvent->iType, expectedPointerEvent->iType); |
|
106 iTest->LOG_MESSAGE(logText); |
|
107 #endif |
|
108 TestL(actualPointerEvent->iType == expectedPointerEvent->iType); |
|
109 |
|
110 #if defined(FAILLOG) |
|
111 _LIT(KPointerPosition, "Actual PointerPosition from Wserv = (%d, %d) Expected PointerPosition = (%d, %d) "); |
|
112 logText.Format(KPointerPosition, actualPointerEvent->iPosition.iX, actualPointerEvent->iPosition.iY, expectedPointerEvent->iPosition.iX, expectedPointerEvent->iPosition.iY); |
|
113 iTest->LOG_MESSAGE(logText); |
|
114 #endif |
|
115 TestL(actualPointerEvent->iPosition == expectedPointerEvent->iPosition); |
|
116 |
|
117 #if defined(FAILLOG) |
|
118 _LIT(KPointerNumber, "Actual PointerNumber from Wserv = %d Expected PointerNumber = %d "); |
|
119 logText.Format(KPointerNumber, actualPointerEvent->PointerNumber(), expectedPointerEvent->PointerNumber()); |
|
120 iTest->LOG_MESSAGE(logText); |
|
121 #endif |
|
122 TestL(actualPointerEvent->PointerNumber() == expectedPointerEvent->PointerNumber()); |
|
123 } |
|
124 |
|
125 End: |
|
126 // Call NextSetOfEvents() when all the events have been checked |
|
127 if (iEventBuffer.Count()==0) |
|
128 { |
|
129 iTest->NextSetOfEventsL(); // Cannot Leave |
|
130 } |
|
131 } |
|
132 |
|
133 void CTPointerOffsetBuffer::TestL(TInt aTest) |
|
134 { |
|
135 if (!aTest) |
|
136 { |
|
137 iTest->Failed(); |
|
138 User::Leave(ETestFailed); |
|
139 } |
|
140 } |
|
141 |
|
142 //CTPointerOffsetClient |
|
143 CTPointerOffsetClient::CTPointerOffsetClient(CTPointerOffsetTest *aTest) |
|
144 : iTest(aTest) |
|
145 { |
|
146 } |
|
147 |
|
148 CTPointerOffsetClient::~CTPointerOffsetClient() |
|
149 { |
|
150 delete iWin; |
|
151 } |
|
152 |
|
153 void CTPointerOffsetClient::ConstructL() |
|
154 { |
|
155 CTClient::ConstructL(); |
|
156 |
|
157 // Create a group window and assign it iGroup |
|
158 iGroup = new(ELeave) CTWindowGroup(this); |
|
159 iGroup->ConstructL(); |
|
160 |
|
161 iWinSize = iScreen->SizeInPixels(); |
|
162 iWinPos = TPoint(); |
|
163 |
|
164 // Create window for this client so that events can come to this client |
|
165 iWin=new(ELeave) CTBlankWindow(); |
|
166 iWin->ConstructL(*iGroup); |
|
167 iWin->SetExt(iWinPos, iWinSize); |
|
168 iWin->SetColor(KRgbRed); |
|
169 iWin->BaseWin()->EnableAdvancedPointers(); |
|
170 iWin->Activate(); |
|
171 iWs.Flush(); |
|
172 } |
|
173 |
|
174 void CTPointerOffsetClient::AddExpectedPointerEvent(TPointerEvent::TType aType, TPoint aPos, TUint8 aPointerNumber, TUint aHandle) |
|
175 { |
|
176 TWsEvent ptrEvent; |
|
177 ptrEvent.SetType(EEventPointer); |
|
178 ptrEvent.Pointer()->iParentPosition = aPos; |
|
179 ptrEvent.Pointer()->iType = aType; |
|
180 ptrEvent.Pointer()->iPosition = aPos; |
|
181 ptrEvent.SetPointerNumber(aPointerNumber); |
|
182 if (!aHandle) |
|
183 ptrEvent.SetHandle((TUint)iWin); |
|
184 else |
|
185 ptrEvent.SetHandle(aHandle); |
|
186 |
|
187 static_cast<CTPointerOffsetBuffer*>(iEventHandler)->AddExpectedEvent(ptrEvent); |
|
188 } |
|
189 |
|
190 void CTPointerOffsetClient::AddExpectedWsEvent(TEventCode aType, TInt /*aPointerNumber*/, TUint aHandle) |
|
191 { |
|
192 TWsEvent ptrEvent; |
|
193 ptrEvent.SetType(aType); |
|
194 if (!aHandle) |
|
195 ptrEvent.SetHandle((TUint)iGroup); |
|
196 else |
|
197 ptrEvent.SetHandle(aHandle); |
|
198 static_cast<CTPointerOffsetBuffer*>(iEventHandler)->AddExpectedEvent(ptrEvent); |
|
199 } |
|
200 |
|
201 // Create and store CTPointerOffsetBuffer in iEventHandler |
|
202 void CTPointerOffsetClient::ConstructEventHandlerL() |
|
203 { |
|
204 CTPointerOffsetBuffer* eventBufferAndHandler = new(ELeave) CTPointerOffsetBuffer(&iWs, iTest, this); |
|
205 eventBufferAndHandler->ConstructL(); |
|
206 iEventHandler = eventBufferAndHandler; |
|
207 } |
|
208 |
|
209 //CTPointerOffsetTest |
|
210 CTPointerOffsetTest::CTPointerOffsetTest(CTestStep* aStep) |
|
211 : CTWsGraphicsBase(aStep) |
|
212 { |
|
213 } |
|
214 |
|
215 CTPointerOffsetTest::~CTPointerOffsetTest() |
|
216 { |
|
217 delete iPointerOffsetClient; |
|
218 } |
|
219 |
|
220 void CTPointerOffsetTest::ConstructL() |
|
221 { |
|
222 // If YOffsetValues are not defined in wsini file then just return without doing anything |
|
223 _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini"); |
|
224 CIniData* iniData = CIniData::NewL(KWsIniFile, ' '); |
|
225 _LIT( KWsiniYShiftingTop, "YSHIFTINGTOP"); |
|
226 if (iniData->FindVar(KWsiniYShiftingTop, iYOffsetTop) == EFalse) |
|
227 goto FAIL; |
|
228 _LIT( KWsiniYShiftingBottom, "YSHIFTINGBOTTOM"); |
|
229 if (iniData->FindVar(KWsiniYShiftingBottom, iYOffsetBottom) == EFalse) |
|
230 goto FAIL; |
|
231 _LIT( KWsiniYShiftingMax, "YSHIFTINGMAX"); |
|
232 if (iniData->FindVar(KWsiniYShiftingMax, iYOffsetMax) == EFalse) |
|
233 goto FAIL; |
|
234 delete iniData; |
|
235 |
|
236 if (!iYOffsetTop || !iYOffsetBottom || !iYOffsetMax) |
|
237 { |
|
238 FAIL: |
|
239 delete iniData; |
|
240 TLogMessageText logText1; |
|
241 _LIT(KWrongHALConfig, "Y Offset values are incorrect. \n"); |
|
242 logText1.Append(KWrongHALConfig); |
|
243 LOG_MESSAGE(logText1); |
|
244 TEST(EFalse); |
|
245 User::Leave(KErrArgument); |
|
246 } |
|
247 iPhysicalScreenSize = TheClient->iScreen->SizeInPixels(); |
|
248 |
|
249 // If we fail to get the maxpointernumber then just test with single pointer |
|
250 TInt ret = HAL::Get(HALData::EPointerMaxPointers, iMaxPointerNumbers); |
|
251 if (ret != KErrNone || iMaxPointerNumbers < 2 || iMaxPointerNumbers > 8) |
|
252 { |
|
253 iMaxPointerNumbers = 1; |
|
254 } |
|
255 } |
|
256 |
|
257 // Common function for all tests |
|
258 // Important point to remember is that this function should not leave when running tests |
|
259 void CTPointerOffsetTest::NextSetOfEventsL() |
|
260 { |
|
261 // For each test case calls its respective tests |
|
262 switch (iTest->iState) |
|
263 { |
|
264 case 0: |
|
265 TestYOffsetValues(); |
|
266 break; |
|
267 case 1: |
|
268 TestYOffsetValues(); |
|
269 break; |
|
270 default: |
|
271 AutoPanic(EAutoPanicWrongTest); |
|
272 } |
|
273 } |
|
274 |
|
275 void CTPointerOffsetTest::SimulatePointerEvent(TRawEvent::TType aType, TInt aX, TInt aY, TUint8 aPointerNumber) |
|
276 { |
|
277 TRawEvent rawEvent; |
|
278 rawEvent.Set(aType, aX, aY, 0, aPointerNumber); |
|
279 UserSvr::AddEvent(rawEvent); |
|
280 } |
|
281 |
|
282 void CTPointerOffsetTest::AddExpectedPointerEvent(TPointerEvent::TType aType, TInt aX, TInt aY, TUint8 aPointerNumber, TUint aHandle) |
|
283 { |
|
284 iPointerOffsetClient->AddExpectedPointerEvent(aType, TPoint(aX, aY), aPointerNumber, aHandle); |
|
285 } |
|
286 |
|
287 void CTPointerOffsetTest::AddExpectedWsEvent(TEventCode aType, TInt aPointerNumber, TUint aHandle) |
|
288 { |
|
289 iPointerOffsetClient->AddExpectedWsEvent(aType, aPointerNumber, aHandle); |
|
290 } |
|
291 |
|
292 // If any of the Tests fails, bring the wserv in a consistent state for other test to run, |
|
293 // stop ActiveScheduler and display some logs where the fail occured. |
|
294 void CTPointerOffsetTest::Failed() |
|
295 { |
|
296 // Display the test case number, subtest case number and number of events left in the buffer which can be used to |
|
297 // find out which event actually caused the failure when any test fails |
|
298 TLogMessageText logText1; |
|
299 _LIT(KEventsAdded, "Test case number %d Sub test case number %d Events remaining in the buffer %d \n"); |
|
300 logText1.AppendFormat(KEventsAdded, iTest->iState, iEventSet, iPointerOffsetClient->EventBuffer()->EventsRemaining()); |
|
301 LOG_MESSAGE(logText1); |
|
302 RDebug::Printf("Test case number %d Sub test case number %d Events remaining in the buffer %d \n", iTest->iState, iEventSet, iPointerOffsetClient->EventBuffer()->EventsRemaining()); |
|
303 |
|
304 CActiveScheduler::Stop(); |
|
305 iFailed=ETrue; |
|
306 } |
|
307 |
|
308 // Get YValue after applying YOffset using iYOffsetTop, iYOffsetBottom and iYOffsetMax variables. |
|
309 // Depending upon the Y poistion of input, yOffset is gradually reduced from top of the screen to |
|
310 // bottom of the screen. |
|
311 TInt CTPointerOffsetTest::GetShiftedYValue(TInt aY) |
|
312 { |
|
313 if (!iYOffsetTop || !iYOffsetMax || !iYOffsetBottom) |
|
314 return aY; |
|
315 |
|
316 TInt offset = 0; |
|
317 TInt returnValue = aY; |
|
318 TInt displayHeight = TheClient->iScreen->SizeInPixels().iHeight; |
|
319 if (aY >= iYOffsetMax) |
|
320 { |
|
321 // Gradual reduction of Yoffset depending upon the aY value |
|
322 offset = iYOffsetTop + iYOffsetBottom - (iYOffsetTop * aY / displayHeight ); |
|
323 if ( offset > iYOffsetMax ) |
|
324 { |
|
325 offset = iYOffsetMax; |
|
326 } |
|
327 returnValue -= offset; |
|
328 if (returnValue > (displayHeight-1)) |
|
329 { |
|
330 returnValue = displayHeight-1; |
|
331 } |
|
332 } |
|
333 else |
|
334 { |
|
335 returnValue = 0; |
|
336 } |
|
337 |
|
338 return returnValue; |
|
339 } |
|
340 |
|
341 // Common function for all test cases |
|
342 void CTPointerOffsetTest::RunTestsL() |
|
343 { |
|
344 // Create CTPointerOffsetClient for each test case and call NextSetOfEventsL() |
|
345 iPointerOffsetClient = new(ELeave) CTPointerOffsetClient(this); |
|
346 iPointerOffsetClient->SetScreenNumber(iTest->iScreenNumber); |
|
347 iPointerOffsetClient->ConstructL(); |
|
348 |
|
349 iEventSet=0; |
|
350 |
|
351 TRAPD(err, NextSetOfEventsL()); |
|
352 if (err != KErrNone) |
|
353 { |
|
354 iFailed = ETrue; |
|
355 } |
|
356 |
|
357 // Start nested activescheduler if it is not failed |
|
358 if (!iFailed) |
|
359 { |
|
360 CActiveScheduler::Start(); |
|
361 } |
|
362 |
|
363 TInt eventsRem = iPointerOffsetClient->EventBuffer()->EventsRemaining(); |
|
364 if (eventsRem > 0) |
|
365 { |
|
366 iFailed=ETrue; |
|
367 } |
|
368 |
|
369 delete iPointerOffsetClient; |
|
370 iPointerOffsetClient = NULL; |
|
371 } |
|
372 |
|
373 // This function is called by TestExecute Framework, through which all the testcases are run |
|
374 void CTPointerOffsetTest::RunTestCaseL(TInt /*aCurTestCase*/) |
|
375 { |
|
376 _LIT(KTest0, "PointerOffset tests"); |
|
377 _LIT(KTest1, "PointerOffset tests for other pointer"); |
|
378 |
|
379 switch(iTest->iState) |
|
380 { |
|
381 case 0: |
|
382 iTest->LogSubTest(KTest0); |
|
383 iPointerNumber = 0; |
|
384 RunTestsL(); |
|
385 break; |
|
386 case 1: |
|
387 if (iMaxPointerNumbers == 1) |
|
388 { |
|
389 TestComplete(); |
|
390 } |
|
391 else |
|
392 { |
|
393 iTest->LogSubTest(KTest1); |
|
394 iPointerNumber = iMaxPointerNumbers-1; |
|
395 RunTestsL(); |
|
396 } |
|
397 break; |
|
398 case 2: |
|
399 // Keep this code in last case statement for main test completion |
|
400 TestComplete(); |
|
401 break; |
|
402 default: |
|
403 AutoPanic(EAutoPanicWrongTest); |
|
404 } |
|
405 |
|
406 // |
|
407 if (iFailed) |
|
408 { |
|
409 TEST(EFalse); |
|
410 iFailed=EFalse; |
|
411 } |
|
412 ++iTest->iState; |
|
413 } |
|
414 |
|
415 |
|
416 void CTPointerOffsetTest::TestYOffsetValues() |
|
417 { |
|
418 TLogMessageText logText; |
|
419 _LIT(KSet, "Offset tests number : %d of 5"); |
|
420 logText.AppendFormat(KSet, iEventSet); |
|
421 LOG_MESSAGE(logText); |
|
422 |
|
423 TPoint simulatedPos(iPhysicalScreenSize.iWidth/2, iPhysicalScreenSize.iHeight/2); |
|
424 TPoint expectedPos(simulatedPos); |
|
425 switch(iEventSet++) |
|
426 { |
|
427 case 0: |
|
428 // Test any point which has Y value less than YOffsetMax, where Y position would be 0 |
|
429 simulatedPos.iY = iYOffsetMax - 1; |
|
430 SimulatePointerEvent(TRawEvent::EButton1Down, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
431 SimulatePointerEvent(TRawEvent::EButton1Up, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
432 |
|
433 expectedPos.iY = 0; |
|
434 AddExpectedWsEvent(EEventFocusGained); |
|
435 AddExpectedPointerEvent(TPointerEvent::EButton1Down, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
436 AddExpectedPointerEvent(TPointerEvent::EButton1Up, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
437 break; |
|
438 case 1: |
|
439 // Test any point which has Y value just over YOffsetMax |
|
440 simulatedPos.iY = iYOffsetMax + 1; |
|
441 SimulatePointerEvent(TRawEvent::EButton1Down, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
442 SimulatePointerEvent(TRawEvent::EButton1Up, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
443 |
|
444 expectedPos.iY = GetShiftedYValue(simulatedPos.iY); |
|
445 AddExpectedPointerEvent(TPointerEvent::EButton1Down, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
446 AddExpectedPointerEvent(TPointerEvent::EButton1Up, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
447 break; |
|
448 case 2: |
|
449 // Test any point which has Y value middle of the screen |
|
450 SimulatePointerEvent(TRawEvent::EButton1Down, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
451 SimulatePointerEvent(TRawEvent::EButton1Up, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
452 |
|
453 expectedPos.iY = GetShiftedYValue(simulatedPos.iY); |
|
454 AddExpectedPointerEvent(TPointerEvent::EButton1Down, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
455 AddExpectedPointerEvent(TPointerEvent::EButton1Up, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
456 break; |
|
457 case 3: |
|
458 // Test any point which has Y value less than bottommost of the screen |
|
459 simulatedPos.iY = iPhysicalScreenSize.iHeight - 10; |
|
460 SimulatePointerEvent(TRawEvent::EButton1Down, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
461 SimulatePointerEvent(TRawEvent::EButton1Up, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
462 |
|
463 expectedPos.iY = GetShiftedYValue(simulatedPos.iY); |
|
464 AddExpectedPointerEvent(TPointerEvent::EButton1Down, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
465 AddExpectedPointerEvent(TPointerEvent::EButton1Up, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
466 break; |
|
467 case 4: |
|
468 // Test any point which has Y value at bottom of the screen |
|
469 // As pixels are zero counted and so it cannot be >= iPhysicalScreenSize.iHeight |
|
470 simulatedPos.iY = iPhysicalScreenSize.iHeight-1; |
|
471 SimulatePointerEvent(TRawEvent::EButton1Down, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
472 SimulatePointerEvent(TRawEvent::EButton1Up, simulatedPos.iX, simulatedPos.iY, iPointerNumber); |
|
473 |
|
474 expectedPos.iY = GetShiftedYValue(simulatedPos.iY); |
|
475 AddExpectedPointerEvent(TPointerEvent::EButton1Down, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
476 AddExpectedPointerEvent(TPointerEvent::EButton1Up, expectedPos.iX, expectedPos.iY, iPointerNumber); |
|
477 break; |
|
478 default: |
|
479 CActiveScheduler::Stop(); |
|
480 } |
|
481 } |
|
482 // Macro which is used for construction of CTPointerOffsetTestStep object |
|
483 // and also used to call CreateTestL() which creates CTPointerOffsetTest and CTestBase objects |
|
484 __WS_CONSTRUCT_STEP__(PointerOffsetTest) |