test/testautomation.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Mon, 24 Dec 2012 14:43:57 -0800
changeset 6772 5229a117ef97
parent 6771 55337ff4256f
child 6813 b21879e67db2
permissions -rw-r--r--
Added audio test suite; minor code cleanups in test lib
     1 /*
     2   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 
    13 #include <stdlib.h>
    14 #include <stdio.h>
    15 #include <time.h>
    16 
    17 #include "SDL.h"
    18 #include "SDL_test.h"
    19 
    20 #include "testautomation_suites.h"
    21 
    22 static SDLTest_CommonState *state;
    23 
    24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    25 static void
    26 quit(int rc)
    27 {
    28     SDLTest_CommonQuit(state);
    29     exit(rc);
    30 }
    31 
    32 int
    33 main(int argc, char *argv[])
    34 {
    35     int result;
    36     int testIterations = 1;
    37     Uint64 userExecKey = 0;
    38     char *userRunSeed = NULL;
    39     char *filter = NULL;
    40     int i;
    41 
    42     /* Initialize test framework */
    43     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    44     if (!state) {
    45         return 1;
    46     }
    47 
    48     /* Parse commandline */
    49     for (i = 1; i < argc;) {
    50         int consumed;
    51 
    52         consumed = SDLTest_CommonArg(state, i);
    53         if (consumed == 0) {
    54             consumed = -1;
    55             if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
    56                 if (argv[i + 1]) {
    57                     testIterations = SDL_atoi(argv[i + 1]);
    58                     if (testIterations < 1) testIterations = 1;
    59                     consumed = 2;                    
    60                 }
    61             } 
    62             else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
    63                 if (argv[i + 1]) {
    64                     SDL_sscanf(argv[i + 1], "%llu", &userExecKey);
    65                     consumed = 2;                    
    66                 }
    67             } 
    68             else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
    69                 if (argv[i + 1]) {
    70                     userRunSeed = SDL_strdup(argv[i + 1]);
    71                     consumed = 2;
    72                 }
    73             } 
    74             else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
    75                 if (argv[i + 1]) {
    76                     filter = SDL_strdup(argv[i + 1]);
    77                     consumed = 2;
    78                 }
    79             } 
    80         }
    81         if (consumed < 0) {
    82             fprintf(stderr,
    83                     "Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
    84                     argv[0], SDLTest_CommonUsage(state));
    85             quit(1);
    86         }
    87         
    88         i += consumed;
    89     }
    90 
    91     /* Initialize common state */    
    92     if (!SDLTest_CommonInit(state)) {
    93         quit(2);
    94     }
    95 
    96     /* Create the windows, initialize the renderers */
    97     for (i = 0; i < state->num_windows; ++i) {
    98         SDL_Renderer *renderer = state->renderers[i];
    99         SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
   100         SDL_RenderClear(renderer);
   101     }
   102 
   103     /* Call Harness */
   104     result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
   105 
   106     /* Clean up */
   107     if (userRunSeed != NULL) {
   108         SDL_free(userRunSeed);
   109     }
   110     if (filter != NULL) {
   111         SDL_free(filter);
   112     }
   113         
   114     /* Shutdown everything */
   115     quit(result);        
   116     return(result);
   117 }
   118 
   119 /* vi: set ts=4 sw=4 expandtab: */