1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tman/HOTKEY2.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,424 @@
1.4 +// Copyright (c) 1995-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 capture key
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32svr.h>
1.23 +#include "W32STD.H"
1.24 +#include "../tlib/testbase.h"
1.25 +#include "TMAN.H"
1.26 +
1.27 +enum THotKeyRetValues
1.28 + {
1.29 + EHotKeyOkay,
1.30 + EHotKeyRetry,
1.31 + EHotKeyFail,
1.32 + };
1.33 +
1.34 +struct SHotKeyParams
1.35 + {
1.36 + THotKey hotKey;
1.37 + TUint keyCode;
1.38 + TUint mod_mask;
1.39 + TUint modifiers;
1.40 + };
1.41 +
1.42 +struct SHotKeyTestParams
1.43 + {
1.44 + TText *txt; // Text message telling user what to do
1.45 + };
1.46 +
1.47 +LOCAL_D SHotKeyParams HotKeys[]={
1.48 + {EHotKeyEnableLogging,'e',EModifierFunc|EModifierCtrl|EModifierShift,0},
1.49 + {EHotKeyDisableLogging,'d',EModifierFunc|EModifierCtrl|EModifierShift,EModifierFunc},
1.50 + {EHotKeyOfDeath,'q',0},
1.51 + {EHotKeyOfDeath,'w',0},
1.52 + };
1.53 +
1.54 +LOCAL_D SHotKeyTestParams HotKeyTests[]={
1.55 + {(TText *)_S("Use \"e\" to enable logging")},
1.56 + {(TText *)_S("Use \"<Alt>d\" to disable logging")},
1.57 + {(TText *)_S("Use \"q\" to kill the foreground app")},
1.58 + {(TText *)_S("Use \"w\" to kill the foreground app")},
1.59 + {(TText *)_S("Use \"<Cntrl><Alt><Shift>K\" to kill the foreground app")},
1.60 + };
1.61 +
1.62 +LOCAL_D TBool HotKeyTestIsDeathTest[]={EFalse, EFalse, ETrue, ETrue, ETrue};
1.63 +
1.64 +struct SErrorHotKey
1.65 + {
1.66 + THotKey hotKey;
1.67 + TUint keyCode;
1.68 + TUint mod_mask;
1.69 + TUint modifiers;
1.70 + };
1.71 +
1.72 +LOCAL_D SErrorHotKey errorKeys[]={
1.73 + {EHotKeyEnableLogging,'a',EModifierFunc|EModifierShift,EModifierFunc|EModifierCtrl},
1.74 + {EHotKeyDisableLogging,'1',0,EModifierFunc},
1.75 + {EHotKeyEnableLogging,3,EModifierCtrl,EModifierCtrl|EModifierShift},
1.76 + {EHotKeyDisableLogging,'a',EModifierFunc|EModifierShift,EModifierFunc|EModifierCtrl},
1.77 + {(THotKey)100,'1',0,EModifierFunc},
1.78 + {(THotKey)200, 3,EModifierCtrl,EModifierCtrl|EModifierShift},
1.79 + };
1.80 +
1.81 +const TInt numHotKeys=sizeof(HotKeys)/sizeof(HotKeys[0]);
1.82 +const TInt numHotKeyTests=sizeof(HotKeyTests)/sizeof(HotKeyTests[0]);
1.83 +const TInt numErrorKeys=sizeof(errorKeys)/sizeof(errorKeys[0]);
1.84 +
1.85 +class SHKWindow;
1.86 +class THotKeyTest;
1.87 +class SHKConnection;
1.88 +
1.89 +class SHKDeath : public CActive
1.90 + {
1.91 +public:
1.92 + SHKDeath(TInt aPriority);
1.93 + void SetConnection(SHKConnection *aConn);
1.94 + virtual void DoCancel();
1.95 + virtual void RunL();
1.96 + void Request();
1.97 +private:
1.98 + SHKConnection *iConn;
1.99 + };
1.100 +
1.101 +class SHKWindowGroup : public CTWindowGroup
1.102 + {
1.103 +public:
1.104 + SHKWindowGroup(CTClient *aClient);
1.105 + void KeyL(const TKeyEvent &aKey,const TTime &aTime);
1.106 + };
1.107 +
1.108 +class SHKConnection : public CTClient
1.109 + {
1.110 +public:
1.111 + SHKConnection(THotKeyTest *aTest, TInt aMode);
1.112 + ~SHKConnection();
1.113 + void ConstructL();
1.114 + void KeyL(const TKeyEvent &aKey);
1.115 + void SubStateChangedL();
1.116 + void CompleteL();
1.117 +protected:
1.118 + TInt iMode;
1.119 + SHKDeath iDeath;
1.120 + THotKeyTest *iTest;
1.121 + CTWin *iWin;
1.122 + static TInt iMainWinId;
1.123 + };
1.124 +
1.125 +class SHKWindow : public CTWin
1.126 + {
1.127 +public:
1.128 + SHKWindow(THotKeyTest *aTest);
1.129 + void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
1.130 + void Draw();
1.131 +protected:
1.132 + THotKeyTest *iTest;
1.133 + TRgb iBack;
1.134 + };
1.135 +
1.136 +class SHKWindow2 : public CTWin
1.137 + {
1.138 +public:
1.139 + SHKWindow2();
1.140 + void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
1.141 + void Draw();
1.142 + };
1.143 +
1.144 +class THotKeyTest : public CTestBase
1.145 + {
1.146 +public:
1.147 + THotKeyTest();
1.148 + ~THotKeyTest();
1.149 + TestState DoTestL();
1.150 + void ConstructL();
1.151 + void EndCaptureKeyTest();
1.152 + TInt SubState() const;
1.153 + void IncSubStateL();
1.154 + void BadParamsL();
1.155 +private:
1.156 + SHKConnection *iConn1;
1.157 + TSize iWinSize;
1.158 + TInt iState;
1.159 + TInt iSubState;
1.160 + TBool iIsInActiveScheduler;
1.161 + };
1.162 +
1.163 +TInt SHKConnection::iMainWinId;
1.164 +
1.165 +TInt SubThread(TAny *);
1.166 +
1.167 +GLDEF_C CTestBase *CreateHotKeyTest()
1.168 + {
1.169 + return(new(ELeave) THotKeyTest());
1.170 + }
1.171 +
1.172 +THotKeyTest::THotKeyTest() : CTestBase(_L("Hot Key"))
1.173 + {}
1.174 +
1.175 +THotKeyTest::~THotKeyTest()
1.176 + {
1.177 + User::SetJustInTime(ETrue);
1.178 + for(TInt index=0;index<numHotKeys;index++)
1.179 + {
1.180 + Client()->iWs.ClearHotKeys(HotKeys[index].hotKey);
1.181 + Client()->iWs.RestoreDefaultHotKey(HotKeys[index].hotKey);
1.182 + }
1.183 + delete iConn1;
1.184 + if (iIsInActiveScheduler)
1.185 + CActiveScheduler::Stop();
1.186 + }
1.187 +
1.188 +void THotKeyTest::EndCaptureKeyTest()
1.189 + {
1.190 + Request();
1.191 + }
1.192 +
1.193 +void THotKeyTest::ConstructL()
1.194 + {
1.195 + iConn1=new(ELeave) SHKConnection(this, EFalse);
1.196 + iConn1->ConstructL();
1.197 + for(TInt index=0;index<numHotKeys;index++)
1.198 + User::LeaveIfError(Client()->iWs.SetHotKey(HotKeys[index].hotKey, HotKeys[index].keyCode,HotKeys[index].mod_mask,HotKeys[index].modifiers));
1.199 + User::SetJustInTime(EFalse);
1.200 + }
1.201 +
1.202 +//
1.203 +// SHKDeath //
1.204 +//
1.205 +
1.206 +SHKDeath::SHKDeath(TInt aPriority) : CActive(aPriority)
1.207 + {
1.208 + CActiveScheduler::Add(this);
1.209 + }
1.210 +
1.211 +void SHKDeath::SetConnection(SHKConnection *aConn)
1.212 + {
1.213 + iConn=aConn;
1.214 + }
1.215 +
1.216 +void SHKDeath::DoCancel()
1.217 + {
1.218 + }
1.219 +
1.220 +void SHKDeath::RunL()
1.221 + {
1.222 + iConn->CompleteL();
1.223 + }
1.224 +
1.225 +void SHKDeath::Request()
1.226 + {
1.227 + SetActive();
1.228 + }
1.229 +
1.230 +//
1.231 +
1.232 +SHKWindowGroup::SHKWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
1.233 + {}
1.234 +
1.235 +void SHKWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &)
1.236 + {
1.237 + ((SHKConnection *)iClient)->KeyL(aKey);
1.238 + }
1.239 +
1.240 +//
1.241 +// SHKConnection
1.242 +
1.243 +SHKConnection::SHKConnection(THotKeyTest *aTest, TInt aMode) : iMode(aMode), iDeath(100), iTest(aTest)
1.244 + {
1.245 + iDeath.SetConnection(this);
1.246 + }
1.247 +
1.248 +SHKConnection::~SHKConnection()
1.249 + {
1.250 + iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
1.251 + CTWin::Delete(iWin);
1.252 + }
1.253 +
1.254 +void SHKConnection::KeyL(const TKeyEvent &aKey)
1.255 + {
1.256 + if (iTest)
1.257 + {
1.258 + if (aKey.iCode==EKeyEnter && !HotKeyTestIsDeathTest[iTest->SubState()])
1.259 + iTest->IncSubStateL();
1.260 + else if (aKey.iCode==EKeyEscape)
1.261 + iTest->AbortL();
1.262 + }
1.263 + }
1.264 +
1.265 +void SHKConnection::CompleteL()
1.266 + {
1.267 + iTest->IncSubStateL();
1.268 + }
1.269 +
1.270 +void SHKConnection::SubStateChangedL()
1.271 + {
1.272 + if (HotKeyTestIsDeathTest[iTest->SubState()])
1.273 + {
1.274 + RThread thread;
1.275 + iMainWinId=iGroup->GroupWin()->Identifier();
1.276 + TInt subState=iTest->SubState();
1.277 + User::After(100000);
1.278 + User::LeaveIfError(thread.Create(_L("SubThread"),SubThread,KDefaultStackSize,0x2000,0x2000,&subState,EOwnerThread));
1.279 + thread.Logon(iDeath.iStatus);
1.280 + iDeath.Request();
1.281 + thread.Resume();
1.282 + thread.Close();
1.283 + }
1.284 + iWin->Invalidate();
1.285 + iWs.Flush();
1.286 + }
1.287 +
1.288 +void SHKConnection::ConstructL()
1.289 + {
1.290 + CTClient::ConstructL();
1.291 + iGroup=new(ELeave) SHKWindowGroup(this);
1.292 + iGroup->ConstructL();
1.293 + TSize screenSize=iGroup->Size();
1.294 + iGroup->GroupWin()->AutoForeground(EFalse); // Don't allow clicking to cause foreground, might mess up test
1.295 + TInt winWidth;
1.296 + TInt winHeight;
1.297 + if (iMode==0)
1.298 + {
1.299 + winWidth=screenSize.iWidth/2;
1.300 + winHeight=screenSize.iHeight-10;
1.301 + SHKWindow *win=new(ELeave) SHKWindow(iTest);
1.302 + win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
1.303 + iWin=win;
1.304 + }
1.305 + else
1.306 + {
1.307 + winWidth=150;
1.308 + winHeight=50;
1.309 + iGroup->GroupWin()->SetOwningWindowGroup(iMainWinId);
1.310 + SHKWindow2 *win=new(ELeave) SHKWindow2();
1.311 + win->SetUpL(TPoint((screenSize.iWidth-winWidth)/2,(screenSize.iHeight-winHeight)/2),TSize(winWidth,winHeight),iGroup,*iGc);
1.312 + iWin=win;
1.313 + }
1.314 + iWs.Flush();
1.315 + }
1.316 +
1.317 +//
1.318 +// SHKWindow, class //
1.319 +//
1.320 +
1.321 +SHKWindow::SHKWindow(THotKeyTest *aTest) : CTWin(), iTest(aTest)
1.322 + {
1.323 + iBack=TRgb::Gray256(230);
1.324 + }
1.325 +
1.326 +void SHKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
1.327 + {
1.328 + ConstructExtLD(*parent,pos,size);
1.329 + iWin.SetBackgroundColor(iBack);
1.330 + Activate();
1.331 + AssignGC(aGc);
1.332 + }
1.333 +
1.334 +void SHKWindow::Draw()
1.335 + {
1.336 + iGc->Clear();
1.337 + iGc->DrawText(TPtrC(HotKeyTests[iTest->SubState()].txt), TPoint(10,20));
1.338 + iGc->DrawText(TPtrC(_L("Press <Enter> when tested okay")), TPoint(10,35));
1.339 + iGc->DrawText(TPtrC(_L("or escape to abort tests")), TPoint(10,50));
1.340 + }
1.341 +
1.342 +//
1.343 +// SHKWindow2, class //
1.344 +//
1.345 +
1.346 +SHKWindow2::SHKWindow2() : CTWin()
1.347 + {
1.348 + }
1.349 +
1.350 +void SHKWindow2::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
1.351 + {
1.352 + ConstructExtLD(*parent,pos,size);
1.353 + iWin.SetBackgroundColor(TRgb(0,0,0));
1.354 + Activate();
1.355 + AssignGC(aGc);
1.356 + }
1.357 +
1.358 +void SHKWindow2::Draw()
1.359 + {
1.360 + iGc->SetBrushColor(TRgb::Gray4(1));
1.361 + iGc->Clear();
1.362 + iGc->SetPenColor(TRgb::Gray4(3));
1.363 + iGc->DrawText(TPtrC(_L("Kill me!!!")), TPoint(10,15));
1.364 + }
1.365 +
1.366 +//
1.367 +
1.368 +TInt THotKeyTest::SubState() const
1.369 + {
1.370 + return(iSubState);
1.371 + }
1.372 +
1.373 +void THotKeyTest::IncSubStateL()
1.374 + {
1.375 + if (iSubState==(numHotKeyTests-1))
1.376 + EndCaptureKeyTest();
1.377 + else
1.378 + {
1.379 + iSubState++;
1.380 + iConn1->SubStateChangedL();
1.381 + }
1.382 + }
1.383 +
1.384 +void THotKeyTest::BadParamsL()
1.385 + {
1.386 + TInt resCount=Client()->iWs.ResourceCount();
1.387 + for(TInt index=0;index<numErrorKeys;index++)
1.388 + TestL(Client()->iWs.SetHotKey(errorKeys[index].hotKey, errorKeys[index].keyCode,errorKeys[index].mod_mask,errorKeys[index].modifiers)==KErrArgument);
1.389 + TestL(Client()->iWs.ResourceCount()==resCount);
1.390 + }
1.391 +
1.392 +TestState THotKeyTest::DoTestL()
1.393 + {
1.394 + switch(iState)
1.395 + {
1.396 + case 0:
1.397 + LogSubTest(_L("Errors"),1);
1.398 + BadParamsL();
1.399 + LogSubTest(_L("CaptureKey"),2);
1.400 + iState++;
1.401 + return(EContinue);
1.402 + default:
1.403 + return(EFinished);
1.404 + }
1.405 + }
1.406 +
1.407 +//======================================================//
1.408 +// Sub thread to do tests and get shot by window server //
1.409 +//======================================================//
1.410 +
1.411 +void SubThreadMain()
1.412 + {
1.413 + CActiveScheduler *TheActiveScheduler=new(ELeave) CActiveScheduler;
1.414 + CActiveScheduler::Install(TheActiveScheduler);
1.415 + SHKConnection *conn=new(ELeave) SHKConnection(NULL, ETrue);
1.416 + conn->ConstructL();
1.417 + CActiveScheduler::Start();
1.418 + delete TheActiveScheduler;
1.419 + }
1.420 +
1.421 +TInt SubThread(TAny *)
1.422 + {
1.423 + CTrapCleanup* CleanUpStack=CTrapCleanup::New();
1.424 + TRAPD(err,SubThreadMain());
1.425 + delete CleanUpStack;
1.426 + return(err);
1.427 + }