1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TSPRITE.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,996 @@
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 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#include "TSPRITE.H"
1.26 +
1.27 +CTTSprite::CTTSprite(CTestStep* aStep):
1.28 + CTWsGraphicsBase(aStep)
1.29 + {
1.30 + INFO_PRINTF1(_L("Testing TSprite functions"));
1.31 + }
1.32 +
1.33 +void CTTSprite::SetUpMember(TSpriteMember &aMember)
1.34 + {
1.35 + aMember.iMaskBitmap=NULL;
1.36 + aMember.iInvertMask=EFalse;
1.37 + aMember.iDrawMode=CGraphicsContext::EDrawModePEN;
1.38 + aMember.iOffset=TPoint();
1.39 + aMember.iInterval=TTimeIntervalMicroSeconds32(0);
1.40 + aMember.iBitmap=&iBitmap;
1.41 + }
1.42 +
1.43 +void CTTSprite::SetUpPointerCursorL(RWsPointerCursor &aCursor, RWsSession &aSession)
1.44 + {
1.45 + aCursor=RWsPointerCursor(aSession);
1.46 + TSpriteMember member;
1.47 + SetUpMember(member);
1.48 + User::LeaveIfError(aCursor.Construct(0));
1.49 + User::LeaveIfError(aCursor.AppendMember(member));
1.50 + User::LeaveIfError(aCursor.Activate());
1.51 + }
1.52 +
1.53 +void CTTSprite::SetUpSpriteL(RWsSprite &aSprite, RWsSession &aSession, RWindowTreeNode &aWindow,TInt aFlags/*=0*/)
1.54 + {
1.55 + aSprite=RWsSprite(aSession);
1.56 + User::LeaveIfError(aSprite.Construct(aWindow,TPoint(),aFlags));
1.57 + TSpriteMember member;
1.58 + SetUpMember(member);
1.59 + User::LeaveIfError(aSprite.AppendMember(member));
1.60 + User::LeaveIfError(aSprite.Activate());
1.61 + }
1.62 +
1.63 +void CTTSprite::ConstructL()
1.64 + {
1.65 + User::LeaveIfError(iBitmap.Load(TEST_BITMAP_NAME,0));
1.66 + }
1.67 +
1.68 +CTTSprite::~CTTSprite()
1.69 + {
1.70 + }
1.71 +
1.72 +/**
1.73 +@SYMTestCaseID GRAPHICS-WSERV-0018
1.74 +
1.75 +@SYMDEF DEF081259
1.76 +
1.77 +@SYMTestCaseDesc General cursor tests involving a sprite
1.78 +
1.79 +@SYMTestPriority High
1.80 +
1.81 +@SYMTestStatus Implemented
1.82 +
1.83 +@SYMTestActions Carries out cursor and window tests before updating
1.84 + a cursor's member with a sprite
1.85 +
1.86 +@SYMTestExpectedResults When the cursor member is update returns KErrArgument
1.87 +*/
1.88 +
1.89 +void CTTSprite::GeneralTestsL()
1.90 + {
1.91 +//
1.92 +// Close cursor while still active on a window
1.93 +//
1.94 +
1.95 + RWindow win(TheClient->iWs);
1.96 + win.Construct(*TheClient->iGroup->GroupWin(),1);
1.97 + win.Activate();
1.98 + SetUpPointerCursorL(iCursor1,TheClient->iWs);
1.99 + win.SetCustomPointerCursor(iCursor1);
1.100 + iCursor1.Close();
1.101 +//
1.102 +// Close window while cursor active on it
1.103 +//
1.104 + SetUpPointerCursorL(iCursor1,TheClient->iWs);
1.105 + win.SetCustomPointerCursor(iCursor1);
1.106 + win.Close();
1.107 + iCursor1.Close();
1.108 +
1.109 +//
1.110 +// Close session with:
1.111 +// An open cursor active on a window & A closed cursor active on another window
1.112 +//
1.113 + RWsSession ws;
1.114 + User::LeaveIfError(ws.Connect());
1.115 + // use correct screen
1.116 + //
1.117 + ws.SetFocusScreen(iTest->iScreenNumber);
1.118 + CWsScreenDevice* screen = new (ELeave) CWsScreenDevice(ws);
1.119 + CleanupStack::PushL(screen);
1.120 + User::LeaveIfError(screen->Construct(0));
1.121 +
1.122 + RWindowGroup group(ws);
1.123 + User::LeaveIfError(group.Construct(123));
1.124 + group.EnableReceiptOfFocus(EFalse); // Stop auto group switching on close
1.125 + RWindow win2(ws);
1.126 + User::LeaveIfError(win2.Construct(group, 1));
1.127 + win2.Activate();
1.128 + RWindow win3(ws);
1.129 + User::LeaveIfError(win3.Construct(group, 2));
1.130 + win3.Activate();
1.131 +//
1.132 + SetUpPointerCursorL(iCursor1,ws);
1.133 + SetUpPointerCursorL(iCursor2,ws);
1.134 + win2.SetCustomPointerCursor(iCursor1);
1.135 + win3.SetCustomPointerCursor(iCursor2);
1.136 +//
1.137 + TSpriteMember member;
1.138 + member.iBitmap=member.iMaskBitmap=NULL;
1.139 + TInt err = iCursor1.UpdateMember(9999,member);
1.140 + TEST(err==KErrArgument);
1.141 + if (err!=KErrArgument)
1.142 + INFO_PRINTF3(_L("iCursor1.UpdateMember(9999,member) return value - Expected: %d, Actual: %d"), KErrArgument, err);
1.143 +
1.144 + iCursor1.Close();
1.145 +
1.146 + CleanupStack::PopAndDestroy(screen);
1.147 + ws.Close();
1.148 + }
1.149 +
1.150 +/**
1.151 +@SYMTestCaseID GRAPHICS-WSERV-0019
1.152 +
1.153 +@SYMDEF DEF081259
1.154 +
1.155 +@SYMTestCaseDesc Construct a sprite in a group window
1.156 +
1.157 +@SYMTestPriority High
1.158 +
1.159 +@SYMTestStatus Implemented
1.160 +
1.161 +@SYMTestActions Creates a sprite in a group window
1.162 +
1.163 +@SYMTestExpectedResults The sprite is created without error
1.164 +*/
1.165 +void CTTSprite::GroupWindowSpritesL()
1.166 + {
1.167 + RWsSprite sprite1;
1.168 + RWsSprite sprite2;
1.169 + SetUpSpriteL(sprite1,TheClient->iWs,*TheClient->iGroup->GroupWin());
1.170 + SetUpSpriteL(sprite2,TheClient->iWs,*TheClient->iGroup->GroupWin());
1.171 + TheClient->iWs.Flush();
1.172 + sprite2.Close();
1.173 + sprite1.Close();
1.174 + }
1.175 +
1.176 +/**
1.177 +@SYMTestCaseID GRAPHICS-WSERV-0020
1.178 +
1.179 +@SYMDEF DEF081259
1.180 +
1.181 +@SYMTestCaseDesc Constructs a number of different sprites in different windows
1.182 +
1.183 +@SYMTestPriority High
1.184 +
1.185 +@SYMTestStatus Implemented
1.186 +
1.187 +@SYMTestActions Creates many sprites in three different windows and the checks
1.188 + the sprites can be manipulated
1.189 +
1.190 +@SYMTestExpectedResults The sprite are created and manipulated without error
1.191 +*/
1.192 +#define NUM_SPRITES 8
1.193 +void CTTSprite::LotsSpritesL()
1.194 + {
1.195 + CTBlankWindow* win=new(ELeave) CTBlankWindow();
1.196 + CTBlankWindow* win2=new(ELeave) CTBlankWindow();
1.197 + TSize size(100,120);
1.198 + win->ConstructL(*TheClient->iGroup);
1.199 + win2->ConstructL(*win);
1.200 + win2->SetExt(TPoint(100,100),size);
1.201 + win2->SetColor(TRgb::Gray4(2));
1.202 + RWindowBase window=*win->BaseWin();
1.203 + RWindowBase window2=*win2->BaseWin();
1.204 + window.Activate();
1.205 + window2.Activate();
1.206 + RWsSprite sprite[NUM_SPRITES];
1.207 + TInt ii;
1.208 + //TheClient->iWs.SetAutoFlush(ETrue);
1.209 + for (ii=0;ii<NUM_SPRITES;ii++)
1.210 + SetUpSpriteL(sprite[ii],TheClient->iWs,window);
1.211 + sprite[4].Close();
1.212 + sprite[2].SetPosition(TPoint(20,20));
1.213 + sprite[0].Close();
1.214 + win2->SetExt(TPoint(80,100),size);
1.215 + sprite[6].SetPosition(TPoint(60,120));
1.216 + sprite[7].Close();
1.217 + sprite[5].SetPosition(TPoint(100,120));
1.218 + sprite[3].Close();
1.219 + SetUpSpriteL(sprite[7],TheClient->iWs,window);
1.220 + sprite[7].SetPosition(TPoint(80,150));
1.221 + sprite[1].Close();
1.222 + win2->SetExt(TPoint(60,110),size);
1.223 + sprite[5].SetPosition(TPoint(50,40));
1.224 + sprite[7].Close();
1.225 + SetUpSpriteL(sprite[0],TheClient->iWs,window);
1.226 + sprite[0].SetPosition(TPoint(55,65));
1.227 + sprite[6].Close();
1.228 + win2->SetExt(TPoint(40,90),size);
1.229 + sprite[2].SetPosition(TPoint(80,45));
1.230 + sprite[5].Close();
1.231 + sprite[0].SetPosition(TPoint(90,60));
1.232 + sprite[2].Close();
1.233 + SetUpSpriteL(sprite[2],TheClient->iWs,window);
1.234 + sprite[2].SetPosition(TPoint(70,80));
1.235 + sprite[0].Close();
1.236 + win2->SetExt(TPoint(20,80),size);
1.237 + sprite[2].SetPosition(TPoint(600,200));
1.238 + sprite[2].Close();
1.239 + SetUpSpriteL(sprite[0],TheClient->iWs,window2,ESpriteFlash);
1.240 + sprite[0].SetPosition(TPoint(0,25));
1.241 + SetUpSpriteL(sprite[1],TheClient->iWs,window2,ESpriteFlash);
1.242 + SetUpSpriteL(sprite[2],TheClient->iWs,window2,ESpriteFlash);
1.243 + sprite[2].SetPosition(TPoint(25,0));
1.244 + win2->SetExt(TPoint(40,70),size);
1.245 + CTBlankWindow* win3=new(ELeave) CTBlankWindow();
1.246 + win3->ConstructL(*TheClient->iGroup);
1.247 + win3->SetExt(TPoint(30,60),TSize(30,30));
1.248 + win3->SetColor(TRgb::Gray4(1));
1.249 + win3->BaseWin()->SetShadowHeight(10);
1.250 + win3->BaseWin()->Activate();
1.251 + User::After(1000000); //1 sec so sprites has time to flash
1.252 + delete win2;
1.253 + delete win;
1.254 + delete win3;
1.255 + sprite[0].Close();
1.256 + sprite[1].Close();
1.257 + sprite[2].Close();
1.258 + }
1.259 +
1.260 +/**
1.261 +@SYMTestCaseID GRAPHICS-WSERV-0021
1.262 +
1.263 +@SYMDEF DEF081259
1.264 +
1.265 +@SYMTestCaseDesc General PointerCursor Tests
1.266 +
1.267 +@SYMTestPriority High
1.268 +
1.269 +@SYMTestStatus Implemented
1.270 +
1.271 +@SYMTestActions Exercise the different pointercursor methods of a Window Server Session
1.272 +
1.273 +@SYMTestExpectedResults The methods are called without error
1.274 +*/
1.275 +void CTTSprite::GeneralPointerCursor()
1.276 + {
1.277 + if (!TestBase()->ConfigurationSupportsPointerEventTesting())
1.278 + {
1.279 + INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
1.280 + return;
1.281 + }
1.282 + TInt currentSMode=TheClient->iScreen->CurrentScreenMode();
1.283 + TInt altSMode=-1;
1.284 + if (TheClient->iScreen->NumScreenModes()>1)
1.285 + altSMode=(currentSMode==1?0:1);
1.286 + RWsSession &ws=TheClient->iWs;
1.287 + TRect rect=ws.PointerCursorArea();
1.288 + TRect testRect1(TPoint(rect.iBr.iX/4,rect.iBr.iY/4),TSize(rect.Width()/2,rect.Height()/2));
1.289 + TRect testRect2(TPoint(rect.iBr.iX/3,rect.iBr.iY/3),TSize(2*rect.Width()/3,2*rect.Height()/3));
1.290 + ws.SetPointerCursorArea(testRect1);
1.291 + TEST(ws.PointerCursorArea()==testRect1);
1.292 + TEST(ws.PointerCursorArea(currentSMode)==testRect1);
1.293 + ws.SetPointerCursorArea(currentSMode,testRect2);
1.294 + TEST(ws.PointerCursorArea()==testRect2);
1.295 + TEST(ws.PointerCursorArea(currentSMode)==testRect2);
1.296 + ws.SetPointerCursorArea(rect);
1.297 + TEST(ws.PointerCursorArea()==rect);
1.298 +
1.299 + if (altSMode>=0)
1.300 + {
1.301 + rect=ws.PointerCursorArea(altSMode);
1.302 + testRect1.iTl.iX=rect.iBr.iX/4;
1.303 + testRect1.iTl.iY=rect.iBr.iY/4;
1.304 + testRect1.SetWidth(rect.Width()/2);
1.305 + testRect1.SetHeight(rect.Height()/2);
1.306 + ws.SetPointerCursorArea(altSMode,testRect1);
1.307 + TEST(ws.PointerCursorArea(altSMode)==testRect1);
1.308 + ws.SetPointerCursorArea(altSMode,rect);
1.309 + TEST(ws.PointerCursorArea(altSMode)==rect);
1.310 + }
1.311 + TPointerCursorMode currentMode=ws.PointerCursorMode();
1.312 + TInt ii;
1.313 + TInt err1;
1.314 + for(ii=EPointerCursorFirstMode;ii<=EPointerCursorLastMode;ii++)
1.315 + {
1.316 + ws.SetPointerCursorMode(STATIC_CAST(TPointerCursorMode,ii));
1.317 + err1 = ws.PointerCursorMode();
1.318 + TEST(ii==err1);
1.319 + if (ii!=err1)
1.320 + INFO_PRINTF3(_L("ws.PointerCursorMode() return value - Expected: %d, Actual: %d"), ii, err1);
1.321 + }
1.322 + ws.SetPointerCursorMode(currentMode);
1.323 + TEST(currentMode==ws.PointerCursorMode());
1.324 + TPoint point1(10,12);
1.325 + TPoint point2(24,20);
1.326 + ws.PointerCursorPosition();
1.327 + ws.SetPointerCursorPosition(point1);
1.328 + TEST(ws.PointerCursorPosition()==point1);
1.329 + ws.SetPointerCursorPosition(point2);
1.330 + TEST(ws.PointerCursorPosition()==point2);
1.331 + }
1.332 +
1.333 +
1.334 +/**
1.335 +@SYMTestCaseID GRAPHICS-WSERV-0498
1.336 +
1.337 +@SYMDEF PDEF137614 - Propagation to TB92
1.338 +
1.339 +@SYMTestCaseDesc Test activating a pointer cursor
1.340 +
1.341 +@SYMTestPriority High
1.342 +
1.343 +@SYMTestStatus Implemented
1.344 +
1.345 +@SYMTestActions Construct and activate a pointer cursor.
1.346 + Check it is visible.
1.347 + Deactivate it
1.348 + Check it is removed
1.349 +
1.350 +
1.351 +@SYMTestExpectedResults
1.352 + The pointer cursor bitmp should be visible when activated and removed when deactivated.
1.353 +*/
1.354 +
1.355 +void CTTSprite::PointerCursorVisibleL()
1.356 + {
1.357 + if (!TestBase()->ConfigurationSupportsPointerEventTesting())
1.358 + {
1.359 + INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
1.360 + return;
1.361 + }
1.362 +
1.363 + // The pointer events need time to have an affect on the wserv
1.364 + static const TInt eventPropagationDelay = 100 * 1000; // 100 ms
1.365 +
1.366 + TInt screenNumber = TheClient->iScreen->GetScreenNumber();
1.367 +
1.368 + if(screenNumber != 0) // pointer events only supported on emulator screen 0
1.369 + {
1.370 + LOG_MESSAGE(_L("Pointer Cursor Visible only runs on screen 0"));
1.371 + return;
1.372 + }
1.373 +
1.374 + // set up objects used in test
1.375 + // 50x50 red rectangle colour 24
1.376 + CFbsBitmap bitmap;
1.377 + User::LeaveIfError(bitmap.Load(TEST_BITMAP_NAME, 8));
1.378 +
1.379 + TSize bmSize = bitmap.SizeInPixels();
1.380 + TPoint bmSample = TPoint(bmSize.iWidth / 2, bmSize.iHeight / 2);
1.381 + TRgb bmColour;
1.382 + bitmap.GetPixel(bmColour, bmSample);
1.383 + TEST(bmColour == KRgbRed);
1.384 +
1.385 + // single window, size of screen
1.386 + RWindow win(TheClient->iWs);
1.387 + User::LeaveIfError(win.Construct(*TheClient->iGroup->GroupWin(),1));
1.388 + win.Activate();
1.389 +
1.390 + // setup cursor mode
1.391 + TheClient->iWs.SetPointerCursorMode(EPointerCursorWindow);
1.392 +
1.393 + // setup cursor to contain single 50x50 red bitmap
1.394 + RWsPointerCursor iCursor1 = RWsPointerCursor(TheClient->iWs);
1.395 + TSpriteMember member;
1.396 + SetUpMember(member);
1.397 + member.iBitmap=&bitmap;
1.398 + User::LeaveIfError(iCursor1.Construct(0));
1.399 + User::LeaveIfError(iCursor1.AppendMember(member));
1.400 + User::LeaveIfError(iCursor1.Activate());
1.401 + win.SetCustomPointerCursor(iCursor1);
1.402 + iCursor1.UpdateMember(0);
1.403 +
1.404 + // draw a green rect, size of screen as defined background and wait till it is rendered
1.405 + win.BeginRedraw();
1.406 + TheGc->Activate(win);
1.407 + TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1.408 + TheGc->SetBrushColor(KRgbGreen);
1.409 + TSize wSize = win.Size();
1.410 + TheGc->DrawRect(TRect(TPoint(0,0), wSize));
1.411 + TheGc->Deactivate();
1.412 + win.EndRedraw();
1.413 + TheClient->iWs.Finish();
1.414 +
1.415 + // #### do test ####
1.416 + // define locations of simulated pointer events and sample positions of where we expect to see the cursor
1.417 + // The cursor will be moved and a check will be made to see if this has actually happened
1.418 +
1.419 + TPoint pos1(wSize.iWidth / 2, wSize.iHeight / 2); // top left of cursor at centre screen
1.420 + TPoint sample1(pos1 + bmSample); // centre of sprite at pos1
1.421 + TPoint pos2 = pos1 - bmSize; // bottom right of cursor at centre screen
1.422 + TPoint sample2 = pos2 + bmSample; // centre of sprite at pos2
1.423 +
1.424 + TRgb pixel;
1.425 +
1.426 + // check initial state of screen at both sample positions
1.427 + TheClient->iScreen->GetPixel(pixel, sample1);
1.428 + TEST(pixel == KRgbGreen);
1.429 +
1.430 + TheClient->iScreen->GetPixel(pixel, sample2);
1.431 + TEST(pixel == KRgbGreen);
1.432 +
1.433 + TRawEvent e; // to simulate pointer events
1.434 +
1.435 + // simulate button 1 down event at pos1
1.436 + e.Set(TRawEvent::EButton1Down, pos1.iX, pos1.iY);
1.437 + e.SetDeviceNumber(screenNumber);
1.438 + UserSvr::AddEvent(e);
1.439 +
1.440 + User::After(eventPropagationDelay);
1.441 +
1.442 + // check red cursor visible on top of background
1.443 + TheClient->iScreen->GetPixel(pixel, sample1);
1.444 + TEST(pixel == KRgbRed);
1.445 +
1.446 + // simulate button 1 up event
1.447 + e.Set(TRawEvent::EButton1Up, pos1.iX, pos1.iY);
1.448 + UserSvr::AddEvent(e);
1.449 + User::After(eventPropagationDelay);
1.450 +
1.451 + // Move cursor away to pos2
1.452 + e.Set(TRawEvent::EButton1Down, pos2.iX, pos2.iY);
1.453 + e.SetDeviceNumber(screenNumber);
1.454 + UserSvr::AddEvent(e);
1.455 +
1.456 + User::After(eventPropagationDelay);
1.457 +
1.458 + // check cursor has left this position ...
1.459 + TheClient->iScreen->GetPixel(pixel, sample1);
1.460 + TEST(pixel == KRgbGreen);
1.461 + // and arrived at the correct place
1.462 + TheClient->iScreen->GetPixel(pixel, sample2);
1.463 + TEST(pixel == KRgbRed);
1.464 +
1.465 + // simulate button 1 up event
1.466 + e.Set(TRawEvent::EButton1Up, pos2.iX, pos2.iY);
1.467 + UserSvr::AddEvent(e);
1.468 + User::After(eventPropagationDelay);
1.469 +
1.470 + // remove the cursor
1.471 + win.ClearPointerCursor();
1.472 + User::After(eventPropagationDelay);
1.473 +
1.474 + // check it has gone
1.475 + TheClient->iScreen->GetPixel(pixel, sample2);
1.476 + TEST(pixel == KRgbGreen);
1.477 +
1.478 + // #### clean up ####
1.479 + iCursor1.Close();
1.480 + win.Close();
1.481 + }
1.482 +
1.483 +
1.484 +/**
1.485 + @SYMTestCaseID GRAPHICS-CODEBASE-WSERV-0053-0001
1.486 +
1.487 + @SYMPREQ PGM027
1.488 +
1.489 + @SYMTestCaseDesc Tests RWsPointerCursor::UpdateMember APIs.
1.490 +
1.491 + @SYMTestPriority 1
1.492 +
1.493 + @SYMTestStatus Implemented
1.494 +
1.495 + @SYMTestActions This test calls RWsPointerCursor::UpdateMember
1.496 +
1.497 + @SYMTestExpectedResults Should run properly with out any Panics.
1.498 +
1.499 + */
1.500 +void CTTSprite::SpriteUpdateMemberTestsL()
1.501 + {
1.502 + RWsPointerCursor iCursor1;
1.503 +
1.504 + CFbsBitmap bitmap;
1.505 + bitmap.Load(TEST_BITMAP_NAME,0);
1.506 +
1.507 + RWindow win(TheClient->iWs);
1.508 + win.Construct(*TheClient->iGroup->GroupWin(),1);
1.509 + win.Activate();
1.510 +
1.511 + iCursor1=RWsPointerCursor(TheClient->iWs);
1.512 + TSpriteMember member;
1.513 + SetUpMember(member);
1.514 + member.iBitmap=&bitmap;
1.515 + User::LeaveIfError(iCursor1.Construct(0));
1.516 + User::LeaveIfError(iCursor1.AppendMember(member));
1.517 + User::LeaveIfError(iCursor1.Activate());
1.518 + win.SetCustomPointerCursor(iCursor1);
1.519 + iCursor1.UpdateMember(0);
1.520 +
1.521 + RWsPointerCursor iCursor2;
1.522 + bitmap.Load(TEST_NEW_BITMAP_NAME,0);
1.523 + iCursor2=RWsPointerCursor(TheClient->iWs);
1.524 + User::LeaveIfError(iCursor2.Construct(0));
1.525 + User::LeaveIfError(iCursor2.AppendMember(member));
1.526 + User::LeaveIfError(iCursor2.Activate());
1.527 + win.SetCustomPointerCursor(iCursor2);
1.528 + iCursor2.UpdateMember(1);
1.529 +
1.530 + iCursor1.Close();
1.531 + iCursor2.Close();
1.532 + win.Close();
1.533 + }
1.534 +
1.535 +/**
1.536 + @SYMTestCaseID GRAPHICS-CODEBASE-WSERV-0054-0001
1.537 +
1.538 + @SYMPREQ PGM027
1.539 +
1.540 + @SYMTestCaseDesc Negative Tests RWsSpriteBase::UpdateMember API.
1.541 +
1.542 + @SYMTestPriority 1
1.543 +
1.544 + @SYMTestStatus Implemented
1.545 +
1.546 + @SYMTestActions This test calls RWsPointerCursor::UpdateMember
1.547 +
1.548 + @SYMTestExpectedResults Should run properly with out any Panics.
1.549 +
1.550 + */
1.551 +void CTTSprite::SpriteUpdateMemberNegTestsL()
1.552 + {
1.553 + RWsPointerCursor iCursor1;
1.554 +
1.555 + CFbsBitmap bitmap;
1.556 + bitmap.Load(TEST_BITMAP_NAME,0);
1.557 +
1.558 + RWindow win(TheClient->iWs);
1.559 + win.Construct(*TheClient->iGroup->GroupWin(),1);
1.560 + win.Activate();
1.561 +
1.562 + iCursor1=RWsPointerCursor(TheClient->iWs);
1.563 + TSpriteMember member;
1.564 + SetUpMember(member);
1.565 + member.iBitmap=&bitmap;
1.566 + User::LeaveIfError(iCursor1.Construct(0));
1.567 + User::LeaveIfError(iCursor1.AppendMember(member));
1.568 + User::LeaveIfError(iCursor1.Activate());
1.569 + win.SetCustomPointerCursor(iCursor1);
1.570 + iCursor1.UpdateMember(-100);
1.571 +
1.572 + RWsPointerCursor iCursor2;
1.573 + bitmap.Load(TEST_NEW_BITMAP_NAME,0);
1.574 + iCursor2=RWsPointerCursor(TheClient->iWs);
1.575 + User::LeaveIfError(iCursor2.Construct(0));
1.576 + User::LeaveIfError(iCursor2.AppendMember(member));
1.577 + User::LeaveIfError(iCursor2.Activate());
1.578 + win.SetCustomPointerCursor(iCursor2);
1.579 + iCursor2.UpdateMember(10000);
1.580 +
1.581 + iCursor1.Close();
1.582 + iCursor2.Close();
1.583 + win.Close();
1.584 + }
1.585 +
1.586 +/**
1.587 + @SYMTestCaseID GRAPHICS-CODEBASE-WSERV-0055-0001
1.588 +
1.589 + @SYMPREQ PGM027
1.590 +
1.591 + @SYMTestCaseDesc Tests FindWindowGroupIdentifier API.
1.592 +
1.593 + @SYMTestPriority 1
1.594 +
1.595 + @SYMTestStatus Implemented
1.596 +
1.597 + @SYMTestActions Create windows session and call FindWindowGroupIdentifier \n
1.598 + with different thread Id's both with valid thread ids and in valid thread id's.
1.599 +
1.600 + @SYMTestExpectedResults Should run properly.
1.601 +
1.602 + */
1.603 +void CTTSprite::FindWindowGroupThreadTestsL()
1.604 + {
1.605 + RThread proc;
1.606 + TInt ident;
1.607 + TUint64 id=proc.Id();
1.608 + RWsSession ws1;
1.609 + User::LeaveIfError(ws1.Connect());
1.610 + CleanupClosePushL(ws1);
1.611 + //Positive test for FindWindowGroupIdentifier
1.612 + ident=ws1.FindWindowGroupIdentifier(0,id);
1.613 + TEST(ws1.SetWindowGroupOrdinalPosition(ident,0)==KErrNone);
1.614 + TEST(ws1.SetWindowGroupOrdinalPosition(ident,1)==KErrNone);
1.615 + //Negative test for FindWindowGroupIdentifier
1.616 + TInt ret=ws1.FindWindowGroupIdentifier(0,id+200);
1.617 + TEST(ret==KErrNotFound);
1.618 + #if defined __WINS__ || defined __WINSCW__
1.619 + ret=ws1.FindWindowGroupIdentifier(0,-200);
1.620 + TEST(ret==KErrNotFound);
1.621 + #endif//defined __WINS__ || defined __WINSCW__
1.622 + CleanupStack::PopAndDestroy(1, &ws1);
1.623 + ws1.Close();
1.624 + }
1.625 +
1.626 +/**
1.627 +@SYMTestCaseID GRAPHICS-WSERV-0462
1.628 +
1.629 +@SYMDEF PDEF114190
1.630 +
1.631 +@SYMTestCaseDesc Test sprite list cleanup when a window is deleted in low memory conditions
1.632 +
1.633 +@SYMTestPriority High
1.634 +
1.635 +@SYMTestStatus Implemented
1.636 +
1.637 +@SYMTestActions Have a loop which increases the number of allocations in the server thread before failure;
1.638 + Within the loop:
1.639 + 1) Create a parent window and a child window of the parent;
1.640 + 2) Create a sprite on the child window;
1.641 + 3) Delete the parent window only, but not the child window;
1.642 + 4) Create a testWindow and do redraw on this window;
1.643 + 5) Do redraw on the testWindow. This testWindow's redraw will force checking the sprite list.
1.644 + This would panic the client thread due to this defect because the sprite on the orphaned
1.645 + window (which is the previous child window) is still in the sprite list;
1.646 + 6) Delete all the windows involved.
1.647 +
1.648 +@SYMTestExpectedResults The sprite should be disabled when a window is deleted;
1.649 + The client thread should not be panic'd.
1.650 + The test should pass.
1.651 +*/
1.652 +void CTTSprite::SpriteOnWindowOrphanedTestsL()
1.653 + {
1.654 + TInt handles = 344;
1.655 + TInt loop = 0;
1.656 + TInt allocFailRate = 0;
1.657 + TInt err = KErrNone;
1.658 +
1.659 + CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
1.660 + CleanupStack::PushL(bitmap);
1.661 + User::LeaveIfError(bitmap->Create(TSize(500, 500), EColor16MU));
1.662 + TSpriteMember spritemember;
1.663 + spritemember.iBitmap = bitmap;
1.664 + spritemember.iMaskBitmap = NULL;
1.665 +
1.666 + RWindowGroup group(TheClient->iWs);
1.667 + RWindow parent1(TheClient->iWs);
1.668 + RWindow child1(TheClient->iWs);
1.669 + RWindow testWindow(TheClient->iWs);
1.670 + RWsSprite sprite(TheClient->iWs);
1.671 +
1.672 + while (loop < 5)
1.673 + {
1.674 + TRect mainRect(TPoint(0,0), TSize(500,500));
1.675 + err = group.Construct(++handles, EFalse);
1.676 + if (err == KErrNone)
1.677 + {
1.678 + TheClient->iWs.HeapSetFail(RHeap::EDeterministic, allocFailRate);
1.679 +
1.680 + //Create parent 1
1.681 + err = parent1.Construct(group,++handles);
1.682 + if (err == KErrNone)
1.683 + {
1.684 + parent1.SetExtent(mainRect.iTl, mainRect.Size());
1.685 + parent1.EnableRedrawStore(ETrue);
1.686 + parent1.Activate();
1.687 + }
1.688 + }
1.689 +
1.690 + //Create child 1
1.691 + if (err == KErrNone)
1.692 + {
1.693 + TRect childRect(TPoint (10, 10), TSize (200, 150));
1.694 + err = child1.Construct(parent1,++handles);
1.695 + if (err == KErrNone)
1.696 + {
1.697 + child1.SetExtent(childRect.iTl, childRect.Size());
1.698 + child1.SetBackgroundColor(TRgb(128,100,255,20));
1.699 + child1.Activate();
1.700 + }
1.701 + }
1.702 +
1.703 + //Add sprite to child 1
1.704 + if (err == KErrNone)
1.705 + {
1.706 + err = sprite.Construct(child1,TPoint(10,10), 0);
1.707 + if (err == KErrNone)
1.708 + {
1.709 + err = sprite.AppendMember(spritemember);
1.710 + if (err == KErrNone)
1.711 + err = sprite.Activate();
1.712 + }
1.713 + }
1.714 +
1.715 + //Only delete parent 1, but not child 1
1.716 + parent1.Close();
1.717 +
1.718 + if (err == KErrNone)
1.719 + {
1.720 + TRect testRect(TPoint(10, 30), TSize(200, 150));
1.721 + //Create testWindow
1.722 + err = testWindow.Construct(group,++handles);
1.723 + if (err == KErrNone)
1.724 + {
1.725 + testWindow.SetExtent(testRect.iTl, testRect.Size());
1.726 + testWindow.SetBackgroundColor(TRgb(128,100,255,20));
1.727 + testWindow.EnableRedrawStore(ETrue);
1.728 + testWindow.Activate();
1.729 + testWindow.BeginRedraw();
1.730 + testWindow.EndRedraw();
1.731 + TheClient->Flush();
1.732 + }
1.733 + }
1.734 + TheClient->iWs.HeapSetFail(RAllocator::ENone, 0);
1.735 +
1.736 + sprite.Close();
1.737 + child1.Close();
1.738 + testWindow.Close();
1.739 + group.Close();
1.740 + ++allocFailRate;
1.741 + loop = (err == KErrNone) ? loop + 1 : 0;
1.742 + }
1.743 + CleanupStack::PopAndDestroy(bitmap);
1.744 + }
1.745 +void CTTSprite::ResizeMemberL()
1.746 + {
1.747 +#ifndef __WINS__
1.748 + CTBlankWindow* win=new(ELeave) CTBlankWindow();
1.749 + CleanupStack::PushL(win);
1.750 + win->ConstructL(*TheClient->iGroup);
1.751 + win->SetExt(TPoint(),TSize(640,240));
1.752 + RWindowBase& window=*win->BaseWin();
1.753 + window.Activate();
1.754 + RWsSprite sprite(TheClient->iWs);
1.755 + CleanupClosePushL(sprite);
1.756 + User::LeaveIfError(sprite.Construct(window,TPoint(),0));
1.757 + TSpriteMember member;
1.758 + member.iMaskBitmap=NULL;
1.759 + member.iInvertMask=EFalse;
1.760 + member.iDrawMode=CGraphicsContext::EDrawModePEN;
1.761 + member.iOffset=TPoint();
1.762 + member.iInterval=TTimeIntervalMicroSeconds32(250000);
1.763 + member.iBitmap=&iBitmap;
1.764 + User::LeaveIfError(sprite.AppendMember(member));
1.765 + User::LeaveIfError(sprite.AppendMember(member));
1.766 + User::LeaveIfError(sprite.Activate());
1.767 + User::After(1000000); // // Interval is 1 sec.
1.768 + User::LeaveIfError(iBitmap.Resize(iBitmap.SizeInPixels() + TSize(100,100)));
1.769 + User::After(1000000); // Interval is 1 sec.
1.770 + CleanupStack::PopAndDestroy(&sprite);
1.771 + CleanupStack::PopAndDestroy(win);
1.772 +#endif // __WINS__
1.773 + }
1.774 +
1.775 +
1.776 +void CTTSprite::SetUpSpriteL(RWsSprite &aSprite, RWindowTreeNode &aWindow,TPoint aPoint, TSpriteMember aMember, TInt aFlags/*=0*/)
1.777 + {
1.778 + User::LeaveIfError(aSprite.Construct(aWindow,aPoint,aFlags));
1.779 + User::LeaveIfError(aSprite.AppendMember(aMember));
1.780 + User::LeaveIfError(aSprite.Activate());
1.781 + }
1.782 +/**
1.783 +@SYMTestCaseID GRAPHICS-WSERV-00-0001
1.784 +
1.785 +@SYMDEF PDEF117721
1.786 +
1.787 +@SYMTestCaseDesc Test Screenrotation does not cause panic by sprite with NULL bitmap and NULL maskbitmap
1.788 +
1.789 +@SYMTestPriority High
1.790 +
1.791 +@SYMTestStatus Implemented
1.792 +
1.793 +@SYMTestActions Defines two sprites and one with Null iBitmap and Null iMaskBitmap, then rotate the screen to 90 degrees
1.794 +
1.795 +@SYMTestExpectedResults the screen rotation will not cause wserv a panic
1.796 +*/
1.797 +void CTTSprite::RotateNullSpriteL()
1.798 + {
1.799 + if (TheClient->iScreen->NumScreenModes() < 2)
1.800 + {
1.801 + LOG_MESSAGE(_L("WARNING: Unable to rotate screen"));
1.802 + return;
1.803 + }
1.804 +// Sprite Members
1.805 + TSpriteMember spriteMember1,spriteMember2;
1.806 + SetUpMember(spriteMember1);
1.807 + SetUpMember(spriteMember2);
1.808 + spriteMember2.iBitmap = NULL;
1.809 +
1.810 +// Create windows
1.811 + RWindowGroup group(TheClient->iWs);
1.812 + User::LeaveIfError(group.Construct(ENullWsHandle,EFalse)); //Creates a Group Window
1.813 + CleanupClosePushL(group);
1.814 + RBlankWindow win(TheClient->iWs);
1.815 + User::LeaveIfError(win.Construct(group,ENullWsHandle)); //Creates a Blank Window
1.816 + CleanupClosePushL(win);
1.817 + win.SetVisible(ETrue);
1.818 + win.SetColor(TRgb::Gray4(2));
1.819 + win.Activate();
1.820 + TheClient->Flush();
1.821 +
1.822 +// Create Sprites
1.823 + RWsSprite sprite1(TheClient->iWs);
1.824 + CleanupClosePushL(sprite1);
1.825 + SetUpSpriteL(sprite1, win,TPoint(20,70),spriteMember1,0);
1.826 + RWsSprite sprite2(TheClient->iWs);
1.827 + CleanupClosePushL(sprite2);
1.828 + SetUpSpriteL(sprite2, win,TPoint(80,130),spriteMember2,0);
1.829 + RWsSprite sprite3(TheClient->iWs);
1.830 + CleanupClosePushL(sprite3);
1.831 + SetUpSpriteL(sprite3, win,TPoint(2800,2130),spriteMember1,0);
1.832 + TheClient->Flush();
1.833 +
1.834 +// Get the original screen mode
1.835 + CWsScreenDevice* device = TheClient->iScreen;
1.836 + TInt originalScreenMode = device->CurrentScreenMode();
1.837 + TPixelsTwipsAndRotation originalModeSettings;
1.838 + device->GetScreenModeSizeAndRotation(originalScreenMode,originalModeSettings);
1.839 +
1.840 +// Rotate screens
1.841 + TPixelsAndRotation pixelsAndRotation;
1.842 + device->SetScreenMode( 1 );
1.843 + device->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
1.844 + device->SetCurrentRotations(1,pixelsAndRotation.iRotation);
1.845 + device->SetScreenSizeAndRotation(pixelsAndRotation);
1.846 + User::After(1000000);
1.847 +
1.848 + CleanupStack::PopAndDestroy(5,&group);
1.849 +// Restore the original screen mode
1.850 + device->SetScreenMode(originalScreenMode);
1.851 + device->SetCurrentRotations(originalScreenMode,originalModeSettings.iRotation);
1.852 + device->SetScreenSizeAndRotation(originalModeSettings);
1.853 + TheClient->Flush();
1.854 + }
1.855 +
1.856 +/**
1.857 +@SYMTestCaseID GRAPHICS-WSERV-GCE-0700
1.858 +
1.859 +@SYMDEF DEF123129
1.860 +
1.861 +@SYMTestCaseDesc Test activating a sprite twice does not cause the system to hang
1.862 +
1.863 +@SYMTestPriority High
1.864 +
1.865 +@SYMTestStatus Implemented
1.866 +
1.867 +@SYMTestActions Construct a sprite and add a member to it. Activate twice.
1.868 +
1.869 +@SYMTestExpectedResults The test should terminate smoothly and it should not hang the system.
1.870 +*/
1.871 +void CTTSprite::DoubleActivateL()
1.872 + {
1.873 + RWsSession ws;
1.874 + User::LeaveIfError(ws.Connect());
1.875 + CleanupClosePushL(ws);
1.876 +
1.877 + RWindowGroup group(ws);
1.878 + User::LeaveIfError(group.Construct(890, EFalse));
1.879 + CleanupClosePushL(group);
1.880 +
1.881 + RWsSprite sprite = RWsSprite(ws);
1.882 + User::LeaveIfError(sprite.Construct(group,TPoint(),0));
1.883 + CleanupClosePushL(sprite);
1.884 + CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
1.885 + CleanupStack::PushL(bitmap);
1.886 + User::LeaveIfError(bitmap->Create(TSize(10,12),EColor256));
1.887 + TSpriteMember member;
1.888 + member.iMaskBitmap=NULL;
1.889 + member.iInvertMask=EFalse;
1.890 + member.iDrawMode=CGraphicsContext::EDrawModePEN;
1.891 + member.iOffset=TPoint();
1.892 + member.iInterval=TTimeIntervalMicroSeconds32(0);
1.893 + member.iBitmap=bitmap;
1.894 + User::LeaveIfError(sprite.AppendMember(member));
1.895 + User::LeaveIfError(sprite.Activate());
1.896 + User::LeaveIfError(sprite.Activate());
1.897 +
1.898 + sprite.Close();
1.899 + CleanupStack::PopAndDestroy(4, &ws);
1.900 +
1.901 + group.Close();
1.902 + ws.Close();
1.903 + }
1.904 +
1.905 +void CTTSprite::RunTestCaseL(TInt /*aCurTestCase*/)
1.906 + {
1.907 + _LIT(KTest1, "General Tests");
1.908 + _LIT(KTest2, "Group Window Sprites Tests");
1.909 + _LIT(KTest3, "Lots Sprites Tests");
1.910 + _LIT(KTest4, "General Pointer Cursor Tests");
1.911 + _LIT(KTest5, "Pointer Cursor Visible Tests");
1.912 + _LIT(KTest6, "Update member tests");
1.913 + _LIT(KTest7, "Negative tests for Update member");
1.914 + _LIT(KTest8, "Window Group with Thread");
1.915 + _LIT(KTest9, "Resize Sprite Member Tests");
1.916 + _LIT(KTest10, "Rotate a NULL sprite");
1.917 + _LIT(KTest11, "Sprite On Window Orphaned Tests");
1.918 + _LIT(KTest12, "Sprite Double Activation Test");
1.919 +
1.920 + ((CTTSpriteStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.921 + switch(++iTest->iState)
1.922 + {
1.923 + case 1:
1.924 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0018"));
1.925 + TheClient->iWs.SetFocusScreen(0);
1.926 + iTest->LogSubTest(KTest1);
1.927 + GeneralTestsL();
1.928 + break;
1.929 + case 2:
1.930 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0019"));
1.931 + iTest->LogSubTest(KTest2);
1.932 + GroupWindowSpritesL();
1.933 + break;
1.934 + case 3:
1.935 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0020"));
1.936 + iTest->LogSubTest(KTest3);
1.937 + LotsSpritesL();
1.938 + break;
1.939 + case 4:
1.940 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0021"));
1.941 + iTest->LogSubTest(KTest4);
1.942 + GeneralPointerCursor();
1.943 + break;
1.944 + case 5:
1.945 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0498"));
1.946 + iTest->LogSubTest(KTest5);
1.947 + TRAPD(err, PointerCursorVisibleL());
1.948 + TEST(err == KErrNone);
1.949 + break;
1.950 + case 6:
1.951 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-CODEBASE-WSERV-0053-0001"));
1.952 + iTest->LogSubTest(KTest6);
1.953 + TRAP(err, SpriteUpdateMemberTestsL());
1.954 + TEST(err == KErrNone);
1.955 + break;
1.956 + case 7:
1.957 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-CODEBASE-WSERV-0054-0001"));
1.958 + iTest->LogSubTest(KTest7);
1.959 + TRAP(err, SpriteUpdateMemberNegTestsL());
1.960 + TEST(err == KErrNone);
1.961 + break;
1.962 + case 8:
1.963 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-CODEBASE-WSERV-0055-0001"));
1.964 + iTest->LogSubTest(KTest8);
1.965 + TRAP(err, FindWindowGroupThreadTestsL());
1.966 + TEST(err == KErrNone);
1.967 + break;
1.968 + case 9:
1.969 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0526"));
1.970 + iTest->LogSubTest(KTest9);
1.971 + ResizeMemberL();
1.972 + break;
1.973 + case 10:
1.974 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-00-0001"));
1.975 + iTest->LogSubTest(KTest10);
1.976 + RotateNullSpriteL();
1.977 + break;
1.978 + case 11:
1.979 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0462"));
1.980 + iTest->LogSubTest(KTest11);
1.981 + SpriteOnWindowOrphanedTestsL();
1.982 + break;
1.983 + case 12:
1.984 + ((CTTSpriteStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-GCE-0700"));
1.985 + iTest->LogSubTest(KTest12);
1.986 + DoubleActivateL();
1.987 + break;
1.988 + default:
1.989 + ((CTTSpriteStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.990 + ((CTTSpriteStep*)iStep)->CloseTMSGraphicsStep();
1.991 + TestComplete();
1.992 + break;
1.993 + }
1.994 + ((CTTSpriteStep*)iStep)->RecordTestResultL();
1.995 + }
1.996 +
1.997 +//--------------
1.998 +__WS_CONSTRUCT_STEP__(TSprite)
1.999 +