Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added command line options.
Added verbosity levels.
  • Loading branch information
bobbens committed Aug 2, 2009
1 parent 3e9b0cc commit 3c25c26
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 31 deletions.
6 changes: 3 additions & 3 deletions test/automated/Makefile
Expand Up @@ -15,21 +15,21 @@ SRC := testsdl.c \
COMMON_SRC := SDL_at.c common/common.c
COMMON_INCLUDE := SDL_at.h

TESTS_ALL := rwops/rwops platform/platform surface/surface render/render
TESTS_ALL := testsdl rwops/rwops platform/platform surface/surface render/render


.PHONY: all clean test


all: testsdl $(TESTS_ALL)
all: $(TESTS_ALL)

test: all
@./rwops/rwops
@./platform/platform
@./surface/surface
@./render/render

testsdl:
testsdl: $(SRC) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC) $(COMMON_SRC)

rwops/rwops: rwops/rwops.c $(COMMON_INCLUDE) $(COMMON_SRC)
Expand Down
142 changes: 122 additions & 20 deletions test/automated/SDL_at.c
Expand Up @@ -22,6 +22,13 @@ static int at_success = 0; /**< Number of successful testcases. */
static int at_failure = 0; /**< Number of failed testcases. */


/*
* Global properties.
*/
static int at_verbose = 0; /**< Verbosity. */
static int at_quiet = 0; /**< Quietness. */


