os/graphics/windowing/windowserver/test/tman/TPASSWRD.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
// Test Wserv password features
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32hal.h>
sl@0
    20
#include "W32STD.H"
sl@0
    21
#include "../tlib/testbase.h"
sl@0
    22
#include "TMAN.H"
sl@0
    23
sl@0
    24
//#define LOG_TESTS
sl@0
    25
sl@0
    26
#define THE_PASSWORD _L("pass")
sl@0
    27
sl@0
    28
enum TPasswordState 
sl@0
    29
	{
sl@0
    30
	ENotStarted,
sl@0
    31
	EWaitForSwitchOff,
sl@0
    32
	EWaitForEnter,
sl@0
    33
	EWaitForA,
sl@0
    34
	EWaitForSwitchOff2,
sl@0
    35
	EWaitForSwitchOff3,
sl@0
    36
	EWaitForSwitchOff4,
sl@0
    37
	EWaitForSwitchOff5,
sl@0
    38
	EWaitForEnter2,
sl@0
    39
	EPasswordFinished,
sl@0
    40
	};
sl@0
    41
sl@0
    42
class CPasswordTest;
sl@0
    43
sl@0
    44
class CPasswordWindowGroup : public CTWindowGroup
sl@0
    45
	{
sl@0
    46
public:
sl@0
    47
	CPasswordWindowGroup(CTClient *aClient, CPasswordTest *aTest);
sl@0
    48
	void ConstructL();
sl@0
    49
	void PasswordL(const TTime &aTime);
sl@0
    50
	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
sl@0
    51
	void SwitchOn(const TTime &aTime);
sl@0
    52
private:
sl@0
    53
	CPasswordTest *iTest;
sl@0
    54
	};
sl@0
    55
sl@0
    56
class CPasswordWindowGroup2 : public CTWindowGroup
sl@0
    57
	{
sl@0
    58
public:
sl@0
    59
	CPasswordWindowGroup2(CTClient *aClient, CPasswordTest *aTest);
sl@0
    60
	void ConstructL();
sl@0
    61
	void KeyL(const TKeyEvent &aKey,const TTime &aTime);
sl@0
    62
private:
sl@0
    63
	CPasswordTest *iTest;
sl@0
    64
	};
sl@0
    65
sl@0
    66
class CPasswordWindow : public CTWin
sl@0
    67
	{
sl@0
    68
public:
sl@0
    69
	CPasswordWindow(CPasswordTest *aTest);
sl@0
    70
	void Draw();
sl@0
    71
private:
sl@0
    72
	CPasswordTest *iTest;
sl@0
    73
	};
sl@0
    74
sl@0
    75
class CPasswordTest : public CTestBase
sl@0
    76
	{
sl@0
    77
public:
sl@0
    78
	CPasswordTest();
sl@0
    79
	~CPasswordTest();
sl@0
    80
	TestState DoTestL();
sl@0
    81
	void ConstructL();
sl@0
    82
	void Fail(TInt aWhere);
sl@0
    83
	void EnterKeyPressed(TPasswordState aNewState);
sl@0
    84
	void SwitchOn();
sl@0
    85
	void TestComplete(TPasswordState aNewState);
sl@0
    86
	void PasswordMsgReceivedL();
sl@0
    87
	TPasswordState PasswordState() const;
sl@0
    88
	void SetPassState(TPasswordState aPassState);
sl@0
    89
	void StartMainPasswordTestL();
sl@0
    90
	void StartOnceADayPasswordTestL();
sl@0
    91
	void TurnOffAndOn();
sl@0
    92
private:
sl@0
    93
	CPasswordWindowGroup *iGroup;
sl@0
    94
	CPasswordWindowGroup2 *iGroup2;
sl@0
    95
	CPasswordWindow *iPassWin;
sl@0
    96
	CTBlankWindow *iBlankWin;
sl@0
    97
	TSize iWinSize;
sl@0
    98
	TInt iState;
sl@0
    99
	TPasswordState iPassState;
sl@0
   100
	TBool iPasswordTestFailed;
sl@0
   101
	};
sl@0
   102
sl@0
   103
GLDEF_C CTestBase *CreatePasswordTest()
sl@0
   104
	{
sl@0
   105
	return(new(ELeave) CPasswordTest());
sl@0
   106
	}
