1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/TMESSAGE.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,471 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +
1.26 +#include "TMESSAGE.H"
1.27 +
1.28 +const TInt KTotalNumberOfTestMessages=5;
1.29 +const TInt KMaxNumOfMessagesInActiveQueue=21;
1.30 +const TInt KMaxNumOfSyncMessages=25;
1.31 +const TInt KNumOfTestCases=7;
1.32 +TInt MsgCountCheck=0;
1.33 +TInt SyncSendReceiveCount=0;
1.34 +TUid UidAtFirstLocation;
1.35 +TUid UidAtLastLocation;
1.36 +TBool TestNeedsExtraCheck=EFalse;
1.37 +
1.38 +CTMessage::CTMessage(CTestStep* aStep) : CTWsGraphicsBase(aStep), iSyncSendReceiveFlag(EFalse), iCounter(-1), iState(0)
1.39 + {
1.40 + }
1.41 +
1.42 +TInt CTMessage::CreateAndSendMessages(TInt aCount,TInt aNoOfMessages)
1.43 + {
1.44 + CMessageReceiver* msgReceiver=(*iMessageReceiver)[iState];
1.45 + TInt identifer=msgReceiver->GroupWin()->Identifier();
1.46 + TInt length=aCount*2;
1.47 + TUint8 modificationFactor=(TUint8 )(aCount*3+1);
1.48 + TUint8 msgValue=0;
1.49 + if(!iSyncSendReceiveFlag && TestNeedsExtraCheck)
1.50 + {
1.51 + if(aCount==0)
1.52 + {
1.53 + UidAtFirstLocation=TUid::Uid(length+(modificationFactor<<24));
1.54 + }
1.55 + else if(aCount==(aNoOfMessages-1))
1.56 + {
1.57 + UidAtLastLocation=TUid::Uid(length+(modificationFactor<<24));
1.58 + }
1.59 + }
1.60 + iMsg->Des().Zero();
1.61 + for(TInt index=0;index<length;index++)
1.62 + {
1.63 + msgValue=(TUint8)(msgValue+modificationFactor);
1.64 + iMsg->Des().Append(msgValue);
1.65 + }
1.66 + return TheClient->iWs.SendMessageToWindowGroup(identifer, TUid::Uid(length+(modificationFactor<<24)), *iMsg);
1.67 + }
1.68 +
1.69 +TInt CTMessage::CallbackLowPriority(TAny* aMessageTest)
1.70 + {
1.71 + return static_cast<CTMessage*>(aMessageTest)->SendSyncMessages();
1.72 + }
1.73 +
1.74 +TInt CTMessage::SendSyncMessages()
1.75 + {
1.76 + if(iSyncSendReceiveFlag && iCounter++<SyncSendReceiveCount)
1.77 + {
1.78 + TEST(CreateAndSendMessages(iCounter,SyncSendReceiveCount)==KErrNone);
1.79 + return ETrue;
1.80 + }
1.81 + TheClient->iWs.NumWindowGroups(); //Make sure all asyncronus calls have been processed
1.82 + CTEventBase& eventHandler=*TheClient->EventHandler();
1.83 + if (eventHandler.iStatus.Int()==KRequestPending)
1.84 + CActiveScheduler::Stop();
1.85 + else
1.86 + return ETrue;
1.87 + return EFalse;
1.88 + }
1.89 +
1.90 +CTMessage::~CTMessage()
1.91 + {
1.92 + iMessageReceiver->ResetAndDestroy();
1.93 + iMessageReceiver->Close();
1.94 + delete iMessageReceiver;
1.95 + iLowPriorityObject->Cancel();
1.96 + delete iLowPriorityObject;
1.97 + iLowPriorityObject=NULL;
1.98 + delete iMsg;
1.99 + }
1.100 +
1.101 +void CTMessage::ConstructL()
1.102 + {
1.103 + iLowPriorityObject= new(ELeave) CLowPriorityIdle();
1.104 + iMessageReceiver=new(ELeave) RPointerArray<CMessageReceiver>(KNumOfTestCases);
1.105 + iMsg=HBufC8::NewL(KMaxNumOfSyncMessages*2);
1.106 + for(TInt index=0;index<KNumOfTestCases;index++)
1.107 + {
1.108 + CMessageReceiver* messageReceiver=new(ELeave) CMessageReceiver(TheClient, this);
1.109 + messageReceiver->ConstructL();
1.110 + iMessageReceiver->AppendL(messageReceiver);
1.111 + }
1.112 + }
1.113 +
1.114 +
1.115 +CLowPriorityIdle::CLowPriorityIdle() : CIdle(EPriorityIdle)
1.116 + {
1.117 + CActiveScheduler::Add(this);
1.118 + }
1.119 +
1.120 +TInt CLowPriorityIdle::RunError(TInt /*aError*/)
1.121 + {
1.122 + CActiveScheduler::Stop();
1.123 + return KErrNone;
1.124 + }
1.125 +
1.126 +LOCAL_C TInt DoPanicTest(TInt aInt, TAny *)
1.127 + {
1.128 + switch(aInt)
1.129 + {
1.130 + case 1:
1.131 + User::Panic(KWSERV,EWservPanicGcActive);
1.132 + break;
1.133 + }
1.134 + return(EWsExitReasonBad);
1.135 + }
1.136 +
1.137 +CMessageReceiver::CMessageReceiver(CTClient *aClient, CTMessage *aTMessage) : CTWindowGroup(aClient), iMsgCount(0)
1.138 + {
1.139 + iTMessage = aTMessage;
1.140 + }
1.141 +
1.142 +#define MESSAGES_READ 1 //Change to 2 to test the 16-bit functions too.
1.143 +void CMessageReceiver::MessageReady(const TWsEvent& aEvent)
1.144 + {
1.145 + iTMessage->OnMessageReceived(aEvent, iMsgCount);
1.146 + }
1.147 +
1.148 +void CTMessage::OnMessageReceived(const TWsEvent& aEvent, TInt& aMsgCount)
1.149 + {
1.150 + aMsgCount++;
1.151 + if(aMsgCount>MsgCountCheck)
1.152 + {
1.153 + return;
1.154 + }
1.155 + if (MESSAGES_READ*(aMsgCount/MESSAGES_READ)<aMsgCount)
1.156 + {
1.157 + return;
1.158 + }
1.159 + TPtr8 msgPtr(NULL,0);
1.160 + //TPtr16 msgPtr2(NULL,0);
1.161 + TUid uid;
1.162 + TInt retValue=TheClient->iWs.FetchMessage(uid, msgPtr, aEvent);
1.163 + TEST(retValue==KErrNone);
1.164 + //GroupWin()->FetchMessage(uid, msgPtr2);
1.165 + if(TestNeedsExtraCheck)
1.166 + {
1.167 + TEST(uid==(aMsgCount==1?UidAtFirstLocation:UidAtLastLocation));
1.168 + }
1.169 + TInt msgLength=(uid.iUid)&0xFFFFFF;
1.170 + TUint8 uidFactor=(TUint8)((uid.iUid&0xFF000000)>>24);
1.171 + TBool retVal = msgPtr.Length()==msgLength;
1.172 + TEST(retVal);
1.173 + if (!retVal)
1.174 + INFO_PRINTF3(_L("msgPtr.Length()==msgLength - Expected: %d, Actual: %d"), msgLength, msgPtr.Length());
1.175 +
1.176 + TUint8 check=0;
1.177 + for(TInt index=0;index<msgLength;index++)
1.178 + {
1.179 + check=(TUint8)(check+uidFactor);
1.180 + retVal = msgPtr[index]==check;
1.181 + TEST(retVal);
1.182 + if (!retVal)
1.183 + INFO_PRINTF3(_L("msgPtr[index]==check - Expected: %d, Actual: %d"), check, msgPtr[index]);
1.184 +
1.185 + }
1.186 + /*CTestBase::Test(msgPtr.Length()/2==msgPtr2.Length());
1.187 + TPtrC8 data2((const TUint8*) msgPtr2.Ptr(),msgPtr2.Size());
1.188 + CTestBase::Test(data2==msgPtr.Left(msgPtr2.Size()));*/
1.189 + User::Free((TAny *)msgPtr.Ptr());
1.190 + //User::Free((TAny *)msgPtr2.Ptr());
1.191 + }
1.192 +
1.193 +void CTMessage::TestPanicsL()
1.194 + {
1.195 + TEST(iTest->TestWsPanicL(&DoPanicTest,EWservPanicGcActive,1));
1.196 + iTest->CloseAllPanicWindows();
1.197 + }
1.198 +
1.199 +void CTMessage::MessageTests(TInt aNoOfMessages,TInt aMsgCountCheck,TBool aSyncSendReceiveFlag,TBool aTestNeedsExtraCheck)
1.200 + {
1.201 + iSyncSendReceiveFlag=aSyncSendReceiveFlag;
1.202 + TestNeedsExtraCheck=aTestNeedsExtraCheck;
1.203 + MsgCountCheck=aMsgCountCheck;
1.204 + iLowPriorityObject->Start(TCallBack(CallbackLowPriority,this));
1.205 +
1.206 + if(iSyncSendReceiveFlag)
1.207 + {
1.208 + //Messages will be sent and received one by one using the function SendSyncMessages().
1.209 + CActiveScheduler::Start();
1.210 + }
1.211 + else
1.212 + {
1.213 + for(TInt count=0;count<aNoOfMessages;count++)
1.214 + {
1.215 + TInt err=CreateAndSendMessages(count,aNoOfMessages);
1.216 + TEST(err==KErrNone);
1.217 + if (err!=KErrNone)
1.218 + {
1.219 + _LIT(KLog,"Error %d when trying to send Messages");
1.220 + LOG_MESSAGE2(KLog,err);
1.221 + }
1.222 + }
1.223 + CActiveScheduler::Start();
1.224 + TInt msgCount=(*iMessageReceiver)[iState]->MessageCount();
1.225 + TEST(msgCount==MsgCountCheck);
1.226 + if (msgCount!=MsgCountCheck)
1.227 + {
1.228 + _LIT(KLog,"Number of messages recieved=%d expected=%d");
1.229 + LOG_MESSAGE3(KLog,msgCount,MsgCountCheck);
1.230 + }
1.231 + }
1.232 + }
1.233 +
1.234 +/**
1.235 + Test delivery group messages in case when event queue is overflow
1.236 + */
1.237 +void CTMessage::TestMessageQueueOverflowL()
1.238 + {
1.239 + const TInt numMaxMessages = 60;
1.240 + TInt numWasteMessages = 0;
1.241 + TInt numWgMessages = 5;
1.242 +
1.243 + TInt gotRealWasteMessages = 0;
1.244 + TInt gotRealWgMessages = 0;
1.245 +
1.246 + const TInt oneSecond = 1000000;
1.247 + const TInt allPossibleMessages = 500;
1.248 +
1.249 + RWsSession senderWsSession;
1.250 + RWindowGroup senderGroupWin;
1.251 + TInt sndrHanGrpWin = 7777;
1.252 +
1.253 + RWsSession receiverWsSession;
1.254 + RWindowGroup receiverGroupWin;
1.255 + TInt rcvrHanGrpWin = 8888;
1.256 +
1.257 + TRequestStatus testStatus;
1.258 + TRequestStatus timerStatus;
1.259 + TWsEvent wasteEvent;
1.260 + TWsEvent event;
1.261 +
1.262 + RTimer timer;
1.263 + timer.CreateLocal();
1.264 + CleanupClosePushL(timer);
1.265 +
1.266 + // Create sender WsSession and the window group
1.267 + User::LeaveIfError(senderWsSession.Connect());
1.268 + CleanupClosePushL(senderWsSession);
1.269 +
1.270 + senderGroupWin = RWindowGroup(senderWsSession);
1.271 + User::LeaveIfError(senderGroupWin.Construct(sndrHanGrpWin));
1.272 + CleanupClosePushL(senderGroupWin);
1.273 +
1.274 + // Create reciever WsSession and the window group
1.275 + User::LeaveIfError(receiverWsSession.Connect());
1.276 + CleanupClosePushL(receiverWsSession);
1.277 +
1.278 + receiverGroupWin = RWindowGroup(receiverWsSession);
1.279 + User::LeaveIfError(receiverGroupWin.Construct(rcvrHanGrpWin));
1.280 + CleanupClosePushL(receiverGroupWin);
1.281 +
1.282 + TInt err = KErrNone;
1.283 +
1.284 + // Send waste events to the receiver and overflow the event queue
1.285 + for (TInt ind = 0; ind < numMaxMessages; ind++)
1.286 + {
1.287 + wasteEvent.SetType(sndrHanGrpWin);
1.288 + err = senderWsSession.SendEventToWindowGroup(receiverGroupWin.Identifier(), wasteEvent);
1.289 + if (err != KErrNone)
1.290 + {
1.291 + numWasteMessages = ind; // Real number waste messages that was sent
1.292 + break;
1.293 + }
1.294 + }
1.295 +
1.296 + // Send messages to the receiver
1.297 + for (TInt ind = 0; ind < numWgMessages; ind++)
1.298 + {
1.299 + TInt uidData = ind + sndrHanGrpWin;
1.300 + TPtr8 msg((unsigned char*) &uidData, sizeof(uidData));
1.301 + err = senderWsSession.SendMessageToWindowGroup(receiverGroupWin.Identifier(), TUid::Uid(uidData), msg);
1.302 + if (err != KErrNone)
1.303 + {
1.304 + LOG_MESSAGE2(_L("UnExpected Error Code = %d"),err);
1.305 + numWgMessages = ind; // Real number window group messages that was sent
1.306 + }
1.307 + }
1.308 +
1.309 + // Check and count sent messages
1.310 + for (TInt ind = 0; ind < allPossibleMessages; ind++)
1.311 + {
1.312 + receiverWsSession.EventReady(&testStatus);
1.313 + timer.After(timerStatus, oneSecond);
1.314 + User::WaitForRequest(testStatus, timerStatus);
1.315 + if (testStatus == 0)
1.316 + {
1.317 + // Test incoming events
1.318 + receiverWsSession.GetEvent(event);
1.319 + if (event.Type() == sndrHanGrpWin)
1.320 + {
1.321 + ++gotRealWasteMessages;
1.322 + }
1.323 + else if (event.Type() == EEventMessageReady)
1.324 + {
1.325 + if (gotRealWgMessages == 0)
1.326 + {
1.327 + for (TInt ind = 0; ind < numMaxMessages; ind++)
1.328 + {
1.329 + wasteEvent.SetType(sndrHanGrpWin);
1.330 + err = senderWsSession.SendEventToWindowGroup(receiverGroupWin.Identifier(), wasteEvent);
1.331 + if (err == KErrNone)
1.332 + {
1.333 + ++numWasteMessages;
1.334 + }
1.335 + else
1.336 + {
1.337 + break;
1.338 + }
1.339 + }
1.340 + }
1.341 + ++gotRealWgMessages;
1.342 + TUid uid;
1.343 + TPtr8 msgPtr(NULL,0);
1.344 + err = receiverWsSession.FetchMessage(uid, msgPtr, event);
1.345 + User::Free((TAny *) msgPtr.Ptr());
1.346 + }
1.347 + // testStatus has been completed. Hence, Cancel the timer.
1.348 + timer.Cancel();
1.349 + User::WaitForRequest(timerStatus);
1.350 + }
1.351 + else
1.352 + {
1.353 + // Times out, cancel the event notification
1.354 + receiverWsSession.EventReadyCancel();
1.355 + User::WaitForRequest(testStatus);
1.356 + // All events were recieved
1.357 + break;
1.358 + }
1.359 + }
1.360 +
1.361 + LOG_MESSAGE3(_L("Got Waste message = %d expected =%d"),gotRealWasteMessages,numWasteMessages);
1.362 + LOG_MESSAGE3(_L("Got Group message = %d expected =%d"),gotRealWgMessages,numWgMessages);
1.363 + TEST(gotRealWasteMessages == numWasteMessages);
1.364 + TEST(gotRealWgMessages == numWgMessages);
1.365 +
1.366 + CleanupStack::PopAndDestroy(&receiverGroupWin);
1.367 + CleanupStack::PopAndDestroy(&receiverWsSession);
1.368 + CleanupStack::PopAndDestroy(&senderGroupWin);
1.369 + CleanupStack::PopAndDestroy(&senderWsSession);
1.370 + CleanupStack::PopAndDestroy(&timer);
1.371 +
1.372 + TheClient->iWs.Flush();
1.373 +
1.374 + }
1.375 +
1.376 +void CTMessage::RunTestCaseL(TInt /*aCurTestCase*/)
1.377 + {
1.378 + _LIT(KMsgTest0,"Message test 1");
1.379 + _LIT(KMsgTest1,"Message test 2");
1.380 + _LIT(KMsgTest2,"Message test 3");
1.381 + _LIT(KMsgTest3,"Message test 4");
1.382 + _LIT(KMsgTest4,"Message test 5");
1.383 + _LIT(KMsgTest5,"Message test 6");
1.384 + _LIT(KMsgTest6,"Message test 7");
1.385 + _LIT(KMsgTest7,"Message test 8 - when event queue is overflow");
1.386 +
1.387 + iState=iTest->iState; // used by iMessageReceiver array
1.388 + ((CTMessageStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.389 + switch(++iTest->iState)
1.390 + {
1.391 +/**
1.392 +@SYMTestCaseID GRAPHICS-WSERV-0084
1.393 +
1.394 +@SYMDEF DEF081259
1.395 +
1.396 +@SYMTestCaseDesc Test message sending and receiving
1.397 +
1.398 +@SYMTestPriority High
1.399 +
1.400 +@SYMTestStatus Implemented
1.401 +
1.402 +@SYMTestActions Generates 5 short messages and sends them to window group, window group receives them
1.403 +
1.404 +@SYMTestExpectedResults Expects that received messages have the same length and the same content as those sent
1.405 +*/
1.406 + case 1:
1.407 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0084"));
1.408 + iTest->LogSubTest(KMsgTest0);
1.409 + MessageTests(KTotalNumberOfTestMessages,KTotalNumberOfTestMessages,EFalse,EFalse);
1.410 + break;
1.411 +/**
1.412 +@SYMTestCaseID GRAPHICS-WSERV-0406
1.413 +
1.414 +@SYMDEF DEF102201,DEF141447
1.415 +
1.416 +@SYMTestCaseDesc Test message sending and receiving
1.417 +
1.418 +@SYMTestPriority High
1.419 +
1.420 +@SYMTestStatus Implemented
1.421 +
1.422 +@SYMTestActions Generates some diffrent size of messages and sends them to window group, window group receives them
1.423 +
1.424 +@SYMTestExpectedResults Expects that received messages have the same length and the same content as those sent
1.425 +*/
1.426 + case 2:
1.427 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.428 + iTest->LogSubTest(KMsgTest1);
1.429 + MessageTests(KMaxNumOfMessagesInActiveQueue-1,KMaxNumOfMessagesInActiveQueue-1,EFalse,EFalse);
1.430 + break;
1.431 + case 3:
1.432 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.433 + iTest->LogSubTest(KMsgTest2);
1.434 + MessageTests(KMaxNumOfMessagesInActiveQueue,2,EFalse,ETrue);
1.435 + break;
1.436 + case 4:
1.437 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.438 + iTest->LogSubTest(KMsgTest3);
1.439 + MessageTests(KMaxNumOfMessagesInActiveQueue+1,2,EFalse,ETrue);
1.440 + break;
1.441 + case 5:
1.442 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.443 + iTest->LogSubTest(KMsgTest4);
1.444 + MessageTests(KMaxNumOfMessagesInActiveQueue+2,2,EFalse,ETrue);
1.445 + break;
1.446 + case 6:
1.447 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.448 + iTest->LogSubTest(KMsgTest5);
1.449 + SyncSendReceiveCount=KMaxNumOfSyncMessages;
1.450 + MessageTests(KMaxNumOfSyncMessages,KMaxNumOfSyncMessages,ETrue,EFalse);
1.451 + break;
1.452 + case 7:
1.453 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.454 + iTest->LogSubTest(KMsgTest6);
1.455 + MessageTests(KMaxNumOfMessagesInActiveQueue+1,2,EFalse,ETrue);
1.456 + ((*iMessageReceiver)[iState])->ResetMessageCount();
1.457 + SyncSendReceiveCount=KTotalNumberOfTestMessages;
1.458 + MessageTests(KTotalNumberOfTestMessages,KTotalNumberOfTestMessages,ETrue,EFalse);
1.459 + break;
1.460 + case 8:
1.461 + ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406"));
1.462 + iTest->LogSubTest(KMsgTest7);
1.463 + TestMessageQueueOverflowL();
1.464 + ((CTMessageStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.465 + ((CTMessageStep*)iStep)->CloseTMSGraphicsStep();
1.466 + TestComplete();
1.467 + return;
1.468 + }
1.469 + ((*iMessageReceiver)[iState])->ResetMessageCount();
1.470 + ((CTMessageStep*)iStep)->RecordTestResultL();
1.471 + }
1.472 +
1.473 +
1.474 +__WS_CONSTRUCT_STEP__(Message)