1 // Copyright (c) 2005-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 "smcmstepbase.h" |
|
17 |
|
18 #include <csmsaccount.h> |
|
19 #include <csmsemailfields.h> |
|
20 #include <e32math.h> |
|
21 #include <emsformatie.h> |
|
22 #include <emspictureie.h> |
|
23 #include <emstestutils.h> |
|
24 #include <f32file.h> |
|
25 #include <smuthdr.h> |
|
26 #include <mtmdef.h> |
|
27 |
|
28 RTest test( _L( "SMS Test" ) ); |
|
29 |
|
30 const TInt KOneHourSeconds = 3600; |
|
31 |
|
32 // @return - TVerdict |
|
33 // Implementation of CTestStep base class virtual |
|
34 // All common initialisation to derived classes is done in here. |
|
35 TVerdict CSMCMStepBase::doTestStepPreambleL( ) |
|
36 { |
|
37 INFO_PRINTF1( _L( "CSMCMStepBase::doTestStepPreambleL()" ) ); |
|
38 |
|
39 ChangeLocale ( KUTC0 ); |
|
40 |
|
41 iScheduler = new( ELeave ) CActiveScheduler; |
|
42 CActiveScheduler::Install( iScheduler ); |
|
43 |
|
44 // need this to open a server session |
|
45 iDummyObserver = new( ELeave ) TMsvDummyObserver; |
|
46 |
|
47 // All the test steps will need an SMS Client MTM so we |
|
48 // build it here |
|
49 iSmsTestUtils = CSmsTestUtils::NewL( test ); |
|
50 iSmsTestUtils->SetLogToFile( ); |
|
51 iSmsTestUtils->InstantiateClientMtmsL( ); |
|
52 |
|
53 // Initialize mailbox |
|
54 CSmsSettings* settings = CSmsSettings::NewL( ); |
|
55 CleanupStack::PushL( settings ); |
|
56 CSmsAccount* account = CSmsAccount::NewLC( ); |
|
57 TRAPD(err,account->InitialiseDefaultSettingsL( *settings ) ); |
|
58 if ( err != KErrNone ) |
|
59 { |
|
60 User::Leave( err ); |
|
61 } |
|
62 |
|
63 CleanupStack::PopAndDestroy( account ); |
|
64 CleanupStack::PopAndDestroy( settings ); |
|
65 |
|
66 // open the server session |
|
67 iServerSession = CMsvSession::OpenSyncL( *iDummyObserver ); |
|
68 |
|
69 // create the Client MTM registry and get the Client MTM from it |
|
70 iClientMtmRegistry = CClientMtmRegistry::NewL( *iServerSession ); |
|
71 iSmsClientMtm = ( CSmsClientMtm* ) iClientMtmRegistry->NewMtmL( KUidMsgTypeSMS ); |
|
72 |
|
73 // create the root entry |
|
74 iMsvEntry = CMsvEntry::NewL( *iServerSession, |
|
75 KMsvRootIndexEntryId, |
|
76 TMsvSelectionOrdering( ) ); |
|
77 |
|
78 TSmsUtilities::ServiceIdL( *iServerSession, |
|
79 iSmsServiceId, |
|
80 KUidMsgTypeSMS ); |
|
81 |
|
82 SetTestStepResult( EPass ); |
|
83 |
|
84 return TestStepResult( ); |
|
85 } |
|
86 |
|
87 CSMCMStepBase::~CSMCMStepBase( ) |
|
88 { |
|
89 delete iSmsClientMtm; |
|
90 delete iClientMtmRegistry; |
|
91 |
|
92 delete iDummyObserver; |
|
93 delete iServerSession; |
|
94 |
|
95 delete iScheduler; |
|
96 |
|
97 } |
|
98 |
|
99 CSMCMStepBase::CSMCMStepBase( ) |
|
100 { |
|
101 |
|
102 } |
|
103 |
|
104 void CSMCMStepBase::ChangeLocale( TInt aHours ) |
|
105 { |
|
106 User::SetUTCOffset( KOneHourSeconds * aHours ); |
|
107 } |
|
108 |
|
109 TMsvId CSMCMStepBase::CreateEmailSmsMessageL( const TDesC& aEmailMessageData ) |
|
110 { |
|
111 RFs fs; |
|
112 User::LeaveIfError( fs.Connect( ) ); |
|
113 CleanupClosePushL( fs ); |
|
114 |
|
115 CSmsMessage* message = CSmsMessage::NewL( fs, |
|
116 CSmsPDU::ESmsDeliver, |
|
117 CSmsEditorBuffer::NewL( *iSmsTestUtils->iRichText ), |
|
118 EFalse ); |
|
119 CleanupStack::PushL( message ); |
|
120 |
|
121 CSmsBufferBase& buffer = message->Buffer( ); |
|
122 buffer.Reset( ); |
|
123 buffer.InsertL( 0, aEmailMessageData ); |
|
124 |
|
125 // Set the PID for email. |
|
126 if( message->SmsPDU( ).ProtocolIdentifierPresent( ) ) |
|
127 { |
|
128 message->SmsPDU( ).SetPIDType( TSmsProtocolIdentifier::ESmsPIDTelematicInterworking ); |
|
129 message->SmsPDU( ).SetTelematicDeviceIndicator( TSmsProtocolIdentifier::ESmsTelematicDevice ); |
|
130 message->SmsPDU( ).SetTelematicDeviceType( TSmsProtocolIdentifier::ESmsInternetElectronicMail ); |
|
131 |
|
132 } |
|
133 |
|
134 // Create a new SMS header ( CSmsHeader takes ownership of message ) |
|
135 CSmsHeader* header = CSmsHeader::NewL( message ); |
|
136 CleanupStack::Pop( message ); |
|
137 CleanupStack::PushL( header ); |
|
138 |
|
139 header->SetFromAddressL( KScriptItemRecipientsDef ); |
|
140 header->Message( ).SetServiceCenterAddressL( KScriptItemSCDef ); |
|
141 |
|
142 // Set the entry data... |
|
143 TMsvEntry entry; |
|
144 entry.iType = KUidMsvMessageEntry; |
|
145 entry.SetSendingState( KMsvSendStateNotApplicable ); |
|
146 TSmsUtilities::PopulateMsgEntry( entry, |
|
147 header->Message( ), |
|
148 iSmsTestUtils->iSmsServiceId ); |
|
149 |
|
150 entry.iDate.UniversalTime( ); |
|
151 |
|
152 const CSmsEmailFields& fields = header->EmailFields( ); |
|
153 // Set the details fiels to the address field. |
|
154 if ( !fields.HasAddress( ) ) |
|
155 { |
|
156 SetTestStepResult( EFail ); |
|
157 } |
|
158 TInt count = fields.Addresses( ).MdcaCount( ); |
|
159 entry.iDetails.Set( fields.Addresses( ).MdcaPoint( 0 ).Left( KSmsDetailsLength ) ); |
|
160 |
|
161 // Set the description to either the subject or the beginning part of the |
|
162 // body text. |
|
163 HBufC* desBuffer = HBufC::NewLC( iSmsClientMtm->ServiceSettings( ).DescriptionLength( ) ); |
|
164 TPtr description( desBuffer->Des( ) ); |
|
165 if( fields.Subject( ).Length( ) > 0 ) |
|
166 { |
|
167 // There is a subject - use this as the description |
|
168 description.Copy( fields.Subject( ).Left( description.MaxLength( ) ) ); |
|
169 |
|
170 } |
|
171 else |
|
172 { |
|
173 // No subject - use the beginning part of the body text. |
|
174 CSmsBufferBase& body = header->Message( ).Buffer( ); |
|
175 TInt length = body.Length( ); |
|
176 HBufC* buf = HBufC::NewLC( length ); |
|
177 TPtr ptr( buf->Des( ) ); |
|
178 body.Extract( ptr, 0, length ); |
|
179 |
|
180 description.Copy( ptr.Left( description.MaxLength( ) ) ); |
|
181 CleanupStack::PopAndDestroy( buf ); |
|
182 |
|
183 } |
|
184 entry.iDescription.Set( description ); |
|
185 |
|
186 // Create the entry in the inbox. |
|
187 iSmsTestUtils->SetEntryL( KMsvGlobalInBoxIndexEntryId ); |
|
188 iSmsTestUtils->CreateEntryL( entry ); |
|
189 iServerSession->CleanupEntryPushL( entry.Id( ) ); |
|
190 |
|
191 // Store the header... |
|
192 iSmsTestUtils->SetEntryL( entry.Id( ) ); |
|
193 CMsvStore* store = iSmsTestUtils->EditStoreL( ); |
|
194 CleanupStack::PushL( store ); |
|
195 |
|
196 header->StoreL( *store ); |
|
197 |
|
198 // Store the body text |
|
199 store->StoreBodyTextL( *iSmsTestUtils->iRichText ); |
|
200 store->CommitL( ); |
|
201 |
|
202 entry.iSize = store->SizeL( ); |
|
203 entry.SetReadOnly( ETrue ); |
|
204 iSmsTestUtils->ChangeEntryL( entry ); |
|
205 |
|
206 CleanupStack::PopAndDestroy( store ); |
|
207 iServerSession->CleanupEntryPop( ); |
|
208 CleanupStack::PopAndDestroy( 3, &fs ); // fs, header, desBuffer |
|
209 |
|
210 return entry.Id( ); |
|
211 |
|
212 } |
|
213 |
|
214 TMsvId CSMCMStepBase::CreateMessageAndEntryL( const TDesC& aUserData, TMessageSettings aSettings ) |
|
215 { |
|
216 TMsvEntry entry; |
|
217 entry.iType = KUidMsvMessageEntry; |
|
218 entry.SetSendingState( KMsvSendStateUnknown ); |
|
219 entry.iDetails.Set( _L( "Alias" ) ); |
|
220 entry.iBioType = aSettings.iOriginalBioType; |
|
221 |
|
222 iSmsTestUtils->iRichText->Reset( ); |
|
223 iSmsTestUtils->iRichText->InsertL( 0, aUserData ); |
|
224 |
|
225 CSmsHeader* header = NULL; |
|
226 if ( aSettings.iOperation == EOperationNone || aSettings.iOperation == EOperationReply ) |
|
227 { |
|
228 header = CSmsHeader::NewL( aSettings.iOriginalSmsPDUType, |
|
229 *iSmsTestUtils->iRichText ); |
|
230 } |
|
231 else // EOperationForward |
|
232 { |
|
233 header = CSmsHeader::NewL( CSmsMessage::NewL( iSmsTestUtils->FileSession(), |
|
234 aSettings.iOriginalSmsPDUType, |
|
235 CSmsEditorBuffer::NewL( *iSmsTestUtils->iRichText ) ) ); |
|
236 } |
|
237 |
|
238 |
|
239 CleanupStack::PushL( header ); |
|
240 |
|
241 // Add formating and a picture |
|
242 CEmsFormatIE* format = CEmsFormatIE::NewL( ); |
|
243 CleanupStack::PushL( format ); |
|
244 format->SetStartPosition(10); |
|
245 format->SetFormatLength(10); |
|
246 format->SetBold( ETrue ); |
|
247 header->Message( ).AddEMSInformationElementL( *format ); |
|
248 CleanupStack::PopAndDestroy( format ); |
|
249 |
|
250 CEmsPictureIE* pic = EmsTestUtils::CreatePictureL( 0 ); |
|
251 CleanupStack::PushL( pic ); |
|
252 pic->SetStartPosition( 0 ); |
|
253 header->Message().AddEMSInformationElementL( *pic ); |
|
254 CleanupStack::PopAndDestroy(pic); |
|
255 |
|
256 header->SetFromAddressL( KScriptItemRecipientsDef ); |
|
257 header->Message().SetServiceCenterAddressL( KScriptItemSCDef ); |
|
258 |
|
259 TTime now; |
|
260 now.UniversalTime( ); |
|
261 |
|
262 iSmsTestUtils->CreateMessageL( aSettings.iOriginalBoxId, |
|
263 entry, |
|
264 *header, |
|
265 *iSmsTestUtils->iRichText, |
|
266 now ); |
|
267 entry.SetReadOnly( ETrue ); |
|
268 |
|
269 CleanupStack::PopAndDestroy( header ); |
|
270 |
|
271 return entry.Id( ); |
|
272 |
|
273 } |
|
274 |
|
275 // Creates a random string of lenth aLen (is used to generate a random body) |
|
276 HBufC* CSMCMStepBase::CreateRandomLC( TInt aLen ) const |
|
277 { |
|
278 HBufC* msg = HBufC::NewLC( aLen ); |
|
279 TPtr msgPtr( msg->Des( ) ); |
|
280 msgPtr.SetLength( aLen ); |
|
281 |
|
282 TUint16* ptr = &msgPtr[ 0 ]; |
|
283 while( --aLen ) |
|
284 { |
|
285 // Create a random character between ASCII code 65 and 128 |
|
286 *ptr++ = TUint16( Math::Random( ) % ( 128 - 65 ) +65 ); |
|
287 } |
|
288 |
|
289 return msg; |
|
290 } |
|
291 |
|
292 TMsvId CSMCMStepBase::PerformForwardOrReplyOperationL( TMessageOperation aOperation, |
|
293 TMsvId aInFolder ) |
|
294 { |
|
295 TMsvPartList part = 0; |
|
296 CMsvOperationWait* wait = CMsvOperationWait::NewLC( ); |
|
297 wait->Start( ); |
|
298 |
|
299 CMsvOperation* operation = NULL; |
|
300 |
|
301 switch( aOperation ) |
|
302 { |
|
303 case EOperationReply: |
|
304 operation = iSmsClientMtm->ReplyL( aInFolder, part, wait->iStatus ); |
|
305 break; |
|
306 case EOperationForward: |
|
307 operation = iSmsClientMtm->ForwardL( aInFolder, part, wait->iStatus ); |
|
308 break; |
|
309 default: |
|
310 User::Leave( KErrNotSupported ); |
|
311 break; |
|
312 |
|
313 } |
|
314 |
|
315 |
|
316 CleanupStack::PushL( operation ); |
|
317 |
|
318 CActiveScheduler::Start( ); // Wait for operation to complete |
|
319 |
|
320 if ( wait->iStatus.Int() != KErrNone) |
|
321 { |
|
322 SetTestStepResult( EFail ); |
|
323 |
|
324 } |
|
325 |
|
326 // Extract the TMsvId new message created using the operation |
|
327 TPckgBuf< TMsvId > pkg; |
|
328 pkg.Copy( operation->ProgressL( ) ); |
|
329 TMsvId messageId = pkg( ); |
|
330 |
|
331 // Cleanup |
|
332 CleanupStack::PopAndDestroy( 2, wait ); // operation, wait |
|
333 |
|
334 return( messageId ); |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 TVerdict CSMCMStepBase::PerformTestL( TMsvId aOriginalMessageId, |
|
340 const TDesC& aNewText, |
|
341 const TMessageSettings& aSettings ) |
|
342 { |
|
343 // Lets point at the message which we'll forward |
|
344 iSmsClientMtm->SwitchCurrentEntryL( aOriginalMessageId ); |
|
345 |
|
346 TMsvId responseMessageId = PerformForwardOrReplyOperationL( aSettings.iOperation, KMsvDraftEntryId ); |
|
347 |
|
348 // Load the newly created FORWARD message |
|
349 iSmsClientMtm->SwitchCurrentEntryL( responseMessageId ); |
|
350 iSmsClientMtm->LoadMessageL( ); |
|
351 |
|
352 // Add new part of message |
|
353 iSmsClientMtm->Body( ).InsertL( 0, aNewText ); |
|
354 iSmsClientMtm->SaveMessageL( ); |
|
355 |
|
356 TVerdict result = CompareMessagesL( aOriginalMessageId, responseMessageId, aSettings ); |
|
357 |
|
358 return result; |
|
359 } |
|
360 |
|
361 |
|
362 TVerdict CSMCMStepBase::CompareMessagesL( TMsvId aOriginalMessageId, |
|
363 TMsvId aTargetMessageId, |
|
364 const TMessageSettings& aSettings ) |
|
365 { |
|
366 __ASSERT_ALWAYS( aOriginalMessageId != aTargetMessageId, User::Panic( SMSTEST_PANIC, KSmsTestUtilsPanicCannotCompareSameIds ) ); |
|
367 |
|
368 TVerdict result = EPass; |
|
369 // Load the Original Message |
|
370 iSmsClientMtm->SwitchCurrentEntryL( aOriginalMessageId ); |
|
371 iSmsClientMtm->LoadMessageL( ); |
|
372 |
|
373 TMsvEntry originalEntry = iSmsClientMtm->Entry( ).Entry( ); |
|
374 |
|
375 const CSmsHeader& originalHeader = iSmsClientMtm->SmsHeader( ); |
|
376 |
|
377 // copy original body text & description in a buffer to be used later |
|
378 CSmsEditorBuffer* origBuffer = CSmsEditorBuffer::NewL( iSmsClientMtm->Body( ) ); |
|
379 TInt length = origBuffer->Length( ); |
|
380 TBufC< KMaxBodyLength > originalMessage; |
|
381 |
|
382 TPtr origMsgPtr( originalMessage.Des( ) ); |
|
383 origBuffer->Extract( origMsgPtr, 0, length ); |
|
384 |
|
385 TBufC< CSmsBufferBase::EMaxBufLength > originalDescription; |
|
386 TPtr origDescPtr( originalDescription.Des( ) ); |
|
387 origDescPtr.Copy( originalEntry.iDescription ); |
|
388 |
|
389 // Load the Target message |
|
390 iSmsClientMtm->SwitchCurrentEntryL( aTargetMessageId ); |
|
391 iSmsClientMtm->LoadMessageL( ); |
|
392 |
|
393 TMsvEntry targetEntry = iSmsClientMtm->Entry( ).Entry( ); |
|
394 |
|
395 const CSmsHeader& targetHeader = iSmsClientMtm->SmsHeader( ); |
|
396 |
|
397 // Compare UTC Time of original and target messages |
|
398 if ( originalEntry.iDate >= targetEntry.iDate ) |
|
399 { |
|
400 result = EFail; |
|
401 |
|
402 } |
|
403 |
|
404 // Applicable to both Forward and Reply |
|
405 TBool originalTextIncluded = EFalse; |
|
406 TMsvPartList partList = KMsvMessagePartBody; |
|
407 if ( iSmsClientMtm->Find( originalMessage.Des( ), partList ) == KMsvMessagePartBody ) |
|
408 { |
|
409 originalTextIncluded = ETrue; |
|
410 |
|
411 } |
|
412 if ( !iSmsTestUtils->AreMessagesSameTextL( originalEntry.Id(), |
|
413 targetEntry.Id(), |
|
414 ETrue ) ) |
|
415 { |
|
416 result = EFail; |
|
417 } |
|
418 |
|
419 if ( aSettings.iOperation == EOperationReply ) |
|
420 { |
|
421 // nothing extra to do for a reply |
|
422 } |
|
423 |
|
424 if ( aSettings.iOperation == EOperationForward ) |
|
425 { |
|
426 TUint stateOrig = originalEntry.SendingState( ); |
|
427 TUint statetarg = targetEntry.SendingState( ); |
|
428 if ( ( originalEntry.SendingState( ) != targetEntry.SendingState( ) ) || |
|
429 ( originalEntry.iBioType != targetEntry.iBioType ) || |
|
430 ( originalDescription != targetEntry.iDescription) ) |
|
431 { |
|
432 result = EFail; |
|
433 |
|
434 } |
|
435 if ( !originalTextIncluded ) |
|
436 { |
|
437 INFO_PRINTF1( _L( "Comparison Failed - Forward messages expect original text to be included" ) ); |
|
438 result = EFail; |
|
439 |
|
440 } |
|
441 } |
|
442 |
|
443 return result; |
|
444 |
|
445 } |
|
446 |
|
447 void CSMCMStepBase::SetSettingsL( ) |
|
448 { |
|
449 CSmsSettings* settings = CSmsSettings::NewLC( ); |
|
450 |
|
451 CSmsAccount* account = CSmsAccount::NewLC( ); |
|
452 account->InitialiseDefaultSettingsL( *settings ); |
|
453 |
|
454 settings->AddServiceCenterL( KScriptItemSC1, KScriptItemSC1Def ); |
|
455 settings->AddServiceCenterL( KScriptItemSC2, KScriptItemSC2Def ); |
|
456 settings->AddServiceCenterL( KScriptItemSC3, KScriptItemSC3Def ); |
|
457 settings->SetDefaultServiceCenter( 2 ); |
|
458 |
|
459 settings->SetValidityPeriod( ESmsVPWeek ); |
|
460 settings->SetReplyQuoted( ETrue ); |
|
461 settings->SetRejectDuplicate( ETrue ); |
|
462 settings->SetDelivery( ESmsDeliveryImmediately ); |
|
463 settings->SetDeliveryReport( ETrue ); |
|
464 settings->SetReplyPath( EFalse ); |
|
465 settings->SetMessageConversion( ESmsConvPIDNone ); |
|
466 settings->SetCanConcatenate( ETrue ); |
|
467 settings->SetCharacterSet( TSmsDataCodingScheme::ESmsAlphabet8Bit ); |
|
468 settings->SetValidityPeriodFormat( TSmsFirstOctet::ESmsVPFSemiOctet ); |
|
469 settings->SetStatusReportHandling( CSmsSettings::EMoveReportToInboxVisible ); |
|
470 settings->SetSpecialMessageHandling( CSmsSettings::EMoveReportToInboxVisible ); |
|
471 |
|
472 account->SaveSettingsL( *settings ); |
|
473 |
|
474 iSmsTestUtils->iServiceSettings->CopyL( *settings); |
|
475 |
|
476 CleanupStack::PopAndDestroy( 2, settings ); |
|
477 |
|
478 } |
|
479 |
|
480 |
|