1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tman/TMPNTKEY.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,305 @@
1.4 +// Copyright (c) 1996-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 Pointer move/drag buffer
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <hal.h>
1.23 +#include "W32STD.H"
1.24 +#include "../tlib/testbase.h"
1.25 +#include "TMAN.H"
1.26 +
1.27 +const TInt ENumPntKeyTests=6;
1.28 +const TUint EModifierMask=EModifierCtrl|EModifierShift|EModifierFunc;
1.29 +
1.30 +class CTPntKeyTest;
1.31 +
1.32 +class CTPntKeyWindow : public CTWin
1.33 + {
1.34 +private:
1.35 + enum {KPointerMoveBufferSize=32};
1.36 +public:
1.37 + CTPntKeyWindow(CTPntKeyTest *aTest);
1.38 + ~CTPntKeyWindow();
1.39 + void SetUpLD(TPoint pos,TSize size,CTWinBase *parent);
1.40 + void PointerL(const TPointerEvent &pointer,const TTime &aTime);
1.41 + void KeyUpL(const TKeyEvent &aKey,const TTime &);
1.42 + void KeyDownL(const TKeyEvent &aKey,const TTime &);
1.43 + void WinKeyL(const TKeyEvent &aKey,const TTime &);
1.44 + void SwitchOn(const TTime &aTime);
1.45 + void SetState(TInt iState);
1.46 + void NextKey();
1.47 + void Test(TInt aCheck);
1.48 + void Error();
1.49 + void DrawButton(const TRect &aRect, const TDesC &aText);
1.50 + void Draw();
1.51 +private:
1.52 + CTPntKeyTest *iTest;
1.53 + TInt iKeyCount;
1.54 + TRect iKey1;
1.55 + TRect iKey2;
1.56 + TRect iKey3;
1.57 + static TInt iTestScanCodes[ENumPntKeyTests];
1.58 + static TUint iTestCodes[ENumPntKeyTests];
1.59 + static TUint iTestModifiers[ENumPntKeyTests];
1.60 + };
1.61 +
1.62 +class CTPntKeyTest : public CTestBase
1.63 + {
1.64 +public:
1.65 + CTPntKeyTest();
1.66 + ~CTPntKeyTest();
1.67 + TestState DoTestL();
1.68 + void FinishedTests();
1.69 + void ConstructL();
1.70 + void Failed();
1.71 + inline TBool NoDigitiser() const {return iNoDigitiser;}
1.72 +private:
1.73 + CTPntKeyWindow *iWin;
1.74 + TSize iWinSize;
1.75 + TInt iState;
1.76 + TBool iFailed;
1.77 + TBool iOldPointerState;
1.78 + TBool iNoDigitiser;
1.79 + };
1.80 +
1.81 +TInt CTPntKeyWindow::iTestScanCodes[ENumPntKeyTests]={'A','B',0,'C',EStdKeyEnter,'Y'};
1.82 +TUint CTPntKeyWindow::iTestCodes[ENumPntKeyTests]={'a','B',0,'c',EKeyEnter,'y'};
1.83 +TUint CTPntKeyWindow::iTestModifiers[ENumPntKeyTests]={0,EModifierShift,0,0,0,0};
1.84 +
1.85 +GLDEF_C CTestBase *CreatePointerKeyTest()
1.86 + {
1.87 + return(new(ELeave) CTPntKeyTest());
1.88 + }
1.89 +
1.90 +CTPntKeyWindow::CTPntKeyWindow(CTPntKeyTest *aTest) : iTest(aTest)
1.91 + {}
1.92 +
1.93 +CTPntKeyWindow::~CTPntKeyWindow()
1.94 + {
1.95 + }
1.96 +
1.97 +void CTPntKeyWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent)
1.98 + {
1.99 + ConstructExtLD(*parent,pos,size);
1.100 + iWin.SetPointerGrab(ETrue);
1.101 + iKey1=TRect(size.iWidth*1/16,size.iHeight/2,size.iWidth*5/16,size.iHeight);
1.102 + iKey2=TRect(size.iWidth*6/16,size.iHeight/2,size.iWidth*10/16,size.iHeight);
1.103 + iKey3=TRect(size.iWidth*11/16,size.iHeight/2,size.iWidth*15/16,size.iHeight);
1.104 + iWin.AddKeyRect(iKey1,'A',EFalse);
1.105 + iWin.AddKeyRect(iKey2,'B',EFalse);
1.106 + AssignGC(*Client()->iGc);
1.107 + BaseWin()->EnableOnEvents();
1.108 + Activate();
1.109 + }
1.110 +
1.111 +void CTPntKeyWindow::Error()
1.112 + {
1.113 + iTest->Failed();
1.114 + }
1.115 +
1.116 +void CTPntKeyWindow::SetState(TInt iState)
1.117 + {
1.118 + iKeyCount=iState-1;
1.119 + NextKey();
1.120 + iTest->Client()->Flush();
1.121 + }
1.122 +
1.123 +void CTPntKeyWindow::NextKey()
1.124 + {
1.125 + if (++iKeyCount==ENumPntKeyTests || iKeyCount>4)
1.126 + iTest->FinishedTests();
1.127 + else
1.128 + {
1.129 + if (iKeyCount==2)
1.130 + iWin.RemoveAllKeyRects();
1.131 + else if (iKeyCount==3)
1.132 + iWin.AddKeyRect(iKey3,'C',EFalse);
1.133 + else if (iKeyCount==4)
1.134 + {
1.135 + #if !defined(__WINS__)
1.136 + if (iTest->NoDigitiser())
1.137 + iTest->FinishedTests();
1.138 + #endif
1.139 + iWin.RemoveAllKeyRects();
1.140 + iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Z',EFalse);
1.141 + }
1.142 + else if (iKeyCount==5)
1.143 + {
1.144 + iWin.RemoveAllKeyRects();
1.145 + Client()->iWs.Flush();
1.146 + User::After(500000); // Wait half a second
1.147 + iWin.AddKeyRect(TRect(Client()->iScreen->SizeInPixels()),'Y',ETrue);
1.148 + }
1.149 + Invalidate();
1.150 + }
1.151 + }
1.152 +
1.153 +void CTPntKeyWindow::Test(TInt aCheck)
1.154 + {
1.155 + if (!aCheck)
1.156 + Error();
1.157 + }
1.158 +
1.159 +void CTPntKeyWindow::KeyUpL(const TKeyEvent &aKey,const TTime&)
1.160 + {
1.161 + if (aKey.iScanCode==iTestScanCodes[iKeyCount])
1.162 + NextKey();
1.163 + }
1.164 +
1.165 +void CTPntKeyWindow::KeyDownL(const TKeyEvent &aKey,const TTime &)
1.166 + {
1.167 + if (aKey.iScanCode!=EStdKeyLeftFunc && aKey.iScanCode!=EStdKeyRightFunc &&
1.168 + aKey.iScanCode!=EStdKeyLeftAlt && aKey.iScanCode!=EStdKeyRightAlt &&
1.169 + aKey.iScanCode!=EStdKeyLeftCtrl && aKey.iScanCode!=EStdKeyRightCtrl &&
1.170 + aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift &&
1.171 + aKey.iScanCode!=EStdKeyOff &&
1.172 + aKey.iScanCode!=EStdKeyEscape)
1.173 + Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
1.174 + }
1.175 +
1.176 +void CTPntKeyWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
1.177 + {
1.178 + if (aKey.iCode==EKeyEscape)
1.179 + iTest->FinishedTests();
1.180 + else
1.181 + {
1.182 + Test(aKey.iScanCode==iTestScanCodes[iKeyCount]);
1.183 + Test(aKey.iCode==iTestCodes[iKeyCount]);
1.184 + Test((aKey.iModifiers&EModifierMask)==(iTestModifiers[iKeyCount]&EModifierMask));
1.185 + }
1.186 + }
1.187 +
1.188 +void CTPntKeyWindow::SwitchOn(const TTime &)
1.189 + {
1.190 + if (iKeyCount==4)
1.191 + NextKey();
1.192 + else if (iKeyCount!=5)
1.193 + Error();
1.194 + }
1.195 +
1.196 +void CTPntKeyWindow::PointerL(const TPointerEvent &aPointer,const TTime &)
1.197 + {
1.198 + if (aPointer.iType==TPointerEvent::EButton1Down)
1.199 + {
1.200 + if (iKeyCount!=2)
1.201 + Error();
1.202 + else
1.203 + NextKey();
1.204 + }
1.205 + }
1.206 +
1.207 +void CTPntKeyWindow::DrawButton(const TRect &aRect, const TDesC &aText)
1.208 + {
1.209 + iGc->DrawRect(aRect);
1.210 + iGc->DrawText(aText, TPoint((aRect.iBr.iX+aRect.iTl.iX)/2,(aRect.iBr.iY+aRect.iTl.iY)/2));
1.211 + }
1.212 +
1.213 +void CTPntKeyWindow::Draw()
1.214 + {
1.215 + iGc->SetBrushColor(TRgb::Gray4(0));
1.216 + iGc->SetPenColor(TRgb::Gray4(3));
1.217 + iGc->Clear();
1.218 + DrawButton(iKey1,_L("A"));
1.219 + DrawButton(iKey2,_L("B"));
1.220 + DrawButton(iKey3,_L("C"));
1.221 + switch(iKeyCount)
1.222 + {
1.223 + case 0:
1.224 + iGc->DrawText(_L("Click on 'A'"), TPoint(10,20));
1.225 + break;
1.226 + case 1:
1.227 + iGc->DrawText(_L("Shift-Click on 'B'"), TPoint(10,20));
1.228 + break;
1.229 + case 2:
1.230 + iGc->DrawText(_L("Click anywhere in this window"), TPoint(10,20));
1.231 + break;
1.232 + case 3:
1.233 + iGc->DrawText(_L("Click on 'C'"), TPoint(10,20));
1.234 + break;
1.235 + case 4:
1.236 +#if defined(__WINS__) // Can't emulate touching dig when switched off under WINS
1.237 + iGc->DrawText(_L("Switch off and on (or press Enter)"), TPoint(10,20));
1.238 +#else
1.239 + iGc->DrawText(_L("1st Switch off, then touch the screen to switch on"), TPoint(10,20));
1.240 +#endif
1.241 + break;
1.242 + case 5:
1.243 +#if defined(__WINS__) // Can't emulate touching dig when switched off under WINS
1.244 + iGc->DrawText(_L("Touch anywhere in the window"), TPoint(10,20));
1.245 +#else
1.246 + iGc->DrawText(_L("2nd Switch off and touch the screen to switch on"), TPoint(10,20));
1.247 +#endif
1.248 + break;
1.249 + }
1.250 + }
1.251 +
1.252 +CTPntKeyTest::CTPntKeyTest() : CTestBase(_L("Pointer Key Test"))
1.253 + {}
1.254 +
1.255 +CTPntKeyTest::~CTPntKeyTest()
1.256 + {
1.257 + HAL::Set(HALData::EPenDisplayOn,iOldPointerState);
1.258 + CTWin::Delete(iWin);
1.259 + Client()->ResetFocus();
1.260 + }
1.261 +
1.262 +void CTPntKeyTest::Failed()
1.263 + {
1.264 + if (!iFailed)
1.265 + {
1.266 + iFailed=ETrue;
1.267 + FinishedTests();
1.268 + }
1.269 + }
1.270 +
1.271 +void CTPntKeyTest::FinishedTests()
1.272 + {
1.273 + Request();
1.274 + }
1.275 +
1.276 +void CTPntKeyTest::ConstructL()
1.277 + {
1.278 + CTPntKeyWindow *win=new(ELeave) CTPntKeyWindow(this);
1.279 + win->SetUpLD(TPoint(20,20),Client()->iScreen->SizeInPixels()-TSize(40,40),Client()->iGroup);
1.280 + iWin=win;
1.281 + Client()->iGroup->SetCurrentWindow(iWin);
1.282 + iNoDigitiser=EFalse;
1.283 + TInt err=HAL::Get(HALData::EPenDisplayOn,iOldPointerState);
1.284 + if (err==KErrNotSupported)
1.285 + iNoDigitiser=ETrue;
1.286 + else if (err==KErrNone)
1.287 + err=HAL::Set(HALData::EPenDisplayOn,ETrue);
1.288 + if (err==KErrNotSupported)
1.289 + iNoDigitiser=(!iOldPointerState);
1.290 + else
1.291 + TestL(err==KErrNone);
1.292 + }
1.293 +
1.294 +TestState CTPntKeyTest::DoTestL()
1.295 + {
1.296 + TestL(!iFailed);
1.297 + switch(iState)
1.298 + {
1.299 + case 0:
1.300 + LogSubTest(_L("Key set 1"),1);
1.301 + iWin->SetState(4);
1.302 + iState++;
1.303 + return(EContinue);
1.304 + default:
1.305 + return(EFinished);
1.306 + }
1.307 +// return(ENext);
1.308 + }