test/testautomation.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Sat, 15 Dec 2012 21:50:17 -0800
changeset 6757 9935f71c8c81
parent 6756 398073b195bb
child 6763 9cbd31a3450b
permissions -rw-r--r--
Fixes in harness and fuzzer test lib components; improve harness driver; add rect test suite
     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 "tests/testsuites.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     int i;
    41 
    42     /* Initialize test framework */
    43     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    44     if (!state) {
    45         return 1;
    46     }
    47 
    48     // Needed?
    49     // state->window_flags |= SDL_WINDOW_RESIZABLE;
    50 
    51     /* Parse commandline */
    52     for (i = 1; i < argc;) {
    53         int consumed;
    54 
    55         consumed = SDLTest_CommonArg(state, i);
    56         if (consumed == 0) {
    57             consumed = -1;
    58             if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
    59                 if (argv[i + 1]) {
    60                     testIterations = SDL_atoi(argv[i + 1]);
    61                     if (testIterations < 1) testIterations = 1;
    62                     consumed = 2;                    
    63                 }
    64             } 
    65             else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
    66                 if (argv[i + 1]) {
    67                     SDL_sscanf(argv[i + 1], "%llu", &userExecKey);
    68                     consumed = 2;                    
    69                 }
    70             } 
    71             else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
    72                 if (argv[i + 1]) {
    73                     userRunSeed = SDL_strdup(argv[i + 1]);
    74                     consumed = 2;
    75                 }
    76             } 
    77         }
    78         if (consumed < 0) {
    79             fprintf(stderr,
    80                     "Usage: %s %s [--iterations #] [--execKey #] [--seed string]\n",
    81                     argv[0], SDLTest_CommonUsage(state));
    82             quit(1);
    83         }
    84         
    85         i += consumed;
    86     }
    87 
    88     /* Initialize common state */    
    89     if (!SDLTest_CommonInit(state)) {
    90         quit(2);
    91     }
    92 
    93     /* Create the windows, initialize the renderers */
    94     for (i = 0; i < state->num_windows; ++i) {
    95         SDL_Renderer *renderer = state->renderers[i];
    96         SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
    97         SDL_RenderClear(renderer);
    98     }
    99 
   100     /* Call Harness */
   101     result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, testIterations);
   102 
   103     /* Clean up */
   104     if (userRunSeed != NULL) {
   105         SDL_free(userRunSeed);
   106     }
   107         
   108     /* Shutdown everything */
   109     quit(result);        
   110     return(result);
   111 }
   112 
   113 /* vi: set ts=4 sw=4 expandtab: */