os/graphics/graphicscomposition/surfaceupdate/tsrc/tsurfaceupdate.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/surfaceupdate/tsrc/tsurfaceupdate.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2580 @@
     1.4 +// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +#include <e32std.h>
    1.26 +#include <hal.h>
    1.27 +#include <u32hal.h>
    1.28 +
    1.29 +#include <graphics/surfaceupdateclient.h>
    1.30 +#include <graphics/suerror.h>
    1.31 +#include <limits.h>
    1.32 +#include "surfaceupdatetest.h"
    1.33 +#include "tsurfaceupdate.h"
    1.34 +#include "surfaceupdate.h"
    1.35 +
    1.36 +
    1.37 +CTSurfaceUpdate::CTSurfaceUpdate(CTestStep* aStep) :
    1.38 +	CTGraphicsBase(aStep)
    1.39 +	{
    1.40 +	}
    1.41 +
    1.42 +CTSurfaceUpdate::~CTSurfaceUpdate()
    1.43 +	{
    1.44 +	while (iReceivers.Count())
    1.45 +		{
    1.46 +		CTContentUpdateReceiver *receiver = iReceivers[0];
    1.47 +		iReceivers.Remove(0);
    1.48 +		CloseTestUpdateReceiver(receiver);
    1.49 +		}
    1.50 +	iReceivers.Reset();	
    1.51 +	}
    1.52 +
    1.53 +void CTSurfaceUpdate::ConstructL()
    1.54 +	{
    1.55 +	SetupContentUpdateReceiversL();
    1.56 +	}
    1.57 +
    1.58 +void CTSurfaceUpdate::SetupContentUpdateReceiversL()
    1.59 +	{
    1.60 +	//first receiver
    1.61 +	CTContentUpdateReceiver *receiver;
    1.62 +	User::LeaveIfError(StartTestUpdateReceiver(receiver, 1));
    1.63 +	iReceivers.AppendL(receiver);
    1.64 +	
    1.65 +	//second receiver
    1.66 +	CTContentUpdateReceiver *receiver2;
    1.67 +	User::LeaveIfError(StartTestUpdateReceiver(receiver2, 2));
    1.68 +	iReceivers.AppendL(receiver2);
    1.69 +	
    1.70 +	//third receiver
    1.71 +	CTContentUpdateReceiver *receiver3;
    1.72 +	User::LeaveIfError(StartTestUpdateReceiver(receiver3, 3));
    1.73 +	iReceivers.AppendL(receiver3);
    1.74 +	
    1.75 +	User::LeaveIfError(Provider()->Register(0, receiver, -1));
    1.76 +	User::LeaveIfError(Provider()->Register(1, receiver2, 1));
    1.77 +	User::LeaveIfError(Provider()->Register(2, receiver3, 2));
    1.78 +	}
    1.79 +
    1.80 +/**
    1.81 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0001
    1.82 +
    1.83 +
    1.84 +  @SYMPREQ 1007
    1.85 +
    1.86 +  @SYMREQ 8223
    1.87 +
    1.88 +  @SYMTestCaseDesc Initialization of the server environment twice.
    1.89 +
    1.90 +  @SYMTestPriority High
    1.91 +
    1.92 +  @SYMTestStatus Implemented
    1.93 +
    1.94 +  @SYMTestActions Attempt to start the server for the second time.
    1.95 +
    1.96 +  @SYMTestExpectedResults Must return KErrAlreadyExists.
    1.97 +*/
    1.98 +void CTSurfaceUpdate::TestCase1()
    1.99 +	{
   1.100 +	INFO_PRINTF1(_L("Attempt to start the server for the second time"));
   1.101 +	MSurfaceUpdateServerProvider *surfaceUpdateProvider = NULL;
   1.102 +	TInt res = StartSurfaceUpdateServer(surfaceUpdateProvider);
   1.103 +	TEST(res==KErrNone);
   1.104 +	TEST(surfaceUpdateProvider!=NULL);
   1.105 +	TEST(surfaceUpdateProvider==Provider());
   1.106 +	}
   1.107 +
   1.108 +/**
   1.109 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0002
   1.110 +
   1.111 +  @SYMPREQ 1007
   1.112 +
   1.113 +  @SYMREQ 8223
   1.114 +
   1.115 +  @SYMTestCaseDesc Submit update commands and subscribe for notifications. 
   1.116 +
   1.117 +  @SYMTestPriority High
   1.118 +
   1.119 +  @SYMTestStatus Implemented
   1.120 +
   1.121 +  @SYMTestActions Create connection to the server. 
   1.122 +  		Subscribe for different notifications (consumed, displayed, displayedXTimes). 
   1.123 +  		Submit update command. Wait for notifications to arrive. 
   1.124 +  		Repeat for a few times in a row .
   1.125 +
   1.126 +  @SYMTestExpectedResults Errors, which will be conveyed in 
   1.127 +  TRequestStatus must be equal to KErrNone. The order must be consistent with 
   1.128 +  before and after submission (Before submission < composition < after submission). 
   1.129 +*/
   1.130 +void CTSurfaceUpdate::TestCase2L()
   1.131 +	{
   1.132 +	INFO_PRINTF1(_L("Submit update and subscribe for notifications"));
   1.133 +	const TInt KMaxSubmissionNumber = 60; //it should be divisible by 3!
   1.134 +	RSurfaceUpdateSession session;
   1.135 +	TInt res = session.Connect();
   1.136 +	User::LeaveIfError(res);
   1.137 +	
   1.138 +	iSurfaceOrder = CRequestOrder::NewL(KMaxSubmissionNumber);
   1.139 +	    
   1.140 +	iReceivers[0]->SetCompositionOrder(iSurfaceOrder);
   1.141 +	iReceivers[1]->SetCompositionOrder(iSurfaceOrder);
   1.142 +	iReceivers[2]->SetCompositionOrder(iSurfaceOrder);
   1.143 +	
   1.144 +	TInt screen = 0;
   1.145 +	TInt buffer = 2;
   1.146 +	TSurfaceId surface = 
   1.147 +		{
   1.148 +		1,2,3,4
   1.149 +		};
   1.150 +	TRect rc[2] =
   1.151 +			{
   1.152 +			TRect(1,2, 10, 20),
   1.153 +			TRect(5,6, 30, 30)
   1.154 +			};
   1.155 +	RRegion region(2, rc);
   1.156 +
   1.157 +	// Test that submitting for an update before any noitfications causes no problems
   1.158 +	TEST(KErrNone == session.SubmitUpdate(screen, surface, buffer, &region));
   1.159 +
   1.160 +	iSurfaceOrder->ResetAll();
   1.161 +	for(TInt submissionNumber = 0; submissionNumber < KMaxSubmissionNumber/3; submissionNumber++)
   1.162 +		{
   1.163 +		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   1.164 +
   1.165 +		TRequestStatus status = KRequestPending;
   1.166 +		TRequestStatus status1 = KRequestPending;
   1.167 +		TRequestStatus status2 = KRequestPending;
   1.168 +		TTimeStamp timeStamp; 
   1.169 +	
   1.170 +		iSurfaceOrder->SetOrder(EOrderBefore);
   1.171 +		session.NotifyWhenAvailable(status);	
   1.172 +		session.NotifyWhenDisplayed(status1, timeStamp);	
   1.173 +		session.NotifyWhenDisplayedXTimes(10, status2);
   1.174 +		
   1.175 +		res = session.SubmitUpdate(screen, surface, buffer, &region);
   1.176 +		TEST(res==KErrNone);
   1.177 +		
   1.178 +		User::WaitForRequest(status);
   1.179 +		User::WaitForRequest(status1);
   1.180 +		User::WaitForRequest(status2);
   1.181 +		iSurfaceOrder->SetOrder(EOrderAfter);
   1.182 +
   1.183 +		TEST(status == KErrNone);
   1.184 +		TEST(status1 == KErrNone);
   1.185 +		TEST(status2 == KErrNone);
   1.186 +		}
   1.187 +	
   1.188 +    for(TInt i=0; i < KMaxSubmissionNumber/3; i++)
   1.189 +        {
   1.190 +        TInt positionBefore=-1;
   1.191 +        TInt positionComposition=-1;
   1.192 +        TInt positionAfter=-1;
   1.193 +        for(TInt j=0; j < KMaxSubmissionNumber; j++)
   1.194 +            {
   1.195 +            if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderBefore))
   1.196 +                {
   1.197 +                positionBefore=j;
   1.198 +                }
   1.199 +            
   1.200 +            if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderComposition))
   1.201 +                {
   1.202 +                positionComposition=j;
   1.203 +                }
   1.204 +                
   1.205 +            if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderAfter))
   1.206 +                {
   1.207 +                positionAfter=j;
   1.208 +                }
   1.209 +            }
   1.210 +        TEST((positionBefore != -1) && (positionComposition != -1) && (positionAfter != -1));
   1.211 +        TEST(positionBefore < positionComposition);
   1.212 +        TEST(positionAfter > positionComposition);
   1.213 +        }
   1.214 +	
   1.215 +	delete iSurfaceOrder;
   1.216 +	iSurfaceOrder = NULL;
   1.217 +	iReceivers[0]->SetCompositionOrder(NULL);
   1.218 +	iReceivers[1]->SetCompositionOrder(NULL);
   1.219 +	iReceivers[2]->SetCompositionOrder(NULL);
   1.220 +	
   1.221 +	session.Close();
   1.222 +	}
   1.223 +
   1.224 +/**
   1.225 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0003
   1.226 +
   1.227 +  @SYMPREQ 1007
   1.228 +  
   1.229 +  @SYMREQ 8223
   1.230 +
   1.231 +  @SYMTestCaseDesc Submit a few requests, then consume them. 
   1.232 +
   1.233 +  @SYMTestPriority High
   1.234 +
   1.235 +  @SYMTestStatus Implemented
   1.236 +
   1.237 +  @SYMTestActions A. Request notifications of the same type consecutively 
   1.238 +  	(no submit in-between) and check that the behaviour is correct.
   1.239 +    B. Create connection to the server with sufficient number of 
   1.240 +  	outstanding asynchronous message slots. 
   1.241 +  	1. Subscribe for different notifications (consumed, displayed, 
   1.242 +  	displayedXTimes). 
   1.243 +  	2. Submit update command. 
   1.244 +  	3 Repeat step 1 & 2 a few times. 
   1.245 +  	Wait for notifications (from all requests) to arrive. 
   1.246 +  	Repeat 1& 2 & 3 a few times in a row
   1.247 +
   1.248 +  @SYMTestExpectedResults A. The last of each notification request type 
   1.249 +  to be issued before the submission will return with KErrNone, as will 
   1.250 +  the SubmitUpdate. B. Errors, which will be conveyed in TRequestStatus 
   1.251 +  must be equal to KErrNone. The order must be consistent with 
   1.252 +  before and after submission (Before submission < composition < after submission).  
   1.253 +*/
   1.254 +void CTSurfaceUpdate::TestCase3L()
   1.255 +	{
   1.256 +	INFO_PRINTF1(_L("Submission a few update requests in  a row, then waiting for notifications to arrive"));
   1.257 +	RSurfaceUpdateSession session;
   1.258 +	
   1.259 +	const TInt KNumberAsynchronousRequests = 42; //it should be divisible by 3!
   1.260 +	TInt res = session.Connect(KNumberAsynchronousRequests);
   1.261 +	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests as: %d"), KNumberAsynchronousRequests);	
   1.262 +	User::LeaveIfError(res);
   1.263 +	
   1.264 +	iSurfaceOrder = CRequestOrder::NewL(KNumberAsynchronousRequests);
   1.265 +	
   1.266 +	iReceivers[0]->SetCompositionOrder(iSurfaceOrder);
   1.267 +	iReceivers[1]->SetCompositionOrder(iSurfaceOrder);
   1.268 +	iReceivers[2]->SetCompositionOrder(iSurfaceOrder);
   1.269 +	
   1.270 +	TInt screen = 0;
   1.271 +	TInt screen1 = 1;
   1.272 +	TInt buffer = 2;
   1.273 +	TSurfaceId surface = 
   1.274 +		{
   1.275 +		1,2,3,4
   1.276 +		};
   1.277 +	
   1.278 +	TRect rc[] =
   1.279 +			{
   1.280 +			TRect(1,2, 3, 4),
   1.281 +			TRect(5,6, 7, 8),
   1.282 +			TRect(9, 10, 11, 12),
   1.283 +			TRect(13, 14, 15, 16),
   1.284 +			};
   1.285 +	RRegion region(4, rc);
   1.286 +	
   1.287 +	// Test calling two notifies in a row followed by a submit
   1.288 +	TRequestStatus stat[6];
   1.289 +	session.NotifyWhenAvailable(stat[0]);
   1.290 +	session.NotifyWhenAvailable(stat[1]);
   1.291 +	TTimeStamp tStamp[2];
   1.292 +	session.NotifyWhenDisplayed(stat[2], tStamp[0]);
   1.293 +	session.NotifyWhenDisplayed(stat[3], tStamp[1]);
   1.294 +	session.NotifyWhenDisplayedXTimes(10, stat[4]);
   1.295 +	session.NotifyWhenDisplayedXTimes(10, stat[5]);	
   1.296 +	TEST(KErrNone == session.SubmitUpdate(0 , surface, buffer, &region));
   1.297 +	// The last requests for notification will be fulfilled, the others ignored
   1.298 +	User::WaitForRequest(stat[1]);
   1.299 +	User::WaitForRequest(stat[3]);
   1.300 +	User::WaitForRequest(stat[5]);	
   1.301 +	TEST(stat[1] == KErrNone);
   1.302 +	TEST(stat[3] == KErrNone);
   1.303 +	TEST(stat[5] == KErrNone);
   1.304 +	
   1.305 +	// Submit a few requests, then consume them
   1.306 +	for(TInt index1 = 0; index1 < 5; index1++)
   1.307 +		{
   1.308 +		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   1.309 +
   1.310 +		TRequestStatus status[KNumberAsynchronousRequests];
   1.311 +		TTimeStamp timeStamp[KNumberAsynchronousRequests];
   1.312 +		
   1.313 +		// Reset all values
   1.314 +		iSurfaceOrder->ResetAll();
   1.315 +		
   1.316 +		for(TInt index2 = 0; index2 < KNumberAsynchronousRequests; index2 += 3)
   1.317 +			{
   1.318 +			INFO_PRINTF2(_L("Submission number %d"), index2 / 3 + 1);	
   1.319 +			status[index2]=KRequestPending;
   1.320 +			session.NotifyWhenAvailable(status[index2]);	
   1.321 +			status[index2 + 1]=KRequestPending;
   1.322 +			session.NotifyWhenDisplayed(status[index2 + 1], timeStamp[index2 / 3]);	
   1.323 +			status[index2 + 2]=KRequestPending;
   1.324 +			session.NotifyWhenDisplayedXTimes(10, status[index2 + 2]);
   1.325 +			
   1.326 +			iSurfaceOrder->SetOrder(EOrderBefore);
   1.327 +			
   1.328 +			res = session.SubmitUpdate((index2 % 2) ? screen : screen1, surface, buffer, &region);
   1.329 +			TEST(res==KErrNone);
   1.330 +			}
   1.331 +		
   1.332 +		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests; submissionNumber++)
   1.333 +			{
   1.334 +			User::WaitForRequest(status[submissionNumber]);
   1.335 +			TEST(status[submissionNumber] == KErrNone);
   1.336 +			
   1.337 +			if(((submissionNumber - 1) % 3) == 0)
   1.338 +				{
   1.339 +				iSurfaceOrder->SetOrder(EOrderAfter);
   1.340 +				}
   1.341 +			}
   1.342 +		
   1.343 +		for(TInt i=0; i < KNumberAsynchronousRequests/3; i++)
   1.344 +			{
   1.345 +			TInt positionBefore=-1;
   1.346 +			TInt positionComposition=-1;
   1.347 +			TInt positionAfter=-1;
   1.348 +			for(TInt j=0; j < KNumberAsynchronousRequests; j++)
   1.349 +				{
   1.350 +				if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderBefore))
   1.351 +					{
   1.352 +					positionBefore=j;
   1.353 +					}
   1.354 +				
   1.355 +				if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderComposition))
   1.356 +					{
   1.357 +					positionComposition=j;
   1.358 +					}
   1.359 +					
   1.360 +				if((iSurfaceOrder->GetOrderNumber(j) == i) && (iSurfaceOrder->GetOrderType(j) == EOrderAfter))
   1.361 +					{
   1.362 +					positionAfter=j;
   1.363 +					}
   1.364 +				}
   1.365 +			TEST((positionBefore != -1) && (positionComposition != -1) && (positionAfter != -1));
   1.366 +			TEST(positionBefore < positionComposition);
   1.367 +			TEST(positionAfter > positionComposition);
   1.368 +			}
   1.369 +		}
   1.370 +		
   1.371 +	delete iSurfaceOrder;
   1.372 +	iSurfaceOrder = NULL;
   1.373 +	iReceivers[0]->SetCompositionOrder(NULL);
   1.374 +	iReceivers[1]->SetCompositionOrder(NULL);
   1.375 +	iReceivers[2]->SetCompositionOrder(NULL);
   1.376 +	
   1.377 +	session.Close();
   1.378 +	}
   1.379 +
   1.380 +/**
   1.381 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0004
   1.382 +
   1.383 +  @SYMPREQ 1007
   1.384 +  
   1.385 +  @SYMREQ 8223
   1.386 +
   1.387 +  @SYMTestCaseDesc Cancellation of the requests. 
   1.388 +
   1.389 +  @SYMTestPriority High
   1.390 +
   1.391 +  @SYMTestStatus Implemented
   1.392 +
   1.393 +  @SYMTestActions Create connection to the server.
   1.394 +  	1. Test cancellation without SubmitUpdate
   1.395 +    2. Check cancellation before submission does nothing bad.
   1.396 +  	3. Subscribe for different notifications (consumed, displayed, 
   1.397 +  	displayedXTimes). 
   1.398 +  	4. Submit update command. 5. Repeat steps 3 & 4 a few times. 
   1.399 +  	Cancel all outstanding notifications. Wait for cancelled notifications 
   1.400 +  	to arrive.
   1.401 +
   1.402 +  @SYMTestExpectedResults Notifications must arrive straightway with 
   1.403 +  KErrCancel error code or KErrNone, if events have already occurred.
   1.404 +*/
   1.405 +void CTSurfaceUpdate::TestCase4L()
   1.406 +	{
   1.407 +	INFO_PRINTF1(_L("Submission a few requests in a row and then cancelling them"));
   1.408 +	RSurfaceUpdateSession session;
   1.409 +	
   1.410 +	const TInt KNumberAsynchronousRequests = 99; //should be divisible by 3!
   1.411 +	TInt res = session.Connect(KNumberAsynchronousRequests);
   1.412 +	INFO_PRINTF1(_L("Test CancelAllUpdateNotifications without SubmitUpdate"));
   1.413 +	// Test CancelAllUpdateNotifications without SubmitUpdate
   1.414 +	TRequestStatus status1, status2, status3;
   1.415 +	TTimeStamp ts;
   1.416 +	session.NotifyWhenAvailable(status1);
   1.417 +	session.NotifyWhenDisplayed(status2, ts);
   1.418 +	session.NotifyWhenDisplayedXTimes(5, status3);
   1.419 +	session.CancelAllUpdateNotifications();
   1.420 +	User::WaitForRequest(status1);
   1.421 +	User::WaitForRequest(status2);
   1.422 +	User::WaitForRequest(status3);
   1.423 +	TEST(status1==KErrCancel);
   1.424 +	TEST(status2==KErrCancel);
   1.425 +	TEST(status3==KErrCancel);
   1.426 +	
   1.427 +	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests as: %d"), KNumberAsynchronousRequests);	
   1.428 +	User::LeaveIfError(res);
   1.429 +	
   1.430 +	TInt screen = 0;
   1.431 +	TInt screen1 = 1;
   1.432 +	TInt buffer = 2;
   1.433 +	TSurfaceId surface = 
   1.434 +		{
   1.435 +		1,2,3,4
   1.436 +		};
   1.437 +	TRect rc[] =
   1.438 +			{
   1.439 +			TRect(1,2, 3, 4),
   1.440 +			TRect(5,6, 7, 8),
   1.441 +			TRect(9, 10, 11, 12),
   1.442 +			TRect(13, 14, 15, 16),
   1.443 +			};
   1.444 +	RRegion region(4, rc);
   1.445 +	
   1.446 +	// Check that cancelling notifications before any submission does nothing bad
   1.447 +	session.CancelAllUpdateNotifications();
   1.448 +	
   1.449 +	for(TInt index1 = 0; index1 < 2; index1++)
   1.450 +		{
   1.451 +		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   1.452 +
   1.453 +		TRequestStatus status[KNumberAsynchronousRequests];
   1.454 +		
   1.455 +		TTimeStamp timeStamp[KNumberAsynchronousRequests];
   1.456 +		TUint64 timestampComposition[KNumberAsynchronousRequests];
   1.457 +		TUint64 timestampBefore[KNumberAsynchronousRequests];
   1.458 +		TUint64 timestampAfter[KNumberAsynchronousRequests];
   1.459 +		for(TInt index2 = 0; index2 < KNumberAsynchronousRequests; index2 += 3)
   1.460 +			{
   1.461 +			INFO_PRINTF2(_L("Submission number %d"), index2 / 3 + 1);	
   1.462 +			status[index2]=KRequestPending;
   1.463 +			session.NotifyWhenAvailable(status[index2]);	
   1.464 +			status[index2 + 1]=KRequestPending;
   1.465 +			session.NotifyWhenDisplayed(status[index2 + 1], timeStamp[index2 / 3]);	
   1.466 +			status[index2 + 2]=KRequestPending;
   1.467 +			session.NotifyWhenDisplayedXTimes(10, status[index2 + 2]);	
   1.468 +			
   1.469 +			timestampBefore[index2 / 3] = User::FastCounter();	
   1.470 +			res = session.SubmitUpdate((index2 % 2) ? screen : screen1, surface, buffer, &region);
   1.471 +			TEST(res==KErrNone);
   1.472 +			}
   1.473 +		TBool cancel=EFalse;
   1.474 +		session.CancelAllUpdateNotifications();
   1.475 +		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests; submissionNumber++)
   1.476 +			{
   1.477 +			User::WaitForRequest(status[submissionNumber]);
   1.478 +			TEST((status[submissionNumber] == KErrCancel) || (status[submissionNumber] == KErrNone) );
   1.479 +			if(status[submissionNumber] == KErrCancel)
   1.480 +				{
   1.481 +				cancel = ETrue;
   1.482 +				}
   1.483 +			
   1.484 +			if((status[submissionNumber] == KErrNone) && ((submissionNumber - 1) % 3) == 0)
   1.485 +				{
   1.486 +				TInt index22 = submissionNumber / 3;
   1.487 +				timestampAfter[index22] = User::FastCounter();	
   1.488 +		
   1.489 +				if(timestampAfter[index22] < timestampBefore[index22])
   1.490 +					{
   1.491 +					timestampAfter[index22] += UINT_MAX;
   1.492 +					}
   1.493 +				timestampComposition[index22] = timeStamp[index22]();
   1.494 +				if(timestampComposition[index22] < timestampBefore[index22])
   1.495 +					{
   1.496 +					timestampComposition[index22] += UINT_MAX;
   1.497 +					}
   1.498 +
   1.499 +				TEST(timestampComposition[index22] != 0);
   1.500 +				TEST(timestampAfter[index22] >= timestampComposition[index22]);
   1.501 +				TEST(timestampBefore[index22] <= timestampComposition[index22]);
   1.502 +				}
   1.503 +			}
   1.504 +		TEST(cancel);		
   1.505 +		}
   1.506 +		session.Close();
   1.507 +	}
   1.508 +
   1.509 +/**
   1.510 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0005
   1.511 +
   1.512 +  @SYMPREQ 1007
   1.513 +  
   1.514 +  @SYMREQ 8223
   1.515 +
   1.516 +  @SYMTestCaseDesc Submission from multiple sessions. 
   1.517 +
   1.518 +  @SYMTestPriority High
   1.519 +
   1.520 +  @SYMTestStatus Implemented
   1.521 +
   1.522 +  @SYMTestActions Create a few connections to the server. For each connection: 
   1.523 +  		1. Subscribe for different notifications (consumed, displayed, 
   1.524 +  		displayedXTimes). 
   1.525 +  		2. Submit update command. Wait for notifications to arrive.
   1.526 +
   1.527 +  @SYMTestExpectedResults Errors, which will be conveyed in 
   1.528 +  TRequestStatus must be equal to KErrNone. Timestamps must be consistent 
   1.529 +  with time before and after submissions.
   1.530 +*/
   1.531 +void CTSurfaceUpdate::TestCase5L()
   1.532 +	{
   1.533 +	INFO_PRINTF1(_L("Submission a few update requests in  a row from different sessions, then waiting for notifications to arrive"));
   1.534 +	
   1.535 +	const TInt KNumberAsynchronousRequests = 9;
   1.536 +	const TInt KNumberSessions = 5;
   1.537 +	TInt res = KErrNone;	
   1.538 +	
   1.539 +	RSurfaceUpdateSession sessions[KNumberSessions];
   1.540 +	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests per each session as: %d"), KNumberAsynchronousRequests);	
   1.541 +	INFO_PRINTF2(_L("Set number of sessions: %d"), KNumberSessions);	
   1.542 +	
   1.543 +	TInt screen = 0;
   1.544 +	TInt screen1 = 1;
   1.545 +	TInt buffer = 2;
   1.546 +	TSurfaceId surface = 
   1.547 +		{
   1.548 +		1,2,3,4
   1.549 +		};
   1.550 +	TRect rc[] =
   1.551 +			{
   1.552 +			TRect(1,2, 3, 4),
   1.553 +			TRect(5,6, 7, 8),
   1.554 +			TRect(9, 10, 11, 12),
   1.555 +			TRect(13, 14, 15, 16),
   1.556 +			};
   1.557 +	RRegion region(4, rc);
   1.558 +
   1.559 +	TRequestStatus status[KNumberAsynchronousRequests * KNumberSessions];
   1.560 +	
   1.561 +	for(TInt index2 = 0; index2 < KNumberSessions; index2++)
   1.562 +		{
   1.563 +		res = sessions[index2].Connect(KNumberAsynchronousRequests);
   1.564 +		User::LeaveIfError(res);
   1.565 +		}
   1.566 +	
   1.567 +	for(TInt index1 = 0; index1 < 3; index1++)
   1.568 +		{
   1.569 +		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   1.570 +
   1.571 +		for(TInt index2 = 0; index2 < KNumberSessions; index2++)
   1.572 +			{
   1.573 +			TTimeStamp timeStamp;
   1.574 +			INFO_PRINTF2(_L("Session number %d"), index2 + 1);	
   1.575 +		 
   1.576 +			for(TInt index3 = index2 * KNumberAsynchronousRequests; 
   1.577 +					index3 < (index2 + 1) * KNumberAsynchronousRequests; index3 += 3)
   1.578 +				{
   1.579 +				INFO_PRINTF2(_L("Submission number %d"), index3 / 3 + 1);	
   1.580 +				status[index3]=KRequestPending;
   1.581 +				sessions[index2].NotifyWhenAvailable(status[index3]);	
   1.582 +				status[index3 + 1]=KRequestPending;
   1.583 +				sessions[index2].NotifyWhenDisplayed(status[index3 + 1], timeStamp);	
   1.584 +				status[index3 + 2]=KRequestPending;
   1.585 +				sessions[index2].NotifyWhenDisplayedXTimes(10, status[index3 + 2]);	
   1.586 +				res = sessions[index2].SubmitUpdate((index3 % 2) ? screen : screen1, surface, buffer, &region);
   1.587 +				if(res != KErrNone)
   1.588 +				    {
   1.589 +	                ERR_PRINTF2(_L("Returned SubmitUpdate code %d"), res);
   1.590 +	                TEST(EFail);
   1.591 +				    }
   1.592 +				}
   1.593 +			}
   1.594 +
   1.595 +		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests * KNumberSessions; submissionNumber++)
   1.596 +			{
   1.597 +			User::WaitForRequest(status[submissionNumber]);
   1.598 +			if(status[submissionNumber] != KErrNone)
   1.599 +			    {
   1.600 +			    ERR_PRINTF2(_L("Returned request status %d"), status[submissionNumber].Int());
   1.601 +			    TEST(EFail);
   1.602 +			    }
   1.603 +			}
   1.604 +		}
   1.605 +		
   1.606 +	for(TInt index5 = 0; index5 < KNumberSessions; index5++)
   1.607 +		{
   1.608 +		sessions[index5].Close();
   1.609 +		}
   1.610 +	}
   1.611 +
   1.612 +/**
   1.613 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0023
   1.614 +
   1.615 +
   1.616 +  @SYMPREQ 1007/11596
   1.617 +
   1.618 +  @SYMREQ 8223
   1.619 +
   1.620 +  @SYMTestCaseDesc SubmitUpdate() to cope with Global Updates 
   1.621 +
   1.622 +  @SYMTestPriority High
   1.623 +
   1.624 +  @SYMTestStatus Implemented
   1.625 +
   1.626 +  @SYMTestActions 
   1.627 +  		1.	Submit for a global update before subscribing for any notifications.
   1.628 +		From this point onwards, all further cases assume that we’ve subscribed 
   1.629 +		for different notifications (available, displayed, displayedXTimes) 
   1.630 +		before submitting a global update:
   1.631 +		2.	Submit a global update for a surface that is not visible on any screen.
   1.632 +		3.	Submit a global update for a surface that is only visible on one screen.
   1.633 +		4.	Submit a global update for a surface that is visible on different screens.
   1.634 +
   1.635 +  @SYMTestExpectedResults 
   1.636 +  	1.	Submitting for an update before any notifications causes no problems.
   1.637 +	2.	SubmitUpdate() signals KErrNotVisible
   1.638 +	3.	TRequestStatus signals KErrNone in all cases. Timestamps must be valid.
   1.639 +	4.	TRequestStatus signals KErrNone in all cases. Timestamps must be valid.
   1.640 +*/
   1.641 +void CTSurfaceUpdate::TestCase15()
   1.642 +	{
   1.643 +	INFO_PRINTF1(_L("SubmitUpdate() to cope with Global Updates"));
   1.644 +
   1.645 +	RSurfaceUpdateSession session;
   1.646 +	TInt res = session.Connect();
   1.647 +	TEST(res == KErrNone);
   1.648 +	
   1.649 +	TInt buffer = 2;
   1.650 +	TSurfaceId surface = 
   1.651 +		{
   1.652 +		1,2,3,4
   1.653 +		};
   1.654 +
   1.655 +	// Test that submitting for an update before any noitfications causes no problems
   1.656 +	TInt numReceivers = iReceivers.Count();
   1.657 +
   1.658 +	//make all screens invisible
   1.659 +	INFO_PRINTF1(_L("make all screens invisible"));	
   1.660 +	for(TInt index = 0; index < numReceivers; index++)
   1.661 +		{
   1.662 +		CTContentUpdateReceiver* receiver = iReceivers[index];
   1.663 +		receiver->SetVisible(EFalse);
   1.664 +		}
   1.665 +	
   1.666 +	for(TInt submissionNumber = 0; submissionNumber < 5; submissionNumber++)
   1.667 +		{
   1.668 +		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   1.669 +
   1.670 +		TRequestStatus status = KRequestPending;
   1.671 +		TRequestStatus status1 = KRequestPending;
   1.672 +		TRequestStatus status2 = KRequestPending;
   1.673 +		TTimeStamp timeStamp; 
   1.674 +	
   1.675 +		session.NotifyWhenAvailable(status);	
   1.676 +		session.NotifyWhenDisplayed(status1, timeStamp);	
   1.677 +		session.NotifyWhenDisplayedXTimes(10, status2);
   1.678 +		
   1.679 +		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   1.680 +		TEST(res==KErrNone);
   1.681 +		
   1.682 +		User::WaitForRequest(status);
   1.683 +		User::WaitForRequest(status1);
   1.684 +		User::WaitForRequest(status2);
   1.685 +
   1.686 +		TEST(status == KErrNotVisible);
   1.687 +		TEST(status1 == KErrNotVisible);
   1.688 +		TEST(status2 == KErrNotVisible);
   1.689 +		}
   1.690 +	
   1.691 +	//make only one screen visible
   1.692 +	CTContentUpdateReceiver* receiver = iReceivers[0];
   1.693 +	receiver->SetVisible(ETrue);
   1.694 +	INFO_PRINTF1(_L("Make visible one screen"));	
   1.695 +
   1.696 +	
   1.697 +	for(TInt submissionNumber = 0; submissionNumber < 5; submissionNumber++)
   1.698 +		{
   1.699 +		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   1.700 +
   1.701 +		TRequestStatus status = KRequestPending;
   1.702 +		TRequestStatus status1 = KRequestPending;
   1.703 +		TRequestStatus status2 = KRequestPending;
   1.704 +		TUint64 timestampComposition = 0;
   1.705 +		TTimeStamp timeStamp; 
   1.706 +	
   1.707 +		TUint64 timestampBefore = User::FastCounter();
   1.708 +
   1.709 +		session.NotifyWhenAvailable(status);	
   1.710 +		session.NotifyWhenDisplayed(status1, timeStamp);	
   1.711 +		session.NotifyWhenDisplayedXTimes(10, status2);
   1.712 +		
   1.713 +		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   1.714 +		TEST(res==KErrNone);
   1.715 +		
   1.716 +		User::WaitForRequest(status);
   1.717 +		User::WaitForRequest(status1);
   1.718 +		User::WaitForRequest(status2);
   1.719 +
   1.720 +		TUint64 timestampAfter = User::FastCounter();
   1.721 +		if(timestampAfter < timestampBefore)
   1.722 +			{
   1.723 +			timestampAfter += UINT_MAX;
   1.724 +			}
   1.725 +		timestampComposition = timeStamp();
   1.726 +		if(timestampComposition < timestampBefore)
   1.727 +			{
   1.728 +			timestampComposition += UINT_MAX;
   1.729 +			}
   1.730 +	
   1.731 +		TEST(status == KErrNone);
   1.732 +		TEST(status1 == KErrNone);
   1.733 +		TEST(status2 == KErrNone);
   1.734 +		
   1.735 +		TEST(timestampComposition != 0);
   1.736 +		TEST(timestampAfter >= timestampComposition);
   1.737 +		TEST(timestampBefore <= timestampComposition);
   1.738 +		
   1.739 +		INFO_PRINTF2(_L("Time before composition: %lu"), timestampBefore);	
   1.740 +		INFO_PRINTF2(_L("Time at composition: %lu"), timestampComposition);	
   1.741 +		INFO_PRINTF2(_L("Time after composition: %lu"), timestampAfter);
   1.742 +		}
   1.743 +	
   1.744 +	//make another screen visible
   1.745 +	INFO_PRINTF1(_L("make another screen visible"));	
   1.746 +	receiver->SetVisible(EFalse);
   1.747 +	receiver = iReceivers[1];
   1.748 +	receiver->SetVisible(ETrue);
   1.749 +	
   1.750 +	for(TInt submissionNumber = 0; submissionNumber < 5; submissionNumber++)
   1.751 +		{
   1.752 +		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   1.753 +
   1.754 +		TRequestStatus status = KRequestPending;
   1.755 +		TRequestStatus status1 = KRequestPending;
   1.756 +		TRequestStatus status2 = KRequestPending;
   1.757 +		TUint64 timestampComposition = 0;
   1.758 +		TTimeStamp timeStamp; 
   1.759 +	
   1.760 +		TUint64 timestampBefore = User::FastCounter();
   1.761 +
   1.762 +		session.NotifyWhenAvailable(status);	
   1.763 +		session.NotifyWhenDisplayed(status1, timeStamp);	
   1.764 +		session.NotifyWhenDisplayedXTimes(10, status2);
   1.765 +		
   1.766 +		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   1.767 +		TEST(res==KErrNone);
   1.768 +		
   1.769 +		User::WaitForRequest(status);
   1.770 +		User::WaitForRequest(status1);
   1.771 +		User::WaitForRequest(status2);
   1.772 +
   1.773 +		TUint64 timestampAfter = User::FastCounter();
   1.774 +		if(timestampAfter < timestampBefore)
   1.775 +			{
   1.776 +			timestampAfter += UINT_MAX;
   1.777 +			}
   1.778 +		timestampComposition = timeStamp();
   1.779 +		if(timestampComposition < timestampBefore)
   1.780 +			{
   1.781 +			timestampComposition += UINT_MAX;
   1.782 +			}
   1.783 +	
   1.784 +		TEST(status == KErrNone);
   1.785 +		TEST(status1 == KErrNone);
   1.786 +		TEST(status2 == KErrNone);
   1.787 +		
   1.788 +		TEST(timestampComposition != 0);
   1.789 +		TEST(timestampAfter >= timestampComposition);
   1.790 +		TEST(timestampBefore <= timestampComposition);
   1.791 +		
   1.792 +		INFO_PRINTF2(_L("Time before composition: %lu"), timestampBefore);	
   1.793 +		INFO_PRINTF2(_L("Time at composition: %lu"), timestampComposition);	
   1.794 +		INFO_PRINTF2(_L("Time after composition: %lu"), timestampAfter);
   1.795 +		}
   1.796 +	
   1.797 +	//make all screens visible
   1.798 +	for(TInt index = 0; index < numReceivers; index++)
   1.799 +		{
   1.800 +		CTContentUpdateReceiver* receiver = iReceivers[index];
   1.801 +		receiver->SetVisible(ETrue);
   1.802 +		}
   1.803 +
   1.804 +	session.Close();
   1.805 +	}
   1.806 +
   1.807 +
   1.808 +/**
   1.809 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0024
   1.810 +
   1.811 +  @SYMPREQ 1007/11596
   1.812 +
   1.813 +  @SYMREQ 8223
   1.814 +
   1.815 +  @SYMTestCaseDesc CancelAllUpdateNotifications() to deal with global updates 
   1.816 +  correctly. 
   1.817 +
   1.818 +  @SYMTestPriority High
   1.819 +
   1.820 +  @SYMTestStatus Implemented
   1.821 +
   1.822 +  @SYMTestActions 
   1.823 +  		The test consists of a single surface, visible on screens A (master), B & C. 
   1.824 +		The test will submit for different notifications (available, displayed, 
   1.825 +		displayedXTimes) and then submit a global update. 
   1.826 +		These actions will be repeated a number of times.
   1.827 +		Finally, the test will cancel all outstanding notifications via 
   1.828 +		CancelAllUpdateNotifications() and wait for the cancelled notifications to arrive.
   1.829 +  		
   1.830 +  @SYMTestExpectedResults 
   1.831 +  	Notifications to arrive straight away with KErrCancel, otherwise with 
   1.832 +  	KErrNone if the events have already occurred.
   1.833 +*/
   1.834 +void CTSurfaceUpdate::TestCase16L()
   1.835 +	{
   1.836 +	INFO_PRINTF1(_L("CancelAllUpdateNotifications() to deal with global updates correctly"));
   1.837 +	RSurfaceUpdateSession session;
   1.838 +	
   1.839 +	const TInt KNumberAsynchronousRequests = 33; //should be divisible by 3!
   1.840 +	TInt res = session.Connect(KNumberAsynchronousRequests);
   1.841 +	INFO_PRINTF1(_L("Test CancelAllUpdateNotifications without SubmitUpdate"));
   1.842 +	// Test CancelAllUpdateNotifications without SubmitUpdate
   1.843 +	TRequestStatus status1, status2, status3;
   1.844 +	TTimeStamp ts;
   1.845 +	
   1.846 +	INFO_PRINTF2(_L("Set number of outstanding asynchronous requests as: %d"), KNumberAsynchronousRequests);	
   1.847 +	User::LeaveIfError(res);
   1.848 +	
   1.849 +	TInt buffer = 2;
   1.850 +	TSurfaceId surface = 
   1.851 +		{
   1.852 +		1,2,3,4
   1.853 +		};
   1.854 +	
   1.855 +	for(TInt index1 = 0; index1 < 2; index1++)
   1.856 +		{
   1.857 +		INFO_PRINTF2(_L("Attempt number %d"), index1+1);	
   1.858 +
   1.859 +		TRequestStatus status[KNumberAsynchronousRequests];
   1.860 +		
   1.861 +		TTimeStamp timeStamp[KNumberAsynchronousRequests];
   1.862 +		TUint64 timestampComposition[KNumberAsynchronousRequests];
   1.863 +		TUint64 timestampBefore[KNumberAsynchronousRequests];
   1.864 +		TUint64 timestampAfter[KNumberAsynchronousRequests];
   1.865 +		for(TInt index2 = 0; index2 < KNumberAsynchronousRequests; index2 += 3)
   1.866 +			{
   1.867 +			INFO_PRINTF2(_L("Submission number %d"), index2 / 3 + 1);	
   1.868 +			status[index2]=KRequestPending;
   1.869 +			session.NotifyWhenAvailable(status[index2]);	
   1.870 +			status[index2 + 1]=KRequestPending;
   1.871 +			session.NotifyWhenDisplayed(status[index2 + 1], timeStamp[index2 / 3]);	
   1.872 +			status[index2 + 2]=KRequestPending;
   1.873 +			session.NotifyWhenDisplayedXTimes(10, status[index2 + 2]);	
   1.874 +			
   1.875 +			timestampBefore[index2 / 3] = User::FastCounter();	
   1.876 +			res = session.SubmitUpdate(KAllScreens, surface, buffer);
   1.877 +			TEST(res==KErrNone);
   1.878 +			}
   1.879 +		TBool cancel=EFalse;
   1.880 +		session.CancelAllUpdateNotifications();
   1.881 +		for(TInt submissionNumber = 0; submissionNumber < KNumberAsynchronousRequests; submissionNumber++)
   1.882 +			{
   1.883 +			User::WaitForRequest(status[submissionNumber]);
   1.884 +			TEST((status[submissionNumber] == KErrCancel) || (status[submissionNumber] == KErrNone) );
   1.885 +			if(status[submissionNumber] == KErrCancel)
   1.886 +				{
   1.887 +				cancel = ETrue;
   1.888 +				}
   1.889 +			
   1.890 +			if((status[submissionNumber] == KErrNone) && ((submissionNumber - 1) % 3) == 0)
   1.891 +				{
   1.892 +				TInt index22 = submissionNumber / 3;
   1.893 +				timestampAfter[index22] = User::FastCounter();	
   1.894 +		
   1.895 +				if(timestampAfter[index22] < timestampBefore[index22])
   1.896 +					{
   1.897 +					timestampAfter[index22] += UINT_MAX;
   1.898 +					}
   1.899 +				timestampComposition[index22] = timeStamp[index22]();
   1.900 +				if(timestampComposition[index22] < timestampBefore[index22])
   1.901 +					{
   1.902 +					timestampComposition[index22] += UINT_MAX;
   1.903 +					}
   1.904 +
   1.905 +				TEST(timestampComposition[index22] != 0);
   1.906 +				TEST(timestampAfter[index22] >= timestampComposition[index22]);
   1.907 +				TEST(timestampBefore[index22] <= timestampComposition[index22]);
   1.908 +				}
   1.909 +			}
   1.910 +		TEST(cancel);		
   1.911 +		}
   1.912 +		session.Close();
   1.913 +	}
   1.914 +
   1.915 +/**
   1.916 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0027
   1.917 +
   1.918 +  @SYMPREQ 1007/11598
   1.919 +
   1.920 +  @SYMREQ 8223
   1.921 +
   1.922 +  @SYMTestCaseDesc NotifyWhenAvailable() to deal with global updates and be signalled correctly
   1.923 +  @SYMTestPriority High
   1.924 +
   1.925 +  @SYMTestStatus Implemented
   1.926 +
   1.927 +  @SYMTestActions 
   1.928 +	The test consists of a single surface, visible on screens B (master) and C, 
   1.929 +	but not visible on A. 
   1.930 +	1. Screens are ordered in the following priority : A > B > C
   1.931 +	2. Set priority of the receiver threads as follows A < B < C.
   1.932 +	3. Set receiver A invisible.
   1.933 +	4. Make global submit update with notify when displayed and notify 
   1.934 +	when displayed X times.
   1.935 +	5. Repeat step 4 a few times.
   1.936 +  		
   1.937 +  @SYMTestExpectedResults 
   1.938 +  	Notification to arrive with error code KErrNone initiated by the 
   1.939 +  	master display.
   1.940 +*/
   1.941 +void CTSurfaceUpdate::TestCaseNotifyWhenAvailableGlobal()
   1.942 +	{
   1.943 +	INFO_PRINTF1(_L("NotifyWhenAvailable() to deal with global updates and be signalled correctly"));
   1.944 +
   1.945 +	RSurfaceUpdateSession session;
   1.946 +	TInt res = session.Connect();
   1.947 +	TEST(res == KErrNone);
   1.948 +	
   1.949 +	TInt buffer = 2;
   1.950 +	TSurfaceId surface = 
   1.951 +		{
   1.952 +		1,2,3,4
   1.953 +		};
   1.954 +
   1.955 +	TEST(iReceivers[2]->OutstandingRequest()==EFalse);
   1.956 +	TEST(iReceivers[1]->OutstandingRequest()==EFalse);
   1.957 +	TEST(iReceivers[0]->OutstandingRequest()==EFalse);
   1.958 +	
   1.959 +	//change the order.
   1.960 +	//higher screen number means that the screen is higher priority. 
   1.961 +	//So Receiver0 is lowest screen priority
   1.962 +	res = iReceivers[2]->SetInternalPriority(EPriorityLess);
   1.963 +	TEST(res == KErrNone);
   1.964 +	res = iReceivers[1]->SetInternalPriority(EPriorityNormal);
   1.965 +	TEST(res == KErrNone);
   1.966 +	res = iReceivers[0]->SetInternalPriority(EPriorityAbsoluteHighNormal);
   1.967 +	TEST(res == KErrNone);
   1.968 +	iReceivers[2]->SetVisible(EFalse);
   1.969 +	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
   1.970 +	
   1.971 +	for(TInt submissionNumber = 0; submissionNumber < 20; submissionNumber++)
   1.972 +		{
   1.973 +		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
   1.974 +
   1.975 +		TRequestStatus status = KRequestPending;
   1.976 +	
   1.977 +		session.NotifyWhenAvailable(status);	
   1.978 +		
   1.979 +		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
   1.980 +		TEST(res==KErrNone);
   1.981 +		
   1.982 +		User::WaitForRequest(status);
   1.983 +
   1.984 +		TEST(status == KErrNone);
   1.985 +		TEST(iReceivers[2]->OutstandingRequest()==EFalse);
   1.986 +		TEST(iReceivers[1]->OutstandingRequest()==EFalse);
   1.987 +		TEST(iReceivers[0]->OutstandingRequest()==EFalse);
   1.988 +		}
   1.989 +
   1.990 +	//restore envorienment
   1.991 +	iReceivers[0]->SetInternalPriority(EPriorityNormal);
   1.992 +	iReceivers[1]->SetInternalPriority(EPriorityNormal);
   1.993 +	iReceivers[2]->SetInternalPriority(EPriorityNormal);
   1.994 +	iReceivers[2]->SetVisible(ETrue);
   1.995 +	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
   1.996 +	WaitUntilAllNotificationsProcessed();
   1.997 +	session.Close();
   1.998 +	}
   1.999 +
  1.1000 +/**
  1.1001 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0028
  1.1002 +
  1.1003 +  @SYMPREQ 1007/11599, 1007/11600, 1007/11601
  1.1004 +
  1.1005 +  @SYMREQ 8223
  1.1006 +
  1.1007 +  @SYMTestCaseDesc NotifyWhenDisplayed() & NotifyWhenDisplayedXTimes() to deal with global updates and be signalled correctly
  1.1008 +  @SYMTestPriority High
  1.1009 +
  1.1010 +  @SYMTestStatus Implemented
  1.1011 +
  1.1012 +  @SYMTestActions 
  1.1013 +	The test consists of a single surface, visible on screens B (master) and C, but not visible on A. 
  1.1014 +	1. Screens are ordered in the following priority : A > B > C.
  1.1015 +	2. Set priority of the receiver threads as follows A < B < C.
  1.1016 +	3. Set receiver A invisible.
  1.1017 +	4. Make global submit update with notify when displayed and notify when displayed X times.
  1.1018 +	Repeat step 4 a few times.
  1.1019 +
  1.1020 +	5. Screens are ordered in the following priority : A > B > C.
  1.1021 +	6. Set priority of the receiver threads as follows A > B > C.
  1.1022 +	7. Set receiver A invisible.
  1.1023 +	8. Make global submit update with notify when displayed and notify when displayed X times.
  1.1024 +	Repeat step 4 a few times.
  1.1025 +
  1.1026 +  		
  1.1027 +  @SYMTestExpectedResults 
  1.1028 +  	Notification to arrive with error code KErrNone initiated by the master display.
  1.1029 +  	There is no outstanding request for receiver A & B after steps 4 and 8.
  1.1030 +*/
  1.1031 +void CTSurfaceUpdate::TestCase17()
  1.1032 +	{
  1.1033 +	INFO_PRINTF1(_L("NotifyWhenDisplayed() && NotifyWhenDisplayedXTimes() to deal with global updates and be signalled correctly"));
  1.1034 +
  1.1035 +	RSurfaceUpdateSession session;
  1.1036 +	TInt res = session.Connect();
  1.1037 +	TEST(res == KErrNone);
  1.1038 +	
  1.1039 +	TInt buffer = 2;
  1.1040 +	TSurfaceId surface = 
  1.1041 +		{
  1.1042 +		1,2,3,4
  1.1043 +		};
  1.1044 +	
  1.1045 +//change the order, receiver with highest priority has a lowest internal priority 
  1.1046 +	res = iReceivers[2]->SetInternalPriority(EPriorityLess);
  1.1047 +	TEST(res == KErrNone);
  1.1048 +	res = iReceivers[1]->SetInternalPriority(EPriorityNormal);
  1.1049 +	TEST(res == KErrNone);
  1.1050 +	res = iReceivers[0]->SetInternalPriority(EPriorityAbsoluteHighNormal);
  1.1051 +	TEST(res == KErrNone);
  1.1052 +	iReceivers[2]->SetVisible(EFalse);
  1.1053 +	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority setting takes place
  1.1054 +	
  1.1055 +	for(TInt submissionNumber = 0; submissionNumber < 10; submissionNumber++)
  1.1056 +		{
  1.1057 +		INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
  1.1058 +
  1.1059 +		TRequestStatus status = KRequestPending;
  1.1060 +		TRequestStatus status1 = KRequestPending;
  1.1061 +		TTimeStamp timeStamp; 
  1.1062 +	
  1.1063 +		session.NotifyWhenDisplayed(status, timeStamp);	
  1.1064 +		session.NotifyWhenDisplayedXTimes(10, status1);
  1.1065 +		
  1.1066 +		res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  1.1067 +		TEST(res==KErrNone);
  1.1068 +		
  1.1069 +		User::WaitForRequest(status);
  1.1070 +		User::WaitForRequest(status1);
  1.1071 +
  1.1072 +		TEST(status == KErrNone);
  1.1073 +		TEST(status1 == KErrNone);
  1.1074 +		TEST(iReceivers[0]->OutstandingRequest() == EFalse);
  1.1075 +		TEST(iReceivers[1]->OutstandingRequest() == EFalse);
  1.1076 +		TEST(iReceivers[2]->OutstandingRequest() == EFalse);
  1.1077 +		}
  1.1078 +
  1.1079 +	//change the order, receiver with highest priority has a highest internal priority 
  1.1080 +		res = iReceivers[0]->SetInternalPriority(EPriorityLess);
  1.1081 +		TEST(res == KErrNone);
  1.1082 +		res = iReceivers[1]->SetInternalPriority(EPriorityNormal);
  1.1083 +		TEST(res == KErrNone);
  1.1084 +		res = iReceivers[2]->SetInternalPriority(EPriorityAbsoluteHighNormal);
  1.1085 +		TEST(res == KErrNone);
  1.1086 +		iReceivers[2]->SetVisible(EFalse);
  1.1087 +		User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
  1.1088 +		
  1.1089 +		TInt numUnprocessedSignals = 0;
  1.1090 +		for(TInt submissionNumber = 0; submissionNumber < 10; submissionNumber++)
  1.1091 +			{
  1.1092 +			INFO_PRINTF2(_L("Submission number %d"), submissionNumber+1);	
  1.1093 +
  1.1094 +			TRequestStatus status = KRequestPending;
  1.1095 +			TRequestStatus status1 = KRequestPending;
  1.1096 +			TTimeStamp timeStamp; 
  1.1097 +		
  1.1098 +			session.NotifyWhenDisplayed(status, timeStamp);	
  1.1099 +			session.NotifyWhenDisplayedXTimes(10, status1);
  1.1100 +			
  1.1101 +			res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  1.1102 +			TEST(res==KErrNone);
  1.1103 +			
  1.1104 +			User::WaitForRequest(status);
  1.1105 +			User::WaitForRequest(status1);
  1.1106 +
  1.1107 +			TEST(status == KErrNone);
  1.1108 +			TEST(status1 == KErrNone);
  1.1109 +			if(iReceivers[0]->OutstandingRequest())
  1.1110 +				{		
  1.1111 +				numUnprocessedSignals++;
  1.1112 +				INFO_PRINTF1(_L("Unprocessed signals"));	
  1.1113 +
  1.1114 +				}
  1.1115 +			TEST(iReceivers[1]->OutstandingRequest() == EFalse);
  1.1116 +			TEST(iReceivers[2]->OutstandingRequest() == EFalse);
  1.1117 +			TEST(iReceivers[0]->OutstandingRequest()); //receiver is signalled last, in since its priority is lowest, 
  1.1118 +														//SUS shouldn’t wait for it before the signal goes back to client  
  1.1119 +			}
  1.1120 +
  1.1121 +	INFO_PRINTF2(_L("Number unprocessed signals %d"), numUnprocessedSignals);	
  1.1122 +	TEST(numUnprocessedSignals > 0);
  1.1123 +		
  1.1124 +	//restore envorienment
  1.1125 +	iReceivers[0]->SetInternalPriority(EPriorityNormal);
  1.1126 +	iReceivers[1]->SetInternalPriority(EPriorityNormal);
  1.1127 +	iReceivers[2]->SetInternalPriority(EPriorityNormal);
  1.1128 +	iReceivers[2]->SetVisible(ETrue);
  1.1129 +	User::After(TTimeIntervalMicroSeconds32(100000)); //make sure that priority takes place
  1.1130 +	WaitUntilAllNotificationsProcessed();
  1.1131 +	
  1.1132 +	session.Close();
  1.1133 +	}
  1.1134 +
  1.1135 +/**
  1.1136 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0029
  1.1137 +
  1.1138 +
  1.1139 +  @SYMPREQ 1007/11596
  1.1140 +
  1.1141 +  @SYMREQ 8223
  1.1142 +
  1.1143 +  @SYMTestCaseDesc Register with identical priorities. 
  1.1144 +
  1.1145 +  @SYMTestPriority High
  1.1146 +
  1.1147 +  @SYMTestStatus Implemented
  1.1148 +
  1.1149 +  @SYMTestActions 
  1.1150 +		1.	Start the server.
  1.1151 +		2.	Create two content update receivers
  1.1152 +		3.	Register receiverA using Register() with a priority
  1.1153 +		4.	Register receiverB using Register() with the same priority
  1.1154 +		5.	Unregister receiverA
  1.1155 +		6.	Register receiverB using Register() with the same priority as before
  1.1156 +
  1.1157 +  @SYMTestExpectedResults 
  1.1158 +		Step 4 should fail, returning KErrAlreadyExists.
  1.1159 +		Step 6 should succeed.
  1.1160 +*/
  1.1161 +void CTSurfaceUpdate::TestCaseRegisterIdenticalPrioritiesL()
  1.1162 +	{
  1.1163 +	INFO_PRINTF1(_L("Register with identical priorities test"));
  1.1164 +	const TInt KIdenticalPriority = 100;
  1.1165 +	
  1.1166 +	// Start two content update receivers for register test
  1.1167 +	CTContentUpdateReceiver* receiverA;
  1.1168 +	CTContentUpdateReceiver* receiverB;
  1.1169 +	User::LeaveIfError(StartTestUpdateReceiver(receiverA, 8));
  1.1170 +	iReceivers.AppendL(receiverA);
  1.1171 +	User::LeaveIfError(StartTestUpdateReceiver(receiverB, 9));
  1.1172 +	iReceivers.AppendL(receiverB);
  1.1173 +		
  1.1174 +	INFO_PRINTF2(_L("Registering receiver A with priority %i"), KIdenticalPriority);	
  1.1175 +	User::LeaveIfError(Provider()->Register(receiverA->Screen(), receiverA, KIdenticalPriority));
  1.1176 +
  1.1177 +	INFO_PRINTF2(_L("Registering receiver B with the same priority (%i), which should return KErrAlreadyExists"), KIdenticalPriority);	
  1.1178 +	TInt ret = Provider()->Register(receiverB->Screen(), receiverB, KIdenticalPriority);
  1.1179 +	if(KErrAlreadyExists == ret)
  1.1180 +		{
  1.1181 +		INFO_PRINTF1(_L("KErrAlreadyExists returned as expected"));
  1.1182 +		}
  1.1183 +	else
  1.1184 +		{
  1.1185 +		ERR_PRINTF3(_L("Test failed - expected Register() to return KErrAlreadyExists(%i) but instead returned %i"), KErrAlreadyExists, ret);
  1.1186 +		User::Leave(ret);
  1.1187 +		}
  1.1188 +
  1.1189 +	INFO_PRINTF1(_L("Unregistering receiver A"));
  1.1190 +	User::LeaveIfError(Provider()->Register(receiverA->Screen(), NULL, KIdenticalPriority));
  1.1191 +
  1.1192 +	INFO_PRINTF2(_L("Registering receiver B with the same priority (%i), which should succeed"), KIdenticalPriority);
  1.1193 +	User::LeaveIfError(Provider()->Register(receiverB->Screen(), receiverB, KIdenticalPriority));
  1.1194 +	}
  1.1195 +
  1.1196 +/**
  1.1197 +negative testing
  1.1198 +*/
  1.1199 +
  1.1200 +
  1.1201 +/**
  1.1202 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0006
  1.1203 +
  1.1204 +  @SYMPREQ 1007
  1.1205 +  
  1.1206 +  @SYMREQ 8223
  1.1207 +
  1.1208 +  @SYMTestCaseDesc Negative testing - various cases
  1.1209 +
  1.1210 +  @SYMTestPriority High
  1.1211 +
  1.1212 +  @SYMTestStatus Implemented
  1.1213 +
  1.1214 +  @SYMTestActions 6. The client mustn't try to send any command to the server before 
  1.1215 +     establishing a connection.
  1.1216 +     7. Attempt to connect twice
  1.1217 +     8. Attempt notify then submit with invalid parameters
  1.1218 +     9. Submission with screen which doesn't exist in the system
  1.1219 +     10. Submission with invalid number of counts in NotifyWhenDisplayedXTimes()
  1.1220 +     11. Number of outstanding requests exceeds pre-defined value
  1.1221 +     12. Submission of region with empty rectangle list
  1.1222 +     13. Assigning receiver to the screen with negative number
  1.1223 +
  1.1224 +  @SYMTestExpectedResults 6. Shouldn't panic and subsequent session connect should succeed.
  1.1225 +     7. Second attempt to connect should return KErrAlreadyExists
  1.1226 +     8. With invalid parameters we get KErrArgument; with a screen that doesn't exist we
  1.1227 +        get KErrUpdateReceiverNotAvailable
  1.1228 +     9. Too big a screen number results in KErrUpdateReceiverNotAvailable; -ve buffer results in KErrArgument.
  1.1229 +     10. With a negative diplayedXtimes number, we expect KErrArgument
  1.1230 +     11. When we exceed the number of allowed outstanding requests, we get KErrBusy
  1.1231 +     12. With empty region, all return codes are KErrNone.
  1.1232 +     13. Registering with negative screen gives KErrArgument
  1.1233 +*/
  1.1234 +void CTSurfaceUpdate::TestCase6L()
  1.1235 +	{
  1.1236 +	INFO_PRINTF1(_L("negative testing"));
  1.1237 +	RSurfaceUpdateSession session;
  1.1238 +	TRequestStatus status;
  1.1239 +	TRequestStatus status1;
  1.1240 +	TRequestStatus status2;
  1.1241 +	TRequestStatus status3;
  1.1242 +	TRequestStatus status4;
  1.1243 +	TRequestStatus status5;
  1.1244 +	TInt res;
  1.1245 +	TTimeStamp timeStamp; 
  1.1246 +	
  1.1247 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0006 apply operation on disconnected session
  1.1248 +	TInt screen = 0;
  1.1249 +	TInt buffer = 2;
  1.1250 +	TSurfaceId surface = 
  1.1251 +		{
  1.1252 +		1,2,3,4
  1.1253 +		};
  1.1254 +	TRect rc[2] =
  1.1255 +			{
  1.1256 +			TRect(1,2, 10, 20),
  1.1257 +		
  1.1258 +			TRect(5,6, 30, 30)
  1.1259 +			};
  1.1260 +		
  1.1261 +	RRegion region(2, rc);
  1.1262 +
  1.1263 +	//next command will be ignored, but shouldn't cause a panic
  1.1264 +	INFO_PRINTF1(_L("close disconnected session"));
  1.1265 +	session.Close();
  1.1266 +	
  1.1267 +	User::LeaveIfError(session.Connect());
  1.1268 +	
  1.1269 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0007 Attempt to connect twice
  1.1270 +	INFO_PRINTF1(_L("try to connect twice"));
  1.1271 +	res = session.Connect();
  1.1272 +	TEST(res == KErrAlreadyExists);
  1.1273 +	
  1.1274 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0008 wrong parameters
  1.1275 +	INFO_PRINTF1(_L("specifying wrong parametrs"));
  1.1276 +	INFO_PRINTF1(_L("specify a negative screen number"));
  1.1277 +	screen = -10;
  1.1278 +	session.NotifyWhenAvailable(status);	
  1.1279 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1280 +	session.NotifyWhenDisplayedXTimes(10, status2);	
  1.1281 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1282 +	User::WaitForRequest(status);
  1.1283 +	User::WaitForRequest(status1);
  1.1284 +	User::WaitForRequest(status2);
  1.1285 +	
  1.1286 +	TEST(status == KErrArgument);
  1.1287 +	TEST(status1 == KErrArgument);
  1.1288 +	TEST(status2 == KErrArgument);
  1.1289 +	TEST(res == KErrArgument);
  1.1290 +
  1.1291 +	INFO_PRINTF1(_L("receiver for the following screen doesn't exist"));
  1.1292 +	screen = 10;
  1.1293 +	session.NotifyWhenAvailable(status);	
  1.1294 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1295 +	session.NotifyWhenDisplayedXTimes(10, status2);	
  1.1296 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1297 +	User::WaitForRequest(status);
  1.1298 +	User::WaitForRequest(status1);
  1.1299 +	User::WaitForRequest(status2);
  1.1300 +
  1.1301 +	TEST(status == KErrUpdateReceiverNotAvailable);
  1.1302 +	TEST(status1 == KErrUpdateReceiverNotAvailable);
  1.1303 +	TEST(status2 == KErrUpdateReceiverNotAvailable);
  1.1304 +	TEST(res == KErrUpdateReceiverNotAvailable);
  1.1305 +
  1.1306 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0009 Submission with screen which doesn't exist in the system
  1.1307 +	INFO_PRINTF1(_L("too big screen number"));
  1.1308 +	screen = 100000;
  1.1309 +	session.NotifyWhenAvailable(status);	
  1.1310 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1311 +	session.NotifyWhenDisplayedXTimes(10, status2);	
  1.1312 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1313 +	User::WaitForRequest(status);
  1.1314 +	User::WaitForRequest(status1);
  1.1315 +	User::WaitForRequest(status2);
  1.1316 +
  1.1317 +	TEST(status == KErrUpdateReceiverNotAvailable);
  1.1318 +	TEST(status1 == KErrUpdateReceiverNotAvailable);
  1.1319 +	TEST(status2 == KErrUpdateReceiverNotAvailable);
  1.1320 +	TEST(res == KErrUpdateReceiverNotAvailable);
  1.1321 +	
  1.1322 +	INFO_PRINTF1(_L("negative buffer"));
  1.1323 +	screen = 0;
  1.1324 +	buffer = -10;
  1.1325 +	session.NotifyWhenAvailable(status);	
  1.1326 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1327 +	session.NotifyWhenDisplayedXTimes(10, status2);	
  1.1328 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1329 +	User::WaitForRequest(status);
  1.1330 +	User::WaitForRequest(status1);
  1.1331 +	User::WaitForRequest(status2);
  1.1332 +
  1.1333 +	TEST(status == KErrArgument);
  1.1334 +	TEST(status1 == KErrArgument);
  1.1335 +	TEST(status2 == KErrArgument);
  1.1336 +	TEST(res == KErrArgument);
  1.1337 +
  1.1338 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0010 Submission with invalid number of counts in NotifyWhenDisplayedXTimes()
  1.1339 +	INFO_PRINTF1(_L("displaying for negative number of times"));
  1.1340 +	screen = 0;
  1.1341 +	buffer = 0;
  1.1342 +	TInt displayedXTimes = -10;	
  1.1343 +	session.NotifyWhenAvailable(status);	
  1.1344 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1345 +	session.NotifyWhenDisplayedXTimes(displayedXTimes, status2);	
  1.1346 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1347 +	User::WaitForRequest(status);
  1.1348 +	User::WaitForRequest(status1);
  1.1349 +	User::WaitForRequest(status2);
  1.1350 +
  1.1351 +	TEST(status == KErrNone);
  1.1352 +	TEST(status1 == KErrNone);
  1.1353 +	TEST(status2 == KErrArgument);
  1.1354 +	TEST(res == KErrNone);
  1.1355 +	
  1.1356 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0011 Number of outstanding requests exceeds pre-defined value
  1.1357 +	INFO_PRINTF1(_L("number of outstanding requests exceeds pre-defined value"));
  1.1358 +	session.Close();
  1.1359 +	User::LeaveIfError(session.Connect(4));
  1.1360 +	buffer = 0;
  1.1361 +	session.NotifyWhenAvailable(status);	
  1.1362 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1363 +	session.NotifyWhenDisplayedXTimes(10, status2);	
  1.1364 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1365 +	TEST(res == KErrNone);
  1.1366 +
  1.1367 +	session.NotifyWhenAvailable(status3);	
  1.1368 +	session.NotifyWhenDisplayed(status4, timeStamp);	
  1.1369 +	session.NotifyWhenDisplayedXTimes(10, status5);	
  1.1370 +	res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1371 +	TEST(res == KErrNone);
  1.1372 +
  1.1373 +	User::WaitForRequest(status);
  1.1374 +	User::WaitForRequest(status1);
  1.1375 +	User::WaitForRequest(status2);
  1.1376 +	User::WaitForRequest(status3);
  1.1377 +	User::WaitForRequest(status4);
  1.1378 +	User::WaitForRequest(status5);
  1.1379 +	
  1.1380 +	TEST(status == KErrNone);
  1.1381 +	TEST(status1== KErrNone);
  1.1382 +	TEST(status2== KErrNone);
  1.1383 +	TEST(status3== KErrNone);
  1.1384 +	TEST(status4== KErrServerBusy);
  1.1385 +	TEST(status5== KErrServerBusy);
  1.1386 +	
  1.1387 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0012 Submission of region with empty rectangle list
  1.1388 +	INFO_PRINTF1(_L("specify empty region"));
  1.1389 +	RRegion region1;
  1.1390 +	session.NotifyWhenAvailable(status);	
  1.1391 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.1392 +	session.NotifyWhenDisplayedXTimes(10, status2);	
  1.1393 +	res = session.SubmitUpdate(screen, surface, buffer, &region1);
  1.1394 +	TEST(res == KErrNone);
  1.1395 +
  1.1396 +	User::WaitForRequest(status);
  1.1397 +	User::WaitForRequest(status1);
  1.1398 +	User::WaitForRequest(status2);
  1.1399 +	TEST(status == KErrNone);
  1.1400 +	TEST(status1== KErrNone);
  1.1401 +	TEST(status2== KErrNone);
  1.1402 +	
  1.1403 +	//register with negative screen
  1.1404 +	//@SYMTestCaseID GRAPHICS-SURFACEUPDATE-0013 Assigning receiver to the screen with negative number
  1.1405 +	INFO_PRINTF1(_L("register with negative screen"));
  1.1406 +	res = Provider()->Register(-1, NULL, 1);
  1.1407 +	TEST(res==KErrArgument);
  1.1408 +	session.Close();
  1.1409 +	}
  1.1410 +
  1.1411 +/**
  1.1412 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0014
  1.1413 +
  1.1414 +  @SYMPREQ 1007
  1.1415 +  
  1.1416 +  @SYMREQ 8223
  1.1417 +
  1.1418 +  @SYMTestCaseDesc OOM testing. 
  1.1419 +
  1.1420 +  @SYMTestPriority High
  1.1421 +
  1.1422 +  @SYMTestStatus Implemented
  1.1423 +
  1.1424 +  @SYMTestActions Create connection to the server. 
  1.1425 +  	Set server in special mode which simulates heap allocation failure. 
  1.1426 +  	1. Subscribe for notifications. 
  1.1427 +  	2. Submit update command with not empty region.
  1.1428 +  	
  1.1429 +  @SYMTestExpectedResults Submit return code and notifications must arrive 
  1.1430 +  with KErrNoMemory in the case of memory allocation failures.
  1.1431 +*/
  1.1432 +void CTSurfaceUpdate::TestCase7L()
  1.1433 +	{
  1.1434 +	RMisbehavingSession session;
  1.1435 +	TRequestStatus status;
  1.1436 +	TRequestStatus status1;
  1.1437 +	TRequestStatus status2;
  1.1438 +	TTimeStamp timeStamp;
  1.1439 +	TSurfaceId surface = 
  1.1440 +		{
  1.1441 +		1,2,3,4
  1.1442 +		};
  1.1443 +	TRect rc[2] =
  1.1444 +		{
  1.1445 +		TRect(1,2, 10, 20),
  1.1446 +		TRect(5,6, 30, 30)
  1.1447 +		};
  1.1448 +	
  1.1449 +	RRegion region(2, rc);
  1.1450 +	TInt buffer = 0;
  1.1451 +	TInt screen = 0;
  1.1452 +	User::LeaveIfError(session.Connect());
  1.1453 +	TInt res = KErrNone;
  1.1454 +	
  1.1455 +	//create another receiver
  1.1456 +	CTContentUpdateReceiver *receiver4;
  1.1457 +	User::LeaveIfError(StartTestUpdateReceiver(receiver4, 4));
  1.1458 +	iReceivers.AppendL(receiver4);
  1.1459 +	
  1.1460 +	TInt ii = 1;
  1.1461 +	const TInt screenNo = 16;
  1.1462 +	// Cause a failure on all the allocs on server side
  1.1463 +	for(ii = 1; ; ++ii)
  1.1464 +		{
  1.1465 +		session.SetFailRate(ii);
  1.1466 +		res = Provider()->Register(screenNo, receiver4, -100);
  1.1467 +		if(res != KErrNoMemory)
  1.1468 +			break;
  1.1469 +		} 
  1.1470 +	TEST(res == KErrNone);
  1.1471 +	//unregister receiver
  1.1472 +	User::LeaveIfError(Provider()->Register(screenNo, NULL, 0));
  1.1473 +	//try to do the same same thing again, to make sure that it won't panic
  1.1474 +	User::LeaveIfError(Provider()->Register(screenNo, NULL, 0)); //unregister the function
  1.1475 +	TInt index = iReceivers.Find(receiver4);
  1.1476 +	TEST(index != KErrNotFound);
  1.1477 +	CloseTestUpdateReceiver(receiver4);	
  1.1478 +	iReceivers.Remove(index);
  1.1479 +	//end register testing
  1.1480 +	
  1.1481 +	// Cause a failure on all the allocs on server side
  1.1482 +	for(ii = 1; ; ++ii)
  1.1483 +		{
  1.1484 +		// Test 1st alloc failure
  1.1485 +		session.SetFailRate(ii);
  1.1486 +		session.NotifyWhenAvailable(status);
  1.1487 +		session.NotifyWhenDisplayed(status1, timeStamp);
  1.1488 +		session.NotifyWhenDisplayedXTimes(1, status2);
  1.1489 +		res = session.SubmitUpdate(screen, surface, buffer, &region);
  1.1490 +		User::WaitForRequest(status);
  1.1491 +		User::WaitForRequest(status1);
  1.1492 +		User::WaitForRequest(status2);
  1.1493 +		
  1.1494 +		// Whenever we hit error codes that aren't no memory, we're finished
  1.1495 +		if(res != KErrNoMemory || status.Int() != KErrNoMemory || status1.Int() != KErrNoMemory || status2.Int() != KErrNoMemory)
  1.1496 +			break;
  1.1497 +		
  1.1498 +		TEST(res == KErrNoMemory); // Since the first alloc fail kills the server
  1.1499 +		TEST(status.Int() == KErrNoMemory);
  1.1500 +		}
  1.1501 +		
  1.1502 +	TEST(res == KErrNone);
  1.1503 +	TEST((status.Int() == KErrNone) || (status.Int() == KErrNoMemory));
  1.1504 +	TEST((status1.Int() == KErrNone) || (status1.Int() == KErrNoMemory));
  1.1505 +	TEST((status2.Int() == KErrNone) || (status2.Int() == KErrNoMemory));
  1.1506 +	session.SetFailRate(0); // turns off oom failures
  1.1507 +	session.Close();
  1.1508 +	}
  1.1509 +	
  1.1510 +/**
  1.1511 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0015
  1.1512 +
  1.1513 +  @SYMPREQ 1007
  1.1514 +  
  1.1515 +  @SYMREQ 8223
  1.1516 +
  1.1517 +  @SYMTestCaseDesc Causing panic of client 
  1.1518 +
  1.1519 +  @SYMTestPriority High
  1.1520 +
  1.1521 +  @SYMTestStatus Implemented
  1.1522 +
  1.1523 +  @SYMTestActions Create second thread which connects to the server. 
  1.1524 +  	Pass an invalid opcode to the server which will cause a client panic.
  1.1525 +  	
  1.1526 +  @SYMTestExpectedResults The thread will die with the correct exit reason
  1.1527 +    (EUpdateServPanicBadRequest) and the correct exit category (SurfUpServ).
  1.1528 +*/
  1.1529 +void CTSurfaceUpdate::TestCase8()
  1.1530 + 	{
  1.1531 + 	// Create another thread in which we will panic the client
  1.1532 + 	_LIT(KThreadName, "TestPanicClientThread");
  1.1533 + 	RThread thread;
  1.1534 +	TEST(KErrNone == thread.Create(KThreadName,
  1.1535 +			PanicClientThread,
  1.1536 +			KDefaultStackSize,
  1.1537 +			&User::Heap(),
  1.1538 +			NULL));
  1.1539 +	TRequestStatus rendezvousStatus;
  1.1540 +	thread.Rendezvous(rendezvousStatus);
  1.1541 +	thread.Resume();
  1.1542 +	User::WaitForRequest(rendezvousStatus);
  1.1543 +	_LIT(KExitCategory,"SurfUpServ");
  1.1544 +	TBuf<16> exitCategory(KExitCategory);
  1.1545 +	TEST(thread.ExitReason() == EUpdateServPanicBadRequest);
  1.1546 +	TEST(thread.ExitCategory() == exitCategory);
  1.1547 +	thread.Close();
  1.1548 + 	}
  1.1549 + 	
  1.1550 +/**
  1.1551 +Thread function called from TestCase8L in order to panic the client.
  1.1552 +*/ 	
  1.1553 +TInt CTSurfaceUpdate::PanicClientThread(TAny*)
  1.1554 +	{
  1.1555 +	User::SetJustInTime(EFalse);
  1.1556 +	RMisbehavingSession session;
  1.1557 +	TInt err = session.Connect();
  1.1558 + 	if(KErrNone != err)
  1.1559 + 		return err;
  1.1560 + 	session.TestPassingInvalidOpcode();
  1.1561 + 	// Exit reason will be the panic number due to the invalid op code:
  1.1562 + 	// returning zero here is redundant
  1.1563 + 	return 0;
  1.1564 +	}
  1.1565 +
  1.1566 +/**
  1.1567 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0016
  1.1568 +
  1.1569 +
  1.1570 +  @SYMPREQ 1007
  1.1571 +  
  1.1572 +  @SYMREQ 8223
  1.1573 +
  1.1574 +  @SYMTestCaseDesc Calling submit before any notify with invalid arguments. 
  1.1575 +
  1.1576 +  @SYMTestPriority High
  1.1577 +
  1.1578 +  @SYMTestStatus Implemented
  1.1579 +
  1.1580 +  @SYMTestActions Set an invalid screen number and call SubmitUpdate (before a notify).
  1.1581 +    Set an invalid buffer number and call SubmitUpdate (before a notify).
  1.1582 +  	Set a Null surfaceId and call SubmitUpdate (before a notify).
  1.1583 +  	
  1.1584 +  @SYMTestExpectedResults SubmitUpdate will return KErrArgument in both cases.
  1.1585 +*/
  1.1586 +void CTSurfaceUpdate::TestCase9L()
  1.1587 +	{
  1.1588 +	RSurfaceUpdateSession session;	
  1.1589 +	User::LeaveIfError(session.Connect());
  1.1590 +	
  1.1591 +	// Test submit before notify with -ve screen
  1.1592 +	TInt screen = -1;
  1.1593 +	TSurfaceId surface = 
  1.1594 +			{
  1.1595 +			1,2,3,4
  1.1596 +			};
  1.1597 +	TInt buffer = 1;
  1.1598 +	TInt res = session.SubmitUpdate(screen, surface, buffer, NULL);
  1.1599 +	TEST(res == KErrArgument);
  1.1600 +	
  1.1601 +	// Test submit before notify with -ve buffer
  1.1602 +	screen = 1;
  1.1603 +	buffer = -1;
  1.1604 +	res = session.SubmitUpdate(screen, surface, buffer, NULL);
  1.1605 +	TEST(res == KErrArgument);
  1.1606 +
  1.1607 +	//Test submit before notify with Null surfaceId
  1.1608 +	surface = TSurfaceId::CreateNullId();
  1.1609 +	screen = 1;
  1.1610 +	buffer = 1;
  1.1611 +	res = session.SubmitUpdate(screen, surface, buffer, NULL);
  1.1612 +	TEST(res == KErrArgument);
  1.1613 +	session.Close();
  1.1614 +	}
  1.1615 +
  1.1616 +/**
  1.1617 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0017
  1.1618 +
  1.1619 +
  1.1620 +  @SYMPREQ 1007
  1.1621 +  
  1.1622 +  @SYMREQ 8223
  1.1623 +
  1.1624 +  @SYMTestCaseDesc Using a rogue client to call multiple notifies in a row. 
  1.1625 +
  1.1626 +  @SYMTestPriority High
  1.1627 +
  1.1628 +  @SYMTestStatus Implemented
  1.1629 +
  1.1630 +  @SYMTestActions Create a second thread which will call multiple notifies
  1.1631 +   in succession (not interleaved with Submits).
  1.1632 +  	
  1.1633 +  @SYMTestExpectedResults The thread should have an exit category
  1.1634 +   of SurfUpServ and and exit reason of EUpdateServPanicDataIntegrity in
  1.1635 +   all cases.
  1.1636 +*/
  1.1637 +void CTSurfaceUpdate::TestCase10()
  1.1638 +	{
  1.1639 + 	for(TInt testNum = 0; testNum < 3; ++testNum)
  1.1640 + 		{
  1.1641 + 		_LIT(KThreadName, "TestMultipleNotify%d");
  1.1642 + 		TBuf<19> threadName;
  1.1643 + 		threadName.Format(KThreadName, testNum);
  1.1644 + 		RThread thread;
  1.1645 + 		TRequestStatus status;
  1.1646 +	 	TMultipleNotify statusCol(status, testNum);
  1.1647 +		TEST(KErrNone == thread.Create(threadName,
  1.1648 +				TestMultipleNotifyThreadL,
  1.1649 +				KDefaultStackSize,
  1.1650 +				&User::Heap(),
  1.1651 +				&statusCol));
  1.1652 +		TRequestStatus rendezvousStatus;
  1.1653 +		thread.Rendezvous(rendezvousStatus);
  1.1654 +		thread.Resume();
  1.1655 +		User::WaitForRequest(rendezvousStatus);
  1.1656 +		// We expect the first request to be cancelled.
  1.1657 +		//The request can also be on a pending state if the connection is closed before the 
  1.1658 +		//cancellation has been transferred to client 
  1.1659 +		TEST((KErrCancel == status.Int()) || (status.Int() == KRequestPending));
  1.1660 +		// We expect the second request to Panic the client
  1.1661 +		_LIT(KExitCategory,"SurfUpServ");
  1.1662 +		TBuf<16> exitCategory(KExitCategory);
  1.1663 +		TEST(thread.ExitReason() == EUpdateServPanicDataIntegrity);
  1.1664 +		TEST(thread.ExitCategory() == exitCategory);
  1.1665 +		thread.Close();
  1.1666 + 		}
  1.1667 +	}
  1.1668 +	
  1.1669 +/**
  1.1670 +Thread function called from TestCase10 in order to submit multiple notifies.
  1.1671 +*/	
  1.1672 +TInt CTSurfaceUpdate::TestMultipleNotifyThreadL(TAny* aStatusCol)
  1.1673 +	{
  1.1674 +	User::SetJustInTime(EFalse);
  1.1675 +	RMisbehavingSession badSession;
  1.1676 +	User::LeaveIfError(badSession.Connect());
  1.1677 +	TMultipleNotify* statusCol = static_cast<TMultipleNotify*>(aStatusCol);
  1.1678 +	TRequestStatus status;
  1.1679 +	switch(statusCol->iTestNum)
  1.1680 +		{
  1.1681 +	case 0:
  1.1682 +		badSession.NotifyWhenAvailableNoChecking(statusCol->iStatus);
  1.1683 +		badSession.NotifyWhenAvailableNoChecking(status);
  1.1684 +		break;
  1.1685 +	case 1:
  1.1686 +		badSession.NotifyWhenDisplayedNoChecking(statusCol->iStatus);
  1.1687 +		badSession.NotifyWhenDisplayedNoChecking(status);
  1.1688 +		break;
  1.1689 +	case 2:
  1.1690 +		badSession.NotifyWhenDisplayedXTimesNoChecking(10, statusCol->iStatus);
  1.1691 +		badSession.NotifyWhenDisplayedXTimesNoChecking(10, status);
  1.1692 +		break;
  1.1693 +	default:
  1.1694 +		_LIT(KMultipleNotifyPanic, "MultNotifyPanic");
  1.1695 +		User::Panic(KMultipleNotifyPanic, 1);
  1.1696 +		break;
  1.1697 +		}
  1.1698 +	User::WaitForRequest(statusCol->iStatus);
  1.1699 +	User::WaitForRequest(status);
  1.1700 +	// Exit reason will be the panic number due to the invalid op code:
  1.1701 + 	// returning zero here is redundant
  1.1702 +	return 0;
  1.1703 +	}
  1.1704 +
  1.1705 +/**
  1.1706 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0018
  1.1707 +
  1.1708 +  @SYMPREQ 1007
  1.1709 +  
  1.1710 +  @SYMREQ 8223
  1.1711 +
  1.1712 +  @SYMTestCaseDesc Use a rogue client to misbehave in various ways.
  1.1713 +
  1.1714 +  @SYMTestPriority High
  1.1715 +
  1.1716 +  @SYMTestStatus Implemented
  1.1717 +
  1.1718 +  @SYMTestActions 1. Attempt to connect with an incorrect version number.
  1.1719 +    Connect to the server, communicate with server without proper client side checking:
  1.1720 +    2. Submit update with a negative buffer number (no client side checking).
  1.1721 +    3. Submit update with a negative screen number (no client side checking).
  1.1722 +    4. Call NotifyWhenDisplayedXTimes with no client side checking and a count of 0.
  1.1723 +  	
  1.1724 +  @SYMTestExpectedResults 1. KErrNotSupported
  1.1725 +    2. KErrArgument
  1.1726 +    3. KErrArgument
  1.1727 +    4. Status int is KErrArgument (SubmitUpdate == KErrNone).
  1.1728 +*/
  1.1729 +void CTSurfaceUpdate::TestCase11()
  1.1730 +	{
  1.1731 +	// Attempt to connect with the wrong version number
  1.1732 +	RMisbehavingSession session;
  1.1733 +	TEST(KErrNotSupported == session.Connect(KDefaultMessageSlot, ETrue));
  1.1734 +	
  1.1735 +	TEST(KErrNone == session.Connect());
  1.1736 +	TInt screen = 0;
  1.1737 +	TSurfaceId surface = 
  1.1738 +		{
  1.1739 +		1,2,3,4
  1.1740 +		};
  1.1741 +	TInt buffer = -1;
  1.1742 +	
  1.1743 +	// Call RMisbehavingSession::SubmitUpdate which doesn't do the correct
  1.1744 +	// client side checking
  1.1745 +	TEST(KErrArgument == session.SubmitUpdateNoChecking(screen, surface, buffer, NULL));
  1.1746 +	
  1.1747 +	// Test with -ve screen
  1.1748 +	screen = -1;
  1.1749 +	buffer = 0;
  1.1750 +	TEST(KErrArgument == session.SubmitUpdateNoChecking(screen, surface, buffer, NULL));
  1.1751 +	
  1.1752 +	// Test calling NotifyWhenDisplayedXTimes with no client side checking and a count of 0
  1.1753 +	screen = 0;
  1.1754 +	buffer = 1;
  1.1755 +	TRequestStatus status;
  1.1756 +	session.NotifyWhenDisplayedXTimesNoChecking(0, status);
  1.1757 +	TEST(KErrNone == session.SubmitUpdateNoChecking(screen, surface, buffer, NULL));
  1.1758 +	User::WaitForRequest(status);
  1.1759 +	TEST(KErrArgument == status.Int());
  1.1760 +	
  1.1761 +	session.Close();
  1.1762 +	}
  1.1763 +
  1.1764 +
  1.1765 +/**
  1.1766 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0019
  1.1767 +
  1.1768 +
  1.1769 +  @SYMPREQ 1007
  1.1770 +  
  1.1771 +  @SYMREQ 8223
  1.1772 +
  1.1773 +  @SYMTestCaseDesc Starting the surface update server in two different threads.
  1.1774 +
  1.1775 +  @SYMTestPriority High
  1.1776 +
  1.1777 +  @SYMTestStatus Implemented
  1.1778 +
  1.1779 +  @SYMTestActions Start the surface update server in two different threads.
  1.1780 +    
  1.1781 +  @SYMTestExpectedResults Thread 1: KErrNone
  1.1782 +     Thread 2: KErrNone
  1.1783 +     The "provider" returned to both threads should also be the same value!
  1.1784 +*/
  1.1785 +void CTSurfaceUpdate::TestCase12L()
  1.1786 +    {
  1.1787 +    MSurfaceUpdateServerProvider *surfaceUpdateProvider = NULL;
  1.1788 +    TInt res = StartSurfaceUpdateServer(surfaceUpdateProvider);
  1.1789 +    TEST(res == KErrNone);
  1.1790 +    User::LeaveIfError(res);
  1.1791 +
  1.1792 +    _LIT(KThreadName, "TestServerStartupTwoThreads");
  1.1793 +    TTime tm;
  1.1794 +    TBuf<32> buf;
  1.1795 +    tm.UniversalTime();
  1.1796 +    TRAP(res, tm.FormatL(buf, _L("_%H%T%S%C")));
  1.1797 +    TEST(res == KErrNone);
  1.1798 +    User::LeaveIfError(res);
  1.1799 +    TBuf<128> threadName(KThreadName);
  1.1800 +    threadName.Append(buf); //guarantee uniqueness  of the thread name
  1.1801 +    RThread thread;
  1.1802 +    MSurfaceUpdateServerProvider *surfaceUpdateProvider2 = NULL;
  1.1803 +    res = thread.Create(threadName,
  1.1804 +            TestServerStartupTwoThreads,
  1.1805 +            KDefaultStackSize,
  1.1806 +            &User::Heap(),
  1.1807 +            &surfaceUpdateProvider2);
  1.1808 +    TEST(res == KErrNone);
  1.1809 +    User::LeaveIfError(res);
  1.1810 +    TRequestStatus rendezvousStatus;
  1.1811 +    thread.Rendezvous(rendezvousStatus);
  1.1812 +    thread.Resume();
  1.1813 +    User::WaitForRequest(rendezvousStatus);
  1.1814 +    TEST(KErrNone == rendezvousStatus.Int());
  1.1815 +    // Check that we get the same provider for both threads!
  1.1816 +    TEST(surfaceUpdateProvider2 == surfaceUpdateProvider);
  1.1817 +    }
  1.1818 +
  1.1819 +
  1.1820 +/**
  1.1821 +Starting the update server in another thread - called from TestCase12
  1.1822 +*/
  1.1823 +TInt CTSurfaceUpdate::TestServerStartupTwoThreads(TAny *aArgPtr)
  1.1824 +	{
  1.1825 +	MSurfaceUpdateServerProvider **surfaceUpdateProviderPtr = 
  1.1826 +	        reinterpret_cast<MSurfaceUpdateServerProvider **>(aArgPtr);
  1.1827 +	TInt res = StartSurfaceUpdateServer(*surfaceUpdateProviderPtr);
  1.1828 +	return res;
  1.1829 +	}
  1.1830 +
  1.1831 +/**
  1.1832 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0020
  1.1833 +
  1.1834 +  @SYMPREQ 1007
  1.1835 +  
  1.1836 +  @SYMREQ 8223
  1.1837 +
  1.1838 +  @SYMTestCaseDesc Requesting notifies, leaving enough time for them to 
  1.1839 +  complete before requesting the subsequent notification.
  1.1840 +
  1.1841 +  @SYMTestPriority High
  1.1842 +
  1.1843 +  @SYMTestStatus Implemented
  1.1844 +
  1.1845 +  @SYMTestActions Execute some notifies and submits, wait for a short period (100us), 
  1.1846 +  then cancel them all.
  1.1847 +  	
  1.1848 +  @SYMTestExpectedResults Two results are acceptable: KErrNone (notify 
  1.1849 +  completed before it was cancelled) or KErrCancel (notify sucessfully cancelled).
  1.1850 +*/	
  1.1851 +void CTSurfaceUpdate::TestCase13L()
  1.1852 +	{
  1.1853 +	RSurfaceUpdateSession session;
  1.1854 +	const TInt numNotifies = 10;
  1.1855 +	User::LeaveIfError(session.Connect(numNotifies));	
  1.1856 +	
  1.1857 +	TRequestStatus statusArray[numNotifies];
  1.1858 +	TInt screen = 0;
  1.1859 +	TSurfaceId surface = 
  1.1860 +		{
  1.1861 +		1,2,3,4
  1.1862 +		};
  1.1863 +	TInt buffer = 1;
  1.1864 +	
  1.1865 +	// Send the same type of notification request multiply, cancelling after each submission
  1.1866 +	for(TInt ii = 0; ii < numNotifies; ++ii)
  1.1867 +		{
  1.1868 +		session.NotifyWhenAvailable(statusArray[ii]);
  1.1869 +		TEST(KErrNone == session.SubmitUpdate(screen, surface, buffer, NULL));
  1.1870 +		session.CancelAllUpdateNotifications();
  1.1871 +		User::After(100); // Enough time for the notify to be processed
  1.1872 +		}
  1.1873 +	
  1.1874 +	// Check that the error codes are acceptable
  1.1875 +	for(TInt ii = 0; ii < numNotifies; ++ii)
  1.1876 +		{
  1.1877 +		TInt ret = statusArray[ii].Int();
  1.1878 +		TEST(statusArray[ii].Int() == KErrNone || statusArray[ii].Int() == KErrCancel);
  1.1879 +		}
  1.1880 +	
  1.1881 +	session.Close();
  1.1882 +	}
  1.1883 +	
  1.1884 +/**
  1.1885 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0021
  1.1886 +
  1.1887 +  @SYMPREQ 1007
  1.1888 +  
  1.1889 +  @SYMREQ 8223
  1.1890 +
  1.1891 +  @SYMTestCaseDesc Terminating and restarting the server.
  1.1892 +
  1.1893 +  @SYMTestPriority High
  1.1894 +
  1.1895 +  @SYMTestStatus Implemented
  1.1896 +
  1.1897 +  @SYMTestActions Terminate and restart the server
  1.1898 +  	
  1.1899 +  @SYMTestExpectedResults Test that trying to connect the session after 
  1.1900 +  	termination of the server results in KErrNotFound, and that the server 
  1.1901 +  	can be restarted with result KErrNone.
  1.1902 +*/
  1.1903 +void CTSurfaceUpdate::TestCaseTerminateServer()
  1.1904 +	{
  1.1905 +	(static_cast <CTSurfaceUpdateStep*> (iStep)) ->TerminateServer();
  1.1906 +	
  1.1907 +	//at that point server has been terminated
  1.1908 +	RSurfaceUpdateSession session;
  1.1909 +	TInt res = session.Connect();
  1.1910 +	TEST(res == KErrNotFound);
  1.1911 +	session.Close();
  1.1912 +	
  1.1913 +	res = (static_cast <CTSurfaceUpdateStep*> (iStep)) ->StartServer();
  1.1914 +	TEST(res == KErrNone);
  1.1915 +	res = session.Connect();
  1.1916 +	TEST(res == KErrNone);
  1.1917 +	session.Close();
  1.1918 +	}
  1.1919 +	
  1.1920 +/**
  1.1921 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0022
  1.1922 +
  1.1923 +  @SYMPREQ 1007
  1.1924 +  
  1.1925 +  @SYMREQ 8223
  1.1926 +
  1.1927 +  @SYMTestCaseDesc Terminating the thread while some outstanding request in progress.
  1.1928 +
  1.1929 +  @SYMTestPriority High
  1.1930 +
  1.1931 +  @SYMTestStatus Implemented
  1.1932 +
  1.1933 +  @SYMTestActions Terminate the thread which has outstanding request to 
  1.1934 +  the server for surface update notifications. 
  1.1935 +  	
  1.1936 +  @SYMTestExpectedResults Surface update surface should process the request 
  1.1937 +  and try to send notification without hanging.
  1.1938 +  
  1.1939 +*/
  1.1940 +void CTSurfaceUpdate::TestCase14()
  1.1941 +	{
  1.1942 + 	_LIT(KThreadNameTemplate, "TestPanicClientThread1_%d");
  1.1943 + 	
  1.1944 + 	RThread thread;
  1.1945 +	const TInt KMaxIndex = 50;
  1.1946 + 	for(TInt index = 0; index < KMaxIndex; index++)
  1.1947 + 		{
  1.1948 + 		const TInt KUnexpectedLeavePanic = 194;
  1.1949 + 		TBuf<128> threadName;
  1.1950 + 		threadName.Format(KThreadNameTemplate, index);
  1.1951 + 		TInt res = thread.Create(threadName,
  1.1952 +			PanicClientThread1,
  1.1953 +			KDefaultStackSize,
  1.1954 +			&User::Heap(),
  1.1955 +			this);
  1.1956 +		TEST(res == KErrNone);	
  1.1957 + 		TRequestStatus status = KRequestPending;
  1.1958 + 		thread.Logon(status);
  1.1959 + 		thread.Resume();
  1.1960 + 		User::WaitForRequest(status);
  1.1961 +
  1.1962 + 		res = thread.ExitReason();
  1.1963 + 		TEST(res == KUnexpectedLeavePanic);
  1.1964 + 		if(res != KUnexpectedLeavePanic)
  1.1965 + 			{
  1.1966 + 			INFO_PRINTF2(_L("Thread exits with error code %d"), res);
  1.1967 + 			}
  1.1968 + 		thread.Close();
  1.1969 + 		}
  1.1970 +	}
  1.1971 +
  1.1972 +/**
  1.1973 +  @SYMTestCaseID GRAPHICS-SURFACEUPDATE-0025
  1.1974 +
  1.1975 +  @SYMPREQ 1007/11599, 1007/11600, 1007/11601
  1.1976 +
  1.1977 +  @SYMREQ 8223
  1.1978 +
  1.1979 +  @SYMTestCaseDesc SubmitUpdate() with a global and a per-display 
  1.1980 +  update cannot be mixed.
  1.1981 +  @SYMTestPriority High
  1.1982 +
  1.1983 +  @SYMTestStatus Implemented
  1.1984 +
  1.1985 +  @SYMTestActions 
  1.1986 +	Create the session and make a global submit update.
  1.1987 +	Subscribe for all notifications and make per screen submit update. 
  1.1988 +	Create another session and make a per screen update.
  1.1989 +	Subscribe for all notifications and make a global submit update. 
  1.1990 +	
  1.1991 +  		
  1.1992 +  @SYMTestExpectedResults 
  1.1993 +  	Mixing two different types of submit update should fail with an error KErrNotSupported.
  1.1994 +*/
  1.1995 +void CTSurfaceUpdate::TestCase18()
  1.1996 +	{
  1.1997 +	INFO_PRINTF1(_L("SubmitUpdate() to deal with both a global and a per-display update in the same session"));
  1.1998 +
  1.1999 +	RSurfaceUpdateSession session;
  1.2000 +	TInt buffer = 2;
  1.2001 +	TSurfaceId surface = 
  1.2002 +		{
  1.2003 +		1,2,3,4
  1.2004 +		};
  1.2005 +
  1.2006 +	TInt res = session.Connect();
  1.2007 +	TEST(res == KErrNone);
  1.2008 +
  1.2009 +	res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  1.2010 +	TEST(res==KErrNone);
  1.2011 +	
  1.2012 +	TRequestStatus status = KRequestPending;
  1.2013 +	TRequestStatus status1 = KRequestPending;
  1.2014 +	TRequestStatus status2 = KRequestPending;
  1.2015 +	TTimeStamp timeStamp; 
  1.2016 +	
  1.2017 +	session.NotifyWhenAvailable(status);	
  1.2018 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.2019 +	session.NotifyWhenDisplayedXTimes(10, status2);
  1.2020 +		
  1.2021 +	res = session.SubmitUpdate(1, surface, buffer, NULL);
  1.2022 +	TEST(res==KErrNotSupported);
  1.2023 +		
  1.2024 +	User::WaitForRequest(status);
  1.2025 +	User::WaitForRequest(status1);
  1.2026 +	User::WaitForRequest(status2);
  1.2027 +
  1.2028 +	TEST(status == KErrNotSupported);
  1.2029 +	TEST(status1 == KErrNotSupported);
  1.2030 +	TEST(status2 == KErrNotSupported);
  1.2031 +	
  1.2032 +	session.Close();
  1.2033 +	//make per screen update first
  1.2034 +	res = session.Connect();
  1.2035 +	TEST(res == KErrNone);
  1.2036 +
  1.2037 +	res = session.SubmitUpdate(1, surface, buffer, NULL);
  1.2038 +	TEST(res==KErrNone);
  1.2039 +	
  1.2040 +	status = KRequestPending;
  1.2041 +	status1 = KRequestPending;
  1.2042 +	status2 = KRequestPending;
  1.2043 +	
  1.2044 +	session.NotifyWhenAvailable(status);	
  1.2045 +	session.NotifyWhenDisplayed(status1, timeStamp);	
  1.2046 +	session.NotifyWhenDisplayedXTimes(10, status2);
  1.2047 +		
  1.2048 +	res = session.SubmitUpdate(KAllScreens, surface, buffer, NULL);
  1.2049 +	TEST(res==KErrNotSupported);
  1.2050 +		
  1.2051 +	User::WaitForRequest(status);
  1.2052 +	User::WaitForRequest(status1);
  1.2053 +	User::WaitForRequest(status2);
  1.2054 +
  1.2055 +	TEST(status == KErrNotSupported);
  1.2056 +	TEST(status1 == KErrNotSupported);
  1.2057 +	TEST(status2 == KErrNotSupported);
  1.2058 +	
  1.2059 +	session.Close();
  1.2060 +	}
  1.2061 +
  1.2062 +/**
  1.2063 +Thread function called from TestCase14 in order to panic the client
  1.2064 +*/ 	
  1.2065 +TInt CTSurfaceUpdate::PanicClientThread1(TAny* aAny)
  1.2066 +	{
  1.2067 +	CTSurfaceUpdate* surfaceUpdateTest = (CTSurfaceUpdate*) aAny;
  1.2068 +	surfaceUpdateTest->GenerateMultipleUpdateWithPanic();
  1.2069 +	
  1.2070 +	return 0;
  1.2071 +	}
  1.2072 +
  1.2073 +/**
  1.2074 +Helper function for test case described in TestCase14
  1.2075 +*/ 	
  1.2076 +void CTSurfaceUpdate::GenerateMultipleUpdateWithPanic()
  1.2077 +	{
  1.2078 +	TRequestStatus status = KRequestPending;
  1.2079 +	TTimeStamp timeStamp; 
  1.2080 +	RSurfaceUpdateSession session;
  1.2081 +	TInt screen = 0;
  1.2082 +	TSurfaceId surface = 
  1.2083 +		{
  1.2084 +		1,2,3,4
  1.2085 +		};
  1.2086 +	TInt buffer = 0;
  1.2087 +	
  1.2088 +	TInt res = session.Connect();
  1.2089 +	TEST(res == KErrNone); 
  1.2090 +	session.NotifyWhenDisplayed(status, timeStamp);	
  1.2091 +	res = session.SubmitUpdate(screen, surface, buffer);
  1.2092 +	TEST(res == KErrNone); 
  1.2093 +	User::After(TTimeIntervalMicroSeconds32(100000));
  1.2094 +	
  1.2095 +	User::PanicUnexpectedLeave();
  1.2096 +	}
  1.2097 +
  1.2098 +void CTSurfaceUpdate::ResetSusL()
  1.2099 +	{
  1.2100 +	while (iReceivers.Count() > 0)
  1.2101 +		{
  1.2102 +		CTContentUpdateReceiver *receiver = iReceivers[0];
  1.2103 +		iReceivers.Remove(0);
  1.2104 +		CloseTestUpdateReceiver(receiver);
  1.2105 +		}
  1.2106 +	(static_cast<CTSurfaceUpdateStep*>(iStep))->TerminateServer();
  1.2107 +	User::LeaveIfError((static_cast<CTSurfaceUpdateStep*>(iStep))->StartServer());
  1.2108 +	}
  1.2109 +
  1.2110 +void CTSurfaceUpdate::SetupTestCaseRegisterPanicL()
  1.2111 +	{
  1.2112 +	ResetSusL();
  1.2113 +	// Start two content update receivers for register test
  1.2114 +	CTContentUpdateReceiver* receiverA;
  1.2115 +	CTContentUpdateReceiver* receiverB;
  1.2116 +	User::LeaveIfError(StartTestUpdateReceiver(receiverA, 0));
  1.2117 +	iReceivers.AppendL(receiverA);
  1.2118 +	User::LeaveIfError(StartTestUpdateReceiver(receiverB, 1));
  1.2119 +	iReceivers.AppendL(receiverB);
  1.2120 +	}
  1.2121 +
  1.2122 +void CTSurfaceUpdate::DoTestCaseRegisterPanicL(TThreadFunction aThreadFunction)
  1.2123 +	{
  1.2124 +	_LIT(KRegisterThreadName, "TestPanicRegisterThread");
  1.2125 +	RThread thread;
  1.2126 +	TInt res = thread.Create(KRegisterThreadName, aThreadFunction,
  1.2127 +							 KDefaultStackSize,	&User::Heap(), this);
  1.2128 +	TEST(res == KErrNone);
  1.2129 +	User::LeaveIfError(res);
  1.2130 +	TRequestStatus status = KRequestPending;
  1.2131 +	thread.Logon(status);
  1.2132 +	thread.Resume();
  1.2133 +	User::WaitForRequest(status);
  1.2134 +
  1.2135 +	res = thread.ExitReason();
  1.2136 +	TEST(res == EUpdateServPanicRegister);
  1.2137 +	if(res != EUpdateServPanicRegister)
  1.2138 +		{
  1.2139 +		ERR_PRINTF2(_L("Thread exits with error code %d"), res);
  1.2140 +		}
  1.2141 +	thread.Close();
  1.2142 +	}
  1.2143 +
  1.2144 +/**
  1.2145 + * Ensure that there is no outstanding request from all receivers
  1.2146 + */
  1.2147 +void CTSurfaceUpdate::WaitUntilAllNotificationsProcessed()
  1.2148 +	{
  1.2149 +	const TInt KMaxIterationNumber = 10;
  1.2150 +	TInt ii = 0;
  1.2151 +	for(; ii < KMaxIterationNumber; ii++)
  1.2152 +		{
  1.2153 +		if(((iReceivers[0]->OutstandingRequest() == EFalse)) &&
  1.2154 +				((iReceivers[1]->OutstandingRequest() == EFalse)) &&
  1.2155 +				((iReceivers[2]->OutstandingRequest() == EFalse)))
  1.2156 +				break;
  1.2157 +		INFO_PRINTF2(_L("Wait until all notification processed, iteration %d"), ii);
  1.2158 +		User::After(KCompositionIntervalLong);
  1.2159 +		}
  1.2160 +	TEST(ii < KMaxIterationNumber);//We have waited enough, if it fails, something weird going on
  1.2161 +	}
  1.2162 +
  1.2163 +void CTSurfaceUpdate::RunTestCaseL(TInt aCurTestCase)
  1.2164 +	{
  1.2165 +	((CTSurfaceUpdateStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
  1.2166 +	switch(aCurTestCase)
  1.2167 +		{
  1.2168 +	case 1:
  1.2169 +		{
  1.2170 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0001"));
  1.2171 +		if((static_cast <CTSurfaceUpdateStep*> (iStep)) -> iGce)
  1.2172 +			{
  1.2173 +			INFO_PRINTF1(_L("TestCase1"));
  1.2174 +			TRAPD(ret, TestCase1());
  1.2175 +			TEST(ret == KErrNone);
  1.2176 +			}
  1.2177 +		else
  1.2178 +			{
  1.2179 +			TestComplete();		
  1.2180 +			}	
  1.2181 +		break;
  1.2182 +		}
  1.2183 +	case 2:
  1.2184 +		{
  1.2185 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0002"));
  1.2186 +		INFO_PRINTF1(_L("TestCase2L"));
  1.2187 +		TRAPD(ret, TestCase2L());
  1.2188 +		TEST(ret == KErrNone);
  1.2189 +		break;
  1.2190 +		}
  1.2191 +	case 3:
  1.2192 +		{
  1.2193 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0003"));
  1.2194 +		INFO_PRINTF1(_L("TestCase3L"));
  1.2195 +		TRAPD(ret, TestCase3L());
  1.2196 +		TEST(ret == KErrNone);
  1.2197 +		break;
  1.2198 +		}
  1.2199 +	case 4:
  1.2200 +		{
  1.2201 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0004"));
  1.2202 +		INFO_PRINTF1(_L("TestCase4L"));
  1.2203 +		TRAPD(ret, TestCase4L());
  1.2204 +		TEST(ret == KErrNone);
  1.2205 +		break;
  1.2206 +		}
  1.2207 +	case 5:
  1.2208 +		{
  1.2209 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0005"));
  1.2210 +		INFO_PRINTF1(_L("TestCase5L"));
  1.2211 +		TRAPD(ret, TestCase5L());
  1.2212 +		TEST(ret == KErrNone);
  1.2213 +		break;
  1.2214 +		}
  1.2215 +	case 6:
  1.2216 +		{
  1.2217 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0006"));
  1.2218 +		INFO_PRINTF1(_L("TestCase6L"));
  1.2219 +		TRAPD(ret, TestCase6L());
  1.2220 +		TEST(ret == KErrNone);
  1.2221 +		break;
  1.2222 +		}
  1.2223 +	case 7:
  1.2224 +		{
  1.2225 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0014"));
  1.2226 +		INFO_PRINTF1(_L("TestCase7L"));
  1.2227 +		TRAPD(ret, TestCase7L());
  1.2228 +		TEST(ret == KErrNone);
  1.2229 +		break;
  1.2230 +		}
  1.2231 +	case 8:
  1.2232 +		{
  1.2233 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0015"));
  1.2234 +		INFO_PRINTF1(_L("TestCase8"));
  1.2235 +		TRAPD(ret, TestCase8());
  1.2236 +		TEST(ret == KErrNone);
  1.2237 +		break;
  1.2238 +		}
  1.2239 +	case 9:
  1.2240 + 		{
  1.2241 + 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0016"));
  1.2242 + 		INFO_PRINTF1(_L("TestCase9L"));
  1.2243 + 		TRAPD(ret, TestCase9L());
  1.2244 + 		TEST(ret == KErrNone);
  1.2245 + 		break;
  1.2246 +		}
  1.2247 +	case 10:
  1.2248 + 		{
  1.2249 + 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0017"));
  1.2250 + 		INFO_PRINTF1(_L("TestCase10"));
  1.2251 + 		TRAPD(ret, TestCase10());
  1.2252 + 		TEST(ret == KErrNone);
  1.2253 + 		break;
  1.2254 +		}
  1.2255 +	case 11:
  1.2256 + 		{
  1.2257 + 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0018"));
  1.2258 + 		INFO_PRINTF1(_L("TestCase11"));
  1.2259 + 		TRAPD(ret, TestCase11());
  1.2260 + 		TEST(ret == KErrNone);
  1.2261 + 		break;
  1.2262 +		}
  1.2263 +    case 12:
  1.2264 +        {
  1.2265 +        ((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0019"));
  1.2266 +        INFO_PRINTF1(_L("TestCase12L"));
  1.2267 +        TRAPD(ret, TestCase12L());
  1.2268 +        TEST(ret == KErrNone);
  1.2269 +        break;
  1.2270 +        }
  1.2271 +	case 13:
  1.2272 + 		{
  1.2273 + 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0020"));
  1.2274 + 		INFO_PRINTF1(_L("TestCase13L"));
  1.2275 + 		TRAPD(ret, TestCase13L());
  1.2276 + 		TEST(ret == KErrNone);
  1.2277 + 		break;
  1.2278 +		}
  1.2279 +	case 14:
  1.2280 + 		{
  1.2281 + 		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0022"));
  1.2282 + 		INFO_PRINTF1(_L("TestCase14"));
  1.2283 + 		TestCase14();
  1.2284 + 		break;
  1.2285 +		}
  1.2286 +	case 15:
  1.2287 + 		{
  1.2288 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0023"));
  1.2289 + 		INFO_PRINTF1(_L("TestCase15"));
  1.2290 + 		TRAPD(ret, TestCase15());
  1.2291 + 		TEST(ret == KErrNone);
  1.2292 + 		break;
  1.2293 +		}
  1.2294 +	case 16:
  1.2295 + 		{
  1.2296 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0024"));
  1.2297 + 		INFO_PRINTF1(_L("TestCase16"));
  1.2298 + 		TRAPD(ret, TestCase16L());
  1.2299 + 		TEST(ret == KErrNone);
  1.2300 + 		break;
  1.2301 +		}
  1.2302 +	case 17:
  1.2303 + 		{
  1.2304 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0028"));
  1.2305 + 		INFO_PRINTF1(_L("TestCase17"));
  1.2306 + 		TRAPD(ret, TestCase17());
  1.2307 + 		TEST(ret == KErrNone);
  1.2308 + 		break;
  1.2309 +		}
  1.2310 +	case 18:
  1.2311 + 		{
  1.2312 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0025"));
  1.2313 + 		INFO_PRINTF1(_L("TestCase18"));
  1.2314 + 		TRAPD(ret, TestCase18());
  1.2315 + 		TEST(ret == KErrNone);
  1.2316 + 		break;
  1.2317 +		}
  1.2318 +	case 19:
  1.2319 +		{
  1.2320 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0027"));
  1.2321 +	 	INFO_PRINTF1(_L("TestCaseNotifyWhenAvailableGlobal"));
  1.2322 + 		TRAPD(ret, TestCaseNotifyWhenAvailableGlobal());
  1.2323 + 		TEST(ret == KErrNone);
  1.2324 + 		break;
  1.2325 +		}
  1.2326 +	case 20:
  1.2327 +		{
  1.2328 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0029"));
  1.2329 +	 	INFO_PRINTF1(_L("TestCaseRegisterIdenticalPrioritiesL"));
  1.2330 + 		TRAPD(ret, TestCaseRegisterIdenticalPrioritiesL());
  1.2331 + 		TEST(ret == KErrNone);
  1.2332 + 		break;
  1.2333 +		}
  1.2334 +	case 21:
  1.2335 + 		{//should be the last test case
  1.2336 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(_L("GRAPHICS-SURFACEUPDATE-0021"));
  1.2337 + 		INFO_PRINTF1(_L("TestCaseTerminateServer"));
  1.2338 + 		TRAPD(ret, TestCaseTerminateServer());
  1.2339 + 		TEST(ret == KErrNone);
  1.2340 + 		break;
  1.2341 +		}
  1.2342 +	default:
  1.2343 +		((CTSurfaceUpdateStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
  1.2344 +		((CTSurfaceUpdateStep*)iStep)->CloseTMSGraphicsStep();
  1.2345 +		TestComplete();		
  1.2346 +		break;
  1.2347 +		}
  1.2348 +	((CTSurfaceUpdateStep*)iStep)->RecordTestResultL();
  1.2349 +	}
  1.2350 +
  1.2351 +//--------------
  1.2352 +__CONSTRUCT_STEP__(SurfaceUpdate)
  1.2353 +
  1.2354 +void CTSurfaceUpdateStep::TestSetupL()
  1.2355 +	{
  1.2356 +#ifdef __WINS__
  1.2357 +	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalBoolProperty,  (TAny*)"symbian_graphics_use_gce",  &iGce);
  1.2358 +#else
  1.2359 +	iGce = ETrue;
  1.2360 +// we would need to check here whether it is gce-mode or not.	
  1.2361 +#endif	
  1.2362 +	if(iGce)
  1.2363 +		{
  1.2364 +		User::LeaveIfError(StartServer());
  1.2365 +		}
  1.2366 +	else
  1.2367 +		{//it should work for both cases, but that would be waste of time
  1.2368 +		INFO_PRINTF1(_L("This test must be run in the GCE environment"));
  1.2369 +		}	
  1.2370 +	}
  1.2371 +	
  1.2372 +void CTSurfaceUpdateStep::TestClose()
  1.2373 +	{
  1.2374 +	TerminateServer();
  1.2375 +	}
  1.2376 +
  1.2377 +TInt CTSurfaceUpdateStep::StartServer()
  1.2378 +	{
  1.2379 +	return StartSurfaceUpdateServer(iSurfaceUpdateProvider);
  1.2380 +	}
  1.2381 +	
  1.2382 +void CTSurfaceUpdateStep::TerminateServer()
  1.2383 +	{
  1.2384 +	if(iSurfaceUpdateProvider)
  1.2385 +		{
  1.2386 +		iSurfaceUpdateProvider->Terminate();
  1.2387 +		iSurfaceUpdateProvider = NULL;
  1.2388 +		}
  1.2389 +	}
  1.2390 +	
  1.2391 +//-------------
  1.2392 +// Code for client that doesn't quite behave as it should
  1.2393 +
  1.2394 +TInt RMisbehavingSession::Connect(TInt aMessageSlots, TBool aWrongVersion /*= false*/)
  1.2395 +	{
  1.2396 +	if(Handle())
  1.2397 +		{
  1.2398 +		return KErrAlreadyExists; 
  1.2399 +		}
  1.2400 +	iStatusAvailable = NULL;
  1.2401 +	iStatusDisplayed = NULL;
  1.2402 +	iStatusDisplayedXTimes = NULL;
  1.2403 +	if(aWrongVersion)
  1.2404 +		return CreateSession(KTestSurfaceUpdateServerName, WrongVersion(), aMessageSlots);
  1.2405 +	else
  1.2406 +		return CreateSession(KTestSurfaceUpdateServerName, Version(), aMessageSlots);
  1.2407 +	}
  1.2408 +	
  1.2409 +
  1.2410 +void RMisbehavingSession::Close()
  1.2411 +	{
  1.2412 +	if(Handle())
  1.2413 +		{
  1.2414 +		RHandleBase::Close();
  1.2415 +		}
  1.2416 +	iStatusAvailable = NULL;
  1.2417 +	iStatusDisplayed = NULL;
  1.2418 +	iStatusDisplayedXTimes = NULL;
  1.2419 +	}
  1.2420 +	
  1.2421 +TVersion RMisbehavingSession::Version() const
  1.2422 +	{
  1.2423 +	return (TVersion(KSurfaceUpdateServMajorVersionNumber, KSurfaceUpdateServMinorVersionNumber, KSurfaceUpdateServBuildVersionNumber));
  1.2424 +	}
  1.2425 +	
  1.2426 +TVersion RMisbehavingSession::WrongVersion() const
  1.2427 +	{
  1.2428 +	return (TVersion(KSurfaceUpdateServMajorVersionNumber + 1, KSurfaceUpdateServMinorVersionNumber + 1, KSurfaceUpdateServBuildVersionNumber + 1));
  1.2429 +	}
  1.2430 +
  1.2431 +/**
  1.2432 +Send the NotifyWhenAvailable request directly to the server (without waiting for submit)
  1.2433 +*/
  1.2434 +void RMisbehavingSession::NotifyWhenAvailableNoChecking(TRequestStatus& aStatus)
  1.2435 +	{
  1.2436 +	SendReceive(EUpdateServNotifyWhenAvailable, aStatus);
  1.2437 +	}
  1.2438 +
  1.2439 +/**
  1.2440 +Send the NotifyWhenDisplayed request directly to the server (without waiting for submit)
  1.2441 +*/
  1.2442 +void RMisbehavingSession::NotifyWhenDisplayedNoChecking(TRequestStatus& aStatus)
  1.2443 +	{
  1.2444 +	TTimeStamp* timeStamp = NULL;	
  1.2445 +	TIpcArgs args(timeStamp);
  1.2446 +	SendReceive(EUpdateServNotifyWhenDisplayed, args, aStatus);
  1.2447 +	}
  1.2448 +
  1.2449 +/**
  1.2450 +Send the NotifyWhenDisplayedXTimes request directly to the server (without waiting for submit)
  1.2451 +*/
  1.2452 +void RMisbehavingSession::NotifyWhenDisplayedXTimesNoChecking(TInt aCount, TRequestStatus& aStatus)
  1.2453 +	{
  1.2454 +	TIpcArgs args(aCount);
  1.2455 +	SendReceive(EUpdateServNotifyWhenDisplayedXTimes, args, aStatus);
  1.2456 +	}
  1.2457 +
  1.2458 +/**
  1.2459 +Submit an update to the server without doing any checking of values such as screen number and buffer
  1.2460 +*/
  1.2461 +TInt RMisbehavingSession::SubmitUpdateNoChecking(TInt aScreen, const TSurfaceId& aSurfaceId, 
  1.2462 +									TInt aBuffer, const TRegion* aDirtyRegion)
  1.2463 +	{
  1.2464 +	TPckgC<TSurfaceId> pckgSurfaceId(aSurfaceId);
  1.2465 +	TIpcArgs theArgs(aScreen, &pckgSurfaceId, aBuffer);
  1.2466 +	if(aDirtyRegion)
  1.2467 +		{
  1.2468 +		const TInt regionCount = aDirtyRegion->Count();
  1.2469 +		if(regionCount > 0)
  1.2470 +			{
  1.2471 +			TPtrC8 ptrRect(reinterpret_cast<const TUint8*> (aDirtyRegion->RectangleList()), regionCount * sizeof(TRect));
  1.2472 +			theArgs.Set(3, &ptrRect);
  1.2473 +			}
  1.2474 +		}
  1.2475 +	return SendReceive(EUpdateServSubmitUpdate, theArgs);
  1.2476 +	}
  1.2477 +
  1.2478 +/**
  1.2479 +Pass an invalid opcode to the surface update server
  1.2480 +*/
  1.2481 +void RMisbehavingSession::TestPassingInvalidOpcode(TInt aInvalidOpcode)
  1.2482 +	{
  1.2483 +	SendReceive(aInvalidOpcode);
  1.2484 +	}
  1.2485 +
  1.2486 +/**
  1.2487 +Set the fail rate for OOM checking, server side.
  1.2488 +*/	
  1.2489 +void RMisbehavingSession::SetFailRate(TInt aFailRate)
  1.2490 +	{
  1.2491 +	TIpcArgs args(aFailRate);
  1.2492 +	SendReceive(EUpdateServOOM, args);
  1.2493 +	}
  1.2494 +
  1.2495 +/**
  1.2496 +Implementation of NotifyWhenAvailable. Intended to behave the same as 
  1.2497 +RSurfaceUpdateSession::NotifyWhenAvailable except it assumes that the handle
  1.2498 +to the RClass is never a Null handle.
  1.2499 +*/
  1.2500 +void RMisbehavingSession::NotifyWhenAvailable(TRequestStatus& aStatus)
  1.2501 +	{
  1.2502 +	iStatusAvailable = &aStatus;
  1.2503 +	}
  1.2504 +
  1.2505 +/**
  1.2506 +Implementation of NotifyWhenDisplayed. Intended to behave the same as 
  1.2507 +RSurfaceUpdateSession::NotifyWhenDisplayed except it assumes that the handle
  1.2508 +to the RClass is never a Null handle.
  1.2509 +*/
  1.2510 +void RMisbehavingSession::NotifyWhenDisplayed(TRequestStatus& aStatus, TTimeStamp& aTimeStamp)
  1.2511 +	{
  1.2512 +	iStatusDisplayed = &aStatus;
  1.2513 +	iTimeStamp = &aTimeStamp;
  1.2514 +	}
  1.2515 +
  1.2516 +/**
  1.2517 +Implementation of NotifyWhenDisplayedXTimes. Intended to behave the same as 
  1.2518 +RSurfaceUpdateSession::NotifyWhenDisplayedXTimes except it assumes that the handle
  1.2519 +to the RClass is never a Null handle.
  1.2520 +*/
  1.2521 +void RMisbehavingSession::NotifyWhenDisplayedXTimes(TInt aCount, TRequestStatus& aStatus)
  1.2522 +	{
  1.2523 +	iStatusDisplayedXTimes = &aStatus;
  1.2524 +	iCount = aCount;
  1.2525 +	}
  1.2526 +
  1.2527 +/**
  1.2528 +Implementation of NotifyWhenAvailable. Intended to behave the same as 
  1.2529 +RSurfaceUpdateSession::NotifyWhenAvailable except it assumes that the user
  1.2530 +will not pass invalid parameters to the function.
  1.2531 +*/
  1.2532 +TInt RMisbehavingSession::SubmitUpdate(TInt aScreen, const TSurfaceId& aSurfaceId, 
  1.2533 +											TInt aBuffer, const TRegion* aDirtyRegion/* = NULL*/)
  1.2534 +	{
  1.2535 +	if(iStatusAvailable)
  1.2536 +		{
  1.2537 +		SendReceive(EUpdateServNotifyWhenAvailable, *iStatusAvailable);
  1.2538 +		iStatusAvailable= NULL;
  1.2539 +		}
  1.2540 +	
  1.2541 +	if(iStatusDisplayed)
  1.2542 +		{
  1.2543 +		TIpcArgs args(iTimeStamp);
  1.2544 +		SendReceive(EUpdateServNotifyWhenDisplayed, args, *iStatusDisplayed);
  1.2545 +		iStatusDisplayed=NULL;
  1.2546 +		}
  1.2547 +		
  1.2548 +	if(iStatusDisplayedXTimes)
  1.2549 +		{
  1.2550 +		TIpcArgs args(iCount);
  1.2551 +		SendReceive(EUpdateServNotifyWhenDisplayedXTimes, 
  1.2552 +                     	args, *iStatusDisplayedXTimes);	
  1.2553 +		iStatusDisplayedXTimes=NULL;
  1.2554 +		}
  1.2555 +
  1.2556 +	TPckgC<TSurfaceId> pckgSurfaceId(aSurfaceId);
  1.2557 +	TIpcArgs theArgs(aScreen, &pckgSurfaceId, aBuffer);
  1.2558 +
  1.2559 +	if(aDirtyRegion)
  1.2560 +		{
  1.2561 +		const TInt regionCount = aDirtyRegion->Count();
  1.2562 +		if(regionCount > 0)
  1.2563 +			{
  1.2564 +			TPtrC8 ptrRect(reinterpret_cast<const TUint8*> (aDirtyRegion->RectangleList()), regionCount * sizeof(TRect));
  1.2565 +			theArgs.Set(3, &ptrRect);
  1.2566 +			}
  1.2567 +		}
  1.2568 +
  1.2569 +	//final request for composition 
  1.2570 +	return SendReceive(EUpdateServSubmitUpdate, theArgs);
  1.2571 +	}
  1.2572 +
  1.2573 +/**
  1.2574 +Implementation of NotifyWhenAvailable. Intended to behave the same as 
  1.2575 +RSurfaceUpdateSession::CancelAllUpdateNotifications except it assumes that the handle
  1.2576 +to the RClass is never a Null handle.
  1.2577 +*/
  1.2578 +void RMisbehavingSession::CancelAllUpdateNotifications()
  1.2579 +	{
  1.2580 +	SendReceive(EUpdateServCancelAllNotifications);
  1.2581 +	}
  1.2582 +
  1.2583 +