Atlas - testautomation_rect.c

Home / ext / SDL / test Lines: 1 | Size: 93858 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/** 2 * Original code: automated SDL rect test written by Edgar Simo "bobbens" 3 * New/updated tests: aschiffler at ferzkopp dot net 4 */ 5#include <limits.h> 6#include <SDL3/SDL.h> 7#include <SDL3/SDL_test.h> 8#include "testautomation_suites.h" 9 10/* ================= Test Case Implementation ================== */ 11 12/* Helper functions */ 13 14/** 15 * Private helper to check SDL_GetRectAndLineIntersectionFloat results 16 */ 17static bool IsFRectEqual(const SDL_FRect *r1, const SDL_FRect *r2) { 18 static const float MAX_DELTA = 1e-5f; 19 SDL_FRect delta; 20 delta.x = r1->x - r2->x; 21 delta.y = r1->y - r2->y; 22 delta.w = r1->w - r2->w; 23 delta.h = r1->h - r2->h; 24 25 return -MAX_DELTA <= delta.x && delta.x <= MAX_DELTA 26 && -MAX_DELTA <= delta.y && delta.y <= MAX_DELTA 27 && -MAX_DELTA <= delta.w && delta.w <= MAX_DELTA 28 && -MAX_DELTA <= delta.w && delta.h <= MAX_DELTA; 29} 30 31/* ! 32 * \brief Private helper to check SDL_FPoint equality 33 */ 34static bool IsFPointEqual(const SDL_FPoint *p1, const SDL_FPoint *p2) { 35 static const float MAX_DELTA = 1e-5f; 36 SDL_FPoint delta; 37 delta.x = p1->x - p2->x; 38 delta.y = p1->y - p2->y; 39 40 return -MAX_DELTA <= delta.x && delta.x <= MAX_DELTA 41 && -MAX_DELTA <= delta.y && delta.y <= MAX_DELTA; 42} 43 44static void validateIntersectRectAndLineFloatResults( 45 bool intersection, bool expectedIntersection, 46 SDL_FRect *rect, 47 float x1, float y1, float x2, float y2, 48 float x1Ref, float y1Ref, float x2Ref, float y2Ref) 49{ 50 SDLTest_AssertCheck(intersection == expectedIntersection, 51 "Check for correct intersection result: expected %s, got %s intersecting rect (%.2f,%.2f,%.2f,%.2f) with line (%.2f,%.2f - %.2f,%.2f)", 52 (expectedIntersection == true) ? "true" : "false", 53 (intersection == true) ? "true" : "false", 54 rect->x, rect->y, rect->w, rect->h, 55 x1Ref, y1Ref, x2Ref, y2Ref); 56 SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref, 57 "Check if line was incorrectly clipped or modified: got (%.2f,%.2f - %.2f,%.2f) expected (%.2f,%.2f - %.2f,%.2f)", 58 x1, y1, x2, y2, 59 x1Ref, y1Ref, x2Ref, y2Ref); 60} 61 62/** 63 * Private helper to check SDL_GetRectAndLineIntersection results 64 */ 65static void validateIntersectRectAndLineResults( 66 bool intersection, bool expectedIntersection, 67 SDL_Rect *rect, SDL_Rect *refRect, 68 int x1, int y1, int x2, int y2, 69 int x1Ref, int y1Ref, int x2Ref, int y2Ref) 70{ 71 SDLTest_AssertCheck(intersection == expectedIntersection, 72 "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)", 73 (expectedIntersection == true) ? "true" : "false", 74 (intersection == true) ? "true" : "false", 75 refRect->x, refRect->y, refRect->w, refRect->h, 76 x1Ref, y1Ref, x2Ref, y2Ref); 77 SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h, 78 "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 79 rect->x, rect->y, rect->w, rect->h, 80 refRect->x, refRect->y, refRect->w, refRect->h); 81 SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref, 82 "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)", 83 x1, y1, x2, y2, 84 x1Ref, y1Ref, x2Ref, y2Ref); 85} 86 87/* Test case functions */ 88 89/** 90 * Tests SDL_GetRectAndLineIntersectionFloat() clipping cases 91 * 92 * \sa SDL_GetRectAndLineIntersectionFloat 93 */ 94static int SDLCALL rect_testIntersectRectAndLineFloat(void *arg) 95{ 96 SDL_FRect rect; 97 float x1, y1; 98 float x2, y2; 99 bool intersected; 100 101 x1 = 5.0f; 102 y1 = 6.0f; 103 x2 = 23.0f; 104 y2 = 6.0f; 105 rect.x = 2.5f; 106 rect.y = 1.5f; 107 rect.w = 15.25f; 108 rect.h = 12.0f; 109 intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2); 110 validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 5.0f, 6.0f, 17.75f, 6.0f); 111 112 x1 = 0.0f; 113 y1 = 6.0f; 114 x2 = 23.0f; 115 y2 = 6.0f; 116 rect.x = 2.5f; 117 rect.y = 1.5f; 118 rect.w = 0.25f; 119 rect.h = 12.0f; 120 intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2); 121 validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 2.5f, 6.0f, 2.75f, 6.0f); 122 123 x1 = 456.0f; 124 y1 = 592.0f; 125 x2 = 160.0f; 126 y2 = 670.0f; 127 rect.x = 300.0f; 128 rect.y = 592.0f; 129 rect.w = 64.0f; 130 rect.h = 64.0f; 131 intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2); 132 validateIntersectRectAndLineFloatResults(intersected, true, &rect, x1, y1, x2, y2, 364.0f, 616.243225f, 300.0f, 633.108093f); 133 134 return TEST_COMPLETED; 135} 136 137/** 138 * Tests SDL_GetRectAndLineIntersection() clipping cases 139 * 140 * \sa SDL_GetRectAndLineIntersection 141 */ 142static int SDLCALL rect_testIntersectRectAndLine(void *arg) 143{ 144 SDL_Rect refRect = { 0, 0, 32, 32 }; 145 SDL_Rect rect; 146 int x1, y1; 147 int x2, y2; 148 bool intersected; 149 150 int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w); 151 int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w); 152 int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h); 153 int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h); 154 155 x1 = xLeft; 156 y1 = 15; 157 x2 = xRight; 158 y2 = 15; 159 rect = refRect; 160 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 161 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15); 162 163 x1 = 15; 164 y1 = yTop; 165 x2 = 15; 166 y2 = yBottom; 167 rect = refRect; 168 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 169 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31); 170 171 x1 = -refRect.w; 172 y1 = -refRect.h; 173 x2 = 2 * refRect.w; 174 y2 = 2 * refRect.h; 175 rect = refRect; 176 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 177 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31); 178 179 x1 = 2 * refRect.w; 180 y1 = 2 * refRect.h; 181 x2 = -refRect.w; 182 y2 = -refRect.h; 183 rect = refRect; 184 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 185 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0); 186 187 x1 = -1; 188 y1 = 32; 189 x2 = 32; 190 y2 = -1; 191 rect = refRect; 192 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 193 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0); 194 195 x1 = 32; 196 y1 = -1; 197 x2 = -1; 198 y2 = 32; 199 rect = refRect; 200 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 201 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31); 202 203 /* Test some overflow cases */ 204 refRect.x = INT_MAX - 4; 205 refRect.y = INT_MAX - 4; 206 x1 = INT_MAX; 207 y1 = INT_MIN; 208 x2 = INT_MIN; 209 y2 = INT_MAX; 210 rect = refRect; 211 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 212 validateIntersectRectAndLineResults(intersected, false, &rect, &refRect, x1, y1, x2, y2, x1, y1, x2, y2); 213 214 return TEST_COMPLETED; 215} 216 217/** 218 * Tests SDL_GetRectAndLineIntersection() non-clipping case line inside 219 * 220 * \sa SDL_GetRectAndLineIntersection 221 */ 222static int SDLCALL rect_testIntersectRectAndLineInside(void *arg) 223{ 224 SDL_Rect refRect = { 0, 0, 32, 32 }; 225 SDL_Rect rect; 226 int x1, y1; 227 int x2, y2; 228 bool intersected; 229 230 int xmin = refRect.x; 231 int xmax = refRect.x + refRect.w - 1; 232 int ymin = refRect.y; 233 int ymax = refRect.y + refRect.h - 1; 234 int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1); 235 int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1); 236 int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1); 237 int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1); 238 239 x1 = x1Ref; 240 y1 = y1Ref; 241 x2 = x2Ref; 242 y2 = y2Ref; 243 rect = refRect; 244 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 245 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref); 246 247 x1 = x1Ref; 248 y1 = y1Ref; 249 x2 = xmax; 250 y2 = ymax; 251 rect = refRect; 252 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 253 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax); 254 255 x1 = xmin; 256 y1 = ymin; 257 x2 = x2Ref; 258 y2 = y2Ref; 259 rect = refRect; 260 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 261 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref); 262 263 x1 = xmin; 264 y1 = ymin; 265 x2 = xmax; 266 y2 = ymax; 267 rect = refRect; 268 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 269 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax); 270 271 x1 = xmin; 272 y1 = ymax; 273 x2 = xmax; 274 y2 = ymin; 275 rect = refRect; 276 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 277 validateIntersectRectAndLineResults(intersected, true, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin); 278 279 return TEST_COMPLETED; 280} 281 282/** 283 * Tests SDL_GetRectAndLineIntersection() non-clipping cases outside 284 * 285 * \sa SDL_GetRectAndLineIntersection 286 */ 287static int SDLCALL rect_testIntersectRectAndLineOutside(void *arg) 288{ 289 SDL_Rect refRect = { 0, 0, 32, 32 }; 290 SDL_Rect rect; 291 int x1, y1; 292 int x2, y2; 293 bool intersected; 294 295 int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w); 296 int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w); 297 int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h); 298 int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h); 299 300 x1 = xLeft; 301 y1 = 0; 302 x2 = xLeft; 303 y2 = 31; 304 rect = refRect; 305 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 306 validateIntersectRectAndLineResults(intersected, false, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31); 307 308 x1 = xRight; 309 y1 = 0; 310 x2 = xRight; 311 y2 = 31; 312 rect = refRect; 313 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 314 validateIntersectRectAndLineResults(intersected, false, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31); 315 316 x1 = 0; 317 y1 = yTop; 318 x2 = 31; 319 y2 = yTop; 320 rect = refRect; 321 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 322 validateIntersectRectAndLineResults(intersected, false, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop); 323 324 x1 = 0; 325 y1 = yBottom; 326 x2 = 31; 327 y2 = yBottom; 328 rect = refRect; 329 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 330 validateIntersectRectAndLineResults(intersected, false, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom); 331 332 return TEST_COMPLETED; 333} 334 335/** 336 * Tests SDL_GetRectAndLineIntersection() with empty rectangle 337 * 338 * \sa SDL_GetRectAndLineIntersection 339 */ 340static int SDLCALL rect_testIntersectRectAndLineEmpty(void *arg) 341{ 342 SDL_Rect refRect; 343 SDL_Rect rect; 344 int x1, y1, x1Ref, y1Ref; 345 int x2, y2, x2Ref, y2Ref; 346 bool intersected; 347 348 refRect.x = SDLTest_RandomIntegerInRange(1, 1024); 349 refRect.y = SDLTest_RandomIntegerInRange(1, 1024); 350 refRect.w = 0; 351 refRect.h = 0; 352 x1Ref = refRect.x; 353 y1Ref = refRect.y; 354 x2Ref = SDLTest_RandomIntegerInRange(1, 1024); 355 y2Ref = SDLTest_RandomIntegerInRange(1, 1024); 356 357 x1 = x1Ref; 358 y1 = y1Ref; 359 x2 = x2Ref; 360 y2 = y2Ref; 361 rect = refRect; 362 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 363 validateIntersectRectAndLineResults(intersected, false, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref); 364 365 return TEST_COMPLETED; 366} 367 368/** 369 * Negative tests against SDL_GetRectAndLineIntersection() with invalid parameters 370 * 371 * \sa SDL_GetRectAndLineIntersection 372 */ 373static int SDLCALL rect_testIntersectRectAndLineParam(void *arg) 374{ 375 SDL_Rect rect = { 0, 0, 32, 32 }; 376 int x1 = rect.w / 2; 377 int y1 = rect.h / 2; 378 int x2 = x1; 379 int y2 = 2 * rect.h; 380 bool intersected; 381 382 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2); 383 SDLTest_AssertCheck(intersected == true, "Check that intersection result was true"); 384 385 intersected = SDL_GetRectAndLineIntersection((SDL_Rect *)NULL, &x1, &y1, &x2, &y2); 386 SDLTest_AssertCheck(intersected == false, "Check that function returns false when 1st parameter is NULL"); 387 intersected = SDL_GetRectAndLineIntersection(&rect, (int *)NULL, &y1, &x2, &y2); 388 SDLTest_AssertCheck(intersected == false, "Check that function returns false when 2nd parameter is NULL"); 389 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, (int *)NULL, &x2, &y2); 390 SDLTest_AssertCheck(intersected == false, "Check that function returns false when 3rd parameter is NULL"); 391 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, (int *)NULL, &y2); 392 SDLTest_AssertCheck(intersected == false, "Check that function returns false when 4th parameter is NULL"); 393 intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, (int *)NULL); 394 SDLTest_AssertCheck(intersected == false, "Check that function returns false when 5th parameter is NULL"); 395 intersected = SDL_GetRectAndLineIntersection((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL); 396 SDLTest_AssertCheck(intersected == false, "Check that function returns false when all parameters are NULL"); 397 398 return TEST_COMPLETED; 399} 400 401/** 402 * Private helper to check SDL_HasRectIntersectionFloat results 403 */ 404static void validateHasIntersectionFloatResults( 405 bool intersection, bool expectedIntersection, 406 SDL_FRect *rectA, SDL_FRect *rectB) 407{ 408 SDLTest_AssertCheck(intersection == expectedIntersection, 409 "Check intersection result: expected %s, got %s intersecting A (%.2f,%.2f,%.2f,%.2f) with B (%.2f,%.2f,%.2f,%.2f)", 410 (expectedIntersection == true) ? "true" : "false", 411 (intersection == true) ? "true" : "false", 412 rectA->x, rectA->y, rectA->w, rectA->h, 413 rectB->x, rectB->y, rectB->w, rectB->h); 414} 415 416/** 417 * Private helper to check SDL_HasRectIntersection results 418 */ 419static void validateHasIntersectionResults( 420 bool intersection, bool expectedIntersection, 421 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB) 422{ 423 SDLTest_AssertCheck(intersection == expectedIntersection, 424 "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)", 425 (expectedIntersection == true) ? "true" : "false", 426 (intersection == true) ? "true" : "false", 427 rectA->x, rectA->y, rectA->w, rectA->h, 428 rectB->x, rectB->y, rectB->w, rectB->h); 429 SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h, 430 "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 431 rectA->x, rectA->y, rectA->w, rectA->h, 432 refRectA->x, refRectA->y, refRectA->w, refRectA->h); 433 SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h, 434 "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 435 rectB->x, rectB->y, rectB->w, rectB->h, 436 refRectB->x, refRectB->y, refRectB->w, refRectB->h); 437} 438 439/** 440 * Private helper to check SDL_GetRectIntersection results 441 */ 442static void validateIntersectRectFloatResults( 443 bool intersection, bool expectedIntersection, 444 SDL_FRect *rectA, SDL_FRect *rectB, 445 SDL_FRect *result, SDL_FRect *expectedResult) 446{ 447 validateHasIntersectionFloatResults(intersection, expectedIntersection, rectA, rectB); 448 if (result && expectedResult) { 449 SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h, 450 "Check that intersection of rectangles A (%.2f,%.2f, %.2fx%.2f) and B (%.2f,%.2f %.2fx%.2f) was correctly calculated, got (%.2f,%.2f %.2fx%.2f) expected (%.2f,%.2f,%.2f,%.2f)", 451 rectA->x, rectA->y, rectA->w, rectA->h, 452 rectB->x, rectB->y, rectB->w, rectB->h, 453 result->x, result->y, result->w, result->h, 454 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h); 455 } 456 SDLTest_AssertCheck(intersection == SDL_HasRectIntersectionFloat(rectA, rectB), 457 "Check that intersection (%s) matches SDL_HasRectIntersectionFloat() result (%s)", 458 intersection ? "true" : "false", 459 SDL_HasRectIntersectionFloat(rectA, rectB) ? "true" : "false"); 460} 461 462/** 463 * Private helper to check SDL_GetRectIntersection results 464 */ 465static void validateIntersectRectResults( 466 bool intersection, bool expectedIntersection, 467 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, 468 SDL_Rect *result, SDL_Rect *expectedResult) 469{ 470 validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB); 471 if (result && expectedResult) { 472 SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h, 473 "Check that intersection of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was correctly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 474 rectA->x, rectA->y, rectA->w, rectA->h, 475 rectB->x, rectB->y, rectB->w, rectB->h, 476 result->x, result->y, result->w, result->h, 477 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h); 478 } 479} 480 481/** 482 * Private helper to check SDL_GetRectUnion results 483 */ 484static void validateUnionRectResults( 485 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, 486 SDL_Rect *result, SDL_Rect *expectedResult) 487{ 488 SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h, 489 "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 490 rectA->x, rectA->y, rectA->w, rectA->h, 491 refRectA->x, refRectA->y, refRectA->w, refRectA->h); 492 SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h, 493 "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 494 rectB->x, rectB->y, rectB->w, rectB->h, 495 refRectB->x, refRectB->y, refRectB->w, refRectB->h); 496 SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h, 497 "Check that union of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was correctly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 498 rectA->x, rectA->y, rectA->w, rectA->h, 499 rectB->x, rectB->y, rectB->w, rectB->h, 500 result->x, result->y, result->w, result->h, 501 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h); 502} 503 504/** 505 * Private helper to check SDL_RectEmptyFloat results 506 */ 507static void validateRectEmptyFloatResults( 508 bool empty, bool expectedEmpty, 509 SDL_FRect *rect) 510{ 511 SDLTest_AssertCheck(empty == expectedEmpty, 512 "Check for correct empty result: expected %s, got %s testing (%.2f,%.2f,%.2f,%.2f)", 513 (expectedEmpty == true) ? "true" : "false", 514 (empty == true) ? "true" : "false", 515 rect->x, rect->y, rect->w, rect->h); 516} 517 518/** 519 * Private helper to check SDL_RectEmpty results 520 */ 521static void validateRectEmptyResults( 522 bool empty, bool expectedEmpty, 523 SDL_Rect *rect, SDL_Rect *refRect) 524{ 525 SDLTest_AssertCheck(empty == expectedEmpty, 526 "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)", 527 (expectedEmpty == true) ? "true" : "false", 528 (empty == true) ? "true" : "false", 529 rect->x, rect->y, rect->w, rect->h); 530 SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h, 531 "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 532 rect->x, rect->y, rect->w, rect->h, 533 refRect->x, refRect->y, refRect->w, refRect->h); 534} 535 536/** 537 * Private helper to check SDL_RectsEqual results 538 */ 539static void validateRectEqualsResults( 540 bool equals, bool expectedEquals, 541 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB) 542{ 543 SDLTest_AssertCheck(equals == expectedEquals, 544 "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)", 545 (expectedEquals == true) ? "true" : "false", 546 (equals == true) ? "true" : "false", 547 rectA->x, rectA->y, rectA->w, rectA->h, 548 rectB->x, rectB->y, rectB->w, rectB->h); 549 SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h, 550 "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 551 rectA->x, rectA->y, rectA->w, rectA->h, 552 refRectA->x, refRectA->y, refRectA->w, refRectA->h); 553 SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h, 554 "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)", 555 rectB->x, rectB->y, rectB->w, rectB->h, 556 refRectB->x, refRectB->y, refRectB->w, refRectB->h); 557} 558 559/** 560 * Private helper to check SDL_RectsEqualFloat results 561 */ 562static void validateFRectEqualsResults( 563 bool equals, bool expectedEquals, 564 SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB) 565{ 566 int cmpRes; 567 SDLTest_AssertCheck(equals == expectedEquals, 568 "Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)", 569 (expectedEquals == true) ? "true" : "false", 570 (equals == true) ? "true" : "false", 571 rectA->x, rectA->y, rectA->w, rectA->h, 572 rectB->x, rectB->y, rectB->w, rectB->h); 573 cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA)); 574 SDLTest_AssertCheck(cmpRes == 0, 575 "Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)", 576 rectA->x, rectA->y, rectA->w, rectA->h, 577 refRectA->x, refRectA->y, refRectA->w, refRectA->h); 578 cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB)); 579 SDLTest_AssertCheck(cmpRes == 0, 580 "Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)", 581 rectB->x, rectB->y, rectB->w, rectB->h, 582 refRectB->x, refRectB->y, refRectB->w, refRectB->h); 583} 584 585/** 586 * Tests SDL_GetRectIntersectionFloat() 587 * 588 * \sa SDL_GetRectIntersectionFloat 589 */ 590static int SDLCALL rect_testIntersectRectFloat(void *arg) 591{ 592 SDL_FRect rectA; 593 SDL_FRect rectB; 594 SDL_FRect result; 595 SDL_FRect expectedResult; 596 bool intersection; 597 598 rectA.x = 0.0f; 599 rectA.y = 0.0f; 600 rectA.w = 1.0f; 601 rectA.h = 1.0f; 602 rectB.x = 0.0f; 603 rectB.y = 0.0f; 604 rectB.w = 1.0f; 605 rectB.h = 1.0f; 606 expectedResult = rectA; 607 intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result); 608 validateIntersectRectFloatResults(intersection, true, &rectA, &rectB, &result, &expectedResult); 609 610 rectA.x = 0.0f; 611 rectA.y = 0.0f; 612 rectA.w = 1.0f; 613 rectA.h = 1.0f; 614 rectB.x = 1.0f; 615 rectB.y = 0.0f; 616 rectB.w = 1.0f; 617 rectB.h = 1.0f; 618 expectedResult = rectB; 619 expectedResult.w = 0.0f; 620 intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result); 621 validateIntersectRectFloatResults(intersection, true, &rectA, &rectB, &result, &expectedResult); 622 623 rectA.x = 0.0f; 624 rectA.y = 0.0f; 625 rectA.w = 1.0f; 626 rectA.h = 1.0f; 627 rectB.x = 1.0f; 628 rectB.y = 1.0f; 629 rectB.w = 1.0f; 630 rectB.h = 1.0f; 631 expectedResult = rectB; 632 expectedResult.w = 0.0f; 633 expectedResult.h = 0.0f; 634 intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result); 635 validateIntersectRectFloatResults(intersection, true, &rectA, &rectB, &result, &expectedResult); 636 637 rectA.x = 0.0f; 638 rectA.y = 0.0f; 639 rectA.w = 1.0f; 640 rectA.h = 1.0f; 641 rectB.x = 2.0f; 642 rectB.y = 0.0f; 643 rectB.w = 1.0f; 644 rectB.h = 1.0f; 645 expectedResult = rectB; 646 expectedResult.w = -1.0f; 647 intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result); 648 validateIntersectRectFloatResults(intersection, false, &rectA, &rectB, &result, &expectedResult); 649 650 return TEST_COMPLETED; 651} 652 653/** 654 * Tests SDL_GetRectIntersection() with B fully inside A 655 * 656 * \sa SDL_GetRectIntersection 657 */ 658static int SDLCALL rect_testIntersectRectInside(void *arg) 659{ 660 SDL_Rect refRectA = { 0, 0, 32, 32 }; 661 SDL_Rect refRectB; 662 SDL_Rect rectA; 663 SDL_Rect rectB; 664 SDL_Rect result; 665 bool intersection; 666 667 /* rectB fully contained in rectA */ 668 refRectB.x = 0; 669 refRectB.y = 0; 670 refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1); 671 refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1); 672 rectA = refRectA; 673 rectB = refRectB; 674 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 675 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB); 676 677 return TEST_COMPLETED; 678} 679 680/** 681 * Tests SDL_GetRectIntersection() with B fully outside A 682 * 683 * \sa SDL_GetRectIntersection 684 */ 685static int SDLCALL rect_testIntersectRectOutside(void *arg) 686{ 687 SDL_Rect refRectA = { 0, 0, 32, 32 }; 688 SDL_Rect refRectB; 689 SDL_Rect rectA; 690 SDL_Rect rectB; 691 SDL_Rect result; 692 bool intersection; 693 694 /* rectB fully outside of rectA */ 695 refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10); 696 refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10); 697 refRectB.w = refRectA.w; 698 refRectB.h = refRectA.h; 699 rectA = refRectA; 700 rectB = refRectB; 701 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 702 validateIntersectRectResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 703 704 return TEST_COMPLETED; 705} 706 707/** 708 * Tests SDL_GetRectIntersection() with B partially intersecting A 709 * 710 * \sa SDL_GetRectIntersection 711 */ 712static int SDLCALL rect_testIntersectRectPartial(void *arg) 713{ 714 SDL_Rect refRectA = { 0, 0, 32, 32 }; 715 SDL_Rect refRectB; 716 SDL_Rect rectA; 717 SDL_Rect rectB; 718 SDL_Rect result; 719 SDL_Rect expectedResult; 720 bool intersection; 721 722 /* rectB partially contained in rectA */ 723 refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1); 724 refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1); 725 refRectB.w = refRectA.w; 726 refRectB.h = refRectA.h; 727 rectA = refRectA; 728 rectB = refRectB; 729 expectedResult.x = refRectB.x; 730 expectedResult.y = refRectB.y; 731 expectedResult.w = refRectA.w - refRectB.x; 732 expectedResult.h = refRectA.h - refRectB.y; 733 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 734 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 735 736 /* rectB right edge */ 737 refRectB.x = rectA.w - 1; 738 refRectB.y = rectA.y; 739 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1); 740 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1); 741 rectA = refRectA; 742 rectB = refRectB; 743 expectedResult.x = refRectB.x; 744 expectedResult.y = refRectB.y; 745 expectedResult.w = 1; 746 expectedResult.h = refRectB.h; 747 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 748 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 749 750 /* rectB left edge */ 751 refRectB.x = 1 - rectA.w; 752 refRectB.y = rectA.y; 753 refRectB.w = refRectA.w; 754 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1); 755 rectA = refRectA; 756 rectB = refRectB; 757 expectedResult.x = 0; 758 expectedResult.y = refRectB.y; 759 expectedResult.w = 1; 760 expectedResult.h = refRectB.h; 761 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 762 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 763 764 /* rectB bottom edge */ 765 refRectB.x = rectA.x; 766 refRectB.y = rectA.h - 1; 767 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1); 768 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1); 769 rectA = refRectA; 770 rectB = refRectB; 771 expectedResult.x = refRectB.x; 772 expectedResult.y = refRectB.y; 773 expectedResult.w = refRectB.w; 774 expectedResult.h = 1; 775 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 776 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 777 778 /* rectB top edge */ 779 refRectB.x = rectA.x; 780 refRectB.y = 1 - rectA.h; 781 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1); 782 refRectB.h = rectA.h; 783 rectA = refRectA; 784 rectB = refRectB; 785 expectedResult.x = refRectB.x; 786 expectedResult.y = 0; 787 expectedResult.w = refRectB.w; 788 expectedResult.h = 1; 789 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 790 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 791 792 return TEST_COMPLETED; 793} 794 795/** 796 * Tests SDL_GetRectIntersection() with 1x1 pixel sized rectangles 797 * 798 * \sa SDL_GetRectIntersection 799 */ 800static int SDLCALL rect_testIntersectRectPoint(void *arg) 801{ 802 SDL_Rect refRectA = { 0, 0, 1, 1 }; 803 SDL_Rect refRectB = { 0, 0, 1, 1 }; 804 SDL_Rect rectA; 805 SDL_Rect rectB; 806 SDL_Rect result; 807 bool intersection; 808 int offsetX, offsetY; 809 810 /* intersecting pixels */ 811 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 812 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 813 refRectB.x = refRectA.x; 814 refRectB.y = refRectA.y; 815 rectA = refRectA; 816 rectB = refRectB; 817 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 818 validateIntersectRectResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA); 819 820 /* non-intersecting pixels cases */ 821 for (offsetX = -1; offsetX <= 1; offsetX++) { 822 for (offsetY = -1; offsetY <= 1; offsetY++) { 823 if (offsetX != 0 || offsetY != 0) { 824 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 825 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 826 refRectB.x = refRectA.x; 827 refRectB.y = refRectA.y; 828 refRectB.x += offsetX; 829 refRectB.y += offsetY; 830 rectA = refRectA; 831 rectB = refRectB; 832 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 833 validateIntersectRectResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 834 } 835 } 836 } 837 838 return TEST_COMPLETED; 839} 840 841/** 842 * Tests SDL_GetRectIntersection() with empty rectangles 843 * 844 * \sa SDL_GetRectIntersection 845 */ 846static int SDLCALL rect_testIntersectRectEmpty(void *arg) 847{ 848 SDL_Rect refRectA; 849 SDL_Rect refRectB; 850 SDL_Rect rectA; 851 SDL_Rect rectB; 852 SDL_Rect result; 853 bool intersection; 854 bool empty; 855 856 /* Rect A empty */ 857 result.w = SDLTest_RandomIntegerInRange(1, 100); 858 result.h = SDLTest_RandomIntegerInRange(1, 100); 859 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 860 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 861 refRectA.w = SDLTest_RandomIntegerInRange(1, 100); 862 refRectA.h = SDLTest_RandomIntegerInRange(1, 100); 863 refRectB = refRectA; 864 refRectA.w = 0; 865 refRectA.h = 0; 866 rectA = refRectA; 867 rectB = refRectB; 868 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 869 validateIntersectRectResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 870 empty = SDL_RectEmpty(&result); 871 SDLTest_AssertCheck(empty == true, "Validate result is empty Rect; got: %s", (empty == true) ? "true" : "false"); 872 873 /* Rect B empty */ 874 result.w = SDLTest_RandomIntegerInRange(1, 100); 875 result.h = SDLTest_RandomIntegerInRange(1, 100); 876 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 877 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 878 refRectA.w = SDLTest_RandomIntegerInRange(1, 100); 879 refRectA.h = SDLTest_RandomIntegerInRange(1, 100); 880 refRectB = refRectA; 881 refRectB.w = 0; 882 refRectB.h = 0; 883 rectA = refRectA; 884 rectB = refRectB; 885 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 886 validateIntersectRectResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 887 empty = SDL_RectEmpty(&result); 888 SDLTest_AssertCheck(empty == true, "Validate result is empty Rect; got: %s", (empty == true) ? "true" : "false"); 889 890 /* Rect A and B empty */ 891 result.w = SDLTest_RandomIntegerInRange(1, 100); 892 result.h = SDLTest_RandomIntegerInRange(1, 100); 893 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 894 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 895 refRectA.w = SDLTest_RandomIntegerInRange(1, 100); 896 refRectA.h = SDLTest_RandomIntegerInRange(1, 100); 897 refRectB = refRectA; 898 refRectA.w = 0; 899 refRectA.h = 0; 900 refRectB.w = 0; 901 refRectB.h = 0; 902 rectA = refRectA; 903 rectB = refRectB; 904 intersection = SDL_GetRectIntersection(&rectA, &rectB, &result); 905 validateIntersectRectResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 906 empty = SDL_RectEmpty(&result); 907 SDLTest_AssertCheck(empty == true, "Validate result is empty Rect; got: %s", (empty == true) ? "true" : "false"); 908 909 return TEST_COMPLETED; 910} 911 912/** 913 * Negative tests against SDL_GetRectIntersection() with invalid parameters 914 * 915 * \sa SDL_GetRectIntersection 916 */ 917static int SDLCALL rect_testIntersectRectParam(void *arg) 918{ 919 SDL_Rect rectA = { 0 }; 920 SDL_Rect rectB = { 0 }; 921 SDL_Rect result; 922 bool intersection; 923 924 /* invalid parameter combinations */ 925 intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, &rectB, &result); 926 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 1st parameter is NULL"); 927 intersection = SDL_GetRectIntersection(&rectA, (SDL_Rect *)NULL, &result); 928 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 2nd parameter is NULL"); 929 intersection = SDL_GetRectIntersection(&rectA, &rectB, (SDL_Rect *)NULL); 930 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 3rd parameter is NULL"); 931 intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result); 932 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 1st and 2nd parameters are NULL"); 933 intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL); 934 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 1st and 3rd parameters are NULL "); 935 intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 936 SDLTest_AssertCheck(intersection == false, "Check that function returns false when all parameters are NULL"); 937 938 return TEST_COMPLETED; 939} 940 941/** 942 * Tests SDL_HasRectIntersection() with B fully inside A 943 * 944 * \sa SDL_HasRectIntersection 945 */ 946static int SDLCALL rect_testHasIntersectionInside(void *arg) 947{ 948 SDL_Rect refRectA = { 0, 0, 32, 32 }; 949 SDL_Rect refRectB; 950 SDL_Rect rectA; 951 SDL_Rect rectB; 952 bool intersection; 953 954 /* rectB fully contained in rectA */ 955 refRectB.x = 0; 956 refRectB.y = 0; 957 refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1); 958 refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1); 959 rectA = refRectA; 960 rectB = refRectB; 961 intersection = SDL_HasRectIntersection(&rectA, &rectB); 962 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 963 964 return TEST_COMPLETED; 965} 966 967/** 968 * Tests SDL_HasRectIntersection() with B fully outside A 969 * 970 * \sa SDL_HasRectIntersection 971 */ 972static int SDLCALL rect_testHasIntersectionOutside(void *arg) 973{ 974 SDL_Rect refRectA = { 0, 0, 32, 32 }; 975 SDL_Rect refRectB; 976 SDL_Rect rectA; 977 SDL_Rect rectB; 978 bool intersection; 979 980 /* rectB fully outside of rectA */ 981 refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10); 982 refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10); 983 refRectB.w = refRectA.w; 984 refRectB.h = refRectA.h; 985 rectA = refRectA; 986 rectB = refRectB; 987 intersection = SDL_HasRectIntersection(&rectA, &rectB); 988 validateHasIntersectionResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB); 989 990 return TEST_COMPLETED; 991} 992 993/** 994 * Tests SDL_HasRectIntersection() with B partially intersecting A 995 * 996 * \sa SDL_HasRectIntersection 997 */ 998static int SDLCALL rect_testHasIntersectionPartial(void *arg) 999{ 1000 SDL_Rect refRectA = { 0, 0, 32, 32 }; 1001 SDL_Rect refRectB; 1002 SDL_Rect rectA; 1003 SDL_Rect rectB; 1004 bool intersection; 1005 1006 /* rectB partially contained in rectA */ 1007 refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1); 1008 refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1); 1009 refRectB.w = refRectA.w; 1010 refRectB.h = refRectA.h; 1011 rectA = refRectA; 1012 rectB = refRectB; 1013 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1014 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 1015 1016 /* rectB right edge */ 1017 refRectB.x = rectA.w - 1; 1018 refRectB.y = rectA.y; 1019 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1); 1020 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1); 1021 rectA = refRectA; 1022 rectB = refRectB; 1023 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1024 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 1025 1026 /* rectB left edge */ 1027 refRectB.x = 1 - rectA.w; 1028 refRectB.y = rectA.y; 1029 refRectB.w = refRectA.w; 1030 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1); 1031 rectA = refRectA; 1032 rectB = refRectB; 1033 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1034 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 1035 1036 /* rectB bottom edge */ 1037 refRectB.x = rectA.x; 1038 refRectB.y = rectA.h - 1; 1039 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1); 1040 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1); 1041 rectA = refRectA; 1042 rectB = refRectB; 1043 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1044 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 1045 1046 /* rectB top edge */ 1047 refRectB.x = rectA.x; 1048 refRectB.y = 1 - rectA.h; 1049 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1); 1050 refRectB.h = rectA.h; 1051 rectA = refRectA; 1052 rectB = refRectB; 1053 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1054 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 1055 1056 return TEST_COMPLETED; 1057} 1058 1059/** 1060 * Tests SDL_HasRectIntersection() with 1x1 pixel sized rectangles 1061 * 1062 * \sa SDL_HasRectIntersection 1063 */ 1064static int SDLCALL rect_testHasIntersectionPoint(void *arg) 1065{ 1066 SDL_Rect refRectA = { 0, 0, 1, 1 }; 1067 SDL_Rect refRectB = { 0, 0, 1, 1 }; 1068 SDL_Rect rectA; 1069 SDL_Rect rectB; 1070 bool intersection; 1071 int offsetX, offsetY; 1072 1073 /* intersecting pixels */ 1074 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 1075 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 1076 refRectB.x = refRectA.x; 1077 refRectB.y = refRectA.y; 1078 rectA = refRectA; 1079 rectB = refRectB; 1080 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1081 validateHasIntersectionResults(intersection, true, &rectA, &rectB, &refRectA, &refRectB); 1082 1083 /* non-intersecting pixels cases */ 1084 for (offsetX = -1; offsetX <= 1; offsetX++) { 1085 for (offsetY = -1; offsetY <= 1; offsetY++) { 1086 if (offsetX != 0 || offsetY != 0) { 1087 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 1088 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 1089 refRectB.x = refRectA.x; 1090 refRectB.y = refRectA.y; 1091 refRectB.x += offsetX; 1092 refRectB.y += offsetY; 1093 rectA = refRectA; 1094 rectB = refRectB; 1095 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1096 validateHasIntersectionResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB); 1097 } 1098 } 1099 } 1100 1101 return TEST_COMPLETED; 1102} 1103 1104/** 1105 * Tests SDL_HasRectIntersection() with empty rectangles 1106 * 1107 * \sa SDL_HasRectIntersection 1108 */ 1109static int SDLCALL rect_testHasIntersectionEmpty(void *arg) 1110{ 1111 SDL_Rect refRectA; 1112 SDL_Rect refRectB; 1113 SDL_Rect rectA; 1114 SDL_Rect rectB; 1115 bool intersection; 1116 1117 /* Rect A empty */ 1118 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 1119 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 1120 refRectA.w = SDLTest_RandomIntegerInRange(1, 100); 1121 refRectA.h = SDLTest_RandomIntegerInRange(1, 100); 1122 refRectB = refRectA; 1123 refRectA.w = 0; 1124 refRectA.h = 0; 1125 rectA = refRectA; 1126 rectB = refRectB; 1127 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1128 validateHasIntersectionResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB); 1129 1130 /* Rect B empty */ 1131 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 1132 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 1133 refRectA.w = SDLTest_RandomIntegerInRange(1, 100); 1134 refRectA.h = SDLTest_RandomIntegerInRange(1, 100); 1135 refRectB = refRectA; 1136 refRectB.w = 0; 1137 refRectB.h = 0; 1138 rectA = refRectA; 1139 rectB = refRectB; 1140 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1141 validateHasIntersectionResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB); 1142 1143 /* Rect A and B empty */ 1144 refRectA.x = SDLTest_RandomIntegerInRange(1, 100); 1145 refRectA.y = SDLTest_RandomIntegerInRange(1, 100); 1146 refRectA.w = SDLTest_RandomIntegerInRange(1, 100); 1147 refRectA.h = SDLTest_RandomIntegerInRange(1, 100); 1148 refRectB = refRectA; 1149 refRectA.w = 0; 1150 refRectA.h = 0; 1151 refRectB.w = 0; 1152 refRectB.h = 0; 1153 rectA = refRectA; 1154 rectB = refRectB; 1155 intersection = SDL_HasRectIntersection(&rectA, &rectB); 1156 validateHasIntersectionResults(intersection, false, &rectA, &rectB, &refRectA, &refRectB); 1157 1158 return TEST_COMPLETED; 1159} 1160 1161/** 1162 * Negative tests against SDL_HasRectIntersection() with invalid parameters 1163 * 1164 * \sa SDL_HasRectIntersection 1165 */ 1166static int SDLCALL rect_testHasIntersectionParam(void *arg) 1167{ 1168 SDL_Rect rectA = { 0 }; 1169 SDL_Rect rectB = { 0 }; 1170 bool intersection; 1171 1172 /* invalid parameter combinations */ 1173 intersection = SDL_HasRectIntersection((SDL_Rect *)NULL, &rectB); 1174 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 1st parameter is NULL"); 1175 intersection = SDL_HasRectIntersection(&rectA, (SDL_Rect *)NULL); 1176 SDLTest_AssertCheck(intersection == false, "Check that function returns false when 2nd parameter is NULL"); 1177 intersection = SDL_HasRectIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL); 1178 SDLTest_AssertCheck(intersection == false, "Check that function returns false when all parameters are NULL"); 1179 1180 return TEST_COMPLETED; 1181} 1182 1183/** 1184 * Test SDL_GetRectEnclosingPointsFloat() 1185 * 1186 * \sa SDL_GetRectEnclosingPointsFloat 1187 */ 1188static int SDLCALL rect_testEnclosePointsFloat(void *arg) 1189{ 1190 SDL_FPoint fpts[3] = { { 1.25f, 2.5f }, { 1.75f, 3.75f }, { 3.5f, 3.0f } }; 1191 int i, count = 3; 1192 SDL_FRect clip = { 0.0f, 1.0f, 4.0f, 4.0f }; 1193 SDL_FRect result; 1194 1195 SDL_GetRectEnclosingPointsFloat(fpts, count, &clip, &result); 1196 SDLTest_AssertCheck(result.x == 1.25f && result.y == 2.5f && result.w == 2.25f && result.h == 1.25f, 1197 "Resulting enclosing rectangle incorrect: expected (%.2f,%.2f - %.2fx%.2f), actual (%.2f,%.2f - %.2fx%.2f)", 1198 1.25f, 2.5f, 2.25f, 1.25f, result.x, result.y, result.w, result.h); 1199 for (i = 0; i != count; i++) { 1200 bool inside; 1201 1202 inside = SDL_PointInRectFloat(&fpts[i], &clip); 1203 SDLTest_AssertCheck(inside, 1204 "Expected point (%.2f,%.2f) to be inside clip rect (%.2f,%.2f - %.2fx%.2f)", 1205 fpts[i].x, fpts[i].y, clip.x, clip.y, clip.w, clip.h); 1206 1207 inside = SDL_PointInRectFloat(&fpts[i], &result); 1208 SDLTest_AssertCheck(inside, 1209 "Expected point (%.2f,%.2f) to be inside result rect (%.2f,%.2f - %.2fx%.2f)", 1210 fpts[i].x, fpts[i].y, result.x, result.y, result.w, result.h); 1211 } 1212 1213 return TEST_COMPLETED; 1214} 1215 1216/** 1217 * Test SDL_GetRectEnclosingPoints() without clipping 1218 * 1219 * \sa SDL_GetRectEnclosingPoints 1220 */ 1221static int SDLCALL rect_testEnclosePoints(void *arg) 1222{ 1223 const int numPoints = 16; 1224 SDL_Point refPoints[16]; 1225 SDL_Point points[16]; 1226 SDL_Rect result; 1227 bool anyEnclosed; 1228 bool anyEnclosedNoResult; 1229 bool expectedEnclosed = true; 1230 int newx, newy; 1231 int minx = 0, maxx = 0, miny = 0, maxy = 0; 1232 int i; 1233 1234 /* Create input data, tracking result */ 1235 for (i = 0; i < numPoints; i++) { 1236 newx = SDLTest_RandomIntegerInRange(-1024, 1024); 1237 newy = SDLTest_RandomIntegerInRange(-1024, 1024); 1238 refPoints[i].x = newx; 1239 refPoints[i].y = newy; 1240 points[i].x = newx; 1241 points[i].y = newy; 1242 if (i == 0) { 1243 minx = newx; 1244 maxx = newx; 1245 miny = newy; 1246 maxy = newy; 1247 } else { 1248 if (newx < minx) { 1249 minx = newx; 1250 } 1251 if (newx > maxx) { 1252 maxx = newx; 1253 } 1254 if (newy < miny) { 1255 miny = newy; 1256 } 1257 if (newy > maxy) { 1258 maxy = newy; 1259 } 1260 } 1261 } 1262 1263 /* Call function and validate - special case: no result requested */ 1264 anyEnclosedNoResult = SDL_GetRectEnclosingPoints(points, numPoints, NULL, (SDL_Rect *)NULL); 1265 SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult, 1266 "Check expected return value %s, got %s", 1267 (expectedEnclosed == true) ? "true" : "false", 1268 (anyEnclosedNoResult == true) ? "true" : "false"); 1269 for (i = 0; i < numPoints; i++) { 1270 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y, 1271 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 1272 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y); 1273 } 1274 1275 /* Call function and validate */ 1276 anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, NULL, &result); 1277 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed, 1278 "Check return value %s, got %s", 1279 (expectedEnclosed == true) ? "true" : "false", 1280 (anyEnclosed == true) ? "true" : "false"); 1281 for (i = 0; i < numPoints; i++) { 1282 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y, 1283 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 1284 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y); 1285 } 1286 SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1), 1287 "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)", 1288 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1); 1289 1290 return TEST_COMPLETED; 1291} 1292 1293/** 1294 * Test SDL_GetRectEnclosingPoints() with repeated input points 1295 * 1296 * \sa SDL_GetRectEnclosingPoints 1297 */ 1298static int SDLCALL rect_testEnclosePointsRepeatedInput(void *arg) 1299{ 1300 const int numPoints = 8; 1301 const int halfPoints = 4; 1302 SDL_Point refPoints[8]; 1303 SDL_Point points[8]; 1304 SDL_Rect result; 1305 bool anyEnclosed; 1306 bool anyEnclosedNoResult; 1307 bool expectedEnclosed = true; 1308 int newx, newy; 1309 int minx = 0, maxx = 0, miny = 0, maxy = 0; 1310 int i; 1311 1312 /* Create input data, tracking result */ 1313 for (i = 0; i < numPoints; i++) { 1314 if (i < halfPoints) { 1315 newx = SDLTest_RandomIntegerInRange(-1024, 1024); 1316 newy = SDLTest_RandomIntegerInRange(-1024, 1024); 1317 } else { 1318 newx = refPoints[i - halfPoints].x; 1319 newy = refPoints[i - halfPoints].y; 1320 } 1321 refPoints[i].x = newx; 1322 refPoints[i].y = newy; 1323 points[i].x = newx; 1324 points[i].y = newy; 1325 if (i == 0) { 1326 minx = newx; 1327 maxx = newx; 1328 miny = newy; 1329 maxy = newy; 1330 } else { 1331 if (newx < minx) { 1332 minx = newx; 1333 } 1334 if (newx > maxx) { 1335 maxx = newx; 1336 } 1337 if (newy < miny) { 1338 miny = newy; 1339 } 1340 if (newy > maxy) { 1341 maxy = newy; 1342 } 1343 } 1344 } 1345 1346 /* Call function and validate - special case: no result requested */ 1347 anyEnclosedNoResult = SDL_GetRectEnclosingPoints(points, numPoints, NULL, (SDL_Rect *)NULL); 1348 SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult, 1349 "Check return value %s, got %s", 1350 (expectedEnclosed == true) ? "true" : "false", 1351 (anyEnclosedNoResult == true) ? "true" : "false"); 1352 for (i = 0; i < numPoints; i++) { 1353 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y, 1354 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 1355 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y); 1356 } 1357 1358 /* Call function and validate */ 1359 anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, NULL, &result); 1360 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed, 1361 "Check return value %s, got %s", 1362 (expectedEnclosed == true) ? "true" : "false", 1363 (anyEnclosed == true) ? "true" : "false"); 1364 for (i = 0; i < numPoints; i++) { 1365 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y, 1366 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 1367 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y); 1368 } 1369 SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1), 1370 "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)", 1371 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1); 1372 1373 return TEST_COMPLETED; 1374} 1375 1376/** 1377 * Test SDL_GetRectEnclosingPoints() with clipping 1378 * 1379 * \sa SDL_GetRectEnclosingPoints 1380 */ 1381static int SDLCALL rect_testEnclosePointsWithClipping(void *arg) 1382{ 1383 const int numPoints = 16; 1384 SDL_Point refPoints[16]; 1385 SDL_Point points[16]; 1386 SDL_Rect refClip; 1387 SDL_Rect clip; 1388 SDL_Rect result; 1389 bool anyEnclosed; 1390 bool anyEnclosedNoResult; 1391 bool expectedEnclosed = false; 1392 int newx, newy; 1393 int minx = 0, maxx = 0, miny = 0, maxy = 0; 1394 int i; 1395 1396 /* Setup clipping rectangle */ 1397 refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1398 refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1399 refClip.w = SDLTest_RandomIntegerInRange(1, 1024); 1400 refClip.h = SDLTest_RandomIntegerInRange(1, 1024); 1401 1402 /* Create input data, tracking result */ 1403 for (i = 0; i < numPoints; i++) { 1404 newx = SDLTest_RandomIntegerInRange(-1024, 1024); 1405 newy = SDLTest_RandomIntegerInRange(-1024, 1024); 1406 refPoints[i].x = newx; 1407 refPoints[i].y = newy; 1408 points[i].x = newx; 1409 points[i].y = newy; 1410 if ((newx >= refClip.x) && (newx < (refClip.x + refClip.w)) && 1411 (newy >= refClip.y) && (newy < (refClip.y + refClip.h))) { 1412 if (expectedEnclosed == false) { 1413 minx = newx; 1414 maxx = newx; 1415 miny = newy; 1416 maxy = newy; 1417 } else { 1418 if (newx < minx) { 1419 minx = newx; 1420 } 1421 if (newx > maxx) { 1422 maxx = newx; 1423 } 1424 if (newy < miny) { 1425 miny = newy; 1426 } 1427 if (newy > maxy) { 1428 maxy = newy; 1429 } 1430 } 1431 expectedEnclosed = true; 1432 } 1433 } 1434 1435 /* Call function and validate - special case: no result requested */ 1436 clip = refClip; 1437 anyEnclosedNoResult = SDL_GetRectEnclosingPoints(points, numPoints, &clip, NULL); 1438 SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult, 1439 "Expected return value %s, got %s", 1440 (expectedEnclosed == true) ? "true" : "false", 1441 (anyEnclosedNoResult == true) ? "true" : "false"); 1442 for (i = 0; i < numPoints; i++) { 1443 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y, 1444 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 1445 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y); 1446 } 1447 SDLTest_AssertCheck(refClip.x == clip.x && refClip.y == clip.y && refClip.w == clip.w && refClip.h == clip.h, 1448 "Check that source clipping rectangle was not modified"); 1449 1450 /* Call function and validate */ 1451 anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, &clip, &result); 1452 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed, 1453 "Check return value %s, got %s", 1454 (expectedEnclosed == true) ? "true" : "false", 1455 (anyEnclosed == true) ? "true" : "false"); 1456 for (i = 0; i < numPoints; i++) { 1457 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y, 1458 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 1459 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y); 1460 } 1461 SDLTest_AssertCheck(refClip.x == clip.x && refClip.y == clip.y && refClip.w == clip.w && refClip.h == clip.h, 1462 "Check that source clipping rectangle was not modified"); 1463 if (expectedEnclosed == true) { 1464 SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1), 1465 "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)", 1466 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1); 1467 } 1468 1469 /* Empty clipping rectangle */ 1470 clip.w = 0; 1471 clip.h = 0; 1472 expectedEnclosed = false; 1473 anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, &clip, &result); 1474 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed, 1475 "Check return value %s, got %s", 1476 (expectedEnclosed == true) ? "true" : "false", 1477 (anyEnclosed == true) ? "true" : "false"); 1478 1479 return TEST_COMPLETED; 1480} 1481 1482/** 1483 * Negative tests against SDL_GetRectEnclosingPoints() with invalid parameters 1484 * 1485 * \sa SDL_GetRectEnclosingPoints 1486 */ 1487static int SDLCALL rect_testEnclosePointsParam(void *arg) 1488{ 1489 SDL_Point points[1]; 1490 int count; 1491 SDL_Rect clip = { 0 }; 1492 SDL_Rect result; 1493 bool anyEnclosed; 1494 1495 /* invalid parameter combinations */ 1496 anyEnclosed = SDL_GetRectEnclosingPoints((SDL_Point *)NULL, 1, &clip, &result); 1497 SDLTest_AssertCheck(anyEnclosed == false, "Check that functions returns false when 1st parameter is NULL"); 1498 anyEnclosed = SDL_GetRectEnclosingPoints(points, 0, &clip, &result); 1499 SDLTest_AssertCheck(anyEnclosed == false, "Check that functions returns false when 2nd parameter is 0"); 1500 count = SDLTest_RandomIntegerInRange(-100, -1); 1501 anyEnclosed = SDL_GetRectEnclosingPoints(points, count, &clip, &result); 1502 SDLTest_AssertCheck(anyEnclosed == false, "Check that functions returns false when 2nd parameter is %i (negative)", count); 1503 anyEnclosed = SDL_GetRectEnclosingPoints((SDL_Point *)NULL, 0, &clip, &result); 1504 SDLTest_AssertCheck(anyEnclosed == false, "Check that functions returns false when 1st parameter is NULL and 2nd parameter was 0"); 1505 1506 return TEST_COMPLETED; 1507} 1508 1509/** 1510 * Tests SDL_GetRectUnion() where rect B is outside rect A 1511 * 1512 * \sa SDL_GetRectUnion 1513 */ 1514static int SDLCALL rect_testUnionRectOutside(void *arg) 1515{ 1516 SDL_Rect refRectA, refRectB; 1517 SDL_Rect rectA, rectB; 1518 SDL_Rect expectedResult; 1519 SDL_Rect result; 1520 int minx, maxx, miny, maxy; 1521 int dx, dy; 1522 1523 /* Union 1x1 outside */ 1524 for (dx = -1; dx < 2; dx++) { 1525 for (dy = -1; dy < 2; dy++) { 1526 if ((dx != 0) || (dy != 0)) { 1527 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1528 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1529 refRectA.w = 1; 1530 refRectA.h = 1; 1531 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024) + dx * 2048; 1532 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024) + dx * 2048; 1533 refRectB.w = 1; 1534 refRectB.h = 1; 1535 minx = (refRectA.x < refRectB.x) ? refRectA.x : refRectB.x; 1536 maxx = (refRectA.x > refRectB.x) ? refRectA.x : refRectB.x; 1537 miny = (refRectA.y < refRectB.y) ? refRectA.y : refRectB.y; 1538 maxy = (refRectA.y > refRectB.y) ? refRectA.y : refRectB.y; 1539 expectedResult.x = minx; 1540 expectedResult.y = miny; 1541 expectedResult.w = maxx - minx + 1; 1542 expectedResult.h = maxy - miny + 1; 1543 rectA = refRectA; 1544 rectB = refRectB; 1545 SDL_GetRectUnion(&rectA, &rectB, &result); 1546 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1547 } 1548 } 1549 } 1550 1551 /* Union outside overlap */ 1552 for (dx = -1; dx < 2; dx++) { 1553 for (dy = -1; dy < 2; dy++) { 1554 if ((dx != 0) || (dy != 0)) { 1555 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1556 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1557 refRectA.w = SDLTest_RandomIntegerInRange(256, 512); 1558 refRectA.h = SDLTest_RandomIntegerInRange(256, 512); 1559 refRectB.x = refRectA.x + 1 + dx * 2; 1560 refRectB.y = refRectA.y + 1 + dy * 2; 1561 refRectB.w = refRectA.w - 2; 1562 refRectB.h = refRectA.h - 2; 1563 expectedResult = refRectA; 1564 if (dx == -1) { 1565 expectedResult.x--; 1566 } 1567 if (dy == -1) { 1568 expectedResult.y--; 1569 } 1570 if ((dx == 1) || (dx == -1)) { 1571 expectedResult.w++; 1572 } 1573 if ((dy == 1) || (dy == -1)) { 1574 expectedResult.h++; 1575 } 1576 rectA = refRectA; 1577 rectB = refRectB; 1578 SDL_GetRectUnion(&rectA, &rectB, &result); 1579 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1580 } 1581 } 1582 } 1583 1584 return TEST_COMPLETED; 1585} 1586 1587/** 1588 * Tests SDL_GetRectUnion() where rect A or rect B are empty 1589 * 1590 * \sa SDL_GetRectUnion 1591 */ 1592static int SDLCALL rect_testUnionRectEmpty(void *arg) 1593{ 1594 SDL_Rect refRectA, refRectB; 1595 SDL_Rect rectA, rectB; 1596 SDL_Rect expectedResult; 1597 SDL_Rect result; 1598 1599 /* A empty */ 1600 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1601 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1602 refRectA.w = 0; 1603 refRectA.h = 0; 1604 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1605 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1606 refRectB.w = SDLTest_RandomIntegerInRange(1, 1024); 1607 refRectB.h = SDLTest_RandomIntegerInRange(1, 1024); 1608 expectedResult = refRectB; 1609 rectA = refRectA; 1610 rectB = refRectB; 1611 SDL_GetRectUnion(&rectA, &rectB, &result); 1612 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1613 1614 /* B empty */ 1615 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1616 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1617 refRectA.w = SDLTest_RandomIntegerInRange(1, 1024); 1618 refRectA.h = SDLTest_RandomIntegerInRange(1, 1024); 1619 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1620 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1621 refRectB.w = 0; 1622 refRectB.h = 0; 1623 expectedResult = refRectA; 1624 rectA = refRectA; 1625 rectB = refRectB; 1626 SDL_GetRectUnion(&rectA, &rectB, &result); 1627 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1628 1629 /* A and B empty */ 1630 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1631 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1632 refRectA.w = 0; 1633 refRectA.h = 0; 1634 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1635 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1636 refRectB.w = 0; 1637 refRectB.h = 0; 1638 result.x = 0; 1639 result.y = 0; 1640 result.w = 0; 1641 result.h = 0; 1642 expectedResult = result; 1643 rectA = refRectA; 1644 rectB = refRectB; 1645 SDL_GetRectUnion(&rectA, &rectB, &result); 1646 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1647 1648 return TEST_COMPLETED; 1649} 1650 1651/** 1652 * Tests SDL_GetRectUnion() where rect B is inside rect A 1653 * 1654 * \sa SDL_GetRectUnion 1655 */ 1656static int SDLCALL rect_testUnionRectInside(void *arg) 1657{ 1658 SDL_Rect refRectA, refRectB; 1659 SDL_Rect rectA, rectB; 1660 SDL_Rect expectedResult; 1661 SDL_Rect result; 1662 int dx, dy; 1663 1664 /* Union 1x1 with itself */ 1665 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1666 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1667 refRectA.w = 1; 1668 refRectA.h = 1; 1669 expectedResult = refRectA; 1670 rectA = refRectA; 1671 SDL_GetRectUnion(&rectA, &rectA, &result); 1672 validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult); 1673 1674 /* Union 1x1 somewhere inside */ 1675 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1676 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1677 refRectA.w = SDLTest_RandomIntegerInRange(256, 1024); 1678 refRectA.h = SDLTest_RandomIntegerInRange(256, 1024); 1679 refRectB.x = refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2); 1680 refRectB.y = refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2); 1681 refRectB.w = 1; 1682 refRectB.h = 1; 1683 expectedResult = refRectA; 1684 rectA = refRectA; 1685 rectB = refRectB; 1686 SDL_GetRectUnion(&rectA, &rectB, &result); 1687 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1688 1689 /* Union inside with edges modified */ 1690 for (dx = -1; dx < 2; dx++) { 1691 for (dy = -1; dy < 2; dy++) { 1692 if ((dx != 0) || (dy != 0)) { 1693 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1694 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1695 refRectA.w = SDLTest_RandomIntegerInRange(256, 1024); 1696 refRectA.h = SDLTest_RandomIntegerInRange(256, 1024); 1697 refRectB = refRectA; 1698 if (dx == -1) { 1699 refRectB.x++; 1700 } 1701 if ((dx == 1) || (dx == -1)) { 1702 refRectB.w--; 1703 } 1704 if (dy == -1) { 1705 refRectB.y++; 1706 } 1707 if ((dy == 1) || (dy == -1)) { 1708 refRectB.h--; 1709 } 1710 expectedResult = refRectA; 1711 rectA = refRectA; 1712 rectB = refRectB; 1713 SDL_GetRectUnion(&rectA, &rectB, &result); 1714 validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult); 1715 } 1716 } 1717 } 1718 1719 return TEST_COMPLETED; 1720} 1721 1722/** 1723 * Negative tests against SDL_GetRectUnion() with invalid parameters 1724 * 1725 * \sa SDL_GetRectUnion 1726 */ 1727static int SDLCALL rect_testUnionRectParam(void *arg) 1728{ 1729 SDL_Rect rectA = { 0 }, rectB = { 0 }; 1730 SDL_Rect result; 1731 1732 /* invalid parameter combinations */ 1733 SDL_GetRectUnion((SDL_Rect *)NULL, &rectB, &result); 1734 SDLTest_AssertPass("Check that function returns when 1st parameter is NULL"); 1735 SDL_GetRectUnion(&rectA, (SDL_Rect *)NULL, &result); 1736 SDLTest_AssertPass("Check that function returns when 2nd parameter is NULL"); 1737 SDL_GetRectUnion(&rectA, &rectB, (SDL_Rect *)NULL); 1738 SDLTest_AssertPass("Check that function returns when 3rd parameter is NULL"); 1739 SDL_GetRectUnion((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL); 1740 SDLTest_AssertPass("Check that function returns when 1st and 3rd parameter are NULL"); 1741 SDL_GetRectUnion(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 1742 SDLTest_AssertPass("Check that function returns when 2nd and 3rd parameter are NULL"); 1743 SDL_GetRectUnion((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL); 1744 SDLTest_AssertPass("Check that function returns when all parameters are NULL"); 1745 1746 return TEST_COMPLETED; 1747} 1748 1749/** 1750 * Tests SDL_RectEmptyFloat() with various inputs 1751 * 1752 * \sa SDL_RectEmptyFloat 1753 */ 1754static int SDLCALL rect_testRectEmptyFloat(void *arg) 1755{ 1756 SDL_FRect rect; 1757 bool result; 1758 1759 rect.x = 0.0f; 1760 rect.y = 0.0f; 1761 rect.w = 1.0f; 1762 rect.h = 1.0f; 1763 result = SDL_RectEmptyFloat(&rect); 1764 validateRectEmptyFloatResults(result, false, &rect); 1765 1766 rect.x = 0.0f; 1767 rect.y = 0.0f; 1768 rect.w = 0.0f; 1769 rect.h = 0.0f; 1770 result = SDL_RectEmptyFloat(&rect); 1771 validateRectEmptyFloatResults(result, false, &rect); 1772 1773 rect.x = 0.0f; 1774 rect.y = 0.0f; 1775 rect.w = -1.0f; 1776 rect.h = 1.0f; 1777 result = SDL_RectEmptyFloat(&rect); 1778 validateRectEmptyFloatResults(result, true, &rect); 1779 1780 rect.x = 0.0f; 1781 rect.y = 0.0f; 1782 rect.w = 1.0f; 1783 rect.h = -1.0f; 1784 result = SDL_RectEmptyFloat(&rect); 1785 validateRectEmptyFloatResults(result, true, &rect); 1786 1787 1788 return TEST_COMPLETED; 1789} 1790 1791/** 1792 * Tests SDL_RectEmpty() with various inputs 1793 * 1794 * \sa SDL_RectEmpty 1795 */ 1796static int SDLCALL rect_testRectEmpty(void *arg) 1797{ 1798 SDL_Rect refRect; 1799 SDL_Rect rect; 1800 bool expectedResult; 1801 bool result; 1802 int w, h; 1803 1804 /* Non-empty case */ 1805 refRect.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1806 refRect.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1807 refRect.w = SDLTest_RandomIntegerInRange(256, 1024); 1808 refRect.h = SDLTest_RandomIntegerInRange(256, 1024); 1809 expectedResult = false; 1810 rect = refRect; 1811 result = SDL_RectEmpty(&rect); 1812 validateRectEmptyResults(result, expectedResult, &rect, &refRect); 1813 1814 /* Empty case */ 1815 for (w = -1; w < 2; w++) { 1816 for (h = -1; h < 2; h++) { 1817 if ((w != 1) || (h != 1)) { 1818 refRect.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1819 refRect.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1820 refRect.w = w; 1821 refRect.h = h; 1822 expectedResult = true; 1823 rect = refRect; 1824 result = SDL_RectEmpty(&rect); 1825 validateRectEmptyResults(result, expectedResult, &rect, &refRect); 1826 } 1827 } 1828 } 1829 1830 return TEST_COMPLETED; 1831} 1832 1833/** 1834 * Negative tests against SDL_RectEmpty() with invalid parameters 1835 * 1836 * \sa SDL_RectEmpty 1837 */ 1838static int SDLCALL rect_testRectEmptyParam(void *arg) 1839{ 1840 bool result; 1841 1842 /* invalid parameter combinations */ 1843 result = SDL_RectEmpty(NULL); 1844 SDLTest_AssertCheck(result == true, "Check that function returns TRUE when 1st parameter is NULL"); 1845 1846 return TEST_COMPLETED; 1847} 1848 1849/** 1850 * Tests SDL_RectsEqual() with various inputs 1851 * 1852 * \sa SDL_RectsEqual 1853 */ 1854static int SDLCALL rect_testRectEquals(void *arg) 1855{ 1856 SDL_Rect refRectA; 1857 SDL_Rect refRectB; 1858 SDL_Rect rectA; 1859 SDL_Rect rectB; 1860 bool expectedResult; 1861 bool result; 1862 1863 /* Equals */ 1864 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1865 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1866 refRectA.w = SDLTest_RandomIntegerInRange(1, 1024); 1867 refRectA.h = SDLTest_RandomIntegerInRange(1, 1024); 1868 refRectB = refRectA; 1869 expectedResult = true; 1870 rectA = refRectA; 1871 rectB = refRectB; 1872 result = SDL_RectsEqual(&rectA, &rectB); 1873 validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB); 1874 1875 return TEST_COMPLETED; 1876} 1877 1878/** 1879 * Negative tests against SDL_RectsEqual() with invalid parameters 1880 * 1881 * \sa SDL_RectsEqual 1882 */ 1883static int SDLCALL rect_testRectEqualsParam(void *arg) 1884{ 1885 SDL_Rect rectA; 1886 SDL_Rect rectB; 1887 bool result; 1888 1889 /* data setup */ 1890 rectA.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1891 rectA.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1892 rectA.w = SDLTest_RandomIntegerInRange(1, 1024); 1893 rectA.h = SDLTest_RandomIntegerInRange(1, 1024); 1894 rectB.x = SDLTest_RandomIntegerInRange(-1024, 1024); 1895 rectB.y = SDLTest_RandomIntegerInRange(-1024, 1024); 1896 rectB.w = SDLTest_RandomIntegerInRange(1, 1024); 1897 rectB.h = SDLTest_RandomIntegerInRange(1, 1024); 1898 1899 /* invalid parameter combinations */ 1900 result = SDL_RectsEqual(NULL, &rectB); 1901 SDLTest_AssertCheck(result == false, "Check that function returns false when 1st parameter is NULL"); 1902 result = SDL_RectsEqual(&rectA, NULL); 1903 SDLTest_AssertCheck(result == false, "Check that function returns false when 2nd parameter is NULL"); 1904 result = SDL_RectsEqual(NULL, NULL); 1905 SDLTest_AssertCheck(result == false, "Check that function returns false when 1st and 2nd parameter are NULL"); 1906 1907 return TEST_COMPLETED; 1908} 1909 1910/** 1911 * Tests SDL_RectsEqualFloat() with various inputs 1912 * 1913 * \sa SDL_RectsEqualFloat 1914 */ 1915static int SDLCALL rect_testFRectEquals(void *arg) 1916{ 1917 SDL_FRect refRectA; 1918 SDL_FRect refRectB; 1919 SDL_FRect rectA; 1920 SDL_FRect rectB; 1921 bool expectedResult; 1922 bool result; 1923 1924 /* Equals */ 1925 refRectA.x = (float)SDLTest_RandomIntegerInRange(-1024, 1024); 1926 refRectA.y = (float)SDLTest_RandomIntegerInRange(-1024, 1024); 1927 refRectA.w = (float)SDLTest_RandomIntegerInRange(1, 1024); 1928 refRectA.h = (float)SDLTest_RandomIntegerInRange(1, 1024); 1929 refRectB = refRectA; 1930 expectedResult = true; 1931 rectA = refRectA; 1932 rectB = refRectB; 1933 result = SDL_RectsEqualFloat(&rectA, &rectB); 1934 validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB); 1935 1936 return TEST_COMPLETED; 1937} 1938 1939/** 1940 * Negative tests against SDL_RectsEqualFloat() with invalid parameters 1941 * 1942 * \sa SDL_RectsEqualFloat 1943 */ 1944static int SDLCALL rect_testFRectEqualsParam(void *arg) 1945{ 1946 SDL_FRect rectA; 1947 SDL_FRect rectB; 1948 bool result; 1949 1950 /* data setup -- For the purpose of this test, the values don't matter. */ 1951 rectA.x = SDLTest_RandomFloat(); 1952 rectA.y = SDLTest_RandomFloat(); 1953 rectA.w = SDLTest_RandomFloat(); 1954 rectA.h = SDLTest_RandomFloat(); 1955 rectB.x = SDLTest_RandomFloat(); 1956 rectB.y = SDLTest_RandomFloat(); 1957 rectB.w = SDLTest_RandomFloat(); 1958 rectB.h = SDLTest_RandomFloat(); 1959 1960 /* invalid parameter combinations */ 1961 result = SDL_RectsEqualFloat(NULL, &rectB); 1962 SDLTest_AssertCheck(result == false, "Check that function returns false when 1st parameter is NULL"); 1963 result = SDL_RectsEqualFloat(&rectA, NULL); 1964 SDLTest_AssertCheck(result == false, "Check that function returns false when 2nd parameter is NULL"); 1965 result = SDL_RectsEqualFloat(NULL, NULL); 1966 SDLTest_AssertCheck(result == false, "Check that function returns false when 1st and 2nd parameter are NULL"); 1967 1968 return TEST_COMPLETED; 1969} 1970 1971/* ! 1972 * \brief Test SDL_HasRectIntersectionFloat 1973 * 1974 * \sa 1975 * http://wiki.libsdl.org/SDL3/SDL_HasRectIntersectionFloat 1976 */ 1977static int SDLCALL rect_testHasIntersectionFloat(void *arg) 1978{ 1979 const struct { 1980 SDL_FRect r1; 1981 SDL_FRect r2; 1982 bool expected; 1983 } cases[] = { 1984 { { 0, 0, 0, 0 }, {0, 0, 0, 0}, true }, 1985 { { 0, 0, -200, 200 }, {0, 0, -200, 200}, false }, 1986 { { 0, 0, 10, 10 }, {-5, 5, 10, 2}, true }, 1987 { { 0, 0, 10, 10 }, {-5, -5, 10, 2}, false }, 1988 { { 0, 0, 10, 10 }, {-5, -5, 2, 10}, false }, 1989 { { 0, 0, 10, 10 }, {-5, -5, 5, 5}, true }, 1990 { { 0, 0, 10, 10 }, {-5, -5, 5.1f, 5.1f}, true }, 1991 { { 0, 0, 10, 10 }, {-4.99f, -4.99f, 5, 5}, true }, 1992 }; 1993 size_t i; 1994 1995 for (i = 0; i < SDL_arraysize(cases); i++) { 1996 bool result; 1997 SDLTest_AssertPass("About to call SDL_HasRectIntersectionFloat(&{ %g, %g, %g, %g }, &{ %g, %g, %g, %g })", 1998 cases[i].r1.x, cases[i].r1.y, cases[i].r1.w, cases[i].r1.h, 1999 cases[i].r2.x, cases[i].r2.y, cases[i].r2.w, cases[i].r2.h 2000 ); 2001 result = SDL_HasRectIntersectionFloat(&cases[i].r1, &cases[i].r2); 2002 SDLTest_AssertCheck(result == cases[i].expected, "Got %d, expected %d", result, cases[i].expected); 2003 } 2004 return TEST_COMPLETED; 2005} 2006 2007/* ! 2008 * \brief Test SDL_GetRectIntersectionFloat 2009 * 2010 * \sa 2011 * http://wiki.libsdl.org/SDL3/SDL_GetRectIntersectionFloat 2012 */ 2013static int SDLCALL rect_testGetRectIntersectionFloat(void *arg) 2014{ 2015 const struct { 2016 SDL_FRect r1; 2017 SDL_FRect r2; 2018 bool result; 2019 SDL_FRect intersect; 2020 } cases[] = { 2021 { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, true }, 2022 { { 0, 0, -200, 200 }, { 0, 0, -200, 200 }, false }, 2023 { { 0, 0, 10, 10 }, { -5, 5, 9.9f, 2 }, true, { 0, 5, 4.9f, 2 } }, 2024 { { 0, 0, 10, 10 }, { -5, -5, 10, 2 }, false}, 2025 { { 0, 0, 10, 10 }, { -5, -5, 2, 10 }, false}, 2026 { { 0, 0, 10, 10 }, { -5, -5, 5, 5 }, true}, 2027 { { 0, 0, 10, 10 }, { -5, -5, 5.5f, 6 }, true, { 0, 0, 0.5f, 1 } } 2028 }; 2029 size_t i; 2030 2031 for (i = 0; i < SDL_arraysize(cases); i++) { 2032 bool result; 2033 SDL_FRect intersect; 2034 SDLTest_AssertPass("About to call SDL_GetRectIntersectionFloat(&{ %g, %g, %g, %g }, &{ %g, %g, %g, %g })", 2035 cases[i].r1.x, cases[i].r1.y, cases[i].r1.w, cases[i].r1.h, 2036 cases[i].r2.x, cases[i].r2.y, cases[i].r2.w, cases[i].r2.h 2037 ); 2038 result = SDL_GetRectIntersectionFloat(&cases[i].r1, &cases[i].r2, &intersect); 2039 SDLTest_AssertCheck(result == cases[i].result, "Got %d, expected %d", result, cases[i].result); 2040 if (cases[i].result) { 2041 SDLTest_AssertCheck(IsFRectEqual(&intersect, &cases[i].intersect), 2042 "Got { %g, %g, %g, %g }, expected { %g, %g, %g, %g }", 2043 intersect.x, intersect.y, intersect.w, intersect.h, 2044 cases[i].intersect.x, cases[i].intersect.y, cases[i].intersect.w, cases[i].intersect.h); 2045 } 2046 } 2047 return TEST_COMPLETED; 2048} 2049 2050/* ! 2051 * \brief Test SDL_GetRectUnionFloat 2052 * 2053 * \sa 2054 * http://wiki.libsdl.org/SDL3/SDL_GetRectUnionFloat 2055 */ 2056static int SDLCALL rect_testGetRectUntionFloat(void *arg) 2057{ 2058 const struct { 2059 SDL_FRect r1; 2060 SDL_FRect r2; 2061 SDL_FRect expected; 2062 } cases[] = { 2063 { { 0, 0, 10, 10 }, { 19.9f, 20, 10, 10 }, { 0, 0, 29.9f, 30 } }, 2064 { { 0, 0, 0, 0 }, { 20, 20.1f, 10.1f, 10 }, { 0, 0.f, 30.1f, 30.1f } }, 2065 { { -200, -4.5f, 450, 33 }, { 20, 20, 10, 10 }, { -200, -4.5f, 450, 34.5f } }, 2066 { { 0, 0, 15, 16.5f }, { 20, 20, 0, 0 }, { 0, 0, 20.f, 20.f } } 2067 }; 2068 size_t i; 2069 2070 for (i = 0; i < SDL_arraysize(cases); i++) { 2071 SDL_FRect result; 2072 SDLTest_AssertPass("About to call SDL_GetRectUnionFloat(&{ %g, %g, %g, %g }, &{ %g, %g, %g, %g })", 2073 cases[i].r1.x, cases[i].r1.y, cases[i].r1.w, cases[i].r1.h, 2074 cases[i].r2.x, cases[i].r2.y, cases[i].r2.w, cases[i].r2.h 2075 ); 2076 SDL_GetRectUnionFloat(&cases[i].r1, &cases[i].r2, &result); 2077 SDLTest_AssertCheck(IsFRectEqual(&result, &cases[i].expected), 2078 "Got { %g, %g, %g, %g }, expected { %g, %g, %g, %g }", 2079 result.x, result.y, result.w, result.h, 2080 cases[i].expected.x, cases[i].expected.y, cases[i].expected.w, cases[i].expected.h); 2081 } 2082 return TEST_COMPLETED; 2083} 2084 2085/* ! 2086 * \brief Test SDL_EncloseFPointsUnionFRect 2087 * 2088 * \sa 2089 * http://wiki.libsdl.org/SDL3/SDL_GetRectEnclosingPointsFloat 2090 */ 2091static int SDLCALL rect_testGetRectEnclosingPointsFloat(void *arg) 2092{ 2093 const struct { 2094 bool with_clip; 2095 SDL_FRect clip; 2096 bool result; 2097 SDL_FRect enclosing; 2098 } cases[] = { 2099 { true, { 0, 0, 10, 10 }, true, { 0.5f, 0.1f, 5, 7 }}, 2100 { true, { 1.2f, 1, 10, 10 }, true, { 1.5f, 1.1f, 4, 6 }}, 2101 { true, { -10, -10, 3, 3 }, false }, 2102 { false, { 0 }, true, { 0.5f, 0.1f, 5, 7 }} 2103 }; 2104 const SDL_FPoint points[] = { 2105 { 0.5f, 0.1f }, 2106 { 5.5f, 7.1f }, 2107 { 1.5f, 1.1f } 2108 }; 2109 char points_str[256]; 2110 size_t i; 2111 2112 SDL_strlcpy(points_str, "{", sizeof(points_str)); 2113 for (i = 0; i < SDL_arraysize(points); i++) { 2114 char point_str[32]; 2115 SDL_snprintf(point_str, sizeof(point_str), "{ %g, %g }, ", points[i].x, points[i].y); 2116 SDL_strlcat(points_str, point_str, sizeof(points_str)); 2117 } 2118 SDL_strlcat(points_str, "}", sizeof(points_str)); 2119 for (i = 0; i < SDL_arraysize(cases); i++) { 2120 char clip_str[64]; 2121 bool result; 2122 SDL_FRect enclosing; 2123 const SDL_FRect* clip_ptr = NULL; 2124 if (cases[i].with_clip) { 2125 SDL_snprintf(clip_str, sizeof(clip_str), "&{ %g, %g, %g, %g }", 2126 cases[i].clip.x, cases[i].clip.y, cases[i].clip.w, cases[i].clip.h); 2127 clip_ptr = &cases[i].clip; 2128 } else { 2129 SDL_strlcpy(clip_str, "NULL", sizeof(clip_str)); 2130 } 2131 SDLTest_AssertPass("About to call SDL_GetRectEnclosingPointsFloat(&%s, %d, %s)", points_str, (int)SDL_arraysize(points), clip_str); 2132 result = SDL_GetRectEnclosingPointsFloat(points, SDL_arraysize(points), clip_ptr, &enclosing); 2133 SDLTest_AssertCheck(result == cases[i].result, "Got %d, expected %d", result, cases[i].result); 2134 if (cases[i].result) { 2135 SDLTest_AssertCheck(IsFRectEqual(&enclosing, &cases[i].enclosing), 2136 "Got { %g, %g, %g, %g }, expected { %g, %g, %g, %g }", 2137 enclosing.x, enclosing.y, enclosing.w, enclosing.h, 2138 cases[i].enclosing.x, cases[i].enclosing.y, cases[i].enclosing.w, cases[i].enclosing.h); 2139 } 2140 } 2141 return TEST_COMPLETED; 2142} 2143 2144/* ! 2145 * \brief Test SDL_GetRectAndLineIntersectionFloat 2146 * 2147 * \sa 2148 * http://wiki.libsdl.org/SDL3/SDL_GetRectAndLineIntersectionFloat 2149 */ 2150static int SDLCALL rect_testGetRectAndLineIntersectionFloat(void *arg) 2151{ 2152 const struct { 2153 SDL_FRect rect; 2154 SDL_FPoint p1; 2155 SDL_FPoint p2; 2156 bool result; 2157 SDL_FPoint expected1; 2158 SDL_FPoint expected2; 2159 } cases[] = { 2160 { { 0, 0, 0, 0 }, { -4.8f, -4.8f }, { 5.2f, 5.2f}, true, { 0, 0 }, { 0, 0 } }, 2161 { { 0, 0, 2, 2 }, { -1, -1 }, { 3.5f, 3.5f}, true, { 0, 0 }, { 2, 2 } }, 2162 { { -4, -4, 14, 14 }, { 8, 22 }, { 8, 33}, false } 2163 2164 }; 2165 size_t i; 2166 2167 for (i = 0; i < SDL_arraysize(cases); i++) { 2168 bool result; 2169 SDL_FPoint p1 = cases[i].p1; 2170 SDL_FPoint p2 = cases[i].p2; 2171 2172 SDLTest_AssertPass("About to call SDL_GetRectAndLineIntersectionFloat(&{%g, %g, %g, %g}, &%g, &%g, &%g, &%g)", 2173 cases[i].rect.x, cases[i].rect.y, cases[i].rect.w, cases[i].rect.h, 2174 p1.x, p1.y, p2.x, p2.y); 2175 result = SDL_GetRectAndLineIntersectionFloat(&cases[i].rect, &p1.x, &p1.y, &p2.x, &p2.y); 2176 SDLTest_AssertCheck(result == cases[i].result, "Got %d, expected %d", result, cases[i].result); 2177 if (cases[i].result) { 2178 SDLTest_AssertCheck(IsFPointEqual(&p1, &cases[i].expected1), 2179 "Got p1={ %g, %g }, expected p1={ %g, %g }", 2180 p1.x, p1.y, 2181 cases[i].expected1.x, cases[i].expected1.y); 2182 SDLTest_AssertCheck(IsFPointEqual(&p2, &cases[i].expected2), 2183 "Got p2={ %g, %g }, expected p2={ %g, %g }", 2184 p2.x, p2.y, 2185 cases[i].expected2.x, cases[i].expected2.y); 2186 } 2187 } 2188 return TEST_COMPLETED; 2189} 2190 2191/* ================= Test References ================== */ 2192 2193/* Rect test cases */ 2194 2195/* SDL_GetRectAndLineIntersectionFloat */ 2196static const SDLTest_TestCaseReference rectTestIntersectRectAndLineFloat = { 2197 rect_testIntersectRectAndLineFloat, "rect_testIntersectRectAndLineFloat", "Tests SDL_GetRectAndLineIntersectionFloat", TEST_ENABLED 2198}; 2199 2200/* SDL_GetRectAndLineIntersection */ 2201static const SDLTest_TestCaseReference rectTestIntersectRectAndLine = { 2202 rect_testIntersectRectAndLine, "rect_testIntersectRectAndLine", "Tests SDL_GetRectAndLineIntersection clipping cases", TEST_ENABLED 2203}; 2204 2205static const SDLTest_TestCaseReference rectTestIntersectRectAndLineInside = { 2206 rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_GetRectAndLineIntersection with line fully contained in rect", TEST_ENABLED 2207}; 2208 2209static const SDLTest_TestCaseReference rectTestIntersectRectAndLineOutside = { 2210 rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_GetRectAndLineIntersection with line fully outside of rect", TEST_ENABLED 2211}; 2212 2213static const SDLTest_TestCaseReference rectTestIntersectRectAndLineEmpty = { 2214 rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_GetRectAndLineIntersection with empty rectangle ", TEST_ENABLED 2215}; 2216 2217static const SDLTest_TestCaseReference rectTestIntersectRectAndLineParam = { 2218 rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_GetRectAndLineIntersection with invalid parameters", TEST_ENABLED 2219}; 2220 2221/* SDL_GetRectIntersectionFloat */ 2222static const SDLTest_TestCaseReference rectTestIntersectRectFloat = { 2223 rect_testIntersectRectFloat, "rect_testIntersectRectFloat", "Tests SDL_GetRectIntersectionFloat", TEST_ENABLED 2224}; 2225 2226/* SDL_GetRectIntersection */ 2227static const SDLTest_TestCaseReference rectTestIntersectRectInside = { 2228 rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_GetRectIntersection with B fully contained in A", TEST_ENABLED 2229}; 2230 2231static const SDLTest_TestCaseReference rectTestIntersectRectOutside = { 2232 rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_GetRectIntersection with B fully outside of A", TEST_ENABLED 2233}; 2234 2235static const SDLTest_TestCaseReference rectTestIntersectRectPartial = { 2236 rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_GetRectIntersection with B partially intersecting A", TEST_ENABLED 2237}; 2238 2239static const SDLTest_TestCaseReference rectTestIntersectRectPoint = { 2240 rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_GetRectIntersection with 1x1 sized rectangles", TEST_ENABLED 2241}; 2242 2243static const SDLTest_TestCaseReference rectTestIntersectRectEmpty = { 2244 rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_GetRectIntersection with empty rectangles", TEST_ENABLED 2245}; 2246 2247static const SDLTest_TestCaseReference rectTestIntersectRectParam = { 2248 rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_GetRectIntersection with invalid parameters", TEST_ENABLED 2249}; 2250 2251/* SDL_HasRectIntersection */ 2252static const SDLTest_TestCaseReference rectTestHasIntersectionInside = { 2253 rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasRectIntersection with B fully contained in A", TEST_ENABLED 2254}; 2255 2256static const SDLTest_TestCaseReference rectTestHasIntersectionOutside = { 2257 rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasRectIntersection with B fully outside of A", TEST_ENABLED 2258}; 2259 2260static const SDLTest_TestCaseReference rectTestHasIntersectionPartial = { 2261 rect_testHasIntersectionPartial, "rect_testHasIntersectionPartial", "Tests SDL_HasRectIntersection with B partially intersecting A", TEST_ENABLED 2262}; 2263 2264static const SDLTest_TestCaseReference rectTestHasIntersectionPoint = { 2265 rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasRectIntersection with 1x1 sized rectangles", TEST_ENABLED 2266}; 2267 2268static const SDLTest_TestCaseReference rectTestHasIntersectionEmpty = { 2269 rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasRectIntersection with empty rectangles", TEST_ENABLED 2270}; 2271 2272static const SDLTest_TestCaseReference rectTestHasIntersectionParam = { 2273 rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasRectIntersection with invalid parameters", TEST_ENABLED 2274}; 2275 2276/* SDL_GetRectEnclosingPointsFloat */ 2277static const SDLTest_TestCaseReference rectTestEnclosePointsFloat = { 2278 rect_testEnclosePointsFloat, "rect_testEnclosePointsFloat", "Tests SDL_GetRectEnclosingPointsFloat", TEST_ENABLED 2279}; 2280 2281/* SDL_GetRectEnclosingPoints */ 2282static const SDLTest_TestCaseReference rectTestEnclosePoints = { 2283 rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_GetRectEnclosingPoints without clipping", TEST_ENABLED 2284}; 2285 2286static const SDLTest_TestCaseReference rectTestEnclosePointsWithClipping = { 2287 rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_GetRectEnclosingPoints with clipping", TEST_ENABLED 2288}; 2289 2290static const SDLTest_TestCaseReference rectTestEnclosePointsRepeatedInput = { 2291 rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_GetRectEnclosingPoints with repeated input", TEST_ENABLED 2292}; 2293 2294static const SDLTest_TestCaseReference rectTestEnclosePointsParam = { 2295 rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_GetRectEnclosingPoints with invalid parameters", TEST_ENABLED 2296}; 2297 2298/* SDL_GetRectUnion */ 2299static const SDLTest_TestCaseReference rectTestUnionRectInside = { 2300 rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_GetRectUnion where rect B is inside rect A", TEST_ENABLED 2301}; 2302 2303static const SDLTest_TestCaseReference rectTestUnionRectOutside = { 2304 rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_GetRectUnion where rect B is outside rect A", TEST_ENABLED 2305}; 2306 2307static const SDLTest_TestCaseReference rectTestUnionRectEmpty = { 2308 rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_GetRectUnion where rect A or rect B are empty", TEST_ENABLED 2309}; 2310 2311static const SDLTest_TestCaseReference rectTestUnionRectParam = { 2312 rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_GetRectUnion with invalid parameters", TEST_ENABLED 2313}; 2314 2315/* SDL_RectEmptyFloat */ 2316static const SDLTest_TestCaseReference rectTestRectEmptyFloat = { 2317 rect_testRectEmptyFloat, "rect_testRectEmptyFloat", "Tests SDL_RectEmptyFloat with various inputs", TEST_ENABLED 2318}; 2319 2320/* SDL_RectEmpty */ 2321static const SDLTest_TestCaseReference rectTestRectEmpty = { 2322 rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED 2323}; 2324 2325static const SDLTest_TestCaseReference rectTestRectEmptyParam = { 2326 rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED 2327}; 2328 2329/* SDL_RectsEqual */ 2330static const SDLTest_TestCaseReference rectTestRectEquals = { 2331 rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectsEqual with various inputs", TEST_ENABLED 2332}; 2333 2334static const SDLTest_TestCaseReference rectTestRectEqualsParam = { 2335 rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectsEqual with invalid parameters", TEST_ENABLED 2336}; 2337 2338/* SDL_RectsEqualFloat */ 2339static const SDLTest_TestCaseReference rectTestFRectEquals = { 2340 rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_RectsEqualFloat with various inputs", TEST_ENABLED 2341}; 2342 2343static const SDLTest_TestCaseReference rectTestFRectEqualsParam = { 2344 rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_RectsEqualFloat with invalid parameters", TEST_ENABLED 2345}; 2346 2347static const SDLTest_TestCaseReference rectTestHasIntersectionFloat = { 2348 rect_testHasIntersectionFloat, "rect_testHasIntersectionFloat", "Tests SDL_HasRectIntersectionFloat", TEST_ENABLED 2349}; 2350 2351static const SDLTest_TestCaseReference rectTestGetRectIntersectionFloat = { 2352 rect_testGetRectIntersectionFloat, "rect_testGetRectIntersectionFloat", "Tests SDL_GetRectIntersectionFloat", TEST_ENABLED 2353}; 2354 2355static const SDLTest_TestCaseReference rectTestGetRectUntionFloat = { 2356 rect_testGetRectUntionFloat, "rect_testGetRectUntionFloat", "Tests SDL_GetRectUnionFloat", TEST_ENABLED 2357}; 2358 2359static const SDLTest_TestCaseReference rectTestGetRectEnclosingPointsFloat = { 2360 rect_testGetRectEnclosingPointsFloat, "rect_testGetRectEnclosingPointsFloat", "Tests SDL_GetRectEnclosingPointsFloat", TEST_ENABLED 2361}; 2362 2363static const SDLTest_TestCaseReference rectTestGetRectAndLineIntersectionFloat = { 2364 rect_testGetRectAndLineIntersectionFloat, "rect_testGetRectAndLineIntersectionFloat", "Tests SDL_GetRectAndLineIntersectionFloat", TEST_ENABLED 2365}; 2366 2367/** 2368 * Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges. 2369 */ 2370static const SDLTest_TestCaseReference *rectTests[] = { 2371 &rectTestIntersectRectAndLineFloat, 2372 &rectTestIntersectRectAndLine, 2373 &rectTestIntersectRectAndLineInside, 2374 &rectTestIntersectRectAndLineOutside, 2375 &rectTestIntersectRectAndLineEmpty, 2376 &rectTestIntersectRectAndLineParam, 2377 &rectTestIntersectRectFloat, 2378 &rectTestIntersectRectInside, 2379 &rectTestIntersectRectOutside, 2380 &rectTestIntersectRectPartial, 2381 &rectTestIntersectRectPoint, 2382 &rectTestIntersectRectEmpty, 2383 &rectTestIntersectRectParam, 2384 &rectTestHasIntersectionInside, 2385 &rectTestHasIntersectionOutside, 2386 &rectTestHasIntersectionPartial, 2387 &rectTestHasIntersectionPoint, 2388 &rectTestHasIntersectionEmpty, 2389 &rectTestHasIntersectionParam, 2390 &rectTestEnclosePointsFloat, 2391 &rectTestEnclosePoints, 2392 &rectTestEnclosePointsWithClipping, 2393 &rectTestEnclosePointsRepeatedInput, 2394 &rectTestEnclosePointsParam, 2395 &rectTestUnionRectInside, 2396 &rectTestUnionRectOutside, 2397 &rectTestUnionRectEmpty, 2398 &rectTestUnionRectParam, 2399 &rectTestRectEmptyFloat, 2400 &rectTestRectEmpty, 2401 &rectTestRectEmptyParam, 2402 &rectTestRectEquals, 2403 &rectTestRectEqualsParam, 2404 &rectTestFRectEquals, 2405 &rectTestFRectEqualsParam, 2406 &rectTestHasIntersectionFloat, 2407 &rectTestGetRectIntersectionFloat, 2408 &rectTestGetRectUntionFloat, 2409 &rectTestGetRectEnclosingPointsFloat, 2410 &rectTestGetRectAndLineIntersectionFloat, 2411 NULL 2412}; 2413 2414/* Rect test suite (global) */ 2415SDLTest_TestSuiteReference rectTestSuite = { 2416 "Rect", 2417 NULL, 2418 rectTests, 2419 NULL 2420}; 2421
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.