cryptomgmtlibs/securitytestfw/test/testhandler2/t_testactionspec.cpp
changeset 8 35751d3474b7
parent 0 2c201484c85f
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
    19 #include "t_testactionspec.h"
    19 #include "t_testactionspec.h"
    20 #include "t_testsetup.h"
    20 #include "t_testsetup.h"
    21 #include "tScriptSetup.h"
    21 #include "tScriptSetup.h"
    22 #include "t_input.h"
    22 #include "t_input.h"
    23 #include "tScriptTests.h"
    23 #include "tScriptTests.h"
       
    24 #include "t_tefinput.h"
    24 
    25 
    25 _LIT8(KTrue, "true");
    26 _LIT8(KTrue, "true");
    26 _LIT8(KFalse, "false");
    27 _LIT8(KFalse, "false");
    27 
    28 
    28 _LIT8(KExOOMStart, "<exoom>");
    29 _LIT8(KExOOMStart, "<exoom>");
    38 _LIT8(KSmokeStart, "<smoke>");
    39 _LIT8(KSmokeStart, "<smoke>");
    39 _LIT8(KSmokeEnd, "</smoke>");
    40 _LIT8(KSmokeEnd, "</smoke>");
    40 _LIT8(KInteractiveStart, "<interactive>");
    41 _LIT8(KInteractiveStart, "<interactive>");
    41 _LIT8(KInteractiveEnd, "</interactive>");
    42 _LIT8(KInteractiveEnd, "</interactive>");
    42 
    43 
       
    44 
    43 TTestActionSpec::TTestActionSpec()
    45 TTestActionSpec::TTestActionSpec()
    44 	{
    46 	{
    45 	}
    47 	}
    46 
    48 
       
    49 TTestActionSpec::~TTestActionSpec()
       
    50 	{
       
    51 	iniSectionResultBody.Close();
       
    52 	}
       
    53 
    47 TInt TTestActionSpec::Init(const TDesC8& aInput, 
    54 TInt TTestActionSpec::Init(const TDesC8& aInput, 
    48 						   TInt& aPos, 
    55 						   TInt& aPos,
    49 						   CConsoleBase& /*aConsole*/,
    56 						   CConsoleBase& /*aConsole*/,
    50 						   Output& aOut,
    57 						   Output& aOut,
    51 						   TInt& aBitFlag)
    58 						   TInt& aBitFlag)
    52 	{
    59 	{
    53 	TInt err = KErrNone;
    60 	TInt err = KErrNone;
    54 	iActionName.Set(Input::ParseElement(aInput, KActionNameStart, KActionNameEnd, 
    61 	iActionName.Set(Input::ParseElement(aInput, KActionNameStart, KActionNameEnd, aPos, err));
    55 		aPos, err));
       
    56 	if (err != KErrNone)
    62 	if (err != KErrNone)
    57 		{
    63 		{
    58 		aOut.writeString(_L("Error couldn't find actionname in test case spec"));
    64 		aOut.writeString(_L("Error couldn't find actionname in test case spec"));
    59 		aOut.writeNewLine();
    65 		aOut.writeNewLine();
    60 		return err;
    66 		return err;
   151 			}
   157 			}
   152 		}
   158 		}
   153 	
   159 	
   154 	iActionBody.Set(Input::ParseElement(aInput, KActionBodyStart, KActionBodyEnd, aPos, err));
   160 	iActionBody.Set(Input::ParseElement(aInput, KActionBodyStart, KActionBodyEnd, aPos, err));
   155 	iActionResult.Set(Input::ParseElement(aInput, KActionResultStart, KActionResultEnd, aPos, err));
   161 	iActionResult.Set(Input::ParseElement(aInput, KActionResultStart, KActionResultEnd, aPos, err));
       
   162 	iTefScript = EFalse;
   156 	
   163 	
   157 	return KErrNone; 
   164 	return KErrNone; 
   158 	}
   165 	}
       
   166 
       
   167 
       
   168 // Extracts information from *.script and *.ini files to the appropriate member variables.
       
   169 
       
   170 TInt TTestActionSpec::TEFInit(RFs& aFs, 
       
   171 						   const TDesC8& aInput,
       
   172 						   const TDesC8& aTestCaseID,
       
   173 						   TDesC8& aPrevTestCaseID,
       
   174 						   TBool& tefFile,
       
   175 						   TBool& runtest,
       
   176 						   TBool& inifile,
       
   177 						   TDes8& aScriptResult,
       
   178 						   TDes8& aActionType,
       
   179 						   const TDesC& aScriptPath,
       
   180 						   CConsoleBase& /*aConsole*/,
       
   181 						   Output& aOut)
       
   182 	{
       
   183 	
       
   184 	TInt 		err = KErrNone;
       
   185 	TInt 		actionTypePos=3;
       
   186 	TBool 		scriptactionResultSet = EFalse;
       
   187 //	TBool 		iniactionResultSet = EFalse;
       
   188 	TBuf8<512> 	prevTestCaseID;
       
   189 	TBuf8<512> 	prevTestDescription;
       
   190 
       
   191 
       
   192 	
       
   193 // Checks if the first word from the script file is an error code
       
   194 // if(error code)
       
   195 //		sets 'actionResult' to the relevent error code with the <return></return> tags
       
   196 
       
   197 	TPtrC8 firstWord = Tefinput::ParseNthElement(aInput,1, err);
       
   198 	if(err == KErrNone)
       
   199 		{
       
   200 		TInt tmpno;
       
   201 		TLex8 lex8(firstWord); 
       
   202 		err = lex8.Val(tmpno);			
       
   203 		if(err != KErrNone)
       
   204 			{
       
   205 			actionTypePos = 4;
       
   206 			err = Tefinput::ParseActionResult(firstWord, aScriptResult);
       
   207 			scriptactionResultSet = ETrue;
       
   208 			}
       
   209 		}
       
   210 	
       
   211 //1. Extracts the .ini file name from the .script file
       
   212 //2. Reads in the [section] name from the .script file
       
   213 //3. Generates  .ini path from .script file path and .ini file name
       
   214 //4. Sets iActionBody with the info from .ini file
       
   215 	
       
   216 	TBuf<KMaxPath + KMaxFileName> 	iniFilePath;
       
   217 	TBuf<512> 						iniFileData;
       
   218 	TPtrC8 							iniSectionData;
       
   219 	
       
   220 	
       
   221 	TPtrC8 iniFileName = Tefinput::ParseNthElement(aInput,actionTypePos+1,err);
       
   222 	if(err == KErrNone)
       
   223 		{
       
   224 		TPtrC8 iniSectionName = Tefinput::ParseNthElement(aInput,actionTypePos+2,err);
       
   225 		if(err == KErrNone)
       
   226 			{
       
   227 			err = Tefinput::ParseiniPath(iniFileName, aScriptPath, iniFilePath);
       
   228 			if(err == KErrNone)
       
   229 				{
       
   230 				aTestIniFilePtr.Assign(Tefinput::GetiniFile(aFs, iniFilePath, err)); // Load up our local RBuf ptr to takeover the management of the inifile data in Heap
       
   231 				
       
   232 				if(err == KErrNone)
       
   233 					{
       
   234 					TPtrC8 iniFile = aTestIniFilePtr.Ptr();
       
   235 					inifile = ETrue;
       
   236 					err = Tefinput::ParseActionbody(iniFile, iniSectionName, iniSectionData);
       
   237 					if(err == KErrNone)
       
   238 						{
       
   239 						TInt pos = 0;
       
   240 						iActionBody.Set(Input::ParseElement(iniSectionData, KActionBodyStart, KActionBodyEnd, pos, err));
       
   241 						if (err == KErrNotFound)
       
   242 							{
       
   243 							aOut.writeString(_L("Error couldn't find actionbody in test case spec"));
       
   244 							aOut.writeNewLine();
       
   245 							return err;
       
   246 							}
       
   247 						}
       
   248 					}
       
   249 				else
       
   250 					{
       
   251 					inifile = EFalse;
       
   252 					}
       
   253 				}
       
   254 			}
       
   255 		}
       
   256 	else
       
   257 		{
       
   258 		inifile = EFalse;
       
   259 		}
       
   260 		
       
   261 	TInt pos = 0;
       
   262 
       
   263 // Extracts info b/w <actionresult> </actionresult> tags
       
   264 // 	Sets iActionResult with info both from .script and .ini file
       
   265 	TPtrC8 tempResult;
       
   266 	TPtrC8 scriptResult;
       
   267 	TInt resultlen ;
       
   268 	
       
   269 	if(scriptactionResultSet)
       
   270 		{
       
   271 		scriptResult.Set(aScriptResult);
       
   272 		tempResult.Set(Input::ParseElement(iniSectionData, KActionResultStart, KActionResultEnd, pos, err));
       
   273 		if (err == KErrNone)
       
   274 			{
       
   275 			resultlen = scriptResult.Length() + tempResult.Length();
       
   276 			iniSectionResultBody.Create(tempResult,resultlen);
       
   277 			iniSectionResultBody.Insert(0,scriptResult);			
       
   278 			iActionResult.Set(iniSectionResultBody);
       
   279 //			iniactionResultSet = ETrue;
       
   280 			}
       
   281 		else
       
   282 			{
       
   283 			iniSectionResultBody.Create(scriptResult);
       
   284 			iActionResult.Set(iniSectionResultBody);
       
   285 			}
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		tempResult.Set(Input::ParseElement(iniSectionData, KActionResultStart, KActionResultEnd, pos, err));
       
   290 		err = Tefinput::GetActionResult(KErrNone, aScriptResult);
       
   291 		if(err == KErrNone)
       
   292 			{
       
   293 			scriptResult.Set(aScriptResult);
       
   294 			resultlen = tempResult.Length() + scriptResult.Length();
       
   295 			iniSectionResultBody.Create(tempResult, resultlen);
       
   296 			iniSectionResultBody.Insert(0,aScriptResult);
       
   297 			iActionResult.Set(iniSectionResultBody);
       
   298 			}
       
   299 		else
       
   300 			{
       
   301 			iniSectionResultBody.Create(tempResult);
       
   302 			iActionResult.Set(iniSectionResultBody);
       
   303 			}
       
   304 		}
       
   305 	
       
   306 		
       
   307 //	aPrevTestCaseID = aTestCaseID;
       
   308 //Sets iActionName with the @SYMTestCaseID
       
   309 	if(!runtest)
       
   310 		{
       
   311 		iActionName.Set(aPrevTestCaseID);
       
   312 		}
       
   313 	else
       
   314 		{
       
   315 		iActionName.Set(aTestCaseID);
       
   316 		}
       
   317 
       
   318 	
       
   319 
       
   320 //Sets iActionType from .script file
       
   321 	
       
   322 	TBuf8<512> modifiedType;
       
   323 	TBuf8<512> modifiedTypeTemp;
       
   324 	TPtrC8 actionTypeTemp;
       
   325 	TPtrC8 actionType;
       
   326 	TPtrC8 TempType;
       
   327 	
       
   328 	
       
   329 	iActionType.Set(Tefinput::ParseNthElement(aInput,actionTypePos,err));
       
   330 	if (err == KErrNone)
       
   331 		{
       
   332 		modifiedType.Copy(iActionType);
       
   333 		modifiedType.Copy(Tefinput::TrimActionType(modifiedType, aActionType));
       
   334 
       
   335 		iActionType.Set(aActionType);
       
   336 		}
       
   337 	else
       
   338 		{
       
   339 		aOut.writeString(_L("Error couldn't find actiontype in test case spec"));
       
   340 		aOut.writeNewLine();
       
   341 		return err;
       
   342 		}
       
   343 
       
   344 	
       
   345 
       
   346 	iTefScript = tefFile;
       
   347 
       
   348 
       
   349 	
       
   350 	
       
   351 	return KErrNone; 
       
   352 	}
       
   353 
   159 
   354 
   160 void TTestActionSpec::HardcodedInit(const TDesC8& aInput)
   355 void TTestActionSpec::HardcodedInit(const TDesC8& aInput)
   161 	{
   356 	{
   162 	iActionName.Set(aInput);
   357 	iActionName.Set(aInput);
   163 	iActionType.Set(KNullDesC8);
   358 	iActionType.Set(KNullDesC8);