sl@0
   107
sl@0
   108
//
sl@0
   109
sl@0
   110
CPasswordWindowGroup::CPasswordWindowGroup(CTClient *aClient, CPasswordTest *aTest) :
sl@0
   111
	CTWindowGroup(aClient),
sl@0
   112
	iTest(aTest)
sl@0
   113
	{
sl@0
   114
	__DECLARE_NAME(_S("CPasswordWindowGroup"));
sl@0
   115
	}
sl@0
   116
sl@0
   117
void CPasswordWindowGroup::ConstructL()
sl@0
   118
	{
sl@0
   119
	CTWindowGroup::ConstructL();
sl@0
   120
	GroupWin()->EnableOnEvents();
sl@0
   121
	}
sl@0
   122
sl@0
   123
void CPasswordWindowGroup::SwitchOn(const TTime &)
sl@0
   124
	{
sl@0
   125
	iTest->SwitchOn();
sl@0
   126
	}
sl@0
   127
sl@0
   128
void CPasswordWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
sl@0
   129
	{
sl@0
   130
	if (aKey.iCode==EKeyEscape)
sl@0
   131
		iTest->TestComplete(EPasswordFinished);
sl@0
   132
	switch(iTest->PasswordState())
sl@0
   133
		{
sl@0
   134
		case EWaitForEnter:
sl@0
   135
			if (aKey.iCode==EKeyEnter)
sl@0
   136
				iTest->EnterKeyPressed(EWaitForA);
sl@0
   137
			break;
sl@0
   138
		case EWaitForEnter2:
sl@0
   139
			if (aKey.iCode==EKeyEnter)
sl@0
   140
				iTest->TestComplete(EPasswordFinished);
sl@0
   141
			break;
sl@0
   142
		default:;
sl@0
   143
		}
sl@0
   144
	}
sl@0
   145
sl@0
   146
void CPasswordWindowGroup::PasswordL(const TTime &)
sl@0
   147
	{
sl@0
   148
	iTest->TestL(iGroupWin.OrdinalPosition()==0);
sl@0
   149
	iTest->PasswordMsgReceivedL();
sl@0
   150
	}
sl@0
   151
sl@0
   152
//
sl@0
   153
sl@0
   154
CPasswordWindowGroup2::CPasswordWindowGroup2(CTClient *aClient, CPasswordTest *aTest) :
sl@0
   155
	CTWindowGroup(aClient),
sl@0
   156
	iTest(aTest)
sl@0
   157
	{
sl@0
   158
	__DECLARE_NAME(_S("CPasswordWindowGroup"));
sl@0
   159
	}
sl@0
   160
sl@0
   161
void CPasswordWindowGroup2::ConstructL()
sl@0
   162
	{
sl@0
   163
	CTWindowGroup::ConstructL();
sl@0
   164
	iGroupWin.CaptureKey('a',0,0);
sl@0
   165
	}
sl@0
   166
sl@0
   167
void CPasswordWindowGroup2::KeyL(const TKeyEvent &aKey,const TTime &)
sl@0
   168
	{
sl@0
   169
	if (iTest->PasswordState()!=EPasswordFinished)
sl@0
   170
		{
sl@0
   171
		if (iTest->PasswordState()!=EWaitForA)
sl@0
   172
			{
sl@0
   173
		#if defined(LOG_TESTS)
sl@0
   174
			TLogMessageText buf;
sl@0
   175
			_LIT(KBadKey,"Bad Key  Code=%d(%c) Scan=%d(%c) Rep=%d");
sl@0
   176
			buf.AppendFormat(KBadKey,aKey.iCode,aKey.iCode,aKey.iScanCode,aKey.iScanCode,aKey.iRepeats);
sl@0
   177
			Client()->LogMessage(buf);
sl@0
   178
		#endif
sl@0
   179
			if (aKey.iRepeats==0)
sl@0
   180
				iTest->Fail(1);
sl@0
   181
			}
sl@0
   182
		else
sl@0
   183
			{
sl@0
   184
			if (aKey.iCode!='a')
sl@0
   185
				iTest->Fail(2);
sl@0
   186
			iTest->TestComplete(EWaitForSwitchOff2);
sl@0
   187
			}
sl@0
   188
		}
sl@0
   189
	}
