os/persistentdata/loggingservices/rfilelogger/Logger/te_RFileLogger/src/addfield_logStep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2004-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 // Example CTestStep derived implementation
    15 // 
    16 //
    17 
    18 /**
    19  @file addfield_logStep.cpp
    20 */
    21 #include "addfield_logStep.h"
    22 #include "Te_RFileLoggerSuiteDefs.h"
    23 
    24 _LIT(K16BitFormatText,"logger string int = %d,  string = %S");
    25 _LIT(K16BitString,"The String16");
    26 
    27 Caddfield_logStep::~Caddfield_logStep()
    28 /**
    29  * Destructor
    30  */
    31 	{
    32 	}
    33 
    34 Caddfield_logStep::Caddfield_logStep()
    35 /**
    36  * Constructor
    37  */
    38 	{
    39 	// **MUST** call SetTestStepName in the constructor as the controlling
    40 	// framework uses the test step name immediately following construction to set
    41 	// up the step's unique logging ID.
    42 	SetTestStepName(Kaddfield_logStep);
    43 	}
    44 
    45 TVerdict Caddfield_logStep::doTestStepPreambleL()
    46 /**
    47  * @return - TVerdict code
    48  * Override of base class virtual
    49  */
    50 	{
    51 	CTe_RFileLoggerSuiteStepBase::doTestStepPreambleL();
    52 		SetTestStepResult(EPass);
    53 	return TestStepResult();
    54 	}
    55 
    56 
    57 TVerdict Caddfield_logStep::doTestStepL()
    58 /**
    59  * @return - TVerdict code
    60  * Override of base class pure virtual
    61  * Our implementation only gets called if the base class doTestStepPreambleL() did
    62  * not leave. That being the case, the current test result value will be EPass.
    63  */
    64 	{
    65 	
    66 	if(TestStepResult()==EFail) return TestStepResult();
    67 	INFO_PRINTF1(_L("AddField test and logging test")); 
    68 
    69 	// OS needs time to shutdown the server in case being connected previous test
    70 	// The delay means we get server terminated from the OS
    71 //	
    72 	RFileFlogger ilogger;
    73 	TInt err=ilogger.Connect();
    74 	if(err)
    75 	{
    76 		INFO_PRINTF2(_L("Connect() failed. err = %d"),err);
    77 		SetTestStepResult(EFail);
    78 		return TestStepResult();
    79 	}
    80 	err=ilogger.CreateLog(KLogFile1,RFileFlogger::ELogModeAppend);
    81 //	err=ilogger.CreateLog(KLogFile1,RFileFlogger::ELogModeOverWrite);
    82 	//ELogModeAppend
    83 	if(!err)
    84 	{
    85 		INFO_PRINTF1(_L("xml format file open passed and test start"));
    86 	}
    87 	else  
    88 	{
    89 		ERR_PRINTF2(_L("error value = %d"),err);
    90 		SetTestStepResult(EFail);
    91 		return TestStepResult();
    92 
    93 	}
    94 
    95 	TBuf<20> buf16(K16BitString);
    96 	TInt n=0;
    97 	ilogger.SetLogLevel(RFileFlogger::ESevrAll);
    98 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
    99 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   100 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   101 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrHigh, K16BitFormatText,n++,&buf16);
   102 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrMedium, K16BitFormatText,n++,&buf16);
   103 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrLow, K16BitFormatText,n++,&buf16);
   104 
   105 	INFO_PRINTF1(_L("test ESevrErr"));
   106 	ilogger.SetLogLevel(RFileFlogger::ESevrErr);
   107 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   108 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   109 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   110 
   111 	INFO_PRINTF1(_L("test log with add fileds"));
   112 	TInt aLength = 2;
   113 	TExtraLogField logField[2];
   114 	logField[0].iLogFieldName.Copy(_L("SUITE_NAME"));
   115 	logField[0].iLogFieldValue.Copy(_L("SUITE_VALUE"));
   116 	logField[1].iLogFieldName.Copy(_L("TEST_NAME"));
   117 	logField[1].iLogFieldValue.Copy(_L("TEST_VALUE"));
   118 	
   119 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, aLength, logField, K16BitFormatText,n++,&buf16);
   120 
   121 
   122 	INFO_PRINTF1(_L("test ESevrWarn"));
   123 	n=0;
   124 	ilogger.SetLogLevel(RFileFlogger::ESevrWarn);
   125 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   126 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   127 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   128 
   129 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
   130 
   131 	INFO_PRINTF1(_L("test ESevrInfo"));
   132 	n=0;
   133 	ilogger.SetLogLevel(RFileFlogger::ESevrInfo);
   134 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   135 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   136 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   137 
   138 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
   139 
   140 	INFO_PRINTF1(_L("test ESevrAll"));
   141 	n=0;
   142 	ilogger.SetLogLevel(RFileFlogger::ESevrAll);
   143 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   144 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   145 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   146 
   147 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
   148 // txt log test
   149 	ilogger.Close();
   150 	err=ilogger.Connect();
   151 	if(err)
   152 	{
   153 		INFO_PRINTF2(_L("Connect() failed. err = %d"),err);
   154 		SetTestStepResult(EFail);
   155 		return TestStepResult();
   156 	}
   157 	INFO_PRINTF1(_L("RFileFlogger::ELogModeAppend test ..."));
   158 	err=ilogger.CreateLog(KLogFiletxt,RFileFlogger::ELogModeAppend);
   159 	if(!err)
   160 	{
   161 	    INFO_PRINTF1(_L("RFileFlogger::ELogModeAppend testing is fine"));
   162 		INFO_PRINTF1(_L("txt format file open passed and test start"));
   163 	}
   164 	else  
   165 	{
   166 		ERR_PRINTF2(_L("error value = %d"),err);
   167 		SetTestStepResult(EFail);
   168 		return TestStepResult();
   169 
   170 	}
   171 
   172 	n=0;
   173 	ilogger.SetLogLevel(RFileFlogger::ESevrAll);
   174 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   175 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   176 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   177 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrHigh, K16BitFormatText,n++,&buf16);
   178 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrMedium, K16BitFormatText,n++,&buf16);
   179 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrLow, K16BitFormatText,n++,&buf16);
   180 
   181 	INFO_PRINTF1(_L("test ESevrErr"));
   182 	ilogger.SetLogLevel(RFileFlogger::ESevrErr);
   183 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   184 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   185 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   186 
   187 	INFO_PRINTF1(_L("test log with add fileds"));
   188     aLength = 2;
   189 	logField[0].iLogFieldName.Copy(_L("SUITE_NAME"));
   190 	logField[0].iLogFieldValue.Copy(_L("SUITE_VALUE"));
   191 	logField[1].iLogFieldName.Copy(_L("TEST_NAME"));
   192 	logField[1].iLogFieldValue.Copy(_L("TEST_VALUE"));
   193 	
   194 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, aLength, logField, K16BitFormatText,n++,&buf16);
   195 
   196 	
   197 	INFO_PRINTF1(_L("test ESevrWarn"));
   198 	n=0;
   199 	ilogger.SetLogLevel(RFileFlogger::ESevrWarn);
   200 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   201 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   202 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   203 
   204 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
   205 
   206 	INFO_PRINTF1(_L("test ESevrInfo"));
   207 	n=0;
   208 	ilogger.SetLogLevel(RFileFlogger::ESevrInfo);
   209 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   210 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   211 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   212 
   213 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
   214 
   215 	INFO_PRINTF1(_L("test ESevrAll"));
   216 	n=0;
   217 	ilogger.SetLogLevel(RFileFlogger::ESevrAll);
   218 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrAll, K16BitFormatText,n++,&buf16);
   219 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrInfo, K16BitFormatText,n++,&buf16);
   220 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrWarn, K16BitFormatText,n++,&buf16);
   221 
   222 	ilogger.Log(((TText8*)__FILE__), __LINE__,RFileFlogger::ESevrErr, K16BitFormatText,n++,&buf16);
   223 
   224 
   225 	ilogger.Close();
   226 	
   227 	INFO_PRINTF1(_L("test finished"));
   228 	
   229 	return TestStepResult();
   230 	}
   231 
   232 
   233 
   234 TVerdict Caddfield_logStep::doTestStepPostambleL()
   235 /**
   236  * @return - TVerdict code
   237  * Override of base class virtual
   238  */
   239 	{
   240 	return TestStepResult();
   241 	}