test/automated/testsdl.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 22 Nov 2009 07:00:26 +0000
changeset 3482 78db4f7ae2f3
parent 3460 ba48701b0534
child 3541 0c429a5fda8a
permissions -rw-r--r--
More fixes to compile under Visual C++
     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 "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_surface     = 1; /**< Run surface tests. */
    45 static int run_render      = 1; /**< Run render tests. */
    46 static int run_audio       = 1; /**< Run audio tests. */
    47 
    48 /*
    49  * Prototypes.
    50  */
    51 static void print_usage( const char *name );
    52 static void parse_options( int argc, char *argv[] );
    53 
    54 
    55 /**
    56  * @brief Displays program usage.
    57  */
    58 #ifdef NO_GETOPT
    59 static void print_usage( const char *name )
    60 {
    61 }
    62 #else
    63 #if !defined(NO_GETOPT_LONG)
    64 static void print_usage( const char *name )
    65 {
    66    printf("Usage: %s [OPTIONS]\n", name);
    67    printf("Options are:\n");
    68    printf("   -m, --manual        enables tests that require user interaction\n");
    69    printf("   -p, --noplatform    do not run the platform tests\n");
    70    printf("   -o, --norwops       do not run the rwops tests\n");
    71    printf("   -s, --nosurface     do not run the surface tests\n");
    72    printf("   -r, --norender      do not run the render tests\n");
    73    printf("   -a, --noaudio       do not run the audio tests\n");
    74    printf("   -v, --verbose       increases verbosity level by 1 for each -v\n");
    75    printf("   -q, --quiet         only displays errors\n");
    76    printf("   -h, --help          display this message and exit\n");
    77 }
    78 #endif /* !NO_GETOPT_LONG */
    79 
    80 #if defined(NO_GETOPT_LONG)
    81 static void print_usage( const char *name )
    82 {
    83    printf("Usage: %s [OPTIONS]\n", name);
    84    printf("Options are:\n");
    85    printf("   -m,     enables tests that require user interaction\n");
    86    printf("   -p,     do not run the platform tests\n");
    87    printf("   -o,     do not run the rwops tests\n");
    88    printf("   -s,     do not run the surface tests\n");
    89    printf("   -r,     do not run the render tests\n");
    90    printf("   -a,     do not run the audio tests\n");
    91    printf("   -v,     increases verbosity level by 1 for each -v\n");
    92    printf("   -q,     only displays errors\n");
    93    printf("   -h,     display this message and exit\n");
    94 }
    95 #endif /* NO_GETOPT_LONG */
    96 #endif /* NO_GETOPT */
    97 
    98 /**
    99  * @brief Handles the options.
   100  */
   101 #ifdef NO_GETOPT
   102 static void parse_options( int argc, char *argv[] )
   103 {
   104 }
   105 #else
   106 #if !defined(NO_GETOPT_LONG)
   107 static void parse_options( int argc, char *argv[] )
   108 {
   109    static struct option long_options[] = {
   110       { "manual", no_argument, 0, 'm' },
   111       { "noplatform", no_argument, 0, 'p' },
   112       { "norwops", no_argument, 0, 'o' },
   113       { "nosurface", no_argument, 0, 's' },
   114       { "norender", no_argument, 0, 'r' },
   115       { "noaudio", no_argument, 0, 'a' },
   116       { "verbose", no_argument, 0, 'v' },
   117       { "quiet", no_argument, 0, 'q' },
   118       { "help", no_argument, 0, 'h' },
   119       {NULL,0,0,0}
   120    };
   121    int option_index = 0;
   122    int c = 0;
   123    int i;
   124    const char *str;
   125 
   126    /* Iterate over options. */
   127    while ((c = getopt_long( argc, argv,
   128                "mposravqh",
   129                long_options, &option_index)) != -1) {
   130 
   131       /* Handle options. */
   132       switch (c) {
   133          case 0:
   134             str = long_options[option_index].name;
   135             if (strcmp(str,"noplatform")==0)
   136                run_platform = 0;
   137             else if (strcmp(str,"norwops")==0)
   138                run_rwops = 0;
   139             else if (strcmp(str,"nosurface")==0)
   140                run_surface = 0;
   141             else if (strcmp(str,"norender")==0)
   142                run_render = 0;
   143             else if (strcmp(str,"noaudio")==0)
   144                run_audio = 0;
   145             break;
   146 
   147          /* Manual. */
   148          case 'm':
   149             run_manual = 1;
   150             break;
   151 
   152          /* No platform. */
   153          case 'p':
   154             run_platform = 0;
   155             break;
   156 
   157          /* No rwops. */
   158          case 'o':
   159             run_rwops = 0;
   160             break;
   161 
   162          /* No surface. */
   163          case 's':
   164             run_surface = 0;
   165             break;
   166 
   167          /* No render. */
   168          case 'r':
   169             run_render = 0;
   170             break;
   171 
   172          /* No audio. */
   173          case 'a':
   174             run_audio = 0;
   175             break;
   176 
   177          /* Verbosity. */
   178          case 'v':
   179             SDL_ATgeti( SDL_AT_VERBOSE, &i );
   180             SDL_ATseti( SDL_AT_VERBOSE, i+1 );
   181             break;
   182 
   183          /* Quiet. */
   184          case 'q':
   185             SDL_ATseti( SDL_AT_QUIET, 1 );
   186             break;
   187 
   188          /* Help. */
   189          case 'h':
   190             print_usage( argv[0] );
   191             exit(EXIT_SUCCESS);
   192       }
   193    }
   194 }
   195 #endif /* !NO_GETOPT_LONG */
   196 
   197 #if defined(NO_GETOPT_LONG)
   198 static void parse_options( int argc, char *argv[] )
   199 {
   200    static char* short_options="mposravqh";
   201    int c = 0;
   202    int i;
   203 
   204    /* Iterate over options. */
   205    while ((c = getopt(argc, argv, short_options)) != -1) {
   206       /* Handle options. */
   207       switch (c) {
   208          /* Manual. */
   209          case 'm':
   210             run_manual = 1;
   211             break;
   212 
   213          /* No platform. */
   214          case 'p':
   215             run_platform = 0;
   216             break;
   217 
   218          /* No rwops. */
   219          case 'o':
   220             run_rwops = 0;
   221             break;
   222 
   223          /* No surface. */
   224          case 's':
   225             run_surface = 0;
   226             break;
   227 
   228          /* No render. */
   229          case 'r':
   230             run_render = 0;
   231             break;
   232 
   233          /* No audio. */
   234          case 'a':
   235             run_audio = 0;
   236             break;
   237 
   238          /* Verbosity. */
   239          case 'v':
   240             SDL_ATgeti( SDL_AT_VERBOSE, &i );
   241             SDL_ATseti( SDL_AT_VERBOSE, i+1 );
   242             break;
   243 
   244          /* Quiet. */
   245          case 'q':
   246             SDL_ATseti( SDL_AT_QUIET, 1 );
   247             break;
   248 
   249          /* Help. */
   250          case 'h':
   251             print_usage( argv[0] );
   252             exit(EXIT_SUCCESS);
   253       }
   254    }
   255 }
   256 #endif /* NO_GETOPT_LONG */
   257 #endif /* NO_GETOPT */
   258 
   259 /**
   260  * @brief Main entry point.
   261  */
   262 int main( int argc, char *argv[] )
   263 {
   264    int failed;
   265    int rev;
   266    SDL_version ver;
   267 
   268    /* Get options. */
   269    parse_options( argc, argv );
   270 
   271    /* Defaults. */
   272    failed = 0;
   273 
   274    /* Print some text if verbose. */
   275    SDL_GetVersion( &ver );
   276    rev = SDL_GetRevision();
   277    SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
   278          ver.major, ver.minor, ver.patch, rev );
   279 
   280    /* Automatic tests. */
   281    if (run_platform)
   282       failed += test_platform();
   283    if (run_rwops)
   284       failed += test_rwops();
   285    if (run_surface)
   286       failed += test_surface();
   287    if (run_render)
   288       failed += test_render();
   289    if (run_audio)
   290       failed += test_audio();
   291 
   292    /* Manual tests. */
   293    if (run_manual) {
   294    }
   295 
   296    /* Display more information if failed. */
   297    if (failed > 0) {
   298       SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
   299             ver.major, ver.minor, ver.patch, rev );
   300       SDL_ATprintErr( "System is running %s and is %s endian\n",
   301             SDL_GetPlatform(),
   302 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   303             "little"
   304 #else
   305             "big"
   306 #endif
   307             );
   308    }
   309 
   310    return failed;
   311 }
   312