test/automated/testsdl.c
author Edgar Simo <bobbens@gmail.com>
Thu, 06 Aug 2009 08:39:42 +0000
branchgsoc2009_unit_tests
changeset 3753 5b48a529fd8a
parent 3750 cb75359d29bb
child 3756 427f059bc814
permissions -rw-r--r--
More debugging information when test fails.
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@3753
    10
#include "SDL.h"
bobbens@3741
    11
#include "SDL_at.h"
bobbens@3741
    12
bobbens@3740
    13
#include "platform/platform.h"
bobbens@3740
    14
#include "rwops/rwops.h"
bobbens@3740
    15
#include "surface/surface.h"
bobbens@3740
    16
#include "render/render.h"
bobbens@3740
    17
bobbens@3741
    18
#include <stdio.h> /* printf */
bobbens@3741
    19
#include <stdlib.h> /* exit */
bobbens@3741
    20
#include <unistd.h> /* getopt */
bobbens@3741
    21
#include <getopt.h> /* getopt_long */
bobbens@3745
    22
#include <string.h> /* strcmp */
bobbens@3740
    23
bobbens@3741
    24
bobbens@3741
    25
/*
bobbens@3745
    26
 * Tests to run.
bobbens@3745
    27
 */
bobbens@3749
    28
static int run_manual      = 0; /**< Run manual tests. */
bobbens@3749
    29
/* Manual. */
bobbens@3749
    30
/* Automatic. */
bobbens@3749
    31
static int run_platform    = 1; /**< Run platform tests. */
bobbens@3749
    32
static int run_rwops       = 1; /**< Run RWops tests. */
bobbens@3749
    33
static int run_surface     = 1; /**< Run surface tests. */
bobbens@3749
    34
static int run_render      = 1; /**< Run render tests. */
bobbens@3745
    35
bobbens@3745
    36
/*
bobbens@3741
    37
 * Prototypes.
bobbens@3741
    38
 */
bobbens@3741
    39
static void print_usage( const char *name );
bobbens@3741
    40
static void parse_options( int argc, char *argv[] );
bobbens@3741
    41
bobbens@3741
    42
bobbens@3741
    43
/**
bobbens@3741
    44
 * @brief Displays program usage.
bobbens@3741
    45
 */
bobbens@3741
    46
static void print_usage( const char *name )
bobbens@3741
    47
{
bobbens@3741
    48
   printf("Usage: %s [OPTIONS]\n", name);
bobbens@3741
    49
   printf("Options are:\n");
bobbens@3750
    50
   printf("   -m, --manual    enables tests that require user interaction\n");
bobbens@3745
    51
   printf("   --noplatform    do not run the platform tests\n");
bobbens@3745
    52
   printf("   --norwops       do not run the rwops tests\n");
bobbens@3745
    53
   printf("   --nosurface     do not run the surface tests\n");
bobbens@3745
    54
   printf("   --norender      do not run the render tests\n");
bobbens@3741
    55
   printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
bobbens@3741
    56
   printf("   -q, --quiet     only displays errors\n");
bobbens@3741
    57
   printf("   -h, --help      display this message and exit\n");
bobbens@3741
    58
}
bobbens@3741
    59
bobbens@3741
    60
bobbens@3741
    61
/**
bobbens@3741
    62
 * @brief Handles the options.
bobbens@3741
    63
 */
bobbens@3741
    64
