os/graphics/windowing/windowserver/test/tauto/TPntKey.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) 1996-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
// Converted from TMan test code (TMPNTKEY.CPP) May 2001
sl@0
    15
// Test Pointer move/drag buffer
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @test
sl@0
    22
 @internalComponent - Internal Symbian test code
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include "TPNTKEY.H"
sl@0
    26
sl@0
    27
#define LOGGING on	//Uncomment this line to get more logging
sl@0
    28
sl@0
    29
TInt CTPntKeyWindow::iTestScanCodes[ENumPntKeyTests]={'A','B',0,'C',EStdKeyEnter,'Y'};
sl@0
    30
TUint CTPntKeyWindow::iTestCodes[ENumPntKeyTests]={'a','B',0,'c',EKeyEnter,'y'};
sl@0
    31
TUint CTPntKeyWindow::iTestModifiers[ENumPntKeyTests]={0,EModifierShift,0,0,0,0};
sl@0
    32
sl@0
    33
CTPntKeyWindow::CTPntKeyWindow(CTPntKey *aTest) : iTest(aTest)
sl@0
    34
	{}
sl@0
    35
sl@0
    36
CTPntKeyWindow::~CTPntKeyWindow()
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
void CTPntKeyWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
sl@0
    41
	{
sl@0
    42
	ConstructExtLD(*parent,pos,size);
sl@0
    43
	iWin.SetPointerGrab(ETrue);
sl@0
    44
	iKey1=TRect(size.iWidth*1/16,size.iHeight/2,size.iWidth*5/16,size.iHeight);
sl@0
    45
	iKey2=TRect(size.iWidth*6/16,size.iHeight/2,size.iWidth*10/16,size.iHeight);
sl@0
    46
	iKey3=TRect(size.iWidth*11/16,size.iHeight/2,size.iWidth*15/16,size.iHeight);
sl@0
    47
	iWin.AddKeyRect(iKey1,'A',EFalse);
sl@0
    48
	iWin.AddKeyRect(iKey2,'B',EFalse);
sl@0
    49
	AssignGC(*Client()->iGc);
sl@0
    50
	BaseWin()->EnableOnEvents();
sl@0
    51
	Activate();
sl@0
    52
	}
sl@0
    53
sl@0
    54
void CTPntKeyWindow::Error(TInt aWhere)
sl@0
    55
	{
sl@0
    56
	iTest->Failed(aWhere);
sl@0
    57
	}
sl@0
    58
sl@0
    59
void CTPntKeyWindow::NextKey()
sl@0
    60
	{
sl@0
    61
	if (++iKeyCount!=ENumPntKeyTests)
sl@0
    62
		{
sl@0
    63
	#if defined(LOGGING)
sl@0
    64
		_LIT(KLog,"Next Key  KeyCount=%d");
sl@0
    65
		iTest->LOG_MESSAGE2(KLog,iKeyCount);
sl@0
    66
	#endif
sl@0
    67
		if (iKeyCount==2)
sl@0
    68
			iWin.RemoveAllKeyRects();
sl@0
    69
		else if (iKeyCount==3)
sl@0
    70
			iWin.AddKeyRect(iKey3,'C',EFalse);
sl@0
    71
		else if (iKeyCount==4)
sl@0
    72
			{
sl@0
    73
	#if !defined(__WINS__)
sl@0
    74
			if (iTest->NoDigitiser())
sl@0
    75
				{
sl@0
    76
				return;
sl@0
    77
				}
sl@0
    78
	#endif
sl@0
    79
			iWin.RemoveAllKeyRects();
sl@0
    80
			iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Z',EFalse);
sl@0
    81
			}
sl@0
    82
		else if (iKeyCount==5)
sl@0
    83
			{
sl@0
    84
			iWin.RemoveAllKeyRects();
sl@0
    85
			Client()->iWs.Flush();
sl@0
    86
			User::After(500000);	// Wait half a second
sl@0
    87
			iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Y',ETrue);
sl@0
    88
			}
sl@0
    89
		Invalidate();
sl@0
    90
		}
sl@0
    91
	SendEvent();
sl@0
    92
	}
sl@0
    93
sl@0
    94
