diff test/automated/testsdl.c @ 3541:0c429a5fda8a

Added an automated test for rectangle routines, currently only testing line clipping. Use the Cohen-Sutherland algorithm for line clipping which uses integer math and preserves ordering of clipped points. Removed getopt() support in testsdl.c, replaced with simple argv scanning.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Dec 2009 09:22:34 +0000
parents 78db4f7ae2f3
children f638ded38b8a
line wrap: on
line diff
--- a/test/automated/testsdl.c	Fri Dec 11 09:13:51 2009 +0000
+++ b/test/automated/testsdl.c	Fri Dec 11 09:22:34 2009 +0000
@@ -12,6 +12,7 @@
 
 #include "platform/platform.h"
 #include "rwops/rwops.h"
+#include "rect/rect.h"
 #include "surface/surface.h"
 #include "render/render.h"
 #include "audio/audio.h"
@@ -41,6 +42,7 @@
 /* Automatic. */
 static int run_platform    = 1; /**< Run platform tests. */
 static int run_rwops       = 1; /**< Run RWops tests. */
+static int run_rect        = 1; /**< Run rect tests. */
 static int run_surface     = 1; /**< Run surface tests. */
 static int run_render      = 1; /**< Run render tests. */
 static int run_audio       = 1; /**< Run audio tests. */
@@ -55,206 +57,75 @@
 /**
  * @brief Displays program usage.
  */
-#ifdef NO_GETOPT
-static void print_usage( const char *name )
-{
-}
-#else
-#if !defined(NO_GETOPT_LONG)
 static void print_usage( const char *name )
 {
    printf("Usage: %s [OPTIONS]\n", name);
    printf("Options are:\n");
    printf("   -m, --manual        enables tests that require user interaction\n");
-   printf("   -p, --noplatform    do not run the platform tests\n");
-   printf("   -o, --norwops       do not run the rwops tests\n");
-   printf("   -s, --nosurface     do not run the surface tests\n");
-   printf("   -r, --norender      do not run the render tests\n");
-   printf("   -a, --noaudio       do not run the audio tests\n");
+   printf("   --noplatform        do not run the platform tests\n");
+   printf("   --norwops           do not run the rwops tests\n");
+   printf("   --norect            do not run the rect tests\n");
+   printf("   --nosurface         do not run the surface tests\n");
+   printf("   --norender          do not run the render tests\n");
+   printf("   --noaudio           do not run the audio tests\n");
    printf("   -v, --verbose       increases verbosity level by 1 for each -v\n");
    printf("   -q, --quiet         only displays errors\n");
    printf("   -h, --help          display this message and exit\n");
 }
-#endif /* !NO_GETOPT_LONG */
-
-#if defined(NO_GETOPT_LONG)
-static void print_usage( const char *name )
-{
-   printf("Usage: %s [OPTIONS]\n", name);
-   printf("Options are:\n");
-   printf("   -m,     enables tests that require user interaction\n");
-   printf("   -p,     do not run the platform tests\n");
-   printf("   -o,     do not run the rwops tests\n");
-   printf("   -s,     do not run the surface tests\n");
-   printf("   -r,     do not run the render tests\n");
-   printf("   -a,     do not run the audio tests\n");
-   printf("   -v,     increases verbosity level by 1 for each -v\n");
-   printf("   -q,     only displays errors\n");
-   printf("   -h,     display this message and exit\n");
-}
-#endif /* NO_GETOPT_LONG */
-#endif /* NO_GETOPT */
 
 /**
  * @brief Handles the options.
  */