static void parse_options( int argc, char *argv[] )
bobbens@3741
    65
{
bobbens@3741
    66
   static struct option long_options[] = {
bobbens@3750
    67
      { "manual", no_argument, 0, 'm' },
bobbens@3745
    68
      { "noplatform", no_argument, 0, 0 },
bobbens@3745
    69
      { "norwops", no_argument, 0, 0 },
bobbens@3745
    70
      { "nosurface", no_argument, 0, 0 },
bobbens@3745
    71
      { "norender", no_argument, 0, 0 },
bobbens@3741
    72
      { "verbose", no_argument, 0, 'v' },
bobbens@3741
    73
      { "quiet", no_argument, 0, 'q' },
bobbens@3741
    74
      { "help", no_argument, 0, 'h' },
bobbens@3741
    75
      {NULL,0,0,0}
bobbens@3741
    76
   };
bobbens@3741
    77
   int option_index = 0;
bobbens@3741
    78
   int c = 0;
bobbens@3741
    79
   int i;
bobbens@3745
    80
   const char *str;
bobbens@3741
    81
bobbens@3741
    82
   /* Iterate over options. */
bobbens@3741
    83
   while ((c = getopt_long( argc, argv,
bobbens@3741
    84
               "vqh",
bobbens@3741
    85
               long_options, &option_index)) != -1) {
bobbens@3741
    86
bobbens@3741
    87
      /* Handle options. */
bobbens@3741
    88
      switch (c) {
bobbens@3745
    89
         case 0:
bobbens@3745
    90
            str = long_options[option_index].name;
bobbens@3745
    91
            if (strcmp(str,"noplatform")==0)
bobbens@3745
    92
               run_platform = 0;
bobbens@3745
    93
            else if (strcmp(str,"norwops")==0)
bobbens@3745
    94
               run_rwops = 0;
bobbens@3745
    95
            else if (strcmp(str,"nosurface")==0)
bobbens@3745
    96
               run_surface = 0;
bobbens@3745
    97
            else if (strcmp(str,"norender")==0)
bobbens@3745
    98
               run_render = 0;
bobbens@3745
    99
            break;
bobbens@3745
   100
bobbens@3750
   101
         /* Manual. */
bobbens@3750
   102
         case 'm':
bobbens@3750
   103
            run_manual = 1;
bobbens@3750
   104
            break;
bobbens@3741
   105
bobbens@3741
   106
         /* Verbosity. */
bobbens@3741
   107
         case 'v':
bobbens@3741
   108
            SDL_ATgeti( SDL_AT_VERBOSE, &i );
bobbens@3741
   109
            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
bobbens@3741
   110
            break;
bobbens@3741
   111
bobbens@3741
   112
         /* Quiet. */
bobbens@3741
   113
         case 'q':
bobbens@3741
   114
            SDL_ATseti( SDL_AT_QUIET, 1 );
bobbens@3741
   115
            break;
bobbens@3741
   116
bobbens@3741
   117
         /* Help. */
bobbens@3741
   118
         case 'h':
bobbens@3741
   119
            print_usage( argv[0] );
bobbens@3741
   120
            exit(EXIT_SUCCESS);
bobbens@3741
   121
      }
bobbens@3741
   122
   }
bobbens@3741
   123
bobbens@3741
   124
}
bobbens@3741
   125
bobbens@3741
   126
bobbens@3741
   127
/**
bobbens@3741
   128
 * @brief Main entry point.
bobbens@3741
   129
 */
bobbens@3740
   130
int main( int argc, char *argv[] )
bobbens@3740
   131
{
bobbens@3753
   132
   int failed;
bobbens@3753
   133
   int rev;
bobbens@3753
   134
   SDL_version ver;
bobbens@3753
   135
bobbens@3753
   136
   /* Get options. */
bobbens@3741
   137
   parse_options( argc, argv );
bobbens@3740
   138
bobbens@3753
   139
   /* Defaults. */
bobbens@3753
   140
   failed = 0;
bobbens@3753
   141
bobbens@3753
   142
   /* Print some text if verbose. */
bobbens@3753
   143
   SDL_GetVersion( &ver );
bobbens@3753
   144
   rev = SDL_GetRevision();
bobbens@3753
   145
   SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
bobbens@3753
   146
         ver.major, ver.minor, ver.patch, rev );
bobbens@3753
   147
bobbens@3749
   148
   /* Automatic tests. */
bobbens@3745
   149
   if (run_platform)
bobbens@3753
   150
      failed += test_platform();
bobbens@3745
   151
   if (run_rwops)
bobbens@3753
   152
      failed += test_rwops();
bobbens@3745
   153
   if (run_surface)
bobbens@3753
   154
      failed += test_surface();
bobbens@3745
   155
   if (run_render)
bobbens@3753
   156
      failed += test_render();
bobbens@3740
   157
bobbens@3749
   158
   /* Manual tests. */
bobbens@3749
   159
   if (run_manual) {
bobbens@3749
   160
   }
bobbens@3749
   161
bobbens@3753
   162
   /* Display more information if failed. */
bobbens@3753
   163
   if (failed > 0) {
bobbens@3753
   164
      SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
bobbens@3753
   165
            ver.major, ver.minor, ver.patch, rev );
bobbens@3753
   166
      SDL_ATprintErr( "System is running %s and is %s endian\n",
bobbens@3753
   167
            platform_getPlatform(),
bobbens@3753
   168
#ifdef SDL_LIL_ENDIAN
bobbens@3753
   169
            "little"
bobbens@3753
   170
#else
bobbens@3753
   171
            "big"
bobbens@3753
   172
#endif
bobbens@3753
   173
            );
bobbens@3753
   174
   }
bobbens@3753
   175
bobbens@3753
   176
   return failed;
bobbens@3740
   177
}
bobbens@3740
   178