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