test/testautomation_rect.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 7678 286c42d7c5ed
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
aschiffler@6757
     1
/**
aschiffler@6757
     2
 * Original code: automated SDL rect test written by Edgar Simo "bobbens"
aschiffler@6757
     3
 * New/updated tests: aschiffler at ferzkopp dot net
aschiffler@6757
     4
 */
aschiffler@6757
     5
aschiffler@6757
     6
#include <stdio.h>
aschiffler@6757
     7
aschiffler@6757
     8
#include "SDL.h"
aschiffler@6757
     9
#include "SDL_test.h"
aschiffler@6757
    10
aschiffler@6757
    11
/* ================= Test Case Implementation ================== */
aschiffler@6757
    12
aschiffler@6757
    13
/* Helper functions */
aschiffler@6757
    14
gabomdq@7678
    15
/* !
aschiffler@6757
    16
 * \brief Private helper to check SDL_IntersectRectAndLine results
aschiffler@6757
    17
 */
aschiffler@6757
    18
void _validateIntersectRectAndLineResults(
aschiffler@6757
    19
    SDL_bool intersection, SDL_bool expectedIntersection,
aschiffler@6757
    20
    SDL_Rect *rect, SDL_Rect * refRect,
aschiffler@6757
    21
    int x1, int y1, int x2, int y2,
aschiffler@6757
    22
    int x1Ref, int y1Ref, int x2Ref, int y2Ref)
aschiffler@6757
    23
{
slouken@7191
    24
    SDLTest_AssertCheck(intersection == expectedIntersection,
aschiffler@6757
    25
        "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
aschiffler@6757
    26
        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
    27
        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
    28
        refRect->x, refRect->y, refRect->w, refRect->h,
aschiffler@6757
    29
        x1Ref, y1Ref, x2Ref, y2Ref);
aschiffler@6757
    30
    SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
aschiffler@6757
    31
        "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
    32
        rect->x, rect->y, rect->w, rect->h,
aschiffler@6757
    33
        refRect->x, refRect->y, refRect->w, refRect->h);
aschiffler@6757
    34
    SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
aschiffler@6757
    35
        "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
aschiffler@6757
    36
        x1, y1, x2, y2,
aschiffler@6757
    37
        x1Ref, y1Ref, x2Ref, y2Ref);
aschiffler@6757
    38
}
aschiffler@6757
    39
aschiffler@6757
    40
/* Test case functions */
aschiffler@6757
    41
gabomdq@7678
    42
/* !
aschiffler@6757
    43
 * \brief Tests SDL_IntersectRectAndLine() clipping cases
aschiffler@6757
    44
 *
aschiffler@6757
    45
 * \sa
aschiffler@6757
    46
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
aschiffler@6757
    47
 */
slouken@7191
    48
int
aschiffler@6757
    49
rect_testIntersectRectAndLine (void *arg)
aschiffler@6757
    50
{
aschiffler@6757
    51
    SDL_Rect refRect = { 0, 0, 32, 32 };
aschiffler@6757
    52
    SDL_Rect rect;
aschiffler@6757
    53
    int x1, y1;
aschiffler@6757
    54
    int x2, y2;
aschiffler@6757
    55
    SDL_bool intersected;
aschiffler@6757
    56
aschiffler@6757
    57
    int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
aschiffler@6757
    58
    int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
aschiffler@6757
    59
    int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
aschiffler@6757
    60
    int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
aschiffler@6757
    61
aschiffler@6757
    62
    x1 = xLeft;
aschiffler@6757
    63
    y1 = 15;
aschiffler@6757
    64
    x2 = xRight;
aschiffler@6757
    65
    y2 = 15;
aschiffler@6757
    66
    rect = refRect;
aschiffler@6757
    67
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
    68
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
aschiffler@6757
    69
aschiffler@6757
    70
    x1 = 15;
aschiffler@6757
    71
    y1 = yTop;
aschiffler@6757
    72
    x2 = 15;
aschiffler@6757
    73
    y2 = yBottom;
aschiffler@6757
    74
    rect = refRect;
aschiffler@6757
    75
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
    76
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
aschiffler@6757
    77
aschiffler@6757
    78
    x1 = -refRect.w;
aschiffler@6757
    79
    y1 = -refRect.h;
aschiffler@6757
    80
    x2 = 2*refRect.w;
aschiffler@6757
    81
    y2 = 2*refRect.h;
aschiffler@6757
    82
    rect = refRect;
aschiffler@6757
    83
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
    84
     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
aschiffler@6757
    85
aschiffler@6757
    86
    x1 = 2*refRect.w;
aschiffler@6757
    87
    y1 = 2*refRect.h;
aschiffler@6757
    88
    x2 = -refRect.w;
aschiffler@6757
    89
    y2 = -refRect.h;
aschiffler@6757
    90
    rect = refRect;
aschiffler@6757
    91
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
    92
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
aschiffler@6757
    93
aschiffler@6757
    94
    x1 = -1;
aschiffler@6757
    95
    y1 = 32;
aschiffler@6757
    96
    x2 = 32;
aschiffler@6757
    97
    y2 = -1;
aschiffler@6757
    98
    rect = refRect;
aschiffler@6757
    99
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   100
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
aschiffler@6757
   101
aschiffler@6757
   102
    x1 = 32;
aschiffler@6757
   103
    y1 = -1;
aschiffler@6757
   104
    x2 = -1;
aschiffler@6757
   105
    y2 = 32;
aschiffler@6757
   106
    rect = refRect;
aschiffler@6757
   107
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   108
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
aschiffler@6757
   109
slouken@7191
   110
    return TEST_COMPLETED;
aschiffler@6757
   111
}
aschiffler@6757
   112
gabomdq@7678
   113
/* !
aschiffler@6757
   114
 * \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
aschiffler@6757
   115
 *
aschiffler@6757
   116
 * \sa
aschiffler@6757
   117
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
aschiffler@6757
   118
 */
slouken@7191
   119
int
aschiffler@6757
   120
rect_testIntersectRectAndLineInside (void *arg)
aschiffler@6757
   121
{
aschiffler@6757
   122
    SDL_Rect refRect = { 0, 0, 32, 32 };
aschiffler@6757
   123
    SDL_Rect rect;
aschiffler@6757
   124
    int x1, y1;
aschiffler@6757
   125
    int x2, y2;
aschiffler@6757
   126
    SDL_bool intersected;
aschiffler@6757
   127
aschiffler@6757
   128
    int xmin = refRect.x;
aschiffler@6757
   129
    int xmax = refRect.x + refRect.w - 1;
aschiffler@6757
   130
    int ymin = refRect.y;
aschiffler@6757
   131
    int ymax = refRect.y + refRect.h - 1;
aschiffler@6757
   132
    int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
aschiffler@6757
   133
    int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
aschiffler@6757
   134
    int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
aschiffler@6757
   135
    int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
aschiffler@6757
   136
aschiffler@6757
   137
    x1 = x1Ref;
aschiffler@6757
   138
    y1 = y1Ref;
aschiffler@6757
   139
    x2 = x2Ref;
aschiffler@6757
   140
    y2 = y2Ref;
aschiffler@6757
   141
    rect = refRect;
aschiffler@6757
   142
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   143
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
aschiffler@6757
   144
aschiffler@6757
   145
    x1 = x1Ref;
aschiffler@6757
   146
    y1 = y1Ref;
aschiffler@6757
   147
    x2 = xmax;
aschiffler@6757
   148
    y2 = ymax;
aschiffler@6757
   149
    rect = refRect;
aschiffler@6757
   150
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   151
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
aschiffler@6757
   152
aschiffler@6757
   153
    x1 = xmin;
aschiffler@6757
   154
    y1 = ymin;
aschiffler@6757
   155
    x2 = x2Ref;
aschiffler@6757
   156
    y2 = y2Ref;
aschiffler@6757
   157
    rect = refRect;
aschiffler@6757
   158
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   159
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
aschiffler@6757
   160
aschiffler@6757
   161
    x1 = xmin;
aschiffler@6757
   162
    y1 = ymin;
aschiffler@6757
   163
    x2 = xmax;
aschiffler@6757
   164
    y2 = ymax;
aschiffler@6757
   165
    rect = refRect;
aschiffler@6757
   166
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   167
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
aschiffler@6757
   168
aschiffler@6757
   169
    x1 = xmin;
aschiffler@6757
   170
    y1 = ymax;
aschiffler@6757
   171
    x2 = xmax;
aschiffler@6757
   172
    y2 = ymin;
aschiffler@6757
   173
    rect = refRect;
aschiffler@6757
   174
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   175
    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
aschiffler@6757
   176
slouken@7191
   177
    return TEST_COMPLETED;
aschiffler@6757
   178
}
aschiffler@6757
   179
gabomdq@7678
   180
/* !
aschiffler@6757
   181
 * \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
aschiffler@6757
   182
 *
aschiffler@6757
   183
 * \sa
aschiffler@6757
   184
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
aschiffler@6757
   185
 */
slouken@7191
   186
int
aschiffler@6757
   187
rect_testIntersectRectAndLineOutside (void *arg)
aschiffler@6757
   188
{
aschiffler@6757
   189
    SDL_Rect refRect = { 0, 0, 32, 32 };
aschiffler@6757
   190
    SDL_Rect rect;
aschiffler@6757
   191
    int x1, y1;
aschiffler@6757
   192
    int x2, y2;
aschiffler@6757
   193
    SDL_bool intersected;
aschiffler@6757
   194
aschiffler@6757
   195
    int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
aschiffler@6757
   196
    int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
aschiffler@6757
   197
    int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
aschiffler@6757
   198
    int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
aschiffler@6757
   199
aschiffler@6757
   200
    x1 = xLeft;
aschiffler@6757
   201
    y1 = 0;
aschiffler@6757
   202
    x2 = xLeft;
aschiffler@6757
   203
    y2 = 31;
aschiffler@6757
   204
    rect = refRect;
aschiffler@6757
   205
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   206
    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
aschiffler@6757
   207
aschiffler@6757
   208
    x1 = xRight;
aschiffler@6757
   209
    y1 = 0;
aschiffler@6757
   210
    x2 = xRight;
aschiffler@6757
   211
    y2 = 31;
aschiffler@6757
   212
    rect = refRect;
aschiffler@6757
   213
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   214
    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
aschiffler@6757
   215
aschiffler@6757
   216
    x1 = 0;
aschiffler@6757
   217
    y1 = yTop;
aschiffler@6757
   218
    x2 = 31;
aschiffler@6757
   219
    y2 = yTop;
aschiffler@6757
   220
    rect = refRect;
aschiffler@6757
   221
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   222
    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
aschiffler@6757
   223
aschiffler@6757
   224
    x1 = 0;
aschiffler@6757
   225
    y1 = yBottom;
aschiffler@6757
   226
    x2 = 31;
aschiffler@6757
   227
    y2 = yBottom;
aschiffler@6757
   228
    rect = refRect;
aschiffler@6757
   229
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   230
    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
aschiffler@6757
   231
slouken@7191
   232
    return TEST_COMPLETED;
aschiffler@6757
   233
}
aschiffler@6757
   234
