|
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 |
|
23 #include "TMESSAGE.H" |
|
24 |
|
25 const TInt KTotalNumberOfTestMessages=5; |
|
26 const TInt KMaxNumOfMessagesInActiveQueue=21; |
|
27 const TInt KMaxNumOfSyncMessages=25; |
|
28 const TInt KNumOfTestCases=7; |
|
29 TInt MsgCountCheck=0; |
|
30 TInt SyncSendReceiveCount=0; |
|
31 TUid UidAtFirstLocation; |
|
32 TUid UidAtLastLocation; |
|
33 TBool TestNeedsExtraCheck=EFalse; |
|
34 |
|
35 CTMessage::CTMessage(CTestStep* aStep) : CTWsGraphicsBase(aStep), iSyncSendReceiveFlag(EFalse), iCounter(-1), iState(0) |
|
36 { |
|
37 } |
|
38 |
|
39 TInt CTMessage::CreateAndSendMessages(TInt aCount,TInt aNoOfMessages) |
|
40 { |
|
41 CMessageReceiver* msgReceiver=(*iMessageReceiver)[iState]; |
|
42 TInt identifer=msgReceiver->GroupWin()->Identifier(); |
|
43 TInt length=aCount*2; |
|
44 TUint8 modificationFactor=(TUint8 )(aCount*3+1); |
|
45 TUint8 msgValue=0; |
|
46 if(!iSyncSendReceiveFlag && TestNeedsExtraCheck) |
|
47 { |
|
48 if(aCount==0) |
|
49 { |
|
50 UidAtFirstLocation=TUid::Uid(length+(modificationFactor<<24)); |
|
51 } |
|
52 else if(aCount==(aNoOfMessages-1)) |
|
53 { |
|
54 UidAtLastLocation=TUid::Uid(length+(modificationFactor<<24)); |
|
55 } |
|
56 } |
|
57 iMsg->Des().Zero(); |
|
58 for(TInt index=0;index<length;index++) |
|
59 { |
|
60 msgValue=(TUint8)(msgValue+modificationFactor); |
|
61 iMsg->Des().Append(msgValue); |
|
62 } |
|
63 return TheClient->iWs.SendMessageToWindowGroup(identifer, TUid::Uid(length+(modificationFactor<<24)), *iMsg); |
|
64 } |
|
65 |
|
66 TInt CTMessage::CallbackLowPriority(TAny* aMessageTest) |
|
67 { |
|
68 return static_cast<CTMessage*>(aMessageTest)->SendSyncMessages(); |
|
69 } |
|
70 |
|
71 TInt CTMessage::SendSyncMessages() |
|
72 { |
|
73 if(iSyncSendReceiveFlag && iCounter++<SyncSendReceiveCount) |
|
74 { |
|
75 TEST(CreateAndSendMessages(iCounter,SyncSendReceiveCount)==KErrNone); |
|
76 return ETrue; |
|
77 } |
|
78 TheClient->iWs.NumWindowGroups(); //Make sure all asyncronus calls have been processed |
|
79 CTEventBase& eventHandler=*TheClient->EventHandler(); |
|
80 if (eventHandler.iStatus.Int()==KRequestPending) |
|
81 CActiveScheduler::Stop(); |
|
82 else |
|
83 return ETrue; |
|
84 return EFalse; |
|
85 } |
|
86 |
|
87 CTMessage::~CTMessage() |
|
88 { |
|
89 iMessageReceiver->ResetAndDestroy(); |
|
90 iMessageReceiver->Close(); |
|
91 delete iMessageReceiver; |
|
92 iLowPriorityObject->Cancel(); |
|
93 delete iLowPriorityObject; |
|
94 iLowPriorityObject=NULL; |
|
95 delete iMsg; |
|
96 } |
|
97 |
|
98 void CTMessage::ConstructL() |
|
99 { |
|
100 iLowPriorityObject= new(ELeave) CLowPriorityIdle(); |
|
101 iMessageReceiver=new(ELeave) RPointerArray<CMessageReceiver>(KNumOfTestCases); |
|
102 iMsg=HBufC8::NewL(KMaxNumOfSyncMessages*2); |
|
103 for(TInt index=0;index<KNumOfTestCases;index++) |
|
104 { |
|
105 CMessageReceiver* messageReceiver=new(ELeave) CMessageReceiver(TheClient, this); |
|
106 messageReceiver->ConstructL(); |
|
107 iMessageReceiver->AppendL(messageReceiver); |
|
108 } |
|
109 } |
|
110 |
|
111 |
|
112 CLowPriorityIdle::CLowPriorityIdle() : CIdle(EPriorityIdle) |
|
113 { |
|
114 CActiveScheduler::Add(this); |
|
115 } |
|
116 |
|
117 TInt CLowPriorityIdle::RunError(TInt /*aError*/) |
|
118 { |
|
119 CActiveScheduler::Stop(); |
|
120 return KErrNone; |
|
121 } |
|
122 |
|
123 LOCAL_C TInt DoPanicTest(TInt aInt, TAny *) |
|
124 { |
|
125 switch(aInt) |
|
126 { |
|
127 case 1: |
|
128 User::Panic(KWSERV,EWservPanicGcActive); |
|
129 break; |
|
130 } |
|
131 return(EWsExitReasonBad); |
|
132 } |
|
133 |
|
134 CMessageReceiver::CMessageReceiver(CTClient *aClient, CTMessage *aTMessage) : CTWindowGroup(aClient), iMsgCount(0) |
|
135 { |
|
136 iTMessage = aTMessage; |
|
137 } |
|
138 |
|
139 #define MESSAGES_READ 1 //Change to 2 to test the 16-bit functions too. |
|
140 void CMessageReceiver::MessageReady(const TWsEvent& aEvent) |
|
141 { |
|
142 iTMessage->OnMessageReceived(aEvent, iMsgCount); |
|
143 } |
|
144 |
|
145 void CTMessage::OnMessageReceived(const TWsEvent& aEvent, TInt& aMsgCount) |
|
146 { |
|
147 aMsgCount++; |
|
148 if(aMsgCount>MsgCountCheck) |
|
149 { |
|
150 return; |
|
151 } |
|
152 if (MESSAGES_READ*(aMsgCount/MESSAGES_READ)<aMsgCount) |
|
153 { |
|
154 return; |
|
155 } |
|
156 TPtr8 msgPtr(NULL,0); |
|
157 //TPtr16 msgPtr2(NULL,0); |
|
158 TUid uid; |
|
159 TInt retValue=TheClient->iWs.FetchMessage(uid, msgPtr, aEvent); |
|
160 TEST(retValue==KErrNone); |
|
161 //GroupWin()->FetchMessage(uid, msgPtr2); |
|
162 if(TestNeedsExtraCheck) |
|
163 { |
|
164 TEST(uid==(aMsgCount==1?UidAtFirstLocation:UidAtLastLocation)); |
|
165 } |
|
166 TInt msgLength=(uid.iUid)&0xFFFFFF; |
|
167 TUint8 uidFactor=(TUint8)((uid.iUid&0xFF000000)>>24); |
|
168 TBool retVal = msgPtr.Length()==msgLength; |
|
169 TEST(retVal); |
|
170 if (!retVal) |
|
171 INFO_PRINTF3(_L("msgPtr.Length()==msgLength - Expected: %d, Actual: %d"), msgLength, msgPtr.Length()); |
|
172 |
|
173 TUint8 check=0; |
|
174 for(TInt index=0;index<msgLength;index++) |
|
175 { |
|
176 check=(TUint8)(check+uidFactor); |
|
177 retVal = msgPtr[index]==check; |
|
178 TEST(retVal); |
|
179 if (!retVal) |
|
180 INFO_PRINTF3(_L("msgPtr[index]==check - Expected: %d, Actual: %d"), check, msgPtr[index]); |
|
181 |
|
182 } |
|
183 /*CTestBase::Test(msgPtr.Length()/2==msgPtr2.Length()); |
|
184 TPtrC8 data2((const TUint8*) msgPtr2.Ptr(),msgPtr2.Size()); |
|
185 CTestBase::Test(data2==msgPtr.Left(msgPtr2.Size()));*/ |
|
186 User::Free((TAny *)msgPtr.Ptr()); |
|
187 //User::Free((TAny *)msgPtr2.Ptr()); |
|
188 } |
|
189 |
|
190 void CTMessage::TestPanicsL() |
|
191 { |
|
192 TEST(iTest->TestWsPanicL(&DoPanicTest,EWservPanicGcActive,1)); |
|
193 iTest->CloseAllPanicWindows(); |
|
194 } |
|
195 |
|
196 void CTMessage::MessageTests(TInt aNoOfMessages,TInt aMsgCountCheck,TBool aSyncSendReceiveFlag,TBool aTestNeedsExtraCheck) |
|
197 { |
|
198 iSyncSendReceiveFlag=aSyncSendReceiveFlag; |
|
199 TestNeedsExtraCheck=aTestNeedsExtraCheck; |
|
200 MsgCountCheck=aMsgCountCheck; |
|
201 iLowPriorityObject->Start(TCallBack(CallbackLowPriority,this)); |
|
202 |
|
203 if(iSyncSendReceiveFlag) |
|
204 { |
|
205 //Messages will be sent and received one by one using the function SendSyncMessages(). |
|
206 CActiveScheduler::Start(); |
|
207 } |
|
208 else |
|
209 { |
|
210 for(TInt count=0;count<aNoOfMessages;count++) |
|
211 { |
|
212 TInt err=CreateAndSendMessages(count,aNoOfMessages); |
|
213 TEST(err==KErrNone); |
|
214 if (err!=KErrNone) |
|
215 { |
|
216 _LIT(KLog,"Error %d when trying to send Messages"); |
|
217 LOG_MESSAGE2(KLog,err); |
|
218 } |
|
219 } |
|
220 CActiveScheduler::Start(); |
|
221 TInt msgCount=(*iMessageReceiver)[iState]->MessageCount(); |
|
222 TEST(msgCount==MsgCountCheck); |
|
223 if (msgCount!=MsgCountCheck) |
|
224 { |
|
225 _LIT(KLog,"Number of messages recieved=%d expected=%d"); |
|
226 LOG_MESSAGE3(KLog,msgCount,MsgCountCheck); |
|
227 } |
|
228 } |
|
229 } |
|
230 |
|
231 /** |
|
232 Test delivery group messages in case when event queue is overflow |
|
233 */ |
|
234 void CTMessage::TestMessageQueueOverflowL() |
|
235 { |
|
236 const TInt numMaxMessages = 60; |
|
237 TInt numWasteMessages = 0; |
|
238 TInt numWgMessages = 5; |
|
239 |
|
240 TInt gotRealWasteMessages = 0; |
|
241 TInt gotRealWgMessages = 0; |
|
242 |
|
243 const TInt oneSecond = 1000000; |
|
244 const TInt allPossibleMessages = 500; |
|
245 |
|
246 RWsSession senderWsSession; |
|
247 RWindowGroup senderGroupWin; |
|
248 TInt sndrHanGrpWin = 7777; |
|
249 |
|
250 RWsSession receiverWsSession; |
|
251 RWindowGroup receiverGroupWin; |
|
252 TInt rcvrHanGrpWin = 8888; |
|
253 |
|
254 TRequestStatus testStatus; |
|
255 TRequestStatus timerStatus; |
|
256 TWsEvent wasteEvent; |
|
257 TWsEvent event; |
|
258 |
|
259 RTimer timer; |
|
260 timer.CreateLocal(); |
|
261 CleanupClosePushL(timer); |
|
262 |
|
263 // Create sender WsSession and the window group |
|
264 User::LeaveIfError(senderWsSession.Connect()); |
|
265 CleanupClosePushL(senderWsSession); |
|
266 |
|
267 senderGroupWin = RWindowGroup(senderWsSession); |
|
268 User::LeaveIfError(senderGroupWin.Construct(sndrHanGrpWin)); |
|
269 CleanupClosePushL(senderGroupWin); |
|
270 |
|
271 // Create reciever WsSession and the window group |
|
272 User::LeaveIfError(receiverWsSession.Connect()); |
|
273 CleanupClosePushL(receiverWsSession); |
|
274 |
|
275 receiverGroupWin = RWindowGroup(receiverWsSession); |
|
276 User::LeaveIfError(receiverGroupWin.Construct(rcvrHanGrpWin)); |
|
277 CleanupClosePushL(receiverGroupWin); |
|
278 |
|
279 TInt err = KErrNone; |
|
280 |
|
281 // Send waste events to the receiver and overflow the event queue |
|
282 for (TInt ind = 0; ind < numMaxMessages; ind++) |
|
283 { |
|
284 wasteEvent.SetType(sndrHanGrpWin); |
|
285 err = senderWsSession.SendEventToWindowGroup(receiverGroupWin.Identifier(), wasteEvent); |
|
286 if (err != KErrNone) |
|
287 { |
|
288 numWasteMessages = ind; // Real number waste messages that was sent |
|
289 break; |
|
290 } |
|
291 } |
|
292 |
|
293 // Send messages to the receiver |
|
294 for (TInt ind = 0; ind < numWgMessages; ind++) |
|
295 { |
|
296 TInt uidData = ind + sndrHanGrpWin; |
|
297 TPtr8 msg((unsigned char*) &uidData, sizeof(uidData)); |
|
298 err = senderWsSession.SendMessageToWindowGroup(receiverGroupWin.Identifier(), TUid::Uid(uidData), msg); |
|
299 if (err != KErrNone) |
|
300 { |
|
301 LOG_MESSAGE2(_L("UnExpected Error Code = %d"),err); |
|
302 numWgMessages = ind; // Real number window group messages that was sent |
|
303 } |
|
304 } |
|
305 |
|
306 // Check and count sent messages |
|
307 for (TInt ind = 0; ind < allPossibleMessages; ind++) |
|
308 { |
|
309 receiverWsSession.EventReady(&testStatus); |
|
310 timer.After(timerStatus, oneSecond); |
|
311 User::WaitForRequest(testStatus, timerStatus); |
|
312 if (testStatus == 0) |
|
313 { |
|
314 // Test incoming events |
|
315 receiverWsSession.GetEvent(event); |
|
316 if (event.Type() == sndrHanGrpWin) |
|
317 { |
|
318 ++gotRealWasteMessages; |
|
319 } |
|
320 else if (event.Type() == EEventMessageReady) |
|
321 { |
|
322 if (gotRealWgMessages == 0) |
|
323 { |
|
324 for (TInt ind = 0; ind < numMaxMessages; ind++) |
|
325 { |
|
326 wasteEvent.SetType(sndrHanGrpWin); |
|
327 err = senderWsSession.SendEventToWindowGroup(receiverGroupWin.Identifier(), wasteEvent); |
|
328 if (err == KErrNone) |
|
329 { |
|
330 ++numWasteMessages; |
|
331 } |
|
332 else |
|
333 { |
|
334 break; |
|
335 } |
|
336 } |
|
337 } |
|
338 ++gotRealWgMessages; |
|
339 TUid uid; |
|
340 TPtr8 msgPtr(NULL,0); |
|
341 err = receiverWsSession.FetchMessage(uid, msgPtr, event); |
|
342 User::Free((TAny *) msgPtr.Ptr()); |
|
343 } |
|
344 // testStatus has been completed. Hence, Cancel the timer. |
|
345 timer.Cancel(); |
|
346 User::WaitForRequest(timerStatus); |
|
347 } |
|
348 else |
|
349 { |
|
350 // Times out, cancel the event notification |
|
351 receiverWsSession.EventReadyCancel(); |
|
352 User::WaitForRequest(testStatus); |
|
353 // All events were recieved |
|
354 break; |
|
355 } |
|
356 } |
|
357 |
|
358 LOG_MESSAGE3(_L("Got Waste message = %d expected =%d"),gotRealWasteMessages,numWasteMessages); |
|
359 LOG_MESSAGE3(_L("Got Group message = %d expected =%d"),gotRealWgMessages,numWgMessages); |
|
360 TEST(gotRealWasteMessages == numWasteMessages); |
|
361 TEST(gotRealWgMessages == numWgMessages); |
|
362 |
|
363 CleanupStack::PopAndDestroy(&receiverGroupWin); |
|
364 CleanupStack::PopAndDestroy(&receiverWsSession); |
|
365 CleanupStack::PopAndDestroy(&senderGroupWin); |
|
366 CleanupStack::PopAndDestroy(&senderWsSession); |
|
367 CleanupStack::PopAndDestroy(&timer); |
|
368 |
|
369 TheClient->iWs.Flush(); |
|
370 |
|
371 } |
|
372 |
|
373 void CTMessage::RunTestCaseL(TInt /*aCurTestCase*/) |
|
374 { |
|
375 _LIT(KMsgTest0,"Message test 1"); |
|
376 _LIT(KMsgTest1,"Message test 2"); |
|
377 _LIT(KMsgTest2,"Message test 3"); |
|
378 _LIT(KMsgTest3,"Message test 4"); |
|
379 _LIT(KMsgTest4,"Message test 5"); |
|
380 _LIT(KMsgTest5,"Message test 6"); |
|
381 _LIT(KMsgTest6,"Message test 7"); |
|
382 _LIT(KMsgTest7,"Message test 8 - when event queue is overflow"); |
|
383 |
|
384 iState=iTest->iState; // used by iMessageReceiver array |
|
385 ((CTMessageStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
386 switch(++iTest->iState) |
|
387 { |
|
388 /** |
|
389 @SYMTestCaseID GRAPHICS-WSERV-0084 |
|
390 |
|
391 @SYMDEF DEF081259 |
|
392 |
|
393 @SYMTestCaseDesc Test message sending and receiving |
|
394 |
|
395 @SYMTestPriority High |
|
396 |
|
397 @SYMTestStatus Implemented |
|
398 |
|
399 @SYMTestActions Generates 5 short messages and sends them to window group, window group receives them |
|
400 |
|
401 @SYMTestExpectedResults Expects that received messages have the same length and the same content as those sent |
|
402 */ |
|
403 case 1: |
|
404 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0084")); |
|
405 iTest->LogSubTest(KMsgTest0); |
|
406 MessageTests(KTotalNumberOfTestMessages,KTotalNumberOfTestMessages,EFalse,EFalse); |
|
407 break; |
|
408 /** |
|
409 @SYMTestCaseID GRAPHICS-WSERV-0406 |
|
410 |
|
411 @SYMDEF DEF102201,DEF141447 |
|
412 |
|
413 @SYMTestCaseDesc Test message sending and receiving |
|
414 |
|
415 @SYMTestPriority High |
|
416 |
|
417 @SYMTestStatus Implemented |
|
418 |
|
419 @SYMTestActions Generates some diffrent size of messages and sends them to window group, window group receives them |
|
420 |
|
421 @SYMTestExpectedResults Expects that received messages have the same length and the same content as those sent |
|
422 */ |
|
423 case 2: |
|
424 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
425 iTest->LogSubTest(KMsgTest1); |
|
426 MessageTests(KMaxNumOfMessagesInActiveQueue-1,KMaxNumOfMessagesInActiveQueue-1,EFalse,EFalse); |
|
427 break; |
|
428 case 3: |
|
429 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
430 iTest->LogSubTest(KMsgTest2); |
|
431 MessageTests(KMaxNumOfMessagesInActiveQueue,2,EFalse,ETrue); |
|
432 break; |
|
433 case 4: |
|
434 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
435 iTest->LogSubTest(KMsgTest3); |
|
436 MessageTests(KMaxNumOfMessagesInActiveQueue+1,2,EFalse,ETrue); |
|
437 break; |
|
438 case 5: |
|
439 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
440 iTest->LogSubTest(KMsgTest4); |
|
441 MessageTests(KMaxNumOfMessagesInActiveQueue+2,2,EFalse,ETrue); |
|
442 break; |
|
443 case 6: |
|
444 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
445 iTest->LogSubTest(KMsgTest5); |
|
446 SyncSendReceiveCount=KMaxNumOfSyncMessages; |
|
447 MessageTests(KMaxNumOfSyncMessages,KMaxNumOfSyncMessages,ETrue,EFalse); |
|
448 break; |
|
449 case 7: |
|
450 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
451 iTest->LogSubTest(KMsgTest6); |
|
452 MessageTests(KMaxNumOfMessagesInActiveQueue+1,2,EFalse,ETrue); |
|
453 ((*iMessageReceiver)[iState])->ResetMessageCount(); |
|
454 SyncSendReceiveCount=KTotalNumberOfTestMessages; |
|
455 MessageTests(KTotalNumberOfTestMessages,KTotalNumberOfTestMessages,ETrue,EFalse); |
|
456 break; |
|
457 case 8: |
|
458 ((CTMessageStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0406")); |
|
459 iTest->LogSubTest(KMsgTest7); |
|
460 TestMessageQueueOverflowL(); |
|
461 ((CTMessageStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
462 ((CTMessageStep*)iStep)->CloseTMSGraphicsStep(); |
|
463 TestComplete(); |
|
464 return; |
|
465 } |
|
466 ((*iMessageReceiver)[iState])->ResetMessageCount(); |
|
467 ((CTMessageStep*)iStep)->RecordTestResultL(); |
|
468 } |
|
469 |
|
470 |
|
471 __WS_CONSTRUCT_STEP__(Message) |