|
1 /* |
|
2 * Copyright (c) 1998-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 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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tScriptSetup.h" |
|
20 #include "tScriptTests.h" |
|
21 |
|
22 #include "t_testactionspec.h" |
|
23 #include "t_input.h" |
|
24 #include "t_certstoreactionmemfail.h" |
|
25 #include "tcancel.h" |
|
26 #include "t_sleep.h" |
|
27 #include "t_message.h" |
|
28 #include "t_output.h" |
|
29 #include "tTestSpec.h" |
|
30 |
|
31 #include <s32file.h> |
|
32 |
|
33 #include "t_logger.h" |
|
34 |
|
35 _LIT8(KStartMemFail, "startmemfailure"); |
|
36 _LIT8(KStopMemFail, "stopmemfailure"); |
|
37 _LIT8(KCancelStart, "startcancellation"); |
|
38 _LIT8(KCancelStop, "stopcancellation"); |
|
39 _LIT8(KMessage, "message"); |
|
40 _LIT8(KSleep, "sleep"); |
|
41 |
|
42 #include "t_policy.h" |
|
43 _LIT8(KPolicyTest, "policytest"); |
|
44 |
|
45 EXPORT_C CScriptSetup* CScriptSetup::NewLC(CConsoleBase* aConsole) |
|
46 { |
|
47 CScriptSetup* self = new (ELeave) CScriptSetup(aConsole); |
|
48 CleanupStack::PushL(self); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 CScriptSetup::CScriptSetup(CConsoleBase* aConsole) : CTestSetup(aConsole) |
|
54 { |
|
55 } |
|
56 |
|
57 CScriptSetup::~CScriptSetup() |
|
58 { |
|
59 delete iTestInput; |
|
60 } |
|
61 |
|
62 EXPORT_C void CScriptSetup::SetupTestsL(RFs& aFs, |
|
63 CTestSpec& aTestSpec, |
|
64 TScriptTests theTestTypes[], |
|
65 const CTestHandlerSettings& aCommandLineSettings) |
|
66 { |
|
67 TInt pos = 0; |
|
68 TInt err = KErrNone; |
|
69 for (TInt i = 1 ; ; ++i) |
|
70 { |
|
71 TPtrC8 actionData = Input::ParseElement(*iTestInput, KActionStart, KActionEnd, pos, err); |
|
72 if (err != KErrNone) |
|
73 { |
|
74 break; |
|
75 } |
|
76 |
|
77 TInt relativePos = 0; |
|
78 TInt scriptGroupings= DEFAULTGROUPING; |
|
79 TTestActionSpec actionSpec; |
|
80 //Parse the file to create action name, type , body and result |
|
81 User::LeaveIfError(actionSpec.Init(actionData, relativePos, *iConsole, *iLogFile, scriptGroupings)); |
|
82 |
|
83 //Start off checking Exhaustive and Smoke flags, then calls groupings |
|
84 if (!CheckAllFlags(aCommandLineSettings, scriptGroupings)) |
|
85 //The current test should not be run |
|
86 continue; |
|
87 |
|
88 CTestAction* newAction = 0; |
|
89 TRAP(err, newAction = |
|
90 CreateActionL(aFs, actionSpec, theTestTypes)); |
|
91 |
|
92 if (err != KErrNone) |
|
93 { |
|
94 iLogFile->write(_L("CScriptSetup::CreateActionL failed: ")); |
|
95 iLogFile->writeError(err); |
|
96 iLogFile->writeNewLine(); |
|
97 |
|
98 iLogFile->write(_L("Action name: ")); |
|
99 iLogFile->writeString(actionSpec.iActionName); |
|
100 iLogFile->writeNewLine(); |
|
101 |
|
102 iLogFile->write(_L("Action type: ")); |
|
103 iLogFile->writeString(actionSpec.iActionType); |
|
104 iLogFile->writeNewLine(); |
|
105 |
|
106 iLogFile->write(_L("1 tests failed out of 1\r\n")); |
|
107 |
|
108 User::Leave(err); |
|
109 } |
|
110 |
|
111 if(newAction->ScriptError() != CTestAction::ENone) |
|
112 { |
|
113 TBuf<KMaxErrorSize> scriptError; |
|
114 newAction->ScriptError(scriptError); |
|
115 |
|
116 iLogFile->write(_L("Script error \"%S\" in test %s\r\n"), &scriptError, i); |
|
117 |
|
118 delete newAction; |
|
119 User::Leave(KErrArgument); |
|
120 } |
|
121 |
|
122 CleanupStack::PushL(newAction); |
|
123 User::LeaveIfError(aTestSpec.AddNextTest(newAction)); |
|
124 CleanupStack::Pop(newAction); |
|
125 } |
|
126 } |
|
127 |
|
128 EXPORT_C TBool CScriptSetup::InitialiseL(RFs &aFs, const TDesC& aDefaultScript, const TDesC& aDefaultLog, TBool aUseCommandLine) |
|
129 { |
|
130 // gets the script file argument |
|
131 HBufC* scriptFileName = NULL; |
|
132 |
|
133 if (aUseCommandLine) |
|
134 { |
|
135 scriptFileName = GetArgument(); |
|
136 CleanupStack::PushL(scriptFileName); |
|
137 if(scriptFileName->Length()==0) |
|
138 { |
|
139 CleanupStack::PopAndDestroy(scriptFileName); |
|
140 scriptFileName = NULL; |
|
141 } |
|
142 } |
|
143 |
|
144 if(scriptFileName == NULL) |
|
145 { |
|
146 if(aDefaultScript.Length() == 0) |
|
147 { |
|
148 PRINTANDLOG(_L("No script file specified on command line and no default given")); |
|
149 return(EFalse); |
|
150 } |
|
151 else |
|
152 { |
|
153 scriptFileName = aDefaultScript.AllocLC(); |
|
154 } |
|
155 }; |
|
156 |
|
157 PRINTANDLOG1(_L("Script file: %S"), scriptFileName); |
|
158 |
|
159 // open the script file |
|
160 RFile scriptFile; |
|
161 TInt err = scriptFile.Open(aFs, *scriptFileName, EFileStream | EFileRead | EFileShareReadersOnly); |
|
162 if (err != KErrNone) |
|
163 { |
|
164 PRINTANDLOG1(_L("Error opening script file: %d"), err); |
|
165 CleanupStack::PopAndDestroy();// scriptFileName |
|
166 return(EFalse); |
|
167 } |
|
168 CleanupClosePushL(scriptFile); |
|
169 |
|
170 TRAP(err, OpenLogFileL(aFs, 1, aDefaultLog, aUseCommandLine)); |
|
171 if (err != KErrNone) |
|
172 { |
|
173 PRINTANDLOG1(_L("Error opening log file: %d"), err); |
|
174 CleanupStack::PopAndDestroy(2);// scripFile, scriptFileName |
|
175 return(EFalse); |
|
176 } |
|
177 |
|
178 // gets size of script file |
|
179 TInt size; |
|
180 scriptFile.Size(size); |
|
181 CleanupStack::PopAndDestroy(); // scriptFile |
|
182 |
|
183 // reads script into iTestInput |
|
184 iTestInput = HBufC8::NewL(size); |
|
185 TPtr8 pInput(iTestInput->Des()); |
|
186 pInput.SetLength(size); |
|
187 |
|
188 RFileReadStream stream; |
|
189 User::LeaveIfError(stream.Open(aFs, *scriptFileName, EFileStream | EFileRead | EFileShareReadersOnly)); |
|
190 CleanupClosePushL(stream); |
|
191 stream.ReadL(pInput, size); |
|
192 |
|
193 CleanupStack::PopAndDestroy(2); // stream, scriptFileName |
|
194 return(ETrue); |
|
195 } |
|
196 |
|
197 EXPORT_C CTestAction* CScriptSetup::CreateActionL(RFs& aFs, |
|
198 const TTestActionSpec& aTestActionSpec, |
|
199 const TScriptTests theTestTypes[]) const |
|
200 { |
|
201 // Instantiate built in test actions |
|
202 if (aTestActionSpec.iActionType == KStartMemFail) |
|
203 { |
|
204 return CMemFailStart::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
205 } |
|
206 else if (aTestActionSpec.iActionType == KStopMemFail) |
|
207 { |
|
208 return CMemFailStop::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
209 } |
|
210 else if (aTestActionSpec.iActionType == KCancelStart) |
|
211 { |
|
212 return CCancelStart::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
213 } |
|
214 else if (aTestActionSpec.iActionType == KCancelStop) |
|
215 { |
|
216 return CCancelStop::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
217 } |
|
218 else if (aTestActionSpec.iActionType == KMessage) |
|
219 { |
|
220 return CTestActionMessage::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
221 } |
|
222 else if (aTestActionSpec.iActionType == KSleep) |
|
223 { |
|
224 return CSleep::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
225 } |
|
226 else if (aTestActionSpec.iActionType == KPolicyTest) |
|
227 { |
|
228 return CPolicyTest::NewL(*iTestConsole, *iLogFile, aTestActionSpec); |
|
229 } |
|
230 |
|
231 // Look through the array of tests in order to find the correct class to return |
|
232 TInt loop=0; |
|
233 while (theTestTypes[loop].action!=NULL) |
|
234 { |
|
235 if (aTestActionSpec.iActionType == theTestTypes[loop].name) |
|
236 { |
|
237 return theTestTypes[loop].action(aFs, *iTestConsole, *iLogFile, aTestActionSpec); |
|
238 } |
|
239 loop++; |
|
240 } |
|
241 |
|
242 User::Leave(KErrNotSupported); |
|
243 return NULL; |
|
244 } |