windowing/windowserver/test/tauto/TMODCHG.CPP
author hgs
Tue, 20 Jul 2010 13:27:44 +0300
changeset 121 d72fc2aace31
parent 103 2717213c588a
permissions -rw-r--r--
201027_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
103
hgs
parents:
diff changeset
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
// All rights reserved.
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
//
hgs
parents:
diff changeset
     8
// Initial Contributors:
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
//
hgs
parents:
diff changeset
    11
// Contributors:
hgs
parents:
diff changeset
    12
//
hgs
parents:
diff changeset
    13
// Description:
hgs
parents:
diff changeset
    14
// Coverted from TMan test code (TMMODCHG.CPP) August 2000
hgs
parents:
diff changeset
    15
// Test modifier changed message
hgs
parents:
diff changeset
    16
// 
hgs
parents:
diff changeset
    17
//
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
/**
hgs
parents:
diff changeset
    20
 @file
hgs
parents:
diff changeset
    21
 @test
hgs
parents:
diff changeset
    22
 @internalComponent - Internal Symbian test code
hgs
parents:
diff changeset
    23
*/
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include "TMODCHG.H"
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
#define LOGGING on	//Uncoment this line to get extra logging
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
struct TModifierChangedTestsParams
hgs
parents:
diff changeset
    30
	{
hgs
parents:
diff changeset
    31
	TText *txt;			// Text message telling user what to do
hgs
parents:
diff changeset
    32
	TUint changed;
hgs
parents:
diff changeset
    33
	TUint state;
hgs
parents:
diff changeset
    34
	TUint stateMask;
hgs
parents:
diff changeset
    35
	};
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
LOCAL_D TModifierChangedTestsParams ModifierChangedTests[]={
hgs
parents:
diff changeset
    38
	{(TText *)_S("Press Caps"),EModifierCapsLock,EModifierCapsLock,EModifierCapsLock},
hgs
parents:
diff changeset
    39
	{(TText *)_S("Press Caps (again)"),EModifierCapsLock,0,EModifierCapsLock},
hgs
parents:
diff changeset
    40
	{(TText *)_S("Press left shift"),EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift},
hgs
parents:
diff changeset
    41
	{(TText *)_S("Release left shift"),EModifierShift|EModifierLeftShift,0,EModifierShift|EModifierLeftShift},
hgs
parents:
diff changeset
    42
	{(TText *)_S("Press right shift"),EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift},
hgs
parents:
diff changeset
    43
	{(TText *)_S("Release right shift"),EModifierShift|EModifierRightShift,0,EModifierShift|EModifierRightShift},
hgs
parents:
diff changeset
    44
	{(TText *)_S("Press (left) func"),EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc},
hgs
parents:
diff changeset
    45
	{(TText *)_S("Release (left) func"),EModifierFunc|EModifierLeftFunc,0,EModifierFunc|EModifierLeftFunc},
hgs
parents:
diff changeset
    46
	{(TText *)_S("Press (left) control"),EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl},
hgs
parents:
diff changeset
    47
	{(TText *)_S("Release (left) control"),EModifierCtrl|EModifierLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl},
hgs
parents:
diff changeset
    48
	};
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
// list of ModifierEvents that should be monitored
hgs
parents:
diff changeset
    51
LOCAL_D TInt ModifierChangedEvents=EModifierShift|EModifierLeftShift|EModifierRightShift|
hgs
parents:
diff changeset
    52
	EModifierCapsLock|EModifierFunc|EModifierLeftFunc|EModifierCtrl|EModifierLeftCtrl;
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
const TInt numTests=sizeof(ModifierChangedTests)/sizeof(ModifierChangedTests[0]);
hgs
parents:
diff changeset
    55
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
//
hgs
parents:
diff changeset
    58
// CTEventWindowGroup class //
hgs
parents:
diff changeset
    59
//
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
CTEventWindowGroup::CTEventWindowGroup(CTClient *aClient, CTModifiersChanged *aTest) : CTWindowGroup(aClient), iTest(aTest)
hgs
parents:
diff changeset
    62
	{}
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
void CTEventWindowGroup::ConstructL()
hgs
parents:
diff changeset
    65
	{
hgs
parents:
diff changeset
    66
	CTWindowGroup::ConstructL();
hgs
parents:
diff changeset
    67
	iGroupWin.EnableModifierChangedEvents(ModifierChangedEvents,EEventControlAlways);
hgs
parents:
diff changeset
    68
	}
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
void CTEventWindowGroup::ModifiersChanged(const TModifiersChangedEvent &aModifiersChanged, const TTime &)
hgs
parents:
diff changeset
    71
	{
hgs
parents:
diff changeset
    72
	iTest->TestModifiersState(aModifiersChanged); // tests if event is correct
hgs
parents:
diff changeset
    73
	}
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
void CTEventWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
hgs
parents:
diff changeset
    76
	{
hgs
parents:
diff changeset
    77
	if (aKey.iCode==EKeyEscape || (aKey.iCode==' ' && iTest->iModSetTest))
hgs
parents:
diff changeset
    78
		iTest->EndTest(); // not really needed, because timer cancels long running tests
hgs
parents:
diff changeset
    79
	}
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
//
hgs
parents:
diff changeset
    82
