|
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 // This utility converts any email logfiles ( imlog*.txt ) to script |
|
15 // files ( imsk*.scr ). |
|
16 // It strips out the comments, date stamps and '<<' '>>' markers. |
|
17 // |
|
18 // |
|
19 |
|
20 #include "emailtestutils.h" |
|
21 #include "scripttestutils.h" |
|
22 #include <miutlog.h> |
|
23 #include <miutmsg.h> |
|
24 #include <txtrich.h> |
|
25 |
|
26 // local variables etc // |
|
27 |
|
28 _LIT(KImcmTest, "U_IMUT2 - Utility for stripping down logfiles for use as scripts"); |
|
29 RTest test(KImcmTest); |
|
30 |
|
31 LOCAL_D CTrapCleanup* theCleanup; |
|
32 LOCAL_D CImLog* log; |
|
33 LOCAL_D CEmailTestUtils* testUtils; |
|
34 LOCAL_D CActiveScheduler* scheduler; |
|
35 |
|
36 |
|
37 // |
|
38 |
|
39 LOCAL_C void Init() |
|
40 { |
|
41 scheduler = new (ELeave) CActiveScheduler; |
|
42 CActiveScheduler::Install(scheduler); |
|
43 CleanupStack::PushL(scheduler); |
|
44 |
|
45 testUtils = CEmailTestUtils::NewLC(test); |
|
46 testUtils->CreateAllTestDirectories(); |
|
47 testUtils->FileSession().SetSessionPath(_L("C:\\")); |
|
48 |
|
49 log = CImLog::NewL(_L("c:\\logs\\email\\u_imut2.log"), EAppend); |
|
50 CleanupStack::PushL(log); |
|
51 log->AppendComment(_L8("*** U_IMUT2 Utility ***")); |
|
52 TBuf8<80> buf; |
|
53 #if defined(__WINS__) |
|
54 buf.Append(_L8("WINS ")); |
|
55 #else |
|
56 buf.Append(_L8("MARM ")); |
|
57 #endif |
|
58 #if defined(_UNICODE) |
|
59 buf.Append(_L8("U")); |
|
60 #endif |
|
61 #if defined(_DEBUG) |
|
62 buf.Append(_L8("DEB")); |
|
63 #else |
|
64 buf.Append(_L8("REL")); |
|
65 #endif |
|
66 log->AppendComment(buf); |
|
67 } |
|
68 |
|
69 LOCAL_C void Closedown() |
|
70 { |
|
71 log->AppendComment(_L8("********** U_IMUT2 Complete **********")); |
|
72 log->AppendComment(_L8("")); |
|
73 |
|
74 CleanupStack::PopAndDestroy(3); //testUtils, log, scheduler |
|
75 } |
|
76 |
|
77 // |
|
78 |
|
79 enum TImStripLogType |
|
80 { |
|
81 EImMakeInFile, |
|
82 EImMakeOutFile, |
|
83 EImEndMakeFile |
|
84 }; |
|
85 |
|
86 LOCAL_C void CreateScriptFilesL() |
|
87 { |
|
88 RFs& fs = testUtils->FileSession(); |
|
89 fs.SetSessionPath(_L("c:\\logs\\email\\")); |
|
90 |
|
91 CScriptTestUtils* scriptTestUtils = CScriptTestUtils::NewLC(*testUtils); |
|
92 |
|
93 CDir* logFiles; |
|
94 TInt portStringCounter; |
|
95 RFile logFile; |
|
96 RFile scriptFile; |
|
97 TBufC<KMaxFileName> logFileName; |
|
98 TBuf<KMaxFileName> scriptFileName; |
|
99 |
|
100 // First create the script file, then create the output test file. |
|
101 |
|
102 TImStripLogType lineType = EImMakeInFile; |
|
103 while ((lineType == EImMakeInFile) |
|
104 || (lineType == EImMakeOutFile)) |
|
105 { |
|
106 |
|
107 User::LeaveIfError(fs.GetDir(_L("imlog*.txt"), 0, ESortNone, logFiles)); |
|
108 CleanupStack::PushL(logFiles); |
|
109 |
|
110 TInt logFileCounter = logFiles->Count(); |
|
111 |
|
112 while (logFileCounter > 0) |
|
113 // Generate the script file from each log file |
|
114 { |
|
115 // Get the name of the log file. |
|
116 logFileCounter--; |
|
117 logFileName = ((*logFiles)[logFileCounter]).iName; |
|
118 |
|
119 // Get the name of the destination script file. |
|
120 scriptFileName = _L("imsk"); |
|
121 portStringCounter = 5; |
|
122 |
|
123 while (logFileName[portStringCounter] != L'.') |
|
124 { |
|
125 scriptFileName.Append(logFileName[portStringCounter]); |
|
126 portStringCounter++; |
|
127 } |
|
128 |
|
129 if (EImMakeInFile == lineType) |
|
130 { |
|
131 scriptFileName.Append(_L(".scr")); |
|
132 } |
|
133 else if (EImMakeOutFile == lineType) |
|
134 { |
|
135 scriptFileName.Append(_L(".out")); |
|
136 } |
|
137 |
|
138 if (lineType == EImMakeInFile) |
|
139 scriptTestUtils->LogToInputFileL(logFileName, scriptFileName, EFalse); |
|
140 else |
|
141 scriptTestUtils->LogToOutputFileL(logFileName, scriptFileName, ETrue); |
|
142 |
|
143 // Close the files |
|
144 logFile.Close(); |
|
145 scriptFile.Close(); |
|
146 } |
|
147 |
|
148 CleanupStack::PopAndDestroy(); // logFiles |
|
149 |
|
150 // If we have just created the script file the create the output test file. |
|
151 if (EImMakeInFile == lineType) |
|
152 { |
|
153 lineType = EImMakeOutFile; |
|
154 } |
|
155 else |
|
156 { |
|
157 lineType = EImEndMakeFile; |
|
158 } |
|
159 } |
|
160 |
|
161 CleanupStack::PopAndDestroy(); // scriptTestUtils |
|
162 } |
|
163 |
|
164 // |
|
165 LOCAL_C void doMainL() |
|
166 { |
|
167 Init(); |
|
168 |
|
169 CreateScriptFilesL(); |
|
170 |
|
171 Closedown(); |
|
172 } |
|
173 |
|
174 GLDEF_C TInt E32Main() |
|
175 { |
|
176 __UHEAP_MARK; |
|
177 test.Start(_L("U_IMUT2 Log -> Script Utility")); |
|
178 theCleanup=CTrapCleanup::New(); |
|
179 TRAPD(ret,doMainL()); |
|
180 test(ret==KErrNone); |
|
181 delete theCleanup; |
|
182 test.End(); |
|
183 test.Close(); |
|
184 __UHEAP_MARKEND; |
|
185 User::Heap().Check(); |
|
186 return(KErrNone); |
|
187 } |
|
188 |