test/automated/testsdl.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 23 Dec 2009 01:55:00 +0000
changeset 3596 f638ded38b8a
parent 3541 0c429a5fda8a
child 3658 1a99755b3b04
permissions -rw-r--r--
Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color.
Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine().
Added API for rectangle drawing (as opposed to filling)
Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay.
Optimized software line drawing quite a bit.
Added support for Wu's anti-aliased line drawing, currently disabled by default.
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@3541
    96
         continue;
slouken@3541
    97
      }
slouken@3541
    98
      if (SDL_strcmp(arg, "--noplatform") == 0) {
slouken@3541
    99
         run_platform = 0;
slouken@3541
   100
         continue;
slouken@3541
   101
      }
slouken@3541
   102
      if (SDL_strcmp(arg, "--norwops") == 0) {
slouken@3541
   103
         run_rwops = 0;
slouken@3541
   104
         continue;
slouken@3541
   105
      }
slouken@3541
   106
      if (SDL_strcmp(arg, "--norect") == 0) {
slouken@3541
   107
         run_rect = 0;
slouken@3541
   108
         continue;
slouken@3541
   109
      }
slouken@3541
   110
      if (SDL_strcmp(arg, "--nosurface") == 0) {
slouken@3541
   111
         run_surface = 0;
slouken@3541
   112
         continue;
slouken@3541
   113
      }
slouken@3541
   114
      if (SDL_strcmp(arg, "--norender") == 0) {
slouken@3541
   115
         run_render = 0;
slouken@3541
   116
         continue;
slouken@3541
   117
      }
slouken@3541
   118
      if (SDL_strcmp(arg, "--noaudio") == 0) {
slouken@3541
   119
         run_audio = 0;
slouken@3541
   120
         continue;
slouken@3541
   121
      }
slouken@3259
   122
slouken@3541
   123
      /* Print help and exit! */
slouken@3541
   124
      print_usage( argv[0] );
slouken@3541
   125
      exit(EXIT_FAILURE);
slouken@3259
   126
   }
lestat@3460
   127
}
slouken@3259
   128
slouken@3259
   129
/**
slouken@3259
   130
 * @brief Main entry point.
slouken@3259
   131
 */
slouken@3259
   132
int main( int argc, char *argv[] )
slouken@3259
   133
{
slouken@3259
   134
   int failed;
slouken@3259
   135
   int rev;
slouken@3259
   136
   SDL_version ver;
slouken@3259
   137
slouken@3259
   138
   /* Get options. */
slouken@3259
   139
   parse_options( argc, argv );
slouken@3259
   140
slouken@3259
   141
   /* Defaults. */
slouken@3259
   142
   failed = 0;
slouken@3259
   143
slouken@3259
   144
   /* Print some text if verbose. */
slouken@3259
   145
   SDL_GetVersion( &ver );
slouken@3259
   146
   rev = SDL_GetRevision();
slouken@3259
   147
   SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
slouken@3259
   148
         ver.major, ver.minor, ver.patch, rev );
slouken@3259
   149
slouken@3259
   150
   /* Automatic tests. */
slouken@3259
   151
   if (run_platform)
slouken@3259
   152
      failed += test_platform();
slouken@3259
   153
   if (run_rwops)
slouken@3259
   154
      failed += test_rwops();
slouken@3541
   155
   if (run_rect)
slouken@3541
   156
      failed += test_rect();
slouken@3259
   157
   if (run_surface)
slouken@3259
   158
      failed += test_surface();
slouken@3259
   159
   if (run_render)
slouken@3259
   160
      failed += test_render();
slouken@3259
   161
   if (run_audio)
slouken@3259
   162
      failed += test_audio();
slouken@3259
   163
slouken@3259
   164
   /* Manual tests. */
slouken@3259
   165
   if (run_manual) {
slouken@3259
   166
   }
slouken@3259
   167
slouken@3259
   168
   /* Display more information if failed. */
slouken@3259
   169
   if (failed > 0) {
slouken@3259
   170
      SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
slouken@3259
   171
            ver.major, ver.minor, ver.patch, rev );
slouken@3259
   172
      SDL_ATprintErr( "System is running %s and is %s endian\n",
slouken@3319
   173
            SDL_GetPlatform(),
slouken@3482
   174
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@3259
   175
            "little"
slouken@3259
   176
#else
slouken@3259
   177
            "big"
slouken@3259
   178
#endif
slouken@3259
   179
            );
slouken@3259
   180
   }
slouken@3259
   181
slouken@3259
   182
   return failed;
slouken@3259
   183
}
slouken@3259
   184