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