Update contrib.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Advanced pointer event unit tests
21 @internalComponent - Internal Symbian test code
24 #include "tadvancedpointerevent.h"
26 CTAdvancedPointerEvent::CTAdvancedPointerEvent(CTestStep* aStep)
27 : CTWsGraphicsBase(aStep)
30 CTAdvancedPointerEvent::~CTAdvancedPointerEvent()
33 void CTAdvancedPointerEvent::TestPointerEventInit()
35 // Test size of class with hard coded values to prevent regression failure
36 TEST(sizeof(TPointerEvent) == 24);
38 TPointerEvent ptrEvent1 = TPointerEvent();
39 ptrEvent1.iType = TPointerEvent::EButton1Down;
40 TPoint initCoords(10,10);
41 ptrEvent1.iPosition = initCoords;
42 ptrEvent1.iParentPosition = initCoords;
43 ptrEvent1.iModifiers = 0;
45 // Construct two TPointerEvent objects. The first using default constructor, the second using the copy constructor. T
47 TPointerEvent ptrEvent2 = TPointerEvent(ptrEvent1);
48 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&ptrEvent1),sizeof(TPointerEvent),reinterpret_cast<TUint8*>(&ptrEvent2),sizeof(TPointerEvent)));
52 TPointerEvent ptrEvent2(TPointerEvent::EButton1Down, 0, initCoords, initCoords);
53 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&ptrEvent1),sizeof(TPointerEvent),reinterpret_cast<TUint8*>(&ptrEvent2),sizeof(TPointerEvent)));
57 void AdvancedPointerInit(TWsEvent& aEvent1, TWsEvent& aEvent2, const TPointerEvent::TType aType, const TPoint3D& aPoint3D, const TUint8 aPointerNumber)
60 TAdvancedPointerEvent& ptrEvent = *aEvent1.Pointer();
61 ptrEvent.iType = aType;
62 ptrEvent.iModifiers = EModifierAdvancedPointerEvent; // done implicitly by TAdvancedPointerEvent::Init method
63 ptrEvent.iPosition.iX = aPoint3D.iX;
64 ptrEvent.iPosition.iY = aPoint3D.iY;
65 aEvent1.SetPointerNumber(aPointerNumber);
66 aEvent1.SetPointerZ(aPoint3D.iZ);
69 aEvent2.InitAdvancedPointerEvent(aType,0,aPoint3D,aPointerNumber);
72 void CTAdvancedPointerEvent::TestAdvancedPointerInit()
74 // Test size of class with hard coded values to prevent regression failure
75 TEST(sizeof(TAdvancedPointerEvent) == 32);
80 // low value coords, lowest value event type
82 TPoint3D point3D(1,2,3);
83 AdvancedPointerInit(event1, event2, TPointerEvent::EButton1Down, point3D, 1);
85 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
87 // high value coords, highest value event type and pointer number
89 TPoint3D point3D(KMaxTInt, KMaxTInt-1, KMaxTInt-3);
90 AdvancedPointerInit(event1, event2, TPointerEvent::EOutOfRange, point3D, KMaxTUint8);
92 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
94 // high negative value coords, highest value event type and pointer number
96 TPoint3D point3D(KMinTInt, KMinTInt+1, KMinTInt+3);
97 AdvancedPointerInit(event1, event2, TPointerEvent::EOutOfRange, point3D, KMaxTUint8);
99 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
102 void CTAdvancedPointerEvent::TestAdvancedPointerGetPointerId()
105 TAdvancedPointerEvent& ptrEvent = *event.Pointer();
106 const TPoint3D point3D(1,2,3);
107 const TUint8 MaxLikelyCommonPointerNumber = 10;
109 // Likely Common Values
110 TUint8 pointerNumber = 0;
111 for(;pointerNumber<=MaxLikelyCommonPointerNumber;pointerNumber++)
113 event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
114 TEST(ptrEvent.PointerNumber()==pointerNumber);
119 event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
120 TEST(ptrEvent.PointerNumber()==pointerNumber);
123 pointerNumber = 255; // KMaxTUint8 is there was one defined.
124 event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
125 TEST(ptrEvent.PointerNumber()==pointerNumber);
128 /** helper method for TestAdvancedPointerGetPressureAndProximity() */
129 void CTAdvancedPointerEvent::TestAdvancedPointerGetPressureAndProximity(const TPoint3D aPoint3D)
132 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, aPoint3D, 0);
133 TAdvancedPointerEvent ptrEvent = *event.Pointer();
134 const TPoint3D positionAndPressure3D = ptrEvent.PositionAndPressure3D();
135 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&aPoint3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&positionAndPressure3D),sizeof(TPoint3D)));
136 TInt proximityAndPressure = ptrEvent.ProximityAndPressure();
137 TEST(aPoint3D.iZ==proximityAndPressure);
140 void CTAdvancedPointerEvent::TestAdvancedPointerGetPressureAndProximity()
144 TPoint3D point3D(0,0,0);
145 TestAdvancedPointerGetPressureAndProximity(point3D);
149 TPoint3D point3D(10,9,8);
150 TestAdvancedPointerGetPressureAndProximity(point3D);
154 TPoint3D point3D(10,9,-8);
155 TestAdvancedPointerGetPressureAndProximity(point3D);
159 TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
160 TestAdvancedPointerGetPressureAndProximity(point3D);
164 TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
165 TestAdvancedPointerGetPressureAndProximity(point3D);
169 void CTAdvancedPointerEvent::TestAdvancedPointerGetPressure()
173 const TPoint3D point3D(0,0,0);
175 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
176 TAdvancedPointerEvent ptrEvent = *event.Pointer();
177 const TPoint3D pressure3D = ptrEvent.Pressure3D();
178 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
179 TInt pressure = ptrEvent.Pressure();
180 TEST(point3D.iZ==pressure);
184 const TPoint3D point3D(10,9,8);
186 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
187 TAdvancedPointerEvent ptrEvent = *event.Pointer();
188 const TPoint3D pressure3D = ptrEvent.Pressure3D();
189 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
190 TInt pressure = ptrEvent.Pressure();
191 TEST(point3D.iZ==pressure);
195 const TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
197 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
198 TAdvancedPointerEvent ptrEvent = *event.Pointer();
199 const TPoint3D pressure3D = ptrEvent.Pressure3D();
200 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
201 TInt pressure = ptrEvent.Pressure();
202 TEST(point3D.iZ==pressure);
206 TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
208 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
209 TAdvancedPointerEvent ptrEvent = *event.Pointer();
210 const TPoint3D pressure3D = ptrEvent.Pressure3D();
211 point3D.iZ=0; // pressure can't be negative
212 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
213 TInt pressure = ptrEvent.Pressure();
218 void CTAdvancedPointerEvent::TestAdvancedPointerGetPosition()
222 const TPoint3D point3D(0,0,0);
224 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
225 TAdvancedPointerEvent ptrEvent = *event.Pointer();
226 const TPoint3D position3D = ptrEvent.Position3D();
227 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
228 TInt proximity = ptrEvent.Proximity();
229 TEST(point3D.iZ==proximity);
233 const TPoint3D point3D(10,9,-8);
235 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
236 TAdvancedPointerEvent ptrEvent = *event.Pointer();
237 const TPoint3D position3D = ptrEvent.Position3D();
238 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
239 TInt proximity = ptrEvent.Proximity();
240 TEST(point3D.iZ==proximity);
244 TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
246 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
247 TAdvancedPointerEvent ptrEvent = *event.Pointer();
248 const TPoint3D position3D = ptrEvent.Position3D();
249 point3D.iZ=0; // proximity can't be positive
250 TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
251 TInt proximity = ptrEvent.Proximity();
256 const TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
258 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
259 TAdvancedPointerEvent ptrEvent = *event.Pointer();
260 const TPoint3D position3D = ptrEvent.Position3D();
261 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
262 TInt proximity = ptrEvent.Proximity();
263 TEST(point3D.iZ==proximity);
267 void CTAdvancedPointerEvent::TestPointerEventCopying()
270 event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, TPoint3D(2,3,4),1);
271 TPointerEvent testPointerEvent;
272 testPointerEvent.iModifiers =0;
273 testPointerEvent.iParentPosition=TPoint(0,0);
274 testPointerEvent.iPosition = TPoint(2,3);
275 testPointerEvent.iType=TPointerEvent::EMove;
277 // TPointerEvent to TPointerEvent
280 TPointerEvent* pointerEventPtr = event.Pointer();
281 TPointerEvent pointerEvent = *pointerEventPtr;
282 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
284 // Assignment operator
286 TPointerEvent* pointerEventPtr = event.Pointer();
287 TPointerEvent pointerEvent;
288 pointerEvent = *pointerEventPtr;
289 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
291 // TAdvancedPointerEvent to TPointerEvent
294 TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
295 TPointerEvent pointerEvent = *advancedPointerEventPtr;
296 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
298 // Assignment operator
300 TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
301 TPointerEvent pointerEvent;
302 pointerEvent = *advancedPointerEventPtr;
303 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
306 // TPointerEvent to TPointerEvent
309 TPointerEvent* pointerEventPtr = event.Pointer();
310 TPointerEvent pointerEvent;
311 pointerEvent.Copy(*pointerEventPtr);
312 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
315 // TAdvancedPointerEvent to TPointerEvent
318 TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
319 TPointerEvent pointerEvent;
320 pointerEvent.Copy(*advancedPointerEventPtr);
321 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
324 // Assignment operator
326 TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
327 TAdvancedPointerEvent advancedPointerEventPtr2;
328 advancedPointerEventPtr2 = *advancedPointerEventPtr;
329 TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&advancedPointerEventPtr2),sizeof(TAdvancedPointerEvent),reinterpret_cast<TUint8 const*>(event.Pointer()),sizeof(TAdvancedPointerEvent)));
333 void CTAdvancedPointerEvent::RunTestCaseL(TInt /*aCurTestCase*/)
335 _LIT(KTest1,"PointerEventInit");
336 _LIT(KTest2,"AdvancedPointerEventInit");
337 _LIT(KTest3,"PointerEventCopying");
338 _LIT(KTest4,"AdvancedPointerEventGetPointerId");
339 _LIT(KTest5,"AdvancedPointerEventGetPressureAndProximity");
340 _LIT(KTest6,"AdvancedPointerEventGetPressure");
341 _LIT(KTest7,"AdvancedPointerEventGetPosition");
343 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
344 switch(++iTest->iState)
348 @SYMTestCaseID GRAPHICS-WSERV-0542
350 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0542"));
351 iTest->LogSubTest(KTest1);
352 TestPointerEventInit();
356 @SYMTestCaseID GRAPHICS-WSERV-0543
358 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0543"));
359 iTest->LogSubTest(KTest2);
360 TestAdvancedPointerInit();
364 @SYMTestCaseID GRAPHICS-WSERV-0544
366 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0544"));
367 iTest->LogSubTest(KTest3);
368 TestPointerEventCopying();
372 @SYMTestCaseID GRAPHICS-WSERV-0545
374 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0545"));
375 iTest->LogSubTest(KTest4);
376 TestAdvancedPointerGetPointerId();
380 @SYMTestCaseID GRAPHICS-WSERV-0546
382 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0546"));
383 iTest->LogSubTest(KTest5);
384 TestAdvancedPointerGetPressureAndProximity();
388 @SYMTestCaseID GRAPHICS-WSERV-0547
390 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0547"));
391 iTest->LogSubTest(KTest6);
392 TestAdvancedPointerGetPressure();
396 @SYMTestCaseID GRAPHICS-WSERV-0548
398 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0548"));
399 iTest->LogSubTest(KTest7);
400 TestAdvancedPointerGetPosition();
403 ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
404 ((CTAdvancedPointerEventStep*)iStep)->CloseTMSGraphicsStep();
408 ((CTAdvancedPointerEventStep*)iStep)->RecordTestResultL();
411 __WS_CONSTRUCT_STEP__(AdvancedPointerEvent)