gabomdq@7678
   235
/* !
aschiffler@6757
   236
 * \brief Tests SDL_IntersectRectAndLine() with empty rectangle
aschiffler@6757
   237
 *
aschiffler@6757
   238
 * \sa
aschiffler@6757
   239
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
aschiffler@6757
   240
 */
slouken@7191
   241
int
aschiffler@6757
   242
rect_testIntersectRectAndLineEmpty (void *arg)
aschiffler@6757
   243
{
aschiffler@6757
   244
    SDL_Rect refRect;
aschiffler@6757
   245
    SDL_Rect rect;
aschiffler@6757
   246
    int x1, y1, x1Ref, y1Ref;
aschiffler@6757
   247
    int x2, y2, x2Ref, y2Ref;
aschiffler@6757
   248
    SDL_bool intersected;
slouken@7191
   249
aschiffler@6757
   250
    refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
   251
    refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
   252
    refRect.w = 0;
aschiffler@6757
   253
    refRect.h = 0;
aschiffler@6757
   254
    x1Ref = refRect.x;
aschiffler@6757
   255
    y1Ref = refRect.y;
aschiffler@6757
   256
    x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
   257
    y2Ref = SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
   258
aschiffler@6757
   259
    x1 = x1Ref;
aschiffler@6757
   260
    y1 = y1Ref;
aschiffler@6757
   261
    x2 = x2Ref;
aschiffler@6757
   262
    y2 = y2Ref;
aschiffler@6757
   263
    rect = refRect;
aschiffler@6757
   264
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   265
    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
aschiffler@6757
   266
slouken@7191
   267
    return TEST_COMPLETED;
aschiffler@6757
   268
}
aschiffler@6757
   269
gabomdq@7678
   270
/* !
aschiffler@6757
   271
 * \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
aschiffler@6757
   272
 *
aschiffler@6757
   273
 * \sa
aschiffler@6757
   274
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
aschiffler@6757
   275
 */
slouken@7191
   276
int
aschiffler@6757
   277
rect_testIntersectRectAndLineParam (void *arg)
aschiffler@6757
   278
{
aschiffler@6757
   279
    SDL_Rect rect = { 0, 0, 32, 32 };
aschiffler@6757
   280
    int x1 = rect.w / 2;
aschiffler@6757
   281
    int y1 = rect.h / 2;
aschiffler@6757
   282
    int x2 = x1;
aschiffler@6757
   283
    int y2 = 2 * rect.h;
aschiffler@6757
   284
    SDL_bool intersected;
slouken@7191
   285
aschiffler@6757
   286
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
aschiffler@6757
   287
    SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
slouken@7191
   288
aschiffler@6757
   289
    intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
aschiffler@6757
   290
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
aschiffler@6757
   291
    intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
aschiffler@6757
   292
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
aschiffler@6757
   293
    intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
aschiffler@6757
   294
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
aschiffler@6757
   295
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
aschiffler@6757
   296
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
aschiffler@6757
   297
    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
aschiffler@6757
   298
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
aschiffler@6757
   299
    intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
aschiffler@6757
   300
    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
aschiffler@6757
   301
slouken@7191
   302
    return TEST_COMPLETED;
aschiffler@6757
   303
}
aschiffler@6757
   304
gabomdq@7678
   305
/* !
aschiffler@6757
   306
 * \brief Private helper to check SDL_HasIntersection results
aschiffler@6757
   307
 */
aschiffler@6757
   308
