|
1 /* |
|
2 * Copyright (c) 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: QT C++ and Symbian C++ combination Class. |
|
15 * STIF UI interface and engine caller implementaion. |
|
16 * |
|
17 */ |
|
18 #include <e32base.h> |
|
19 #include <e32cons.h> |
|
20 #include <e32svr.h> |
|
21 #include <f32file.h> |
|
22 #include <HAL.h> |
|
23 #include <hal_data.h> |
|
24 #include "stiflogger.h" |
|
25 #include <QString> |
|
26 #include "stifexecutor.h" |
|
27 #include "StifTFwIf.h" |
|
28 |
|
29 _LIT( KLogPath, "\\Logs\\STFUI\\" ); |
|
30 // Log file |
|
31 _LIT( KLogFile, "StifUi.log" ); |
|
32 |
|
33 CStifExecutor::CStifExecutor() : |
|
34 listenerList(NULL) |
|
35 { |
|
36 iLog = CStifLogger::NewL( KLogPath, |
|
37 KLogFile, |
|
38 CStifLogger::ETxt, |
|
39 CStifLogger::EFile, |
|
40 ETrue, |
|
41 ETrue, |
|
42 ETrue, |
|
43 EFalse, |
|
44 ETrue, |
|
45 EFalse, |
|
46 100 ); |
|
47 |
|
48 |
|
49 iLog->Log(_L("started")); |
|
50 TInt result; |
|
51 TRAP(result, CUIStoreIf::ConstructL()); |
|
52 iLog->Log(_L("CUIStoreIf ConstructL, result=%d"), result); |
|
53 if (result != KErrNone) |
|
54 { |
|
55 return; |
|
56 } |
|
57 TRAP(result, iBuffer = HBufC::NewL(500)); |
|
58 iLog->Log(_L("Create Case Execution output buffer, result=%d"), result); |
|
59 |
|
60 } |
|
61 |
|
62 CStifExecutor::~CStifExecutor() |
|
63 { |
|
64 UIStore().Close(); |
|
65 delete iBuffer; |
|
66 if (listenerList) |
|
67 { |
|
68 delete listenerList; |
|
69 listenerList = NULL; |
|
70 } |
|
71 iLog->Log(_L("finished")); |
|
72 } |
|
73 |
|
74 bool CStifExecutor::OpenIniFile(const QString& filename) |
|
75 { |
|
76 TInt result = UIStore().Open(QString2TPtrC(filename)); |
|
77 iLog->Log(_L("Open ini file %s.result=%d"),QString2TPtrC(filename).Ptr(),result); |
|
78 return (result == KErrNone); |
|
79 } |
|
80 |
|
81 TPtrC CStifExecutor::QString2TPtrC(const QString& aString) |
|
82 { |
|
83 TPtrC ret(reinterpret_cast<const TText*> (aString.constData()), |
|
84 aString.length()); |
|
85 return ret; |
|
86 } |
|
87 QString CStifExecutor::TDesC2QString(const TDesC& des) |
|
88 { |
|
89 //#ifdef QT_NO_UNICODE |
|
90 //return QString::fromLocal8Bit((char*)des.Ptr(), des.Length()); |
|
91 //#else |
|
92 QString rst = QString::fromUtf16(des.Ptr(), des.Length()); |
|
93 return rst; |
|
94 //#endif |
|
95 } |
|
96 |
|
97 bool CStifExecutor::LogResult(const TInt result,const QString str) |
|
98 { |
|
99 QString tmp = str + " result=%d"; |
|
100 iLog->Log(QString2TPtrC(tmp), result); |
|
101 bool rst = true; |
|
102 if(result != KErrNone) |
|
103 { |
|
104 rst = false; |
|
105 } |
|
106 return rst; |
|
107 } |
|
108 |
|
109 void CStifExecutor::AddStifCaseUpdateListener( |
|
110 IStifCaseUpdateListener* listener) |
|
111 { |
|
112 iLog->Log(_L("AddStifCaseUpdateListener")); |
|
113 if (!listenerList) |
|
114 { |
|
115 listenerList = new QList<IStifCaseUpdateListener*> (); |
|
116 } |
|
117 if (!listenerList->contains(listener)) |
|
118 { |
|
119 listenerList->append(listener); |
|
120 } |
|
121 } |
|
122 |
|
123 void CStifExecutor::RemoveStifCaseUpdateListener( |
|
124 IStifCaseUpdateListener* listener) |
|
125 { |
|
126 iLog->Log(_L("RemoveStifCaseUpdateListener")); |
|
127 if (!listenerList) |
|
128 { |
|
129 return; |
|
130 } |
|
131 |
|
132 if (listenerList->contains(listener)) |
|
133 { |
|
134 listenerList->removeOne(listener); |
|
135 } |
|
136 |
|
137 } |
|
138 |
|
139 QList<CSTFModule> CStifExecutor::GetModuleList() |
|
140 { |
|
141 QList<CSTFModule> list; |
|
142 RRefArray<TDesC> modules; |
|
143 iLog->Log(_L("GetModuleList")); |
|
144 TInt ret = UIStore().Modules(modules); |
|
145 iLog->Log(_L("LoadAllModules %d"), ret); |
|
146 iLog->Log(_L("Modules number=%d"), modules.Count()); |
|
147 for (TInt i = 0; i < modules.Count(); i++) |
|
148 { |
|
149 iLog->Log(_L("Get Module Names %d"), i); |
|
150 iLog->Log(_L("Get Module Name = %d .=%s"),i,modules[i].Ptr()); |
|
151 |
|
152 CSTFModule module; |
|
153 module.SetName(QString::fromUtf16(modules[i].Ptr(), |
|
154 modules[i].Length())); |
|
155 //module.SetName(TDesC2QString(modules[i])); |
|
156 list.append(module); |
|
157 } |
|
158 modules.Reset(); |
|
159 modules.Close(); |
|
160 return list; |
|
161 } |
|
162 |
|
163 QList<CSTFCase> CStifExecutor::GetCaseList(const QString& moduleName) |
|
164 { |
|
165 TPtrC name = QString2TPtrC(moduleName); |
|
166 QList<CSTFCase> list; |
|
167 RRefArray<CTestInfo> testCases; |
|
168 TInt ret = UIStore().TestCases(testCases, name, KNullDesC); |
|
169 iLog->Log(_L("Get TestCases: %d"), ret); |
|
170 for (TInt i = 0; i < testCases.Count(); i++) |
|
171 { |
|
172 iLog->Log(_L("Case Number: %d"),testCases[i].TestCaseNum()); |
|
173 iLog->Log(_L("Case Name: %s"),testCases[i].TestCaseTitle().Ptr()); |
|
174 CSTFCase testcase; |
|
175 testcase.SetName(TDesC2QString(testCases[i].TestCaseTitle())); |
|
176 testcase.SetIndex(i); |
|
177 list.append(testcase); |
|
178 } |
|
179 testCases.Reset(); |
|
180 testCases.Close(); |
|
181 return list; |
|
182 } |
|
183 |
|
184 void CStifExecutor::ExecuteSingleCase(const QString& moduleName, const int caseIndex) |
|
185 { |
|
186 iLog->Log(_L("ExecuteCase start")); |
|
187 TPtrC name = QString2TPtrC(moduleName); |
|
188 RRefArray<CTestInfo> testCases; |
|
189 TInt ret = UIStore().TestCases(testCases, name, KNullDesC); |
|
190 iLog->Log(_L("Get TestCases return code=%d"), ret); |
|
191 if (testCases.Count() > caseIndex) |
|
192 { |
|
193 TInt index; |
|
194 UIStore().StartTestCase(testCases[caseIndex], index); |
|
195 iLog->Log(_L("start test case index=%d"), index); |
|
196 } |
|
197 testCases.Reset(); |
|
198 testCases.Close(); |
|
199 iLog->Log(_L("ExecuteCase end")); |
|
200 |
|
201 } |
|
202 |
|
203 QList<QString> CStifExecutor::GetSetList() |
|
204 { |
|
205 QList<QString> list; |
|
206 RRefArray<TDesC> aArray; |
|
207 TInt ret = UIStore().GetTestSetsList(aArray); |
|
208 iLog->Log(_L("Get TestSet list return code=%d"), ret); |
|
209 if (ret != KErrNone) //setInfos.Count() != 1 |
|
210 { |
|
211 return list; |
|
212 } |
|
213 for (int i = 0; i < aArray.Count(); i++) |
|
214 { |
|
215 list.append(TDesC2QString(aArray[i])); |
|
216 } |
|
217 aArray.Reset(); |
|
218 aArray.Close(); |
|
219 return list; |
|
220 } |
|
221 |
|
222 QList<CSTFCase> CStifExecutor::GetCaseListFromSet(const QString& setName) |
|
223 { |
|
224 iLog->Log(_L("GetCaseListFromSet start.")); |
|
225 QList<CSTFCase> list; |
|
226 TPtrC name = QString2TPtrC(setName); |
|
227 |
|
228 //iLog->Log(name); |
|
229 if (name.Length() == 0) |
|
230 { |
|
231 return list; |
|
232 } |
|
233 |
|
234 iLog->Log(_L("name.Length()=%d"), name.Length()); |
|
235 TInt ret = UIStore().LoadTestSet(name); |
|
236 iLog->Log(_L("Load Test Set return=%d"),ret); |
|
237 const CTestSetInfo* set = NULL; |
|
238 TRAP(ret , set = &UIStore().TestSetL(name)); |
|
239 iLog->Log(_L("GetCaseListFromSet TestSetL.")); |
|
240 if(ret != KErrNone) |
|
241 { |
|
242 return list; |
|
243 } |
|
244 const RRefArray<const CTestInfo>& testCases = set->TestCases(); |
|
245 iLog->Log(_L("GetCaseListFromSet TestCases.")); |
|
246 TInt count = testCases.Count(); |
|
247 for (TInt i = 0; i < count; i++) |
|
248 { |
|
249 CSTFCase testcase; |
|
250 testcase.SetName(TDesC2QString(testCases[i].TestCaseTitle())); |
|
251 testcase.SetIndex(testCases[i].TestCaseNum()); |
|
252 testcase.SetModuleName(TDesC2QString(testCases[i].ModuleName())); |
|
253 list.append(testcase); |
|
254 } |
|
255 iLog->Log(_L("GetCaseListFromSet end.")); |
|
256 return list; |
|
257 } |
|
258 |
|
259 bool CStifExecutor::CreateSet(const QString& setName) |
|
260 { |
|
261 TPtrC name = QString2TPtrC(setName); |
|
262 TInt ret = UIStore().CreateTestSet(name); |
|
263 return LogResult(ret, "CreateSet"); |
|
264 } |
|
265 |
|
266 bool CStifExecutor::SaveSet(QString& setName) |
|
267 { |
|
268 TPtrC name = QString2TPtrC(setName); |
|
269 TFileName testSetName; |
|
270 testSetName.Copy(name); |
|
271 TInt ret = UIStore().SaveTestSet(testSetName); |
|
272 setName = TDesC2QString(testSetName); |
|
273 return LogResult(ret, "SaveSet"); |
|
274 } |
|
275 |
|
276 bool CStifExecutor::RemoveSet(const QString& setName) |
|
277 { |
|
278 //This method wil not work at this stage. |
|
279 TPtrC name = QString2TPtrC(setName); |
|
280 TInt ret = UIStore().RemoveTestSet(name); |
|
281 return LogResult(ret, "RemoveSet"); |
|
282 } |
|
283 |
|
284 bool CStifExecutor::AddtoSet(const QString& setName, CSTFCase& caseInfo) |
|
285 { |
|
286 iLog->Log(_L("AddToSet Start")); |
|
287 |
|
288 //IMPORT_C TInt AddToTestSet( const TDesC& aSetName, const CTestInfo& aTestInfo ); |
|
289 TPtrC modulename = QString2TPtrC(caseInfo.ModuleName()); |
|
290 iLog->Log(_L("AddToSet dealwith module: %s"), modulename.Ptr()); |
|
291 iLog->Log(_L("Case name: %s"),QString2TPtrC(caseInfo.Name()).Ptr()); |
|
292 iLog->Log(_L("Case index: %d"),caseInfo.Index()); |
|
293 TInt caseIndex = caseInfo.Index(); |
|
294 if(caseInfo.ModuleName().toLower() == "testscripter" |
|
295 ||caseInfo.ModuleName().toLower() == "teftestmodule") |
|
296 { |
|
297 caseIndex++; |
|
298 } |
|
299 RRefArray<CTestInfo> testCases; |
|
300 TInt ret = UIStore().TestCases(testCases, modulename, KNullDesC); |
|
301 if(!LogResult(ret, "AddToSet, GetTestCases")) |
|
302 { |
|
303 return false; |
|
304 } |
|
305 |
|
306 ret = -1; |
|
307 for (TInt i = 0; i < testCases.Count(); i++) |
|
308 { |
|
309 iLog->Log(_L("Case Number: %d"),testCases[i].TestCaseNum()); |
|
310 iLog->Log(_L("Case Title: %s"),testCases[i].TestCaseTitle().Ptr()); |
|
311 |
|
312 if (testCases[i].TestCaseNum() == caseIndex) |
|
313 { |
|
314 ret = UIStore().AddToTestSet(QString2TPtrC(setName), testCases[i]); |
|
315 iLog->Log(_L("AddToTestSet: %d"), ret); |
|
316 break; |
|
317 } |
|
318 } |
|
319 testCases.Reset(); |
|
320 testCases.Close(); |
|
321 return LogResult(ret, "AddToSet"); |
|
322 } |
|
323 |
|
324 void CStifExecutor::ExecuteSet(const QString& SetName, const int startIndex, |
|
325 const TSTFCaseRunningType type) |
|
326 { |
|
327 CStartedTestSet::TSetType setType = CStartedTestSet::ESetSequential; |
|
328 if (type == Parallel) |
|
329 { |
|
330 setType = CStartedTestSet::ESetParallel; |
|
331 } |
|
332 const CTestSetInfo* set = NULL; |
|
333 TInt ret; |
|
334 TBuf<30> test; |
|
335 test.Append(QString2TPtrC(SetName)); |
|
336 iLog->Log(_L("StartTestSet GetSetName:")); |
|
337 iLog->Log(test); |
|
338 TRAP(ret, set = &UIStore().TestSetL(test)); |
|
339 |
|
340 //const CTestSetInfo& set = UIStore().TestSetL(QString2TPtrC(SetName)); |
|
341 if(ret != KErrNone) |
|
342 { |
|
343 iLog->Log(_L("StartTestSet GetTestSet Error return=%d"),ret); |
|
344 return; |
|
345 } |
|
346 int a = startIndex; |
|
347 ret = UIStore().StartTestSet(*set, a, setType); |
|
348 iLog->Log(_L("StartTestSet return=%d"),ret); |
|
349 } |
|
350 |
|
351 void CStifExecutor::Update(CStartedTestCase* aCase, int flags) |
|
352 { |
|
353 iLog->Log(_L("CStifExecutor::Update return case=%d"),aCase); |
|
354 iLog->Log(_L("CStifExecutor::Update return status=%d"),flags); |
|
355 |
|
356 if(aCase == NULL) |
|
357 { |
|
358 return; |
|
359 } |
|
360 |
|
361 if (flags & CUIStoreIf::EPrintUpdate) |
|
362 { |
|
363 //Cases output information update. |
|
364 const RPointerArray<CTestProgress> printArray = aCase->PrintArray(); |
|
365 TInt rows = aCase->PrintArray().Count(); |
|
366 TPtr buffer(iBuffer->Des()); |
|
367 buffer.Zero(); |
|
368 for (int i = 0; i < rows; i++) |
|
369 { |
|
370 buffer.Append(_L("\r\n")); |
|
371 buffer.Append(printArray[i]->iDescription); |
|
372 buffer.Append(_L(" ")); |
|
373 buffer.Append(printArray[i]->iText); |
|
374 buffer.Append(_L("\r\n")); |
|
375 } |
|
376 QString msg = TDesC2QString(buffer); |
|
377 iLog->Log(_L("Get output msg:")); |
|
378 iLog->Log(buffer); |
|
379 if (listenerList) |
|
380 { |
|
381 for (int i = 0; i < listenerList->size(); i++) |
|
382 { |
|
383 listenerList->at(i)->OnGetCaseOutput(aCase, msg); |
|
384 } |
|
385 } |
|
386 |
|
387 } |
|
388 else |
|
389 { |
|
390 //case status changed update. |
|
391 CSTFCase testcase; |
|
392 testcase.SetName(TDesC2QString(aCase->TestInfo().TestCaseTitle())); |
|
393 testcase.SetIndex(aCase->TestInfo().TestCaseNum()); |
|
394 testcase.SetModuleName(TDesC2QString(aCase->TestInfo().ModuleName())); |
|
395 if (listenerList) |
|
396 { |
|
397 for (int i = 0; i < listenerList->size(); i++) |
|
398 { |
|
399 listenerList->at(i)->OnGetCaseUpdated(aCase, testcase, flags); |
|
400 } |
|
401 } |
|
402 |
|
403 } |
|
404 |
|
405 } |
|
406 |
|
407 // End of File |