1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implements logging of test data.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CamLogger.h" |
|
21 #include <f32file.h> |
|
22 #include <Flogger.h> |
|
23 |
|
24 // CONSTANTS |
|
25 const TInt KMaxFileNameLength = 50; |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 //#ifdef CAMERAAPP_TEST |
|
29 |
|
30 #ifdef CAMERAAPP_UNIT_TEST_SETTINGS_LIST_TESTER |
|
31 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
32 #endif // CAMERAAPP_UNIT_TEST_SETTINGS_LIST_TESTER |
|
33 |
|
34 #ifdef CAMERAAPP_UNIT_TEST |
|
35 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
36 #endif // CAMERAAPP_UNIT_TEST |
|
37 |
|
38 #ifdef CAPTURESETUP_UNIT_TEST |
|
39 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
40 #endif // CAMERAAPP_UNIT_TEST |
|
41 |
|
42 #ifdef CAMERAAPP_INTEGRATION_TEST |
|
43 _LIT( KDirectory, "Integration Tests\\Output" ); |
|
44 #endif // CAMERAAPP_INTEGRATION_TEST |
|
45 |
|
46 #ifdef CAMERAAPP_FRAMEWORK_UNIT_TEST |
|
47 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
48 #endif // CAMERAAPP_FRAMEWORK_UNIT_TEST |
|
49 |
|
50 #ifdef CAPTURE_SETUP_MENU_UNIT_TEST |
|
51 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
52 #endif // CAPTURE_SETUP_MENU_UNIT_TEST |
|
53 |
|
54 #ifdef SETUP_PANE_UNIT_TEST |
|
55 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
56 #endif // SETUP_PANE_UNIT_TEST |
|
57 |
|
58 #ifdef CAMERAAPP_BURST_UNIT_TEST |
|
59 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
60 #endif // CAMERAAPP_BURST_UNIT_TEST |
|
61 |
|
62 #ifdef CAMERAAPP_UNIT_TEST_USER_SCENE_SETUP |
|
63 _LIT( KDirectory, "Unit Tests\\Output" ); |
|
64 #endif // CAMERAAPP_UNIT_TEST_USER_SCENE_SETUP |
|
65 |
|
66 // ============================ STATIC FUNCTIONS =============================== |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CamLogger::InitialiseLogs |
|
70 // Initialises the files for writing to. |
|
71 // Necessary, otherwise previous output will remain in logs. |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 void CamLogger::InitialiseLogsL( const TDesC& aIdentifier, TBool aIgnore ) |
|
75 { |
|
76 if ( !aIgnore ) |
|
77 { |
|
78 // Create the directory for log files, if not already created. |
|
79 _LIT( KUnitTestsLogPath, "C:\\Logs\\Unit Tests\\Output\\" ); |
|
80 RFs rfs; |
|
81 User::LeaveIfError( rfs.Connect() ); |
|
82 CleanupClosePushL( rfs ); |
|
83 TInt err = rfs.MkDirAll( KUnitTestsLogPath ); |
|
84 // If there was an error and it wasn't that the directory already exists |
|
85 // then leave. |
|
86 if ( ( err != KErrNone ) && ( err != KErrAlreadyExists ) ) |
|
87 { |
|
88 User::Leave( err ); |
|
89 } |
|
90 CleanupStack::PopAndDestroy( &rfs ); |
|
91 |
|
92 // Overwrite contents of passed file. |
|
93 TBuf<KMaxFileNameLength> passedFileName; |
|
94 GetPassedFileName( aIdentifier, passedFileName ); |
|
95 RFileLogger::Write( KDirectory, passedFileName, EFileLoggingModeOverwrite, KNullDesC ); |
|
96 |
|
97 // Overwrite contents of failed file. |
|
98 TBuf<KMaxFileNameLength> failedFileName; |
|
99 GetFailedFileName( aIdentifier, failedFileName ); |
|
100 RFileLogger::Write( KDirectory, failedFileName, EFileLoggingModeOverwrite, KNullDesC ); |
|
101 |
|
102 // Overwrite contents of log file. |
|
103 TBuf<KMaxFileNameLength> logFileName; |
|
104 GetLogFileName( aIdentifier, logFileName ); |
|
105 RFileLogger::Write( KDirectory, logFileName, EFileLoggingModeOverwrite, KNullDesC ); |
|
106 } |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------- |
|
110 // CamLogger::LogHeader |
|
111 // Writes header info to all files identified by aIdentifier. |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CamLogger::LogHeader( const TDesC& aIdentifier, const TDesC& aHeader ) |
|
115 { |
|
116 // Header divider to be written under the header content. |
|
117 _LIT( KHeaderDivider, "=====================================================" ); |
|
118 |
|
119 // Write header to passed file. |
|
120 TBuf<KMaxFileNameLength> passedFileName; |
|
121 GetPassedFileName( aIdentifier, passedFileName ); |
|
122 RFileLogger::Write( KDirectory, passedFileName, EFileLoggingModeAppend, aHeader ); |
|
123 RFileLogger::Write( KDirectory, passedFileName, EFileLoggingModeAppend, KHeaderDivider ); |
|
124 |
|
125 // Write header to failed file. |
|
126 TBuf<KMaxFileNameLength> failedFileName; |
|
127 GetFailedFileName( aIdentifier, failedFileName ); |
|
128 RFileLogger::Write( KDirectory, failedFileName, EFileLoggingModeAppend, aHeader ); |
|
129 RFileLogger::Write( KDirectory, failedFileName, EFileLoggingModeAppend, KHeaderDivider ); |
|
130 |
|
131 // Write header to log file. |
|
132 TBuf<KMaxFileNameLength> logFileName; |
|
133 GetLogFileName( aIdentifier, logFileName ); |
|
134 RFileLogger::Write( KDirectory, logFileName, EFileLoggingModeAppend, aHeader ); |
|
135 RFileLogger::Write( KDirectory, logFileName, EFileLoggingModeAppend, KHeaderDivider ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------- |
|
139 // CamLogger::LogTestResult |
|
140 // Writes results of a test to either the passed, failed or log file. |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 void CamLogger::LogTestResult( const TDesC& aIdentifier, |
|
144 TTestFileType aExpr, const TDesC& aTestDesc ) |
|
145 { |
|
146 const TInt KMaxTestDescLength = 256; |
|
147 // Evaluate expression (aExpr), and write the test description to either the |
|
148 // passed.txt or failed.txt or log.txt file, depending on result. |
|
149 if ( aExpr == ETestFilePassed ) |
|
150 { |
|
151 // Create text |
|
152 _LIT( KPassedTest, "Test passed: " ); |
|
153 TBuf<KMaxTestDescLength> desc( KPassedTest ); |
|
154 desc.Append( aTestDesc ); |
|
155 |
|
156 // Write text to passed file. |
|
157 TBuf<KMaxFileNameLength> passedFileName; |
|
158 GetPassedFileName( aIdentifier, passedFileName ); |
|
159 RFileLogger::Write( KDirectory, passedFileName, EFileLoggingModeAppend, desc ); |
|
160 } |
|
161 else if ( aExpr == ETestFileFailed ) |
|
162 { |
|
163 // Create text |
|
164 _LIT( KFailedTest, "Test failed: " ); |
|
165 TBuf<KMaxTestDescLength> desc( KFailedTest ); |
|
166 desc.Append( aTestDesc ); |
|
167 |
|
168 // Write text to failed file. |
|
169 TBuf<KMaxFileNameLength> failedFileName; |
|
170 GetFailedFileName( aIdentifier, failedFileName ); |
|
171 RFileLogger::Write( KDirectory, failedFileName, EFileLoggingModeAppend, desc ); |
|
172 } |
|
173 else |
|
174 { |
|
175 // Write text to log file. |
|
176 TBuf<KMaxFileNameLength> logFileName; |
|
177 GetLogFileName( aIdentifier, logFileName ); |
|
178 RFileLogger::Write( KDirectory, logFileName, EFileLoggingModeAppend, aTestDesc ); |
|
179 } |
|
180 } |
|
181 |
|
182 void CamLogger::LogDetail( const TDesC& aIdentifier, |
|
183 const TDesC& aUnitTestId, |
|
184 TInt aTestId, |
|
185 TTestResult aResult, |
|
186 const TDesC& aDetail ) |
|
187 { |
|
188 // Write detail to log file. |
|
189 const TInt KMaxTestDescLength = 256; |
|
190 TBuf<KMaxFileNameLength> logFileName; |
|
191 GetLogFileName( aIdentifier, logFileName ); |
|
192 |
|
193 TBuf<KMaxTestDescLength> LogString; |
|
194 |
|
195 TBuf<KMaxTestDescLength> Result; |
|
196 switch (aResult) |
|
197 { |
|
198 case UTStarted: |
|
199 { |
|
200 _LIT(KUTStarted, "Started"); |
|
201 Result = KUTStarted; |
|
202 LogString.Format(_L("UT:%S,T%03d,%S,%S"), |
|
203 &aUnitTestId, |
|
204 static_cast<TInt>(aTestId), |
|
205 &Result, |
|
206 &aDetail); |
|
207 } |
|
208 break; |
|
209 case UTFinished: |
|
210 { |
|
211 _LIT(KUTFinished, "Finished"); |
|
212 Result = KUTFinished; |
|
213 LogString.Format(_L("UT:%S,T%03d,%S,%S"), |
|
214 &aUnitTestId, |
|
215 static_cast<TInt>(aTestId), |
|
216 &Result, |
|
217 &aDetail); |
|
218 } |
|
219 break; |
|
220 case UTFailed: |
|
221 { |
|
222 _LIT(KUTFailed, "Failed"); |
|
223 Result = KUTFailed; |
|
224 LogString.Format(_L("UT:%S,T%03d,%S,%S"), |
|
225 &aUnitTestId, |
|
226 static_cast<TInt>(aTestId), |
|
227 &Result, |
|
228 &aDetail); |
|
229 } |
|
230 break; |
|
231 case UTNumberOfTests: |
|
232 { |
|
233 _LIT(KUTNumberOfTests, "NoOfTests"); |
|
234 Result = KUTNumberOfTests; |
|
235 LogString.Format(_L("UT:%S,%S,%d"), |
|
236 &aUnitTestId, |
|
237 &Result, |
|
238 static_cast<TInt>(aTestId)); |
|
239 } |
|
240 break; |
|
241 case UTAllTestsFinished: |
|
242 { |
|
243 _LIT(KUTAllTestsFinished, "AllTestsFinished"); |
|
244 Result = KUTAllTestsFinished; |
|
245 LogString.Format(_L("UT:%S,%S"), |
|
246 &aUnitTestId, |
|
247 &Result); |
|
248 } |
|
249 break; |
|
250 default: |
|
251 { |
|
252 LogString.Format(_L("UT:Invalid Log")); |
|
253 } |
|
254 break; |
|
255 } |
|
256 |
|
257 RFileLogger::Write( KDirectory, logFileName, EFileLoggingModeAppend, LogString ); |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CamLogger::GetFailedFileName |
|
262 // Returns the file name of failed test results, for a specific identifer. |
|
263 // --------------------------------------------------------- |
|
264 // |
|
265 void CamLogger::GetFailedFileName( const TDesC& aIdentifier, TDes& aFileName ) |
|
266 { |
|
267 _LIT( KFailedPostfix, "Failed.txt" ); |
|
268 aFileName = aIdentifier; |
|
269 aFileName.Append( KFailedPostfix ); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------- |
|
273 // CamLogger::GetPassedFileName |
|
274 // Returns the file name of passed test results, for a specific identifer. |
|
275 // --------------------------------------------------------- |
|
276 // |
|
277 void CamLogger::GetPassedFileName( const TDesC& aIdentifier, TDes& aFileName ) |
|
278 { |
|
279 _LIT( KPassedPostfix, "Passed.txt" ); |
|
280 aFileName = aIdentifier; |
|
281 aFileName.Append( KPassedPostfix ); |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------- |
|
285 // CamLogger::GetLogFileName |
|
286 // Returns the file name of log test results, for a specific identifer. |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 void CamLogger::GetLogFileName( const TDesC& aIdentifier, TDes& aFileName ) |
|
290 { |
|
291 _LIT( KLogPostfix, "Log.txt" ); |
|
292 aFileName = aIdentifier; |
|
293 aFileName.Append( KLogPostfix ); |
|
294 } |
|
295 |
|
296 |
|
297 //#endif // __CAM_TEST_MODE__ |
|
298 // End of File |
|