SDL  2.0
testautomation_mouse.c File Reference
#include <stdio.h>
#include <limits.h>
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_mouse.c:

Go to the source code of this file.

Macros

#define MOUSE_TESTWINDOW_WIDTH   320
 
#define MOUSE_TESTWINDOW_HEIGHT   200
 

Functions

int _mouseStateCheck (Uint32 state)
 
int mouse_getMouseState (void *arg)
 Check call to SDL_GetMouseState. More...
 
int mouse_getRelativeMouseState (void *arg)
 Check call to SDL_GetRelativeMouseState. More...
 
static SDL_Cursor_initArrowCursor (const char *image[])
 
int mouse_createFreeCursor (void *arg)
 Check call to SDL_CreateCursor and SDL_FreeCursor. More...
 
int mouse_createFreeColorCursor (void *arg)
 Check call to SDL_CreateColorCursor and SDL_FreeCursor. More...
 
void _changeCursorVisibility (int state)
 
int mouse_showCursor (void *arg)
 Check call to SDL_ShowCursor. More...
 
int mouse_setCursor (void *arg)
 Check call to SDL_SetCursor. More...
 
int mouse_getCursor (void *arg)
 Check call to SDL_GetCursor. More...
 
int mouse_getSetRelativeMouseMode (void *arg)
 Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode. More...
 
SDL_Window_createMouseSuiteTestWindow ()
 
void _destroyMouseSuiteTestWindow (SDL_Window *window)
 
int mouse_warpMouseInWindow (void *arg)
 Check call to SDL_WarpMouseInWindow. More...
 
int mouse_getMouseFocus (void *arg)
 Check call to SDL_GetMouseFocus. More...
 

Variables

static const char * _mouseArrowData []
 
static const SDLTest_TestCaseReference mouseTest1
 
static const SDLTest_TestCaseReference mouseTest2
 
static const SDLTest_TestCaseReference mouseTest3
 
static const SDLTest_TestCaseReference mouseTest4
 
static const SDLTest_TestCaseReference mouseTest5
 
static const SDLTest_TestCaseReference mouseTest6
 
static const SDLTest_TestCaseReference mouseTest7
 
static const SDLTest_TestCaseReference mouseTest8
 
static const SDLTest_TestCaseReference mouseTest9
 
static const SDLTest_TestCaseReference mouseTest10
 
static const SDLTest_TestCaseReferencemouseTests []
 
SDLTest_TestSuiteReference mouseTestSuite
 

Macro Definition Documentation

◆ MOUSE_TESTWINDOW_HEIGHT

#define MOUSE_TESTWINDOW_HEIGHT   200

◆ MOUSE_TESTWINDOW_WIDTH

#define MOUSE_TESTWINDOW_WIDTH   320

Function Documentation

◆ _changeCursorVisibility()

void _changeCursorVisibility ( int  state)

Definition at line 255 of file testautomation_mouse.c.

References SDL_ENABLE, SDL_QUERY, SDL_ShowCursor, SDLTest_AssertCheck(), and SDLTest_AssertPass().

Referenced by mouse_showCursor().

256 {
257  int oldState;
258  int newState;
259  int result;
260 
261  oldState = SDL_ShowCursor(SDL_QUERY);
262  SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
263 
264  result = SDL_ShowCursor(state);
265  SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
266  SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i",
267  (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
268 
269  newState = SDL_ShowCursor(SDL_QUERY);
270  SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
271  SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i",
272  state, newState);
273 }
GLuint64EXT * result
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
struct xkb_state * state
#define SDL_ENABLE
Definition: SDL_events.h:722
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define SDL_QUERY
Definition: SDL_events.h:719
#define SDL_ShowCursor

◆ _createMouseSuiteTestWindow()

SDL_Window* _createMouseSuiteTestWindow ( )

Creates a test window

Definition at line 418 of file testautomation_mouse.c.

References MOUSE_TESTWINDOW_HEIGHT, MOUSE_TESTWINDOW_WIDTH, NULL, SDL_CreateWindow, SDLTest_AssertCheck(), and SDLTest_AssertPass().

Referenced by mouse_getMouseFocus(), and mouse_warpMouseInWindow().

419 {
420  int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
422  window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
423  SDLTest_AssertPass("SDL_CreateWindow()");
424  SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
425  return window;
426 }
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
#define SDL_CreateWindow
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
#define MOUSE_TESTWINDOW_WIDTH
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define NULL
Definition: begin_code.h:164
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:73
#define MOUSE_TESTWINDOW_HEIGHT

◆ _destroyMouseSuiteTestWindow()

void _destroyMouseSuiteTestWindow ( SDL_Window window)

Definition at line 431 of file testautomation_mouse.c.

References NULL, SDL_DestroyWindow, and SDLTest_AssertPass().

Referenced by mouse_getMouseFocus(), and mouse_warpMouseInWindow().

432 {
433  if (window != NULL) {
434  SDL_DestroyWindow(window);
435  window = NULL;
436  SDLTest_AssertPass("SDL_DestroyWindow()");
437  }
438 }
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
#define NULL
Definition: begin_code.h:164
#define SDL_DestroyWindow

◆ _initArrowCursor()

static SDL_Cursor* _initArrowCursor ( const char *  image[])
static

Definition at line 157 of file testautomation_mouse.c.

References cursor, i, and SDL_CreateCursor.

Referenced by mouse_createFreeCursor(), and mouse_setCursor().

158 {
160  int i, row, col;
161  Uint8 data[4*32];
162  Uint8 mask[4*32];
163 
164  i = -1;
165  for ( row=0; row<32; ++row ) {
166  for ( col=0; col<32; ++col ) {
167  if ( col % 8 ) {
168  data[i] <<= 1;
169  mask[i] <<= 1;
170  } else {
171  ++i;
172  data[i] = mask[i] = 0;
173  }
174  switch (image[row][col]) {
175  case 'X':
176  data[i] |= 0x01;
177  mask[i] |= 0x01;
178  break;
179  case '.':
180  mask[i] |= 0x01;
181  break;
182  case ' ':
183  break;
184  }
185  }
186  }
187 
188  cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
189  return cursor;
190 }
GLeglImageOES image
Definition: SDL_opengl.h:2148
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
uint8_t Uint8
Definition: SDL_stdinc.h:157
GLenum GLint GLuint mask
SDL_Cursor * cursor
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_CreateCursor
GLenum GLenum void * row

◆ _mouseStateCheck()

int _mouseStateCheck ( Uint32  state)

Mouse test suite

Definition at line 16 of file testautomation_mouse.c.

References SDL_BUTTON, SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, SDL_BUTTON_X1, and SDL_BUTTON_X2.

Referenced by mouse_getMouseState(), and mouse_getRelativeMouseState().

17 {
18  return (state == 0) ||
24 }
#define SDL_BUTTON_RIGHT
Definition: SDL_mouse.h:284
struct xkb_state * state
#define SDL_BUTTON_X1
Definition: SDL_mouse.h:285
#define SDL_BUTTON_LEFT
Definition: SDL_mouse.h:282
#define SDL_BUTTON_MIDDLE
Definition: SDL_mouse.h:283
#define SDL_BUTTON(X)
Definition: SDL_mouse.h:281
#define SDL_BUTTON_X2
Definition: SDL_mouse.h:286

◆ mouse_createFreeColorCursor()

int mouse_createFreeColorCursor ( void arg)

Check call to SDL_CreateColorCursor and SDL_FreeCursor.

See also
http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor

Definition at line 225 of file testautomation_mouse.c.

References cursor, NULL, SDL_CreateColorCursor, SDL_FreeCursor, SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_ImageFace(), TEST_ABORTED, and TEST_COMPLETED.