void _validateHasIntersectionResults(
slouken@7191
   309
    SDL_bool intersection, SDL_bool expectedIntersection,
aschiffler@6757
   310
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
aschiffler@6757
   311
{
slouken@7191
   312
    SDLTest_AssertCheck(intersection == expectedIntersection,
aschiffler@6757
   313
        "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
aschiffler@6757
   314
        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
   315
        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
   316
        rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   317
        rectB->x, rectB->y, rectB->w, rectB->h);
aschiffler@6757
   318
    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
aschiffler@6757
   319
        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   320
        rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   321
        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
aschiffler@6757
   322
    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
aschiffler@6757
   323
        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   324
        rectB->x, rectB->y, rectB->w, rectB->h,
aschiffler@6757
   325
        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
aschiffler@6757
   326
}
aschiffler@6757
   327
gabomdq@7678
   328
/* !
aschiffler@6757
   329
 * \brief Private helper to check SDL_IntersectRect results
aschiffler@6757
   330
 */
aschiffler@6757
   331
void _validateIntersectRectResults(
slouken@7191
   332
    SDL_bool intersection, SDL_bool expectedIntersection,
slouken@7191
   333
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
aschiffler@6757
   334
    SDL_Rect *result, SDL_Rect *expectedResult)
aschiffler@6757
   335
{
aschiffler@6757
   336
    _validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
aschiffler@6757
   337
    if (result && expectedResult) {
aschiffler@6757
   338
        SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
aschiffler@6757
   339
            "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)",
slouken@7191
   340
            rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   341
            rectB->x, rectB->y, rectB->w, rectB->h,
aschiffler@6757
   342
            result->x, result->y, result->w, result->h,
aschiffler@6757
   343
            expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
aschiffler@6757
   344
    }
aschiffler@6757
   345
}
aschiffler@6757
   346
gabomdq@7678
   347
/* !
aschiffler@6757
   348
 * \brief Private helper to check SDL_UnionRect results
aschiffler@6757
   349
 */
aschiffler@6757
   350
void _validateUnionRectResults(
slouken@7191
   351
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
aschiffler@6757
   352
    SDL_Rect *result, SDL_Rect *expectedResult)
aschiffler@6757
   353
{
aschiffler@6757
   354
    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
aschiffler@6757
   355
        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   356
        rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   357
        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
aschiffler@6757
   358
    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
aschiffler@6757
   359
        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   360
        rectB->x, rectB->y, rectB->w, rectB->h,
aschiffler@6757
   361
        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
aschiffler@6757
   362
    SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
aschiffler@6757
   363
        "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)",
slouken@7191
   364
        rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   365
        rectB->x, rectB->y, rectB->w, rectB->h,
aschiffler@6757
   366
        result->x, result->y, result->w, result->h,
aschiffler@6757
   367
        expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
aschiffler@6757
   368
}
aschiffler@6757
   369
gabomdq@7678
   370
/* !
aschiffler@6757
   371
 * \brief Private helper to check SDL_RectEmpty results
aschiffler@6757
   372
 */
aschiffler@6757
   373
void _validateRectEmptyResults(
slouken@7191
   374
    SDL_bool empty, SDL_bool expectedEmpty,
aschiffler@6757
   375
    SDL_Rect *rect, SDL_Rect *refRect)
aschiffler@6757
   376
{
slouken@7191
   377
    SDLTest_AssertCheck(empty == expectedEmpty,
aschiffler@6757
   378
        "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
aschiffler@6757
   379
        (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
   380
        (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
   381
        rect->x, rect->y, rect->w, rect->h);
aschiffler@6757
   382
    SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
aschiffler@6757
   383
        "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   384
        rect->x, rect->y, rect->w, rect->h,
aschiffler@6757
   385
        refRect->x, refRect->y, refRect->w, refRect->h);
aschiffler@6757
   386
}
aschiffler@6757
   387
gabomdq@7678
   388
/* !
aschiffler@6757
   389
 * \brief Private helper to check SDL_RectEquals results
aschiffler@6757
   390
 */
aschiffler@6757
   391
void _validateRectEqualsResults(
slouken@7191
   392
    SDL_bool equals, SDL_bool expectedEquals,
aschiffler@6757
   393
    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
aschiffler@6757
   394
{
slouken@7191
   395
    SDLTest_AssertCheck(equals == expectedEquals,
aschiffler@6757
   396
        "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
aschiffler@6757
   397
        (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
   398
        (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
aschiffler@6757
   399
        rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   400
        rectB->x, rectB->y, rectB->w, rectB->h);
aschiffler@6757
   401
    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
aschiffler@6757
   402
        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   403
        rectA->x, rectA->y, rectA->w, rectA->h,
aschiffler@6757
   404
        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
aschiffler@6757
   405
    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
aschiffler@6757
   406
        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
aschiffler@6757
   407
        rectB->x, rectB->y, rectB->w, rectB->h,
aschiffler@6757
   408
        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
aschiffler@6757
   409
}
aschiffler@6757
   410
gabomdq@7678
   411
/* !
aschiffler@6757
   412
 * \brief Tests SDL_IntersectRect() with B fully inside A
aschiffler@6757
   413
 *
aschiffler@6757
   414
 * \sa
aschiffler@6757
   415
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
aschiffler@6757
   416
 */
aschiffler@6757
   417
int rect_testIntersectRectInside (void *arg)
aschiffler@6757
   418
{
aschiffler@6757
   419
    SDL_Rect refRectA = { 0, 0, 32, 32 };
aschiffler@6757
   420
    SDL_Rect refRectB;
aschiffler@6757
   421
    SDL_Rect rectA;
aschiffler@6757
   422
    SDL_Rect rectB;
aschiffler@6757
   423
    SDL_Rect result;
aschiffler@6757
   424
    SDL_bool intersection;
aschiffler@6757
   425
gabomdq@7663
   426
    /* rectB fully contained in rectA */
aschiffler@6757
   427
    refRectB.x = 0;
aschiffler@6757
   428
    refRectB.y = 0;
aschiffler@6757
   429
    refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
aschiffler@6757
   430
    refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
aschiffler@6757
   431
    rectA = refRectA;
aschiffler@6757
   432
    rectB = refRectB;
aschiffler@6757
   433
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   434
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
aschiffler@6757
   435
slouken@7191
   436
    return TEST_COMPLETED;
aschiffler@6757
   437
}
aschiffler@6757
   438
gabomdq@7678
   439
/* !
aschiffler@6757
   440
 * \brief Tests SDL_IntersectRect() with B fully outside A
aschiffler@6757
   441
 *
aschiffler@6757
   442
 * \sa
aschiffler@6757
   443
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
aschiffler@6757
   444
 */
aschiffler@6757
   445
int rect_testIntersectRectOutside (void *arg)
aschiffler@6757
   446
{
aschiffler@6757
   447
    SDL_Rect refRectA = { 0, 0, 32, 32 };
aschiffler@6757
   448
    SDL_Rect refRectB;
aschiffler@6757
   449
    SDL_Rect rectA;
aschiffler@6757
   450
    SDL_Rect rectB;
aschiffler@6757
   451
    SDL_Rect result;
aschiffler@6757
   452
    SDL_bool intersection;
aschiffler@6757
   453
gabomdq@7663
   454
    /* rectB fully outside of rectA */
aschiffler@6757
   455
    refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
aschiffler@6757
   456
    refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
aschiffler@6757
   457
    refRectB.w = refRectA.w;
aschiffler@6757
   458
    refRectB.h = refRectA.h;
aschiffler@6757
   459
    rectA = refRectA;
aschiffler@6757
   460
    rectB = refRectB;
aschiffler@6757
   461
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
slouken@7191
   462
    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
aschiffler@6757
   463
slouken@7191
   464
    return TEST_COMPLETED;
aschiffler@6757
   465
}
aschiffler@6757
   466
gabomdq@7678
   467
/* !
aschiffler@6757
   468
 * \brief Tests SDL_IntersectRect() with B partially intersecting A
aschiffler@6757
   469
 *
aschiffler@6757
   470
 * \sa
aschiffler@6757
   471
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
aschiffler@6757
   472
 */
aschiffler@6757
   473
int rect_testIntersectRectPartial (void *arg)
aschiffler@6757
   474
{
aschiffler@6757
   475
    SDL_Rect refRectA = { 0, 0, 32, 32 };
aschiffler@6757
   476
    SDL_Rect refRectB;
aschiffler@6757
   477
    SDL_Rect rectA;
aschiffler@6757
   478
    SDL_Rect rectB;
aschiffler@6757
   479
    SDL_Rect result;
aschiffler@6757
   480
    SDL_Rect expectedResult;
aschiffler@6757
   481
    SDL_bool intersection;
aschiffler@6757
   482
gabomdq@7663
   483
    /* rectB partially contained in rectA */
aschiffler@6757
   484
    refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
aschiffler@6757
   485
    refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
aschiffler@6757
   486
    refRectB.w = refRectA.w;
aschiffler@6757
   487
    refRectB.h = refRectA.h;
aschiffler@6757
   488
    rectA = refRectA;
aschiffler@6757
   489
    rectB = refRectB;
aschiffler@6757
   490
    expectedResult.x = refRectB.x;
aschiffler@6757
   491
    expectedResult.y = refRectB.y;
aschiffler@6757
   492
    expectedResult.w = refRectA.w - refRectB.x;
slouken@7191
   493
    expectedResult.h = refRectA.h - refRectB.y;
aschiffler@6757
   494
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   495
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
   496
gabomdq@7663
   497
    /* rectB right edge */
aschiffler@6757
   498
    refRectB.x = rectA.w - 1;
aschiffler@6757
   499
    refRectB.y = rectA.y;
aschiffler@6757
   500
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
aschiffler@6757
   501
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
aschiffler@6757
   502
    rectA = refRectA;
aschiffler@6757
   503
    rectB = refRectB;
aschiffler@6757
   504
    expectedResult.x = refRectB.x;
aschiffler@6757
   505
    expectedResult.y = refRectB.y;
aschiffler@6757
   506
    expectedResult.w = 1;
slouken@7191
   507
    expectedResult.h = refRectB.h;
aschiffler@6757
   508
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   509
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
   510
gabomdq@7663
   511
    /* rectB left edge */
aschiffler@6757
   512
    refRectB.x = 1 - rectA.w;
aschiffler@6757
   513
    refRectB.y = rectA.y;
aschiffler@6757
   514
    refRectB.w = refRectA.w;
aschiffler@6757
   515
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
aschiffler@6757
   516
    rectA = refRectA;
aschiffler@6757
   517
    rectB = refRectB;
aschiffler@6757
   518
    expectedResult.x = 0;
aschiffler@6757
   519
    expectedResult.y = refRectB.y;
aschiffler@6757
   520
    expectedResult.w = 1;
slouken@7191
   521
    expectedResult.h = refRectB.h;
aschiffler@6757
   522
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   523
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
   524
gabomdq@7663
   525
    /* rectB bottom edge */
aschiffler@6757
   526
    refRectB.x = rectA.x;
aschiffler@6757
   527
    refRectB.y = rectA.h - 1;
aschiffler@6757
   528
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
aschiffler@6757
   529
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
aschiffler@6757
   530
    rectA = refRectA;
aschiffler@6757
   531
    rectB = refRectB;
aschiffler@6757
   532
    expectedResult.x = refRectB.x;
aschiffler@6757
   533
    expectedResult.y = refRectB.y;
aschiffler@6757
   534
    expectedResult.w = refRectB.w;
slouken@7191
   535
    expectedResult.h = 1;
aschiffler@6757
   536
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   537
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
   538
gabomdq@7663
   539
    /* rectB top edge */
aschiffler@6757
   540
    refRectB.x = rectA.x;
aschiffler@6757
   541
    refRectB.y = 1 - rectA.h;
aschiffler@6757
   542
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
aschiffler@6757
   543
    refRectB.h = rectA.h;
aschiffler@6757
   544
    rectA = refRectA;
aschiffler@6757
   545
    rectB = refRectB;
aschiffler@6757
   546
    expectedResult.x = refRectB.x;
aschiffler@6757
   547
    expectedResult.y = 0;
aschiffler@6757
   548
    expectedResult.w = refRectB.w;
slouken@7191
   549
    expectedResult.h = 1;
aschiffler@6757
   550
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   551
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
   552
slouken@7191
   553
    return TEST_COMPLETED;
aschiffler@6757
   554
}
aschiffler@6757
   555
gabomdq@7678
   556
/* !
aschiffler@6757
   557
 * \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
aschiffler@6757
   558
 *
aschiffler@6757
   559
 * \sa
aschiffler@6757
   560
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
aschiffler@6757
   561
 */
aschiffler@6757
   562
int rect_testIntersectRectPoint (void *arg)
aschiffler@6757
   563
{
aschiffler@6757
   564
    SDL_Rect refRectA = { 0, 0, 1, 1 };
aschiffler@6757
   565
    SDL_Rect refRectB = { 0, 0, 1, 1 };
aschiffler@6757
   566
    SDL_Rect rectA;
aschiffler@6757
   567
    SDL_Rect rectB;
aschiffler@6757
   568
    SDL_Rect result;
aschiffler@6757
   569
    SDL_bool intersection;
aschiffler@6757
   570
    int offsetX, offsetY;
aschiffler@6757
   571
gabomdq@7663
   572
    /* intersecting pixels */
aschiffler@6757
   573
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   574
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   575
    refRectB.x = refRectA.x;
aschiffler@6757
   576
    refRectB.y = refRectA.y;
aschiffler@6757
   577
    rectA = refRectA;
aschiffler@6757
   578
    rectB = refRectB;
aschiffler@6757
   579
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   580
    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
aschiffler@6757
   581
gabomdq@7663
   582
    /* non-intersecting pixels cases */
aschiffler@6757
   583
    for (offsetX = -1; offsetX <= 1; offsetX++) {
aschiffler@6757
   584
        for (offsetY = -1; offsetY <= 1; offsetY++) {
aschiffler@6757
   585
            if (offsetX != 0 || offsetY != 0) {
aschiffler@6757
   586
                refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   587
                refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   588
                refRectB.x = refRectA.x;
slouken@7191
   589
                refRectB.y = refRectA.y;
aschiffler@6757
   590
                refRectB.x += offsetX;
aschiffler@6757
   591
                refRectB.y += offsetY;
aschiffler@6757
   592
                rectA = refRectA;
aschiffler@6757
   593
                rectB = refRectB;
aschiffler@6757
   594
                intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   595
                _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
aschiffler@6757
   596
            }
aschiffler@6757
   597
        }
aschiffler@6757
   598
    }
aschiffler@6757
   599
slouken@7191
   600
    return TEST_COMPLETED;
aschiffler@6757
   601
}
aschiffler@6757
   602
gabomdq@7678
   603
/* !
aschiffler@6757
   604
 * \brief Tests SDL_IntersectRect() with empty rectangles
aschiffler@6757
   605
 *
aschiffler@6757
   606
 * \sa
aschiffler@6757
   607
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
aschiffler@6757
   608
 */
aschiffler@6757
   609
int rect_testIntersectRectEmpty (void *arg)
aschiffler@6757
   610
{
aschiffler@6757
   611
    SDL_Rect refRectA;
aschiffler@6757
   612
    SDL_Rect refRectB;
aschiffler@6757
   613
    SDL_Rect rectA;
aschiffler@6757
   614
    SDL_Rect rectB;
aschiffler@6757
   615
    SDL_Rect result;
aschiffler@6757
   616
    SDL_bool intersection;
aschiffler@7074
   617
    SDL_bool empty;
aschiffler@6757
   618
gabomdq@7663
   619
    /* Rect A empty */
aschiffler@7074
   620
    result.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@7074
   621
    result.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   622
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   623
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   624
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   625
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   626
    refRectB = refRectA;
aschiffler@6757
   627
    refRectA.w = 0;
aschiffler@6757
   628
    refRectA.h = 0;
aschiffler@6757
   629
    rectA = refRectA;
aschiffler@6757
   630
    rectB = refRectB;
aschiffler@6757
   631
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   632
    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
aschiffler@7074
   633
    empty = (SDL_bool)SDL_RectEmpty(&result);
aschiffler@7074
   634
    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
slouken@7191
   635
gabomdq@7663
   636
    /* Rect B empty */
aschiffler@7074
   637
    result.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@7074
   638
    result.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   639
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   640
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   641
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   642
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   643
    refRectB = refRectA;
aschiffler@6757
   644
    refRectB.w = 0;
aschiffler@6757
   645
    refRectB.h = 0;
aschiffler@6757
   646
    rectA = refRectA;
aschiffler@6757
   647
    rectB = refRectB;
aschiffler@6757
   648
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   649
    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
aschiffler@7074
   650
    empty = (SDL_bool)SDL_RectEmpty(&result);
aschiffler@7074
   651
    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
   652
gabomdq@7663
   653
    /* Rect A and B empty */
aschiffler@7074
   654
    result.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@7074
   655
    result.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   656
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   657
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   658
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   659
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   660
    refRectB = refRectA;
aschiffler@6757
   661
    refRectA.w = 0;
aschiffler@6757
   662
    refRectA.h = 0;
aschiffler@6757
   663
    refRectB.w = 0;
aschiffler@6757
   664
    refRectB.h = 0;
aschiffler@6757
   665
    rectA = refRectA;
aschiffler@6757
   666
    rectB = refRectB;
aschiffler@6757
   667
    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
aschiffler@6757
   668
    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
aschiffler@7074
   669
    empty = (SDL_bool)SDL_RectEmpty(&result);
aschiffler@7074
   670
    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
   671
aschiffler@7074
   672
    return TEST_COMPLETED;
aschiffler@6757
   673
}
aschiffler@6757
   674
gabomdq@7678
   675
/* !
aschiffler@6757
   676
 * \brief Negative tests against SDL_IntersectRect() with invalid parameters
aschiffler@6757
   677
 *
aschiffler@6757
   678
 * \sa
aschiffler@6757
   679
 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
aschiffler@6757
   680
 */
aschiffler@6757
   681
int rect_testIntersectRectParam(void *arg)
aschiffler@6757
   682
{
aschiffler@6757
   683
    SDL_Rect rectA;
aschiffler@6757
   684
    SDL_Rect rectB;
aschiffler@6757
   685
    SDL_Rect result;
aschiffler@6757
   686
    SDL_bool intersection;
aschiffler@6757
   687
gabomdq@7663
   688
    /* invalid parameter combinations */
aschiffler@6757
   689
    intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
slouken@7191
   690
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
aschiffler@6757
   691
    intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
slouken@7191
   692
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
aschiffler@6757
   693
    intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
slouken@7191
   694
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL");
aschiffler@6757
   695
    intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
slouken@7191
   696
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL");
aschiffler@6757
   697
    intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
slouken@7191
   698
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL ");
aschiffler@6757
   699
    intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
slouken@7191
   700
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
aschiffler@6757
   701
slouken@7191
   702
    return TEST_COMPLETED;
aschiffler@6757
   703
}
aschiffler@6757
   704
gabomdq@7678
   705
/* !
aschiffler@6757
   706
 * \brief Tests SDL_HasIntersection() with B fully inside A
aschiffler@6757
   707
 *
aschiffler@6757
   708
 * \sa
aschiffler@6757
   709
 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
aschiffler@6757
   710
 */
aschiffler@6757
   711
int rect_testHasIntersectionInside (void *arg)
aschiffler@6757
   712
{
aschiffler@6757
   713
    SDL_Rect refRectA = { 0, 0, 32, 32 };
aschiffler@6757
   714
    SDL_Rect refRectB;
aschiffler@6757
   715
    SDL_Rect rectA;
aschiffler@6757
   716
    SDL_Rect rectB;
aschiffler@6757
   717
    SDL_bool intersection;
aschiffler@6757
   718
gabomdq@7663
   719
    /* rectB fully contained in rectA */
aschiffler@6757
   720
    refRectB.x = 0;
aschiffler@6757
   721
    refRectB.y = 0;
aschiffler@6757
   722
    refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
aschiffler@6757
   723
    refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
aschiffler@6757
   724
    rectA = refRectA;
aschiffler@6757
   725
    rectB = refRectB;
aschiffler@6757
   726
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   727
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   728
slouken@7191
   729
    return TEST_COMPLETED;
aschiffler@6757
   730
}
aschiffler@6757
   731
gabomdq@7678
   732
/* !
aschiffler@6757
   733
 * \brief Tests SDL_HasIntersection() with B fully outside A
aschiffler@6757
   734
 *
aschiffler@6757
   735
 * \sa
aschiffler@6757
   736
 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
aschiffler@6757
   737
 */
aschiffler@6757
   738
int rect_testHasIntersectionOutside (void *arg)
aschiffler@6757
   739
{
aschiffler@6757
   740
    SDL_Rect refRectA = { 0, 0, 32, 32 };
aschiffler@6757
   741
    SDL_Rect refRectB;
aschiffler@6757
   742
    SDL_Rect rectA;
aschiffler@6757
   743
    SDL_Rect rectB;
aschiffler@6757
   744
    SDL_bool intersection;
aschiffler@6757
   745
gabomdq@7663
   746
    /* rectB fully outside of rectA */
aschiffler@6757
   747
    refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
aschiffler@6757
   748
    refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
aschiffler@6757
   749
    refRectB.w = refRectA.w;
aschiffler@6757
   750
    refRectB.h = refRectA.h;
aschiffler@6757
   751
    rectA = refRectA;
aschiffler@6757
   752
    rectB = refRectB;
aschiffler@6757
   753
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   754
    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   755
slouken@7191
   756
    return TEST_COMPLETED;
aschiffler@6757
   757
}
aschiffler@6757
   758
gabomdq@7678
   759
/* !
aschiffler@6757
   760
 * \brief Tests SDL_HasIntersection() with B partially intersecting A
aschiffler@6757
   761
 *
aschiffler@6757
   762
 * \sa
aschiffler@6757
   763
 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
aschiffler@6757
   764
 */
aschiffler@6757
   765
int rect_testHasIntersectionPartial (void *arg)
aschiffler@6757
   766
{
aschiffler@6757
   767
    SDL_Rect refRectA = { 0, 0, 32, 32 };
aschiffler@6757
   768
    SDL_Rect refRectB;
aschiffler@6757
   769
    SDL_Rect rectA;
aschiffler@6757
   770
    SDL_Rect rectB;
aschiffler@6757
   771
    SDL_bool intersection;
aschiffler@6757
   772
gabomdq@7663
   773
    /* rectB partially contained in rectA */
aschiffler@6757
   774
    refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
aschiffler@6757
   775
    refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
aschiffler@6757
   776
    refRectB.w = refRectA.w;
aschiffler@6757
   777
    refRectB.h = refRectA.h;
aschiffler@6757
   778
    rectA = refRectA;
aschiffler@6757
   779
    rectB = refRectB;
aschiffler@6757
   780
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   781
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   782
gabomdq@7663
   783
    /* rectB right edge */
aschiffler@6757
   784
    refRectB.x = rectA.w - 1;
aschiffler@6757
   785
    refRectB.y = rectA.y;
aschiffler@6757
   786
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
aschiffler@6757
   787
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
aschiffler@6757
   788
    rectA = refRectA;
aschiffler@6757
   789
    rectB = refRectB;
aschiffler@6757
   790
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   791
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   792
gabomdq@7663
   793
    /* rectB left edge */
aschiffler@6757
   794
    refRectB.x = 1 - rectA.w;
aschiffler@6757
   795
    refRectB.y = rectA.y;
aschiffler@6757
   796
    refRectB.w = refRectA.w;
aschiffler@6757
   797
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
aschiffler@6757
   798
    rectA = refRectA;
aschiffler@6757
   799
    rectB = refRectB;
aschiffler@6757
   800
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   801
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   802
gabomdq@7663
   803
    /* rectB bottom edge */
aschiffler@6757
   804
    refRectB.x = rectA.x;
aschiffler@6757
   805
    refRectB.y = rectA.h - 1;
aschiffler@6757
   806
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
aschiffler@6757
   807
    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
aschiffler@6757
   808
    rectA = refRectA;
aschiffler@6757
   809
    rectB = refRectB;
aschiffler@6757
   810
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   811
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   812
gabomdq@7663
   813
    /* rectB top edge */
aschiffler@6757
   814
    refRectB.x = rectA.x;
aschiffler@6757
   815
    refRectB.y = 1 - rectA.h;
aschiffler@6757
   816
    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
aschiffler@6757
   817
    refRectB.h = rectA.h;
aschiffler@6757
   818
    rectA = refRectA;
aschiffler@6757
   819
    rectB = refRectB;
aschiffler@6757
   820
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   821
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   822
slouken@7191
   823
    return TEST_COMPLETED;
aschiffler@6757
   824
}
aschiffler@6757
   825
gabomdq@7678
   826
/* !
aschiffler@6757
   827
 * \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
aschiffler@6757
   828
 *
aschiffler@6757
   829
 * \sa
aschiffler@6757
   830
 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
aschiffler@6757
   831
 */
aschiffler@6757
   832
int rect_testHasIntersectionPoint (void *arg)
aschiffler@6757
   833
{
aschiffler@6757
   834
    SDL_Rect refRectA = { 0, 0, 1, 1 };
aschiffler@6757
   835
    SDL_Rect refRectB = { 0, 0, 1, 1 };
aschiffler@6757
   836
    SDL_Rect rectA;
aschiffler@6757
   837
    SDL_Rect rectB;
aschiffler@6757
   838
    SDL_bool intersection;
aschiffler@6757
   839
    int offsetX, offsetY;
aschiffler@6757
   840
gabomdq@7663
   841
    /* intersecting pixels */
aschiffler@6757
   842
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   843
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   844
    refRectB.x = refRectA.x;
aschiffler@6757
   845
    refRectB.y = refRectA.y;
aschiffler@6757
   846
    rectA = refRectA;
aschiffler@6757
   847
    rectB = refRectB;
aschiffler@6757
   848
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   849
    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   850
gabomdq@7663
   851
    /* non-intersecting pixels cases */
aschiffler@6757
   852
    for (offsetX = -1; offsetX <= 1; offsetX++) {
aschiffler@6757
   853
        for (offsetY = -1; offsetY <= 1; offsetY++) {
aschiffler@6757
   854
            if (offsetX != 0 || offsetY != 0) {
aschiffler@6757
   855
                refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   856
                refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   857
                refRectB.x = refRectA.x;
slouken@7191
   858
                refRectB.y = refRectA.y;
aschiffler@6757
   859
                refRectB.x += offsetX;
aschiffler@6757
   860
                refRectB.y += offsetY;
aschiffler@6757
   861
                rectA = refRectA;
aschiffler@6757
   862
                rectB = refRectB;
aschiffler@6757
   863
                intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   864
                _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   865
            }
aschiffler@6757
   866
        }
aschiffler@6757
   867
    }
aschiffler@6757
   868
slouken@7191
   869
    return TEST_COMPLETED;
aschiffler@6757
   870
}
aschiffler@6757
   871
gabomdq@7678
   872
/* !
aschiffler@6757
   873
 * \brief Tests SDL_HasIntersection() with empty rectangles
aschiffler@6757
   874
 *
aschiffler@6757
   875
 * \sa
aschiffler@6757
   876
 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
aschiffler@6757
   877
 */
aschiffler@6757
   878
int rect_testHasIntersectionEmpty (void *arg)
aschiffler@6757
   879
{
aschiffler@6757
   880
    SDL_Rect refRectA;
aschiffler@6757
   881
    SDL_Rect refRectB;
aschiffler@6757
   882
    SDL_Rect rectA;
aschiffler@6757
   883
    SDL_Rect rectB;
aschiffler@6757
   884
    SDL_bool intersection;
aschiffler@6757
   885
gabomdq@7663
   886
    /* Rect A empty */
aschiffler@6757
   887
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   888
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   889
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   890
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   891
    refRectB = refRectA;
aschiffler@6757
   892
    refRectA.w = 0;
aschiffler@6757
   893
    refRectA.h = 0;
aschiffler@6757
   894
    rectA = refRectA;
aschiffler@6757
   895
    rectB = refRectB;
aschiffler@6757
   896
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   897
    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   898
gabomdq@7663
   899
    /* Rect B empty */
aschiffler@6757
   900
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   901
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   902
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   903
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   904
    refRectB = refRectA;
aschiffler@6757
   905
    refRectB.w = 0;
aschiffler@6757
   906
    refRectB.h = 0;
aschiffler@6757
   907
    rectA = refRectA;
aschiffler@6757
   908
    rectB = refRectB;
aschiffler@6757
   909
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   910
    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   911
gabomdq@7663
   912
    /* Rect A and B empty */
aschiffler@6757
   913
    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   914
    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   915
    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   916
    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
aschiffler@6757
   917
    refRectB = refRectA;
aschiffler@6757
   918
    refRectA.w = 0;
aschiffler@6757
   919
    refRectA.h = 0;
aschiffler@6757
   920
    refRectB.w = 0;
aschiffler@6757
   921
    refRectB.h = 0;
aschiffler@6757
   922
    rectA = refRectA;
aschiffler@6757
   923
    rectB = refRectB;
aschiffler@6757
   924
    intersection = SDL_HasIntersection(&rectA, &rectB);
aschiffler@6757
   925
    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
   926
slouken@7191
   927
    return TEST_COMPLETED;
aschiffler@6757
   928
}
aschiffler@6757
   929
gabomdq@7678
   930
/* !
aschiffler@6757
   931
 * \brief Negative tests against SDL_HasIntersection() with invalid parameters
aschiffler@6757
   932
 *
aschiffler@6757
   933
 * \sa
aschiffler@6757
   934
 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
aschiffler@6757
   935
 */
aschiffler@6757
   936
int rect_testHasIntersectionParam(void *arg)
aschiffler@6757
   937
{
aschiffler@6757
   938
    SDL_Rect rectA;
aschiffler@6757
   939
    SDL_Rect rectB;
aschiffler@6757
   940
    SDL_bool intersection;
aschiffler@6757
   941
gabomdq@7663
   942
    /* invalid parameter combinations */
aschiffler@6757
   943
    intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
slouken@7191
   944
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
aschiffler@6757
   945
    intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
slouken@7191
   946
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
aschiffler@6757
   947
    intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
slouken@7191
   948
    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
aschiffler@6757
   949
slouken@7191
   950
    return TEST_COMPLETED;
aschiffler@6757
   951
}
aschiffler@6757
   952
gabomdq@7678
   953
/* !
aschiffler@6757
   954
 * \brief Test SDL_EnclosePoints() without clipping
aschiffler@6757
   955
 *
aschiffler@6757
   956
 * \sa
aschiffler@6757
   957
 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
aschiffler@6757
   958
 */
aschiffler@6757
   959
int rect_testEnclosePoints(void *arg)
aschiffler@6757
   960
{
aschiffler@6757
   961
    const int numPoints = 16;
aschiffler@6757
   962
    SDL_Point refPoints[16];
aschiffler@6757
   963
    SDL_Point points[16];
aschiffler@6757
   964
    SDL_Rect result;
aschiffler@6757
   965
    SDL_bool anyEnclosed;
aschiffler@6757
   966
    SDL_bool anyEnclosedNoResult;
aschiffler@6772
   967
    SDL_bool expectedEnclosed = SDL_TRUE;
aschiffler@6772
   968
    int newx, newy;
aschiffler@6772
   969
    int minx = 0, maxx = 0, miny = 0, maxy = 0;
aschiffler@6772
   970
    int i;
aschiffler@6757
   971
gabomdq@7663
   972
    /* Create input data, tracking result */
aschiffler@6757
   973
    for (i=0; i<numPoints; i++) {
aschiffler@6757
   974
        newx = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
   975
        newy = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
   976
        refPoints[i].x = newx;
aschiffler@6757
   977
        refPoints[i].y = newy;
aschiffler@6757
   978
        points[i].x = newx;
aschiffler@6757
   979
        points[i].y = newy;
aschiffler@6757
   980
        if (i==0) {
aschiffler@6772
   981
            minx = newx;
aschiffler@6772
   982
            maxx = newx;
aschiffler@6772
   983
            miny = newy;
aschiffler@6772
   984
            maxy = newy;
aschiffler@6757
   985
        } else {
aschiffler@6772
   986
            if (newx < minx) minx = newx;
aschiffler@6772
   987
            if (newx > maxx) maxx = newx;
aschiffler@6772
   988
            if (newy < miny) miny = newy;
aschiffler@6772
   989
            if (newy > maxy) maxy = newy;
aschiffler@6757
   990
        }
aschiffler@6757
   991
    }
slouken@7191
   992
gabomdq@7663
   993
    /* Call function and validate - special case: no result requested */
aschiffler@6757
   994
    anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
slouken@7191
   995
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
slouken@7191
   996
        "Check expected return value %s, got %s",
slouken@7191
   997
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
   998
        (anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
   999
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1000
        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
slouken@7191
  1001
            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
aschiffler@6757
  1002
            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
aschiffler@6757
  1003
    }
aschiffler@6757
  1004
gabomdq@7663
  1005
    /* Call function and validate */
aschiffler@6757
  1006
    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
slouken@7191
  1007
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
slouken@7191
  1008
        "Check return value %s, got %s",
slouken@7191
  1009
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
  1010
        (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
  1011
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1012
        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
slouken@7191
  1013
            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
aschiffler@6757
  1014
            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
aschiffler@6757
  1015
    }
aschiffler@6757
  1016
    SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
aschiffler@6757
  1017
        "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
aschiffler@6757
  1018
        minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
aschiffler@6757
  1019
slouken@7191
  1020
    return TEST_COMPLETED;
aschiffler@6757
  1021
}
aschiffler@6757
  1022
gabomdq@7678
  1023
/* !
aschiffler@6757
  1024
 * \brief Test SDL_EnclosePoints() with repeated input points
aschiffler@6757
  1025
 *
aschiffler@6757
  1026
 * \sa
aschiffler@6757
  1027
 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
aschiffler@6757
  1028
 */
aschiffler@6757
  1029
int rect_testEnclosePointsRepeatedInput(void *arg)
aschiffler@6757
  1030
{
aschiffler@6757
  1031
    const int numPoints = 8;
aschiffler@6757
  1032
    const int halfPoints = 4;
aschiffler@6757
  1033
    SDL_Point refPoints[8];
aschiffler@6757
  1034
    SDL_Point points[8];
aschiffler@6757
  1035
    SDL_Rect result;
aschiffler@6757
  1036
    SDL_bool anyEnclosed;
aschiffler@6757
  1037
    SDL_bool anyEnclosedNoResult;
aschiffler@6772
  1038
    SDL_bool expectedEnclosed = SDL_TRUE;
aschiffler@6772
  1039
    int newx, newy;
aschiffler@6772
  1040
    int minx = 0, maxx = 0, miny = 0, maxy = 0;
aschiffler@6772
  1041
    int i;
aschiffler@6757
  1042
gabomdq@7663
  1043
    /* Create input data, tracking result */
aschiffler@6757
  1044
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1045
        if (i < halfPoints) {
aschiffler@6757
  1046
            newx = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1047
            newy = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1048
        } else {
aschiffler@6757
  1049
            newx = refPoints[i-halfPoints].x;
aschiffler@6757
  1050
            newy = refPoints[i-halfPoints].y;
aschiffler@6757
  1051
        }
aschiffler@6757
  1052
        refPoints[i].x = newx;
aschiffler@6757
  1053
        refPoints[i].y = newy;
aschiffler@6757
  1054
        points[i].x = newx;
aschiffler@6757
  1055
        points[i].y = newy;
aschiffler@6757
  1056
        if (i==0) {
aschiffler@6772
  1057
            minx = newx;
aschiffler@6772
  1058
            maxx = newx;
aschiffler@6772
  1059
            miny = newy;
aschiffler@6772
  1060
            maxy = newy;
aschiffler@6757
  1061
        } else {
aschiffler@6772
  1062
            if (newx < minx) minx = newx;
aschiffler@6772
  1063
            if (newx > maxx) maxx = newx;
aschiffler@6772
  1064
            if (newy < miny) miny = newy;
aschiffler@6772
  1065
            if (newy > maxy) maxy = newy;
aschiffler@6757
  1066
        }
aschiffler@6757
  1067
    }
aschiffler@6757
  1068
gabomdq@7663
  1069
    /* Call function and validate - special case: no result requested */
aschiffler@6757
  1070
    anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
slouken@7191
  1071
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
slouken@7191
  1072
        "Check return value %s, got %s",
slouken@7191
  1073
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
  1074
        (anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
  1075
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1076
        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
slouken@7191
  1077
            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
aschiffler@6757
  1078
            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
aschiffler@6757
  1079
    }
slouken@7191
  1080
gabomdq@7663
  1081
    /* Call function and validate */
aschiffler@6757
  1082
    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
slouken@7191
  1083
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
slouken@7191
  1084
        "Check return value %s, got %s",
slouken@7191
  1085
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
  1086
        (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
  1087
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1088
        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
slouken@7191
  1089
            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
aschiffler@6757
  1090
            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
aschiffler@6757
  1091
    }
aschiffler@6757
  1092
    SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
aschiffler@6757
  1093
        "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
aschiffler@6757
  1094
        minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
aschiffler@6757
  1095
slouken@7191
  1096
    return TEST_COMPLETED;
aschiffler@6757
  1097
}
aschiffler@6757
  1098
gabomdq@7678
  1099
/* !
aschiffler@6757
  1100
 * \brief Test SDL_EnclosePoints() with clipping
aschiffler@6757
  1101
 *
aschiffler@6757
  1102
 * \sa
aschiffler@6757
  1103
 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
aschiffler@6757
  1104
 */
aschiffler@6757
  1105
int rect_testEnclosePointsWithClipping(void *arg)
aschiffler@6757
  1106
{
aschiffler@6757
  1107
    const int numPoints = 16;
aschiffler@6757
  1108
    SDL_Point refPoints[16];
aschiffler@6757
  1109
    SDL_Point points[16];
aschiffler@6757
  1110
    SDL_Rect refClip;
aschiffler@6757
  1111
    SDL_Rect clip;
aschiffler@6757
  1112
    SDL_Rect result;
aschiffler@6757
  1113
    SDL_bool anyEnclosed;
aschiffler@6757
  1114
    SDL_bool anyEnclosedNoResult;
aschiffler@6757
  1115
    SDL_bool expectedEnclosed = SDL_FALSE;
aschiffler@6757
  1116
    int newx, newy;
aschiffler@6772
  1117
    int minx = 0, maxx = 0, miny = 0, maxy = 0;
aschiffler@6757
  1118
    int i;
aschiffler@6757
  1119
gabomdq@7663
  1120
    /* Setup clipping rectangle */
aschiffler@6757
  1121
    refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1122
    refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1123
    refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1124
    refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1125
gabomdq@7663
  1126
    /* Create input data, tracking result */
aschiffler@6757
  1127
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1128
        newx = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1129
        newy = SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1130
        refPoints[i].x = newx;
aschiffler@6757
  1131
        refPoints[i].y = newy;
aschiffler@6757
  1132
        points[i].x = newx;
aschiffler@6757
  1133
        points[i].y = newy;
aschiffler@6757
  1134
        if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
aschiffler@6757
  1135
            (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
aschiffler@6757
  1136
            if (expectedEnclosed==SDL_FALSE) {
aschiffler@6772
  1137
                minx = newx;
aschiffler@6772
  1138
                maxx = newx;
aschiffler@6772
  1139
                miny = newy;
aschiffler@6772
  1140
                maxy = newy;
aschiffler@6757
  1141
            } else {
aschiffler@6772
  1142
                if (newx < minx) minx = newx;
aschiffler@6772
  1143
                if (newx > maxx) maxx = newx;
aschiffler@6772
  1144
                if (newy < miny) miny = newy;
aschiffler@6772
  1145
                if (newy > maxy) maxy = newy;
aschiffler@6757
  1146
            }
aschiffler@6757
  1147
            expectedEnclosed = SDL_TRUE;
aschiffler@6757
  1148
        }
aschiffler@6757
  1149
    }
aschiffler@6757
  1150
gabomdq@7663
  1151
    /* Call function and validate - special case: no result requested */
aschiffler@6757
  1152
    clip = refClip;
aschiffler@6757
  1153
    anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
slouken@7191
  1154
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
slouken@7191
  1155
        "Expected return value %s, got %s",
slouken@7191
  1156
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
  1157
        (anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
  1158
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1159
        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
slouken@7191
  1160
            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
aschiffler@6757
  1161
            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
aschiffler@6757
  1162
    }
aschiffler@6757
  1163
    SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
aschiffler@6757
  1164
        "Check that source clipping rectangle was not modified");
slouken@7191
  1165
gabomdq@7663
  1166
    /* Call function and validate */
aschiffler@6757
  1167
    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
slouken@7191
  1168
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
slouken@7191
  1169
        "Check return value %s, got %s",
slouken@7191
  1170
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
  1171
        (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
  1172
    for (i=0; i<numPoints; i++) {
aschiffler@6757
  1173
        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
slouken@7191
  1174
            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
aschiffler@6757
  1175
            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
aschiffler@6757
  1176
    }
aschiffler@6757
  1177
    SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
aschiffler@6757
  1178
        "Check that source clipping rectangle was not modified");
aschiffler@6757
  1179
    if (expectedEnclosed==SDL_TRUE) {
aschiffler@6757
  1180
        SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
aschiffler@6757
  1181
            "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
aschiffler@6757
  1182
            minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
slouken@7191
  1183
    }
slouken@7191
  1184
aschiffler@6757
  1185
    /* Empty clipping rectangle */
aschiffler@6757
  1186
    clip.w = 0;
aschiffler@6757
  1187
    clip.h = 0;
aschiffler@6757
  1188
    expectedEnclosed = SDL_FALSE;
aschiffler@6757
  1189
    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
slouken@7191
  1190
    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
slouken@7191
  1191
        "Check return value %s, got %s",
slouken@7191
  1192
        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
slouken@7191
  1193
        (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
aschiffler@6757
  1194
slouken@7191
  1195
    return TEST_COMPLETED;
aschiffler@6757
  1196
}
aschiffler@6757
  1197
gabomdq@7678
  1198
/* !
aschiffler@6757
  1199
 * \brief Negative tests against SDL_EnclosePoints() with invalid parameters
aschiffler@6757
  1200
 *
aschiffler@6757
  1201
 * \sa
aschiffler@6757
  1202
 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
aschiffler@6757
  1203
 */
aschiffler@6757
  1204
int rect_testEnclosePointsParam(void *arg)
aschiffler@6757
  1205
{
aschiffler@6757
  1206
    SDL_Point points[1];
aschiffler@6757
  1207
    int count;
aschiffler@6757
  1208
    SDL_Rect clip;
aschiffler@6757
  1209
    SDL_Rect result;
aschiffler@6757
  1210
    SDL_bool anyEnclosed;
aschiffler@6757
  1211
gabomdq@7663
  1212
    /* invalid parameter combinations */
aschiffler@6757
  1213
    anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
slouken@7191
  1214
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL");
aschiffler@6757
  1215
    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
aschiffler@6757
  1216
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is 0");
aschiffler@6757
  1217
    count = SDLTest_RandomIntegerInRange(-100, -1);
aschiffler@6757
  1218
    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, count, (const SDL_Rect *)&clip, &result);
slouken@7191
  1219
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is %i (negative)", count);
aschiffler@6757
  1220
    anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 0, (const SDL_Rect *)&clip, &result);
slouken@7191
  1221
    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL and 2nd parameter was 0");
aschiffler@6757
  1222
slouken@7191
  1223
    return TEST_COMPLETED;
aschiffler@6757
  1224
}
aschiffler@6757
  1225
gabomdq@7678
  1226
/* !
aschiffler@6757
  1227
 * \brief Tests SDL_UnionRect() where rect B is outside rect A
aschiffler@6757
  1228
 *
aschiffler@6757
  1229
 * \sa
aschiffler@6757
  1230
 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
aschiffler@6757
  1231
 */
aschiffler@6757
  1232
int rect_testUnionRectOutside(void *arg)
aschiffler@6757
  1233
{
aschiffler@6757
  1234
    SDL_Rect refRectA, refRectB;
aschiffler@6757
  1235
    SDL_Rect rectA, rectB;
aschiffler@6757
  1236
    SDL_Rect expectedResult;
aschiffler@6757
  1237
    SDL_Rect result;
aschiffler@6757
  1238
    int minx, maxx, miny, maxy;
aschiffler@6757
  1239
    int dx, dy;
slouken@7191
  1240
aschiffler@6757
  1241
    /* Union 1x1 outside */
slouken@7191
  1242
    for (dx = -1; dx < 2; dx++) {
aschiffler@6757
  1243
        for (dy = -1; dy < 2; dy++) {
aschiffler@6757
  1244
            if ((dx != 0) || (dy != 0)) {
aschiffler@6757
  1245
                refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1246
                refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1247
                refRectA.w=1;
aschiffler@6757
  1248
                refRectA.h=1;
aschiffler@6757
  1249
                refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
aschiffler@6757
  1250
                refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
aschiffler@6757
  1251
                refRectB.w=1;
aschiffler@6757
  1252
                refRectB.h=1;
aschiffler@6757
  1253
                minx = (refRectA.x<refRectB.x) ? refRectA.x : refRectB.x;
aschiffler@6757
  1254
                maxx = (refRectA.x>refRectB.x) ? refRectA.x : refRectB.x;
aschiffler@6757
  1255
                miny = (refRectA.y<refRectB.y) ? refRectA.y : refRectB.y;
slouken@7191
  1256
                maxy = (refRectA.y>refRectB.y) ? refRectA.y : refRectB.y;
aschiffler@6757
  1257
                expectedResult.x = minx;
aschiffler@6757
  1258
                expectedResult.y = miny;
aschiffler@6757
  1259
                expectedResult.w = maxx - minx + 1;
aschiffler@6757
  1260
                expectedResult.h = maxy - miny + 1;
aschiffler@6757
  1261
                rectA = refRectA;
aschiffler@6757
  1262
                rectB = refRectB;
aschiffler@6757
  1263
                SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1264
                _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
  1265
            }
aschiffler@6757
  1266
        }
aschiffler@6757
  1267
    }
aschiffler@6757
  1268
aschiffler@6757
  1269
    /* Union outside overlap */
slouken@7191
  1270
    for (dx = -1; dx < 2; dx++) {
aschiffler@6757
  1271
        for (dy = -1; dy < 2; dy++) {
aschiffler@6757
  1272
            if ((dx != 0) || (dy != 0)) {
aschiffler@6757
  1273
                refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1274
                refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1275
                refRectA.w=SDLTest_RandomIntegerInRange(256, 512);
aschiffler@6757
  1276
                refRectA.h=SDLTest_RandomIntegerInRange(256, 512);
aschiffler@6757
  1277
                refRectB.x=refRectA.x + 1 + dx*2;
aschiffler@6757
  1278
                refRectB.y=refRectA.y + 1 + dy*2;
aschiffler@6757
  1279
                refRectB.w=refRectA.w - 2;
aschiffler@6757
  1280
                refRectB.h=refRectA.h - 2;
aschiffler@6757
  1281
                expectedResult = refRectA;
aschiffler@6757
  1282
                if (dx == -1) expectedResult.x--;
aschiffler@6757
  1283
                if (dy == -1) expectedResult.y--;
aschiffler@6757
  1284
                if ((dx == 1) || (dx == -1)) expectedResult.w++;
aschiffler@6757
  1285
                if ((dy == 1) || (dy == -1)) expectedResult.h++;
aschiffler@6757
  1286
                rectA = refRectA;
aschiffler@6757
  1287
                rectB = refRectB;
aschiffler@6757
  1288
                SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1289
                _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
  1290
            }
aschiffler@6757
  1291
        }
aschiffler@6757
  1292
    }
aschiffler@6757
  1293
slouken@7191
  1294
    return TEST_COMPLETED;
aschiffler@6757
  1295
}
aschiffler@6757
  1296
gabomdq@7678
  1297
/* !
aschiffler@6757
  1298
 * \brief Tests SDL_UnionRect() where rect A or rect B are empty
aschiffler@6757
  1299
 *
aschiffler@6757
  1300
 * \sa
aschiffler@6757
  1301
 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
aschiffler@6757
  1302
 */
aschiffler@6757
  1303
int rect_testUnionRectEmpty(void *arg)
aschiffler@6757
  1304
{
aschiffler@6757
  1305
    SDL_Rect refRectA, refRectB;
aschiffler@6757
  1306
    SDL_Rect rectA, rectB;
aschiffler@6757
  1307
    SDL_Rect expectedResult;
aschiffler@6757
  1308
    SDL_Rect result;
aschiffler@6757
  1309
slouken@7191
  1310
    /* A empty */
aschiffler@6757
  1311
    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1312
    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1313
    refRectA.w=0;
aschiffler@6757
  1314
    refRectA.h=0;
aschiffler@6757
  1315
    refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1316
    refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1317
    refRectB.w=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1318
    refRectB.h=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1319
    expectedResult = refRectB;
aschiffler@6757
  1320
    rectA = refRectA;
aschiffler@6757
  1321
    rectB = refRectB;
aschiffler@6757
  1322
    SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1323
    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
slouken@7191
  1324
slouken@7191
  1325
    /* B empty */
aschiffler@6757
  1326
    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1327
    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1328
    refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1329
    refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1330
    refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1331
    refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1332
    refRectB.w=0;
aschiffler@6757
  1333
    refRectB.h=0;
aschiffler@6757
  1334
    expectedResult = refRectA;
aschiffler@6757
  1335
    rectA = refRectA;
aschiffler@6757
  1336
    rectB = refRectB;
aschiffler@6757
  1337
    SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1338
    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
  1339
slouken@7191
  1340
    /* A and B empty */
aschiffler@6757
  1341
    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1342
    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1343
    refRectA.w=0;
aschiffler@6757
  1344
    refRectA.h=0;
aschiffler@6757
  1345
    refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1346
    refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1347
    refRectB.w=0;
aschiffler@6757
  1348
    refRectB.h=0;
aschiffler@6757
  1349
    result.x=0;
aschiffler@6757
  1350
    result.y=0;
aschiffler@6757
  1351
    result.w=0;
aschiffler@6757
  1352
    result.h=0;
aschiffler@6757
  1353
    expectedResult = result;
aschiffler@6757
  1354
    rectA = refRectA;
aschiffler@6757
  1355
    rectB = refRectB;
aschiffler@6757
  1356
    SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1357
    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
  1358
slouken@7191
  1359
    return TEST_COMPLETED;
aschiffler@6757
  1360
}
aschiffler@6757
  1361
gabomdq@7678
  1362
/* !
aschiffler@6757
  1363
 * \brief Tests SDL_UnionRect() where rect B is inside rect A
aschiffler@6757
  1364
 *
aschiffler@6757
  1365
 * \sa
aschiffler@6757
  1366
 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
aschiffler@6757
  1367
 */
aschiffler@6757
  1368
int rect_testUnionRectInside(void *arg)
aschiffler@6757
  1369
{
aschiffler@6757
  1370
    SDL_Rect refRectA, refRectB;
aschiffler@6757
  1371
    SDL_Rect rectA, rectB;
aschiffler@6757
  1372
    SDL_Rect expectedResult;
aschiffler@6757
  1373
    SDL_Rect result;
aschiffler@6757
  1374
    int dx, dy;
slouken@7191
  1375
aschiffler@6757
  1376
    /* Union 1x1 with itself */
aschiffler@6757
  1377
    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1378
    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1379
    refRectA.w=1;
aschiffler@6757
  1380
    refRectA.h=1;
aschiffler@6757
  1381
    expectedResult = refRectA;
aschiffler@6757
  1382
    rectA = refRectA;
aschiffler@6757
  1383
    SDL_UnionRect(&rectA, &rectA, &result);
aschiffler@6757
  1384
    _validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
aschiffler@6757
  1385
aschiffler@6757
  1386
    /* Union 1x1 somewhere inside */
aschiffler@6757
  1387
    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1388
    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1389
    refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
aschiffler@6757
  1390
    refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
aschiffler@6757
  1391
    refRectB.x=refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2);
aschiffler@6757
  1392
    refRectB.y=refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2);
