windowing/windowserver/test/TClick/multiptrclick.cpp
changeset 103 2717213c588a
child 178 89bd4cfee505
equal deleted inserted replaced
98:bf7481649c98 103:2717213c588a
       
     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 // Test Multi Pointer Click Plug-In DLL
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include "W32CLICK.H"
       
    20 #include "multiptrclick.h"
       
    21 
       
    22 class CMultiPtrClickMaker : public CClickMaker
       
    23 	{
       
    24 	enum {EEventBufferSize=32};
       
    25 public:
       
    26 	~CMultiPtrClickMaker();
       
    27 	void ConstructL();
       
    28 	//Virtual function from CClickMaker
       
    29 	void KeyEvent(TEventCode aType, const TKeyEvent& aEvent);
       
    30 	void PointerEvent(const TPointerEvent& aEvent);
       
    31 	void OtherEvent(TInt aType, TAny* aParam);
       
    32 	TInt CommandReplyL(TInt aOpcode, TAny *aArgs);
       
    33 
       
    34 private:
       
    35 	TInt AddEvent(const TWsEvent* aEvent);
       
    36 	TInt AddEvent(const TPointerEventData* aEvent);
       
    37 	TBool ComparePointerEvents(const TPointerEvent* aExpectedEvent, const TPointerEvent* aActualEvent);
       
    38 	TBool CompareOtherEvents(const TPointerEventData* aExpectedEvent, const TPointerEventData* aActualEvent);
       
    39 private:
       
    40 	CCirBuf<TWsEvent> iPtrEventBuffer;
       
    41 	CCirBuf<TPointerEventData> iOtherEventBuffer;
       
    42 	TBuf<255> iErrorDes;
       
    43 	TInt iPtrEventCount;
       
    44 	TInt iOtherEventCount;
       
    45 	TInt iError;
       
    46 	};
       
    47 
       
    48 
       
    49 void CMultiPtrClickMaker::ConstructL()
       
    50 	{
       
    51 	iPtrEventBuffer.SetLengthL(EEventBufferSize);
       
    52 	iOtherEventBuffer.SetLengthL(EEventBufferSize);
       
    53 	}
       
    54 
       
    55 CMultiPtrClickMaker::~CMultiPtrClickMaker()
       
    56 	{
       
    57 	}
       
    58 
       
    59 void CMultiPtrClickMaker::KeyEvent(TEventCode /*aType*/,const TKeyEvent& /*aEvent*/)
       
    60 	{
       
    61 	}
       
    62 
       
    63 TBool CMultiPtrClickMaker::ComparePointerEvents(const TPointerEvent* aExpectedEvent, const TPointerEvent* aActualEvent)
       
    64 	{
       
    65 	// Check pointer type
       
    66 	if (aExpectedEvent->iType != aActualEvent->iType)
       
    67 		{
       
    68 		_LIT(KEventType, "Actual Wserv Event type = %d Expected Wserv Event Type = %d ");
       
    69 		iErrorDes.Format(KEventType, aActualEvent->iType, aExpectedEvent->iType);
       
    70 		return EFalse;
       
    71 		}
       
    72 	
       
    73 	if (aExpectedEvent->iPosition != aActualEvent->iPosition)
       
    74 		{
       
    75 		_LIT(KPointerPosition, "Actual PointerPosition = (%d, %d) Expected PointerPosition = (%d, %d) ");
       
    76 		iErrorDes.Format(KPointerPosition, aActualEvent->iPosition.iX, aActualEvent->iPosition.iY, aExpectedEvent->iPosition.iX, aExpectedEvent->iPosition.iY);
       
    77 		return EFalse;
       
    78 		}
       
    79 	
       
    80 	if (aExpectedEvent->iParentPosition != aActualEvent->iParentPosition)
       
    81 		{
       
    82 		_LIT(KPointerPosition, "Actual parent Position = (%d, %d) Expected parent Position = (%d, %d) ");
       
    83 		iErrorDes.Format(KPointerPosition, aActualEvent->iParentPosition.iX, aActualEvent->iParentPosition.iY, aExpectedEvent->iParentPosition.iX, aExpectedEvent->iParentPosition.iY);
       
    84 		return EFalse;
       
    85 		}
       
    86 	
       
    87 	if (aExpectedEvent->IsAdvancedPointerEvent() != aActualEvent->IsAdvancedPointerEvent())
       
    88 		{
       
    89 		_LIT(KPointerPosition, "Actual event is TAdvancedPointerEvent = %d Expected event is TAdvancedPointerEvent = %d ");
       
    90 		iErrorDes.Format(KPointerPosition, aActualEvent->IsAdvancedPointerEvent(), aExpectedEvent->IsAdvancedPointerEvent());
       
    91 		return EFalse;
       
    92 		}
       
    93 	
       
    94 	if (aExpectedEvent->IsAdvancedPointerEvent())
       
    95 		{
       
    96 		const TAdvancedPointerEvent& expectedAdvancedEvent = *aExpectedEvent->AdvancedPointerEvent();
       
    97 		const TAdvancedPointerEvent& actualAdvancedEvent   = *aActualEvent->AdvancedPointerEvent();
       
    98 		
       
    99 		if (expectedAdvancedEvent.PointerNumber() != actualAdvancedEvent.PointerNumber())
       
   100 			{
       
   101 			_LIT(KPointerNumber, "Actual PointerNumber = %d Expected PointerNumber = %d ");
       
   102 			iErrorDes.Format(KPointerNumber, actualAdvancedEvent.PointerNumber(), expectedAdvancedEvent.PointerNumber());
       
   103 			return EFalse;
       
   104 			}
       
   105 		
       
   106 		if (expectedAdvancedEvent.Pressure() != actualAdvancedEvent.Pressure())
       
   107 			{
       
   108 			_LIT(KPointerPressure, "Actual Pressure = %d Expected Pressure = %d ");
       
   109 			iErrorDes.Format(KPointerPressure, actualAdvancedEvent.Pressure(), expectedAdvancedEvent.Pressure());
       
   110 			return EFalse;
       
   111 			}
       
   112 		
       
   113 		if (expectedAdvancedEvent.Proximity() != actualAdvancedEvent.Proximity())
       
   114 			{
       
   115 			_LIT(KPointerProximity, "Actual Proximity = %d Expected Proximity = %d ");
       
   116 			iErrorDes.Format(KPointerProximity, actualAdvancedEvent.Proximity(), expectedAdvancedEvent.Proximity());
       
   117 			return EFalse;
       
   118 			}
       
   119 		}
       
   120 
       
   121 	return ETrue;
       
   122 	}
       
   123 
       
   124 //
       
   125 void CMultiPtrClickMaker::PointerEvent(const TPointerEvent& aEvent)
       
   126 	{
       
   127 	// If it has already failed then do not test other events
       
   128 	// becasue the error value and its descriptor will be over written
       
   129 	if (iError)
       
   130 		{
       
   131 		return;
       
   132 		}
       
   133 		
       
   134 	// Get pointer event from buffer
       
   135 	TWsEvent expectedEvent;
       
   136 	iPtrEventBuffer.Remove(&expectedEvent);
       
   137 	
       
   138 	// Increment event count
       
   139 	iPtrEventCount++;
       
   140 	
       
   141 	// increment this counter in OtherEvent() becasue first pointer event iscalled and then OtherEvent() is called
       
   142 	if (!ComparePointerEvents(expectedEvent.Pointer(), &aEvent))
       
   143 		{
       
   144 		iError = iPtrEventCount;
       
   145 		}
       
   146 	}
       
   147 
       
   148 TBool CMultiPtrClickMaker::CompareOtherEvents(const TPointerEventData* aExpectedEvent, const TPointerEventData* aActualEvent)
       
   149 	{
       
   150 	if (aExpectedEvent->iCurrentPos != aActualEvent->iCurrentPos)
       
   151 		{
       
   152 		_LIT(KCurrentPosition, "Actual CurrentPosition  w.r.t screen = (%d,%d) Expected CurrentPosition  w.r.t screen = (%d,%d)");
       
   153 		iErrorDes.Copy(KCurrentPosition);
       
   154 		iErrorDes.Format(KCurrentPosition, aActualEvent->iCurrentPos.iX, aActualEvent->iCurrentPos.iX, aExpectedEvent->iCurrentPos.iX, aExpectedEvent->iCurrentPos.iY);
       
   155 		return EFalse;
       
   156 		}
       
   157 	
       
   158 	if (aExpectedEvent->iClientHandle != aActualEvent->iClientHandle)
       
   159 		{
       
   160 		_LIT(KWindowHandle, "Actual Window Handle = %d Expected Window Handle = %d ");
       
   161 		iErrorDes.Copy(KWindowHandle);
       
   162 		iErrorDes.Format(KWindowHandle, aActualEvent->iClientHandle, aExpectedEvent->iClientHandle);
       
   163 		return EFalse;
       
   164 		}
       
   165 	
       
   166 	return ComparePointerEvents(&aExpectedEvent->iPointerEvent, &aActualEvent->iPointerEvent);
       
   167 	}
       
   168 
       
   169 void CMultiPtrClickMaker::OtherEvent(TInt aType, TAny* aParam)
       
   170 	{
       
   171 	if (aType != EEventPointer)
       
   172 		{
       
   173 		return;
       
   174 		}
       
   175 			
       
   176 	if (iError)
       
   177 		{
       
   178 		return;
       
   179 		}
       
   180 
       
   181 	TPointerEventData expectedEvent;
       
   182 	iOtherEventBuffer.Remove(&expectedEvent);
       
   183 	
       
   184 	iOtherEventCount++;
       
   185 	
       
   186 	TPointerEventData* data=static_cast<TPointerEventData*>(aParam);
       
   187 	
       
   188 	if (!CompareOtherEvents(&expectedEvent, data))
       
   189 		{
       
   190 		iError = iPtrEventCount;
       
   191 		}
       
   192 	}
       
   193 
       
   194 TInt CMultiPtrClickMaker::AddEvent(const TWsEvent* aEvent)
       
   195 	{
       
   196 	return iPtrEventBuffer.Add(aEvent);
       
   197 	}
       
   198 
       
   199 TInt CMultiPtrClickMaker::AddEvent(const TPointerEventData* aEvent)
       
   200 	{
       
   201 	return iOtherEventBuffer.Add(aEvent);
       
   202 	}
       
   203 
       
   204 TInt CMultiPtrClickMaker::CommandReplyL(TInt aOpcode, TAny *aArgs)
       
   205 	{
       
   206 	TMultiPtrClickArgUnion pData;
       
   207 	pData.any=aArgs;
       
   208 	switch (aOpcode)
       
   209 		{
       
   210 	case EMultiPtrClickEventAdd:
       
   211 		return AddEvent(pData.WsEvent);
       
   212 	case EMultiPtrOtherEventAdd:
       
   213 		return AddEvent(pData.OtherEvent);
       
   214 	case EMultiPtrClickEventError:
       
   215 		return iError;
       
   216 	case EMultiPtrClickEventErrorDesc:
       
   217 		if (iError != KErrNone)
       
   218 			{
       
   219 			RChunk chunk;
       
   220 			chunk.OpenGlobal(KMultiPtrClickChunk, ETrue);
       
   221 			TUint8* desPtr = chunk.Base() + *(static_cast<TInt*>(aArgs));
       
   222 			TPtr8 ptrDes(desPtr, iErrorDes.Length(), iErrorDes.Length());
       
   223 			ptrDes.Copy(iErrorDes);
       
   224 			chunk.Close();
       
   225 			return iErrorDes.Length();
       
   226 			// returns the error description which gets displayed in logs if test failed
       
   227 			}
       
   228 		break;
       
   229 	case EMultiPtrClickEventReset:
       
   230 		iPtrEventBuffer.Reset();
       
   231 		iError = 0;
       
   232 		iPtrEventCount = 0;
       
   233 		break;
       
   234 	default:;
       
   235 		}
       
   236 	return(KErrNone);
       
   237 	}
       
   238 
       
   239 EXPORT_C CClickMaker* CreateMultiPtrClickMakerL()
       
   240 	{
       
   241 	CMultiPtrClickMaker* plugIn=new(ELeave) CMultiPtrClickMaker;
       
   242 	CleanupStack::PushL(plugIn);
       
   243 	plugIn->ConstructL();
       
   244 	CleanupStack::Pop(plugIn);
       
   245 	return plugIn;
       
   246 	}