sl@0
   190
sl@0
   191
//
sl@0
   192
sl@0
   193
CPasswordWindow::CPasswordWindow(CPasswordTest *aTest) :
sl@0
   194
	iTest(aTest)
sl@0
   195
	{
sl@0
   196
	}
sl@0
   197
sl@0
   198
void CPasswordWindow::Draw()
sl@0
   199
	{
sl@0
   200
	iGc->Clear();
sl@0
   201
	switch(iTest->PasswordState())
sl@0
   202
		{
sl@0
   203
		case EWaitForSwitchOff:
sl@0
   204
			iGc->DrawText(_L("Please wait, turning off & on [1]"),TPoint(10,20));
sl@0
   205
			break;
sl@0
   206
		case EWaitForSwitchOff2:
sl@0
   207
			iGc->DrawText(_L("Please wait, turning off & on [2]"),TPoint(10,20));
sl@0
   208
			break;
sl@0
   209
		case EWaitForSwitchOff3:
sl@0
   210
			iGc->DrawText(_L("Please wait, turning off & on [3]"),TPoint(10,20));
sl@0
   211
			break;
sl@0
   212
		case EWaitForSwitchOff4:
sl@0
   213
			iGc->DrawText(_L("Please wait, turning off & on [4]"),TPoint(10,20));
sl@0
   214
			break;
sl@0
   215
		case EWaitForSwitchOff5:
sl@0
   216
			iGc->DrawText(_L("Please wait, turning off & on [5]"),TPoint(10,20));
sl@0
   217
			break;
sl@0
   218
		case EWaitForEnter:
sl@0
   219
			iGc->DrawText(_L("Try the key of death, then..."),TPoint(10,20));
sl@0
   220
			iGc->DrawText(_L("Press 'a', then..."),TPoint(10,40));
sl@0
   221
			iGc->DrawText(_L("Press Enter"),TPoint(10,60));
sl@0
   222
			break;
sl@0
   223
		case EWaitForEnter2:
sl@0
   224
			iGc->DrawText(_L("Press Enter"),TPoint(10,20));
sl@0
   225
			break;
sl@0
   226
		case EWaitForA:
sl@0
   227
			iGc->DrawText(_L("Press 'a'"),TPoint(10,20));
sl@0
   228
		case EPasswordFinished:
sl@0
   229
			break;
sl@0
   230
		default:;
sl@0
   231
		}
sl@0
   232
	}
sl@0
   233
sl@0
   234
//
sl@0
   235
sl@0
   236
CPasswordTest::CPasswordTest() : CTestBase(_L("Password"))
sl@0
   237
	{}
sl@0
   238
sl@0
   239
CPasswordTest::~CPasswordTest()
sl@0
   240
	{
sl@0
   241
	delete iBlankWin;
sl@0
   242
	delete iPassWin;
sl@0
   243
	delete iGroup;
sl@0
   244
	delete iGroup2;
sl@0
   245
	}
sl@0
   246
sl@0
   247
#if defined(LOG_TESTS)
sl@0
   248
void CPasswordTest::Fail(TInt aWhere)
sl@0
   249
#else
sl@0
   250
void CPasswordTest::Fail(TInt /*aWhere*/)
sl@0
   251
#endif
sl@0
   252
	{
sl@0
   253
#if defined(LOG_TESTS)
sl@0
   254
	TLogMessageText buf;
sl@0
   255
	_LIT(KFailed,"Password Failed at %d (%d,%d)");
sl@0
   256
	buf.AppendFormat(KFailed,aWhere,iState,iPassState);
sl@0
   257
	Client()->LogMessage(buf);
sl@0
   258
#endif
sl@0
   259
	iPasswordTestFailed=ETrue;
sl@0
   260
	Request();
sl@0
   261
	}
sl@0
   262
sl@0
   263