aschiffler@6757
  1393
    refRectB.w=1;
aschiffler@6757
  1394
    refRectB.h=1;
aschiffler@6757
  1395
    expectedResult = refRectA;
aschiffler@6757
  1396
    rectA = refRectA;
aschiffler@6757
  1397
    rectB = refRectB;
aschiffler@6757
  1398
    SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1399
    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
  1400
aschiffler@6757
  1401
    /* Union inside with edges modified */
slouken@7191
  1402
    for (dx = -1; dx < 2; dx++) {
aschiffler@6757
  1403
        for (dy = -1; dy < 2; dy++) {
aschiffler@6757
  1404
            if ((dx != 0) || (dy != 0)) {
aschiffler@6757
  1405
                refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1406
                refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1407
                refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
aschiffler@6757
  1408
                refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
aschiffler@6757
  1409
                refRectB = refRectA;
aschiffler@6757
  1410
                if (dx == -1) refRectB.x++;
aschiffler@6757
  1411
                if ((dx == 1) || (dx == -1)) refRectB.w--;
aschiffler@6757
  1412
                if (dy == -1) refRectB.y++;
slouken@7191
  1413
                if ((dy == 1) || (dy == -1)) refRectB.h--;
aschiffler@6757
  1414
                expectedResult = refRectA;
aschiffler@6757
  1415
                rectA = refRectA;
aschiffler@6757
  1416
                rectB = refRectB;
aschiffler@6757
  1417
                SDL_UnionRect(&rectA, &rectB, &result);
aschiffler@6757
  1418
                _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
aschiffler@6757
  1419
            }
aschiffler@6757
  1420
        }
aschiffler@6757
  1421
    }
