|
1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // VerifyEmail |
|
17 // [Action Parameters] |
|
18 // CMsvSession& session <input> : Reference to the session. |
|
19 // CMsvEntrySelection& SentMailSelection <input> : Reference to the |
|
20 // sent mail selection |
|
21 // CMsvEntrySelection& RecvMailSelection <input> : Reference to the |
|
22 // received mail selection |
|
23 // TInt Number of mails under test |
|
24 // CExpMailInfo A list of expected results |
|
25 // [Action Description] |
|
26 // Compares the recieved mails with the expected number s of lines to test POP3 TOP command |
|
27 // [APIs Used] |
|
28 // __ACTION_INFO_END__ |
|
29 // |
|
30 // |
|
31 |
|
32 /** |
|
33 @file |
|
34 */ |
|
35 // |
|
36 #include <e32std.h> |
|
37 #include <msvstd.h> |
|
38 #include <msvapi.h> |
|
39 #include <txtrich.h> |
|
40 #include <mtclreg.h> |
|
41 #include <miutmsg.h> |
|
42 #include <imcm.rsg> |
|
43 |
|
44 |
|
45 #include "CMtfTestActionUtils.h" |
|
46 #include "CMtfTestActionVerifyEmail.h" |
|
47 #include "CMtfTestCase.h" |
|
48 #include "CMtfTestActionParameters.h" |
|
49 #include "MtfTestActionUtilsUser.h" |
|
50 #include "TMtfTestParameterType.h" |
|
51 #include "CPop3MailInfo.h" |
|
52 |
|
53 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
54 #include "timrfc822datefield.h" |
|
55 #endif |
|
56 |
|
57 /** |
|
58 Function : NewL |
|
59 Description : Standard symbian 2 phase constructor |
|
60 @internalTechnology |
|
61 @param aMtfTestCase - CMtfTestCase test case reference for base class constructor |
|
62 @param aActionParameters - pointer to the parameters for this test action |
|
63 @return A CMtfTestAction pointer to the newly created CMtfTestActionVerifyEmail object |
|
64 @pre none |
|
65 @post none |
|
66 */ |
|
67 CMtfTestAction* CMtfTestActionVerifyEmail::NewL( CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters ) |
|
68 { |
|
69 CMtfTestActionVerifyEmail* self = new (ELeave) CMtfTestActionVerifyEmail(aTestCase); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(aActionParameters); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 |
|
76 /** |
|
77 Function : CMtfTestActionVerifyEmail constructor |
|
78 Description : Private constructor - must not leave |
|
79 @internalTechnology |
|
80 @param aTestCase - CMtfTestCase reference for the base class constructor |
|
81 @return N/A |
|
82 @pre none |
|
83 @post none |
|
84 */ |
|
85 CMtfTestActionVerifyEmail::CMtfTestActionVerifyEmail(CMtfTestCase& aTestCase) : |
|
86 CMtfSynchronousTestAction(aTestCase), |
|
87 iSession(NULL), |
|
88 iSentSelectionList(NULL), |
|
89 iInboxSelectionList(NULL) |
|
90 { |
|
91 } |
|
92 |
|
93 /** |
|
94 Function : CMtfTestActionVerifyEmail destructor |
|
95 Description : Destructor |
|
96 @internalTechnology |
|
97 @param N/A |
|
98 @return N/A |
|
99 @pre none |
|
100 @post none |
|
101 */ |
|
102 CMtfTestActionVerifyEmail::~CMtfTestActionVerifyEmail() |
|
103 { |
|
104 iExpResults.Reset(); |
|
105 iExpResults.Close(); |
|
106 } |
|
107 |
|
108 /** |
|
109 Function : LoadParametersL |
|
110 Description : Loads the test action parameters |
|
111 @internalTechnology |
|
112 @param none |
|
113 @return ETrue if parameters loaded Efalse on failure |
|
114 @pre none |
|
115 @post Upon failure TestCase status is EFail |
|
116 */ |
|
117 TBool CMtfTestActionVerifyEmail::LoadParametersL() |
|
118 { |
|
119 |
|
120 iSession = ObtainParameterReferenceL<CMsvSession> (TestCase(),ActionParameters().Parameter(0)); |
|
121 if( ! iSession ) |
|
122 { |
|
123 TestCase().ERR_PRINTF1(_L("Invalid session object")); |
|
124 TestCase().SetTestStepResult(EFail); |
|
125 return EFalse; |
|
126 } |
|
127 iSentSelectionList = ObtainParameterReferenceL<CMsvEntrySelection> (TestCase(), ActionParameters().Parameter(1)); |
|
128 if( ! iSentSelectionList ) |
|
129 { |
|
130 TestCase().ERR_PRINTF1(_L("Invalid sentSelectionList")); |
|
131 TestCase().SetTestStepResult(EFail); |
|
132 return EFalse; |
|
133 } |
|
134 iInboxSelectionList = ObtainParameterReferenceL<CMsvEntrySelection> (TestCase(), ActionParameters().Parameter(2)); |
|
135 if( ! iInboxSelectionList ) |
|
136 { |
|
137 TestCase().ERR_PRINTF1(_L("Invalid inboxSelectionList")); |
|
138 TestCase().SetTestStepResult(EFail); |
|
139 return EFalse; |
|
140 } |
|
141 |
|
142 if( iInboxSelectionList->Count() != iSentSelectionList->Count() ) |
|
143 { |
|
144 TestCase().ERR_PRINTF3( _L("iInboxSelectionList->Count(%d) != iSentSelectionList->Count(%d)"), |
|
145 iInboxSelectionList->Count(), iSentSelectionList->Count() ); |
|
146 TestCase().SetTestStepResult(EFail); |
|
147 return EFalse; |
|
148 } |
|
149 |
|
150 TInt numTests = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(3)); |
|
151 if( numTests != iInboxSelectionList->Count() ) |
|
152 { |
|
153 TestCase().ERR_PRINTF1(_L("iNumTests != iInboxSelectionList")); |
|
154 TestCase().SetTestStepResult(EFail); |
|
155 return EFalse; |
|
156 } |
|
157 iExpResults.Reset(); |
|
158 for( TInt i=0;i<numTests;i++) |
|
159 { |
|
160 CExpPop3MailInfo* pExp = ObtainParameterReferenceL<CExpPop3MailInfo> ( TestCase(), ActionParameters().Parameter(i+4) ); |
|
161 if( ! pExp ) |
|
162 { |
|
163 TestCase().ERR_PRINTF1(_L("Invalid expected mail Info")); |
|
164 TestCase().SetTestStepResult(EFail); |
|
165 return EFalse; |
|
166 } |
|
167 else |
|
168 { |
|
169 iExpResults.Append( pExp ); |
|
170 } |
|
171 } |
|
172 |
|
173 return ETrue; |
|
174 } |
|
175 |
|
176 /** |
|
177 Function : ExecuteActionL |
|
178 Description : Test framework entry point for CMtfTestActionVerifyEmail test action |
|
179 @internalTechnology |
|
180 @param none |
|
181 @return void |
|
182 @pre none |
|
183 @post TestCase status EPass if tests passed otherwise EFail |
|
184 */ |
|
185 void CMtfTestActionVerifyEmail::ExecuteActionL() |
|
186 { |
|
187 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionVerifyEmail); |
|
188 if( LoadParametersL() ) |
|
189 { |
|
190 User::LeaveIfError( iFs.Connect() ); |
|
191 CleanupClosePushL(iFs); |
|
192 // Normally do not push an object that is a data member of another object. |
|
193 // But in this case we want to close early if we get a leave. |
|
194 // Otherwise the iFs would be open till the thread had begun to die. |
|
195 |
|
196 if( TestCase().TestStepResult() == EPass) |
|
197 { |
|
198 CheckPartialDownloadedFlag(); |
|
199 CMsvEntry* recvMsvEntry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
200 CleanupStack::PushL( recvMsvEntry ); |
|
201 CMsvEntry* sentMsvEntry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
202 CleanupStack::PushL( sentMsvEntry ); |
|
203 |
|
204 for( TInt i=0;i<iInboxSelectionList->Count();i++) |
|
205 { |
|
206 recvMsvEntry->SetEntryL( iInboxSelectionList->At(i) ); |
|
207 TMsvEntry recvEntry = recvMsvEntry->Entry(); |
|
208 for( TInt j=0;j<iSentSelectionList->Count();j++) |
|
209 { |
|
210 sentMsvEntry->SetEntryL( iSentSelectionList->At(j) ); |
|
211 TMsvEntry sentEntry = sentMsvEntry->Entry(); |
|
212 if( recvEntry.iDescription.Compare( sentEntry.iDescription ) == 0 ) |
|
213 { |
|
214 CExpPop3MailInfo* pExpMailInfo = NULL; |
|
215 for( int k = 0;k<iExpResults.Count();k++) |
|
216 { |
|
217 if( iExpResults[k]->GetDescription().Compare( recvEntry.iDescription ) == 0 ) |
|
218 { |
|
219 pExpMailInfo = iExpResults[k]; |
|
220 break; |
|
221 } |
|
222 } |
|
223 if( ! pExpMailInfo ) |
|
224 { |
|
225 TestCase().ERR_PRINTF2(_L("Test %d failed could not retrieve expected mail info"), j+1 ); |
|
226 TestCase().SetTestStepResult(EFail); |
|
227 break; |
|
228 } |
|
229 |
|
230 |
|
231 if( ! DoCompareL( recvEntry, *pExpMailInfo, sentEntry ) ) |
|
232 { |
|
233 TestCase().INFO_PRINTF2(_L("Test %d failed"), j+1 ); |
|
234 TestCase().SetTestStepResult(EFail); |
|
235 } |
|
236 } |
|
237 } |
|
238 } |
|
239 CleanupStack::PopAndDestroy(2, recvMsvEntry ); // recvMsvEntry, sentMsvEntry |
|
240 } |
|
241 |
|
242 CleanupStack::PopAndDestroy(&iFs); |
|
243 } |
|
244 |
|
245 TestCase().INFO_PRINTF1( _L("Test Action CMtfTestActionVerifyEmail Completed") ); |
|
246 TestCase().ActionCompletedL(*this); |
|
247 } |
|
248 |
|
249 /** |
|
250 Function : CheckPartialFlagOfRecvEntry |
|
251 Description : checks the Partialdownloaded flag |
|
252 */ |
|
253 void CMtfTestActionVerifyEmail::CheckPartialDownloadedFlag() |
|
254 { |
|
255 CMsvEntry* recvMsvEntry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
256 CleanupStack::PushL( recvMsvEntry ); |
|
257 TMsvEmailEntry entry; |
|
258 TMsvId service = KMsvNullIndexEntryId; |
|
259 for( TInt i = 0; i < iInboxSelectionList->Count(); ++i) |
|
260 { |
|
261 iSession->GetEntry((iInboxSelectionList->At(i)), service, entry); |
|
262 if(entry.PartialDownloaded()) |
|
263 { |
|
264 TestCase().INFO_PRINTF1( _L("Partial downloaded flag is ETrue") ); |
|
265 } |
|
266 else |
|
267 { |
|
268 TestCase().INFO_PRINTF1( _L("Partial downloaded flag is EFalse") ); |
|
269 } |
|
270 } |
|
271 CleanupStack::PopAndDestroy(); |
|
272 } |
|
273 |
|
274 /** |
|
275 Function : DoCompareL |
|
276 Description : Comparison of 2 email messages identified by TMsvEntry |
|
277 @internalTechnology |
|
278 @param aRecvEntry - The recieved email identifier |
|
279 @param aMailInfo - expected state of the recieved email |
|
280 @param aSentEntry - Identifier of the original sent email foir comparison purposes |
|
281 @return ETrue if emails match EFalse otherwise |
|
282 @pre Email must have been sent and recieved correctly and parameters loaded ok |
|
283 @post none |
|
284 */ |
|
285 TBool CMtfTestActionVerifyEmail::DoCompareL( TMsvEntry& aRecvEntry, CExpPop3MailInfo& aMailInfo, TMsvEntry& aSentEntry ) |
|
286 { |
|
287 TBool ret = ETrue; |
|
288 TBool footerExists = EFalse; |
|
289 TInt footersize = 0; |
|
290 |
|
291 |
|
292 TInt nLines = GetMessageLinesL(aRecvEntry, KUidMsvEmailTextEntry, footerExists, footersize); |
|
293 if( nLines != aMailInfo.GetNumLinesBodyText() ) |
|
294 { |
|
295 TestCase().ERR_PRINTF3(_L("Lines of body text wrong actual = %d expected = %d!"), nLines, aMailInfo.GetNumLinesBodyText() ); |
|
296 ret = EFalse; |
|
297 } |
|
298 nLines = GetMessageLinesL(aRecvEntry, KUidMsvEmailHtmlEntry, footerExists, footersize ); |
|
299 |
|
300 if( nLines != aMailInfo.GetNumLinesHtml() ) |
|
301 { |
|
302 TestCase().ERR_PRINTF3(_L("HTML size wrong actual = %d expected = %d!"), nLines, aMailInfo.GetNumLinesHtml() ); |
|
303 ret = EFalse; |
|
304 } |
|
305 |
|
306 if( ! CheckAttachmentsL( aRecvEntry, aMailInfo, aSentEntry ) ) |
|
307 { |
|
308 TestCase().ERR_PRINTF1(_L("Attachment comparison failed !")); |
|
309 ret = EFalse; |
|
310 } |
|
311 |
|
312 if( ! footerExists && aMailInfo.GetFooterExpected() ) |
|
313 { |
|
314 TestCase().ERR_PRINTF1(_L("An expected footer was missing !")); |
|
315 ret = EFalse; |
|
316 } |
|
317 else if( footerExists && ! aMailInfo.GetFooterExpected() ) |
|
318 { |
|
319 TestCase().ERR_PRINTF1(_L("An unexpected footer was found !")); |
|
320 ret = EFalse; |
|
321 } |
|
322 else if(aMailInfo.GetFooterExpected() && aMailInfo.GetFooterSize()!=0 |
|
323 && aMailInfo.GetFooterSize() != footersize) |
|
324 { |
|
325 TestCase().ERR_PRINTF3(_L("KB left on server size wrong = %d expected = %d!"), footersize, aMailInfo.GetFooterSize()); |
|
326 ret = EFalse; |
|
327 } |
|
328 return ret; |
|
329 } |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 // |
|
335 // CAttachmentItem : Used to ensure that MMsvAttachmentManager is not destroyed until we want it to be. |
|
336 // To do this we need to preserve certain objects CImEmailMessage, which if disappeared |
|
337 // would invalidate MMsvAttachmentManager. |
|
338 // But we also want to delete these objects in a contraolled manner |
|
339 // after we have finished with MMsvAttachmentManager. |
|
340 |
|
341 void CAttachmentItem::ConstructL( CMsvSession& aSession, TMsvEntry aEntry) |
|
342 { |
|
343 |
|
344 iMsvEntry = aSession.GetEntryL(aEntry.Id()); |
|
345 |
|
346 iMsvEntry->SetEntryL(aEntry.Id()); |
|
347 iEmailMsg = CImEmailMessage::NewL(*iMsvEntry); |
|
348 |
|
349 CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC(); |
|
350 iEmailMsg->GetAttachmentsListL( waiter->iStatus, aEntry.Id(), |
|
351 CImEmailMessage::EAllAttachments, |
|
352 CImEmailMessage::EThisMessageOnly); |
|
353 waiter->Start(); |
|
354 |
|
355 CleanupStack::PopAndDestroy( 1 , waiter ); |
|
356 |
|
357 } |
|
358 |
|
359 |
|
360 CAttachmentItem* CAttachmentItem::NewL( CMsvSession& aSession, TMsvEntry aEntry ) |
|
361 { |
|
362 CAttachmentItem* self=CAttachmentItem::NewLC( aSession, aEntry ); |
|
363 CleanupStack::Pop(self); |
|
364 |
|
365 return self; |
|
366 } |
|
367 |
|
368 CAttachmentItem* CAttachmentItem::NewLC( CMsvSession& aSession, TMsvEntry aEntry ) |
|
369 { |
|
370 CAttachmentItem* self=new (ELeave) CAttachmentItem; |
|
371 CleanupStack::PushL(self); |
|
372 |
|
373 self->ConstructL(aSession, aEntry); |
|
374 |
|
375 return self; |
|
376 } |
|
377 |
|
378 CAttachmentItem::~CAttachmentItem() |
|
379 { |
|
380 delete iEmailMsg; |
|
381 delete iMsvEntry; |
|
382 } |
|
383 |
|
384 |
|
385 MMsvAttachmentManager& CAttachmentItem::MMsvAttachmentManager() const |
|
386 { |
|
387 return (iEmailMsg->AttachmentManager()); |
|
388 } |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 /** |
|
394 Function : CheckAttachmentsL |
|
395 Description : Compares attachments for the email messages aRecvEntry and aSentEntry using expected results in aMailInfo |
|
396 @internalTechnology |
|
397 @param aRecvEntry - an identifier for the recieved email |
|
398 @param aMailInfo - expected state of recieved email attachments |
|
399 @param aSentEntry - an identifier for the original email |
|
400 @return ETrue if attachments match otherwise EFalse |
|
401 @pre aRecvEntry and aSentEntry must be valid email identifiers |
|
402 @post none |
|
403 */ |
|
404 TBool CMtfTestActionVerifyEmail::CheckAttachmentsL( TMsvEntry& aRecvEntry, CExpPop3MailInfo& aMailInfo, TMsvEntry& aSentEntry ) |
|
405 { |
|
406 TBool ret = ETrue; |
|
407 CAttachmentItem* recvManager = CAttachmentItem::NewLC( *iSession, aRecvEntry ); |
|
408 CAttachmentItem* sentManager = CAttachmentItem::NewLC( *iSession, aSentEntry ); |
|
409 |
|
410 TInt recvCount = recvManager->MMsvAttachmentManager().AttachmentCount(); |
|
411 TInt sentCount = sentManager->MMsvAttachmentManager().AttachmentCount(); |
|
412 |
|
413 TFileName recvFileName; |
|
414 TFileName sentFileName; |
|
415 |
|
416 if( recvCount == aMailInfo.GetNumAttachments() ) |
|
417 { |
|
418 for( TInt i=0;i<recvCount;i++ ) |
|
419 { |
|
420 for( TInt j=0;j<sentCount;j++ ) |
|
421 { |
|
422 CMsvAttachment* recvAttInfo = recvManager->MMsvAttachmentManager().GetAttachmentInfoL(i); |
|
423 CleanupStack::PushL(recvAttInfo); |
|
424 |
|
425 CMsvAttachment* sentAttInfo = sentManager->MMsvAttachmentManager().GetAttachmentInfoL(j); |
|
426 CleanupStack::PushL(sentAttInfo); |
|
427 |
|
428 if( recvAttInfo->AttachmentName().Compare( sentAttInfo->AttachmentName() ) == 0 ) |
|
429 { |
|
430 recvFileName = recvAttInfo->FilePath(); |
|
431 sentFileName = sentAttInfo->FilePath(); |
|
432 ret = CompareFilesL( recvFileName, sentFileName ); |
|
433 } |
|
434 CleanupStack::PopAndDestroy(2, recvAttInfo); |
|
435 } |
|
436 } |
|
437 } |
|
438 else |
|
439 { |
|
440 TestCase().INFO_PRINTF3( _L("Warning - Expected attachments mismatch recieved (%d) expected (%d)"), |
|
441 recvCount, aMailInfo.GetNumAttachments() ); |
|
442 ret = EFalse; |
|
443 } |
|
444 |
|
445 CleanupStack::PopAndDestroy(2, recvManager); // recvManager, sentManager |
|
446 return ret; |
|
447 } |
|
448 |
|
449 |
|
450 /** |
|
451 Function : CompareFilesL |
|
452 Description : Performs byte for byte copmparison of the files indicated by aFileName1 and aFileName2 |
|
453 @internalTechnology |
|
454 @param aFileName1 - filename of first file to be compared |
|
455 @param aFileName2 - filename of second file to be compared |
|
456 @return ETrue if files match, EFalse otherwise |
|
457 @pre Filenames must be valid or function will leave |
|
458 @post none |
|
459 */ |
|
460 TBool CMtfTestActionVerifyEmail::CompareFilesL( TFileName& aFileName1, TFileName& aFileName2 ) |
|
461 { |
|
462 |
|
463 TBool ret = ETrue; |
|
464 RFile file1, file2; |
|
465 |
|
466 User::LeaveIfError( file1.Open( iFs, aFileName1, EFileRead ) ); |
|
467 User::LeaveIfError( file2.Open( iFs, aFileName2, EFileRead ) ); |
|
468 |
|
469 TInt sz1, sz2; |
|
470 User::LeaveIfError( file1.Size(sz1) ); |
|
471 User::LeaveIfError( file2.Size(sz2) ); |
|
472 |
|
473 if( sz1 != sz2 ) |
|
474 { |
|
475 TestCase().ERR_PRINTF3( _L("File size mismatch 1(%d) 2(%d)"), sz1, sz2 ); |
|
476 ret = EFalse; |
|
477 } |
|
478 else |
|
479 { |
|
480 TBuf8<1> char1; |
|
481 TBuf8<1> char2; |
|
482 TInt len1, len2; |
|
483 do |
|
484 { |
|
485 file1.Read(char1); |
|
486 file2.Read(char2); |
|
487 len1 = char1.Length(); |
|
488 len2 = char2.Length(); |
|
489 if( char1.Compare( char2 ) != 0 ) |
|
490 { |
|
491 ret = EFalse; |
|
492 break; |
|
493 } |
|
494 } |
|
495 while( len1 && len2 ); |
|
496 } |
|
497 file1.Close(); |
|
498 file2.Close(); |
|
499 return ret; |
|
500 } |
|
501 |
|
502 /** |
|
503 Function : GetMessageLinesL |
|
504 Description : Counts the number of lines in a message's HTML or body text |
|
505 @internalTechnology |
|
506 @param aEntry - email message identifier |
|
507 @param aUid - request identifier KUidMsvEmailHtmlEntry or KUidMsvEmailTextEntry at present |
|
508 @param aFooterExists - reference to a boolean variable only used when aUid == KUidMsvEmailTextEntry |
|
509 @param aFooterSize - expected KB left on server inserted into footer string if present |
|
510 @return Returns the number of lines in the requested message part |
|
511 @pre aEntry must be a valid email identifier |
|
512 @post none |
|
513 */ |
|
514 TInt CMtfTestActionVerifyEmail::GetMessageLinesL(TMsvEntry& aEntry, TUid aUid, TBool& aFooterExists, TInt &aFooterSize ) |
|
515 { |
|
516 TInt lines = 0; |
|
517 |
|
518 TMsvId msgPartIndex = GetMessagePartIndexL(aEntry,aUid); |
|
519 |
|
520 if(msgPartIndex) |
|
521 { |
|
522 CMsvEntry* msvEntry = iSession->GetEntryL(msgPartIndex); |
|
523 CleanupStack::PushL(msvEntry); |
|
524 |
|
525 msvEntry->SetEntryL(msgPartIndex); |
|
526 if( aUid == KUidMsvEmailTextEntry ) |
|
527 { |
|
528 lines = CountLinesOfBodyTextL( *msvEntry, aFooterExists, aFooterSize ); |
|
529 } |
|
530 else if( aUid == KUidMsvEmailHtmlEntry ) |
|
531 { |
|
532 lines = CountLinesOfHtmlL( *msvEntry ); |
|
533 } |
|
534 |
|
535 CleanupStack::PopAndDestroy(msvEntry); |
|
536 } |
|
537 return lines; |
|
538 } |
|
539 |
|
540 /** |
|
541 Function : CountLinesOfBodyTextL |
|
542 Description : Counts the lines of body text in the email aEntry |
|
543 @internalTechnology |
|
544 @param aEntry - a reference to an object representing the email |
|
545 @param aFooterExists - reference to a boolean variable - set to ETrue if the footer string is found in the body text |
|
546 @param aFooterSize - expected KB left on server inserted into footer string if present |
|
547 @return number of lines in the body text |
|
548 @pre aEntry must be a valid email object |
|
549 @post none |
|
550 */ |
|
551 TInt CMtfTestActionVerifyEmail::CountLinesOfBodyTextL( CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize) |
|
552 { |
|
553 _LIT(KServerMessage,"*This message was transferred with a trial version of CommuniGate(r) Pro*"); |
|
554 TInt lines = 0; |
|
555 aFooterExists=EFalse; |
|
556 aFooterSize=0; |
|
557 aEntry.SetEntryL(aEntry.EntryId()); |
|
558 if(aEntry.HasStoreL()) |
|
559 { |
|
560 CMsvStore* msvStore1= aEntry.ReadStoreL(); |
|
561 CleanupStack::PushL(msvStore1); |
|
562 CParaFormatLayer* paraFormatLayer1 = CParaFormatLayer::NewL(); |
|
563 CleanupStack::PushL(paraFormatLayer1); |
|
564 CCharFormatLayer* charFormatLayer1 = CCharFormatLayer::NewL(); |
|
565 CleanupStack::PushL(charFormatLayer1); |
|
566 CRichText* bodyText1=CRichText::NewL( paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256); |
|
567 CleanupStack::PushL(bodyText1); |
|
568 |
|
569 bodyText1->Reset(); |
|
570 if ( msvStore1->HasBodyTextL()) |
|
571 { |
|
572 msvStore1->RestoreBodyTextL(*bodyText1); |
|
573 TUint16 val = CEditableText::ELineBreak; |
|
574 TInt n = 0; |
|
575 TInt pos = 0; |
|
576 for(;;) |
|
577 { |
|
578 TPtrC bodyText = bodyText1->Read(pos); |
|
579 n = bodyText.Find( &val, 1 ); |
|
580 if( n < 0 ) |
|
581 break; |
|
582 lines++; |
|
583 pos += n+1; |
|
584 |
|
585 //This Check is needed to ignore the disclaimer line introduced by communigate Pro Server |
|
586 TInt fpos = bodyText.FindC(KServerMessage); |
|
587 if (fpos != KErrNotFound) |
|
588 { |
|
589 lines--; |
|
590 } |
|
591 } |
|
592 TPtrC pBt = bodyText1->Read(0); |
|
593 aFooterExists = CheckIfFooterMessageExistsL( pBt , aFooterSize); |
|
594 } |
|
595 CleanupStack::PopAndDestroy(4, msvStore1); |
|
596 } |
|
597 return lines; |
|
598 } |
|
599 |
|
600 /** |
|
601 Function : CountLinesOfHtmlL |
|
602 Description : Counts the number of lines of HTML |
|
603 @internalTechnology |
|
604 @param aEntry - a reference to an object representing the email |
|
605 @return number of lines of HTML |
|
606 @pre aEntry must be a valid email object |
|
607 @post none |
|
608 */ |
|
609 TInt CMtfTestActionVerifyEmail::CountLinesOfHtmlL( CMsvEntry& aEntry ) |
|
610 { |
|
611 TInt lines = 0; |
|
612 aEntry.SetEntryL(aEntry.EntryId()); |
|
613 |
|
614 CMsvStore* store = aEntry.ReadStoreL(); |
|
615 CleanupStack::PushL(store); |
|
616 |
|
617 MMsvAttachmentManager& attManager = store->AttachmentManagerL(); |
|
618 |
|
619 RFile htmlFile = attManager.GetAttachmentFileL(0); |
|
620 CleanupClosePushL(htmlFile); |
|
621 |
|
622 _LIT8( KFindData, "\r\n" ); |
|
623 TInt htmlSize = 0; |
|
624 User::LeaveIfError( htmlFile.Size(htmlSize) ); |
|
625 HBufC8* fBuf = HBufC8::NewLC( htmlSize ); |
|
626 TPtr8 p = fBuf->Des(); |
|
627 htmlFile.Read( p ); |
|
628 TInt pos = 0; |
|
629 for(;;) |
|
630 { |
|
631 pos = p.Find( KFindData ); |
|
632 if( pos < 0 ) |
|
633 break; |
|
634 p = p.Mid(pos+2); |
|
635 lines++; |
|
636 } |
|
637 |
|
638 CleanupStack::PopAndDestroy( fBuf ); |
|
639 CleanupStack::PopAndDestroy(); // htmlFile |
|
640 CleanupStack::PopAndDestroy(store); |
|
641 |
|
642 |
|
643 return lines; |
|
644 } |
|
645 |
|
646 /** |
|
647 Function : GetMessagePartIndexL |
|
648 Description : Retrieves the part index id for the email identified by aEntry |
|
649 @internalTechnology |
|
650 @param aEntry - a valid email identifier |
|
651 @param aUid - an identifier tfor the type of message part to be retrieved |
|
652 @return TMsvId - message part identifier |
|
653 @pre none |
|
654 @post none |
|
655 */ |
|
656 TMsvId CMtfTestActionVerifyEmail::GetMessagePartIndexL(TMsvEntry& aEntry, TUid aUid) |
|
657 { |
|
658 static TBool msgPartFound = EFalse; |
|
659 TMsvId msgPartId = 0; |
|
660 CMsvEntry* baseEntry = iSession->GetEntryL(aEntry.Id()); |
|
661 CleanupStack::PushL(baseEntry); |
|
662 CMsvEntrySelection* selection = baseEntry->ChildrenL(); |
|
663 CleanupStack::PushL(selection); |
|
664 TInt count = selection->Count(); |
|
665 TInt ind1; |
|
666 CMsvEntry* entry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
667 CleanupStack::PushL(entry); |
|
668 for (ind1=0, msgPartFound=EFalse; ind1 < count; ind1++ ) |
|
669 { |
|
670 if(msgPartFound) |
|
671 { |
|
672 break; |
|
673 } |
|
674 TMsvId childId = selection->At(ind1); |
|
675 entry->SetEntryL(childId); |
|
676 |
|
677 if ( entry->Entry().iType == aUid) |
|
678 { |
|
679 msgPartId = childId; |
|
680 break; |
|
681 } |
|
682 else if (entry->Entry().iType == KUidMsvFolderEntry) |
|
683 { |
|
684 TMsvEntry ent = entry->Entry(); |
|
685 msgPartId = GetMessagePartIndexL( ent, aUid); |
|
686 } |
|
687 } |
|
688 CleanupStack::PopAndDestroy(entry); |
|
689 CleanupStack::PopAndDestroy(selection); |
|
690 CleanupStack::PopAndDestroy(baseEntry); |
|
691 return msgPartId; |
|
692 } |
|
693 |
|
694 /** |
|
695 Function : CheckIfFooterMessageExistsL |
|
696 Description : Checks the email for the presence of the footer string |
|
697 @internalTechnology |
|
698 @param aRecvBodyText - reference to a descriptor holding the body text |
|
699 @param aFooterSize - the expected number of KB remaining on the server which has been inserted into the footer string |
|
700 @return ETrue if footer string found otherwise EFalse |
|
701 @pre PARTIAL_DOWNLOAD_FOOTER_MESSAGE must be a valid string resource identifier |
|
702 @post none |
|
703 */ |
|
704 TBool CMtfTestActionVerifyEmail::CheckIfFooterMessageExistsL(TPtrC& aRecvBodyText , TInt& aFooterSize ) |
|
705 { |
|
706 |
|
707 RResourceFile resFile; |
|
708 CMtfTestActionUtils::OpenResourceFileL(resFile, iFs, KImEngineResourceFile ); // NB leaves if file not found |
|
709 TCleanupItem close( CMtfTestActionUtils::CloseResourceFile, &resFile ); |
|
710 CleanupStack::PushL( close ); |
|
711 |
|
712 HBufC8* buf = NULL; |
|
713 buf = resFile.AllocReadLC( PARTIAL_DOWNLOAD_FOOTER_MESSAGE ); |
|
714 TResourceReader reader; |
|
715 reader.SetBuffer(buf); |
|
716 |
|
717 HBufC* resourceBuf = (reader.ReadTPtrC()).AllocL(); |
|
718 CleanupStack::PushL( resourceBuf ); |
|
719 |
|
720 TInt len = resourceBuf->Find( _L("%d") ); |
|
721 const TInt KBufLen = 256; |
|
722 TBuf<KBufLen> findBuf; |
|
723 |
|
724 if( len == KErrNotFound ) |
|
725 len = resourceBuf->Length(); |
|
726 |
|
727 if( len > KBufLen ) |
|
728 len = KBufLen; |
|
729 |
|
730 findBuf.Copy( resourceBuf->Ptr(), len ); |
|
731 len = aRecvBodyText.Find( findBuf ); |
|
732 |
|
733 if(len>=0) |
|
734 { |
|
735 TPtrC rest=aRecvBodyText.Right(aRecvBodyText.Length()-len-findBuf.Length()); |
|
736 TLex lex(rest.Left(rest.Locate(TChar(' ')))); |
|
737 lex.Val(aFooterSize); |
|
738 } |
|
739 else |
|
740 { |
|
741 aFooterSize=0; |
|
742 } |
|
743 |
|
744 CMtfTestActionUtils::CloseResourceFile( &resFile ); |
|
745 CleanupStack::PopAndDestroy(3); // buf, resourceBuf, close |
|
746 return ( len != KErrNotFound ); |
|
747 } |