windowing/windowserver/tauto/TKRepeat.CPP
changeset 116 171fae344dd4
parent 103 2717213c588a
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
     1 // Copyright (c) 1996-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 // Converted from TMan test code May 2001
       
    15 // Keyboard repeat test
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "TKRepeat.H"
       
    20 
       
    21 #define LOGGING 1
       
    22 
       
    23 //
       
    24 // CRKWindow, class //
       
    25 //
       
    26 
       
    27 CRKWindow::CRKWindow(CTKRepeat *aTest) : CTWin(), iTest(aTest)
       
    28 	{
       
    29 	}
       
    30 
       
    31 void CRKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
       
    32 	{
       
    33 	ConstructExtLD(*parent,pos,size);
       
    34 	iWin.SetBackgroundColor(TRgb::Gray256(230));
       
    35 	Activate();
       
    36 	AssignGC(aGc);
       
    37 	}
       
    38 
       
    39 void CRKWindow::Draw()
       
    40 	{
       
    41 	iGc->Clear();
       
    42 	switch(iState)
       
    43 		{
       
    44 		case EStateWaitingForKeyDown:
       
    45 			iGc->DrawText(_L("Press and hold the space bar"), TPoint(10,20));
       
    46 			break;
       
    47 		case EStateWaitingForFirstRepeat:
       
    48 		case EStateWaitingForNthRepeat:
       
    49 			{
       
    50 			TBuf<0x40> buf;
       
    51 			buf.Format(TRefByValue<const TDesC>(_L("Keep space bar down (%d repeats so far)")),iRepCount);
       
    52 			iGc->DrawText(buf, TPoint(10,20));
       
    53 			}
       
    54 			break;
       
    55 		case EStateWaitingForKeyUp:
       
    56 			iGc->DrawText(_L("Release space bar"), TPoint(10,20));
       
    57 		default:
       
    58 			break;
       
    59 		}
       
    60 	}
       
    61 
       
    62 void CRKWindow::SetState(TRKStates aState)
       
    63 	{
       
    64 #if defined(LOGGING)
       
    65 	TLogMessageText logMessageText;
       
    66 	_LIT(KStateChange,"State Change  Old=%d  New=%d");
       
    67 	logMessageText.Format(KStateChange,iState,aState);
       
    68 	iTest->LOG_MESSAGE(logMessageText);
       
    69 #endif
       
    70 	iState=aState;
       
    71 	DrawNow();
       
    72 	TheClient->WaitForRedrawsToFinish();
       
    73 	SendEvent();
       
    74 	}
       
    75 
       
    76 void CRKWindow::SendEvent()
       
    77 	{
       
    78 	switch (iState)
       
    79 		{
       
    80 	case EStateWaitingForKeyDown:
       
    81 	case EStateWaitingForKeyUp:
       
    82 	#if defined(LOGGING)
       
    83 		_LIT(KKeyUp,"Send key up event  substate 0");
       
    84 		_LIT(KKeyDown,"Send key down event  substate 4");
       
    85 		iTest->LOG_MESSAGE(iState==EStateWaitingForKeyDown ? KKeyDown() : KKeyUp());
       
    86 	#endif
       
    87 		iTest->TestBase()->SimulateKey((iState==EStateWaitingForKeyDown ? TRawEvent::EKeyDown : TRawEvent::EKeyUp),EStdKeySpace);
       
    88 		break;
       
    89 	case EStateWaitingForKeyCode:
       
    90 	case EStateWaitingForFirstRepeat:
       
    91 	case EStateWaitingForNthRepeat:
       
    92 	case EStateInactive:
       
    93 	case EStateError:
       
    94 	#if defined(LOGGING)
       
    95 		_LIT(KLog,"SendEvent:  substate %d so no event to send");
       
    96 		iTest->LOG_MESSAGE2(KLog,iState);
       
    97 	#endif
       
    98 		break;
       
    99 		}
       
   100 	}
       
   101 
       
   102 TBool CRKWindow::CheckResults()
       
   103 	{
       
   104 //
       
   105 // Checks repeat results, first convert everything to 10th's as that what is actually used 
       
   106 // for the timer in the window server.
       
   107 //
       
   108 // Return ETrue if the inacuracy in the average time is greater than 1/10th either way
       
   109 // Allow initial 2/10ths either
       
   110 // Allow min 2/10ths below
       
   111 // Allow max 2/10ths above
       
   112 //
       
   113 	if (iState!=EStateInactive)
       
   114 		return(ETrue);
       
   115 	TInt initial=iInitialGap.Int()/100000;
       
   116 	TInt initialX=iInitialRepeatSet.Int()/100000;
       
   117 	if (initialX==0)
       
   118 		initialX=1;
       
   119 	TInt average=(iTotalGap.Int()/100000)/(iRepCount-1);
       
   120 	TInt repeatX=iRepeatSet.Int()/100000;
       
   121 	if (repeatX==0)
       
   122 		repeatX=1;
       
   123 	TInt min=iMinGap.Int()/100000;
       
   124 	TInt max=iMaxGap.Int()/100000;
       
   125 	if (average>(repeatX+1) || average<(repeatX-1))
       
   126 		return(ETrue);
       
   127 	if (initial>(initialX+2) || initial<(initialX-2))
       
   128 		return(ETrue);
       
   129 #if defined(__MARM_ARM4__)
       
   130 	if (min>(repeatX+1) || min<(repeatX-2) || max>(repeatX+3) || max<repeatX)
       
   131 		{
       
   132 		if (max<min || (max+min)<2*(repeatX-2) || (max+min)>2*(repeatX+2))
       
   133 			return(ETrue);
       
   134 		}
       
   135 #else
       
   136 	if (min>(repeatX+1) || min<(repeatX-2))
       
   137 		return(ETrue);
       
   138 	if (max>(repeatX+3) || max<repeatX)
       
   139 		return(ETrue);
       
   140 #endif
       
   141 	return(EFalse);
       
   142 	}
       
   143 
       
   144 TDesC& CRKWindow::Report()
       
   145 	{
       
   146 	if (iState!=EStateInactive)
       
   147 		{
       
   148 		iReport.Format(_L("Error, test not completed"));
       
   149 		}
       
   150 	else
       
   151 		{
       
   152 		TInt initial=iInitialGap.Int()/10000;
       
   153 		TInt initialX=iInitialRepeatSet.Int()/10000;
       
   154 		TInt average=(iTotalGap.Int()/10000/(iRepCount-1));
       
   155 		TInt repeatX=iRepeatSet.Int()/10000;
       
   156 		TInt min=iMinGap.Int()/10000;
       
   157 		TInt max=iMaxGap.Int()/10000;
       
   158 		iReport.Format(TRefByValue<const TDesC>(_L("Initial=%d [%d], Av=%d [%d], Min=%d, Max=%d")),initial,initialX,average,repeatX,min,max);
       
   159 		}
       
   160 	return(iReport);
       
   161 	}
       
   162 
       
   163 void CRKWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
       
   164 	{
       
   165 #if defined(LOGGING)
       
   166 	TLogMessageText logMessageText;
       
   167 	_LIT(KKeyDown,"CRKWindow::KeyDownL  Code=%d '%c'  State=%d (0)");
       
   168 	logMessageText.Format(KKeyDown,aKey.iScanCode,aKey.iScanCode,iState);
       
   169 	iTest->LOG_MESSAGE(logMessageText);
       
   170 #endif
       
   171 	switch(iState)
       
   172 		{
       
   173 		case EStateWaitingForKeyDown:
       
   174 			SetState(EStateWaitingForKeyCode);
       
   175 			iDownCode=aKey.iScanCode;
       
   176 			break;
       
   177 		default:;
       
   178 		}
       
   179 	}
       
   180 
       
   181 void CRKWindow::KeyUpL(const TKeyEvent &aKey,const TTime &)
       
   182 	{
       
   183 #if defined(LOGGING)
       
   184 	TLogMessageText logMessageText;
       
   185 	_LIT(KKeyUp,"CRKWindow::KeyUpL  Code=%d (%c)  State=%d  Down=%d");
       
   186 	logMessageText.Format(KKeyUp,aKey.iScanCode,aKey.iScanCode,iState,iDownCode);
       
   187 	iTest->LOG_MESSAGE(logMessageText);
       
   188 #endif
       
   189 	if (aKey.iScanCode==iDownCode)
       
   190 		{
       
   191 		switch(iState)
       
   192 			{
       
   193 			case EStateWaitingForKeyUp:
       
   194 				SetState(EStateInactive);
       
   195 				break;
       
   196 			default:
       
   197 				SetState(EStateError);
       
   198 				break;
       
   199 			}
       
   200 		CActiveScheduler::Stop();
       
   201 		}
       
   202 	}
       
   203 
       
   204 void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime)
       
   205 	{
       
   206 	if (aKey.iCode==EKeyEscape)
       
   207 		{
       
   208 		CActiveScheduler::Stop();
       
   209 		iTest->iAbort=ETrue;
       
   210 		}
       
   211 #if defined(LOGGING)
       
   212 	TLogMessageText logMessageText;
       
   213 	_LIT(KKey,"CRKWindow::WinKeyL  Code=%d (%c)  State=%d  RepeatCount=%d");
       
   214 	logMessageText.Format(KKey,aKey.iScanCode,aKey.iScanCode,iState,iRepCount);
       
   215 	iTest->LOG_MESSAGE(logMessageText);
       
   216 #endif
       
   217 	if (aKey.iCode==32)
       
   218 		{
       
   219 		switch(iState)
       
   220 			{
       
   221 			case EStateWaitingForKeyCode:
       
   222 				SetState(EStateWaitingForFirstRepeat);
       
   223 				iPrevTime=aTime;
       
   224 				break;
       
   225 			case EStateWaitingForFirstRepeat:
       
   226 				iRepCount=1;
       
   227 				iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64());
       
   228 				SetState(EStateWaitingForNthRepeat);
       
   229 				break;
       
   230 			case EStateWaitingForNthRepeat:
       
   231 				if (iRepCount==5)
       
   232 					SetState(EStateWaitingForKeyUp);
       
   233 				else
       
   234 					{
       
   235 					TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()));
       
   236 				#if defined(LOGGING)
       
   237 					TLogMessageText logMessageText;
       
   238 					_LIT(KRepeatGap,"Repeat after %d");
       
   239 					logMessageText.AppendFormat(KRepeatGap,gap.Int());
       
   240 					iTest->LOG_MESSAGE(logMessageText);
       
   241 					TheClient->Flush();
       
   242 				#endif
       
   243 					if (gap<iMinGap)
       
   244 						iMinGap=gap;
       
   245 					if (gap>iMaxGap)
       
   246 						iMaxGap=gap;
       
   247 					iTotalGap=iTotalGap.Int()+gap.Int();	// Horrible way to do a +=
       
   248 					iRepCount++;
       
   249 					SetState(EStateWaitingForNthRepeat);
       
   250 					}
       
   251 			case EStateWaitingForKeyUp: 	// Do nothing here
       
   252 				break;
       
   253 			default:
       
   254 				//iTest->Test(EFalse);
       
   255 				iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeySpace);
       
   256 				CActiveScheduler::Stop();
       
   257 			}
       
   258 		iPrevTime=aTime;
       
   259 		}
       
   260 	}
       
   261 
       
   262 void CRKWindow::SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
       
   263 	{
       
   264 	iInitialRepeatSet=aInitialTime;
       
   265 	iRepeatSet=aTime;
       
   266 	iMinGap=TTimeIntervalMicroSeconds32(100000000);	// Any very big number will do
       
   267 	iMaxGap=TTimeIntervalMicroSeconds32(0);
       
   268 	iTotalGap=TTimeIntervalMicroSeconds32(0);
       
   269 	SetState(EStateWaitingForKeyDown);
       
   270 	Client()->iWs.Flush();
       
   271 	}
       
   272 
       
   273 //
       
   274 
       
   275 CTKRepeat::CTKRepeat(CTestStep* aStep) : CTWsGraphicsBase(aStep)
       
   276 	{
       
   277 	}
       
   278 
       
   279 CTKRepeat::~CTKRepeat()
       
   280 	{
       
   281 	CTWin::Delete(iWin);
       
   282 	Client()->iWs.SetKeyboardRepeatRate(iOldInitialTime, iOldTime);
       
   283 	}
       
   284 
       
   285 void CTKRepeat::ConstructL()
       
   286 	{
       
   287 	TheClient->iWs.SetFocusScreen(iTest->iScreenNumber);
       
   288 	iWin=new(ELeave) CRKWindow(this);
       
   289 	TSize screenSize=Client()->iGroup->Size();
       
   290 	iWin->SetUpL(TPoint(5,5),TSize(Min(Max(screenSize.iWidth/2,250),screenSize.iWidth-10),screenSize.iHeight-10),Client()->iGroup,*Client()->iGc);
       
   291 	Client()->iGroup->WinTreeNode()->SetOrdinalPosition(0);
       
   292 	Client()->iGroup->SetCurrentWindow(iWin);
       
   293 	Client()->iWs.GetKeyboardRepeatRate(iOldInitialTime, iOldTime);
       
   294 	iTest->SimulateKeyDownUp(EStdKeyLeftCtrl);
       
   295 	iTest->SimulateKeyDownUp(EStdKeyRightCtrl);
       
   296 	TInt mods=Client()->iWs.GetModifierState();
       
   297 	TheClient->WaitForRedrawsToFinish();		//Let all pending events be processed before test begins
       
   298 	_LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
       
   299 	LOG_MESSAGE2(KLog,mods);
       
   300 	}
       
   301 
       
   302 TInt CTKRepeat::CheckReportL()
       
   303 	{
       
   304 	if (iWin->CheckResults())
       
   305 		{
       
   306 		/*CTDialog *dialog=new(ELeave) CTDialog();
       
   307 		dialog->SetTitle(_L("Keyboard repeat innacuracies"));
       
   308 		dialog->SetLine1(iWin->Report());
       
   309 		dialog->SetNumButtons(3);
       
   310 		dialog->SetButtonText(0,_L("Okay"));
       
   311 		dialog->SetButtonText(1,_L("Retest"));
       
   312 		dialog->SetButtonText(2,_L("Fail"));
       
   313 		dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
       
   314 		switch(dialog->Display())
       
   315 			{
       
   316 			case 0:
       
   317 				break;
       
   318 			case 1:
       
   319 				return(ETrue);	// Redo test
       
   320 			case 2:
       
   321 				Client()->iGroup->ClearCurrentWindow();
       
   322 				Test(EFalse);
       
   323 				break;
       
   324 			}
       
   325 		*/}
       
   326 	return(EFalse);
       
   327 	}
       
   328 
       
   329 void CTKRepeat::TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
       
   330 	{
       
   331 	do
       
   332 		{
       
   333 	#if defined(LOGGING)
       
   334 		const TInt KOneSec=1000000;
       
   335 		const TInt KOneHundrethSec=KOneSec/100;
       
   336 		TLogMessageText logMessageText;
       
   337 		_LIT(KRepeatRate,"Repeat Rate Initial=%d.%02dsecs, Subsequent=%d.%02dsecs");
       
   338 		logMessageText.Format(KRepeatRate,aInitialTime.Int()/KOneSec,(aInitialTime.Int()%KOneSec)/KOneHundrethSec
       
   339 																	,aTime.Int()/KOneSec,(aTime.Int()%KOneSec)/KOneHundrethSec);
       
   340 		LOG_MESSAGE(logMessageText);
       
   341 	#endif
       
   342 		TheClient->iWs.SetKeyboardRepeatRate(aInitialTime, aTime);
       
   343 		iWin->SetKeyboardRepeatRate(aInitialTime, aTime);
       
   344 		CActiveScheduler::Start();
       
   345 		if (iAbort)
       
   346 			{
       
   347 			iTest->AbortL();
       
   348 			}
       
   349 		} while(CheckReportL());
       
   350 	}
       
   351 	
       
   352 void CTKRepeat::RunTestCaseL(TInt /*aCurTestCase*/)
       
   353 	{
       
   354 	_LIT(KTestName1,"Keyboard Repeat 1");
       
   355 	_LIT(KTestName2,"Keyboard Repeat 2");
       
   356 	_LIT(KTestName3,"Keyboard Repeat 3");
       
   357 	_LIT(KTestName4,"Keyboard Repeat 4");
       
   358 	((CTKRepeatStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
   359 	switch(++iTest->iState)
       
   360 		{
       
   361 /**
       
   362 
       
   363   @SYMTestCaseID GRAPHICS-WSERV-0311
       
   364   
       
   365   @SYMDEF             DEF081259
       
   366  
       
   367   @SYMTestCaseDesc Test that a key can be repeatedly struck after a second, then every half second
       
   368     
       
   369   @SYMTestPriority High
       
   370  
       
   371   @SYMTestStatus Implemented
       
   372  
       
   373   @SYMTestActions Simulate a key being struck first after a second and then repeatedly every
       
   374   					half second and check the response time to the key strike is correct 
       
   375   
       
   376   @SYMTestExpectedResults Response time each time the key is struck is correct
       
   377  
       
   378 */
       
   379 		case 1:
       
   380 			((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0311"));
       
   381 			iTest->LogSubTest(KTestName1);
       
   382 			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(1000000), TTimeIntervalMicroSeconds32(500000));
       
   383 			break;
       
   384 /**
       
   385 
       
   386   @SYMTestCaseID GRAPHICS-WSERV-0312
       
   387   
       
   388   @SYMDEF             DEF081259
       
   389  
       
   390   @SYMTestCaseDesc Test that a key can be repeatedly struck after a 5th of a second, then every 10th of a second
       
   391     
       
   392   @SYMTestPriority High
       
   393  
       
   394   @SYMTestStatus Implemented
       
   395  
       
   396   @SYMTestActions Simulate a key being struck first after a 5th of a second and then repeatedly every
       
   397   					10th of a second and check the response time to the key strike is correct 
       
   398   
       
   399   @SYMTestExpectedResults Response time each time the key is struck is correct
       
   400  
       
   401 */
       
   402 		case 2:
       
   403 			((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0312"));
       
   404 			iTest->LogSubTest(KTestName2);
       
   405 			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(200000), TTimeIntervalMicroSeconds32(100000));
       
   406 			break;
       
   407 /**
       
   408 
       
   409   @SYMTestCaseID GRAPHICS-WSERV-0313
       
   410   
       
   411   @SYMDEF             DEF081259
       
   412  
       
   413   @SYMTestCaseDesc Test that a key can be repeatedly struck immediately, then every 10th of a second
       
   414     
       
   415   @SYMTestPriority High
       
   416  
       
   417   @SYMTestStatus Implemented
       
   418  
       
   419   @SYMTestActions Simulate a key being struck first immediately and then repeatedly every
       
   420   					10th of a second and check the response time to the key strike is correct 
       
   421   
       
   422   @SYMTestExpectedResults Response time each time the key is struck is correct
       
   423  
       
   424 */
       
   425 		case 3:
       
   426 			((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0313"));
       
   427 			iTest->LogSubTest(KTestName3);
       
   428 			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(0), TTimeIntervalMicroSeconds32(100000));
       
   429 			break;
       
   430 /**
       
   431 
       
   432   @SYMTestCaseID GRAPHICS-WSERV-0314
       
   433   
       
   434   @SYMDEF             DEF081259
       
   435  
       
   436   @SYMTestCaseDesc Test that a key can be repeatedly struck after a 10 of a second, then every 10th of a second
       
   437     
       
   438   @SYMTestPriority High
       
   439  
       
   440   @SYMTestStatus Implemented
       
   441  
       
   442   @SYMTestActions Simulate a key being struck first after a 10th of a second and then repeatedly every
       
   443   					10th of a second and check the response time to the key strike is correct 
       
   444   
       
   445   @SYMTestExpectedResults Response time each time the key is struck is correct
       
   446  
       
   447 */
       
   448 
       
   449 		case 4:
       
   450 			((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0314"));
       
   451 			iTest->LogSubTest(KTestName4);
       
   452 			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(100000), TTimeIntervalMicroSeconds32(100000));
       
   453 			break;
       
   454 		case 5:
       
   455 			((CTKRepeatStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
   456 			((CTKRepeatStep*)iStep)->CloseTMSGraphicsStep();
       
   457 			TestComplete();
       
   458 			break;
       
   459 		}
       
   460 	((CTKRepeatStep*)iStep)->RecordTestResultL();
       
   461 	}
       
   462 	
       
   463 __WS_CONSTRUCT_STEP__(KRepeat)
       
   464