Added SDL_ATvassert for printf style printing. gsoc2009_unit_tests
authorEdgar Simo <bobbens@gmail.com>
Sat, 11 Jul 2009 18:54:03 +0000
branchgsoc2009_unit_tests
changeset 37256eca2af6a86b
parent 3724 48e2b67bb2de
child 3726 ffe22900a50a
Added SDL_ATvassert for printf style printing.
Check to see if testcase is closed before finishing testsuite.
test/automated/SDL_at.c
test/automated/SDL_at.h
     1.1 --- a/test/automated/SDL_at.c	Sat Jul 11 17:57:49 2009 +0000
     1.2 +++ b/test/automated/SDL_at.c	Sat Jul 11 18:54:03 2009 +0000
     1.3 @@ -66,6 +66,12 @@
     1.4        return 1;
     1.5     }
     1.6  
     1.7 +   /* Finished without closing testcase. */
     1.8 +   if (at_test_msg) {
     1.9 +      SDL_ATprint( "AT suite '%s' finished without closing testcase '%s'\n",
    1.10 +            ac_suite_msg, ac_test_msg );
    1.11 +   }
    1.12 +
    1.13     /* Display message if verbose on failed. */
    1.14     failed = at_failure;
    1.15     if (verbose) {
    1.16 @@ -134,7 +140,32 @@
    1.17  {
    1.18     /* Condition failed. */
    1.19     if (!condition) {
    1.20 +      /* Print. */
    1.21        SDL_ATprint( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg );
    1.22 +      /* End. */
    1.23 +      SDL_ATendWith(0);
    1.24 +   }
    1.25 +   return !condition;
    1.26 +}
    1.27 +
    1.28 +
    1.29 +/**
    1.30 + * @brief Testcase test.
    1.31 + */
    1.32 +int SDL_ATvassert( int condition, const char *msg, ... )
    1.33 +{
    1.34 +   va_list args;
    1.35 +   char buf[256];
    1.36 +
    1.37 +   /* Condition failed. */
    1.38 +   if (!condition) {
    1.39 +      /* Get message. */
    1.40 +      va_start( args, msg );
    1.41 +      vsnprintf( buf, sizeof(buf), msg, args );
    1.42 +      va_end( args );
    1.43 +      /* Print. */
    1.44 +      SDL_ATprint( "%s [%s] : %s\n", at_suite_msg, at_test_msg, buf );
    1.45 +      /* End. */
    1.46        SDL_ATendWith(0);
    1.47     }
    1.48     return !condition;
     2.1 --- a/test/automated/SDL_at.h	Sat Jul 11 17:57:49 2009 +0000
     2.2 +++ b/test/automated/SDL_at.h	Sat Jul 11 18:54:03 2009 +0000
     2.3 @@ -20,11 +20,11 @@
     2.4   * SDL_ATinit( "My testsuite" );
     2.5   *
     2.6   * SDL_ATbegin( "My first testcase" );
     2.7 - * if (!SDL_ATassert( "Trying '1+1=2'.", (1+1)==2))
     2.8 + * if (!SDL_ATassert( (1+1)==2, "Trying '1+1=2'."))
     2.9   *    return;
    2.10   *
    2.11   * SDL_ATbegin( "My second testcase" );
    2.12 - * if (!SDL_ATassert( "Trying '4/2=2'.", (4/2)==2))
    2.13 + * if (!SDL_ATassert( (4/2)==2, "Trying '4/2=2'."))
    2.14   *    return;
    2.15   *
    2.16   * f = SDL_ATend();
    2.17 @@ -69,12 +69,22 @@
    2.18   *
    2.19   * Will automatically call SDL_ATend if the condition isn't met.
    2.20   *
    2.21 + *    @param condition Condition to make sure is true.
    2.22   *    @param msg Message to display for failure.
    2.23 - *    @param condition Condition to make sure is true.
    2.24   *    @return Returns 1 if the condition isn't met.
    2.25   */
    2.26  int SDL_ATassert( const char *msg, int condition );
    2.27  /**
    2.28 + * @brief Checks a condition in the testcase.
    2.29 + *
    2.30 + * Will automatically call SDL_ATend if the condition isn't met.
    2.31 + *
    2.32 + *    @param condition Condition to make sure is true.
    2.33 + *    @param msg Message to display for failure with printf style formatting.
    2.34 + *    @return Returns 1 if the condition isn't met.
    2.35 + */
    2.36 +int SDL_ATvassert( int condition, const char *msg, ... );
    2.37 +/**
    2.38   * @brief Ends a testcase.
    2.39   */
    2.40  void SDL_ATend (void);