aschiffler@6757
  1422
slouken@7191
  1423
    return TEST_COMPLETED;
aschiffler@6757
  1424
}
aschiffler@6757
  1425
gabomdq@7678
  1426
/* !
aschiffler@6757
  1427
 * \brief Negative tests against SDL_UnionRect() with invalid parameters
aschiffler@6757
  1428
 *
aschiffler@6757
  1429
 * \sa
aschiffler@6757
  1430
 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
aschiffler@6757
  1431
 */
aschiffler@6757
  1432
int rect_testUnionRectParam(void *arg)
aschiffler@6757
  1433
{
aschiffler@6757
  1434
    SDL_Rect rectA, rectB;
aschiffler@6757
  1435
    SDL_Rect result;
aschiffler@6757
  1436
gabomdq@7663
  1437
    /* invalid parameter combinations */
aschiffler@6757
  1438
    SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
slouken@7191
  1439
    SDLTest_AssertPass("Check that function returns when 1st parameter is NULL");
aschiffler@6757
  1440
    SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
slouken@7191
  1441
    SDLTest_AssertPass("Check that function returns  when 2nd parameter is NULL");
aschiffler@6757
  1442
    SDL_UnionRect(&rectA, &rectB, (SDL_Rect *)NULL);
slouken@7191
  1443
    SDLTest_AssertPass("Check that function returns  when 3rd parameter is NULL");
aschiffler@6757
  1444
    SDL_UnionRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
slouken@7191
  1445
    SDLTest_AssertPass("Check that function returns  when 1st and 3rd parameter are NULL");
aschiffler@6757
  1446
    SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
slouken@7191
  1447
    SDLTest_AssertPass("Check that function returns  when 2nd and 3rd parameter are NULL");
aschiffler@6757
  1448
    SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
slouken@7191
  1449
    SDLTest_AssertPass("Check that function returns  when all parameters are NULL");
aschiffler@6757
  1450
slouken@7191
  1451
    return TEST_COMPLETED;
aschiffler@6757
  1452
}
aschiffler@6757
  1453
