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