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