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++ based Class. |
|
15 * Stf Controller implementation. |
|
16 * |
|
17 */ |
|
18 #include "stfqtuicontroller.h" |
|
19 #include <stifinternal/UIStoreIf.h> |
|
20 #include <stifinternal/UIStoreContainer.h> |
|
21 #include <QDateTime> |
|
22 |
|
23 const QString TEMPSETNAME = "TEMPSET"; |
|
24 const QString DEFAULTINI = "c:\\testframework\\testframework.ini"; |
|
25 |
|
26 |
|
27 |
|
28 StfQtUIController::StfQtUIController(IStfQtUIModel* aModel) : |
|
29 model(aModel), |
|
30 isShowOutput(false), |
|
31 iCurrentRunPos(0), |
|
32 isLoopInfinitely(false), |
|
33 loopTimes(0) |
|
34 |
|
35 { |
|
36 executor = new CStifExecutor(); |
|
37 executor->OpenIniFile(DEFAULTINI); |
|
38 executor->AddStifCaseUpdateListener(this); |
|
39 } |
|
40 |
|
41 StfQtUIController::~StfQtUIController() |
|
42 { |
|
43 executor->RemoveStifCaseUpdateListener(this); |
|
44 delete executor; |
|
45 executor = NULL; |
|
46 } |
|
47 //for cases |
|
48 |
|
49 bool StfQtUIController::OpenEngineIniFile(const QString& fileName) |
|
50 { |
|
51 QString path = fileName; |
|
52 if(path.contains('/')) |
|
53 { |
|
54 path = path.replace('/', '\\'); |
|
55 } |
|
56 executor->RemoveStifCaseUpdateListener(this); |
|
57 delete executor; |
|
58 executor = new CStifExecutor(); |
|
59 bool rst = executor->OpenIniFile(path); |
|
60 executor->AddStifCaseUpdateListener(this); |
|
61 return rst; |
|
62 } |
|
63 |
|
64 QList<QString> StfQtUIController::GetModuleList() |
|
65 { |
|
66 QList<CSTFModule> modules = executor->GetModuleList(); |
|
67 QList<QString> moduleList; |
|
68 foreach(CSTFModule m, modules) |
|
69 { |
|
70 moduleList.append(m.Name()); |
|
71 } |
|
72 return moduleList; |
|
73 } |
|
74 |
|
75 CSTFModule StfQtUIController::GetModuleByName(const QString& moduleName) |
|
76 { |
|
77 QList<CSTFModule> modules = executor->GetModuleList(); |
|
78 CSTFModule module; |
|
79 foreach(CSTFModule m, modules) |
|
80 { |
|
81 if(m.Name() == moduleName) |
|
82 { |
|
83 module = m; |
|
84 break; |
|
85 } |
|
86 } |
|
87 return module; |
|
88 |
|
89 } |
|
90 |
|
91 QList<QString> StfQtUIController::GetCaseListByModule(const QString& moduleName) |
|
92 { |
|
93 QList<QString> caseList; |
|
94 if (moduleName != "") |
|
95 { |
|
96 QList<CSTFCase> cases = executor->GetCaseList(moduleName); |
|
97 foreach(CSTFCase c, cases) |
|
98 { |
|
99 caseList.append(c.Name()); |
|
100 } |
|
101 } |
|
102 |
|
103 return caseList; |
|
104 } |
|
105 |
|
106 CSTFCase StfQtUIController::GetCase(const QString& moduleName, const int index) |
|
107 { |
|
108 CSTFCase rst; |
|
109 if(moduleName != "") |
|
110 { |
|
111 QList<CSTFCase> cases = executor->GetCaseList(moduleName); |
|
112 if(index < cases.length()) |
|
113 { |
|
114 rst = cases.at(index); |
|
115 } |
|
116 } |
|
117 return rst; |
|
118 } |
|
119 |
|
120 void StfQtUIController::RunCases(const QList<CSTFCase>& caseList, |
|
121 const TSTFCaseRunningType& type) |
|
122 { |
|
123 if (caseList.size() == 1) |
|
124 { |
|
125 CSTFCase aCase = caseList.at(0); |
|
126 QString msg = "Start execute case:" + aCase.Name(); |
|
127 FireOnGetOutput(msg); |
|
128 executor->ExecuteSingleCase(aCase.ModuleName(), aCase.Index()); |
|
129 } |
|
130 else |
|
131 { |
|
132 //create a temp set, append cases into the set and execute it. |
|
133 executor->CreateSet(TEMPSETNAME); |
|
134 foreach(CSTFCase aCase, caseList) |
|
135 { |
|
136 executor->AddtoSet(TEMPSETNAME, aCase); |
|
137 } |
|
138 RunSets(TEMPSETNAME, type); |
|
139 executor->RemoveSet(TEMPSETNAME); |
|
140 } |
|
141 } |
|
142 |
|
143 // run cases repeatly. |
|
144 // By default, loopTimes = -1 means loop infinitely util user stop it. |
|
145 void StfQtUIController::RepeatRunCases(const QList<CSTFCase>& aCaseList, const bool aIsLoopInfinitely, const int aLoopTimes) |
|
146 { |
|
147 InitRepeatSetting(aIsLoopInfinitely, aLoopTimes); |
|
148 repeatRunCaseList = aCaseList; |
|
149 |
|
150 Execution(); |
|
151 |
|
152 } |
|
153 |
|
154 void StfQtUIController::InitRepeatSetting(const bool aIsLoopInfinitely, const int aLoopTimes) |
|
155 { |
|
156 loopTimes = aLoopTimes; |
|
157 isLoopInfinitely = aIsLoopInfinitely; |
|
158 iCurrentRunPos = 0; |
|
159 } |
|
160 |
|
161 void StfQtUIController::ResetRepeatSetting() |
|
162 { |
|
163 iCurrentRunPos = 0; |
|
164 isLoopInfinitely = false; |
|
165 loopTimes = 0; |
|
166 } |
|
167 |
|
168 // Repeat execution cases |
|
169 void StfQtUIController::Execution() |
|
170 { |
|
171 if(loopTimes > 0 || isLoopInfinitely) |
|
172 { |
|
173 int count = repeatRunCaseList.count(); |
|
174 CSTFCase aCase = repeatRunCaseList.at(iCurrentRunPos); |
|
175 QString msg = "Start execute case:" + aCase.Name(); |
|
176 FireOnGetOutput(msg); |
|
177 executor->ExecuteSingleCase(aCase.ModuleName(), aCase.Index()); |
|
178 |
|
179 iCurrentRunPos++; |
|
180 if( iCurrentRunPos >= count ) |
|
181 { |
|
182 iCurrentRunPos = 0; |
|
183 loopTimes --; |
|
184 } |
|
185 } |
|
186 } |
|
187 |
|
188 bool StfQtUIController::AddCaseToSet(const QList<CSTFCase>& caseList, |
|
189 const QString& setName) |
|
190 { |
|
191 QString name = setName; |
|
192 bool rst = true; |
|
193 foreach(CSTFCase aCase, caseList) |
|
194 { |
|
195 rst = executor->AddtoSet(name, aCase); |
|
196 if(!rst) |
|
197 { |
|
198 break; |
|
199 } |
|
200 } |
|
201 if(!rst) |
|
202 { |
|
203 return false; |
|
204 } |
|
205 rst = executor->SaveSet(name); |
|
206 FireOnSetListChanged(); |
|
207 return rst; |
|
208 } |
|
209 |
|
210 //for set |
|
211 |
|
212 QList<QString> StfQtUIController::GetSetList() |
|
213 { |
|
214 return executor->GetSetList(); |
|
215 } |
|
216 QList<QString> StfQtUIController::GetCaseListBySet(const QString& setName) |
|
217 { |
|
218 QList<CSTFCase> cases = executor->GetCaseListFromSet(setName); |
|
219 QList<QString> caseList; |
|
220 foreach(CSTFCase c, cases) |
|
221 { |
|
222 caseList.append(c.Name()); |
|
223 } |
|
224 return caseList; |
|
225 } |
|
226 |
|
227 bool StfQtUIController::CreateSet(QString& setName) |
|
228 { |
|
229 bool rst = executor->CreateSet(setName); |
|
230 if(!rst) |
|
231 { |
|
232 return rst; |
|
233 } |
|
234 rst = executor->SaveSet(setName); |
|
235 FireOnSetListChanged(); |
|
236 return rst; |
|
237 } |
|
238 |
|
239 bool StfQtUIController::DeleteSet(const QString& setName) |
|
240 { |
|
241 bool rst = executor->RemoveSet(setName); |
|
242 if(!rst) |
|
243 { |
|
244 return false; |
|
245 } |
|
246 QString name = setName; |
|
247 rst = executor->SaveSet(name); |
|
248 FireOnSetListChanged(); |
|
249 return rst; |
|
250 } |
|
251 |
|
252 void StfQtUIController::RunSets(const QString& setName, const TSTFCaseRunningType& type) |
|
253 { |
|
254 executor->ExecuteSet(setName, 0, type); |
|
255 } |
|
256 |
|
257 //for Started |
|
258 void StfQtUIController::PauseCase() |
|
259 { |
|
260 model->PauseCase(); |
|
261 QString msg = "Execution Paused"; |
|
262 FireOnGetOutput(msg); |
|
263 } |
|
264 |
|
265 void StfQtUIController::ResumeCase() |
|
266 { |
|
267 model->ResumeCase(); |
|
268 FireOnGetOutput("Execution Resumed"); |
|
269 } |
|
270 |
|
271 void StfQtUIController::AbortCase() |
|
272 { |
|
273 model->AbortCase(); |
|
274 FireOnGetOutput("Case Aborted"); |
|
275 } |
|
276 |
|
277 CSTFCase StfQtUIController::GetRunningCase(int index) |
|
278 { |
|
279 CStartedTestCase* startedCase = (CStartedTestCase*) index; |
|
280 return model->GetRunningCase(startedCase); |
|
281 } |
|
282 |
|
283 bool StfQtUIController::ShowOutput() |
|
284 { |
|
285 return isShowOutput; |
|
286 } |
|
287 |
|
288 void StfQtUIController::SetShowOutput(bool isShow) |
|
289 { |
|
290 isShowOutput = isShow; |
|
291 } |
|
292 |
|
293 QList<CSTFCase> StfQtUIController::GetCasesByStatus(const TSTFCaseStatusType& type) |
|
294 { |
|
295 return model->GetCasesByStatus(type); |
|
296 } |
|
297 |
|
298 void StfQtUIController::AddStfEventListener(IStfEventListener* listener) |
|
299 { |
|
300 if (!listenerList.contains(listener)) |
|
301 { |
|
302 listenerList.append(listener); |
|
303 } |
|
304 } |
|
305 void StfQtUIController::RemoveStfEventListener(IStfEventListener* listener) |
|
306 { |
|
307 if (listenerList.contains(listener)) |
|
308 { |
|
309 listenerList.removeOne(listener); |
|
310 } |
|
311 } |
|
312 |
|
313 void StfQtUIController::OnGetCaseUpdated(CStartedTestCase* aCase, |
|
314 CSTFCase& stfcase, int flags) |
|
315 { |
|
316 if (flags & CUIStoreIf::EPrintUpdate || aCase == NULL) |
|
317 { |
|
318 return; |
|
319 } |
|
320 QString msg = "case Name:"; |
|
321 msg += stfcase.Name() + "\r\n Status:"; |
|
322 flags = aCase->Status(); |
|
323 if (flags & CUIStoreIf::EStatusRunning) |
|
324 { |
|
325 model->AddRunningCase(aCase, stfcase); |
|
326 msg += "start running"; |
|
327 FireOnCaseOutputChanged(IStfEventListener::ECreate, (int) aCase, |
|
328 stfcase.Name()); |
|
329 } |
|
330 else if (flags & CUIStoreIf::EStatusAborted) |
|
331 { |
|
332 FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, ""); |
|
333 model->RemoveRunningCase(aCase); |
|
334 model->AddCaseByStatus(EStatusAborted, stfcase); |
|
335 msg += "aborted"; |
|
336 |
|
337 //reset repeat execution information |
|
338 ResetRepeatSetting(); |
|
339 |
|
340 } |
|
341 else if (flags & CUIStoreIf::EStatusExecuted) |
|
342 { |
|
343 FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, ""); |
|
344 model->RemoveRunningCase(aCase); |
|
345 model->AddCaseByStatus(EStatusExecuted, stfcase); |
|
346 |
|
347 if (flags & CUIStoreIf::EStatusCrashed) |
|
348 { |
|
349 model->AddCaseByStatus(EStatusCrashed, stfcase); |
|
350 msg += "crashed"; |
|
351 } |
|
352 else if (flags & CUIStoreIf::EStatusFailed) |
|
353 { |
|
354 model->AddCaseByStatus(EStatusFailed, stfcase); |
|
355 msg += "failed"; |
|
356 } |
|
357 else if (flags & CUIStoreIf::EStatusPassed) |
|
358 { |
|
359 model->AddCaseByStatus(EStatusPassed, stfcase); |
|
360 msg += "passed"; |
|
361 } |
|
362 |
|
363 // if repeat execution is choosed, start to execution again. |
|
364 if(loopTimes > 0 || isLoopInfinitely) |
|
365 { |
|
366 Execution(); |
|
367 } |
|
368 } |
|
369 else |
|
370 { |
|
371 return; |
|
372 } |
|
373 |
|
374 FireOnGetOutput(msg); |
|
375 } |
|
376 |
|
377 void StfQtUIController::OnGetCaseOutput(CStartedTestCase* aCase, QString& msg) |
|
378 { |
|
379 FireOnCaseOutputChanged(IStfEventListener::EOutput, (int) aCase, msg); |
|
380 } |
|
381 |
|
382 void StfQtUIController::FireOnCaseOutputChanged( |
|
383 IStfEventListener::CaseOutputCommand cmd, int index, QString msg) |
|
384 { |
|
385 if (true)//ShowOutput |
|
386 { |
|
387 foreach(IStfEventListener* listener, listenerList) |
|
388 { |
|
389 listener->OnCaseOutputChanged(cmd, |
|
390 QString::number(index, 10), msg); |
|
391 } |
|
392 } |
|
393 } |
|
394 |
|
395 void StfQtUIController::FireOnGetOutput(QString message) |
|
396 { |
|
397 foreach(IStfEventListener* listener, listenerList) |
|
398 { |
|
399 listener->OnGetMessage(message); |
|
400 } |
|
401 } |
|
402 |
|
403 void StfQtUIController::FireOnSetListChanged() |
|
404 { |
|
405 foreach(IStfEventListener* listener, listenerList) |
|
406 { |
|
407 listener->OnSetListChanged(); |
|
408 } |
|
409 } |
|
410 |
|
411 // End of File |
|