gabomdq@7678
  1454
/* !
aschiffler@6757
  1455
 * \brief Tests SDL_RectEmpty() with various inputs
aschiffler@6757
  1456
 *
aschiffler@6757
  1457
 * \sa
aschiffler@6757
  1458
 * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
aschiffler@6757
  1459
 */
aschiffler@6757
  1460
int rect_testRectEmpty(void *arg)
aschiffler@6757
  1461
{
aschiffler@6757
  1462
    SDL_Rect refRect;
aschiffler@6757
  1463
    SDL_Rect rect;
aschiffler@6757
  1464
    SDL_bool expectedResult;
aschiffler@6757
  1465
    SDL_bool result;
aschiffler@6757
  1466
    int w, h;
aschiffler@6757
  1467
gabomdq@7663
  1468
    /* Non-empty case */
aschiffler@6757
  1469
    refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1470
    refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1471
    refRect.w=SDLTest_RandomIntegerInRange(256, 1024);
aschiffler@6757
  1472
    refRect.h=SDLTest_RandomIntegerInRange(256, 1024);
aschiffler@6757
  1473
    expectedResult = SDL_FALSE;
aschiffler@6757
  1474
    rect = refRect;
aschiffler@6757
  1475
    result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
aschiffler@6757
  1476
    _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
slouken@7191
  1477
gabomdq@7663
  1478
    /* Empty case */
aschiffler@6757
  1479
    for (w=-1; w<2; w++) {
aschiffler@6757
  1480
        for (h=-1; h<2; h++) {
aschiffler@6757
  1481
            if ((w != 1) || (h != 1)) {
aschiffler@6757
  1482
                refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1483
                refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1484
                refRect.w=w;
aschiffler@6757
  1485
                refRect.h=h;
aschiffler@6757
  1486
                expectedResult = SDL_TRUE;
aschiffler@6757
  1487
                rect = refRect;
aschiffler@6757
  1488
                result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
aschiffler@6757
  1489
                _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
aschiffler@6757
  1490
            }
aschiffler@6757
  1491
        }
aschiffler@6757
  1492
    }
aschiffler@6757
  1493
slouken@7191
  1494
    return TEST_COMPLETED;
aschiffler@6757
  1495
}
aschiffler@6757
  1496