void CTPntKeyWindow::SendEvent()
sl@0
    95
	{
sl@0
    96
	TheClient->WaitForRedrawsToFinish();
sl@0
    97
#if defined(LOGGING)
sl@0
    98
	_LIT(KLog,"SendEvent  KeyCount=%d");
sl@0
    99
	iTest->LOG_MESSAGE2(KLog,iKeyCount);
sl@0
   100
#endif
sl@0
   101
	switch(iKeyCount)
sl@0
   102
		{
sl@0
   103
		case 0:
sl@0
   104
			SimulatePointerDownUp(iKey1);
sl@0
   105
			break;
sl@0
   106
		case 1:
sl@0
   107
			iTest->TestBase()->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
sl@0
   108
			SimulatePointerDownUp(iKey2);
sl@0
   109
			iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
sl@0
   110
			break;
sl@0
   111
		case 2:
sl@0
   112
		case 5:
sl@0
   113
			{
sl@0
   114
			TPoint pos=Position();
sl@0
   115
			TSize size=Size();
sl@0
   116
			iTest->TestBase()->SimulatePointerDownUp(pos.iX+size.iWidth/2,pos.iY+size.iHeight/4);
sl@0
   117
			}
sl@0
   118
			break;
sl@0
   119
		case 3:
sl@0
   120
			SimulatePointerDownUp(iKey3);
sl@0
   121
			break;
sl@0
   122
		case 4:
sl@0
   123
			iTest->TestBase()->SimulateKeyDownUp(EStdKeyEnter);
sl@0
   124
			break;
sl@0
   125
		}
sl@0
   126
	}
sl@0
   127
sl@0
   128
void CTPntKeyWindow::SimulatePointerDownUp(const TRect& aRect)
sl@0
   129
	{
sl@0
   130
	iTest->TestBase()->SimulatePointerDownUp((aRect.iTl.iX+aRect.iBr.iX)/2,(aRect.iTl.iY+aRect.iBr.iY)/2);
sl@0
   131
	}
sl@0
   132
sl@0
   133
void CTPntKeyWindow::Test(TInt aCheck)
sl@0
   134
	{
sl@0
   135
	if (!aCheck)
sl@0
   136
		Error(3);
sl@0
   137
	}
sl@0
   138
sl@0
   139
void CTPntKeyWindow::KeyUpL(const TKeyEvent &aKey,const TTime&)
sl@0
   140
	{
sl@0
   141
	if (aKey.iScanCode==iTestScanCodes[iKeyCount])
sl@0
   142
		NextKey();
sl@0
   143
	}
sl@0
   144
sl@0
   145
void CTPntKeyWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
sl@0
   146
	{
sl@0
   147
#if defined(LOGGING)
sl@0
   148
	_LIT(KLog,"KeyDownL  ScanCode=%d '%c' (%d)  KeyCount=%d");
sl@0
   149
	iTest->LOG_MESSAGE5(KLog,aKey.iScanCode,aKey.iScanCode,iTestScanCodes[iKeyCount],iKeyCount);
sl@0
   150
#endif
sl@0
   151
	if (aKey.iScanCode!=EStdKeyLeftFunc && aKey.iScanCode!=EStdKeyRightFunc && 
sl@0
   152
		 aKey.iScanCode!=EStdKeyLeftAlt && aKey.iScanCode!=EStdKeyRightAlt &&
sl@0
   153
		 aKey.iScanCode!=EStdKeyLeftCtrl && aKey.iScanCode!=EStdKeyRightCtrl &&
sl@0
   154
		 aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift && 
sl@0
   155
		 aKey.iScanCode!=EStdKeyOff &&
sl@0
   156
		 aKey.iScanCode!=EStdKeyEscape)
sl@0
   157
		Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
sl@0
   158
	}
sl@0
   159
sl@0
   160
void CTPntKeyWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
sl@0
   161
	{
sl@0
   162
	if (aKey.iCode!=EKeyEscape)
sl@0
   163
		{
sl@0
   164
#if defined(LOGGING)
sl@0
   165
		_LIT(KLog1,"WinKeyL1  ScanCode=%d (%d)  Code=%d '%c' (%d)");
sl@0
   166
		_LIT(KLog2,"WinKeyL2  ScanCode=%d  Modifiers=0x%x (0x%x) KeyCount=%d");
sl@0
   167
		iTest->LOG_MESSAGE6(KLog1,aKey.iScanCode,iTestScanCodes[iKeyCount],aKey.iCode,aKey.iCode,iTestCodes[iKeyCount]);
sl@0
   168
		iTest->LOG_MESSAGE5(KLog2,aKey.iScanCode,aKey.iModifiers&EModifierMask,iTestModifiers[iKeyCount]&EModifierMask,iKeyCount);
sl@0
   169
#endif
sl@0
   170
		Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
sl@0
   171
		Test(aKey.iCode==iTestCodes[iKeyCount]);
sl@0
   172
		Test((aKey.iModifiers&EModifierMask)==(iTestModifiers[iKeyCount]&EModifierMask));
sl@0
   173
		}
sl@0
   174
	}
sl@0
   175
sl@0
   176
void CTPntKeyWindow::SwitchOn(const TTime &)
sl@0
   177
	{
sl@0
   178
#if defined(LOGGING)
sl@0
   179
	_LIT(KLog,"SwitchOn  KeyCount=%d");
sl@0
   180
	iTest->LOG_MESSAGE2(KLog,iKeyCount);
sl@0
   181
#endif
sl@0
   182
	if (iKeyCount==4)
sl@0
   183
		NextKey();
sl@0
   184
 	else if (iKeyCount!=5)
sl@0
   185
		Error(2);
sl@0
   186
	}
sl@0
   187
sl@0
   188
void CTPntKeyWindow::PointerL(const TPointerEvent &aPointer,const TTime &)
sl@0
   189
	{
sl@0
   190
#if defined(LOGGING)
sl@0
   191
	_LIT(KLog,"Pointer Event  Type=%d  Pos=(%d,%d)  PPos=(%d,%d)  KeyCount=%d");
sl@0
   192
	iTest->LOG_MESSAGE7(KLog,aPointer.iType,aPointer.iPosition.iX,aPointer.iPosition.iY
sl@0
   193
						,aPointer.iParentPosition.iX,aPointer.iParentPosition.iY,iKeyCount);
sl@0
   194
#endif
sl@0
   195
	if (aPointer.iType==TPointerEvent::EButton1Down)
sl@0
   196
		{
sl@0
   197
		if (iKeyCount!=2)
sl@0
   198
			Error(1);
sl@0
   199
		else
sl@0
   200
			NextKey();
sl@0
   201
		}
sl@0
   202
	}
sl@0
   203
sl@0
   204
void CTPntKeyWindow::DrawButton(const TRect &aRect, const TDesC &aText)
sl@0
   205
	{
sl@0
   206
	iGc->DrawRect(aRect);
sl@0
   207
	iGc->DrawText(aText, TPoint((aRect.iBr.iX+aRect.iTl.iX)/2,(aRect.iBr.iY+aRect.iTl.iY)/2));
sl@0
   208
	}
sl@0
   209
sl@0
   210
void CTPntKeyWindow::Draw()
sl@0
   211
	{
sl@0
   212
	iGc->SetBrushColor(TRgb::Gray4(0));
sl@0
   213
	iGc->SetPenColor(TRgb::Gray4(3));
sl@0
   214
	iGc->Clear();
sl@0
   215
	DrawButton(iKey1,_L("A"));
sl@0
   216
	DrawButton(iKey2,_L("B"));
sl@0
   217
	DrawButton(iKey3,_L("C"));
sl@0
   218
	switch(iKeyCount)
sl@0
   219
		{
sl@0
   220
		case 0:
sl@0
   221
			iGc->DrawText(_L("Click on 'A'"), TPoint(10,20));
sl@0
   222
			break;
sl@0
   223
		case 1:
sl@0
   224
			iGc->DrawText(_L("Shift-Click on 'B'"), TPoint(10,20));
sl@0
   225
			break;
sl@0
   226
		case 2:
sl@0
   227
			iGc->DrawText(_L("Click anywhere in this window"), TPoint(10,20));
sl@0
   228
			break;
sl@0
   229
		case 3:
sl@0
   230
			iGc->DrawText(_L("Click on 'C'"), TPoint(10,20));
sl@0
   231
			break;
sl@0
   232
		case 4:
sl@0
   233
#if defined(__WINS__)	// Can't emulate touching dig when switched off under WINS
sl@0
   234
			iGc->DrawText(_L("Switch off and on (or press Enter)"), TPoint(10,20));
sl@0
   235
#else
sl@0
   236
			iGc->DrawText(_L("Switch off, then touch the screen to switch on"), TPoint(10,20));
sl@0
   237
#endif
sl@0
   238
			break;
sl@0
   239
		case 5:
sl@0
   240
#if defined(__WINS__)	// Can't emulate touching dig when switched off under WINS
sl@0
   241
			iGc->DrawText(_L("Touch anywhere in the window"), TPoint(10,20));
sl@0
   242
#else
sl@0
   243
			iGc->DrawText(_L("Switch off and touch the screen to switch on again"), TPoint(10,20));
sl@0
   244
#endif
sl@0
   245
			break;
sl@0
   246
		}
sl@0
   247
	}
