test/automated/testsdl.c
author Edgar Simo <bobbens@gmail.com>
Tue, 04 Aug 2009 16:26:43 +0000
branchgsoc2009_unit_tests
changeset 3745 f0b89cf4bffc
parent 3741 808fad5fb593
child 3749 1e277c40babe
permissions -rw-r--r--
You can now disable any of the testsuites.
     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_at.h"
    11 
    12 #include "platform/platform.h"
    13 #include "rwops/rwops.h"
    14 #include "surface/surface.h"
    15 #include "render/render.h"
    16 
    17 #include <stdio.h> /* printf */
    18 #include <stdlib.h> /* exit */
    19 #include <unistd.h> /* getopt */
    20 #include <getopt.h> /* getopt_long */
    21 #include <string.h> /* strcmp */
    22 
    23 
    24 /*
    25  * Tests to run.
    26  */
    27 static int run_platform    = 1;
    28 static int run_rwops       = 1;
    29 static int run_surface     = 1;
    30 static int run_render      = 1;
    31 
    32 /*
    33  * Prototypes.
    34  */
    35 static void print_usage( const char *name );
    36 static void parse_options( int argc, char *argv[] );
    37 
    38 
    39 /**
    40  * @brief Displays program usage.
    41  */
    42 static void print_usage( const char *name )
    43 {
    44    printf("Usage: %s [OPTIONS]\n", name);
    45    printf("Options are:\n");
    46    printf("   --noplatform    do not run the platform tests\n");
    47    printf("   --norwops       do not run the rwops tests\n");
    48    printf("   --nosurface     do not run the surface tests\n");
    49    printf("   --norender      do not run the render tests\n");
    50    printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
    51    printf("   -q, --quiet     only displays errors\n");
    52    printf("   -h, --help      display this message and exit\n");
    53 }
    54 
    55 
    56 /**
    57  * @brief Handles the options.
    58  */
    59 static void parse_options( int argc, char *argv[] )
    60 {
    61    static struct option long_options[] = {
    62       { "noplatform", no_argument, 0, 0 },
    63       { "norwops", no_argument, 0, 0 },
    64       { "nosurface", no_argument, 0, 0 },
    65       { "norender", no_argument, 0, 0 },
    66       { "verbose", no_argument, 0, 'v' },
    67       { "quiet", no_argument, 0, 'q' },
    68       { "help", no_argument, 0, 'h' },
    69       {NULL,0,0,0}
    70    };
    71    int option_index = 0;
    72    int c = 0;
    73    int i;
    74    const char *str;
    75 
    76    /* Iterate over options. */
    77    while ((c = getopt_long( argc, argv,
    78                "vqh",
    79                long_options, &option_index)) != -1) {
    80 
    81       /* Handle options. */
    82       switch (c) {
    83          case 0:
    84             str = long_options[option_index].name;
    85             if (strcmp(str,"noplatform")==0)
    86                run_platform = 0;
    87             else if (strcmp(str,"norwops")==0)
    88                run_rwops = 0;
    89             else if (strcmp(str,"nosurface")==0)
    90                run_surface = 0;
    91             else if (strcmp(str,"norender")==0)
    92                run_render = 0;
    93             break;
    94 
    95 
    96          /* Verbosity. */
    97          case 'v':
    98             SDL_ATgeti( SDL_AT_VERBOSE, &i );
    99             SDL_ATseti( SDL_AT_VERBOSE, i+1 );
   100             break;
   101 
   102          /* Quiet. */
   103          case 'q':
   104             SDL_ATseti( SDL_AT_QUIET, 1 );
   105             break;
   106 
   107          /* Help. */
   108          case 'h':
   109             print_usage( argv[0] );
   110             exit(EXIT_SUCCESS);
   111       }
   112    }
   113 
   114 }
   115 
   116 
   117 /**
   118  * @brief Main entry point.
   119  */
   120 int main( int argc, char *argv[] )
   121 {
   122    parse_options( argc, argv );
   123 
   124    if (run_platform)
   125       test_platform();
   126    if (run_rwops)
   127       test_rwops();
   128    if (run_surface)
   129       test_surface();
   130    if (run_render)
   131       test_render();
   132 
   133    return 0;
   134 }
   135