|
1 // Copyright (c) 2005-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 // Neil Taylor |
|
15 // System Includes |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32cons.h> |
|
21 |
|
22 #include <Test\RFileLogger.h> |
|
23 |
|
24 /******************************************************************************** |
|
25 * Externally available test functions |
|
26 * TInt CreateTextTest(void) |
|
27 * TInt CreateXMLTest(void) |
|
28 * TInt AppendXMLTest(void) |
|
29 ********************************************************************************/ |
|
30 |
|
31 static TInt WriteTextTest(RFileFlogger& logger); |
|
32 static TInt LogLevelTest(RFileFlogger& logger); |
|
33 static TInt LogAdditionalFieldsTest(RFileFlogger& logger); |
|
34 |
|
35 TInt CreateTextTest(void) |
|
36 { |
|
37 TInt err = KErrNone; |
|
38 |
|
39 RFileFlogger logger; |
|
40 |
|
41 err = logger.Connect( ); |
|
42 err = logger.CreateLog( _L("C:\\logs\\logger.txt"), RFileFlogger::ELogModeOverWrite ); |
|
43 |
|
44 WriteTextTest( logger ); |
|
45 LogLevelTest( logger ); |
|
46 LogAdditionalFieldsTest( logger ); |
|
47 |
|
48 logger.Close( ); |
|
49 |
|
50 return ( err ); |
|
51 } |
|
52 |
|
53 TInt CreateXMLTest(void) |
|
54 { |
|
55 TInt err = KErrNone; |
|
56 |
|
57 RFileFlogger logger; |
|
58 |
|
59 err = logger.Connect( ); |
|
60 err = logger.CreateLog( _L("C:\\logger.xml"), RFileFlogger::ELogModeOverWrite ); |
|
61 |
|
62 WriteTextTest( logger ); |
|
63 LogLevelTest( logger ); |
|
64 LogAdditionalFieldsTest( logger ); |
|
65 |
|
66 logger.Close( ); |
|
67 |
|
68 return ( err ); |
|
69 } |
|
70 |
|
71 TInt AppendXMLTest(void) |
|
72 { |
|
73 TInt err = KErrNone; |
|
74 |
|
75 RFileFlogger logger; |
|
76 |
|
77 err = logger.Connect( ); |
|
78 err = logger.CreateLog( _L("C:\\logger.xml"), RFileFlogger::ELogModeAppend ); |
|
79 |
|
80 WriteTextTest( logger ); |
|
81 |
|
82 logger.Close( ); |
|
83 |
|
84 return ( err ); |
|
85 } |
|
86 |
|
87 TInt WriteTextTest(RFileFlogger& logger) |
|
88 { |
|
89 TInt err = KErrNone; |
|
90 |
|
91 logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrWarn, _L("This is a warning.") ); |
|
92 |
|
93 return ( err ); |
|
94 } |
|
95 |
|
96 TInt LogLevelTest(RFileFlogger& logger) |
|
97 { |
|
98 TInt err = KErrNone; |
|
99 |
|
100 logger.SetLogLevel( RFileFlogger::ESevrAll ); |
|
101 logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the first info log.") ); |
|
102 logger.SetLogLevel( RFileFlogger::ESevrErr ); |
|
103 logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the second info log.") ); |
|
104 logger.SetLogLevel( RFileFlogger::ESevrAll ); |
|
105 logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the third info log.") ); |
|
106 |
|
107 return ( err ); |
|
108 } |
|
109 |
|
110 TInt LogAdditionalFieldsTest(RFileFlogger& logger) |
|
111 { |
|
112 TInt err = KErrNone; |
|
113 |
|
114 TExtraLogField fields[2]; |
|
115 |
|
116 fields[0].iLogFieldName = _L("Animal"); |
|
117 fields[0].iLogFieldValue = _L("Rabbit"); |
|
118 fields[1].iLogFieldName = _L("City"); |
|
119 fields[1].iLogFieldValue = _L("London"); |
|
120 |
|
121 logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, 2, fields, _L("This is %d fields."), 2 ); |
|
122 |
|
123 return ( err ); |
|
124 } |
|
125 |