testexecfw/tef/test/regressiontest/logger/src/tefloggertestwrapper.cpp
changeset 0 3e07fef1e154
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 * @file
       
    16 * This is the test class for TEF (PREQ10437).
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include "TEFLoggerTestWrapper.h"
       
    23 
       
    24 /// Enumerations
       
    25 _LIT(KFail, "EFail");
       
    26 _LIT(KPass, "EPass");
       
    27 
       
    28 /// Commands
       
    29 _LIT(KPrint, "Print");
       
    30 _LIT(KPrintNonVALIST, "PrintNonVA_LIST");
       
    31 _LIT(KUnCoveredFuntions, "UnCoveredFuntions");
       
    32 _LIT(KGetCPPModuleName, "GetCPPModuleName");
       
    33 _LIT(KNew, "New");
       
    34 _LIT(KGetDataObject, "GetDataObject");
       
    35 _LIT(KGetLongSectionName, "GetLongSectionName");
       
    36 _LIT(KGetLongKeyName, "GetLongKeyName");
       
    37 
       
    38 _LIT(KNullExpected, "null_expected");
       
    39 _LIT(KObjectValue, "object_value");
       
    40 _LIT(KESevrLevel, "ESevrLevel");
       
    41 
       
    42 CTEFLoggerTestWrapper::CTEFLoggerTestWrapper() :
       
    43 	iActiveCallback(NULL), iObject(NULL), iActiveObject(NULL)
       
    44 	{
       
    45 	}
       
    46 
       
    47 CTEFLoggerTestWrapper::~CTEFLoggerTestWrapper()
       
    48 	{
       
    49 	delete iActiveCallback;
       
    50 	iActiveCallback = NULL;
       
    51 
       
    52 	delete iActiveObject;
       
    53 	iActiveObject = NULL;
       
    54 
       
    55 	delete iObject;
       
    56 	iObject = NULL;
       
    57 	}
       
    58 
       
    59 CTEFLoggerTestWrapper* CTEFLoggerTestWrapper::NewL()
       
    60 	{
       
    61 	CTEFLoggerTestWrapper* ret = new (ELeave) CTEFLoggerTestWrapper();
       
    62 	CleanupStack::PushL(ret);
       
    63 	ret->ConstructL();
       
    64 	CleanupStack::Pop(ret);
       
    65 	return ret;
       
    66 	}
       
    67 
       
    68 void CTEFLoggerTestWrapper::ConstructL()
       
    69 	{
       
    70 	iActiveCallback = CActiveCallback::NewL(*this);
       
    71 	iObject = new (ELeave) TInt;
       
    72 	}
       
    73 
       
    74 TBool CTEFLoggerTestWrapper::DoCommandL(const TTEFFunction& aCommand,
       
    75 		const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
    76 	{
       
    77 	TBool ret = ETrue;
       
    78 
       
    79 	// Print out the parameters for debugging
       
    80 	INFO_PRINTF2( _L("aCommand = %S"), &aCommand );
       
    81 	INFO_PRINTF2( _L("aSection = %S"), &aSection );
       
    82 	INFO_PRINTF2( _L("aAsyncErrorIndex = %D"), aAsyncErrorIndex );
       
    83 
       
    84 	if (KNew() == aCommand)
       
    85 		{
       
    86 		DoCmdNewL(aSection);
       
    87 		}
       
    88 	else
       
    89 	if (KGetDataObject() == aCommand)
       
    90 		{
       
    91 		DoCmdGetDataObject(aSection);
       
    92 		}
       
    93 	else
       
    94 	if (KPrint() == aCommand)
       
    95 		{
       
    96 		DoCmdPrint(aSection);
       
    97 		}
       
    98 	else
       
    99 	if (KPrintNonVALIST() == aCommand)
       
   100 		{
       
   101 		DoCmdPrintNoVALIST(aSection);
       
   102 		}
       
   103 	else
       
   104 	if (KUnCoveredFuntions() == aCommand)
       
   105 		{
       
   106 		DoCmdKUnCoveredFuntions(aSection);
       
   107 		}	
       
   108 	else
       
   109 	if (KGetCPPModuleName() == aCommand)
       
   110 		{
       
   111 		DoCmdKGetCPPModuleName();
       
   112 		}
       
   113 	else
       
   114 	if (KGetLongSectionName()== aCommand)
       
   115 		{
       
   116 		GetLongSectionName(aSection);
       
   117 		}
       
   118 	else
       
   119 	if (KGetLongKeyName()== aCommand)
       
   120 		{
       
   121 		GetLongKeyName(aSection);
       
   122 		}
       
   123 	else
       
   124 		{
       
   125 		ret = EFalse;
       
   126 		}
       
   127 	return ret;
       
   128 	}
       
   129 
       
   130 _LIT(KLoggerServityInfo,"Logger severity test.");
       
   131 void CTEFLoggerTestWrapper::DoCmdPrint(const TDesC& aSection)
       
   132 	{
       
   133 	TInt severity = 0;
       
   134 	if (!GetIntFromConfig(aSection, KESevrLevel(), severity))
       
   135 		{
       
   136 		ERR_PRINTF2(_L("No parameter %S"), &KESevrLevel());
       
   137 		SetBlockResult(EFail);
       
   138 		}
       
   139 	else
       
   140 		{
       
   141 		Logger().LogExtra(((TText8*)__FILE__), __LINE__, severity, (KLoggerServityInfo));
       
   142 		}	
       
   143 	}
       
   144 _LIT(KLoggerServityInfoFmt,"Logger severity test(with %2d level @%3d line ).");
       
   145 void CTEFLoggerTestWrapper::DoCmdPrintNoVALIST(const TDesC& aSection)
       
   146 	{
       
   147 	TInt severity = 0;
       
   148 	if (!GetIntFromConfig(aSection, KESevrLevel(), severity))
       
   149 		{
       
   150 		ERR_PRINTF2(_L("No parameter %S"), &KESevrLevel());
       
   151 		SetBlockResult(EFail);
       
   152 		}
       
   153 	else
       
   154 		{
       
   155 		Logger().LogExtra(((TText8*)__FILE__), __LINE__, severity, (KLoggerServityInfoFmt),severity,__LINE__);
       
   156 		}
       
   157 	}
       
   158 
       
   159 /**
       
   160  Purpose: To test that an wrapped object exists in the dictionary. And optionally to check the object's value.
       
   161 
       
   162  @internalComponent
       
   163  @param  aSection Current ini file command section
       
   164  */
       
   165 void CTEFLoggerTestWrapper::DoCmdGetDataObject(const TDesC& aSection)
       
   166 	{
       
   167 	// check if null is expected
       
   168 	TBool nullExpected = EFalse;
       
   169 	GetBoolFromConfig(aSection, KNullExpected(), nullExpected);
       
   170 
       
   171 	// call GetDataObject() and check that the wrapped object is found
       
   172 	TInt* wrappedObject= NULL;
       
   173 	TRAPD(err, wrappedObject = static_cast<TInt*>(GetDataObjectL(aSection)));
       
   174 
       
   175 	if (err != KErrNone)
       
   176 		{
       
   177 		ERR_PRINTF2(_L("GetDataObjectL() error: %d"), err);
       
   178 		SetBlockResult(EFail);
       
   179 		SetError(err);
       
   180 		}
       
   181 
       
   182 	// check if is null if is expetced to be null and vice versa
       
   183 	if (wrappedObject == NULL && !nullExpected)
       
   184 		{
       
   185 		ERR_PRINTF1(_L("Wrapped object is not expected to be null!"));
       
   186 		SetBlockResult(EFail);
       
   187 		}
       
   188 	else
       
   189 		if (wrappedObject != NULL)
       
   190 			{
       
   191 			if (nullExpected)
       
   192 				{
       
   193 				ERR_PRINTF1(_L("Wrapped object is expected to be null!"));
       
   194 				SetBlockResult(EFail);
       
   195 				}
       
   196 			else
       
   197 				{
       
   198 				// check expected value
       
   199 				TInt objectValue = 0;
       
   200 				if (GetIntFromConfig(aSection, KObjectValue(), objectValue))
       
   201 					{
       
   202 					if (*wrappedObject != objectValue)
       
   203 						{
       
   204 						ERR_PRINTF3(_L("Wrapped object's value is not as expected. expected=%d, actual=%d"), objectValue, *wrappedObject);
       
   205 						SetBlockResult(EFail);
       
   206 						}					
       
   207 					}
       
   208 				}
       
   209 			}
       
   210 	}
       
   211 void CTEFLoggerTestWrapper::DoCmdKUnCoveredFuntions(const TDesC& aSection)
       
   212 	{
       
   213 	Logger().Write(aSection); //Write(const TDesC& aLogBuffer)
       
   214 	TBuf8<256> copy8;
       
   215 	copy8.Copy(aSection);
       
   216 	copy8.Append(_L8("8"));
       
   217 	Logger().Write(copy8);//Write(const TDesC8& aLogBuffer)
       
   218 	_LIT(KFomarteString,"%S");
       
   219 	Logger().WriteFormat(KFomarteString,&aSection);//WriteFormat(TRefByValue<const TDesC> aFmt,...)
       
   220 	_LIT8(KFomarteString8,"%S");
       
   221 	Logger().WriteFormat(KFomarteString8,&copy8);//WriteFormat(TRefByValue<const TDesC8> aFmt,...)
       
   222 	_LIT(KTEFUnCovFunXML,"UnCoveredFuntions.xml");
       
   223 #define UnCovFunXML "UnCoveredFuntions.xml"
       
   224 	Logger().LogToXml( ((TText8*)__FILE__) , __LINE__, (TInt)ESevrInfo, KTEFUnCovFunXML);
       
   225 	}
       
   226 
       
   227 void CTEFLoggerTestWrapper::DoCmdKGetCPPModuleName()
       
   228 	{
       
   229 #define KA_Cpp "A.cpp"
       
   230 	Logger().LogExtra( (TText8*)KA_Cpp , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   231 #define KABSLT_Cpp "\\A.cpp"
       
   232 	Logger().LogExtra( (TText8*)KABSLT_Cpp , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   233 #define KB_Cpp "dir\\A.cpp"
       
   234 	Logger().LogExtra( (TText8*)KB_Cpp , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   235 #define KDIR_DIR "DIR\\DIR\\"
       
   236 	Logger().LogExtra( (TText8*)KDIR_DIR , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   237 #define KDIR_DIR1 "DIR\\DIR1"
       
   238 	Logger().LogExtra( (TText8*)KDIR_DIR1 , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   239 #define KDIR_CDRIVER "c:\\"
       
   240 	Logger().LogExtra( (TText8*)KDIR_CDRIVER , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   241 #define KDIR_EMPTY ""
       
   242 	Logger().LogExtra( (TText8*)KDIR_EMPTY , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   243 #define KDIR_FULLPATH "c:\\fulltpath\\to\\file.cpp"
       
   244 	Logger().LogExtra( (TText8*)KDIR_FULLPATH , __LINE__, ESevrInfo, (KGetCPPModuleName));
       
   245 	}
       
   246 
       
   247 
       
   248 _LIT(KTEFTESTIniKey,"Key");
       
   249 void CTEFLoggerTestWrapper::GetLongSectionName(const TDesC& aSection)
       
   250 	{
       
   251 	TPtrC value;
       
   252 	if (GetStringFromConfig(aSection, KTEFTESTIniKey(), value ))
       
   253 		{
       
   254 		Logger().Write(value);
       
   255 		_LIT(KFomarteString,"%S");
       
   256 		Logger().WriteFormat(KFomarteString,&value);
       
   257 		}
       
   258 	else
       
   259 		{
       
   260 		SetBlockResult(EFail);
       
   261 		}
       
   262 	}
       
   263 void CTEFLoggerTestWrapper::GetLongKeyName(const TDesC& aSection)
       
   264 	{
       
   265 	TPtrC value;
       
   266 	if (GetStringFromConfig(aSection, KTEFTESTIniKey(), value ))
       
   267 		{
       
   268 		Logger().Write(value);
       
   269 		_LIT(KFomarteString,"%S");
       
   270 		Logger().WriteFormat(KFomarteString,&value);
       
   271 		}
       
   272 	else
       
   273 		{
       
   274 		SetBlockResult(EFail);
       
   275 		}
       
   276 	}
       
   277 /**
       
   278  Purpose: To create a new object of the CTEFTest type through the API.
       
   279 
       
   280  Ini file options:
       
   281  iniData - The data from the ini file at the section provided.
       
   282 
       
   283  @internalComponent
       
   284  @param  aSection Current ini file command section
       
   285  */
       
   286 void CTEFLoggerTestWrapper::DoCmdNewL(const TDesC& aSection)
       
   287 	{
       
   288 	TInt objectValue = 0;
       
   289 	SetBlockResult(EFail);
       
   290 	if (!GetIntFromConfig(aSection, KObjectValue(), objectValue))
       
   291 		{
       
   292 		ERR_PRINTF2(_L("No parameter %S"), &KObjectValue());
       
   293 		}
       
   294 	else
       
   295 		{
       
   296 		if (iObject != NULL)
       
   297 			{
       
   298 			delete iObject;
       
   299 			iObject = NULL;
       
   300 			}
       
   301 		iObject = new (ELeave) TInt(objectValue);
       
   302 		SetBlockResult(EPass);
       
   303 		}
       
   304 	}
       
   305 void CTEFLoggerTestWrapper::RunL(CActive* aActive, TInt aIndex)
       
   306 	{
       
   307 	INFO_PRINTF1(_L("CTEFLoggerTestWrapper::RunL"));
       
   308 	TInt err = aActive->iStatus.Int();
       
   309 	SetAsyncError(aIndex, err);
       
   310 	DecOutstanding();
       
   311 	}
       
   312 
       
   313 /** Reads drive mapping operation name from INI-file */
       
   314 TBool CTEFLoggerTestWrapper::GetVerdictFromConfig(const TDesC& aSection,
       
   315 		const TDesC& aParameterName, TVerdict& aVerdict)
       
   316 	{
       
   317 	// Read drives mapping operation name from INI file
       
   318 	TPtrC verdictStr;
       
   319 	TBool ret = GetStringFromConfig(aSection, aParameterName, verdictStr);
       
   320 	if (ret)
       
   321 		{
       
   322 		if (verdictStr == KPass())
       
   323 			{
       
   324 			aVerdict = EPass;
       
   325 			}
       
   326 		else
       
   327 			if (verdictStr == KFail())
       
   328 				{
       
   329 				aVerdict = EFail;
       
   330 				}
       
   331 			else
       
   332 				{
       
   333 				TInt verdict = 0;
       
   334 				ret = GetIntFromConfig(aSection, aParameterName, verdict);
       
   335 				if (ret)
       
   336 					{
       
   337 					aVerdict = (TVerdict) verdict;
       
   338 					}
       
   339 				}
       
   340 		}
       
   341 
       
   342 	return ret;
       
   343 	}
       
   344