testexecfw/stf/stfext/testmodules/scriptermod/src/TestKeywords.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: This module contains the implementation of 
       
    15 * TTestKeywords class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "TestKeywords.h"
       
    22 
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 // None
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 // None
       
    28 
       
    29 // CONSTANTS
       
    30 // None
       
    31 
       
    32 // MACROS
       
    33 // None
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 // None
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 // None
       
    40 
       
    41 // LOCAL FUNCTION PROTOTYPES
       
    42 // None
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 // None
       
    46 
       
    47 // ==================== LOCAL FUNCTIONS =======================================
       
    48 // None
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =========================================
       
    51 
       
    52 /*
       
    53 -------------------------------------------------------------------------------
       
    54 
       
    55      Class: TTestKeywords
       
    56 
       
    57      Method: Keyword
       
    58 
       
    59      Description: Returns a string desrciptor corresponding to keyword number. 
       
    60 
       
    61      Parameters:    TInt aKeyword: in: keyword index.
       
    62      
       
    63      Return Values: TPtrC8: keyword descriptor
       
    64 
       
    65      Errors/Exceptions: None
       
    66      
       
    67      Status: Approved 
       
    68     
       
    69 -------------------------------------------------------------------------------
       
    70 */
       
    71 TPtrC TTestKeywords::Keyword( TInt aKeyword )
       
    72     {
       
    73     static TText* const keywords[] =
       
    74         {
       
    75         (TText*)L"title",
       
    76         (TText*)L"timeout",
       
    77         (TText*)L"priority",
       
    78         (TText*)L"create",
       
    79         (TText*)L"delete",
       
    80         (TText*)L"request",
       
    81         (TText*)L"wait",
       
    82         (TText*)L"release",
       
    83         (TText*)L"set",
       
    84         (TText*)L"unset",
       
    85         (TText*)L"print",
       
    86         (TText*)L"allownextresult",
       
    87         (TText*)L"waittestclass",
       
    88         (TText*)L"createkernel",
       
    89         (TText*)L"pause",
       
    90         (TText*)L"loop",
       
    91         (TText*)L"endloop",
       
    92         (TText*)L"oomignorefailure",
       
    93         (TText*)L"oomheapfailnext",
       
    94         (TText*)L"oomheapsetfail",
       
    95         (TText*)L"oomheaptonormal",
       
    96         (TText*)L"testinterference",
       
    97         (TText*)L"measurement",
       
    98         (TText*)L"allowerrorcodes",
       
    99         (TText*)L"bringtoforeground",
       
   100         (TText*)L"sendtobackground",
       
   101         (TText*)L"presskey",
       
   102         (TText*)L"typetext",        
       
   103         (TText*)L"var",
       
   104         (TText*)L"callsub",
       
   105         (TText*)L"createx",
       
   106         (TText*)L"setresultdescription",
       
   107         (TText*)L"sendpointerevent",
       
   108         (TText*)L"using",
       
   109         (TText*)L"expectedpanic",
       
   110         (TText*)L"createshareobj",
       
   111         (TText*)L"restoreshareobj",
       
   112         (TText*)L"deleteshareobj",
       
   113         (TText*)L"run",
       
   114         (TText*)L"complete",
       
   115         (TText*)L"canceliferror",
       
   116         (TText*)L"pausetest",
       
   117         (TText*)L"resume",
       
   118         (TText*)L"cancel",
       
   119         (TText*)L"allocate",
       
   120         (TText*)L"free",
       
   121         (TText*)L"remote",
       
   122         (TText*)L"sendreceive",        
       
   123         };
       
   124 
       
   125     if( (TUint)aKeyword >= (sizeof( keywords )/sizeof(TText*)) )
       
   126           {
       
   127           TPtrC null;
       
   128           return null;
       
   129           } 
       
   130 
       
   131     TPtrC keyword( keywords[ aKeyword ] ); 
       
   132     return keyword;
       
   133 
       
   134     }
       
   135 
       
   136 /*
       
   137 -------------------------------------------------------------------------------
       
   138 
       
   139      Class: TTestKeywords
       
   140 
       
   141      Method: Priority
       
   142 
       
   143      Description: Returns a string desrciptor corresponding to priority 
       
   144                     keywords optional argument number. 
       
   145 
       
   146      Parameters:   TInt aArg: in: argument index.
       
   147      
       
   148      Return Values: TPtrC8: keyword descriptor
       
   149 
       
   150      Errors/Exceptions: None
       
   151      
       
   152      Status: Draft 
       
   153     
       
   154 -------------------------------------------------------------------------------
       
   155 */
       
   156 TPtrC TTestKeywords::Priority( TInt aArg )
       
   157     {
       
   158     static TText* const priority[] =
       
   159         {
       
   160         (TText*)L"high",
       
   161         (TText*)L"normal",
       
   162         (TText*)L"low",
       
   163         };
       
   164 
       
   165     if( aArg >= (TInt)(sizeof( priority )/sizeof(TText*)) )
       
   166         {
       
   167         TPtrC null;
       
   168         return null;
       
   169         } 
       
   170 
       
   171     TPtrC arg( priority[ aArg ] ); 
       
   172     return arg;
       
   173     
       
   174     }
       
   175       
       
   176 /*
       
   177 -------------------------------------------------------------------------------
       
   178 
       
   179      Class: TTestKeywords
       
   180 
       
   181      Method: Parse
       
   182 
       
   183      Description: Returns a keyword enum corresponding to keyword 
       
   184                       string descriptor.
       
   185 
       
   186      Parameters:    TPtrC aKeyword: in: keyword descriptor.
       
   187                     KeywordFunc aFunc: in: Function pointer to keyword parser 
       
   188      
       
   189      Return Values: TInt: keyword index
       
   190 
       
   191      Errors/Exceptions: None
       
   192      
       
   193      Status: Draft 
       
   194     
       
   195 -------------------------------------------------------------------------------
       
   196 */
       
   197 TInt TTestKeywords::Parse( TDesC& aKeyword, KeywordFunc aFunc )
       
   198     {
       
   199     TInt ind;
       
   200     for( ind = 0; aFunc( ind ).Length() > 0; ind++ )
       
   201         {
       
   202         if( aFunc( ind ) == aKeyword )
       
   203             {
       
   204             return ind;
       
   205             }
       
   206         }
       
   207     return KErrNotFound;
       
   208     };
       
   209 
       
   210 /*
       
   211 -------------------------------------------------------------------------------
       
   212 
       
   213      Class: TTestKeywords
       
   214 
       
   215      Method: RunOptArg
       
   216 
       
   217      Description: Returns a string desrciptor corresponding to run keyword 
       
   218                   optional argument number. 
       
   219 
       
   220      Parameters:    TRunOptArgs aArg: in: run keyword optional argument index
       
   221      
       
   222      Return Values: TPtrC8: argument descriptor
       
   223 
       
   224      Errors/Exceptions: None
       
   225      
       
   226      Status: Approved 
       
   227     
       
   228 -------------------------------------------------------------------------------
       
   229 */
       
   230 TPtrC TTestKeywords::RunOptArg( TInt aArg )
       
   231     {
       
   232     static TText* const runOptArgs[] =
       
   233         {
       
   234         (TText*)L"expect",
       
   235         (TText*)L"testid",
       
   236         (TText*)L"ini",
       
   237         (TText*)L"category",
       
   238         (TText*)L"timeout",
       
   239         (TText*)L"title",
       
   240         };
       
   241 
       
   242     if( aArg >= (TInt)(sizeof( runOptArgs )/sizeof(TText*)) )
       
   243           {
       
   244           TPtrC null;
       
   245           return null;
       
   246           }
       
   247 
       
   248     TPtrC arg( runOptArgs[ aArg ] );
       
   249     return arg;    
       
   250     }
       
   251 
       
   252 /*
       
   253 -------------------------------------------------------------------------------
       
   254 
       
   255      Class: TTestKeywords
       
   256 
       
   257      Method: ResultCategory
       
   258 
       
   259      Description: Returns a string desrciptor corresponding to result 
       
   260         category number. 
       
   261 
       
   262      Parameters:    TInt aArg: in: argument index.
       
   263      
       
   264      Return Values: TPtrC: keyword descriptor
       
   265 
       
   266      Errors/Exceptions: None
       
   267      
       
   268      Status: Proposal
       
   269     
       
   270 -------------------------------------------------------------------------------
       
   271 */              
       
   272 TPtrC TTestKeywords::ResultCategory( TInt aArg )
       
   273     {
       
   274     static TText* const category[] =
       
   275         {
       
   276         (TText*)L"ongoing",
       
   277         (TText*)L"normal",
       
   278         (TText*)L"cancelled",
       
   279         (TText*)L"errorfrommodule",
       
   280         (TText*)L"leave",
       
   281         (TText*)L"panic",
       
   282         (TText*)L"exception",
       
   283         (TText*)L"timeout",
       
   284         };
       
   285         
       
   286     if( aArg >= (TInt)(sizeof( category )/sizeof(TText*)) )
       
   287         {
       
   288         TPtrC null;
       
   289         return null;
       
   290         } 
       
   291     
       
   292     TPtrC arg( category[ aArg ] ); 
       
   293     return arg;
       
   294     
       
   295     }
       
   296 
       
   297 /*
       
   298 -------------------------------------------------------------------------------
       
   299 
       
   300      Class: TTestKeywords
       
   301 
       
   302      Method: ResultCategory
       
   303 
       
   304      Description: Returns a string desrciptor corresponding to event keywords 
       
   305                       optional argument number. 
       
   306 
       
   307      Parameters:    TEventOptArgs aArg: in: argument index.
       
   308      
       
   309      Return Values: TPtrC8: keyword descriptor
       
   310 
       
   311      Errors/Exceptions: None
       
   312      
       
   313      Status: Proposal 
       
   314     
       
   315 -------------------------------------------------------------------------------
       
   316 */              
       
   317 TFullTestResult::TCaseExecutionResult TTestKeywords::GetResultCategory( TDesC& aCategory )
       
   318     {
       
   319     
       
   320     TInt ind;
       
   321     for( ind = 0; ResultCategory( ind ).Length() > 0; ind++ )
       
   322         {
       
   323         if( ResultCategory( ind ) == aCategory )
       
   324             {
       
   325             switch( ind )
       
   326                 {
       
   327                 case TFullTestResult::ECaseExecuted:
       
   328                 case TFullTestResult::ECaseLeave:
       
   329                 case TFullTestResult::ECasePanic:
       
   330                 case TFullTestResult::ECaseException:
       
   331                 case TFullTestResult::ECaseTimeout:
       
   332                     return (TFullTestResult::TCaseExecutionResult)ind;
       
   333                 default:
       
   334                     break;
       
   335                 }        
       
   336             }
       
   337         }      
       
   338     return TFullTestResult::ECaseOngoing;    
       
   339     }
       
   340 
       
   341 // ================= OTHER EXPORTED FUNCTIONS =================================
       
   342 // None
       
   343 
       
   344 // End of File