SDL

Форк
0
/
testautomation_rect.c 
2137 строк · 82.3 Кб
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
 */
17
static void validateIntersectRectAndLineFloatResults(
18
    SDL_bool intersection, SDL_bool expectedIntersection,
19
    SDL_FRect *rect,
20
    float x1, float y1, float x2, float y2,
21
    float x1Ref, float y1Ref, float x2Ref, float y2Ref)
22
{
23
    SDLTest_AssertCheck(intersection == expectedIntersection,
24
                        "Check for correct intersection result: expected %s, got %s intersecting rect (%.2f,%.2f,%.2f,%.2f) with line (%.2f,%.2f - %.2f,%.2f)",
25
                        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
26
                        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
27
                        rect->x, rect->y, rect->w, rect->h,
28
                        x1Ref, y1Ref, x2Ref, y2Ref);
29
    SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
30
                        "Check if line was incorrectly clipped or modified: got (%.2f,%.2f - %.2f,%.2f) expected (%.2f,%.2f - %.2f,%.2f)",
31
                        x1, y1, x2, y2,
32
                        x1Ref, y1Ref, x2Ref, y2Ref);
33
}
34

35
/**
36
 * Private helper to check SDL_GetRectAndLineIntersection results
37
 */
38
static void validateIntersectRectAndLineResults(
39
    SDL_bool intersection, SDL_bool expectedIntersection,
40
    SDL_Rect *rect, SDL_Rect *refRect,
41
    int x1, int y1, int x2, int y2,
42
    int x1Ref, int y1Ref, int x2Ref, int y2Ref)
43
{
44
    SDLTest_AssertCheck(intersection == expectedIntersection,
45
                        "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
46
                        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
47
                        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
48
                        refRect->x, refRect->y, refRect->w, refRect->h,
49
                        x1Ref, y1Ref, x2Ref, y2Ref);
50
    SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
51
                        "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
52
                        rect->x, rect->y, rect->w, rect->h,
53
                        refRect->x, refRect->y, refRect->w, refRect->h);
54
    SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
55
                        "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
56
                        x1, y1, x2, y2,
57
                        x1Ref, y1Ref, x2Ref, y2Ref);
58
}
59

60
/* Test case functions */
61

62
/**
63
 * Tests SDL_GetRectAndLineIntersectionFloat() clipping cases
64
 *
65
 * \sa SDL_GetRectAndLineIntersectionFloat
66
 */
67
static int rect_testIntersectRectAndLineFloat(void *arg)
68
{
69
    SDL_FRect rect;
70
    float x1, y1;
71
    float x2, y2;
72
    SDL_bool intersected;
73

74
    x1 = 5.0f;
75
    y1 = 6.0f;
76
    x2 = 23.0f;
77
    y2 = 6.0f;
78
    rect.x = 2.5f;
79
    rect.y = 1.5f;
80
    rect.w = 15.25f;
81
    rect.h = 12.0f;
82
    intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2);
83
    validateIntersectRectAndLineFloatResults(intersected, SDL_TRUE, &rect, x1, y1, x2, y2, 5.0f, 6.0f, 17.75f, 6.0f);
84

85
    x1 = 0.0f;
86
    y1 = 6.0f;
87
    x2 = 23.0f;
88
    y2 = 6.0f;
89
    rect.x = 2.5f;
90
    rect.y = 1.5f;
91
    rect.w = 0.25f;
92
    rect.h = 12.0f;
93
    intersected = SDL_GetRectAndLineIntersectionFloat(&rect, &x1, &y1, &x2, &y2);
94
    validateIntersectRectAndLineFloatResults(intersected, SDL_TRUE, &rect, x1, y1, x2, y2, 2.5f, 6.0f, 2.75f, 6.0f);
95

96
    return TEST_COMPLETED;
97
}
98

99
/**
100
 * Tests SDL_GetRectAndLineIntersection() clipping cases
101
 *
102
 * \sa SDL_GetRectAndLineIntersection
103
 */
104
static int rect_testIntersectRectAndLine(void *arg)
105
{
106
    SDL_Rect refRect = { 0, 0, 32, 32 };
107
    SDL_Rect rect;
108
    int x1, y1;
109
    int x2, y2;
110
    SDL_bool intersected;
111

112
    int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
113
    int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
114
    int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
115
    int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
116

117
    x1 = xLeft;
118
    y1 = 15;
119
    x2 = xRight;
120
    y2 = 15;
121
    rect = refRect;
122
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
123
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
124

125
    x1 = 15;
126
    y1 = yTop;
127
    x2 = 15;
128
    y2 = yBottom;
129
    rect = refRect;
130
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
131
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
132

133
    x1 = -refRect.w;
134
    y1 = -refRect.h;
135
    x2 = 2 * refRect.w;
136
    y2 = 2 * refRect.h;
137
    rect = refRect;
138
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
139
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
140

141
    x1 = 2 * refRect.w;
142
    y1 = 2 * refRect.h;
143
    x2 = -refRect.w;
144
    y2 = -refRect.h;
145
    rect = refRect;
146
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
147
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
148

149
    x1 = -1;
150
    y1 = 32;
151
    x2 = 32;
152
    y2 = -1;
153
    rect = refRect;
154
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
155
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
156

157
    x1 = 32;
158
    y1 = -1;
159
    x2 = -1;
160
    y2 = 32;
161
    rect = refRect;
162
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
163
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
164

165
    /* Test some overflow cases */
166
    refRect.x = INT_MAX - 4;
167
    refRect.y = INT_MAX - 4;
168
    x1 = INT_MAX;
169
    y1 = INT_MIN;
170
    x2 = INT_MIN;
171
    y2 = INT_MAX;
172
    rect = refRect;
173
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
174
    validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1, y1, x2, y2);
175

176
    return TEST_COMPLETED;
177
}
178

179
/**
180
 * Tests SDL_GetRectAndLineIntersection() non-clipping case line inside
181
 *
182
 * \sa SDL_GetRectAndLineIntersection
183
 */
184
static int rect_testIntersectRectAndLineInside(void *arg)
185
{
186
    SDL_Rect refRect = { 0, 0, 32, 32 };
187
    SDL_Rect rect;
188
    int x1, y1;
189
    int x2, y2;
190
    SDL_bool intersected;
191

192
    int xmin = refRect.x;
193
    int xmax = refRect.x + refRect.w - 1;
194
    int ymin = refRect.y;
195
    int ymax = refRect.y + refRect.h - 1;
196
    int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
197
    int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
198
    int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
199
    int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
200

201
    x1 = x1Ref;
202
    y1 = y1Ref;
203
    x2 = x2Ref;
204
    y2 = y2Ref;
205
    rect = refRect;
206
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
207
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
208

209
    x1 = x1Ref;
210
    y1 = y1Ref;
211
    x2 = xmax;
212
    y2 = ymax;
213
    rect = refRect;
214
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
215
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
216

217
    x1 = xmin;
218
    y1 = ymin;
219
    x2 = x2Ref;
220
    y2 = y2Ref;
221
    rect = refRect;
222
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
223
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
224

225
    x1 = xmin;
226
    y1 = ymin;
227
    x2 = xmax;
228
    y2 = ymax;
229
    rect = refRect;
230
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
231
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
232

233
    x1 = xmin;
234
    y1 = ymax;
235
    x2 = xmax;
236
    y2 = ymin;
237
    rect = refRect;
238
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
239
    validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
240

241
    return TEST_COMPLETED;
242
}
243

244
/**
245
 * Tests SDL_GetRectAndLineIntersection() non-clipping cases outside
246
 *
247
 * \sa SDL_GetRectAndLineIntersection
248
 */
249
static int rect_testIntersectRectAndLineOutside(void *arg)
250
{
251
    SDL_Rect refRect = { 0, 0, 32, 32 };
252
    SDL_Rect rect;
253
    int x1, y1;
254
    int x2, y2;
255
    SDL_bool intersected;
256

257
    int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
258
    int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
259
    int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
260
    int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
261

262
    x1 = xLeft;
263
    y1 = 0;
264
    x2 = xLeft;
265
    y2 = 31;
266
    rect = refRect;
267
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
268
    validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
269

270
    x1 = xRight;
271
    y1 = 0;
272
    x2 = xRight;
273
    y2 = 31;
274
    rect = refRect;
275
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
276
    validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
277

278
    x1 = 0;
279
    y1 = yTop;
280
    x2 = 31;
281
    y2 = yTop;
282
    rect = refRect;
283
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
284
    validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
285

286
    x1 = 0;
287
    y1 = yBottom;
288
    x2 = 31;
289
    y2 = yBottom;
290
    rect = refRect;
291
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
292
    validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
293

294
    return TEST_COMPLETED;
295
}
296

297
/**
298
 * Tests SDL_GetRectAndLineIntersection() with empty rectangle
299
 *
300
 * \sa SDL_GetRectAndLineIntersection
301
 */
302
static int rect_testIntersectRectAndLineEmpty(void *arg)
303
{
304
    SDL_Rect refRect;
305
    SDL_Rect rect;
306
    int x1, y1, x1Ref, y1Ref;
307
    int x2, y2, x2Ref, y2Ref;
308
    SDL_bool intersected;
309

310
    refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
311
    refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
312
    refRect.w = 0;
313
    refRect.h = 0;
314
    x1Ref = refRect.x;
315
    y1Ref = refRect.y;
316
    x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
317
    y2Ref = SDLTest_RandomIntegerInRange(1, 1024);
318

319
    x1 = x1Ref;
320
    y1 = y1Ref;
321
    x2 = x2Ref;
322
    y2 = y2Ref;
323
    rect = refRect;
324
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
325
    validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
326

327
    return TEST_COMPLETED;
328
}
329

