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 // Test Multi Pointer Click Plug-In DLL
20 #include "multiptrclick.h"
22 class CMultiPtrClickMaker : public CClickMaker
24 enum {EEventBufferSize=32};
26 ~CMultiPtrClickMaker();
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);
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);
40 CCirBuf<TWsEvent> iPtrEventBuffer;
41 CCirBuf<TPointerEventData> iOtherEventBuffer;
44 TInt iOtherEventCount;
49 void CMultiPtrClickMaker::ConstructL()
51 iPtrEventBuffer.SetLengthL(EEventBufferSize);
52 iOtherEventBuffer.SetLengthL(EEventBufferSize);
55 CMultiPtrClickMaker::~CMultiPtrClickMaker()
59 void CMultiPtrClickMaker::KeyEvent(TEventCode /*aType*/,const TKeyEvent& /*aEvent*/)
63 TBool CMultiPtrClickMaker::ComparePointerEvents(const TPointerEvent* aExpectedEvent, const TPointerEvent* aActualEvent)
66 if (aExpectedEvent->iType != aActualEvent->iType)
68 _LIT(KEventType, "Actual Wserv Event type = %d Expected Wserv Event Type = %d ");
69 iErrorDes.Format(KEventType, aActualEvent->iType, aExpectedEvent->iType);
73 if (aExpectedEvent->iPosition != aActualEvent->iPosition)
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);
80 if (aExpectedEvent->iParentPosition != aActualEvent->iParentPosition)
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);
87 if (aExpectedEvent->IsAdvancedPointerEvent() != aActualEvent->IsAdvancedPointerEvent())
89 _LIT(KPointerPosition, "Actual event is TAdvancedPointerEvent = %d Expected event is TAdvancedPointerEvent = %d ");
90 iErrorDes.Format(KPointerPosition, aActualEvent->IsAdvancedPointerEvent(), aExpectedEvent->IsAdvancedPointerEvent());
94 if (aExpectedEvent->IsAdvancedPointerEvent())
96 const TAdvancedPointerEvent& expectedAdvancedEvent = *aExpectedEvent->AdvancedPointerEvent();
97 const TAdvancedPointerEvent& actualAdvancedEvent = *aActualEvent->AdvancedPointerEvent();
99 if (expectedAdvancedEvent.PointerNumber() != actualAdvancedEvent.PointerNumber())
101 _LIT(KPointerNumber, "Actual PointerNumber = %d Expected PointerNumber = %d ");
102 iErrorDes.Format(KPointerNumber, actualAdvancedEvent.PointerNumber(), expectedAdvancedEvent.PointerNumber());
106 if (expectedAdvancedEvent.Pressure() != actualAdvancedEvent.Pressure())
108 _LIT(KPointerPressure, "Actual Pressure = %d Expected Pressure = %d ");
109 iErrorDes.Format(KPointerPressure, actualAdvancedEvent.Pressure(), expectedAdvancedEvent.Pressure());
113 if (expectedAdvancedEvent.Proximity() != actualAdvancedEvent.Proximity())
115 _LIT(KPointerProximity, "Actual Proximity = %d Expected Proximity = %d ");
116 iErrorDes.Format(KPointerProximity, actualAdvancedEvent.Proximity(), expectedAdvancedEvent.Proximity());
125 void CMultiPtrClickMaker::PointerEvent(const TPointerEvent& aEvent)
127 // If it has already failed then do not test other events
128 // becasue the error value and its descriptor will be over written
134 // Get pointer event from buffer
135 TWsEvent expectedEvent;
136 iPtrEventBuffer.Remove(&expectedEvent);
138 // Increment event count
141 // increment this counter in OtherEvent() becasue first pointer event iscalled and then OtherEvent() is called
142 if (!ComparePointerEvents(expectedEvent.Pointer(), &aEvent))
144 iError = iPtrEventCount;
148 TBool CMultiPtrClickMaker::CompareOtherEvents(const TPointerEventData* aExpectedEvent, const TPointerEventData* aActualEvent)
150 if (aExpectedEvent->iCurrentPos != aActualEvent->iCurrentPos)
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);
158 if (aExpectedEvent->iClientHandle != aActualEvent->iClientHandle)
160 _LIT(KWindowHandle, "Actual Window Handle = %d Expected Window Handle = %d ");
161 iErrorDes.Copy(KWindowHandle);
162 iErrorDes.Format(KWindowHandle, aActualEvent->iClientHandle, aExpectedEvent->iClientHandle);
166 return ComparePointerEvents(&aExpectedEvent->iPointerEvent, &aActualEvent->iPointerEvent);
169 void CMultiPtrClickMaker::OtherEvent(TInt aType, TAny* aParam)
171 if (aType != EEventPointer)
181 TPointerEventData expectedEvent;
182 iOtherEventBuffer.Remove(&expectedEvent);
186 TPointerEventData* data=static_cast<TPointerEventData*>(aParam);
188 if (!CompareOtherEvents(&expectedEvent, data))
190 iError = iPtrEventCount;
194 TInt CMultiPtrClickMaker::AddEvent(const TWsEvent* aEvent)
196 return iPtrEventBuffer.Add(aEvent);
199 TInt CMultiPtrClickMaker::AddEvent(const TPointerEventData* aEvent)
201 return iOtherEventBuffer.Add(aEvent);
204 TInt CMultiPtrClickMaker::CommandReplyL(TInt aOpcode, TAny *aArgs)
206 TMultiPtrClickArgUnion pData;
210 case EMultiPtrClickEventAdd:
211 return AddEvent(pData.WsEvent);
212 case EMultiPtrOtherEventAdd:
213 return AddEvent(pData.OtherEvent);
214 case EMultiPtrClickEventError:
216 case EMultiPtrClickEventErrorDesc:
217 if (iError != KErrNone)
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);
225 return iErrorDes.Length();
226 // returns the error description which gets displayed in logs if test failed
229 case EMultiPtrClickEventReset:
230 iPtrEventBuffer.Reset();
239 EXPORT_C CClickMaker* CreateMultiPtrClickMakerL()
241 CMultiPtrClickMaker* plugIn=new(ELeave) CMultiPtrClickMaker;
242 CleanupStack::PushL(plugIn);
243 plugIn->ConstructL();
244 CleanupStack::Pop(plugIn);