test/automated/testsdl.c
branchgsoc2009_unit_tests
changeset 3741 808fad5fb593
parent 3740 e451d5d288e9
child 3745 f0b89cf4bffc
     1.1 --- a/test/automated/testsdl.c	Sun Aug 02 16:01:23 2009 +0000
     1.2 +++ b/test/automated/testsdl.c	Sun Aug 02 18:58:03 2009 +0000
     1.3 @@ -7,16 +7,89 @@
     1.4   */
     1.5  
     1.6  
     1.7 +#include "SDL_at.h"
     1.8 +
     1.9  #include "platform/platform.h"
    1.10  #include "rwops/rwops.h"
    1.11  #include "surface/surface.h"
    1.12  #include "render/render.h"
    1.13  
    1.14 +#include <stdio.h> /* printf */
    1.15 +#include <stdlib.h> /* exit */
    1.16 +#include <unistd.h> /* getopt */
    1.17 +#include <getopt.h> /* getopt_long */
    1.18  
    1.19 +
    1.20 +/*
    1.21 + * Prototypes.
    1.22 + */
    1.23 +static void print_usage( const char *name );
    1.24 +static void parse_options( int argc, char *argv[] );
    1.25 +
    1.26 +
    1.27 +/**
    1.28 + * @brief Displays program usage.
    1.29 + */
    1.30 +static void print_usage( const char *name )
    1.31 +{
    1.32 +   printf("Usage: %s [OPTIONS]\n", name);
    1.33 +   printf("Options are:\n");
    1.34 +   printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
    1.35 +   printf("   -q, --quiet     only displays errors\n");
    1.36 +   printf("   -h, --help      display this message and exit\n");
    1.37 +}
    1.38 +
    1.39 +
    1.40 +/**
    1.41 + * @brief Handles the options.
    1.42 + */
    1.43 +static void parse_options( int argc, char *argv[] )
    1.44 +{
    1.45 +   static struct option long_options[] = {
    1.46 +      { "verbose", no_argument, 0, 'v' },
    1.47 +      { "quiet", no_argument, 0, 'q' },
    1.48 +      { "help", no_argument, 0, 'h' },
    1.49 +      {NULL,0,0,0}
    1.50 +   };
    1.51 +   int option_index = 0;
    1.52 +   int c = 0;
    1.53 +   int i;
    1.54 +
    1.55 +   /* Iterate over options. */
    1.56 +   while ((c = getopt_long( argc, argv,
    1.57 +               "vqh",
    1.58 +               long_options, &option_index)) != -1) {
    1.59 +
    1.60 +      /* Handle options. */
    1.61 +      switch (c) {
    1.62 +
    1.63 +         /* Verbosity. */
    1.64 +         case 'v':
    1.65 +            SDL_ATgeti( SDL_AT_VERBOSE, &i );
    1.66 +            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
    1.67 +            break;
    1.68 +
    1.69 +         /* Quiet. */
    1.70 +         case 'q':
    1.71 +            SDL_ATseti( SDL_AT_QUIET, 1 );
    1.72 +            break;
    1.73 +
    1.74 +         /* Help. */
    1.75 +         case 'h':
    1.76 +            print_usage( argv[0] );
    1.77 +            exit(EXIT_SUCCESS);
    1.78 +      }
    1.79 +   }
    1.80 +
    1.81 +}
    1.82 +
    1.83 +
    1.84 +/**
    1.85 + * @brief Main entry point.
    1.86 + */
    1.87  int main( int argc, char *argv[] )
    1.88  {
    1.89 -   (void) argc;
    1.90 -   (void) argv;
    1.91 +   parse_options( argc, argv );
    1.92  
    1.93     test_platform();
    1.94     test_rwops();