os/graphics/graphicscomposition/surfaceupdate/tsrc/tsurfaceupdate.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-2010 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 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 #include <e32std.h>
    23 #include <hal.h>
    24 #include <u32hal.h>
    25 
    26 #include <graphics/surfaceupdateclient.h>
    27 #include <graphics/suerror.h>
    28 #include <limits.h>
    29 #include "surfaceupdatetest.h"
    30 #include "tsurfaceupdate.h"
    31 #include "surfaceupdate.h"
    32 
    33 
    34 CTSurfaceUpdate::CTSurfaceUpdate(CTestStep* aStep) :
    35 	CTGraphicsBase(aStep)
    36 	{
    37 	}
    38 
    39 CTSurfaceUpdate::~CTSurfaceUpdate()
    40 	{
    41 	while (iReceivers.Count())
    42 		{
    43 		CTContentUpdateReceiver *receiver = iReceivers[0];
    44 		iReceivers.Remove(0);
    45 		CloseTestUpdateReceiver(receiver);
    46 		}
    47 	iReceivers.Reset();	
    48 	}
    49 
    50 void CTSurfaceUpdate::ConstructL()
    51 	{
    52 	SetupContentUpdateReceiversL();
    53 	}
    54 
    55 void CTSurfaceUpdate::SetupContentUpdateReceiversL()
    56 	{
    57 	//first receiver
    58 	CTContentUpdateReceiver *receiver;
    59 	User::LeaveIfError(StartTestUpdateReceiver(receiver, 1));
    60 	iReceivers.AppendL(receiver);
    61 	
    62 	//second receiver
    63 	CTContentUpdateReceiver *receiver2;
    64 	User::LeaveIfError(StartTestUpdateReceiver(receiver2, 2));
    65 	iReceivers.AppendL(receiver2);
    66 	
    67 	//third receiver
    68 	CTContentUpdateReceiver *receiver3;
    69 	User::LeaveIfError(StartTestUpdateReceiver(receiver3, 3));
    70 	iReceivers.AppendL(receiver3);
    71 	
    72 	User::LeaveIfError(Provider()->Register(0, receiver, -1));
    73 	User::LeaveIfError(Provider()->Register(1, receiver2, 1));
    74 	User::LeaveIfError(Provider()->Register(2, receiver3, 2));
    75 	}
    76 
    77 /**
    78   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0001
    79 
    80 
    81   @SYMPREQ 1007
    82 
    83   @SYMREQ 8223
    84 
    85   @SYMTestCaseDesc Initialization of the server environment twice.
    86 
    87   @SYMTestPriority High
    88 
    89   @SYMTestStatus Implemented
    90 
    91   @SYMTestActions Attempt to start the server for the second time.
    92 
    93   @SYMTestExpectedResults Must return KErrAlreadyExists.
    94 */
    95 void CTSurfaceUpdate::TestCase1()
    96 	{
    97 	INFO_PRINTF1(_L("Attempt to start the server for the second time"));
    98 	MSurfaceUpdateServerProvider *surfaceUpdateProvider = NULL;
    99 	TInt res = StartSurfaceUpdateServer(surfaceUpdateProvider);
   100 	TEST(res==KErrNone);
   101 	TEST(surfaceUpdateProvider!=NULL);
   102 	TEST(surfaceUpdateProvider==Provider());
   103 	}
   104 
   105 /**
   106   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0002
   107 
   108   @SYMPREQ 1007
   109 
   110   @SYMREQ 8223
   111 
   112   @SYMTestCaseDesc Submit update commands and subscribe for notifications. 
   113 
   114   @SYMTestPriority High
   115 
   116   @SYMTestStatus Implemented
   117 
   118   @SYMTestActions Create connection to the server. 
   119   		Subscribe for different notifications (consumed, displayed, displayedXTimes). 
   120   		Submit update command. Wait for notifications to arrive. 
   121   		Repeat for a few times in a row .
   122 
   123   @SYMTestExpectedResults Errors, which will be conveyed in 
   124   TRequestStatus must be equal to KErrNone. The order must be consistent with 
   125   before and after submission (Before submission < composition < after submission). 
   126 */
   127 void CTSurfaceUpdate::TestCase2L()
   128 	{
   129 	INFO_PRINTF1(_L("Submit update and subscribe for notifications"));
   130 	const TInt KMaxSubmissionNumber = 60; //it should be divisible by 3!
   131 	RSurfaceUpdateSession session;
   132 	TInt res = session.Connect();
   133 	User::LeaveIfError(res);
   134 	
   135 	iSurfaceOrder = CRequestOrder::NewL(KMaxSubmissionNumber);
   136 	    
   137 	iReceivers[0]->SetCompositionOrder(iSurfaceOrder);
   138 	iReceivers[1]->SetCompositionOrder(iSurfaceOrder);
   139 	iReceivers[2]->SetCompositionOrder(iSurfaceOrder);
   140 	
   141 	TInt screen = 0;
   142 	TInt buffer = 2;
   143 	TSurfaceId surface = 
   144 		{
   145 		1,2,3,4
   146 		};
   147 	TRect rc[2] =
   148 			{
   149 			TRect(1,2, 10, 20),
   150 			TRect(5,6, 30, 30)
   151 			};
   152 	RRegion region(2, rc);
   153 
   154 	// Test that submitting for an update before any noitfications causes no problems
   155 	TEST(KErrNone == session.SubmitUpdate(screen, surface, buffer, &region));
   156 
   157 	iSurfaceOrder->ResetAll();
   158 	for(TInt submissionNumber = 0; submissionNumber < KMaxSubmissionNumber/3; submissionNumber++)
   159 		{
   160 		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   161 
   162 		TRequestStatus status = KRequestPending;
   163 		TRequestStatus status1 = KRequestPending;
   164 		TRequestStatus status2 = KRequestPending;
   165 		TTimeStamp timeStamp; 
   166 	
   167 		iSurfaceOrder->SetOrder(EOrderBefore);
   168 		session.NotifyWhenAvailable(status);	
   169 		session.NotifyWhenDisplayed(status1, timeStamp);	
   170 		session.NotifyWhenDisplayedXTimes(10, status2);
   171 		
   172 		res = session.SubmitUpdate(screen, surface, buffer, &region);
   173 		TEST(res==KErrNone);
   174 		
   175 		User::WaitForRequest(status);
   176 		User::WaitForRequest(status1);
   177 		User::WaitForRequest(status2);
   178 		iSurfaceOrder->SetOrder(EOrderAfter);
   179 
   180 		TEST(status == KErrNone);
   181 		TEST(status1 == KErrNone);
   182 		TEST(status2 == KErrNone);
   183 		}
   184 	
   185     for(TInt i=0; i < KMaxSubmissionNumber/3; i++)
   186         {
   187         TInt positionBefore=-1;
   188         TInt positionComposition=-1;
   189         TInt positionAfter=-1;
   190         for(TInt j=0; j < KMaxSubmissionNumber; j++)
   191             {
   192             if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderBefore))
   193                 {
   194                 positionBefore=j;
   195                 }
   196             
   197             if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderComposition))
   198                 {
   199                 positionComposition=j;
   200                 }
   201                 
   202             if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderAfter))
   203                 {
   204                 positionAfter=j;
   205                 }
   206             }
   207         TEST((positionBefore != -1) && (positionComposition != -1) && (positionAfter != -1));
   208         TEST(positionBefore < positionComposition);
   209         TEST(positionAfter > positionComposition);
   210         }
   211 	
   212 	delete iSurfaceOrder;
   213 	iSurfaceOrder = NULL;
   214 	iReceivers[0]->SetCompositionOrder(NULL);
   215 	iReceivers[1]->SetCompositionOrder(NULL);
   216 	iReceivers[2]->SetCompositionOrder(NULL);
   217 	
   218 	session.Close();
   219 	}
   220 
   221 /**
   222   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0003
   223 
   224   @SYMPREQ 1007
   225   
   226   @SYMREQ 8223
   227 
   228   @SYMTestCaseDesc Submit a few requests, then consume them. 
   229 
   230   @SYMTestPriority High
   231 
   232   @SYMTestStatus Implemented
   233 
   234   @SYMTestActions A. Request notifications of the same type consecutively 
   235   	(no submit in-between) and check that the behaviour is correct.
   236     B. Create connection to the server with sufficient number of 
   237   	outstanding asynchronous message slots. 
   238   	1. Subscribe for different notifications (consumed, displayed, 
   239   	displayedXTimes). 
   240   	2. Submit update command. 
   241   	3 Repeat step 1 & 2 a few times. 
   242   	Wait for notifications (from all requests) to arrive. 
   243   	Repeat 1& 2 & 3 a few times in a row
   244 
   245   @SYMTestExpectedResults A. The last of each notification request type 
   246   to be issued before the submission will return with KErrNone, as will 
   247   the SubmitUpdate. B. Errors, which will be conveyed in TRequestStatus 
   248   must be equal to KErrNone. The order must be consistent with 
   249   before and after submission (Before submission < composition < after submission).  
   250 */
   251 void CTSurfaceUpdate::TestCase3L()
   252 	{
   253 	INFO_PRINTF1(_L("Submission a few update requests in  a row, then waiting for notifications to arrive"));
   254 	RSurfaceUpdateSession session;
   255 	
   256 	const TInt KNumberAsynchronousRequests = 42; //it should be divisible by 3!
   257 	TInt res = session.Connect(KNumberAsynchronousRequests);
   258 	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests as: %d"), KNumberAsynchronousRequests);	
   259 	User::LeaveIfError(res);
   260 	
   261 	iSurfaceOrder = CRequestOrder::NewL(KNumberAsynchronousRequests);
   262 	
   263 	iReceivers[0]->SetCompositionOrder(iSurfaceOrder);
   264 	iReceivers[1]->SetCompositionOrder(iSurfaceOrder);
   265 	iReceivers[2]->SetCompositionOrder(iSurfaceOrder);
   266 	
   267 	TInt screen = 0;
   268 	TInt screen1 = 1;
   269 	TInt buffer = 2;
   270 	TSurfaceId surface = 
   271 		{
   272 		1,2,3,4
   273 		};
   274 	
   275 	TRect rc[] =
   276 			{
   277 			TRect(1,2, 3, 4),
   278 			TRect(5,6, 7, 8),
   279 			TRect(9, 10, 11, 12),
   280 			TRect(13, 14, 15, 16),
   281 			};
   282 	RRegion region(4, rc);
   283 	
   284 	// Test calling two notifies in a row followed by a submit
   285 	TRequestStatus stat[6];
   286 	session.NotifyWhenAvailable(stat[0]);
   287 	session.NotifyWhenAvailable(stat[1]);
   288 	TTimeStamp tStamp[2];
   289 	session.NotifyWhenDisplayed(stat[2], tStamp[0]);
   290 	session.NotifyWhenDisplayed(stat[3], tStamp[1]);
   291 	session.NotifyWhenDisplayedXTimes(10, stat[4]);
   292 	session.NotifyWhenDisplayedXTimes(10, stat[5]);	
   293 	TEST(KErrNone == session.SubmitUpdate(0 , surface, buffer, &region));
   294 	// The last requests for notification will be fulfilled, the others ignored
   295 	User::WaitForRequest(stat[1]);
   296 	User::WaitForRequest(stat[3]);
   297 	User::WaitForRequest(stat[5]);	
   298 	TEST(stat[1] == KErrNone);
   299 	TEST(stat[3] == KErrNone);
   300 	TEST(stat[5] == KErrNone);
   301 	
   302 	// Submit a few requests, then consume them
   303 	for(TInt index1 = 0; index1 < 5; index1++)
   304 		{
   305 		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   306 
   307 		TRequestStatus status[KNumberAsynchronousRequests];
   308 		TTimeStamp timeStamp[KNumberAsynchronousRequests];
   309 		
   310 		// Reset all values
   311 		iSurfaceOrder->ResetAll();
   312 		
   313 		for(TInt index2 = 0; index2 < KNumberAsynchronousRequests; index2 += 3)
   314 			{
   315 			INFO_PRINTF2(_L("Submission number %d"), index2 / 3 + 1);	
   316 			status[index2]=KRequestPending;
   317 			session.NotifyWhenAvailable(status[index2]);	
   318 			status[index2 + 1]=KRequestPending;
   319 			session.NotifyWhenDisplayed(status[index2 + 1], timeStamp[index2 / 3]);	
   320 			status[index2 + 2]=KRequestPending;
   321 			session.NotifyWhenDisplayedXTimes(10, status[index2 + 2]);
   322 			
   323 			iSurfaceOrder->SetOrder(EOrderBefore);
   324 			
   325 			res = session.SubmitUpdate((index2 % 2) ? screen : screen1, surface, buffer, &region);
   326 			TEST(res==KErrNone);
   327 			}
   328 		
   329 		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests; submissionNumber++)
   330 			{
   331 			User::WaitForRequest(status[submissionNumber]);
   332 			TEST(status[submissionNumber] == KErrNone);
   333 			
   334 			if(((submissionNumber - 1) % 3) == 0)
   335 				{
   336 				iSurfaceOrder->SetOrder(EOrderAfter);
   337 				}
   338 			}
   339 		
   340 		for(TInt i=0; i < KNumberAsynchronousRequests/3; i++)
   341 			{
   342 			TInt positionBefore=-1;
   343 			TInt positionComposition=-1;
   344 			TInt positionAfter=-1;
   345 			for(TInt j=0; j < KNumberAsynchronousRequests; j++)
   346 				{
   347 				if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderBefore))
   348 					{
   349 					positionBefore=j;
   350 					}
   351 				
   352 				if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderComposition))
   353 					{
   354 					positionComposition=j;
   355 					}
   356 					
   357 				if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderAfter))
   358 					{
   359 					positionAfter=j;
   360 					}
   361 				}
   362 			TEST((positionBefore != -1) && (positionComposition != -1) && (positionAfter != -1));
   363 			TEST(positionBefore < positionComposition);
   364 			TEST(positionAfter > positionComposition);
   365 			}
   366 		}
   367 		
   368 	delete iSurfaceOrder;
   369 	iSurfaceOrder = NULL;
   370 	iReceivers[0]->SetCompositionOrder(NULL);
   371 	iReceivers[1]->SetCompositionOrder(NULL);
   372 	iReceivers[2]->SetCompositionOrder(NULL);
   373 	
   374 	session.Close();
   375 	}
   376 
   377 /**
   378   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0004
   379 
   380   @SYMPREQ 1007
   381   
   382   @SYMREQ 8223
   383 
   384   @SYMTestCaseDesc Cancellation of the requests. 
   385 
   386   @SYMTestPriority High
   387 
   388   @SYMTestStatus Implemented
   389 
   390   @SYMTestActions Create connection to the server.
   391   	1. Test cancellation without SubmitUpdate
   392     2. Check cancellation before submission does nothing bad.
   393   	3. Subscribe for different notifications (consumed, displayed, 
   394   	displayedXTimes). 
   395   	4. Submit update command. 5. Repeat steps 3 & 4 a few times. 
   396   	Cancel all outstanding notifications. Wait for cancelled notifications 
   397   	to arrive.
   398 
   399   @SYMTestExpectedResults Notifications must arrive straightway with 
   400   KErrCancel error code or KErrNone, if events have already occurred.
   401 */
   402 void CTSurfaceUpdate::TestCase4L()
   403 	{
   404 	INFO_PRINTF1(_L("Submission a few requests in a row and then cancelling them"));
   405 	RSurfaceUpdateSession session;
   406 	
   407 	const TInt KNumberAsynchronousRequests = 99; //should be divisible by 3!
   408 	TInt res = session.Connect(KNumberAsynchronousRequests);
   409 	INFO_PRINTF1(_L("Test CancelAllUpdateNotifications without SubmitUpdate"));
   410 	// Test CancelAllUpdateNotifications without SubmitUpdate
   411 	TRequestStatus status1, status2, status3;
   412 	TTimeStamp ts;
   413 	session.NotifyWhenAvailable(status1);
   414 	session.NotifyWhenDisplayed(status2, ts);
   415 	session.NotifyWhenDisplayedXTimes(5, status3);
   416 	session.CancelAllUpdateNotifications();
   417 	User::WaitForRequest(status1);
   418 	User::WaitForRequest(status2);
   419 	User::WaitForRequest(status3);
   420 	TEST(status1==KErrCancel);
   421 	TEST(status2==KErrCancel);
   422 	TEST(status3==KErrCancel);
   423 	
   424 	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests as: %d"), KNumberAsynchronousRequests);	
   425 	User::LeaveIfError(res);
   426 	
   427 	TInt screen = 0;
   428 	TInt screen1 = 1;
   429 	TInt buffer = 2;
   430 	TSurfaceId surface = 
   431 		{
   432 		1,2,3,4
   433 		};
   434 	TRect rc[] =
   435 			{
   436 			TRect(1,2, 3, 4),
   437 			TRect(5,6, 7, 8),
   438 			TRect(9, 10, 11, 12),
   439 			TRect(13, 14, 15, 16),
   440 			};
   441 	RRegion region(4, rc);
   442 	
   443 	// Check that cancelling notifications before any submission does nothing bad
   444 	session.CancelAllUpdateNotifications();
   445 	
   446 	for(TInt index1 = 0; index1 < 2; index1++)
   447 		{
   448 		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   449 
   450 		TRequestStatus status[KNumberAsynchronousRequests];
   451 		
   452 		TTimeStamp timeStamp[KNumberAsynchronousRequests];
   453 		TUint64 timestampComposition[KNumberAsynchronousRequests];
   454 		TUint64 timestampBefore[KNumberAsynchronousRequests];
   455 		TUint64 timestampAfter[KNumberAsynchronousRequests];
   456 		for(TInt index2 = 0; index2 < KNumberAsynchronousRequests; index2 += 3)
   457 			{
   458 			INFO_PRINTF2(_L("Submission number %d"), index2 / 3 + 1);	
   459 			status[index2]=KRequestPending;
   460 			session.NotifyWhenAvailable(status[index2]);	
   461 			status[index2 + 1]=KRequestPending;
   462 			session.NotifyWhenDisplayed(status[index2 + 1], timeStamp[index2 / 3]);	
   463 			status[index2 + 2]=KRequestPending;
   464 			session.NotifyWhenDisplayedXTimes(10, status[index2 + 2]);	
   465 			
   466 			timestampBefore[index2 / 3] = User::FastCounter();	
   467 			res = session.SubmitUpdate((index2 % 2) ? screen : screen1, surface, buffer, &region);
   468 			TEST(res==KErrNone);
   469 			}
   470 		TBool cancel=EFalse;
   471 		session.CancelAllUpdateNotifications();
   472 		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests; submissionNumber++)
   473 			{
   474 			User::WaitForRequest(status[submissionNumber]);
   475 			TEST((status[submissionNumber] == KErrCancel) || (status[submissionNumber] == KErrNone) );
   476 			if(status[submissionNumber] == KErrCancel)
   477 				{
   478 				cancel = ETrue;
   479 				}
   480 			
   481 			if((status[submissionNumber] == KErrNone) && ((submissionNumber - 1) % 3) == 0)
   482 				{
   483 				TInt index22 = submissionNumber / 3;
   484 				timestampAfter[index22] = User::FastCounter();	
   485 		
   486 				if(timestampAfter[index22] < timestampBefore[index22])
   487 					{
   488 					timestampAfter[index22] += UINT_MAX;
   489 					}
   490 				timestampComposition[index22] = timeStamp[index22]();
   491 				if(timestampComposition[index22] < timestampBefore[index22])
   492 					{
   493 					timestampComposition[index22] += UINT_MAX;
   494 					}
   495 
   496 				TEST(timestampComposition[index22] != 0);
   497 				TEST(timestampAfter[index22] >= timestampComposition[index22]);
   498 				TEST(timestampBefore[index22] <= timestampComposition[index22]);
   499 				}
   500 			}
   501 		TEST(cancel);		
   502 		}
   503 		session.Close();
   504 	}
   505 
   506 /**
   507   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0005
   508 
   509   @SYMPREQ 1007
   510   
   511   @SYMREQ 8223
   512 
   513   @SYMTestCaseDesc Submission from multiple sessions. 
   514 
   515   @SYMTestPriority High
   516 
   517   @SYMTestStatus Implemented
   518 
   519   @SYMTestActions Create a few connections to the server. For each connection: 
   520   		1. Subscribe for different notifications (consumed, displayed, 
   521   		displayedXTimes). 
   522   		2. Submit update command. Wait for notifications to arrive.
   523 
   524   @SYMTestExpectedResults Errors, which will be conveyed in 
   525   TRequestStatus must be equal to KErrNone. Timestamps must be consistent 
   526   with time before and after submissions.
   527 */
   528 void CTSurfaceUpdate::TestCase5L()
   529 	{
   530 	INFO_PRINTF1(_L("Submission a few update requests in  a row from different sessions, then waiting for notifications to arrive"));
   531 	
   532 	const TInt KNumberAsynchronousRequests = 9;
   533 	const TInt KNumberSessions = 5;
   534 	TInt res = KErrNone;	
   535 	
   536 	RSurfaceUpdateSession sessions[KNumberSessions];
   537 	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests per each session as: %d"), KNumberAsynchronousRequests);	
   538 	INFO_PRINTF2(_L("Set number of sessions: %d"), KNumberSessions);	
   539 	
   540 	TInt screen = 0;
   541 	TInt screen1 = 1;
   542 	TInt buffer = 2;
   543 	TSurfaceId surface = 
   544 		{
   545 		1,2,3,4
   546 		};
   547 	TRect rc[] =
   548 			{
   549 			TRect(1,2, 3, 4),
   550 			TRect(5,6, 7, 8),
   551 			TRect(9, 10, 11, 12),
   552 			TRect(13, 14, 15, 16),
   553 			};
   554 	RRegion region(4, rc);
   555 
   556 	TRequestStatus status[KNumberAsynchronousRequests * KNumberSessions];
   557 	
   558 	for(TInt index2 = 0; index2 < KNumberSessions; index2++)
   559 		{
   560 		res = sessions[index2].Connect(KNumberAsynchronousRequests);
   561 		User::LeaveIfError(res);
   562 		}
   563 	
   564 	for(TInt index1 = 0; index1 < 3; index1++)
   565 		{
   566 		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   567 
   568 		for(TInt index2 = 0; index2 < KNumberSessions; index2++)
   569 			{
   570 			TTimeStamp timeStamp;
   571 			INFO_PRINTF2(_L("Session number %d"), index2 + 1);	
   572 		 
   573 			for(TInt index3 = index2 * KNumberAsynchronousRequests; 
   574 					index3 < (index2 + 1) * KNumberAsynchronousRequests; index3 += 3)
   575 				{
   576 				INFO_PRINTF2(_L("Submission number %d"), index3 / 3 + 1);	
   577 				status[index3]=KRequestPending;
   578 				sessions[index2].NotifyWhenAvailable(status[index3]);	
   579 				status[index3 + 1]=KRequestPending;
   580 				sessions[index2].NotifyWhenDisplayed(status[index3 + 1], timeStamp);	
   581 				status[index3 + 2]=KRequestPending;
   582 				sessions[index2].NotifyWhenDisplayedXTimes(10, status[index3 + 2]);	
   583 				res = sessions[index2].SubmitUpdate((index3 % 2) ? screen : screen1, surface, buffer, &region);
   584 				if(res != KErrNone)
   585 				    {
   586 	                ERR_PRINTF2(_L("Returned SubmitUpdate code %d"), res);
   587 	                TEST(EFail);
   588 				    }
   589 				}
   590 			}
   591 
   592 		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests * KNumberSessions; submissionNumber++)
   593 			{
   594 			User::WaitForRequest(status[submissionNumber]);
   595 			if(status[submissionNumber] != KErrNone)
   596 			    {
   597 			    ERR_PRINTF2(_L("Returned request status %d"), status[submissionNumber].Int());
   598 			    TEST(EFail);
   599 			    }
   600 			}
   601 		}
   602 		
   603 	for(TInt index5 = 0; index5 < KNumberSessions; index5++)
   604 		{
   605 		sessions[index5].Close();
   606 		}
   607 	}
   608 
   609 /**
   610   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0023
   611 
   612 
   613   @SYMPREQ 1007/11596
   614 
   615   @SYMREQ 8223
   616 
   617   @SYMTestCaseDesc SubmitUpdate() to cope with Global Updates 
   618 
   619   @SYMTestPriority High
   620 
   621   @SYMTestStatus Implemented
   622 
   623   @SYMTestActions 
   624   		1.	Submit for a global update before subscribing for any notifications.
   625 		From this point onwards, all further cases assume that we’ve subscribed 
   626 		for different notifications (available, displayed, displayedXTimes) 
   627 		before submitting a global update:
   628 		2.	Submit a global update for a surface that is not visible on any screen.
   629 		3.	Submit a global update for a surface that is only visible on one screen.
   630 		4.	Submit a global update for a surface that is visible on different screens.
   631 
   632   @SYMTestExpectedResults 
   633   	1.	Submitting for an update before any notifications causes no problems.
   634 	2.	SubmitUpdate() signals KErrNotVisible
   635 	3.	TRequestStatus signals KErrNone in all cases. Timestamps must be valid.
   636 	4.	TRequestStatus signals KErrNone in all cases. Timestamps must be valid.
   637 */
   638 void CTSurfaceUpdate::TestCase15()
   639 	{
   640 	INFO_PRINTF1(_L("SubmitUpdate() to cope with Global Updates"));
   641 
   642 	RSurfaceUpdateSession session;
   643 	TInt res = session.Connect();
   644 	TEST(res == KErrNone);
   645 	
   646 	TInt buffer = 2;
   647 	TSurfaceId surface = 
   648 		{
   649 		1,2,3,4
   650 		};
   651 
   652 	// Test that submitting for an update before any noitfications causes no problems
   653 	TInt numReceivers = iReceivers.Count();
   654 
   655 	//make all screens invisible
   656 	INFO_PRINTF1(_L("make all screens invisible"));	
   657 	for(TInt index = 0; index < numReceivers; index++)
   658 		{
   659 		CTContentUpdateReceiver* receiver = iReceivers[index];
   660 		receiver->SetVisible(EFalse);
   661 		}
   662 	
   663 	for(TInt submissionNumber = 0; submissionNumber < 5; submissionNumber++)
   664 		{
   665 		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   666 
   667 		TRequestStatus status = KRequestPending;
   668 		TRequestStatus status1 = KRequestPending;
   669 		TRequestStatus status2 = KRequestPending;
   670 		TTimeStamp timeStamp; 
   671 	
   672 		session.NotifyWhenAvailable(status);	
   673 		session.NotifyWhenDisplayed(status1, timeStamp);	
   674 		session.NotifyWhenDisplayedXTimes(10, status2);
   675 		
   676 		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   677 		TEST(res==KErrNone);
   678 		
   679 		User::WaitForRequest(status);
   680 		User::WaitForRequest(status1);
   681 		User::WaitForRequest(status2);
   682 
   683 		TEST(status == KErrNotVisible);
   684 		TEST(status1 == KErrNotVisible);
   685 		TEST(status2 == KErrNotVisible);
   686 		}
   687 	
   688 	//make only one screen visible
   689 	CTContentUpdateReceiver* receiver = iReceivers[0];
   690 	receiver->SetVisible(ETrue);
   691 	INFO_PRINTF1(_L("Make visible one screen"));	
   692 
   693 	
   694 	for(TInt submissionNumber = 0; submissionNumber < 5; submissionNumber++)
   695 		{
   696 		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   697 
   698 		TRequestStatus status = KRequestPending;
   699 		TRequestStatus status1 = KRequestPending;
   700 		TRequestStatus status2 = KRequestPending;
   701 		TUint64 timestampComposition = 0;
   702 		TTimeStamp timeStamp; 
   703 	
   704 		TUint64 timestampBefore = User::FastCounter();
   705 
   706 		session.NotifyWhenAvailable(status);	
   707 		session.NotifyWhenDisplayed(status1, timeStamp);	
   708 		session.NotifyWhenDisplayedXTimes(10, status2);
   709 		
   710 		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   711 		TEST(res==KErrNone);
   712 		
   713 		User::WaitForRequest(status);
   714 		User::WaitForRequest(status1);
   715 		User::WaitForRequest(status2);
   716 
   717 		TUint64 timestampAfter = User::FastCounter();
   718 		if(timestampAfter < timestampBefore)
   719 			{
   720 			timestampAfter += UINT_MAX;
   721 			}
   722 		timestampComposition = timeStamp();
   723 		if(timestampComposition < timestampBefore)
   724 			{
   725 			timestampComposition += UINT_MAX;
   726 			}
   727 	
   728 		TEST(status == KErrNone);
   729 		TEST(status1 == KErrNone);
   730 		TEST(status2 == KErrNone);
   731 		
   732 		TEST(timestampComposition != 0);
   733 		TEST(timestampAfter >= timestampComposition);
   734 		TEST(timestampBefore <= timestampComposition);
   735 		
   736 		INFO_PRINTF2(_L("Time before composition: %lu"), timestampBefore);	
   737 		INFO_PRINTF2(_L("Time at composition: %lu"), timestampComposition);	
   738 		INFO_PRINTF2(_L("Time after composition: %lu"), timestampAfter);
   739 		}
   740 	
   741 	//make another screen visible
   742 	INFO_PRINTF1(_L("make another screen visible"));	
   743 	receiver->SetVisible(EFalse);
   744 	receiver = iReceivers[1];
   745 	receiver->SetVisible(ETrue);
   746 	
   747 	for(TInt submissionNumber = 0; submissionNumber < 5; submissionNumber++)
   748 		{
   749 		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   750 
   751 		TRequestStatus status = KRequestPending;
   752 		TRequestStatus status1 = KRequestPending;
   753 		TRequestStatus status2 = KRequestPending;
   754 		TUint64 timestampComposition = 0;
   755 		TTimeStamp timeStamp; 
   756 	
   757 		TUint64 timestampBefore = User::FastCounter();
   758 
   759 		session.NotifyWhenAvailable(status);	
   760 		session.NotifyWhenDisplayed(status1, timeStamp);	
   761 		session.NotifyWhenDisplayedXTimes(10, status2);
   762 		
   763 		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   764 		TEST(res==KErrNone);
   765 		
   766 		User::WaitForRequest(status);
   767 		User::WaitForRequest(status1);
   768 		User::WaitForRequest(status2);
   769 
   770 		TUint64 timestampAfter = User::FastCounter();
   771 		if(timestampAfter < timestampBefore)
   772 			{
   773 			timestampAfter += UINT_MAX;
   774 			}
   775 		timestampComposition = timeStamp();
   776 		if(timestampComposition < timestampBefore)
   777 			{
   778 			timestampComposition += UINT_MAX;
   779 			}
   780 	
   781 		TEST(status == KErrNone);
   782 		TEST(status1 == KErrNone);
   783 		TEST(status2 == KErrNone);
   784 		
   785 		TEST(timestampComposition != 0);
   786 		TEST(timestampAfter >= timestampComposition);
   787 		TEST(timestampBefore <= timestampComposition);
   788 		
   789 		INFO_PRINTF2(_L("Time before composition: %lu"), timestampBefore);	
   790 		INFO_PRINTF2(_L("Time at composition: %lu"), timestampComposition);	
   791 		INFO_PRINTF2(_L("Time after composition: %lu"), timestampAfter);
   792 		}
   793 	
   794 	//make all screens visible
   795 	for(TInt index = 0; index < numReceivers; index++)
   796 		{
   797 		CTContentUpdateReceiver* receiver = iReceivers[index];
   798 		receiver->SetVisible(ETrue);
   799 		}
   800 
   801 	session.Close();
   802 	}
   803 
   804 
   805 /**
   806   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0024
   807 
   808   @SYMPREQ 1007/11596
   809 
   810   @SYMREQ 8223
   811 
   812   @SYMTestCaseDesc CancelAllUpdateNotifications() to deal with global updates 
   813   correctly. 
   814 
   815   @SYMTestPriority High
   816 
   817   @SYMTestStatus Implemented
   818 
   819   @SYMTestActions 
   820   		The test consists of a single surface, visible on screens A (master), B & C. 
   821 		The test will submit for different notifications (available, displayed, 
   822 		displayedXTimes) and then submit a global update. 
   823 		These actions will be repeated a number of times.
   824 		Finally, the test will cancel all outstanding notifications via 
   825 		CancelAllUpdateNotifications() and wait for the cancelled notifications to arrive.
   826   		
   827   @SYMTestExpectedResults 
   828   	Notifications to arrive straight away with KErrCancel, otherwise with 
   829   	KErrNone if the events have already occurred.
   830 */
   831 void CTSurfaceUpdate::TestCase16L()
   832 	{
   833 	INFO_PRINTF1(_L("CancelAllUpdateNotifications() to deal with global updates correctly"));
   834 	RSurfaceUpdateSession session;
   835 	
   836 	const TInt KNumberAsynchronousRequests = 33; //should be divisible by 3!
   837 	TInt res = session.Connect(KNumberAsynchronousRequests);
   838 	INFO_PRINTF1(_L("Test CancelAllUpdateNotifications without SubmitUpdate"));
   839 	// Test CancelAllUpdateNotifications without SubmitUpdate
   840 	TRequestStatus status1, status2, status3;
   841 	TTimeStamp ts;
   842 	
   843 	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests as: %d"), KNumberAsynchronousRequests);	
   844 	User::LeaveIfError(res);
   845 	
   846 	TInt buffer = 2;
   847 	TSurfaceId surface = 
   848 		{
   849 		1,2,3,4
   850 		};
   851 	
   852 	for(TInt index1 = 0; index1 < 2; index1++)
   853 		{
   854 		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   855 
   856 		TRequestStatus status[KNumberAsynchronousRequests];
   857 		
   858 		TTimeStamp timeStamp[KNumberAsynchronousRequests];
   859 		TUint64 timestampComposition[KNumberAsynchronousRequests];
   860 		TUint64 timestampBefore[KNumberAsynchronousRequests];
   861 		TUint64 timestampAfter[KNumberAsynchronousRequests];
   862 		for(TInt index2 = 0; index2 < KNumberAsynchronousRequests; index2 += 3)
   863 			{
   864 			INFO_PRINTF2(_L("Submission number %d"), index2 / 3 + 1);	
   865 			status[index2]=KRequestPending;
   866 			session.NotifyWhenAvailable(status[index2]);	
   867 			status[index2 + 1]=KRequestPending;
   868 			session.NotifyWhenDisplayed(status[index2 + 1], timeStamp[index2 / 3]);	
   869 			status[index2 + 2]=KRequestPending;
   870 			session.NotifyWhenDisplayedXTimes(10, status[index2 + 2]);	
   871 			
   872 			timestampBefore[index2 / 3] = User::FastCounter();	
   873 			res = session.SubmitUpdate(KAllScreens, surface, buffer);
   874 			TEST(res==KErrNone);
   875 			}
   876 		TBool cancel=EFalse;
   877 		session.CancelAllUpdateNotifications();
   878 		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests; submissionNumber++)
   879 			{
   880 			User::WaitForRequest(status[submissionNumber]);
   881 			TEST((status[submissionNumber] == KErrCancel) || (status[submissionNumber] == KErrNone) );
   882 			if(status[submissionNumber] == KErrCancel)
   883 				{
   884 				cancel = ETrue;
   885 				}
   886 			
   887 			if((status[submissionNumber] == KErrNone) && ((submissionNumber - 1) % 3) == 0)
   888 				{
   889 				TInt index22 = submissionNumber / 3;
   890 				timestampAfter[index22] = User::FastCounter();	
   891 		
   892 				if(timestampAfter[index22] < timestampBefore[index22])
   893 					{
   894 					timestampAfter[index22] += UINT_MAX;
   895 					}
   896 				timestampComposition[index22] = timeStamp[index22]();
   897 				if(timestampComposition[index22] < timestampBefore[index22])
   898 					{
   899 					timestampComposition[index22] += UINT_MAX;
   900 					}
   901 
   902 				TEST(timestampComposition[index22] != 0);
   903 				TEST(timestampAfter[index22] >= timestampComposition[index22]);
   904 				TEST(timestampBefore[index22] <= timestampComposition[index22]);
   905 				}
   906 			}
   907 		TEST(cancel);		
   908 		}
   909 		session.Close();
   910 	}
   911 
   912 /**
   913   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0027
   914 
   915   @SYMPREQ 1007/11598
   916 
   917   @SYMREQ 8223
   918 
   919   @SYMTestCaseDesc NotifyWhenAvailable() to deal with global updates and be signalled correctly
   920   @SYMTestPriority High
   921 
   922   @SYMTestStatus Implemented
   923 
   924   @SYMTestActions 
   925 	The test consists of a single surface, visible on screens B (master) and C, 
   926 	but not visible on A. 
   927 	1. Screens are ordered in the following priority : A > B > C
   928 	2. Set priority of the receiver threads as follows A < B < C.
   929 	3. Set receiver A invisible.
   930 	4. Make global submit update with notify when displayed and notify 
   931 	when displayed X times.
   932 	5. Repeat step 4 a few times.
   933   		
   934   @SYMTestExpectedResults 
   935   	Notification to arrive with error code KErrNone initiated by the 
   936   	master display.
   937 */
   938 void CTSurfaceUpdate::TestCaseNotifyWhenAvailableGlobal()
   939 	{
   940 	INFO_PRINTF1(_L("NotifyWhenAvailable() to deal with global updates and be signalled correctly"));
   941 
   942 	RSurfaceUpdateSession session;
   943 	TInt res = session.Connect();
   944 	TEST(res == KErrNone);
   945 	
   946 	TInt buffer = 2;
   947 	TSurfaceId surface = 
   948 		{
   949 		1,2,3,4
   950 		};
   951 
   952 	TEST(iReceivers[2]->OutstandingRequest()==EFalse);
   953 	TEST(iReceivers[1]->OutstandingRequest()==EFalse);
   954 	TEST(iReceivers[0]->OutstandingRequest()==EFalse);
   955 	
   956 	//change the order.
   957 	//higher screen number means that the screen is higher priority. 
   958 	//So Receiver0 is lowest screen priority
   959 	res = iReceivers[2]->SetInternalPriority(EPriorityLess);
   960 	TEST(res == KErrNone);
   961 	res = iReceivers[1]->SetInternalPriority(EPriorityNormal);
   962 	TEST(res == KErrNone);
   963 	res = iReceivers[0]->SetInternalPriority(EPriorityAbsoluteHighNormal);
   964 	TEST(res == KErrNone);
   965 	iReceivers[2]->SetVisible(EFalse);
   966 	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
   967 	
   968 	for(TInt submissionNumber = 0; submissionNumber < 20; submissionNumber++)
   969 		{
   970 		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   971 
   972 		TRequestStatus status = KRequestPending;
   973 	
   974 		session.NotifyWhenAvailable(status);	
   975 		
   976 		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   977 		TEST(res==KErrNone);
   978 		
   979 		User::WaitForRequest(status);
   980 
   981 		TEST(status == KErrNone);
   982 		TEST(iReceivers[2]->OutstandingRequest()==EFalse);
   983 		TEST(iReceivers[1]->OutstandingRequest()==EFalse);
   984 		TEST(iReceivers[0]->OutstandingRequest()==EFalse);
   985 		}
   986 
   987 	//restore envorienment
   988 	iReceivers[0]->SetInternalPriority(EPriorityNormal);
   989 	iReceivers[1]->SetInternalPriority(EPriorityNormal);
   990 	iReceivers[2]->SetInternalPriority(EPriorityNormal);
   991 	iReceivers[2]->SetVisible(ETrue);
   992 	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
   993 	WaitUntilAllNotificationsProcessed();
   994 	session.Close();
   995 	}
   996 
   997 /**
   998   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0028
   999 
  1000   @SYMPREQ 1007/11599, 1007/11600, 1007/11601
  1001 
  1002   @SYMREQ 8223
  1003 
  1004   @SYMTestCaseDesc NotifyWhenDisplayed() & NotifyWhenDisplayedXTimes() to deal with global updates and be signalled correctly
  1005   @SYMTestPriority High
  1006 
  1007   @SYMTestStatus Implemented
  1008 
  1009   @SYMTestActions 
  1010 	The test consists of a single surface, visible on screens B (master) and C, but not visible on A. 
  1011 	1. Screens are ordered in the following priority : A > B > C.
  1012 	2. Set priority of the receiver threads as follows A < B < C.
  1013 	3. Set receiver A invisible.
  1014 	4. Make global submit update with notify when displayed and notify when displayed X times.
  1015 	Repeat step 4 a few times.
  1016 
  1017 	5. Screens are ordered in the following priority : A > B > C.
  1018 	6. Set priority of the receiver threads as follows A > B > C.
  1019 	7. Set receiver A invisible.
  1020 	8. Make global submit update with notify when displayed and notify when displayed X times.
  1021 	Repeat step 4 a few times.
  1022 
  1023   		
  1024   @SYMTestExpectedResults 
  1025   	Notification to arrive with error code KErrNone initiated by the master display.
  1026   	There is no outstanding request for receiver A & B after steps 4 and 8.
  1027 */
  1028 void CTSurfaceUpdate::TestCase17()
  1029 	{
  1030 	INFO_PRINTF1(_L("NotifyWhenDisplayed() && NotifyWhenDisplayedXTimes() to deal with global updates and be signalled correctly"));
  1031 
  1032 	RSurfaceUpdateSession session;
  1033 	TInt res = session.Connect();
  1034 	TEST(res == KErrNone);
  1035 	
  1036 	TInt buffer = 2;
  1037 	TSurfaceId surface = 
  1038 		{
  1039 		1,2,3,4
  1040 		};
  1041 	
  1042 //change the order, receiver with highest priority has a lowest internal priority 
  1043 	res = iReceivers[2]->SetInternalPriority(EPriorityLess);
  1044 	TEST(res == KErrNone);
  1045 	res = iReceivers[1]->SetInternalPriority(EPriorityNormal);
  1046 	TEST(res == KErrNone);
  1047 	res = iReceivers[0]->SetInternalPriority(EPriorityAbsoluteHighNormal);
  1048 	TEST(res == KErrNone);
  1049 	iReceivers[2]->SetVisible(EFalse);
  1050 	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority setting takes place
  1051 	
  1052 	for(TInt submissionNumber = 0; submissionNumber < 10; submissionNumber++)
  1053 		{
  1054 		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
  1055 
  1056 		TRequestStatus status = KRequestPending;
  1057 		TRequestStatus status1 = KRequestPending;
  1058 		TTimeStamp timeStamp; 
  1059 	
  1060 		session.NotifyWhenDisplayed(status, timeStamp);	
  1061 		session.NotifyWhenDisplayedXTimes(10, status1);
  1062 		
  1063 		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  1064 		TEST(res==KErrNone);
  1065 		
  1066 		User::WaitForRequest(status);
  1067 		User::WaitForRequest(status1);
  1068 
  1069 		TEST(status == KErrNone);
  1070 		TEST(status1 == KErrNone);
  1071 		TEST(iReceivers[0]->OutstandingRequest() == EFalse);
  1072 		TEST(iReceivers[1]->OutstandingRequest() == EFalse);
  1073 		TEST(iReceivers[2]->OutstandingRequest() == EFalse);
  1074 		}
  1075 
  1076 	//change the order, receiver with highest priority has a highest internal priority 
  1077 		res = iReceivers[0]->SetInternalPriority(EPriorityLess);
  1078 		TEST(res == KErrNone);
  1079 		res = iReceivers[1]->SetInternalPriority(EPriorityNormal);
  1080 		TEST(res == KErrNone);
  1081 		res = iReceivers[2]->SetInternalPriority(EPriorityAbsoluteHighNormal);
  1082 		TEST(res == KErrNone);
  1083 		iReceivers[2]->SetVisible(EFalse);
  1084 		User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
  1085 		
  1086 		TInt numUnprocessedSignals = 0;
  1087 		for(TInt submissionNumber = 0; submissionNumber < 10; submissionNumber++)
  1088 			{
  1089 			INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
  1090 
  1091 			TRequestStatus status = KRequestPending;
  1092 			TRequestStatus status1 = KRequestPending;
  1093 			TTimeStamp timeStamp; 
  1094 		
  1095 			session.NotifyWhenDisplayed(status, timeStamp);	
  1096 			session.NotifyWhenDisplayedXTimes(10, status1);
  1097 			
  1098 			res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  1099 			TEST(res==KErrNone);
  1100 			
  1101 			User::WaitForRequest(status);
  1102 			User::WaitForRequest(status1);
  1103 
  1104 			TEST(status == KErrNone);
  1105 			TEST(status1 == KErrNone);
  1106 			if(iReceivers[0]->OutstandingRequest())
  1107 				{		
  1108 				numUnprocessedSignals++;
  1109 				INFO_PRINTF1(_L("Unprocessed signals"));	
  1110 
  1111 				}
  1112 			TEST(iReceivers[1]->OutstandingRequest() == EFalse);
  1113 			TEST(iReceivers[2]->OutstandingRequest() == EFalse);
  1114 			TEST(iReceivers[0]->OutstandingRequest()); //receiver is signalled last, in since its priority is lowest, 
  1115 														//SUS shouldn’t wait for it before the signal goes back to client  
  1116 			}
  1117 
  1118 	INFO_PRINTF2(_L("Number unprocessed signals %d"), numUnprocessedSignals);	
  1119 	TEST(numUnprocessedSignals > 0);
  1120 		
  1121 	//restore envorienment
  1122 	iReceivers[0]->SetInternalPriority(EPriorityNormal);
  1123 	iReceivers[1]->SetInternalPriority(EPriorityNormal);
  1124 	iReceivers[2]->SetInternalPriority(EPriorityNormal);
  1125 	iReceivers[2]->SetVisible(ETrue);
  1126 	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
  1127 	WaitUntilAllNotificationsProcessed();
  1128 	
  1129 	session.Close();
  1130 	}
  1131 
  1132 /**
  1133   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0029
  1134 
  1135 
  1136   @SYMPREQ 1007/11596
  1137 
  1138   @SYMREQ 8223
  1139 
  1140   @SYMTestCaseDesc Register with identical priorities. 
  1141 
  1142   @SYMTestPriority High
  1143 
  1144   @SYMTestStatus Implemented
  1145 
  1146   @SYMTestActions 
  1147 		1.	Start the server.
  1148 		2.	Create two content update receivers
  1149 		3.	Register receiverA using Register() with a priority
  1150 		4.	Register receiverB using Register() with the same priority
  1151 		5.	Unregister receiverA
  1152 		6.	Register receiverB using Register() with the same priority as before
  1153 
  1154   @SYMTestExpectedResults 
  1155 		Step 4 should fail, returning KErrAlreadyExists.
  1156 		Step 6 should succeed.
  1157 */
  1158 void CTSurfaceUpdate::TestCaseRegisterIdenticalPrioritiesL()
  1159 	{
  1160 	INFO_PRINTF1(_L("Register with identical priorities test"));
  1161 	const TInt KIdenticalPriority = 100;
  1162 	
  1163 	// Start two content update receivers for register test
  1164 	CTContentUpdateReceiver* receiverA;
  1165 	CTContentUpdateReceiver* receiverB;
  1166 	User::LeaveIfError(StartTestUpdateReceiver(receiverA, 8));
  1167 	iReceivers.AppendL(receiverA);
  1168 	User::LeaveIfError(StartTestUpdateReceiver(receiverB, 9));
  1169 	iReceivers.AppendL(receiverB);
  1170 		
  1171 	INFO_PRINTF2(_L("Registering receiver A with priority %i"), KIdenticalPriority);	
  1172 	User::LeaveIfError(Provider()->Register(receiverA->Screen(), receiverA, KIdenticalPriority));
  1173 
  1174 	INFO_PRINTF2(_L("Registering receiver B with the same priority (%i), which should return KErrAlreadyExists"), KIdenticalPriority);	
  1175 	TInt ret = Provider()->Register(receiverB->Screen(), receiverB, KIdenticalPriority);
  1176 	if(KErrAlreadyExists == ret)
  1177 		{
  1178 		INFO_PRINTF1(_L("KErrAlreadyExists returned as expected"));
  1179 		}
  1180 	else
  1181 		{
  1182 		ERR_PRINTF3(_L("Test failed - expected Register() to return KErrAlreadyExists(%i) but instead returned %i"), KErrAlreadyExists, ret);
  1183 		User::Leave(ret);
  1184 		}
  1185 
  1186 	INFO_PRINTF1(_L("Unregistering receiver A"));
  1187 	User::LeaveIfError(Provider()->Register(receiverA->Screen(), NULL, KIdenticalPriority));
  1188 
  1189 	INFO_PRINTF2(_L("Registering receiver B with the same priority (%i), which should succeed"), KIdenticalPriority);
  1190 	User::LeaveIfError(Provider()->Register(receiverB->Screen(), receiverB, KIdenticalPriority));
  1191 	}
  1192 
  1193 /**
  1194 negative testing
  1195 */
  1196 
  1197 
  1198 /**
  1199   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0006
  1200 
  1201   @SYMPREQ 1007
  1202   
  1203   @SYMREQ 8223
  1204 
  1205   @SYMTestCaseDesc Negative testing - various cases
  1206 
  1207   @SYMTestPriority High
  1208 
  1209   @SYMTestStatus Implemented
  1210 
  1211   @SYMTestActions 6. The client mustn't try to send any command to the server before 
  1212      establishing a connection.
  1213      7. Attempt to connect twice
  1214      8. Attempt notify then submit with invalid parameters
  1215      9. Submission with screen which doesn't exist in the system
  1216      10. Submission with invalid number of counts in NotifyWhenDisplayedXTimes()
  1217      11. Number of outstanding requests exceeds pre-defined value
  1218      12. Submission of region with empty rectangle list
  1219      13. Assigning receiver to the screen with negative number
  1220 
  1221   @SYMTestExpectedResults 6. Shouldn't panic and subsequent session connect should succeed.
  1222      7. Second attempt to connect should return KErrAlreadyExists
  1223      8. With invalid parameters we get KErrArgument; with a screen that doesn't exist we
  1224         get KErrUpdateReceiverNotAvailable
  1225      9. Too big a screen number results in KErrUpdateReceiverNotAvailable; -ve buffer results in KErrArgument.
  1226      10. With a negative diplayedXtimes number, we expect KErrArgument
  1227      11. When we exceed the number of allowed outstanding requests, we get KErrBusy
  1228      12. With empty region, all return codes are KErrNone.
  1229      13. Registering with negative screen gives KErrArgument
  1230 */
  1231 void CTSurfaceUpdate::TestCase6L()
  1232 	{
  1233 	INFO_PRINTF1(_L("negative testing"));
  1234 	RSurfaceUpdateSession session;
  1235 	TRequestStatus status;
  1236 	TRequestStatus status1;
  1237 	TRequestStatus status2;
  1238 	TRequestStatus status3;
  1239 	TRequestStatus status4;
  1240 	TRequestStatus status5;
  1241 	TInt res;
  1242 	TTimeStamp timeStamp; 
  1243 	
  1244 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0006 apply operation on disconnected session
  1245 	TInt screen = 0;
  1246 	TInt buffer = 2;
  1247 	TSurfaceId surface = 
  1248 		{
  1249 		1,2,3,4
  1250 		};
  1251 	TRect rc[2] =
  1252 			{
  1253 			TRect(1,2, 10, 20),
  1254 		
  1255 			TRect(5,6, 30, 30)
  1256 			};
  1257 		
  1258 	RRegion region(2, rc);
  1259 
  1260 	//next command will be ignored, but shouldn't cause a panic
  1261 	INFO_PRINTF1(_L("close disconnected session"));
  1262 	session.Close();
  1263 	
  1264 	User::LeaveIfError(session.Connect());
  1265 	
  1266 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0007 Attempt to connect twice
  1267 	INFO_PRINTF1(_L("try to connect twice"));
  1268 	res = session.Connect();
  1269 	TEST(res == KErrAlreadyExists);
  1270 	
  1271 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0008 wrong parameters
  1272 	INFO_PRINTF1(_L("specifying wrong parametrs"));
  1273 	INFO_PRINTF1(_L("specify a negative screen number"));
  1274 	screen = -10;
  1275 	session.NotifyWhenAvailable(status);	
  1276 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1277 	session.NotifyWhenDisplayedXTimes(10, status2);	
  1278 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1279 	User::WaitForRequest(status);
  1280 	User::WaitForRequest(status1);
  1281 	User::WaitForRequest(status2);
  1282 	
  1283 	TEST(status == KErrArgument);
  1284 	TEST(status1 == KErrArgument);
  1285 	TEST(status2 == KErrArgument);
  1286 	TEST(res == KErrArgument);
  1287 
  1288 	INFO_PRINTF1(_L("receiver for the following screen doesn't exist"));
  1289 	screen = 10;
  1290 	session.NotifyWhenAvailable(status);	
  1291 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1292 	session.NotifyWhenDisplayedXTimes(10, status2);	
  1293 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1294 	User::WaitForRequest(status);
  1295 	User::WaitForRequest(status1);
  1296 	User::WaitForRequest(status2);
  1297 
  1298 	TEST(status == KErrUpdateReceiverNotAvailable);
  1299 	TEST(status1 == KErrUpdateReceiverNotAvailable);
  1300 	TEST(status2 == KErrUpdateReceiverNotAvailable);
  1301 	TEST(res == KErrUpdateReceiverNotAvailable);
  1302 
  1303 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0009 Submission with screen which doesn't exist in the system
  1304 	INFO_PRINTF1(_L("too big screen number"));
  1305 	screen = 100000;
  1306 	session.NotifyWhenAvailable(status);	
  1307 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1308 	session.NotifyWhenDisplayedXTimes(10, status2);	
  1309 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1310 	User::WaitForRequest(status);
  1311 	User::WaitForRequest(status1);
  1312 	User::WaitForRequest(status2);
  1313 
  1314 	TEST(status == KErrUpdateReceiverNotAvailable);
  1315 	TEST(status1 == KErrUpdateReceiverNotAvailable);
  1316 	TEST(status2 == KErrUpdateReceiverNotAvailable);
  1317 	TEST(res == KErrUpdateReceiverNotAvailable);
  1318 	
  1319 	INFO_PRINTF1(_L("negative buffer"));
  1320 	screen = 0;
  1321 	buffer = -10;
  1322 	session.NotifyWhenAvailable(status);	
  1323 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1324 	session.NotifyWhenDisplayedXTimes(10, status2);	
  1325 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1326 	User::WaitForRequest(status);
  1327 	User::WaitForRequest(status1);
  1328 	User::WaitForRequest(status2);
  1329 
  1330 	TEST(status == KErrArgument);
  1331 	TEST(status1 == KErrArgument);
  1332 	TEST(status2 == KErrArgument);
  1333 	TEST(res == KErrArgument);
  1334 
  1335 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0010 Submission with invalid number of counts in NotifyWhenDisplayedXTimes()
  1336 	INFO_PRINTF1(_L("displaying for negative number of times"));
  1337 	screen = 0;
  1338 	buffer = 0;
  1339 	TInt displayedXTimes = -10;	
  1340 	session.NotifyWhenAvailable(status);	
  1341 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1342 	session.NotifyWhenDisplayedXTimes(displayedXTimes, status2);	
  1343 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1344 	User::WaitForRequest(status);
  1345 	User::WaitForRequest(status1);
  1346 	User::WaitForRequest(status2);
  1347 
  1348 	TEST(status == KErrNone);
  1349 	TEST(status1 == KErrNone);
  1350 	TEST(status2 == KErrArgument);
  1351 	TEST(res == KErrNone);
  1352 	
  1353 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0011 Number of outstanding requests exceeds pre-defined value
  1354 	INFO_PRINTF1(_L("number of outstanding requests exceeds pre-defined value"));
  1355 	session.Close();
  1356 	User::LeaveIfError(session.Connect(4));
  1357 	buffer = 0;
  1358 	session.NotifyWhenAvailable(status);	
  1359 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1360 	session.NotifyWhenDisplayedXTimes(10, status2);	
  1361 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1362 	TEST(res == KErrNone);
  1363 
  1364 	session.NotifyWhenAvailable(status3);	
  1365 	session.NotifyWhenDisplayed(status4, timeStamp);	
  1366 	session.NotifyWhenDisplayedXTimes(10, status5);	
  1367 	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1368 	TEST(res == KErrNone);
  1369 
  1370 	User::WaitForRequest(status);
  1371 	User::WaitForRequest(status1);
  1372 	User::WaitForRequest(status2);
  1373 	User::WaitForRequest(status3);
  1374 	User::WaitForRequest(status4);
  1375 	User::WaitForRequest(status5);
  1376 	
  1377 	TEST(status == KErrNone);
  1378 	TEST(status1== KErrNone);
  1379 	TEST(status2== KErrNone);
  1380 	TEST(status3== KErrNone);
  1381 	TEST(status4== KErrServerBusy);
  1382 	TEST(status5== KErrServerBusy);
  1383 	
  1384 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0012 Submission of region with empty rectangle list
  1385 	INFO_PRINTF1(_L("specify empty region"));
  1386 	RRegion region1;
  1387 	session.NotifyWhenAvailable(status);	
  1388 	session.NotifyWhenDisplayed(status1, timeStamp);	
  1389 	session.NotifyWhenDisplayedXTimes(10, status2);	
  1390 	res = session.SubmitUpdate(screen, surface, buffer, &region1);
  1391 	TEST(res == KErrNone);
  1392 
  1393 	User::WaitForRequest(status);
  1394 	User::WaitForRequest(status1);
  1395 	User::WaitForRequest(status2);
  1396 	TEST(status == KErrNone);
  1397 	TEST(status1== KErrNone);
  1398 	TEST(status2== KErrNone);
  1399 	
  1400 	//register with negative screen
  1401 	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0013 Assigning receiver to the screen with negative number
  1402 	INFO_PRINTF1(_L("register with negative screen"));
  1403 	res = Provider()->Register(-1, NULL, 1);
  1404 	TEST(res==KErrArgument);
  1405 	session.Close();
  1406 	}
  1407 
  1408 /**
  1409   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0014
  1410 
  1411   @SYMPREQ 1007
  1412   
  1413   @SYMREQ 8223
  1414 
  1415   @SYMTestCaseDesc OOM testing. 
  1416 
  1417   @SYMTestPriority High
  1418 
  1419   @SYMTestStatus Implemented
  1420 
  1421   @SYMTestActions Create connection to the server. 
  1422   	Set server in special mode which simulates heap allocation failure. 
  1423   	1. Subscribe for notifications. 
  1424   	2. Submit update command with not empty region.
  1425   	
  1426   @SYMTestExpectedResults Submit return code and notifications must arrive 
  1427   with KErrNoMemory in the case of memory allocation failures.
  1428 */
  1429 void CTSurfaceUpdate::TestCase7L()
  1430 	{
  1431 	RMisbehavingSession session;
  1432 	TRequestStatus status;
  1433 	TRequestStatus status1;
  1434 	TRequestStatus status2;
  1435 	TTimeStamp timeStamp;
  1436 	TSurfaceId surface = 
  1437 		{
  1438 		1,2,3,4
  1439 		};
  1440 	TRect rc[2] =
  1441 		{
  1442 		TRect(1,2, 10, 20),
  1443 		TRect(5,6, 30, 30)
  1444 		};
  1445 	
  1446 	RRegion region(2, rc);
  1447 	TInt buffer = 0;
  1448 	TInt screen = 0;
  1449 	User::LeaveIfError(session.Connect());
  1450 	TInt res = KErrNone;
  1451 	
  1452 	//create another receiver
  1453 	CTContentUpdateReceiver *receiver4;
  1454 	User::LeaveIfError(StartTestUpdateReceiver(receiver4, 4));
  1455 	iReceivers.AppendL(receiver4);
  1456 	
  1457 	TInt ii = 1;
  1458 	const TInt screenNo = 16;
  1459 	// Cause a failure on all the allocs on server side
  1460 	for(ii = 1; ; ++ii)
  1461 		{
  1462 		session.SetFailRate(ii);
  1463 		res = Provider()->Register(screenNo, receiver4, -100);
  1464 		if(res != KErrNoMemory)
  1465 			break;
  1466 		} 
  1467 	TEST(res == KErrNone);
  1468 	//unregister receiver
  1469 	User::LeaveIfError(Provider()->Register(screenNo, NULL, 0));
  1470 	//try to do the same same thing again, to make sure that it won't panic
  1471 	User::LeaveIfError(Provider()->Register(screenNo, NULL, 0)); //unregister the function
  1472 	TInt index = iReceivers.Find(receiver4);
  1473 	TEST(index != KErrNotFound);
  1474 	CloseTestUpdateReceiver(receiver4);	
  1475 	iReceivers.Remove(index);
  1476 	//end register testing
  1477 	
  1478 	// Cause a failure on all the allocs on server side
  1479 	for(ii = 1; ; ++ii)
  1480 		{
  1481 		// Test 1st alloc failure
  1482 		session.SetFailRate(ii);
  1483 		session.NotifyWhenAvailable(status);
  1484 		session.NotifyWhenDisplayed(status1, timeStamp);
  1485 		session.NotifyWhenDisplayedXTimes(1, status2);
  1486 		res = session.SubmitUpdate(screen, surface, buffer, &region);
  1487 		User::WaitForRequest(status);
  1488 		User::WaitForRequest(status1);
  1489 		User::WaitForRequest(status2);
  1490 		
  1491 		// Whenever we hit error codes that aren't no memory, we're finished
  1492 		if(res != KErrNoMemory || status.Int() != KErrNoMemory || status1.Int() != KErrNoMemory || status2.Int() != KErrNoMemory)
  1493 			break;
  1494 		
  1495 		TEST(res == KErrNoMemory); // Since the first alloc fail kills the server
  1496 		TEST(status.Int() == KErrNoMemory);
  1497 		}
  1498 		
  1499 	TEST(res == KErrNone);
  1500 	TEST((status.Int() == KErrNone) || (status.Int() == KErrNoMemory));
  1501 	TEST((status1.Int() == KErrNone) || (status1.Int() == KErrNoMemory));
  1502 	TEST((status2.Int() == KErrNone) || (status2.Int() == KErrNoMemory));
  1503 	session.SetFailRate(0); // turns off oom failures
  1504 	session.Close();
  1505 	}
  1506 	
  1507 /**
  1508   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0015
  1509 
  1510   @SYMPREQ 1007
  1511   
  1512   @SYMREQ 8223
  1513 
  1514   @SYMTestCaseDesc Causing panic of client 
  1515 
  1516   @SYMTestPriority High
  1517 
  1518   @SYMTestStatus Implemented
  1519 
  1520   @SYMTestActions Create second thread which connects to the server. 
  1521   	Pass an invalid opcode to the server which will cause a client panic.
  1522   	
  1523   @SYMTestExpectedResults The thread will die with the correct exit reason
  1524     (EUpdateServPanicBadRequest) and the correct exit category (SurfUpServ).
  1525 */
  1526 void CTSurfaceUpdate::TestCase8()
  1527  	{
  1528  	// Create another thread in which we will panic the client
  1529  	_LIT(KThreadName, "TestPanicClientThread");
  1530  	RThread thread;
  1531 	TEST(KErrNone == thread.Create(KThreadName,
  1532 			PanicClientThread,
  1533 			KDefaultStackSize,
  1534 			&User::Heap(),
  1535 			NULL));
  1536 	TRequestStatus rendezvousStatus;
  1537 	thread.Rendezvous(rendezvousStatus);
  1538 	thread.Resume();
  1539 	User::WaitForRequest(rendezvousStatus);
  1540 	_LIT(KExitCategory,"SurfUpServ");
  1541 	TBuf<16> exitCategory(KExitCategory);
  1542 	TEST(thread.ExitReason() == EUpdateServPanicBadRequest);
  1543 	TEST(thread.ExitCategory() == exitCategory);
  1544 	thread.Close();
  1545  	}
  1546  	
  1547 /**
  1548 Thread function called from TestCase8L in order to panic the client.
  1549 */ 	
  1550 TInt CTSurfaceUpdate::PanicClientThread(TAny*)
  1551 	{
  1552 	User::SetJustInTime(EFalse);
  1553 	RMisbehavingSession session;
  1554 	TInt err = session.Connect();
  1555  	if(KErrNone != err)
  1556  		return err;
  1557  	session.TestPassingInvalidOpcode();
  1558  	// Exit reason will be the panic number due to the invalid op code:
  1559  	// returning zero here is redundant
  1560  	return 0;
  1561 	}
  1562 
  1563 /**
  1564   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0016
  1565 
  1566 
  1567   @SYMPREQ 1007
  1568   
  1569   @SYMREQ 8223
  1570 
  1571   @SYMTestCaseDesc Calling submit before any notify with invalid arguments. 
  1572 
  1573   @SYMTestPriority High
  1574 
  1575   @SYMTestStatus Implemented
  1576 
  1577   @SYMTestActions Set an invalid screen number and call SubmitUpdate (before a notify).
  1578     Set an invalid buffer number and call SubmitUpdate (before a notify).
  1579   	Set a Null surfaceId and call SubmitUpdate (before a notify).
  1580   	
  1581   @SYMTestExpectedResults SubmitUpdate will return KErrArgument in both cases.
  1582 */
  1583 void CTSurfaceUpdate::TestCase9L()
  1584 	{
  1585 	RSurfaceUpdateSession session;	
  1586 	User::LeaveIfError(session.Connect());
  1587 	
  1588 	// Test submit before notify with -ve screen
  1589 	TInt screen = -1;
  1590 	TSurfaceId surface = 
  1591 			{
  1592 			1,2,3,4
  1593 			};
  1594 	TInt buffer = 1;
  1595 	TInt res = session.SubmitUpdate(screen, surface, buffer, NULL);
  1596 	TEST(res == KErrArgument);
  1597 	
  1598 	// Test submit before notify with -ve buffer
  1599 	screen = 1;
  1600 	buffer = -1;
  1601 	res = session.SubmitUpdate(screen, surface, buffer, NULL);
  1602 	TEST(res == KErrArgument);
  1603 
  1604 	//Test submit before notify with Null surfaceId
  1605 	surface = TSurfaceId::CreateNullId();
  1606 	screen = 1;
  1607 	buffer = 1;
  1608 	res = session.SubmitUpdate(screen, surface, buffer, NULL);
  1609 	TEST(res == KErrArgument);
  1610 	session.Close();
  1611 	}
  1612 
  1613 /**
  1614   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0017
  1615 
  1616 
  1617   @SYMPREQ 1007
  1618   
  1619   @SYMREQ 8223
  1620 
  1621   @SYMTestCaseDesc Using a rogue client to call multiple notifies in a row. 
  1622 
  1623   @SYMTestPriority High
  1624 
  1625   @SYMTestStatus Implemented
  1626 
  1627   @SYMTestActions Create a second thread which will call multiple notifies
  1628    in succession (not interleaved with Submits).
  1629   	
  1630   @SYMTestExpectedResults The thread should have an exit category
  1631    of SurfUpServ and and exit reason of EUpdateServPanicDataIntegrity in
  1632    all cases.
  1633 */
  1634 void CTSurfaceUpdate::TestCase10()
  1635 	{
  1636  	for(TInt testNum = 0; testNum < 3; ++testNum)
  1637  		{
  1638  		_LIT(KThreadName, "TestMultipleNotify%d");
  1639  		TBuf<19> threadName;
  1640  		threadName.Format(KThreadName, testNum);
  1641  		RThread thread;
  1642  		TRequestStatus status;
  1643 	 	TMultipleNotify statusCol(status, testNum);
  1644 		TEST(KErrNone == thread.Create(threadName,
  1645 				TestMultipleNotifyThreadL,
  1646 				KDefaultStackSize,
  1647 				&User::Heap(),
  1648 				&statusCol));
  1649 		TRequestStatus rendezvousStatus;
  1650 		thread.Rendezvous(rendezvousStatus);
  1651 		thread.Resume();
  1652 		User::WaitForRequest(rendezvousStatus);
  1653 		// We expect the first request to be cancelled.
  1654 		//The request can also be on a pending state if the connection is closed before the 
  1655 		//cancellation has been transferred to client 
  1656 		TEST((KErrCancel == status.Int()) || (status.Int() == KRequestPending));
  1657 		// We expect the second request to Panic the client
  1658 		_LIT(KExitCategory,"SurfUpServ");
  1659 		TBuf<16> exitCategory(KExitCategory);
  1660 		TEST(thread.ExitReason() == EUpdateServPanicDataIntegrity);
  1661 		TEST(thread.ExitCategory() == exitCategory);
  1662 		thread.Close();
  1663  		}
  1664 	}
  1665 	
  1666 /**
  1667 Thread function called from TestCase10 in order to submit multiple notifies.
  1668 */	
  1669 TInt CTSurfaceUpdate::TestMultipleNotifyThreadL(TAny* aStatusCol)
  1670 	{
  1671 	User::SetJustInTime(EFalse);
  1672 	RMisbehavingSession badSession;
  1673 	User::LeaveIfError(badSession.Connect());
  1674 	TMultipleNotify* statusCol = static_cast<TMultipleNotify*>(aStatusCol);
  1675 	TRequestStatus status;
  1676 	switch(statusCol->iTestNum)
  1677 		{
  1678 	case 0:
  1679 		badSession.NotifyWhenAvailableNoChecking(statusCol->iStatus);
  1680 		badSession.NotifyWhenAvailableNoChecking(status);
  1681 		break;
  1682 	case 1:
  1683 		badSession.NotifyWhenDisplayedNoChecking(statusCol->iStatus);
  1684 		badSession.NotifyWhenDisplayedNoChecking(status);
  1685 		break;
  1686 	case 2:
  1687 		badSession.NotifyWhenDisplayedXTimesNoChecking(10, statusCol->iStatus);
  1688 		badSession.NotifyWhenDisplayedXTimesNoChecking(10, status);
  1689 		break;
  1690 	default:
  1691 		_LIT(KMultipleNotifyPanic, "MultNotifyPanic");
  1692 		User::Panic(KMultipleNotifyPanic, 1);
  1693 		break;
  1694 		}
  1695 	User::WaitForRequest(statusCol->iStatus);
  1696 	User::WaitForRequest(status);
  1697 	// Exit reason will be the panic number due to the invalid op code:
  1698  	// returning zero here is redundant
  1699 	return 0;
  1700 	}
  1701 
  1702 /**
  1703   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0018
  1704 
  1705   @SYMPREQ 1007
  1706   
  1707   @SYMREQ 8223
  1708 
  1709   @SYMTestCaseDesc Use a rogue client to misbehave in various ways.
  1710 
  1711   @SYMTestPriority High
  1712 
  1713   @SYMTestStatus Implemented
  1714 
  1715   @SYMTestActions 1. Attempt to connect with an incorrect version number.
  1716     Connect to the server, communicate with server without proper client side checking:
  1717     2. Submit update with a negative buffer number (no client side checking).
  1718     3. Submit update with a negative screen number (no client side checking).
  1719     4. Call NotifyWhenDisplayedXTimes with no client side checking and a count of 0.
  1720   	
  1721   @SYMTestExpectedResults 1. KErrNotSupported
  1722     2. KErrArgument
  1723     3. KErrArgument
  1724     4. Status int is KErrArgument (SubmitUpdate == KErrNone).
  1725 */
  1726 void CTSurfaceUpdate::TestCase11()
  1727 	{
  1728 	// Attempt to connect with the wrong version number
  1729 	RMisbehavingSession session;
  1730 	TEST(KErrNotSupported == session.Connect(KDefaultMessageSlot, ETrue));
  1731 	
  1732 	TEST(KErrNone == session.Connect());
  1733 	TInt screen = 0;
  1734 	TSurfaceId surface = 
  1735 		{
  1736 		1,2,3,4
  1737 		};
  1738 	TInt buffer = -1;
  1739 	
  1740 	// Call RMisbehavingSession::SubmitUpdate which doesn't do the correct
  1741 	// client side checking
  1742 	TEST(KErrArgument == session.SubmitUpdateNoChecking(screen, surface, buffer, NULL));
  1743 	
  1744 	// Test with -ve screen
  1745 	screen = -1;
  1746 	buffer = 0;
  1747 	TEST(KErrArgument == session.SubmitUpdateNoChecking(screen, surface, buffer, NULL));
  1748 	
  1749 	// Test calling NotifyWhenDisplayedXTimes with no client side checking and a count of 0
  1750 	screen = 0;
  1751 	buffer = 1;
  1752 	TRequestStatus status;
  1753 	session.NotifyWhenDisplayedXTimesNoChecking(0, status);
  1754 	TEST(KErrNone == session.SubmitUpdateNoChecking(screen, surface, buffer, NULL));
  1755 	User::WaitForRequest(status);
  1756 	TEST(KErrArgument == status.Int());
  1757 	
  1758 	session.Close();
  1759 	}
  1760 
  1761 
  1762 /**
  1763   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0019
  1764 
  1765 
  1766   @SYMPREQ 1007
  1767   
  1768   @SYMREQ 8223
  1769 
  1770   @SYMTestCaseDesc Starting the surface update server in two different threads.
  1771 
  1772   @SYMTestPriority High
  1773 
  1774   @SYMTestStatus Implemented
  1775 
  1776   @SYMTestActions Start the surface update server in two different threads.
  1777     
  1778   @SYMTestExpectedResults Thread 1: KErrNone
  1779      Thread 2: KErrNone
  1780      The "provider" returned to both threads should also be the same value!
  1781 */
  1782 void CTSurfaceUpdate::TestCase12L()
  1783     {
  1784     MSurfaceUpdateServerProvider *surfaceUpdateProvider = NULL;
  1785     TInt res = StartSurfaceUpdateServer(surfaceUpdateProvider);
  1786     TEST(res == KErrNone);
  1787     User::LeaveIfError(res);
  1788 
  1789     _LIT(KThreadName, "TestServerStartupTwoThreads");
  1790     TTime tm;
  1791     TBuf<32> buf;
  1792     tm.UniversalTime();
  1793     TRAP(res, tm.FormatL(buf, _L("_%H%T%S%C")));
  1794     TEST(res == KErrNone);
  1795     User::LeaveIfError(res);
  1796     TBuf<128> threadName(KThreadName);
  1797     threadName.Append(buf); //guarantee uniqueness  of the thread name
  1798     RThread thread;
  1799     MSurfaceUpdateServerProvider *surfaceUpdateProvider2 = NULL;
  1800     res = thread.Create(threadName,
  1801             TestServerStartupTwoThreads,
  1802             KDefaultStackSize,
  1803             &User::Heap(),
  1804             &surfaceUpdateProvider2);
  1805     TEST(res == KErrNone);
  1806     User::LeaveIfError(res);
  1807     TRequestStatus rendezvousStatus;
  1808     thread.Rendezvous(rendezvousStatus);
  1809     thread.Resume();
  1810     User::WaitForRequest(rendezvousStatus);
  1811     TEST(KErrNone == rendezvousStatus.Int());
  1812     // Check that we get the same provider for both threads!
  1813     TEST(surfaceUpdateProvider2 == surfaceUpdateProvider);
  1814     }
  1815 
  1816 
  1817 /**
  1818 Starting the update server in another thread - called from TestCase12
  1819 */
  1820 TInt CTSurfaceUpdate::TestServerStartupTwoThreads(TAny *aArgPtr)
  1821 	{
  1822 	MSurfaceUpdateServerProvider **surfaceUpdateProviderPtr = 
  1823 	        reinterpret_cast<MSurfaceUpdateServerProvider **>(aArgPtr);
  1824 	TInt res = StartSurfaceUpdateServer(*surfaceUpdateProviderPtr);
  1825 	return res;
  1826 	}
  1827 
  1828 /**
  1829   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0020
  1830 
  1831   @SYMPREQ 1007
  1832   
  1833   @SYMREQ 8223
  1834 
  1835   @SYMTestCaseDesc Requesting notifies, leaving enough time for them to 
  1836   complete before requesting the subsequent notification.
  1837 
  1838   @SYMTestPriority High
  1839 
  1840   @SYMTestStatus Implemented
  1841 
  1842   @SYMTestActions Execute some notifies and submits, wait for a short period (100us), 
  1843   then cancel them all.
  1844   	
  1845   @SYMTestExpectedResults Two results are acceptable: KErrNone (notify 
  1846   completed before it was cancelled) or KErrCancel (notify sucessfully cancelled).
  1847 */	
  1848 void CTSurfaceUpdate::TestCase13L()
  1849 	{
  1850 	RSurfaceUpdateSession session;
  1851 	const TInt numNotifies = 10;
  1852 	User::LeaveIfError(session.Connect(numNotifies));	
  1853 	
  1854 	TRequestStatus statusArray[numNotifies];
  1855 	TInt screen = 0;
  1856 	TSurfaceId surface = 
  1857 		{
  1858 		1,2,3,4
  1859 		};
  1860 	TInt buffer = 1;
  1861 	
  1862 	// Send the same type of notification request multiply, cancelling after each submission
  1863 	for(TInt ii = 0; ii < numNotifies; ++ii)
  1864 		{
  1865 		session.NotifyWhenAvailable(statusArray[ii]);
  1866 		TEST(KErrNone == session.SubmitUpdate(screen, surface, buffer, NULL));
  1867 		session.CancelAllUpdateNotifications();
  1868 		User::After(100); // Enough time for the notify to be processed
  1869 		}
  1870 	
  1871 	// Check that the error codes are acceptable
  1872 	for(TInt ii = 0; ii < numNotifies; ++ii)
  1873 		{
  1874 		TInt ret = statusArray[ii].Int();
  1875 		TEST(statusArray[ii].Int() == KErrNone || statusArray[ii].Int() == KErrCancel);
  1876 		}
  1877 	
  1878 	session.Close();
  1879 	}
  1880 	
  1881 /**
  1882   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0021
  1883 
  1884   @SYMPREQ 1007
  1885   
  1886   @SYMREQ 8223
  1887 
  1888   @SYMTestCaseDesc Terminating and restarting the server.
  1889 
  1890   @SYMTestPriority High
  1891 
  1892   @SYMTestStatus Implemented
  1893 
  1894   @SYMTestActions Terminate and restart the server
  1895   	
  1896   @SYMTestExpectedResults Test that trying to connect the session after 
  1897   	termination of the server results in KErrNotFound, and that the server 
  1898   	can be restarted with result KErrNone.
  1899 */
  1900 void CTSurfaceUpdate::TestCaseTerminateServer()
  1901 	{
  1902 	(static_cast <CTSurfaceUpdateStep*> (iStep)) ->TerminateServer();
  1903 	
  1904 	//at that point server has been terminated
  1905 	RSurfaceUpdateSession session;
  1906 	TInt res = session.Connect();
  1907 	TEST(res == KErrNotFound);
  1908 	session.Close();
  1909 	
  1910 	res = (static_cast <CTSurfaceUpdateStep*> (iStep)) ->StartServer();
  1911 	TEST(res == KErrNone);
  1912 	res = session.Connect();
  1913 	TEST(res == KErrNone);
  1914 	session.Close();
  1915 	}
  1916 	
  1917 /**
  1918   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0022
  1919 
  1920   @SYMPREQ 1007
  1921   
  1922   @SYMREQ 8223
  1923 
  1924   @SYMTestCaseDesc Terminating the thread while some outstanding request in progress.
  1925 
  1926   @SYMTestPriority High
  1927 
  1928   @SYMTestStatus Implemented
  1929 
  1930   @SYMTestActions Terminate the thread which has outstanding request to 
  1931   the server for surface update notifications. 
  1932   	
  1933   @SYMTestExpectedResults Surface update surface should process the request 
  1934   and try to send notification without hanging.
  1935   
  1936 */
  1937 void CTSurfaceUpdate::TestCase14()
  1938 	{
  1939  	_LIT(KThreadNameTemplate, "TestPanicClientThread1_%d");
  1940  	
  1941  	RThread thread;
  1942 	const TInt KMaxIndex = 50;
  1943  	for(TInt index = 0; index < KMaxIndex; index++)
  1944  		{
  1945  		const TInt KUnexpectedLeavePanic = 194;
  1946  		TBuf<128> threadName;
  1947  		threadName.Format(KThreadNameTemplate, index);
  1948  		TInt res = thread.Create(threadName,
  1949 			PanicClientThread1,
  1950 			KDefaultStackSize,
  1951 			&User::Heap(),
  1952 			this);
  1953 		TEST(res == KErrNone);	
  1954  		TRequestStatus status = KRequestPending;
  1955  		thread.Logon(status);
  1956  		thread.Resume();
  1957  		User::WaitForRequest(status);
  1958 
  1959  		res = thread.ExitReason();
  1960  		TEST(res == KUnexpectedLeavePanic);
  1961  		if(res != KUnexpectedLeavePanic)
  1962  			{
  1963  			INFO_PRINTF2(_L("Thread exits with error code %d"), res);
  1964  			}
  1965  		thread.Close();
  1966  		}
  1967 	}
  1968 
  1969 /**
  1970   @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0025
  1971 
  1972   @SYMPREQ 1007/11599, 1007/11600, 1007/11601
  1973 
  1974   @SYMREQ 8223
  1975 
  1976   @SYMTestCaseDesc SubmitUpdate() with a global and a per-display 
  1977   update cannot be mixed.
  1978   @SYMTestPriority High
  1979 
  1980   @SYMTestStatus Implemented
  1981 
  1982   @SYMTestActions 
  1983 	Create the session and make a global submit update.
  1984 	Subscribe for all notifications and make per screen submit update. 
  1985 	Create another session and make a per screen update.
  1986 	Subscribe for all notifications and make a global submit update. 
  1987 	
  1988   		
  1989   @SYMTestExpectedResults 
  1990   	Mixing two different types of submit update should fail with an error KErrNotSupported.
  1991 */
  1992 void CTSurfaceUpdate::TestCase18()
  1993 	{
  1994 	INFO_PRINTF1(_L("SubmitUpdate() to deal with both a global and a per-display update in the same session"));
  1995 
  1996 	RSurfaceUpdateSession session;
  1997 	TInt buffer = 2;
  1998 	TSurfaceId surface = 
  1999 		{
  2000 		1,2,3,4
  2001 		};
  2002 
  2003 	TInt res = session.Connect();
  2004 	TEST(res == KErrNone);
  2005 
  2006 	res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  2007 	TEST(res==KErrNone);
  2008 	
  2009 	TRequestStatus status = KRequestPending;
  2010 	TRequestStatus status1 = KRequestPending;
  2011 	TRequestStatus status2 = KRequestPending;
  2012 	TTimeStamp timeStamp; 
  2013 	
  2014 	session.NotifyWhenAvailable(status);	
  2015 	session.NotifyWhenDisplayed(status1, timeStamp);	
  2016 	session.NotifyWhenDisplayedXTimes(10, status2);
  2017 		
  2018 	res = session.SubmitUpdate(1, surface, buffer, NULL);
  2019 	TEST(res==KErrNotSupported);
  2020 		
  2021 	User::WaitForRequest(status);
  2022 	User::WaitForRequest(status1);
  2023 	User::WaitForRequest(status2);
  2024 
  2025 	TEST(status == KErrNotSupported);
  2026 	TEST(status1 == KErrNotSupported);
  2027 	TEST(status2 == KErrNotSupported);
  2028 	
  2029 	session.Close();
  2030 	//make per screen update first
  2031 	res = session.Connect();
  2032 	TEST(res == KErrNone);
  2033 
  2034 	res = session.SubmitUpdate(1, surface, buffer, NULL);
  2035 	TEST(res==KErrNone);
  2036 	
  2037 	status = KRequestPending;
  2038 	status1 = KRequestPending;
  2039 	status2 = KRequestPending;
  2040 	
  2041 	session.NotifyWhenAvailable(status);	
  2042 	session.NotifyWhenDisplayed(status1, timeStamp);	
  2043 	session.NotifyWhenDisplayedXTimes(10, status2);
  2044 		
  2045 	res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  2046 	TEST(res==KErrNotSupported);
  2047 		
  2048 	User::WaitForRequest(status);
  2049 	User::WaitForRequest(status1);
  2050 	User::WaitForRequest(status2);
  2051 
  2052 	TEST(status == KErrNotSupported);
  2053 	TEST(status1 == KErrNotSupported);
  2054 	TEST(status2 == KErrNotSupported);
  2055 	
  2056 	session.Close();
  2057 	}
  2058 
  2059 /**
  2060 Thread function called from TestCase14 in order to panic the client
  2061 */ 	
  2062 TInt CTSurfaceUpdate::PanicClientThread1(TAny* aAny)
  2063 	{
  2064 	CTSurfaceUpdate* surfaceUpdateTest = (CTSurfaceUpdate*) aAny;
  2065 	surfaceUpdateTest->GenerateMultipleUpdateWithPanic();
  2066 	
  2067 	return 0;
  2068 	}
  2069 
  2070 /**
  2071 Helper function for test case described in TestCase14
  2072 */ 	
  2073 void CTSurfaceUpdate::GenerateMultipleUpdateWithPanic()
  2074 	{
  2075 	TRequestStatus status = KRequestPending;
  2076 	TTimeStamp timeStamp; 
  2077 	RSurfaceUpdateSession session;
  2078 	TInt screen = 0;
  2079 	TSurfaceId surface = 
  2080 		{
  2081 		1,2,3,4
  2082 		};
  2083 	TInt buffer = 0;
  2084 	
  2085 	TInt res = session.Connect();
  2086 	TEST(res == KErrNone); 
  2087 	session.NotifyWhenDisplayed(status, timeStamp);	
  2088 	res = session.SubmitUpdate(screen, surface, buffer);
  2089 	TEST(res == KErrNone); 
  2090 	User::After(TTimeIntervalMicroSeconds32(100000));
  2091 	
  2092 	User::PanicUnexpectedLeave();
  2093 	}
  2094 
  2095 void CTSurfaceUpdate::ResetSusL()
  2096 	{
  2097 	while (iReceivers.Count() > 0)
  2098 		{
  2099 		CTContentUpdateReceiver *receiver = iReceivers[0];
  2100 		iReceivers.Remove(0);
  2101 		CloseTestUpdateReceiver(receiver);
  2102 		}
  2103 	(static_cast<CTSurfaceUpdateStep*>(iStep))->TerminateServer();
  2104 	User::LeaveIfError((static_cast<CTSurfaceUpdateStep*>(iStep))->StartServer());
  2105 	}
  2106 
  2107 void CTSurfaceUpdate::SetupTestCaseRegisterPanicL()
  2108 	{
  2109 	ResetSusL();
  2110 	// Start two content update receivers for register test
  2111 	CTContentUpdateReceiver* receiverA;
  2112 	CTContentUpdateReceiver* receiverB;
  2113 	User::LeaveIfError(StartTestUpdateReceiver(receiverA, 0));
  2114 	iReceivers.AppendL(receiverA);
  2115 	User::LeaveIfError(StartTestUpdateReceiver(receiverB, 1));
  2116 	iReceivers.AppendL(receiverB);
  2117 	}
  2118 
  2119 void CTSurfaceUpdate::DoTestCaseRegisterPanicL(TThreadFunction aThreadFunction)
  2120 	{
  2121 	_LIT(KRegisterThreadName, "TestPanicRegisterThread");
  2122 	RThread thread;
  2123 	TInt res = thread.Create(KRegisterThreadName, aThreadFunction,
  2124 							 KDefaultStackSize,	&User::Heap(), this);
  2125 	TEST(res == KErrNone);
  2126 	User::LeaveIfError(res);
  2127 	TRequestStatus status = KRequestPending;
  2128 	thread.Logon(status);
  2129 	thread.Resume();
  2130 	User::WaitForRequest(status);
  2131 
  2132 	res = thread.ExitReason();
  2133 	TEST(res == EUpdateServPanicRegister);
  2134 	if(res != EUpdateServPanicRegister)
  2135 		{
  2136 		ERR_PRINTF2(_L("Thread exits with error code %d"), res);
  2137 		}
  2138 	thread.Close();
  2139 	}
  2140 
  2141 /**
  2142  * Ensure that there is no outstanding request from all receivers
  2143  */
  2144 void CTSurfaceUpdate::WaitUntilAllNotificationsProcessed()
  2145 	{
  2146 	const TInt KMaxIterationNumber = 10;
  2147 	TInt ii = 0;
  2148 	for(; ii < KMaxIterationNumber; ii++)
  2149 		{
  2150 		if(((iReceivers[0]->OutstandingRequest() == EFalse)) &&
  2151 				((iReceivers[1]->OutstandingRequest() == EFalse)) &&
  2152 				((iReceivers[2]->OutstandingRequest() == EFalse)))
  2153 				break;
  2154 		INFO_PRINTF2(_L("Wait until all notification processed, iteration %d"), ii);
  2155 		User::After(KCompositionIntervalLong);
  2156 		}
  2157 	TEST(ii < KMaxIterationNumber);//We have waited enough, if it fails, something weird going on
  2158 	}
  2159 
  2160 void CTSurfaceUpdate::RunTestCaseL(TInt aCurTestCase)
  2161 	{
  2162 	((CTSurfaceUpdateStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
  2163 	switch(aCurTestCase)
  2164 		{
  2165 	case 1:
  2166 		{
  2167 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0001"));
  2168 		if((static_cast <CTSurfaceUpdateStep*> (iStep)) -> iGce)
  2169 			{
  2170 			INFO_PRINTF1(_L("TestCase1"));
  2171 			TRAPD(ret, TestCase1());
  2172 			TEST(ret == KErrNone);
  2173 			}
  2174 		else
  2175 			{
  2176 			TestComplete();		
  2177 			}	
  2178 		break;
  2179 		}
  2180 	case 2:
  2181 		{
  2182 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0002"));
  2183 		INFO_PRINTF1(_L("TestCase2L"));
  2184 		TRAPD(ret, TestCase2L());
  2185 		TEST(ret == KErrNone);
  2186 		break;
  2187 		}
  2188 	case 3:
  2189 		{
  2190 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0003"));
  2191 		INFO_PRINTF1(_L("TestCase3L"));
  2192 		TRAPD(ret, TestCase3L());
  2193 		TEST(ret == KErrNone);
  2194 		break;
  2195 		}
  2196 	case 4:
  2197 		{
  2198 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0004"));
  2199 		INFO_PRINTF1(_L("TestCase4L"));
  2200 		TRAPD(ret, TestCase4L());
  2201 		TEST(ret == KErrNone);
  2202 		break;
  2203 		}
  2204 	case 5:
  2205 		{
  2206 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0005"));
  2207 		INFO_PRINTF1(_L("TestCase5L"));
  2208 		TRAPD(ret, TestCase5L());
  2209 		TEST(ret == KErrNone);
  2210 		break;
  2211 		}
  2212 	case 6:
  2213 		{
  2214 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0006"));
  2215 		INFO_PRINTF1(_L("TestCase6L"));
  2216 		TRAPD(ret, TestCase6L());
  2217 		TEST(ret == KErrNone);
  2218 		break;
  2219 		}
  2220 	case 7:
  2221 		{
  2222 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0014"));
  2223 		INFO_PRINTF1(_L("TestCase7L"));
  2224 		TRAPD(ret, TestCase7L());
  2225 		TEST(ret == KErrNone);
  2226 		break;
  2227 		}
  2228 	case 8:
  2229 		{
  2230 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0015"));
  2231 		INFO_PRINTF1(_L("TestCase8"));
  2232 		TRAPD(ret, TestCase8());
  2233 		TEST(ret == KErrNone);
  2234 		break;
  2235 		}
  2236 	case 9:
  2237  		{
  2238  		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0016"));
  2239  		INFO_PRINTF1(_L("TestCase9L"));
  2240  		TRAPD(ret, TestCase9L());
  2241  		TEST(ret == KErrNone);
  2242  		break;
  2243 		}
  2244 	case 10:
  2245  		{
  2246  		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0017"));
  2247  		INFO_PRINTF1(_L("TestCase10"));
  2248  		TRAPD(ret, TestCase10());
  2249  		TEST(ret == KErrNone);
  2250  		break;
  2251 		}
  2252 	case 11:
  2253  		{
  2254  		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0018"));
  2255  		INFO_PRINTF1(_L("TestCase11"));
  2256  		TRAPD(ret, TestCase11());
  2257  		TEST(ret == KErrNone);
  2258  		break;
  2259 		}
  2260     case 12:
  2261         {
  2262         ((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0019"));
  2263         INFO_PRINTF1(_L("TestCase12L"));
  2264         TRAPD(ret, TestCase12L());
  2265         TEST(ret == KErrNone);
  2266         break;
  2267         }
  2268 	case 13:
  2269  		{
  2270  		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0020"));
  2271  		INFO_PRINTF1(_L("TestCase13L"));
  2272  		TRAPD(ret, TestCase13L());
  2273  		TEST(ret == KErrNone);
  2274  		break;
  2275 		}
  2276 	case 14:
  2277  		{
  2278  		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0022"));
  2279  		INFO_PRINTF1(_L("TestCase14"));
  2280  		TestCase14();
  2281  		break;
  2282 		}
  2283 	case 15:
  2284  		{
  2285 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0023"));
  2286  		INFO_PRINTF1(_L("TestCase15"));
  2287  		TRAPD(ret, TestCase15());
  2288  		TEST(ret == KErrNone);
  2289  		break;
  2290 		}
  2291 	case 16:
  2292  		{
  2293 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0024"));
  2294  		INFO_PRINTF1(_L("TestCase16"));
  2295  		TRAPD(ret, TestCase16L());
  2296  		TEST(ret == KErrNone);
  2297  		break;
  2298 		}
  2299 	case 17:
  2300  		{
  2301 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0028"));
  2302  		INFO_PRINTF1(_L("TestCase17"));
  2303  		TRAPD(ret, TestCase17());
  2304  		TEST(ret == KErrNone);
  2305  		break;
  2306 		}
  2307 	case 18:
  2308  		{
  2309 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0025"));
  2310  		INFO_PRINTF1(_L("TestCase18"));
  2311  		TRAPD(ret, TestCase18());
  2312  		TEST(ret == KErrNone);
  2313  		break;
  2314 		}
  2315 	case 19:
  2316 		{
  2317 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0027"));
  2318 	 	INFO_PRINTF1(_L("TestCaseNotifyWhenAvailableGlobal"));
  2319  		TRAPD(ret, TestCaseNotifyWhenAvailableGlobal());
  2320  		TEST(ret == KErrNone);
  2321  		break;
  2322 		}
  2323 	case 20:
  2324 		{
  2325 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0029"));
  2326 	 	INFO_PRINTF1(_L("TestCaseRegisterIdenticalPrioritiesL"));
  2327  		TRAPD(ret, TestCaseRegisterIdenticalPrioritiesL());
  2328  		TEST(ret == KErrNone);
  2329  		break;
  2330 		}
  2331 	case 21:
  2332  		{//should be the last test case
  2333 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0021"));
  2334  		INFO_PRINTF1(_L("TestCaseTerminateServer"));
  2335  		TRAPD(ret, TestCaseTerminateServer());
  2336  		TEST(ret == KErrNone);
  2337  		break;
  2338 		}
  2339 	default:
  2340 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
  2341 		((CTSurfaceUpdateStep*)iStep)->CloseTMSGraphicsStep();
  2342 		TestComplete();		
  2343 		break;
  2344 		}
  2345 	((CTSurfaceUpdateStep*)iStep)->RecordTestResultL();
  2346 	}
  2347 
  2348 //--------------
  2349 __CONSTRUCT_STEP__(SurfaceUpdate)
  2350 
  2351 void CTSurfaceUpdateStep::TestSetupL()
  2352 	{
  2353 #ifdef __WINS__
  2354 	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty,  (TAny*)"symbian_graphics_use_gce",  &iGce);
  2355 #else
  2356 	iGce = ETrue;
  2357 // we would need to check here whether it is gce-mode or not.	
  2358 #endif	
  2359 	if(iGce)
  2360 		{
  2361 		User::LeaveIfError(StartServer());
  2362 		}
  2363 	else
  2364 		{//it should work for both cases, but that would be waste of time
  2365 		INFO_PRINTF1(_L("This test must be run in the GCE environment"));
  2366 		}	
  2367 	}
  2368 	
  2369 void CTSurfaceUpdateStep::TestClose()
  2370 	{
  2371 	TerminateServer();
  2372 	}
  2373 
  2374 TInt CTSurfaceUpdateStep::StartServer()
  2375 	{
  2376 	return StartSurfaceUpdateServer(iSurfaceUpdateProvider);
  2377 	}
  2378 	
  2379 void CTSurfaceUpdateStep::TerminateServer()
  2380 	{
  2381 	if(iSurfaceUpdateProvider)
  2382 		{
  2383 		iSurfaceUpdateProvider->Terminate();
  2384 		iSurfaceUpdateProvider = NULL;
  2385 		}
  2386 	}
  2387 	
  2388 //-------------
  2389 // Code for client that doesn't quite behave as it should
  2390 
  2391 TInt RMisbehavingSession::Connect(TInt aMessageSlots, TBool aWrongVersion /*= false*/)
  2392 	{
  2393 	if(Handle())
  2394 		{
  2395 		return KErrAlreadyExists; 
  2396 		}
  2397 	iStatusAvailable = NULL;
  2398 	iStatusDisplayed = NULL;
  2399 	iStatusDisplayedXTimes = NULL;
  2400 	if(aWrongVersion)
  2401 		return CreateSession(KTestSurfaceUpdateServerName, WrongVersion(), aMessageSlots);
  2402 	else
  2403 		return CreateSession(KTestSurfaceUpdateServerName, Version(), aMessageSlots);
  2404 	}
  2405 	
  2406 
  2407 void RMisbehavingSession::Close()
  2408 	{
  2409 	if(Handle())
  2410 		{
  2411 		RHandleBase::Close();
  2412 		}
  2413 	iStatusAvailable = NULL;
  2414 	iStatusDisplayed = NULL;
  2415 	iStatusDisplayedXTimes = NULL;
  2416 	}
  2417 	
  2418 TVersion RMisbehavingSession::Version() const
  2419 	{
  2420 	return (TVersion(KSurfaceUpdateServMajorVersionNumber, KSurfaceUpdateServMinorVersionNumber, KSurfaceUpdateServBuildVersionNumber));
  2421 	}
  2422 	
  2423 TVersion RMisbehavingSession::WrongVersion() const
  2424 	{
  2425 	return (TVersion(KSurfaceUpdateServMajorVersionNumber + 1, KSurfaceUpdateServMinorVersionNumber + 1, KSurfaceUpdateServBuildVersionNumber + 1));
  2426 	}
  2427 
  2428 /**
  2429 Send the NotifyWhenAvailable request directly to the server (without waiting for submit)
  2430 */
  2431 void RMisbehavingSession::NotifyWhenAvailableNoChecking(TRequestStatus& aStatus)
  2432 	{
  2433 	SendReceive(EUpdateServNotifyWhenAvailable, aStatus);
  2434 	}
  2435 
  2436 /**
  2437 Send the NotifyWhenDisplayed request directly to the server (without waiting for submit)
  2438 */
  2439 void RMisbehavingSession::NotifyWhenDisplayedNoChecking(TRequestStatus& aStatus)
  2440 	{
  2441 	TTimeStamp* timeStamp = NULL;	
  2442 	TIpcArgs args(timeStamp);
  2443 	SendReceive(EUpdateServNotifyWhenDisplayed, args, aStatus);
  2444 	}
  2445 
  2446 /**
  2447 Send the NotifyWhenDisplayedXTimes request directly to the server (without waiting for submit)
  2448 */
  2449 void RMisbehavingSession::NotifyWhenDisplayedXTimesNoChecking(TInt aCount, TRequestStatus& aStatus)
  2450 	{
  2451 	TIpcArgs args(aCount);
  2452 	SendReceive(EUpdateServNotifyWhenDisplayedXTimes, args, aStatus);
  2453 	}
  2454 
  2455 /**
  2456 Submit an update to the server without doing any checking of values such as screen number and buffer
  2457 */
  2458 TInt RMisbehavingSession::SubmitUpdateNoChecking(TInt aScreen, const TSurfaceId& aSurfaceId, 
  2459 									TInt aBuffer, const TRegion* aDirtyRegion)
  2460 	{
  2461 	TPckgC<TSurfaceId> pckgSurfaceId(aSurfaceId);
  2462 	TIpcArgs theArgs(aScreen, &pckgSurfaceId, aBuffer);
  2463 	if(aDirtyRegion)
  2464 		{
  2465 		const TInt regionCount = aDirtyRegion->Count();
  2466 		if(regionCount > 0)
  2467 			{
  2468 			TPtrC8 ptrRect(reinterpret_cast<const TUint8*> (aDirtyRegion->RectangleList()), regionCount * sizeof(TRect));
  2469 			theArgs.Set(3, &ptrRect);
  2470 			}
  2471 		}
  2472 	return SendReceive(EUpdateServSubmitUpdate, theArgs);
  2473 	}
  2474 
  2475 /**
  2476 Pass an invalid opcode to the surface update server
  2477 */
  2478 void RMisbehavingSession::TestPassingInvalidOpcode(TInt aInvalidOpcode)
  2479 	{
  2480 	SendReceive(aInvalidOpcode);
  2481 	}
  2482 
  2483 /**
  2484 Set the fail rate for OOM checking, server side.
  2485 */	
  2486 void RMisbehavingSession::SetFailRate(TInt aFailRate)
  2487 	{
  2488 	TIpcArgs args(aFailRate);
  2489 	SendReceive(EUpdateServOOM, args);
  2490 	}
  2491 
  2492 /**
  2493 Implementation of NotifyWhenAvailable. Intended to behave the same as 
  2494 RSurfaceUpdateSession::NotifyWhenAvailable except it assumes that the handle
  2495 to the RClass is never a Null handle.
  2496 */
  2497 void RMisbehavingSession::NotifyWhenAvailable(TRequestStatus& aStatus)
  2498 	{
  2499 	iStatusAvailable = &aStatus;
  2500 	}
  2501 
  2502 /**
  2503 Implementation of NotifyWhenDisplayed. Intended to behave the same as 
  2504 RSurfaceUpdateSession::NotifyWhenDisplayed except it assumes that the handle
  2505 to the RClass is never a Null handle.
  2506 */
  2507 void RMisbehavingSession::NotifyWhenDisplayed(TRequestStatus& aStatus, TTimeStamp& aTimeStamp)
  2508 	{
  2509 	iStatusDisplayed = &aStatus;
  2510 	iTimeStamp = &aTimeStamp;
  2511 	}
  2512 
  2513 /**
  2514 Implementation of NotifyWhenDisplayedXTimes. Intended to behave the same as 
  2515 RSurfaceUpdateSession::NotifyWhenDisplayedXTimes except it assumes that the handle
  2516 to the RClass is never a Null handle.
  2517 */
  2518 void RMisbehavingSession::NotifyWhenDisplayedXTimes(TInt aCount, TRequestStatus& aStatus)
  2519 	{
  2520 	iStatusDisplayedXTimes = &aStatus;
  2521 	iCount = aCount;
  2522 	}
  2523 
  2524 /**
  2525 Implementation of NotifyWhenAvailable. Intended to behave the same as 
  2526 RSurfaceUpdateSession::NotifyWhenAvailable except it assumes that the user
  2527 will not pass invalid parameters to the function.
  2528 */
  2529 TInt RMisbehavingSession::SubmitUpdate(TInt aScreen, const TSurfaceId& aSurfaceId, 
  2530 											TInt aBuffer, const TRegion* aDirtyRegion/* = NULL*/)
  2531 	{
  2532 	if(iStatusAvailable)
  2533 		{
  2534 		SendReceive(EUpdateServNotifyWhenAvailable, *iStatusAvailable);
  2535 		iStatusAvailable= NULL;
  2536 		}
  2537 	
  2538 	if(iStatusDisplayed)
  2539 		{
  2540 		TIpcArgs args(iTimeStamp);
  2541 		SendReceive(EUpdateServNotifyWhenDisplayed, args, *iStatusDisplayed);
  2542 		iStatusDisplayed=NULL;
  2543 		}
  2544 		
  2545 	if(iStatusDisplayedXTimes)
  2546 		{
  2547 		TIpcArgs args(iCount);
  2548 		SendReceive(EUpdateServNotifyWhenDisplayedXTimes, 
  2549                      	args, *iStatusDisplayedXTimes);	
  2550 		iStatusDisplayedXTimes=NULL;
  2551 		}
  2552 
  2553 	TPckgC<TSurfaceId> pckgSurfaceId(aSurfaceId);
  2554 	TIpcArgs theArgs(aScreen, &pckgSurfaceId, aBuffer);
  2555 
  2556 	if(aDirtyRegion)
  2557 		{
  2558 		const TInt regionCount = aDirtyRegion->Count();
  2559 		if(regionCount > 0)
  2560 			{
  2561 			TPtrC8 ptrRect(reinterpret_cast<const TUint8*> (aDirtyRegion->RectangleList()), regionCount * sizeof(TRect));
  2562 			theArgs.Set(3, &ptrRect);
  2563 			}
  2564 		}
  2565 
  2566 	//final request for composition 
  2567 	return SendReceive(EUpdateServSubmitUpdate, theArgs);
  2568 	}
  2569 
  2570 /**
  2571 Implementation of NotifyWhenAvailable. Intended to behave the same as 
  2572 RSurfaceUpdateSession::CancelAllUpdateNotifications except it assumes that the handle
  2573 to the RClass is never a Null handle.
  2574 */
  2575 void RMisbehavingSession::CancelAllUpdateNotifications()
  2576 	{
  2577 	SendReceive(EUpdateServCancelAllNotifications);
  2578 	}
  2579 
  2580