🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.0 KiB

  1. /**
  2. * Hints test suite
  3. */
  4. #include <stdio.h>
  5. #include "SDL.h"
  6. #include "SDL_test.h"
  7. const int _numHintsEnum = 25;
  8. char* _HintsEnum[] =
  9. {
  10. SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
  11. SDL_HINT_FRAMEBUFFER_ACCELERATION,
  12. SDL_HINT_GAMECONTROLLERCONFIG,
  13. SDL_HINT_GRAB_KEYBOARD,
  14. SDL_HINT_IDLE_TIMER_DISABLED,
  15. SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
  16. SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
  17. SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
  18. SDL_HINT_ORIENTATIONS,
  19. SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
  20. SDL_HINT_RENDER_DRIVER,
  21. SDL_HINT_RENDER_OPENGL_SHADERS,
  22. SDL_HINT_RENDER_SCALE_QUALITY,
  23. SDL_HINT_RENDER_VSYNC,
  24. SDL_HINT_TIMER_RESOLUTION,
  25. SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
  26. SDL_HINT_VIDEO_HIGHDPI_DISABLED,
  27. SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
  28. SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
  29. SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
  30. SDL_HINT_VIDEO_WIN_D3DCOMPILER,
  31. SDL_HINT_VIDEO_X11_XINERAMA,
  32. SDL_HINT_VIDEO_X11_XRANDR,
  33. SDL_HINT_VIDEO_X11_XVIDMODE,
  34. SDL_HINT_XINPUT_ENABLED,
  35. };
  36. char* _HintsVerbose[] =
  37. {
  38. "SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
  39. "SDL_HINT_FRAMEBUFFER_ACCELERATION",
  40. "SDL_HINT_GAMECONTROLLERCONFIG",
  41. "SDL_HINT_GRAB_KEYBOARD",
  42. "SDL_HINT_IDLE_TIMER_DISABLED",
  43. "SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
  44. "SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
  45. "SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
  46. "SDL_HINT_ORIENTATIONS",
  47. "SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
  48. "SDL_HINT_RENDER_DRIVER",
  49. "SDL_HINT_RENDER_OPENGL_SHADERS",
  50. "SDL_HINT_RENDER_SCALE_QUALITY",
  51. "SDL_HINT_RENDER_VSYNC",
  52. "SDL_HINT_TIMER_RESOLUTION",
  53. "SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
  54. "SDL_HINT_VIDEO_HIGHDPI_DISABLED",
  55. "SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
  56. "SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
  57. "SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
  58. "SDL_HINT_VIDEO_WIN_D3DCOMPILER",
  59. "SDL_HINT_VIDEO_X11_XINERAMA",
  60. "SDL_HINT_VIDEO_X11_XRANDR",
  61. "SDL_HINT_VIDEO_X11_XVIDMODE",
  62. "SDL_HINT_XINPUT_ENABLED"
  63. };
  64. /* Test case functions */
  65. /**
  66. * @brief Call to SDL_GetHint
  67. */
  68. int
  69. hints_getHint(void *arg)
  70. {
  71. char *result1;
  72. char *result2;
  73. int i;
  74. for (i=0; i<_numHintsEnum; i++) {
  75. result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
  76. SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
  77. result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
  78. SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
  79. SDLTest_AssertCheck(
  80. (result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
  81. "Verify returned values are equal; got: result1='%s' result2='%s",
  82. (result1 == NULL) ? "null" : result1,
  83. (result2 == NULL) ? "null" : result2);
  84. }
  85. return TEST_COMPLETED;
  86. }
  87. /**
  88. * @brief Call to SDL_SetHint
  89. */
  90. int
  91. hints_setHint(void *arg)
  92. {
  93. char *originalValue;
  94. char *value;
  95. char *testValue;
  96. SDL_bool result;
  97. int i, j;
  98. /* Create random values to set */
  99. value = SDLTest_RandomAsciiStringOfSize(10);
  100. for (i=0; i<_numHintsEnum; i++) {
  101. /* Capture current value */
  102. originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
  103. SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
  104. /* Set value (twice) */
  105. for (j=1; j<=2; j++) {
  106. result = SDL_SetHint((char*)_HintsEnum[i], value);
  107. SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
  108. SDLTest_AssertCheck(
  109. result == SDL_TRUE || result == SDL_FALSE,
  110. "Verify valid result was returned, got: %i",
  111. (int)result);
  112. testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
  113. SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
  114. SDLTest_AssertCheck(
  115. (SDL_strcmp(value, testValue) == 0),
  116. "Verify returned value equals set value; got: testValue='%s' value='%s",
  117. (testValue == NULL) ? "null" : testValue,
  118. value);
  119. }
  120. /* Reset original value */
  121. result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
  122. SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
  123. SDLTest_AssertCheck(
  124. result == SDL_TRUE || result == SDL_FALSE,
  125. "Verify valid result was returned, got: %i",
  126. (int)result);
  127. }
  128. SDL_free(value);
  129. return TEST_COMPLETED;
  130. }
  131. /* ================= Test References ================== */
  132. /* Hints test cases */
  133. static const SDLTest_TestCaseReference hintsTest1 =
  134. { (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
  135. static const SDLTest_TestCaseReference hintsTest2 =
  136. { (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
  137. /* Sequence of Hints test cases */
  138. static const SDLTest_TestCaseReference *hintsTests[] = {
  139. &hintsTest1, &hintsTest2, NULL
  140. };
  141. /* Hints test suite (global) */
  142. SDLTest_TestSuiteReference hintsTestSuite = {
  143. "Hints",
  144. NULL,
  145. hintsTests,
  146. NULL
  147. };