test/automated/testsdl.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 23 Dec 2009 01:55:00 +0000
changeset 3596 f638ded38b8a
parent 3541 0c429a5fda8a
child 3658 1a99755b3b04
permissions -rw-r--r--
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine().
Added API for rectangle drawing (as opposed to filling)
Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay.
Optimized software line drawing quite a bit.
Added support for Wu's anti-aliased line drawing, currently disabled by default.
     1 /*
     2  * SDL test suite framework code.
     3  *
     4  * Written by Edgar Simo "bobbens"
     5  *
     6  * Released under Public Domain.
     7  */
     8 
     9 #include "SDL.h"
    10 #include "SDL_at.h"
    11 
    12 #include "platform/platform.h"
    13 #include "rwops/rwops.h"
    14 #include "rect/rect.h"
    15 #include "surface/surface.h"
    16 #include "render/render.h"
    17 #include "audio/audio.h"
    18 
    19 #if defined(WIN32)
    20 #define NO_GETOPT
    21 #endif
    22 #if defined(__QNXNTO__)
    23 #define NO_GETOPT_LONG 1
    24 #endif /* __QNXNTO__ */
    25 
    26 #include <stdio.h> /* printf */
    27 #include <stdlib.h> /* exit */
    28 #ifndef NO_GETOPT
    29 #include <unistd.h> /* getopt */
    30 #if !defined(NO_GETOPT_LONG)
    31 #include <getopt.h> /* getopt_long */
    32 #endif /* !NO_GETOPT_LONG */
    33 #endif /* !NO_GETOPT */
    34 
    35 
    36 /*
    37  * Tests to run.
    38  */
    39 static int run_manual      = 0; /**< Run manual tests. */
    40 /* Manual. */
    41 /* Automatic. */
    42 static int run_platform    = 1; /**< Run platform tests. */
    43 static int run_rwops       = 1; /**< Run RWops tests. */
    44 static int run_rect        = 1; /**< Run rect tests. */
    45 static int run_surface     = 1; /**< Run surface tests. */
    46 static int run_render      = 1; /**< Run render tests. */
    47 static int run_audio       = 1; /**< Run audio tests. */
    48 
    49 /*
    50  * Prototypes.
    51  */
    52 static void print_usage( const char *name );
    53 static void parse_options( int argc, char *argv[] );
    54 
    55 
    56 /**
    57  * @brief Displays program usage.
    58  */
    59 static void print_usage( const char *name )
    60 {
    61    printf("Usage: %s [OPTIONS]\n", name);
    62    printf("Options are:\n");
    63    printf("   -m, --manual        enables tests that require user interaction\n");
    64    printf("   --noplatform        do not run the platform tests\n");
    65    printf("   --norwops           do not run the rwops tests\n");
    66    printf("   --norect            do not run the rect tests\n");
    67    printf("   --nosurface         do not run the surface tests\n");
    68    printf("   --norender          do not run the render tests\n");
    69    printf("   --noaudio           do not run the audio tests\n");
    70    printf("   -v, --verbose       increases verbosity level by 1 for each -v\n");
    71    printf("   -q, --quiet         only displays errors\n");
    72    printf("   -h, --help          display this message and exit\n");
    73 }
    74 
    75 /**
    76  * @brief Handles the options.
    77  */
    78 static void parse_options( int argc, char *argv[] )
    79 {
    80    int i;
    81 
    82    for (i = 1; i < argc; ++i) {
    83       const char *arg = argv[i];
    84       if (SDL_strcmp(arg, "-m") == 0 || SDL_strcmp(arg, "--manual") == 0) {
    85          run_manual = 1;
    86          continue;
    87       }
    88       if (SDL_strcmp(arg, "-v") == 0 || SDL_strcmp(arg, "--verbose") == 0) {
    89          int level;
    90          SDL_ATgeti( SDL_AT_VERBOSE, &level );
    91          SDL_ATseti( SDL_AT_VERBOSE, level+1 );
    92          continue;
    93       }
    94       if (SDL_strcmp(arg, "-q") == 0 || SDL_strcmp(arg, "--quiet") == 0) {
    95          SDL_ATseti( SDL_AT_QUIET, 1 );
    96          continue;
    97       }
    98       if (SDL_strcmp(arg, "--noplatform") == 0) {
    99          run_platform = 0;
   100          continue;
   101       }
   102       if (SDL_strcmp(arg, "--norwops") == 0) {
   103          run_rwops = 0;
   104          continue;
   105       }
   106       if (SDL_strcmp(arg, "--norect") == 0) {
   107          run_rect = 0;
   108          continue;
   109       }
   110       if (SDL_strcmp(arg, "--nosurface") == 0) {
   111          run_surface = 0;
   112          continue;
   113       }
   114       if (SDL_strcmp(arg, "--norender") == 0) {
   115          run_render = 0;
   116          continue;
   117       }
   118       if (SDL_strcmp(arg, "--noaudio") == 0) {
   119          run_audio = 0;
   120          continue;
   121       }
   122 
   123       /* Print help and exit! */
   124       print_usage( argv[0] );
   125       exit(EXIT_FAILURE);
   126    }
   127 }
   128 
   129 /**
   130  * @brief Main entry point.
   131  */
   132 int main( int argc, char *argv[] )
   133 {
   134    int failed;
   135    int rev;
   136    SDL_version ver;
   137 
   138    /* Get options. */
   139    parse_options( argc, argv );
   140 
   141    /* Defaults. */
   142    failed = 0;
   143 
   144    /* Print some text if verbose. */
   145    SDL_GetVersion( &ver );
   146    rev = SDL_GetRevision();
   147    SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
   148          ver.major, ver.minor, ver.patch, rev );
   149 
   150    /* Automatic tests. */
   151    if (run_platform)
   152       failed += test_platform();
   153    if (run_rwops)
   154       failed += test_rwops();
   155    if (run_rect)
   156       failed += test_rect();
   157    if (run_surface)
   158       failed += test_surface();
   159    if (run_render)
   160       failed += test_render();
   161    if (run_audio)
   162       failed += test_audio();
   163 
   164    /* Manual tests. */
   165    if (run_manual) {
   166    }
   167 
   168    /* Display more information if failed. */
   169    if (failed > 0) {
   170       SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
   171             ver.major, ver.minor, ver.patch, rev );
   172       SDL_ATprintErr( "System is running %s and is %s endian\n",
   173             SDL_GetPlatform(),
   174 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   175             "little"
   176 #else
   177             "big"
   178 #endif
   179             );
   180    }
   181 
   182    return failed;
   183 }
   184