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