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 // Test modifier changed message
21 #include "../tlib/testbase.h"
24 class CTModifiersChangedTest;
26 class CMCWindow : public CTWin
29 CMCWindow(CTModifiersChangedTest *aTest);
30 void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
32 void DrawModSetLine(const TDesC &aDes,TInt aModifier,TInt iSettableModifiers);
34 CTModifiersChangedTest *iTest;
43 class CTEventWindowGroup : public CTWindowGroup
46 CTEventWindowGroup(CTClient *aClient, CTModifiersChangedTest *iTest);
48 void ModifiersChanged(const TModifiersChangedEvent &aModifiersChanged ,const TTime &aTime);
49 void KeyL(const TKeyEvent &aKey,const TTime &aTime);
51 CTModifiersChangedTest *iTest;
54 class CTModifiersChangedTest : public CTestBase
57 CTModifiersChangedTest();
58 ~CTModifiersChangedTest();
62 TInt SubState() const;
65 void ModifierChangedEventsL();
67 void CheckModifierL(TEventModifier aModifier);
75 CTEventWindowGroup *iEventGroup;
79 struct TModifierChangedTestsParams
81 TText *txt; // Text message telling user what to do
87 LOCAL_D TModifierChangedTestsParams ModifierChangedTests[]={
89 {(TText *)_S("Press Caps"),EModifierCapsLock,EModifierCapsLock,EModifierCapsLock},
90 {(TText *)_S("Press Caps (again)"),EModifierCapsLock,0,EModifierCapsLock},
92 {(TText *)_S("Press left shift"),EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift,EModifierShift|EModifierLeftShift},
93 {(TText *)_S("Release left shift"),EModifierShift|EModifierLeftShift,0,EModifierShift|EModifierLeftShift},
94 {(TText *)_S("Press right shift"),EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift,EModifierShift|EModifierRightShift},
95 {(TText *)_S("Release right shift"),EModifierShift|EModifierRightShift,0,EModifierShift|EModifierRightShift},
96 {(TText *)_S("Press (left) func"),EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc,EModifierFunc|EModifierLeftFunc},
97 {(TText *)_S("Release (left) func"),EModifierFunc|EModifierLeftFunc,0,EModifierFunc|EModifierLeftFunc},
98 {(TText *)_S("Press (left) control"),EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl,EModifierCtrl|EModifierLeftCtrl},
99 {(TText *)_S("Release (left) control"),EModifierCtrl|EModifierLeftCtrl,0,EModifierCtrl|EModifierLeftCtrl},
102 const TInt numTests=sizeof(ModifierChangedTests)/sizeof(ModifierChangedTests[0]);
104 GLDEF_C CTestBase *CreateModifiersChangedTest()
106 return(new(ELeave) CTModifiersChangedTest());
110 // CTEventWindowGroup class //
113 CTEventWindowGroup::CTEventWindowGroup(CTClient *aClient, CTModifiersChangedTest *aTest) : CTWindowGroup(aClient), iTest(aTest)
116 void CTEventWindowGroup::ConstructL()
118 CTWindowGroup::ConstructL();
119 iGroupWin.EnableModifierChangedEvents(EModifierShift|EModifierLeftShift|EModifierRightShift|EModifierCapsLock|
120 EModifierFunc|EModifierLeftFunc|EModifierCtrl|EModifierLeftCtrl,EEventControlAlways);
123 void CTEventWindowGroup::ModifiersChanged(const TModifiersChangedEvent &aModifiersChanged ,const TTime &)
125 TInt ss=iTest->SubState();
126 TInt getMods=Client()->iWs.GetModifierState(); // Double check the mods with get mods
127 if (aModifiersChanged.iChangedModifiers==ModifierChangedTests[ss].changed &&
128 (aModifiersChanged.iModifiers&ModifierChangedTests[ss].stateMask)==ModifierChangedTests[ss].state &&
129 (getMods&ModifierChangedTests[ss].stateMask)==ModifierChangedTests[ss].state)
130 iTest->IncSubState();
133 void CTEventWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
135 if (aKey.iCode==EKeyEscape || (aKey.iCode==' ' && iTest->iModSetTest))
140 // CMCWindow, class //
143 CMCWindow::CMCWindow(CTModifiersChangedTest *aTest) : CTWin(), iTest(aTest)
145 iBack=TRgb::Gray256(230);
148 void CMCWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
150 ConstructExtLD(*parent,pos,size);
151 iWin.SetBackgroundColor(iBack);
154 iLineHeight=iFont->HeightInPixels()*5/4;
155 iFontAscent=iFont->AscentInPixels();
157 iXpos2=iXpos1+12*iFont->TextWidthInPixels(_L("M"));
160 void CMCWindow::DrawModSetLine(const TDesC &aDes,TInt aModifier,TInt iSettableModifiers)
163 iGc->DrawText(aDes, TPoint(iXpos1,iYpos));
164 iGc->DrawText(aModifier&iSettableModifiers ? _L("Yes"):_L("No"), TPoint(iXpos2,iYpos));
167 void CMCWindow::Draw()
170 if (iTest->iModSetTest)
174 buf.Format(TRefByValue<const TDesC>(_L("Settable? [0x%4x]")), iTest->iSettable);
175 iGc->DrawText(_L("Modifier"), TPoint(iXpos1,iYpos));
176 iGc->DrawText(buf, TPoint(iXpos2,iYpos));
177 DrawModSetLine(_L("Shift"),EModifierShift,iTest->iSettable);
178 DrawModSetLine(_L("Left Shift"),EModifierLeftShift,iTest->iSettable);
179 DrawModSetLine(_L("Func"),EModifierFunc,iTest->iSettable);
180 DrawModSetLine(_L("Caps"),EModifierCapsLock,iTest->iSettable);
181 DrawModSetLine(_L("NumLock"),EModifierNumLock,iTest->iSettable);
182 DrawModSetLine(_L("Double Click"),EModifierDoubleClick,iTest->iSettable);
185 iGc->DrawText(TPtrC(ModifierChangedTests[iTest->SubState()].txt), TPoint(10,20));
190 CTModifiersChangedTest::CTModifiersChangedTest() : CTestBase(_L("Capture Key"))
193 CTModifiersChangedTest::~CTModifiersChangedTest()
199 void CTModifiersChangedTest::EndTest()
209 void CTModifiersChangedTest::ConstructL()
211 iWin=new(ELeave) CMCWindow(this);
212 iWin->SetUpL(TPoint(10,10),TSize(240,200),Client()->iGroup, *Client()->iGc);
215 TInt CTModifiersChangedTest::SubState() const
220 void CTModifiersChangedTest::IncSubState()
222 if (iSubState==(numTests-1))
231 void CTModifiersChangedTest::BadParams()
235 void CTModifiersChangedTest::ModifierChangedEventsL()
237 iEventGroup=new(ELeave) CTEventWindowGroup(Client(), this);
238 iEventGroup->ConstructL();
241 void CTModifiersChangedTest::CheckModifierL(TEventModifier aModifier)
243 TInt oldMods=Client()->iWs.GetModifierState();
244 Client()->iWs.SetModifierState(aModifier, EToggleModifier);
245 TInt getMods=Client()->iWs.GetModifierState();
246 if (oldMods!=getMods)
248 iSettable|=aModifier;
249 Client()->iWs.SetModifierState(aModifier, ETurnOffModifier);
250 getMods=Client()->iWs.GetModifierState();
251 TestL(!(getMods&aModifier));
252 Client()->iWs.SetModifierState(aModifier, ETurnOnModifier);
253 getMods=Client()->iWs.GetModifierState();
254 TestL(getMods&aModifier);
255 Client()->iWs.SetModifierState(aModifier, ETurnOffModifier);
256 getMods=Client()->iWs.GetModifierState();
257 TestL(!(getMods&aModifier));
258 if (oldMods&aModifier)
259 Client()->iWs.SetModifierState(aModifier, ETurnOnModifier);
263 Client()->iWs.SetModifierState(aModifier, ETurnOffModifier);
264 TestL(oldMods==Client()->iWs.GetModifierState());
265 Client()->iWs.SetModifierState(aModifier, ETurnOnModifier);
266 TestL(oldMods==Client()->iWs.GetModifierState());
270 void CTModifiersChangedTest::SetModifiersL()
273 for(TInt mod=1;mod!=0;mod<<=1)
274 CheckModifierL((TEventModifier)mod);
276 Client()->iWs.Flush();
279 TestState CTModifiersChangedTest::DoTestL()
283 case 0: //The first 2 tests have been converted to TAuto test code.
284 ModifierChangedEventsL();
288 LogSubTest(_L("Errors"),1);
292 LogSubTest(_L("Set modifiers"),1);