Better error handling. gsoc2009_unit_tests
authorEdgar Simo <bobbens@gmail.com>
Wed, 05 Aug 2009 18:56:56 +0000
branchgsoc2009_unit_tests
changeset 3752 f47658c8f87a
parent 3751 4a58821c9c98
child 3753 5b48a529fd8a
Better error handling.
test/automated/SDL_at.c
--- a/test/automated/SDL_at.c	Wed Aug 05 18:45:55 2009 +0000
+++ b/test/automated/SDL_at.c	Wed Aug 05 18:56:56 2009 +0000
@@ -31,6 +31,14 @@
 static int at_quiet = 0; /**< Quietness. */
 
 
+/*
+ * Prototypes.
+ */
+static void SDL_ATcleanup (void);
+static void SDL_ATendWith( int success );
+static void SDL_ATassertFailed( const char *msg );
+
+
 /**
  * @brief Cleans up the automated testsuite state.
  */
@@ -193,16 +201,29 @@
 
 
 /**
+ * @brief Display failed assert message.
+ */
+static void SDL_ATassertFailed( const char *msg )
+{
+   /* Print. */
+   SDL_ATprintErr( "Assert Failed!\n" );
+   SDL_ATprintErr( "   %s\n", msg );
+   SDL_ATprintErr( "   Test Case '%s'\n", at_test_msg );
+   SDL_ATprintErr( "   Test Suite '%s'\n", at_suite_msg );
+   /* End. */
+   SDL_ATendWith(0);
+}
+
+
+/**
  * @brief Testcase test.
  */
 int SDL_ATassert( const char *msg, int condition )
 {
    /* Condition failed. */
    if (!condition) {
-      /* Print. */
-      SDL_ATprintErr( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg );
-      /* End. */
-      SDL_ATendWith(0);
+      /* Failed message. */
+      SDL_ATassertFailed(msg);
    }
    return !condition;
 }
@@ -222,10 +243,8 @@
       va_start( args, msg );
       vsnprintf( buf, sizeof(buf), msg, args );
       va_end( args );
-      /* Print. */
-      SDL_ATprintErr( "%s [%s] : %s\n", at_suite_msg, at_test_msg, buf );
-      /* End. */
-      SDL_ATendWith(0);
+      /* Failed message. */
+      SDL_ATassertFailed( buf );
    }
    return !condition;
 }