test/automated/testsdl.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 11 Dec 2009 09:22:34 +0000
changeset 3541 0c429a5fda8a
parent 3482 78db4f7ae2f3
child 3596 f638ded38b8a
permissions -rw-r--r--
Added an automated test for rectangle routines, currently only testing line clipping.
Use the Cohen-Sutherland algorithm for line clipping which uses integer math and preserves ordering of clipped points.

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