226 {
227  SDL_Surface *face;
229 
230  /* Get sample surface */
231  face = SDLTest_ImageFace();
232  SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
233  if (face == NULL) return TEST_ABORTED;
234 
235  /* Create a color cursor from surface */
236  cursor = SDL_CreateColorCursor(face, 0, 0);
237  SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
238  SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
239  if (cursor == NULL) {
240  SDL_FreeSurface(face);
241  return TEST_ABORTED;
242  }
243 
244  /* Free cursor again */
245  SDL_FreeCursor(cursor);
246  SDLTest_AssertPass("Call to SDL_FreeCursor()");
247 
248  /* Clean up */
249  SDL_FreeSurface(face);
250 
251  return TEST_COMPLETED;
252 }
#define TEST_ABORTED
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
SDL_Surface * SDLTest_ImageFace(void)
Returns the Face test image as SDL_Surface.
GLenum GLuint GLint GLenum face
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define SDL_FreeSurface
#define SDL_CreateColorCursor
#define TEST_COMPLETED
SDL_Cursor * cursor
#define NULL
Definition: begin_code.h:164
#define SDL_FreeCursor

◆ mouse_createFreeCursor()

int mouse_createFreeCursor ( void arg)

Check call to SDL_CreateCursor and SDL_FreeCursor.

See also
http://wiki.libsdl.org/moin.cgi/SDL_CreateCursor
http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor

Definition at line 199 of file testautomation_mouse.c.

References _initArrowCursor(), _mouseArrowData, cursor, NULL, SDL_FreeCursor, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, and TEST_COMPLETED.

200 {
202 
203  /* Create a cursor */
205  SDLTest_AssertPass("Call to SDL_CreateCursor()");
206  SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
207  if (cursor == NULL) {
208  return TEST_ABORTED;
209  }
210 
211  /* Free cursor again */
212  SDL_FreeCursor(cursor);
213  SDLTest_AssertPass("Call to SDL_FreeCursor()");
214 
215  return TEST_COMPLETED;
216 }
#define TEST_ABORTED
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
static SDL_Cursor * _initArrowCursor(const char *image[])
static const char * _mouseArrowData[]
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
SDL_Cursor * cursor
#define NULL
Definition: begin_code.h:164
#define SDL_FreeCursor

◆ mouse_getCursor()

int mouse_getCursor ( void arg)

Check call to SDL_GetCursor.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetCursor

Definition at line 344 of file testautomation_mouse.c.

References cursor, NULL, SDL_GetCursor, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

345 {
347 
348  /* Get current cursor */
349  cursor = SDL_GetCursor();
350  SDLTest_AssertPass("Call to SDL_GetCursor()");
351  SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
352 
353  return TEST_COMPLETED;
354 }
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
SDL_Cursor * cursor
#define NULL
Definition: begin_code.h:164
#define SDL_GetCursor

◆ mouse_getMouseFocus()

int mouse_getMouseFocus ( void arg)

Check call to SDL_GetMouseFocus.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetMouseFocus

Definition at line 508 of file testautomation_mouse.c.

References _createMouseSuiteTestWindow(), _destroyMouseSuiteTestWindow(), MOUSE_TESTWINDOW_HEIGHT, MOUSE_TESTWINDOW_WIDTH, NULL, SDL_GetMouseFocus, SDL_PumpEvents, SDL_WarpMouseInWindow, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), TEST_ABORTED, and TEST_COMPLETED.