void CPasswordTest::TurnOffAndOn()
sl@0
   264
	{
sl@0
   265
/*#if defined(LOG_TESTS)
sl@0
   266
	TLogMessageText buf;
sl@0
   267
	_LIT(KSettingTime,"Setting Off Timer");
sl@0
   268
	buf.Append(KSettingTime);
sl@0
   269
	Client()->LogMessage(buf);
sl@0
   270
#endif*/
sl@0
   271
	RTimer timer;
sl@0
   272
	timer.CreateLocal();
sl@0
   273
	TTime time;
sl@0
   274
	time.HomeTime();
sl@0
   275
	time+=TTimeIntervalSeconds(7);	// For some reason the O/S won't switch off for less than 6 seconds
sl@0
   276
	TRequestStatus status;
sl@0
   277
	timer.At(status,time);
sl@0
   278
	UserHal::SwitchOff();
sl@0
   279
	User::WaitForRequest(status);
sl@0
   280
#if !defined(__WINS__)
sl@0
   281
	TRawEvent event;
sl@0
   282
	event.Set(TRawEvent::ESwitchOn);
sl@0
   283
	UserSvr::AddEvent(event);
sl@0
   284
#endif
sl@0
   285
/*#if defined(LOG_TESTS)
sl@0
   286
	TLogMessageText buf;
sl@0
   287
	_LIT(KTimerOff,"Timer Gone Off (P=%d,S=%d)");
sl@0
   288
	buf.AppendFormat(KTimerOff,iState,iPassState);
sl@0
   289
	Client()->LogMessage(buf);
sl@0
   290
#endif*/
sl@0
   291
	}
sl@0
   292
sl@0
   293
TPasswordState CPasswordTest::PasswordState() const
sl@0
   294
	{
sl@0
   295
	return(iPassState);
sl@0
   296
	}
sl@0
   297
sl@0
   298
void CPasswordTest::SetPassState(TPasswordState aPassState)
sl@0
   299
	{
sl@0
   300
	iPassState=aPassState;
sl@0
   301
	iPassWin->DrawNow();
sl@0
   302
	Client()->iWs.Flush();
sl@0
   303
/*#if defined(LOG_TESTS)
sl@0
   304
	TLogMessageText buf;
sl@0
   305
	_LIT(PassTestState,"Password Test(%d), State=%d");
sl@0
   306
	buf.AppendFormat(PassTestState,iState,aPassState);
sl@0
   307
	Client()->LogMessage(buf);
sl@0
   308
#endif*/
sl@0
   309
	switch(aPassState)
sl@0
   310
		{
sl@0
   311
		case EWaitForSwitchOff:
sl@0
   312
		case EWaitForSwitchOff2:
sl@0
   313
		case EWaitForSwitchOff3:
sl@0
   314
		case EWaitForSwitchOff4:
sl@0
   315
		case EWaitForSwitchOff5:
sl@0
   316
			TurnOffAndOn();
sl@0
   317
			break;
sl@0
   318
		default:;
sl@0
   319
		}
sl@0
   320
	}
sl@0
   321
sl@0
   322
void CPasswordTest::SwitchOn()
sl@0
   323
	{
sl@0
   324
/*#if defined(LOG_TESTS)
sl@0
   325
	TLogMessageText buf;
sl@0
   326
	_LIT(KTimerOff,"Switch On (P=%d,S=%d)");
sl@0
   327
	buf.AppendFormat(KTimerOff,iState,iPassState);
sl@0
   328
	Client()->LogMessage(buf);
sl@0
   329
#endif*/
sl@0
   330
	switch (iPassState)
sl@0
   331
		{
sl@0
   332
		case EWaitForSwitchOff:
sl@0
   333
			SetPassState(EWaitForEnter);
sl@0
   334
			break;
sl@0
   335
		case EWaitForSwitchOff2:
sl@0
   336
			SetPassState(EWaitForSwitchOff3);
sl@0
   337
			break;
sl@0
   338
		case EWaitForSwitchOff3:
sl@0
   339
			SetPassState(EWaitForSwitchOff4);
sl@0
   340
			break;
sl@0
   341
		case EWaitForSwitchOff4:
sl@0
   342
			{
sl@0
   343
			SetPassState(EWaitForSwitchOff5);
sl@0
   344
			TTime time;
sl@0
   345
			time.HomeTime();
sl@0
   346
			time+=TTimeIntervalHours(24);
sl@0
   347
			User::SetHomeTime(time);
sl@0
   348
			}
sl@0
   349
			break;
sl@0
   350
		case EWaitForSwitchOff5:
sl@0
   351
			SetPassState(EWaitForEnter2);
sl@0
   352
			break;
sl@0
   353
		default:;
sl@0
   354
		}
sl@0
   355
	}
