stifui/qt/src/stfqtuicontroller.cpp
branchRCL_3
changeset 9 404ad6c9bc20
child 12 aefcba28a3e0
equal deleted inserted replaced
8:87e9ebfbe96a 9:404ad6c9bc20
       
     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 "stiflogger.h"
       
    22 #include <QDateTime>
       
    23 
       
    24 const QString TEMPSETNAME = "TEMPSET";
       
    25 const QString DEFAULTINI = "c:\\testframework\\testframework.ini";
       
    26 
       
    27 //__DECLARE_LOG
       
    28 
       
    29 StfQtUIController::StfQtUIController(IStfQtUIModel* aModel) :
       
    30     model(aModel), isShowOutput(false)
       
    31     {
       
    32 //    __OPENLOGL ("\\STFQtUI\\", "StifQtUi.log" );
       
    33     executor = new CStifExecutor();
       
    34     executor->OpenIniFile(DEFAULTINI);
       
    35     executor->AddStifCaseUpdateListener(this);
       
    36     }
       
    37 
       
    38 StfQtUIController::~StfQtUIController()
       
    39     {
       
    40     executor->RemoveStifCaseUpdateListener(this);
       
    41     delete executor;
       
    42     executor = NULL;
       
    43 //    __CLOSELOG;
       
    44     }
       
    45 //for cases
       
    46 
       
    47 bool StfQtUIController::OpenEngineIniFile(const QString& fileName)
       
    48     {
       
    49     delete executor;
       
    50     executor = new CStifExecutor();
       
    51     bool rst = executor->OpenIniFile(fileName);
       
    52     executor->AddStifCaseUpdateListener(this);
       
    53     return rst;
       
    54     }
       
    55 
       
    56 QList<QString> StfQtUIController::GetModuleList()
       
    57     {
       
    58     QList<CSTFModule> modules = executor->GetModuleList();
       
    59     QList<QString> moduleList;
       
    60     foreach(CSTFModule m, modules)
       
    61             {
       
    62             moduleList.append(m.Name());
       
    63             }
       
    64     return moduleList;
       
    65     }
       
    66 
       
    67 CSTFModule StfQtUIController::GetModuleByName(const QString& moduleName)
       
    68     {
       
    69     QList<CSTFModule> modules = executor->GetModuleList();
       
    70     CSTFModule module;
       
    71     foreach(CSTFModule m, modules)
       
    72         {
       
    73         if(m.Name() == moduleName)
       
    74             {
       
    75             module = m;
       
    76             break;
       
    77             }
       
    78         }
       
    79     return module;
       
    80         
       
    81     }
       
    82 
       
    83 QList<QString> StfQtUIController::GetCaseListByModule(const QString& moduleName)
       
    84     {
       
    85     QList<QString> caseList;
       
    86     if (moduleName != "")
       
    87         {
       
    88         QList<CSTFCase> cases = executor->GetCaseList(moduleName);
       
    89         foreach(CSTFCase c, cases)
       
    90                 {
       
    91                 caseList.append(c.Name());
       
    92                 }
       
    93         }
       
    94 
       
    95     return caseList;
       
    96     }
       
    97 
       
    98 CSTFCase StfQtUIController::GetCase(const QString& moduleName, const int index)
       
    99     {
       
   100     CSTFCase rst;
       
   101     if(moduleName != "")
       
   102         {
       
   103         QList<CSTFCase> cases = executor->GetCaseList(moduleName);
       
   104         if(index < cases.length())
       
   105             {
       
   106             rst = cases.at(index);
       
   107             }
       
   108         }
       
   109     return rst;
       
   110     }
       
   111 
       
   112 void StfQtUIController::RunCases(const QList<CSTFCase>& caseList,
       
   113         const TSTFCaseRunningType& type)
       
   114     {
       
   115     if (caseList.size() == 1)
       
   116         {
       
   117         CSTFCase aCase = caseList.at(0);
       
   118         QString msg = "Start execute case:" + aCase.Name();
       
   119         FireOnGetOutput(msg);
       
   120         executor->ExecuteSingleCase(aCase.ModuleName(), aCase.Index());
       
   121         }
       
   122     else
       
   123         {
       
   124         //create a temp set, append cases into the set and execute it.
       
   125         executor->CreateSet(TEMPSETNAME);
       
   126         foreach(CSTFCase aCase, caseList)
       
   127                 {
       
   128                 executor->AddtoSet(TEMPSETNAME, aCase);
       
   129                 }
       
   130         RunSets(TEMPSETNAME, type);
       
   131         executor->RemoveSet(TEMPSETNAME);
       
   132         }
       
   133     }
       
   134 
       
   135 void StfQtUIController::AddCaseToSet(const QList<CSTFCase>& caseList,
       
   136         const QString& /*setName*/)
       
   137     {
       
   138     QString setName = QDateTime::currentDateTime().toString("hh_mm_ss");
       
   139     setName.append(".set");
       
   140     executor->CreateSet(setName);
       
   141     foreach(CSTFCase aCase, caseList)
       
   142             {
       
   143             executor->AddtoSet(setName, aCase);
       
   144             }
       
   145     executor->SaveSet(setName);
       
   146     executor->RemoveSet(setName);
       
   147     FireOnSetListChanged();
       
   148     }
       
   149 
       
   150 //for set
       
   151 
       
   152 QList<QString> StfQtUIController::GetSetList()
       
   153     {
       
   154     return executor->GetSetList();
       
   155     }
       
   156 QList<QString> StfQtUIController::GetCaseListBySet(const QString& setName)
       
   157     {
       
   158     QList<CSTFCase> cases = executor->GetCaseListFromSet(setName);
       
   159     QList<QString> caseList;
       
   160     foreach(CSTFCase c, cases)
       
   161             {
       
   162             caseList.append(c.Name());
       
   163             }
       
   164     return caseList;
       
   165     }
       
   166 
       
   167 void StfQtUIController::CreateSet(const QString& setName)
       
   168     {
       
   169     executor->CreateSet(setName);
       
   170     //executor->SaveSet(setName);
       
   171     FireOnSetListChanged();
       
   172     }
       
   173 
       
   174 void StfQtUIController::DeleteSet(const QString& setName)
       
   175     {
       
   176     executor->RemoveSet(setName);
       
   177     //executor->SaveSet(setName);
       
   178     FireOnSetListChanged();
       
   179     }
       
   180 
       
   181 void StfQtUIController::RunSets(const QString& setName, const TSTFCaseRunningType& type)
       
   182     {
       
   183     executor->ExecuteSet(setName, 0, type);
       
   184     }
       
   185 
       
   186 //for Started
       
   187 void StfQtUIController::PauseCase()
       
   188     {
       
   189     model->PauseCase();
       
   190     QString msg = "Execution Paused";
       
   191     FireOnGetOutput(msg);
       
   192     }
       
   193 
       
   194 void StfQtUIController::ResumeCase()
       
   195     {
       
   196     model->ResumeCase();
       
   197     FireOnGetOutput("Execution Resumed");
       
   198     }
       
   199 
       
   200 void StfQtUIController::AbortCase()
       
   201     {
       
   202     model->AbortCase();
       
   203     FireOnGetOutput("Case Aborted");
       
   204     }
       
   205 
       
   206 bool StfQtUIController::ShowOutput()
       
   207     {
       
   208     return isShowOutput;
       
   209     }
       
   210 
       
   211 void StfQtUIController::SetShowOutput(bool isShow)
       
   212     {
       
   213     isShowOutput = isShow;
       
   214     }
       
   215 
       
   216 QList<CSTFCase> StfQtUIController::GetCasesByStatus(const TSTFCaseStatusType& type)
       
   217     {
       
   218     return model->GetCasesByStatus(type);
       
   219     }
       
   220 
       
   221 void StfQtUIController::AddStfEventListener(IStfEventListener* listener)
       
   222     {
       
   223     if (!listenerList.contains(listener))
       
   224         {
       
   225         listenerList.append(listener);
       
   226         }
       
   227     }
       
   228 void StfQtUIController::RemoveStfEventListener(IStfEventListener* listener)
       
   229     {
       
   230     if (listenerList.contains(listener))
       
   231         {
       
   232         listenerList.removeOne(listener);
       
   233         }
       
   234     }
       
   235 
       
   236 void StfQtUIController::OnGetCaseUpdated(CStartedTestCase* aCase,
       
   237         CSTFCase& stfcase, int flags)
       
   238     {
       
   239     if (flags & CUIStoreIf::EPrintUpdate || aCase == NULL)
       
   240         {
       
   241         return;
       
   242         }
       
   243     QString msg = "case Name:";
       
   244     msg += stfcase.Name() + "\r\n Status:";
       
   245     flags = aCase->Status();
       
   246     if (flags & CUIStoreIf::EStatusRunning)
       
   247         {
       
   248         model->AddRunningCase(aCase, stfcase);
       
   249         msg += "start running";
       
   250         FireOnCaseOutputChanged(IStfEventListener::ECreate, (int) aCase,
       
   251                 stfcase.Name());
       
   252         }
       
   253     else if (flags & CUIStoreIf::EStatusAborted)
       
   254         {
       
   255         FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, "");
       
   256         model->RemoveRunningCase(aCase);
       
   257         model->AddCaseByStatus(EStatusAborted, stfcase);
       
   258         msg += "aborted";
       
   259 
       
   260         }
       
   261     else if (flags & CUIStoreIf::EStatusExecuted)
       
   262         {
       
   263         FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, "");
       
   264         model->RemoveRunningCase(aCase);
       
   265         model->AddCaseByStatus(EStatusExecuted, stfcase);
       
   266 
       
   267         if (flags & CUIStoreIf::EStatusCrashed)
       
   268             {
       
   269             model->AddCaseByStatus(EStatusCrashed, stfcase);
       
   270             msg += "crashed";
       
   271             }
       
   272         else if (flags & CUIStoreIf::EStatusFailed)
       
   273             {
       
   274             model->AddCaseByStatus(EStatusFailed, stfcase);
       
   275             msg += "failed";
       
   276             }
       
   277         else if (flags & CUIStoreIf::EStatusPassed)
       
   278             {
       
   279             model->AddCaseByStatus(EStatusPassed, stfcase);
       
   280             msg += "passed";
       
   281             }
       
   282 
       
   283         }
       
   284     else
       
   285         {
       
   286         return;
       
   287         }
       
   288 
       
   289     FireOnGetOutput(msg);
       
   290     }
       
   291 
       
   292 void StfQtUIController::OnGetCaseOutput(CStartedTestCase* aCase, QString& msg)
       
   293     {
       
   294     FireOnCaseOutputChanged(IStfEventListener::EOutput, (int) aCase, msg);
       
   295     }
       
   296 
       
   297 void StfQtUIController::FireOnCaseOutputChanged(
       
   298         IStfEventListener::CaseOutputCommand cmd, int index, QString msg)
       
   299     {
       
   300     if (ShowOutput())
       
   301         {
       
   302         foreach(IStfEventListener* listener, listenerList)
       
   303                 {
       
   304                 listener->OnCaseOutputChanged(cmd,
       
   305                         QString::number(index, 10), msg);
       
   306                 }
       
   307         }
       
   308     }
       
   309 
       
   310 void StfQtUIController::FireOnGetOutput(QString message)
       
   311     {
       
   312     foreach(IStfEventListener* listener, listenerList)
       
   313             {
       
   314             listener->OnGetMessage(message);
       
   315             }
       
   316     }
       
   317 
       
   318 void StfQtUIController::FireOnSetListChanged()
       
   319     {
       
   320     foreach(IStfEventListener* listener, listenerList)
       
   321             {
       
   322             listener->OnSetListChanged();
       
   323             }
       
   324     }