stifui/qt/src/stfqtuicontroller.cpp
branchGCC_SURGE
changeset 37 c20154ccf3c0
parent 35 98924d2efce9
equal deleted inserted replaced
20:ba8a586c45f1 37:c20154ccf3c0
    16  *
    16  *
    17  */
    17  */
    18 #include "stfqtuicontroller.h"
    18 #include "stfqtuicontroller.h"
    19 #include <stifinternal/UIStoreIf.h>
    19 #include <stifinternal/UIStoreIf.h>
    20 #include <stifinternal/UIStoreContainer.h>
    20 #include <stifinternal/UIStoreContainer.h>
    21 //#include "stiflogger.h"
       
    22 #include <QDateTime>
    21 #include <QDateTime>
    23 
    22 
    24 const QString TEMPSETNAME = "TEMPSET";
    23 const QString TEMPSETNAME = "TEMPSET";
    25 const QString DEFAULTINI = "c:\\testframework\\testframework.ini";
    24 const QString DEFAULTINI = "c:\\testframework\\testframework.ini";
    26 
    25 
    27 //__DECLARE_LOG
    26 
    28 
    27 
    29 StfQtUIController::StfQtUIController(IStfQtUIModel* aModel) :
    28 StfQtUIController::StfQtUIController(IStfQtUIModel* aModel) :
    30     model(aModel), isShowOutput(false)
    29     model(aModel), 
    31     {
    30     isShowOutput(false), 
    32 //    __OPENLOGL ("\\STFQtUI\\", "StifQtUi.log" );
    31     iCurrentRunPos(0),
       
    32     isLoopInfinitely(false),
       
    33     loopTimes(0)
       
    34        
       
    35     {
    33     executor = new CStifExecutor();
    36     executor = new CStifExecutor();
    34     executor->OpenIniFile(DEFAULTINI);
    37     executor->OpenIniFile(DEFAULTINI);
    35     executor->AddStifCaseUpdateListener(this);
    38     executor->AddStifCaseUpdateListener(this);
    36     }
    39     }
    37 
    40 
    38 StfQtUIController::~StfQtUIController()
    41 StfQtUIController::~StfQtUIController()
    39     {
    42     {
    40     executor->RemoveStifCaseUpdateListener(this);
    43     executor->RemoveStifCaseUpdateListener(this);
    41     delete executor;
    44     delete executor;
    42     executor = NULL;
    45     executor = NULL;
    43 //    __CLOSELOG;
       
    44     }
    46     }
    45 //for cases
    47 //for cases
    46 
    48 
    47 bool StfQtUIController::OpenEngineIniFile(const QString& fileName)
    49 bool StfQtUIController::OpenEngineIniFile(const QString& fileName)
    48     {
    50     {
       
    51     QString path = fileName;
       
    52     if(path.contains('/'))
       
    53         {
       
    54         path = path.replace('/', '\\');
       
    55         }
       
    56     executor->RemoveStifCaseUpdateListener(this);
    49     delete executor;
    57     delete executor;
    50     executor = new CStifExecutor();
    58     executor = new CStifExecutor();
    51     bool rst = executor->OpenIniFile(fileName);
    59     bool rst = executor->OpenIniFile(path);
    52     executor->AddStifCaseUpdateListener(this);
    60     executor->AddStifCaseUpdateListener(this);
    53     return rst;
    61     return rst;
    54     }
    62     }
    55 
    63 
    56 QList<QString> StfQtUIController::GetModuleList()
    64 QList<QString> StfQtUIController::GetModuleList()
   130         RunSets(TEMPSETNAME, type);
   138         RunSets(TEMPSETNAME, type);
   131         executor->RemoveSet(TEMPSETNAME);
   139         executor->RemoveSet(TEMPSETNAME);
   132         }
   140         }
   133     }
   141     }
   134 
   142 
   135 void StfQtUIController::AddCaseToSet(const QList<CSTFCase>& caseList,
   143 // run cases repeatly. 
   136         const QString& /*setName*/)
   144 // By default, loopTimes = -1 means loop infinitely util user stop it.
   137     {
   145 void StfQtUIController::RepeatRunCases(const QList<CSTFCase>& aCaseList, const bool aIsLoopInfinitely, const int aLoopTimes)
   138     QString setName = QDateTime::currentDateTime().toString("hh_mm_ss");
   146     {
   139     setName.append(".set");
   147     InitRepeatSetting(aIsLoopInfinitely, aLoopTimes);
   140     executor->CreateSet(setName);
   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;
   141     foreach(CSTFCase aCase, caseList)
   193     foreach(CSTFCase aCase, caseList)
   142             {
   194             {
   143             executor->AddtoSet(setName, aCase);
   195             rst = executor->AddtoSet(name, aCase);
   144             }
   196             if(!rst)
   145     executor->SaveSet(setName);
   197                 {
   146     executor->RemoveSet(setName);
   198                 break;
       
   199                 }
       
   200             }
       
   201     if(!rst)
       
   202         {
       
   203         return false;
       
   204         }
       
   205     rst = executor->SaveSet(name);
   147     FireOnSetListChanged();
   206     FireOnSetListChanged();
       
   207     return rst;
   148     }
   208     }
   149 
   209 
   150 //for set
   210 //for set
   151 
   211 
   152 QList<QString> StfQtUIController::GetSetList()
   212 QList<QString> StfQtUIController::GetSetList()
   162             caseList.append(c.Name());
   222             caseList.append(c.Name());
   163             }
   223             }
   164     return caseList;
   224     return caseList;
   165     }
   225     }
   166 
   226 
   167 void StfQtUIController::CreateSet(const QString& setName)
   227 bool StfQtUIController::CreateSet(QString& setName)
   168     {
   228     {
   169     executor->CreateSet(setName);
   229     bool rst = executor->CreateSet(setName);
   170     //executor->SaveSet(setName);
   230     if(!rst)
       
   231         {
       
   232         return rst;
       
   233         }
       
   234     rst = executor->SaveSet(setName);
   171     FireOnSetListChanged();
   235     FireOnSetListChanged();
   172     }
   236     return rst;
   173 
   237     }
   174 void StfQtUIController::DeleteSet(const QString& setName)
   238 
   175     {
   239 bool StfQtUIController::DeleteSet(const QString& setName)
   176     executor->RemoveSet(setName);
   240     {
   177     //executor->SaveSet(setName);
   241     bool rst = executor->RemoveSet(setName);
       
   242     if(!rst)
       
   243         {
       
   244         return false;
       
   245         }
       
   246     QString name = setName;
       
   247     rst = executor->SaveSet(name);
   178     FireOnSetListChanged();
   248     FireOnSetListChanged();
       
   249     return rst;
   179     }
   250     }
   180 
   251 
   181 void StfQtUIController::RunSets(const QString& setName, const TSTFCaseRunningType& type)
   252 void StfQtUIController::RunSets(const QString& setName, const TSTFCaseRunningType& type)
   182     {
   253     {
   183     executor->ExecuteSet(setName, 0, type);
   254     executor->ExecuteSet(setName, 0, type);
   199 
   270 
   200 void StfQtUIController::AbortCase()
   271 void StfQtUIController::AbortCase()
   201     {
   272     {
   202     model->AbortCase();
   273     model->AbortCase();
   203     FireOnGetOutput("Case Aborted");
   274     FireOnGetOutput("Case Aborted");
       
   275     }
       
   276 
       
   277 CSTFCase StfQtUIController::GetRunningCase(int index)
       
   278     {
       
   279     CStartedTestCase* startedCase = (CStartedTestCase*) index;
       
   280     return model->GetRunningCase(startedCase);
   204     }
   281     }
   205 
   282 
   206 bool StfQtUIController::ShowOutput()
   283 bool StfQtUIController::ShowOutput()
   207     {
   284     {
   208     return isShowOutput;
   285     return isShowOutput;
   254         {
   331         {
   255         FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, "");
   332         FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, "");
   256         model->RemoveRunningCase(aCase);
   333         model->RemoveRunningCase(aCase);
   257         model->AddCaseByStatus(EStatusAborted, stfcase);
   334         model->AddCaseByStatus(EStatusAborted, stfcase);
   258         msg += "aborted";
   335         msg += "aborted";
       
   336         
       
   337         //reset repeat execution information
       
   338         ResetRepeatSetting();
   259 
   339 
   260         }
   340         }
   261     else if (flags & CUIStoreIf::EStatusExecuted)
   341     else if (flags & CUIStoreIf::EStatusExecuted)
   262         {
   342         {
   263         FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, "");
   343         FireOnCaseOutputChanged(IStfEventListener::EClose, (int) aCase, "");
   277         else if (flags & CUIStoreIf::EStatusPassed)
   357         else if (flags & CUIStoreIf::EStatusPassed)
   278             {
   358             {
   279             model->AddCaseByStatus(EStatusPassed, stfcase);
   359             model->AddCaseByStatus(EStatusPassed, stfcase);
   280             msg += "passed";
   360             msg += "passed";
   281             }
   361             }
   282 
   362         
       
   363         // if repeat execution is choosed, start to execution again.
       
   364         if(loopTimes > 0 || isLoopInfinitely)
       
   365             {
       
   366             Execution();
       
   367             }
   283         }
   368         }
   284     else
   369     else
   285         {
   370         {
   286         return;
   371         return;
   287         }
   372         }
   295     }
   380     }
   296 
   381 
   297 void StfQtUIController::FireOnCaseOutputChanged(
   382 void StfQtUIController::FireOnCaseOutputChanged(
   298         IStfEventListener::CaseOutputCommand cmd, int index, QString msg)
   383         IStfEventListener::CaseOutputCommand cmd, int index, QString msg)
   299     {
   384     {
   300     if (ShowOutput())
   385     if (true)//ShowOutput
   301         {
   386         {
   302         foreach(IStfEventListener* listener, listenerList)
   387         foreach(IStfEventListener* listener, listenerList)
   303                 {
   388                 {
   304                 listener->OnCaseOutputChanged(cmd,
   389                 listener->OnCaseOutputChanged(cmd,
   305                         QString::number(index, 10), msg);
   390                         QString::number(index, 10), msg);
   320     foreach(IStfEventListener* listener, listenerList)
   405     foreach(IStfEventListener* listener, listenerList)
   321             {
   406             {
   322             listener->OnSetListChanged();
   407             listener->OnSetListChanged();
   323             }
   408             }
   324     }
   409     }
       
   410 
       
   411 // End of File