os/graphics/windowing/windowserver/test/tman/TPASSWRD.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/TPASSWRD.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,429 @@
     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 +// Test Wserv password features
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32hal.h>
    1.23 +#include "W32STD.H"
    1.24 +#include "../tlib/testbase.h"
    1.25 +#include "TMAN.H"
    1.26 +
    1.27 +//#define LOG_TESTS
    1.28 +
    1.29 +#define THE_PASSWORD _L("pass")
    1.30 +
    1.31 +enum TPasswordState 
    1.32 +	{
    1.33 +	ENotStarted,
    1.34 +	EWaitForSwitchOff,
    1.35 +	EWaitForEnter,
    1.36 +	EWaitForA,
    1.37 +	EWaitForSwitchOff2,
    1.38 +	EWaitForSwitchOff3,
    1.39 +	EWaitForSwitchOff4,
    1.40 +	EWaitForSwitchOff5,
    1.41 +	EWaitForEnter2,
    1.42 +	EPasswordFinished,
    1.43 +	};
    1.44 +
    1.45 +class CPasswordTest;
    1.46 +
    1.47 +class CPasswordWindowGroup : public CTWindowGroup
    1.48 +	{
    1.49 +public:
    1.50 +	CPasswordWindowGroup(CTClient *aClient, CPasswordTest *aTest);
    1.51 +	void ConstructL();
    1.52 +	void PasswordL(const TTime &aTime);
    1.53 +	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
    1.54 +	void SwitchOn(const TTime &aTime);
    1.55 +private:
    1.56 +	CPasswordTest *iTest;
    1.57 +	};
    1.58 +
    1.59 +class CPasswordWindowGroup2 : public CTWindowGroup
    1.60 +	{
    1.61 +public:
    1.62 +	CPasswordWindowGroup2(CTClient *aClient, CPasswordTest *aTest);
    1.63 +	void ConstructL();
    1.64 +	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
    1.65 +private:
    1.66 +	CPasswordTest *iTest;
    1.67 +	};
    1.68 +
    1.69 +class CPasswordWindow : public CTWin
    1.70 +	{
    1.71 +public:
    1.72 +	CPasswordWindow(CPasswordTest *aTest);
    1.73 +	void Draw();
    1.74 +private:
    1.75 +	CPasswordTest *iTest;
    1.76 +	};
    1.77 +
    1.78 +class CPasswordTest : public CTestBase
    1.79 +	{
    1.80 +public:
    1.81 +	CPasswordTest();
    1.82 +	~CPasswordTest();
    1.83 +	TestState DoTestL();
    1.84 +	void ConstructL();
    1.85 +	void Fail(TInt aWhere);
    1.86 +	void EnterKeyPressed(TPasswordState aNewState);
    1.87 +	void SwitchOn();
    1.88 +	void TestComplete(TPasswordState aNewState);
    1.89 +	void PasswordMsgReceivedL();
    1.90 +	TPasswordState PasswordState() const;
    1.91 +	void SetPassState(TPasswordState aPassState);
    1.92 +	void StartMainPasswordTestL();
    1.93 +	void StartOnceADayPasswordTestL();
    1.94 +	void TurnOffAndOn();
    1.95 +private:
    1.96 +	CPasswordWindowGroup *iGroup;
    1.97 +	CPasswordWindowGroup2 *iGroup2;
    1.98 +	CPasswordWindow *iPassWin;
    1.99 +	CTBlankWindow *iBlankWin;
   1.100 +	TSize iWinSize;
   1.101 +	TInt iState;
   1.102 +	TPasswordState iPassState;
   1.103 +	TBool iPasswordTestFailed;
   1.104 +	};
   1.105 +
   1.106 +GLDEF_C CTestBase *CreatePasswordTest()
   1.107 +	{
   1.108 +	return(new(ELeave) CPasswordTest());
   1.109 +	}
   1.110 +
   1.111 +//
   1.112 +
   1.113 +CPasswordWindowGroup::CPasswordWindowGroup(CTClient *aClient, CPasswordTest *aTest) :
   1.114 +	CTWindowGroup(aClient),
   1.115 +	iTest(aTest)
   1.116 +	{
   1.117 +	__DECLARE_NAME(_S("CPasswordWindowGroup"));
   1.118 +	}
   1.119 +
   1.120 +void CPasswordWindowGroup::ConstructL()
   1.121 +	{
   1.122 +	CTWindowGroup::ConstructL();
   1.123 +	GroupWin()->EnableOnEvents();
   1.124 +	}
   1.125 +
   1.126 +void CPasswordWindowGroup::SwitchOn(const TTime &)
   1.127 +	{
   1.128 +	iTest->SwitchOn();
   1.129 +	}
   1.130 +
   1.131 +void CPasswordWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
   1.132 +	{
   1.133 +	if (aKey.iCode==EKeyEscape)
   1.134 +		iTest->TestComplete(EPasswordFinished);
   1.135 +	switch(iTest->PasswordState())
   1.136 +		{
   1.137 +		case EWaitForEnter:
   1.138 +			if (aKey.iCode==EKeyEnter)
   1.139 +				iTest->EnterKeyPressed(EWaitForA);
   1.140 +			break;
   1.141 +		case EWaitForEnter2:
   1.142 +			if (aKey.iCode==EKeyEnter)
   1.143 +				iTest->TestComplete(EPasswordFinished);
   1.144 +			break;
   1.145 +		default:;
   1.146 +		}
   1.147 +	}
   1.148 +
   1.149 +void CPasswordWindowGroup::PasswordL(const TTime &)
   1.150 +	{
   1.151 +	iTest->TestL(iGroupWin.OrdinalPosition()==0);
   1.152 +	iTest->PasswordMsgReceivedL();
   1.153 +	}
   1.154 +
   1.155 +//
   1.156 +
   1.157 +CPasswordWindowGroup2::CPasswordWindowGroup2(CTClient *aClient, CPasswordTest *aTest) :
   1.158 +	CTWindowGroup(aClient),
   1.159 +	iTest(aTest)
   1.160 +	{
   1.161 +	__DECLARE_NAME(_S("CPasswordWindowGroup"));
   1.162 +	}
   1.163 +
   1.164 +void CPasswordWindowGroup2::ConstructL()
   1.165 +	{
   1.166 +	CTWindowGroup::ConstructL();
   1.167 +	iGroupWin.CaptureKey('a',0,0);
   1.168 +	}
   1.169 +
   1.170 +void CPasswordWindowGroup2::KeyL(const TKeyEvent &aKey,const TTime &)
   1.171 +	{
   1.172 +	if (iTest->PasswordState()!=EPasswordFinished)
   1.173 +		{
   1.174 +		if (iTest->PasswordState()!=EWaitForA)
   1.175 +			{
   1.176 +		#if defined(LOG_TESTS)
   1.177 +			TLogMessageText buf;
   1.178 +			_LIT(KBadKey,"Bad Key  Code=%d(%c) Scan=%d(%c) Rep=%d");
   1.179 +			buf.AppendFormat(KBadKey,aKey.iCode,aKey.iCode,aKey.iScanCode,aKey.iScanCode,aKey.iRepeats);
   1.180 +			Client()->LogMessage(buf);
   1.181 +		#endif
   1.182 +			if (aKey.iRepeats==0)
   1.183 +				iTest->Fail(1);
   1.184 +			}
   1.185 +		else
   1.186 +			{
   1.187 +			if (aKey.iCode!='a')
   1.188 +				iTest->Fail(2);
   1.189 +			iTest->TestComplete(EWaitForSwitchOff2);
   1.190 +			}
   1.191 +		}
   1.192 +	}
   1.193 +
   1.194 +//
   1.195 +
   1.196 +CPasswordWindow::CPasswordWindow(CPasswordTest *aTest) :
   1.197 +	iTest(aTest)
   1.198 +	{
   1.199 +	}
   1.200 +
   1.201 +void CPasswordWindow::Draw()
   1.202 +	{
   1.203 +	iGc->Clear();
   1.204 +	switch(iTest->PasswordState())
   1.205 +		{
   1.206 +		case EWaitForSwitchOff:
   1.207 +			iGc->DrawText(_L("Please wait, turning off & on [1]"),TPoint(10,20));
   1.208 +			break;
   1.209 +		case EWaitForSwitchOff2:
   1.210 +			iGc->DrawText(_L("Please wait, turning off & on [2]"),TPoint(10,20));
   1.211 +			break;
   1.212 +		case EWaitForSwitchOff3:
   1.213 +			iGc->DrawText(_L("Please wait, turning off & on [3]"),TPoint(10,20));
   1.214 +			break;
   1.215 +		case EWaitForSwitchOff4:
   1.216 +			iGc->DrawText(_L("Please wait, turning off & on [4]"),TPoint(10,20));
   1.217 +			break;
   1.218 +		case EWaitForSwitchOff5:
   1.219 +			iGc->DrawText(_L("Please wait, turning off & on [5]"),TPoint(10,20));
   1.220 +			break;
   1.221 +		case EWaitForEnter:
   1.222 +			iGc->DrawText(_L("Try the key of death, then..."),TPoint(10,20));
   1.223 +			iGc->DrawText(_L("Press 'a', then..."),TPoint(10,40));
   1.224 +			iGc->DrawText(_L("Press Enter"),TPoint(10,60));
   1.225 +			break;
   1.226 +		case EWaitForEnter2:
   1.227 +			iGc->DrawText(_L("Press Enter"),TPoint(10,20));
   1.228 +			break;
   1.229 +		case EWaitForA:
   1.230 +			iGc->DrawText(_L("Press 'a'"),TPoint(10,20));
   1.231 +		case EPasswordFinished:
   1.232 +			break;
   1.233 +		default:;
   1.234 +		}
   1.235 +	}
   1.236 +
   1.237 +//
   1.238 +
   1.239 +CPasswordTest::CPasswordTest() : CTestBase(_L("Password"))
   1.240 +	{}
   1.241 +
   1.242 +CPasswordTest::~CPasswordTest()
   1.243 +	{
   1.244 +	delete iBlankWin;
   1.245 +	delete iPassWin;
   1.246 +	delete iGroup;
   1.247 +	delete iGroup2;
   1.248 +	}
   1.249 +
   1.250 +#if defined(LOG_TESTS)
   1.251 +void CPasswordTest::Fail(TInt aWhere)
   1.252 +#else
   1.253 +void CPasswordTest::Fail(TInt /*aWhere*/)
   1.254 +#endif
   1.255 +	{
   1.256 +#if defined(LOG_TESTS)
   1.257 +	TLogMessageText buf;
   1.258 +	_LIT(KFailed,"Password Failed at %d (%d,%d)");
   1.259 +	buf.AppendFormat(KFailed,aWhere,iState,iPassState);
   1.260 +	Client()->LogMessage(buf);
   1.261 +#endif
   1.262 +	iPasswordTestFailed=ETrue;
   1.263 +	Request();
   1.264 +	}
   1.265 +
   1.266 +void CPasswordTest::TurnOffAndOn()
   1.267 +	{
   1.268 +/*#if defined(LOG_TESTS)
   1.269 +	TLogMessageText buf;
   1.270 +	_LIT(KSettingTime,"Setting Off Timer");
   1.271 +	buf.Append(KSettingTime);
   1.272 +	Client()->LogMessage(buf);
   1.273 +#endif*/
   1.274 +	RTimer timer;
   1.275 +	timer.CreateLocal();
   1.276 +	TTime time;
   1.277 +	time.HomeTime();
   1.278 +	time+=TTimeIntervalSeconds(7);	// For some reason the O/S won't switch off for less than 6 seconds
   1.279 +	TRequestStatus status;
   1.280 +	timer.At(status,time);
   1.281 +	UserHal::SwitchOff();
   1.282 +	User::WaitForRequest(status);
   1.283 +#if !defined(__WINS__)
   1.284 +	TRawEvent event;
   1.285 +	event.Set(TRawEvent::ESwitchOn);
   1.286 +	UserSvr::AddEvent(event);
   1.287 +#endif
   1.288 +/*#if defined(LOG_TESTS)
   1.289 +	TLogMessageText buf;
   1.290 +	_LIT(KTimerOff,"Timer Gone Off (P=%d,S=%d)");
   1.291 +	buf.AppendFormat(KTimerOff,iState,iPassState);
   1.292 +	Client()->LogMessage(buf);
   1.293 +#endif*/
   1.294 +	}
   1.295 +
   1.296 +TPasswordState CPasswordTest::PasswordState() const
   1.297 +	{
   1.298 +	return(iPassState);
   1.299 +	}
   1.300 +
   1.301 +void CPasswordTest::SetPassState(TPasswordState aPassState)
   1.302 +	{
   1.303 +	iPassState=aPassState;
   1.304 +	iPassWin->DrawNow();
   1.305 +	Client()->iWs.Flush();
   1.306 +/*#if defined(LOG_TESTS)
   1.307 +	TLogMessageText buf;
   1.308 +	_LIT(PassTestState,"Password Test(%d), State=%d");
   1.309 +	buf.AppendFormat(PassTestState,iState,aPassState);
   1.310 +	Client()->LogMessage(buf);
   1.311 +#endif*/
   1.312 +	switch(aPassState)
   1.313 +		{
   1.314 +		case EWaitForSwitchOff:
   1.315 +		case EWaitForSwitchOff2:
   1.316 +		case EWaitForSwitchOff3:
   1.317 +		case EWaitForSwitchOff4:
   1.318 +		case EWaitForSwitchOff5:
   1.319 +			TurnOffAndOn();
   1.320 +			break;
   1.321 +		default:;
   1.322 +		}
   1.323 +	}
   1.324 +
   1.325 +void CPasswordTest::SwitchOn()
   1.326 +	{
   1.327 +/*#if defined(LOG_TESTS)
   1.328 +	TLogMessageText buf;
   1.329 +	_LIT(KTimerOff,"Switch On (P=%d,S=%d)");
   1.330 +	buf.AppendFormat(KTimerOff,iState,iPassState);
   1.331 +	Client()->LogMessage(buf);
   1.332 +#endif*/
   1.333 +	switch (iPassState)
   1.334 +		{
   1.335 +		case EWaitForSwitchOff:
   1.336 +			SetPassState(EWaitForEnter);
   1.337 +			break;
   1.338 +		case EWaitForSwitchOff2:
   1.339 +			SetPassState(EWaitForSwitchOff3);
   1.340 +			break;
   1.341 +		case EWaitForSwitchOff3:
   1.342 +			SetPassState(EWaitForSwitchOff4);
   1.343 +			break;
   1.344 +		case EWaitForSwitchOff4:
   1.345 +			{
   1.346 +			SetPassState(EWaitForSwitchOff5);
   1.347 +			TTime time;
   1.348 +			time.HomeTime();
   1.349 +			time+=TTimeIntervalHours(24);
   1.350 +			User::SetHomeTime(time);
   1.351 +			}
   1.352 +			break;
   1.353 +		case EWaitForSwitchOff5:
   1.354 +			SetPassState(EWaitForEnter2);
   1.355 +			break;
   1.356 +		default:;
   1.357 +		}
   1.358 +	}
   1.359 +
   1.360 +void CPasswordTest::PasswordMsgReceivedL()
   1.361 +	{
   1.362 +	TestL(iPassWin->BaseWin()->OrdinalPosition()==0);
   1.363 +	if (iPassState==EWaitForSwitchOff3 || iPassState==EWaitForSwitchOff4)
   1.364 +		Fail(3);
   1.365 +	}
   1.366 +
   1.367 +void CPasswordTest::EnterKeyPressed(TPasswordState aNewState)
   1.368 +	{
   1.369 +	iPassWin->BaseWin()->SetOrdinalPosition(-1);
   1.370 +	SetPassState(aNewState);
   1.371 +	Client()->iWs.PasswordEntered();
   1.372 +	}
   1.373 +
   1.374 +void CPasswordTest::TestComplete(TPasswordState aNewState)
   1.375 +	{
   1.376 +	Request();
   1.377 +	SetPassState(aNewState);
   1.378 +	iPassState=aNewState;
   1.379 +	}
   1.380 +
   1.381 +void CPasswordTest::ConstructL()
   1.382 +	{
   1.383 +	iGroup2=new(ELeave) CPasswordWindowGroup2(Client(),this);
   1.384 +	iGroup2->ConstructL();
   1.385 +	iGroup=new(ELeave) CPasswordWindowGroup(Client(),this);
   1.386 +	iGroup->ConstructL();
   1.387 +	iPassWin=new(ELeave) CPasswordWindow(this);
   1.388 +	iPassWin->ConstructL(*iGroup);
   1.389 +	iPassWin->AssignGC(*Client()->iGc);
   1.390 +	iPassWin->Activate();
   1.391 +	iBlankWin=new(ELeave) CTBlankWindow();
   1.392 +	iBlankWin->ConstructL(*iGroup);
   1.393 +	iBlankWin->SetVisible(EFalse);
   1.394 +	iBlankWin->Activate();
   1.395 +	iState=ENotStarted;
   1.396 +	}
   1.397 +
   1.398 +void CPasswordTest::StartMainPasswordTestL()
   1.399 +	{
   1.400 +	if (iPassWin->BaseWin()->PasswordWindow(EPasswordAlways)!=KErrNone)
   1.401 +		{
   1.402 +		DisplayDialog(_L("Can't do password tests"),_L("Password window"),_L("already exists"), Client()->iGroup->GroupWin());
   1.403 +		AbortL();
   1.404 +		}
   1.405 +	SetPassState(EWaitForSwitchOff);
   1.406 +	}
   1.407 +
   1.408 +void CPasswordTest::StartOnceADayPasswordTestL()
   1.409 +	{
   1.410 +	TestL(iPassWin->BaseWin()->PasswordWindow(EPasswordOnceADay)==KErrNone);
   1.411 +	}
   1.412 +
   1.413 +TestState CPasswordTest::DoTestL()
   1.414 +	{
   1.415 +	if (iPasswordTestFailed)
   1.416 +		TestL(ETrue);
   1.417 +	switch(iState)
   1.418 +		{
   1.419 +		case 0:
   1.420 +			LogSubTest(_L("Password 1"),1);
   1.421 +			StartMainPasswordTestL();
   1.422 +			iState++;
   1.423 +			return(EContinue);
   1.424 +		case 1:
   1.425 +			LogSubTest(_L("Password 2"),2);
   1.426 +			StartOnceADayPasswordTestL();
   1.427 +			iState++;
   1.428 +			return(EContinue);
   1.429 +		default:
   1.430 +			return(EFinished);
   1.431 +		}
   1.432 +	}