First public contribution.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Coverted from TMan test code (TMMODCHG.CPP) August 2000
15 // Test modifier changed message
22 @internalComponent - Internal Symbian test code
27 #define LOGGING on //Uncoment this line to get extra logging
29 struct TModifierChangedTestsParams
31 TText *txt; // Text message telling user what to do
37 LOCAL_D TModifierChangedTestsParams ModifierChangedTests[]={
38 {(TText *)_S("Press Caps"),EModifierCapsLock,EModifierCapsLock,EModifierCapsLock},
39 {(TText *)_S("Press Caps (again)"),EModifierCapsLock,0,EModifierCapsLock},
40 {(TText *)_S("Press left shift"),EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift},
41 {(TText *)_S("Release left shift"),EModifierShift|EModifierLeftShift,0,EModifierShift|EModifierLeftShift},
42 {(TText *)_S("Press right shift"),EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift},
43 {(TText *)_S("Release right shift"),EModifierShift|EModifierRightShift,0,EModifierShift|EModifierRightShift},
44 {(TText *)_S("Press (left) func"),EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc},
45 {(TText *)_S("Release (left) func"),EModifierFunc|EModifierLeftFunc,0,EModifierFunc|EModifierLeftFunc},
46 {(TText *)_S("Press (left) control"),EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl},
47 {(TText *)_S("Release (left) control"),EModifierCtrl|EModifierLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl},
50 // list of ModifierEvents that should be monitored
51 LOCAL_D TInt ModifierChangedEvents=EModifierShift|EModifierLeftShift|EModifierRightShift|
52 EModifierCapsLock|EModifierFunc|EModifierLeftFunc|EModifierCtrl|EModifierLeftCtrl;
54 const TInt numTests=sizeof(ModifierChangedTests)/sizeof(ModifierChangedTests[0]);
58 // CTEventWindowGroup class //
61 CTEventWindowGroup::CTEventWindowGroup(CTClient *aClient, CTModifiersChanged *aTest) : CTWindowGroup(aClient), iTest(aTest)
64 void CTEventWindowGroup::ConstructL()
66 CTWindowGroup::ConstructL();
67 iGroupWin.EnableModifierChangedEvents(ModifierChangedEvents,EEventControlAlways);
70 void CTEventWindowGroup::ModifiersChanged(const TModifiersChangedEvent &aModifiersChanged, const TTime &)
72 iTest->TestModifiersState(aModifiersChanged); // tests if event is correct
75 void CTEventWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
77 if (aKey.iCode==EKeyEscape || (aKey.iCode==' ' && iTest->iModSetTest))
78 iTest->EndTest(); // not really needed, because timer cancels long running tests
82 // CMCWindow, class //
85 CMCWindow::CMCWindow(CTModifiersChanged *aTest) : CTWin(), iTest(aTest)
87 iBack=TRgb::Gray256(230);
90 void CMCWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
92 ConstructExtLD(*parent,pos,size);
93 iWin.SetBackgroundColor(iBack);
96 iLineHeight=iFont->HeightInPixels()*5/4;
97 iFontAscent=iFont->AscentInPixels();
99 iXpos2=iXpos1+12*iFont->TextWidthInPixels(_L("M"));
102 void CMCWindow::DrawModSetLine(const TDesC &aDes,TInt aModifier,TInt iSettableModifiers)
105 iGc->DrawText(aDes, TPoint(iXpos1,iYpos));
106 iGc->DrawText(aModifier&iSettableModifiers ? _L("Yes"):_L("No"), TPoint(iXpos2,iYpos));
109 void CMCWindow::Draw()
112 if (iTest->iModSetTest)
116 buf.Format(TRefByValue<const TDesC>(_L("Settable? [0x%4x]")), iTest->iSettable);
117 iGc->DrawText(_L("Modifier"), TPoint(iXpos1,iYpos));
118 iGc->DrawText(buf, TPoint(iXpos2,iYpos));
119 DrawModSetLine(_L("Shift"),EModifierShift,iTest->iSettable);
120 DrawModSetLine(_L("Left Shift"),EModifierLeftShift,iTest->iSettable);
121 DrawModSetLine(_L("Func"),EModifierFunc,iTest->iSettable);
122 DrawModSetLine(_L("Caps"),EModifierCapsLock,iTest->iSettable);
123 DrawModSetLine(_L("NumLock"),EModifierNumLock,iTest->iSettable);
124 DrawModSetLine(_L("Double Click"),EModifierDoubleClick,iTest->iSettable);
127 iGc->DrawText(TPtrC(ModifierChangedTests[iTest->SubState()].txt), TPoint(10,20));
132 CTModifiersChanged::CTModifiersChanged(CTestStep* aStep): CTWsGraphicsBase(aStep),
133 iSkipFirstModifierEvents(EFalse), iSubSchedulerRunning(EFalse)
137 CTModifiersChanged::~CTModifiersChanged()
144 void CTModifiersChanged::ConstructL()
146 iTimeOut=new(ELeave) CTimeOut();
147 iTimeOut->ConstructL();
148 iWin=new(ELeave) CMCWindow(this);
149 iWin->SetUpL(TPoint(10,10),TSize(240,200),Client()->iGroup, *Client()->iGc);
152 TInt CTModifiersChanged::TimeOut(TAny* aTest) // static
154 static_cast<CTModifiersChanged*>(aTest)->TimeOut();
158 void CTModifiersChanged::TimeOut()
161 _LIT(KLogTimeOut,"Test timed out after %d secs.");
162 LOG_MESSAGE2(KLogTimeOut,KTimeOutAfter/1000000);
167 void CTModifiersChanged::EndTest()
169 TEST(EFalse); // test failed (timeout or manually cancelled)
175 _LIT(KLogEndTest,"EndTest - State %d - SubState %d");
176 LOG_MESSAGE3(KLogEndTest,iTest->iState,iSubState);
177 if (iSubSchedulerRunning)
179 iSubSchedulerRunning = EFalse;
180 CActiveScheduler::Stop(); // stop the sub-scheduler, so test-framework can execute the next test
184 TInt CTModifiersChanged::SubState() const
189 void CTModifiersChanged::IncSubState()
191 if (iSubState<numTests-1)
195 TheClient->WaitForRedrawsToFinish();
198 else if (iSubState>=numTests-1) // test finished successfully
200 if (iSubSchedulerRunning)
202 iSubSchedulerRunning = EFalse;
203 CActiveScheduler::Stop(); // stop the sub-scheduler, so test-framework can execute the next test
208 void CTModifiersChanged::TestModifiersState(const TModifiersChangedEvent &aModifiersChanged)
210 if (iTest->iState==1) // only if currently in test 1 (add another if for further tests)
212 TInt getMods=Client()->iWs.GetModifierState(); // double check the modifiers
214 if (iSkipFirstModifierEvents)
216 _LIT(KLogIgnored,"### This Event is part of the initial setup and is ignored for the test. ###");
217 LOG_MESSAGE(KLogIgnored);
220 _LIT(KLog1,"##MC1 SS=%x Test-Modifiers=0x%x Test-Changed=0x%x Test-Mask=0x%x");
221 buf.Format(KLog1,iSubState,ModifierChangedTests[iSubState].state,ModifierChangedTests[iSubState].changed,ModifierChangedTests[iSubState].stateMask);
223 _LIT(KLog2,"##MC2 Event-Modifiers=0x%x Event-Changed=0x%x Get-Modifiers=0x%x");
224 buf.Format(KLog2,aModifiersChanged.iModifiers,aModifiersChanged.iChangedModifiers,getMods);
226 _LIT(KLog3,"##MC3 Changed: (Event) 0x%x==0x%x (Test)");
227 buf.Format(KLog3,aModifiersChanged.iChangedModifiers,ModifierChangedTests[iSubState].changed);
229 _LIT(KLog4,"##MC4 Modifier (with mask): (Event) 0x%x==0x%x (Test)");
230 buf.Format(KLog4,aModifiersChanged.iModifiers&ModifierChangedTests[iSubState].stateMask,ModifierChangedTests[iSubState].state);
232 _LIT(KLog5,"##MC5 Modifier (with mask): (Get) 0x%x==0x%x (Test)");
233 buf.Format(KLog5,getMods&ModifierChangedTests[iSubState].stateMask,ModifierChangedTests[iSubState].state);
236 if (iSkipFirstModifierEvents) // skip the events caused by the initialization
238 if(--iSkipCounter<=0)
240 iSkipFirstModifierEvents = EFalse;
245 if (aModifiersChanged.iChangedModifiers==ModifierChangedTests[iSubState].changed &&
246 (aModifiersChanged.iModifiers&ModifierChangedTests[iSubState].stateMask)==ModifierChangedTests[iSubState].state &&
247 (getMods&ModifierChangedTests[iSubState].stateMask)==ModifierChangedTests[iSubState].state)
249 IncSubState(); // subtest is successfull
253 TEST(EFalse); // subtest failed
254 _LIT(KLogTestFailed,"Modifier Change test failed.");
255 LOG_MESSAGE(KLogTestFailed);
261 void CTModifiersChanged::BadParams()
266 * Resets all the modifiers after the test is finished. Make sure that all keys used in the
267 * test are in the up-state.
269 void CTModifiersChanged::ResetModifiers()
271 _LIT(KLogResetModifiersError,"Error %d occured while turning off modifier 0x%x");
273 if ((err = Client()->iWs.SetModifierState(EModifierCapsLock,ETurnOffModifier)) != KErrNone)
274 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierCapsLock);
275 if ((err = Client()->iWs.SetModifierState(EModifierShift,ETurnOffModifier)) != KErrNone)
276 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierShift);
277 if ((err = Client()->iWs.SetModifierState(EModifierLeftShift,ETurnOffModifier)) != KErrNone)
278 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierLeftShift);
279 if ((err = Client()->iWs.SetModifierState(EModifierRightShift,ETurnOffModifier)) != KErrNone)
280 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierRightShift);
281 if ((err = Client()->iWs.SetModifierState(EModifierFunc,ETurnOffModifier)) != KErrNone)
282 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierFunc);
283 if ((err = Client()->iWs.SetModifierState(EModifierLeftFunc,ETurnOffModifier)) != KErrNone)
284 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierLeftFunc);
285 if ((err = Client()->iWs.SetModifierState(EModifierCtrl,ETurnOffModifier)) != KErrNone)
286 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierCtrl);
287 if ((err = Client()->iWs.SetModifierState(EModifierLeftCtrl,ETurnOffModifier)) != KErrNone)
288 LOG_MESSAGE3(KLogResetModifiersError,err, EModifierLeftCtrl);
292 * Initialises the Modifier state. All tested modifiers must be in the up-state before the
293 * test starts. The number of sent key simulations needed for initialization is recorded.
294 * Each key simulation during initialization causes a ModifierChanged event which should be
295 * ignored because it's not part of the actual test.
297 void CTModifiersChanged::ModifierChangedEventsL()
299 iEventGroup=new(ELeave) CTEventWindowGroup(Client(), this);
300 iEventGroup->ConstructL();
301 TInt modifiers=Client()->iWs.GetModifierState();
303 if ((ModifierChangedEvents&modifiers)>0) // reset modifiers if they are in the down-state
305 iSkipFirstModifierEvents = ETrue;
306 if ((modifiers&EModifierCapsLock)>0)
308 iTest->SimulateKeyDownUp(EStdKeyCapsLock);
310 modifiers=Client()->iWs.GetModifierState();
312 if ((modifiers&EModifierLeftShift)>0)
314 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
316 modifiers=Client()->iWs.GetModifierState();
318 if ((modifiers&EModifierRightShift)>0)
320 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyRightShift);
322 modifiers=Client()->iWs.GetModifierState();
324 if ((modifiers&EModifierLeftFunc)>0)
326 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftFunc);
328 modifiers=Client()->iWs.GetModifierState();
330 if ((modifiers&EModifierLeftCtrl)>0)
332 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftCtrl);
336 modifiers=Client()->iWs.GetModifierState();
337 _LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
338 LOG_MESSAGE2(KLog,modifiers);
341 void CTModifiersChanged::CheckModifier(TEventModifier aModifier)
344 TInt oldMods=Client()->iWs.GetModifierState();
345 Client()->iWs.SetModifierState(aModifier,EToggleModifier);
346 TInt getMods=Client()->iWs.GetModifierState();
347 if (oldMods!=getMods)
349 _LIT(KLogOff,"Attempted to turn off modifiers 0x%x, 0x%x still on");
350 _LIT(KLogOn,"Attempted to turn on modifiers 0x%x, 0x%x still off");
351 iSettable|=aModifier;
352 Client()->iWs.SetModifierState(aModifier,ETurnOffModifier);
353 getMods=Client()->iWs.GetModifierState();
354 retVal=!(getMods&aModifier);
357 LOG_MESSAGE3(KLogOff,aModifier,getMods&aModifier);
358 Client()->iWs.SetModifierState(aModifier,ETurnOnModifier);
359 getMods=Client()->iWs.GetModifierState();
360 retVal=getMods&aModifier;
363 LOG_MESSAGE3(KLogOn,aModifier,getMods&aModifier);
364 Client()->iWs.SetModifierState(aModifier,ETurnOffModifier);
365 getMods=Client()->iWs.GetModifierState();
366 retVal=!(getMods&aModifier);
369 LOG_MESSAGE3(KLogOff,aModifier,getMods&aModifier);
370 if (oldMods&aModifier)
371 Client()->iWs.SetModifierState(aModifier,ETurnOnModifier);
375 Client()->iWs.SetModifierState(aModifier,ETurnOffModifier);
376 retVal=oldMods==Client()->iWs.GetModifierState();
380 _LIT(KLog,"Attempted to turn off modifiers 0x%x, suceeded when it should have failed");
381 LOG_MESSAGE2(KLog,aModifier);
383 Client()->iWs.SetModifierState(aModifier,ETurnOnModifier);
384 retVal=oldMods==Client()->iWs.GetModifierState();
388 _LIT(KLog,"Attempted to turn on modifiers 0x%x, suceeded when it should have failed");
389 LOG_MESSAGE2(KLog,aModifier);
394 void CTModifiersChanged::SetModifiers()
397 for(TInt mod=1;mod!=0;mod<<=1)
398 CheckModifier((TEventModifier)mod);
400 Client()->iWs.Flush();
403 void CTModifiersChanged::SendEvents()
405 iTest->LogSubState(iSubState);
409 iTest->SimulateKeyDownUp(EStdKeyCapsLock);
412 iTest->SimulateKeyDownUp(EStdKeyCapsLock);
415 iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
418 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
421 iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyRightShift);
424 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyRightShift);
427 iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftFunc);
430 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftFunc);
433 iTest->SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftCtrl);
436 iTest->SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftCtrl);
442 TheClient->iWs.Flush();
445 void CTModifiersChanged::RunTestCaseL(TInt /*aCurTestCase*/)
447 _LIT(KModChange,"Modifier Change");
448 _LIT(KTestErrors,"Bad Parameter");
449 ((CTModifiersChangedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
450 switch(++iTest->iState)
453 @SYMTestCaseID GRAPHICS-WSERV-0239
457 @SYMTestCaseDesc Test modifier changed message
459 @SYMTestPriority High
461 @SYMTestStatus Implemented
463 @SYMTestActions Test that modifier changed message functions correctly
465 @SYMTestExpectedResults The message functions correctly
468 ((CTModifiersChangedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0239"));
469 iTest->LogSubTest(KModChange);
470 ModifierChangedEventsL();
471 // start a timer to cancel the sub-scheduler
472 iTimeOut->Start(KTimeOutAfter,TCallBack(CTModifiersChanged::TimeOut,this));
474 iSubSchedulerRunning = ETrue;
475 CActiveScheduler::Start(); // sub-scheduler blocks this AO (test-framework) until completion
477 ((CTModifiersChangedStep*)iStep)->RecordTestResultL();
478 ((CTModifiersChangedStep*)iStep)->CloseTMSGraphicsStep();
481 @SYMTestCaseID GRAPHICS-WSERV-0240
485 @SYMTestCaseDesc Test bad parameters for modifier changed message
487 @SYMTestPriority High
489 @SYMTestStatus Implemented
491 @SYMTestActions Test using bad parameters for a modifier changed message
493 @SYMTestExpectedResults Responds correctly when bad parameters are used
496 ((CTModifiersChangedStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0240"));
497 iTest->LogSubTest(KTestErrors);
499 ((CTModifiersChangedStep*)iStep)->RecordTestResultL();
502 ResetModifiers(); // reset modifiers, so further tests are not influenced
503 ((CTModifiersChangedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
504 ((CTModifiersChangedStep*)iStep)->CloseTMSGraphicsStep();
511 __WS_CONSTRUCT_STEP__(ModifiersChanged)