testdev/ite/src/com.nokia.testfw.testrunner/src/com/nokia/testfw/testrunner/SymbianUnitTestCommandLineParser.java
changeset 1 96906a986c3b
equal deleted inserted replaced
0:f1112f777ce9 1:96906a986c3b
       
     1 /*
       
     2 * Copyright (c) 2005 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:  A tool that parse command line parser.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.testfw.testrunner;
       
    20 
       
    21 public class SymbianUnitTestCommandLineParser {
       
    22 	
       
    23 	public static final String TEST_CASE_KEY = "-cases=";
       
    24 	public static final String TEST_CASE_KEY_SHORT = "-c=";
       
    25 	public static final String TESTS_KEY = "-tests=";
       
    26 	public static final String TESTS_KEY_SHORT = "-t=";
       
    27 	public static final String EPOC_ROOT = "-epocroot=";
       
    28 	public static final String EPOC_ROOT_SHORT = "-e=";
       
    29 	public static final String ALLOC_KEY = "-alloc";
       
    30 	public static final String ALLOC_KEY_SHORT = "-a";
       
    31 	public static final String OUTPUT_KEY = "-output=";
       
    32 	public static final String OUTPUT_KEY_SHORT = "-o=";
       
    33 //	public static final String NO_PROMPT_KEY = "-noprompt";
       
    34 	public static final String TIMEOUT_KEY = "-timeout=";
       
    35 	public static final String TIMEOUT_KEY_SHORT = "-to=";
       
    36 	public static final String DEFAULT_OUTPUT_FORMAT = "html";
       
    37 	public static final String OUTPUT_FILE_NAME = "SymbianUnitTestResults";
       
    38 	public static final String DEVICE_KEY = "-device";
       
    39 	public static final String DEVICE_KEY_SHORT = "-d";
       
    40 	
       
    41 	public static final int SYMBIAN_UNIT_TEST_DEFAULT_TIMEOUT = 30;
       
    42 	
       
    43 	public static String findArgument(String[] arguments, String key, String shortKey) {
       
    44 		boolean found = false;
       
    45 		String value = null;
       
    46 		
       
    47 		if (arguments == null)
       
    48 			throw new NullPointerException();
       
    49 		
       
    50 		for (int i = 0; i < arguments.length; ++i) {
       
    51 			if (arguments[i].compareTo(key) == 0 || arguments[i].compareTo(shortKey) == 0) {
       
    52 				int equalsPos = arguments[i].indexOf('=');
       
    53 				if (equalsPos > 0 & equalsPos < arguments[i].length() - 1) {
       
    54 					value = arguments[i].substring(equalsPos + 1);
       
    55 					found = true;
       
    56 				}
       
    57 			}
       
    58 		}
       
    59 		return found? value : null;
       
    60 	}
       
    61 	
       
    62 	public static boolean hasArgument(String[] arguments, String key, String shortKey){
       
    63 		boolean found = false;
       
    64 		for (int i = 0; i < arguments.length; ++i){
       
    65 			if (arguments[i].compareTo(key) == 0 || arguments[i].compareTo(shortKey) == 0){
       
    66 				found = true;
       
    67 			}
       
    68 		}
       
    69 		return found;
       
    70 	}
       
    71 
       
    72 	public static String[] getTestCaseNames(String[] arguments){
       
    73 			return findArgument(arguments, TEST_CASE_KEY, TEST_CASE_KEY_SHORT).split(",");
       
    74 	}
       
    75 	
       
    76 	public static String[] getTestDllNames(String[] arguments){
       
    77 		return findArgument(arguments, TESTS_KEY, TESTS_KEY_SHORT).split(",");
       
    78 	}
       
    79 	
       
    80 	public static int getTimeout(String[] arguments) {
       
    81 		String timeOut = findArgument(arguments, TIMEOUT_KEY, TIMEOUT_KEY_SHORT);
       
    82 		if (timeOut == null)
       
    83 			return SYMBIAN_UNIT_TEST_DEFAULT_TIMEOUT;
       
    84 		else
       
    85 			return Integer.parseInt(timeOut);
       
    86 	}
       
    87 	
       
    88 	public static String getOutputFormat(String[] arguments){
       
    89 		String outputFormat = findArgument(arguments, OUTPUT_KEY, OUTPUT_KEY_SHORT);
       
    90 		if (outputFormat == null)
       
    91 			outputFormat = DEFAULT_OUTPUT_FORMAT;
       
    92 		return outputFormat;
       
    93 	}
       
    94 	
       
    95 	public static String getOutputFileName(){
       
    96 		return OUTPUT_FILE_NAME;
       
    97 	}
       
    98 	
       
    99 	public static boolean getMemoryAllocationFailureSimulation(String[] arguments){
       
   100 		return hasArgument(arguments, ALLOC_KEY, ALLOC_KEY_SHORT);
       
   101 	}
       
   102 
       
   103 	public static String getEpocRoot(String[] arguments){
       
   104 		return findArgument(arguments, EPOC_ROOT, EPOC_ROOT_SHORT);
       
   105 	}
       
   106 
       
   107 	public static boolean getRunOnDevice(String[] arguments){
       
   108 		return hasArgument(arguments, DEVICE_KEY, DEVICE_KEY_SHORT);
       
   109 	}
       
   110 }