509 {
511  int x, y;
513  SDL_Window *focusWindow;
514 
515  /* Get focus - focus non-deterministic */
516  focusWindow = SDL_GetMouseFocus();
517  SDLTest_AssertPass("SDL_GetMouseFocus()");
518 
519  /* Create test window */
520  window = _createMouseSuiteTestWindow();
521  if (window == NULL) return TEST_ABORTED;
522 
523  /* Mouse to random position inside window */
524  x = SDLTest_RandomIntegerInRange(1, w-1);
525  y = SDLTest_RandomIntegerInRange(1, h-1);
526  SDL_WarpMouseInWindow(window, x, y);
527  SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
528 
529  /* Pump events to update focus state */
530  SDL_PumpEvents();
531  SDLTest_AssertPass("SDL_PumpEvents()");
532 
533  /* Get focus with explicit window setup - focus deterministic */
534  focusWindow = SDL_GetMouseFocus();
535  SDLTest_AssertPass("SDL_GetMouseFocus()");
536  SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
537  SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");
538 
539  /* Mouse to random position outside window */
540  x = SDLTest_RandomIntegerInRange(-9, -1);
541  y = SDLTest_RandomIntegerInRange(-9, -1);
542  SDL_WarpMouseInWindow(window, x, y);
543  SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
544 
545  /* Clean up test window */
547 
548  /* Pump events to update focus state */
549  SDL_PumpEvents();
550  SDLTest_AssertPass("SDL_PumpEvents()");
551 
552  /* Get focus for non-existing window */
553  focusWindow = SDL_GetMouseFocus();
554  SDLTest_AssertPass("SDL_GetMouseFocus()");
555  SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");
556 
557 
558  return TEST_COMPLETED;
559 }
#define TEST_ABORTED
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
void _destroyMouseSuiteTestWindow(SDL_Window *window)
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
GLfloat GLfloat GLfloat GLfloat h
SDL_Window * _createMouseSuiteTestWindow()
#define MOUSE_TESTWINDOW_WIDTH
#define SDL_PumpEvents
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define TEST_COMPLETED
#define NULL
Definition: begin_code.h:164
#define SDL_GetMouseFocus
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:73
#define SDL_WarpMouseInWindow
#define MOUSE_TESTWINDOW_HEIGHT

◆ mouse_getMouseState()

int mouse_getMouseState ( void arg)

Check call to SDL_GetMouseState.

Definition at line 31 of file testautomation_mouse.c.

References _mouseStateCheck(), NULL, SDL_GetMouseState, SDL_PumpEvents, SDLTest_AssertCheck(), SDLTest_AssertPass(), state, and TEST_COMPLETED.

