test/testautomation.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 22 Dec 2012 17:24:42 -0800
changeset 6769 b49778d885cd
parent 6763 9cbd31a3450b
child 6771 55337ff4256f
permissions -rw-r--r--
Added the automation test to the autoconf build system
     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 
    25 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    26 static void
    27 quit(int rc)
    28 {
    29     SDLTest_CommonQuit(state);
    30     exit(rc);
    31 }
    32 
    33 int
    34 main(int argc, char *argv[])
    35 {
    36     int result;
    37     int testIterations = 1;
    38     Uint64 userExecKey = 0;
    39     char *userRunSeed = NULL;
    40     char *filter = NULL;
    41     int i;
    42 
    43     /* Initialize test framework */
    44     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    45     if (!state) {
    46         return 1;
    47     }
    48 
    49     // Needed?
    50     // state->window_flags |= SDL_WINDOW_RESIZABLE;
    51 
    52     /* Parse commandline */
    53     for (i = 1; i < argc;) {
    54         int consumed;
    55 
    56         consumed = SDLTest_CommonArg(state, i);
    57         if (consumed == 0) {
    58             consumed = -1;
    59             if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
    60                 if (argv[i + 1]) {
    61                     testIterations = SDL_atoi(argv[i + 1]);
    62                     if (testIterations < 1) testIterations = 1;
    63                     consumed = 2;                    
    64                 }
    65             } 
    66             else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
    67                 if (argv[i + 1]) {
    68                     SDL_sscanf(argv[i + 1], "%llu", &userExecKey);
    69                     consumed = 2;                    
    70                 }
    71             } 
    72             else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
    73                 if (argv[i + 1]) {
    74                     userRunSeed = SDL_strdup(argv[i + 1]);
    75                     consumed = 2;
    76                 }
    77             } 
    78             else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
    79                 if (argv[i + 1]) {
    80                     filter = SDL_strdup(argv[i + 1]);
    81                     consumed = 2;
    82                 }
    83             } 
    84         }
    85         if (consumed < 0) {
    86             fprintf(stderr,
    87                     "Usage: %s %s [--iterations #] [--execKey #] [--seed string]\n",
    88                     argv[0], SDLTest_CommonUsage(state));
    89             quit(1);
    90         }
    91         
    92         i += consumed;
    93     }
    94 
    95     /* Initialize common state */    
    96     if (!SDLTest_CommonInit(state)) {
    97         quit(2);
    98     }
    99 
   100     /* Create the windows, initialize the renderers */
   101     for (i = 0; i < state->num_windows; ++i) {
   102         SDL_Renderer *renderer = state->renderers[i];
   103         SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
   104         SDL_RenderClear(renderer);
   105     }
   106 
   107     /* Call Harness */
   108     result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
   109 
   110     /* Clean up */
   111     if (userRunSeed != NULL) {
   112         SDL_free(userRunSeed);
   113     }
   114     if (filter != NULL) {
   115         SDL_free(filter);
   116     }
   117         
   118     /* Shutdown everything */
   119     quit(result);        
   120     return(result);
   121 }
   122 
   123 /* vi: set ts=4 sw=4 expandtab: */