Update contrib.
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "tScriptSetup.h"
20 #include "tScriptTests.h"
22 #include "t_testactionspec.h"
24 #include "t_tefinput.h"
25 #include "t_certstoreactionmemfail.h"
28 #include "t_message.h"
30 #include "tTestSpec.h"
36 _LIT8(KStartMemFail, "startmemfailure");
37 _LIT8(KStopMemFail, "stopmemfailure");
38 _LIT8(KCancelStart, "startcancellation");
39 _LIT8(KCancelStop, "stopcancellation");
40 _LIT8(KMessage, "message");
41 _LIT8(KSleep, "sleep");
44 _LIT8(KPolicyTest, "policytest");
46 EXPORT_C CScriptSetup* CScriptSetup::NewLC(CConsoleBase* aConsole)
48 CScriptSetup* self = new (ELeave) CScriptSetup(aConsole);
49 CleanupStack::PushL(self);
54 CScriptSetup::CScriptSetup(CConsoleBase* aConsole) : CTestSetup(aConsole)
58 EXPORT_C CScriptSetup::~CScriptSetup()
64 EXPORT_C void CScriptSetup::SetupTestsL(RFs& aFs,
66 TScriptTests theTestTypes[],
67 const CTestHandlerSettings& aCommandLineSettings)
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;
80 for (TInt i = 1 ; ; ++i)
83 TPtrC8 testDescription;
93 testCaseID.Copy(Tefinput::ParseTestCaseID(*iTestInput, KStartTestStep, prevtestCaseID, pos, err, runtest, startTest));
94 prevtestCaseID.Copy(testCaseID);
98 if(endTest && startTest)
107 testCaseID.Copy(prevtestCaseID);
111 testCaseID.Copy(Tefinput::ParseTestCaseID(*iTestInput, KStartTestStep, prevtestCaseID, pos, err, runtest, startTest));
112 prevtestCaseID.Copy(testCaseID);
114 runTestStep.Set(Tefinput::ParseRunTestStep(*iTestInput, KRunTestStep, pos, err));
115 endTest = Tefinput::EndTestCase(*iTestInput, runTestStep, KEndTestStep, pos);
119 actionData.Set(Input::ParseElement(*iTestInput, KActionStart, KActionEnd, pos, err));
126 TInt relativePos = 0;
127 TInt scriptGroupings= DEFAULTGROUPING;
128 TTestActionSpec actionSpec;
129 //Parse the file to create action name, type , body and result
132 User::LeaveIfError(actionSpec.TEFInit(aFs, runTestStep, testCaseID, prevtestCaseID, iTefScript, runtest, iniFile, scriptResult, actionType, *iScriptPath, *iConsole, *iLogFile));
136 User::LeaveIfError(actionSpec.Init(actionData, relativePos, *iConsole, *iLogFile, scriptGroupings));
139 //Start off checking Exhaustive and Smoke flags, then calls groupings
140 if (!CheckAllFlags(aCommandLineSettings, scriptGroupings))
141 //The current test should not be run
145 CTestAction* newAction = 0;
146 TRAP(err, newAction = CreateActionL(aFs, actionSpec, theTestTypes));
153 iLogFile->write(_L("CScriptSetup::CreateActionL failed: "));
154 iLogFile->writeError(err);
155 iLogFile->writeNewLine();
157 iLogFile->write(_L("Action name: "));
158 iLogFile->writeString(actionSpec.iActionName);
159 iLogFile->writeNewLine();
161 iLogFile->write(_L("Action type: "));
162 iLogFile->writeString(actionSpec.iActionType);
163 iLogFile->writeNewLine();
165 iLogFile->write(_L("1 tests failed out of 1\r\n"));
170 if(newAction->ScriptError() != CTestAction::ENone)
172 TBuf<KMaxErrorSize> scriptError;
173 newAction->ScriptError(scriptError);
175 iLogFile->write(_L("Script error \"%S\" in test %s\r\n"), &scriptError, i);
178 User::Leave(KErrArgument);
181 CleanupStack::PushL(newAction);
182 User::LeaveIfError(aTestSpec.AddNextTest(newAction));
183 CleanupStack::Pop(newAction);
187 CleanupStack::PopAndDestroy(1);
192 EXPORT_C TBool CScriptSetup::InitialiseL(RFs &aFs, const TDesC& aDefaultScript, const TDesC& aDefaultLog, TBool aUseCommandLine)
194 // gets the script file argument
200 iScriptPath = GetArgument();
201 if(iScriptPath->Length()==0)
208 TPtr scriptFileNameDes = iScriptPath->Des();
209 if (scriptFileNameDes.Right(8) == _L(".script1") || scriptFileNameDes.Right(7) == _L(".script"))
216 if(iScriptPath == NULL)
218 if(aDefaultScript.Length() == 0)
220 PRINTANDLOG(_L("No script file specified on command line and no default given"));
225 iScriptPath = aDefaultScript.AllocLC();
229 PRINTANDLOG1(_L("Script file: %S"), iScriptPath);
231 // open the script file
233 TInt err = scriptFile.Open(aFs, *iScriptPath, EFileStream | EFileRead | EFileShareReadersOnly);
236 PRINTANDLOG1(_L("Error opening script file: %d"), err);
241 CleanupClosePushL(scriptFile);
243 TRAP(err, OpenLogFileL(aFs, 1, aDefaultLog, aUseCommandLine));
246 PRINTANDLOG1(_L("Error opening log file: %d"), err);
249 CleanupStack::PopAndDestroy(1);// scripFile
253 // gets size of script file
255 scriptFile.Size(size);
256 CleanupStack::PopAndDestroy(); // scriptFile
258 // reads script into iTestInput
259 iTestInput = HBufC8::NewL(size);
260 TPtr8 pInput(iTestInput->Des());
261 pInput.SetLength(size);
263 RFileReadStream stream;
264 User::LeaveIfError(stream.Open(aFs, *iScriptPath, EFileStream | EFileRead | EFileShareReadersOnly));
265 CleanupClosePushL(stream);
266 stream.ReadL(pInput, size);
267 CleanupStack::PopAndDestroy(1); // stream
271 EXPORT_C CTestAction* CScriptSetup::CreateActionL(RFs& aFs,
272 const TTestActionSpec& aTestActionSpec,
273 const TScriptTests theTestTypes[]) const
275 // Instantiate built in test actions
276 if (aTestActionSpec.iActionType == KStartMemFail)
278 return CMemFailStart::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
280 else if (aTestActionSpec.iActionType == KStopMemFail)
282 return CMemFailStop::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
284 else if (aTestActionSpec.iActionType == KCancelStart)
286 return CCancelStart::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
288 else if (aTestActionSpec.iActionType == KCancelStop)
290 return CCancelStop::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
292 else if (aTestActionSpec.iActionType == KMessage)
294 return CTestActionMessage::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
296 else if (aTestActionSpec.iActionType == KSleep)
298 return CSleep::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
300 else if (aTestActionSpec.iActionType == KPolicyTest)
302 return CPolicyTest::NewL(*iTestConsole, *iLogFile, aTestActionSpec);
305 // Look through the array of tests in order to find the correct class to return
307 while (theTestTypes[loop].action!=NULL)
309 if (aTestActionSpec.iActionType == theTestTypes[loop].name)
311 return theTestTypes[loop].action(aFs, *iTestConsole, *iLogFile, aTestActionSpec);
316 User::Leave(KErrNotSupported);