windowing/windowserver/tauto/TOOM.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Out of memory tests
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 
       
    25 #include "TOOM.H"
       
    26 
       
    27  
       
    28 typedef COomFailBase *(*COmmCreate)(CTOom *aTest);
       
    29 
       
    30 COomFailBase *CreateOomConnect(CTOom *aTest)
       
    31 	{return(new(ELeave) COomConnect(aTest));}
       
    32 
       
    33 COomFailBase *CreateOomWindow(CTOom *aTest)
       
    34 	{return(new(ELeave) COomWindow(aTest));}
       
    35 
       
    36 COomFailBase *CreateOomWindowGroup(CTOom *aTest)
       
    37 	{return(new(ELeave) COomWindowGroup(aTest));}
       
    38 
       
    39 COomFailBase *CreateOomBackedUpWindow(CTOom *aTest)
       
    40 	{return(new(ELeave) COomBackedUpWindow(aTest));}
       
    41 
       
    42 COomFailBase *CreateOomBackupResize(CTOom *aTest)
       
    43 	{return(new(ELeave) COomBackupResize(aTest));}
       
    44 
       
    45 COomFailBase *CreateOomBlankWindow(CTOom *aTest)
       
    46 	{return(new(ELeave) COomBlankWindow(aTest));}
       
    47 
       
    48 COomFailBase *CreateOomGc(CTOom *aTest)
       
    49 	{return(new(ELeave) COomGc(aTest));}
       
    50 
       
    51 COomFailBase *CreateOomScreenDevice(CTOom *aTest)
       
    52 	{return(new(ELeave) COomScreenDevice(aTest));}
       
    53 
       
    54 COomFailBase *CreateOomPointerBuffer(CTOom *aTest)
       
    55 	{return(new(ELeave) COomPointerBuffer(aTest));}
       
    56 
       
    57 COomFailBase *CreateOomPolygon(CTOom *aTest)
       
    58 	{return(new(ELeave) COomPolygon(aTest));}
       
    59 
       
    60 COomFailBase *CreateOomPriorityKey(CTOom *aTest)
       
    61 	{return(new(ELeave) COomPriorityKey(aTest));}
       
    62 
       
    63 COomFailBase *CreateOomCaptureKey(CTOom *aTest)
       
    64 	{return(new(ELeave) COomCaptureKey(aTest));}
       
    65 
       
    66 COomFailBase *CreateOomCaptureKeyUpDown(CTOom *aTest)
       
    67 	{return(new(ELeave) COomCaptureKeyUpDown(aTest));}
       
    68 
       
    69 COomFailBase *CreateOomHotKey(CTOom *aTest)
       
    70 	{return(new(ELeave) COomHotKey(aTest));}
       
    71 
       
    72 COomFailBase *CreateOomGroupName(CTOom *aTest)
       
    73 	{return(new(ELeave) COomGroupName(aTest));}
       
    74 
       
    75 COomFailBase *CreateOomMessageSend(CTOom *aTest)
       
    76 	{return(new(ELeave) COomMessageSend(aTest));}
       
    77 
       
    78 COomFailBase *CreateOomMessageFetch(CTOom *aTest)
       
    79 	{return(new(ELeave) COomMessageFetch(aTest));}
       
    80 
       
    81 COomFailBase *CreateOomSprite(CTOom *aTest)
       
    82 	{return(new(ELeave) COomSprite(aTest));}
       
    83 
       
    84 COomFailBase *CreateOomPointerCursor(CTOom *aTest)
       
    85 	{return(new(ELeave) COomPointerCursor(aTest));}
       
    86 
       
    87 COomFailBase *CreateOomCopyScreen(CTOom *aTest)
       
    88 	{return(new(ELeave) COomCopyScreen(aTest));}
       
    89 
       
    90 COomFailBase *CreateOomRequestEvents(CTOom *aTest)
       
    91 	{return(new(ELeave) COomRequestEvents(aTest));}
       
    92 
       
    93 COomFailBase *CreateOomCustomTextCursor(CTOom *aTest)
       
    94 	{return(new(ELeave) COomCustomTextCursor(aTest));}
       
    95 
       
    96 COomFailBase *CreateOomTranspWindow(CTOom *aTest)
       
    97 	{return(new(ELeave) COomTranspWindow(aTest));}
       
    98 
       
    99 COomFailBase *CreateOomObscuredWindow(CTOom *aTest)
       
   100 	{return(new(ELeave) COomObscuredWindow(aTest));}
       
   101 
       
   102 COmmCreate CreateOomFailTest[]={
       
   103 	CreateOomConnect,
       
   104 	CreateOomWindow,
       
   105 	CreateOomWindowGroup,
       
   106 	CreateOomBackedUpWindow,
       
   107 	CreateOomBackupResize,
       
   108 	CreateOomBlankWindow,
       
   109 	CreateOomGc,
       
   110 	CreateOomScreenDevice,
       
   111 	CreateOomPointerBuffer,
       
   112 	CreateOomPolygon,
       
   113 	CreateOomPriorityKey,
       
   114 	CreateOomCaptureKey,
       
   115 	CreateOomCaptureKeyUpDown,
       
   116 	CreateOomHotKey,
       
   117 	CreateOomGroupName,
       
   118 	CreateOomSprite,
       
   119 	CreateOomPointerCursor,
       
   120 	CreateOomCopyScreen,
       
   121 	CreateOomRequestEvents,
       
   122 	CreateOomMessageSend,
       
   123 	CreateOomMessageFetch,
       
   124 	CreateOomCustomTextCursor,
       
   125 	CreateOomTranspWindow,
       
   126 	CreateOomObscuredWindow,
       
   127 	};
       
   128 
       
   129 //
       
   130 // Individual out of memory test classes //
       
   131 //
       
   132 
       
   133 COomFailBase::COomFailBase(CTOom *aTest) : iTest(aTest)
       
   134 	{}
       
   135 
       
   136 void COomFailBase::ConstructL()
       
   137 	{
       
   138 	iTest->INFO_PRINTF1(TestName());
       
   139 	}
       
   140 
       
   141 void COomFailBase::PreFail()
       
   142 	{}
       
   143 
       
   144 void COomFailBase::ClearUpL()
       
   145 	{}
       
   146 
       
   147 void COomFailBase::Flush()
       
   148 	{
       
   149 	iWs.Flush();
       
   150 	}
       
   151 
       
   152 COomConnect::COomConnect(CTOom *aTest) : COomFailBase(aTest)
       
   153 	{}
       
   154 
       
   155 TOomTestName COomConnect::TestName()
       
   156 	{
       
   157 	return(_L("Connect"));
       
   158 	}
       
   159 
       
   160 /** Creates a wserv session, connects and creates CWsScreenDevice object
       
   161 */
       
   162 TInt COomConnect::Fail()
       
   163 	{
       
   164 	TInt err = iWs.Connect();
       
   165 	if (err!=KErrNone)
       
   166 		return err;
       
   167 	
       
   168 	TRAP(err, iDummyScreen = new (ELeave) CWsScreenDevice(iWs));
       
   169 	if (err!=KErrNone)
       
   170 		{
       
   171 		iWs.Close();
       
   172 		return err;
       
   173 		}
       
   174 		
       
   175 	if ((err=iDummyScreen->Construct(iTest->ScreenNumber()))!=KErrNone)
       
   176 		{
       
   177 		delete iDummyScreen;
       
   178 		iDummyScreen = NULL;
       
   179 		iWs.Close();
       
   180 		return err;
       
   181 		}
       
   182 		
       
   183 	return err;
       
   184 	}
       
   185 
       
   186 void COomConnect::ClearUpL()
       
   187 	{
       
   188 	if (iDummyScreen)
       
   189 		{
       
   190 		delete iDummyScreen;
       
   191 		iDummyScreen = NULL;
       
   192 		}
       
   193 	iWs.Close();
       
   194 	}
       
   195 
       
   196 //
       
   197 
       
   198 COomSetup::COomSetup(CTOom *aTest) : COomFailBase(aTest)
       
   199 	{}
       
   200 
       
   201 void COomSetup::ConstructL()
       
   202 	{
       
   203 	COomFailBase::ConstructL();
       
   204 	User::LeaveIfError(iWs.Connect());
       
   205 	iDummyScreen = new (ELeave) CWsScreenDevice(iWs);
       
   206 	User::LeaveIfError(iDummyScreen->Construct(iTest->ScreenNumber()));
       
   207 	
       
   208 	iWinGroup=RWindowGroup(iWs);
       
   209 	iWinGroup.Construct(556);
       
   210 	iWinGroup.EnableReceiptOfFocus(EFalse);	// Stop auto group switching on close
       
   211 	}
       
   212 
       
   213 COomSetup::~COomSetup()
       
   214 	{
       
   215 	iWinGroup.Close();
       
   216 	delete iDummyScreen;
       
   217 	iDummyScreen = NULL;
       
   218 	
       
   219 	iTest->TEST(iWs.ResourceCount()==0);
       
   220 	if (iWs.ResourceCount()!=0)
       
   221 		iTest->INFO_PRINTF3(_L("iWs.ResourceCount() return value - Expected: %d, Actual: %d"), 0, iWs.ResourceCount());			
       
   222 
       
   223 	iWs.Close();
       
   224 	}
       
   225 
       
   226 //
       
   227 
       
   228 COomWindowGroup::COomWindowGroup(CTOom *aTest) : COomSetup(aTest)
       
   229 	{}
       
   230 
       
   231 TOomTestName COomWindowGroup::TestName()
       
   232 	{
       
   233 	return(_L("Window Group"));
       
   234 	}
       
   235 
       
   236 /** Creates a RWindowGroup object
       
   237 */
       
   238 TInt COomWindowGroup::Fail()
       
   239 	{
       
   240 	iFailWinGroup=RWindowGroup(iWs);
       
   241 	return(iFailWinGroup.Construct(987));
       
   242 	}
       
   243 
       
   244 void COomWindowGroup::ClearUpL()
       
   245 	{
       
   246 	iFailWinGroup.Close();
       
   247 	}
       
   248 
       
   249 //
       
   250 
       
   251 COomWindow::COomWindow(CTOom *aTest) : COomSetup(aTest)
       
   252 	{}
       
   253 
       
   254 TOomTestName COomWindow::TestName()
       
   255 	{
       
   256 	return(_L("Window"));
       
   257 	}
       
   258 
       
   259 /** Creates a RWindow object
       
   260 */
       
   261 TInt COomWindow::Fail()
       
   262 	{
       
   263 	iFailWin=RWindow(iWs);
       
   264 	return(iFailWin.Construct(iWinGroup,11));
       
   265 	}
       
   266 
       
   267 void COomWindow::ClearUpL()
       
   268 	{
       
   269 	iFailWin.Close();
       
   270 	}
       
   271 
       
   272 //
       
   273 
       
   274 COomBackedUpWindow::COomBackedUpWindow(CTOom *aTest) : COomSetup(aTest)
       
   275 	{}
       
   276 
       
   277 TOomTestName COomBackedUpWindow::TestName()
       
   278 	{
       
   279 	return(_L("Backed up window"));
       
   280 	}
       
   281 
       
   282 /** Creates a RBackedUpWindow object
       
   283 */
       
   284 TInt COomBackedUpWindow::Fail()
       
   285 	{
       
   286 	iFailWin=RBackedUpWindow(iWs);
       
   287 	return(iFailWin.Construct(iWinGroup,EGray16,22));
       
   288 	}
       
   289 
       
   290 void COomBackedUpWindow::ClearUpL()
       
   291 	{
       
   292 	iFailWin.Close();
       
   293 	}
       
   294 
       
   295 //
       
   296 
       
   297 COomBackupResize::COomBackupResize(CTOom *aTest) : COomSetup(aTest)
       
   298 	{}
       
   299 
       
   300 COomBackupResize::~COomBackupResize()
       
   301 	{
       
   302 	iFailWin.Close();
       
   303 	}
       
   304 
       
   305 TOomTestName COomBackupResize::TestName()
       
   306 	{
       
   307 	return(_L("Resize backed up window"));
       
   308 	}
       
   309 
       
   310 void COomBackupResize::ConstructL()
       
   311 	{
       
   312 	COomSetup::ConstructL();
       
   313 	iFailWin=RBackedUpWindow(iWs);
       
   314 	User::LeaveIfError(iFailWin.Construct(iWinGroup,EGray16,33));
       
   315 	User::LeaveIfError(iFailWin.SetSizeErr(TSize(10,10)));
       
   316 	iFailWin.Activate();
       
   317 	}
       
   318 	
       
   319 /** Sets the size of previously created backed-up window
       
   320 */
       
   321 TInt COomBackupResize::Fail()
       
   322 	{
       
   323 	return(iFailWin.SetSizeErr(TSize(100,100)));
       
   324 	}
       
   325 
       
   326 void COomBackupResize::ClearUpL()
       
   327 //Virtual fn declared in CoomFailBase. This is the only one that can leave, I think, but one is enough
       
   328 	{
       
   329 	User::LeaveIfError(iFailWin.SetSizeErr(TSize(10,10)));
       
   330 	}
       
   331 
       
   332 //
       
   333 
       
   334 COomBlankWindow::COomBlankWindow(CTOom *aTest) : COomSetup(aTest)
       
   335 	{}
       
   336 
       
   337 TOomTestName COomBlankWindow::TestName()
       
   338 	{
       
   339 	return(_L("Blank window"));
       
   340 	}
       
   341 
       
   342 /** Creates a RBlankWindow object
       
   343 */
       
   344 TInt COomBlankWindow::Fail()
       
   345 	{
       
   346 	iFailWin=RBlankWindow(iWs);
       
   347 	return(iFailWin.Construct(iWinGroup,44));
       
   348 	}
       
   349 
       
   350 void COomBlankWindow::ClearUpL()
       
   351 	{
       
   352 	iFailWin.Close();
       
   353 	}
       
   354 
       
   355 //
       
   356 
       
   357 COomPointerBuffer::COomPointerBuffer(CTOom *aTest) : COomSetup(aTest)
       
   358 	{}
       
   359 
       
   360 COomPointerBuffer::~COomPointerBuffer()
       
   361 	{
       
   362 	iFailWin.Close();
       
   363 	}
       
   364 
       
   365 TOomTestName COomPointerBuffer::TestName()
       
   366 	{
       
   367 	return(_L("Pointer buffer"));
       
   368 	}
       
   369 
       
   370 void COomPointerBuffer::ConstructL()
       
   371 	{
       
   372 	COomSetup::ConstructL();
       
   373 	iFailWin=RBackedUpWindow(iWs);
       
   374 	User::LeaveIfError(iFailWin.Construct(iWinGroup,EGray16,55));
       
   375 	User::LeaveIfError(iFailWin.SetSizeErr(TSize(10,10)));
       
   376 	iFailWin.Activate();
       
   377 	}
       
   378 
       
   379 /** Allocates a buffer for storing pointer movements for previously created backed-up window
       
   380 */
       
   381 TInt COomPointerBuffer::Fail()
       
   382 	{
       
   383 	return(iFailWin.AllocPointerMoveBuffer(10,0));
       
   384 	}
       
   385 
       
   386 void COomPointerBuffer::ClearUpL()
       
   387 	{
       
   388 	iFailWin.FreePointerMoveBuffer();
       
   389 	}
       
   390 
       
   391 //
       
   392 
       
   393 COomPriorityKey::COomPriorityKey(CTOom *aTest) : COomSetup(aTest)
       
   394 	{}
       
   395 
       
   396 COomPriorityKey::~COomPriorityKey()
       
   397 	{
       
   398 	}
       
   399 
       
   400 TOomTestName COomPriorityKey::TestName()
       
   401 	{
       
   402 	return(_L("Priority key"));
       
   403 	}
       
   404 
       
   405 void COomPriorityKey::ConstructL()
       
   406 	{
       
   407 	COomSetup::ConstructL();
       
   408 	}
       
   409 
       
   410 /** Adds a priority key for a previously created window group
       
   411 */
       
   412 TInt COomPriorityKey::Fail()
       
   413 	{
       
   414 	return(iWinGroup.AddPriorityKey(1,0,0));
       
   415 	}
       
   416 
       
   417 void COomPriorityKey::ClearUpL()
       
   418 	{
       
   419 	iWinGroup.RemovePriorityKey(1,0,0);
       
   420 	}
       
   421 
       
   422 //
       
   423 
       
   424 COomCaptureKey::COomCaptureKey(CTOom *aTest) : COomSetup(aTest)
       
   425 	{}
       
   426 
       
   427 COomCaptureKey::~COomCaptureKey()
       
   428 	{
       
   429 	}
       
   430 
       
   431 TOomTestName COomCaptureKey::TestName()
       
   432 	{
       
   433 	return(_L("Capture key"));
       
   434 	}
       
   435 
       
   436 void COomCaptureKey::ConstructL()
       
   437 	{
       
   438 	COomSetup::ConstructL();
       
   439 	}
       
   440 
       
   441 /** Requests a capture keys for a previously created window group
       
   442 */
       
   443 TInt COomCaptureKey::Fail()
       
   444 	{
       
   445 	for (iIndex=0;iIndex<(TInt)(sizeof(iCapKey)/sizeof(iCapKey[0]));iIndex++)
       
   446 		{
       
   447 		TInt ret=iWinGroup.CaptureKey('a',0,0);
       
   448 		if (ret<0)
       
   449 			return(ret);
       
   450 		iCapKey[iIndex]=ret;
       
   451 		}
       
   452 	return(KErrNone);
       
   453 	}
       
   454 
       
   455 void COomCaptureKey::ClearUpL()
       
   456 	{
       
   457 	for (TInt index=0;index<iIndex;index++)
       
   458 		iWinGroup.CancelCaptureKey(iCapKey[index]);
       
   459 	}
       
   460 
       
   461 //
       
   462 
       
   463 COomCaptureKeyUpDown::COomCaptureKeyUpDown(CTOom *aTest) : COomSetup(aTest)
       
   464 	{}
       
   465 
       
   466 COomCaptureKeyUpDown::~COomCaptureKeyUpDown()
       
   467 	{
       
   468 	}
       
   469 
       
   470 TOomTestName COomCaptureKeyUpDown::TestName()
       
   471 	{
       
   472 	return(_L("Capture up/down keys"));
       
   473 	}
       
   474 
       
   475 void COomCaptureKeyUpDown::ConstructL()
       
   476 	{
       
   477 	COomSetup::ConstructL();
       
   478 	}
       
   479 
       
   480 /** Requests the capture of key-up and key-down events for a previously created window group
       
   481 */
       
   482 TInt COomCaptureKeyUpDown::Fail()
       
   483 	{
       
   484 	for (iIndex=0;iIndex<(TInt)(sizeof(iCapKey)/sizeof(iCapKey[0]));iIndex++)
       
   485 		{
       
   486 		TInt ret=iWinGroup.CaptureKeyUpAndDowns('a',0,0);
       
   487 		if (ret<0)
       
   488 			return(ret);
       
   489 		iCapKey[iIndex]=ret;
       
   490 		}
       
   491 	return(KErrNone);
       
   492 	}
       
   493 
       
   494 void COomCaptureKeyUpDown::ClearUpL()
       
   495 	{
       
   496 	for (TInt index=0;index<iIndex;index++)
       
   497 		iWinGroup.CancelCaptureKeyUpAndDowns(iCapKey[index]);
       
   498 	}
       
   499 
       
   500 //
       
   501 
       
   502 COomHotKey::COomHotKey(CTOom *aTest) : COomSetup(aTest)
       
   503 	{}
       
   504 
       
   505 COomHotKey::~COomHotKey()
       
   506 	{
       
   507 	}
       
   508 
       
   509 TOomTestName COomHotKey::TestName()
       
   510 	{
       
   511 	return(_L("hot keys"));
       
   512 	}
       
   513 
       
   514 void COomHotKey::ConstructL()
       
   515 	{
       
   516 	COomSetup::ConstructL();
       
   517 	}
       
   518 
       
   519 /** Sets hot key for the session.
       
   520 */
       
   521 TInt COomHotKey::Fail()
       
   522 	{
       
   523 	return(iWs.SetHotKey(EHotKeyEnableLogging,'a',0,0));
       
   524 	}
       
   525 
       
   526 void COomHotKey::ClearUpL()
       
   527 	{
       
   528 	iWs.RestoreDefaultHotKey(EHotKeyEnableLogging);
       
   529 	}
       
   530 
       
   531 //
       
   532 
       
   533 COomGroupName::COomGroupName(CTOom *aTest) : COomSetup(aTest)
       
   534 	{}
       
   535 
       
   536 COomGroupName::~COomGroupName()
       
   537 	{
       
   538 	}
       
   539 
       
   540 TOomTestName COomGroupName::TestName()
       
   541 	{
       
   542 	return(_L("Group name"));
       
   543 	}
       
   544 
       
   545 void COomGroupName::ConstructL()
       
   546 	{
       
   547 	COomSetup::ConstructL();
       
   548 	}
       
   549 
       
   550 /** Sets the window group's name.
       
   551 */
       
   552 TInt COomGroupName::Fail()
       
   553 	{
       
   554 	return(iWinGroup.SetName(_L("A Name")));
       
   555 	}
       
   556 
       
   557 void COomGroupName::ClearUpL()
       
   558 	{
       
   559 	iWinGroup.SetName(_L(""));
       
   560 	}
       
   561 
       
   562 //
       
   563 
       
   564 COomMessageSend::COomMessageSend(CTOom *aTest) : COomSetup(aTest)
       
   565 	{}
       
   566 
       
   567 COomMessageSend::~COomMessageSend()
       
   568 	{
       
   569 	}
       
   570 
       
   571 TOomTestName COomMessageSend::TestName()
       
   572 	{
       
   573 	return(_L("MessageSend"));
       
   574 	}
       
   575 
       
   576 void COomMessageSend::ConstructL()
       
   577 	{
       
   578 	COomSetup::ConstructL();
       
   579 	}
       
   580 
       
   581 void COomMessageSend::PreFail()
       
   582 	{
       
   583 	iWinGroup2=RWindowGroup(iWs);
       
   584 	iWinGroup2.Construct(557);
       
   585 	iWinGroup2.EnableReceiptOfFocus(EFalse);	// Stop auto group switching on close
       
   586 	}
       
   587 
       
   588 /** Sends a message to another window group
       
   589 */
       
   590 TInt COomMessageSend::Fail()
       
   591 	{
       
   592 	TBuf8<0x20> params(_L8("SomeParams"));
       
   593 	return(iWs.SendMessageToWindowGroup(iWinGroup2.Identifier(),TUid::Uid(123),params));
       
   594 	}
       
   595 
       
   596 void COomMessageSend::ClearUpL()
       
   597 	{
       
   598 	iWinGroup2.Close();
       
   599 	}
       
   600 
       
   601 //
       
   602 
       
   603 COomMessageFetch::COomMessageFetch(CTOom *aTest) : COomSetup(aTest)
       
   604 	{}
       
   605 
       
   606 COomMessageFetch::~COomMessageFetch()
       
   607 	{
       
   608 	}
       
   609 
       
   610 TOomTestName COomMessageFetch::TestName()
       
   611 	{
       
   612 	return(_L("MessageFetch"));
       
   613 	}
       
   614 
       
   615 void COomMessageFetch::ConstructL()
       
   616 	{
       
   617 	COomSetup::ConstructL();
       
   618 	}
       
   619 
       
   620 #define CLIENT_HANDLE 555
       
   621 #define UID_VALUE 123
       
   622 #define MESSAGE_LEN 0x20
       
   623 void COomMessageFetch::PreFail()
       
   624 	{
       
   625 	iWinGroup2=RWindowGroup(iWs);
       
   626 	iWinGroup2.Construct(CLIENT_HANDLE);
       
   627 	iWinGroup2.EnableReceiptOfFocus(EFalse);	// Stop auto group switching on close
       
   628 	TBuf8<MESSAGE_LEN> params(_L8("SomeParams"));
       
   629 	TBool retVal = iWs.SendMessageToWindowGroup(iWinGroup2.Identifier(),TUid::Uid(UID_VALUE),params);
       
   630 	iTest->TEST(retVal==KErrNone);
       
   631 	if (retVal!=KErrNone)
       
   632 		iTest->INFO_PRINTF3(_L("iWs.SendMessageToWindowGroup() return value - Expected: %d, Actual: %d"), KErrNone, retVal);			
       
   633 	}
       
   634 
       
   635 /** Fetches a message
       
   636 */
       
   637 TInt COomMessageFetch::Fail()
       
   638 	{
       
   639 	TWsEvent event;
       
   640 	TPtr8 ptr(NULL,0);
       
   641 	TUid uid;
       
   642 	event.SetType(EEventMessageReady);
       
   643 	event.SetHandle(CLIENT_HANDLE);
       
   644 	event.SetTimeNow();
       
   645 	SEventMessageReady& eventMessageReady=*(SEventMessageReady*)event.EventData();
       
   646 	eventMessageReady.iWindowGroupIdentifier=iWinGroup2.Identifier();
       
   647 	eventMessageReady.iMessageUid=TUid::Uid(UID_VALUE);
       
   648 	eventMessageReady.iMessageParametersSize=MESSAGE_LEN;
       
   649 	TInt ret=TheClient->iWs.FetchMessage(uid,ptr,event);
       
   650 	if (ret==KErrNone)
       
   651 		User::Free((TAny *)ptr.Ptr());
       
   652 	return(ret);
       
   653 	}
       
   654 
       
   655 void COomMessageFetch::ClearUpL()
       
   656 	{
       
   657 	iWinGroup2.Close();
       
   658 	}
       
   659 
       
   660 //
       
   661 
       
   662 COomRequestEvents::COomRequestEvents(CTOom *aTest) : COomSetup(aTest)
       
   663 	{}
       
   664 
       
   665 COomRequestEvents::~COomRequestEvents()
       
   666 	{
       
   667 	}
       
   668 
       
   669 TOomTestName COomRequestEvents::TestName()
       
   670 	{
       
   671 	return(_L("Request events"));
       
   672 	}
       
   673 
       
   674 void COomRequestEvents::ConstructL()
       
   675 	{
       
   676 	COomSetup::ConstructL();
       
   677 	}
       
   678 
       
   679 /** Enables window group change events and modifier change events
       
   680 */
       
   681 TInt COomRequestEvents::Fail()
       
   682 	{
       
   683 	TInt err;
       
   684 	if ((err=iWinGroup.EnableOnEvents())==KErrNone)
       
   685 		if ((err=iWinGroup.EnableGroupChangeEvents())==KErrNone)
       
   686 			err=iWinGroup.EnableModifierChangedEvents(EModifierCapsLock,EEventControlAlways);
       
   687 	return(err);
       
   688 	}
       
   689 
       
   690 void COomRequestEvents::ClearUpL()
       
   691 	{
       
   692 	iWinGroup.DisableOnEvents();
       
   693 	iWinGroup.DisableGroupChangeEvents();
       
   694 	iWinGroup.DisableModifierChangedEvents();
       
   695 	}
       
   696 
       
   697 //
       
   698 
       
   699 COomCopyScreen::COomCopyScreen(CTOom *aTest) : COomSetup(aTest)
       
   700 	{}
       
   701 
       
   702 TOomTestName COomCopyScreen::TestName()
       
   703 	{
       
   704 	return(_L("Copy screen"));
       
   705 	}
       
   706 
       
   707 COomCopyScreen::~COomCopyScreen()
       
   708 	{
       
   709 	delete iScrDev;
       
   710 	delete iBitmap;
       
   711 	}
       
   712 
       
   713 void COomCopyScreen::ConstructL()
       
   714 	{
       
   715 	COomSetup::ConstructL();
       
   716 	iScrDev=new(ELeave) CWsScreenDevice(iWs);
       
   717 	User::LeaveIfError(iScrDev->Construct(iTest->ScreenNumber()));
       
   718 	iBitmap=new(ELeave) CFbsBitmap();
       
   719 	User::LeaveIfError(iBitmap->Create(TSize(100,100),EGray4));
       
   720 	}
       
   721 
       
   722 /** Copies screen to bitmap
       
   723 */
       
   724 TInt COomCopyScreen::Fail()
       
   725 	{
       
   726 	TInt ret=iScrDev->CopyScreenToBitmap(iBitmap);
       
   727 	if (ret==KErrNone)
       
   728 		ret=iScrDev->CopyScreenToBitmap(iBitmap,TRect(10,10,50,50));
       
   729 	return(ret);
       
   730 	}
       
   731 
       
   732 void COomCopyScreen::ClearUpL()
       
   733 	{
       
   734 	}
       
   735 
       
   736 //
       
   737 
       
   738 COomSpriteBase::COomSpriteBase(CTOom *aTest) : COomSetup(aTest)
       
   739 	{}
       
   740 
       
   741 COomSpriteBase::~COomSpriteBase()
       
   742 	{
       
   743 	iWin.Close();
       
   744 	delete iBitmap;
       
   745 	delete iMask;
       
   746 	delete iBitmap2;
       
   747 	delete iMask2;
       
   748 	}
       
   749 
       
   750 void COomSpriteBase::ConstructL()
       
   751 	{
       
   752 	COomSetup::ConstructL();
       
   753 	iWin=RWindow(iWs);
       
   754 	User::LeaveIfError(iWin.Construct(iWinGroup,33));
       
   755 	User::LeaveIfError(iWin.SetSizeErr(TSize(100,100)));
       
   756 	iWin.Activate();
       
   757 	iBitmap=new(ELeave) CFbsBitmap();
       
   758 	User::LeaveIfError(iBitmap->Create(TSize(10,10),EGray4));
       
   759 	iBitmap2=new(ELeave) CFbsBitmap();
       
   760 	User::LeaveIfError(iBitmap2->Create(TSize(40,40),EGray4));
       
   761 	iMask=new(ELeave) CFbsBitmap();
       
   762 	User::LeaveIfError(iMask->Create(TSize(10,10),EGray4));
       
   763 	iMask2=new(ELeave) CFbsBitmap();
       
   764 	User::LeaveIfError(iMask2->Create(TSize(40,40),EGray4));
       
   765 	}
       
   766 
       
   767 //
       
   768 
       
   769 COomSprite::COomSprite(CTOom *aTest) : COomSpriteBase(aTest)
       
   770 	{}
       
   771 
       
   772 TOomTestName COomSprite::TestName()
       
   773 	{
       
   774 	return(_L("Sprites"));
       
   775 	}
       
   776 
       
   777 /** Creates a sprite.
       
   778 */
       
   779 TInt COomSprite::Fail()
       
   780 	{
       
   781 	iSprite=RWsSprite(iWs);
       
   782 	TInt err=iSprite.Construct(iWin,TPoint(10,10),0);
       
   783 	if (err==KErrNone)
       
   784 		{
       
   785 		TSpriteMember sprite;
       
   786 		sprite.iBitmap=iBitmap;
       
   787 		sprite.iMaskBitmap=iMask;
       
   788 		sprite.iInvertMask=EFalse;
       
   789 		sprite.iDrawMode=CGraphicsContext::EDrawModePEN;
       
   790 		sprite.iOffset=TPoint(0,0);
       
   791 		sprite.iInterval=TTimeIntervalMicroSeconds32(100000);
       
   792 		if ((err=iSprite.AppendMember(sprite))==KErrNone)
       
   793 			if ((err=iSprite.Activate())==KErrNone)
       
   794 				{
       
   795 				sprite.iBitmap=iBitmap2;		// Bigger bitmap to force resize of bitmap
       
   796 				sprite.iMaskBitmap=iMask2;
       
   797 				if ((err=iSprite.AppendMember(sprite))==KErrNone)
       
   798 					err=iSprite.UpdateMember(1,sprite);
       
   799 				}
       
   800 		}
       
   801 	return(err);
       
   802 	}
       
   803 
       
   804 void COomSprite::ClearUpL()
       
   805 	{
       
   806 	iSprite.Close();
       
   807 	}
       
   808 
       
   809 //
       
   810 
       
   811 COomPointerCursor::COomPointerCursor(CTOom *aTest) : COomSpriteBase(aTest)
       
   812 	{}
       
   813 
       
   814 TOomTestName COomPointerCursor::TestName()
       
   815 	{
       
   816 	return(_L("Pointer cursor"));
       
   817 	}
       
   818 
       
   819 /** Creates a pointer cursor.
       
   820 */
       
   821 TInt COomPointerCursor::Fail()
       
   822 	{
       
   823 	iPointerCursor=RWsPointerCursor(iWs);
       
   824 	TInt err=iPointerCursor.Construct(0);
       
   825 	if (err==KErrNone)
       
   826 		{
       
   827 		TSpriteMember sprite;
       
   828 		sprite.iBitmap=iBitmap;
       
   829 		sprite.iMaskBitmap=iMask;
       
   830 		sprite.iInvertMask=EFalse;
       
   831 		sprite.iDrawMode=CGraphicsContext::EDrawModePEN;
       
   832 		sprite.iOffset=TPoint(0,0);
       
   833 		sprite.iInterval=TTimeIntervalMicroSeconds32(100000);
       
   834 		if ((err=iPointerCursor.AppendMember(sprite))==KErrNone)
       
   835 			if ((err=iPointerCursor.Activate())==KErrNone)
       
   836 				{
       
   837 				sprite.iBitmap=iBitmap2;		// Bigger bitmap to force resize of bitmap
       
   838 				sprite.iMaskBitmap=iMask2;
       
   839 				if ((err=iPointerCursor.AppendMember(sprite))==KErrNone)
       
   840 					err=iPointerCursor.UpdateMember(1,sprite);
       
   841 				}
       
   842 		}
       
   843 	return(err);
       
   844 	}
       
   845 
       
   846 void COomPointerCursor::ClearUpL()
       
   847 	{
       
   848 	iPointerCursor.Close();
       
   849 	}
       
   850 
       
   851 //
       
   852 
       
   853 COomGc::COomGc(CTOom *aTest) : COomSetup(aTest)
       
   854 	{}
       
   855 
       
   856 COomGc::~COomGc()
       
   857 	{
       
   858 	delete iScrDev;
       
   859 	}
       
   860 
       
   861 TOomTestName COomGc::TestName()
       
   862 	{
       
   863 	return(_L("Graphic Context"));
       
   864 	}
       
   865 
       
   866 void COomGc::ConstructL()
       
   867 	{
       
   868 	COomSetup::ConstructL();
       
   869 	iScrDev=new(ELeave) CWsScreenDevice(iWs);
       
   870 	User::LeaveIfError(iScrDev->Construct(iTest->ScreenNumber()));
       
   871 	}
       
   872 
       
   873 /** Creates a graphical context for a previously created screen device.
       
   874 */
       
   875 TInt COomGc::Fail()
       
   876 	{
       
   877 	TRAPD(err,iFailGc=new(ELeave) CWindowGc(iScrDev));
       
   878 	if (err!=KErrNone)
       
   879 		return(err);
       
   880 	return(iFailGc->Construct());
       
   881 	}
       
   882 
       
   883 void COomGc::ClearUpL()
       
   884 	{
       
   885 	delete iFailGc;
       
   886 	iFailGc=NULL;
       
   887 	}
       
   888 
       
   889 //
       
   890 
       
   891 COomPolygon::COomPolygon(CTOom *aTest) : COomSetup(aTest), iPnts(5)
       
   892 	{}
       
   893 
       
   894 COomPolygon::~COomPolygon()
       
   895 	{
       
   896 	delete iGc;
       
   897 	delete iScrDev;
       
   898 	iWin.Close();
       
   899 	}
       
   900 
       
   901 TOomTestName COomPolygon::TestName()
       
   902 	{
       
   903 	return(_L("Polygon"));
       
   904 	}
       
   905 
       
   906 void COomPolygon::ConstructL()
       
   907 	{
       
   908 	COomSetup::ConstructL();
       
   909 	iScrDev=new(ELeave) CWsScreenDevice(iWs);
       
   910 	User::LeaveIfError(iScrDev->Construct(iTest->ScreenNumber()));
       
   911 	User::LeaveIfError(iScrDev->CreateContext(iGc));
       
   912 	iWin=RBackedUpWindow(iWs);
       
   913 	User::LeaveIfError(iWin.Construct(iWinGroup,EGray16,33));
       
   914 	User::LeaveIfError(iWin.SetSizeErr(TSize(40,40)));
       
   915 	iWin.Activate();
       
   916 	TInt index;
       
   917 	for(index=0;index<20;index+=2)
       
   918 		iPnts.AppendL(TPoint(20+index,index));
       
   919 	for(index=0;index<20;index+=2)
       
   920 		iPnts.AppendL(TPoint(40-index,20+index));
       
   921 	for(index=0;index<20;index+=2)
       
   922 		iPnts.AppendL(TPoint(20-index,40-index));
       
   923 	for(index=0;index<20;index+=2)
       
   924 		iPnts.AppendL(TPoint(index,20-index));
       
   925 	}
       
   926 
       
   927 /** Draws a polygon.
       
   928 */
       
   929 TInt COomPolygon::Fail()
       
   930 	{
       
   931 	iGc->Activate(iWin);
       
   932 	iGc->Clear();
       
   933 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   934 	iGc->SetBrushColor(TRgb::Gray4(2));
       
   935 	iGc->SetPenColor(TRgb::Gray4(0));
       
   936 	TInt err=iGc->DrawPolygon(&iPnts,CGraphicsContext::EAlternate);
       
   937 	if (err!=KErrNone)
       
   938 		return(err);
       
   939 	err=iGc->DrawPolygon(&iPnts,CGraphicsContext::EWinding);
       
   940 	if (err!=KErrNone)
       
   941 		return(err);
       
   942 	return(KErrNone);
       
   943 	}
       
   944 
       
   945 void COomPolygon::ClearUpL()
       
   946 	{
       
   947 	iGc->Deactivate();
       
   948 	}
       
   949 
       
   950 //
       
   951 
       
   952 COomScreenDevice::COomScreenDevice(CTOom *aTest) : COomSetup(aTest)
       
   953 	{}
       
   954 
       
   955 TOomTestName COomScreenDevice::TestName()
       
   956 	{
       
   957 	return(_L("Screen device"));
       
   958 	}
       
   959 
       
   960 /** Creates a screen device handle.
       
   961 */
       
   962 TInt COomScreenDevice::Fail()
       
   963 	{
       
   964 	TRAPD(err,iScrDev=new(ELeave) CWsScreenDevice(iWs));
       
   965 	if (err!=KErrNone)
       
   966 		return(err);
       
   967 	return(iScrDev->Construct(iTest->ScreenNumber()));
       
   968 	}
       
   969 
       
   970 void COomScreenDevice::ClearUpL()
       
   971 	{
       
   972 	delete iScrDev;
       
   973 	iScrDev=NULL;
       
   974 	}
       
   975 
       
   976 //
       
   977 
       
   978 COomCustomTextCursor::COomCustomTextCursor(CTOom *aTest) : COomSetup(aTest)
       
   979 	{}
       
   980 
       
   981 COomCustomTextCursor::~COomCustomTextCursor()
       
   982 	{
       
   983 	delete iMemberArray;
       
   984 	delete iBitmap;
       
   985 	}
       
   986 
       
   987 TOomTestName COomCustomTextCursor::TestName()
       
   988 	{
       
   989 	return(_L("Custom Text Cursor"));
       
   990 	}
       
   991 
       
   992 void COomCustomTextCursor::ConstructL()
       
   993 	{
       
   994 	COomSetup::ConstructL();
       
   995 
       
   996 	iBitmap = new(ELeave) CFbsBitmap;
       
   997 	User::LeaveIfError(iBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1));
       
   998 
       
   999 	TSpriteMember member;
       
  1000 	member.iMaskBitmap=NULL;
       
  1001 	member.iInvertMask=EFalse;
       
  1002 	member.iDrawMode=CGraphicsContext::EDrawModePEN;
       
  1003 	member.iOffset=TPoint();
       
  1004 	member.iInterval=TTimeIntervalMicroSeconds32(0);
       
  1005 	member.iBitmap = iBitmap;
       
  1006 
       
  1007 	iMemberArray = new(ELeave) CArrayFixFlat<TSpriteMember>(1);
       
  1008 	iMemberArray->AppendL(member);
       
  1009 	}
       
  1010 
       
  1011 /** Adds a custom text cursor to the server's list of cursors.
       
  1012 */
       
  1013 TInt COomCustomTextCursor::Fail()
       
  1014 	{
       
  1015 	TInt err = TheClient->iWs.SetCustomTextCursor(0x98765432, iMemberArray->Array(), 0, RWsSession::ECustomTextCursorAlignTop);
       
  1016 	if (err == KErrAlreadyExists)
       
  1017 		return KErrNone;
       
  1018 	else
       
  1019 		return err;
       
  1020 	}
       
  1021 
       
  1022 void COomCustomTextCursor::ClearUpL()
       
  1023 	{
       
  1024 	}
       
  1025 
       
  1026 COomTranspWindow::COomTranspWindow(CTOom *aTest) : COomSetup(aTest)
       
  1027 	{}
       
  1028 
       
  1029 COomTranspWindow::~COomTranspWindow()
       
  1030 	{
       
  1031 	delete iBackgroundWin;
       
  1032 	delete iFirst;
       
  1033 	delete iSecond;
       
  1034 	
       
  1035 	delete iFbsBitmap;
       
  1036 	delete iWsBitmap;
       
  1037 	delete iFbsBitmapDevice; 
       
  1038 	delete iFbsBitmapGc;
       
  1039 	delete iWsBitmapDevice; 
       
  1040 	delete iWsBitmapGc;				
       
  1041 	}
       
  1042 
       
  1043 TOomTestName COomTranspWindow::TestName()
       
  1044 	{
       
  1045 	return(_L("Transparent Window"));
       
  1046 	}
       
  1047 
       
  1048 void COomTranspWindow::ConstructL()
       
  1049 	{
       
  1050 	COomSetup::ConstructL();
       
  1051 	
       
  1052 	iTransparencyEnabled = (TransparencySupportedL() == KErrNone);
       
  1053 	if(!iTransparencyEnabled)
       
  1054 		return;
       
  1055 
       
  1056 	iFbsBitmap = new (ELeave) CFbsBitmap;
       
  1057 
       
  1058 	// Do the creation 
       
  1059 	const TSize KSizeForBitmap(10,10);
       
  1060 	iFbsBitmap->Create(KSizeForBitmap,EGray256);
       
  1061 	
       
  1062 	// Fill the bitmap with a colour		
       
  1063 	iFbsBitmapDevice=CFbsBitmapDevice::NewL(iFbsBitmap);
       
  1064 		
       
  1065 	iFbsBitmapDevice->CreateContext(iFbsBitmapGc);
       
  1066 	
       
  1067 	iFbsBitmapGc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1068 	iFbsBitmapGc->SetBrushStyle(CGraphicsContext::ESolidBrush);	
       
  1069 	iFbsBitmapGc->SetBrushColor(128);
       
  1070 	iFbsBitmapGc->DrawRect(TRect(KSizeForBitmap));
       
  1071 	
       
  1072 	// Create a CWsBitmap, and fill it with a colour	
       
  1073 	iWsBitmap = new (ELeave) CWsBitmap(TheClient->iWs);
       
  1074 	
       
  1075 	// Do the creation 
       
  1076 	iWsBitmap->Create(KSizeForBitmap,EGray256);	
       
  1077 		
       
  1078 	// Fill the bitmap with a colour		
       
  1079 	iWsBitmapDevice=CFbsBitmapDevice::NewL(iWsBitmap);	
       
  1080 			
       
  1081 	iWsBitmapDevice->CreateContext(iWsBitmapGc);		
       
  1082 	iWsBitmapGc->SetPenStyle(CGraphicsContext::ENullPen);
       
  1083 	iWsBitmapGc->SetBrushStyle(CGraphicsContext::ESolidBrush);	
       
  1084 	iWsBitmapGc->SetBrushColor(128);
       
  1085 	iWsBitmapGc->DrawRect(TRect(KSizeForBitmap));				
       
  1086 	}
       
  1087 	
       
  1088 
       
  1089 /** Does nothing if transparency is not enabled. Creates a blank window with 
       
  1090 * two transparent child-windows. Tests setting the transparency via a factor, CFbsBitmap
       
  1091 * or a CWsBitmap, and changing from one to the other.
       
  1092 * Changes child-windows' sizes and toggles their visibility.
       
  1093 */
       
  1094 TInt COomTranspWindow::Fail()
       
  1095 	{
       
  1096 	if(!iTransparencyEnabled)
       
  1097 		return KErrNone;
       
  1098 	TSize scrSize(TheClient->iScreen->SizeInPixels());
       
  1099 	TRAPD(res, iBackgroundWin = new (ELeave) CBlankWindow(TRgb(0,0,238)));
       
  1100 	if(res != KErrNone)
       
  1101 		{
       
  1102 		return res;	
       
  1103 		}
       
  1104 
       
  1105 	TDisplayMode mode=EColor256;
       
  1106 	TRAP(res, iBackgroundWin->SetUpL(TPoint(50,50),scrSize-TSize(100,100),TheClient->iGroup,*TheClient->iGc,&mode));
       
  1107 	if(res != KErrNone)
       
  1108 		{
       
  1109 		return res;
       
  1110 		}
       
  1111 
       
  1112 	TheClient->Flush();
       
  1113 	TheClient->WaitForRedrawsToFinish();
       
  1114 
       
  1115 	iBackgroundWin->Win()->SetBackgroundColor(TRgb(51,204,51));
       
  1116 	iBackgroundWin->Invalidate();
       
  1117 
       
  1118 	TheClient->Flush();
       
  1119 	TheClient->WaitForRedrawsToFinish();
       
  1120 
       
  1121 	TRect	thePos1(20, 20, 60, 60);
       
  1122 	TRect	thePos2(100, 40, 160, 80);
       
  1123 	TRAP(res, iFirst = CTransWindow::NewL(iBackgroundWin, TRgb(255,0,0,128),&mode));
       
  1124 	if(res != KErrNone)
       
  1125 		{
       
  1126 		return res;
       
  1127 		}
       
  1128 
       
  1129 	TRAP(res, iSecond = CTransWindow::NewL(iBackgroundWin, TRgb(255,0,0,128),&mode));
       
  1130 	if(res != KErrNone)
       
  1131 		{
       
  1132 		return res;
       
  1133 		}
       
  1134 
       
  1135 	TRAP(res, iFirst->SetExtL(thePos1.iTl,thePos1.Size()));
       
  1136 	if(res != KErrNone)
       
  1137 		{
       
  1138 		return res;
       
  1139 		}
       
  1140 
       
  1141 	TRAP(res, iSecond->SetExtL(thePos2.iTl,thePos2.Size()));
       
  1142 	if(res != KErrNone)
       
  1143 		{
       
  1144 		return res;
       
  1145 		}
       
  1146 
       
  1147 	res=SetTransparencyTesting();
       
  1148 	if(res != KErrNone)
       
  1149 		{
       
  1150 		return res;
       
  1151 		}
       
  1152 
       
  1153 	TheClient->Flush();
       
  1154 	//TheClient->WaitForRedrawsToFinish();
       
  1155 
       
  1156 	iFirst->Activate();
       
  1157 	iFirst->AssignGC(*TheClient->iGc);
       
  1158 
       
  1159 	iSecond->Activate();
       
  1160 	iSecond->AssignGC(*TheClient->iGc);
       
  1161 
       
  1162 	iFirst->Win()->SetBackgroundColor(TRgb(0, 0, 255));
       
  1163 	iSecond->Win()->SetBackgroundColor(TRgb(0, 0, 255));
       
  1164 	iFirst->Invalidate();
       
  1165 	iSecond->Invalidate();
       
  1166 	
       
  1167 	iFirst->AdjustSize(150,10, 0);
       
  1168 	iSecond->AdjustSize(150,10, 0);
       
  1169 
       
  1170 	TheClient->Flush();
       
  1171 	TheClient->WaitForRedrawsToFinish();
       
  1172 
       
  1173 	iFirst->ToggleVisibility();
       
  1174 	iSecond->ToggleVisibility();
       
  1175 
       
  1176 	TheClient->Flush();
       
  1177 	TheClient->WaitForRedrawsToFinish();
       
  1178 	
       
  1179 	iFirst->AdjustSize(200,10, 0);
       
  1180 	iSecond->AdjustSize(200,10, 0);
       
  1181 
       
  1182 	iFirst->ToggleVisibility();
       
  1183 	iSecond->ToggleVisibility();
       
  1184 
       
  1185 	TheClient->Flush();
       
  1186 	TheClient->WaitForRedrawsToFinish();
       
  1187 
       
  1188 	return KErrNone;
       
  1189 	}
       
  1190 
       
  1191 
       
  1192 // This function tests setting the transparency via a factor, CFbsBitmap
       
  1193 // or a CWsBitmap, and changing from one to the other.
       
  1194 TInt COomTranspWindow::SetTransparencyTesting()
       
  1195 	{
       
  1196 	TInt res;	
       
  1197 	TLogMessageText buf;
       
  1198 		
       
  1199 	// Need all nine transitions, from the 3 ways to the same 3 ways.
       
  1200 	// The ways are Factor, CWsBitmap, CFbsBitmap
       
  1201 	const TRgb KTransparencyFactor(128,128,128);
       
  1202 	res=iFirst->Win()->SetTransparencyFactor(KTransparencyFactor);
       
  1203 	if (res!=KErrNone)
       
  1204 		{
       
  1205 		buf=_L("test failure!! with SetTransparencyFactor -1");
       
  1206 		TheClient->LogMessage(buf);
       
  1207 		return res;
       
  1208 		}
       
  1209 			
       
  1210 	res=iFirst->Win()->SetTransparencyBitmap(*iFbsBitmap);
       
  1211 	if (res!=KErrNone)
       
  1212 		{
       
  1213 		buf=_L("test failure!! with SetTransparencyBitmap - fbs -2");
       
  1214 		TheClient->LogMessage(buf);
       
  1215 		return res;
       
  1216 		}			
       
  1217 		
       
  1218 	res=iFirst->Win()->SetTransparencyWsBitmap(*iWsBitmap);
       
  1219 	if (res!=KErrNone)
       
  1220 		{
       
  1221 		buf=_L("test failure!! with SetTransparencyBitmap - Ws -3");
       
  1222 		TheClient->LogMessage(buf);
       
  1223 		return res;
       
  1224 		}
       
  1225 				
       
  1226 	res=iFirst->Win()->SetTransparencyFactor(KTransparencyFactor);
       
  1227 	if (res!=KErrNone)
       
  1228 		{
       
  1229 		buf=_L("test failure!! with SetTransparencyBitmap - fbs -4");
       
  1230 		TheClient->LogMessage(buf);
       
  1231 		return res;
       
  1232 		}	
       
  1233 	res=iFirst->Win()->SetTransparencyWsBitmap(*iWsBitmap);
       
  1234 	if (res!=KErrNone)
       
  1235 		{
       
  1236 		buf=_L("test failure!! with SetTransparencyBitmap - Ws -5");
       
  1237 		TheClient->LogMessage(buf);
       
  1238 		return res;
       
  1239 		}
       
  1240 	res=iFirst->Win()->SetTransparencyWsBitmap(*iWsBitmap);
       
  1241 	if (res!=KErrNone)
       
  1242 		{
       
  1243 		buf=_L("test failure!! with SetTransparencyBitmap - Ws -6");
       
  1244 		TheClient->LogMessage(buf);
       
  1245 		return res;
       
  1246 		}			
       
  1247 		
       
  1248 	res=iFirst->Win()->SetTransparencyBitmap(*iFbsBitmap);
       
  1249 	if (res!=KErrNone)
       
  1250 		{
       
  1251 		buf=_L("test failure!! with SetTransparencyBitmap - fbs -7");
       
  1252 		TheClient->LogMessage(buf);
       
  1253 		return res;
       
  1254 		}	
       
  1255 		
       
  1256 	res=iFirst->Win()->SetTransparencyBitmap(*iFbsBitmap);
       
  1257 	if (res!=KErrNone)
       
  1258 		{
       
  1259 		buf=_L("test failure!! with SetTransparencyBitmap - fbs -8");
       
  1260 		TheClient->LogMessage(buf);
       
  1261 		return res;
       
  1262 		}
       
  1263 		
       
  1264 	res=iFirst->Win()->SetTransparencyFactor(KTransparencyFactor);
       
  1265 	if (res!=KErrNone)
       
  1266 		{
       
  1267 		buf=_L("test failure!! with SetTransparencyFactor -9");
       
  1268 		TheClient->LogMessage(buf);
       
  1269 		return res;
       
  1270 		}				
       
  1271 		
       
  1272 	res=iFirst->Win()->SetTransparencyFactor(KTransparencyFactor);
       
  1273 	if (res!=KErrNone)
       
  1274 		{
       
  1275 		buf=_L("test failure!! with SetTransparencyFactor -10");
       
  1276 		TheClient->LogMessage(buf);
       
  1277 		return res;
       
  1278 		}
       
  1279 					
       
  1280 	return res;
       
  1281 	}	
       
  1282 
       
  1283 void COomTranspWindow::ClearUpL()
       
  1284 	{
       
  1285 	delete iFirst;
       
  1286 	iFirst = NULL;
       
  1287 	delete iSecond;
       
  1288 	iSecond = NULL;
       
  1289 	delete iBackgroundWin;
       
  1290 	iBackgroundWin = NULL;
       
  1291 	}
       
  1292 
       
  1293 //
       
  1294 
       
  1295 CWindowWithOneLine* CWindowWithOneLine::NewL(CTWinBase& aParent, const TRect& aExtent)
       
  1296 	{
       
  1297 	CWindowWithOneLine* self = new(ELeave) CWindowWithOneLine;
       
  1298 	CleanupStack::PushL(self);
       
  1299 	self->ConstructL(aParent);
       
  1300 	const TSize screenSize(TheClient->iScreen->SizeInPixels());	
       
  1301 	self->SetExtL(aExtent.iTl, aExtent.Size());
       
  1302 	self->AssignGC(*TheClient->iGc);
       
  1303 	self->Activate();
       
  1304 	self->DrawNow();
       
  1305 	CleanupStack::Pop(self);
       
  1306 	return self;
       
  1307 	}
       
  1308 
       
  1309 void CWindowWithOneLine::Draw()
       
  1310 	{
       
  1311 	iGc->DrawLine(TPoint(0,0), TPoint(Size().iWidth, Size().iHeight));
       
  1312 	}
       
  1313 
       
  1314 //
       
  1315 
       
  1316 COomObscuredWindow::COomObscuredWindow(CTOom *aTest) : COomSetup(aTest)
       
  1317 	{}
       
  1318 
       
  1319 TOomTestName COomObscuredWindow::TestName()
       
  1320 	{
       
  1321 	return(_L("Obscured window"));
       
  1322 	}
       
  1323 
       
  1324 TInt COomObscuredWindow::Fail()
       
  1325 	{
       
  1326 	TRAPD(err, DoFailL());
       
  1327 	return err;
       
  1328 	}
       
  1329 
       
  1330 	
       
  1331 void COomObscuredWindow::DoFailL()
       
  1332 	{
       
  1333 #ifdef __WINS__
       
  1334 	RDebug::Print(_L("COomObscuredWindow::DoFailL - enter"));
       
  1335 #endif
       
  1336 	const TRect extent(20, 20, 100, 100);
       
  1337 	CBlankWindow* backgroundWindow = new(ELeave) CBlankWindow(TRgb(12, 23, 34));
       
  1338 	CleanupStack::PushL(backgroundWindow);
       
  1339 	TDisplayMode mode = EColor16MAP;
       
  1340 	backgroundWindow->SetUpL(extent.iTl, extent.Size(), TheClient->iGroup, *TheClient->iGc, &mode);
       
  1341 	
       
  1342 	CWindowWithOneLine* window = CWindowWithOneLine::NewL(*backgroundWindow, extent);
       
  1343 	CleanupStack::PushL(window);
       
  1344 #ifdef __WINS__
       
  1345 	RDebug::Print(_L("COomObscuredWindow - WaitForRedrawsToFinish - 1"));
       
  1346 #endif
       
  1347 	TheClient->WaitForRedrawsToFinish();
       
  1348 	
       
  1349 	CBlankWindow* obscuringWindow = new(ELeave) CBlankWindow(TRgb(255, 0, 0));
       
  1350 	CleanupStack::PushL(obscuringWindow);
       
  1351 	obscuringWindow->SetUpL(extent.iTl, extent.Size(), backgroundWindow, *TheClient->iGc, &mode);
       
  1352 
       
  1353 	TheClient->Flush();
       
  1354 #ifdef __WINS__
       
  1355     RDebug::Print(_L("COomObscuredWindow - WaitForRedrawsToFinish - 2"));
       
  1356 #endif
       
  1357 	TheClient->WaitForRedrawsToFinish();
       
  1358 
       
  1359 	window->Invalidate();
       
  1360 
       
  1361 	for(TInt i = 0; i < 50; i++)
       
  1362 		{
       
  1363 		RWindow anotherWin(iWs);
       
  1364 		User::LeaveIfError(anotherWin.Construct(iWinGroup, 11));
       
  1365 		anotherWin.Close();
       
  1366 		
       
  1367 		if(i % 4)
       
  1368 			window->Invalidate();
       
  1369 
       
  1370 		TheClient->Flush();
       
  1371 #ifdef __WINS__
       
  1372 	    RDebug::Print(_L("COomObscuredWindow - WaitForRedrawsToFinish - 3 - %d"), i);
       
  1373 #endif
       
  1374 	    TheClient->WaitForRedrawsToFinish();
       
  1375 		}
       
  1376 
       
  1377 	TheClient->Flush();
       
  1378 #ifdef __WINS__
       
  1379     RDebug::Print(_L("COomObscuredWindow - WaitForRedrawsToFinish - 4"));
       
  1380 #endif
       
  1381 	TheClient->WaitForRedrawsToFinish();
       
  1382 
       
  1383 	CleanupStack::PopAndDestroy(obscuringWindow);
       
  1384 	CleanupStack::PopAndDestroy(window);
       
  1385 	CleanupStack::PopAndDestroy(backgroundWindow);
       
  1386 #ifdef __WINS__
       
  1387     RDebug::Print(_L("COomObscuredWindow::DoFailL - exit"));
       
  1388 #endif
       
  1389 	}
       
  1390 
       
  1391 void COomObscuredWindow::ClearUpL()
       
  1392 	{
       
  1393 	}	
       
  1394 
       
  1395 //
       
  1396 
       
  1397 CTOom::CTOom(CTestStep* aStep) : CTWsGraphicsBase(aStep)
       
  1398 	{
       
  1399 	iState = 0;
       
  1400 	}
       
  1401 	
       
  1402 const TDesC& CTOom::TestName() const
       
  1403 	{
       
  1404 	_LIT(KTestName,"CTOom");
       
  1405 	return(KTestName());
       
  1406 	}
       
  1407 	
       
  1408 void CTOom::DoOomTestL(COomFailBase *aOomTest)
       
  1409 	{
       
  1410 	//TLogMessageText buf;
       
  1411 	TEST(aOomTest!=NULL);
       
  1412 	if (aOomTest==NULL)
       
  1413 		INFO_PRINTF1(_L("aOomTest - Expected: Not Null, Actual: NULL"));			
       
  1414 
       
  1415 	TRAPD(ret1,aOomTest->ConstructL());
       
  1416 	TEST(ret1==KErrNone);
       
  1417 	if (ret1!=KErrNone)
       
  1418 		INFO_PRINTF3(_L("aOomTest->ConstructL() return value - Expected: %d, Actual: %d"), KErrNone, ret1);			
       
  1419 
       
  1420 	aOomTest->Flush();
       
  1421 	__UHEAP_MARK;
       
  1422 //	TInt oldCount=TheClient->iWs.HeapCount();
       
  1423 	for(TInt mode=0;mode<3;mode++)
       
  1424 		{
       
  1425 		/*buf.Format(_L("OOMTest[%d] Mode=%d"),iState,mode),
       
  1426 		TheClient->LogMessage(buf);*/
       
  1427 		TInt successCount=0;
       
  1428 		for(TInt count=1;;count++)
       
  1429 			{
       
  1430 			TInt ret;
       
  1431 			aOomTest->PreFail();
       
  1432 			if (mode==0)
       
  1433 				TheClient->iWs.HeapSetFail(RHeap::EDeterministic,count);
       
  1434 			else if (mode==1)
       
  1435 				TheClient->iWs.HeapSetBurstFail(RHeap::EBurstFailNext, count, KMaxTUint16);
       
  1436 			else if (mode==3)
       
  1437 				{
       
  1438 				__UHEAP_SETFAIL(RHeap::EDeterministic,count);	//Leavescan will complain about EFailNext, although it isn't a leaving function
       
  1439 				}
       
  1440 			ret=aOomTest->Fail();
       
  1441 			if (mode==0)
       
  1442 				TheClient->iWs.HeapSetFail(RHeap::ENone,0);
       
  1443 			else if (mode==1)
       
  1444 				TheClient->iWs.HeapSetBurstFail(RHeap::ENone, 0, 0);
       
  1445 			else if (mode==2)
       
  1446 				{
       
  1447 				__UHEAP_RESET;
       
  1448 				}
       
  1449 			aOomTest->ClearUpL();  //In just 1 case this could leave...
       
  1450 			aOomTest->Flush();
       
  1451 			if (ret==KErrNone)
       
  1452 				{
       
  1453 				if (successCount==10)
       
  1454 					break;
       
  1455 				successCount++;
       
  1456 				}
       
  1457 			else
       
  1458 				{
       
  1459 				/*if (successCount>0)
       
  1460 					{
       
  1461 					buf.Format(_L("[%d,%d] Count=%d, MaxSuccess=%d"),iState,mode,count,successCount);
       
  1462 					TheClient->LogMessage(buf);
       
  1463 					}*/
       
  1464 				successCount=0;
       
  1465 				/*if (ret!=KErrNoMemory)
       
  1466 					{
       
  1467 					buf.Format(_L("[%d,%d] Fail, Count=%d, Error=%d"),iState,mode,count,ret);
       
  1468 					TheClient->LogMessage(buf);
       
  1469 					}*/
       
  1470 				TEST(ret==KErrNoMemory);
       
  1471 				if (ret!=KErrNoMemory)
       
  1472 					INFO_PRINTF3(_L("aOomTest->Fail() return value - Expected: %d, Actual: %d"), KErrNoMemory, ret);			
       
  1473 
       
  1474 				}
       
  1475 			}
       
  1476 		/*buf.Format(_L("[%d,%d] LastCount=%d"),iState,mode,count),
       
  1477 		TheClient->LogMessage(buf);*/
       
  1478 		}
       
  1479 //	TEST(oldCount>=TheClient->iWs.HeapCount());
       
  1480 	__UHEAP_MARKEND;
       
  1481 	delete aOomTest;
       
  1482 	/*buf.Format(_L("OOMTest[%d] Finished"),iState);
       
  1483 	TheClient->LogMessage(buf);*/
       
  1484 	}
       
  1485 
       
  1486 void CTOom::ConstructL()
       
  1487 	{
       
  1488 	iShieldWin=RBlankWindow(TheClient->iWs);
       
  1489 	User::LeaveIfError(iShieldWin.Construct(*(TheClient->iGroup->GroupWin()),1));
       
  1490 //	iShieldWin.SetOrdinalPosition(0,-1);
       
  1491 	iShieldWin.Activate();
       
  1492 	}
       
  1493 
       
  1494 CTOom::~CTOom()
       
  1495 	{
       
  1496 	iShieldWin.Close();
       
  1497 	}
       
  1498 
       
  1499 /**
       
  1500 @SYMTestCaseID		GRAPHICS-WSERV-0124
       
  1501 
       
  1502 @SYMDEF             DEF081259
       
  1503 
       
  1504 @SYMTestCaseDesc    Out of memory tests
       
  1505 
       
  1506 @SYMTestPriority    High
       
  1507 
       
  1508 @SYMTestStatus      Implemented
       
  1509 
       
  1510 @SYMTestActions     Uses deterministic heap failure mode to test WSERV classes against out-of-memory errors.
       
  1511 					Sets and unsets deterministic mode using both RWsSession.HeapSetFail() methods and
       
  1512 					__UHEAP_SETFAIL/__UHEAP_RESET macros (doing this both client and WSERV threads are tested). 
       
  1513 					On each step the test creates a failure object and repeatedly asks it to do some work (calling Fail() method).
       
  1514 					A failure object is an object which encapsulates some allocation functionality inside it's Fail() method.
       
  1515 					The test is performed for 23 different failure objects that do the following:
       
  1516 						1. Creates a wserv session, connects and creates CWsScreenDevice object.
       
  1517 						2. Creates a RWindowGroup object.
       
  1518 						3. Creates a RWindow object.
       
  1519 						4. Creates a RBackedUpWindow object.
       
  1520 						5. Sets the size of previously created backed-up window.
       
  1521 						6. Creates a RBlankWindow object.
       
  1522 						7. Allocates a buffer for storing pointer movements for a previously created backed-up window.
       
  1523 						8. Adds a priority key for a previously created window group.
       
  1524 						9. Requests a capture keys for a previously created window group.
       
  1525 						10. Requests the capture of key-up and key-down events for a previously created window group.
       
  1526 						11. Sets hot key for the session.
       
  1527 						12. Sets the window group's name.
       
  1528 						13. Sends a message to another window group.
       
  1529 						14. Fetches a message.
       
  1530 						15. Enables window group change events and modifier change events.
       
  1531 						16. Copies screen to bitmap.
       
  1532 						17. Creates a sprite.
       
  1533 						18. Creates a pointer cursor.
       
  1534 						19. Creates a graphical context for a previously created screen device.
       
  1535 						20. Draws a polygon.
       
  1536 						21. Creates a screen device handle.
       
  1537 						22. Adds a custom text cursor to the server's list of cursors.
       
  1538 						23. Does nothing if transparency is not enabled. Creates a blank window with 
       
  1539 							two transparent child-windows. Tests setting the transparency via a factor, CFbsBitmap
       
  1540 							or a CWsBitmap, and changing from one to the other.
       
  1541 							Changes child-windows' sizes and toggles their visibility.
       
  1542 					
       
  1543 
       
  1544 @SYMTestExpectedResults The test checks that the creation failure objects doesn't fail and their's work either causes no errors or causes KErrNoMemory error.
       
  1545 */
       
  1546 void CTOom::RunTestCaseL(TInt /*aCurTestCase*/) 
       
  1547 	{
       
  1548 	((CTOomStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0124"));
       
  1549 	if (iState==0)
       
  1550 		{
       
  1551 		// commented by Anton Golovko, 01.03.2006 while converting to TEF
       
  1552 		// the code below prevented the test to do anything.
       
  1553 //		if (iTest->IsFullRomL()) 
       
  1554 //			{
       
  1555 //			TestComplete();
       
  1556 //			return;
       
  1557 //			}
       
  1558 		iOldCount=TheClient->iWs.HeapCount();
       
  1559 		}
       
  1560 	else if (iState==sizeof(CreateOomFailTest)/sizeof(CreateOomFailTest[0]))
       
  1561 		{
       
  1562 		iTest->CloseAllPanicWindows();
       
  1563 		TInt heapCount=TheClient->iWs.HeapCount();
       
  1564 		if (heapCount>iOldCount)
       
  1565 			{
       
  1566 			TEST(iOldCount>=heapCount-184);		//For some uninvestigated reason 184 object get allocated on the server side, partly because of INFO_PRINTF1
       
  1567 			if (iOldCount<heapCount-184)
       
  1568 					INFO_PRINTF3(_L("iOldCount>=heapCount-174 - Expected: %d, Actual: %d"), heapCount-184, iOldCount);			
       
  1569 
       
  1570 			}
       
  1571 		((CTOomStep*)iStep)->CloseTMSGraphicsStep();
       
  1572 		TestComplete();
       
  1573 		return;
       
  1574 		}
       
  1575 	DoOomTestL(CreateOomFailTest[iState++](this));
       
  1576 	((CTOomStep*)iStep)->RecordTestResultL();
       
  1577 	}
       
  1578 	
       
  1579 	
       
  1580 	
       
  1581 	
       
  1582 __WS_CONSTRUCT_STEP__(Oom)
       
  1583