test/automated/testsdl.c
author David Ludwig <dludwig@pobox.com>
Tue, 12 Feb 2013 12:57:06 -0500
changeset 8424 3cf9501008f1
parent 4478 c84712de8433
permissions -rw-r--r--
WinRT: fixed bug: SDL_CreateWindow wouldn't work after an initial window was created + destroyed
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
#include "SDL.h"
slouken@3259
    10
#include "SDL_at.h"
slouken@3259
    11
slouken@3259
    12
#include "platform/platform.h"
slouken@3259
    13
#include "rwops/rwops.h"
slouken@3541
    14
#include "rect/rect.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@3541
    44
static int run_rect        = 1; /**< Run rect tests. */
slouken@3259
    45
static int run_surface     = 1; /**< Run surface tests. */
slouken@3259
    46
static int run_render      = 1; /**< Run render tests. */
slouken@3259
    47
static int run_audio       = 1; /**< Run audio tests. */
slouken@3259
    48
slouken@3259
    49
/*
slouken@3259
    50
 * Prototypes.
slouken@3259
    51
 */
slouken@3259
    52
static void print_usage( const char *name );
slouken@3259
    53
static void parse_options( int argc, char *argv[] );
slouken@3259
    54
slouken@3259
    55
slouken@3259
    56
/**
slouken@3259
    57
 * @brief Displays program usage.
slouken@3259
    58
 */
slouken@3259
    59
static void print_usage( const char *name )
slouken@3259
    60
{
slouken@3259
    61
   printf("Usage: %s [OPTIONS]\n", name);
slouken@3259
    62
   printf("Options are:\n");
lestat@3460
    63
   printf("   -m, --manual        enables tests that require user interaction\n");
slouken@3541
    64
   printf("   --noplatform        do not run the platform tests\n");
slouken@3541
    65
   printf("   --norwops           do not run the rwops tests\n");
slouken@3541
    66
   printf("   --norect            do not run the rect tests\n");
slouken@3541
    67
   printf("   --nosurface         do not run the surface tests\n");
slouken@3541
    68
   printf("   --norender          do not run the render tests\n");
slouken@3541
    69
   printf("   --noaudio           do not run the audio tests\n");
lestat@3460
    70
   printf("   -v, --verbose       increases verbosity level by 1 for each -v\n");
lestat@3460
    71
   printf("   -q, --quiet         only displays errors\n");
lestat@3460
    72
   printf("   -h, --help          display this message and exit\n");
slouken@3259
    73
}
slouken@3259
    74
slouken@3259
    75
/**
slouken@3259
    76
 * @brief Handles the options.
slouken@3259
    77
 */
slouken@3482
    78
