test: Basic tests for SDL_FRectEquals Based on the integer version. These tests mostly check that input isn't mangled and that invalid input gives the expected negative result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/test/testautomation_rect.c b/test/testautomation_rect.c
index 26f03e9..cd8f65c 100644
--- a/test/testautomation_rect.c
+++ b/test/testautomation_rect.c
@@ -409,6 +409,32 @@ void _validateRectEqualsResults(
}
/* !
+ * \brief Private helper to check SDL_FRectEquals results
+ */
+void _validateFRectEqualsResults(
+ SDL_bool equals, SDL_bool expectedEquals,
+ SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
+{
+ int cmpRes;
+ SDLTest_AssertCheck(equals == expectedEquals,
+ "Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
+ (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
+ (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
+ rectA->x, rectA->y, rectA->w, rectA->h,
+ rectB->x, rectB->y, rectB->w, rectB->h);
+ cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
+ SDLTest_AssertCheck(cmpRes == 0,
+ "Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
+ rectA->x, rectA->y, rectA->w, rectA->h,
+ refRectA->x, refRectA->y, refRectA->w, refRectA->h);
+ cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
+ SDLTest_AssertCheck(cmpRes == 0,
+ "Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
+ 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
*
* \sa
@@ -1574,6 +1600,69 @@ int rect_testRectEqualsParam(void *arg)
return TEST_COMPLETED;
}
+/* !
+ * \brief Tests SDL_FRectEquals() with various inputs
+ *
+ * \sa
+ * http://wiki.libsdl.org/SDL_FRectEquals
+ */
+int rect_testFRectEquals(void *arg)
+{
+ SDL_FRect refRectA;
+ SDL_FRect refRectB;
+ SDL_FRect rectA;
+ SDL_FRect rectB;
+ SDL_bool expectedResult;
+ SDL_bool result;
+
+ /* Equals */
+ refRectA.x=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
+ refRectA.y=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
+ refRectA.w=(float)SDLTest_RandomIntegerInRange(1, 1024);
+ refRectA.h=(float)SDLTest_RandomIntegerInRange(1, 1024);
+ refRectB = refRectA;
+ expectedResult = SDL_TRUE;
+ rectA = refRectA;
+ rectB = refRectB;
+ result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)&rectB);
+ _validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
+
+ return TEST_COMPLETED;
+}
+
+/* !
+ * \brief Negative tests against SDL_FRectEquals() with invalid parameters
+ *
+ * \sa
+ * http://wiki.libsdl.org/SDL_FRectEquals
+ */
+int rect_testFRectEqualsParam(void *arg)
+{
+ SDL_FRect rectA;
+ SDL_FRect rectB;
+ SDL_bool result;
+
+ /* data setup -- For the purpose of this test, the values don't matter. */
+ rectA.x=SDLTest_RandomFloat();
+ rectA.y=SDLTest_RandomFloat();
+ rectA.w=SDLTest_RandomFloat();
+ rectA.h=SDLTest_RandomFloat();
+ rectB.x=SDLTest_RandomFloat();
+ rectB.y=SDLTest_RandomFloat();
+ rectB.w=SDLTest_RandomFloat();
+ rectB.h=SDLTest_RandomFloat();
+
+ /* invalid parameter combinations */
+ result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)&rectB);
+ SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
+ result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)NULL);
+ SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
+ result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)NULL);
+ SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
+
+ return TEST_COMPLETED;
+}
+
/* ================= Test References ================== */
/* Rect test cases */
@@ -1673,6 +1762,13 @@ static const SDLTest_TestCaseReference rectTest28 =
static const SDLTest_TestCaseReference rectTest29 =
{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
+/* SDL_FRectEquals */
+
+static const SDLTest_TestCaseReference rectTest30 =
+ { (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_FRectEquals with various inputs", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference rectTest31 =
+ { (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_FRectEquals with invalid parameters", TEST_ENABLED };
/* !
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
@@ -1683,7 +1779,7 @@ static const SDLTest_TestCaseReference rectTest29 =
static const SDLTest_TestCaseReference *rectTests[] = {
&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
- &rectTest28, &rectTest29, NULL
+ &rectTest28, &rectTest29, &rectTest30, &rectTest31, NULL
};