| 1 |
/** |
| 2 |
* Mouse test suite |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <limits.h> |
| 7 |
|
| 8 |
#include "SDL.h" |
| 9 |
#include "SDL_test.h" |
| 10 |
|
| 11 |
/* ================= Test Case Implementation ================== */ |
| 12 |
|
| 13 |
/* Test case functions */ |
| 14 |
|
| 15 |
/* Helper to evaluate state returned from SDL_GetMouseState */ |
| 16 |
int _mouseStateCheck(Uint32 state) |
| 17 |
{ |
| 18 |
return (state == 0) || |
| 19 |
(state == SDL_BUTTON(SDL_BUTTON_LEFT)) || |
| 20 |
(state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) || |
| 21 |
(state == SDL_BUTTON(SDL_BUTTON_RIGHT)) || |
| 22 |
(state == SDL_BUTTON(SDL_BUTTON_X1)) || |
| 23 |
(state == SDL_BUTTON(SDL_BUTTON_X2)); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* @brief Check call to SDL_GetMouseState |
| 28 |
* |
| 29 |
*/ |
| 30 |
int mouse_getMouseState(void *arg) |
| 31 |
{ |
| 32 |
int x; |
| 33 |
int y; |
| 34 |
Uint32 state; |
| 35 |
|
| 36 |
/* Pump some events to update mouse state */ |
| 37 |
SDL_PumpEvents(); |
| 38 |
SDLTest_AssertPass("Call to SDL_PumpEvents()"); |
| 39 |
|
| 40 |
/* Case where x, y pointer is NULL */ |
| 41 |
state = SDL_GetMouseState(NULL, NULL); |
| 42 |
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)"); |
| 43 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 44 |
|
| 45 |
/* Case where x pointer is not NULL */ |
| 46 |
x = INT_MIN; |
| 47 |
state = SDL_GetMouseState(&x, NULL); |
| 48 |
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)"); |
| 49 |
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x); |
| 50 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 51 |
|
| 52 |
/* Case where y pointer is not NULL */ |
| 53 |
y = INT_MIN; |
| 54 |
state = SDL_GetMouseState(NULL, &y); |
| 55 |
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)"); |
| 56 |
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y); |
| 57 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 58 |
|
| 59 |
/* Case where x and y pointer is not NULL */ |
| 60 |
x = INT_MIN; |
| 61 |
y = INT_MIN; |
| 62 |
state = SDL_GetMouseState(&x, &y); |
| 63 |
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)"); |
| 64 |
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x); |
| 65 |
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y); |
| 66 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 67 |
|
| 68 |
return TEST_COMPLETED; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* @brief Check call to SDL_GetRelativeMouseState |
| 73 |
* |
| 74 |
*/ |
| 75 |
int mouse_getRelativeMouseState(void *arg) |
| 76 |
{ |
| 77 |
int x; |
| 78 |
int y; |
| 79 |
Uint32 state; |
| 80 |
|
| 81 |
/* Pump some events to update mouse state */ |
| 82 |
SDL_PumpEvents(); |
| 83 |
SDLTest_AssertPass("Call to SDL_PumpEvents()"); |
| 84 |
|
| 85 |
/* Case where x, y pointer is NULL */ |
| 86 |
state = SDL_GetRelativeMouseState(NULL, NULL); |
| 87 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)"); |
| 88 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 89 |
|
| 90 |
/* Case where x pointer is not NULL */ |
| 91 |
x = INT_MIN; |
| 92 |
state = SDL_GetRelativeMouseState(&x, NULL); |
| 93 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)"); |
| 94 |
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x); |
| 95 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 96 |
|
| 97 |
/* Case where y pointer is not NULL */ |
| 98 |
y = INT_MIN; |
| 99 |
state = SDL_GetRelativeMouseState(NULL, &y); |
| 100 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)"); |
| 101 |
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y); |
| 102 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 103 |
|
| 104 |
/* Case where x and y pointer is not NULL */ |
| 105 |
x = INT_MIN; |
| 106 |
y = INT_MIN; |
| 107 |
state = SDL_GetRelativeMouseState(&x, &y); |
| 108 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)"); |
| 109 |
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x); |
| 110 |
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y); |
| 111 |
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state); |
| 112 |
|
| 113 |
return TEST_COMPLETED; |
| 114 |
} |
| 115 |
|
| 116 |
/* XPM definition of mouse Cursor */ |
| 117 |
static const char *_mouseArrowData[] = { |
| 118 |
/* pixels */ |
| 119 |
"X ", |
| 120 |
"XX ", |
| 121 |
"X.X ", |
| 122 |
"X..X ", |
| 123 |
"X...X ", |
| 124 |
"X....X ", |
| 125 |
"X.....X ", |
| 126 |
"X......X ", |
| 127 |
"X.......X ", |
| 128 |
"X........X ", |
| 129 |
"X.....XXXXX ", |
| 130 |
"X..X..X ", |
| 131 |
"X.X X..X ", |
| 132 |
"XX X..X ", |
| 133 |
"X X..X ", |
| 134 |
" X..X ", |
| 135 |
" X..X ", |
| 136 |
" X..X ", |
| 137 |
" XX ", |
| 138 |
" ", |
| 139 |
" ", |
| 140 |
" ", |
| 141 |
" ", |
| 142 |
" ", |
| 143 |
" ", |
| 144 |
" ", |
| 145 |
" ", |
| 146 |
" ", |
| 147 |
" ", |
| 148 |
" ", |
| 149 |
" ", |
| 150 |
" " |
| 151 |
}; |
| 152 |
|
| 153 |
/* Helper that creates a new mouse cursor from an XPM */ |
| 154 |
static SDL_Cursor *_initArrowCursor(const char *image[]) |
| 155 |
{ |
| 156 |
SDL_Cursor *cursor; |
| 157 |
int i, row, col; |
| 158 |
Uint8 data[4 * 32]; |
| 159 |
Uint8 mask[4 * 32]; |
| 160 |
|
| 161 |
i = -1; |
| 162 |
for (row = 0; row < 32; ++row) { |
| 163 |
for (col = 0; col < 32; ++col) { |
| 164 |
if (col % 8) { |
| 165 |
data[i] <<= 1; |
| 166 |
mask[i] <<= 1; |
| 167 |
} else { |
| 168 |
++i; |
| 169 |
data[i] = mask[i] = 0; |
| 170 |
} |
| 171 |
switch (image[row][col]) { |
| 172 |
case 'X': |
| 173 |
data[i] |= 0x01; |
| 174 |
mask[i] |= 0x01; |
| 175 |
break; |
| 176 |
case '.': |
| 177 |
mask[i] |= 0x01; |
| 178 |
break; |
| 179 |
case ' ': |
| 180 |
break; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0); |
| 186 |
return cursor; |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* @brief Check call to SDL_CreateCursor and SDL_FreeCursor |
| 191 |
* |
| 192 |
* @sa http://wiki.libsdl.org/SDL_CreateCursor |
| 193 |
* @sa http://wiki.libsdl.org/SDL_FreeCursor |
| 194 |
*/ |
| 195 |
int mouse_createFreeCursor(void *arg) |
| 196 |
{ |
| 197 |
SDL_Cursor *cursor; |
| 198 |
|
| 199 |
/* Create a cursor */ |
| 200 |
cursor = _initArrowCursor(_mouseArrowData); |
| 201 |
SDLTest_AssertPass("Call to SDL_CreateCursor()"); |
| 202 |
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL"); |
| 203 |
if (cursor == NULL) { |
| 204 |
return TEST_ABORTED; |
| 205 |
} |
| 206 |
|
| 207 |
/* Free cursor again */ |
| 208 |
SDL_FreeCursor(cursor); |
| 209 |
SDLTest_AssertPass("Call to SDL_FreeCursor()"); |
| 210 |
|
| 211 |
return TEST_COMPLETED; |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor |
| 216 |
* |
| 217 |
* @sa http://wiki.libsdl.org/SDL_CreateColorCursor |
| 218 |
* @sa http://wiki.libsdl.org/SDL_FreeCursor |
| 219 |
*/ |
| 220 |
int mouse_createFreeColorCursor(void *arg) |
| 221 |
{ |
| 222 |
SDL_Surface *face; |
| 223 |
SDL_Cursor *cursor; |
| 224 |
|
| 225 |
/* Get sample surface */ |
| 226 |
face = SDLTest_ImageFace(); |
| 227 |
SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL"); |
| 228 |
if (face == NULL) { |
| 229 |
return TEST_ABORTED; |
| 230 |
} |
| 231 |
|
| 232 |
/* Create a color cursor from surface */ |
| 233 |
cursor = SDL_CreateColorCursor(face, 0, 0); |
| 234 |
SDLTest_AssertPass("Call to SDL_CreateColorCursor()"); |
| 235 |
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL"); |
| 236 |
if (cursor == NULL) { |
| 237 |
SDL_FreeSurface(face); |
| 238 |
return TEST_ABORTED; |
| 239 |
} |
| 240 |
|
| 241 |
/* Free cursor again */ |
| 242 |
SDL_FreeCursor(cursor); |
| 243 |
SDLTest_AssertPass("Call to SDL_FreeCursor()"); |
| 244 |
|
| 245 |
/* Clean up */ |
| 246 |
SDL_FreeSurface(face); |
| 247 |
|
| 248 |
return TEST_COMPLETED; |
| 249 |
} |
| 250 |
|
| 251 |
/* Helper that changes cursor visibility */ |
| 252 |
void _changeCursorVisibility(int state) |
| 253 |
{ |
| 254 |
int oldState; |
| 255 |
int newState; |
| 256 |
int result; |
| 257 |
|
| 258 |
oldState = SDL_ShowCursor(SDL_QUERY); |
| 259 |
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); |
| 260 |
|
| 261 |
result = SDL_ShowCursor(state); |
| 262 |
SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE"); |
| 263 |
SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i", |
| 264 |
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result); |
| 265 |
|
| 266 |
newState = SDL_ShowCursor(SDL_QUERY); |
| 267 |
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); |
| 268 |
SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i", |
| 269 |
state, newState); |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* @brief Check call to SDL_ShowCursor |
| 274 |
* |
| 275 |
* @sa http://wiki.libsdl.org/SDL_ShowCursor |
| 276 |
*/ |
| 277 |
int mouse_showCursor(void *arg) |
| 278 |
{ |
| 279 |
int currentState; |
| 280 |
|
| 281 |
/* Get current state */ |
| 282 |
currentState = SDL_ShowCursor(SDL_QUERY); |
| 283 |
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); |
| 284 |
SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE, |
| 285 |
"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState); |
| 286 |
if (currentState == SDL_DISABLE) { |
| 287 |
/* Show the cursor, then hide it again */ |
| 288 |
_changeCursorVisibility(SDL_ENABLE); |
| 289 |
_changeCursorVisibility(SDL_DISABLE); |
| 290 |
} else if (currentState == SDL_ENABLE) { |
| 291 |
/* Hide the cursor, then show it again */ |
| 292 |
_changeCursorVisibility(SDL_DISABLE); |
| 293 |
_changeCursorVisibility(SDL_ENABLE); |
| 294 |
} else { |
| 295 |
return TEST_ABORTED; |
| 296 |
} |
| 297 |
|
| 298 |
return TEST_COMPLETED; |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* @brief Check call to SDL_SetCursor |
| 303 |
* |
| 304 |
* @sa http://wiki.libsdl.org/SDL_SetCursor |
| 305 |
*/ |
| 306 |
int mouse_setCursor(void *arg) |
| 307 |
{ |
| 308 |
SDL_Cursor *cursor; |
| 309 |
|
| 310 |
/* Create a cursor */ |
| 311 |
cursor = _initArrowCursor(_mouseArrowData); |
| 312 |
SDLTest_AssertPass("Call to SDL_CreateCursor()"); |
| 313 |
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL"); |
| 314 |
if (cursor == NULL) { |
| 315 |
return TEST_ABORTED; |
| 316 |
} |
| 317 |
|
| 318 |
/* Set the arrow cursor */ |
| 319 |
SDL_SetCursor(cursor); |
| 320 |
SDLTest_AssertPass("Call to SDL_SetCursor(cursor)"); |
| 321 |
|
| 322 |
/* Force redraw */ |
| 323 |
SDL_SetCursor(NULL); |
| 324 |
SDLTest_AssertPass("Call to SDL_SetCursor(NULL)"); |
| 325 |
|
| 326 |
/* Free cursor again */ |
| 327 |
SDL_FreeCursor(cursor); |
| 328 |
SDLTest_AssertPass("Call to SDL_FreeCursor()"); |
| 329 |
|
| 330 |
return TEST_COMPLETED; |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* @brief Check call to SDL_GetCursor |
| 335 |
* |
| 336 |
* @sa http://wiki.libsdl.org/SDL_GetCursor |
| 337 |
*/ |
| 338 |
int mouse_getCursor(void *arg) |
| 339 |
{ |
| 340 |
SDL_Cursor *cursor; |
| 341 |
|
| 342 |
/* Get current cursor */ |
| 343 |
cursor = SDL_GetCursor(); |
| 344 |
SDLTest_AssertPass("Call to SDL_GetCursor()"); |
| 345 |
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL"); |
| 346 |
|
| 347 |
return TEST_COMPLETED; |
| 348 |
} |
| 349 |
|
| 350 |
/** |
| 351 |
* @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode |
| 352 |
* |
| 353 |
* @sa http://wiki.libsdl.org/SDL_GetRelativeMouseMode |
| 354 |
* @sa http://wiki.libsdl.org/SDL_SetRelativeMouseMode |
| 355 |
*/ |
| 356 |
int mouse_getSetRelativeMouseMode(void *arg) |
| 357 |
{ |
| 358 |
int result; |
| 359 |
int i; |
| 360 |
SDL_bool initialState; |
| 361 |
SDL_bool currentState; |
| 362 |
|
| 363 |
/* Capture original state so we can revert back to it later */ |
| 364 |
initialState = SDL_GetRelativeMouseMode(); |
| 365 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); |
| 366 |
|
| 367 |
/* Repeat twice to check D->D transition */ |
| 368 |
for (i = 0; i < 2; i++) { |
| 369 |
/* Disable - should always be supported */ |
| 370 |
result = SDL_SetRelativeMouseMode(SDL_FALSE); |
| 371 |
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)"); |
| 372 |
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); |
| 373 |
currentState = SDL_GetRelativeMouseMode(); |
| 374 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); |
| 375 |
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); |
| 376 |
} |
| 377 |
|
| 378 |
/* Repeat twice to check D->E->E transition */ |
| 379 |
for (i = 0; i < 2; i++) { |
| 380 |
/* Enable - may not be supported */ |
| 381 |
result = SDL_SetRelativeMouseMode(SDL_TRUE); |
| 382 |
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)"); |
| 383 |
if (result != -1) { |
| 384 |
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); |
| 385 |
currentState = SDL_GetRelativeMouseMode(); |
| 386 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); |
| 387 |
SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
/* Disable to check E->D transition */ |
| 392 |
result = SDL_SetRelativeMouseMode(SDL_FALSE); |
| 393 |
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)"); |
| 394 |
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); |
| 395 |
currentState = SDL_GetRelativeMouseMode(); |
| 396 |
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); |
| 397 |
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); |
| 398 |
|
| 399 |
/* Revert to original state - ignore result */ |
| 400 |
result = SDL_SetRelativeMouseMode(initialState); |
| 401 |
|
| 402 |
return TEST_COMPLETED; |
| 403 |
} |
| 404 |
|
| 405 |
#define MOUSE_TESTWINDOW_WIDTH 320 |
| 406 |
#define MOUSE_TESTWINDOW_HEIGHT 200 |
| 407 |
|
| 408 |
/** |
| 409 |
* Creates a test window |
| 410 |
*/ |
| 411 |
SDL_Window *_createMouseSuiteTestWindow() |
| 412 |
{ |
| 413 |
int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT; |
| 414 |
SDL_Window *window; |
| 415 |
window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0); |
| 416 |
SDLTest_AssertPass("SDL_CreateWindow()"); |
| 417 |
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); |
| 418 |
return window; |
| 419 |
} |
| 420 |
|
| 421 |
/* |
| 422 |
* Destroy test window |
| 423 |
*/ |
| 424 |
void _destroyMouseSuiteTestWindow(SDL_Window *window) |
| 425 |
{ |
| 426 |
if (window) { |
| 427 |
SDL_DestroyWindow(window); |
| 428 |
window = NULL; |
| 429 |
SDLTest_AssertPass("SDL_DestroyWindow()"); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* @brief Check call to SDL_WarpMouseInWindow |
| 435 |
* |
| 436 |
* @sa http://wiki.libsdl.org/SDL_WarpMouseInWindow |
| 437 |
*/ |
| 438 |
int mouse_warpMouseInWindow(void *arg) |
| 439 |
{ |
| 440 |
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT; |
| 441 |
int numPositions = 6; |
| 442 |
int xPositions[6]; |
| 443 |
int yPositions[6]; |
| 444 |
int x, y, i, j; |
| 445 |
SDL_Window *window; |
| 446 |
|
| 447 |
xPositions[0] = -1; |
| 448 |
xPositions[1] = 0; |
| 449 |
xPositions[2] = 1; |
| 450 |
xPositions[3] = w - 1; |
| 451 |
xPositions[4] = w; |
| 452 |
xPositions[5] = w + 1; |
| 453 |
yPositions[0] = -1; |
| 454 |
yPositions[1] = 0; |
| 455 |
yPositions[2] = 1; |
| 456 |
yPositions[3] = h - 1; |
| 457 |
yPositions[4] = h; |
| 458 |
yPositions[5] = h + 1; |
| 459 |
/* Create test window */ |
| 460 |
window = _createMouseSuiteTestWindow(); |
| 461 |
if (!window) { |
| 462 |
return TEST_ABORTED; |
| 463 |
} |
| 464 |
|
| 465 |
/* Mouse to random position inside window */ |
| 466 |
x = SDLTest_RandomIntegerInRange(1, w - 1); |
| 467 |
y = SDLTest_RandomIntegerInRange(1, h - 1); |
| 468 |
SDL_WarpMouseInWindow(window, x, y); |
| 469 |
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); |
| 470 |
|
| 471 |
/* Same position again */ |
| 472 |
SDL_WarpMouseInWindow(window, x, y); |
| 473 |
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); |
| 474 |
|
| 475 |
/* Mouse to various boundary positions */ |
| 476 |
for (i = 0; i < numPositions; i++) { |
| 477 |
for (j = 0; j < numPositions; j++) { |
| 478 |
x = xPositions[i]; |
| 479 |
y = yPositions[j]; |
| 480 |
SDL_WarpMouseInWindow(window, x, y); |
| 481 |
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); |
| 482 |
|
| 483 |
/* TODO: add tracking of events and check that each call generates a mouse motion event */ |
| 484 |
SDL_PumpEvents(); |
| 485 |
SDLTest_AssertPass("SDL_PumpEvents()"); |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
/* Clean up test window */ |
| 490 |
_destroyMouseSuiteTestWindow(window); |
| 491 |
|
| 492 |
return TEST_COMPLETED; |
| 493 |
} |
| 494 |
|
| 495 |
/** |
| 496 |
* @brief Check call to SDL_GetMouseFocus |
| 497 |
* |
| 498 |
* @sa http://wiki.libsdl.org/SDL_GetMouseFocus |
| 499 |
*/ |
| 500 |
int mouse_getMouseFocus(void *arg) |
| 501 |
{ |
| 502 |
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT; |
| 503 |
int x, y; |
| 504 |
SDL_Window *window; |
| 505 |
SDL_Window *focusWindow; |
| 506 |
const SDL_bool video_driver_is_wayland = !SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland"); |
| 507 |
|
| 508 |
/* Get focus - focus non-deterministic */ |
| 509 |
focusWindow = SDL_GetMouseFocus(); |
| 510 |
SDLTest_AssertPass("SDL_GetMouseFocus()"); |
| 511 |
|
| 512 |
/* Create test window */ |
| 513 |
window = _createMouseSuiteTestWindow(); |
| 514 |
if (!window) { |
| 515 |
return TEST_ABORTED; |
| 516 |
} |
| 517 |
|
| 518 |
/* Wayland explicitly disallows warping the mouse pointer, so this test must be skipped. */ |
| 519 |
if (!video_driver_is_wayland) { |
| 520 |
/* Mouse to random position inside window */ |
| 521 |
x = SDLTest_RandomIntegerInRange(1, w - 1); |
| 522 |
y = SDLTest_RandomIntegerInRange(1, h - 1); |
| 523 |
SDL_WarpMouseInWindow(window, x, y); |
| 524 |
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); |
| 525 |
|
| 526 |
/* Pump events to update focus state */ |
| 527 |
SDL_Delay(100); |
| 528 |
SDL_PumpEvents(); |
| 529 |
SDLTest_AssertPass("SDL_PumpEvents()"); |
| 530 |
|
| 531 |
/* Get focus with explicit window setup - focus deterministic */ |
| 532 |
focusWindow = SDL_GetMouseFocus(); |
| 533 |
SDLTest_AssertPass("SDL_GetMouseFocus()"); |
| 534 |
SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL"); |
| 535 |
SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window"); |
| 536 |
|
| 537 |
/* Mouse to random position outside window */ |
| 538 |
x = SDLTest_RandomIntegerInRange(-9, -1); |
| 539 |
y = SDLTest_RandomIntegerInRange(-9, -1); |
| 540 |
SDL_WarpMouseInWindow(window, x, y); |
| 541 |
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); |
| 542 |
} else { |
| 543 |
SDLTest_Log("Skipping mouse warp focus tests: Wayland does not support warping the mouse pointer"); |
| 544 |
} |
| 545 |
|
| 546 |
/* Clean up test window */ |
| 547 |
_destroyMouseSuiteTestWindow(window); |
| 548 |
|
| 549 |
/* Pump events to update focus state */ |
| 550 |
SDL_PumpEvents(); |
| 551 |
SDLTest_AssertPass("SDL_PumpEvents()"); |
| 552 |
|
| 553 |
/* Get focus for non-existing window */ |
| 554 |
focusWindow = SDL_GetMouseFocus(); |
| 555 |
SDLTest_AssertPass("SDL_GetMouseFocus()"); |
| 556 |
SDLTest_AssertCheck(focusWindow == NULL, "Check returned window value is NULL"); |
| 557 |
|
| 558 |
return TEST_COMPLETED; |
| 559 |
} |
| 560 |
|
| 561 |
/* ================= Test References ================== */ |
| 562 |
|
| 563 |
/* Mouse test cases */ |
| 564 |
static const SDLTest_TestCaseReference mouseTest1 = { |
| 565 |
(SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED |
| 566 |
}; |
| 567 |
|
| 568 |
static const SDLTest_TestCaseReference mouseTest2 = { |
| 569 |
(SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED |
| 570 |
}; |
| 571 |
|
| 572 |
static const SDLTest_TestCaseReference mouseTest3 = { |
| 573 |
(SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED |
| 574 |
}; |
| 575 |
|
| 576 |
static const SDLTest_TestCaseReference mouseTest4 = { |
| 577 |
(SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED |
| 578 |
}; |
| 579 |
|
| 580 |
static const SDLTest_TestCaseReference mouseTest5 = { |
| 581 |
(SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED |
| 582 |
}; |
| 583 |
|
| 584 |
static const SDLTest_TestCaseReference mouseTest6 = { |
| 585 |
(SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED |
| 586 |
}; |
| 587 |
|
| 588 |
static const SDLTest_TestCaseReference mouseTest7 = { |
| 589 |
(SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED |
| 590 |
}; |
| 591 |
|
| 592 |
static const SDLTest_TestCaseReference mouseTest8 = { |
| 593 |
(SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED |
| 594 |
}; |
| 595 |
|
| 596 |
static const SDLTest_TestCaseReference mouseTest9 = { |
| 597 |
(SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED |
| 598 |
}; |
| 599 |
|
| 600 |
static const SDLTest_TestCaseReference mouseTest10 = { |
| 601 |
(SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED |
| 602 |
}; |
| 603 |
|
| 604 |
/* Sequence of Mouse test cases */ |
| 605 |
static const SDLTest_TestCaseReference *mouseTests[] = { |
| 606 |
&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, |
| 607 |
&mouseTest7, &mouseTest8, &mouseTest9, &mouseTest10, NULL |
| 608 |
}; |
| 609 |
|
| 610 |
/* Mouse test suite (global) */ |
| 611 |
SDLTest_TestSuiteReference mouseTestSuite = { |
| 612 |
"Mouse", |
| 613 |
NULL, |
| 614 |
mouseTests, |
| 615 |
NULL |
| 616 |
}; |