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