Commit 450610b7 authored by Markus Kauppila's avatar Markus Kauppila

Ported testrect from original automation code, updated AssertEquals, added AssertTrue

parent 75691b7b
ACLOCAL_AMFLAGS = -I acinclude -I build-scripts
SUBDIRS = tests
SUBDIRS = tests testrect
bin_PROGRAMS = runner
runner_SOURCES = runner.c SDL_test.c
......@@ -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/
......
......@@ -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)
AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
{
va_list args;
char buf[256];
if(expected != actual) {
printf("===============================\n");
printf("Assert failed: %s\n", message);
printf("Expected %d, got %d\n", expected, actual);
printf("===============================\n");
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
......@@ -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
......@@ -33,7 +33,7 @@ CFLAGS="-g"
AC_FUNC_FORK
AC_CONFIG_FILES([Makefile
tests/Makefile])
tests/Makefile testrect/Makefile])
AC_OUTPUT
echo ""
......
......@@ -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;
}
......
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
This diff is collapsed.
/**
* Original code: automated SDL rect test written by Edgar Simo "bobbens"
*/
#include <stdio.h>
#include <SDL/SDL.h>
#include "../SDL_test.h"
/* Test cases */
static const TestCaseReference test1 =
(TestCaseReference){ "rect_testIntersectRectAndLine", "description", TEST_ENABLED, 0 };
/* Test suite */
extern const TestCaseReference *testSuite[] = {
&test1, NULL
};
TestCaseReference **QueryTestSuite() {
return (TestCaseReference **)testSuite;
}
/**
* @brief Tests SDL_IntersectRectAndLine()
*/
int rect_testIntersectRectAndLine (void *arg)
{
SDL_Rect rect = { 0, 0, 32, 32 };
int x1, y1;
int x2, y2;
SDL_bool clipped;
TestCaseInit();
x1 = -10;
y1 = 0;
x2 = -10;
y2 = 31;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( !clipped &&
x1 == -10 && y1 == 0 && x2 == -10 && y2 == 31,
"line outside to the left was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = 40;
y1 = 0;
x2 = 40;
y2 = 31;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( !clipped &&
x1 == 40 && y1 == 0 && x2 == 40 && y2 == 31,
"line outside to the right was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = 0;
y1 = -10;
x2 = 31;
y2 = -10;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( !clipped &&
x1 == 0 && y1 == -10 && x2 == 31 && y2 == -10,
"line outside above was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = 0;
y1 = 40;
x2 = 31;
y2 = 40;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( !clipped &&
x1 == 0 && y1 == 40 && x2 == 31 && y2 == 40,
"line outside below was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = 0;
y1 = 0;
x2 = 31;
y2 = 31;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( clipped &&
x1 == 0 && y1 == 0 && x2 == 31 && y2 == 31,
"line fully inside rect was clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = -10;
y1 = 15;
x2 = 40;
y2 = 15;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( clipped &&
x1 == 0 && y1 == 15 && x2 == 31 && y2 == 15,
"horizontal line rect was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = -32;
y1 = -32;
x2 = 63;
y2 = 63;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( clipped &&
x1 == 0 && y1 == 0 && x2 == 31 && y2 == 31,
"diagonal line to lower right was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = 63;
y1 = 63;
x2 = -32;
y2 = -32;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( clipped &&
x1 == 31 && y1 == 31 && x2 == 0 && y2 == 0,
"diagonal line to upper left was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = 63;
y1 = -32;
x2 = -32;
y2 = 63;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( clipped &&
x1 == 31 && y1 == 0 && x2 == 0 && y2 == 31,
"diagonal line to lower left was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
x1 = -32;
y1 = 63;
x2 = 63;
y2 = -32;
clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue( clipped &&
x1 == 0 && y1 == 31 && x2 == 31 && y2 == 0,
"diagonal line to upper right was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
return TestCaseQuit();
}
......@@ -55,7 +55,7 @@ int hello(void *arg)
const char *revision = SDL_GetRevision();
printf("Revision is %s\n", revision);
AssertEquals("will fail", 3, 5);
AssertEquals(3, 5, "fails");
return TestCaseQuit();
}
......@@ -75,7 +75,7 @@ int hello3(void *arg)
TestCaseInit();
printf("hello3\n");
AssertEquals("passes", 3, 3);
AssertEquals(3, 3, "passes");
return TestCaseQuit();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment