|
1 // Copyright (c) 2002-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This contains CTestMessCreateSMS. This class creates the sms message |
|
15 // for GSM or CDMA. For CDMA mtm, it uses utility classes to create |
|
16 // the respective GSM or CDMA sms message |
|
17 // |
|
18 // |
|
19 |
|
20 #include "Configuration.cfg" |
|
21 |
|
22 #include "TestMessCreateSMS.h" |
|
23 #include "TestMessEditEntryUtil.h" |
|
24 |
|
25 //Usage of macros of Cdma mtm |
|
26 #include "TestMessCreateGsmSmsUtil.h" |
|
27 #if (defined CDMA_API_ENABLED) |
|
28 #include "TestMessCreateCdmaSmsUtil.h" |
|
29 #endif |
|
30 |
|
31 // EPOC includes |
|
32 #include <mtmuids.h> |
|
33 #include <txtrich.h> |
|
34 #include <smut.h> |
|
35 #include <etelmm.h> |
|
36 #include <SMUTSET.h> //For CSmsMessageSettings |
|
37 |
|
38 /*@{*/ |
|
39 /// Literal constants read from the ini file |
|
40 _LIT(KRecipients, "recipients"); |
|
41 _LIT(KTo, "to%d"); |
|
42 _LIT(KPtSaveDraft, "SaveInDraft"); |
|
43 _LIT(KDefTo, "smsto"); |
|
44 |
|
45 _LIT(KPtMsgBearerGsm, "GSM"); |
|
46 //Usage of macros for Cdma mtm |
|
47 #if (defined CDMA_API_ENABLED) |
|
48 _LIT(KPtMsgBearerType, "MessageBearerType"); |
|
49 _LIT(KPtMsgBearerCdma, "CDMA"); |
|
50 #endif |
|
51 /*@}*/ |
|
52 |
|
53 #if (defined CDMA_API_ENABLED) |
|
54 #define KPtDefaultCount 1 |
|
55 #endif |
|
56 |
|
57 CTestMessCreateSMS::CTestMessCreateSMS() |
|
58 : CTestMessBase(EFalse) |
|
59 , iSimInDatabase(EFalse) |
|
60 { |
|
61 SetTestStepName(_L("CreateSms")); |
|
62 } |
|
63 |
|
64 /** |
|
65 Creates the SMS message for GSM or CDMA. |
|
66 @return TVerdict |
|
67 */ |
|
68 |
|
69 TVerdict CTestMessCreateSMS::doTestStepPreambleL() |
|
70 { |
|
71 TVerdict ret=CTestMessBase::doTestStepPreambleL(); |
|
72 // IMK iSimInDatabase=(GetPhoneSmsNumberL(iSimPhoneNumber)==KErrNone); |
|
73 iSimInDatabase=false; //IMK (GetPhoneSmsNumberL(iSimPhoneNumber)==KErrNone); |
|
74 return ret; |
|
75 } |
|
76 |
|
77 /** |
|
78 Creates the SMS message for GSM or CDMA. |
|
79 @return TVerdict |
|
80 */ |
|
81 TVerdict CTestMessCreateSMS::doTestStepL() |
|
82 { |
|
83 // Get scheduling data |
|
84 TTimeIntervalMinutes scheduledTime=ReadScheduleTime(); |
|
85 |
|
86 //create the message |
|
87 TBool saveDraft = EFalse; |
|
88 GetBoolFromConfig(ConfigSection(), KPtSaveDraft, saveDraft); |
|
89 |
|
90 if ( saveDraft ) |
|
91 { |
|
92 //Create the message in Draft |
|
93 CreateSmsL(KMsvDraftEntryId, scheduledTime); |
|
94 } |
|
95 else |
|
96 { |
|
97 //Creates the message in Outbox |
|
98 CreateSmsL(KMsvGlobalOutBoxIndexEntryId, scheduledTime); |
|
99 } |
|
100 |
|
101 return TestStepResult(); |
|
102 } |
|
103 |
|
104 void CTestMessCreateSMS::CreateSmsL(const TMsvId aMsvId, TTimeIntervalMinutes aScheduledTime) |
|
105 { |
|
106 // Get the bearertype (CDMA/GSM) |
|
107 TPtrC messageBearerType; |
|
108 messageBearerType.Set(KPtMsgBearerGsm); |
|
109 #if (defined CDMA_API_ENABLED) |
|
110 GetStringFromConfig(ConfigSection(), KPtMsgBearerType, messageBearerType); |
|
111 INFO_PRINTF2(_L("The message bearertype is : %S"), &messageBearerType); |
|
112 #endif |
|
113 |
|
114 CTestMessCreateSmsUtilBase* createSmsUtil = NULL; |
|
115 // Create the repective util class |
|
116 if ( messageBearerType.Compare(KPtMsgBearerGsm)==0 ) |
|
117 { |
|
118 createSmsUtil=new (ELeave) CTestMessCreateGsmSmsUtil(*this); |
|
119 } |
|
120 #if (defined CDMA_API_ENABLED) |
|
121 else if ( messageBearerType.Compare(KPtMsgBearerCdma)==0 ) |
|
122 { |
|
123 createSmsUtil=new (ELeave) CTestMessCreateCdmaSmsUtil(*this); |
|
124 } |
|
125 #endif |
|
126 else |
|
127 { |
|
128 WARN_PRINTF1(_L("Unknown bearer type using Gsm")); |
|
129 createSmsUtil=new (ELeave) CTestMessCreateGsmSmsUtil(*this); |
|
130 } |
|
131 CleanupStack::PushL(createSmsUtil); |
|
132 |
|
133 // All references to PrepareAccountL can be removed when DEF054045 is fixed |
|
134 // createSmsUtil->PrepareAccountL(*iSession); |
|
135 |
|
136 if(!iBodyAvailable) |
|
137 { |
|
138 ERR_PRINTF1(_L("No Body")); |
|
139 SetTestStepResult(EFail); |
|
140 } |
|
141 |
|
142 if ( TestStepResult()==EPass ) |
|
143 { |
|
144 TInt err=KErrNone; |
|
145 RSendAs sendAsServer; |
|
146 User::LeaveIfError(sendAsServer.Connect()); |
|
147 CleanupClosePushL(sendAsServer); |
|
148 AddMtmCapabilitiesL(sendAsServer); |
|
149 |
|
150 RSendAsMessage sendAs; |
|
151 TRAP(err, sendAs.CreateL(sendAsServer, KUidMsgTypeSMS)); |
|
152 PrepareSendAsL(sendAs); |
|
153 |
|
154 if ( err!=KErrNone ) |
|
155 { |
|
156 SetTestStepError(err); |
|
157 } |
|
158 else |
|
159 { |
|
160 INFO_PRINTF1(_L("sendAs.SetBodyTextL")); |
|
161 sendAs.SetBodyTextL(*iBodyText); |
|
162 |
|
163 #if (!defined CDMA_API_ENABLED) |
|
164 TInt recipients=1; |
|
165 GetIntFromConfig(ConfigSection(), KRecipients, recipients); |
|
166 |
|
167 TPtrC to(iSimPhoneNumber.iTelNumber); |
|
168 TBool returnValue=ETrue; |
|
169 for ( TInt recipient=0; (recipient<recipients) && (TestStepResult()==EPass); ) |
|
170 { |
|
171 ++recipient; |
|
172 |
|
173 if ( iSimInDatabase ) |
|
174 { |
|
175 returnValue=ETrue; |
|
176 } |
|
177 else |
|
178 { |
|
179 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
180 tempStore.Format(KTo(), recipient); |
|
181 returnValue=GetStringFromConfig(ConfigSection(), tempStore, to); |
|
182 if ( !returnValue ) |
|
183 { |
|
184 returnValue=GetStringFromConfig(KDef, KDefTo, to); |
|
185 } |
|
186 } |
|
187 if ( !returnValue ) |
|
188 { |
|
189 ERR_PRINTF1(_L("No To")); |
|
190 SetTestStepResult(EFail); |
|
191 } |
|
192 else |
|
193 { |
|
194 INFO_PRINTF2(_L("To = %S"), &to); |
|
195 sendAs.AddRecipientL(to, RSendAsMessage::ESendAsRecipientTo); |
|
196 } |
|
197 } |
|
198 #endif |
|
199 |
|
200 TRAP(err, sendAs.SaveMessageAndCloseL()); |
|
201 if ( err!=KErrNone ) |
|
202 { |
|
203 ERR_PRINTF1(_L("Save Message Failiure")); |
|
204 SetTestStepResult(EFail); |
|
205 sendAs.Close(); |
|
206 } |
|
207 else |
|
208 { |
|
209 TMsvId messageId=KMsvNullIndexEntryId; |
|
210 CMsvEntry* parent=iSession->GetEntryL(KMsvDraftEntryIdValue); |
|
211 CleanupStack::PushL(parent); |
|
212 parent->SetSortTypeL(SelectionOrdering()); |
|
213 CMsvEntrySelection* selection=parent->ChildrenL(); |
|
214 CleanupStack::PushL(selection); |
|
215 |
|
216 if ( selection->Count()>0 ) |
|
217 { |
|
218 messageId=selection->At(0); |
|
219 } |
|
220 if ( messageId!=KMsvNullIndexEntryId ) |
|
221 { |
|
222 SetEntryL(messageId); |
|
223 TMsvEntry child=EntryL().Entry(); |
|
224 |
|
225 //Get the message header |
|
226 CSmsHeader* smsHeader = createSmsUtil->NewHeaderL(*iBodyText); |
|
227 CleanupStack::PushL(smsHeader); |
|
228 |
|
229 //If message is too big lets concatenate..... |
|
230 ConCatMessageTextL(*smsHeader); |
|
231 |
|
232 CMsvStore* store =NULL; |
|
233 TRAPD(error, store = EntryL().EditStoreL()); |
|
234 if(error != KErrNone) |
|
235 { |
|
236 ERR_PRINTF2(_L("Edit Store Failed. Error %d"), error); |
|
237 SetTestStepError(error); |
|
238 } |
|
239 else |
|
240 { |
|
241 CleanupStack::PushL(store); |
|
242 smsHeader->RestoreL(*store); |
|
243 #if (defined CDMA_API_ENABLED) |
|
244 //Adding the recipients... |
|
245 CArrayPtrFlat<CSmsNumber>& recips = smsHeader->Recipients(); |
|
246 |
|
247 TInt recipients=KPtDefaultCount; |
|
248 GetIntFromConfig(ConfigSection(), KRecipients, recipients); |
|
249 |
|
250 TBool returnValue; |
|
251 for ( TInt recipient=1; recipient<=recipients; recipient++) |
|
252 { |
|
253 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
254 |
|
255 tempStore.Format(KTo(), recipient); |
|
256 |
|
257 TPtrC to; |
|
258 returnValue=GetStringFromConfig(ConfigSection(), tempStore, to); |
|
259 if ( !returnValue ) |
|
260 { |
|
261 returnValue=GetStringFromConfig(KDef, KDefTo, to); |
|
262 } |
|
263 if ( !returnValue ) |
|
264 { |
|
265 ERR_PRINTF1(_L("No To")); |
|
266 SetTestStepResult(EFail); |
|
267 } |
|
268 else |
|
269 { |
|
270 INFO_PRINTF2(_L("To = %S"), &to); |
|
271 |
|
272 //Get the recipient array |
|
273 CSmsNumber* newRecip = CSmsNumber::NewL(); |
|
274 CleanupStack::PushL(newRecip); |
|
275 |
|
276 // Check for the email address in recipient |
|
277 // This is for email over sms feature |
|
278 if(to.Locate('@') != KErrNotFound) |
|
279 { |
|
280 newRecip->SetAddressL(to, EMsvAddressTypeEMail); |
|
281 } |
|
282 else |
|
283 { |
|
284 newRecip->SetAddressL(to, EMsvAddressTypeISDN); |
|
285 } |
|
286 |
|
287 //Append the recipients |
|
288 recips.AppendL(newRecip); |
|
289 CleanupStack::Pop(newRecip); |
|
290 } |
|
291 } |
|
292 #endif |
|
293 child.SetSendingState(KMsvSendStateSuspended); |
|
294 child.SetInPreparation(EFalse); |
|
295 child.SetVisible(ETrue); |
|
296 |
|
297 //Get the details |
|
298 TBuf<KSmsDetailsLength> details; |
|
299 |
|
300 //Usage of macros of Cdma mtm |
|
301 #if (!defined CDMA_API_ENABLED) |
|
302 if ( TSmsUtilities::GetDetails(EntryL().Session().FileSession(), smsHeader->Message(), details) == KErrNone ) |
|
303 { |
|
304 child.iDetails.Set(details); |
|
305 } |
|
306 #else |
|
307 //if ( TSmsUtilities::GetDetails(EntryL().Session().FileSession(), smsHeader->Message(), details) == KErrNone ) |
|
308 CArrayPtrFlat<CSmsNumber>& smsNumberArray = smsHeader->Recipients(); |
|
309 if ( smsNumberArray.Count() ) |
|
310 { |
|
311 details.Copy(smsNumberArray[0]->Address()); |
|
312 } |
|
313 if ( details.Length() ) |
|
314 { |
|
315 child.iDetails.Set(details); |
|
316 } |
|
317 #endif |
|
318 |
|
319 //Get the description |
|
320 TBuf<KSmsDescriptionLength> desc; |
|
321 if ( TSmsUtilities::GetDescription(smsHeader->Message(), desc) == KErrNone ) |
|
322 { |
|
323 child.iDescription.Set(desc); |
|
324 } |
|
325 |
|
326 //fill up the fields of the message header |
|
327 PrepareHeaderL(*createSmsUtil, *smsHeader); |
|
328 |
|
329 //set the scheduled time if any |
|
330 if ( aScheduledTime!=TTimeIntervalMinutes(0) ) |
|
331 { |
|
332 child.SetSendingState(KMsvSendStateScheduled); |
|
333 child.SetScheduled(ETrue); |
|
334 child.iDate.UniversalTime(); |
|
335 child.iDate+=aScheduledTime; |
|
336 } |
|
337 |
|
338 // Update entry with data set from .ini file |
|
339 EntryL().ChangeL(child); |
|
340 smsHeader->StoreL(*store); |
|
341 store->CommitL(); |
|
342 CleanupStack::PopAndDestroy(store); |
|
343 |
|
344 CTestMessEditEntryUtil* editUtil=new (ELeave) CTestMessEditEntryUtil(*this, ETrue, iSimInDatabase, iSimPhoneNumber); |
|
345 CleanupStack::PushL(editUtil); |
|
346 editUtil->ProcessEntryL(EntryL().EntryId()); |
|
347 CleanupStack::PopAndDestroy(editUtil); |
|
348 |
|
349 if ( aMsvId==KMsvGlobalOutBoxIndexEntryId ) |
|
350 { |
|
351 // Move the selected message to out box |
|
352 CTestActive* active=CTestActive::NewLC(*this); |
|
353 CMsvOperation* op=parent->MoveL(child.Id(), KMsvGlobalOutBoxIndexEntryIdValue, active->iStatus); |
|
354 CleanupStack::PushL(op); |
|
355 active->Activate(); |
|
356 CActiveScheduler::Start(); |
|
357 CleanupStack::PopAndDestroy(2, active); |
|
358 } |
|
359 } |
|
360 CleanupStack::PopAndDestroy(smsHeader); |
|
361 } |
|
362 CleanupStack::PopAndDestroy(2, parent); |
|
363 } |
|
364 } |
|
365 |
|
366 CleanupStack::PopAndDestroy(&sendAsServer); |
|
367 } |
|
368 CleanupStack::PopAndDestroy(createSmsUtil); |
|
369 } |
|
370 |
|
371 void CTestMessCreateSMS::AddMtmCapabilitiesL(RSendAs& aSendAs) |
|
372 { |
|
373 aSendAs.ResetMessageFilter(); |
|
374 } |
|
375 |
|
376 void CTestMessCreateSMS::PrepareSendAsL(RSendAsMessage& /*aSendAs*/) |
|
377 { |
|
378 } |
|
379 |
|
380 void CTestMessCreateSMS::PrepareHeaderL(CTestMessCreateSmsUtilBase& aCreateUtil, CSmsHeader& aSmsHeader) |
|
381 { |
|
382 aCreateUtil.PrepareHeaderL(aSmsHeader); |
|
383 } |
|
384 |
|
385 //Usage of macro for CDMA mtm |
|
386 #if (defined CDMA_API_ENABLED) |
|
387 void CTestMessCreateSMS::ConCatMessageTextL(CSmsHeader& /*aHeader*/) |
|
388 { |
|
389 } |
|
390 #else |
|
391 void CTestMessCreateSMS::ConCatMessageTextL(CSmsHeader& aHeader) |
|
392 //Doxygen compatible comments |
|
393 /** |
|
394 This method Concatenates the long message. Checks for the length of |
|
395 body, if it is greater than 160 characters sets the concatenation |
|
396 option on for the Sms. |
|
397 |
|
398 @param aHeader |
|
399 Header for which the concatenation option is set on... |
|
400 |
|
401 */ |
|
402 { |
|
403 CSmsSettings* smsSettings = CSmsSettings::NewL(); |
|
404 CleanupStack::PushL(smsSettings); |
|
405 //if the length of the iBodyText is greater than the sms maximum length |
|
406 //i.e 160 chars...Set the Concatenation On.... |
|
407 if( aHeader.Message().MessageLengthL() > aHeader.Message().MaxMessageLength() ) |
|
408 { |
|
409 INFO_PRINTF1(_L("Concatenate Message...")); |
|
410 INFO_PRINTF1(_L("Message Exceeds max length setting Concatenate On...")); |
|
411 aHeader.GetSmsSettingsL(*smsSettings); |
|
412 smsSettings->SetCanConcatenate(ETrue); |
|
413 aHeader.SetSmsSettingsL(*smsSettings); |
|
414 } |
|
415 CleanupStack::PopAndDestroy(smsSettings); |
|
416 } |
|
417 #endif |