cryptomgmtlibs/securitytestfw/test/testhandler2/tScriptSetup.cpp
changeset 8 35751d3474b7
parent 0 2c201484c85f
child 61 641f389e9157
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
    19 #include "tScriptSetup.h"
    19 #include "tScriptSetup.h"
    20 #include "tScriptTests.h"
    20 #include "tScriptTests.h"
    21 
    21 
    22 #include "t_testactionspec.h"
    22 #include "t_testactionspec.h"
    23 #include "t_input.h"
    23 #include "t_input.h"
       
    24 #include "t_tefinput.h"
    24 #include "t_certstoreactionmemfail.h"
    25 #include "t_certstoreactionmemfail.h"
    25 #include "tcancel.h"
    26 #include "tcancel.h"
    26 #include "t_sleep.h"
    27 #include "t_sleep.h"
    27 #include "t_message.h"
    28 #include "t_message.h"
    28 #include "t_output.h"
    29 #include "t_output.h"
    52 
    53 
    53 CScriptSetup::CScriptSetup(CConsoleBase* aConsole) : CTestSetup(aConsole)
    54 CScriptSetup::CScriptSetup(CConsoleBase* aConsole) : CTestSetup(aConsole)
    54 	{
    55 	{
    55 	}
    56 	}
    56 
    57 
    57 CScriptSetup::~CScriptSetup()
    58 EXPORT_C CScriptSetup::~CScriptSetup()
    58 	{
    59 	{
    59 	delete iTestInput;
    60 	delete iTestInput;
       
    61 	delete iScriptPath;
    60 	}
    62 	}
    61 
    63 
    62 EXPORT_C void CScriptSetup::SetupTestsL(RFs& aFs,
    64 EXPORT_C void CScriptSetup::SetupTestsL(RFs& aFs,
    63 										CTestSpec& aTestSpec, 
    65 										CTestSpec& aTestSpec, 
    64 										TScriptTests theTestTypes[], 
    66 										TScriptTests theTestTypes[], 
    65 										const CTestHandlerSettings& aCommandLineSettings)
    67 										const CTestHandlerSettings& aCommandLineSettings)
    66 	{
    68 	{
    67 	TInt pos = 0;
    69 	TInt pos = 0;
    68 	TInt err = KErrNone;
    70 	TInt err = KErrNone;
       
    71 	TBuf8<256> testCaseID;
       
    72 	TBuf8<256> prevtestCaseID;
       
    73 	TBuf8<512> scriptResult;
       
    74 	TBuf8<512> actionType;
       
    75 	TBool runtest = EFalse;
       
    76 	TBool iniFile = EFalse;
       
    77 	TBool startTest = EFalse;
       
    78 	TBool endTest = EFalse;
       
    79 	
    69 	for (TInt i = 1 ; ; ++i)
    80 	for (TInt i = 1 ; ; ++i)
    70 		{
    81 		{
    71 		TPtrC8 actionData = Input::ParseElement(*iTestInput, KActionStart, KActionEnd, pos, err);
    82 		TPtrC8 runTestStep;
       
    83 		TPtrC8 testDescription;
       
    84 		TPtrC8 actionData;
       
    85 		
       
    86 		if (iTefScript)
       
    87 			{
       
    88 			
       
    89 			if(endTest)
       
    90 				{
       
    91 				startTest = EFalse;
       
    92 				runtest = EFalse;
       
    93 				testCaseID.Copy(Tefinput::ParseTestCaseID(*iTestInput, KStartTestStep, prevtestCaseID, pos, err, runtest, startTest));
       
    94 				prevtestCaseID.Copy(testCaseID);
       
    95 				}
       
    96 			if(runtest)
       
    97 				{
       
    98 				if(endTest && startTest)
       
    99 					{
       
   100 					startTest = ETrue;
       
   101 					}
       
   102 				else
       
   103 					{
       
   104 					startTest = EFalse;
       
   105 					}
       
   106 				endTest = EFalse;
       
   107 				testCaseID.Copy(prevtestCaseID);
       
   108 				}
       
   109 			else
       
   110 				{
       
   111 				testCaseID.Copy(Tefinput::ParseTestCaseID(*iTestInput, KStartTestStep, prevtestCaseID, pos, err, runtest, startTest));
       
   112 				prevtestCaseID.Copy(testCaseID);
       
   113 				}
       
   114 			runTestStep.Set(Tefinput::ParseRunTestStep(*iTestInput, KRunTestStep, pos, err));
       
   115 			endTest = Tefinput::EndTestCase(*iTestInput, runTestStep, KEndTestStep, pos);
       
   116 			}
       
   117 		else
       
   118 			{
       
   119 			actionData.Set(Input::ParseElement(*iTestInput, KActionStart, KActionEnd, pos, err));
       
   120 			}
    72 		if (err != KErrNone)
   121 		if (err != KErrNone)
    73 			{
   122 		  	{
    74 			break;
   123 			break;
    75 			}
   124 			} 
    76 		
   125 			 
    77 		TInt relativePos = 0;
   126 		TInt relativePos = 0;
    78 		TInt scriptGroupings= DEFAULTGROUPING;
   127 		TInt scriptGroupings= DEFAULTGROUPING;
    79 		TTestActionSpec actionSpec;
   128 		TTestActionSpec actionSpec;
    80 		//Parse the file to create action name, type , body and result
   129 		//Parse the file to create action name, type , body and result
    81 		User::LeaveIfError(actionSpec.Init(actionData, relativePos, *iConsole, *iLogFile, scriptGroupings));
   130 		if (iTefScript)
    82 			
   131 			{
       
   132 			User::LeaveIfError(actionSpec.TEFInit(aFs, runTestStep, testCaseID, prevtestCaseID, iTefScript, runtest, iniFile, scriptResult, actionType, *iScriptPath, *iConsole, *iLogFile));
       
   133 			}
       
   134 		else
       
   135 			{
       
   136 			User::LeaveIfError(actionSpec.Init(actionData, relativePos, *iConsole, *iLogFile, scriptGroupings));
       
   137 			}
       
   138 		
    83 		//Start off checking Exhaustive and Smoke flags, then calls groupings
   139 		//Start off checking Exhaustive and Smoke flags, then calls groupings
    84 		if (!CheckAllFlags(aCommandLineSettings, scriptGroupings))
   140 		if (!CheckAllFlags(aCommandLineSettings, scriptGroupings))
    85 			//The current test should not be run
   141 			//The current test should not be run
    86 			continue;
   142 			continue;
    87 	
   143 	
       
   144 		
    88 		CTestAction* newAction = 0;
   145 		CTestAction* newAction = 0;
    89 		TRAP(err, newAction = 
   146 		TRAP(err, newAction = CreateActionL(aFs, actionSpec, theTestTypes));
    90 			 CreateActionL(aFs, actionSpec, theTestTypes));
   147 		
    91 				
   148 	
       
   149 		
       
   150 
    92 		if (err != KErrNone)
   151 		if (err != KErrNone)
    93 			{
   152 			{
    94 			iLogFile->write(_L("CScriptSetup::CreateActionL failed: "));
   153 			iLogFile->write(_L("CScriptSetup::CreateActionL failed: "));
    95 			iLogFile->writeError(err);		
   154 			iLogFile->writeError(err);		
    96 			iLogFile->writeNewLine();
   155 			iLogFile->writeNewLine();
   120 			}
   179 			}
   121 		
   180 		
   122 		CleanupStack::PushL(newAction);
   181 		CleanupStack::PushL(newAction);
   123 		User::LeaveIfError(aTestSpec.AddNextTest(newAction));
   182 		User::LeaveIfError(aTestSpec.AddNextTest(newAction));
   124 		CleanupStack::Pop(newAction);
   183 		CleanupStack::Pop(newAction);
       
   184 	
       
   185 		if(iniFile)
       
   186 			{
       
   187 			CleanupStack::PopAndDestroy(1);
       
   188 			}
   125 		}
   189 		}
   126 	}
   190 	}
   127 
   191 
   128 EXPORT_C TBool CScriptSetup::InitialiseL(RFs &aFs, const TDesC& aDefaultScript, const TDesC& aDefaultLog, TBool aUseCommandLine)
   192 EXPORT_C TBool CScriptSetup::InitialiseL(RFs &aFs, const TDesC& aDefaultScript, const TDesC& aDefaultLog, TBool aUseCommandLine)
   129 	{
   193 	{
   130 	// gets the script file argument
   194 	// gets the script file argument
   131 	HBufC* scriptFileName = NULL;
   195 	iScriptPath = NULL;
       
   196 	iTefScript = EFalse;
   132 
   197 
   133 	if (aUseCommandLine)
   198 	if (aUseCommandLine)
   134 		{
   199 		{
   135 		scriptFileName = GetArgument();
   200 		iScriptPath = GetArgument();
   136 		CleanupStack::PushL(scriptFileName);
   201 		if(iScriptPath->Length()==0)
   137 		if(scriptFileName->Length()==0)
   202 			{
   138 			{
   203 			delete iScriptPath;  
   139 			CleanupStack::PopAndDestroy(scriptFileName);
   204 			iScriptPath = NULL;
   140 			scriptFileName = NULL;
   205 			}
   141 			}
   206 		else
   142 		}
   207 			{
   143 
   208 			TPtr scriptFileNameDes = iScriptPath->Des();
   144 	if(scriptFileName == NULL)
   209 			if (scriptFileNameDes.Right(7) == _L(".script"))
       
   210 				{
       
   211 				iTefScript = ETrue;
       
   212 				}
       
   213 			}
       
   214 		}
       
   215 
       
   216 	if(iScriptPath == NULL)
   145 		{
   217 		{
   146 		if(aDefaultScript.Length() == 0)
   218 		if(aDefaultScript.Length() == 0)
   147 			{
   219 			{
   148 			PRINTANDLOG(_L("No script file specified on command line and no default given"));
   220 			PRINTANDLOG(_L("No script file specified on command line and no default given"));
   149 			return(EFalse);
   221 			return(EFalse);
   150 			}
   222 			}
   151 		else
   223 		else
   152 			{
   224 			{
   153 			scriptFileName = aDefaultScript.AllocLC();
   225 			iScriptPath = aDefaultScript.AllocLC();
   154 			}
   226 			}
   155 		};
   227 		};
   156 
   228 
   157 	PRINTANDLOG1(_L("Script file: %S"), scriptFileName);
   229 	PRINTANDLOG1(_L("Script file: %S"), iScriptPath);
   158 
   230 
   159 	// open the script file
   231 	// open the script file
   160 	RFile scriptFile;
   232 	RFile scriptFile;
   161 	TInt err = scriptFile.Open(aFs, *scriptFileName, EFileStream | EFileRead | EFileShareReadersOnly);
   233 	TInt err = scriptFile.Open(aFs, *iScriptPath, EFileStream | EFileRead | EFileShareReadersOnly);
   162 	if (err != KErrNone)
   234 	if (err != KErrNone)
   163 		{
   235 		{
   164 		PRINTANDLOG1(_L("Error opening script file: %d"), err);
   236 		PRINTANDLOG1(_L("Error opening script file: %d"), err);
   165 		CleanupStack::PopAndDestroy();// scriptFileName
   237 		delete iScriptPath;
       
   238 		iScriptPath = NULL;
   166 		return(EFalse);
   239 		return(EFalse);
   167 		}
   240 		}
   168 	CleanupClosePushL(scriptFile);
   241 	CleanupClosePushL(scriptFile);
   169 	
   242 	
   170 	TRAP(err, OpenLogFileL(aFs, 1, aDefaultLog, aUseCommandLine));	
   243 	TRAP(err, OpenLogFileL(aFs, 1, aDefaultLog, aUseCommandLine));	
   171 	if (err != KErrNone)
   244 	if (err != KErrNone)
   172 		{
   245 		{
   173 		PRINTANDLOG1(_L("Error opening log file: %d"), err);		
   246 		PRINTANDLOG1(_L("Error opening log file: %d"), err);	
   174 		CleanupStack::PopAndDestroy(2);// scripFile, scriptFileName
   247 		delete iScriptPath;
       
   248 		iScriptPath = NULL;
       
   249 		CleanupStack::PopAndDestroy(1);// scripFile
   175 		return(EFalse);
   250 		return(EFalse);
   176 		}
   251 		}
   177 		
   252 		
   178 	// gets size of script file
   253 	// gets size of script file
   179 	TInt size;
   254 	TInt size;
   180 	scriptFile.Size(size);
   255 	scriptFile.Size(size);
   181 	CleanupStack::PopAndDestroy(); // scriptFile
   256 	CleanupStack::PopAndDestroy(); // scriptFile
   182 		
   257 		
   183 	// reads script into iTestInput
   258 	// reads script into iTestInput
   184 	iTestInput = HBufC8::NewL(size);
   259 	iTestInput = HBufC8::NewL(size);
   185 	TPtr8 pInput(iTestInput->Des());
   260 	TPtr8 pInput(iTestInput->Des()); 
   186 	pInput.SetLength(size);
   261 	pInput.SetLength(size); 
   187 
   262 
   188 	RFileReadStream stream;
   263 	RFileReadStream stream;
   189 	User::LeaveIfError(stream.Open(aFs, *scriptFileName, EFileStream | EFileRead | EFileShareReadersOnly));
   264 	User::LeaveIfError(stream.Open(aFs, *iScriptPath, EFileStream | EFileRead | EFileShareReadersOnly));
   190 	CleanupClosePushL(stream);
   265 	CleanupClosePushL(stream);
   191 	stream.ReadL(pInput, size);
   266 	stream.ReadL(pInput, size);
   192 
   267 	CleanupStack::PopAndDestroy(1); // stream
   193 	CleanupStack::PopAndDestroy(2); // stream, scriptFileName
       
   194 	return(ETrue);
   268 	return(ETrue);
   195 	}
   269 	}
   196 
   270 
   197 EXPORT_C CTestAction* CScriptSetup::CreateActionL(RFs& aFs,
   271 EXPORT_C CTestAction* CScriptSetup::CreateActionL(RFs& aFs,
   198 												  const TTestActionSpec& aTestActionSpec,
   272 												  const TTestActionSpec& aTestActionSpec,