sl@0
   248
sl@0
   249
CTPntKey::CTPntKey(CTestStep* aStep):
sl@0
   250
	CTWsGraphicsBase(aStep)
sl@0
   251
	{
sl@0
   252
	}
sl@0
   253
sl@0
   254
CTPntKey::~CTPntKey()
sl@0
   255
	{
sl@0
   256
	HAL::Set(HALData::EPenDisplayOn,iOldPointerState);
sl@0
   257
	CTWin::Delete(iWin);
sl@0
   258
	Client()->ResetFocus();
sl@0
   259
	delete iTimeOut;
sl@0
   260
	}
sl@0
   261
sl@0
   262
TInt CTPntKey::TimeOut(TAny* aTest)		//static
sl@0
   263
	{
sl@0
   264
	static_cast<CTPntKey*>(aTest)->TimeOut();
sl@0
   265
	return(KErrNone);
sl@0
   266
	}
sl@0
   267
sl@0
   268
void CTPntKey::TimeOut()
sl@0
   269
	{
sl@0
   270
	TLogMessageText buf;
sl@0
   271
	_LIT(KPntKeyTimeOut,"TIMEOUT: Pointer Key, %d, %S");
sl@0
   272
	buf.AppendFormat(KPntKeyTimeOut,iState,&TestBase()->iSubTitle);
sl@0
   273
	TheClient->LogMessage(buf);
sl@0
   274
	Failed(4);
sl@0
   275
	}
sl@0
   276
sl@0
   277
void CTPntKey::Failed(TInt aWhere)
sl@0
   278
	{
sl@0
   279
	_LIT(KLog,"Failed at %d");
sl@0
   280
	LOG_MESSAGE2(KLog,aWhere);
sl@0
   281
	if (!iFailed)
sl@0
   282
		{
sl@0
   283
		iFailed=ETrue;
sl@0
   284
		Client()->iGroup->ClearCurrentWindow();
sl@0
   285
		}
sl@0
   286
	}
sl@0
   287
sl@0
   288
void CTPntKey::ConstructL()
sl@0
   289
	{
sl@0
   290
	TInt mods=TheClient->iWs.GetModifierState();
sl@0
   291
	if (mods&EModifierCapsLock)
sl@0
   292
		iTest->SimulateKeyDownUp(EStdKeyCapsLock);
sl@0
   293
	//Make sure all the keys we test are in the up state
sl@0
   294
	iTest->SimulateKeyDownUp(EStdKeyLeftShift);
sl@0
   295
	iTest->SimulateKeyDownUp(EStdKeyRightShift);
sl@0
   296
	iTest->SimulateKeyDownUp(EStdKeyLeftFunc);
sl@0
   297
	iTest->SimulateKeyDownUp(EStdKeyLeftCtrl);
sl@0
   298
	iTest->SimulateKeyDownUp(EStdKeyRightCtrl);
sl@0
   299
	mods=TheClient->iWs.GetModifierState();
sl@0
   300
	_LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
sl@0
   301
	LOG_MESSAGE2(KLog,mods);
sl@0
   302
	TheClient->iScreen->SetScreenMode(0);		//May sure we are in the right screen size mode
sl@0
   303
	TheClient->iScreen->SetAppScreenMode(0);
sl@0
   304
	TheClient->iWs.SetPointerCursorArea(TestBase()->iNormalPointerCursorArea);
sl@0
   305
	CTPntKeyWindow *win=new(ELeave) CTPntKeyWindow(this);
sl@0
   306
	win->SetUpLD(TPoint(20,20),Client()->iScreen->SizeInPixels()-TSize(40,40),Client()->iGroup);
sl@0
   307
	iWin=win;
sl@0
   308
	Client()->iGroup->SetCurrentWindow(iWin);
sl@0
   309
	iNoDigitiser=EFalse;
sl@0
   310
	TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState);
