test/testautomation.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Thu, 31 Jan 2013 08:45:30 -0800
changeset 6830 0cd3e2e9b2c5
parent 6813 b21879e67db2
child 7191 75360622e65f
permissions -rw-r--r--
Add tests to audio suite; update harness filter logic
     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, done;
    41     SDL_Event event;
    42 
    43     /* Initialize test framework */
    44     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    45     if (!state) {
    46         return 1;
    47     }
    48 
    49     /* Parse commandline */
    50     for (i = 1; i < argc;) {
    51         int consumed;
    52 
    53         consumed = SDLTest_CommonArg(state, i);
    54         if (consumed == 0) {
    55             consumed = -1;
    56             if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
    57                 if (argv[i + 1]) {
    58                     testIterations = SDL_atoi(argv[i + 1]);
    59                     if (testIterations < 1) testIterations = 1;
    60                     consumed = 2;                    
    61                 }
    62             } 
    63             else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
    64                 if (argv[i + 1]) {
    65                     SDL_sscanf(argv[i + 1], "%llu", (long long unsigned int *)&userExecKey);
    66                     consumed = 2;                    
    67                 }
    68             } 
    69             else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
    70                 if (argv[i + 1]) {
    71                     userRunSeed = SDL_strdup(argv[i + 1]);
    72                     consumed = 2;
    73                 }
    74             } 
    75             else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
    76                 if (argv[i + 1]) {
    77                     filter = SDL_strdup(argv[i + 1]);
    78                     consumed = 2;
    79                 }
    80             } 
    81         }
    82         if (consumed < 0) {
    83             fprintf(stderr,
    84                     "Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
    85                     argv[0], SDLTest_CommonUsage(state));
    86             quit(1);
    87         }
    88         
    89         i += consumed;
    90     }
    91 
    92     /* Initialize common state */    
    93     if (!SDLTest_CommonInit(state)) {
    94         quit(2);
    95     }
    96 
    97     /* Create the windows, initialize the renderers */
    98     for (i = 0; i < state->num_windows; ++i) {
    99         SDL_Renderer *renderer = state->renderers[i];
   100         SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
   101         SDL_RenderClear(renderer);
   102     }
   103 
   104     /* Call Harness */
   105     result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
   106 
   107     /* Empty event queue */    
   108     done = 0;
   109     for (i=0; i<100; i++)  {
   110       while (SDL_PollEvent(&event)) {
   111         SDLTest_CommonEvent(state, &event, &done);
   112       }
   113       SDL_Delay(10);
   114     }
   115 
   116     /* Clean up */
   117     if (userRunSeed != NULL) {
   118         SDL_free(userRunSeed);
   119     }
   120     if (filter != NULL) {
   121         SDL_free(filter);
   122     }
   123         
   124     /* Shutdown everything */
   125     quit(result);        
   126     return(result);
   127 }
   128 
   129 /* vi: set ts=4 sw=4 expandtab: */