1 // Copyright (c) 2000-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_SmsRegress.h" |
|
17 #include <smscmds.h> |
|
18 _LIT(KSmsScript, "sms.script"); |
|
19 |
|
20 GLDEF_C TInt E32Main() |
|
21 { |
|
22 __UHEAP_MARK; |
|
23 test.Start(_L("Setup")); |
|
24 theCleanup = CTrapCleanup::New(); |
|
25 TRAPD(ret,doMainL()); |
|
26 test(ret==KErrNone); |
|
27 delete theCleanup; |
|
28 test.Console()->SetPos(0, 13); |
|
29 test.End(); |
|
30 test.Close(); |
|
31 __UHEAP_MARKEND; |
|
32 return(KErrNone); |
|
33 } |
|
34 |
|
35 LOCAL_C void doMainL() |
|
36 { |
|
37 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
38 CleanupStack::PushL(scheduler); |
|
39 CActiveScheduler::Install(scheduler); |
|
40 |
|
41 CSmsTestUtils* smsTest = CSmsTestUtils::NewL(test); |
|
42 CleanupStack::PushL(smsTest); |
|
43 TInt nextTest = 0; |
|
44 |
|
45 smsTest->NotifySaPhoneOnL(); |
|
46 |
|
47 CSmsRegressTest* SmcmTest = CSmsRegressTest::NewLC(*smsTest, KNullDesC, nextTest); |
|
48 |
|
49 smsTest->WaitForInitializeL(); |
|
50 |
|
51 SmcmTest->StartL(); |
|
52 |
|
53 CleanupStack::PopAndDestroy(3); //SmcmTest. scheduler |
|
54 } |
|
55 |
|
56 CSmsRegressTest::CSmsRegressTest(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest) |
|
57 : CSmsTestBase(aSmsTest, aScriptFile, aNextTest), iOperations(aSmsTest) |
|
58 { |
|
59 CActiveScheduler::Add(this); |
|
60 } |
|
61 |
|
62 void CSmsRegressTest::RunAutoL() |
|
63 { |
|
64 iNextTest = 0; |
|
65 |
|
66 iSmsTest.TestStart(++iNextTest, _L("Test2SMSSInstances")); |
|
67 Test2SMSSInstancesL(); |
|
68 User::LeaveIfError(iStatus.Int()); |
|
69 iSmsTest.TestFinish(iNextTest); |
|
70 } |
|
71 |
|
72 void CSmsRegressTest::Test2SMSSInstancesL() |
|
73 { |
|
74 TTime now; |
|
75 now.HomeTime(); |
|
76 |
|
77 CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection; |
|
78 CleanupStack::PushL(sel); |
|
79 |
|
80 iSmsTest(iSmsTest.ReadScriptL(KSmsScript, KMsvGlobalOutBoxIndexEntryId, *sel, now)); |
|
81 iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
82 |
|
83 CMsvOperationWait* wait = CMsvOperationWait::NewLC(); |
|
84 wait->Start(); |
|
85 |
|
86 CMsvOperation* op = iSmsTest.iMsvEntry->CopyL((*sel)[0], KMsvGlobalOutBoxIndexEntryId, wait->iStatus); |
|
87 CleanupStack::PushL(op); |
|
88 CActiveScheduler::Start(); |
|
89 |
|
90 TMsvLocalOperationProgress prog; |
|
91 TPckgC<TMsvLocalOperationProgress> pkg(prog); |
|
92 pkg.Set(op->ProgressL()); |
|
93 prog = pkg(); |
|
94 User::LeaveIfError(prog.iError); |
|
95 |
|
96 const TMsvId sms1 = (*sel)[0]; |
|
97 const TMsvId sms2 = prog.iId; |
|
98 |
|
99 CleanupStack::PopAndDestroy(2); //wait, op |
|
100 |
|
101 _LIT(KDesc1, "Remote"); |
|
102 _LIT(KDesc2, "Local"); |
|
103 |
|
104 iSmsTest.SetEntryL(sms1); |
|
105 TMsvEntry entry(iSmsTest.Entry()); |
|
106 entry.iDescription.Set(KDesc1); |
|
107 iSmsTest.ChangeEntryL(entry); |
|
108 |
|
109 iSmsTest.SetEntryL(sms2); |
|
110 entry = iSmsTest.Entry(); |
|
111 entry.iServiceId = KMsvLocalServiceIndexEntryId; |
|
112 entry.iDescription.Set(KDesc2); |
|
113 iSmsTest.ChangeEntryL(entry); |
|
114 |
|
115 iSmsTest.Printf(_L("Test2SMSSInstancesL for 2 messages:\n")); |
|
116 iSmsTest.DisplayMessageL(sms1); |
|
117 iSmsTest.DisplayMessageL(sms2); |
|
118 |
|
119 iOperations.ResetAndDestroy(); |
|
120 |
|
121 //Start first operation |
|
122 COpActive* opActive = new (ELeave) COpActive(iOperations, sms1); |
|
123 CleanupStack::PushL(opActive); |
|
124 iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
125 opActive->iOperation = iSmsTest.iMsvEntry->CopyL(opActive->Id(), iSmsTest.iSmsServiceId, opActive->Status()); |
|
126 iOperations.AppendL(opActive); |
|
127 CleanupStack::Pop(opActive); |
|
128 |
|
129 //Start second operation |
|
130 opActive = new (ELeave) COpActive(iOperations, sms2); |
|
131 CleanupStack::PushL(opActive); |
|
132 iSmsTest.SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
133 sel->Reset(); |
|
134 sel->AppendL(opActive->Id()); |
|
135 opActive->iOperation = iSmsTest.iMsvSession->TransferCommandL(*sel, ESmsMtmCommandScheduleCopy, KNullDesC8, opActive->Status()); |
|
136 iOperations.AppendL(opActive); |
|
137 CleanupStack::Pop(opActive); |
|
138 |
|
139 CleanupStack::PopAndDestroy(sel); |
|
140 |
|
141 iState = ETest2SMSSInstances; |
|
142 iOperations.Start(iStatus); |
|
143 SetActive(); |
|
144 CActiveScheduler::Start(); |
|
145 } |
|
146 |
|
147 |
|
148 CSmsRegressTest::~CSmsRegressTest() |
|
149 { |
|
150 Cancel(); |
|
151 delete iWatchers; |
|
152 |
|
153 iSocket.Close(); |
|
154 iSocketServ.Close(); |
|
155 } |
|
156 |
|
157 void CSmsRegressTest::ConstructL() |
|
158 { |
|
159 iSmsTest.SetLogToFile(); |
|
160 iTimer = CTestTimer::NewL(); |
|
161 |
|
162 User::LeaveIfError(iSocketServ.Connect()); |
|
163 TProtocolDesc protoinfo; |
|
164 TProtocolName protocolname(KSmsDatagram); |
|
165 User::LeaveIfError(iSocketServ.FindProtocol(protocolname,protoinfo)); |
|
166 User::LeaveIfError(iSocket.Open(iSocketServ,protoinfo.iAddrFamily,protoinfo.iSockType,protoinfo.iProtocol)); |
|
167 |
|
168 TSmsAddr smsaddr; |
|
169 smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly); |
|
170 User::LeaveIfError(iSocket.Bind(smsaddr)); |
|
171 } |
|
172 |
|
173 void CSmsRegressTest::DoCancel() |
|
174 { |
|
175 iOperations.Cancel(); |
|
176 iTimer->Cancel(); |
|
177 } |
|
178 |
|
179 void CSmsRegressTest::DoRunTest2SMSSInstancesL() |
|
180 { |
|
181 TInt count = iOperations.Count(); |
|
182 |
|
183 while (count-- && !IsActive()) |
|
184 { |
|
185 const COpActive& active = *iOperations[count]; |
|
186 iSmsTest.SetEntryL(active.Id()); |
|
187 const TMsvEntry& entry = iSmsTest.Entry(); |
|
188 switch (entry.SendingState()) |
|
189 { |
|
190 case KMsvSendStateSent: |
|
191 case KMsvSendStateFailed: |
|
192 iSmsTest.Printf(_L("%d Complete [SendingState=%d]\n"), entry.Id(), entry.SendingState()); |
|
193 break; //do nothing |
|
194 default: |
|
195 iSmsTest.Printf(_L("%d Active [SendingState=%d]\n"), entry.Id(), entry.SendingState()); |
|
196 iTimer->AfterReq(2000000, iStatus); |
|
197 SetActive(); |
|
198 break; |
|
199 } |
|
200 } |
|
201 } |
|
202 |
|
203 void CSmsRegressTest::RunL() |
|
204 { |
|
205 User::LeaveIfError(iStatus.Int()); |
|
206 |
|
207 switch (iState) |
|
208 { |
|
209 case ETest2SMSSInstances: |
|
210 DoRunTest2SMSSInstancesL(); |
|
211 break; |
|
212 default: |
|
213 iSmsTest(EFalse); |
|
214 break; |
|
215 } |
|
216 |
|
217 if (!IsActive()) |
|
218 CActiveScheduler::Stop(); |
|
219 } |
|
220 |
|
221 TInt CSmsRegressTest::RunError(TInt aError) |
|
222 { |
|
223 iSmsTest.Printf(_L("CSmsRegressTest::RunError [iStatus=%d aError, iState=%d]\n"), iStatus.Int(), aError, iState); |
|
224 |
|
225 if (iStatus.Int() == KErrNone) |
|
226 iStatus = aError; |
|
227 |
|
228 CActiveScheduler::Stop(); |
|
229 return KErrNone; |
|
230 } |
|
231 |
|
232 CSmsRegressTest* CSmsRegressTest::NewLC(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aNextTest) |
|
233 { |
|
234 CSmsRegressTest* self = new (ELeave) CSmsRegressTest(aSmsTest, aScriptFile, aNextTest); |
|
235 CleanupStack::PushL(self); |
|
236 |
|
237 self->ConstructL(); |
|
238 |
|
239 return self; |
|
240 } |
|
241 |
|
242 void CSmsRegressTest::ShowMenuL() |
|
243 { |
|
244 iSmsTest.ResetMenu(); |
|
245 |
|
246 iSmsTest.AppendToMenuL(_L("Start")); |
|
247 |
|
248 TInt result = iSmsTest.DisplayMenu(_L("SMS Client MTM Test")); |
|
249 |
|
250 if (result <= 0) |
|
251 return; |
|
252 |
|
253 switch (result) |
|
254 { |
|
255 case 1: |
|
256 RunAutoL(); |
|
257 break; |
|
258 default: |
|
259 User::Leave(KErrArgument); |
|
260 break; |
|
261 } |
|
262 |
|
263 if (!iSmsTest.RunAuto()) |
|
264 { |
|
265 iSmsTest.Printf(_L("Press any key to continue...\n")); |
|
266 iSmsTest.Test().Getch(); |
|
267 } |
|
268 |
|
269 ShowMenuL(); |
|
270 } |
|
271 |
|
272 /* |
|
273 TBool CSmsRegressTest::CompareSettings(const CSmsSettings& aLeft, const CSmsSettings& aRight, TBool aTestSC) |
|
274 { |
|
275 TCompare compare(CompareMessageSettings(aLeft, aRight)); |
|
276 |
|
277 compare(aLeft.CommDbAction() == aRight.CommDbAction()); |
|
278 compare(aLeft.SmsBearerAction() == aRight.SmsBearerAction()); |
|
279 compare(aLeft.SmsBearer() == aRight.SmsBearer()); |
|
280 compare(aLeft.Delivery() == aRight.Delivery()); |
|
281 compare(CompareBools(aLeft.ReplyQuoted(), aRight.ReplyQuoted())); |
|
282 compare(aLeft.SpecialMessageHandling() == aRight.SpecialMessageHandling()); |
|
283 compare(aLeft.StatusReportHandling() == aRight.StatusReportHandling()); |
|
284 |
|
285 if (aTestSC) |
|
286 { |
|
287 compare(aLeft.DefaultSC() == aRight.DefaultSC()); |
|
288 compare(aLeft.NumSCAddresses() == aRight.NumSCAddresses()); |
|
289 |
|
290 TInt count = aLeft.NumSCAddresses(); |
|
291 |
|
292 while (count--) |
|
293 { |
|
294 compare(CompareNumbers(aLeft.SCAddress(count), aRight.SCAddress(count))); |
|
295 } |
|
296 } |
|
297 |
|
298 return compare; |
|
299 } |
|
300 |
|
301 TBool CSmsRegressTest::CompareMessageSettings(const CSmsMessageSettings& aLeft, const CSmsMessageSettings& aRight) |
|
302 { |
|
303 TCompare compare(CompareBools(aLeft.CanConcatenate(), aRight.CanConcatenate())); |
|
304 compare(aLeft.CharacterSet() == aRight.CharacterSet()); |
|
305 compare(CompareBools(aLeft.DeliveryReport(), aRight.DeliveryReport())); |
|
306 compare(aLeft.MessageConversion() == aRight.MessageConversion()); |
|
307 compare(CompareBools(aLeft.RejectDuplicate(), aRight.RejectDuplicate())); |
|
308 compare(CompareBools(aLeft.ReplyPath(), aRight.ReplyPath())); |
|
309 compare(aLeft.ValidityPeriod() == aRight.ValidityPeriod()); |
|
310 compare(aLeft.ValidityPeriodFormat() == aRight.ValidityPeriodFormat()); |
|
311 return compare; |
|
312 } |
|
313 |
|
314 TBool CSmsRegressTest::CompareNumbers(const CSmsNumber& aLeft, const CSmsNumber& aRight) |
|
315 { |
|
316 TCompare compare(aLeft.Name() == aRight.Name()); |
|
317 compare(aLeft.Address() == aRight.Address()); |
|
318 compare(aLeft.LogId() == aRight.LogId()); |
|
319 return compare; |
|
320 } |
|
321 */ |
|
322 COpActive::COpActive(COpActiveArray& aParent, TMsvId aId, TInt aPriority) |
|
323 : CActive(aPriority), iParent(aParent), iSmsTest(aParent.iSmsTest), iId(aId) |
|
324 { |
|
325 CActiveScheduler::Add(this); |
|
326 } |
|
327 |
|
328 COpActive::~COpActive() |
|
329 { |
|
330 Cancel(); |
|
331 delete iOperation; |
|
332 } |
|
333 |
|
334 void COpActive::RunL() |
|
335 { |
|
336 iSmsTest.Printf(_L("COpActive::RunL [iStatus=%d]\n"), iStatus.Int()); |
|
337 User::LeaveIfError(iStatus.Int()); |
|
338 iSmsTest.SetProgressL(*iOperation); |
|
339 iSmsTest.Printf(_L("COpActive::RunL [Progress.iError=%d]\n"), iSmsTest.iProgress.iError); |
|
340 User::LeaveIfError(iSmsTest.iProgress.iError); |
|
341 Complete(KErrNone); |
|
342 } |
|
343 |
|
344 void COpActive::DoCancel() |
|
345 { |
|
346 iOperation->Cancel(); |
|
347 Complete(KErrCancel); |
|
348 } |
|
349 |
|
350 TInt COpActive::RunError(TInt aError) |
|
351 { |
|
352 Complete(aError); |
|
353 return KErrNone; |
|
354 } |
|
355 |
|
356 void COpActive::Complete(TInt aError) |
|
357 { |
|
358 iParent.ActiveComplete(*this, aError); |
|
359 } |
|
360 |
|
361 COpActiveArray::COpActiveArray(CSmsTestUtils& aSmsTest) |
|
362 : CArrayPtrFlat<COpActive>(1), iSmsTest(aSmsTest) |
|
363 { |
|
364 } |
|
365 |
|
366 COpActiveArray::~COpActiveArray() |
|
367 { |
|
368 Cancel(); |
|
369 ResetAndDestroy(); |
|
370 } |
|
371 |
|
372 void COpActiveArray::Cancel() |
|
373 { |
|
374 TInt count = Count(); |
|
375 |
|
376 while (count--) |
|
377 At(count)->Cancel(); |
|
378 } |
|
379 |
|
380 void COpActiveArray::Start(TRequestStatus& aStatus) |
|
381 { |
|
382 aStatus = KRequestPending; |
|
383 iReport = &aStatus; |
|
384 } |
|
385 |
|
386 void COpActiveArray::ActiveComplete(const CActive& aActive, TInt aError) |
|
387 { |
|
388 iSmsTest.Printf(_L("COpActiveArray::ActiveComplete [Id=aActive.Id() aError=%d]\n"), &aActive, aError); |
|
389 |
|
390 if (iReport != NULL) |
|
391 { |
|
392 if (aError != KErrNone) |
|
393 User::RequestComplete(iReport, aError); |
|
394 else |
|
395 { |
|
396 TInt count = Count(); |
|
397 TBool active = EFalse; |
|
398 while (!active && count--) |
|
399 active = active || At(count)->IsActive(); |
|
400 |
|
401 if (!active) |
|
402 User::RequestComplete(iReport, KErrNone); |
|
403 } |
|
404 } |
|
405 } |
|