test/automated/testsdl.c
author Edgar Simo <bobbens@gmail.com>
Thu, 06 Aug 2009 08:39:42 +0000
branchgsoc2009_unit_tests
changeset 3753 5b48a529fd8a
parent 3750 cb75359d29bb
child 3756 427f059bc814
permissions -rw-r--r--
More debugging information when test fails.
     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 
    18 #include <stdio.h> /* printf */
    19 #include <stdlib.h> /* exit */
    20 #include <unistd.h> /* getopt */
    21 #include <getopt.h> /* getopt_long */
    22 #include <string.h> /* strcmp */
    23 
    24 
    25 /*
    26  * Tests to run.
    27  */
    28 static int run_manual      = 0; /**< Run manual tests. */
    29 /* Manual. */
    30 /* Automatic. */
    31 static int run_platform    = 1; /**< Run platform tests. */
    32 static int run_rwops       = 1; /**< Run RWops tests. */
    33 static int run_surface     = 1; /**< Run surface tests. */
    34 static int run_render      = 1; /**< Run render tests. */
    35 
    36 /*
    37  * Prototypes.
    38  */
    39 static void print_usage( const char *name );
    40 static void parse_options( int argc, char *argv[] );
    41 
    42 
    43 /**
    44  * @brief Displays program usage.
    45  */
    46 static void print_usage( const char *name )
    47 {
    48    printf("Usage: %s [OPTIONS]\n", name);
    49    printf("Options are:\n");
    50    printf("   -m, --manual    enables tests that require user interaction\n");
    51    printf("   --noplatform    do not run the platform tests\n");
    52    printf("   --norwops       do not run the rwops tests\n");
    53    printf("   --nosurface     do not run the surface tests\n");
    54    printf("   --norender      do not run the render tests\n");
    55    printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
    56    printf("   -q, --quiet     only displays errors\n");
    57    printf("   -h, --help      display this message and exit\n");
    58 }
    59 
    60 
    61 /**
    62  * @brief Handles the options.
    63  */
    64 static void parse_options( int argc, char *argv[] )
    65 {
    66    static struct option long_options[] = {
    67       { "manual", no_argument, 0, 'm' },
    68       { "noplatform", no_argument, 0, 0 },
    69       { "norwops", no_argument, 0, 0 },
    70       { "nosurface", no_argument, 0, 0 },
    71       { "norender", no_argument, 0, 0 },
    72       { "verbose", no_argument, 0, 'v' },
    73       { "quiet", no_argument, 0, 'q' },
    74       { "help", no_argument, 0, 'h' },
    75       {NULL,0,0,0}
    76    };
    77    int option_index = 0;
    78    int c = 0;
    79    int i;
    80    const char *str;
    81 
    82    /* Iterate over options. */
    83    while ((c = getopt_long( argc, argv,
    84                "vqh",
    85                long_options, &option_index)) != -1) {
    86 
    87       /* Handle options. */
    88       switch (c) {
    89          case 0:
    90             str = long_options[option_index].name;
    91             if (strcmp(str,"noplatform")==0)
    92                run_platform = 0;
    93             else if (strcmp(str,"norwops")==0)
    94                run_rwops = 0;
    95             else if (strcmp(str,"nosurface")==0)
    96                run_surface = 0;
    97             else if (strcmp(str,"norender")==0)
    98                run_render = 0;
    99             break;
   100 
   101          /* Manual. */
   102          case 'm':
   103             run_manual = 1;
   104             break;
   105 
   106          /* Verbosity. */
   107          case 'v':
   108             SDL_ATgeti( SDL_AT_VERBOSE, &i );
   109             SDL_ATseti( SDL_AT_VERBOSE, i+1 );
   110             break;
   111 
   112          /* Quiet. */
   113          case 'q':
   114             SDL_ATseti( SDL_AT_QUIET, 1 );
   115             break;
   116 
   117          /* Help. */
   118          case 'h':
   119             print_usage( argv[0] );
   120             exit(EXIT_SUCCESS);
   121       }
   122    }
   123 
   124 }
   125 
   126 
   127 /**
   128  * @brief Main entry point.
   129  */
   130 int main( int argc, char *argv[] )
   131 {
   132    int failed;
   133    int rev;
   134    SDL_version ver;
   135 
   136    /* Get options. */
   137    parse_options( argc, argv );
   138 
   139    /* Defaults. */
   140    failed = 0;
   141 
   142    /* Print some text if verbose. */
   143    SDL_GetVersion( &ver );
   144    rev = SDL_GetRevision();
   145    SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
   146          ver.major, ver.minor, ver.patch, rev );
   147 
   148    /* Automatic tests. */
   149    if (run_platform)
   150       failed += test_platform();
   151    if (run_rwops)
   152       failed += test_rwops();
   153    if (run_surface)
   154       failed += test_surface();
   155    if (run_render)
   156       failed += test_render();
   157 
   158    /* Manual tests. */
   159    if (run_manual) {
   160    }
   161 
   162    /* Display more information if failed. */
   163    if (failed > 0) {
   164       SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
   165             ver.major, ver.minor, ver.patch, rev );
   166       SDL_ATprintErr( "System is running %s and is %s endian\n",
   167             platform_getPlatform(),
   168 #ifdef SDL_LIL_ENDIAN
   169             "little"
   170 #else
   171             "big"
   172 #endif
   173             );
   174    }
   175 
   176    return failed;
   177 }
   178