32 {
33  int x;
34  int y;
35  Uint32 state;
36 
37  /* Pump some events to update mouse state */
39  SDLTest_AssertPass("Call to SDL_PumpEvents()");
40 
41  /* Case where x, y pointer is NULL */
42  state = SDL_GetMouseState(NULL, NULL);
43  SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
44  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
45 
46  /* Case where x pointer is not NULL */
47  x = INT_MIN;
48  state = SDL_GetMouseState(&x, NULL);
49  SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
50  SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
51  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
52 
53  /* Case where y pointer is not NULL */
54  y = INT_MIN;
55  state = SDL_GetMouseState(NULL, &y);
56  SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
57  SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
58  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
59 
60  /* Case where x and y pointer is not NULL */
61  x = INT_MIN;
62  y = INT_MIN;
63  state = SDL_GetMouseState(&x, &y);
64  SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
65  SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
66  SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
67  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
68 
69  return TEST_COMPLETED;
70 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
struct xkb_state * state
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_PumpEvents
int _mouseStateCheck(Uint32 state)
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define TEST_COMPLETED
#define NULL
Definition: begin_code.h:164
#define SDL_GetMouseState

◆ mouse_getRelativeMouseState()

int mouse_getRelativeMouseState ( void arg)

Check call to SDL_GetRelativeMouseState.

Definition at line 77 of file testautomation_mouse.c.

References _mouseStateCheck(), NULL, SDL_GetRelativeMouseState, SDL_PumpEvents, SDLTest_AssertCheck(), SDLTest_AssertPass(), state, and TEST_COMPLETED.

78 {
79  int x;
80  int y;
81  Uint32 state;
82 
83  /* Pump some events to update mouse state */
85  SDLTest_AssertPass("Call to SDL_PumpEvents()");
86 
87  /* Case where x, y pointer is NULL */
89  SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
90  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
91 
92  /* Case where x pointer is not NULL */
93  x = INT_MIN;
94  state = SDL_GetRelativeMouseState(&x, NULL);
95  SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
96  SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
97  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
98 
99  /* Case where y pointer is not NULL */
100  y = INT_MIN;
101  state = SDL_GetRelativeMouseState(NULL, &y);
102  SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
103  SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
104  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
105 
106  /* Case where x and y pointer is not NULL */
107  x = INT_MIN;
108  y = INT_MIN;
109  state = SDL_GetRelativeMouseState(&x, &y);
110  SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
111  SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
112  SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
113  SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
114 
115  return TEST_COMPLETED;
116 }
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
struct xkb_state * state
uint32_t Uint32
Definition: SDL_stdinc.h:181
#define SDL_PumpEvents
int _mouseStateCheck(Uint32 state)
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define SDL_GetRelativeMouseState
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define TEST_COMPLETED
#define NULL
Definition: begin_code.h:164

◆ mouse_getSetRelativeMouseMode()

int mouse_getSetRelativeMouseMode ( void arg)

Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode.

See also
http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode
http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode

Definition at line 363 of file testautomation_mouse.c.

References i, SDL_FALSE, SDL_GetRelativeMouseMode, SDL_SetRelativeMouseMode, SDL_TRUE, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

364 {
365  int result;
366  int i;
367  SDL_bool initialState;
368  SDL_bool currentState;
369 
370  /* Capture original state so we can revert back to it later */
371  initialState = SDL_GetRelativeMouseMode();
372  SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
373 
374  /* Repeat twice to check D->D transition */
375  for (i=0; i<2; i++) {
376  /* Disable - should always be supported */
378  SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
379  SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
380  currentState = SDL_GetRelativeMouseMode();
381  SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
382  SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
383  }
384 
385  /* Repeat twice to check D->E->E transition */
386  for (i=0; i<2; i++) {
387  /* Enable - may not be supported */
389  SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
390  if (result != -1) {
391  SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
392  currentState = SDL_GetRelativeMouseMode();
393  SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
394  SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
395  }
396  }
397 
398  /* Disable to check E->D transition */
400  SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
401  SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
402  currentState = SDL_GetRelativeMouseMode();
403  SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
404  SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
405 
406  /* Revert to original state - ignore result */
407  result = SDL_SetRelativeMouseMode(initialState);
408 
409  return TEST_COMPLETED;
410 }
GLuint64EXT * result
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
#define SDL_SetRelativeMouseMode
#define SDL_GetRelativeMouseMode
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_bool
Definition: SDL_stdinc.h:139

◆ mouse_setCursor()

int mouse_setCursor ( void arg)

Check call to SDL_SetCursor.

See also
http://wiki.libsdl.org/moin.cgi/SDL_SetCursor

Definition at line 311 of file testautomation_mouse.c.

References _initArrowCursor(), _mouseArrowData, cursor, NULL, SDL_FreeCursor, SDL_SetCursor, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, and TEST_COMPLETED.

312 {
314 
315  /* Create a cursor */
317  SDLTest_AssertPass("Call to SDL_CreateCursor()");
318  SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
319  if (cursor == NULL) {
320  return TEST_ABORTED;
321  }
322 
323  /* Set the arrow cursor */
324  SDL_SetCursor(cursor);
325  SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");
326 
327  /* Force redraw */
329  SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");
330 
331  /* Free cursor again */
332  SDL_FreeCursor(cursor);
333  SDLTest_AssertPass("Call to SDL_FreeCursor()");
334 
335  return TEST_COMPLETED;
336 }
#define TEST_ABORTED
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
static SDL_Cursor * _initArrowCursor(const char *image[])
#define SDL_SetCursor
static const char * _mouseArrowData[]
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
SDL_Cursor * cursor
#define NULL
Definition: begin_code.h:164
#define SDL_FreeCursor

◆ mouse_showCursor()

int mouse_showCursor ( void arg)

Check call to SDL_ShowCursor.

See also
http://wiki.libsdl.org/moin.cgi/SDL_ShowCursor

Definition at line 281 of file testautomation_mouse.c.

References _changeCursorVisibility(), SDL_DISABLE, SDL_ENABLE, SDL_QUERY, SDL_ShowCursor, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, and TEST_COMPLETED.

282 {
283  int currentState;
284 
285  /* Get current state */
286  currentState = SDL_ShowCursor(SDL_QUERY);
287  SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
288  SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE,
289  "Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
290  if (currentState == SDL_DISABLE) {
291  /* Show the cursor, then hide it again */
294  } else if (currentState == SDL_ENABLE) {
295  /* Hide the cursor, then show it again */
298  } else {
299  return TEST_ABORTED;
300  }
301 
302  return TEST_COMPLETED;
303 }
#define TEST_ABORTED
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
#define SDL_ENABLE
Definition: SDL_events.h:722
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
#define TEST_COMPLETED
#define SDL_DISABLE
Definition: SDL_events.h:721
#define SDL_QUERY
Definition: SDL_events.h:719
void _changeCursorVisibility(int state)
#define SDL_ShowCursor

◆ mouse_warpMouseInWindow()

int mouse_warpMouseInWindow ( void arg)

Check call to SDL_WarpMouseInWindow.

See also
http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow

Definition at line 446 of file testautomation_mouse.c.

References _createMouseSuiteTestWindow(), _destroyMouseSuiteTestWindow(), i, j, MOUSE_TESTWINDOW_HEIGHT, MOUSE_TESTWINDOW_WIDTH, NULL, SDL_PumpEvents, SDL_WarpMouseInWindow, SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), TEST_ABORTED, and TEST_COMPLETED.

