test/automated/testsdl.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 22 Nov 2009 07:00:26 +0000
changeset 3482 78db4f7ae2f3
parent 3460 ba48701b0534
child 3541 0c429a5fda8a
permissions -rw-r--r--
More fixes to compile under Visual C++
slouken@3259
     1
/*
slouken@3259
     2
 * SDL test suite framework code.
slouken@3259
     3
 *
slouken@3259
     4
 * Written by Edgar Simo "bobbens"
slouken@3259
     5
 *
slouken@3259
     6
 * Released under Public Domain.
slouken@3259
     7
 */
slouken@3259
     8
slouken@3259
     9
slouken@3259
    10
#include "SDL.h"
slouken@3259
    11
#include "SDL_at.h"
slouken@3259
    12
slouken@3259
    13
#include "platform/platform.h"
slouken@3259
    14
#include "rwops/rwops.h"
slouken@3259
    15
#include "surface/surface.h"
slouken@3259
    16
#include "render/render.h"
slouken@3259
    17
#include "audio/audio.h"
slouken@3259
    18
slouken@3482
    19
#if defined(WIN32)
slouken@3482
    20
#define NO_GETOPT
slouken@3482
    21
#endif
lestat@3460
    22
#if defined(__QNXNTO__)
lestat@3460
    23
#define NO_GETOPT_LONG 1
lestat@3460
    24
#endif /* __QNXNTO__ */
lestat@3460
    25
slouken@3259
    26
#include <stdio.h> /* printf */
slouken@3259
    27
#include <stdlib.h> /* exit */
slouken@3482
    28
#ifndef NO_GETOPT
slouken@3259
    29
#include <unistd.h> /* getopt */
lestat@3460
    30
#if !defined(NO_GETOPT_LONG)
slouken@3259
    31
#include <getopt.h> /* getopt_long */
lestat@3460
    32
#endif /* !NO_GETOPT_LONG */
slouken@3482
    33
#endif /* !NO_GETOPT */
slouken@3259
    34
slouken@3259
    35
slouken@3259
    36
/*
slouken@3259
    37
 * Tests to run.
slouken@3259
    38
 */
slouken@3259
    39
static int run_manual      = 0; /**< Run manual tests. */
slouken@3259
    40
/* Manual. */
slouken@3259
    41
/* Automatic. */
slouken@3259
    42
static int run_platform    = 1; /**< Run platform tests. */
slouken@3259
    43
static int run_rwops       = 1; /**< Run RWops tests. */
slouken@3259
    44
static int run_surface     = 1; /**< Run surface tests. */
slouken@3259
    45
static int run_render      = 1; /**< Run render tests. */
slouken@3259
    46
static int run_audio       = 1; /**< Run audio tests. */
slouken@3259
    47
slouken@3259
    48
/*
slouken@3259
    49
 * Prototypes.
slouken@3259
    50
 */
slouken@3259
    51
static void print_usage( const char *name );
slouken@3259
    52
static void parse_options( int argc, char *argv[] );
slouken@3259
    53
slouken@3259
    54
slouken@3259
    55
/**
slouken@3259
    56
 * @brief Displays program usage.
slouken@3259
    57
 */
slouken@3482
    58
#ifdef NO_GETOPT
slouken@3482
    59
static void print_usage( const char *name )
slouken@3482
    60
{
slouken@3482
    61
}
slouken@3482
    62
#else
lestat@3460
    63
#if !defined(NO_GETOPT_LONG)
slouken@3259
    64
