sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Test Multi Pointer Click Plug-In DLL sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "W32CLICK.H" sl@0: #include "multiptrclick.h" sl@0: sl@0: class CMultiPtrClickMaker : public CClickMaker sl@0: { sl@0: enum {EEventBufferSize=32}; sl@0: public: sl@0: ~CMultiPtrClickMaker(); sl@0: void ConstructL(); sl@0: //Virtual function from CClickMaker sl@0: void KeyEvent(TEventCode aType, const TKeyEvent& aEvent); sl@0: void PointerEvent(const TPointerEvent& aEvent); sl@0: void OtherEvent(TInt aType, TAny* aParam); sl@0: TInt CommandReplyL(TInt aOpcode, TAny *aArgs); sl@0: sl@0: private: sl@0: TInt AddEvent(const TWsEvent* aEvent); sl@0: TInt AddEvent(const TPointerEventData* aEvent); sl@0: TBool ComparePointerEvents(const TPointerEvent* aExpectedEvent, const TPointerEvent* aActualEvent); sl@0: TBool CompareOtherEvents(const TPointerEventData* aExpectedEvent, const TPointerEventData* aActualEvent); sl@0: private: sl@0: CCirBuf iPtrEventBuffer; sl@0: CCirBuf iOtherEventBuffer; sl@0: TBuf<255> iErrorDes; sl@0: TInt iPtrEventCount; sl@0: TInt iOtherEventCount; sl@0: TInt iError; sl@0: }; sl@0: sl@0: sl@0: void CMultiPtrClickMaker::ConstructL() sl@0: { sl@0: iPtrEventBuffer.SetLengthL(EEventBufferSize); sl@0: iOtherEventBuffer.SetLengthL(EEventBufferSize); sl@0: } sl@0: sl@0: CMultiPtrClickMaker::~CMultiPtrClickMaker() sl@0: { sl@0: } sl@0: sl@0: void CMultiPtrClickMaker::KeyEvent(TEventCode /*aType*/,const TKeyEvent& /*aEvent*/) sl@0: { sl@0: } sl@0: sl@0: TBool CMultiPtrClickMaker::ComparePointerEvents(const TPointerEvent* aExpectedEvent, const TPointerEvent* aActualEvent) sl@0: { sl@0: // Check pointer type sl@0: if (aExpectedEvent->iType != aActualEvent->iType) sl@0: { sl@0: _LIT(KEventType, "Actual Wserv Event type = %d Expected Wserv Event Type = %d "); sl@0: iErrorDes.Format(KEventType, aActualEvent->iType, aExpectedEvent->iType); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (aExpectedEvent->iPosition != aActualEvent->iPosition) sl@0: { sl@0: _LIT(KPointerPosition, "Actual PointerPosition = (%d, %d) Expected PointerPosition = (%d, %d) "); sl@0: iErrorDes.Format(KPointerPosition, aActualEvent->iPosition.iX, aActualEvent->iPosition.iY, aExpectedEvent->iPosition.iX, aExpectedEvent->iPosition.iY); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (aExpectedEvent->iParentPosition != aActualEvent->iParentPosition) sl@0: { sl@0: _LIT(KPointerPosition, "Actual parent Position = (%d, %d) Expected parent Position = (%d, %d) "); sl@0: iErrorDes.Format(KPointerPosition, aActualEvent->iParentPosition.iX, aActualEvent->iParentPosition.iY, aExpectedEvent->iParentPosition.iX, aExpectedEvent->iParentPosition.iY); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (aExpectedEvent->IsAdvancedPointerEvent() != aActualEvent->IsAdvancedPointerEvent()) sl@0: { sl@0: _LIT(KPointerPosition, "Actual event is TAdvancedPointerEvent = %d Expected event is TAdvancedPointerEvent = %d "); sl@0: iErrorDes.Format(KPointerPosition, aActualEvent->IsAdvancedPointerEvent(), aExpectedEvent->IsAdvancedPointerEvent()); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (aExpectedEvent->IsAdvancedPointerEvent()) sl@0: { sl@0: const TAdvancedPointerEvent& expectedAdvancedEvent = *aExpectedEvent->AdvancedPointerEvent(); sl@0: const TAdvancedPointerEvent& actualAdvancedEvent = *aActualEvent->AdvancedPointerEvent(); sl@0: sl@0: if (expectedAdvancedEvent.PointerNumber() != actualAdvancedEvent.PointerNumber()) sl@0: { sl@0: _LIT(KPointerNumber, "Actual PointerNumber = %d Expected PointerNumber = %d "); sl@0: iErrorDes.Format(KPointerNumber, actualAdvancedEvent.PointerNumber(), expectedAdvancedEvent.PointerNumber()); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (expectedAdvancedEvent.Pressure() != actualAdvancedEvent.Pressure()) sl@0: { sl@0: _LIT(KPointerPressure, "Actual Pressure = %d Expected Pressure = %d "); sl@0: iErrorDes.Format(KPointerPressure, actualAdvancedEvent.Pressure(), expectedAdvancedEvent.Pressure()); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (expectedAdvancedEvent.Proximity() != actualAdvancedEvent.Proximity()) sl@0: { sl@0: _LIT(KPointerProximity, "Actual Proximity = %d Expected Proximity = %d "); sl@0: iErrorDes.Format(KPointerProximity, actualAdvancedEvent.Proximity(), expectedAdvancedEvent.Proximity()); sl@0: return EFalse; sl@0: } sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: // sl@0: void CMultiPtrClickMaker::PointerEvent(const TPointerEvent& aEvent) sl@0: { sl@0: // If it has already failed then do not test other events sl@0: // becasue the error value and its descriptor will be over written sl@0: if (iError) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: // Get pointer event from buffer sl@0: TWsEvent expectedEvent; sl@0: iPtrEventBuffer.Remove(&expectedEvent); sl@0: sl@0: // Increment event count sl@0: iPtrEventCount++; sl@0: sl@0: // increment this counter in OtherEvent() becasue first pointer event iscalled and then OtherEvent() is called sl@0: if (!ComparePointerEvents(expectedEvent.Pointer(), &aEvent)) sl@0: { sl@0: iError = iPtrEventCount; sl@0: } sl@0: } sl@0: sl@0: TBool CMultiPtrClickMaker::CompareOtherEvents(const TPointerEventData* aExpectedEvent, const TPointerEventData* aActualEvent) sl@0: { sl@0: if (aExpectedEvent->iCurrentPos != aActualEvent->iCurrentPos) sl@0: { sl@0: _LIT(KCurrentPosition, "Actual CurrentPosition w.r.t screen = (%d,%d) Expected CurrentPosition w.r.t screen = (%d,%d)"); sl@0: iErrorDes.Copy(KCurrentPosition); sl@0: iErrorDes.Format(KCurrentPosition, aActualEvent->iCurrentPos.iX, aActualEvent->iCurrentPos.iX, aExpectedEvent->iCurrentPos.iX, aExpectedEvent->iCurrentPos.iY); sl@0: return EFalse; sl@0: } sl@0: sl@0: if (aExpectedEvent->iClientHandle != aActualEvent->iClientHandle) sl@0: { sl@0: _LIT(KWindowHandle, "Actual Window Handle = %d Expected Window Handle = %d "); sl@0: iErrorDes.Copy(KWindowHandle); sl@0: iErrorDes.Format(KWindowHandle, aActualEvent->iClientHandle, aExpectedEvent->iClientHandle); sl@0: return EFalse; sl@0: } sl@0: sl@0: return ComparePointerEvents(&aExpectedEvent->iPointerEvent, &aActualEvent->iPointerEvent); sl@0: } sl@0: sl@0: void CMultiPtrClickMaker::OtherEvent(TInt aType, TAny* aParam) sl@0: { sl@0: if (aType != EEventPointer) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: if (iError) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: TPointerEventData expectedEvent; sl@0: iOtherEventBuffer.Remove(&expectedEvent); sl@0: sl@0: iOtherEventCount++; sl@0: sl@0: TPointerEventData* data=static_cast(aParam); sl@0: sl@0: if (!CompareOtherEvents(&expectedEvent, data)) sl@0: { sl@0: iError = iPtrEventCount; sl@0: } sl@0: } sl@0: sl@0: TInt CMultiPtrClickMaker::AddEvent(const TWsEvent* aEvent) sl@0: { sl@0: return iPtrEventBuffer.Add(aEvent); sl@0: } sl@0: sl@0: TInt CMultiPtrClickMaker::AddEvent(const TPointerEventData* aEvent) sl@0: { sl@0: return iOtherEventBuffer.Add(aEvent); sl@0: } sl@0: sl@0: TInt CMultiPtrClickMaker::CommandReplyL(TInt aOpcode, TAny *aArgs) sl@0: { sl@0: TMultiPtrClickArgUnion pData; sl@0: pData.any=aArgs; sl@0: switch (aOpcode) sl@0: { sl@0: case EMultiPtrClickEventAdd: sl@0: return AddEvent(pData.WsEvent); sl@0: case EMultiPtrOtherEventAdd: sl@0: return AddEvent(pData.OtherEvent); sl@0: case EMultiPtrClickEventError: sl@0: return iError; sl@0: case EMultiPtrClickEventErrorDesc: sl@0: if (iError != KErrNone) sl@0: { sl@0: RChunk chunk; sl@0: chunk.OpenGlobal(KMultiPtrClickChunk, ETrue); sl@0: TUint8* desPtr = chunk.Base() + *(static_cast(aArgs)); sl@0: TPtr8 ptrDes(desPtr, iErrorDes.Length(), iErrorDes.Length()); sl@0: ptrDes.Copy(iErrorDes); sl@0: chunk.Close(); sl@0: return iErrorDes.Length(); sl@0: // returns the error description which gets displayed in logs if test failed sl@0: } sl@0: break; sl@0: case EMultiPtrClickEventReset: sl@0: iPtrEventBuffer.Reset(); sl@0: iError = 0; sl@0: iPtrEventCount = 0; sl@0: break; sl@0: default:; sl@0: } sl@0: return(KErrNone); sl@0: } sl@0: sl@0: EXPORT_C CClickMaker* CreateMultiPtrClickMakerL() sl@0: { sl@0: CMultiPtrClickMaker* plugIn=new(ELeave) CMultiPtrClickMaker; sl@0: CleanupStack::PushL(plugIn); sl@0: plugIn->ConstructL(); sl@0: CleanupStack::Pop(plugIn); sl@0: return plugIn; sl@0: }