static void parse_options( int argc, char *argv[] )
slouken@3482
    79
{
slouken@3259
    80
   int i;
slouken@3259
    81
slouken@3541
    82
   for (i = 1; i < argc; ++i) {
slouken@3541
    83
      const char *arg = argv[i];
slouken@3541
    84
      if (SDL_strcmp(arg, "-m") == 0 || SDL_strcmp(arg, "--manual") == 0) {
slouken@3541
    85
         run_manual = 1;
slouken@3541
    86
         continue;
slouken@3541
    87
      }
slouken@3541
    88
      if (SDL_strcmp(arg, "-v") == 0 || SDL_strcmp(arg, "--verbose") == 0) {
slouken@3541
    89
         int level;
slouken@3541
    90
         SDL_ATgeti( SDL_AT_VERBOSE, &level );
slouken@3541
    91
         SDL_ATseti( SDL_AT_VERBOSE, level+1 );
slouken@3541
    92
         continue;
slouken@3541
    93
      }
slouken@3541
    94
      if (SDL_strcmp(arg, "-q") == 0 || SDL_strcmp(arg, "--quiet") == 0) {
slouken@3541
    95
         SDL_ATseti( SDL_AT_QUIET, 1 );
slouken@3658
    96
         SDL_setenv("SDL_ASSERT", "abort", 0);
slouken@3541
    97
         continue;
slouken@3541
    98
      }
slouken@3541
    99
      if (SDL_strcmp(arg, "--noplatform") == 0) {
slouken@3541
   100
         run_platform = 0;
slouken@3541
   101
         continue;
slouken@3541
   102
      }
slouken@3541
   103
      if (SDL_strcmp(arg, "--norwops") == 0) {
slouken@3541
   104
         run_rwops = 0;
slouken@3541
   105
         continue;
slouken@3541
   106
      }
slouken@3541
   107
      if (SDL_strcmp(arg, "--norect") == 0) {
slouken@3541
   108
         run_rect = 0;
slouken@3541
   109
         continue;
slouken@3541
   110
      }
slouken@3541
   111
      if (SDL_strcmp(arg, "--nosurface") == 0) {
slouken@3541
   112
         run_surface = 0;
slouken@3541
   113
         continue;
slouken@3541
   114
      }
slouken@3541
   115
      if (SDL_strcmp(arg, "--norender") == 0) {
slouken@3541
   116
         run_render = 0;
slouken@3541
   117
         continue;
slouken@3541
   118
      }
slouken@3541
   119
      if (SDL_strcmp(arg, "--noaudio") == 0) {
slouken@3541
   120
         run_audio = 0;
slouken@3541
   121
         continue;
slouken@3541
   122
      }
slouken@3259
   123
slouken@3541
   124
      /* Print help and exit! */
slouken@3541
   125
      print_usage( argv[0] );
slouken@3541
   126
      exit(EXIT_FAILURE);
slouken@3259
   127
   }
lestat@3460
   128
}
slouken@3259
   129
slouken@3259
   130
/**
slouken@3259
   131
 * @brief Main entry point.
slouken@3259
   132
 */
slouken@3259
   133
int main( int argc, char *argv[] )
slouken@3259
   134
{
slouken@3259
   135
   int failed;
slouken@4478
   136
   const char *rev;
slouken@3259
   137
   SDL_version ver;
slouken@3259
   138
slouken@3259
   139
   /* Get options. */
slouken@3259
   140
   parse_options( argc, argv );
slouken@3259
   141
slouken@3259
   142
   /* Defaults. */
slouken@3259
   143
   failed = 0;
slouken@3259
   144
slouken@3259
   145
   /* Print some text if verbose. */
slouken@3259
   146
   SDL_GetVersion( &ver );
slouken@3259
   147
   rev = SDL_GetRevision();
slouken@4478
   148
   SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %s\n",
slouken@3259
   149
         ver.major, ver.minor, ver.patch, rev );
slouken@3259
   150
slouken@3259
   151
   /* Automatic tests. */
slouken@3259
   152
   if (run_platform)
slouken@3259
   153
      failed += test_platform();
slouken@3259
   154
   if (run_rwops)
slouken@3259
   155
      failed += test_rwops();
slouken@3541
   156
   if (run_rect)
slouken@3541
   157
      failed += test_rect();
slouken@3259
   158
   if (run_surface)
slouken@3259
   159
      failed += test_surface();
slouken@3259
   160
   if (run_render)
slouken@3259
   161
      failed += test_render();
slouken@3259
   162
   if (run_audio)
slouken@3259
   163
      failed += test_audio();
slouken@3259
   164
slouken@3259
   165
   /* Manual tests. */
slouken@3259
   166
   if (run_manual) {
slouken@3259
   167
   }
slouken@3259
   168
slouken@3259
   169
   /* Display more information if failed. */
slouken@3259
   170
   if (failed > 0) {
slouken@3259
   171
      SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
slouken@3259
   172
            ver.major, ver.minor, ver.patch, rev );
slouken@3259
   173
      SDL_ATprintErr( "System is running %s and is %s endian\n",
slouken@3319
   174
            SDL_GetPlatform(),
slouken@3482
   175
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3259
   176
            "little"
slouken@3259
   177
#else
slouken@3259
   178
            "big"
slouken@3259
   179
#endif
slouken@3259
   180
            );
slouken@3259
   181
   }
slouken@3259
   182
slouken@3259
   183
   return failed;
slouken@3259
   184
}
slouken@3259
   185