sl@0
   356
sl@0
   357
void CPasswordTest::PasswordMsgReceivedL()
sl@0
   358
	{
sl@0
   359
	TestL(iPassWin->BaseWin()->OrdinalPosition()==0);
sl@0
   360
	if (iPassState==EWaitForSwitchOff3 || iPassState==EWaitForSwitchOff4)
sl@0
   361
		Fail(3);
sl@0
   362
	}
sl@0
   363
sl@0
   364
void CPasswordTest::EnterKeyPressed(TPasswordState aNewState)
sl@0
   365
	{
sl@0
   366
	iPassWin->BaseWin()->SetOrdinalPosition(-1);
sl@0
   367
	SetPassState(aNewState);
sl@0
   368
	Client()->iWs.PasswordEntered();
sl@0
   369
	}
sl@0
   370
sl@0
   371
void CPasswordTest::TestComplete(TPasswordState aNewState)
sl@0
   372
	{
sl@0
   373
	Request();
sl@0
   374
	SetPassState(aNewState);
sl@0
   375
	iPassState=aNewState;
sl@0
   376
	}
sl@0
   377
sl@0
   378
void CPasswordTest::ConstructL()
sl@0
   379
	{
sl@0
   380
	iGroup2=new(ELeave) CPasswordWindowGroup2(Client(),this);
sl@0
   381
	iGroup2->ConstructL();
sl@0
   382
	iGroup=new(ELeave) CPasswordWindowGroup(Client(),this);
sl@0
   383
	iGroup->ConstructL();
sl@0
   384
	iPassWin=new(ELeave) CPasswordWindow(this);
sl@0
   385
	iPassWin->ConstructL(*iGroup);
sl@0
   386
	iPassWin->AssignGC(*Client()->iGc);
sl@0
   387
	iPassWin->Activate();
sl@0
   388
	iBlankWin=new(ELeave) CTBlankWindow();
sl@0
   389
	iBlankWin->ConstructL(*iGroup);
sl@0
   390
	iBlankWin->SetVisible(EFalse);
sl@0
   391
	iBlankWin->Activate();
sl@0
   392
	iState=ENotStarted;
sl@0
   393
	}
sl@0
   394
sl@0
   395
void CPasswordTest::StartMainPasswordTestL()
sl@0
   396
	{
sl@0
   397
	if (iPassWin->BaseWin()->PasswordWindow(EPasswordAlways)!=KErrNone)
sl@0
   398
		{
sl@0
   399
		DisplayDialog(_L("Can't do password tests"),_L("Password window"),_L("already exists"), Client()->iGroup->GroupWin());
sl@0
   400
		AbortL();
sl@0
   401
		}
sl@0
   402
	SetPassState(EWaitForSwitchOff);
sl@0
   403
	}
sl@0
   404
sl@0
   405
void CPasswordTest::StartOnceADayPasswordTestL()
sl@0
   406
	{
sl@0
   407
	TestL(iPassWin->BaseWin()->PasswordWindow(EPasswordOnceADay)==KErrNone);
sl@0
   408
	}
sl@0
   409
sl@0
   410
TestState CPasswordTest::DoTestL()
sl@0
   411
	{
sl@0
   412
	if (iPasswordTestFailed)
sl@0
   413
		TestL(ETrue);
sl@0
   414
	switch(iState)
sl@0
   415
		{
sl@0
   416
		case 0:
sl@0
   417
			LogSubTest(_L("Password 1"),1);
sl@0
   418
			StartMainPasswordTestL();
sl@0
   419
			iState++;
sl@0
   420
			return(EContinue);
sl@0
   421
		case 1:
sl@0
   422
			LogSubTest(_L("Password 2"),2);
sl@0
   423
			StartOnceADayPasswordTestL();
sl@0
   424
			iState++;
sl@0
   425
			return(EContinue);
sl@0
   426
		default:
sl@0
   427
			return(EFinished);
sl@0
   428
		}
sl@0
   429
	}