sl@0
   311
	if (err==KErrNotSupported)
sl@0
   312
		{
sl@0
   313
		iNoDigitiser=ETrue;
sl@0
   314
		}
sl@0
   315
	else if (err==KErrNone)
sl@0
   316
		{
sl@0
   317
		err=HAL::Set(HALData::EPenDisplayOn,ETrue);
sl@0
   318
		if (err==KErrNotSupported)
sl@0
   319
			iNoDigitiser=(!iOldPointerState);
sl@0
   320
		}
sl@0
   321
	else
sl@0
   322
		{
sl@0
   323
		TEST(EFalse);
sl@0
   324
		}
sl@0
   325
	TheClient->WaitForRedrawsToFinish();	//Make sure all pending events have been delt with (redraw events are lowest priority)
sl@0
   326
	iTimeOut=new(ELeave) CTimeOut();
sl@0
   327
	iTimeOut->ConstructL();
sl@0
   328
	iTimeOut->Start(KTimeOutAfter,TCallBack(CTPntKey::TimeOut,this));
sl@0
   329
	}
sl@0
   330
sl@0
   331
void CTPntKey::RunTestCaseL(TInt /*aCurTestCase*/)
sl@0
   332
	{
sl@0
   333
	_LIT(KTestName,"Key set 1");
sl@0
   334
	TEST(!iFailed);
sl@0
   335
	if (iFailed)
sl@0
   336
		{
sl@0
   337
		_LIT(KLog,"Test Failed  Substate=%d  KeyCount=%d");
sl@0
   338
		LOG_MESSAGE3(KLog,iTest->iState,iWin->KeyCount());
sl@0
   339
		}
sl@0
   340
	((CTPntKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
   341
	switch(++iTest->iState)
sl@0
   342
		{
sl@0
   343
/**
sl@0
   344
@SYMTestCaseID		GRAPHICS-WSERV-0200
sl@0
   345
sl@0
   346
@SYMDEF             DEF081259
sl@0
   347
sl@0
   348
@SYMTestCaseDesc    Test Pointer move/drag buffer
sl@0
   349
sl@0
   350
@SYMTestPriority    High
sl@0
   351
sl@0
   352
@SYMTestStatus      Implemented
sl@0
   353
sl@0
   354
@SYMTestActions     Exercise the pointer move/drag buffer and check
sl@0
   355
					that it functions correctly
sl@0
   356
sl@0
   357
@SYMTestExpectedResults The buffer functions correctly
sl@0
   358
*/
sl@0
   359
		case 1:
sl@0
   360
			((CTPntKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0200"));
sl@0
   361
			iTest->LogSubTest(KTestName);
sl@0
   362
			if (TestBase()->ConfigurationSupportsPointerEventTesting())
sl@0
   363
			    {
sl@0
   364
			    iWin->SendEvent();
sl@0
   365
			    TheClient->Flush();
sl@0
   366
			    }
sl@0
   367
			else
sl@0
   368
			    {
sl@0
   369
			    INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
sl@0
   370
			    }
sl@0
   371
			break;
sl@0
   372
		case 2:
sl@0
   373
			((CTPntKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   374
			((CTPntKeyStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   375
			if (TestBase()->ConfigurationSupportsPointerEventTesting())
sl@0
   376
			    {
sl@0
   377
                iTimeOut->Cancel();
sl@0
   378
			    }
sl@0
   379
			TestComplete();
sl@0
   380
			break;
sl@0
   381
		}
sl@0
   382
	((CTPntKeyStep*)iStep)->RecordTestResultL();
sl@0
   383
	}
sl@0
   384
	
sl@0
   385
__WS_CONSTRUCT_STEP__(PntKey)