test/automated/testsdl.c
author Edgar Simo <bobbens@gmail.com>
Sun, 02 Aug 2009 18:58:03 +0000
branchgsoc2009_unit_tests
changeset 3741 808fad5fb593
parent 3740 e451d5d288e9
child 3745 f0b89cf4bffc
permissions -rw-r--r--
Added command line options.
Added verbosity levels.
     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 
    22 
    23 /*
    24  * Prototypes.
    25  */
    26 static void print_usage( const char *name );
    27 static void parse_options( int argc, char *argv[] );
    28 
    29 
    30 /**
    31  * @brief Displays program usage.
    32  */
    33 static void print_usage( const char *name )
    34 {
    35    printf("Usage: %s [OPTIONS]\n", name);
    36    printf("Options are:\n");
    37    printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
    38    printf("   -q, --quiet     only displays errors\n");
    39    printf("   -h, --help      display this message and exit\n");
    40 }
    41 
    42 
    43 /**
    44  * @brief Handles the options.
    45  */
    46 static void parse_options( int argc, char *argv[] )
    47 {
    48    static struct option long_options[] = {
    49       { "verbose", no_argument, 0, 'v' },
    50       { "quiet", no_argument, 0, 'q' },
    51       { "help", no_argument, 0, 'h' },
    52       {NULL,0,0,0}
    53    };
    54    int option_index = 0;
    55    int c = 0;
    56    int i;
    57 
    58    /* Iterate over options. */
    59    while ((c = getopt_long( argc, argv,
    60                "vqh",
    61                long_options, &option_index)) != -1) {
    62 
    63       /* Handle options. */
    64       switch (c) {
    65 
    66          /* Verbosity. */
    67          case 'v':
    68             SDL_ATgeti( SDL_AT_VERBOSE, &i );
    69             SDL_ATseti( SDL_AT_VERBOSE, i+1 );
    70             break;
    71 
    72          /* Quiet. */
    73          case 'q':
    74             SDL_ATseti( SDL_AT_QUIET, 1 );
    75             break;
    76 
    77          /* Help. */
    78          case 'h':
    79             print_usage( argv[0] );
    80             exit(EXIT_SUCCESS);
    81       }
    82    }
    83 
    84 }
    85 
    86 
    87 /**
    88  * @brief Main entry point.
    89  */
    90 int main( int argc, char *argv[] )
    91 {
    92    parse_options( argc, argv );
    93 
    94    test_platform();
    95    test_rwops();
    96    test_surface();
    97    test_render();
    98 
    99    return 0;
   100 }
   101