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

Commit

Permalink
Ported testrect from original automation code, updated AssertEquals, …
Browse files Browse the repository at this point in the history
…added AssertTrue
  • Loading branch information
mkauppila committed Jun 2, 2011
1 parent 71428f8 commit 343e28c
Show file tree
Hide file tree
Showing 9 changed files with 731 additions and 15 deletions.
4 changes: 3 additions & 1 deletion test/test-automation/Makefile.am
@@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I acinclude -I build-scripts

SUBDIRS = tests
SUBDIRS = tests testrect

bin_PROGRAMS = runner
runner_SOURCES = runner.c SDL_test.c
Expand All @@ -11,6 +11,8 @@ install: install-tests
install-tests:
-cp -f tests/.libs/*.dylib tests/ 2> /dev/null
-cp -f tests/.libs/*.so tests/ 2> /dev/null
-cp -f testrect/.libs/*.dylib tests/ 2> /dev/null
-cp -f testrect/.libs/*.so tests/ 2> /dev/null

distclean-local:
-rm -Rf docs/
Expand Down
51 changes: 42 additions & 9 deletions test/test-automation/SDL_test.c
Expand Up @@ -21,34 +21,67 @@
#ifndef _SDL_TEST_C
#define _SDL_TEST_C

#include <stdio.h> /* printf/fprintf */
#include <stdarg.h> /* va_list */

#include "SDL_test.h"

/*! \brief return value of test case. Non-zero value means that the test failed */
static int _testReturnValue;

static int _testAssertsFailed;
static int _testAssertsPassed;

void
TestCaseInit()
{
_testReturnValue = 0;
_testAssertsFailed = 0;
_testAssertsPassed = 0;
}

int
TestCaseQuit()
{
printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
return _testReturnValue;
}

void
AssertEquals(char *message, Uint32 expected, Uint32 actual)
void
AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
{
if(expected != actual) {
printf("===============================\n");
printf("Assert failed: %s\n", message);
printf("Expected %d, got %d\n", expected, actual);
printf("===============================\n");
_testReturnValue = 1;
}
va_list args;
char buf[256];

if(expected != actual) {
va_start( args, message );
SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args );
printf("Assert Equals failed: expected %d, got %d; %s\n", expected, actual, buf);
_testReturnValue = 1;
_testAssertsFailed++;
} else {
_testAssertsPassed++;
}
}

void
AssertTrue(int condition, char *message, ...)
{
va_list args;
char buf[256];

if (!condition) {
va_start( args, message );
SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args );

printf("Assert IsTrue failed: %s\n", buf);
_testReturnValue = 1;
_testAssertsFailed++;
} else {
_testAssertsPassed++;
}
}

#endif
4 changes: 3 additions & 1 deletion test/test-automation/SDL_test.h
Expand Up @@ -53,6 +53,8 @@ void TestCaseInit();
int TestCaseQuit();


void AssertEquals(char *message, Uint32 expected, Uint32 actual);
void AssertEquals(Uint32 expected, Uint32 actual, char *message, ...);

void AssertTrue(int condition, char *message, ...);

#endif
2 changes: 1 addition & 1 deletion test/test-automation/configure.ac
Expand Up @@ -33,7 +33,7 @@ CFLAGS="-g"
AC_FUNC_FORK

AC_CONFIG_FILES([Makefile
tests/Makefile])
tests/Makefile testrect/Makefile])
AC_OUTPUT

echo ""
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/runner.c
Expand Up @@ -48,7 +48,7 @@ ScanForTestSuites() {
#if defined(linux) || defined( __linux)
char *libName = "tests/libtest.so";
#else
char *libName = "tests/libtest.dylib";
char *libName = "tests/libtestrect.dylib";
#endif
return libName;
}
Expand Down
9 changes: 9 additions & 0 deletions test/test-automation/testrect/Makefile.am
@@ -0,0 +1,9 @@
lib_LTLIBRARIES = libtestrect.la
libtestrect_la_SOURCES = testrect.c ../SDL_test.c
libtestrect_la_CLAGS = -fPIC -g
libtestrect_la_LDFLAGS = `sdl-config --libs`

distclean-local:
-rm *.dylib
-rm *.so

0 comments on commit 343e28c

Please sign in to comment.