stif/QtUI/StifQtUI/test/testcontroller.cpp
branchRCL_3
changeset 9 8a14024f954a
equal deleted inserted replaced
8:ecff51f1e7fb 9:8a14024f954a
       
     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 *              Unit Test to StfQtUI's controller and model.
       
    16 *
       
    17 */
       
    18 #include "testcontroller.h"
       
    19 #include "stfqtuimodel.h"
       
    20 #include "stfqtuicontroller.h"
       
    21 #include "cstfcase.h"
       
    22 #include "cstfmodule.h"
       
    23 #include <QProcess>
       
    24 
       
    25 const QString KConfigFile1 = "c:\\STFQTUI_Test\\testframework1.ini";
       
    26 const QString KConfigFile2 = "c:\\STFQTUI_Test\\testframework2.ini";
       
    27 const QString KDefaultModuleName = "demomodule";
       
    28 const QString KDefaultSetName = "stfqtuitesting.set";
       
    29 
       
    30 testcontroller::testcontroller() 
       
    31     : OnSetListChangedFired(false),
       
    32             OnCaseStatisticChangedFired(false),
       
    33             OnRunningCaseChangedFired(false)
       
    34     {
       
    35     // TODO Auto-generated constructor stub
       
    36     model = new StfQtUIModel();
       
    37     model->AddStifModelEventListener(this);
       
    38     controller = new StfQtUIController(model);
       
    39     controller->AddStfEventListener(this);
       
    40     controller->OpenEngineIniFile(KConfigFile1);
       
    41     }
       
    42 
       
    43 testcontroller::~testcontroller()
       
    44     {
       
    45     // TODO Auto-generated destructor stub
       
    46     delete controller;
       
    47     delete model;
       
    48     }
       
    49 
       
    50 
       
    51 void testcontroller::T_GetModuleList_ModuleNumber()
       
    52     {
       
    53     controller->OpenEngineIniFile(KConfigFile1);
       
    54     int moduleSize = controller->GetModuleList().size();
       
    55     QCOMPARE(moduleSize, 1);
       
    56     }
       
    57 
       
    58 void testcontroller::T_GetModuleList_ModuleName()
       
    59     {
       
    60     controller->OpenEngineIniFile(KConfigFile1);
       
    61     QList<QString> moduleList = controller->GetModuleList();
       
    62     bool find = false;
       
    63     foreach(QString m, moduleList)
       
    64         {
       
    65         if(m.toLower() == KDefaultModuleName)
       
    66             {
       
    67             find = true;
       
    68             break;
       
    69             }
       
    70         }
       
    71     QCOMPARE(find, true);
       
    72     }
       
    73 
       
    74 void testcontroller::T_OpenEngineIniFile_ModuleNumber()
       
    75     {
       
    76     controller->OpenEngineIniFile(KConfigFile2);    
       
    77     int moduleSize = controller->GetModuleList().size();
       
    78     QCOMPARE(moduleSize, 2);
       
    79     }
       
    80 
       
    81 
       
    82 
       
    83 void testcontroller::T_OpenEngineIniFile()
       
    84     {
       
    85     bool rst;
       
    86     rst = controller->OpenEngineIniFile(KConfigFile2);
       
    87     QCOMPARE(rst, true);
       
    88     rst = controller->OpenEngineIniFile(KConfigFile1);    
       
    89     QCOMPARE(rst, true);
       
    90     rst = controller->OpenEngineIniFile(KConfigFile2);
       
    91     QCOMPARE(rst, true);
       
    92     rst = controller->OpenEngineIniFile("z:\\abc.ini");
       
    93     //QCOMPARE(rst, false);
       
    94     rst = controller->OpenEngineIniFile(KConfigFile1);    
       
    95     QCOMPARE(rst, true);                
       
    96     }
       
    97 
       
    98 void testcontroller::T_GetCaseListByModule()
       
    99     {
       
   100     controller->OpenEngineIniFile(KConfigFile1); 
       
   101     QList<QString> list = controller->GetCaseListByModule(KDefaultModuleName);
       
   102     QCOMPARE(list.size(), 6);
       
   103     list = controller->GetCaseListByModule("null");
       
   104     QCOMPARE(list.size(), 0);
       
   105     
       
   106     }
       
   107 void testcontroller::T_GetCase()
       
   108     {
       
   109     CSTFCase theCase = controller->GetCase(KDefaultModuleName, 1);
       
   110     QCOMPARE(theCase.Index(), 1);
       
   111     theCase = controller->GetCase(KDefaultModuleName, 21);    
       
   112     QCOMPARE(theCase.Index(), -1);
       
   113     QCOMPARE(theCase.Name(), QString(""));
       
   114     theCase = controller->GetCase("null", 0);
       
   115     QCOMPARE(theCase.Name(), QString(""));
       
   116     }
       
   117 
       
   118 void testcontroller::T_GetSetList()
       
   119     {
       
   120     OnSetListChangedFired = false;
       
   121     QList<QString> list = controller->GetSetList();
       
   122     bool find = false;
       
   123     foreach(QString set, list)
       
   124         {
       
   125         if(set == KDefaultSetName)
       
   126             {
       
   127             find = true;
       
   128             break;
       
   129             }
       
   130         }
       
   131     QCOMPARE(find, true);
       
   132     QCOMPARE(OnSetListChangedFired, false);//ensure SetListChanged does not be fired.
       
   133     }
       
   134 
       
   135 void testcontroller::T_GetCaseListBySet()
       
   136     {
       
   137     OnSetListChangedFired = false;
       
   138     QList<QString> list = controller->GetCaseListBySet(KDefaultSetName);
       
   139     QCOMPARE(list.size(),5);
       
   140     list = controller->GetCaseListBySet("null");
       
   141     QCOMPARE(list.size(),0);
       
   142     QCOMPARE(OnSetListChangedFired, false);//ensure SetListChanged does not be fired.
       
   143     }
       
   144 
       
   145 void testcontroller::T_AddCaseToSet()
       
   146     {
       
   147     OnSetListChangedFired = false;
       
   148     QList<QString> list = controller->GetSetList();
       
   149     int before_count = list.count();
       
   150     QList<CSTFCase> cases;
       
   151     QList<QString> caselist = controller->GetCaseListByModule(KDefaultModuleName);
       
   152     for(int i=0;i<caselist.size();i++)
       
   153         {
       
   154         CSTFCase theCase = controller->GetCase(KDefaultModuleName, i);
       
   155         cases.append(theCase);
       
   156         }
       
   157     controller->AddCaseToSet(cases, "test1");
       
   158     list = controller->GetSetList();    
       
   159     int after_count = list.count();
       
   160     QCOMPARE(before_count + 1, after_count);
       
   161     QCOMPARE(OnSetListChangedFired, true);
       
   162     }
       
   163 
       
   164 void testcontroller::T_CreateSet()
       
   165     {
       
   166     //tested object is still not implemented.
       
   167     }
       
   168 
       
   169 void testcontroller::T_DeleteSet()
       
   170     {
       
   171     //tested object is still not implemented.
       
   172     }
       
   173 
       
   174 void testcontroller::T_ShowOutput()
       
   175     {
       
   176     QCOMPARE(controller->ShowOutput(), false);
       
   177     controller->SetShowOutput(true);
       
   178     QCOMPARE(controller->ShowOutput(), true);
       
   179     controller->SetShowOutput(false);
       
   180     QCOMPARE(controller->ShowOutput(), false);     
       
   181     }
       
   182 
       
   183 void testcontroller::T_Model_ClearCasesStatus()
       
   184     {
       
   185     OnCaseStatisticChangedFired = false;
       
   186     model->ClearCasesStatus();
       
   187     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   188     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 0);
       
   189     QCOMPARE(model->GetCasesByStatus(EStatusPassed).size(), 0);
       
   190     QCOMPARE(model->GetCasesByStatus(EStatusFailed).size(), 0);
       
   191     QCOMPARE(model->GetCasesByStatus(EStatusAborted).size(), 0);
       
   192     QCOMPARE(model->GetCasesByStatus(EStatusCrashed).size(), 0);
       
   193     }
       
   194 
       
   195 void testcontroller::T_Model_AddRunningCase_RemoveRunningCase()
       
   196     {
       
   197     CStartedTestCase* startedCase = 0;
       
   198     CSTFCase aCase;
       
   199     OnRunningCaseChangedFired = false;
       
   200     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 0);
       
   201     model->AddRunningCase(startedCase, aCase);
       
   202     QCOMPARE(OnRunningCaseChangedFired, true);
       
   203     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 1);
       
   204     
       
   205     OnRunningCaseChangedFired = false;    
       
   206     model->RemoveRunningCase(startedCase);
       
   207     QCOMPARE(OnRunningCaseChangedFired, true);    
       
   208     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 0);    
       
   209     }
       
   210 
       
   211 void testcontroller::T_Model_AddCaseByStatus_GetCasesByStatus()
       
   212     {
       
   213     CSTFCase aCase;
       
   214     model->ClearCasesStatus();
       
   215     OnCaseStatisticChangedFired = false;
       
   216     
       
   217     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 0);
       
   218     model->AddCaseByStatus(EStatusExecuted,aCase);
       
   219     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   220     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 1);
       
   221     
       
   222     OnCaseStatisticChangedFired = false;
       
   223     QCOMPARE(model->GetCasesByStatus(EStatusPassed).size(), 0);
       
   224     model->AddCaseByStatus(EStatusPassed,aCase);    
       
   225     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   226     QCOMPARE(model->GetCasesByStatus(EStatusPassed).size(), 1);
       
   227 
       
   228     OnCaseStatisticChangedFired = false;
       
   229     QCOMPARE(model->GetCasesByStatus(EStatusFailed).size(), 0);
       
   230     model->AddCaseByStatus(EStatusFailed,aCase);    
       
   231     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   232     QCOMPARE(model->GetCasesByStatus(EStatusFailed).size(), 1);
       
   233 
       
   234     OnCaseStatisticChangedFired = false;
       
   235     QCOMPARE(model->GetCasesByStatus(EStatusAborted).size(), 0);
       
   236     model->AddCaseByStatus(EStatusAborted,aCase);    
       
   237     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   238     QCOMPARE(model->GetCasesByStatus(EStatusAborted).size(), 1);
       
   239 
       
   240     OnCaseStatisticChangedFired = false;
       
   241     QCOMPARE(model->GetCasesByStatus(EStatusCrashed).size(), 0);
       
   242     model->AddCaseByStatus(EStatusCrashed,aCase);    
       
   243     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   244     QCOMPARE(model->GetCasesByStatus(EStatusCrashed).size(), 1);
       
   245     
       
   246     model->ClearCasesStatus();
       
   247     
       
   248     }
       
   249 
       
   250 void testcontroller::T_RunCase()
       
   251     {
       
   252     model->ClearCasesStatus();
       
   253     OnCaseStatisticChangedFired = false;
       
   254     OnRunningCaseChangedFired = false;
       
   255     controller->OpenEngineIniFile(KConfigFile1); 
       
   256     QList<CSTFCase> caseList;
       
   257     caseList.append(controller->GetCase(KDefaultModuleName,2));//math test
       
   258     controller->RunCases(caseList, Sequentially);
       
   259     QTest::qWait(2000);
       
   260     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   261     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 0);
       
   262     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 1);
       
   263     QCOMPARE(model->GetCasesByStatus(EStatusPassed).size(), 1);
       
   264     
       
   265     model->ClearCasesStatus();
       
   266     }
       
   267      
       
   268      
       
   269 void testcontroller::T_RunSet()
       
   270     {
       
   271     model->ClearCasesStatus();
       
   272     //controller->OpenEngineIniFile(KConfigFile1); 
       
   273     QList<QString> list = controller->GetCaseListBySet(KDefaultSetName);    
       
   274     QCOMPARE(list.size(),5);
       
   275     controller->RunSets(KDefaultSetName,Parallel);
       
   276     QTest::qWait(20000);
       
   277     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 5);
       
   278     QCOMPARE(model->GetCasesByStatus(EStatusPassed).size(), 4);
       
   279     QCOMPARE(model->GetCasesByStatus(EStatusFailed).size(), 0);
       
   280     QCOMPARE(model->GetCasesByStatus(EStatusAborted).size(), 0);
       
   281     QCOMPARE(model->GetCasesByStatus(EStatusCrashed).size(), 1);
       
   282     model->ClearCasesStatus();    
       
   283     }
       
   284      
       
   285      
       
   286 void testcontroller::T_PauseCase_ResumeCase()
       
   287     {
       
   288     model->ClearCasesStatus();
       
   289     OnCaseStatisticChangedFired = false;
       
   290     OnRunningCaseChangedFired = false;
       
   291     controller->OpenEngineIniFile(KConfigFile1); 
       
   292     QList<CSTFCase> caseList;
       
   293     caseList.append(controller->GetCase(KDefaultModuleName,0));  //loop test
       
   294     controller->RunCases(caseList, Sequentially);
       
   295     QTest::qWait(500);
       
   296     QCOMPARE(OnRunningCaseChangedFired, true);
       
   297     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 1);
       
   298     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 0);
       
   299     controller->PauseCase();
       
   300     QTest::qWait(15000);
       
   301     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 1);
       
   302     controller->ResumeCase();
       
   303     QTest::qWait(15000);
       
   304     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   305     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 0);
       
   306     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 1);
       
   307     QCOMPARE(model->GetCasesByStatus(EStatusPassed).size(), 1);
       
   308     
       
   309     }
       
   310      
       
   311 void testcontroller::T_AbortCase()
       
   312     {
       
   313     model->ClearCasesStatus();
       
   314     OnCaseStatisticChangedFired = false;
       
   315     OnRunningCaseChangedFired = false;
       
   316     controller->OpenEngineIniFile(KConfigFile1); 
       
   317     QList<CSTFCase> caseList;
       
   318     caseList.append(controller->GetCase(KDefaultModuleName,0));  //loop test
       
   319     controller->RunCases(caseList, Sequentially);
       
   320     QTest::qWait(500);
       
   321     QCOMPARE(OnRunningCaseChangedFired, true);
       
   322     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 1);
       
   323     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 0);
       
   324     controller->AbortCase();
       
   325     QTest::qWait(1000);
       
   326     QCOMPARE(OnCaseStatisticChangedFired, true);
       
   327     QCOMPARE(model->GetCasesByStatus(EStatusRunning).size(), 0);
       
   328     QCOMPARE(model->GetCasesByStatus(EStatusExecuted).size(), 0);
       
   329     QCOMPARE(model->GetCasesByStatus(EStatusAborted).size(), 1);
       
   330     }
       
   331 
       
   332 
       
   333 //===========================================================
       
   334 void testcontroller::OnSetListChanged()
       
   335     {
       
   336     OnSetListChangedFired = true;
       
   337     }
       
   338 
       
   339 void testcontroller::OnCaseStatisticChanged()
       
   340     {
       
   341     OnCaseStatisticChangedFired = true;
       
   342     }
       
   343 
       
   344 void testcontroller::OnRunningCaseChanged()
       
   345     {
       
   346     OnRunningCaseChangedFired = true;
       
   347     }
       
   348 
       
   349 void testcontroller::OnGetMessage(const QString& /*aMessage*/)
       
   350     {
       
   351     //nothing.
       
   352     }
       
   353 
       
   354 void testcontroller::OnCaseOutputChanged(const CaseOutputCommand& /*cmd*/,
       
   355         const QString& , const QString&)
       
   356     {}
       
   357