330
/**
331
 * Negative tests against SDL_GetRectAndLineIntersection() with invalid parameters
332
 *
333
 * \sa SDL_GetRectAndLineIntersection
334
 */
335
static int rect_testIntersectRectAndLineParam(void *arg)
336
{
337
    SDL_Rect rect = { 0, 0, 32, 32 };
338
    int x1 = rect.w / 2;
339
    int y1 = rect.h / 2;
340
    int x2 = x1;
341
    int y2 = 2 * rect.h;
342
    SDL_bool intersected;
343

344
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
345
    SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
346

347
    intersected = SDL_GetRectAndLineIntersection((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
348
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
349
    intersected = SDL_GetRectAndLineIntersection(&rect, (int *)NULL, &y1, &x2, &y2);
350
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
351
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, (int *)NULL, &x2, &y2);
352
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
353
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, (int *)NULL, &y2);
354
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
355
    intersected = SDL_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, (int *)NULL);
356
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
357
    intersected = SDL_GetRectAndLineIntersection((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
358
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
359

360
    return TEST_COMPLETED;
361
}
362

363
/**
364
 * Private helper to check SDL_HasRectIntersectionFloat results
365
 */
366
static void validateHasIntersectionFloatResults(
367
    SDL_bool intersection, SDL_bool expectedIntersection,
368
    SDL_FRect *rectA, SDL_FRect *rectB)
369
{
370
    SDLTest_AssertCheck(intersection == expectedIntersection,
371
                        "Check intersection result: expected %s, got %s intersecting A (%.2f,%.2f,%.2f,%.2f) with B (%.2f,%.2f,%.2f,%.2f)",
372
                        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
373
                        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
374
                        rectA->x, rectA->y, rectA->w, rectA->h,
375
                        rectB->x, rectB->y, rectB->w, rectB->h);
376
}
377

378
/**
379
 * Private helper to check SDL_HasRectIntersection results
380
 */
381
static void validateHasIntersectionResults(
382
    SDL_bool intersection, SDL_bool expectedIntersection,
383
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
384
{
385
    SDLTest_AssertCheck(intersection == expectedIntersection,
386
                        "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
387
                        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
388
                        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
389
                        rectA->x, rectA->y, rectA->w, rectA->h,
390
                        rectB->x, rectB->y, rectB->w, rectB->h);
391
    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
392
                        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
393
                        rectA->x, rectA->y, rectA->w, rectA->h,
394
                        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
395
    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
396
                        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
397
                        rectB->x, rectB->y, rectB->w, rectB->h,
398
                        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
399
}
400

401
/**
402
 * Private helper to check SDL_GetRectIntersection results
403
 */
404
static void validateIntersectRectFloatResults(
405
    SDL_bool intersection, SDL_bool expectedIntersection,
406
    SDL_FRect *rectA, SDL_FRect *rectB,
407
    SDL_FRect *result, SDL_FRect *expectedResult)
408
{
409
    validateHasIntersectionFloatResults(intersection, expectedIntersection, rectA, rectB);
410
    if (result && expectedResult) {
411
        SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
412
                            "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)",
413
                            rectA->x, rectA->y, rectA->w, rectA->h,
414
                            rectB->x, rectB->y, rectB->w, rectB->h,
415
                            result->x, result->y, result->w, result->h,
416
                            expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
417
    }
418
    SDLTest_AssertCheck(intersection == SDL_HasRectIntersectionFloat(rectA, rectB),
419
                        "Check that intersection (%s) matches SDL_HasRectIntersectionFloat() result (%s)",
420
                        intersection ? "SDL_TRUE" : "SDL_FALSE",
421
                        SDL_HasRectIntersectionFloat(rectA, rectB) ? "SDL_TRUE" : "SDL_FALSE");
422
}
423

424
/**
425
 * Private helper to check SDL_GetRectIntersection results
426
 */
427
static void validateIntersectRectResults(
428
    SDL_bool intersection, SDL_bool expectedIntersection,
429
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
430
    SDL_Rect *result, SDL_Rect *expectedResult)
431
{
432
    validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
433
    if (result && expectedResult) {
434
        SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
435
                            "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)",
436
                            rectA->x, rectA->y, rectA->w, rectA->h,
437
                            rectB->x, rectB->y, rectB->w, rectB->h,
438
                            result->x, result->y, result->w, result->h,
439
                            expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
440
    }
441
}
442

443
/**
444
 * Private helper to check SDL_GetRectUnion results
445
 */
446
static void validateUnionRectResults(
447
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
448
    SDL_Rect *result, SDL_Rect *expectedResult)
449
{
450
    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
451
                        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
452
                        rectA->x, rectA->y, rectA->w, rectA->h,
453
                        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
454
    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
455
                        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
456
                        rectB->x, rectB->y, rectB->w, rectB->h,
457
                        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
458
    SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
459
                        "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)",
460
                        rectA->x, rectA->y, rectA->w, rectA->h,
461
                        rectB->x, rectB->y, rectB->w, rectB->h,
462
                        result->x, result->y, result->w, result->h,
463
                        expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
464
}
465

466
/**
467
 * Private helper to check SDL_RectEmptyFloat results
468
 */
469
static void validateRectEmptyFloatResults(
470
    SDL_bool empty, SDL_bool expectedEmpty,
471
    SDL_FRect *rect)
472
{
473
    SDLTest_AssertCheck(empty == expectedEmpty,
474
                        "Check for correct empty result: expected %s, got %s testing (%.2f,%.2f,%.2f,%.2f)",
475
                        (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
476
                        (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
477
                        rect->x, rect->y, rect->w, rect->h);
478
}
479

480
/**
481
 * Private helper to check SDL_RectEmpty results
482
 */
483
static void validateRectEmptyResults(
484
    SDL_bool empty, SDL_bool expectedEmpty,
485
    SDL_Rect *rect, SDL_Rect *refRect)
486
{
487
    SDLTest_AssertCheck(empty == expectedEmpty,
488
                        "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
489
                        (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
490
                        (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
491
                        rect->x, rect->y, rect->w, rect->h);
492
    SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
493
                        "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
494
                        rect->x, rect->y, rect->w, rect->h,
495
                        refRect->x, refRect->y, refRect->w, refRect->h);
496
}
497

498
/**
499
 * Private helper to check SDL_RectsEqual results
500
 */
501
static void validateRectEqualsResults(
502
    SDL_bool equals, SDL_bool expectedEquals,
503
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
504
{
505
    SDLTest_AssertCheck(equals == expectedEquals,
506
                        "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
507
                        (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
508
                        (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
509
                        rectA->x, rectA->y, rectA->w, rectA->h,
510
                        rectB->x, rectB->y, rectB->w, rectB->h);
511
    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
512
                        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
513
                        rectA->x, rectA->y, rectA->w, rectA->h,
514
                        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
515
    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
516
                        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
517
                        rectB->x, rectB->y, rectB->w, rectB->h,
518
                        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
519
}
520

521
/**
522
 * Private helper to check SDL_RectsEqualFloat results
523
 */
524
static void validateFRectEqualsResults(
525
    SDL_bool equals, SDL_bool expectedEquals,
526
    SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
527
{
528
    int cmpRes;
529
    SDLTest_AssertCheck(equals == expectedEquals,
530
                        "Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
531
                        (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
532
                        (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
533
                        rectA->x, rectA->y, rectA->w, rectA->h,
534
                        rectB->x, rectB->y, rectB->w, rectB->h);
535
    cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
536
    SDLTest_AssertCheck(cmpRes == 0,
537
                        "Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
538
                        rectA->x, rectA->y, rectA->w, rectA->h,
539
                        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
540
    cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
541
    SDLTest_AssertCheck(cmpRes == 0,
542
                        "Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
543
                        rectB->x, rectB->y, rectB->w, rectB->h,
544
                        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
545
}
546

547
/**
548
 * Tests SDL_GetRectIntersectionFloat()
549
 *
550
 * \sa SDL_GetRectIntersectionFloat
551
 */
552
static int rect_testIntersectRectFloat(void *arg)
553
{
554
    SDL_FRect rectA;
555
    SDL_FRect rectB;
556
    SDL_FRect result;
557
    SDL_FRect expectedResult;
558
    SDL_bool intersection;
559

560
    rectA.x = 0.0f;
561
    rectA.y = 0.0f;
562
    rectA.w = 1.0f;
563
    rectA.h = 1.0f;
564
    rectB.x = 0.0f;
565
    rectB.y = 0.0f;
566
    rectB.w = 1.0f;
567
    rectB.h = 1.0f;
568
    expectedResult = rectA;
569
    intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result);
570
    validateIntersectRectFloatResults(intersection, SDL_TRUE, &rectA, &rectB, &result, &expectedResult);
571

572
    rectA.x = 0.0f;
573
    rectA.y = 0.0f;
574
    rectA.w = 1.0f;
575
    rectA.h = 1.0f;
576
    rectB.x = 1.0f;
577
    rectB.y = 0.0f;
578
    rectB.w = 1.0f;
579
    rectB.h = 1.0f;
580
    expectedResult = rectB;
581
    expectedResult.w = 0.0f;
582
    intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result);
583
    validateIntersectRectFloatResults(intersection, SDL_TRUE, &rectA, &rectB, &result, &expectedResult);
584

585
    rectA.x = 0.0f;
586
    rectA.y = 0.0f;
587
    rectA.w = 1.0f;
588
    rectA.h = 1.0f;
589
    rectB.x = 1.0f;
590
    rectB.y = 1.0f;
591
    rectB.w = 1.0f;
592
    rectB.h = 1.0f;
593
    expectedResult = rectB;
594
    expectedResult.w = 0.0f;
595
    expectedResult.h = 0.0f;
596
    intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result);
597
    validateIntersectRectFloatResults(intersection, SDL_TRUE, &rectA, &rectB, &result, &expectedResult);
598

599
    rectA.x = 0.0f;
600
    rectA.y = 0.0f;
601
    rectA.w = 1.0f;
602
    rectA.h = 1.0f;
603
    rectB.x = 2.0f;
604
    rectB.y = 0.0f;
605
    rectB.w = 1.0f;
606
    rectB.h = 1.0f;
607
    expectedResult = rectB;
608
    expectedResult.w = -1.0f;
609
    intersection = SDL_GetRectIntersectionFloat(&rectA, &rectB, &result);
610
    validateIntersectRectFloatResults(intersection, SDL_FALSE, &rectA, &rectB, &result, &expectedResult);
611

612
    return TEST_COMPLETED;
613
}
614

615
/**
616
 * Tests SDL_GetRectIntersection() with B fully inside A
617
 *
618
 * \sa SDL_GetRectIntersection
619
 */
620
static int rect_testIntersectRectInside(void *arg)
621
{
622
    SDL_Rect refRectA = { 0, 0, 32, 32 };
623
    SDL_Rect refRectB;
624
    SDL_Rect rectA;
625
    SDL_Rect rectB;
626
    SDL_Rect result;
627
    SDL_bool intersection;
628

629
    /* rectB fully contained in rectA */
630
    refRectB.x = 0;
631
    refRectB.y = 0;
632
    refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
633
    refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
634
    rectA = refRectA;
635
    rectB = refRectB;
636
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
637
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
638

639
    return TEST_COMPLETED;
640
}
641

642
/**
643
 * Tests SDL_GetRectIntersection() with B fully outside A
644
 *
645
 * \sa SDL_GetRectIntersection
646
 */
647
static int rect_testIntersectRectOutside(void *arg)
648
{
649
    SDL_Rect refRectA = { 0, 0, 32, 32 };
650
    SDL_Rect refRectB;
651
    SDL_Rect rectA;
652
    SDL_Rect rectB;
653
    SDL_Rect result;
654
    SDL_bool intersection;
655

656
    /* rectB fully outside of rectA */
657
    refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
658
    refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
659
    refRectB.w = refRectA.w;
660
    refRectB.h = refRectA.h;
661
    rectA = refRectA;
662
    rectB = refRectB;
663
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
664
    validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
665

666
    return TEST_COMPLETED;
667
}
668

669
/**
670
 * Tests SDL_GetRectIntersection() with B partially intersecting A
671
 *
672
 * \sa SDL_GetRectIntersection
673
 */
674
static int rect_testIntersectRectPartial(void *arg)
675
{
676
    SDL_Rect refRectA = { 0, 0, 32, 32 };
677
    SDL_Rect refRectB;
678
    SDL_Rect rectA;
679
    SDL_Rect rectB;
680
    SDL_Rect result;
681
    SDL_Rect expectedResult;
682
    SDL_bool intersection;
683

684
    /* rectB partially contained in rectA */
685
    refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
686
    refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
687
    refRectB.w = refRectA.w;
688
    refRectB.h = refRectA.h;
689
    rectA = refRectA;
690
    rectB = refRectB;
691
    expectedResult.x = refRectB.x;
692
    expectedResult.y = refRectB.y;
693
    expectedResult.w = refRectA.w - refRectB.x;
694
    expectedResult.h = refRectA.h - refRectB.y;
695
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
696
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
697

698
    /* rectB right edge */
699
    refRectB.x = rectA.w - 1;
700
    refRectB.y = rectA.y;
701
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
702
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
703
    rectA = refRectA;
704
    rectB = refRectB;
705
    expectedResult.x = refRectB.x;
706
    expectedResult.y = refRectB.y;
707
    expectedResult.w = 1;
708
    expectedResult.h = refRectB.h;
709
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
710
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
711

712
    /* rectB left edge */
713
    refRectB.x = 1 - rectA.w;
714
    refRectB.y = rectA.y;
715
    refRectB.w = refRectA.w;
716
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
717
    rectA = refRectA;
718
    rectB = refRectB;
719
    expectedResult.x = 0;
720
    expectedResult.y = refRectB.y;
721
    expectedResult.w = 1;
722
    expectedResult.h = refRectB.h;
723
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
724
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
725

726
    /* rectB bottom edge */
727
    refRectB.x = rectA.x;
728
    refRectB.y = rectA.h - 1;
729
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
730
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
731
    rectA = refRectA;
732
    rectB = refRectB;
733
    expectedResult.x = refRectB.x;
734
    expectedResult.y = refRectB.y;
735
    expectedResult.w = refRectB.w;
736
    expectedResult.h = 1;
737
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
738
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
739

740
    /* rectB top edge */
741
    refRectB.x = rectA.x;
742
    refRectB.y = 1 - rectA.h;
743
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
744
    refRectB.h = rectA.h;
745
    rectA = refRectA;
746
    rectB = refRectB;
747
    expectedResult.x = refRectB.x;
748
    expectedResult.y = 0;
749
    expectedResult.w = refRectB.w;
750
    expectedResult.h = 1;
751
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
752
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
753

754
    return TEST_COMPLETED;
755
}
756

757
/**
758
 * Tests SDL_GetRectIntersection() with 1x1 pixel sized rectangles
759
 *
760
 * \sa SDL_GetRectIntersection
761
 */
762
static int rect_testIntersectRectPoint(void *arg)
763
{
764
    SDL_Rect refRectA = { 0, 0, 1, 1 };
765
    SDL_Rect refRectB = { 0, 0, 1, 1 };
766
    SDL_Rect rectA;
767
    SDL_Rect rectB;
768
    SDL_Rect result;
769
    SDL_bool intersection;
770
    int offsetX, offsetY;
771

772
    /* intersecting pixels */
773
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
774
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
775
    refRectB.x = refRectA.x;
776
    refRectB.y = refRectA.y;
777
    rectA = refRectA;
778
    rectB = refRectB;
779
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
780
    validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
781

782
    /* non-intersecting pixels cases */
783
    for (offsetX = -1; offsetX <= 1; offsetX++) {
784
        for (offsetY = -1; offsetY <= 1; offsetY++) {
785
            if (offsetX != 0 || offsetY != 0) {
786
                refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
787
                refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
788
                refRectB.x = refRectA.x;
789
                refRectB.y = refRectA.y;
790
                refRectB.x += offsetX;
791
                refRectB.y += offsetY;
792
                rectA = refRectA;
793
                rectB = refRectB;
794
                intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
795
                validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
796
            }
797
        }
798
    }
799

800
    return TEST_COMPLETED;
801
}
802

803
/**
804
 * Tests SDL_GetRectIntersection() with empty rectangles
805
 *
806
 * \sa SDL_GetRectIntersection
807
 */
808
static int rect_testIntersectRectEmpty(void *arg)
809
{
810
    SDL_Rect refRectA;
811
    SDL_Rect refRectB;
812
    SDL_Rect rectA;
813
    SDL_Rect rectB;
814
    SDL_Rect result;
815
    SDL_bool intersection;
816
    SDL_bool empty;
817

818
    /* Rect A empty */
819
    result.w = SDLTest_RandomIntegerInRange(1, 100);
820
    result.h = SDLTest_RandomIntegerInRange(1, 100);
821
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
822
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
823
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
824
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
825
    refRectB = refRectA;
826
    refRectA.w = 0;
827
    refRectA.h = 0;
828
    rectA = refRectA;
829
    rectB = refRectB;
830
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
831
    validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
832
    empty = SDL_RectEmpty(&result);
833
    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
834

835
    /* Rect B empty */
836
    result.w = SDLTest_RandomIntegerInRange(1, 100);
837
    result.h = SDLTest_RandomIntegerInRange(1, 100);
838
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
839
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
840
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
841
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
842
    refRectB = refRectA;
843
    refRectB.w = 0;
844
    refRectB.h = 0;
845
    rectA = refRectA;
846
    rectB = refRectB;
847
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
848
    validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
849
    empty = SDL_RectEmpty(&result);
850
    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
851

852
    /* Rect A and B empty */
853
    result.w = SDLTest_RandomIntegerInRange(1, 100);
854
    result.h = SDLTest_RandomIntegerInRange(1, 100);
855
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
856
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
857
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
858
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
859
    refRectB = refRectA;
860
    refRectA.w = 0;
861
    refRectA.h = 0;
862
    refRectB.w = 0;
863
    refRectB.h = 0;
864
    rectA = refRectA;
865
    rectB = refRectB;
866
    intersection = SDL_GetRectIntersection(&rectA, &rectB, &result);
867
    validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
868
    empty = SDL_RectEmpty(&result);
869
    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
870

871
    return TEST_COMPLETED;
872
}
873

874
/**
875
 * Negative tests against SDL_GetRectIntersection() with invalid parameters
876
 *
877
 * \sa SDL_GetRectIntersection
878
 */
879
static int rect_testIntersectRectParam(void *arg)
880
{
881
    SDL_Rect rectA;
882
    SDL_Rect rectB = { 0 };
883
    SDL_Rect result;
884
    SDL_bool intersection;
885

886
    /* invalid parameter combinations */
887
    intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, &rectB, &result);
888
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
889
    intersection = SDL_GetRectIntersection(&rectA, (SDL_Rect *)NULL, &result);
890
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
891
    intersection = SDL_GetRectIntersection(&rectA, &rectB, (SDL_Rect *)NULL);
892
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
893
    intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
894
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL");
895
    intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
896
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL ");
897
    intersection = SDL_GetRectIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
898
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
899

900
    return TEST_COMPLETED;
901
}
902

903
/**
904
 * Tests SDL_HasRectIntersection() with B fully inside A
905
 *
906
 * \sa SDL_HasRectIntersection
907
 */
908
static int rect_testHasIntersectionInside(void *arg)
909
{
910
    SDL_Rect refRectA = { 0, 0, 32, 32 };
911
    SDL_Rect refRectB;
912
    SDL_Rect rectA;
913
    SDL_Rect rectB;
914
    SDL_bool intersection;
915

916
    /* rectB fully contained in rectA */
917
    refRectB.x = 0;
918
    refRectB.y = 0;
919
    refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
920
    refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
921
    rectA = refRectA;
922
    rectB = refRectB;
923
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
924
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
925

926
    return TEST_COMPLETED;
927
}
928

929
/**
930
 * Tests SDL_HasRectIntersection() with B fully outside A
931
 *
932
 * \sa SDL_HasRectIntersection
933
 */
934
static int rect_testHasIntersectionOutside(void *arg)
935
{
936
    SDL_Rect refRectA = { 0, 0, 32, 32 };
937
    SDL_Rect refRectB;
938
    SDL_Rect rectA;
939
    SDL_Rect rectB;
940
    SDL_bool intersection;
941

942
    /* rectB fully outside of rectA */
943
    refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
944
    refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
945
    refRectB.w = refRectA.w;
946
    refRectB.h = refRectA.h;
947
    rectA = refRectA;
948
    rectB = refRectB;
949
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
950
    validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
951

952
    return TEST_COMPLETED;
953
}
954

955
/**
956
 * Tests SDL_HasRectIntersection() with B partially intersecting A
957
 *
958
 * \sa SDL_HasRectIntersection
959
 */
960
static int rect_testHasIntersectionPartial(void *arg)
961
{
962
    SDL_Rect refRectA = { 0, 0, 32, 32 };
963
    SDL_Rect refRectB;
964
    SDL_Rect rectA;
965
    SDL_Rect rectB;
966
    SDL_bool intersection;
967

968
    /* rectB partially contained in rectA */
969
    refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
970
    refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
971
    refRectB.w = refRectA.w;
972
    refRectB.h = refRectA.h;
973
    rectA = refRectA;
974
    rectB = refRectB;
975
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
976
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
977

978
    /* rectB right edge */
979
    refRectB.x = rectA.w - 1;
980
    refRectB.y = rectA.y;
981
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
982
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
983
    rectA = refRectA;
984
    rectB = refRectB;
985
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
986
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
987

988
    /* rectB left edge */
989
    refRectB.x = 1 - rectA.w;
990
    refRectB.y = rectA.y;
991
    refRectB.w = refRectA.w;
992
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
993
    rectA = refRectA;
994
    rectB = refRectB;
995
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
996
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
997

998
    /* rectB bottom edge */
999
    refRectB.x = rectA.x;
1000
    refRectB.y = rectA.h - 1;
1001
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
1002
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
1003
    rectA = refRectA;
1004
    rectB = refRectB;
1005
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
1006
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
1007

1008
    /* rectB top edge */
1009
    refRectB.x = rectA.x;
1010
    refRectB.y = 1 - rectA.h;
1011
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
1012
    refRectB.h = rectA.h;
1013
    rectA = refRectA;
1014
    rectB = refRectB;
1015
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
1016
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
1017

1018
    return TEST_COMPLETED;
1019
}
1020

1021
/**
1022
 * Tests SDL_HasRectIntersection() with 1x1 pixel sized rectangles
1023
 *
1024
 * \sa SDL_HasRectIntersection
1025
 */
1026
static int rect_testHasIntersectionPoint(void *arg)
1027
{
1028
    SDL_Rect refRectA = { 0, 0, 1, 1 };
1029
    SDL_Rect refRectB = { 0, 0, 1, 1 };
1030
    SDL_Rect rectA;
1031
    SDL_Rect rectB;
1032
    SDL_bool intersection;
1033
    int offsetX, offsetY;
1034

1035
    /* intersecting pixels */
1036
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
1037
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
1038
    refRectB.x = refRectA.x;
1039
    refRectB.y = refRectA.y;
1040
    rectA = refRectA;
1041
    rectB = refRectB;
1042
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
1043
    validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
1044

1045
    /* non-intersecting pixels cases */
1046
    for (offsetX = -1; offsetX <= 1; offsetX++) {
1047
        for (offsetY = -1; offsetY <= 1; offsetY++) {
1048
            if (offsetX != 0 || offsetY != 0) {
1049
                refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
1050
                refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
1051
                refRectB.x = refRectA.x;
1052
                refRectB.y = refRectA.y;
1053
                refRectB.x += offsetX;
1054
                refRectB.y += offsetY;
1055
                rectA = refRectA;
1056
                rectB = refRectB;
1057
                intersection = SDL_HasRectIntersection(&rectA, &rectB);
1058
                validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
1059
            }
1060
        }
1061
    }
1062

1063
    return TEST_COMPLETED;
1064
}
1065

1066
/**
1067
 * Tests SDL_HasRectIntersection() with empty rectangles
1068
 *
1069
 * \sa SDL_HasRectIntersection
1070
 */
1071
static int rect_testHasIntersectionEmpty(void *arg)
1072
{
1073
    SDL_Rect refRectA;
1074
    SDL_Rect refRectB;
1075
    SDL_Rect rectA;
1076
    SDL_Rect rectB;
1077
    SDL_bool intersection;
1078

1079
    /* Rect A empty */
1080
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
1081
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
1082
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
1083
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
1084
    refRectB = refRectA;
1085
    refRectA.w = 0;
1086
    refRectA.h = 0;
1087
    rectA = refRectA;
1088
    rectB = refRectB;
1089
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
1090
    validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
1091

1092
    /* Rect B empty */
1093
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
1094
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
1095
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
1096
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
1097
    refRectB = refRectA;
1098
    refRectB.w = 0;
1099
    refRectB.h = 0;
1100
    rectA = refRectA;
1101
    rectB = refRectB;
1102
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
1103
    validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
1104

1105
    /* Rect A and B empty */
1106
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
1107
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
1108
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
1109
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
1110
    refRectB = refRectA;
1111
    refRectA.w = 0;
1112
    refRectA.h = 0;
1113
    refRectB.w = 0;
1114
    refRectB.h = 0;
1115
    rectA = refRectA;
1116
    rectB = refRectB;
1117
    intersection = SDL_HasRectIntersection(&rectA, &rectB);
1118
    validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
1119

1120
    return TEST_COMPLETED;
1121
}
1122

1123
/**
1124
 * Negative tests against SDL_HasRectIntersection() with invalid parameters
1125
 *
1126
 * \sa SDL_HasRectIntersection
1127
 */
1128
static int rect_testHasIntersectionParam(void *arg)
1129
{
1130
    SDL_Rect rectA;
1131
    SDL_Rect rectB = { 0 };
1132
    SDL_bool intersection;
1133

1134
    /* invalid parameter combinations */
1135
    intersection = SDL_HasRectIntersection((SDL_Rect *)NULL, &rectB);
1136
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
1137
    intersection = SDL_HasRectIntersection(&rectA, (SDL_Rect *)NULL);
1138
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
1139
    intersection = SDL_HasRectIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
1140
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
1141

1142
    return TEST_COMPLETED;
1143
}
1144

1145
/**
1146
 * Test SDL_GetRectEnclosingPointsFloat()
1147
 *
1148
 * \sa SDL_GetRectEnclosingPointsFloat
1149
 */
1150
static int rect_testEnclosePointsFloat(void *arg)
1151
{
1152
    SDL_FPoint fpts[3] = { { 1.25f, 2.5f }, { 1.75f, 3.75f }, { 3.5f, 3.0f } };
1153
    int i, count = 3;
1154
    SDL_FRect clip = { 0.0f, 1.0f, 4.0f, 4.0f };
1155
    SDL_FRect result;
1156

1157
    SDL_GetRectEnclosingPointsFloat(fpts, count, &clip, &result);
1158
    SDLTest_AssertCheck(result.x == 1.25f && result.y == 2.5f && result.w == 2.25f && result.h == 1.25f,
1159
                        "Resulting enclosing rectangle incorrect: expected (%.2f,%.2f - %.2fx%.2f), actual (%.2f,%.2f - %.2fx%.2f)",
1160
                        1.25f, 2.5f, 2.25f, 1.25f, result.x, result.y, result.w, result.h);
1161
    for (i = 0; i != count; i++) {
1162
        SDL_bool inside;
1163

1164
        inside = SDL_PointInRectFloat(&fpts[i], &clip);
1165
        SDLTest_AssertCheck(inside,
1166
                            "Expected point (%.2f,%.2f) to be inside clip rect (%.2f,%.2f - %.2fx%.2f)",
1167
                            fpts[i].x, fpts[i].y, clip.x, clip.y, clip.w, clip.h);
1168

1169
        inside = SDL_PointInRectFloat(&fpts[i], &result);
1170
        SDLTest_AssertCheck(inside,
1171
                            "Expected point (%.2f,%.2f) to be inside result rect (%.2f,%.2f - %.2fx%.2f)",
1172
                            fpts[i].x, fpts[i].y, result.x, result.y, result.w, result.h);
1173
    }
1174

1175
    return TEST_COMPLETED;
1176
}
1177

1178
/**
1179
 * Test SDL_GetRectEnclosingPoints() without clipping
1180
 *
1181
 * \sa SDL_GetRectEnclosingPoints
1182
 */
1183
static int rect_testEnclosePoints(void *arg)
1184
{
1185
    const int numPoints = 16;
1186
    SDL_Point refPoints[16];
1187
    SDL_Point points[16];
1188
    SDL_Rect result;
1189
    SDL_bool anyEnclosed;
1190
    SDL_bool anyEnclosedNoResult;
1191
    SDL_bool expectedEnclosed = SDL_TRUE;
1192
    int newx, newy;
1193
    int minx = 0, maxx = 0, miny = 0, maxy = 0;
1194
    int i;
1195

1196
    /* Create input data, tracking result */
1197
    for (i = 0; i < numPoints; i++) {
1198
        newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1199
        newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1200
        refPoints[i].x = newx;
1201
        refPoints[i].y = newy;
1202
        points[i].x = newx;
1203
        points[i].y = newy;
1204
        if (i == 0) {
1205
            minx = newx;
1206
            maxx = newx;
1207
            miny = newy;
1208
            maxy = newy;
1209
        } else {
1210
            if (newx < minx) {
1211
                minx = newx;
1212
            }
1213
            if (newx > maxx) {
1214
                maxx = newx;
1215
            }
1216
            if (newy < miny) {
1217
                miny = newy;
1218
            }
1219
            if (newy > maxy) {
1220
                maxy = newy;
1221
            }
1222
        }
1223
    }
1224

1225
    /* Call function and validate - special case: no result requested */
1226
    anyEnclosedNoResult = SDL_GetRectEnclosingPoints(points, numPoints, NULL, (SDL_Rect *)NULL);
1227
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult,
1228
                        "Check expected return value %s, got %s",
1229
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1230
                        (anyEnclosedNoResult == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1231
    for (i = 0; i < numPoints; i++) {
1232
        SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1233
                            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1234
                            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1235
    }
1236

1237
    /* Call function and validate */
1238
    anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, NULL, &result);
1239
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1240
                        "Check return value %s, got %s",
1241
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1242
                        (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1243
    for (i = 0; i < numPoints; i++) {
1244
        SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1245
                            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1246
                            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1247
    }
1248
    SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1),
1249
                        "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1250
                        minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1251

1252
    return TEST_COMPLETED;
1253
}
1254

1255
/**
1256
 * Test SDL_GetRectEnclosingPoints() with repeated input points
1257
 *
1258
 * \sa SDL_GetRectEnclosingPoints
1259
 */
1260
static int rect_testEnclosePointsRepeatedInput(void *arg)
1261
{
1262
    const int numPoints = 8;
1263
    const int halfPoints = 4;
1264
    SDL_Point refPoints[8];
1265
    SDL_Point points[8];
1266
    SDL_Rect result;
1267
    SDL_bool anyEnclosed;
1268
    SDL_bool anyEnclosedNoResult;
1269
    SDL_bool expectedEnclosed = SDL_TRUE;
1270
    int newx, newy;
1271
    int minx = 0, maxx = 0, miny = 0, maxy = 0;
1272
    int i;
1273

1274
    /* Create input data, tracking result */
1275
    for (i = 0; i < numPoints; i++) {
1276
        if (i < halfPoints) {
1277
            newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1278
            newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1279
        } else {
1280
            newx = refPoints[i - halfPoints].x;
1281
            newy = refPoints[i - halfPoints].y;
1282
        }
1283
        refPoints[i].x = newx;
1284
        refPoints[i].y = newy;
1285
        points[i].x = newx;
1286
        points[i].y = newy;
1287
        if (i == 0) {
1288
            minx = newx;
1289
            maxx = newx;
1290
            miny = newy;
1291
            maxy = newy;
1292
        } else {
1293
            if (newx < minx) {
1294
                minx = newx;
1295
            }
1296
            if (newx > maxx) {
1297
                maxx = newx;
1298
            }
1299
            if (newy < miny) {
1300
                miny = newy;
1301
            }
1302
            if (newy > maxy) {
1303
                maxy = newy;
1304
            }
1305
        }
1306
    }
1307

1308
    /* Call function and validate - special case: no result requested */
1309
    anyEnclosedNoResult = SDL_GetRectEnclosingPoints(points, numPoints, NULL, (SDL_Rect *)NULL);
1310
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult,
1311
                        "Check return value %s, got %s",
1312
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1313
                        (anyEnclosedNoResult == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1314
    for (i = 0; i < numPoints; i++) {
1315
        SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1316
                            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1317
                            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1318
    }
1319

1320
    /* Call function and validate */
1321
    anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, NULL, &result);
1322
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1323
                        "Check return value %s, got %s",
1324
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1325
                        (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1326
    for (i = 0; i < numPoints; i++) {
1327
        SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1328
                            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1329
                            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1330
    }
1331
    SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1),
1332
                        "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1333
                        minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1334

1335
    return TEST_COMPLETED;
1336
}
1337

1338
/**
1339
 * Test SDL_GetRectEnclosingPoints() with clipping
1340
 *
1341
 * \sa SDL_GetRectEnclosingPoints
1342
 */
1343
static int rect_testEnclosePointsWithClipping(void *arg)
1344
{
1345
    const int numPoints = 16;
1346
    SDL_Point refPoints[16];
1347
    SDL_Point points[16];
1348
    SDL_Rect refClip;
1349
    SDL_Rect clip;
1350
    SDL_Rect result;
1351
    SDL_bool anyEnclosed;
1352
    SDL_bool anyEnclosedNoResult;
1353
    SDL_bool expectedEnclosed = SDL_FALSE;
1354
    int newx, newy;
1355
    int minx = 0, maxx = 0, miny = 0, maxy = 0;
1356
    int i;
1357

1358
    /* Setup clipping rectangle */
1359
    refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1360
    refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1361
    refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
1362
    refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
1363

1364
    /* Create input data, tracking result */
1365
    for (i = 0; i < numPoints; i++) {
1366
        newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1367
        newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1368
        refPoints[i].x = newx;
1369
        refPoints[i].y = newy;
1370
        points[i].x = newx;
1371
        points[i].y = newy;
1372
        if ((newx >= refClip.x) && (newx < (refClip.x + refClip.w)) &&
1373
            (newy >= refClip.y) && (newy < (refClip.y + refClip.h))) {
1374
            if (expectedEnclosed == SDL_FALSE) {
1375
                minx = newx;
1376
                maxx = newx;
1377
                miny = newy;
1378
                maxy = newy;
1379
            } else {
1380
                if (newx < minx) {
1381
                    minx = newx;
1382
                }
1383
                if (newx > maxx) {
1384
                    maxx = newx;
1385
                }
1386
                if (newy < miny) {
1387
                    miny = newy;
1388
                }
1389
                if (newy > maxy) {
1390
                    maxy = newy;
1391
                }
1392
            }
1393
            expectedEnclosed = SDL_TRUE;
1394
        }
1395
    }
1396

1397
    /* Call function and validate - special case: no result requested */
1398
    clip = refClip;
1399
    anyEnclosedNoResult = SDL_GetRectEnclosingPoints(points, numPoints, &clip, NULL);
1400
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult,
1401
                        "Expected return value %s, got %s",
1402
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1403
                        (anyEnclosedNoResult == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1404
    for (i = 0; i < numPoints; i++) {
1405
        SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1406
                            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1407
                            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1408
    }
1409
    SDLTest_AssertCheck(refClip.x == clip.x && refClip.y == clip.y && refClip.w == clip.w && refClip.h == clip.h,
1410
                        "Check that source clipping rectangle was not modified");
1411

1412
    /* Call function and validate */
1413
    anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, &clip, &result);
1414
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1415
                        "Check return value %s, got %s",
1416
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1417
                        (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1418
    for (i = 0; i < numPoints; i++) {
1419
        SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1420
                            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1421
                            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1422
    }
1423
    SDLTest_AssertCheck(refClip.x == clip.x && refClip.y == clip.y && refClip.w == clip.w && refClip.h == clip.h,
1424
                        "Check that source clipping rectangle was not modified");
1425
    if (expectedEnclosed == SDL_TRUE) {
1426
        SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1),
1427
                            "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1428
                            minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1429
    }
1430

1431
    /* Empty clipping rectangle */
1432
    clip.w = 0;
1433
    clip.h = 0;
1434
    expectedEnclosed = SDL_FALSE;
1435
    anyEnclosed = SDL_GetRectEnclosingPoints(points, numPoints, &clip, &result);
1436
    SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1437
                        "Check return value %s, got %s",
1438
                        (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1439
                        (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1440

1441
    return TEST_COMPLETED;
1442
}
1443

1444
/**
1445
 * Negative tests against SDL_GetRectEnclosingPoints() with invalid parameters
1446
 *
1447
 * \sa SDL_GetRectEnclosingPoints
1448
 */
1449
static int rect_testEnclosePointsParam(void *arg)
1450
{
1451
    SDL_Point points[1];
1452
    int count;
1453
    SDL_Rect clip = { 0 };
1454
    SDL_Rect result;
1455
    SDL_bool anyEnclosed;
1456

1457
    /* invalid parameter combinations */
1458
    anyEnclosed = SDL_GetRectEnclosingPoints((SDL_Point *)NULL, 1, &clip, &result);
1459
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL");
1460
    anyEnclosed = SDL_GetRectEnclosingPoints(points, 0, &clip, &result);
1461
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is 0");
1462
    count = SDLTest_RandomIntegerInRange(-100, -1);
1463
    anyEnclosed = SDL_GetRectEnclosingPoints(points, count, &clip, &result);
1464
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is %i (negative)", count);
1465
    anyEnclosed = SDL_GetRectEnclosingPoints((SDL_Point *)NULL, 0, &clip, &result);
1466
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL and 2nd parameter was 0");
1467

1468
    return TEST_COMPLETED;
1469
}
1470

1471
/**
1472
 * Tests SDL_GetRectUnion() where rect B is outside rect A
1473
 *
1474
 * \sa SDL_GetRectUnion
1475
 */
1476
static int rect_testUnionRectOutside(void *arg)
1477
{
1478
    SDL_Rect refRectA, refRectB;
1479
    SDL_Rect rectA, rectB;
1480
    SDL_Rect expectedResult;
1481
    SDL_Rect result;
1482
    int minx, maxx, miny, maxy;
1483
    int dx, dy;
1484

1485
    /* Union 1x1 outside */
1486
    for (dx = -1; dx < 2; dx++) {
1487
        for (dy = -1; dy < 2; dy++) {
1488
            if ((dx != 0) || (dy != 0)) {
1489
                refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1490
                refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1491
                refRectA.w = 1;
1492
                refRectA.h = 1;
1493
                refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024) + dx * 2048;
1494
                refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024) + dx * 2048;
1495
                refRectB.w = 1;
1496
                refRectB.h = 1;
1497
                minx = (refRectA.x < refRectB.x) ? refRectA.x : refRectB.x;
1498
                maxx = (refRectA.x > refRectB.x) ? refRectA.x : refRectB.x;
1499
                miny = (refRectA.y < refRectB.y) ? refRectA.y : refRectB.y;
1500
                maxy = (refRectA.y > refRectB.y) ? refRectA.y : refRectB.y;
1501
                expectedResult.x = minx;
1502
                expectedResult.y = miny;
1503
                expectedResult.w = maxx - minx + 1;
1504
                expectedResult.h = maxy - miny + 1;
1505
                rectA = refRectA;
1506
                rectB = refRectB;
1507
                SDL_GetRectUnion(&rectA, &rectB, &result);
1508
                validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1509
            }
1510
        }
1511
    }
1512

1513
    /* Union outside overlap */
1514
    for (dx = -1; dx < 2; dx++) {
1515
        for (dy = -1; dy < 2; dy++) {
1516
            if ((dx != 0) || (dy != 0)) {
1517
                refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1518
                refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1519
                refRectA.w = SDLTest_RandomIntegerInRange(256, 512);
1520
                refRectA.h = SDLTest_RandomIntegerInRange(256, 512);
1521
                refRectB.x = refRectA.x + 1 + dx * 2;
1522
                refRectB.y = refRectA.y + 1 + dy * 2;
1523
                refRectB.w = refRectA.w - 2;
1524
                refRectB.h = refRectA.h - 2;
1525
                expectedResult = refRectA;
1526
                if (dx == -1) {
1527
                    expectedResult.x--;
1528
                }
1529
                if (dy == -1) {
1530
                    expectedResult.y--;
1531
                }
1532
                if ((dx == 1) || (dx == -1)) {
1533
                    expectedResult.w++;
1534
                }
1535
                if ((dy == 1) || (dy == -1)) {
1536
                    expectedResult.h++;
1537
                }
1538
                rectA = refRectA;
1539
                rectB = refRectB;
1540
                SDL_GetRectUnion(&rectA, &rectB, &result);
1541
                validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1542
            }
1543
        }
1544
    }
1545

1546
    return TEST_COMPLETED;
1547
}
1548

1549
/**
1550
 * Tests SDL_GetRectUnion() where rect A or rect B are empty
1551
 *
1552
 * \sa SDL_GetRectUnion
1553
 */
1554
static int rect_testUnionRectEmpty(void *arg)
1555
{
1556
    SDL_Rect refRectA, refRectB;
1557
    SDL_Rect rectA, rectB;
1558
    SDL_Rect expectedResult;
1559
    SDL_Rect result;
1560

1561
    /* A empty */
1562
    refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1563
    refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1564
    refRectA.w = 0;
1565
    refRectA.h = 0;
1566
    refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1567
    refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1568
    refRectB.w = SDLTest_RandomIntegerInRange(1, 1024);
1569
    refRectB.h = SDLTest_RandomIntegerInRange(1, 1024);
1570
    expectedResult = refRectB;
1571
    rectA = refRectA;
1572
    rectB = refRectB;
1573
    SDL_GetRectUnion(&rectA, &rectB, &result);
1574
    validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1575

1576
    /* B empty */
1577
    refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1578
    refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1579
    refRectA.w = SDLTest_RandomIntegerInRange(1, 1024);
1580
    refRectA.h = SDLTest_RandomIntegerInRange(1, 1024);
1581
    refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1582
    refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1583
    refRectB.w = 0;
1584
    refRectB.h = 0;
1585
    expectedResult = refRectA;
1586
    rectA = refRectA;
1587
    rectB = refRectB;
1588
    SDL_GetRectUnion(&rectA, &rectB, &result);
1589
    validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1590

1591
    /* A and B empty */
1592
    refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1593
    refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1594
    refRectA.w = 0;
1595
    refRectA.h = 0;
1596
    refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1597
    refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1598
    refRectB.w = 0;
1599
    refRectB.h = 0;
1600
    result.x = 0;
1601
    result.y = 0;
1602
    result.w = 0;
1603
    result.h = 0;
1604
    expectedResult = result;
1605
    rectA = refRectA;
1606
    rectB = refRectB;
1607
    SDL_GetRectUnion(&rectA, &rectB, &result);
1608
    validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1609

1610
    return TEST_COMPLETED;
1611
}
1612

1613
/**
1614
 * Tests SDL_GetRectUnion() where rect B is inside rect A
1615
 *
1616
 * \sa SDL_GetRectUnion
1617
 */
1618
static int rect_testUnionRectInside(void *arg)
1619
{
1620
    SDL_Rect refRectA, refRectB;
1621
    SDL_Rect rectA, rectB;
1622
    SDL_Rect expectedResult;
1623
    SDL_Rect result;
1624
    int dx, dy;
1625

1626
    /* Union 1x1 with itself */
1627
    refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1628
    refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1629
    refRectA.w = 1;
1630
    refRectA.h = 1;
1631
    expectedResult = refRectA;
1632
    rectA = refRectA;
1633
    SDL_GetRectUnion(&rectA, &rectA, &result);
1634
    validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
1635

1636
    /* Union 1x1 somewhere inside */
1637
    refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1638
    refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1639
    refRectA.w = SDLTest_RandomIntegerInRange(256, 1024);
1640
    refRectA.h = SDLTest_RandomIntegerInRange(256, 1024);
1641
    refRectB.x = refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2);
1642
    refRectB.y = refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2);
1643
    refRectB.w = 1;
1644
    refRectB.h = 1;
1645
    expectedResult = refRectA;
1646
    rectA = refRectA;
1647
    rectB = refRectB;
1648
    SDL_GetRectUnion(&rectA, &rectB, &result);
1649
    validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1650

1651
    /* Union inside with edges modified */
1652
    for (dx = -1; dx < 2; dx++) {
1653
        for (dy = -1; dy < 2; dy++) {
1654
            if ((dx != 0) || (dy != 0)) {
1655
                refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1656
                refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1657
                refRectA.w = SDLTest_RandomIntegerInRange(256, 1024);
1658
                refRectA.h = SDLTest_RandomIntegerInRange(256, 1024);
1659
                refRectB = refRectA;
1660
                if (dx == -1) {
1661
                    refRectB.x++;
1662
                }
1663
                if ((dx == 1) || (dx == -1)) {
1664
                    refRectB.w--;
1665
                }
1666
                if (dy == -1) {
1667
                    refRectB.y++;
1668
                }
1669
                if ((dy == 1) || (dy == -1)) {
1670
                    refRectB.h--;
1671
                }
1672
                expectedResult = refRectA;
1673
                rectA = refRectA;
1674
                rectB = refRectB;
1675
                SDL_GetRectUnion(&rectA, &rectB, &result);
1676
                validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1677
            }
1678
        }
1679
    }
1680

1681
    return TEST_COMPLETED;
1682
}
1683

1684
/**
1685
 * Negative tests against SDL_GetRectUnion() with invalid parameters
1686
 *
1687
 * \sa SDL_GetRectUnion
1688
 */
1689
static int rect_testUnionRectParam(void *arg)
1690
{
1691
    SDL_Rect rectA, rectB = { 0 };
1692
    SDL_Rect result;
1693

1694
    /* invalid parameter combinations */
1695
    SDL_GetRectUnion((SDL_Rect *)NULL, &rectB, &result);
1696
    SDLTest_AssertPass("Check that function returns when 1st parameter is NULL");
1697
    SDL_GetRectUnion(&rectA, (SDL_Rect *)NULL, &result);
1698
    SDLTest_AssertPass("Check that function returns  when 2nd parameter is NULL");
1699
    SDL_GetRectUnion(&rectA, &rectB, (SDL_Rect *)NULL);
1700
    SDLTest_AssertPass("Check that function returns  when 3rd parameter is NULL");
1701
    SDL_GetRectUnion((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
1702
    SDLTest_AssertPass("Check that function returns  when 1st and 3rd parameter are NULL");
1703
    SDL_GetRectUnion(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1704
    SDLTest_AssertPass("Check that function returns  when 2nd and 3rd parameter are NULL");
1705
    SDL_GetRectUnion((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1706
    SDLTest_AssertPass("Check that function returns  when all parameters are NULL");
1707

1708
    return TEST_COMPLETED;
1709
}
1710

1711
/**
1712
 * Tests SDL_RectEmptyFloat() with various inputs
1713
 *
1714
 * \sa SDL_RectEmptyFloat
1715
 */
1716
static int rect_testRectEmptyFloat(void *arg)
1717
{
1718
    SDL_FRect rect;
1719
    SDL_bool result;
1720

1721
    rect.x = 0.0f;
1722
    rect.y = 0.0f;
1723
    rect.w = 1.0f;
1724
    rect.h = 1.0f;
1725
    result = SDL_RectEmptyFloat(&rect);
1726
    validateRectEmptyFloatResults(result, SDL_FALSE, &rect);
1727

1728
    rect.x = 0.0f;
1729
    rect.y = 0.0f;
1730
    rect.w = 0.0f;
1731
    rect.h = 0.0f;
1732
    result = SDL_RectEmptyFloat(&rect);
1733
    validateRectEmptyFloatResults(result, SDL_FALSE, &rect);
1734

1735
    rect.x = 0.0f;
1736
    rect.y = 0.0f;
1737
    rect.w = -1.0f;
1738
    rect.h = 1.0f;
1739
    result = SDL_RectEmptyFloat(&rect);
1740
    validateRectEmptyFloatResults(result, SDL_TRUE, &rect);
1741

1742
    rect.x = 0.0f;
1743
    rect.y = 0.0f;
1744
    rect.w = 1.0f;
1745
    rect.h = -1.0f;
1746
    result = SDL_RectEmptyFloat(&rect);
1747
    validateRectEmptyFloatResults(result, SDL_TRUE, &rect);
1748

1749

1750
    return TEST_COMPLETED;
1751
}
1752

1753
/**
1754
 * Tests SDL_RectEmpty() with various inputs
1755
 *
1756
 * \sa SDL_RectEmpty
1757
 */
1758
static int rect_testRectEmpty(void *arg)
1759
{
1760
    SDL_Rect refRect;
1761
    SDL_Rect rect;
1762
    SDL_bool expectedResult;
1763
    SDL_bool result;
1764
    int w, h;
1765

1766
    /* Non-empty case */
1767
    refRect.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1768
    refRect.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1769
    refRect.w = SDLTest_RandomIntegerInRange(256, 1024);
1770
    refRect.h = SDLTest_RandomIntegerInRange(256, 1024);
1771
    expectedResult = SDL_FALSE;
1772
    rect = refRect;
1773
    result = SDL_RectEmpty(&rect);
1774
    validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1775

1776
    /* Empty case */
1777
    for (w = -1; w < 2; w++) {
1778
        for (h = -1; h < 2; h++) {
1779
            if ((w != 1) || (h != 1)) {
1780
                refRect.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1781
                refRect.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1782
                refRect.w = w;
1783
                refRect.h = h;
1784
                expectedResult = SDL_TRUE;
1785
                rect = refRect;
1786
                result = SDL_RectEmpty(&rect);
1787
                validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1788
            }
1789
        }
1790
    }
1791

1792
    return TEST_COMPLETED;
1793
}
1794

1795
/**
1796
 * Negative tests against SDL_RectEmpty() with invalid parameters
1797
 *
1798
 * \sa SDL_RectEmpty
1799
 */
1800
static int rect_testRectEmptyParam(void *arg)
1801
{
1802
    SDL_bool result;
1803

1804
    /* invalid parameter combinations */
1805
    result = SDL_RectEmpty(NULL);
1806
    SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL");
1807

1808
    return TEST_COMPLETED;
1809
}
1810

1811
/**
1812
 * Tests SDL_RectsEqual() with various inputs
1813
 *
1814
 * \sa SDL_RectsEqual
1815
 */
1816
static int rect_testRectEquals(void *arg)
1817
{
1818
    SDL_Rect refRectA;
1819
    SDL_Rect refRectB;
1820
    SDL_Rect rectA;
1821
    SDL_Rect rectB;
1822
    SDL_bool expectedResult;
1823
    SDL_bool result;
1824

1825
    /* Equals */
1826
    refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1827
    refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1828
    refRectA.w = SDLTest_RandomIntegerInRange(1, 1024);
1829
    refRectA.h = SDLTest_RandomIntegerInRange(1, 1024);
1830
    refRectB = refRectA;
1831
    expectedResult = SDL_TRUE;
1832
    rectA = refRectA;
1833
    rectB = refRectB;
1834
    result = SDL_RectsEqual(&rectA, &rectB);
1835
    validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
1836

1837
    return TEST_COMPLETED;
1838
}
1839

1840
/**
1841
 * Negative tests against SDL_RectsEqual() with invalid parameters
1842
 *
1843
 * \sa SDL_RectsEqual
1844
 */
1845
static int rect_testRectEqualsParam(void *arg)
1846
{
1847
    SDL_Rect rectA;
1848
    SDL_Rect rectB;
1849
    SDL_bool result;
1850

1851
    /* data setup */
1852
    rectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1853
    rectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1854
    rectA.w = SDLTest_RandomIntegerInRange(1, 1024);
1855
    rectA.h = SDLTest_RandomIntegerInRange(1, 1024);
1856
    rectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1857
    rectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1858
    rectB.w = SDLTest_RandomIntegerInRange(1, 1024);
1859
    rectB.h = SDLTest_RandomIntegerInRange(1, 1024);
1860

1861
    /* invalid parameter combinations */
1862
    result = SDL_RectsEqual(NULL, &rectB);
1863
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
1864
    result = SDL_RectsEqual(&rectA, NULL);
1865
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
1866
    result = SDL_RectsEqual(NULL, NULL);
1867
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
1868

1869
    return TEST_COMPLETED;
1870
}
1871

1872
/**
1873
 * Tests SDL_RectsEqualFloat() with various inputs
1874
 *
1875
 * \sa SDL_RectsEqualFloat
1876
 */
1877
static int rect_testFRectEquals(void *arg)
1878
{
1879
    SDL_FRect refRectA;
1880
    SDL_FRect refRectB;
1881
    SDL_FRect rectA;
1882
    SDL_FRect rectB;
1883
    SDL_bool expectedResult;
1884
    SDL_bool result;
1885

1886
    /* Equals */
1887
    refRectA.x = (float)SDLTest_RandomIntegerInRange(-1024, 1024);
1888
    refRectA.y = (float)SDLTest_RandomIntegerInRange(-1024, 1024);
1889
    refRectA.w = (float)SDLTest_RandomIntegerInRange(1, 1024);
1890
    refRectA.h = (float)SDLTest_RandomIntegerInRange(1, 1024);
1891
    refRectB = refRectA;
1892
    expectedResult = SDL_TRUE;
1893
    rectA = refRectA;
1894
    rectB = refRectB;
1895
    result = SDL_RectsEqualFloat(&rectA, &rectB);
1896
    validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
1897

1898
    return TEST_COMPLETED;
1899
}
1900

1901
/**
1902
 * Negative tests against SDL_RectsEqualFloat() with invalid parameters
1903
 *
1904
 * \sa SDL_RectsEqualFloat
1905
 */
1906
static int rect_testFRectEqualsParam(void *arg)
1907
{
1908
    SDL_FRect rectA;
1909
    SDL_FRect rectB;
1910
    SDL_bool result;
1911

1912
    /* data setup -- For the purpose of this test, the values don't matter. */
1913
    rectA.x = SDLTest_RandomFloat();
1914
    rectA.y = SDLTest_RandomFloat();
1915
    rectA.w = SDLTest_RandomFloat();
1916
    rectA.h = SDLTest_RandomFloat();
1917
    rectB.x = SDLTest_RandomFloat();
1918
    rectB.y = SDLTest_RandomFloat();
1919
    rectB.w = SDLTest_RandomFloat();
1920
    rectB.h = SDLTest_RandomFloat();
1921

1922
    /* invalid parameter combinations */
1923
    result = SDL_RectsEqualFloat(NULL, &rectB);
1924
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
1925
    result = SDL_RectsEqualFloat(&rectA, NULL);
1926
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
1927
    result = SDL_RectsEqualFloat(NULL, NULL);
1928
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
1929

1930
    return TEST_COMPLETED;
1931
}
1932

1933
/* ================= Test References ================== */
1934

1935
/* Rect test cases */
1936

1937
/* SDL_GetRectAndLineIntersectionFloat */
1938
static const SDLTest_TestCaseReference rectTestIntersectRectAndLineFloat = {
1939
    (SDLTest_TestCaseFp)rect_testIntersectRectAndLineFloat, "rect_testIntersectRectAndLineFloat", "Tests SDL_GetRectAndLineIntersectionFloat", TEST_ENABLED
1940
};
1941

1942
/* SDL_GetRectAndLineIntersection */
1943
static const SDLTest_TestCaseReference rectTestIntersectRectAndLine = {
1944
    (SDLTest_TestCaseFp)rect_testIntersectRectAndLine, "rect_testIntersectRectAndLine", "Tests SDL_GetRectAndLineIntersection clipping cases", TEST_ENABLED
1945
};
1946

1947
static const SDLTest_TestCaseReference rectTestIntersectRectAndLineInside = {
1948
    (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_GetRectAndLineIntersection with line fully contained in rect", TEST_ENABLED
1949
};
1950

1951
static const SDLTest_TestCaseReference rectTestIntersectRectAndLineOutside = {
1952
    (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_GetRectAndLineIntersection with line fully outside of rect", TEST_ENABLED
1953
};
1954

1955
static const SDLTest_TestCaseReference rectTestIntersectRectAndLineEmpty = {
1956
    (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_GetRectAndLineIntersection with empty rectangle ", TEST_ENABLED
1957
};
1958

1959
static const SDLTest_TestCaseReference rectTestIntersectRectAndLineParam = {
1960
    (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_GetRectAndLineIntersection with invalid parameters", TEST_ENABLED
1961
};
1962

1963
/* SDL_GetRectIntersectionFloat */
1964
static const SDLTest_TestCaseReference rectTestIntersectRectFloat = {
1965
    (SDLTest_TestCaseFp)rect_testIntersectRectFloat, "rect_testIntersectRectFloat", "Tests SDL_GetRectIntersectionFloat", TEST_ENABLED
1966
};
1967

1968
/* SDL_GetRectIntersection */
1969
static const SDLTest_TestCaseReference rectTestIntersectRectInside = {
1970
    (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_GetRectIntersection with B fully contained in A", TEST_ENABLED
1971
};
1972

1973
static const SDLTest_TestCaseReference rectTestIntersectRectOutside = {
1974
    (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_GetRectIntersection with B fully outside of A", TEST_ENABLED
1975
};
1976

1977
static const SDLTest_TestCaseReference rectTestIntersectRectPartial = {
1978
    (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_GetRectIntersection with B partially intersecting A", TEST_ENABLED
1979
};
1980

1981
static const SDLTest_TestCaseReference rectTestIntersectRectPoint = {
1982
    (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_GetRectIntersection with 1x1 sized rectangles", TEST_ENABLED
1983
};
1984

1985
static const SDLTest_TestCaseReference rectTestIntersectRectEmpty = {
1986
    (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_GetRectIntersection with empty rectangles", TEST_ENABLED
1987
};
1988

1989
static const SDLTest_TestCaseReference rectTestIntersectRectParam = {
1990
    (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_GetRectIntersection with invalid parameters", TEST_ENABLED
1991
};
1992

1993
/* SDL_HasRectIntersection */
1994
static const SDLTest_TestCaseReference rectTestHasIntersectionInside = {
1995
    (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasRectIntersection with B fully contained in A", TEST_ENABLED
1996
};
1997

1998
static const SDLTest_TestCaseReference rectTestHasIntersectionOutside = {
1999
    (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasRectIntersection with B fully outside of A", TEST_ENABLED
2000
};
2001

2002
static const SDLTest_TestCaseReference rectTestHasIntersectionPartial = {
2003
    (SDLTest_TestCaseFp)rect_testHasIntersectionPartial, "rect_testHasIntersectionPartial", "Tests SDL_HasRectIntersection with B partially intersecting A", TEST_ENABLED
2004
};
2005

2006
static const SDLTest_TestCaseReference rectTestHasIntersectionPoint = {
2007
    (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasRectIntersection with 1x1 sized rectangles", TEST_ENABLED
2008
};
2009

2010
static const SDLTest_TestCaseReference rectTestHasIntersectionEmpty = {
2011
    (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasRectIntersection with empty rectangles", TEST_ENABLED
2012
};
2013

2014
static const SDLTest_TestCaseReference rectTestHasIntersectionParam = {
2015
    (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasRectIntersection with invalid parameters", TEST_ENABLED
2016
};
2017

2018
/* SDL_GetRectEnclosingPointsFloat */
2019
static const SDLTest_TestCaseReference rectTestEnclosePointsFloat = {
2020
    (SDLTest_TestCaseFp)rect_testEnclosePointsFloat, "rect_testEnclosePointsFloat", "Tests SDL_GetRectEnclosingPointsFloat", TEST_ENABLED
2021
};
2022

2023
/* SDL_GetRectEnclosingPoints */
2024
static const SDLTest_TestCaseReference rectTestEnclosePoints = {
2025
    (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_GetRectEnclosingPoints without clipping", TEST_ENABLED
2026
};
2027

2028
static const SDLTest_TestCaseReference rectTestEnclosePointsWithClipping = {
2029
    (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_GetRectEnclosingPoints with clipping", TEST_ENABLED
2030
};
2031

2032
static const SDLTest_TestCaseReference rectTestEnclosePointsRepeatedInput = {
2033
    (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_GetRectEnclosingPoints with repeated input", TEST_ENABLED
2034
};
2035

2036
static const SDLTest_TestCaseReference rectTestEnclosePointsParam = {
2037
    (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_GetRectEnclosingPoints with invalid parameters", TEST_ENABLED
2038
};
2039

2040
/* SDL_GetRectUnion */
2041
static const SDLTest_TestCaseReference rectTestUnionRectInside = {
2042
    (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_GetRectUnion where rect B is inside rect A", TEST_ENABLED
2043
};
2044

2045
static const SDLTest_TestCaseReference rectTestUnionRectOutside = {
2046
    (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_GetRectUnion where rect B is outside rect A", TEST_ENABLED
2047
};
2048

2049
static const SDLTest_TestCaseReference rectTestUnionRectEmpty = {
2050
    (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_GetRectUnion where rect A or rect B are empty", TEST_ENABLED
2051
};
2052

2053
static const SDLTest_TestCaseReference rectTestUnionRectParam = {
2054
    (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_GetRectUnion with invalid parameters", TEST_ENABLED
2055
};
2056

2057
/* SDL_RectEmptyFloat */
2058
static const SDLTest_TestCaseReference rectTestRectEmptyFloat = {
2059
    (SDLTest_TestCaseFp)rect_testRectEmptyFloat, "rect_testRectEmptyFloat", "Tests SDL_RectEmptyFloat with various inputs", TEST_ENABLED
2060
};
2061

2062
/* SDL_RectEmpty */
2063
static const SDLTest_TestCaseReference rectTestRectEmpty = {
2064
    (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED
2065
};
2066

2067
static const SDLTest_TestCaseReference rectTestRectEmptyParam = {
2068
    (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED
2069
};
2070

2071
/* SDL_RectsEqual */
2072
static const SDLTest_TestCaseReference rectTestRectEquals = {
2073
    (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectsEqual with various inputs", TEST_ENABLED
2074
};
2075

2076
static const SDLTest_TestCaseReference rectTestRectEqualsParam = {
2077
    (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectsEqual with invalid parameters", TEST_ENABLED
2078
};
2079

2080
/* SDL_RectsEqualFloat */
2081
static const SDLTest_TestCaseReference rectTestFRectEquals = {
2082
    (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_RectsEqualFloat with various inputs", TEST_ENABLED
2083
};
2084

2085
static const SDLTest_TestCaseReference rectTestFRectEqualsParam = {
2086
    (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_RectsEqualFloat with invalid parameters", TEST_ENABLED
2087
};
2088

2089
/**
2090
 * Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
2091
 */
2092
static const SDLTest_TestCaseReference *rectTests[] = {
2093
    &rectTestIntersectRectAndLineFloat,
2094
    &rectTestIntersectRectAndLine,
2095
    &rectTestIntersectRectAndLineInside,
2096
    &rectTestIntersectRectAndLineOutside,
2097
    &rectTestIntersectRectAndLineEmpty,
2098
    &rectTestIntersectRectAndLineParam,
2099
    &rectTestIntersectRectFloat,
2100
    &rectTestIntersectRectInside,
2101
    &rectTestIntersectRectOutside,
2102
    &rectTestIntersectRectPartial,
2103
    &rectTestIntersectRectPoint,
2104
    &rectTestIntersectRectEmpty,
2105
    &rectTestIntersectRectParam,
2106
    &rectTestHasIntersectionInside,
2107
    &rectTestHasIntersectionOutside,
2108
    &rectTestHasIntersectionPartial,
2109
    &rectTestHasIntersectionPoint,
2110
    &rectTestHasIntersectionEmpty,
2111
    &rectTestHasIntersectionParam,
2112
    &rectTestEnclosePointsFloat,
2113
    &rectTestEnclosePoints,
2114
    &rectTestEnclosePointsWithClipping,
2115
    &rectTestEnclosePointsRepeatedInput,
2116
    &rectTestEnclosePointsParam,
2117
    &rectTestUnionRectInside,
2118
    &rectTestUnionRectOutside,
2119
    &rectTestUnionRectEmpty,
2120
    &rectTestUnionRectParam,
2121
    &rectTestRectEmptyFloat,
2122
    &rectTestRectEmpty,
2123
    &rectTestRectEmptyParam,
2124
    &rectTestRectEquals,
2125
    &rectTestRectEqualsParam,
2126
    &rectTestFRectEquals,
2127
    &rectTestFRectEqualsParam,
2128
    NULL
2129
};
2130

2131
/* Rect test suite (global) */
2132
SDLTest_TestSuiteReference rectTestSuite = {
2133
    "Rect",
2134
    NULL,
2135
    rectTests,
2136
    NULL
2137
};
2138

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.