static void print_usage( const char *name )
slouken@3259
    65
{
slouken@3259
    66
   printf("Usage: %s [OPTIONS]\n", name);
slouken@3259
    67
   printf("Options are:\n");
lestat@3460
    68
   printf("   -m, --manual        enables tests that require user interaction\n");
lestat@3460
    69
   printf("   -p, --noplatform    do not run the platform tests\n");
lestat@3460
    70
   printf("   -o, --norwops       do not run the rwops tests\n");
lestat@3460
    71
   printf("   -s, --nosurface     do not run the surface tests\n");
lestat@3460
    72
   printf("   -r, --norender      do not run the render tests\n");
lestat@3460
    73
   printf("   -a, --noaudio       do not run the audio tests\n");
lestat@3460
    74
   printf("   -v, --verbose       increases verbosity level by 1 for each -v\n");
lestat@3460
    75
   printf("   -q, --quiet         only displays errors\n");
lestat@3460
    76
   printf("   -h, --help          display this message and exit\n");
slouken@3259
    77
}
lestat@3460
    78
#endif /* !NO_GETOPT_LONG */
slouken@3259
    79
lestat@3460
    80
#if defined(NO_GETOPT_LONG)
lestat@3460
    81
static void print_usage( const char *name )
lestat@3460
    82
{
lestat@3460
    83
   printf("Usage: %s [OPTIONS]\n", name);
lestat@3460
    84
   printf("Options are:\n");
lestat@3460
    85
   printf("   -m,     enables tests that require user interaction\n");
lestat@3460
    86
   printf("   -p,     do not run the platform tests\n");
lestat@3460
    87
   printf("   -o,     do not run the rwops tests\n");
lestat@3460
    88
   printf("   -s,     do not run the surface tests\n");
lestat@3460
    89
   printf("   -r,     do not run the render tests\n");
lestat@3460
    90
   printf("   -a,     do not run the audio tests\n");
lestat@3460
    91
   printf("   -v,     increases verbosity level by 1 for each -v\n");
lestat@3460
    92
   printf("   -q,     only displays errors\n");
lestat@3460
    93
   printf("   -h,     display this message and exit\n");
lestat@3460
    94
}
lestat@3460
    95
#endif /* NO_GETOPT_LONG */
slouken@3482
    96
#endif /* NO_GETOPT */
slouken@3259
    97
slouken@3259
    98
/**
slouken@3259
    99
 * @brief Handles the options.
slouken@3259
   100
 */
slouken@3482
   101
#ifdef NO_GETOPT
slouken@3482
   102
static void parse_options( int argc, char *argv[] )
slouken@3482
   103
{
slouken@3482
   104
}
slouken@3482
   105
#else
lestat@3460
   106
#if !defined(NO_GETOPT_LONG)
slouken@3259
   107
