visualtest/src/harness_argparser.c
/* parser an argument, updates the state object and returns the number of
   arguments processed; returns -1 on failure */
parser an argument, updates the state object and returns the number of
arguments processed; returns -1 on failure
parser an argument updates the state object and returns the number of arguments processed ; returns - 1 on failure
static int
ParseArg(char** argv, int index, SDLVisualTest_HarnessState* state)
{
    if(!argv || !argv[index] || !state)
        return 0;
    if(StrCaseCmpIgnoreHyphen("sutapp", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for sutapp.");
            return -1;
        }
        SDL_strlcpy(state->sutapp, argv[index], MAX_PATH_LEN);
        SDLTest_Log("SUT Application: %s", state->sutapp);
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("output-dir", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for output-dir.");
            return -1;
        }
        SDL_strlcpy(state->output_dir, argv[index], MAX_PATH_LEN);
        SDLTest_Log("Screenshot Output Directory: %s", state->output_dir);
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("verify-dir", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for verify-dir.");
            return -1;
        }
        SDL_strlcpy(state->verify_dir, argv[index], MAX_PATH_LEN);
        SDLTest_Log("Screenshot Verification Directory: %s", state->verify_dir);
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("sutargs", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for sutargs.");
            return -1;
        }
        SDL_strlcpy(state->sutargs, argv[index], MAX_SUT_ARGS_LEN);
        SDLTest_Log("SUT Arguments: %s", state->sutargs);
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("timeout", argv[index]) == 0)
    {
        int hr, min, sec;
        index++;
        if(!argv[index] || SDL_sscanf(argv[index], "%d:%d:%d", &hr, &min, &sec) != 3)
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for timeout.");
            return -1;
        }
        state->timeout = (((hr * 60) + min) * 60 + sec) * 1000;
        SDLTest_Log("Maximum Timeout for each SUT run: %d milliseconds",
                    state->timeout);
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("parameter-config", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for parameter-config.");
            return -1;
        }
        SDLTest_Log("SUT Parameters file: %s", argv[index]);
        SDLVisualTest_FreeSUTConfig(&state->sut_config);
        if(!SDLVisualTest_ParseSUTConfig(argv[index], &state->sut_config))
        {
            SDLTest_LogError("Failed to parse SUT parameters file");
            return -1;
        }
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("variator", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for variator.");
            return -1;
        }
        SDLTest_Log("Variator: %s", argv[index]);
        if(SDL_strcasecmp("exhaustive", argv[index]) == 0)
            state->variator_type = SDL_VARIATOR_EXHAUSTIVE;
        else if(SDL_strcasecmp("random", argv[index]) == 0)
            state->variator_type = SDL_VARIATOR_RANDOM;
        else
        {
            SDLTest_LogError("Arguments parsing error: Invalid variator name.");
            return -1;
        }
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("num-variations", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: Invalid argument for num-variations.");
            return -1;
        }
        state->num_variations = SDL_atoi(argv[index]);
        SDLTest_Log("Number of variations to run: %d", state->num_variations);
        if(state->num_variations <= 0)
        {
            SDLTest_LogError("Arguments parsing error: num-variations must be positive.");
            return -1;
        }
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("no-launch", argv[index]) == 0)
    {
        state->no_launch = SDL_TRUE;
        SDLTest_Log("SUT will not be launched.");
        return 1;
    }
    else if(StrCaseCmpIgnoreHyphen("action-config", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: invalid argument for action-config");
            return -1;
        }
        SDLTest_Log("Action Config file: %s", argv[index]);
        SDLVisualTest_EmptyActionQueue(&state->action_queue);
        if(!SDLVisualTest_ParseActionConfig(argv[index], &state->action_queue))
        {
            SDLTest_LogError("SDLVisualTest_ParseActionConfig() failed");
            return -1;
        }
        return 2;
    }
    else if(StrCaseCmpIgnoreHyphen("config", argv[index]) == 0)
    {
        index++;
        if(!argv[index])
        {
            SDLTest_LogError("Arguments parsing error: invalid argument for config");
            return -1;
        }
        return 2;
    }
    return 0;
}
static int ParseArg ( char * * argv , int index , SDLVisualTest_HarnessState * state ) { if ( ! argv || ! argv [ index ] || ! state ) return 0 ; if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDL_strlcpy ( state -> sutapp , argv [ index ] , MAX_PATH_LEN ) ; SDLTest_Log ( " " , state -> sutapp ) ; return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDL_strlcpy ( state -> output_dir , argv [ index ] , MAX_PATH_LEN ) ; SDLTest_Log ( " " , state -> output_dir ) ; return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDL_strlcpy ( state -> verify_dir , argv [ index ] , MAX_PATH_LEN ) ; SDLTest_Log ( " " , state -> verify_dir ) ; return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDL_strlcpy ( state -> sutargs , argv [ index ] , MAX_SUT_ARGS_LEN ) ; SDLTest_Log ( " " , state -> sutargs ) ; return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { int hr , min , sec ; index ++ ; if ( ! argv [ index ] || SDL_sscanf ( argv [ index ] , " " , & hr , & min , & sec ) != 3 ) { SDLTest_LogError ( " " ) ; return -1 ; } state -> timeout = ( ( ( hr * 60 ) + min ) * 60 + sec ) * 1000 ; SDLTest_Log ( " " , state -> timeout ) ; return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDLTest_Log ( " " , argv [ index ] ) ; SDLVisualTest_FreeSUTConfig ( & state -> sut_config ) ; if ( ! SDLVisualTest_ParseSUTConfig ( argv [ index ] , & state -> sut_config ) ) { SDLTest_LogError ( " " ) ; return -1 ; } return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDLTest_Log ( " " , argv [ index ] ) ; if ( SDL_strcasecmp ( " " , argv [ index ] ) == 0 ) state -> variator_type = SDL_VARIATOR_EXHAUSTIVE ; else if ( SDL_strcasecmp ( " " , argv [ index ] ) == 0 ) state -> variator_type = SDL_VARIATOR_RANDOM ; else { SDLTest_LogError ( " " ) ; return -1 ; } return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } state -> num_variations = SDL_atoi ( argv [ index ] ) ; SDLTest_Log ( " " , state -> num_variations ) ; if ( state -> num_variations <= 0 ) { SDLTest_LogError ( " " ) ; return -1 ; } return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { state -> no_launch = SDL_TRUE ; SDLTest_Log ( " " ) ; return 1 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } SDLTest_Log ( " " , argv [ index ] ) ; SDLVisualTest_EmptyActionQueue ( & state -> action_queue ) ; if ( ! SDLVisualTest_ParseActionConfig ( argv [ index ] , & state -> action_queue ) ) { SDLTest_LogError ( " " ) ; return -1 ; } return 2 ; } else if ( StrCaseCmpIgnoreHyphen ( " " , argv [ index ] ) == 0 ) { index ++ ; if ( ! argv [ index ] ) { SDLTest_LogError ( " " ) ; return -1 ; } return 2 ; } return 0 ; }
parser an argument, updates the state object and returns the number of
arguments processed; returns -1 on failure
parser an argument updates the state object and returns the number of arguments processed ; returns - 1 on failure
/* do nothing, this option has already been handled */