gabomdq@7678
  1497
/* !
aschiffler@6757
  1498
 * \brief Negative tests against SDL_RectEmpty() with invalid parameters
aschiffler@6757
  1499
 *
aschiffler@6757
  1500
 * \sa
aschiffler@6757
  1501
 * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
aschiffler@6757
  1502
 */
aschiffler@6757
  1503
int rect_testRectEmptyParam(void *arg)
aschiffler@6757
  1504
{
aschiffler@6757
  1505
    SDL_bool result;
aschiffler@6757
  1506
gabomdq@7663
  1507
    /* invalid parameter combinations */
aschiffler@6757
  1508
    result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)NULL);
slouken@7191
  1509
    SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL");
aschiffler@6757
  1510
slouken@7191
  1511
    return TEST_COMPLETED;
aschiffler@6757
  1512
}
aschiffler@6757
  1513
gabomdq@7678
  1514
/* !
aschiffler@6757
  1515
 * \brief Tests SDL_RectEquals() with various inputs
aschiffler@6757
  1516
 *
aschiffler@6757
  1517
 * \sa
aschiffler@6757
  1518
 * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
aschiffler@6757
  1519
 */
aschiffler@6757
  1520
int rect_testRectEquals(void *arg)
aschiffler@6757
  1521
{
aschiffler@6757
  1522
    SDL_Rect refRectA;
aschiffler@6757
  1523
    SDL_Rect refRectB;
aschiffler@6757
  1524
    SDL_Rect rectA;
aschiffler@6757
  1525
    SDL_Rect rectB;
aschiffler@6757
  1526
    SDL_bool expectedResult;
aschiffler@6757
  1527
    SDL_bool result;
aschiffler@6757
  1528
gabomdq@7663
  1529
    /* Equals */
aschiffler@6757
  1530
    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1531
    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1532
    refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1533
    refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
slouken@7191
  1534
    refRectB = refRectA;
aschiffler@6757
  1535
    expectedResult = SDL_TRUE;
aschiffler@6757
  1536
    rectA = refRectA;
aschiffler@6757
  1537
    rectB = refRectB;
aschiffler@6757
  1538
    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)&rectB);