447 {
449  int numPositions = 6;
450  int xPositions[6];
451  int yPositions[6];
452  int x, y, i, j;
454 
455  xPositions[0] = -1;
456  xPositions[1] = 0;
457  xPositions[2] = 1;
458  xPositions[3] = w-1;
459  xPositions[4] = w;
460  xPositions[5] = w+1;
461  yPositions[0] = -1;
462  yPositions[1] = 0;
463  yPositions[2] = 1;
464  yPositions[3] = h-1;
465  yPositions[4] = h;
466  yPositions[5] = h+1;
467  /* Create test window */
468  window = _createMouseSuiteTestWindow();
469  if (window == NULL) return TEST_ABORTED;
470 
471  /* Mouse to random position inside window */
472  x = SDLTest_RandomIntegerInRange(1, w-1);
473  y = SDLTest_RandomIntegerInRange(1, h-1);
474  SDL_WarpMouseInWindow(window, x, y);
475  SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
476 
477  /* Same position again */
478  SDL_WarpMouseInWindow(window, x, y);
479  SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
480 
481  /* Mouse to various boundary positions */
482  for (i=0; i<numPositions; i++) {
483  for (j=0; j<numPositions; j++) {
484  x = xPositions[i];
485  y = yPositions[j];
486  SDL_WarpMouseInWindow(window, x, y);
487  SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
488 
489  /* TODO: add tracking of events and check that each call generates a mouse motion event */
490  SDL_PumpEvents();
491  SDLTest_AssertPass("SDL_PumpEvents()");
492  }
493  }
494 
495 
496  /* Clean up test window */
498 
499  return TEST_COMPLETED;
500 }
#define TEST_ABORTED
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
void _destroyMouseSuiteTestWindow(SDL_Window *window)
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
GLfloat GLfloat GLfloat GLfloat h
SDL_Window * _createMouseSuiteTestWindow()
#define MOUSE_TESTWINDOW_WIDTH
#define SDL_PumpEvents
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define TEST_COMPLETED
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:73
#define SDL_WarpMouseInWindow
#define MOUSE_TESTWINDOW_HEIGHT

Variable Documentation

◆ _mouseArrowData

const char* _mouseArrowData[]
static