// CMCWindow, class //
hgs
parents:
diff changeset
    83
//
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
CMCWindow::CMCWindow(CTModifiersChanged *aTest) : CTWin(), iTest(aTest)
hgs
parents:
diff changeset
    86
	{
hgs
parents:
diff changeset
    87
	iBack=TRgb::Gray256(230);
hgs
parents:
diff changeset
    88
	}
hgs
parents:
diff changeset
    89
hgs
parents:
diff changeset
    90
void CMCWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
hgs
parents:
diff changeset
    91
	{
hgs
parents:
diff changeset
    92
	ConstructExtLD(*parent,pos,size);
hgs
parents:
diff changeset
    93
	iWin.SetBackgroundColor(iBack);
hgs
parents:
diff changeset
    94
	Activate();
hgs
parents:
diff changeset
    95
	AssignGC(aGc);
hgs
parents:
diff changeset
    96
	iLineHeight=iFont->HeightInPixels()*5/4;
hgs
parents:
diff changeset
    97
	iFontAscent=iFont->AscentInPixels();
hgs
parents:
diff changeset
    98
	iXpos1=4;
hgs
parents:
diff changeset
    99
	iXpos2=iXpos1+12*iFont->TextWidthInPixels(_L("M"));
hgs
parents:
diff changeset
   100
	}
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
void CMCWindow::DrawModSetLine(const TDesC &aDes,TInt aModifier,TInt iSettableModifiers)
hgs
parents:
diff changeset
   103
	{
hgs
parents:
diff changeset
   104
	iYpos+=iLineHeight;
hgs
parents:
diff changeset
   105
	iGc->DrawText(aDes, TPoint(iXpos1,iYpos));
hgs
parents:
diff changeset
   106
	iGc->DrawText(aModifier&iSettableModifiers ? _L("Yes"):_L("No"), TPoint(iXpos2,iYpos));
hgs
parents:
diff changeset
   107
	}
hgs
parents:
diff changeset
   108
hgs
parents:
diff changeset
   109
void CMCWindow::Draw()
hgs
parents:
diff changeset
   110
	{
hgs
parents:
diff changeset
   111
	iGc->Clear();
hgs
parents:
diff changeset
   112
	if (iTest->iModSetTest)
hgs
parents:
diff changeset
   113
		{
hgs
parents:
diff changeset
   114
		iYpos=iFontAscent+3;
hgs
parents:
diff changeset
   115
		TBuf<32> buf;
hgs
parents:
diff changeset
   116
		buf.Format(TRefByValue<const TDesC>(_L("Settable? [0x%4x]")), iTest->iSettable);
hgs
parents:
diff changeset
   117
		iGc->DrawText(_L("Modifier"), TPoint(iXpos1,iYpos));
hgs
parents:
diff changeset
   118
		iGc->DrawText(buf, TPoint(iXpos2,iYpos));
hgs
parents:
diff changeset
   119
		DrawModSetLine(_L("Shift"),EModifierShift,iTest->iSettable);
hgs
parents:
diff changeset
   120
		DrawModSetLine(_L("Left Shift"),EModifierLeftShift,iTest->iSettable);
hgs
parents:
diff changeset
   121
		DrawModSetLine(_L("Func"),EModifierFunc,iTest->iSettable);
hgs
parents:
diff changeset
   122
		DrawModSetLine(_L("Caps"),EModifierCapsLock,iTest->iSettable);
hgs
parents:
diff changeset
   123
		DrawModSetLine(_L("NumLock"),EModifierNumLock,iTest->iSettable);
hgs
parents:
diff changeset
   124
		DrawModSetLine(_L("Double Click"),EModifierDoubleClick,iTest->iSettable);
hgs
parents:
diff changeset
   125
		}
hgs
parents:
diff changeset
   126
	else
hgs
parents:
diff changeset
   127
		iGc->DrawText(TPtrC(ModifierChangedTests[iTest->SubState()].txt), TPoint(10,20));
hgs
parents:
diff changeset
   128
	}
hgs
parents:
diff changeset
   129
hgs
parents:
diff changeset
   130
//
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
CTModifiersChanged::CTModifiersChanged(CTestStep* aStep): CTWsGraphicsBase(aStep), 
hgs
parents:
diff changeset
   133
	iSkipFirstModifierEvents(EFalse), iSubSchedulerRunning(EFalse)
