1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/rfilelogger/Logger/Test/src/TestLogger.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,125 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Neil Taylor
1.18 +// System Includes
1.19 +//
1.20 +//
1.21 +
1.22 +#include <e32base.h>
1.23 +#include <e32cons.h>
1.24 +
1.25 +#include <Test\RFileLogger.h>
1.26 +
1.27 +/********************************************************************************
1.28 + * Externally available test functions
1.29 + * TInt CreateTextTest(void)
1.30 + * TInt CreateXMLTest(void)
1.31 + * TInt AppendXMLTest(void)
1.32 + ********************************************************************************/
1.33 +
1.34 +static TInt WriteTextTest(RFileFlogger& logger);
1.35 +static TInt LogLevelTest(RFileFlogger& logger);
1.36 +static TInt LogAdditionalFieldsTest(RFileFlogger& logger);
1.37 +
1.38 +TInt CreateTextTest(void)
1.39 +{
1.40 + TInt err = KErrNone;
1.41 +
1.42 + RFileFlogger logger;
1.43 +
1.44 + err = logger.Connect( );
1.45 + err = logger.CreateLog( _L("C:\\logs\\logger.txt"), RFileFlogger::ELogModeOverWrite );
1.46 +
1.47 + WriteTextTest( logger );
1.48 + LogLevelTest( logger );
1.49 + LogAdditionalFieldsTest( logger );
1.50 +
1.51 + logger.Close( );
1.52 +
1.53 + return ( err );
1.54 +}
1.55 +
1.56 +TInt CreateXMLTest(void)
1.57 +{
1.58 + TInt err = KErrNone;
1.59 +
1.60 + RFileFlogger logger;
1.61 +
1.62 + err = logger.Connect( );
1.63 + err = logger.CreateLog( _L("C:\\logger.xml"), RFileFlogger::ELogModeOverWrite );
1.64 +
1.65 + WriteTextTest( logger );
1.66 + LogLevelTest( logger );
1.67 + LogAdditionalFieldsTest( logger );
1.68 +
1.69 + logger.Close( );
1.70 +
1.71 + return ( err );
1.72 +}
1.73 +
1.74 +TInt AppendXMLTest(void)
1.75 +{
1.76 + TInt err = KErrNone;
1.77 +
1.78 + RFileFlogger logger;
1.79 +
1.80 + err = logger.Connect( );
1.81 + err = logger.CreateLog( _L("C:\\logger.xml"), RFileFlogger::ELogModeAppend );
1.82 +
1.83 + WriteTextTest( logger );
1.84 +
1.85 + logger.Close( );
1.86 +
1.87 + return ( err );
1.88 +}
1.89 +
1.90 +TInt WriteTextTest(RFileFlogger& logger)
1.91 +{
1.92 + TInt err = KErrNone;
1.93 +
1.94 + logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrWarn, _L("This is a warning.") );
1.95 +
1.96 + return ( err );
1.97 +}
1.98 +
1.99 +TInt LogLevelTest(RFileFlogger& logger)
1.100 +{
1.101 + TInt err = KErrNone;
1.102 +
1.103 + logger.SetLogLevel( RFileFlogger::ESevrAll );
1.104 + logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the first info log.") );
1.105 + logger.SetLogLevel( RFileFlogger::ESevrErr );
1.106 + logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the second info log.") );
1.107 + logger.SetLogLevel( RFileFlogger::ESevrAll );
1.108 + logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, _L("This is the third info log.") );
1.109 +
1.110 + return ( err );
1.111 +}
1.112 +
1.113 +TInt LogAdditionalFieldsTest(RFileFlogger& logger)
1.114 +{
1.115 + TInt err = KErrNone;
1.116 +
1.117 + TExtraLogField fields[2];
1.118 +
1.119 + fields[0].iLogFieldName = _L("Animal");
1.120 + fields[0].iLogFieldValue = _L("Rabbit");
1.121 + fields[1].iLogFieldName = _L("City");
1.122 + fields[1].iLogFieldValue = _L("London");
1.123 +
1.124 + logger.Log( ((TText8*)(__FILE__)), __LINE__, RFileFlogger::ESevrInfo, 2, fields, _L("This is %d fields."), 2 );
1.125 +
1.126 + return ( err );
1.127 +}
1.128 +