testexecfw/stf/stfui/stf/src/cmdparser.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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: 
       
    15 *
       
    16 */
       
    17 #include "cmdparser.h"
       
    18 #include <StifTestInterface.h>
       
    19 
       
    20 
       
    21 _LIT( KTestModule, "-m" );
       
    22 _LIT( KConfigFile, "-s" );
       
    23 _LIT( KEngineIniFile, "-i" );
       
    24 _LIT( KModuleIniFile, "-c" );
       
    25 _LIT( KEngineConfigurationItem, "-engine" );
       
    26 _LIT( KLogConfigurationItem, "-log" );
       
    27 _LIT( KVersion1, "-v" );
       
    28 _LIT( KVersion2, "-version" );
       
    29 _LIT( KHelp1, "-?" );
       
    30 _LIT( KHelp2, "-h" );
       
    31 _LIT( KHelp3, "-help" );
       
    32 _LIT( KNoPrompt, "-NOPROMPT");
       
    33 _LIT( KDefaultEngineIni, "c:\\TestFramework\\TestFramework.ini" );
       
    34 
       
    35 
       
    36 
       
    37 
       
    38 CCmdParser::CCmdParser() : iIsHelp(EFalse), iIsVersion(EFalse), iIsPrompt(ETrue)
       
    39     {
       
    40     iEngineIniFile.Zero();
       
    41     iModuleIniFile.Zero();
       
    42     iConfigFile.Zero();
       
    43     iTestModule.Zero();
       
    44     iTestCase.Zero();
       
    45     
       
    46     }
       
    47 
       
    48 CCmdParser::~CCmdParser()
       
    49     {
       
    50     iTestCaseList.Close();
       
    51     iTestCaseIndexList.Close();
       
    52        
       
    53     }
       
    54 
       
    55 CCmdParser* CCmdParser::NewL()
       
    56     {
       
    57     CCmdParser* self = new(ELeave)CCmdParser();
       
    58     return self;
       
    59     }
       
    60 
       
    61 TBool CCmdParser::Parse(TPtr& commandLine)
       
    62     {
       
    63     TBool rst(ETrue);
       
    64     TBool findmodule(EFalse);
       
    65     TLex lex(commandLine);
       
    66     TBufC<1> comma(_L("\""));
       
    67     TBool continueName(EFalse); //parse case name, when count \" need continue read name.
       
    68     while ( !lex.Eos() )
       
    69         {
       
    70         TPtrC tmpPtr = lex.NextToken();
       
    71         if(tmpPtr == KTestModule)
       
    72             {
       
    73             TPtrC module = lex.NextToken();
       
    74             if(module.Ptr())
       
    75                 {
       
    76                 iTestModule.Copy(module);
       
    77                 if(iTestModule != _L(""))
       
    78                     {
       
    79                     findmodule = ETrue;    
       
    80                     }
       
    81                 }
       
    82             else
       
    83                 {
       
    84                 rst = EFalse;
       
    85                 break;
       
    86                 }
       
    87             }
       
    88         else if(tmpPtr == KConfigFile)
       
    89             {
       
    90             TPtrC config = lex.NextToken();
       
    91             if(config.Ptr())
       
    92                 {
       
    93                 //iTestModule.Copy(_L("testscripter"));//mark here.
       
    94                 iConfigFile.Copy(config);
       
    95                 TStifUtil::CorrectFilePathL(iConfigFile);
       
    96                 if(iConfigFile != _L(""))
       
    97                     {
       
    98                     findmodule = ETrue;    
       
    99                     }
       
   100                 }
       
   101             else
       
   102                 {
       
   103                 rst = EFalse;
       
   104                 break;
       
   105                 }
       
   106             }
       
   107         else if(tmpPtr == KEngineIniFile)
       
   108             {
       
   109             TPtrC iniFile = lex.NextToken();
       
   110             if(iniFile.Ptr())
       
   111                 {
       
   112                 iEngineIniFile.Copy(iniFile);
       
   113                 TStifUtil::CorrectFilePathL(iEngineIniFile);
       
   114                 }
       
   115             else
       
   116                 {
       
   117                 rst = EFalse;                
       
   118                 break;
       
   119                 }
       
   120             }
       
   121         else if(tmpPtr == KModuleIniFile)
       
   122             {
       
   123             TPtrC iniFile = lex.NextToken();
       
   124             if(iniFile.Ptr())
       
   125                 {
       
   126                 iModuleIniFile.Copy(iniFile);
       
   127                 TStifUtil::CorrectFilePathL(iModuleIniFile);
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 rst = EFalse;
       
   132                 break;
       
   133                 }
       
   134             }
       
   135        
       
   136         else if(tmpPtr == KEngineConfigurationItem)
       
   137             {
       
   138             TName pname=lex.NextToken();
       
   139             
       
   140             if(pname.Length() > 0)
       
   141                 {
       
   142                 TPtrC pval = lex.NextToken();            
       
   143                 if(pval.Ptr())
       
   144                     {
       
   145                     
       
   146                     iEngineConfigList.Append(pname);
       
   147                     iEngineConfigList.Append(_L(" "));
       
   148                     iEngineConfigList.Append(pval);
       
   149                     iEngineConfigList.Append(_L(" "));
       
   150                     
       
   151                     }
       
   152                 else
       
   153                     {
       
   154                     rst = EFalse;
       
   155                     break;
       
   156                     }
       
   157                 }
       
   158             else
       
   159                 {
       
   160                 rst = EFalse;
       
   161                 break;
       
   162                 }
       
   163             }
       
   164         else if(tmpPtr == KLogConfigurationItem)
       
   165             {
       
   166             TName pname=lex.NextToken();
       
   167             if(pname.Length() > 0)
       
   168                 {
       
   169                 TPtrC pval = lex.NextToken();            
       
   170                 if(pval.Ptr())
       
   171                     {
       
   172                     
       
   173                     iLogConfigList.Append(pname);
       
   174                     iLogConfigList.Append(_L(" "));
       
   175                     iLogConfigList.Append(pval);
       
   176                     iLogConfigList.Append(_L(" "));
       
   177                     }
       
   178                 else
       
   179                     {
       
   180                     rst = EFalse;
       
   181                     break;
       
   182                     }
       
   183                 }
       
   184             else
       
   185                 {
       
   186                 rst = EFalse;
       
   187                 break;
       
   188                 }
       
   189             
       
   190             }
       
   191         else if(tmpPtr == KVersion1 || tmpPtr == KVersion2)
       
   192             {
       
   193             iIsVersion = true;
       
   194             rst = ETrue;
       
   195             break;            
       
   196             }
       
   197         else if(tmpPtr == KHelp1 || tmpPtr == KHelp2 || tmpPtr == KHelp3)
       
   198             {
       
   199             iIsHelp = true;
       
   200             rst = ETrue;
       
   201             break;
       
   202             }
       
   203         else if(tmpPtr == KNoPrompt)
       
   204             {
       
   205             iIsPrompt = false;
       
   206             }
       
   207         else
       
   208             {
       
   209             if(!tmpPtr.Left(1).Compare(comma))
       
   210                 {
       
   211                 continueName = ETrue;
       
   212                 iTestCase.Copy(tmpPtr);
       
   213                 }
       
   214             else
       
   215                 {
       
   216                 if(continueName)
       
   217                     {
       
   218                     iTestCase.Append(_L(" "));
       
   219                     iTestCase.Append(tmpPtr);
       
   220                     }
       
   221                 else
       
   222                     {
       
   223                     //is a number without "\""
       
   224                     if(IsNumber(tmpPtr))
       
   225                         {
       
   226                         TLex myLex(tmpPtr);
       
   227                         myLex.Val(iTestCaseIndex);  
       
   228                         iTestCaseIndexList.Append(iTestCaseIndex);
       
   229                         continue;
       
   230                         }
       
   231                     else
       
   232                         {
       
   233                         iTestCase.Copy(tmpPtr);                    
       
   234                         }
       
   235                     
       
   236                     }
       
   237                 }
       
   238             
       
   239 
       
   240             
       
   241             if(!iTestCase.Right(1).Compare(comma))
       
   242                 {
       
   243                 if(continueName)
       
   244                     {
       
   245                     iTestCase.Copy(iTestCase.Mid(1, iTestCase.Length() -2));
       
   246                     iTestCaseList.Append(iTestCase);
       
   247                     }
       
   248                 //error input.
       
   249                 iTestCase.Copy(_L(""));
       
   250                 continueName = EFalse;
       
   251                 }
       
   252             else
       
   253                 {
       
   254                 if(!continueName)
       
   255                     {
       
   256                     iTestCaseList.Append(iTestCase);
       
   257                     iTestCase.Copy(_L(""));
       
   258                     }
       
   259                 }
       
   260             
       
   261 
       
   262             }
       
   263         }//end while
       
   264     if(iConfigFile.Length() != 0 && iTestModule.Length() == 0)
       
   265         {
       
   266         iTestModule.Copy(_L("testscripter"));
       
   267         }
       
   268     if(iEngineIniFile.Length()==0)
       
   269         {
       
   270         iEngineIniFile.Append(KDefaultEngineIni);
       
   271         }
       
   272     return (rst && findmodule);
       
   273     }
       
   274 
       
   275 
       
   276 TBool CCmdParser::CaseContains(TInt index, TDesC& caseName)
       
   277     {
       
   278     //RArray<TName> iTestCaseList;
       
   279     //RArray<TInt> iTestCaseIndexList;
       
   280     TInt size = iTestCaseIndexList.Count();
       
   281     for(TInt i=0;i<size; i++)
       
   282         {
       
   283         if(iTestCaseIndexList[i] == index)
       
   284             {
       
   285             return ETrue;
       
   286             }
       
   287         }
       
   288     size = iTestCaseList.Count();
       
   289     for(TInt i=0;i<size;i++)
       
   290         {
       
   291         if(!iTestCaseList[i].Compare(caseName))
       
   292             {
       
   293             return ETrue;
       
   294             }
       
   295         }
       
   296     return EFalse;
       
   297     }
       
   298 
       
   299 TBool CCmdParser::IsNumber(const TDesC & aDes)
       
   300     {
       
   301     TBuf<2> tempChar;
       
   302     for (TInt i=0;i<aDes.Length();i++)
       
   303         {
       
   304         tempChar.Zero();
       
   305         tempChar.Append(aDes.Mid(i,1));
       
   306         TLex myLex(tempChar);
       
   307         TInt32 model;
       
   308         if (myLex.Val(model))
       
   309             {
       
   310             return  EFalse;
       
   311             }
       
   312     }
       
   313     return ETrue;
       
   314     }
       
   315