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