static void parse_options( int argc, char *argv[] )
slouken@3259
   108
{
slouken@3259
   109
   static struct option long_options[] = {
slouken@3259
   110
      { "manual", no_argument, 0, 'm' },
lestat@3460
   111
      { "noplatform", no_argument, 0, 'p' },
lestat@3460
   112
      { "norwops", no_argument, 0, 'o' },
lestat@3460
   113
      { "nosurface", no_argument, 0, 's' },
lestat@3460
   114
      { "norender", no_argument, 0, 'r' },
lestat@3460
   115
      { "noaudio", no_argument, 0, 'a' },
slouken@3259
   116
      { "verbose", no_argument, 0, 'v' },
slouken@3259
   117
      { "quiet", no_argument, 0, 'q' },
slouken@3259
   118
      { "help", no_argument, 0, 'h' },
slouken@3259
   119
      {NULL,0,0,0}
slouken@3259
   120
   };
slouken@3259
   121
   int option_index = 0;
slouken@3259
   122
   int c = 0;
slouken@3259
   123
   int i;
slouken@3259
   124
   const char *str;
slouken@3259
   125
slouken@3259
   126
   /* Iterate over options. */
slouken@3259
   127
   while ((c = getopt_long( argc, argv,
lestat@3460
   128
               "mposravqh",
slouken@3259
   129
               long_options, &option_index)) != -1) {
slouken@3259
   130
slouken@3259
   131
      /* Handle options. */
slouken@3259
   132
      switch (c) {
slouken@3259
   133
         case 0:
slouken@3259
   134
            str = long_options[option_index].name;
slouken@3259
   135
            if (strcmp(str,"noplatform")==0)
slouken@3259
   136
               run_platform = 0;
slouken@3259
   137
            else if (strcmp(str,"norwops")==0)
slouken@3259
   138
               run_rwops = 0;
slouken@3259
   139
            else if (strcmp(str,"nosurface")==0)
slouken@3259
   140
               run_surface = 0;
slouken@3259
   141
            else if (strcmp(str,"norender")==0)
slouken@3259
   142
               run_render = 0;
slouken@3259
   143
            else if (strcmp(str,"noaudio")==0)
slouken@3259
   144
               run_audio = 0;
slouken@3259
   145
            break;
slouken@3259
   146
slouken@3259
   147
         /* Manual. */
slouken@3259
   148
         case 'm':
slouken@3259
   149
            run_manual = 1;
slouken@3259
   150
            break;
slouken@3259
   151
lestat@3460
   152
         /* No platform. */
lestat@3460
   153
         case 'p':
lestat@3460
   154
            run_platform = 0;
lestat@3460
   155
            break;
lestat@3460
   156
lestat@3460
   157
         /* No rwops. */
lestat@3460
   158
         case 'o':
lestat@3460
   159
            run_rwops = 0;
lestat@3460
   160
            break;
lestat@3460
   161
lestat@3460
   162
         /* No surface. */
lestat@3460
   163
         case 's':
lestat@3460
   164
            run_surface = 0;
lestat@3460
   165
            break;
lestat@3460
   166
lestat@3460
   167
         /* No render. */
lestat@3460
   168
         case 'r':
lestat@3460
   169
            run_render = 0;
lestat@3460
   170
            break;
lestat@3460
   171
lestat@3460
   172
         /* No audio. */
lestat@3460
   173
         case 'a':
lestat@3460
   174
            run_audio = 0;
lestat@3460
   175
            break;
lestat@3460
   176
slouken@3259
   177
         /* Verbosity. */
slouken@3259
   178
         case 'v':
slouken@3259
   179
            SDL_ATgeti( SDL_AT_VERBOSE, &i );
slouken@3259
   180
            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
slouken@3259
   181
            break;
slouken@3259
   182
slouken@3259
   183
         /* Quiet. */
slouken@3259
   184
         case 'q':
slouken@3259
   185
            SDL_ATseti( SDL_AT_QUIET, 1 );
slouken@3259
   186
            break;
slouken@3259
   187
slouken@3259
   188
         /* Help. */
slouken@3259
   189
         case 'h':
slouken@3259
   190
            print_usage( argv[0] );
slouken@3259
   191
            exit(EXIT_SUCCESS);
slouken@3259
   192
      }
slouken@3259
   193
   }
lestat@3460
   194
}
lestat@3460
   195
#endif /* !NO_GETOPT_LONG */
slouken@3259
   196
lestat@3460
   197
#if defined(NO_GETOPT_LONG)
lestat@3460
   198
