|
1 /* |
|
2 * Copyright (c) 2009 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: This file contains the header file of the CAtsLogger |
|
15 * class. |
|
16 * |
|
17 */ |
|
18 |
|
19 #ifndef __ATSLOGGER_H__ |
|
20 #define __ATSLOGGER_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <f32file.h> |
|
24 |
|
25 // CONSTANTS |
|
26 _LIT(KAtsLogger, "AtsLogger"); |
|
27 _LIT(KAtsLoggerNa, "NA"); |
|
28 _LIT(KAtsLoggerPassed, "PASSED"); |
|
29 _LIT(KAtsLoggerFailed, "FAILED"); |
|
30 _LIT(KAtsLoggerSkipped, "SKIPPED"); |
|
31 _LIT(KAtsLoggerEmpty, ""); |
|
32 _LIT(KAtsLoggerSemaphore, "AtsLogger"); |
|
33 _LIT(KAtsLoggerXmlDirectory, "\\SPD_LOGS\\XML\\"); |
|
34 _LIT(KAtsLoggerRawDirectory, "\\SPD_LOGS\\RAW\\"); |
|
35 _LIT(KAtsLoggerXmlSuffix, ".xml"); |
|
36 _LIT(KAtsLoggerRawSuffix, ".log"); |
|
37 |
|
38 _LIT(KAtsLoggerTagOpen, "<"); |
|
39 _LIT(KAtsLoggerSpace, " "); |
|
40 _LIT(KAtsLoggerAttr, "=\""); |
|
41 _LIT(KAtsLoggerAttrClose, "\">"); |
|
42 _LIT(KAtsLoggerTagPost, ">"); |
|
43 _LIT(KAtsLoggerTagClose, "</"); |
|
44 _LIT(KAtsLoggerLf, "\n"); |
|
45 _LIT(KAtsLoggerIndent, " "); |
|
46 _LIT8(KAtsLoggerIndent8, " "); |
|
47 _LIT(KAtsLoggerCommentOpen, "<!--"); |
|
48 _LIT(KAtsLoggerCommentClose, "-->"); |
|
49 _LIT(KAtsLoggerQuot, """); |
|
50 _LIT(KAtsLoggerAmp, "&"); |
|
51 _LIT(KAtsLoggerApos, "'"); |
|
52 _LIT(KAtsLoggerLt, "<"); |
|
53 _LIT(KAtsLoggerGt, ">"); |
|
54 |
|
55 _LIT8(KAtsLoggerQuot8, """); |
|
56 _LIT8(KAtsLoggerAmp8, "&"); |
|
57 _LIT8(KAtsLoggerApos8, "'"); |
|
58 _LIT8(KAtsLoggerLt8, "<"); |
|
59 _LIT8(KAtsLoggerGt8, ">"); |
|
60 _LIT8(KAtsLoggerEmpty8, ""); |
|
61 |
|
62 _LIT(KAtsLoggerTagTestReport, "test-report"); |
|
63 _LIT(KAtsLoggerTagTestSet, "test-batch"); |
|
64 _LIT(KAtsLoggerTagTestCase, "test-case"); |
|
65 _LIT(KAtsLoggerTagTestSetInit, "batch-init"); |
|
66 _LIT(KAtsLoggerTagDescription, "description"); |
|
67 _LIT(KAtsLoggerTagDate, "date"); |
|
68 _LIT(KAtsLoggerTagFactory, "factory"); |
|
69 _LIT(KAtsLoggerTagComponent, "component"); |
|
70 _LIT(KAtsLoggerTagName, "name"); |
|
71 _LIT(KAtsLoggerTagVersion, "version"); |
|
72 _LIT(KAtsLoggerTagTestSetResult, "batch-result"); |
|
73 _LIT(KAtsLoggerTagId, "id"); |
|
74 _LIT(KAtsLoggerTagTestCaseInit, "case-init"); |
|
75 _LIT(KAtsLoggerTagExpected, "expected-result"); |
|
76 _LIT(KAtsLoggerTagRunTime, "run-time"); |
|
77 _LIT(KAtsLoggerTagTestCaseResult, "case-result"); |
|
78 _LIT(KAtsLoggerTagActual, "actual-result"); |
|
79 _LIT(KAtsLoggerTagDebug, "debug-info"); |
|
80 _LIT(KAtsLoggerTagWarning, "warning"); |
|
81 _LIT(KAtsLoggerTagError, "error"); |
|
82 _LIT(KAtsLoggerTagStatus, "status"); |
|
83 _LIT(KAtsLoggerTimeStamp, "time-stamp"); |
|
84 |
|
85 const TInt KAtsLoggerBufferSegmentGranularity = 32; |
|
86 |
|
87 // CLASS DECLARATION |
|
88 |
|
89 // DESCRIPTION |
|
90 // CAtsLogger defines API for test case result logging. |
|
91 class CAtsLogger : public CBase |
|
92 { |
|
93 public: // Public enumerations |
|
94 enum TReportStage |
|
95 { |
|
96 ENone, |
|
97 EUninitialized, |
|
98 EBeginTestReport, |
|
99 EBeginTestSet, |
|
100 EBeginTestCase, |
|
101 ESetTestCaseVerdict, |
|
102 EEndTestCase, |
|
103 EEndTestSet, |
|
104 EEndTestReport, |
|
105 EFinished |
|
106 }; |
|
107 private: // Private enumerations |
|
108 // None |
|
109 |
|
110 public: // Public constructors/desctructors |
|
111 |
|
112 /** |
|
113 * Symbian OS constructor |
|
114 */ |
|
115 IMPORT_C static CAtsLogger* NewL( const TDesC& aName, |
|
116 TBool aAfterReboot = EFalse ); |
|
117 |
|
118 /** |
|
119 * C++ destructor |
|
120 */ |
|
121 IMPORT_C ~CAtsLogger(); |
|
122 |
|
123 public: // Public new functions |
|
124 |
|
125 /** |
|
126 * Returns error message. Also includes |
|
127 * base E32 error codes. |
|
128 */ |
|
129 IMPORT_C static const TPtrC ErrorMessage(const TInt& aError); |
|
130 |
|
131 /** |
|
132 * Closes opened resources. Desctructor calls |
|
133 * this if it is not called before. |
|
134 */ |
|
135 IMPORT_C void CloseL(); |
|
136 |
|
137 /** |
|
138 * IsValid() returns ETrue if this logger is valid and |
|
139 * able to write log. |
|
140 */ |
|
141 IMPORT_C TBool IsValid(); |
|
142 |
|
143 /** |
|
144 * BeginTestReportL() should be called at the beginning of the program, |
|
145 * before any testing begins |
|
146 */ |
|
147 IMPORT_C void BeginTestReportL(); |
|
148 |
|
149 /** |
|
150 * EndTestReportL() must be called at the end of the program |
|
151 */ |
|
152 IMPORT_C void EndTestReportL(); |
|
153 |
|
154 /** |
|
155 * SaveForRebootL() should be called before reboot to save data. |
|
156 */ |
|
157 IMPORT_C void SaveForRebootL(); |
|
158 |
|
159 /** |
|
160 * ContinueAfterRebootL() must be called to continue |
|
161 * after reboot. |
|
162 */ |
|
163 IMPORT_C void ContinueAfterRebootL(); |
|
164 |
|
165 /** |
|
166 * BeginTestSetL() must be called when a new test set begins |
|
167 * |
|
168 * factory = component factory whose component is being tested |
|
169 * component = name of the software component being tested |
|
170 * version = version of the software component |
|
171 * description = short, optional description of the batch |
|
172 */ |
|
173 IMPORT_C void BeginTestSetL(const TDesC& aFactory = KAtsLoggerNa, |
|
174 const TDesC& aComponent = KAtsLoggerNa, |
|
175 const TDesC& aVersion = KAtsLoggerNa, |
|
176 const TDesC& aDescription = KAtsLoggerEmpty); |
|
177 |
|
178 /** |
|
179 * EndTestSetL() must be called as soon as a test set ends |
|
180 */ |
|
181 IMPORT_C void EndTestSetL(); |
|
182 |
|
183 /** |
|
184 * BeginTestCaseL() is called whenever an individual testcase begins |
|
185 * |
|
186 * id = unique id of the testcase |
|
187 * expected = expected result of the test (if applicable) |
|
188 * info = short descritpion of the expected result (if applicable) |
|
189 */ |
|
190 IMPORT_C void BeginTestCaseL(const TDesC& aId, |
|
191 const TDesC& aExpected = KAtsLoggerNa, |
|
192 const TDesC& aInfo = KAtsLoggerEmpty, |
|
193 const TDesC& aVersion = KAtsLoggerEmpty); |
|
194 |
|
195 /** |
|
196 * BeginTestCaseL() is called whenever an individual testcase begins |
|
197 * |
|
198 * id = unique id of the testcase |
|
199 * expected = expected result code of the test (if applicable) |
|
200 * info = short descritpion of the expected result (if applicable) |
|
201 */ |
|
202 IMPORT_C void BeginTestCaseL(const TDesC& aId, |
|
203 const TInt aExpected, |
|
204 const TDesC& aInfo = KAtsLoggerEmpty, |
|
205 const TDesC& aVersion = KAtsLoggerEmpty); |
|
206 |
|
207 /** |
|
208 * BeginTestCaseReportL() is called whenever an individual testcase report begins |
|
209 * |
|
210 * id = unique id of the testcase |
|
211 * expected = expected result code of the test (if applicable) |
|
212 * startTime= test case starting time |
|
213 * info = short descritpion of the expected result (if applicable) |
|
214 */ |
|
215 IMPORT_C void BeginTestCaseReportL( const TDesC& aId, |
|
216 const TDesC& aExpected, |
|
217 const TTime& aStartTime, |
|
218 const TDesC& aInfo = KAtsLoggerEmpty, |
|
219 const TDesC& aVersion = KAtsLoggerEmpty ); |
|
220 |
|
221 /** |
|
222 * BeginTestCaseReportL() is called whenever an individual testcase report begins |
|
223 * |
|
224 * id = unique id of the testcase |
|
225 * expected = expected result code of the test (if applicable) |
|
226 * startTime= test case starting time |
|
227 * info = short descritpion of the expected result (if applicable) |
|
228 */ |
|
229 IMPORT_C void BeginTestCaseReportL( const TDesC& aId, |
|
230 const TInt aExpected, |
|
231 const TTime& aStartTime, |
|
232 const TDesC& aInfo = KAtsLoggerEmpty, |
|
233 const TDesC& aVersion = KAtsLoggerEmpty ); |
|
234 |
|
235 /** |
|
236 * EndTestCaseL() is called when an individual testcase ends |
|
237 */ |
|
238 IMPORT_C void EndTestCaseL(); |
|
239 |
|
240 /** |
|
241 * TestCasePassed() must be called between calls |
|
242 * to BeginTestCase() and EndTestCase(). This results |
|
243 * test case to be passed. |
|
244 */ |
|
245 IMPORT_C void TestCasePassed(); |
|
246 |
|
247 |
|
248 /** |
|
249 * TestCaseFailed() must be called between calls |
|
250 * to BeginTestCase() and EndTestCase(). This results |
|
251 * test case to be failed. |
|
252 */ |
|
253 IMPORT_C void TestCaseFailed(); |
|
254 |
|
255 /** |
|
256 * TestCaseSkipped() must be called between calls |
|
257 * to BeginTestCase() and EndTestCase(). This results |
|
258 * test case to be skipped. |
|
259 */ |
|
260 IMPORT_C void TestCaseSkipped(); |
|
261 |
|
262 /** |
|
263 * TestCaseNa() must be called between calls |
|
264 * to BeginTestCase() and EndTestCase(). This results |
|
265 * test case to be N/A. |
|
266 */ |
|
267 IMPORT_C void TestCaseNa(); |
|
268 |
|
269 /** |
|
270 * SetTestCaseResultL() sets the actual result of the test (if applicable), |
|
271 * this should correspond to the expected result (see BeginTestCase) if |
|
272 * the test succeeds. |
|
273 |
|
274 * Must be called between calls to BeginTestCaseL() and EndTestCaseL(). |
|
275 */ |
|
276 IMPORT_C void SetTestCaseResultL(const TInt aResult); |
|
277 IMPORT_C void SetTestCaseResultL(const TDesC& aResult = KAtsLoggerEmpty); |
|
278 IMPORT_C void SetTestCaseResultL(TRefByValue<const TDesC> aFmt,...); |
|
279 |
|
280 /** |
|
281 * DebugL(), WarningL(), ErrorL() and CommentL() as used to place |
|
282 * informational messages of appropriate debug level into the test report. |
|
283 * These functions can be called anywhere between BeginReportL() and EndReportL(). |
|
284 */ |
|
285 IMPORT_C void DebugL(const TDesC& aMsg); |
|
286 IMPORT_C void DebugL(TRefByValue<const TDesC> aFmt,...); |
|
287 |
|
288 IMPORT_C void WarningL(const TDesC& aMsg); |
|
289 IMPORT_C void WarningL(TRefByValue<const TDesC> aFmt,...); |
|
290 |
|
291 IMPORT_C void ErrorL(const TDesC& aMsg); |
|
292 IMPORT_C void ErrorL(TRefByValue<const TDesC> aFmt,...); |
|
293 |
|
294 IMPORT_C void CommentL(const TDesC& aMsg); |
|
295 IMPORT_C void CommentL(TRefByValue<const TDesC> aFmt,...); |
|
296 |
|
297 /** |
|
298 * RawLogL() writes to a separate log file. |
|
299 */ |
|
300 IMPORT_C TInt RawLogL(const TDesC& aMsg); |
|
301 IMPORT_C TInt RawLogL(TRefByValue<const TDesC> aFmt,...); |
|
302 |
|
303 /** |
|
304 * DebugOutput() writes to RDebug |
|
305 */ |
|
306 IMPORT_C void DebugOutput(const TDesC& aMsg); |
|
307 |
|
308 /** |
|
309 * Set this to ETrue if client should use |
|
310 * full set of reporting methods |
|
311 */ |
|
312 IMPORT_C void SetFullReporting(TBool aFlag); |
|
313 |
|
314 /** |
|
315 * Set this to ETrue if XML log should be |
|
316 * written to the debug port also. |
|
317 */ |
|
318 IMPORT_C void SetDebugOutput(TBool aFlag); |
|
319 |
|
320 /** |
|
321 * Set this to ETrue if XML log should have |
|
322 * indentation. This only adds human readability. |
|
323 */ |
|
324 IMPORT_C void SetIndentation(TBool aFlag); |
|
325 |
|
326 |
|
327 public: // Public functions from base classes |
|
328 // None |
|
329 |
|
330 protected: // Protected new functions |
|
331 /** |
|
332 * Outputs message closed by the tags. |
|
333 */ |
|
334 void TagL(const TDesC& aTag, |
|
335 const TDesC& aMsg); |
|
336 |
|
337 /** |
|
338 * Adds attribute with value to the message and |
|
339 * outputs message closed by the tags. |
|
340 */ |
|
341 void TagL(const TDesC& aTag, |
|
342 const TDesC& aMsg, |
|
343 const TDesC& aAttribute, |
|
344 const TDesC& aValue); |
|
345 |
|
346 /** |
|
347 * Outputs message closed by the tags. This is used with |
|
348 * DebugL(), WarningL(), ErrorL() and CommentL(). Time stamp is |
|
349 * added to the message. |
|
350 */ |
|
351 void TimeStampedMessageL(const TDesC& aTag, |
|
352 const TDesC& aMsg); |
|
353 |
|
354 /** |
|
355 * Opens a tag. |
|
356 */ |
|
357 void OpenTagL(const TDesC& aTag); |
|
358 |
|
359 |
|
360 /** |
|
361 * Opens a tag with attribute and value. |
|
362 */ |
|
363 void OpenTagL(const TDesC& aTag, |
|
364 const TDesC& aAttribute, |
|
365 const TDesC& aValue); |
|
366 |
|
367 /** |
|
368 * Opens a tag and increases indent level. |
|
369 */ |
|
370 void OpenTagIndentL(const TDesC& aTag); |
|
371 |
|
372 |
|
373 /** |
|
374 * Opens a tag with attribute having value and increases indent level. |
|
375 */ |
|
376 void OpenTagIndentL(const TDesC& aTag, |
|
377 const TDesC& aAttribute, |
|
378 const TDesC& aValue); |
|
379 |
|
380 /** |
|
381 * Closes a tag; |
|
382 */ |
|
383 void CloseTagL(const TDesC& aTag); |
|
384 |
|
385 /** |
|
386 * Closes a tag and descreases indent level. |
|
387 */ |
|
388 void CloseTagIndentL(const TDesC& aTag); |
|
389 |
|
390 /** |
|
391 * Outputs line feed. |
|
392 */ |
|
393 void LineFeedL(); |
|
394 |
|
395 /** |
|
396 * Writes data to the specified file. |
|
397 */ |
|
398 void WriteL(const TDesC& aData, RFile& aFile); |
|
399 |
|
400 /** |
|
401 * Writes data to the XML file. |
|
402 */ |
|
403 void WriteL(const TDesC& aData); |
|
404 |
|
405 /** |
|
406 * Encodes XML special chararacters from message |
|
407 */ |
|
408 HBufC* EncodeLC(const TDesC& aMsg); |
|
409 |
|
410 /** |
|
411 * Checks whether report stage transition is legal. |
|
412 */ |
|
413 TBool IsTransitionLegal(const TReportStage& aNewStage); |
|
414 |
|
415 protected: // Protected functions from base classes |
|
416 // None |
|
417 |
|
418 protected: // Protected data |
|
419 // None |
|
420 |
|
421 private: // Private functions |
|
422 /** |
|
423 * By default Symbian OS two-phase constructor is private. |
|
424 */ |
|
425 void ConstructL( TBool aAfterReboot ); |
|
426 |
|
427 /** |
|
428 * C++ constructor |
|
429 */ |
|
430 CAtsLogger(const TDesC& aName); |
|
431 |
|
432 /** |
|
433 * Checks whether directory exist or not |
|
434 */ |
|
435 TBool CheckDirectoryL(const TDesC& aDirName, TChar& aDrive); |
|
436 |
|
437 /** |
|
438 * Replaces file if already exist |
|
439 */ |
|
440 TInt ReplaceFileL(const TDesC& aFileName); |
|
441 |
|
442 /** |
|
443 * Open existing file if already exist |
|
444 */ |
|
445 TInt OpenExistingFileL(const TDesC& aFileName); |
|
446 |
|
447 /** |
|
448 * Formats given date to a format of yyyy-mm-dd hh:mm:ss |
|
449 */ |
|
450 HBufC* FormatDateLC(TDateTime aDate); |
|
451 |
|
452 /** |
|
453 * Formats given time to a format of hh:mm:ss |
|
454 */ |
|
455 HBufC* FormatTimeLC(TTimeIntervalMicroSeconds aTime); |
|
456 |
|
457 /** |
|
458 * Expands buffer and then writes aBuf into it. |
|
459 */ |
|
460 TInt BufferL(CBufBase* aBufBase, TInt& aLength,const TDesC& aBuf); |
|
461 |
|
462 /** |
|
463 * Writes whole buffer to a file. Does not reset buffer. |
|
464 */ |
|
465 TInt WriteBufferToFileL(CBufBase* aCBufBase, const TDesC& aFileName); |
|
466 |
|
467 /** |
|
468 * Writes whole buffer to the debug port. Does not reset buffer. |
|
469 */ |
|
470 TInt WriteBufferToDebugPortL(CBufBase* aCBufBase); |
|
471 |
|
472 protected: // Protected data |
|
473 // TTestSet data holder class definition and implementation |
|
474 class TTestSet |
|
475 { |
|
476 public: |
|
477 TTime iStartTime; |
|
478 }; |
|
479 |
|
480 // TCase data holder class definition and implementation |
|
481 class TTestCase |
|
482 { |
|
483 public: |
|
484 TTestCase() { iResult = NULL; } |
|
485 ~TTestCase() |
|
486 { |
|
487 if (iResult) |
|
488 { |
|
489 delete iResult; |
|
490 iResult = NULL; |
|
491 } |
|
492 } |
|
493 public: |
|
494 HBufC* iResult; |
|
495 TPtrC iStatus; |
|
496 TTime iStartTime; |
|
497 |
|
498 }; |
|
499 |
|
500 // Data holder for batch information |
|
501 CAtsLogger::TTestSet iTestSet; |
|
502 |
|
503 // Data holder for test case information |
|
504 CAtsLogger::TTestCase iTestCase; |
|
505 |
|
506 // Holds current report stage |
|
507 CAtsLogger::TReportStage iReportStage; |
|
508 |
|
509 // Test case and logger ID |
|
510 const TFileName iName; |
|
511 |
|
512 private: // Private data |
|
513 // Dynamic buffer for XML data |
|
514 CBufBase* iXmlBuffer; |
|
515 |
|
516 // Current legth of iXmlBuffer |
|
517 TInt iXmlBufferLength; |
|
518 |
|
519 // Indentation level of outputted XML |
|
520 int iIndentLevel; |
|
521 |
|
522 // Handle to file server |
|
523 RFs iRfs; |
|
524 |
|
525 // The name of XML file |
|
526 TFileName iXmlLogFileName; |
|
527 |
|
528 // The name of raw log file |
|
529 TFileName iRawLogFileName; |
|
530 |
|
531 // Flag to indicate that raw log should be done |
|
532 TBool iRawLog; |
|
533 |
|
534 // Flag to indicate that XML log should be done |
|
535 TBool iXmlLog; |
|
536 |
|
537 // Flag to indicate that logger is valid |
|
538 TBool iValid; |
|
539 |
|
540 // Flag to indicate that a line feed has been done |
|
541 TBool iLineFeedDone; |
|
542 |
|
543 // Flag to indicate that BeginTestCase() has been called |
|
544 // and EndTestCase() hasn't yet been called. |
|
545 TBool iInTestCase; |
|
546 |
|
547 // Flag to indicate that logger is closed |
|
548 TBool iClosed; |
|
549 |
|
550 // Flag to indicate if client should use |
|
551 // full set of logger methods: |
|
552 // BeginTestReportL() |
|
553 // BeginTestSetL(); |
|
554 // BeginTestCaseL(); |
|
555 // TestCasePassed(); // or other verdict method |
|
556 // EndTestCase(); |
|
557 // EndTestSetL(); |
|
558 // EndTestReportL(); |
|
559 TBool iFullReportingMode; |
|
560 |
|
561 // Flag to indicate that XML log should be |
|
562 // written to the debug port also |
|
563 TBool iDoDebugOutput; |
|
564 |
|
565 // Flag to indicate that logger does intendation |
|
566 // to the XML file |
|
567 TBool iDoIndentation; |
|
568 |
|
569 public: // Friend classes |
|
570 // None |
|
571 |
|
572 protected: // Friend classes |
|
573 // None |
|
574 |
|
575 private: // Friend classes |
|
576 // None |
|
577 }; |
|
578 |
|
579 #endif// End of File |