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.
bobbens@3740
     1
/*
bobbens@3740
     2
 * SDL test suite framework code.
bobbens@3740
     3
 *
bobbens@3740
     4
 * Written by Edgar Simo "bobbens"
bobbens@3740
     5
 *
bobbens@3740
     6
 * Released under Public Domain.
bobbens@3740
     7
 */
bobbens@3740
     8
bobbens@3740
     9
bobbens@3741
    10
#include "SDL_at.h"
bobbens@3741
    11
bobbens@3740
    12
#include "platform/platform.h"
bobbens@3740
    13
#include "rwops/rwops.h"
bobbens@3740
    14
#include "surface/surface.h"
bobbens@3740
    15
#include "render/render.h"
bobbens@3740
    16
bobbens@3741
    17
#include <stdio.h> /* printf */
bobbens@3741
    18
#include <stdlib.h> /* exit */
bobbens@3741
    19
#include <unistd.h> /* getopt */
bobbens@3741
    20
#include <getopt.h> /* getopt_long */
bobbens@3740
    21
bobbens@3741
    22
bobbens@3741
    23
/*
bobbens@3741
    24
 * Prototypes.
bobbens@3741
    25
 */
bobbens@3741
    26
static void print_usage( const char *name );
bobbens@3741
    27
static void parse_options( int argc, char *argv[] );
bobbens@3741
    28
bobbens@3741
    29
bobbens@3741
    30
/**
bobbens@3741
    31
 * @brief Displays program usage.
bobbens@3741
    32
 */
bobbens@3741
    33
static void print_usage( const char *name )
bobbens@3741
    34
{
bobbens@3741
    35
   printf("Usage: %s [OPTIONS]\n", name);
bobbens@3741
    36
   printf("Options are:\n");
bobbens@3741
    37
   printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
bobbens@3741
    38
   printf("   -q, --quiet     only displays errors\n");
bobbens@3741
    39
   printf("   -h, --help      display this message and exit\n");
bobbens@3741
    40
}
bobbens@3741
    41
bobbens@3741
    42
bobbens@3741
    43
/**
bobbens@3741
    44
 * @brief Handles the options.
bobbens@3741
    45
 */
bobbens@3741
    46
static void parse_options( int argc, char *argv[] )
bobbens@3741
    47
{
bobbens@3741
    48
   static struct option long_options[] = {
bobbens@3741
    49
      { "verbose", no_argument, 0, 'v' },
bobbens@3741
    50
      { "quiet", no_argument, 0, 'q' },
bobbens@3741
    51
      { "help", no_argument, 0, 'h' },
bobbens@3741
    52
      {NULL,0,0,0}
bobbens@3741
    53
   };
bobbens@3741
    54
   int option_index = 0;
bobbens@3741
    55
   int c = 0;
bobbens@3741
    56
   int i;
bobbens@3741
    57
bobbens@3741
    58
   /* Iterate over options. */
bobbens@3741
    59
   while ((c = getopt_long( argc, argv,
bobbens@3741
    60
               "vqh",
bobbens@3741
    61
               long_options, &option_index)) != -1) {
bobbens@3741
    62
bobbens@3741
    63
      /* Handle options. */
bobbens@3741
    64
      switch (c) {
bobbens@3741
    65
bobbens@3741
    66
         /* Verbosity. */
bobbens@3741
    67
         case 'v':
bobbens@3741
    68
            SDL_ATgeti( SDL_AT_VERBOSE, &i );
bobbens@3741
    69
            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
bobbens@3741
    70
            break;
bobbens@3741
    71
bobbens@3741
    72
         /* Quiet. */
bobbens@3741
    73
         case 'q':
bobbens@3741
    74
            SDL_ATseti( SDL_AT_QUIET, 1 );
bobbens@3741
    75
            break;
bobbens@3741
    76
bobbens@3741
    77
         /* Help. */
bobbens@3741
    78
         case 'h':
bobbens@3741
    79
            print_usage( argv[0] );
bobbens@3741
    80
            exit(EXIT_SUCCESS);
bobbens@3741
    81
      }
bobbens@3741
    82
   }
bobbens@3741
    83
bobbens@3741
    84
}
bobbens@3741
    85
bobbens@3741
    86
bobbens@3741
    87
/**
bobbens@3741
    88
 * @brief Main entry point.
bobbens@3741
    89
 */
bobbens@3740
    90
int main( int argc, char *argv[] )
bobbens@3740
    91
{
bobbens@3741
    92
   parse_options( argc, argv );
bobbens@3740
    93
bobbens@3740
    94
   test_platform();
bobbens@3740
    95
   test_rwops();
bobbens@3740
    96
   test_surface();
bobbens@3740
    97
   test_render();
bobbens@3740
    98
bobbens@3740
    99
   return 0;
bobbens@3740
   100
}
bobbens@3740
   101