hgs
parents:
diff changeset
   134
	{
hgs
parents:
diff changeset
   135
	}
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
CTModifiersChanged::~CTModifiersChanged()
hgs
parents:
diff changeset
   138
	{
hgs
parents:
diff changeset
   139
	delete iTimeOut;
hgs
parents:
diff changeset
   140
	delete iWin;
hgs
parents:
diff changeset
   141
	delete iEventGroup;
hgs
parents:
diff changeset
   142
	}
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
void CTModifiersChanged::ConstructL()
hgs
parents:
diff changeset
   145
	{
hgs
parents:
diff changeset
   146
	iTimeOut=new(ELeave) CTimeOut();
hgs
parents:
diff changeset
   147
	iTimeOut->ConstructL();
hgs
parents:
diff changeset
   148
	iWin=new(ELeave) CMCWindow(this);
hgs
parents:
diff changeset
   149
	iWin->SetUpL(TPoint(10,10),TSize(240,200),Client()->iGroup, *Client()->iGc);
hgs
parents:
diff changeset
   150
	}
hgs
parents:
diff changeset
   151
hgs
parents:
diff changeset
   152
TInt CTModifiersChanged::TimeOut(TAny* aTest) // static
hgs
parents:
diff changeset
   153
	{
hgs
parents:
diff changeset
   154
	static_cast<CTModifiersChanged*>(aTest)->TimeOut();
hgs
parents:
diff changeset
   155
	return(KErrNone);
hgs
parents:
diff changeset
   156
	}
hgs
parents:
diff changeset
   157
hgs
parents:
diff changeset
   158
void CTModifiersChanged::TimeOut()
hgs
parents:
diff changeset
   159
	{
hgs
parents:
diff changeset
   160
	#if defined(LOGGING)
hgs
parents:
diff changeset
   161
		_LIT(KLogTimeOut,"Test timed out after %d secs.");
hgs
parents:
diff changeset
   162
		LOG_MESSAGE2(KLogTimeOut,KTimeOutAfter/1000000);
hgs
parents:
diff changeset
   163
	#endif
hgs
parents:
diff changeset
   164
	EndTest();
hgs
parents:
diff changeset
   165
	}
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
void CTModifiersChanged::EndTest() 
hgs
parents:
diff changeset
   168
	{
hgs
parents:
diff changeset
   169
	TEST(EFalse); // test failed (timeout or manually cancelled)
hgs
parents:
diff changeset
   170
	if (iModSetTest)
hgs
parents:
diff changeset
   171
		{
hgs
parents:
diff changeset
   172
		iModSetTest=EFalse;
hgs
parents:
diff changeset
   173
		iWin->Invalidate();
hgs
parents:
diff changeset
   174
		}
hgs
parents:
diff changeset
   175
	_LIT(KLogEndTest,"EndTest - State %d - SubState %d");
hgs
parents:
diff changeset
   176
	LOG_MESSAGE3(KLogEndTest,iTest->iState,iSubState);
hgs
parents:
diff changeset
   177
	if (iSubSchedulerRunning) 
hgs
parents:
diff changeset
   178
		{
hgs
parents:
diff changeset
   179
		iSubSchedulerRunning = EFalse;
hgs
parents:
diff changeset
   180
		CActiveScheduler::Stop(); // stop the sub-scheduler, so test-framework can execute the next test
hgs
parents:
diff changeset
   181
		}		
hgs
parents:
diff changeset
   182
	}
hgs
parents:
diff changeset
   183
hgs
parents:
diff changeset
   184
TInt CTModifiersChanged::SubState() const
hgs
parents:
diff changeset
   185
	{
hgs
parents:
diff changeset
   186
	return(iSubState);
hgs
parents:
diff changeset
   187
	}
hgs
parents:
diff changeset
   188
hgs
parents:
diff changeset
   189
void CTModifiersChanged::IncSubState()
hgs
parents:
diff changeset
   190
	{
hgs
parents:
diff changeset
   191
	if (iSubState<numTests-1)
hgs
parents:
diff changeset
   192
		{
hgs
parents:
diff changeset
   193
		iSubState++;
hgs
parents:
diff changeset
   194
		iWin->Invalidate();
hgs
parents:
diff changeset
   195
		TheClient->WaitForRedrawsToFinish();
hgs
parents:
diff changeset
   196
		SendEvents();
hgs
parents:
diff changeset
   197
		}
hgs
parents:
diff changeset
   198
	else if (iSubState>=numTests-1) // test finished successfully
hgs
parents:
diff changeset
   199
		{
hgs
parents:
diff changeset
   200
		if (iSubSchedulerRunning)
hgs
parents:
diff changeset
   201
			{
hgs
parents:
diff changeset
   202
			iSubSchedulerRunning = EFalse;
hgs
parents:
diff changeset
   203
			CActiveScheduler::Stop(); // stop the sub-scheduler, so test-framework can execute the next test
hgs
parents:
diff changeset
   204
			}
hgs
parents:
diff changeset
   205
		}
hgs
parents:
diff changeset
   206
	}
