From 6584aa6a0390e961f4d36070740c33a9b63ba262 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sun, 4 Sep 2011 14:57:10 -0700 Subject: [PATCH] Added tests to testrect suite. Simple logger improvements. Fixed int-range fuzzer. --- .../src/libSDLtest/fuzzer/fuzzer.c | 11 +- .../src/libSDLtest/plain_logger.c | 5 +- test/test-automation/src/runner/runner.c | 11 +- .../test-automation/tests/testrect/testrect.c | 191 +++++++++++++++++- .../tests/testrwops/testrwops.c | 17 +- 5 files changed, 216 insertions(+), 19 deletions(-) diff --git a/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c b/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c index 1afef0c3d..1d245371a 100644 --- a/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c +++ b/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c @@ -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); } /*! diff --git a/test/test-automation/src/libSDLtest/plain_logger.c b/test/test-automation/src/libSDLtest/plain_logger.c index 6a370a3c0..f570cf84d 100644 --- a/test/test-automation/src/libSDLtest/plain_logger.c +++ b/test/test-automation/src/libSDLtest/plain_logger.c @@ -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); @@ -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); @@ -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); } diff --git a/test/test-automation/src/runner/runner.c b/test/test-automation/src/runner/runner.c index 37128241d..c0068c458 100644 --- a/test/test-automation/src/runner/runner.c +++ b/test/test-automation/src/runner/runner.c @@ -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; diff --git a/test/test-automation/tests/testrect/testrect.c b/test/test-automation/tests/testrect/testrect.c index b06c78efc..ec4fa684c 100644 --- a/test/test-automation/tests/testrect/testrect.c +++ b/test/test-automation/tests/testrect/testrect.c @@ -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() { @@ -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); +} diff --git a/test/test-automation/tests/testrwops/testrwops.c b/test/test-automation/tests/testrwops/testrwops.c index 4c295e5f5..8e0c4bcd8 100644 --- a/test/test-automation/tests/testrwops/testrwops.c +++ b/test/test-automation/tests/testrwops/testrwops.c @@ -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 }; @@ -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) {