test/automated/testsdl.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 26 Sep 2009 10:32:14 +0000
changeset 3319 63d4517fc4ac
parent 3259 22ac66da0765
child 3460 ba48701b0534
permissions -rw-r--r--
Fixed bug #777

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