1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/tadvancedpointerevent.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,411 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Advanced pointer event unit tests
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @test
1.24 + @internalComponent - Internal Symbian test code
1.25 +*/
1.26 +
1.27 +#include "tadvancedpointerevent.h"
1.28 +
1.29 +CTAdvancedPointerEvent::CTAdvancedPointerEvent(CTestStep* aStep)
1.30 + : CTWsGraphicsBase(aStep)
1.31 + {}
1.32 +
1.33 +CTAdvancedPointerEvent::~CTAdvancedPointerEvent()
1.34 + {}
1.35 +
1.36 +void CTAdvancedPointerEvent::TestPointerEventInit()
1.37 + {
1.38 + // Test size of class with hard coded values to prevent regression failure
1.39 + TEST(sizeof(TPointerEvent) == 24);
1.40 +
1.41 + TPointerEvent ptrEvent1 = TPointerEvent();
1.42 + ptrEvent1.iType = TPointerEvent::EButton1Down;
1.43 + TPoint initCoords(10,10);
1.44 + ptrEvent1.iPosition = initCoords;
1.45 + ptrEvent1.iParentPosition = initCoords;
1.46 + ptrEvent1.iModifiers = 0;
1.47 +
1.48 + // Construct two TPointerEvent objects. The first using default constructor, the second using the copy constructor. T
1.49 + {
1.50 + TPointerEvent ptrEvent2 = TPointerEvent(ptrEvent1);
1.51 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&ptrEvent1),sizeof(TPointerEvent),reinterpret_cast<TUint8*>(&ptrEvent2),sizeof(TPointerEvent)));
1.52 + }
1.53 +
1.54 + {
1.55 + TPointerEvent ptrEvent2(TPointerEvent::EButton1Down, 0, initCoords, initCoords);
1.56 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&ptrEvent1),sizeof(TPointerEvent),reinterpret_cast<TUint8*>(&ptrEvent2),sizeof(TPointerEvent)));
1.57 + }
1.58 + }
1.59 +
1.60 +void AdvancedPointerInit(TWsEvent& aEvent1, TWsEvent& aEvent2, const TPointerEvent::TType aType, const TPoint3D& aPoint3D, const TUint8 aPointerNumber)
1.61 + {
1.62 + // init first event
1.63 + TAdvancedPointerEvent& ptrEvent = *aEvent1.Pointer();
1.64 + ptrEvent.iType = aType;
1.65 + ptrEvent.iModifiers = EModifierAdvancedPointerEvent; // done implicitly by TAdvancedPointerEvent::Init method
1.66 + ptrEvent.iPosition.iX = aPoint3D.iX;
1.67 + ptrEvent.iPosition.iY = aPoint3D.iY;
1.68 + aEvent1.SetPointerNumber(aPointerNumber);
1.69 + aEvent1.SetPointerZ(aPoint3D.iZ);
1.70 +
1.71 + // init 2nd event
1.72 + aEvent2.InitAdvancedPointerEvent(aType,0,aPoint3D,aPointerNumber);
1.73 + }
1.74 +
1.75 +void CTAdvancedPointerEvent::TestAdvancedPointerInit()
1.76 + {
1.77 + // Test size of class with hard coded values to prevent regression failure
1.78 + TEST(sizeof(TAdvancedPointerEvent) == 32);
1.79 +
1.80 + TWsEvent event1;
1.81 + TWsEvent event2;
1.82 +
1.83 + // low value coords, lowest value event type
1.84 + {
1.85 + TPoint3D point3D(1,2,3);
1.86 + AdvancedPointerInit(event1, event2, TPointerEvent::EButton1Down, point3D, 1);
1.87 + }
1.88 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
1.89 +
1.90 + // high value coords, highest value event type and pointer number
1.91 + {
1.92 + TPoint3D point3D(KMaxTInt, KMaxTInt-1, KMaxTInt-3);
1.93 + AdvancedPointerInit(event1, event2, TPointerEvent::EOutOfRange, point3D, KMaxTUint8);
1.94 + }
1.95 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
1.96 +
1.97 + // high negative value coords, highest value event type and pointer number
1.98 + {
1.99 + TPoint3D point3D(KMinTInt, KMinTInt+1, KMinTInt+3);
1.100 + AdvancedPointerInit(event1, event2, TPointerEvent::EOutOfRange, point3D, KMaxTUint8);
1.101 + }
1.102 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
1.103 + }
1.104 +
1.105 +void CTAdvancedPointerEvent::TestAdvancedPointerGetPointerId()
1.106 + {
1.107 + TWsEvent event;
1.108 + TAdvancedPointerEvent& ptrEvent = *event.Pointer();
1.109 + const TPoint3D point3D(1,2,3);
1.110 + const TUint8 MaxLikelyCommonPointerNumber = 10;
1.111 +
1.112 + // Likely Common Values
1.113 + TUint8 pointerNumber = 0;
1.114 + for(;pointerNumber<=MaxLikelyCommonPointerNumber;pointerNumber++)
1.115 + {
1.116 + event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
1.117 + TEST(ptrEvent.PointerNumber()==pointerNumber);
1.118 + }
1.119 +
1.120 + // mid-range value
1.121 + pointerNumber = 127;
1.122 + event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
1.123 + TEST(ptrEvent.PointerNumber()==pointerNumber);
1.124 +
1.125 + // highest value
1.126 + pointerNumber = 255; // KMaxTUint8 is there was one defined.
1.127 + event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
1.128 + TEST(ptrEvent.PointerNumber()==pointerNumber);
1.129 + }
1.130 +
1.131 +/** helper method for TestAdvancedPointerGetPressureAndProximity() */
1.132 +void CTAdvancedPointerEvent::TestAdvancedPointerGetPressureAndProximity(const TPoint3D aPoint3D)
1.133 + {
1.134 + TWsEvent event;
1.135 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, aPoint3D, 0);
1.136 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.137 + const TPoint3D positionAndPressure3D = ptrEvent.PositionAndPressure3D();
1.138 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&aPoint3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&positionAndPressure3D),sizeof(TPoint3D)));
1.139 + TInt proximityAndPressure = ptrEvent.ProximityAndPressure();
1.140 + TEST(aPoint3D.iZ==proximityAndPressure);
1.141 + }
1.142 +
1.143 +void CTAdvancedPointerEvent::TestAdvancedPointerGetPressureAndProximity()
1.144 + {
1.145 + {
1.146 + // middle value
1.147 + TPoint3D point3D(0,0,0);
1.148 + TestAdvancedPointerGetPressureAndProximity(point3D);
1.149 + }
1.150 + {
1.151 + // Typical value
1.152 + TPoint3D point3D(10,9,8);
1.153 + TestAdvancedPointerGetPressureAndProximity(point3D);
1.154 + }
1.155 + {
1.156 + // Typical value
1.157 + TPoint3D point3D(10,9,-8);
1.158 + TestAdvancedPointerGetPressureAndProximity(point3D);
1.159 + }
1.160 + {
1.161 + // max values
1.162 + TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
1.163 + TestAdvancedPointerGetPressureAndProximity(point3D);
1.164 + }
1.165 + {
1.166 + // min values
1.167 + TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
1.168 + TestAdvancedPointerGetPressureAndProximity(point3D);
1.169 + }
1.170 + }
1.171 +
1.172 +void CTAdvancedPointerEvent::TestAdvancedPointerGetPressure()
1.173 + {
1.174 + {
1.175 + // middle value
1.176 + const TPoint3D point3D(0,0,0);
1.177 + TWsEvent event;
1.178 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.179 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.180 + const TPoint3D pressure3D = ptrEvent.Pressure3D();
1.181 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
1.182 + TInt pressure = ptrEvent.Pressure();
1.183 + TEST(point3D.iZ==pressure);
1.184 + }
1.185 + {
1.186 + // Typical value
1.187 + const TPoint3D point3D(10,9,8);
1.188 + TWsEvent event;
1.189 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.190 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.191 + const TPoint3D pressure3D = ptrEvent.Pressure3D();
1.192 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
1.193 + TInt pressure = ptrEvent.Pressure();
1.194 + TEST(point3D.iZ==pressure);
1.195 + }
1.196 + {
1.197 + // max value
1.198 + const TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
1.199 + TWsEvent event;
1.200 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.201 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.202 + const TPoint3D pressure3D = ptrEvent.Pressure3D();
1.203 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
1.204 + TInt pressure = ptrEvent.Pressure();
1.205 + TEST(point3D.iZ==pressure);
1.206 + }
1.207 + {
1.208 + // min value
1.209 + TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
1.210 + TWsEvent event;
1.211 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.212 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.213 + const TPoint3D pressure3D = ptrEvent.Pressure3D();
1.214 + point3D.iZ=0; // pressure can't be negative
1.215 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&pressure3D),sizeof(TPoint3D)));
1.216 + TInt pressure = ptrEvent.Pressure();
1.217 + TEST(0==pressure);
1.218 + }
1.219 + }
1.220 +
1.221 +void CTAdvancedPointerEvent::TestAdvancedPointerGetPosition()
1.222 + {
1.223 + {
1.224 + // middle value
1.225 + const TPoint3D point3D(0,0,0);
1.226 + TWsEvent event;
1.227 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.228 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.229 + const TPoint3D position3D = ptrEvent.Position3D();
1.230 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
1.231 + TInt proximity = ptrEvent.Proximity();
1.232 + TEST(point3D.iZ==proximity);
1.233 + }
1.234 + {
1.235 + // typical value
1.236 + const TPoint3D point3D(10,9,-8);
1.237 + TWsEvent event;
1.238 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.239 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.240 + const TPoint3D position3D = ptrEvent.Position3D();
1.241 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
1.242 + TInt proximity = ptrEvent.Proximity();
1.243 + TEST(point3D.iZ==proximity);
1.244 + }
1.245 + {
1.246 + // highest value
1.247 + TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
1.248 + TWsEvent event;
1.249 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.250 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.251 + const TPoint3D position3D = ptrEvent.Position3D();
1.252 + point3D.iZ=0; // proximity can't be positive
1.253 + TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
1.254 + TInt proximity = ptrEvent.Proximity();
1.255 + TEST(0==proximity);
1.256 + }
1.257 + {
1.258 + // lowest value
1.259 + const TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
1.260 + TWsEvent event;
1.261 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, point3D, 0);
1.262 + TAdvancedPointerEvent ptrEvent = *event.Pointer();
1.263 + const TPoint3D position3D = ptrEvent.Position3D();
1.264 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&point3D),sizeof(TPoint3D),reinterpret_cast<TUint8 const*>(&position3D),sizeof(TPoint3D)));
1.265 + TInt proximity = ptrEvent.Proximity();
1.266 + TEST(point3D.iZ==proximity);
1.267 + }
1.268 + }
1.269 +
1.270 +void CTAdvancedPointerEvent::TestPointerEventCopying()
1.271 + {
1.272 + TWsEvent event;
1.273 + event.InitAdvancedPointerEvent(TPointerEvent::EMove, 0, TPoint3D(2,3,4),1);
1.274 + TPointerEvent testPointerEvent;
1.275 + testPointerEvent.iModifiers =0;
1.276 + testPointerEvent.iParentPosition=TPoint(0,0);
1.277 + testPointerEvent.iPosition = TPoint(2,3);
1.278 + testPointerEvent.iType=TPointerEvent::EMove;
1.279 +
1.280 + // TPointerEvent to TPointerEvent
1.281 + // Copy Constructor
1.282 + {
1.283 + TPointerEvent* pointerEventPtr = event.Pointer();
1.284 + TPointerEvent pointerEvent = *pointerEventPtr;
1.285 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
1.286 + }
1.287 + // Assignment operator
1.288 + {
1.289 + TPointerEvent* pointerEventPtr = event.Pointer();
1.290 + TPointerEvent pointerEvent;
1.291 + pointerEvent = *pointerEventPtr;
1.292 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
1.293 + }
1.294 + // TAdvancedPointerEvent to TPointerEvent
1.295 + // Copy Constructor
1.296 + {
1.297 + TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
1.298 + TPointerEvent pointerEvent = *advancedPointerEventPtr;
1.299 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
1.300 + }
1.301 + // Assignment operator
1.302 + {
1.303 + TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
1.304 + TPointerEvent pointerEvent;
1.305 + pointerEvent = *advancedPointerEventPtr;
1.306 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
1.307 + }
1.308 +
1.309 + // TPointerEvent to TPointerEvent
1.310 + // Copy Method
1.311 + {
1.312 + TPointerEvent* pointerEventPtr = event.Pointer();
1.313 + TPointerEvent pointerEvent;
1.314 + pointerEvent.Copy(*pointerEventPtr);
1.315 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
1.316 + }
1.317 +
1.318 + // TAdvancedPointerEvent to TPointerEvent
1.319 + // Copy Constructor
1.320 + {
1.321 + TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
1.322 + TPointerEvent pointerEvent;
1.323 + pointerEvent.Copy(*advancedPointerEventPtr);
1.324 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&pointerEvent),sizeof(TPointerEvent),reinterpret_cast<TUint8 const*>(&testPointerEvent),sizeof(TPointerEvent)));
1.325 + }
1.326 +
1.327 + // Assignment operator
1.328 + {
1.329 + TAdvancedPointerEvent* advancedPointerEventPtr = event.Pointer();
1.330 + TAdvancedPointerEvent advancedPointerEventPtr2;
1.331 + advancedPointerEventPtr2 = *advancedPointerEventPtr;
1.332 + TEST(0==Mem::Compare(reinterpret_cast<TUint8 const*>(&advancedPointerEventPtr2),sizeof(TAdvancedPointerEvent),reinterpret_cast<TUint8 const*>(event.Pointer()),sizeof(TAdvancedPointerEvent)));
1.333 + }
1.334 + }
1.335 +
1.336 +void CTAdvancedPointerEvent::RunTestCaseL(TInt /*aCurTestCase*/)
1.337 + {
1.338 + _LIT(KTest1,"PointerEventInit");
1.339 + _LIT(KTest2,"AdvancedPointerEventInit");
1.340 + _LIT(KTest3,"PointerEventCopying");
1.341 + _LIT(KTest4,"AdvancedPointerEventGetPointerId");
1.342 + _LIT(KTest5,"AdvancedPointerEventGetPressureAndProximity");
1.343 + _LIT(KTest6,"AdvancedPointerEventGetPressure");
1.344 + _LIT(KTest7,"AdvancedPointerEventGetPosition");
1.345 +
1.346 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.347 + switch(++iTest->iState)
1.348 + {
1.349 + case 1:
1.350 +/**
1.351 +@SYMTestCaseID GRAPHICS-WSERV-0542
1.352 +*/
1.353 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0542"));
1.354 + iTest->LogSubTest(KTest1);
1.355 + TestPointerEventInit();
1.356 + break;
1.357 + case 2:
1.358 +/**
1.359 +@SYMTestCaseID GRAPHICS-WSERV-0543
1.360 +*/
1.361 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0543"));
1.362 + iTest->LogSubTest(KTest2);
1.363 + TestAdvancedPointerInit();
1.364 + break;
1.365 + case 3:
1.366 +/**
1.367 +@SYMTestCaseID GRAPHICS-WSERV-0544
1.368 +*/
1.369 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0544"));
1.370 + iTest->LogSubTest(KTest3);
1.371 + TestPointerEventCopying();
1.372 + break;
1.373 + case 4:
1.374 +/**
1.375 +@SYMTestCaseID GRAPHICS-WSERV-0545
1.376 +*/
1.377 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0545"));
1.378 + iTest->LogSubTest(KTest4);
1.379 + TestAdvancedPointerGetPointerId();
1.380 + break;
1.381 + case 5:
1.382 +/**
1.383 +@SYMTestCaseID GRAPHICS-WSERV-0546
1.384 +*/
1.385 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0546"));
1.386 + iTest->LogSubTest(KTest5);
1.387 + TestAdvancedPointerGetPressureAndProximity();
1.388 + break;
1.389 + case 6:
1.390 +/**
1.391 +@SYMTestCaseID GRAPHICS-WSERV-0547
1.392 +*/
1.393 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0547"));
1.394 + iTest->LogSubTest(KTest6);
1.395 + TestAdvancedPointerGetPressure();
1.396 + break;
1.397 + case 7:
1.398 +/**
1.399 +@SYMTestCaseID GRAPHICS-WSERV-0548
1.400 +*/
1.401 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0548"));
1.402 + iTest->LogSubTest(KTest7);
1.403 + TestAdvancedPointerGetPosition();
1.404 + break;
1.405 + default:
1.406 + ((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.407 + ((CTAdvancedPointerEventStep*)iStep)->CloseTMSGraphicsStep();
1.408 + TestComplete();
1.409 + break;
1.410 + }
1.411 + ((CTAdvancedPointerEventStep*)iStep)->RecordTestResultL();
1.412 + }
1.413 +
1.414 +__WS_CONSTRUCT_STEP__(AdvancedPointerEvent)