sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Neil Taylor
|
sl@0
|
15 |
// System Includes
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <e32cons.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <Test\RFileLogger.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
/********************************************************************************
|
sl@0
|
25 |
* Externally available test functions
|
sl@0
|
26 |
* TInt CreateTextTest(void)
|
sl@0
|
27 |
* TInt CreateXMLTest(void)
|
sl@0
|
28 |
* TInt AppendXMLTest(void)
|
sl@0
|
29 |
********************************************************************************/
|
sl@0
|
30 |
|
sl@0
|
31 |
static TInt WriteTextTest(RFileFlogger& logger);
|
sl@0
|
32 |
static TInt LogLevelTest(RFileFlogger& logger);
|
sl@0
|
33 |
static TInt LogAdditionalFieldsTest(RFileFlogger& logger);
|
sl@0
|
34 |
|
sl@0
|
35 |
TInt CreateTextTest(void)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
TInt err = KErrNone;
|
sl@0
|
38 |
|
sl@0
|
39 |
RFileFlogger logger;
|
sl@0
|
40 |
|
sl@0
|
41 |
err = logger.Connect( );
|
sl@0
|
42 |
err = logger.CreateLog( _L("C:\\logs\\logger.txt"), RFileFlogger::ELogModeOverWrite );
|
sl@0
|
43 |
|
sl@0
|
44 |
WriteTextTest( logger );
|
sl@0
|
45 |
LogLevelTest( logger );
|
sl@0
|
46 |
LogAdditionalFieldsTest( logger );
|
sl@0
|
47 |
|
sl@0
|
48 |
logger.Close( );
|
sl@0
|
49 |
|
sl@0
|
50 |
return ( err );
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
TInt CreateXMLTest(void)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
TInt err = KErrNone;
|
sl@0
|
56 |
|
sl@0
|
57 |
RFileFlogger logger;
|
sl@0
|
58 |
|
sl@0
|
59 |
err = logger.Connect( );
|
sl@0
|
60 |
err = logger.CreateLog( _L("C:\\logger.xml"), RFileFlogger::ELogModeOverWrite );
|
sl@0
|
61 |
|
sl@0
|
62 |
WriteTextTest( logger );
|
sl@0
|
63 |
LogLevelTest( logger );
|
sl@0
|
64 |
LogAdditionalFieldsTest( logger );
|
sl@0
|
65 |
|
sl@0
|
66 |
logger.Close( );
|
sl@0
|
67 |
|
sl@0
|
68 |
return ( err );
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
TInt AppendXMLTest(void)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
TInt err = KErrNone;
|
sl@0
|
74 |
|
sl@0
|
75 |
RFileFlogger logger;
|
sl@0
|
76 |
|
sl@0
|
77 |
err = logger.Connect( );
|
sl@0
|
78 |
err = logger.CreateLog( _L("C:\\logger.xml"), RFileFlogger::ELogModeAppend );
|
sl@0
|
79 |
|
sl@0
|
80 |
WriteTextTest( logger );
|
sl@0
|
81 |
|
sl@0
|
82 |
logger.Close( );
|
sl@0
|
83 |
|
sl@0
|
84 |
return ( err );
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
TInt WriteTextTest(RFileFlogger& logger)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
TInt err = KErrNone;
|
sl@0
|
90 |
|
sl@0
|
91 |
logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrWarn, _L("This is a warning.") );
|
sl@0
|
92 |
|
sl@0
|
93 |
return ( err );
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
TInt LogLevelTest(RFileFlogger& logger)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
TInt err = KErrNone;
|
sl@0
|
99 |
|
sl@0
|
100 |
logger.SetLogLevel( RFileFlogger::ESevrAll );
|
sl@0
|
101 |
logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the first info log.") );
|
sl@0
|
102 |
logger.SetLogLevel( RFileFlogger::ESevrErr );
|
sl@0
|
103 |
logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the second info log.") );
|
sl@0
|
104 |
logger.SetLogLevel( RFileFlogger::ESevrAll );
|
sl@0
|
105 |
logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the third info log.") );
|
sl@0
|
106 |
|
sl@0
|
107 |
return ( err );
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
TInt LogAdditionalFieldsTest(RFileFlogger& logger)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TInt err = KErrNone;
|
sl@0
|
113 |
|
sl@0
|
114 |
TExtraLogField fields[2];
|
sl@0
|
115 |
|
sl@0
|
116 |
fields[0].iLogFieldName = _L("Animal");
|
sl@0
|
117 |
fields[0].iLogFieldValue = _L("Rabbit");
|
sl@0
|
118 |
fields[1].iLogFieldName = _L("City");
|
sl@0
|
119 |
fields[1].iLogFieldValue = _L("London");
|
sl@0
|
120 |
|
sl@0
|
121 |
logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, 2, fields, _L("This is %d fields."), 2 );
|
sl@0
|
122 |
|
sl@0
|
123 |
return ( err );
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|