aschiffler@6757
  1539
    _validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
aschiffler@6757
  1540
slouken@7191
  1541
    return TEST_COMPLETED;
aschiffler@6757
  1542
}
aschiffler@6757
  1543
gabomdq@7678
  1544
/* !
aschiffler@6757
  1545
 * \brief Negative tests against SDL_RectEquals() with invalid parameters
aschiffler@6757
  1546
 *
aschiffler@6757
  1547
 * \sa
aschiffler@6757
  1548
 * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
aschiffler@6757
  1549
 */
aschiffler@6757
  1550
int rect_testRectEqualsParam(void *arg)
aschiffler@6757
  1551
{
aschiffler@6757
  1552
    SDL_Rect rectA;
aschiffler@6757
  1553
    SDL_Rect rectB;
aschiffler@6757
  1554
    SDL_bool result;
aschiffler@6757
  1555
aschiffler@6757
  1556
    /* data setup */
aschiffler@6757
  1557
    rectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1558
    rectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1559
    rectA.w=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1560
    rectA.h=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1561
    rectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1562
    rectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
aschiffler@6757
  1563
    rectB.w=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1564
    rectB.h=SDLTest_RandomIntegerInRange(1, 1024);
aschiffler@6757
  1565
gabomdq@7663
  1566
    /* invalid parameter combinations */
aschiffler@6757
  1567
    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)&rectB);
slouken@7191
  1568
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
aschiffler@6757
  1569
    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)NULL);
slouken@7191
  1570
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
aschiffler@6757
  1571
    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)NULL);
slouken@7191
  1572
    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
aschiffler@6757
  1573
slouken@7191
  1574
    return TEST_COMPLETED;
aschiffler@6757
  1575
}
aschiffler@6757
  1576
aschiffler@6757
  1577
/* ================= Test References ================== */
aschiffler@6757
  1578
aschiffler@6757
  1579
/* Rect test cases */
aschiffler@6757
  1580
aschiffler@6757
  1581
/* SDL_IntersectRectAndLine */
aschiffler@6757
  1582
static const SDLTest_TestCaseReference rectTest1 =
slouken@7191
  1583
        { (SDLTest_TestCaseFp)rect_testIntersectRectAndLine,"rect_testIntersectRectAndLine",  "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED };
aschiffler@6757
  1584
aschiffler@6757
  1585
static const SDLTest_TestCaseReference rectTest2 =
slouken@7191
  1586
        { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED };
aschiffler@6757
  1587
aschiffler@6757
  1588
static const SDLTest_TestCaseReference rectTest3 =
slouken@7191
  1589
        { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED };
aschiffler@6757
  1590
aschiffler@6757
  1591
static const SDLTest_TestCaseReference rectTest4 =
slouken@7191
  1592
        { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED };
aschiffler@6757
  1593
aschiffler@6757
  1594
static const SDLTest_TestCaseReference rectTest5 =
slouken@7191
  1595
        { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1596
aschiffler@6757
  1597
/* SDL_IntersectRect */
aschiffler@6757
  1598
static const SDLTest_TestCaseReference rectTest6 =
slouken@7191
  1599
        { (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED };
aschiffler@6757
  1600
aschiffler@6757
  1601
static const SDLTest_TestCaseReference rectTest7 =
slouken@7191
  1602
        { (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED };
aschiffler@6757
  1603
aschiffler@6757
  1604
static const SDLTest_TestCaseReference rectTest8 =
slouken@7191
  1605
        { (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED };
aschiffler@6757
  1606
aschiffler@6757
  1607
static const SDLTest_TestCaseReference rectTest9 =
slouken@7191
  1608
        { (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED };
aschiffler@6757
  1609
aschiffler@6757
  1610
static const SDLTest_TestCaseReference rectTest10 =
slouken@7191
  1611
        { (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED };
aschiffler@6757
  1612
aschiffler@6757
  1613
static const SDLTest_TestCaseReference rectTest11 =
slouken@7191
  1614
        { (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1615
aschiffler@6757
  1616
/* SDL_HasIntersection */
aschiffler@6757
  1617
static const SDLTest_TestCaseReference rectTest12 =
slouken@7191
  1618
        { (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED };
aschiffler@6757
  1619
aschiffler@6757
  1620
static const SDLTest_TestCaseReference rectTest13 =
slouken@7191
  1621
        { (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED };
aschiffler@6757
  1622
aschiffler@6757
  1623
static const SDLTest_TestCaseReference rectTest14 =
slouken@7191
  1624
        { (SDLTest_TestCaseFp)rect_testHasIntersectionPartial,"rect_testHasIntersectionPartial",  "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED };
aschiffler@6757
  1625
aschiffler@6757
  1626
static const SDLTest_TestCaseReference rectTest15 =
slouken@7191
  1627
        { (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED };
aschiffler@6757
  1628
aschiffler@6757
  1629
static const SDLTest_TestCaseReference rectTest16 =
slouken@7191
  1630
        { (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED };
aschiffler@6757
  1631
aschiffler@6757
  1632
static const SDLTest_TestCaseReference rectTest17 =
slouken@7191
  1633
        { (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1634
aschiffler@6757
  1635
/* SDL_EnclosePoints */
aschiffler@6757
  1636
static const SDLTest_TestCaseReference rectTest18 =
slouken@7191
  1637
        { (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED };
aschiffler@6757
  1638
aschiffler@6757
  1639
static const SDLTest_TestCaseReference rectTest19 =
slouken@7191
  1640
        { (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED };
aschiffler@6757
  1641
aschiffler@6757
  1642
static const SDLTest_TestCaseReference rectTest20 =
slouken@7191
  1643
        { (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED };
aschiffler@6757
  1644
aschiffler@6757
  1645
static const SDLTest_TestCaseReference rectTest21 =
slouken@7191
  1646
        { (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1647
aschiffler@6757
  1648
/* SDL_UnionRect */
aschiffler@6757
  1649
static const SDLTest_TestCaseReference rectTest22 =
slouken@7191
  1650
        { (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED };
aschiffler@6757
  1651
aschiffler@6757
  1652
static const SDLTest_TestCaseReference rectTest23 =
slouken@7191
  1653
        { (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED };
aschiffler@6757
  1654
aschiffler@6757
  1655
static const SDLTest_TestCaseReference rectTest24 =
slouken@7191
  1656
        { (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED };
aschiffler@6757
  1657
aschiffler@6757
  1658
static const SDLTest_TestCaseReference rectTest25 =
slouken@7191
  1659
        { (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1660
aschiffler@6757
  1661
/* SDL_RectEmpty */
aschiffler@6757
  1662
static const SDLTest_TestCaseReference rectTest26 =
slouken@7191
  1663
        { (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED };
aschiffler@6757
  1664
aschiffler@6757
  1665
static const SDLTest_TestCaseReference rectTest27 =
slouken@7191
  1666
        { (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1667
aschiffler@6757
  1668
/* SDL_RectEquals */
aschiffler@6757
  1669
aschiffler@6757
  1670
static const SDLTest_TestCaseReference rectTest28 =
slouken@7191
  1671
        { (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED };
aschiffler@6757
  1672
aschiffler@6757
  1673
static const SDLTest_TestCaseReference rectTest29 =
slouken@7191
  1674
        { (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
aschiffler@6757
  1675
aschiffler@6757
  1676
gabomdq@7678
  1677
/* !
aschiffler@6757
  1678
 * \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
aschiffler@6757
  1679
 *
aschiffler@6757
  1680
 * \sa
aschiffler@6757
  1681
 * http://wiki.libsdl.org/moin.cgi/CategoryRect
aschiffler@6757
  1682
 */
aschiffler@6757
  1683
static const SDLTest_TestCaseReference *rectTests[] =  {
slouken@7191
  1684
    &rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
slouken@7191
  1685
    &rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
slouken@7191
  1686
    &rectTest28, &rectTest29, NULL
aschiffler@6757
  1687
};
aschiffler@6757
  1688
aschiffler@6757
  1689
aschiffler@6757
  1690
/* Rect test suite (global) */
aschiffler@6757
  1691
SDLTest_TestSuiteReference rectTestSuite = {
slouken@7191
  1692
    "Rect",
slouken@7191
  1693
    NULL,
slouken@7191
  1694
    rectTests,
slouken@7191
  1695
    NULL
aschiffler@6757
  1696
};