test/automated/testsdl.c
changeset 3259 22ac66da0765
child 3319 63d4517fc4ac
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/automated/testsdl.c	Mon Sep 07 05:06:34 2009 +0000
     1.3 @@ -0,0 +1,186 @@
     1.4 +/*
     1.5 + * SDL test suite framework code.
     1.6 + *
     1.7 + * Written by Edgar Simo "bobbens"
     1.8 + *
     1.9 + * Released under Public Domain.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#include "SDL.h"
    1.14 +#include "SDL_at.h"
    1.15 +
    1.16 +#include "platform/platform.h"
    1.17 +#include "rwops/rwops.h"
    1.18 +#include "surface/surface.h"
    1.19 +#include "render/render.h"
    1.20 +#include "audio/audio.h"
    1.21 +
    1.22 +#include <stdio.h> /* printf */
    1.23 +#include <stdlib.h> /* exit */
    1.24 +#include <unistd.h> /* getopt */
    1.25 +#include <getopt.h> /* getopt_long */
    1.26 +#include <string.h> /* strcmp */
    1.27 +
    1.28 +
    1.29 +/*
    1.30 + * Tests to run.
    1.31 + */
    1.32 +static int run_manual      = 0; /**< Run manual tests. */
    1.33 +/* Manual. */
    1.34 +/* Automatic. */
    1.35 +static int run_platform    = 1; /**< Run platform tests. */
    1.36 +static int run_rwops       = 1; /**< Run RWops tests. */
    1.37 +static int run_surface     = 1; /**< Run surface tests. */
    1.38 +static int run_render      = 1; /**< Run render tests. */
    1.39 +static int run_audio       = 1; /**< Run audio tests. */
    1.40 +
    1.41 +/*
    1.42 + * Prototypes.
    1.43 + */
    1.44 +static void print_usage( const char *name );
    1.45 +static void parse_options( int argc, char *argv[] );
    1.46 +
    1.47 +
    1.48 +/**
    1.49 + * @brief Displays program usage.
    1.50 + */
    1.51 +static void print_usage( const char *name )
    1.52 +{
    1.53 +   printf("Usage: %s [OPTIONS]\n", name);
    1.54 +   printf("Options are:\n");
    1.55 +   printf("   -m, --manual    enables tests that require user interaction\n");
    1.56 +   printf("   --noplatform    do not run the platform tests\n");
    1.57 +   printf("   --norwops       do not run the rwops tests\n");
    1.58 +   printf("   --nosurface     do not run the surface tests\n");
    1.59 +   printf("   --norender      do not run the render tests\n");
    1.60 +   printf("   --noaudio       do not run the audio tests\n");
    1.61 +   printf("   -v, --verbose   increases verbosity level by 1 for each -v\n");
    1.62 +   printf("   -q, --quiet     only displays errors\n");
    1.63 +   printf("   -h, --help      display this message and exit\n");
    1.64 +}
    1.65 +
    1.66 +
    1.67 +/**
    1.68 + * @brief Handles the options.
    1.69 + */
    1.70 +static void parse_options( int argc, char *argv[] )
    1.71 +{
    1.72 +   static struct option long_options[] = {
    1.73 +      { "manual", no_argument, 0, 'm' },
    1.74 +      { "noplatform", no_argument, 0, 0 },
    1.75 +      { "norwops", no_argument, 0, 0 },
    1.76 +      { "nosurface", no_argument, 0, 0 },
    1.77 +      { "norender", no_argument, 0, 0 },
    1.78 +      { "noaudio", no_argument, 0, 0 },
    1.79 +      { "verbose", no_argument, 0, 'v' },
    1.80 +      { "quiet", no_argument, 0, 'q' },
    1.81 +      { "help", no_argument, 0, 'h' },
    1.82 +      {NULL,0,0,0}
    1.83 +   };
    1.84 +   int option_index = 0;
    1.85 +   int c = 0;
    1.86 +   int i;
    1.87 +   const char *str;
    1.88 +
    1.89 +   /* Iterate over options. */
    1.90 +   while ((c = getopt_long( argc, argv,
    1.91 +               "vqh",
    1.92 +               long_options, &option_index)) != -1) {
    1.93 +
    1.94 +      /* Handle options. */
    1.95 +      switch (c) {
    1.96 +         case 0:
    1.97 +            str = long_options[option_index].name;
    1.98 +            if (strcmp(str,"noplatform")==0)
    1.99 +               run_platform = 0;
   1.100 +            else if (strcmp(str,"norwops")==0)
   1.101 +               run_rwops = 0;
   1.102 +            else if (strcmp(str,"nosurface")==0)
   1.103 +               run_surface = 0;
   1.104 +            else if (strcmp(str,"norender")==0)
   1.105 +               run_render = 0;
   1.106 +            else if (strcmp(str,"noaudio")==0)
   1.107 +               run_audio = 0;
   1.108 +            break;
   1.109 +
   1.110 +         /* Manual. */
   1.111 +         case 'm':
   1.112 +            run_manual = 1;
   1.113 +            break;
   1.114 +
   1.115 +         /* Verbosity. */
   1.116 +         case 'v':
   1.117 +            SDL_ATgeti( SDL_AT_VERBOSE, &i );
   1.118 +            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
   1.119 +            break;
   1.120 +
   1.121 +         /* Quiet. */
   1.122 +         case 'q':
   1.123 +            SDL_ATseti( SDL_AT_QUIET, 1 );
   1.124 +            break;
   1.125 +
   1.126 +         /* Help. */
   1.127 +         case 'h':
   1.128 +            print_usage( argv[0] );
   1.129 +            exit(EXIT_SUCCESS);
   1.130 +      }
   1.131 +   }
   1.132 +
   1.133 +}
   1.134 +
   1.135 +
   1.136 +/**
   1.137 + * @brief Main entry point.
   1.138 + */
   1.139 +int main( int argc, char *argv[] )
   1.140 +{
   1.141 +   int failed;
   1.142 +   int rev;
   1.143 +   SDL_version ver;
   1.144 +
   1.145 +   /* Get options. */
   1.146 +   parse_options( argc, argv );
   1.147 +
   1.148 +   /* Defaults. */
   1.149 +   failed = 0;
   1.150 +
   1.151 +   /* Print some text if verbose. */
   1.152 +   SDL_GetVersion( &ver );
   1.153 +   rev = SDL_GetRevision();
   1.154 +   SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
   1.155 +         ver.major, ver.minor, ver.patch, rev );
   1.156 +
   1.157 +   /* Automatic tests. */
   1.158 +   if (run_platform)
   1.159 +      failed += test_platform();
   1.160 +   if (run_rwops)
   1.161 +      failed += test_rwops();
   1.162 +   if (run_surface)
   1.163 +      failed += test_surface();
   1.164 +   if (run_render)
   1.165 +      failed += test_render();
   1.166 +   if (run_audio)
   1.167 +      failed += test_audio();
   1.168 +
   1.169 +   /* Manual tests. */
   1.170 +   if (run_manual) {
   1.171 +   }
   1.172 +
   1.173 +   /* Display more information if failed. */
   1.174 +   if (failed > 0) {
   1.175 +      SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
   1.176 +            ver.major, ver.minor, ver.patch, rev );
   1.177 +      SDL_ATprintErr( "System is running %s and is %s endian\n",
   1.178 +            platform_getPlatform(),
   1.179 +#ifdef SDL_LIL_ENDIAN
   1.180 +            "little"
   1.181 +#else
   1.182 +            "big"
   1.183 +#endif
   1.184 +            );
   1.185 +   }
   1.186 +
   1.187 +   return failed;
   1.188 +}
   1.189 +