|
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 // |
|
15 |
|
16 #include "emailtestutils.h" |
|
17 #include "scripttestutils.h" |
|
18 |
|
19 _LIT8(K_IM_CR_LF, "\r\n"); |
|
20 _LIT(K_IM_LOG_FILE_NAME, "c:\\logs\\email\\imlog%d.txt"); |
|
21 _LIT(K_IM_END_OF_FILE, "END OF FILE"); |
|
22 _LIT(K_IM_LOG_TEMP_FILE_NAME, "temp.out"); |
|
23 _LIT8(K_IM_READ_CANCELLED, "** Read cancelled"); |
|
24 |
|
25 _LIT8(K_IM_TEST_DATE, "Date: "); |
|
26 _LIT8(K_IM_TEST_DATE_REPLACEMENT, "date-replacement-string-"); |
|
27 _LIT8(K_IM_TEST_MESSAGE_ID, "Message-ID: "); |
|
28 _LIT8(K_IM_TEST_MESSAGE_ID_REPLACEMENT, "message-id-replacement-string-"); |
|
29 _LIT8(K_IM_TEST_CONTENT_ID, "Content-ID: "); |
|
30 _LIT8(K_IM_TEST_CONTENT_ID_REPLACEMENT, "content-id-replacement-string-"); |
|
31 _LIT8(K_IM_TEST_BOUNDARY, " boundary="); |
|
32 _LIT8(K_IM_TEST_BOUNDARY_REPLACEMENT, "boundary-replacement-string-"); |
|
33 _LIT8(K_IM_TEST_HELO, "HELO "); |
|
34 _LIT8(K_IM_TEST_HELO_REPLACEMENT, ""); |
|
35 const TInt K_IM_TEST_STRING_MAX = 128; |
|
36 const TInt K_IM_TEST_ID_LEN = 5; |
|
37 |
|
38 |
|
39 CScriptTestUtils::CImTestField::~CImTestField() |
|
40 { |
|
41 delete iFieldName; |
|
42 delete iReplacementString; |
|
43 } |
|
44 |
|
45 CScriptTestUtils::CImFindReplace::~CImFindReplace() |
|
46 { |
|
47 delete iFind; |
|
48 delete iReplace; |
|
49 } |
|
50 |
|
51 EXPORT_C void CScriptTestUtils::LogToInputFileL(const TDesC& aSourceFileName, const TDesC& aDestFileName, TBool aStandardiseDateFields) |
|
52 // Create an email script file from a log file. |
|
53 { |
|
54 StripLogFileL(aSourceFileName, aDestFileName, aStandardiseDateFields, EImLogLineIn); |
|
55 } |
|
56 |
|
57 EXPORT_C void CScriptTestUtils::LogToOutputFileL(const TDesC& aSourceFileName, const TDesC& aDestFileName, TBool aStandardiseDateFields) |
|
58 // Create an email output file from a log file. |
|
59 { |
|
60 StripLogFileL(aSourceFileName, aDestFileName, aStandardiseDateFields, EImLogLineOut); |
|
61 } |
|
62 |
|
63 CScriptTestUtils::CImFindReplace* CScriptTestUtils::FindVariableDataL(TDes8& aLine) |
|
64 // Find any variable data fields in the given line. |
|
65 // The field value and its replacement is returned. |
|
66 // If the line doesn't contain any variable data then a NULL pointer is returned. |
|
67 { |
|
68 CImFindReplace* replacement = NULL; |
|
69 |
|
70 TInt index = iFieldList->Count(); |
|
71 HBufC8* fieldName; |
|
72 TPtrC8 startOfLine; |
|
73 TInt lineIndex = 0; |
|
74 while (index--) |
|
75 // Look for each variable field in turn. |
|
76 { |
|
77 fieldName = ((*iFieldList)[index]->iFieldName); |
|
78 lineIndex = fieldName->Des().Size(); |
|
79 if (lineIndex <= aLine.Size()) |
|
80 { |
|
81 startOfLine.Set(aLine.Left(lineIndex)); |
|
82 |
|
83 if (fieldName->Des().CompareF(startOfLine) == 0) |
|
84 { |
|
85 TPtrC8 fieldValue; |
|
86 fieldValue.Set(aLine.Mid(lineIndex, aLine.Size() - lineIndex)); |
|
87 if (fieldValue.Size() > 1) |
|
88 // Don't include enclosing '<' '>' '"' characters in the value part. |
|
89 { |
|
90 if (((fieldValue[0] == '<') && (fieldValue[fieldValue.Size() - 1] == '>')) |
|
91 || ((fieldValue[0] == '"') && (fieldValue[fieldValue.Size() - 1] == '"')) |
|
92 || ((fieldValue[0] == '[') && (fieldValue[fieldValue.Size() - 1] == ']'))) |
|
93 { |
|
94 fieldValue.Set(fieldValue.Mid(1, fieldValue.Size() - 2)); |
|
95 } |
|
96 } |
|
97 |
|
98 // Set |
|
99 if (fieldValue.Size() > 0) |
|
100 { |
|
101 replacement = new (ELeave) CImFindReplace; |
|
102 replacement->iFind = HBufC8::NewL(fieldValue.Size()); |
|
103 *(replacement->iFind) = fieldValue; |
|
104 |
|
105 replacement->iReplace = HBufC8::NewL((*iFieldList)[index]->iReplacementString->Des().Size() + K_IM_TEST_ID_LEN); |
|
106 *(replacement->iReplace) = (*iFieldList)[index]->iReplacementString->Des(); |
|
107 // Append the ID number to the replacement string. |
|
108 TPtr8 replacementString = replacement->iReplace->Des(); |
|
109 TBuf8<K_IM_TEST_ID_LEN> numberString; |
|
110 (*iFieldList)[index]->iNumberFound++; |
|
111 numberString.Num((*iFieldList)[index]->iNumberFound); |
|
112 if ((replacementString.Size() != 0) && (index != 0)) |
|
113 replacementString.Append(numberString); |
|
114 } |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 return replacement; |
|
120 } |
|
121 |
|
122 void CScriptTestUtils::ReplaceVariableFields(TDes8& aLine) |
|
123 // Replaces any variable data in the given descriptor with a standard equivalent. |
|
124 { |
|
125 TInt index = 0; |
|
126 index = iFindReplaceList->Count(); |
|
127 TInt stringPosition; |
|
128 HBufC8* findString; |
|
129 HBufC8* replaceString; |
|
130 while (index--) |
|
131 // Search for each bit of variable data in turn |
|
132 { |
|
133 findString = (*iFindReplaceList)[index]->iFind; |
|
134 replaceString = (*iFindReplaceList)[index]->iReplace; |
|
135 stringPosition = aLine.FindF(findString->Des()); |
|
136 if (stringPosition != KErrNotFound) |
|
137 { |
|
138 aLine.Replace(stringPosition, findString->Des().Size(), replaceString->Des()); |
|
139 } |
|
140 } |
|
141 } |
|
142 |
|
143 void CScriptTestUtils::StandardiseVariableFieldsL(const TDesC& aSourceFileName) |
|
144 // Write over all the MIME variable field values with standard values. |
|
145 { |
|
146 TInt index = 0; |
|
147 index = iFieldList->Count(); |
|
148 while (index--) |
|
149 { |
|
150 (*iFieldList)[index]->iNumberFound = 0; |
|
151 } |
|
152 |
|
153 // Open and create the files |
|
154 RFile sourceFile; |
|
155 RFile tempFile; |
|
156 TFileName tempFileName; |
|
157 index = 0; |
|
158 while (aSourceFileName[index] != L'.') |
|
159 { |
|
160 tempFileName.Append(aSourceFileName[index]); |
|
161 index++; |
|
162 } |
|
163 tempFileName.Append(_L(".tmp")); |
|
164 |
|
165 TInt err = tempFile.Replace(iTestUtils.FileSession(), tempFileName, EFileShareAny); |
|
166 |
|
167 // Open the log file. |
|
168 err = sourceFile.Open(iTestUtils.FileSession(), aSourceFileName, EFileShareReadersOnly); |
|
169 TFileReader fileReader(sourceFile); |
|
170 |
|
171 HBufC8* sourceLine = GetLineL(fileReader); |
|
172 CImFindReplace* findReplace; |
|
173 while (0 != sourceLine) |
|
174 // Fill in the find and replace table. |
|
175 { |
|
176 TPtr8 linePtr = sourceLine->Des(); |
|
177 CleanupStack::PushL(sourceLine); |
|
178 findReplace = FindVariableDataL(linePtr); |
|
179 if (findReplace) |
|
180 // Add the find and replace strings to the list |
|
181 { |
|
182 iFindReplaceList->AppendL(findReplace); |
|
183 } |
|
184 |
|
185 CleanupStack::PopAndDestroy(); // sourceLine |
|
186 sourceLine = GetLineL(fileReader); |
|
187 } |
|
188 |
|
189 // Go back to the begining of the source file. |
|
190 fileReader.Seek(0); |
|
191 |
|
192 sourceLine = GetLineL(fileReader); |
|
193 // Replace all of the variable field values with the appropriate fixed string. |
|
194 while (0 != sourceLine) |
|
195 { |
|
196 TPtr8 linePtr = sourceLine->Des(); |
|
197 CleanupStack::PushL(sourceLine); |
|
198 |
|
199 TPtr8 sourceLinePtr = sourceLine->Des(); |
|
200 ReplaceVariableFields(sourceLinePtr); |
|
201 |
|
202 tempFile.Write(sourceLinePtr); |
|
203 tempFile.Write(K_IM_CR_LF); |
|
204 |
|
205 CleanupStack::PopAndDestroy(); // sourceLine |
|
206 sourceLine = GetLineL(fileReader); |
|
207 if (sourceLine) |
|
208 linePtr = sourceLine->Des(); |
|
209 } |
|
210 |
|
211 // Close the files. |
|
212 sourceFile.Close(); |
|
213 tempFile.Close(); |
|
214 |
|
215 // Delete the source file. |
|
216 err = iTestUtils.FileSession().Delete(aSourceFileName); |
|
217 |
|
218 // Rename the temp file as the source file. |
|
219 err = iTestUtils.FileSession().Rename(tempFileName, aSourceFileName); |
|
220 } |
|
221 |
|
222 |
|
223 void CScriptTestUtils::StripLogFileL(const TFileName& aSourceFileName, const TFileName& aDestFileName, TBool aStandardiseDateFields, TImLogLineType aLogLineType) |
|
224 { |
|
225 TBuf8<2> crlf = _L8("\r\n"); |
|
226 |
|
227 RFile rSourceFile; |
|
228 RFile rOutputFile; |
|
229 |
|
230 User::LeaveIfError(rOutputFile.Replace(iTestUtils.FileSession(), aDestFileName, EFileShareAny)); |
|
231 |
|
232 // Open the log file. |
|
233 User::LeaveIfError(rSourceFile.Open(iTestUtils.FileSession(), aSourceFileName, EFileShareAny)); |
|
234 |
|
235 TBuf8<2048> scriptLine; |
|
236 TFileReader fileReader(rSourceFile); |
|
237 |
|
238 // Copy the incoming data from the log to the script file, removing any formatting. |
|
239 TInt lineCounter = 0; |
|
240 TInt lineIndex; |
|
241 TImLogLineType lastLineType = aLogLineType; |
|
242 TBool waitingForCrLf = EFalse; |
|
243 |
|
244 HBufC8* logLine = GetLineL(fileReader); |
|
245 while (logLine != 0) |
|
246 { |
|
247 CleanupStack::PushL(logLine); |
|
248 lineCounter++; |
|
249 lineIndex = 0; |
|
250 |
|
251 scriptLine.Zero(); |
|
252 TImLogLineType lineType = LineType(logLine); |
|
253 if (EImEmptyLine == lineType) |
|
254 { |
|
255 if (waitingForCrLf) |
|
256 { |
|
257 waitingForCrLf = EFalse; |
|
258 rOutputFile.Write(crlf); |
|
259 } |
|
260 } |
|
261 else if (aLogLineType == lineType) |
|
262 { |
|
263 if ((lastLineType != EImLogLineComment) && (waitingForCrLf)) |
|
264 { |
|
265 rOutputFile.Write(crlf); |
|
266 } |
|
267 |
|
268 // Copy the line of incoming data to the script file. |
|
269 if (logLine->Size() > 21) |
|
270 { |
|
271 // Copy the logLine from character 20 to the end into the output line. |
|
272 lineIndex = 21; |
|
273 while (lineIndex < logLine->Size()) |
|
274 { |
|
275 scriptLine.Append((*logLine)[lineIndex]); |
|
276 lineIndex++; |
|
277 } |
|
278 |
|
279 // Write the stripped line to the script file |
|
280 User::LeaveIfError(rOutputFile.Write(scriptLine)); |
|
281 } |
|
282 |
|
283 waitingForCrLf = ETrue; |
|
284 // |
|
285 } |
|
286 else if (EImLogLineComment == lineType) |
|
287 {} |
|
288 else if (EImReadCancelled == lineType) |
|
289 { |
|
290 if (EImLogLineIn == aLogLineType) |
|
291 { |
|
292 User::LeaveIfError(rOutputFile.Write(K_IM_READ_CANCELLED)); |
|
293 rOutputFile.Write(crlf); |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 // If we're waiting for a crlf then write one regardless of the last line... |
|
299 if (waitingForCrLf) |
|
300 { |
|
301 rOutputFile.Write(crlf); |
|
302 } |
|
303 } |
|
304 |
|
305 lastLineType = LineType(logLine); |
|
306 |
|
307 CleanupStack::PopAndDestroy(); // logLine |
|
308 logLine = GetLineL(fileReader); |
|
309 } |
|
310 |
|
311 if (waitingForCrLf) |
|
312 { |
|
313 rOutputFile.Write(crlf); |
|
314 } |
|
315 |
|
316 rSourceFile.Close(); |
|
317 rOutputFile.Close(); |
|
318 |
|
319 if (aStandardiseDateFields) |
|
320 { |
|
321 StandardiseVariableFieldsL(aDestFileName); |
|
322 } |
|
323 } |
|
324 |
|
325 EXPORT_C CScriptTestUtils* CScriptTestUtils::NewLC(CEmailTestUtils& aTestUtils) |
|
326 { |
|
327 CScriptTestUtils* self = new (ELeave) CScriptTestUtils(aTestUtils); |
|
328 CleanupStack::PushL(self); |
|
329 self->ConstructL(); |
|
330 return self; |
|
331 } |
|
332 |
|
333 void CScriptTestUtils::ConstructL() |
|
334 { |
|
335 iFieldList = new (ELeave) CArrayPtrFlat<CImTestField>(6); |
|
336 |
|
337 CImTestField* removeReplaceItem = new (ELeave) CImTestField; |
|
338 removeReplaceItem->iFieldName = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
339 *(removeReplaceItem->iFieldName) = K_IM_TEST_DATE; |
|
340 removeReplaceItem->iReplacementString = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
341 *(removeReplaceItem->iReplacementString) = K_IM_TEST_DATE_REPLACEMENT; |
|
342 removeReplaceItem->iNumberFound=0; |
|
343 iFieldList->AppendL(removeReplaceItem); |
|
344 |
|
345 removeReplaceItem = new (ELeave) CImTestField; |
|
346 removeReplaceItem->iFieldName = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
347 *(removeReplaceItem->iFieldName) = K_IM_TEST_MESSAGE_ID; |
|
348 removeReplaceItem->iReplacementString = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
349 *(removeReplaceItem->iReplacementString) = K_IM_TEST_MESSAGE_ID_REPLACEMENT; |
|
350 removeReplaceItem->iNumberFound=0; |
|
351 iFieldList->AppendL(removeReplaceItem); |
|
352 |
|
353 removeReplaceItem = new (ELeave) CImTestField; |
|
354 removeReplaceItem->iFieldName = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
355 *(removeReplaceItem->iFieldName) = K_IM_TEST_CONTENT_ID; |
|
356 removeReplaceItem->iReplacementString = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
357 *(removeReplaceItem->iReplacementString) = K_IM_TEST_CONTENT_ID_REPLACEMENT; |
|
358 removeReplaceItem->iNumberFound=0; |
|
359 iFieldList->AppendL(removeReplaceItem); |
|
360 |
|
361 removeReplaceItem = new (ELeave) CImTestField; |
|
362 removeReplaceItem->iFieldName = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
363 *(removeReplaceItem->iFieldName) = K_IM_TEST_BOUNDARY; |
|
364 removeReplaceItem->iReplacementString = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
365 *(removeReplaceItem->iReplacementString) = K_IM_TEST_BOUNDARY_REPLACEMENT; |
|
366 removeReplaceItem->iNumberFound=0; |
|
367 iFieldList->AppendL(removeReplaceItem); |
|
368 |
|
369 removeReplaceItem = new (ELeave) CImTestField; |
|
370 removeReplaceItem->iFieldName = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
371 *(removeReplaceItem->iFieldName) = K_IM_TEST_HELO; |
|
372 removeReplaceItem->iReplacementString = HBufC8::NewL(K_IM_TEST_STRING_MAX); |
|
373 *(removeReplaceItem->iReplacementString) = K_IM_TEST_HELO_REPLACEMENT; |
|
374 removeReplaceItem->iNumberFound=0; |
|
375 iFieldList->AppendL(removeReplaceItem); |
|
376 |
|
377 iFindReplaceList = new (ELeave) CArrayPtrFlat<CImFindReplace>(6); |
|
378 } |
|
379 |
|
380 CScriptTestUtils::CScriptTestUtils(CEmailTestUtils& aTestUtils) : iTestUtils(aTestUtils) |
|
381 {} |
|
382 |
|
383 |
|
384 CScriptTestUtils::TImLogLineType CScriptTestUtils::LineType(const HBufC8* aLine) |
|
385 { |
|
386 TImLogLineType lineType = EImLogLineComment; |
|
387 |
|
388 if (aLine->Size() == 0) |
|
389 { |
|
390 lineType = EImEmptyLine; |
|
391 } |
|
392 else if (aLine->Size() > 19) |
|
393 { |
|
394 if ((((*aLine)[18]) == '<') |
|
395 && (((*aLine)[19]) == '<')) |
|
396 { |
|
397 lineType = EImLogLineIn; |
|
398 } |
|
399 else if ((((*aLine)[18]) == '>') |
|
400 && (((*aLine)[19]) == '>')) |
|
401 { |
|
402 lineType = EImLogLineOut; |
|
403 } |
|
404 else if ((aLine->Right(17)).Compare(K_IM_READ_CANCELLED) == 0) |
|
405 { |
|
406 lineType = EImReadCancelled; |
|
407 } |
|
408 } |
|
409 |
|
410 return lineType; |
|
411 } |
|
412 |
|
413 HBufC8* CScriptTestUtils::GetLineL(TFileReader& aFileReader) |
|
414 { |
|
415 TBuf8<2048> currentLine; |
|
416 char character; |
|
417 currentLine.Zero(); |
|
418 |
|
419 |
|
420 TBool crlfFound = EFalse; |
|
421 TBool read = ETrue; |
|
422 |
|
423 // Append characters one at a time until we reach a cr/lf pair or the end of the file. |
|
424 while ((read) && (crlfFound == EFalse)) |
|
425 { |
|
426 read = aFileReader.Read(character); |
|
427 |
|
428 if (read) |
|
429 { |
|
430 if (0x0D == character) |
|
431 { |
|
432 read = aFileReader.Read(character); |
|
433 if (read) |
|
434 { |
|
435 if (character == 0x0A) |
|
436 { |
|
437 crlfFound = ETrue; |
|
438 } |
|
439 else |
|
440 { |
|
441 // The cr was not part of the cr/lf pair so go back one space. |
|
442 aFileReader.SeekCurrent(-1); |
|
443 } |
|
444 } |
|
445 } |
|
446 |
|
447 if ((read) && (EFalse == crlfFound)) |
|
448 { |
|
449 currentLine.Append(character); |
|
450 } |
|
451 } |
|
452 } |
|
453 |
|
454 HBufC8* lineCopy; |
|
455 if ((currentLine.Size() != 0) || (read)) |
|
456 { |
|
457 lineCopy = HBufC8::NewL(2048); |
|
458 (*lineCopy) = currentLine; |
|
459 } |
|
460 else |
|
461 { |
|
462 lineCopy = 0; |
|
463 } |
|
464 |
|
465 return lineCopy; |
|
466 } |
|
467 |
|
468 |
|
469 CScriptTestUtils::TFileReader::TFileReader(RFile &rFile) : iFile(rFile), iBufferIndex(0), iBufferStart(0) |
|
470 { |
|
471 } |
|
472 |
|
473 TBool CScriptTestUtils::TFileReader::Read(char &rChar) |
|
474 { |
|
475 // Is the character we want not in the buffer ? |
|
476 TBool read = ETrue; |
|
477 if ((iBufferIndex >= iBuffer.Size()) |
|
478 || (iBufferIndex < 0)) |
|
479 // If it's not then get a new buffer starting at this position. |
|
480 { |
|
481 TInt seekPosition = iBufferIndex + iBufferStart; |
|
482 TInt err = iFile.Seek(ESeekStart, seekPosition); |
|
483 if (KErrNone != err) |
|
484 { |
|
485 iBuffer.SetLength(0); |
|
486 read = EFalse; |
|
487 } |
|
488 else |
|
489 { |
|
490 iFile.Read(iBuffer); |
|
491 if (iBuffer.Size() == 0) |
|
492 { |
|
493 read = EFalse; |
|
494 } |
|
495 iBufferStart += iBufferIndex; |
|
496 iBufferIndex = 0; |
|
497 } |
|
498 |
|
499 if (iBuffer.Size() > 0) |
|
500 { |
|
501 rChar = iBuffer[0]; |
|
502 } |
|
503 } |
|
504 else |
|
505 { |
|
506 rChar = iBuffer[iBufferIndex]; |
|
507 } |
|
508 |
|
509 if (read) |
|
510 { |
|
511 iBufferIndex++; |
|
512 } |
|
513 |
|
514 return read; |
|
515 } |
|
516 |
|
517 void CScriptTestUtils::TFileReader::Seek(TInt aOffset) |
|
518 { |
|
519 iBufferIndex = aOffset; |
|
520 iBuffer.Zero(); |
|
521 iBufferStart = 0; |
|
522 } |
|
523 |
|
524 void CScriptTestUtils::TFileReader::SeekCurrent(TInt aOffset) |
|
525 { |
|
526 iBufferIndex += aOffset; |
|
527 } |
|
528 |
|
529 |
|
530 CScriptTestUtils::~CScriptTestUtils() |
|
531 { |
|
532 delete iExpectedLine; |
|
533 delete iActualLine; |
|
534 iFieldList->ResetAndDestroy(); |
|
535 delete iFieldList; |
|
536 iFindReplaceList->ResetAndDestroy(); |
|
537 delete iFindReplaceList; |
|
538 } |
|
539 |
|
540 // Functions for checking the IM output. |
|
541 |
|
542 EXPORT_C TBool CScriptTestUtils::CheckLogOutputL(TInt aPortNumber, const TDesC& aTestFileName) |
|
543 { |
|
544 TBool matched = ETrue; |
|
545 |
|
546 // Clear the old error values |
|
547 delete iExpectedLine; |
|
548 iExpectedLine = 0; |
|
549 delete iActualLine; |
|
550 iActualLine = 0; |
|
551 |
|
552 RFile testFile; // The file to test against |
|
553 RFile tempFile; // The stripped-down log file to test |
|
554 |
|
555 // Create a temporary .out file from the log file. |
|
556 TFileName logFileName; |
|
557 logFileName.Format(K_IM_LOG_FILE_NAME, aPortNumber); |
|
558 |
|
559 TParse tempFileName; |
|
560 iTestUtils.ResolveLogFile(K_IM_LOG_TEMP_FILE_NAME, tempFileName); |
|
561 LogToOutputFileL(logFileName, tempFileName.FullName(), ETrue); |
|
562 tempFile.Close(); |
|
563 |
|
564 // Open the test file. |
|
565 TInt err = testFile.Open(iTestUtils.FileSession(), aTestFileName, EFileShareReadersOnly); |
|
566 TFileReader testFileReader(testFile); |
|
567 |
|
568 // Open the temp file. |
|
569 TParse tempLogFileName; |
|
570 iTestUtils.ResolveLogFile(K_IM_LOG_TEMP_FILE_NAME, tempLogFileName); |
|
571 err = tempFile.Open(iTestUtils.FileSession(), tempFileName.FullName(), EFileShareReadersOnly); |
|
572 TFileReader tempFileReader(tempFile); |
|
573 |
|
574 HBufC8* testLine = GetLineL(testFileReader); |
|
575 |
|
576 if (testLine) |
|
577 CleanupStack::PushL(testLine); |
|
578 |
|
579 HBufC8* tempLine = GetLineL(tempFileReader); |
|
580 |
|
581 if (tempLine) |
|
582 CleanupStack::PushL(tempLine); |
|
583 |
|
584 TInt lineNumber = 1; |
|
585 |
|
586 while ((testLine != 0) && (tempLine != 0) && matched) |
|
587 // Compare the specified .out file to the temporary one, line-by-line. |
|
588 { |
|
589 if (testLine->Des().Compare(tempLine->Des()) != 0) |
|
590 { |
|
591 matched = EFalse; |
|
592 } |
|
593 |
|
594 if (matched) |
|
595 // If the lines didn't match then save the strings for later. |
|
596 { |
|
597 CleanupStack::PopAndDestroy(); // testLine |
|
598 testLine = 0; |
|
599 CleanupStack::PopAndDestroy(); // tempLine |
|
600 tempLine = 0; |
|
601 // Get the next line |
|
602 testLine = GetLineL(testFileReader); |
|
603 if (testLine) |
|
604 CleanupStack::PushL(testLine); |
|
605 |
|
606 tempLine = GetLineL(tempFileReader); |
|
607 if (tempLine) |
|
608 CleanupStack::PushL(tempLine); |
|
609 |
|
610 lineNumber++; |
|
611 } |
|
612 } |
|
613 |
|
614 if ((!matched) || (testLine != 0) || (tempLine != 0)) |
|
615 // Store the details if the files don't match. |
|
616 { |
|
617 // Set up the new error values |
|
618 matched = EFalse; |
|
619 iErrorLine = lineNumber; |
|
620 TInt stringIndex; |
|
621 if (testLine) |
|
622 { |
|
623 iExpectedLine = HBufC::NewL(testLine->Size()); |
|
624 // Copy the 8 bit buffer to the 16 bit buffer. |
|
625 stringIndex = 0; |
|
626 while (stringIndex < testLine->Size()) |
|
627 { |
|
628 iExpectedLine->Des().Append((*testLine)[stringIndex]); |
|
629 stringIndex++; |
|
630 } |
|
631 } |
|
632 else |
|
633 { |
|
634 iExpectedLine = HBufC::NewL(((TDesC)K_IM_END_OF_FILE).Size()); |
|
635 (*iExpectedLine) = K_IM_END_OF_FILE; |
|
636 } |
|
637 |
|
638 if (tempLine) |
|
639 { |
|
640 iActualLine = HBufC::NewL(tempLine->Size()); |
|
641 // Copy the 8 bit buffer to the 16 bit buffer. |
|
642 stringIndex = 0; |
|
643 while (stringIndex < tempLine->Size()) |
|
644 { |
|
645 iActualLine->Des().Append((*tempLine)[stringIndex]); |
|
646 stringIndex++; |
|
647 } |
|
648 } |
|
649 else |
|
650 { |
|
651 iActualLine = HBufC::NewL(((TDesC)K_IM_END_OF_FILE).Size()); |
|
652 (*iActualLine) = K_IM_END_OF_FILE; |
|
653 } |
|
654 } |
|
655 |
|
656 if (tempLine) |
|
657 CleanupStack::PopAndDestroy(); // tempLine |
|
658 |
|
659 if (testLine) |
|
660 CleanupStack::PopAndDestroy(); // testLine |
|
661 |
|
662 testFile.Close(); |
|
663 tempFile.Close(); |
|
664 |
|
665 return matched; |
|
666 } |
|
667 |
|
668 EXPORT_C TInt CScriptTestUtils::ErrorLineNumber() |
|
669 { |
|
670 return iErrorLine; |
|
671 } |
|
672 |
|
673 EXPORT_C HBufC* CScriptTestUtils::ErrorExpectedL() |
|
674 { |
|
675 HBufC* stringCopy = HBufC::NewL(iExpectedLine->Size()); |
|
676 (*stringCopy) = (*iExpectedLine); |
|
677 return stringCopy; |
|
678 } |
|
679 |
|
680 EXPORT_C HBufC* CScriptTestUtils::ErrorActualL() |
|
681 { |
|
682 HBufC* stringCopy = HBufC::NewL(iActualLine->Size()); |
|
683 (*stringCopy) = (*iActualLine); |
|
684 return stringCopy; |
|
685 } |