static void parse_options( int argc, char *argv[] )
lestat@3460
   199
{
lestat@3460
   200
   static char* short_options="mposravqh";
lestat@3460
   201
   int c = 0;
lestat@3460
   202
   int i;
lestat@3460
   203
lestat@3460
   204
   /* Iterate over options. */
lestat@3460
   205
   while ((c = getopt(argc, argv, short_options)) != -1) {
lestat@3460
   206
      /* Handle options. */
lestat@3460
   207
      switch (c) {
lestat@3460
   208
         /* Manual. */
lestat@3460
   209
         case 'm':
lestat@3460
   210
            run_manual = 1;
lestat@3460
   211
            break;
lestat@3460
   212
lestat@3460
   213
         /* No platform. */
lestat@3460
   214
         case 'p':
lestat@3460
   215
            run_platform = 0;
lestat@3460
   216
            break;
lestat@3460
   217
lestat@3460
   218
         /* No rwops. */
lestat@3460
   219
         case 'o':
lestat@3460
   220
            run_rwops = 0;
lestat@3460
   221
            break;
lestat@3460
   222
lestat@3460
   223
         /* No surface. */
lestat@3460
   224
         case 's':
lestat@3460
   225
            run_surface = 0;
lestat@3460
   226
            break;
lestat@3460
   227
lestat@3460
   228
         /* No render. */
lestat@3460
   229
         case 'r':
lestat@3460
   230
            run_render = 0;
lestat@3460
   231
            break;
lestat@3460
   232
lestat@3460
   233
         /* No audio. */
lestat@3460
   234
         case 'a':
lestat@3460
   235
            run_audio = 0;
lestat@3460
   236
            break;
lestat@3460
   237
lestat@3460
   238
         /* Verbosity. */
lestat@3460
   239
         case 'v':
lestat@3460
   240
            SDL_ATgeti( SDL_AT_VERBOSE, &i );
lestat@3460
   241
            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
lestat@3460
   242
            break;
lestat@3460
   243
lestat@3460
   244
         /* Quiet. */
lestat@3460
   245
         case 'q':
lestat@3460
   246
            SDL_ATseti( SDL_AT_QUIET, 1 );
lestat@3460
   247
            break;
lestat@3460
   248
lestat@3460
   249
         /* Help. */
lestat@3460
   250
         case 'h':
lestat@3460
   251
            print_usage( argv[0] );
lestat@3460
   252
            exit(EXIT_SUCCESS);
lestat@3460
   253
      }
lestat@3460
   254
   }
slouken@3259
   255
}
lestat@3460
   256
#endif /* NO_GETOPT_LONG */
slouken@3482
   257
#endif /* NO_GETOPT */
slouken@3259
   258
slouken@3259
   259
/**
slouken@3259
   260
 * @brief Main entry point.
slouken@3259
   261
 */
slouken@3259
   262
int main( int argc, char *argv[] )
slouken@3259
   263
{
slouken@3259
   264
   int failed;
slouken@3259
   265
   int rev;
slouken@3259
   266
   SDL_version ver;
slouken@3259
   267
slouken@3259
   268
   /* Get options. */
slouken@3259
   269
   parse_options( argc, argv );
slouken@3259
   270
slouken@3259
   271
   /* Defaults. */
slouken@3259
   272
   failed = 0;
slouken@3259
   273
slouken@3259
   274
   /* Print some text if verbose. */
slouken@3259
   275
   SDL_GetVersion( &ver );
slouken@3259
   276
   rev = SDL_GetRevision();
slouken@3259
   277
   SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
slouken@3259
   278
         ver.major, ver.minor, ver.patch, rev );
slouken@3259
   279
slouken@3259
   280
   /* Automatic tests. */
slouken@3259
   281
   if (run_platform)
slouken@3259
   282
      failed += test_platform();
slouken@3259
   283
   if (run_rwops)
slouken@3259
   284
      failed += test_rwops();
slouken@3259
   285
   if (run_surface)
slouken@3259
   286
      failed += test_surface();
slouken@3259
   287
   if (run_render)
slouken@3259
   288
      failed += test_render();
slouken@3259
   289
   if (run_audio)
slouken@3259
   290
      failed += test_audio();
slouken@3259
   291
slouken@3259
   292
   /* Manual tests. */
slouken@3259
   293
   if (run_manual) {
slouken@3259
   294
   }
slouken@3259
   295
slouken@3259
   296
   /* Display more information if failed. */
slouken@3259
   297
   if (failed > 0) {
slouken@3259
   298
      SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
slouken@3259
   299
            ver.major, ver.minor, ver.patch, rev );
slouken@3259
   300
      SDL_ATprintErr( "System is running %s and is %s endian\n",
slouken@3319
   301
            SDL_GetPlatform(),
slouken@3482
   302
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3259
   303
            "little"
slouken@3259
   304
#else
slouken@3259
   305
            "big"
slouken@3259
   306
#endif
slouken@3259
   307
            );
slouken@3259
   308
   }
slouken@3259
   309
slouken@3259
   310
   return failed;
slouken@3259
   311
}
slouken@3259
   312