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_SmsSendBase.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 |
|
25 void CSmsSendTestBase::DoTestSendingL(const TDesC& aScript) |
|
26 /** |
|
27 Tests Sending: Creates and sends sms messages defined in aScript. |
|
28 |
|
29 @param aScript Script file containing sms messages |
|
30 */ |
|
31 { |
|
32 CSmsTestBase::DoTestSendingL(aScript); |
|
33 iState = EStateSending; |
|
34 CActiveScheduler::Start(); |
|
35 } |
|
36 |
|
37 void CSmsSendTestBase::DoTestSchedulingL(const TDesC& aScript, TTimeIntervalSeconds aFromNow) |
|
38 /** |
|
39 Tests Schedule Sending: Creates and schedules sms messages defined in aScript. |
|
40 |
|
41 @param aScript Script file containing sms messages |
|
42 @param aFromNow Time interval |
|
43 */ |
|
44 { |
|
45 CSmsTestBase::DoTestSchedulingL(aScript, EFalse, aFromNow); |
|
46 iState = EStateScheduling; |
|
47 CActiveScheduler::Start(); |
|
48 } |
|
49 |
|
50 CSmsSendTestBase::~CSmsSendTestBase() |
|
51 /** |
|
52 destructor |
|
53 */ |
|
54 { |
|
55 if (iSmsTest.iMsvSession) |
|
56 { |
|
57 iSmsTest.iMsvSession->RemoveObserver(*this); |
|
58 } |
|
59 } |
|
60 |
|
61 CSmsSendTestBase::CSmsSendTestBase(CSmsTestUtils& aSmsTest, const TDesC& aScriptFile, TInt& aCurrentTest) |
|
62 : CSmsTestBase(aSmsTest, aScriptFile, aCurrentTest), iState(EStateWaiting) |
|
63 { |
|
64 } |
|
65 |
|
66 void CSmsSendTestBase::RunAutoL() |
|
67 /** |
|
68 Runs tests in sequence, checks iStatus |
|
69 */ |
|
70 { |
|
71 // Test sending SMSs |
|
72 iSmsTest.TestStart(++iNextTest); |
|
73 TestSendingL(); |
|
74 User::LeaveIfError(iStatus.Int()); |
|
75 iSmsTest.TestFinish(iNextTest, KErrNone); |
|
76 |
|
77 // Test Scheduling |
|
78 iSmsTest.TestStart(++iNextTest); |
|
79 TestSchedulingL(); |
|
80 User::LeaveIfError(iStatus.Int()); |
|
81 iSmsTest.TestFinish(iNextTest, KErrNone); |
|
82 |
|
83 // Test forwarding an already sent SMS |
|
84 iSmsTest.TestStart(++iNextTest); |
|
85 TestForwardSentMsgL(); |
|
86 User::LeaveIfError(iStatus.Int()); |
|
87 iSmsTest.TestFinish(iNextTest, KErrNone); |
|
88 } |
|
89 |
|
90 void CSmsSendTestBase::ConstructL() |
|
91 { |
|
92 iSmsTest.SetLogToFile(); |
|
93 |
|
94 iSelection = new (ELeave) CMsvEntrySelection(); |
|
95 |
|
96 iSmsTest.iMsvSession->AddObserverL(*this); |
|
97 |
|
98 CActiveScheduler::Add(this); |
|
99 } |
|
100 |
|
101 void CSmsSendTestBase::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* /*aArg2*/, TAny* /*aArg3*/) |
|
102 /** |
|
103 Handles Session Event, used by MMsvSessionObserver |
|
104 |
|
105 @param aEvent Msv Session Event |
|
106 @param aArg1 Argument 1 |
|
107 @param aArg2 Argument 2 |
|
108 @param aArg3 Argument 3 |
|
109 */ |
|
110 { |
|
111 CMsvEntrySelection* entries = NULL; |
|
112 |
|
113 switch (aEvent) |
|
114 { |
|
115 case EMsvEntriesCreated: |
|
116 case EMsvEntriesChanged: |
|
117 case EMsvEntriesMoved: |
|
118 entries = STATIC_CAST(CMsvEntrySelection*, aArg1); |
|
119 break; |
|
120 default: |
|
121 return; |
|
122 } |
|
123 |
|
124 if (!IsActive()) |
|
125 return; |
|
126 |
|
127 switch (iState) |
|
128 { |
|
129 case EStateSchedulingThenSend: |
|
130 case EStateSending: |
|
131 { |
|
132 TInt error = KErrNone; |
|
133 |
|
134 iSmsTest.DisplaySendingStatesL(*entries); |
|
135 |
|
136 if (iSmsTest.SendingCompleteL(*iSelection, error) && iState == EStateSchedulingThenSend && iStatus == KRequestPending) |
|
137 { |
|
138 TRequestStatus* status = &iStatus; |
|
139 User::RequestComplete(status, error); |
|
140 } |
|
141 break; |
|
142 } |
|
143 default: |
|
144 break; |
|
145 } |
|
146 } |
|
147 |
|
148 |
|
149 void CSmsSendTestBase::ShowMenuL() |
|
150 /** |
|
151 Shows menu |
|
152 */ |
|
153 { |
|
154 iSmsTest.ResetMenu(); |
|
155 |
|
156 iSmsTest.AppendToMenuL(_L("Send Messages")); |
|
157 iSmsTest.AppendToMenuL(_L("Schedule Messages")); |
|
158 iSmsTest.AppendToMenuL(_L("Display Log")); |
|
159 iSmsTest.AppendToMenuL(_L("Clear Log")); |
|
160 iSmsTest.AppendToMenuL(_L("Navigate Message Store")); |
|
161 |
|
162 TInt result = iSmsTest.DisplayMenu(_L("SMS Send Test")); |
|
163 |
|
164 if (result <= 0) |
|
165 return; |
|
166 |
|
167 switch (result) |
|
168 { |
|
169 case 1: |
|
170 TestSendingL(); |
|
171 break; |
|
172 case 2: |
|
173 TestSchedulingL(); |
|
174 break; |
|
175 case 3: |
|
176 DisplayLogL(); |
|
177 break; |
|
178 case 4: |
|
179 ClearLogL(); |
|
180 break; |
|
181 case 5: |
|
182 iSmsTest.NavigateMessageStoreL(); |
|
183 break; |
|
184 default: |
|
185 User::Leave(KErrArgument); |
|
186 break; |
|
187 } |
|
188 |
|
189 ShowMenuL(); |
|
190 } |
|
191 |
|
192 void CSmsSendTestBase::RunL() |
|
193 /** |
|
194 Handles completed async operations |
|
195 */ |
|
196 { |
|
197 if (iOperation) |
|
198 iSmsTest.SetProgressL(*iOperation); |
|
199 |
|
200 switch (iState) |
|
201 { |
|
202 case EStateScheduling: |
|
203 DoRunSchedulingL(); |
|
204 break; |
|
205 case EStateSending: |
|
206 case EStateSchedulingThenSend: |
|
207 DoRunSendingL(); |
|
208 break; |
|
209 default: |
|
210 break; |
|
211 } |
|
212 |
|
213 delete iOperation; |
|
214 iOperation = NULL; |
|
215 } |
|
216 |
|
217 void CSmsSendTestBase::TestForwardSentMsgL() |
|
218 /** |
|
219 Tests forwarding a Sent Message |
|
220 */ |
|
221 { |
|
222 // Get all the messages in the Sent Folder |
|
223 SmsTest().SetEntryL(KMsvSentEntryId); |
|
224 CMsvEntrySelection* sentEntries = SmsTest().ChildrenWithMtmLC(KUidMsgTypeSMS); |
|
225 |
|
226 // If there are any Sent Messages, then Forward the first one |
|
227 if (sentEntries->Count()) |
|
228 { |
|
229 // This will create and send the forwarded SMS |
|
230 TMsvId sentId = sentEntries->At(0); |
|
231 DoTestForwardMsgL(sentId); |
|
232 |
|
233 iState = EStateSending; |
|
234 CActiveScheduler::Start(); |
|
235 } |
|
236 |
|
237 CleanupStack::PopAndDestroy(); //sentEntries |
|
238 } |
|
239 |
|
240 void CSmsSendTestBase::DoCancel() |
|
241 { |
|
242 if (iOperation) |
|
243 { |
|
244 iOperation->Cancel(); |
|
245 iSmsTest.Printf(_L("Operation Cancelled!\n")); |
|
246 } |
|
247 else |
|
248 { |
|
249 iSmsTest.Printf(_L("No operation to cancel!\n")); |
|
250 } |
|
251 |
|
252 delete iOperation; |
|
253 iOperation = NULL; |
|
254 } |
|
255 |
|
256 void CSmsSendTestBase::DoRunSchedulingL() |
|
257 /** |
|
258 Checks status. |
|
259 The message is rescheduled if sending failed. |
|
260 */ |
|
261 { |
|
262 if (iStatus == KErrNone) |
|
263 iStatus = iSmsTest.iProgress.iError; |
|
264 |
|
265 iSmsTest.Printf(_L("Scheduling completed with error %d\n"), iStatus); |
|
266 |
|
267 TBool sent = EFalse; |
|
268 |
|
269 if (iStatus == KErrNone) |
|
270 { |
|
271 iSmsTest.DisplaySendingStatesL(*iSelection); |
|
272 TInt error = KErrNone; |
|
273 sent = iSmsTest.SendingCompleteL(*iSelection, error); |
|
274 iStatus = error; |
|
275 } |
|
276 |
|
277 if (!sent) |
|
278 { |
|
279 iStatus = KRequestPending; |
|
280 SetActive(); |
|
281 iState = EStateSchedulingThenSend; |
|
282 } |
|
283 else |
|
284 { |
|
285 CActiveScheduler::Stop(); |
|
286 iState = EStateWaiting; |
|
287 iSmsTest.Printf(_L("Scheduling completed with error %d\n"), iStatus); |
|
288 |
|
289 if (!iSmsTest.RunAuto()) |
|
290 { |
|
291 iSmsTest.Test().Printf(_L("\nPress any key to continue...\n")); |
|
292 iSmsTest.Test().Getch(); |
|
293 } |
|
294 } |
|
295 } |
|
296 |
|
297 void CSmsSendTestBase::DoRunSendingL() |
|
298 /** |
|
299 Checks status. |
|
300 The message is rescheduled if sending failed. |
|
301 */ |
|
302 { |
|
303 if (iStatus == KErrNone) |
|
304 iStatus = iSmsTest.iProgress.iError; |
|
305 |
|
306 iState = EStateWaiting; |
|
307 iSmsTest.Printf(_L("Sending completed with error %d\n"), iStatus); |
|
308 |
|
309 TInt err = KErrNone; |
|
310 |
|
311 if (!iSmsTest.SendingCompleteL(*iSelection, err)) |
|
312 { |
|
313 iSmsTest.Printf(_L("Waiting for all messages to send or fail\n"), iStatus); |
|
314 iStatus = KRequestPending; |
|
315 SetActive(); |
|
316 iState = EStateSchedulingThenSend; |
|
317 } |
|
318 else |
|
319 { |
|
320 CActiveScheduler::Stop(); |
|
321 |
|
322 if (!iSmsTest.RunAuto()) |
|
323 { |
|
324 iSmsTest.Test().Printf(_L("\nPress any key to continue...\n")); |
|
325 iSmsTest.Test().Getch(); |
|
326 } |
|
327 } |
|
328 } |
|