/**
* @brief Cleans up the automated testsuite state.
*/
Expand All @@ -41,48 +48,52 @@ void SDL_ATinit( const char *suite )
{
/* Do not open twice. */
if (at_suite_msg) {
SDL_ATprint( "AT suite '%s' not closed before opening suite '%s'\n",
SDL_ATprintErr( "AT suite '%s' not closed before opening suite '%s'\n",
at_suite_msg, suite );
}
/* Must have a name. */
if (suite == NULL) {
SDL_ATprint( "AT testsuite does not have a name.\n");
SDL_ATprintErr( "AT testsuite does not have a name.\n");
}
SDL_ATcleanup();
at_suite_msg = suite;

/* Verbose message. */
SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", suite );
}


/**
* @brief Finish testsuite.
*/
int SDL_ATfinish( int verbose )
int SDL_ATfinish (void)
{
int failed;

/* Make sure initialized. */
if (at_suite_msg == NULL) {
SDL_ATprint("Ended testcase without initializing.\n");
SDL_ATprintErr("Ended testcase without initializing.\n");
return 1;
}

/* Finished without closing testcase. */
if (at_test_msg) {
SDL_ATprint( "AT suite '%s' finished without closing testcase '%s'\n",
SDL_ATprintErr( "AT suite '%s' finished without closing testcase '%s'\n",
at_suite_msg, at_test_msg );
}

/* Verbose message. */
SDL_ATprintVerbose( 2, "<-+---- Finished Test Suite '%s'\n", at_suite_msg );

/* Display message if verbose on failed. */
failed = at_failure;
if (verbose) {
if (at_failure > 0) {
SDL_ATprint( "%s : Failed %d out of %d testcases!\n",
at_suite_msg, at_failure, at_failure+at_success );
}
else {
SDL_ATprint( "%s : All tests successful (%d)\n",
at_suite_msg, at_success );
}
if (at_failure > 0) {
SDL_ATprintErr( "%s : Failed %d out of %d testcases!\n",
at_suite_msg, at_failure, at_failure+at_success );
}
else {
SDL_ATprint( "%s : All tests successful (%d)\n",
at_suite_msg, at_success );
}

/* Clean up. */
Expand All @@ -93,21 +104,58 @@ int SDL_ATfinish( int verbose )
}


/**
* @brief Sets a property.
*/
void SDL_ATseti( int property, int value )
{
switch (property) {
case SDL_AT_VERBOSE:
at_verbose = value;
break;

case SDL_AT_QUIET:
at_quiet = value;
break;
}
}


/**
* @brief Gets a property.
*/
void SDL_ATgeti( int property, int *value )
{
switch (property) {
case SDL_AT_VERBOSE:
*value = at_verbose;
break;

case SDL_AT_QUIET:
*value = at_quiet;
break;
}
}


/**
* @brief Begin testcase.
*/
void SDL_ATbegin( const char *testcase )
{
/* Do not open twice. */
if (at_test_msg) {
SDL_ATprint( "AT testcase '%s' not closed before opening testcase '%s'\n",
SDL_ATprintErr( "AT testcase '%s' not closed before opening testcase '%s'\n",
at_test_msg, testcase );
}
/* Must have a name. */
if (testcase == NULL) {
SDL_ATprint( "AT testcase does not have a name.\n");
SDL_ATprintErr( "AT testcase does not have a name.\n");
}
at_test_msg = testcase;

/* Verbose message. */
SDL_ATprintVerbose( 2, " +---> StartedTest Case '%s'\n", testcase );
}


Expand All @@ -118,7 +166,7 @@ static void SDL_ATendWith( int success )
{
/* Make sure initialized. */
if (at_test_msg == NULL) {
SDL_ATprint("Ended testcase without initializing.\n");
SDL_ATprintErr("Ended testcase without initializing.\n");
return;
}

Expand All @@ -128,6 +176,9 @@ static void SDL_ATendWith( int success )
else
at_failure++;

/* Verbose message. */
SDL_ATprintVerbose( 2, " +---- Finished Test Case '%s'\n", at_test_msg );

/* Clean up. */
at_test_msg = NULL;
}
Expand All @@ -141,7 +192,7 @@ int SDL_ATassert( const char *msg, int condition )
/* Condition failed. */
if (!condition) {
/* Print. */
SDL_ATprint( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg );
SDL_ATprintErr( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg );
/* End. */
SDL_ATendWith(0);
}
Expand All @@ -164,7 +215,7 @@ int SDL_ATvassert( int condition, const char *msg, ... )
vsnprintf( buf, sizeof(buf), msg, args );
va_end( args );
/* Print. */
SDL_ATprint( "%s [%s] : %s\n", at_suite_msg, at_test_msg, buf );
SDL_ATprintErr( "%s [%s] : %s\n", at_suite_msg, at_test_msg, buf );
/* End. */
SDL_ATendWith(0);
}
Expand All @@ -181,6 +232,27 @@ void SDL_ATend (void)
}


/**
* @brief Displays an error.
*/
int SDL_ATprintErr( const char *msg, ... )
{
va_list ap;
int ret;

/* Make sure there is something to print. */
if (msg == NULL)
return 0;
else {
va_start(ap, msg);
ret = vfprintf( stderr, msg, ap );
va_end(ap);
}

return ret;
}


/**
* @brief Displays a message.
*/
Expand All @@ -189,16 +261,46 @@ int SDL_ATprint( const char *msg, ... )
va_list ap;
int ret;

/* Only print if not quiet. */
if (at_quiet)
return 0;

/* Make sure there is something to print. */
if (msg == NULL)
return 0;
else {
va_start(ap, msg);
ret = vfprintf( stdout, msg, ap );
va_end(ap);
}

return ret;
}


/**
* @brief Displays a verbose message.
*/
int SDL_ATprintVerbose( int level, const char *msg, ... )
{
va_list ap;
int ret;

/* Only print if not quiet. */
if (at_quiet || (at_verbose < level))
return 0;

/* Make sure there is something to print. */
if (msg == NULL)
return 0;
else {
va_start(ap, msg);
ret = vprintf(msg, ap);
ret = vfprintf( stdout, msg, ap );
va_end(ap);
}

return ret;
}



38 changes: 37 additions & 1 deletion test/automated/SDL_at.h
Expand Up @@ -38,6 +38,13 @@
# define _SDL_AT_H



enum {
SDL_AT_VERBOSE,
SDL_AT_QUIET
};


/*
* Suite level actions.
*/
Expand All @@ -52,7 +59,21 @@ void SDL_ATinit( const char *suite );
*
* @param verbose Displays global results.
*/
int SDL_ATfinish( int verbose );
int SDL_ATfinish (void);
/**
* @brief Sets a global property value.
*
* @param property Property to set.
* @param value Value to set property to.
*/
void SDL_ATseti( int property, int value );
/**
* @brief Gets a global property value.
*
* @param property Property to get.
* @param[out] value Value of the property.
*/
void SDL_ATgeti( int property, int *value );


/*
Expand Down Expand Up @@ -93,13 +114,28 @@ void SDL_ATend (void);
/*
* Misc functions.
*/
/**
* @brief Prints an error.
*
* @param msg printf formatted string to display.
* @return Number of character printed.
*/
int SDL_ATprintErr( const char *msg, ... );
/**
* @brief Prints some text.
*
* @param msg printf formatted string to display.
* @return Number of character printed.
*/
int SDL_ATprint( const char *msg, ... );
/**
* @brief Prints some verbose text.
*
* @param level Level of verbosity to print at.
* @param msg printf formatted string to display.
* @return Number of character printed.
*/
int SDL_ATprintVerbose( int level, const char *msg, ... );


#endif /* _SDL_AT_H */
Expand Down
2 changes: 1 addition & 1 deletion test/automated/platform/platform.c
Expand Up @@ -149,5 +149,5 @@ int test_platform (void)
plat_testTypes();
plat_testEndian();

return SDL_ATfinish(1);
return SDL_ATfinish();
}
2 changes: 1 addition & 1 deletion test/automated/render/render.c
Expand Up @@ -1056,7 +1056,7 @@ int test_render (void)
/*
* Finish testsuite.
*/
SDL_ATfinish(1);
SDL_ATfinish();
}


Expand Down
2 changes: 1 addition & 1 deletion test/automated/rwops/rwops.c
Expand Up @@ -267,5 +267,5 @@ int test_rwops (void)
rwops_testFile();
rwops_testFP();

return SDL_ATfinish(1);
return SDL_ATfinish();
}
4 changes: 2 additions & 2 deletions test/automated/surface/surface.c
Expand Up @@ -588,9 +588,9 @@ int test_surface (void)
/* Exit SDL. */
SDL_Quit();

return SDL_ATfinish(1);
return SDL_ATfinish();

err:
return SDL_ATfinish(1);
return SDL_ATfinish();
}

0 comments on commit 3c25c26

Please sign in to comment.