|
1 // Copyright (c) 1999-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 #include "T_smcmsimtsytest.h" |
|
17 #include <e32test.h> |
|
18 #include <e32uid.h> |
|
19 #include <e32std.h> |
|
20 #include <smuthdr.h> |
|
21 #include <txtrich.h> |
|
22 #include <smscmds.h> |
|
23 #include <smsclnt.h> |
|
24 #include <smsuaddr.h> |
|
25 |
|
26 // Autotest library header file |
|
27 #include "autotest.h" |
|
28 |
|
29 #include <testconfigfileparser.h> |
|
30 #include <simtsy.h> |
|
31 #include <csmsaccount.h> |
|
32 |
|
33 #include <e32property.h> |
|
34 |
|
35 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
36 #include <tmsvsmsentry.h> |
|
37 #endif |
|
38 |
|
39 // Global pointer for use by the autogTest.h macro's |
|
40 CAutoTest* gAutoTest; |
|
41 |
|
42 |
|
43 RTest gTest(_L("T_SmcmSimTsyTest Testrig")); |
|
44 TBool HasCreatedSmsService = EFalse; |
|
45 CTrapCleanup* theCleanup; |
|
46 |
|
47 #define LOCAL_CHECKPOINT_CODE(a,b) a.TestCheckPointCodeL((b), (__FILE__), (__LINE__)) |
|
48 #define LOCAL_CHECKPOINT(a,b) a.TestCheckPointL((b), (__FILE__), (__LINE__)) |
|
49 #define LOCAL_CHECKPOINT_COMPARE(a,b,c,d) a.TestCheckPointCompareL((b),(c),(d),(__FILE__),(__LINE__)) |
|
50 |
|
51 //SMS Scripting |
|
52 _LIT(KSmsScript,"smcmsimtsytest_config.txt"); |
|
53 _LIT(KSmsScriptFull,"\\msgtest\\sms\\smcmsimtsytest_config.txt"); |
|
54 |
|
55 void DeleteSmsStores(RFs& aFs) |
|
56 { |
|
57 _LIT(KReassemblyStoreName,"C:\\System\\Data\\smsreast.dat"); |
|
58 _LIT(KSegmentationStoreName,"C:\\System\\Data\\smssegst.dat"); |
|
59 aFs.Delete(KReassemblyStoreName); |
|
60 aFs.Delete(KSegmentationStoreName); |
|
61 } |
|
62 |
|
63 |
|
64 CMessageSendStates::CMessageSendStates(TMsvId aId) |
|
65 { |
|
66 iId = aId; |
|
67 } |
|
68 |
|
69 CMessageSendStates* CMessageSendStates::NewLC(TMsvId aId) |
|
70 { |
|
71 CMessageSendStates* self=new (ELeave) CMessageSendStates(aId); |
|
72 CleanupStack::PushL(self); |
|
73 //self->ConstructL(); |
|
74 return self; |
|
75 } |
|
76 |
|
77 CMessageSendStates* CMessageSendStates::NewL(TMsvId aId) |
|
78 { |
|
79 CMessageSendStates* self = NewLC(aId); |
|
80 CleanupStack::Pop(self); |
|
81 return self; |
|
82 } |
|
83 |
|
84 void CMessageSendStates::ConstructL() |
|
85 { |
|
86 } |
|
87 |
|
88 CMessageSendStates::~CMessageSendStates() |
|
89 { |
|
90 iStates.Close(); |
|
91 } |
|
92 |
|
93 RMessageSendStatesArray::RMessageSendStatesArray() |
|
94 { |
|
95 } |
|
96 |
|
97 TInt RMessageSendStatesArray::Find(TMsvId aId) const |
|
98 { |
|
99 const RMessageSendStatesArray& sendArray = *this; |
|
100 TInt count = sendArray.Count(); |
|
101 |
|
102 for (TInt i=0; i<count; ++i) |
|
103 { |
|
104 if (sendArray[i]->iId == aId) |
|
105 return i; |
|
106 } |
|
107 |
|
108 return -1; |
|
109 } |
|
110 |
|
111 void RMessageSendStatesArray::CopyInSelectionL(const CMsvEntrySelection& aSelection) |
|
112 { |
|
113 ResetAndDestroy(); |
|
114 TInt count = aSelection.Count(); |
|
115 |
|
116 while (count--) |
|
117 { |
|
118 const TMsvId id = aSelection[count]; |
|
119 CMessageSendStates* msg = CMessageSendStates::NewLC(id); |
|
120 User::LeaveIfError(Append(msg)); |
|
121 CleanupStack::Pop(msg); |
|
122 } |
|
123 } |
|
124 |
|
125 CSmcmSendTest* NewSmcmTestLCC(TInt aTestNumber, TInt aExpectedError=KErrNone) |
|
126 /** |
|
127 Constructs and returns CSmsScTest object. |
|
128 Notifies the system agent that the phone is on. |
|
129 |
|
130 @return CSmsScTest* A pointer to SmsSc test. |
|
131 */ |
|
132 { |
|
133 CSmsTestUtils* testUtils = CSmsTestUtils::NewL(gTest, HasCreatedSmsService?ETuCreateTestDirectories|ETuGoClientSide:ETuMinimalClientSide); |
|
134 if (HasCreatedSmsService) |
|
135 testUtils->iServiceSettings = CSmsSettings::NewL(); |
|
136 HasCreatedSmsService = ETrue; |
|
137 CleanupStack::PushL(testUtils); |
|
138 |
|
139 // System agent fix... this ensures that the correct test script is used by SIM.TSY |
|
140 User::LeaveIfError(RProperty::Set(KUidSystemCategory, KUidSASimTsyTestNumberValue, aTestNumber)); |
|
141 // testUtils->SetSimTsyTestNumberL(aTestNumber); |
|
142 testUtils->NotifySaPhoneOffL(); |
|
143 User::After(5000000); //wait for SmsProt to go to sleep |
|
144 DeleteSmsStores(testUtils->FileSession()); |
|
145 |
|
146 TInt nextTest = 0; |
|
147 |
|
148 testUtils->NotifySaPhoneOnL(); |
|
149 testUtils->WaitForInitializeL(); |
|
150 |
|
151 return CSmcmSendTest::NewLC(*gAutoTest, *testUtils, KSmsScript, aExpectedError, nextTest); |
|
152 } |
|
153 |
|
154 TBool CSmcmSendTest::CheckWatchersStartedL() |
|
155 { |
|
156 TBool found = EFalse; |
|
157 TFullName fullName; |
|
158 TFindThread finder(_L("*")); |
|
159 // |
|
160 while(finder.Next(fullName) == KErrNone && !found) |
|
161 { |
|
162 // Open the thread |
|
163 RThread thread; |
|
164 User::LeaveIfError(thread.Open(fullName)); |
|
165 |
|
166 // Open the process which owns this thread |
|
167 RProcess process; |
|
168 const TInt error = thread.Process(process); |
|
169 if (error == KErrNone) |
|
170 { |
|
171 const TFileName fileName(process.FileName()); |
|
172 if (fileName.Compare(_L("Z:\\System\\Libs\\watcher.exe")) == 0) |
|
173 found = ETrue; |
|
174 process.Close(); |
|
175 } |
|
176 thread.Close(); |
|
177 } |
|
178 |
|
179 return found; |
|
180 } |
|
181 |
|
182 void CSmcmSendTest::TestReceiveClass2L(TInt aTestNumber, TRequestStatus& aStatus) |
|
183 { |
|
184 iState = EStateTestReceiveClass2; |
|
185 iMessagesReceived = 0; |
|
186 SetMessagesToReceiveL(aTestNumber); |
|
187 |
|
188 //Set the class 2 folder |
|
189 iSmsSettings->SetClass2Folder(KMsvGlobalOutBoxIndexEntryId); |
|
190 iSmsTest.SetEntryL(iSmsTest.iSmsServiceId); |
|
191 CSmsAccount* account = CSmsAccount::NewLC(); |
|
192 account->SaveSettingsL(*iSmsSettings); |
|
193 CleanupStack::PopAndDestroy(account); |
|
194 |
|
195 iSmsTest.Printf(_L("Waiting to recv %d msgs [test=%d inbox=%d class2=%d]\n"), |
|
196 iMessagesToReceive, aTestNumber, KMsvGlobalInBoxIndexEntryId, iSmsSettings->Class2Folder()), |
|
197 |
|
198 delete iWatcherStarter; |
|
199 iWatcherStarter = NULL; |
|
200 |
|
201 TBool watcherRunning = EFalse; |
|
202 TRAPD(ignor, watcherRunning = CheckWatchersStartedL()); |
|
203 if (watcherRunning) |
|
204 { |
|
205 iSmsTest.Printf(_L("Watchers running.\n")); |
|
206 } |
|
207 else |
|
208 { |
|
209 iSmsTest.Printf(_L("Watchers not running. Starting watchers....\n")); |
|
210 iWatcherStarter = CTestUtilsWatcherStarter::NewL(CActive::EPriorityHigh); |
|
211 } |
|
212 |
|
213 iStatus = KRequestPending; |
|
214 Queue(aStatus); |
|
215 SetActive(); |
|
216 } |
|
217 |
|
218 void CSmcmSendTest::TestSendingL(TRequestStatus& aStatus) |
|
219 { |
|
220 iState = EStateSending; |
|
221 |
|
222 TTime now; |
|
223 now.HomeTime(); |
|
224 now += (TTimeIntervalSeconds) 5; |
|
225 |
|
226 iSmsTest.DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId); |
|
227 iSelection->Reset(); |
|
228 |
|
229 // Create the test messages specified in the script file and place in the Outbox. |
|
230 iSmsTest.Printf(_L("Creating msgs in outbox from script %S\n"), &iScriptFile); |
|
231 TBool read = EFalse; |
|
232 TRAPD(err, read = iSmsTest.ReadScriptL(iScriptFile, KMsvGlobalOutBoxIndexEntryId, *iSelection, now)); |
|
233 |
|
234 //iSmsTest.Test()(!err && read); |
|
235 LOCAL_CHECKPOINT(iAutoTest, !err && read); |
|
236 |
|
237 iSmsTest.Printf(_L("Sending %d messages...\n"), iSelection->Count()); |
|
238 iSmsTest.DisplayMessagesL(*iSelection); |
|
239 iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
240 |
|
241 delete iOperation; |
|
242 iOperation = NULL; |
|
243 |
|
244 // Send the message, by copying it to the SMS Service. |
|
245 iCurrentMessages.ResetAndDestroy(); |
|
246 iCurrentMessages.CopyInSelectionL(*iSelection); |
|
247 |
|
248 iOperation = MsvEntry().CopyL(*iSelection, iSmsTest.iSmsServiceId, iStatus); |
|
249 |
|
250 SetActive(); |
|
251 Queue(aStatus); |
|
252 } |
|
253 |
|
254 void CSmcmSendTest::TestSchedulingL(TRequestStatus& aStatus) |
|
255 { |
|
256 iState = EStateScheduling; |
|
257 |
|
258 iSmsTest.DeleteSmsMessagesL(KMsvGlobalOutBoxIndexEntryId); |
|
259 iSelection->Reset(); |
|
260 |
|
261 TTimeIntervalSeconds fromNow = 5; |
|
262 TTime now; |
|
263 now.HomeTime(); |
|
264 now += fromNow; |
|
265 |
|
266 iSmsTest.Printf(_L("Creating msgs in outbox from script %S\n"), &iScriptFile); |
|
267 TBool read = EFalse; |
|
268 TRAPD(err, read = iSmsTest.ReadScriptL(iScriptFile, KMsvGlobalOutBoxIndexEntryId, *iSelection, now)); |
|
269 |
|
270 //iSmsTest.Test()(!err && read); |
|
271 LOCAL_CHECKPOINT(iAutoTest, !err && read); |
|
272 |
|
273 iSmsTest.Printf(_L("Scheduled %d messages...\n"), iSelection->Count()); |
|
274 iSmsTest.DisplayMessagesL(*iSelection); |
|
275 MsvEntry().SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
276 |
|
277 delete iOperation; |
|
278 iOperation = NULL; |
|
279 |
|
280 iCurrentMessages.ResetAndDestroy(); |
|
281 iCurrentMessages.CopyInSelectionL(*iSelection); |
|
282 |
|
283 iOperation = Session().TransferCommandL(*iSelection, ESmsMtmCommandScheduleCopy, TPtrC8(), iStatus); |
|
284 |
|
285 SetActive(); |
|
286 Queue(aStatus); |
|
287 } |
|
288 |
|
289 void Test1L() |
|
290 { |
|
291 CSmcmSendTest* smcmTest = NewSmcmTestLCC(0, KErrServerTerminated); |
|
292 |
|
293 CMsvOperationWait* waiter = CMsvOperationWait::NewLC(); |
|
294 smcmTest->TestSendingL(waiter->iStatus); |
|
295 waiter->Start(); |
|
296 CActiveScheduler::Start(); |
|
297 GLOBAL_CHECKPOINT_COMPARE(waiter->iStatus.Int(), KErrNone, _L("TestSendingL completed with error")); |
|
298 |
|
299 //CleanupStack::PopAndDestroy(waiter); |
|
300 //CleanupStack::PopAndDestroy(smcmTest); |
|
301 //CleanupStack::PopAndDestroy(); |
|
302 CleanupStack::PopAndDestroy(3); |
|
303 } |
|
304 |
|
305 void Test2L() |
|
306 { |
|
307 CSmcmSendTest* smcmTest = NewSmcmTestLCC(0, KErrServerTerminated); |
|
308 |
|
309 CMsvOperationWait* waiter = CMsvOperationWait::NewLC(); |
|
310 smcmTest->TestSchedulingL(waiter->iStatus); |
|
311 waiter->Start(); |
|
312 CActiveScheduler::Start(); |
|
313 GLOBAL_CHECKPOINT_COMPARE(waiter->iStatus.Int(), KErrNone, _L("TestSchedulingL completed with error")); |
|
314 |
|
315 CleanupStack::PopAndDestroy(waiter); |
|
316 CleanupStack::PopAndDestroy(smcmTest); |
|
317 CleanupStack::PopAndDestroy(); |
|
318 } |
|
319 |
|
320 void Test3L() |
|
321 { |
|
322 CSmcmSendTest* smcmTest = NewSmcmTestLCC(2); |
|
323 |
|
324 CMsvOperationWait* waiter = CMsvOperationWait::NewLC(); |
|
325 smcmTest->TestReceiveClass2L(2, waiter->iStatus); |
|
326 waiter->Start(); |
|
327 CActiveScheduler::Start(); |
|
328 GLOBAL_CHECKPOINT_COMPARE(waiter->iStatus.Int(), KErrNone, _L("TestReceiveClass2L completed with error")); |
|
329 |
|
330 CleanupStack::PopAndDestroy(waiter); |
|
331 CleanupStack::PopAndDestroy(smcmTest); |
|
332 CleanupStack::PopAndDestroy(); |
|
333 } |
|
334 |
|
335 |
|
336 void Test4L() |
|
337 { |
|
338 CMsvOperationWait* waiter = CMsvOperationWait::NewLC(); |
|
339 waiter->Start(); |
|
340 |
|
341 CTestUtilsWatcherStarter* watcherStarter = CTestUtilsWatcherStarter::NewL(waiter->iStatus, 20000000); |
|
342 CleanupStack::PushL(watcherStarter); |
|
343 |
|
344 CActiveScheduler::Start(); |
|
345 GLOBAL_CHECKPOINT_COMPARE(waiter->iStatus.Int(), KErrNone, _L("TestReceiveClass2L completed with error")); |
|
346 |
|
347 CleanupStack::PopAndDestroy(watcherStarter); |
|
348 CleanupStack::PopAndDestroy(waiter); |
|
349 } |
|
350 |
|
351 |
|
352 CSmcmSendTest::~CSmcmSendTest() |
|
353 { |
|
354 Cancel(); |
|
355 |
|
356 if (iSmsTest.iMsvSession) |
|
357 { |
|
358 iSmsTest.iMsvSession->RemoveObserver(*this); |
|
359 } |
|
360 |
|
361 if (iOperation) |
|
362 { |
|
363 iOperation->Cancel(); |
|
364 delete iOperation; |
|
365 iOperation = NULL; |
|
366 } |
|
367 |
|
368 delete iSelection; |
|
369 iSelection = NULL; |
|
370 |
|
371 if (iTimer) |
|
372 { |
|
373 iTimer->Cancel(); |
|
374 delete iTimer; |
|
375 iTimer = NULL; |
|
376 } |
|
377 |
|
378 iCurrentMessages.ResetAndDestroy(); |
|
379 delete iSmsSettings; |
|
380 delete iWatcherStarter; |
|
381 } |
|
382 |
|
383 CSmcmSendTest::CSmcmSendTest(CAutoTest& aAutoTest, CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt aExpectedError, TInt aPriority) |
|
384 : CActive(aPriority), iState(EStateWaiting), iAutoTest(aAutoTest), iScriptFile(aScriptFile), iSmsTest(aSmsTest), iExpectedError(aExpectedError) |
|
385 { |
|
386 CActiveScheduler::Add(this); |
|
387 } |
|
388 |
|
389 CSmcmSendTest* CSmcmSendTest::NewLC(CAutoTest& aAutoTest, CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt aExpectedError, TInt aPriority) |
|
390 { |
|
391 CSmcmSendTest* self = new (ELeave) CSmcmSendTest(aAutoTest, aSmsTest, aScriptFile, aExpectedError, aPriority); |
|
392 CleanupStack::PushL(self); |
|
393 |
|
394 self->ConstructL(); |
|
395 |
|
396 return self; |
|
397 } |
|
398 |
|
399 void CSmcmSendTest::ConstructL() |
|
400 { |
|
401 iSmsTest.SetLogToFile(); |
|
402 |
|
403 iSelection = new (ELeave) CMsvEntrySelection(); |
|
404 |
|
405 iSmsTest.iMsvSession->AddObserverL(*this); |
|
406 iSmsTest.InstantiateClientMtmsL(); |
|
407 |
|
408 iSmsTest.SetEntryL(iSmsTest.iSmsServiceId); |
|
409 iSmsSettings = CSmsSettings::NewL(); |
|
410 |
|
411 CSmsAccount* account = CSmsAccount::NewLC(); |
|
412 account->LoadSettingsL(*iSmsSettings); |
|
413 CleanupStack::PopAndDestroy(account); |
|
414 } |
|
415 |
|
416 void CSmcmSendTest::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
417 { |
|
418 CMsvEntrySelection* entries = NULL; |
|
419 |
|
420 switch (aEvent) |
|
421 { |
|
422 // case EMsvEntriesCreated: |
|
423 case EMsvEntriesChanged: |
|
424 case EMsvEntriesMoved: |
|
425 entries = STATIC_CAST(CMsvEntrySelection*, aArg1); |
|
426 break; |
|
427 default: |
|
428 return; |
|
429 } |
|
430 |
|
431 if (!IsActive()) |
|
432 return; |
|
433 |
|
434 TRequestStatus* status = &iStatus; |
|
435 |
|
436 switch (iState) |
|
437 { |
|
438 case EStateSchedulingThenSend: |
|
439 case EStateSending: |
|
440 { |
|
441 if (aEvent == EMsvEntriesCreated) |
|
442 return; |
|
443 |
|
444 TInt error = KErrNone; |
|
445 |
|
446 iSmsTest.DisplaySendingStatesL(*entries); |
|
447 |
|
448 TInt count = entries->Count(); |
|
449 |
|
450 while (count--) |
|
451 { |
|
452 const TMsvId id = (*entries)[count]; |
|
453 const TInt find = iCurrentMessages.Find(id); |
|
454 |
|
455 if (find != KErrNotFound) |
|
456 { |
|
457 CMessageSendStates& messageSendStates = *iCurrentMessages[find]; |
|
458 CMsvEntry* cEntry = Session().GetEntryL(id); |
|
459 CleanupStack::PushL(cEntry); |
|
460 const TMsvEntry& entry = cEntry->Entry(); |
|
461 User::LeaveIfError(messageSendStates.iStates.Append(entry.SendingState())); |
|
462 CleanupStack::PopAndDestroy(cEntry); |
|
463 } |
|
464 } |
|
465 |
|
466 if (iSmsTest.SendingCompleteL(*iSelection, error) && iState == EStateSchedulingThenSend && iStatus == KRequestPending) |
|
467 { |
|
468 User::RequestComplete(status, error); |
|
469 } |
|
470 break; |
|
471 } |
|
472 case EStateTestReceiveClass2: |
|
473 |
|
474 if (aEvent != EMsvEntriesChanged) |
|
475 return; |
|
476 |
|
477 if (!CheckParentOfReceivedMessageL(*entries)) |
|
478 { |
|
479 iSmsTest.Printf(_L("Parent of messages don't match\n")); |
|
480 User::RequestComplete(status, KErrGeneral); |
|
481 } |
|
482 else if (iMessagesReceived >= iMessagesToReceive) |
|
483 { |
|
484 iSmsTest.Printf(_L("All messages received\n")); |
|
485 User::RequestComplete(status, KErrNone); |
|
486 } |
|
487 |
|
488 default: |
|
489 break; |
|
490 } |
|
491 } |
|
492 |
|
493 LOCAL_C const TAutoTestCase SmsScTestCases[] = |
|
494 /** |
|
495 Sets up an array of test functions |
|
496 */ |
|
497 { |
|
498 {Test1L,_S("Test Sending")}, |
|
499 {Test2L,_S("Test Schedule Sending")}, |
|
500 {Test3L,_S("Test Receiving Class2 Messages")}, |
|
501 {Test4L,_S("Test Start Stop Watchers")} |
|
502 }; |
|
503 |
|
504 LOCAL_C void doMainL() |
|
505 /** |
|
506 Constructs sctive scheduler and starts off the tests |
|
507 */ |
|
508 { |
|
509 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
510 CleanupStack::PushL(scheduler); |
|
511 CActiveScheduler::Install( scheduler ); |
|
512 |
|
513 // Copying the config file to the root directory |
|
514 RFs fs; |
|
515 User::LeaveIfError(fs.Connect()); |
|
516 CleanupClosePushL(fs); |
|
517 |
|
518 CSmsTestUtils::CopyToSimTsyConfigFileL(fs, KSmsScriptFull); |
|
519 DeleteSmsStores(fs); |
|
520 |
|
521 CleanupStack::PopAndDestroy(&fs); |
|
522 |
|
523 // Open the socket server |
|
524 |
|
525 RSocketServ serv; |
|
526 RSocket socket; |
|
527 |
|
528 User::LeaveIfError(serv.Connect()); |
|
529 CleanupClosePushL(serv); |
|
530 |
|
531 TProtocolDesc protoinfo; |
|
532 TProtocolName protocolname(KSmsDatagram); |
|
533 User::LeaveIfError(serv.FindProtocol(protocolname,protoinfo)); |
|
534 User::LeaveIfError(socket.Open(serv,protoinfo.iAddrFamily,protoinfo.iSockType,protoinfo.iProtocol)); |
|
535 |
|
536 TSmsAddr smsaddr; |
|
537 smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly); |
|
538 User::LeaveIfError(socket.Bind(smsaddr)); |
|
539 |
|
540 CleanupClosePushL(socket); |
|
541 |
|
542 _LIT(KTestOutput,"smcmsimtsy_testreport.txt"); |
|
543 _LIT8(KComponentInfo,"smcm and smss"); |
|
544 // Library defined macro |
|
545 // Uses a global pointer instance of CAutoTest |
|
546 GLOBAL_AUTOTEST_EXECUTE(SmsScTestCases, KTestOutput, KComponentInfo, gTest); |
|
547 |
|
548 CleanupStack::PopAndDestroy(&socket); |
|
549 CleanupStack::PopAndDestroy(&serv); |
|
550 CleanupStack::PopAndDestroy(scheduler); |
|
551 } |
|
552 |
|
553 GLDEF_C TInt E32Main() |
|
554 /** |
|
555 Calls doMainL and checks for error |
|
556 */ |
|
557 { |
|
558 __UHEAP_MARK; |
|
559 |
|
560 gTest.Start(_L("Setup")); |
|
561 theCleanup = CTrapCleanup::New(); |
|
562 |
|
563 |
|
564 TRAPD(ret,doMainL()); |
|
565 |
|
566 if (ret != KErrNone) |
|
567 gTest.Printf(_L("Test completed with %d"), ret); |
|
568 |
|
569 delete theCleanup; |
|
570 gTest.Console()->SetPos(0, 13); |
|
571 gTest.End(); |
|
572 gTest.Close(); |
|
573 __UHEAP_MARKEND; |
|
574 return(KErrNone); |
|
575 } |
|
576 |
|
577 void CSmcmSendTest::RunL() |
|
578 { |
|
579 if (iOperation) |
|
580 iSmsTest.SetProgressL(*iOperation); |
|
581 |
|
582 switch (iState) |
|
583 { |
|
584 case EStateScheduling: |
|
585 DoRunSchedulingL(); |
|
586 break; |
|
587 case EStateSending: |
|
588 case EStateSchedulingThenSend: |
|
589 DoRunSendingL(); |
|
590 break; |
|
591 case EStateTestReceiveClass2: |
|
592 break; |
|
593 default: |
|
594 break; |
|
595 } |
|
596 |
|
597 delete iOperation; |
|
598 iOperation = NULL; |
|
599 |
|
600 if (!IsActive()) |
|
601 Complete(iStatus.Int()); |
|
602 } |
|
603 |
|
604 void CSmcmSendTest::Complete(TInt aError) |
|
605 /** |
|
606 Indicates that the operation is complete with aError. |
|
607 |
|
608 @param aError error returned by the operation |
|
609 */ |
|
610 { |
|
611 iSmsTest.Printf(_L("CSmsScTest::Complete [aError=%d]\n"), aError); |
|
612 if (iExpectedError == aError && aError) |
|
613 { |
|
614 iSmsTest.Printf(_L("CSmsScTest::Complete [%d Expected - PASSED]\n"), aError); |
|
615 aError = KErrNone; |
|
616 } |
|
617 |
|
618 if (iReport != NULL) |
|
619 User::RequestComplete(iReport, aError); |
|
620 } |
|
621 |
|
622 TInt CSmcmSendTest::RunError(TInt aError) |
|
623 /** |
|
624 |
|
625 @param aError error returned by the operation |
|
626 @return TInt Returns the KErrNone. |
|
627 */ |
|
628 { |
|
629 Complete(aError); |
|
630 return KErrNone; |
|
631 } |
|
632 |
|
633 void CSmcmSendTest::Queue(TRequestStatus& aStatus) |
|
634 /** |
|
635 |
|
636 @param aStatus Indicates the status of the operation. |
|
637 */ |
|
638 { |
|
639 __ASSERT_DEBUG(iReport==NULL, User::Invariant()); |
|
640 |
|
641 aStatus=KRequestPending; |
|
642 iReport=&aStatus; |
|
643 } |
|
644 |
|
645 void CSmcmSendTest::DoCancel() |
|
646 { |
|
647 if (iOperation) |
|
648 { |
|
649 iOperation->Cancel(); |
|
650 iSmsTest.Printf(_L("Operation Cancelled!\n")); |
|
651 } |
|
652 else |
|
653 { |
|
654 iSmsTest.Printf(_L("No operation to cancel!\n")); |
|
655 } |
|
656 |
|
657 delete iOperation; |
|
658 iOperation = NULL; |
|
659 } |
|
660 |
|
661 void CSmcmSendTest::DoRunSchedulingL() |
|
662 { |
|
663 if (iStatus == KErrNone && iOperation != NULL) |
|
664 iStatus = iSmsTest.iProgress.iError; |
|
665 |
|
666 iSmsTest.Printf(_L("Scheduling completed with error %d\n"), iStatus); |
|
667 |
|
668 TBool sent = EFalse; |
|
669 |
|
670 if (iStatus == KErrNone) |
|
671 { |
|
672 iSmsTest.DisplaySendingStatesL(*iSelection); |
|
673 TInt error = KErrNone; |
|
674 sent = iSmsTest.SendingCompleteL(*iSelection, error); |
|
675 iStatus = error; |
|
676 } |
|
677 |
|
678 if (!sent) |
|
679 { |
|
680 iStatus = KRequestPending; |
|
681 SetActive(); |
|
682 iState = EStateSchedulingThenSend; |
|
683 } |
|
684 else |
|
685 { |
|
686 iState = EStateWaiting; |
|
687 iSmsTest.Printf(_L("Scheduling completed with error %d\n"), iStatus); |
|
688 } |
|
689 } |
|
690 |
|
691 void CSmcmSendTest::DoRunSendingL() |
|
692 { |
|
693 if (iStatus == KErrNone && iOperation != NULL) |
|
694 iStatus = iSmsTest.iProgress.iError; |
|
695 |
|
696 iState = EStateWaiting; |
|
697 iSmsTest.Printf(_L("Sending completed with error %d\n"), iStatus); |
|
698 |
|
699 TInt err = KErrNone; |
|
700 |
|
701 if (!iSmsTest.SendingCompleteL(*iSelection, err)) |
|
702 { |
|
703 iSmsTest.Printf(_L("Waiting for all messages to send or fail\n"), iStatus); |
|
704 iStatus = KRequestPending; |
|
705 SetActive(); |
|
706 iState = EStateSchedulingThenSend; |
|
707 } |
|
708 else |
|
709 { |
|
710 PrintSendingStates(iCurrentMessages); |
|
711 LOCAL_CHECKPOINT(iAutoTest, CheckSendingStates(iCurrentMessages)); |
|
712 } |
|
713 } |
|
714 |
|
715 TBool CSmcmSendTest::CheckSendingStates(const RMessageSendStatesArray& sendStateArray) |
|
716 { |
|
717 const TInt count = sendStateArray.Count(); |
|
718 |
|
719 for (TInt i=0; i < count; ++i) |
|
720 { |
|
721 const CMessageSendStates& sendState = *sendStateArray[i]; |
|
722 const TInt stateCount = sendState.iStates.Count(); |
|
723 |
|
724 for (TInt j=0; j < stateCount-1; ++j) |
|
725 { |
|
726 if (sendState.iStates[j] == KMsvSendStateFailed && (sendState.iStates[j+1] == KMsvSendStateResend || sendState.iStates[j+1] == KMsvSendStateScheduled)) |
|
727 return EFalse; |
|
728 } |
|
729 } |
|
730 |
|
731 return ETrue; |
|
732 } |
|
733 |
|
734 void CSmcmSendTest::PrintSendingStates(const RMessageSendStatesArray& sendStateArray) |
|
735 { |
|
736 iSmsTest.Printf(_L("=============== Sending States =============== \n\n")); |
|
737 |
|
738 TInt count = sendStateArray.Count(); |
|
739 iSmsTest.Printf(_L("Number of messages= %d\n\n"), count); |
|
740 |
|
741 for (TInt i=0; i < count; ++i) |
|
742 { |
|
743 iSmsTest.Printf(_L("================= Message %d ================\n\n"), i); |
|
744 |
|
745 const CMessageSendStates& sendState = *sendStateArray[i]; |
|
746 TInt stateCount = sendState.iStates.Count(); |
|
747 |
|
748 for (TInt j=0; j < stateCount; ++j) |
|
749 { |
|
750 //iSmsTest.Printf(_L("%d\n"), sendState.iStates[j]); |
|
751 |
|
752 switch (sendState.iStates[j]) |
|
753 { |
|
754 case KMsvSendStateSending: |
|
755 iSmsTest.Printf(_L("Sending %d\n"), sendState.iStates[j]); |
|
756 break; |
|
757 case KMsvSendStateResend: |
|
758 iSmsTest.Printf(_L("Resend %d\n"), sendState.iStates[j]); |
|
759 break; |
|
760 case KMsvSendStateScheduled: |
|
761 iSmsTest.Printf(_L("Scheduled %d\n"), sendState.iStates[j]); |
|
762 break; |
|
763 case KMsvSendStateFailed: |
|
764 iSmsTest.Printf(_L("Failed %d\n"), sendState.iStates[j]); |
|
765 break; |
|
766 case KMsvSendStateWaiting: |
|
767 iSmsTest.Printf(_L("Waiting %d\n"), sendState.iStates[j]); |
|
768 break; |
|
769 case KMsvSendStateSent: |
|
770 iSmsTest.Printf(_L("Sent %d\n"), sendState.iStates[j]); |
|
771 break; |
|
772 case KMsvSendStateSuspended: |
|
773 iSmsTest.Printf(_L("Suspended %d\n"), sendState.iStates[j]); |
|
774 break; |
|
775 default: |
|
776 break; |
|
777 } |
|
778 } |
|
779 |
|
780 iSmsTest.Printf(_L("============== End of Message %d =============\n\n"), i); |
|
781 } |
|
782 |
|
783 iSmsTest.Printf(_L("=============== End Sending States ============= \n")); |
|
784 } |
|
785 |
|
786 |
|
787 TBool CSmcmSendTest::CheckParentOfReceivedMessageL(const CMsvEntrySelection& aSelection) |
|
788 { |
|
789 TInt count = aSelection.Count(); |
|
790 TBool retVal = ETrue; |
|
791 |
|
792 while (count-- && retVal) |
|
793 { |
|
794 const TMsvId id = aSelection[count]; |
|
795 iSmsTest.SetEntryL(id); |
|
796 const TMsvSmsEntry entry(iSmsTest.Entry()); |
|
797 |
|
798 if (entry.iType == KUidMsvMessageEntry && entry.iMtm == KUidMsgTypeSMS) |
|
799 { |
|
800 iMessagesReceived++; |
|
801 iSmsTest.Printf(_L("%d: %d/%d received\n"), |
|
802 id, iMessagesReceived, iMessagesToReceive); |
|
803 |
|
804 TSmsDataCodingScheme::TSmsClass smsClass; |
|
805 TMsvId expectedFolder = KMsvGlobalInBoxIndexEntryId; |
|
806 |
|
807 const TBool hasClass = entry.Class(smsClass); |
|
808 |
|
809 if (hasClass && smsClass == TSmsDataCodingScheme::ESmsClass2) |
|
810 expectedFolder = iSmsSettings->Class2Folder(); |
|
811 |
|
812 retVal = (expectedFolder == entry.Parent()); |
|
813 |
|
814 if (!retVal) |
|
815 { |
|
816 iSmsTest.Printf(_L("Parent of message %d invalid [parent=%d expected=%d hasClass=%d class=%d smsSettings=%d\n"), |
|
817 id, entry.Parent(), expectedFolder, hasClass, smsClass, iSmsSettings->Class2Folder()); |
|
818 } |
|
819 } |
|
820 } |
|
821 |
|
822 return retVal; |
|
823 } |
|
824 |
|
825 void CSmcmSendTest::SetMessagesToReceiveL(TInt aTestNumber) |
|
826 { |
|
827 TParse parse; |
|
828 User::LeaveIfError(iSmsTest.ResolveFile(_L("SMS"), KSmsScript, parse)); |
|
829 |
|
830 CTestConfig* configFile = CTestConfig::NewLC(iSmsTest.FileSession(), KNullDesC, parse.FullName()); |
|
831 |
|
832 TBuf8<16> name; |
|
833 name.AppendFormat(_L8("test%d"), aTestNumber); |
|
834 |
|
835 const CTestConfigSection* section = configFile->Section(name); |
|
836 |
|
837 if (configFile == NULL) |
|
838 User::Leave(KErrNotFound); |
|
839 |
|
840 iMessagesToReceive = section->ItemCount(_L8("SmsRx")); |
|
841 CleanupStack::PopAndDestroy(configFile); |
|
842 } |
|
843 |
|
844 |