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