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

Commit

Permalink
Added tests to testrect suite. Simple logger improvements. Fixed int-…
Browse files Browse the repository at this point in the history
…range fuzzer.
  • Loading branch information
ferzkopp committed Sep 4, 2011
1 parent 71039ba commit 70d2c64
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 19 deletions.
11 changes: 6 additions & 5 deletions test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
Expand Up @@ -195,19 +195,20 @@ RandomSint64()
Sint32
RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
{
Sint64 min = (Sint64) pMin, max = (Sint64) pMax;
Sint64 min = pMin;
Sint64 max = pMax;

if(min > max) {
if(pMin > pMax) {
Sint64 temp = min;
min = max;
max = temp;
} else if(min == max) {
} else if(pMin == pMax) {
return min;
}

Sint32 number = RandomSint32(); // invocation count increment in there
Sint64 number = RandomUint32(); // invocation count increment in there

return (number % ((max + 1) - min)) + min;
return (Sint32)((number % ((max + 1) - min)) + min);
}

/*!
Expand Down
5 changes: 3 additions & 2 deletions test/test-automation/src/libSDLtest/plain_logger.c
Expand Up @@ -94,7 +94,6 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,


level = data->level;
//printf("Debug: %d == %d\n", level, data->level);

Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
Output(indentLevel, "Fuzzer seed is: %s", runSeed);
Expand All @@ -113,6 +112,8 @@ void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
int testSkippedCount, time_t endTime, double totalRuntime)
{
Output(indentLevel, "Test run ended at %s", TimestampToString(endTime));

Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
testCount, totalRuntime, suiteCount);

Expand Down Expand Up @@ -142,7 +143,7 @@ void
PlainTestStarted(const char *testName, const char *suiteName,
const char *testDescription, Uint64 execKey, time_t startTime)
{
Output(indentLevel, "Executing test: %s (in %s). Exec key: %llX", testName, suiteName, execKey);
Output(indentLevel, "Executing test: %s (in %s, exec key: %llX)", testName, suiteName, execKey);
Output(indentLevel++, "Test description: %s", testDescription);
}

Expand Down
11 changes: 10 additions & 1 deletion test/test-automation/src/runner/runner.c
Expand Up @@ -1365,8 +1365,17 @@ main(int argc, char *argv[])
// if --show-tests option is given, only print tests and exit
if(only_print_tests) {
TestCase *testItem = NULL;
char *lastSuiteName = NULL;
for(testItem = testCases; testItem; testItem = testItem->next) {
printf("%s (in %s) - %s\n", testItem->testName, testItem->suiteName, testItem->description);
if ((lastSuiteName == NULL) || (strcmp(lastSuiteName, testItem->suiteName)!=0)) {
lastSuiteName = testItem->suiteName;
printf ("%s:\n", lastSuiteName);
}
printf(" %s: %s", testItem->testName, testItem->description);
if (testItem->timeout>0) {
printf (" (timeout: %i sec)", testItem->timeout);
}
printf ("\n");
}

return 0;
Expand Down
191 changes: 189 additions & 2 deletions test/test-automation/tests/testrect/testrect.c
Expand Up @@ -10,12 +10,24 @@

/* Test cases */
static const TestCaseReference test1 =
(TestCaseReference){ "rect_testIntersectRectAndLine", "description", TEST_ENABLED, 0, 0 };
(TestCaseReference){ "rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine", TEST_ENABLED, 0, 0 };

static const TestCaseReference test2 =
(TestCaseReference){ "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED, 0, 0 };

static const TestCaseReference test3 =
(TestCaseReference){ "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED, 0, 0 };

static const TestCaseReference test4 =
(TestCaseReference){ "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED, 0, 0 };

static const TestCaseReference test5 =
(TestCaseReference){ "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED, 0, 0 };


/* Test suite */
extern const TestCaseReference *testSuite[] = {
&test1, NULL
&test1, &test2, &test3, &test4, &test5, NULL
};

TestCaseReference **QueryTestSuite() {
Expand Down Expand Up @@ -135,3 +147,178 @@ int rect_testIntersectRectAndLine (void *arg)
"diagonal line to upper right was incorrectly clipped: %d,%d - %d,%d",
x1, y1, x2, y2);
}

/*!
* \brief Tests SDL_IntersectRect() with B fully inside A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectInside (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;

// rectB fully contained in rectA
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.h = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
AssertTrue(intersection,
"Incorrect intersection result: expected true, got false intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
rectA.x, rectA.y, rectA.w, rectA.h,
rectB.x, rectB.y, rectB.w, rectB.h);
AssertTrue(rectA.x == refRectA.x && rectA.y == refRectA.y && rectA.w == refRectA.w && rectA.h == refRectA.h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA.x, rectA.y, rectA.w, rectA.h,
refRectA.x, refRectA.y, refRectA.w, refRectA.h);
AssertTrue(rectB.x == refRectB.x && rectB.y == refRectB.y && rectB.w == refRectB.w && rectB.h == refRectB.h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB.x, rectB.y, rectB.w, rectB.h,
refRectB.x, refRectB.y, refRectB.w, refRectB.h);
AssertTrue(result.x == refRectB.x && result.y == refRectB.y && result.w == refRectB.w && result.h == refRectB.h,
"Intersection of rectangles A and B was incorrectly calculated as: (%d,%d,%d,%d)",
result.x, result.y, result.w, result.h);
}

/*!
* \brief Tests SDL_IntersectRect() with B fully outside A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectOutside (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;

// rectB fully outside of rectA
refRectB.x = refRectA.x + refRectA.w + RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + RandomIntegerInRange(1, 10);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
AssertTrue(!intersection,
"Incorrect intersection result: expected false, got true intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)\n",
rectA.x, rectA.y, rectA.w, rectA.h,
rectB.x, rectB.y, rectB.w, rectB.h);
AssertTrue(rectA.x == refRectA.x && rectA.y == refRectA.y && rectA.w == refRectA.w && rectA.h == refRectA.h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA.x, rectA.y, rectA.w, rectA.h,
refRectA.x, refRectA.y, refRectA.w, refRectA.h);
AssertTrue(rectB.x == refRectB.x && rectB.y == refRectB.y && rectB.w == refRectB.w && rectB.h == refRectB.h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB.x, rectB.y, rectB.w, rectB.h,
refRectB.x, refRectB.y, refRectB.w, refRectB.h);
}

/*!
* \brief Tests SDL_IntersectRect() with B partially intersecting A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectPartial (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;

// rectB partially contained in rectA
refRectB.x = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
AssertTrue(intersection,
"Incorrect intersection result: expected true, got false intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)\n",
rectA.x, rectA.y, rectA.w, rectA.h,
rectB.x, rectB.y, rectB.w, rectB.h);
AssertTrue(rectA.x == refRectA.x && rectA.y == refRectA.y && rectA.w == refRectA.w && rectA.h == refRectA.h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA.x, rectA.y, rectA.w, rectA.h,
refRectA.x, refRectA.y, refRectA.w, refRectA.h);
AssertTrue(rectB.x == refRectB.x && rectB.y == refRectB.y && rectB.w == refRectB.w && rectB.h == refRectB.h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB.x, rectB.y, rectB.w, rectB.h,
refRectB.x, refRectB.y, refRectB.w, refRectB.h);
AssertTrue(result.x == refRectB.x && result.y == refRectB.y && result.w == (refRectA.w - refRectB.x) && result.h == (refRectA.h - refRectB.y),
"Intersection of rectangles A and B was incorrectly calculated as: (%d,%d,%d,%d)",
result.x, result.y, result.w, result.h);
}

/*!
* \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectPoint (void *arg)
{
SDL_Rect refRectA = { 0, 0, 1, 1 };
SDL_Rect refRectB = { 0, 0, 1, 1 };
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;

// intersecting pixels
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
refRectB.y = refRectA.y;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
AssertTrue(intersection,
"Incorrect intersection result: expected true, got false intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)\n",
rectA.x, rectA.y, rectA.w, rectA.h,
rectB.x, rectB.y, rectB.w, rectB.h);
AssertTrue(rectA.x == refRectA.x && rectA.y == refRectA.y && rectA.w == refRectA.w && rectA.h == refRectA.h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA.x, rectA.y, rectA.w, rectA.h,
refRectA.x, refRectA.y, refRectA.w, refRectA.h);
AssertTrue(rectB.x == refRectB.x && rectB.y == refRectB.y && rectB.w == refRectB.w && rectB.h == refRectB.h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB.x, rectB.y, rectB.w, rectB.h,
refRectB.x, refRectB.y, refRectB.w, refRectB.h);
AssertTrue(result.x == refRectA.x && result.y == refRectA.y && result.w == refRectA.w && result.h == refRectA.h,
"Intersection of rectangles A and B was incorrectly calculated as: (%d,%d,%d,%d)",
result.x, result.y, result.w, result.h);

// non-intersecting pixels case
refRectB.x++;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
AssertTrue(!intersection,
"Incorrect intersection result: expected false, got true intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)\n",
rectA.x, rectA.y, rectA.w, rectA.h,
rectB.x, rectB.y, rectB.w, rectB.h);
AssertTrue(rectA.x == refRectA.x && rectA.y == refRectA.y && rectA.w == refRectA.w && rectA.h == refRectA.h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA.x, rectA.y, rectA.w, rectA.h,
refRectA.x, refRectA.y, refRectA.w, refRectA.h);
AssertTrue(rectB.x == refRectB.x && rectB.y == refRectB.y && rectB.w == refRectB.w && rectB.h == refRectB.h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB.x, rectB.y, rectB.w, rectB.h,
refRectB.x, refRectB.y, refRectB.w, refRectB.h);
}
17 changes: 8 additions & 9 deletions test/test-automation/tests/testrwops/testrwops.c
Expand Up @@ -22,25 +22,25 @@ static const char const_mem[] = "Hello World!";

/* Test cases */
static const TestCaseReference test1 =
(TestCaseReference){ "rwops_testParam", "test parameters", TEST_ENABLED, 0, 0 };
(TestCaseReference){ "rwops_testParam", " Negative test for SDL_RWFromFile parameters", TEST_ENABLED, 0, 60 };

static const TestCaseReference test2 =
(TestCaseReference){ "rwops_testMem", "Tests opening from memory", TEST_ENABLED, 0, 0 };
(TestCaseReference){ "rwops_testMem", "Tests opening from memory", TEST_ENABLED, 0, 60 };

static const TestCaseReference test3 =
(TestCaseReference){ "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED, 0, 0 };
(TestCaseReference){ "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED, 0, 60 };

static const TestCaseReference test4 =
(TestCaseReference){ "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED, 0, 0 };
(TestCaseReference){ "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED, 0, 60 };

static const TestCaseReference test5 =
(TestCaseReference){ "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED, 0, 0 };
(TestCaseReference){ "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED, 0, 60 };

static const TestCaseReference test6 =
(TestCaseReference){ "rwops_testFPRead", "Test reading from stdio", TEST_ENABLED, TEST_REQUIRES_STDIO, 0 };
(TestCaseReference){ "rwops_testFPRead", "Test reading from stdio", TEST_ENABLED, TEST_REQUIRES_STDIO, 60 };

static const TestCaseReference test7 =
(TestCaseReference){ "rwops_testFPWrite", "Test writing to stdio", TEST_ENABLED, TEST_REQUIRES_STDIO, 0 };
(TestCaseReference){ "rwops_testFPWrite", "Test writing to stdio", TEST_ENABLED, TEST_REQUIRES_STDIO, 60 };



Expand Down Expand Up @@ -122,11 +122,10 @@ int _testGeneric( SDL_RWops *rw, int write )
}

/*!
* Tests rwops parameters
* Negative test for SDL_RWFromFile parameters
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
*
* TODO Add fuzzer support here, write and read a string
*/
void rwops_testParam (void)
{
Expand Down

0 comments on commit 70d2c64

Please sign in to comment.