SDL-mirror/test/test-automation/tests/testrect/testrect.c

138 lines
3.8 KiB
C
Raw Normal View History

/**
* Original code: automated SDL rect test written by Edgar Simo "bobbens"
*/
#include <stdio.h>
#include <SDL/SDL.h>
Reorganizing the project. --HG-- rename : test/test-automation/SDL_test.h => test/test-automation/include/SDL_test.h rename : test/test-automation/SDL_test.c => test/test-automation/src/libtest/SDL_test.c rename : test/test-automation/common/common.c => test/test-automation/src/libtest/common/common.c rename : test/test-automation/common/common.h => test/test-automation/src/libtest/common/common.h rename : test/test-automation/common/images.h => test/test-automation/src/libtest/common/images.h rename : test/test-automation/common/img_blit.c => test/test-automation/src/libtest/common/img_blit.c rename : test/test-automation/common/img_blitblend.c => test/test-automation/src/libtest/common/img_blitblend.c rename : test/test-automation/common/img_face.c => test/test-automation/src/libtest/common/img_face.c rename : test/test-automation/common/img_primitives.c => test/test-automation/src/libtest/common/img_primitives.c rename : test/test-automation/common/img_primitivesblend.c => test/test-automation/src/libtest/common/img_primitivesblend.c rename : test/test-automation/fuzzer/fuzzer.c => test/test-automation/src/libtest/fuzzer/fuzzer.c rename : test/test-automation/fuzzer/fuzzer.h => test/test-automation/src/libtest/fuzzer/fuzzer.h rename : test/test-automation/fuzzer/utl_crc32.c => test/test-automation/src/libtest/fuzzer/utl_crc32.c rename : test/test-automation/fuzzer/utl_crc32.h => test/test-automation/src/libtest/fuzzer/utl_crc32.h rename : test/test-automation/fuzzer/utl_md5.c => test/test-automation/src/libtest/fuzzer/utl_md5.c rename : test/test-automation/fuzzer/utl_md5.h => test/test-automation/src/libtest/fuzzer/utl_md5.h rename : test/test-automation/fuzzer/utl_random.c => test/test-automation/src/libtest/fuzzer/utl_random.c rename : test/test-automation/fuzzer/utl_random.h => test/test-automation/src/libtest/fuzzer/utl_random.h rename : test/test-automation/logger_helpers.c => test/test-automation/src/libtest/logger_helpers.c rename : test/test-automation/logger_helpers.h => test/test-automation/src/libtest/logger_helpers.h rename : test/test-automation/plain_logger.c => test/test-automation/src/libtest/plain_logger.c rename : test/test-automation/plain_logger.h => test/test-automation/src/libtest/plain_logger.h rename : test/test-automation/xml.c => test/test-automation/src/libtest/xml.c rename : test/test-automation/xml.h => test/test-automation/src/libtest/xml.h rename : test/test-automation/xml_logger.c => test/test-automation/src/libtest/xml_logger.c rename : test/test-automation/xml_logger.h => test/test-automation/src/libtest/xml_logger.h rename : test/test-automation/logger.h => test/test-automation/src/runner/logger.h rename : test/test-automation/runner.c => test/test-automation/src/runner/runner.c rename : test/test-automation/support.c => test/test-automation/src/runner/support.c rename : test/test-automation/support.h => test/test-automation/src/runner/support.h rename : test/test-automation/testaudio/Makefile.am => test/test-automation/tests/testaudio/Makefile.am rename : test/test-automation/testaudio/testaudio.c => test/test-automation/tests/testaudio/testaudio.c rename : test/test-automation/testdummy/Makefile.am => test/test-automation/tests/testdummy/Makefile.am rename : test/test-automation/testdummy/testdummy.c => test/test-automation/tests/testdummy/testdummy.c rename : test/test-automation/testplatform/Makefile.am => test/test-automation/tests/testplatform/Makefile.am rename : test/test-automation/testrect/Makefile.am => test/test-automation/tests/testrect/Makefile.am rename : test/test-automation/testrect/testrect.c => test/test-automation/tests/testrect/testrect.c rename : test/test-automation/testrender/Makefile.am => test/test-automation/tests/testrender/Makefile.am rename : test/test-automation/testrender/testrender.c => test/test-automation/tests/testrender/testrender.c rename : test/test-automation/testrwops/Makefile.am => test/test-automation/tests/testrwops/Makefile.am rename : test/test-automation/testrwops/testrwops.c => test/test-automation/tests/testrwops/testrwops.c rename : test/test-automation/testsurface/Makefile.am => test/test-automation/tests/testsurface/Makefile.am rename : test/test-automation/testsurface/testsurface.c => test/test-automation/tests/testsurface/testsurface.c
2011-08-06 17:35:58 +03:00
#include "../../include/SDL_test.h"
/* Test cases */
static const TestCaseReference test1 =
2011-06-11 21:37:28 +03:00
(TestCaseReference){ "rect_testIntersectRectAndLine", "description", TEST_ENABLED, 0, 0 };
/* Test suite */
extern const TestCaseReference *testSuite[] = {
2011-08-06 19:49:37 +03:00
&test1, NULL
};
TestCaseReference **QueryTestSuite() {
return (TestCaseReference **)testSuite;
}
/*!
* \brief Tests SDL_IntersectRectAndLine()
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int rect_testIntersectRectAndLine (void *arg)
{
SDL_Rect rect = { 0, 0, 32, 32 };
int x1, y1;
int x2, y2;
SDL_bool clipped;
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);
}