test/testautomation.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Fri, 14 Dec 2012 23:05:34 -0800
changeset 6756 398073b195bb
child 6757 9935f71c8c81
permissions -rw-r--r--
Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6756
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     1
/*
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     3
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     6
  arising from the use of this software.
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     7
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    10
  freely.
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    11
*/
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    12
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    13
#include <stdlib.h>
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    14
#include <stdio.h>
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    15
#include <time.h>
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    16
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    17
#include "SDL.h"
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    18
#include "SDL_test.h"
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    19
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    20
#include "tests/testsuites.h"
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    21
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    22
static SDLTest_CommonState *state;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    23
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    24
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    25
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    26
static void
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    27
quit(int rc)
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    28
{
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    29
    SDLTest_CommonQuit(state);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    30
    exit(rc);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    31
}
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    32
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    33
int
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    34
main(int argc, char *argv[])
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    35
{
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    36
    int result;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    37
    int i;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    38
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    39
    /* Initialize test framework */
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    40
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    41
    if (!state) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    42
        return 1;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    43
    }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    44
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    45
    // Needed?
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    46
    // state->window_flags |= SDL_WINDOW_RESIZABLE;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    47
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    48
    /* Parse commandline */
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    49
    for (i = 1; i < argc;) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    50
        int consumed;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    51
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    52
        consumed = SDLTest_CommonArg(state, i);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    53
        if (consumed == 0) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    54
            consumed = -1;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    55
/* Parse additional parameters
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    56
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    57
            if (SDL_strcasecmp(argv[i], "--BLAH") == 0) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    58
                if (argv[i + 1]) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    59
                    if (SDL_strcasecmp(argv[i + 1], "BLUB") == 0) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    60
                        blah = blub;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    61
                        consumed = 2;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    62
                    }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    63
                }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    64
            } else if (SDL_strcasecmp(argv[i], "--BINGO") == 0) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    65
                bingo = SDL_TRUE;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    66
                consumed = 1;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    67
            }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    68
*/
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    69
        }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    70
        if (consumed < 0) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    71
            fprintf(stderr,
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    72
                    "Usage: %s %s [--BLAH BLUB --BINGO]\n",
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    73
                    argv[0], SDLTest_CommonUsage(state));
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    74
            quit(1);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    75
        }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    76
        i += consumed;
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    77
    }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    78
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    79
    /* Initialize common state */    
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    80
    if (!SDLTest_CommonInit(state)) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    81
        quit(2);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    82
    }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    83
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    84
    /* Create the windows, initialize the renderers */
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    85
    for (i = 0; i < state->num_windows; ++i) {
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    86
        SDL_Renderer *renderer = state->renderers[i];
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    87
        SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    88
        SDL_RenderClear(renderer);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    89
    }
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    90
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    91
    /* Call Harness */
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    92
    // TODO: pass custom parameters
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    93
    result = SDLTest_RunSuites(testSuites, NULL, 0, 1);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    94
//int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites, char *userRunSeed, Uint64 userExecKey, int testIterations);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    95
    
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    96
    /* Shutdown everything */
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    97
    quit(result);        
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    98
    return(result);
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
    99
}
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   100
398073b195bb Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
diff changeset
   101
/* vi: set ts=4 sw=4 expandtab: */