os/graphics/windowing/windowserver/test/tman/TKREPEAT.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tman/TKREPEAT.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,348 @@
     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 +// Keyboard repeat test
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32svr.h>
    1.23 +#include "W32STD.H"
    1.24 +#include "../tlib/testbase.h"
    1.25 +#include "TMAN.H"
    1.26 +
    1.27 +class CRKWindow;
    1.28 +
    1.29 +class TKRepeatTest : public CTestBase
    1.30 +	{
    1.31 +public:
    1.32 +	TKRepeatTest();
    1.33 +	~TKRepeatTest();
    1.34 +	TestState DoTestL();
    1.35 +	void ConstructL();
    1.36 +	void TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime);
    1.37 +	TBool CheckReportL();
    1.38 +public:
    1.39 +	TBool iAbort;
    1.40 +private:
    1.41 +	TTimeIntervalMicroSeconds32 iOldInitialTime;
    1.42 +	TTimeIntervalMicroSeconds32 iOldTime;
    1.43 +	CRKWindow *iWin;
    1.44 +	TSize iWinSize;
    1.45 +	TInt iState;
    1.46 +	};
    1.47 +
    1.48 +class CRKWindow : public CTWin
    1.49 +	{
    1.50 +	enum TRKStates {
    1.51 +		EStateWaitingForKeyDown,
    1.52 +		EStateWaitingForKeyCode,
    1.53 +		EStateWaitingForFirstRepeat,
    1.54 +		EStateWaitingForNthRepeat,
    1.55 +		EStateWaitingForKeyUp,
    1.56 +		EStateInactive,
    1.57 +		EStateError,
    1.58 +		};
    1.59 +public:
    1.60 +	CRKWindow(TKRepeatTest *aTest);
    1.61 +	void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
    1.62 +	void SetState(TRKStates aState);
    1.63 +	void SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime);
    1.64 +	void WinKeyL(const TKeyEvent &,const TTime &);
    1.65 +	void KeyUpL(const TKeyEvent &aKey,const TTime &aTime);
    1.66 +	void KeyDownL(const TKeyEvent &aKey,const TTime &aTime);
    1.67 +	void Draw();
    1.68 +	TDesC& Report();
    1.69 +	TBool CheckResults();
    1.70 +protected:
    1.71 +	TInt iConnIndex;
    1.72 +	TKRepeatTest *iTest;
    1.73 +	TRgb iBack;
    1.74 +	TRKStates iState;
    1.75 +	TInt iDownCode;
    1.76 +	TInt iRepCount;
    1.77 +	TTimeIntervalMicroSeconds32 iInitialRepeatSet;
    1.78 +	TTimeIntervalMicroSeconds32 iRepeatSet;
    1.79 +	TTime iPrevTime;
    1.80 +	TTimeIntervalMicroSeconds32 iInitialGap;
    1.81 +	TTimeIntervalMicroSeconds32 iTotalGap;
    1.82 +	TTimeIntervalMicroSeconds32 iMinGap;
    1.83 +	TTimeIntervalMicroSeconds32 iMaxGap;
    1.84 +	TBuf<0x40> iReport;
    1.85 +	};
    1.86 +
    1.87 +GLDEF_C CTestBase *CreateKRepeatTest()
    1.88 +	{
    1.89 +	return(new(ELeave) TKRepeatTest());
    1.90 +	}
    1.91 +
    1.92 +//
    1.93 +// CRKWindow, class //
    1.94 +//
    1.95 +
    1.96 +CRKWindow::CRKWindow(TKRepeatTest *aTest) : CTWin(), iTest(aTest)
    1.97 +	{
    1.98 +	}
    1.99 +
   1.100 +void CRKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   1.101 +	{
   1.102 +	ConstructExtLD(*parent,pos,size);
   1.103 +	iWin.SetBackgroundColor(TRgb::Gray256(230));
   1.104 +	Activate();
   1.105 +	AssignGC(aGc);
   1.106 +	}
   1.107 +
   1.108 +void CRKWindow::Draw()
   1.109 +	{
   1.110 +	iGc->Clear();
   1.111 +	switch(iState)
   1.112 +		{
   1.113 +		case EStateWaitingForKeyDown:
   1.114 +			iGc->DrawText(_L("Press and hold the space bar"), TPoint(10,20));
   1.115 +			break;
   1.116 +		case EStateWaitingForFirstRepeat:
   1.117 +		case EStateWaitingForNthRepeat:
   1.118 +			{
   1.119 +			TBuf<0x40> buf;
   1.120 +			buf.Format(TRefByValue<const TDesC>(_L("Keep space bar down (%d repeats so far)")),iRepCount);
   1.121 +			iGc->DrawText(buf, TPoint(10,20));
   1.122 +			}
   1.123 +			break;
   1.124 +		case EStateWaitingForKeyUp:
   1.125 +			iGc->DrawText(_L("Release space bar"), TPoint(10,20));
   1.126 +		default:
   1.127 +			break;
   1.128 +		}
   1.129 +	}
   1.130 +
   1.131 +void CRKWindow::SetState(TRKStates aState)
   1.132 +	{
   1.133 +	iState=aState;
   1.134 +	DrawNow();
   1.135 +	}
   1.136 +
   1.137 +TBool CRKWindow::CheckResults()
   1.138 +	{
   1.139 +//
   1.140 +// Checks repeat results, first convert everything to 10th's as that what is actually used 
   1.141 +// for the timer in the window server.
   1.142 +//
   1.143 +// Return ETrue if the inacuracy in the average time is greater than 1/10th either way
   1.144 +// Allow initial 2/10ths either
   1.145 +// Allow min 2/10ths below
   1.146 +// Allow max 2/10ths above
   1.147 +//
   1.148 +	if (iState!=EStateInactive)
   1.149 +		return(ETrue);
   1.150 +	TInt initial=iInitialGap.Int()/100000;
   1.151 +	TInt initialX=iInitialRepeatSet.Int()/100000;
   1.152 +	if (initialX==0)
   1.153 +		initialX=1;
   1.154 +	TInt average=(iTotalGap.Int()/100000)/(iRepCount-1);
   1.155 +	TInt repeatX=iRepeatSet.Int()/100000;
   1.156 +	if (repeatX==0)
   1.157 +		repeatX=1;
   1.158 +	TInt min=iMinGap.Int()/100000;
   1.159 +	TInt max=iMaxGap.Int()/100000;
   1.160 +	if (average>(repeatX+1) || average<(repeatX-1))
   1.161 +		return(ETrue);
   1.162 +	if (initial>(initialX+2) || initial<(initialX-2))
   1.163 +		return(ETrue);
   1.164 +	if (min>(repeatX+1) || min<(repeatX-2))
   1.165 +		return(ETrue);
   1.166 +	if (max>(repeatX+3) || max<repeatX)
   1.167 +		return(ETrue);
   1.168 +	return(EFalse);
   1.169 +	}
   1.170 +
   1.171 +TDesC& CRKWindow::Report()
   1.172 +	{
   1.173 +	if (iState!=EStateInactive)
   1.174 +		{
   1.175 +		iReport.Format(_L("Error, test not completed"));
   1.176 +		}
   1.177 +	else
   1.178 +		{
   1.179 +		TInt initial=iInitialGap.Int()/10000;
   1.180 +		TInt initialX=iInitialRepeatSet.Int()/10000;
   1.181 +		TInt average=(iTotalGap.Int()/10000/(iRepCount-1));
   1.182 +		TInt repeatX=iRepeatSet.Int()/10000;
   1.183 +		TInt min=iMinGap.Int()/10000;
   1.184 +		TInt max=iMaxGap.Int()/10000;
   1.185 +		iReport.Format(TRefByValue<const TDesC>(_L("Initial=%d [%d], Av=%d [%d], Min=%d, Max=%d")),initial,initialX,average,repeatX,min,max);
   1.186 +		}
   1.187 +	return(iReport);
   1.188 +	}
   1.189 +
   1.190 +void CRKWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
   1.191 +	{
   1.192 +	switch(iState)
   1.193 +		{
   1.194 +		case EStateWaitingForKeyDown:
   1.195 +			SetState(EStateWaitingForKeyCode);
   1.196 +			iDownCode=aKey.iScanCode;
   1.197 +			break;
   1.198 +		default:;
   1.199 +		}
   1.200 +	}
   1.201 +
   1.202 +void CRKWindow::KeyUpL(const TKeyEvent &aKey,const TTime &)
   1.203 +	{
   1.204 +	if (aKey.iScanCode==iDownCode)
   1.205 +		{
   1.206 +		switch(iState)
   1.207 +			{
   1.208 +			case EStateWaitingForKeyUp:
   1.209 +				SetState(EStateInactive);
   1.210 +				break;
   1.211 +			default:
   1.212 +				SetState(EStateError);
   1.213 +				break;
   1.214 +			}
   1.215 +		CActiveScheduler::Stop();
   1.216 +		}
   1.217 +	}
   1.218 +
   1.219 +void CRKWindow::WinKeyL(const TKeyEvent &aKey,const TTime &aTime)
   1.220 +	{
   1.221 +	if (aKey.iCode==EKeyEscape)
   1.222 +		{
   1.223 +		CActiveScheduler::Stop();
   1.224 +		iTest->iAbort=ETrue;
   1.225 +		}
   1.226 +	if (aKey.iCode==32)
   1.227 +		{
   1.228 +		switch(iState)
   1.229 +			{
   1.230 +			case EStateWaitingForKeyCode:
   1.231 +				SetState(EStateWaitingForFirstRepeat);
   1.232 +				iPrevTime=aTime;
   1.233 +				break;
   1.234 +			case EStateWaitingForFirstRepeat:
   1.235 +				iRepCount=1;
   1.236 +				iInitialGap = I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64());
   1.237 +				SetState(EStateWaitingForNthRepeat);
   1.238 +				break;
   1.239 +			case EStateWaitingForNthRepeat:
   1.240 +				if (iRepCount==5)
   1.241 +					SetState(EStateWaitingForKeyUp);
   1.242 +				else
   1.243 +					{
   1.244 +					TTimeIntervalMicroSeconds32 gap(I64LOW(aTime.MicroSecondsFrom(iPrevTime).Int64()));
   1.245 +					if (gap<iMinGap)
   1.246 +						iMinGap=gap;
   1.247 +					if (gap>iMaxGap)
   1.248 +						iMaxGap=gap;
   1.249 +					iTotalGap=iTotalGap.Int()+gap.Int();	// Horrible way to do a +=
   1.250 +					iRepCount++;
   1.251 +					SetState(EStateWaitingForNthRepeat);
   1.252 +					}
   1.253 +			case EStateWaitingForKeyUp: 	// Do nothing here
   1.254 +				break;
   1.255 +			default:
   1.256 +				iTest->TestL(EFalse);
   1.257 +			}
   1.258 +		iPrevTime=aTime;
   1.259 +		}
   1.260 +	}
   1.261 +
   1.262 +void CRKWindow::SetKeyboardRepeatRate(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
   1.263 +	{
   1.264 +	iInitialRepeatSet=aInitialTime;
   1.265 +	iRepeatSet=aTime;
   1.266 +	iMinGap=TTimeIntervalMicroSeconds32(100000000);	// Any very big number will do
   1.267 +	iMaxGap=TTimeIntervalMicroSeconds32(0);
   1.268 +	iTotalGap=TTimeIntervalMicroSeconds32(0);
   1.269 +	SetState(EStateWaitingForKeyDown);
   1.270 +	Client()->iWs.Flush();
   1.271 +	}
   1.272 +
   1.273 +//
   1.274 +
   1.275 +TKRepeatTest::TKRepeatTest() : CTestBase(_L("KRepeat"))
   1.276 +	{}
   1.277 +
   1.278 +TKRepeatTest::~TKRepeatTest()
   1.279 +	{
   1.280 +	CTWin::Delete(iWin);
   1.281 +	Client()->iWs.SetKeyboardRepeatRate(iOldInitialTime, iOldTime);
   1.282 +	}
   1.283 +
   1.284 +void TKRepeatTest::ConstructL()
   1.285 +	{
   1.286 +	iWin=new(ELeave) CRKWindow(this);
   1.287 +	TSize screenSize=Client()->iGroup->Size();
   1.288 +	iWin->SetUpL(TPoint(5,5),TSize(screenSize.iWidth/2,screenSize.iHeight-10),Client()->iGroup,*Client()->iGc);
   1.289 +	Client()->iGroup->SetCurrentWindow(iWin);
   1.290 +	Client()->iWs.GetKeyboardRepeatRate(iOldInitialTime, iOldTime);
   1.291 +	}
   1.292 +
   1.293 +TInt TKRepeatTest::CheckReportL()
   1.294 +	{
   1.295 +	if (iWin->CheckResults())
   1.296 +		{
   1.297 +		CTDialog *dialog=new(ELeave) CTDialog();
   1.298 +		dialog->SetTitle(_L("Keyboard repeat innacuracies"));
   1.299 +		dialog->SetLine1(iWin->Report());
   1.300 +		dialog->SetNumButtons(2);
   1.301 +		dialog->SetButtonText(0,_L("Okay"));
   1.302 +		dialog->SetButtonText(1,_L("Retest"));
   1.303 +		dialog->SetButtonText(2,_L("Fail"));
   1.304 +		dialog->ConstructLD(*Client()->iGroup,*Client()->iGc);
   1.305 +		switch(dialog->Display())
   1.306 +			{
   1.307 +			case 0:
   1.308 +				break;
   1.309 +			case 1:
   1.310 +				return(ETrue);	// Redo test
   1.311 +			case 2:
   1.312 +				TestL(EFalse);
   1.313 +				break;
   1.314 +			}
   1.315 +		}
   1.316 +	return(EFalse);
   1.317 +	}
   1.318 +
   1.319 +void TKRepeatTest::TestKeyboardRepeatRateL(const TTimeIntervalMicroSeconds32 &aInitialTime, const TTimeIntervalMicroSeconds32 &aTime)
   1.320 +	{
   1.321 +	do
   1.322 +		{
   1.323 +		Client()->iWs.SetKeyboardRepeatRate(aInitialTime, aTime);
   1.324 +		iWin->SetKeyboardRepeatRate(aInitialTime, aTime);
   1.325 +		CActiveScheduler::Start();
   1.326 +		if (iAbort)
   1.327 +			AbortL();
   1.328 +		} while(CheckReportL());
   1.329 +	}
   1.330 +
   1.331 +TestState TKRepeatTest::DoTestL()
   1.332 +	{
   1.333 +	switch(iState)
   1.334 +		{
   1.335 +		case 0:
   1.336 +			LogSubTest(_L("Keyboard Repeat"),1);
   1.337 +			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(1000000), TTimeIntervalMicroSeconds32(500000));
   1.338 +			LogSubTest(_L("Keyboard Repeat"),2);
   1.339 +			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(200000), TTimeIntervalMicroSeconds32(100000));
   1.340 +			LogSubTest(_L("Keyboard Repeat"),3);
   1.341 +			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(0), TTimeIntervalMicroSeconds32(100000));
   1.342 +			LogSubTest(_L("Keyboard Repeat"),4);
   1.343 +			TestKeyboardRepeatRateL(TTimeIntervalMicroSeconds32(100000), TTimeIntervalMicroSeconds32(100000));
   1.344 +			iState++;
   1.345 +			break;
   1.346 +		default:
   1.347 +			return(EFinished);
   1.348 +		}
   1.349 +	return(ENext);
   1.350 +	}
   1.351 +