1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tman/MULTICON.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,446 @@
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 multiple connections to the window server
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 +const TInt EMaxSubState=3;
1.28 +
1.29 +class CMcWindowBase;
1.30 +class TMultiConTest;
1.31 +
1.32 +class CMcConnectionBase : public CTClient
1.33 + {
1.34 +public:
1.35 + CMcConnectionBase(TMultiConTest *aTest);
1.36 + ~CMcConnectionBase();
1.37 + virtual void ConstructL();
1.38 + void SubStateChanged();
1.39 +protected:
1.40 + TMultiConTest *iTest;
1.41 + CMcWindowBase *iWin;
1.42 + CWindowGc *iGc;
1.43 + };
1.44 +
1.45 +class CMcConnection : public CMcConnectionBase // Sets AutoForeground off
1.46 + {
1.47 +public:
1.48 + CMcConnection(TMultiConTest *aTest);
1.49 + void ConstructL();
1.50 + };
1.51 +
1.52 +class CMcWindowGroupAf : public CTWindowGroup
1.53 + {
1.54 +public:
1.55 + CMcWindowGroupAf(CTClient *aClient);
1.56 + void KeyL(const TKeyEvent &aKey, const TTime &aTime);
1.57 + };
1.58 +
1.59 +class CMcConnectionAf : public CMcConnectionBase // Sets AutoForeground on
1.60 + {
1.61 +public:
1.62 + CMcConnectionAf(TMultiConTest *aTest);
1.63 + void ConstructL();
1.64 + void KeyL(const TKeyEvent &aKey);
1.65 + };
1.66 +
1.67 +class CMcConnectionDef : public CMcConnectionBase // Leaves AutoForeground as the default value
1.68 + {
1.69 +public:
1.70 + CMcConnectionDef(TMultiConTest *aTest);
1.71 + void ConstructL();
1.72 + };
1.73 +
1.74 +class CMcWindowBase : public CTWin
1.75 + {
1.76 +public:
1.77 + CMcWindowBase(TMultiConTest *aTest);
1.78 + void SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
1.79 + virtual void Draw()=0;
1.80 + virtual void PointerL(const TPointerEvent &pointer,const TTime &)=0;
1.81 +protected:
1.82 + TMultiConTest *iTest;
1.83 + TRgb iBack;
1.84 + };
1.85 +
1.86 +class CMcWindow : public CMcWindowBase
1.87 + {
1.88 +public:
1.89 + CMcWindow(TMultiConTest *aTest);
1.90 + virtual void Draw();
1.91 + virtual void PointerL(const TPointerEvent &pointer,const TTime &);
1.92 + };
1.93 +
1.94 +class CMcWindowAf : public CMcWindowBase
1.95 + {
1.96 +public:
1.97 + CMcWindowAf(TMultiConTest *aTest);
1.98 + virtual void Draw();
1.99 + virtual void PointerL(const TPointerEvent &pointer,const TTime &);
1.100 + void ConstructL();
1.101 + };
1.102 +
1.103 +class CMcWindowDef : public CMcWindowBase
1.104 + {
1.105 +public:
1.106 + CMcWindowDef(TMultiConTest *aTest);
1.107 + virtual void Draw();
1.108 + virtual void PointerL(const TPointerEvent &pointer,const TTime &);
1.109 + };
1.110 +
1.111 +class TMultiConTest : public CTestBase
1.112 + {
1.113 +public:
1.114 + TMultiConTest();
1.115 + ~TMultiConTest();
1.116 + TestState DoTestL();
1.117 + void ConstructL();
1.118 + void EndAutoForegroundTest();
1.119 + TInt SubState() const;
1.120 + void IncSubState();
1.121 +private:
1.122 + CMcConnectionAf *iConn1;
1.123 + CMcConnection *iConn2;
1.124 + CMcConnectionDef *iConn3;
1.125 + TSize iWinSize;
1.126 + TInt iState;
1.127 + TInt iSubState;
1.128 + };
1.129 +
1.130 +GLDEF_C CTestBase *CreateMultiConTest()
1.131 + {
1.132 + return(new(ELeave) TMultiConTest());
1.133 + }
1.134 +
1.135 +TMultiConTest::TMultiConTest() : CTestBase(_L("MultiCon"))
1.136 + {}
1.137 +
1.138 +TMultiConTest::~TMultiConTest()
1.139 + {
1.140 + delete iConn1;
1.141 + delete iConn2;
1.142 + delete iConn3;
1.143 + }
1.144 +
1.145 +void TMultiConTest::EndAutoForegroundTest()
1.146 + {
1.147 + iConn1->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
1.148 + iConn2->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
1.149 + iConn3->iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
1.150 + Request();
1.151 + }
1.152 +
1.153 +void TMultiConTest::ConstructL()
1.154 + {
1.155 + iConn3=new(ELeave) CMcConnectionDef(this);
1.156 + iConn3->ConstructL();
1.157 + iConn2=new(ELeave) CMcConnection(this);
1.158 + iConn2->ConstructL();
1.159 + iConn1=new(ELeave) CMcConnectionAf(this);
1.160 + iConn1->ConstructL();
1.161 + }
1.162 +
1.163 +//
1.164 +// CMcConnection
1.165 +
1.166 +CMcConnectionBase::CMcConnectionBase(TMultiConTest *aTest) : iTest(aTest)
1.167 + {
1.168 + }
1.169 +
1.170 +CMcConnectionBase::~CMcConnectionBase()
1.171 + {
1.172 + CTWin::Delete(iWin);
1.173 + delete iGc;
1.174 + }
1.175 +
1.176 +void CMcConnectionBase::SubStateChanged()
1.177 + {
1.178 + iWin->Invalidate();
1.179 + iWs.Flush();
1.180 + }
1.181 +
1.182 +void CMcConnectionBase::ConstructL()
1.183 + {
1.184 + CTClient::ConstructL();
1.185 + User::LeaveIfError(iScreen->CreateContext(iGc));
1.186 + }
1.187 +
1.188 +CMcConnection::CMcConnection(TMultiConTest *aTest) : CMcConnectionBase(aTest)
1.189 + {
1.190 + }
1.191 +
1.192 +void CMcConnection::ConstructL()
1.193 + {
1.194 + CMcConnectionBase::ConstructL();
1.195 + iGroup=new(ELeave) CTWindowGroup(this);
1.196 + iGroup->ConstructL();
1.197 + TSize screenSize=iGroup->Size();
1.198 + TInt winWidth=screenSize.iWidth/3;
1.199 + TInt winHeight=screenSize.iHeight/2-10;
1.200 + iGroup->GroupWin()->AutoForeground(EFalse);
1.201 + CMcWindow *win=new(ELeave) CMcWindow(iTest);
1.202 + win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
1.203 + iWin=win;
1.204 + iWs.Flush();
1.205 + }
1.206 +
1.207 +CMcConnectionAf::CMcConnectionAf(TMultiConTest *aTest) : CMcConnectionBase(aTest)
1.208 + {
1.209 + }
1.210 +
1.211 +void CMcConnectionAf::ConstructL()
1.212 + {
1.213 + CMcConnectionBase::ConstructL();
1.214 + iGroup=new(ELeave) CMcWindowGroupAf(this);
1.215 + iGroup->ConstructL();
1.216 + TSize screenSize=iGroup->Size();
1.217 + TInt winWidth=screenSize.iWidth/3;
1.218 + TInt winHeight=screenSize.iHeight/2-10;
1.219 + iGroup->GroupWin()->AutoForeground(ETrue);
1.220 + CMcWindowAf *win=new(ELeave) CMcWindowAf(iTest);
1.221 + win->SetUpL(TPoint(winWidth,5),TSize(winWidth,winHeight),iGroup,*iGc);
1.222 + iWin=win;
1.223 + iWs.Flush();
1.224 + }
1.225 +
1.226 +void CMcConnectionAf::KeyL(const TKeyEvent &aKey)
1.227 + {
1.228 + switch(aKey.iCode)
1.229 + {
1.230 + case ' ':
1.231 + if (iTest->SubState()==0)
1.232 + {
1.233 + iTest->TestL(iGroup->GroupWin()->OrdinalPosition()==0);
1.234 + iTest->IncSubState();
1.235 + }
1.236 + break;
1.237 + case EKeyEscape:
1.238 + iTest->EndAutoForegroundTest();
1.239 + break;
1.240 + }
1.241 + }
1.242 +
1.243 +CMcConnectionDef::CMcConnectionDef(TMultiConTest *aTest) : CMcConnectionBase(aTest)
1.244 + {
1.245 + }
1.246 +
1.247 +void CMcConnectionDef::ConstructL()
1.248 + {
1.249 + CMcConnectionBase::ConstructL();
1.250 + iGroup=new(ELeave) CTWindowGroup(this);
1.251 + iGroup->ConstructL();
1.252 + iGroup->GroupWin()->EnableReceiptOfFocus(EFalse);
1.253 + TSize screenSize=iGroup->Size();
1.254 + TInt winWidth=screenSize.iWidth/3-10;
1.255 + TInt winHeight=(screenSize.iHeight/2)-10;
1.256 + CMcWindowDef *win=new(ELeave) CMcWindowDef(iTest);
1.257 + win->SetUpL(TPoint(5+winWidth/2,screenSize.iHeight/2),TSize(winWidth,winHeight),iGroup,*iGc);
1.258 + iWin=win;
1.259 + iWs.Flush();
1.260 + }
1.261 +
1.262 +//
1.263 +// CMcWindow, base class //
1.264 +//
1.265 +
1.266 +CMcWindowBase::CMcWindowBase(TMultiConTest *aTest) : CTWin(), iTest(aTest)
1.267 + {
1.268 + }
1.269 +
1.270 +void CMcWindowBase::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
1.271 + {
1.272 + ConstructExtLD(*parent,pos,size);
1.273 + iWin.SetBackgroundColor(iBack);
1.274 + Activate();
1.275 + AssignGC(aGc);
1.276 + }
1.277 +
1.278 +//
1.279 +// CMcWindow, window used to test multiple connections //
1.280 +//
1.281 +
1.282 +CMcWindow::CMcWindow(TMultiConTest *aTest) : CMcWindowBase(aTest)
1.283 + {
1.284 + iBack=TRgb::Gray256(221);
1.285 + }
1.286 +
1.287 +void CMcWindow::PointerL(const TPointerEvent &pointer,const TTime &)
1.288 + {
1.289 + if (pointer.iType==TPointerEvent::EButton1Down)
1.290 + {
1.291 + switch(iTest->SubState())
1.292 + {
1.293 + case 1:
1.294 + iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==1);
1.295 + iTest->IncSubState();
1.296 + break;
1.297 + }
1.298 + }
1.299 + }
1.300 +
1.301 +void CMcWindow::Draw()
1.302 + {
1.303 + iGc->Clear();
1.304 + TBuf<0x40> buf;
1.305 + switch(iTest->SubState())
1.306 + {
1.307 + case 1:
1.308 + buf.Copy(_L("Click on me"));
1.309 + break;
1.310 + case 0:
1.311 + case 2:
1.312 + case 3:
1.313 + buf.Copy(_L(""));
1.314 + break;
1.315 + default:
1.316 + buf.Copy(_L("ERROR"));
1.317 + }
1.318 + iGc->DrawText(buf, TPoint(10,20));
1.319 + }
1.320 +
1.321 +//
1.322 +// CMcWindowAf, Auto foreground version of CMcWindow //
1.323 +//
1.324 +
1.325 +CMcWindowAf::CMcWindowAf(TMultiConTest *aTest) : CMcWindowBase(aTest)
1.326 + {
1.327 + iBack=TRgb::Gray256(150);
1.328 + }
1.329 +
1.330 +void CMcWindowAf::PointerL(const TPointerEvent &pointer,const TTime &)
1.331 + {
1.332 + if (pointer.iType==TPointerEvent::EButton1Down)
1.333 + {
1.334 + switch(iTest->SubState())
1.335 + {
1.336 + case 2:
1.337 + iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==0);
1.338 + iTest->IncSubState();
1.339 + break;
1.340 + }
1.341 + }
1.342 + }
1.343 +
1.344 +void CMcWindowAf::Draw()
1.345 + {
1.346 + iGc->Clear();
1.347 + TBuf<0x40> buf;
1.348 + switch(iTest->SubState())
1.349 + {
1.350 + case 1:
1.351 + case 3:
1.352 + break;
1.353 + case 0:
1.354 + buf.Copy(_L("Press <Space>"));
1.355 + break;
1.356 + case 2:
1.357 + buf.Copy(_L("Click on me"));
1.358 + break;
1.359 + default:
1.360 + buf.Copy(_L("ERROR"));
1.361 + }
1.362 + iGc->DrawText(buf, TPoint(10,20));
1.363 + }
1.364 +
1.365 +//
1.366 +
1.367 +CMcWindowGroupAf::CMcWindowGroupAf(CTClient *aClient) : CTWindowGroup(aClient)
1.368 + {}
1.369 +
1.370 +void CMcWindowGroupAf::KeyL(const TKeyEvent &aKey, const TTime &)
1.371 + {
1.372 + ((CMcConnectionAf *)iClient)->KeyL(aKey);
1.373 + }
1.374 +
1.375 +//
1.376 +// CMcWindowDef, Default auto foreground version of CMcWindow //
1.377 +//
1.378 +
1.379 +CMcWindowDef::CMcWindowDef(TMultiConTest *aTest) : CMcWindowBase(aTest)
1.380 + {
1.381 + iBack=TRgb::Gray256(236);
1.382 + }
1.383 +
1.384 +void CMcWindowDef::PointerL(const TPointerEvent &pointer,const TTime &)
1.385 + {
1.386 + if (pointer.iType==TPointerEvent::EButton1Down)
1.387 + {
1.388 + switch(iTest->SubState())
1.389 + {
1.390 + case 3:
1.391 + iTest->TestL(Client()->iGroup->GroupWin()->OrdinalPosition()==0);
1.392 + iTest->IncSubState();
1.393 + break;
1.394 + }
1.395 + }
1.396 + }
1.397 +
1.398 +void CMcWindowDef::Draw()
1.399 + {
1.400 + iGc->Clear();
1.401 + TBuf<0x40> buf;
1.402 + switch(iTest->SubState())
1.403 + {
1.404 + case 0:
1.405 + case 1:
1.406 + case 2:
1.407 + break;
1.408 + case 3:
1.409 + buf.Copy(_L("Click on me"));
1.410 + break;
1.411 + default:
1.412 + buf.Copy(_L("ERROR"));
1.413 + }
1.414 + iGc->DrawText(buf, TPoint(10,20));
1.415 + }
1.416 +
1.417 +//
1.418 +
1.419 +TInt TMultiConTest::SubState() const
1.420 + {
1.421 + return(iSubState);
1.422 + }
1.423 +
1.424 +void TMultiConTest::IncSubState()
1.425 + {
1.426 + if (iSubState==EMaxSubState)
1.427 + EndAutoForegroundTest();
1.428 + else
1.429 + {
1.430 + iSubState++;
1.431 + iConn1->SubStateChanged();
1.432 + iConn2->SubStateChanged();
1.433 + iConn3->SubStateChanged();
1.434 + }
1.435 + }
1.436 +
1.437 +TestState TMultiConTest::DoTestL()
1.438 + {
1.439 + switch(iState)
1.440 + {
1.441 + case 0:
1.442 + LogSubTest(_L("MultiCon 1"),1);
1.443 + iState++;
1.444 + return(EContinue);
1.445 + default:
1.446 + return(EFinished);
1.447 + }
1.448 +// return(ENext);
1.449 + }