os/graphics/windowing/windowserver/test/tauto/tadvancedpointerevent.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Advanced pointer event unit tests
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @test
    21  @internalComponent - Internal Symbian test code
    22 */
    23 
    24 #include "tadvancedpointerevent.h"
    25 
    26 CTAdvancedPointerEvent::CTAdvancedPointerEvent(CTestStep* aStep)
    27 	: CTWsGraphicsBase(aStep)
    28 	{}
    29 
    30 CTAdvancedPointerEvent::~CTAdvancedPointerEvent()
    31 	{}
    32 
    33 void CTAdvancedPointerEvent::TestPointerEventInit()
    34 	{
    35 	// Test size of class with hard coded values to prevent regression failure 
    36 	TEST(sizeof(TPointerEvent) == 24);
    37 	
    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;
    44 	
    45 	// Construct two TPointerEvent objects. The first using default constructor, the second using the copy constructor. T
    46 		{		
    47 		TPointerEvent ptrEvent2 = TPointerEvent(ptrEvent1);
    48 		TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&ptrEvent1),sizeof(TPointerEvent),reinterpret_cast<TUint8*>(&ptrEvent2),sizeof(TPointerEvent)));		
    49 		}	
    50 	
    51 		{		
    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)));		
    54 		}	
    55 	}
    56 
    57 void AdvancedPointerInit(TWsEvent& aEvent1, TWsEvent& aEvent2, const TPointerEvent::TType aType, const TPoint3D& aPoint3D, const TUint8 aPointerNumber)
    58 	{
    59 	// init first event
    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);
    67 	
    68 	// init 2nd event
    69 	aEvent2.InitAdvancedPointerEvent(aType,0,aPoint3D,aPointerNumber);
    70 	}
    71 
    72 void CTAdvancedPointerEvent::TestAdvancedPointerInit()
    73 	{
    74 	// Test size of class with hard coded values to prevent regression failure 
    75 	TEST(sizeof(TAdvancedPointerEvent) == 32);
    76 
    77 	TWsEvent event1;
    78 	TWsEvent event2;
    79 	
    80 	// low value coords, lowest value event type
    81 		{
    82 		TPoint3D point3D(1,2,3);	
    83 		AdvancedPointerInit(event1, event2, TPointerEvent::EButton1Down, point3D, 1);
    84 		}
    85 	TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
    86 	
    87 	// high value coords, highest value event type and pointer number
    88 		{
    89 		TPoint3D point3D(KMaxTInt, KMaxTInt-1, KMaxTInt-3);
    90 		AdvancedPointerInit(event1, event2, TPointerEvent::EOutOfRange, point3D, KMaxTUint8);
    91 		}
    92 	TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));
    93 	
    94 	// high negative value coords, highest value event type and pointer number
    95 		{
    96 		TPoint3D point3D(KMinTInt, KMinTInt+1, KMinTInt+3);
    97 		AdvancedPointerInit(event1, event2, TPointerEvent::EOutOfRange, point3D, KMaxTUint8);
    98 		}
    99 	TEST(0==Mem::Compare(reinterpret_cast<TUint8*>(&event1),sizeof(TWsEvent),reinterpret_cast<TUint8*>(&event2),sizeof(TWsEvent)));		
   100 	}
   101 
   102 void CTAdvancedPointerEvent::TestAdvancedPointerGetPointerId()
   103 	{
   104 	TWsEvent event;
   105 	TAdvancedPointerEvent& ptrEvent = *event.Pointer();
   106 	const TPoint3D point3D(1,2,3);
   107 	const TUint8 MaxLikelyCommonPointerNumber = 10;
   108 	
   109 	// Likely Common Values
   110 	TUint8 pointerNumber = 0;
   111 	for(;pointerNumber<=MaxLikelyCommonPointerNumber;pointerNumber++)
   112 		{
   113 		event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
   114 		TEST(ptrEvent.PointerNumber()==pointerNumber);
   115 		}
   116 
   117 	// mid-range value
   118 	pointerNumber = 127;	
   119 	event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
   120 	TEST(ptrEvent.PointerNumber()==pointerNumber);	
   121 	
   122 	// highest value
   123 	pointerNumber = 255; // KMaxTUint8 is there was one defined.
   124 	event.InitAdvancedPointerEvent(TPointerEvent::EMove,0,point3D,pointerNumber);
   125 	TEST(ptrEvent.PointerNumber()==pointerNumber);	
   126 	}
   127 
   128 /** helper method for TestAdvancedPointerGetPressureAndProximity() */
   129 void CTAdvancedPointerEvent::TestAdvancedPointerGetPressureAndProximity(const TPoint3D aPoint3D)
   130 	{
   131 	TWsEvent event;
   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);	
   138 	}
   139 
   140 void CTAdvancedPointerEvent::TestAdvancedPointerGetPressureAndProximity()
   141 	{
   142 		{
   143 		// middle value
   144 		TPoint3D point3D(0,0,0);
   145 		TestAdvancedPointerGetPressureAndProximity(point3D);
   146 		}
   147 		{
   148 		// Typical value
   149 		TPoint3D point3D(10,9,8);
   150 		TestAdvancedPointerGetPressureAndProximity(point3D);
   151 		}
   152 		{
   153 		// Typical value
   154 		TPoint3D point3D(10,9,-8);
   155 		TestAdvancedPointerGetPressureAndProximity(point3D);
   156 		}
   157 		{
   158 		// max values
   159 		TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
   160 		TestAdvancedPointerGetPressureAndProximity(point3D);
   161 		}
   162 		{
   163 		// min values
   164 		TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
   165 		TestAdvancedPointerGetPressureAndProximity(point3D);
   166 		}
   167 	}
   168 
   169 void CTAdvancedPointerEvent::TestAdvancedPointerGetPressure()
   170 	{
   171 		{
   172 		// middle value
   173 		const TPoint3D point3D(0,0,0);
   174 		TWsEvent event;
   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);
   181 		}
   182 		{
   183 		// Typical value
   184 		const TPoint3D point3D(10,9,8);
   185 		TWsEvent event;
   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);
   192 		}		
   193 		{
   194 		// max value
   195 		const TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
   196 		TWsEvent event;
   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);
   203 		}
   204 		{
   205 		// min value
   206 		TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
   207 		TWsEvent event;
   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();
   214 		TEST(0==pressure);
   215 		}
   216 	}
   217 
   218 void CTAdvancedPointerEvent::TestAdvancedPointerGetPosition()
   219 	{
   220 		{
   221 		// middle value
   222 		const TPoint3D point3D(0,0,0);
   223 		TWsEvent event;
   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);
   230 		}
   231 		{
   232 		// typical value
   233 		const TPoint3D point3D(10,9,-8);
   234 		TWsEvent event;
   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);
   241 		}
   242 		{
   243 		// highest value
   244 		TPoint3D point3D(KMaxTInt-2,KMaxTInt-1,KMaxTInt);
   245 		TWsEvent event;
   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();
   252 		TEST(0==proximity);
   253 		}
   254 		{
   255 		// lowest value
   256 		const TPoint3D point3D(KMinTInt+2,KMinTInt+1,KMinTInt);
   257 		TWsEvent event;
   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);
   264 		}
   265 	}
   266 
   267 void CTAdvancedPointerEvent::TestPointerEventCopying()
   268 	{
   269 	TWsEvent event;
   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;
   276 
   277 	// TPointerEvent to TPointerEvent
   278 	// Copy Constructor
   279 		{
   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)));
   283 		}
   284 	// Assignment operator
   285 		{
   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)));
   290 		}		
   291 	// TAdvancedPointerEvent to TPointerEvent
   292 	// Copy Constructor
   293 		{
   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)));
   297 		}
   298 	// Assignment operator
   299 		{
   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)));
   304 		}
   305 
   306 	// TPointerEvent to TPointerEvent
   307 	// Copy Method
   308 		{
   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)));
   313 		}
   314 		
   315 	// TAdvancedPointerEvent to TPointerEvent
   316 	// Copy Constructor
   317 		{
   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)));
   322 		}
   323 		
   324 	// Assignment operator
   325 		{
   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)));
   330 		}			
   331 	}
   332 
   333 void CTAdvancedPointerEvent::RunTestCaseL(TInt /*aCurTestCase*/)
   334 	{
   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");
   342 	
   343 	((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   344 	switch(++iTest->iState)
   345 		{
   346 	case 1:
   347 /**
   348 @SYMTestCaseID		GRAPHICS-WSERV-0542
   349 */
   350 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0542"));
   351 		iTest->LogSubTest(KTest1);
   352 		TestPointerEventInit();
   353 		break;	
   354 	case 2:
   355 /**
   356 @SYMTestCaseID		GRAPHICS-WSERV-0543
   357 */
   358 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0543"));
   359 		iTest->LogSubTest(KTest2);
   360 		TestAdvancedPointerInit();
   361 		break;
   362 	case 3:
   363 /**
   364 @SYMTestCaseID		GRAPHICS-WSERV-0544
   365 */
   366 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0544"));
   367 		iTest->LogSubTest(KTest3);			
   368 		TestPointerEventCopying();
   369 		break;
   370 	case 4:
   371 /**
   372 @SYMTestCaseID		GRAPHICS-WSERV-0545
   373 */
   374 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0545"));
   375 		iTest->LogSubTest(KTest4);
   376 		TestAdvancedPointerGetPointerId();
   377 		break;		
   378 	case 5:
   379 /**
   380 @SYMTestCaseID		GRAPHICS-WSERV-0546
   381 */
   382 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0546"));
   383 		iTest->LogSubTest(KTest5);
   384 		TestAdvancedPointerGetPressureAndProximity();
   385 		break;
   386 	case 6:
   387 /**
   388 @SYMTestCaseID		GRAPHICS-WSERV-0547
   389 */
   390 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0547"));
   391 		iTest->LogSubTest(KTest6);
   392 		TestAdvancedPointerGetPressure();
   393 		break;
   394 	case 7:
   395 /**
   396 @SYMTestCaseID		GRAPHICS-WSERV-0548
   397 */
   398 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0548"));
   399 		iTest->LogSubTest(KTest7);			
   400 		TestAdvancedPointerGetPosition();
   401 		break;
   402 	default:
   403 		((CTAdvancedPointerEventStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   404 		((CTAdvancedPointerEventStep*)iStep)->CloseTMSGraphicsStep();
   405 		TestComplete();
   406 		break;
   407 		}
   408 	((CTAdvancedPointerEventStep*)iStep)->RecordTestResultL();
   409 	}
   410 
   411 __WS_CONSTRUCT_STEP__(AdvancedPointerEvent)