os/persistentdata/loggingservices/rfilelogger/Logger/te_RFileLogger/src/addfield_logStep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/rfilelogger/Logger/te_RFileLogger/src/addfield_logStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,241 @@
1.4 +// Copyright (c) 2004-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 +// Example CTestStep derived implementation
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file addfield_logStep.cpp
1.23 +*/
1.24 +#include "addfield_logStep.h"
1.25 +#include "Te_RFileLoggerSuiteDefs.h"
1.26 +
1.27 +_LIT(K16BitFormatText,"logger string int = %d, string = %S");
1.28 +_LIT(K16BitString,"The String16");
1.29 +
1.30 +Caddfield_logStep::~Caddfield_logStep()
1.31 +/**
1.32 + * Destructor
1.33 + */
1.34 + {
1.35 + }
1.36 +
1.37 +Caddfield_logStep::Caddfield_logStep()
1.38 +/**
1.39 + * Constructor
1.40 + */
1.41 + {
1.42 + // **MUST** call SetTestStepName in the constructor as the controlling
1.43 + // framework uses the test step name immediately following construction to set
1.44 + // up the step's unique logging ID.
1.45 + SetTestStepName(Kaddfield_logStep);
1.46 + }
1.47 +
1.48 +TVerdict Caddfield_logStep::doTestStepPreambleL()
1.49 +/**
1.50 + * @return - TVerdict code
1.51 + * Override of base class virtual
1.52 + */
1.53 + {
1.54 + CTe_RFileLoggerSuiteStepBase::doTestStepPreambleL();
1.55 + SetTestStepResult(EPass);
1.56 + return TestStepResult();
1.57 + }
1.58 +
1.59 +
1.60 +TVerdict Caddfield_logStep::doTestStepL()
1.61 +/**
1.62 + * @return - TVerdict code
1.63 + * Override of base class pure virtual
1.64 + * Our implementation only gets called if the base class doTestStepPreambleL() did
1.65 + * not leave. That being the case, the current test result value will be EPass.
1.66 + */
1.67 + {
1.68 +
1.69 + if(TestStepResult()==EFail) return TestStepResult();
1.70 + INFO_PRINTF1(_L("AddField test and logging test"));
1.71 +
1.72 + // OS needs time to shutdown the server in case being connected previous test
1.73 + // The delay means we get server terminated from the OS
1.74 +//
1.75 + RFileFlogger ilogger;
1.76 + TInt err=ilogger.Connect();
1.77 + if(err)
1.78 + {
1.79 + INFO_PRINTF2(_L("Connect() failed. err = %d"),err);
1.80 + SetTestStepResult(EFail);
1.81 + return TestStepResult();
1.82 + }
1.83 + err=ilogger.CreateLog(KLogFile1,RFileFlogger::ELogModeAppend);
1.84 +// err=ilogger.CreateLog(KLogFile1,RFileFlogger::ELogModeOverWrite);
1.85 + //ELogModeAppend
1.86 + if(!err)
1.87 + {
1.88 + INFO_PRINTF1(_L("xml format file open passed and test start"));
1.89 + }
1.90 + else
1.91 + {
1.92 + ERR_PRINTF2(_L("error value = %d"),err);
1.93 + SetTestStepResult(EFail);
1.94 + return TestStepResult();
1.95 +
1.96 + }
1.97 +
1.98 + TBuf<20> buf16(K16BitString);
1.99 + TInt n=0;
1.100 + ilogger.SetLogLevel(RFileFlogger::ESevrAll);
1.101 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.102 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.103 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.104 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrHigh, K16BitFormatText,n++,&buf16);
1.105 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrMedium, K16BitFormatText,n++,&buf16);
1.106 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrLow, K16BitFormatText,n++,&buf16);
1.107 +
1.108 + INFO_PRINTF1(_L("test ESevrErr"));
1.109 + ilogger.SetLogLevel(RFileFlogger::ESevrErr);
1.110 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.111 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.112 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.113 +
1.114 + INFO_PRINTF1(_L("test log with add fileds"));
1.115 + TInt aLength = 2;
1.116 + TExtraLogField logField[2];
1.117 + logField[0].iLogFieldName.Copy(_L("SUITE_NAME"));
1.118 + logField[0].iLogFieldValue.Copy(_L("SUITE_VALUE"));
1.119 + logField[1].iLogFieldName.Copy(_L("TEST_NAME"));
1.120 + logField[1].iLogFieldValue.Copy(_L("TEST_VALUE"));
1.121 +
1.122 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, aLength, logField, K16BitFormatText,n++,&buf16);
1.123 +
1.124 +
1.125 + INFO_PRINTF1(_L("test ESevrWarn"));
1.126 + n=0;
1.127 + ilogger.SetLogLevel(RFileFlogger::ESevrWarn);
1.128 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.129 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.130 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.131 +
1.132 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
1.133 +
1.134 + INFO_PRINTF1(_L("test ESevrInfo"));
1.135 + n=0;
1.136 + ilogger.SetLogLevel(RFileFlogger::ESevrInfo);
1.137 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.138 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.139 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.140 +
1.141 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
1.142 +
1.143 + INFO_PRINTF1(_L("test ESevrAll"));
1.144 + n=0;
1.145 + ilogger.SetLogLevel(RFileFlogger::ESevrAll);
1.146 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.147 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.148 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.149 +
1.150 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
1.151 +// txt log test
1.152 + ilogger.Close();
1.153 + err=ilogger.Connect();
1.154 + if(err)
1.155 + {
1.156 + INFO_PRINTF2(_L("Connect() failed. err = %d"),err);
1.157 + SetTestStepResult(EFail);
1.158 + return TestStepResult();
1.159 + }
1.160 + INFO_PRINTF1(_L("RFileFlogger::ELogModeAppend test ..."));
1.161 + err=ilogger.CreateLog(KLogFiletxt,RFileFlogger::ELogModeAppend);
1.162 + if(!err)
1.163 + {
1.164 + INFO_PRINTF1(_L("RFileFlogger::ELogModeAppend testing is fine"));
1.165 + INFO_PRINTF1(_L("txt format file open passed and test start"));
1.166 + }
1.167 + else
1.168 + {
1.169 + ERR_PRINTF2(_L("error value = %d"),err);
1.170 + SetTestStepResult(EFail);
1.171 + return TestStepResult();
1.172 +
1.173 + }
1.174 +
1.175 + n=0;
1.176 + ilogger.SetLogLevel(RFileFlogger::ESevrAll);
1.177 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.178 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.179 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.180 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrHigh, K16BitFormatText,n++,&buf16);
1.181 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrMedium, K16BitFormatText,n++,&buf16);
1.182 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrLow, K16BitFormatText,n++,&buf16);
1.183 +
1.184 + INFO_PRINTF1(_L("test ESevrErr"));
1.185 + ilogger.SetLogLevel(RFileFlogger::ESevrErr);
1.186 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.187 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.188 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.189 +
1.190 + INFO_PRINTF1(_L("test log with add fileds"));
1.191 + aLength = 2;
1.192 + logField[0].iLogFieldName.Copy(_L("SUITE_NAME"));
1.193 + logField[0].iLogFieldValue.Copy(_L("SUITE_VALUE"));
1.194 + logField[1].iLogFieldName.Copy(_L("TEST_NAME"));
1.195 + logField[1].iLogFieldValue.Copy(_L("TEST_VALUE"));
1.196 +
1.197 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, aLength, logField, K16BitFormatText,n++,&buf16);
1.198 +
1.199 +
1.200 + INFO_PRINTF1(_L("test ESevrWarn"));
1.201 + n=0;
1.202 + ilogger.SetLogLevel(RFileFlogger::ESevrWarn);
1.203 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.204 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.205 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.206 +
1.207 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
1.208 +
1.209 + INFO_PRINTF1(_L("test ESevrInfo"));
1.210 + n=0;
1.211 + ilogger.SetLogLevel(RFileFlogger::ESevrInfo);
1.212 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.213 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.214 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.215 +
1.216 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
1.217 +
1.218 + INFO_PRINTF1(_L("test ESevrAll"));
1.219 + n=0;
1.220 + ilogger.SetLogLevel(RFileFlogger::ESevrAll);
1.221 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
1.222 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
1.223 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
1.224 +
1.225 + ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
1.226 +
1.227 +
1.228 + ilogger.Close();
1.229 +
1.230 + INFO_PRINTF1(_L("test finished"));
1.231 +
1.232 + return TestStepResult();
1.233 + }
1.234 +
1.235 +
1.236 +
1.237 +TVerdict Caddfield_logStep::doTestStepPostambleL()
1.238 +/**
1.239 + * @return - TVerdict code
1.240 + * Override of base class virtual
1.241 + */
1.242 + {
1.243 + return TestStepResult();
1.244 + }