Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
e9174b82
Commit
e9174b82
authored
Sep 18, 2011
by
Andreas Schiffler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for SDL_RectEquals and empty rectangle cases
parent
1694584d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
342 additions
and
24 deletions
+342
-24
testrect.c
test/test-automation/tests/testrect/testrect.c
+342
-24
No files found.
test/test-automation/tests/testrect/testrect.c
View file @
e9174b82
...
@@ -17,74 +17,93 @@ static const TestCaseReference test2 =
...
@@ -17,74 +17,93 @@ static const TestCaseReference test2 =
(
TestCaseReference
){
"rect_testIntersectRectAndLineInside"
,
"Tests SDL_IntersectRectAndLine with line fully contained in rect"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectAndLineInside"
,
"Tests SDL_IntersectRectAndLine with line fully contained in rect"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test3
=
static
const
TestCaseReference
test3
=
(
TestCaseReference
){
"rect_testIntersectRectAndLineOutside"
,
"Tests SDL_IntersectRectAndLine with line fully
contained in
rect"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectAndLineOutside"
,
"Tests SDL_IntersectRectAndLine with line fully
outside of
rect"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test4
=
static
const
TestCaseReference
test4
=
(
TestCaseReference
){
"rect_testIntersectRectAndLineEmpty"
,
"Tests SDL_IntersectRectAndLine with empty rectangle "
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test5
=
(
TestCaseReference
){
"rect_testIntersectRectAndLineParam"
,
"Negative tests against SDL_IntersectRectAndLine with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectAndLineParam"
,
"Negative tests against SDL_IntersectRectAndLine with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/* SDL_IntersectRect */
/* SDL_IntersectRect */
static
const
TestCaseReference
test
5
=
static
const
TestCaseReference
test
6
=
(
TestCaseReference
){
"rect_testIntersectRectInside"
,
"Tests SDL_IntersectRect with B fully contained in A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectInside"
,
"Tests SDL_IntersectRect with B fully contained in A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test
6
=
static
const
TestCaseReference
test
7
=
(
TestCaseReference
){
"rect_testIntersectRectOutside"
,
"Tests SDL_IntersectRect with B fully outside of A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectOutside"
,
"Tests SDL_IntersectRect with B fully outside of A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test
7
=
static
const
TestCaseReference
test
8
=
(
TestCaseReference
){
"rect_testIntersectRectPartial"
,
"Tests SDL_IntersectRect with B partially intersecting A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectPartial"
,
"Tests SDL_IntersectRect with B partially intersecting A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test
8
=
static
const
TestCaseReference
test
9
=
(
TestCaseReference
){
"rect_testIntersectRectPoint"
,
"Tests SDL_IntersectRect with 1x1 sized rectangles"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectPoint"
,
"Tests SDL_IntersectRect with 1x1 sized rectangles"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test9
=
static
const
TestCaseReference
test10
=
(
TestCaseReference
){
"rect_testIntersectRectEmpty"
,
"Tests SDL_IntersectRect with empty rectangles"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test11
=
(
TestCaseReference
){
"rect_testIntersectRectParam"
,
"Negative tests against SDL_IntersectRect with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testIntersectRectParam"
,
"Negative tests against SDL_IntersectRect with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/* SDL_HasIntersection */
/* SDL_HasIntersection */
static
const
TestCaseReference
test1
0
=
static
const
TestCaseReference
test1
2
=
(
TestCaseReference
){
"rect_testHasIntersectionInside"
,
"Tests SDL_HasIntersection with B fully contained in A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testHasIntersectionInside"
,
"Tests SDL_HasIntersection with B fully contained in A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test1
1
=
static
const
TestCaseReference
test1
3
=
(
TestCaseReference
){
"rect_testHasIntersectionOutside"
,
"Tests SDL_HasIntersection with B fully outside of A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testHasIntersectionOutside"
,
"Tests SDL_HasIntersection with B fully outside of A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test1
2
=
static
const
TestCaseReference
test1
4
=
(
TestCaseReference
){
"rect_testHasIntersectionPartial"
,
"Tests SDL_HasIntersection with B partially intersecting A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testHasIntersectionPartial"
,
"Tests SDL_HasIntersection with B partially intersecting A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test1
3
=
static
const
TestCaseReference
test1
5
=
(
TestCaseReference
){
"rect_testHasIntersectionPoint"
,
"Tests SDL_HasIntersection with 1x1 sized rectangles"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testHasIntersectionPoint"
,
"Tests SDL_HasIntersection with 1x1 sized rectangles"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test14
=
static
const
TestCaseReference
test16
=
(
TestCaseReference
){
"rect_testHasIntersectionEmpty"
,
"Tests SDL_HasIntersection with empty rectangles"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test17
=
(
TestCaseReference
){
"rect_testHasIntersectionParam"
,
"Negative tests against SDL_HasIntersection with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testHasIntersectionParam"
,
"Negative tests against SDL_HasIntersection with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/* SDL_EnclosePoints */
/* SDL_EnclosePoints */
static
const
TestCaseReference
test1
5
=
static
const
TestCaseReference
test1
8
=
(
TestCaseReference
){
"rect_testEnclosePoints"
,
"Tests SDL_EnclosePoints without clipping"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testEnclosePoints"
,
"Tests SDL_EnclosePoints without clipping"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test1
6
=
static
const
TestCaseReference
test1
9
=
(
TestCaseReference
){
"rect_testEnclosePointsWithClipping"
,
"Tests SDL_EnclosePoints with clipping"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testEnclosePointsWithClipping"
,
"Tests SDL_EnclosePoints with clipping"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test
17
=
static
const
TestCaseReference
test
20
=
(
TestCaseReference
){
"rect_testEnclosePointsRepeatedInput"
,
"Tests SDL_EnclosePoints with repeated input"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testEnclosePointsRepeatedInput"
,
"Tests SDL_EnclosePoints with repeated input"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test
18
=
static
const
TestCaseReference
test
21
=
(
TestCaseReference
){
"rect_testEnclosePointsParam"
,
"Negative tests against SDL_EnclosePoints with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testEnclosePointsParam"
,
"Negative tests against SDL_EnclosePoints with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/* SDL_UnionRect */
/* SDL_UnionRect */
static
const
TestCaseReference
test
19
=
static
const
TestCaseReference
test
22
=
(
TestCaseReference
){
"rect_testUnionRectInside"
,
"Tests SDL_UnionRect where rect B is inside rect A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testUnionRectInside"
,
"Tests SDL_UnionRect where rect B is inside rect A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test2
0
=
static
const
TestCaseReference
test2
3
=
(
TestCaseReference
){
"rect_testUnionRectOutside"
,
"Tests SDL_UnionRect where rect B is outside rect A"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testUnionRectOutside"
,
"Tests SDL_UnionRect where rect B is outside rect A"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test21
=
static
const
TestCaseReference
test24
=
(
TestCaseReference
){
"rect_testUnionRectEmpty"
,
"Tests SDL_UnionRect where rect A or rect B are empty"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test25
=
(
TestCaseReference
){
"rect_testUnionRectParam"
,
"Negative tests against SDL_UnionRect with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testUnionRectParam"
,
"Negative tests against SDL_UnionRect with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/* SDL_RectEmpty */
/* SDL_RectEmpty */
static
const
TestCaseReference
test2
2
=
static
const
TestCaseReference
test2
6
=
(
TestCaseReference
){
"rect_testRectEmpty"
,
"Tests SDL_RectEmpty with various inputs"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testRectEmpty"
,
"Tests SDL_RectEmpty with various inputs"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test2
3
=
static
const
TestCaseReference
test2
7
=
(
TestCaseReference
){
"rect_testRectEmptyParam"
,
"Negative tests against SDL_RectEmpty with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
(
TestCaseReference
){
"rect_testRectEmptyParam"
,
"Negative tests against SDL_RectEmpty with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/* TODO: SDL_RectEquals */
/* SDL_RectEquals */
static
const
TestCaseReference
test28
=
(
TestCaseReference
){
"rect_testRectEquals"
,
"Tests SDL_RectEquals with various inputs"
,
TEST_ENABLED
,
0
,
0
};
static
const
TestCaseReference
test29
=
(
TestCaseReference
){
"rect_testRectEqualsParam"
,
"Negative tests against SDL_RectEquals with invalid parameters"
,
TEST_ENABLED
,
0
,
0
};
/*!
/*!
* \brief Test suite for functions that handle simple rectangles including overlaps and merges.
* \brief Test suite for functions that handle simple rectangles including overlaps and merges.
...
@@ -94,7 +113,8 @@ static const TestCaseReference test23 =
...
@@ -94,7 +113,8 @@ static const TestCaseReference test23 =
*/
*/
extern
const
TestCaseReference
*
testSuite
[]
=
{
extern
const
TestCaseReference
*
testSuite
[]
=
{
&
test1
,
&
test2
,
&
test3
,
&
test4
,
&
test5
,
&
test6
,
&
test7
,
&
test8
,
&
test9
,
&
test10
,
&
test11
,
&
test12
,
&
test13
,
&
test14
,
&
test1
,
&
test2
,
&
test3
,
&
test4
,
&
test5
,
&
test6
,
&
test7
,
&
test8
,
&
test9
,
&
test10
,
&
test11
,
&
test12
,
&
test13
,
&
test14
,
&
test15
,
&
test16
,
&
test17
,
&
test18
,
&
test19
,
&
test20
,
&
test21
,
&
test22
,
&
test23
,
NULL
&
test15
,
&
test16
,
&
test17
,
&
test18
,
&
test19
,
&
test20
,
&
test21
,
&
test22
,
&
test23
,
&
test24
,
&
test25
,
&
test26
,
&
test27
,
&
test28
,
&
test29
,
NULL
};
};
TestCaseReference
**
QueryTestSuite
()
{
TestCaseReference
**
QueryTestSuite
()
{
...
@@ -311,6 +331,38 @@ int rect_testIntersectRectAndLineOutside (void *arg)
...
@@ -311,6 +331,38 @@ int rect_testIntersectRectAndLineOutside (void *arg)
_validateIntersectRectAndLineResults
(
intersected
,
SDL_FALSE
,
&
rect
,
&
refRect
,
x1
,
y1
,
x2
,
y2
,
0
,
yBottom
,
31
,
yBottom
);
_validateIntersectRectAndLineResults
(
intersected
,
SDL_FALSE
,
&
rect
,
&
refRect
,
x1
,
y1
,
x2
,
y2
,
0
,
yBottom
,
31
,
yBottom
);
}
}
/*!
* \brief Tests SDL_IntersectRectAndLine() with empty rectangle
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int
rect_testIntersectRectAndLineEmpty
(
void
*
arg
)
{
SDL_Rect
refRect
;
SDL_Rect
rect
;
int
x1
,
y1
,
x1Ref
,
y1Ref
;
int
x2
,
y2
,
x2Ref
,
y2Ref
;
SDL_bool
intersected
;
refRect
.
x
=
RandomIntegerInRange
(
1
,
1024
);
refRect
.
y
=
RandomIntegerInRange
(
1
,
1024
);
refRect
.
w
=
0
;
refRect
.
h
=
0
;
x1Ref
=
refRect
.
x
;
y1Ref
=
refRect
.
y
;
x2Ref
=
RandomIntegerInRange
(
1
,
1024
);
y2Ref
=
RandomIntegerInRange
(
1
,
1024
);
x1
=
x1Ref
;
y1
=
y1Ref
;
x2
=
x2Ref
;
y2
=
y2Ref
;
rect
=
refRect
;
intersected
=
SDL_IntersectRectAndLine
(
&
rect
,
&
x1
,
&
y1
,
&
x2
,
&
y2
);
_validateIntersectRectAndLineResults
(
intersected
,
SDL_FALSE
,
&
rect
,
&
refRect
,
x1
,
y1
,
x2
,
y2
,
x1Ref
,
y1Ref
,
x2Ref
,
y2Ref
);
}
/*!
/*!
* \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
* \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
*
*
...
@@ -426,6 +478,29 @@ void _validateRectEmptyResults(
...
@@ -426,6 +478,29 @@ void _validateRectEmptyResults(
refRect
->
x
,
refRect
->
y
,
refRect
->
w
,
refRect
->
h
);
refRect
->
x
,
refRect
->
y
,
refRect
->
w
,
refRect
->
h
);
}
}
/*!
* \brief Private helper to check SDL_RectEquals results
*/
void
_validateRectEqualsResults
(
SDL_bool
equals
,
SDL_bool
expectedEquals
,
SDL_Rect
*
rectA
,
SDL_Rect
*
rectB
,
SDL_Rect
*
refRectA
,
SDL_Rect
*
refRectB
)
{
AssertTrue
(
equals
==
expectedEquals
,
"Incorrect equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)
\n
"
,
(
expectedEquals
==
SDL_TRUE
)
?
"true"
:
"false"
,
(
equals
==
SDL_TRUE
)
?
"true"
:
"false"
,
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 fully inside A
* \brief Tests SDL_IntersectRect() with B fully inside A
*
*
...
@@ -610,6 +685,63 @@ int rect_testIntersectRectPoint (void *arg)
...
@@ -610,6 +685,63 @@ int rect_testIntersectRectPoint (void *arg)
}
}
}
}
/*!
* \brief Tests SDL_IntersectRect() with empty rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int
rect_testIntersectRectEmpty
(
void
*
arg
)
{
SDL_Rect
refRectA
;
SDL_Rect
refRectB
;
SDL_Rect
rectA
;
SDL_Rect
rectB
;
SDL_Rect
result
;
SDL_bool
intersection
;
// Rect A empty
refRectA
.
x
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
y
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
100
);
refRectB
=
refRectA
;
refRectA
.
w
=
0
;
refRectA
.
h
=
0
;
rectA
=
refRectA
;
rectB
=
refRectB
;
intersection
=
SDL_IntersectRect
(
&
rectA
,
&
rectB
,
&
result
);
_validateIntersectRectResults
(
intersection
,
SDL_FALSE
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
,
(
SDL_Rect
*
)
NULL
,
(
SDL_Rect
*
)
NULL
);
// Rect B empty
refRectA
.
x
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
y
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
100
);
refRectB
=
refRectA
;
refRectB
.
w
=
0
;
refRectB
.
h
=
0
;
rectA
=
refRectA
;
rectB
=
refRectB
;
intersection
=
SDL_IntersectRect
(
&
rectA
,
&
rectB
,
&
result
);
_validateIntersectRectResults
(
intersection
,
SDL_FALSE
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
,
(
SDL_Rect
*
)
NULL
,
(
SDL_Rect
*
)
NULL
);
// Rect A and B empty
refRectA
.
x
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
y
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
100
);
refRectB
=
refRectA
;
refRectA
.
w
=
0
;
refRectA
.
h
=
0
;
refRectB
.
w
=
0
;
refRectB
.
h
=
0
;
rectA
=
refRectA
;
rectB
=
refRectB
;
intersection
=
SDL_IntersectRect
(
&
rectA
,
&
rectB
,
&
result
);
_validateIntersectRectResults
(
intersection
,
SDL_FALSE
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
,
(
SDL_Rect
*
)
NULL
,
(
SDL_Rect
*
)
NULL
);
}
/*!
/*!
* \brief Negative tests against SDL_IntersectRect() with invalid parameters
* \brief Negative tests against SDL_IntersectRect() with invalid parameters
*
*
...
@@ -798,6 +930,62 @@ int rect_testHasIntersectionPoint (void *arg)
...
@@ -798,6 +930,62 @@ int rect_testHasIntersectionPoint (void *arg)
}
}
}
}
/*!
* \brief Tests SDL_HasIntersection() with empty rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int
rect_testHasIntersectionEmpty
(
void
*
arg
)
{
SDL_Rect
refRectA
;
SDL_Rect
refRectB
;
SDL_Rect
rectA
;
SDL_Rect
rectB
;
SDL_bool
intersection
;
// Rect A empty
refRectA
.
x
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
y
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
100
);
refRectB
=
refRectA
;
refRectA
.
w
=
0
;
refRectA
.
h
=
0
;
rectA
=
refRectA
;
rectB
=
refRectB
;
intersection
=
SDL_HasIntersection
(
&
rectA
,
&
rectB
);
_validateHasIntersectionResults
(
intersection
,
SDL_FALSE
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
);
// Rect B empty
refRectA
.
x
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
y
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
100
);
refRectB
=
refRectA
;
refRectB
.
w
=
0
;
refRectB
.
h
=
0
;
rectA
=
refRectA
;
rectB
=
refRectB
;
intersection
=
SDL_HasIntersection
(
&
rectA
,
&
rectB
);
_validateHasIntersectionResults
(
intersection
,
SDL_FALSE
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
);
// Rect A and B empty
refRectA
.
x
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
y
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
100
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
100
);
refRectB
=
refRectA
;
refRectA
.
w
=
0
;
refRectA
.
h
=
0
;
refRectB
.
w
=
0
;
refRectB
.
h
=
0
;
rectA
=
refRectA
;
rectB
=
refRectB
;
intersection
=
SDL_HasIntersection
(
&
rectA
,
&
rectB
);
_validateHasIntersectionResults
(
intersection
,
SDL_FALSE
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
);
}
/*!
/*!
* \brief Negative tests against SDL_HasIntersection() with invalid parameters
* \brief Negative tests against SDL_HasIntersection() with invalid parameters
*
*
...
@@ -1037,6 +1225,15 @@ int rect_testEnclosePointsWithClipping(void *arg)
...
@@ -1037,6 +1225,15 @@ int rect_testEnclosePointsWithClipping(void *arg)
"Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)"
,
"Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)"
,
minx
,
miny
,
maxx
,
maxy
,
result
.
x
,
result
.
y
,
result
.
x
+
result
.
w
-
1
,
result
.
y
+
result
.
h
-
1
);
minx
,
miny
,
maxx
,
maxy
,
result
.
x
,
result
.
y
,
result
.
x
+
result
.
w
-
1
,
result
.
y
+
result
.
h
-
1
);
}
}
/* Empty clipping rectangle */
clip
.
w
=
0
;
clip
.
h
=
0
;
expectedEnclosed
=
SDL_FALSE
;
anyEnclosed
=
SDL_EnclosePoints
((
const
SDL_Point
*
)
points
,
numPoints
,
(
const
SDL_Rect
*
)
&
clip
,
&
result
);
AssertTrue
(
expectedEnclosed
==
anyEnclosed
,
"Expected return value %s, got %s"
,
(
expectedEnclosed
==
SDL_TRUE
)
?
"true"
:
"false"
,
(
anyEnclosed
==
SDL_TRUE
)
?
"true"
:
"false"
);
}
}
/*!
/*!
...
@@ -1135,6 +1332,69 @@ int rect_testUnionRectOutside(void *arg)
...
@@ -1135,6 +1332,69 @@ int rect_testUnionRectOutside(void *arg)
}
}
}
}
/*!
* \brief Tests SDL_UnionRect() where rect A or rect B are empty
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
*/
int
rect_testUnionRectEmpty
(
void
*
arg
)
{
SDL_Rect
refRectA
,
refRectB
;
SDL_Rect
rectA
,
rectB
;
SDL_Rect
expectedResult
;
SDL_Rect
result
;
/* A empty */
refRectA
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
w
=
0
;
refRectA
.
h
=
0
;
refRectB
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectB
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectB
.
w
=
RandomIntegerInRange
(
1
,
1024
);
refRectB
.
h
=
RandomIntegerInRange
(
1
,
1024
);
expectedResult
=
refRectB
;
rectA
=
refRectA
;
rectB
=
refRectB
;
SDL_UnionRect
(
&
rectA
,
&
rectB
,
&
result
);
_validateUnionRectResults
(
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
,
&
result
,
&
expectedResult
);
/* B empty */
refRectA
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
1024
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
1024
);
refRectB
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectB
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectB
.
w
=
0
;
refRectB
.
h
=
0
;
expectedResult
=
refRectA
;
rectA
=
refRectA
;
rectB
=
refRectB
;
SDL_UnionRect
(
&
rectA
,
&
rectB
,
&
result
);
_validateUnionRectResults
(
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
,
&
result
,
&
expectedResult
);
/* A and B empty */
refRectA
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
w
=
0
;
refRectA
.
h
=
0
;
refRectB
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectB
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectB
.
w
=
0
;
refRectB
.
h
=
0
;
result
.
x
=
0
;
result
.
y
=
0
;
result
.
w
=
0
;
result
.
h
=
0
;
expectedResult
=
result
;
rectA
=
refRectA
;
rectB
=
refRectB
;
SDL_UnionRect
(
&
rectA
,
&
rectB
,
&
result
);
_validateUnionRectResults
(
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
,
&
result
,
&
expectedResult
);
}
/*!
/*!
* \brief Tests SDL_UnionRect() where rect B is inside rect A
* \brief Tests SDL_UnionRect() where rect B is inside rect A
*
*
...
@@ -1273,10 +1533,68 @@ int rect_testRectEmpty(void *arg)
...
@@ -1273,10 +1533,68 @@ int rect_testRectEmpty(void *arg)
*/
*/
int
rect_testRectEmptyParam
(
void
*
arg
)
int
rect_testRectEmptyParam
(
void
*
arg
)
{
{
SDL_Rect
rect
;
SDL_bool
result
;
SDL_bool
result
;
// invalid parameter combinations
// invalid parameter combinations
result
=
SDL_RectEmpty
((
const
SDL_Rect
*
)
NULL
);
result
=
SDL_RectEmpty
((
const
SDL_Rect
*
)
NULL
);
AssertTrue
(
result
=
SDL_TRUE
,
"Function did not return TRUE when 1st parameter was NULL"
);
AssertTrue
(
result
==
SDL_TRUE
,
"Function did not return TRUE when 1st parameter was NULL"
);
}
/*!
* \brief Tests SDL_RectEquals() with various inputs
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
*/
int
rect_testRectEquals
(
void
*
arg
)
{
SDL_Rect
refRectA
;
SDL_Rect
refRectB
;
SDL_Rect
rectA
;
SDL_Rect
rectB
;
SDL_bool
expectedResult
;
SDL_bool
result
;
// Equals
refRectA
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
refRectA
.
w
=
RandomIntegerInRange
(
1
,
1024
);
refRectA
.
h
=
RandomIntegerInRange
(
1
,
1024
);
refRectB
=
refRectA
;
expectedResult
=
SDL_TRUE
;
rectA
=
refRectA
;
rectB
=
refRectB
;
result
=
SDL_RectEquals
((
const
SDL_Rect
*
)
&
rectA
,
(
const
SDL_Rect
*
)
&
rectB
);
_validateRectEqualsResults
(
result
,
expectedResult
,
&
rectA
,
&
rectB
,
&
refRectA
,
&
refRectB
);
}
/*!
* \brief Negative tests against SDL_RectEquals() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
*/
int
rect_testRectEqualsParam
(
void
*
arg
)
{
SDL_Rect
rectA
;
SDL_Rect
rectB
;
SDL_bool
result
;
/* data setup */
rectA
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
rectA
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
rectA
.
w
=
RandomIntegerInRange
(
1
,
1024
);
rectA
.
h
=
RandomIntegerInRange
(
1
,
1024
);
rectB
.
x
=
RandomIntegerInRange
(
-
1024
,
1024
);
rectB
.
y
=
RandomIntegerInRange
(
-
1024
,
1024
);
rectB
.
w
=
RandomIntegerInRange
(
1
,
1024
);
rectB
.
h
=
RandomIntegerInRange
(
1
,
1024
);
// invalid parameter combinations
result
=
SDL_RectEquals
((
const
SDL_Rect
*
)
NULL
,
(
const
SDL_Rect
*
)
&
rectB
);
AssertTrue
(
result
==
SDL_FALSE
,
"Function did not return FALSE when 1st parameter was NULL"
);
result
=
SDL_RectEquals
((
const
SDL_Rect
*
)
&
rectA
,
(
const
SDL_Rect
*
)
NULL
);
AssertTrue
(
result
==
SDL_FALSE
,
"Function did not return FALSE when 2nd parameter was NULL"
);
result
=
SDL_RectEquals
((
const
SDL_Rect
*
)
NULL
,
(
const
SDL_Rect
*
)
NULL
);
AssertTrue
(
result
==
SDL_FALSE
,
"Function did not return FALSE when 1st and 2nd parameter were NULL"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment