🛠️🐜 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.

172 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. const 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. const char* _HintsVerbose[] =
  37. {
  38. "SDL_ACCELEROMETER_AS_JOYSTICK",
  39. "SDL_FRAMEBUFFER_ACCELERATION",
  40. "SDL_GAMECONTROLLERCONFIG",
  41. "SDL_GRAB_KEYBOARD",
  42. "SDL_IDLE_TIMER_DISABLED",
  43. "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
  44. "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
  45. "SDL_MOUSE_RELATIVE_MODE_WARP",
  46. "SDL_ORIENTATIONS",
  47. "SDL_RENDER_DIRECT3D_THREADSAFE",
  48. "SDL_RENDER_DRIVER",
  49. "SDL_RENDER_OPENGL_SHADERS",
  50. "SDL_RENDER_SCALE_QUALITY",
  51. "SDL_RENDER_VSYNC",
  52. "SDL_TIMER_RESOLUTION",
  53. "SDL_VIDEO_ALLOW_SCREENSAVER",
  54. "SDL_VIDEO_HIGHDPI_DISABLED",
  55. "SDL_VIDEO_MAC_FULLSCREEN_SPACES",
  56. "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
  57. "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
  58. "SDL_VIDEO_WIN_D3DCOMPILER",
  59. "SDL_VIDEO_X11_XINERAMA",
  60. "SDL_VIDEO_X11_XRANDR",
  61. "SDL_VIDEO_X11_XVIDMODE",
  62. "SDL_XINPUT_ENABLED"
  63. };
  64. /* Test case functions */
  65. /**
  66. * @brief Call to SDL_GetHint
  67. */
  68. int
  69. hints_getHint(void *arg)
  70. {
  71. const char *result1;
  72. const char *result2;
  73. int i;
  74. for (i=0; i<_numHintsEnum; i++) {
  75. result1 = SDL_GetHint(_HintsEnum[i]);
  76. SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
  77. result2 = SDL_GetHint(_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. const char *originalValue;
  94. const char *value;
  95. const 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 = SDL_GetHint(_HintsEnum[i]);
  103. SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
  104. /* Copy the original value, since it will be freed when we set it again */
  105. originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
  106. /* Set value (twice) */
  107. for (j=1; j<=2; j++) {
  108. result = SDL_SetHint(_HintsEnum[i], value);
  109. SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
  110. SDLTest_AssertCheck(
  111. result == SDL_TRUE || result == SDL_FALSE,
  112. "Verify valid result was returned, got: %i",
  113. (int)result);
  114. testValue = SDL_GetHint(_HintsEnum[i]);
  115. SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
  116. SDLTest_AssertCheck(
  117. (SDL_strcmp(value, testValue) == 0),
  118. "Verify returned value equals set value; got: testValue='%s' value='%s",
  119. (testValue == NULL) ? "null" : testValue,
  120. value);
  121. }
  122. /* Reset original value */
  123. result = SDL_SetHint(_HintsEnum[i], originalValue);
  124. SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
  125. SDLTest_AssertCheck(
  126. result == SDL_TRUE || result == SDL_FALSE,
  127. "Verify valid result was returned, got: %i",
  128. (int)result);
  129. SDL_free((void *)originalValue);
  130. }
  131. SDL_free((void *)value);
  132. return TEST_COMPLETED;
  133. }
  134. /* ================= Test References ================== */
  135. /* Hints test cases */
  136. static const SDLTest_TestCaseReference hintsTest1 =
  137. { (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
  138. static const SDLTest_TestCaseReference hintsTest2 =
  139. { (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
  140. /* Sequence of Hints test cases */
  141. static const SDLTest_TestCaseReference *hintsTests[] = {
  142. &hintsTest1, &hintsTest2, NULL
  143. };
  144. /* Hints test suite (global) */
  145. SDLTest_TestSuiteReference hintsTestSuite = {
  146. "Hints",
  147. NULL,
  148. hintsTests,
  149. NULL
  150. };