hgs
parents:
diff changeset
   207
hgs
parents:
diff changeset
   208
void CTModifiersChanged::TestModifiersState(const TModifiersChangedEvent &aModifiersChanged)
hgs
parents:
diff changeset
   209
	{
hgs
parents:
diff changeset
   210
	if (iTest->iState==1) // only if currently in test 1 (add another if for further tests)
hgs
parents:
diff changeset
   211
		{
hgs
parents:
diff changeset
   212
		TInt getMods=Client()->iWs.GetModifierState();	// double check the modifiers
hgs
parents:
diff changeset
   213
		#if defined(LOGGING)
hgs
parents:
diff changeset
   214
			if (iSkipFirstModifierEvents)
hgs
parents:
diff changeset
   215
				{
hgs
parents:
diff changeset
   216
				_LIT(KLogIgnored,"### This Event is part of the initial setup and is ignored for the test. ###");
hgs
parents:
diff changeset
   217
				LOG_MESSAGE(KLogIgnored);
hgs
parents:
diff changeset
   218
				}			
hgs
parents:
diff changeset
   219
			TLogMessageText buf;
hgs
parents:
diff changeset
   220
			_LIT(KLog1,"##MC1  SS=%x  Test-Modifiers=0x%x  Test-Changed=0x%x  Test-Mask=0x%x");
hgs
parents:
diff changeset
   221
			buf.Format(KLog1,iSubState,ModifierChangedTests[iSubState].state,ModifierChangedTests[iSubState].changed,ModifierChangedTests[iSubState].stateMask);
hgs
parents:
diff changeset
   222
			LOG_MESSAGE(buf);
hgs
parents:
diff changeset
   223
			_LIT(KLog2,"##MC2  Event-Modifiers=0x%x  Event-Changed=0x%x  Get-Modifiers=0x%x");
hgs
parents:
diff changeset
   224
			buf.Format(KLog2,aModifiersChanged.iModifiers,aModifiersChanged.iChangedModifiers,getMods);
hgs
parents:
diff changeset
   225
			LOG_MESSAGE(buf);
hgs
parents:
diff changeset
   226
			_LIT(KLog3,"##MC3  Changed:              (Event) 0x%x==0x%x (Test)");
hgs
parents:
diff changeset
   227
			buf.Format(KLog3,aModifiersChanged.iChangedModifiers,ModifierChangedTests[iSubState].changed);
hgs
parents:
diff changeset
   228
			LOG_MESSAGE(buf);
hgs
parents:
diff changeset
   229
			_LIT(KLog4,"##MC4  Modifier (with mask): (Event) 0x%x==0x%x (Test)");
hgs
parents:
diff changeset
   230
			buf.Format(KLog4,aModifiersChanged.iModifiers&ModifierChangedTests[iSubState].stateMask,ModifierChangedTests[iSubState].state);
hgs
parents:
diff changeset
   231
			LOG_MESSAGE(buf);
hgs
parents:
diff changeset
   232
			_LIT(KLog5,"##MC5  Modifier (with mask):   (Get) 0x%x==0x%x (Test)");
hgs
parents:
diff changeset
   233
			buf.Format(KLog5,getMods&ModifierChangedTests[iSubState].stateMask,ModifierChangedTests[iSubState].state);
hgs
parents:
diff changeset
   234
			LOG_MESSAGE(buf);
hgs
parents:
diff changeset
   235
		#endif
hgs
parents:
diff changeset
   236
		if (iSkipFirstModifierEvents) // skip the events caused by the initialization
hgs
parents:
diff changeset
   237
			{
hgs
parents:
diff changeset
   238
			if(--iSkipCounter<=0)
hgs
parents:
diff changeset
   239
				{
hgs
parents:
diff changeset
   240
				iSkipFirstModifierEvents = EFalse;
hgs
parents:
diff changeset
   241
				}
hgs
parents:
diff changeset
   242
			}
hgs
parents:
diff changeset
   243
		else
hgs
parents:
diff changeset
   244
			{
hgs
parents:
diff changeset
   245
			if (aModifiersChanged.iChangedModifiers==ModifierChangedTests[iSubState].changed && 
hgs
parents:
diff changeset
   246
					(aModifiersChanged.iModifiers&ModifierChangedTests[iSubState].stateMask)==ModifierChangedTests[iSubState].state &&
hgs
parents:
diff changeset
   247
					(getMods&ModifierChangedTests[iSubState].stateMask)==ModifierChangedTests[iSubState].state)
hgs
parents:
diff changeset
   248
				{
hgs
parents:
diff changeset
   249
				IncSubState(); // subtest is successfull
hgs
parents:
diff changeset
   250
				}
hgs
parents:
diff changeset
   251
			else
hgs
parents:
diff changeset
   252
				{				
hgs
parents:
diff changeset
   253
				TEST(EFalse); // subtest failed
hgs
parents:
diff changeset
   254
				_LIT(KLogTestFailed,"Modifier Change test failed.");
hgs
parents:
diff changeset
   255
				LOG_MESSAGE(KLogTestFailed);
hgs
parents:
diff changeset
   256
				}
hgs
parents:
diff changeset
   257
			}
hgs
parents:
diff changeset
   258
		} // if test 1
hgs
parents:
diff changeset
   259
	}
