|
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 // T_IMCV_Transform_Receive |
|
15 // Component: IMUT |
|
16 // Owner: Ibrahim Rahman |
|
17 // Brief description of test harness: |
|
18 // Testing the System Default Charset setting in Messaging. |
|
19 // This is set in the imcm resource file. |
|
20 // This particular test runs the parsing code, |
|
21 // simulating effect of downloading messages. |
|
22 // ( See also t_imcv_transform_send ) |
|
23 // Detailed description of test harness: |
|
24 // Extract RFC data from files save to message store after conversion. |
|
25 // Query the message store, saved info to set of output files. |
|
26 // Compare these files against expected results. |
|
27 // Test is run with the ascii, utf7 and an unknown charset value. |
|
28 // Intermediate files produced while running test harness: |
|
29 // in directory : /msglogs/t_imcv_transform_receive/ |
|
30 // NoneEntry_822Headers.txt |
|
31 // NoneEntry_Files.txt |
|
32 // NoneEntry_MimeHeaders.txt |
|
33 // NoneEntry_RichTextBodies.txt |
|
34 // NoneEntry_Structure.txt |
|
35 // UTF7Entry_822Headers.txt |
|
36 // UTF7Entry_Files.txt |
|
37 // UTF7Entry_MimeHeaders.txt |
|
38 // UTF7Entry_RichTextBodies.txt |
|
39 // UTF7Entry_Structure.txt |
|
40 // UnknownEntry_822Headers.txt |
|
41 // UnknownEntry_Files.txt |
|
42 // UnknownEntry_MimeHeaders.txt |
|
43 // UnknownEntry_RichTextBodies.txt |
|
44 // UnknownEntry_Structure.txt |
|
45 // Output files produced by running test harness: |
|
46 // \msglogs\t_imcv_transform_receive* |
|
47 // Testing encoding/charset setting during the receiving of messages. |
|
48 // Test code is a version of t_imcv00 |
|
49 // |
|
50 // |
|
51 |
|
52 #include <txtetext.h> |
|
53 #include <txtrich.h> |
|
54 #include <bautils.h> |
|
55 #include <miuthdr.h> |
|
56 #include <miutmsg.h> |
|
57 #include <miutset.h> //KUidMsgTypePOP3 |
|
58 #include <imutdll.h> |
|
59 #include <imcvtext.h> |
|
60 #include <imcvrecv.h> |
|
61 #include <imcvsend.h> |
|
62 |
|
63 //Oyster includes |
|
64 #include <msvstd.h> |
|
65 #include <msvids.h> |
|
66 #include <msvuids.h> |
|
67 #include <msvruids.h> |
|
68 #include <msvreg.h> |
|
69 |
|
70 #include "msvindexadapter.h" |
|
71 |
|
72 #include "MSVSERV.H" |
|
73 #include <msventry.h> |
|
74 #include <msvapi.h> |
|
75 #include <mtclbase.h> |
|
76 #include "emailtestutils.h" |
|
77 #include <s32strm.h> |
|
78 #include <f32file.h> |
|
79 |
|
80 |
|
81 #define KComponent _L("IMUT") |
|
82 |
|
83 // File paths used by test program |
|
84 #define KTestMessageDir _L("imcv\\Transform_Receive\\") |
|
85 #define KTest822FilesDir _L("rfc822\\Transform_Receive\\") |
|
86 #define KTestLibsDir _L("c:\\system\\data\\") |
|
87 |
|
88 _LIT(KUnknownResource, "imcm.rsc.unknown"); |
|
89 |
|
90 LOCAL_D RTest test(_L("T_IMCV_Transform_Receive test harness")); |
|
91 LOCAL_D CTrapCleanup* theCleanup; |
|
92 LOCAL_D CEmailTestUtils* testUtils; |
|
93 |
|
94 LOCAL_C CTestActive* active; |
|
95 |
|
96 //---------------------------------------------------------------------------------------- |
|
97 LOCAL_C void ReadDataL(CImRecvConvert* recvConvert, TFileName fileName) |
|
98 //---------------------------------------------------------------------------------------- |
|
99 { |
|
100 // open the file |
|
101 RFile file; |
|
102 |
|
103 TInt anError = file.Open(testUtils->FileSession(), fileName, EFileShareAny); |
|
104 if(anError != KErrNone) |
|
105 { |
|
106 test.Printf(TRefByValue<const TDesC>_L("\r\nFile open error %d"), anError); |
|
107 test.Getch(); |
|
108 User::Leave(KErrNotFound); |
|
109 } |
|
110 |
|
111 test.Printf(TRefByValue<const TDesC>_L("Data from %s...\r\n"), fileName.PtrZ()); |
|
112 |
|
113 // read the file into the conversion object |
|
114 HBufC8* lineBuffer = HBufC8::NewLC(1024); |
|
115 TPtr8 line = lineBuffer->Des(); |
|
116 |
|
117 TBuf8<1> aChar; |
|
118 TBool finished = FALSE; |
|
119 |
|
120 recvConvert->ResetL(); |
|
121 // supply a new attachment path since previous one is discarded by call to Reset() |
|
122 |
|
123 do { |
|
124 line.FillZ(); |
|
125 line.SetLength(0); |
|
126 // compile a line one char at a time |
|
127 do { |
|
128 file.Read(aChar, 1); |
|
129 if(aChar.Length()) |
|
130 line.Append(aChar); |
|
131 else |
|
132 finished = TRUE; |
|
133 // stop at the end of line or no more data |
|
134 } while(aChar.Length() && aChar[0] != 0x0A); |
|
135 if(!line.Length()) |
|
136 break; |
|
137 /***********************************************/ |
|
138 /* -- This is where we actually do the work -- */ |
|
139 /***********************************************/ |
|
140 recvConvert->ParseNextField(line); // This function doesnt actually leave, any leaves are relayed to the MessageCompleteL() function |
|
141 |
|
142 } while(!finished); |
|
143 |
|
144 TRAPD(err, recvConvert->MessageCompleteL()); |
|
145 if(err!=KErrNone) |
|
146 { |
|
147 // At this point the message should be deleted and CImRecvConvert should be Reset() |
|
148 test.Printf(TRefByValue<const TDesC>_L("\r\nError %d occured during the conversion of Message %d"), err, recvConvert->EntryId()); |
|
149 } |
|
150 CleanupStack::PopAndDestroy(); // lineBuffer |
|
151 |
|
152 file.Close(); |
|
153 } |
|
154 |
|
155 |
|
156 //---------------------------------------------------------------------------------------- |
|
157 LOCAL_C void TestReadL(TFileName filename) |
|
158 //---------------------------------------------------------------------------------------- |
|
159 { |
|
160 CImRecvConvert* recvConvert = CImRecvConvert::NewLC(testUtils->FileSession(), testUtils->iServerEntry, |
|
161 KUidMsgTypePOP3, KMsvLocalServiceIndexEntryId); |
|
162 |
|
163 recvConvert->SetMsvId(KMsvGlobalOutBoxIndexEntryId); //Set the TMsvServerEntry to correct context |
|
164 |
|
165 //TRAPD(error,ReadDataWithOOMTestingL(recvConvert, filename)); // Do the stuff |
|
166 TRAPD(error,ReadDataL(recvConvert, filename)); // Do the stuff |
|
167 if (error) |
|
168 { |
|
169 test.Printf(TRefByValue<const TDesC>_L("\r\nReadData Failed, Error %d"), error); |
|
170 test.Getch(); |
|
171 } |
|
172 CleanupStack::PopAndDestroy(); //recvConvert |
|
173 } |
|
174 |
|
175 |
|
176 //---------------------------------------------------------------------------------------- |
|
177 LOCAL_C void UpL() |
|
178 //---------------------------------------------------------------------------------------- |
|
179 { |
|
180 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
181 CActiveScheduler::Install(scheduler); |
|
182 CleanupStack::PushL(scheduler); |
|
183 |
|
184 testUtils = CEmailTestUtils::NewL(test); |
|
185 |
|
186 TParse parsedFileName; |
|
187 TFileName name; |
|
188 |
|
189 testUtils->ResolveLogFile(name, parsedFileName); |
|
190 |
|
191 testUtils->FileSession().RmDir(parsedFileName.DriveAndPath()); |
|
192 |
|
193 if(!testUtils->FileSession().MkDirAll(parsedFileName.DriveAndPath())) |
|
194 { |
|
195 TFileName buffer(parsedFileName.FullName()); |
|
196 test.Printf(TRefByValue<const TDesC>_L("Created %S directory\n"),&buffer); |
|
197 } |
|
198 |
|
199 testUtils->CreateAllTestDirectories(); |
|
200 |
|
201 name.Copy(KTest822FilesDir); |
|
202 testUtils->ResolveFile(KComponent, name, parsedFileName); |
|
203 testUtils->FileSession().SetSessionPath(parsedFileName.FullName()); |
|
204 testUtils->CleanMessageFolderL(); |
|
205 testUtils->GoServerSideL(); |
|
206 |
|
207 active = new (ELeave) CTestActive(); |
|
208 active->StartL(); |
|
209 } |
|
210 |
|
211 |
|
212 //---------------------------------------------------------------------------------------- |
|
213 void PrintTextL(const TDesC& aBuf, TInt err, TFileName& aFilename) |
|
214 //---------------------------------------------------------------------------------------- |
|
215 { |
|
216 HBufC* buff= HBufC::NewLC(100); |
|
217 |
|
218 (buff->Des()).Format(aBuf, err, aFilename.PtrZ()); |
|
219 testUtils->WriteComment(buff->Des()); |
|
220 test.Printf(buff->Des()); |
|
221 |
|
222 CleanupStack::PopAndDestroy(); // buff |
|
223 } |
|
224 |
|
225 //---------------------------------------------------------------------------------------- |
|
226 void PrintTextL(const TDesC& aBuf, TInt err) |
|
227 //---------------------------------------------------------------------------------------- |
|
228 { |
|
229 HBufC* buff= HBufC::NewLC(100); |
|
230 |
|
231 (buff->Des()).Format(aBuf, err); |
|
232 testUtils->WriteComment(buff->Des()); |
|
233 |
|
234 CleanupStack::PopAndDestroy(); // buff |
|
235 } |
|
236 |
|
237 //---------------------------------------------------------------------------------------- |
|
238 TInt CompareLogs(const TDesC& aText) |
|
239 //---------------------------------------------------------------------------------------- |
|
240 { |
|
241 TInt testHarnessError=0; |
|
242 |
|
243 test.Console()->ClearScreen(); |
|
244 test.Next(_L("Comparing:")); |
|
245 |
|
246 CPtrCArray* file = new (ELeave) CPtrCArray(6); |
|
247 file->AppendL(KFileNameHeaders); |
|
248 file->AppendL(KFileNameMimeHeaders); |
|
249 file->AppendL(KFileNameBodies); |
|
250 file->AppendL(KFileNameFiles); |
|
251 file->AppendL(KFileNameEntryStructure); |
|
252 |
|
253 RFileReadStream file1; |
|
254 RFileReadStream file2; |
|
255 HBufC8* line1Buffer = HBufC8::NewLC(1024); |
|
256 TPtr8 line1 = line1Buffer->Des(); |
|
257 TBuf8<1> aChar1; |
|
258 |
|
259 HBufC8* line2Buffer = HBufC8::NewLC(1024); |
|
260 TPtr8 line2 = line2Buffer->Des(); |
|
261 TBuf8<1> aChar2; |
|
262 |
|
263 TParse parsedLogFileName; |
|
264 TParse parsedCompareFileName; |
|
265 |
|
266 for(TInt i=0; i<file->MdcaCount(); i++) |
|
267 { |
|
268 testUtils->TestStart(i+1); |
|
269 |
|
270 TBool errorOccured = EFalse; |
|
271 |
|
272 TFileName file1Name = file->MdcaPoint(i); |
|
273 file1Name.Insert(0, aText); |
|
274 testUtils->ResolveLogFile(file1Name, parsedLogFileName); |
|
275 |
|
276 TFileName file2Name = file->MdcaPoint(i); |
|
277 file2Name.Insert(0, aText); |
|
278 file2Name.Insert(0, KTestMessageDir); |
|
279 testUtils->ResolveFile(KComponent, file2Name, parsedCompareFileName); |
|
280 |
|
281 TInt error1=KErrNone; |
|
282 TInt error2=KErrNone; |
|
283 |
|
284 test.Printf(_L("\n%s"), file2Name.PtrZ()); |
|
285 |
|
286 testHarnessError=error1=file1.Open(testUtils->FileSession(), parsedLogFileName.FullName(), EFileShareAny); |
|
287 if(error1!=KErrNone) |
|
288 { |
|
289 file1Name=parsedLogFileName.FullName(); |
|
290 PrintTextL(_L("\nERROR %d opening file %s"), error1, file1Name); |
|
291 errorOccured = ETrue; |
|
292 } |
|
293 else |
|
294 { |
|
295 testHarnessError=error2=file2.Open(testUtils->FileSession(), parsedCompareFileName.FullName(), EFileShareAny); |
|
296 if(error2!=KErrNone) |
|
297 { |
|
298 file1Name=parsedLogFileName.FullName(); |
|
299 PrintTextL( _L("\nERROR %d opening file %s"), error2, file1Name); |
|
300 errorOccured = ETrue; |
|
301 } |
|
302 else |
|
303 PrintTextL(_L("\nTest %d, Opening file %s"), i+1, file1Name); |
|
304 |
|
305 } |
|
306 |
|
307 if((error1==KErrNone)&&(error2==KErrNone)) |
|
308 { |
|
309 // read the file into the conversion object |
|
310 TInt file1LineCounter = 0; |
|
311 |
|
312 TBool finished = EFalse; |
|
313 |
|
314 do { |
|
315 line1.FillZ(); |
|
316 line1.SetLength(0); |
|
317 // compile the lines one char at a time |
|
318 do { |
|
319 TRAPD( error, file1.ReadL(aChar1, 1) ); |
|
320 if (error!=KErrEof) |
|
321 line1.Append(aChar1); |
|
322 else |
|
323 { |
|
324 finished = ETrue; |
|
325 break; |
|
326 } |
|
327 // stop at the end of line or no more data |
|
328 } |
|
329 while((aChar1[0]!=0x0A)&&(line1.Length()<1024)); |
|
330 |
|
331 line2.FillZ(); |
|
332 line2.SetLength(0); |
|
333 do { |
|
334 TRAPD( error, file2.ReadL(aChar2, 1) ); |
|
335 if (error!=KErrEof) |
|
336 line2.Append(aChar2); |
|
337 else |
|
338 { |
|
339 finished = ETrue; |
|
340 break; |
|
341 } |
|
342 // stop at the end of line or no more data |
|
343 } |
|
344 while((aChar2[0]!=0x0A)&&(line2.Length()<1024)); |
|
345 |
|
346 if(!finished) |
|
347 { |
|
348 line1.TrimRight(); |
|
349 line2.TrimRight(); |
|
350 |
|
351 if(aChar1[0]==0x0A) |
|
352 file1LineCounter++; |
|
353 if(line1.Compare(line2)) |
|
354 { |
|
355 PrintTextL(_L("\nERROR - Line %d is different "), file1LineCounter); |
|
356 errorOccured = ETrue; |
|
357 } |
|
358 } |
|
359 } |
|
360 while(!finished); |
|
361 } |
|
362 |
|
363 file1.Close(); |
|
364 file2.Close(); |
|
365 |
|
366 |
|
367 if (errorOccured) |
|
368 { |
|
369 testUtils->TestFinish(i+1, KErrGeneral); |
|
370 testHarnessError=errorOccured; |
|
371 test.Printf(_L(" - FAILED")); |
|
372 } |
|
373 else |
|
374 { |
|
375 testUtils->TestFinish( i+1, KErrNone); |
|
376 test.Printf(_L(" - OK")); |
|
377 } |
|
378 } |
|
379 |
|
380 test.Printf(_L("\n")); |
|
381 |
|
382 CleanupStack::PopAndDestroy(2); //line 1 , line 2 |
|
383 delete file; |
|
384 return testHarnessError; |
|
385 } |
|
386 |
|
387 |
|
388 //---------------------------------------------------------------------------------------- |
|
389 LOCAL_C void Down() |
|
390 //---------------------------------------------------------------------------------------- |
|
391 { |
|
392 delete testUtils; |
|
393 //CleanupStack::PopAndDestroy(testUtils); |
|
394 CleanupStack::PopAndDestroy(); |
|
395 delete active; |
|
396 } |
|
397 |
|
398 //---------------------------------------------------------------------------------------- |
|
399 void SendFilesToMessageStore(const TDesC& aText) |
|
400 //---------------------------------------------------------------------------------------- |
|
401 { |
|
402 TInt counter=0; |
|
403 TInt numberOfFiles=0; |
|
404 CDir* rfcFileList; |
|
405 |
|
406 TParse parsedFileName; |
|
407 TFileName name(KTest822FilesDir); |
|
408 //name.Append(aText); |
|
409 testUtils->ResolveFile(KComponent, name, parsedFileName); |
|
410 |
|
411 |
|
412 // Loads the any test files into an EntryList |
|
413 TInt error=testUtils->FileSession().GetDir(parsedFileName.FullName(), KEntryAttNormal, ESortByName, rfcFileList); |
|
414 if(!error) |
|
415 { |
|
416 numberOfFiles = rfcFileList->Count(); |
|
417 test.Printf(_L("Number Of Files=%d 1\n"), numberOfFiles); |
|
418 TInt num=1; |
|
419 if(numberOfFiles) |
|
420 { |
|
421 do { |
|
422 TFileName filename = (*rfcFileList)[counter].iName; |
|
423 PrintTextL(_L("\n%d Opening file %s\n"), num++, filename); |
|
424 |
|
425 filename.Insert(0, parsedFileName.FullName()); |
|
426 TestReadL(filename); |
|
427 counter++; |
|
428 } |
|
429 while(counter<numberOfFiles); |
|
430 |
|
431 name.Copy(aText); |
|
432 testUtils->ResolveLogFile(name, parsedFileName); |
|
433 |
|
434 testUtils->FindChildrenL(KMsvRootIndexEntryId, parsedFileName.FullName()); |
|
435 } |
|
436 else |
|
437 test.Printf(_L("WARNING - There are no RFC files in test file source directory\n")); |
|
438 } |
|
439 else |
|
440 test.Printf(TRefByValue<const TDesC>_L("\r\nFile error %d"), error); |
|
441 |
|
442 delete rfcFileList; |
|
443 } |
|
444 |
|
445 |
|
446 LOCAL_C void DeleteMessageFolderL() |
|
447 { |
|
448 test.Console()->ClearScreen(); |
|
449 testUtils->Reset(); |
|
450 |
|
451 CleanupStack::PopAndDestroy(); //scheduler |
|
452 |
|
453 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
454 CActiveScheduler::Install(scheduler); |
|
455 CleanupStack::PushL(scheduler); |
|
456 |
|
457 testUtils->CreateAllTestDirectories(); |
|
458 testUtils->FileSession().SetSessionPath(KTest822FilesDir); |
|
459 testUtils->CleanMessageFolderL(); |
|
460 testUtils->GoServerSideL(); |
|
461 } |
|
462 |
|
463 |
|
464 //---------------------------------------------------------------------------------------- |
|
465 LOCAL_C void doMainL() |
|
466 //---------------------------------------------------------------------------------------- |
|
467 { |
|
468 TInt err; |
|
469 UpL(); |
|
470 |
|
471 |
|
472 test.Console()->ClearScreen(); |
|
473 test.Console()->SetPos(0, 0); |
|
474 test.Printf(_L("\n---------------------")); |
|
475 test.Printf(_L("\n Charset Settings Test - Receive")); |
|
476 test.Printf(_L("\n---------------------\n")); |
|
477 test.Printf(_L("\n")); |
|
478 |
|
479 // SendFilesToMessageStore(_L("None")); |
|
480 // err=CompareLogs(_L("None")); |
|
481 // DeleteMessageFolderL(); |
|
482 |
|
483 // testUtils->FileSession().SetSessionPath(KTestLibsDir); |
|
484 // testUtils->FileSession().Delete(KImEngineResourceFile); // IF IT EXISTS |
|
485 // testUtils->FileSession().Rename(KUtf7Resource, KImEngineResourceFile); |
|
486 SendFilesToMessageStore(_L("UTF7")); |
|
487 err=CompareLogs(_L("UTF7")); |
|
488 DeleteMessageFolderL(); |
|
489 |
|
490 // Testing Unknown charset |
|
491 // testUtils->FileSession().SetSessionPath(KTestLibsDir); |
|
492 // testUtils->FileSession().Rename(KImEngineResourceFile, KUtf7Resource); |
|
493 // testUtils->FileSession().Rename(KUnknownResource, KImEngineResourceFile); |
|
494 // SendFilesToMessageStore(_L("Unknown")); |
|
495 // err=CompareLogs(_L("Unknown")); |
|
496 // DeleteMessageFolderL(); |
|
497 |
|
498 testUtils->FileSession().Rename(KImEngineResourceFile, KUnknownResource); |
|
499 |
|
500 if (err==0) |
|
501 testUtils->TestHarnessCompleted(); |
|
502 else |
|
503 testUtils->TestHarnessFailed(-2); |
|
504 |
|
505 Down(); |
|
506 } |
|
507 |
|
508 //---------------------------------------------------------------------------------------- |
|
509 GLDEF_C TInt E32Main() |
|
510 //---------------------------------------------------------------------------------------- |
|
511 { |
|
512 __UHEAP_MARK; |
|
513 test.Start(_L("T_IMCV_Transform_Receive Test harness")); |
|
514 theCleanup=CTrapCleanup::New(); |
|
515 TRAPD(ret,doMainL()); |
|
516 test(ret==KErrNone); |
|
517 delete theCleanup; |
|
518 test.End(); |
|
519 test.Close(); |
|
520 __UHEAP_MARKEND; |
|
521 return(KErrNone); |
|
522 } |