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