hgs
parents:
diff changeset
   260
hgs
parents:
diff changeset
   261
void CTModifiersChanged::BadParams()
hgs
parents:
diff changeset
   262
	{
hgs
parents:
diff changeset
   263
	}
hgs
parents:
diff changeset
   264
hgs
parents:
diff changeset
   265
/**
hgs
parents:
diff changeset
   266
 * Resets all the modifiers after the test is finished. Make sure that all keys used in the
hgs
parents:
diff changeset
   267
 * test are in the up-state.
hgs
parents:
diff changeset
   268
 */
hgs
parents:
diff changeset
   269
void CTModifiersChanged::ResetModifiers()
hgs
parents:
diff changeset
   270
	{
hgs
parents:
diff changeset
   271
	_LIT(KLogResetModifiersError,"Error %d occured while turning off modifier 0x%x");
hgs
parents:
diff changeset
   272
	TInt err;
hgs
parents:
diff changeset
   273
	if ((err = Client()->iWs.SetModifierState(EModifierCapsLock,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   274
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierCapsLock);
hgs
parents:
diff changeset
   275
	if ((err = Client()->iWs.SetModifierState(EModifierShift,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   276
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierShift);
hgs
parents:
diff changeset
   277
	if ((err = Client()->iWs.SetModifierState(EModifierLeftShift,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   278
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierLeftShift);
hgs
parents:
diff changeset
   279
	if ((err = Client()->iWs.SetModifierState(EModifierRightShift,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   280
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierRightShift);
hgs
parents:
diff changeset
   281
	if ((err = Client()->iWs.SetModifierState(EModifierFunc,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   282
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierFunc);
hgs
parents:
diff changeset
   283
	if ((err = Client()->iWs.SetModifierState(EModifierLeftFunc,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   284
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierLeftFunc);
hgs
parents:
diff changeset
   285
	if ((err = Client()->iWs.SetModifierState(EModifierCtrl,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   286
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierCtrl);
hgs
parents:
diff changeset
   287
	if ((err = Client()->iWs.SetModifierState(EModifierLeftCtrl,ETurnOffModifier)) != KErrNone)
hgs
parents:
diff changeset
   288
		LOG_MESSAGE3(KLogResetModifiersError,err, EModifierLeftCtrl);
hgs
parents:
diff changeset
   289
	}
hgs
parents:
diff changeset
   290
hgs
parents:
diff changeset
   291
/**
hgs
parents:
diff changeset
   292
 * Initialises the Modifier state. All tested modifiers must be in the up-state before the
hgs
parents:
diff changeset
   293
 * test starts. The number of sent key simulations needed for initialization is recorded.
hgs
parents:
diff changeset
   294
 * Each key simulation during initialization causes a ModifierChanged event which should be 
hgs
parents:
diff changeset
   295
 * ignored because it's not part of the actual test.
hgs
parents:
diff changeset
   296
 */
hgs
parents:
diff changeset
   297
void CTModifiersChanged::ModifierChangedEventsL()
hgs
parents:
diff changeset
   298
	{
hgs
parents:
diff changeset
   299
	iEventGroup=new(ELeave) CTEventWindowGroup(Client(), this);
hgs
parents:
diff changeset
   300
	iEventGroup->ConstructL();
hgs
parents:
diff changeset
   301
	TInt modifiers=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   302
	
hgs
parents:
diff changeset
   303
	if ((ModifierChangedEvents&modifiers)>0) // reset modifiers if they are in the down-state
hgs
parents:
diff changeset
   304
		{
hgs
parents:
diff changeset
   305
		iSkipFirstModifierEvents = ETrue;
hgs
parents:
diff changeset
   306
		if ((modifiers&EModifierCapsLock)>0)
hgs
parents:
diff changeset
   307
			{
hgs
parents:
diff changeset
   308
			iTest->SimulateKeyDownUp(EStdKeyCapsLock);
hgs
parents:
diff changeset
   309
			++iSkipCounter;
hgs
parents:
diff changeset
   310
			modifiers=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   311
			}
hgs
parents:
diff changeset
   312
		if ((modifiers&EModifierLeftShift)>0)
hgs
parents:
diff changeset
   313
			{
hgs
parents:
diff changeset
   314
			iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
hgs
parents:
diff changeset
   315
			++iSkipCounter;
hgs
parents:
diff changeset
   316
			modifiers=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   317
			}
hgs
parents:
diff changeset
   318
		if ((modifiers&EModifierRightShift)>0)
hgs
parents:
diff changeset
   319
			{
hgs
parents:
diff changeset
   320
			iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyRightShift);
hgs
parents:
diff changeset
   321
			++iSkipCounter;
hgs
parents:
diff changeset
   322
			modifiers=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   323
			}
hgs
parents:
diff changeset
   324
		if ((modifiers&EModifierLeftFunc)>0)
hgs
parents:
diff changeset
   325
			{
hgs
parents:
diff changeset
   326
			iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftFunc);
hgs
parents:
diff changeset
   327
			++iSkipCounter;
hgs
parents:
diff changeset
   328
			modifiers=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   329
			}
hgs
parents:
diff changeset
   330
		if ((modifiers&EModifierLeftCtrl)>0)
hgs
parents:
diff changeset
   331
			{
hgs
parents:
diff changeset
   332
			iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftCtrl);
hgs
parents:
diff changeset
   333
			++iSkipCounter;
hgs
parents:
diff changeset
   334
			}
hgs
parents:
diff changeset
   335
		}
hgs
parents:
diff changeset
   336
	modifiers=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   337
	_LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
hgs
parents:
diff changeset
   338
	LOG_MESSAGE2(KLog,modifiers);
hgs
parents:
diff changeset
   339
	}
hgs
parents:
diff changeset
   340
hgs
parents:
diff changeset
   341
void CTModifiersChanged::CheckModifier(TEventModifier aModifier)
hgs
parents:
diff changeset
   342
	{
hgs
parents:
diff changeset
   343
	TBool retVal;
hgs
parents:
diff changeset
   344
	TInt oldMods=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   345
	Client()->iWs.SetModifierState(aModifier,EToggleModifier);
hgs
parents:
diff changeset
   346
	TInt getMods=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   347
	if (oldMods!=getMods)
hgs
parents:
diff changeset
   348
		{
hgs
parents:
diff changeset
   349
		_LIT(KLogOff,"Attempted to turn off modifiers 0x%x, 0x%x still on");
hgs
parents:
diff changeset
   350
		_LIT(KLogOn,"Attempted to turn on modifiers 0x%x, 0x%x still off");
hgs
parents:
diff changeset
   351
		iSettable|=aModifier;
hgs
parents:
diff changeset
   352
		Client()->iWs.SetModifierState(aModifier,ETurnOffModifier);
hgs
parents:
diff changeset
   353
		getMods=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   354
		retVal=!(getMods&aModifier);
hgs
parents:
diff changeset
   355
		TEST(retVal);
hgs
parents:
diff changeset
   356
		if (!retVal)
hgs
parents:
diff changeset
   357
			LOG_MESSAGE3(KLogOff,aModifier,getMods&aModifier);
hgs
parents:
diff changeset
   358
		Client()->iWs.SetModifierState(aModifier,ETurnOnModifier);
hgs
parents:
diff changeset
   359
		getMods=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   360
		retVal=getMods&aModifier;
hgs
parents:
diff changeset
   361
		TEST(retVal);
hgs
parents:
diff changeset
   362
		if (!retVal)
hgs
parents:
diff changeset
   363
			LOG_MESSAGE3(KLogOn,aModifier,getMods&aModifier);
hgs
parents:
diff changeset
   364
		Client()->iWs.SetModifierState(aModifier,ETurnOffModifier);
hgs
parents:
diff changeset
   365
		getMods=Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   366
		retVal=!(getMods&aModifier);
hgs
parents:
diff changeset
   367
		TEST(retVal);
hgs
parents:
diff changeset
   368
		if (!retVal)
hgs
parents:
diff changeset
   369
			LOG_MESSAGE3(KLogOff,aModifier,getMods&aModifier);
hgs
parents:
diff changeset
   370
		if (oldMods&aModifier)
hgs
parents:
diff changeset
   371
			Client()->iWs.SetModifierState(aModifier,ETurnOnModifier);
hgs
parents:
diff changeset
   372
		}
hgs
parents:
diff changeset
   373
	else
hgs
parents:
diff changeset
   374
		{
hgs
parents:
diff changeset
   375
		Client()->iWs.SetModifierState(aModifier,ETurnOffModifier);
hgs
parents:
diff changeset
   376
		retVal=oldMods==Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   377
		TEST(retVal);
hgs
parents:
diff changeset
   378
		if (!retVal)
hgs
parents:
diff changeset
   379
			{
hgs
parents:
diff changeset
   380
			_LIT(KLog,"Attempted to turn off modifiers 0x%x, suceeded when it should have failed");
hgs
parents:
diff changeset
   381
			LOG_MESSAGE2(KLog,aModifier);
hgs
parents:
diff changeset
   382
			}
hgs
parents:
diff changeset
   383
		Client()->iWs.SetModifierState(aModifier,ETurnOnModifier);
hgs
parents:
diff changeset
   384
		retVal=oldMods==Client()->iWs.GetModifierState();
hgs
parents:
diff changeset
   385
		TEST(retVal);
hgs
parents:
diff changeset
   386
		if (!retVal)
hgs
parents:
diff changeset
   387
			{
hgs
parents:
diff changeset
   388
			_LIT(KLog,"Attempted to turn on modifiers 0x%x, suceeded when it should have failed");
hgs
parents:
diff changeset
   389
			LOG_MESSAGE2(KLog,aModifier);
hgs
parents:
diff changeset
   390
			}
hgs
parents:
diff changeset
   391
		}
hgs
parents:
diff changeset
   392
	}
hgs
parents:
diff changeset
   393
hgs
parents:
diff changeset
   394
void CTModifiersChanged::SetModifiers()
hgs
parents:
diff changeset
   395
	{
hgs
parents:
diff changeset
   396
	iModSetTest=ETrue;
hgs
parents:
diff changeset
   397
	for(TInt mod=1;mod!=0;mod<<=1)
hgs
parents:
diff changeset
   398
		CheckModifier((TEventModifier)mod);
hgs
parents:
diff changeset
   399
	iWin->Invalidate();
hgs
parents:
diff changeset
   400
	Client()->iWs.Flush();
hgs
parents:
diff changeset
   401
	}
hgs
parents:
diff changeset
   402
hgs
parents:
diff changeset
   403
void CTModifiersChanged::SendEvents()
hgs
parents:
diff changeset
   404
	{
hgs
parents:
diff changeset
   405
	iTest->LogSubState(iSubState);
hgs
parents:
diff changeset
   406
	switch (iSubState)
hgs
parents:
diff changeset
   407
		{
hgs
parents:
diff changeset
   408
	case 0:
hgs
parents:
diff changeset
   409
		iTest->SimulateKeyDownUp(EStdKeyCapsLock);
hgs
parents:
diff changeset
   410
		break;
hgs
parents:
diff changeset
   411
	case 1:
hgs
parents:
diff changeset
   412
		iTest->SimulateKeyDownUp(EStdKeyCapsLock);
hgs
parents:
diff changeset
   413
		break;
hgs
parents:
diff changeset
   414
	case 2:
hgs
parents:
diff changeset
   415
		iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
hgs
parents:
diff changeset
   416
		break;
hgs
parents:
diff changeset
   417
	case 3:
hgs
parents:
diff changeset
   418
		iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
hgs
parents:
diff changeset
   419
		break;
hgs
parents:
diff changeset
   420
	case 4:
hgs
parents:
diff changeset
   421
		iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyRightShift);
hgs
parents:
diff changeset
   422
		break;
hgs
parents:
diff changeset
   423
	case 5:
hgs
parents:
diff changeset
   424
		iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyRightShift);
hgs
parents:
diff changeset
   425
		break;
hgs
parents:
diff changeset
   426
	case 6:
hgs
parents:
diff changeset
   427
		iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftFunc);
hgs
parents:
diff changeset
   428
		break;
hgs
parents:
diff changeset
   429
	case 7:
hgs
parents:
diff changeset
   430
		iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftFunc);
hgs
parents:
diff changeset
   431
		break;
hgs
parents:
diff changeset
   432
	case 8:
hgs
parents:
diff changeset
   433
		iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftCtrl);
hgs
parents:
diff changeset
   434
		break;
hgs
parents:
diff changeset
   435
	case 9:
hgs
parents:
diff changeset
   436
		iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftCtrl);
hgs
parents:
diff changeset
   437
		break;
hgs
parents:
diff changeset
   438
	default:
hgs
parents:
diff changeset
   439
		TEST(EFalse);
hgs
parents:
diff changeset
   440
		return;
hgs
parents:
diff changeset
   441
		}
hgs
parents:
diff changeset
   442
	TheClient->iWs.Flush();
hgs
parents:
diff changeset
   443
	}
hgs
parents:
diff changeset
   444
hgs
parents:
diff changeset
   445
void CTModifiersChanged::RunTestCaseL(TInt /*aCurTestCase*/)
hgs
parents:
diff changeset
   446
	{
hgs
parents:
diff changeset
   447
	_LIT(KModChange,"Modifier Change");
hgs
parents:
diff changeset
   448
	_LIT(KTestErrors,"Bad Parameter");
hgs
parents:
diff changeset
   449
	((CTModifiersChangedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
hgs
parents:
diff changeset
   450
	switch(++iTest->iState)
hgs
parents:
diff changeset
   451
		{
hgs
parents:
diff changeset
   452
/**
hgs
parents:
diff changeset
   453
@SYMTestCaseID		GRAPHICS-WSERV-0239
hgs
parents:
diff changeset
   454
hgs
parents:
diff changeset
   455
@SYMDEF             DEF081259
hgs
parents:
diff changeset
   456
hgs
parents:
diff changeset
   457
@SYMTestCaseDesc    Test modifier changed message
hgs
parents:
diff changeset
   458
hgs
parents:
diff changeset
   459
@SYMTestPriority    High
hgs
parents:
diff changeset
   460
hgs
parents:
diff changeset
   461
@SYMTestStatus      Implemented
hgs
parents:
diff changeset
   462
hgs
parents:
diff changeset
   463
@SYMTestActions     Test that modifier changed message functions correctly
hgs
parents:
diff changeset
   464
hgs
parents:
diff changeset
   465
@SYMTestExpectedResults The message functions correctly
hgs
parents:
diff changeset
   466
*/
hgs
parents:
diff changeset
   467
		case 1:
hgs
parents:
diff changeset
   468
			((CTModifiersChangedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0239"));
hgs
parents:
diff changeset
   469
			iTest->LogSubTest(KModChange);
hgs
parents:
diff changeset
   470
			ModifierChangedEventsL();
hgs
parents:
diff changeset
   471
			// start a timer to cancel the sub-scheduler
hgs
parents:
diff changeset
   472
			iTimeOut->Start(KTimeOutAfter,TCallBack(CTModifiersChanged::TimeOut,this));
hgs
parents:
diff changeset
   473
			SendEvents();
hgs
parents:
diff changeset
   474
			iSubSchedulerRunning = ETrue;
hgs
parents:
diff changeset
   475
			CActiveScheduler::Start(); // sub-scheduler blocks this AO (test-framework) until completion
hgs
parents:
diff changeset
   476
			iTimeOut->Cancel();
hgs
parents:
diff changeset
   477
			((CTModifiersChangedStep*)iStep)->RecordTestResultL();
hgs
parents:
diff changeset
   478
			((CTModifiersChangedStep*)iStep)->CloseTMSGraphicsStep();
hgs
parents:
diff changeset
   479
			break;	
hgs
parents:
diff changeset
   480
/**
hgs
parents:
diff changeset
   481
@SYMTestCaseID		GRAPHICS-WSERV-0240
hgs
parents:
diff changeset
   482
hgs
parents:
diff changeset
   483
@SYMDEF             DEF081259
hgs
parents:
diff changeset
   484
hgs
parents:
diff changeset
   485
@SYMTestCaseDesc    Test bad parameters for modifier changed message
hgs
parents:
diff changeset
   486
hgs
parents:
diff changeset
   487
@SYMTestPriority    High
hgs
parents:
diff changeset
   488
hgs
parents:
diff changeset
   489
@SYMTestStatus      Implemented
hgs
parents:
diff changeset
   490
hgs
parents:
diff changeset
   491
@SYMTestActions     Test using bad parameters for a modifier changed message
hgs
parents:
diff changeset
   492
hgs
parents:
diff changeset
   493
@SYMTestExpectedResults Responds correctly when bad parameters are used
hgs
parents:
diff changeset
   494
*/
hgs
parents:
diff changeset
   495
		case 2:
hgs
parents:
diff changeset
   496
			((CTModifiersChangedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0240"));
hgs
parents:
diff changeset
   497
			iTest->LogSubTest(KTestErrors);
hgs
parents:
diff changeset
   498
			BadParams();
hgs
parents:
diff changeset
   499
			((CTModifiersChangedStep*)iStep)->RecordTestResultL();			
hgs
parents:
diff changeset
   500
			break;
hgs
parents:
diff changeset
   501
		default:
hgs
parents:
diff changeset
   502
			ResetModifiers(); // reset modifiers, so further tests are not influenced
hgs
parents:
diff changeset
   503
			((CTModifiersChangedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
hgs
parents:
diff changeset
   504
			((CTModifiersChangedStep*)iStep)->CloseTMSGraphicsStep();
hgs
parents:
diff changeset
   505
			TestComplete();
hgs
parents:
diff changeset
   506
		}
hgs
parents:
diff changeset
   507
	
hgs
parents:
diff changeset
   508
	
hgs
parents:
diff changeset
   509
	}
hgs
parents:
diff changeset
   510
hgs
parents:
diff changeset
   511
__WS_CONSTRUCT_STEP__(ModifiersChanged)