-#ifdef NO_GETOPT
-static void parse_options( int argc, char *argv[] )
-{
-}
-#else
-#if !defined(NO_GETOPT_LONG)
 static void parse_options( int argc, char *argv[] )
 {
-   static struct option long_options[] = {
-      { "manual", no_argument, 0, 'm' },
-      { "noplatform", no_argument, 0, 'p' },
-      { "norwops", no_argument, 0, 'o' },
-      { "nosurface", no_argument, 0, 's' },
-      { "norender", no_argument, 0, 'r' },
-      { "noaudio", no_argument, 0, 'a' },
-      { "verbose", no_argument, 0, 'v' },
-      { "quiet", no_argument, 0, 'q' },
-      { "help", no_argument, 0, 'h' },
-      {NULL,0,0,0}
-   };
-   int option_index = 0;
-   int c = 0;
    int i;
-   const char *str;
-
-   /* Iterate over options. */
-   while ((c = getopt_long( argc, argv,
-               "mposravqh",
-               long_options, &option_index)) != -1) {
-
-      /* Handle options. */
-      switch (c) {
-         case 0:
-            str = long_options[option_index].name;
-            if (strcmp(str,"noplatform")==0)
-               run_platform = 0;
-            else if (strcmp(str,"norwops")==0)
-               run_rwops = 0;
-            else if (strcmp(str,"nosurface")==0)
-               run_surface = 0;
-            else if (strcmp(str,"norender")==0)
-               run_render = 0;
-            else if (strcmp(str,"noaudio")==0)
-               run_audio = 0;
-            break;
 
-         /* Manual. */
-         case 'm':
-            run_manual = 1;
-            break;
-
-         /* No platform. */
-         case 'p':
-            run_platform = 0;
-            break;
-
-         /* No rwops. */
-         case 'o':
-            run_rwops = 0;
-            break;
-
-         /* No surface. */
-         case 's':
-            run_surface = 0;
-            break;
+   for (i = 1; i < argc; ++i) {
+      const char *arg = argv[i];
+      if (SDL_strcmp(arg, "-m") == 0 || SDL_strcmp(arg, "--manual") == 0) {
+         run_manual = 1;
+         continue;
+      }
+      if (SDL_strcmp(arg, "-v") == 0 || SDL_strcmp(arg, "--verbose") == 0) {
+         int level;
+         SDL_ATgeti( SDL_AT_VERBOSE, &level );
+         SDL_ATseti( SDL_AT_VERBOSE, level+1 );
+         continue;
+      }
+      if (SDL_strcmp(arg, "-q") == 0 || SDL_strcmp(arg, "--quiet") == 0) {
+         SDL_ATseti( SDL_AT_QUIET, 1 );
+         continue;
+      }
+      if (SDL_strcmp(arg, "--noplatform") == 0) {
+         run_platform = 0;
+         continue;
+      }
+      if (SDL_strcmp(arg, "--norwops") == 0) {
+         run_rwops = 0;
+         continue;
+      }
+      if (SDL_strcmp(arg, "--norect") == 0) {
+         run_rect = 0;
+         continue;
+      }
+      if (SDL_strcmp(arg, "--nosurface") == 0) {
+         run_surface = 0;
+         continue;
+      }
+      if (SDL_strcmp(arg, "--norender") == 0) {
+         run_render = 0;
+         continue;
+      }
+      if (SDL_strcmp(arg, "--noaudio") == 0) {
+         run_audio = 0;
+         continue;
+      }
 
-         /* No render. */
-         case 'r':
-            run_render = 0;
-            break;
-
-         /* No audio. */
-         case 'a':
-            run_audio = 0;
-            break;
-
-         /* Verbosity. */
-         case 'v':
-            SDL_ATgeti( SDL_AT_VERBOSE, &i );
-            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
-            break;
-
-         /* Quiet. */
-         case 'q':
-            SDL_ATseti( SDL_AT_QUIET, 1 );
-            break;
-
-         /* Help. */
-         case 'h':
-            print_usage( argv[0] );
-            exit(EXIT_SUCCESS);
-      }
+      /* Print help and exit! */
+      print_usage( argv[0] );
+      exit(EXIT_FAILURE);
    }
 }
-#endif /* !NO_GETOPT_LONG */
-
-#if defined(NO_GETOPT_LONG)
-static void parse_options( int argc, char *argv[] )
-{
-   static char* short_options="mposravqh";
-   int c = 0;
-   int i;
-
-   /* Iterate over options. */
-   while ((c = getopt(argc, argv, short_options)) != -1) {
-      /* Handle options. */
-      switch (c) {
-         /* Manual. */
-         case 'm':
-            run_manual = 1;
-            break;
-
-         /* No platform. */
-         case 'p':
-            run_platform = 0;
-            break;
-
-         /* No rwops. */
-         case 'o':
-            run_rwops = 0;
-            break;
-
-         /* No surface. */
-         case 's':
-            run_surface = 0;
-            break;
-
-         /* No render. */
-         case 'r':
-            run_render = 0;
-            break;
-
-         /* No audio. */
-         case 'a':
-            run_audio = 0;
-            break;
-
-         /* Verbosity. */
-         case 'v':
-            SDL_ATgeti( SDL_AT_VERBOSE, &i );
-            SDL_ATseti( SDL_AT_VERBOSE, i+1 );
-            break;
-
-         /* Quiet. */
-         case 'q':
-            SDL_ATseti( SDL_AT_QUIET, 1 );
-            break;
-
-         /* Help. */
-         case 'h':
-            print_usage( argv[0] );
-            exit(EXIT_SUCCESS);
-      }
-   }
-}
-#endif /* NO_GETOPT_LONG */
-#endif /* NO_GETOPT */
 
 /**
  * @brief Main entry point.
@@ -282,6 +153,8 @@
       failed += test_platform();
    if (run_rwops)
       failed += test_rwops();
+   if (run_rect)
+      failed += test_rect();
    if (run_surface)
       failed += test_surface();
    if (run_render)