1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TKRepeat.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,464 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Converted from TMan test code May 2001
1.18 +// Keyboard repeat test
1.19 +//
1.20 +//
1.21 +
1.22 +#include "TKRepeat.H"
1.23 +
1.24 +#define LOGGING 1
1.25 +
1.26 +//
1.27 +// CRKWindow, class //
1.28 +//
1.29 +
1.30 +CRKWindow::CRKWindow(CTKRepeat *aTest) : CTWin(), iTest(aTest)
1.31 + {
1.32 + }
1.33 +
1.34 +void CRKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
1.35 + {
1.36 + ConstructExtLD(*parent,pos,size);
1.37 + iWin.SetBackgroundColor(TRgb::Gray256(230));
1.38 + Activate();
1.39 + AssignGC(aGc);
1.40 + }
1.41 +
1.42 +void CRKWindow::Draw()
1.43 + {
1.44 + iGc->Clear();
1.45 + switch(iState)
1.46 + {
1.47 + case EStateWaitingForKeyDown:
1.48 + iGc->DrawText(_L("Press and hold the space bar"), TPoint(10,20));
1.49 + break;
1.50 + case EStateWaitingForFirstRepeat:
1.51 + case EStateWaitingForNthRepeat:
1.52 + {
1.53 + TBuf<0x40> buf;
1.54 + buf.Format(TRefByValue<const TDesC>(_L("Keep space bar down (%d repeats so far)")),iRepCount);
1.55 + iGc->DrawText(buf, TPoint(10,20));
1.56 + }
1.57 + break;
1.58 + case EStateWaitingForKeyUp:
1.59 + iGc->DrawText(_L("Release space bar"), TPoint(10,20));
1.60 + default:
1.61 + break;
1.62 + }
1.63 + }
1.64 +
1.65 +void CRKWindow::SetState(TRKStates aState)
1.66 + {
1.67 +#if defined(LOGGING)
1.68 + TLogMessageText logMessageText;
1.69 + _LIT(KStateChange,"State Change Old=%d New=%d");
1.70 + logMessageText.Format(KStateChange,iState,aState);
1.71 + iTest->LOG_MESSAGE(logMessageText);
1.72 +#endif
1.73 + iState=aState;
1.74 + DrawNow();
1.75 + TheClient->WaitForRedrawsToFinish();
1.76 + SendEvent();
1.77 + }
1.78 +
1.79 +void CRKWindow::SendEvent()
1.80 + {
1.81 + switch (iState)
1.82 + {
1.83 + case EStateWaitingForKeyDown:
1.84 + case EStateWaitingForKeyUp:
1.85 + #if defined(LOGGING)
1.86 + _LIT(KKeyUp,"Send key up event substate 0");
1.87 + _LIT(KKeyDown,"Send key down event substate 4");
1.88 + iTest->LOG_MESSAGE(iState==EStateWaitingForKeyDown ? KKeyDown() : KKeyUp());
1.89 + #endif
1.90 + iTest->TestBase()->SimulateKey((iState==EStateWaitingForKeyDown ? TRawEvent::EKeyDown : TRawEvent::EKeyUp),EStdKeySpace);
1.91 + break;
1.92 + case EStateWaitingForKeyCode:
1.93 + case EStateWaitingForFirstRepeat:
1.94 + case EStateWaitingForNthRepeat:
1.95 + case EStateInactive:
1.96 + case EStateError:
1.97 + #if defined(LOGGING)
1.98 + _LIT(KLog,"SendEvent: substate %d so no event to send");
1.99 + iTest->LOG_MESSAGE2(KLog,iState);
1.100 + #endif
1.101 + break;
1.102 + }
1.103 + }
1.104 +
1.105 +TBool CRKWindow::CheckResults()
1.106 + {
1.107 +//
1.108 +// Checks repeat results, first convert everything to 10th's as that what is actually used
1.109 +// for the timer in the window server.
1.110 +//
1.111 +// Return ETrue if the inacuracy in the average time is greater than 1/10th either way
1.112 +// Allow initial 2/10ths either
1.113 +// Allow min 2/10ths below
1.114 +// Allow max 2/10ths above
1.115 +//
1.116 + if (iState!=EStateInactive)
1.117 + return(ETrue);
1.118 + TInt initial=iInitialGap.Int()/100000;
1.119 + TInt initialX=iInitialRepeatSet.Int()/100000;
1.120 + if (initialX==0)
1.121 + initialX=1;
1.122 + TInt average=(iTotalGap.Int()/100000)/(iRepCount-1);
1.123 + TInt repeatX=iRepeatSet.Int()/100000;
1.124 + if (repeatX==0)
1.125 + repeatX=1;
1.126 + TInt min=iMinGap.Int()/100000;
1.127 + TInt max=iMaxGap.Int()/100000;
1.128 + if (average>(repeatX+1) || average<(repeatX-1))
1.129 + return(ETrue);
1.130 + if (initial>(initialX+2) || initial<(initialX-2))
1.131 + return(ETrue);
1.132 +#if defined(__MARM_ARM4__)
1.133 + if (min>(repeatX+1) || min<(repeatX-2) || max>(repeatX+3) || max<repeatX)
1.134 + {
1.135 + if (max<min || (max+min)<2*(repeatX-2) || (max+min)>2*(repeatX+2))
1.136 + return(ETrue);
1.137 + }
1.138 +#else
1.139 + if (min>(repeatX+1) || min<(repeatX-2))
1.140 + return(ETrue);
1.141 + if (max>(repeatX+3) || max<repeatX)
1.142 + return(ETrue);
1.143 +#endif
1.144 + return(EFalse);
1.145 + }
1.146 +
1.147 +TDesC& CRKWindow::Report()
1.148 + {
1.149 + if (iState!=EStateInactive)
1.150 + {
1.151 + iReport.Format(_L("Error, test not completed"));
1.152 + }
1.153 + else
1.154 + {
1.155 + TInt initial=iInitialGap.Int()/10000;
1.156 + TInt initialX=iInitialRepeatSet.Int()/10000;
1.157 + TInt average=(iTotalGap.Int()/10000/(iRepCount-1));
1.158 + TInt repeatX=iRepeatSet.Int()/10000;
1.159 + TInt min=iMinGap.Int()/10000;
1.160 + TInt max=iMaxGap.Int()/10000;
1.161 + iReport.Format(TRefByValue<const TDesC>(_L("Initial=%d [%d], Av=%d [%d], Min=%d, Max=%d")),initial,initialX,average,repeatX,min,max);
1.162 + }
1.163 + return(iReport);
1.164 + }
1.165 +
1.166 +void CRKWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
1.167 + {
1.168 +#if defined(LOGGING)
1.169 + TLogMessageText logMessageText;
1.170 + _LIT(KKeyDown,"CRKWindow::KeyDownL Code=%d '%c' State=%d (0)");
1.171 + logMessageText.Format(KKeyDown,aKey.iScanCode,aKey.iScanCode,iState);
1.172 + iTest->LOG_MESSAGE(logMessageText);
1.173 +#endif
1.174 + switch(iState)
1.175 + {
1.176 + case EStateWaitingForKeyDown:
1.177 + SetState(EStateWaitingForKeyCode);
1.178 + iDownCode=aKey.iScanCode;
1.179 + break;
1.180 + default:;
1.181 + }
1.182 + }
1.183 +
1.184 +void CRKWindow::KeyUpL(const TKeyEvent &aKey,const TTime &)
1.185 + {
1.186 +#if defined(LOGGING)
1.187 + TLogMessageText logMessageText;
1.188 + _LIT(KKeyUp,"CRKWindow::KeyUpL Code=%d (%c) State=%d Down=%d");
1.189 + logMessageText.Format(KKeyUp,aKey.iScanCode,aKey.iScanCode,iState,iDownCode);
1.190 + iTest->LOG_MESSAGE(logMessageText);
1.191 +#endif
1.192 + if (aKey.iScanCode==iDownCode)
1.193 + {
1.194 + switch(iState)
1.195 + {
1.196 + case EStateWaitingForKeyUp:
1.197 + SetState(EStateInactive);
1.198 + break;
1.199 + default:
1.200 + SetState(EStateError);
1.201 + break;
1.202 + }
1.203 + CActiveScheduler::Stop();
1.204 + }
1.205 + }
1.206 +
1.207 +void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime)
1.208 + {
1.209 + if (aKey.iCode==EKeyEscape)
1.210 + {
1.211 + CActiveScheduler::Stop();
1.212 + iTest->iAbort=ETrue;
1.213 + }
1.214 +#if defined(LOGGING)
1.215 + TLogMessageText logMessageText;
1.216 + _LIT(KKey,"CRKWindow::WinKeyL Code=%d (%c) State=%d RepeatCount=%d");
1.217 + logMessageText.Format(KKey,aKey.iScanCode,aKey.iScanCode,iState,iRepCount);
1.218 + iTest->LOG_MESSAGE(logMessageText);
1.219 +#endif
1.220 + if (aKey.iCode==32)
1.221 + {
1.222 + switch(iState)
1.223 + {
1.224 + case EStateWaitingForKeyCode:
1.225 + SetState(EStateWaitingForFirstRepeat);
1.226 + iPrevTime=aTime;
1.227 + break;
1.228 + case EStateWaitingForFirstRepeat:
1.229 + iRepCount=1;
1.230 + iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64());
1.231 + SetState(EStateWaitingForNthRepeat);
1.232 + break;
1.233 + case EStateWaitingForNthRepeat:
1.234 + if (iRepCount==5)
1.235 + SetState(EStateWaitingForKeyUp);
1.236 + else
1.237 + {
1.238 + TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()));
1.239 + #if defined(LOGGING)
1.240 + TLogMessageText logMessageText;
1.241 + _LIT(KRepeatGap,"Repeat after %d");
1.242 + logMessageText.AppendFormat(KRepeatGap,gap.Int());
1.243 + iTest->LOG_MESSAGE(logMessageText);
1.244 + TheClient->Flush();
1.245 + #endif
1.246 + if (gap<iMinGap)
1.247 + iMinGap=gap;
1.248 + if (gap>iMaxGap)
1.249 + iMaxGap=gap;
1.250 + iTotalGap=iTotalGap.Int()+gap.Int(); // Horrible way to do a +=
1.251 + iRepCount++;
1.252 + SetState(EStateWaitingForNthRepeat);
1.253 + }
1.254 + case EStateWaitingForKeyUp: // Do nothing here
1.255 + break;
1.256 + default:
1.257 + //iTest->Test(EFalse);
1.258 + iTest->TestBase()->SimulateKey(TRawEvent::EKeyUp,EStdKeySpace);
1.259 + CActiveScheduler::Stop();
1.260 + }
1.261 + iPrevTime=aTime;
1.262 + }
1.263 + }
1.264 +
1.265 +void CRKWindow::SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
1.266 + {
1.267 + iInitialRepeatSet=aInitialTime;
1.268 + iRepeatSet=aTime;
1.269 + iMinGap=TTimeIntervalMicroSeconds32(100000000); // Any very big number will do
1.270 + iMaxGap=TTimeIntervalMicroSeconds32(0);
1.271 + iTotalGap=TTimeIntervalMicroSeconds32(0);
1.272 + SetState(EStateWaitingForKeyDown);
1.273 + Client()->iWs.Flush();
1.274 + }
1.275 +
1.276 +//
1.277 +
1.278 +CTKRepeat::CTKRepeat(CTestStep* aStep) : CTWsGraphicsBase(aStep)
1.279 + {
1.280 + }
1.281 +
1.282 +CTKRepeat::~CTKRepeat()
1.283 + {
1.284 + CTWin::Delete(iWin);
1.285 + Client()->iWs.SetKeyboardRepeatRate(iOldInitialTime, iOldTime);
1.286 + }
1.287 +
1.288 +void CTKRepeat::ConstructL()
1.289 + {
1.290 + TheClient->iWs.SetFocusScreen(iTest->iScreenNumber);
1.291 + iWin=new(ELeave) CRKWindow(this);
1.292 + TSize screenSize=Client()->iGroup->Size();
1.293 + iWin->SetUpL(TPoint(5,5),TSize(Min(Max(screenSize.iWidth/2,250),screenSize.iWidth-10),screenSize.iHeight-10),Client()->iGroup,*Client()->iGc);
1.294 + Client()->iGroup->WinTreeNode()->SetOrdinalPosition(0);
1.295 + Client()->iGroup->SetCurrentWindow(iWin);
1.296 + Client()->iWs.GetKeyboardRepeatRate(iOldInitialTime, iOldTime);
1.297 + iTest->SimulateKeyDownUp(EStdKeyLeftCtrl);
1.298 + iTest->SimulateKeyDownUp(EStdKeyRightCtrl);
1.299 + TInt mods=Client()->iWs.GetModifierState();
1.300 + TheClient->WaitForRedrawsToFinish(); //Let all pending events be processed before test begins
1.301 + _LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
1.302 + LOG_MESSAGE2(KLog,mods);
1.303 + }
1.304 +
1.305 +TInt CTKRepeat::CheckReportL()
1.306 + {
1.307 + if (iWin->CheckResults())
1.308 + {
1.309 + /*CTDialog *dialog=new(ELeave) CTDialog();
1.310 + dialog->SetTitle(_L("Keyboard repeat innacuracies"));
1.311 + dialog->SetLine1(iWin->Report());
1.312 + dialog->SetNumButtons(3);
1.313 + dialog->SetButtonText(0,_L("Okay"));
1.314 + dialog->SetButtonText(1,_L("Retest"));
1.315 + dialog->SetButtonText(2,_L("Fail"));
1.316 + dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
1.317 + switch(dialog->Display())
1.318 + {
1.319 + case 0:
1.320 + break;
1.321 + case 1:
1.322 + return(ETrue); // Redo test
1.323 + case 2:
1.324 + Client()->iGroup->ClearCurrentWindow();
1.325 + Test(EFalse);
1.326 + break;
1.327 + }
1.328 + */}
1.329 + return(EFalse);
1.330 + }
1.331 +
1.332 +void CTKRepeat::TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
1.333 + {
1.334 + do
1.335 + {
1.336 + #if defined(LOGGING)
1.337 + const TInt KOneSec=1000000;
1.338 + const TInt KOneHundrethSec=KOneSec/100;
1.339 + TLogMessageText logMessageText;
1.340 + _LIT(KRepeatRate,"Repeat Rate Initial=%d.%02dsecs, Subsequent=%d.%02dsecs");
1.341 + logMessageText.Format(KRepeatRate,aInitialTime.Int()/KOneSec,(aInitialTime.Int()%KOneSec)/KOneHundrethSec
1.342 + ,aTime.Int()/KOneSec,(aTime.Int()%KOneSec)/KOneHundrethSec);
1.343 + LOG_MESSAGE(logMessageText);
1.344 + #endif
1.345 + TheClient->iWs.SetKeyboardRepeatRate(aInitialTime, aTime);
1.346 + iWin->SetKeyboardRepeatRate(aInitialTime, aTime);
1.347 + CActiveScheduler::Start();
1.348 + if (iAbort)
1.349 + {
1.350 + iTest->AbortL();
1.351 + }
1.352 + } while(CheckReportL());
1.353 + }
1.354 +
1.355 +void CTKRepeat::RunTestCaseL(TInt /*aCurTestCase*/)
1.356 + {
1.357 + _LIT(KTestName1,"Keyboard Repeat 1");
1.358 + _LIT(KTestName2,"Keyboard Repeat 2");
1.359 + _LIT(KTestName3,"Keyboard Repeat 3");
1.360 + _LIT(KTestName4,"Keyboard Repeat 4");
1.361 + ((CTKRepeatStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.362 + switch(++iTest->iState)
1.363 + {
1.364 +/**
1.365 +
1.366 + @SYMTestCaseID GRAPHICS-WSERV-0311
1.367 +
1.368 + @SYMDEF DEF081259
1.369 +
1.370 + @SYMTestCaseDesc Test that a key can be repeatedly struck after a second, then every half second
1.371 +
1.372 + @SYMTestPriority High
1.373 +
1.374 + @SYMTestStatus Implemented
1.375 +
1.376 + @SYMTestActions Simulate a key being struck first after a second and then repeatedly every
1.377 + half second and check the response time to the key strike is correct
1.378 +
1.379 + @SYMTestExpectedResults Response time each time the key is struck is correct
1.380 +
1.381 +*/
1.382 + case 1:
1.383 + ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0311"));
1.384 + iTest->LogSubTest(KTestName1);
1.385 + TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(1000000), TTimeIntervalMicroSeconds32(500000));
1.386 + break;
1.387 +/**
1.388 +
1.389 + @SYMTestCaseID GRAPHICS-WSERV-0312
1.390 +
1.391 + @SYMDEF DEF081259
1.392 +
1.393 + @SYMTestCaseDesc Test that a key can be repeatedly struck after a 5th of a second, then every 10th of a second
1.394 +
1.395 + @SYMTestPriority High
1.396 +
1.397 + @SYMTestStatus Implemented
1.398 +
1.399 + @SYMTestActions Simulate a key being struck first after a 5th of a second and then repeatedly every
1.400 + 10th of a second and check the response time to the key strike is correct
1.401 +
1.402 + @SYMTestExpectedResults Response time each time the key is struck is correct
1.403 +
1.404 +*/
1.405 + case 2:
1.406 + ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0312"));
1.407 + iTest->LogSubTest(KTestName2);
1.408 + TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(200000), TTimeIntervalMicroSeconds32(100000));
1.409 + break;
1.410 +/**
1.411 +
1.412 + @SYMTestCaseID GRAPHICS-WSERV-0313
1.413 +
1.414 + @SYMDEF DEF081259
1.415 +
1.416 + @SYMTestCaseDesc Test that a key can be repeatedly struck immediately, then every 10th of a second
1.417 +
1.418 + @SYMTestPriority High
1.419 +
1.420 + @SYMTestStatus Implemented
1.421 +
1.422 + @SYMTestActions Simulate a key being struck first immediately and then repeatedly every
1.423 + 10th of a second and check the response time to the key strike is correct
1.424 +
1.425 + @SYMTestExpectedResults Response time each time the key is struck is correct
1.426 +
1.427 +*/
1.428 + case 3:
1.429 + ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0313"));
1.430 + iTest->LogSubTest(KTestName3);
1.431 + TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(0), TTimeIntervalMicroSeconds32(100000));
1.432 + break;
1.433 +/**
1.434 +
1.435 + @SYMTestCaseID GRAPHICS-WSERV-0314
1.436 +
1.437 + @SYMDEF DEF081259
1.438 +
1.439 + @SYMTestCaseDesc Test that a key can be repeatedly struck after a 10 of a second, then every 10th of a second
1.440 +
1.441 + @SYMTestPriority High
1.442 +
1.443 + @SYMTestStatus Implemented
1.444 +
1.445 + @SYMTestActions Simulate a key being struck first after a 10th of a second and then repeatedly every
1.446 + 10th of a second and check the response time to the key strike is correct
1.447 +
1.448 + @SYMTestExpectedResults Response time each time the key is struck is correct
1.449 +
1.450 +*/
1.451 +
1.452 + case 4:
1.453 + ((CTKRepeatStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0314"));
1.454 + iTest->LogSubTest(KTestName4);
1.455 + TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(100000), TTimeIntervalMicroSeconds32(100000));
1.456 + break;
1.457 + case 5:
1.458 + ((CTKRepeatStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.459 + ((CTKRepeatStep*)iStep)->CloseTMSGraphicsStep();
1.460 + TestComplete();
1.461 + break;
1.462 + }
1.463 + ((CTKRepeatStep*)iStep)->RecordTestResultL();
1.464 + }
1.465 +
1.466 +__WS_CONSTRUCT_STEP__(KRepeat)
1.467 +