Definition at line 120 of file testautomation_mouse.c.

Referenced by mouse_createFreeCursor(), and mouse_setCursor().

◆ mouseTest1

const SDLTest_TestCaseReference mouseTest1
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED }
int mouse_getMouseState(void *arg)
Check call to SDL_GetMouseState.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 564 of file testautomation_mouse.c.

◆ mouseTest10

const SDLTest_TestCaseReference mouseTest10
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED }
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED
int mouse_getSetRelativeMouseMode(void *arg)
Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode.

Definition at line 591 of file testautomation_mouse.c.

◆ mouseTest2

const SDLTest_TestCaseReference mouseTest2
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED }
int(* SDLTest_TestCaseFp)(void *arg)
int mouse_getRelativeMouseState(void *arg)
Check call to SDL_GetRelativeMouseState.
#define TEST_ENABLED

Definition at line 567 of file testautomation_mouse.c.

◆ mouseTest3

const SDLTest_TestCaseReference mouseTest3
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED }
int(* SDLTest_TestCaseFp)(void *arg)
int mouse_createFreeCursor(void *arg)
Check call to SDL_CreateCursor and SDL_FreeCursor.
#define TEST_ENABLED

Definition at line 570 of file testautomation_mouse.c.

◆ mouseTest4

const SDLTest_TestCaseReference mouseTest4
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED }
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED
int mouse_showCursor(void *arg)
Check call to SDL_ShowCursor.

Definition at line 573 of file testautomation_mouse.c.

◆ mouseTest5

const SDLTest_TestCaseReference mouseTest5
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED }
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED
int mouse_setCursor(void *arg)
Check call to SDL_SetCursor.

Definition at line 576 of file testautomation_mouse.c.

◆ mouseTest6

const SDLTest_TestCaseReference mouseTest6
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED }
int mouse_getCursor(void *arg)
Check call to SDL_GetCursor.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 579 of file testautomation_mouse.c.

◆ mouseTest7

const SDLTest_TestCaseReference mouseTest7
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED }
int mouse_warpMouseInWindow(void *arg)
Check call to SDL_WarpMouseInWindow.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 582 of file testautomation_mouse.c.

◆ mouseTest8

const SDLTest_TestCaseReference mouseTest8
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED }
int(* SDLTest_TestCaseFp)(void *arg)
int mouse_getMouseFocus(void *arg)
Check call to SDL_GetMouseFocus.
#define TEST_ENABLED

Definition at line 585 of file testautomation_mouse.c.

◆ mouseTest9

const SDLTest_TestCaseReference mouseTest9
static
Initial value:
=
{ (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED }
int mouse_createFreeColorCursor(void *arg)
Check call to SDL_CreateColorCursor and SDL_FreeCursor.
int(* SDLTest_TestCaseFp)(void *arg)
#define TEST_ENABLED

Definition at line 588 of file testautomation_mouse.c.

◆ mouseTests

const SDLTest_TestCaseReference* mouseTests[]
static
Initial value:
= {
}
static const SDLTest_TestCaseReference mouseTest8
static const SDLTest_TestCaseReference mouseTest1
static const SDLTest_TestCaseReference mouseTest6
static const SDLTest_TestCaseReference mouseTest5
static const SDLTest_TestCaseReference mouseTest7
static const SDLTest_TestCaseReference mouseTest3
static const SDLTest_TestCaseReference mouseTest10
static const SDLTest_TestCaseReference mouseTest4
#define NULL
Definition: begin_code.h:164
static const SDLTest_TestCaseReference mouseTest9
static const SDLTest_TestCaseReference mouseTest2

Definition at line 595 of file testautomation_mouse.c.

◆ mouseTestSuite

Initial value:
= {
"Mouse",
}
#define NULL
Definition: begin_code.h:164
static const SDLTest_TestCaseReference * mouseTests[]

Definition at line 601 of file testautomation_mouse.c.