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

157 lines
6.2 KiB

  1. /**
  2. * Automated SDL subsystems management test.
  3. *
  4. * Written by Jrgen Tjern "jorgenpt"
  5. *
  6. * Released under Public Domain.
  7. */
  8. #include "SDL.h"
  9. #include "SDL_test.h"
  10. /* !
  11. * \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
  12. * \sa
  13. * http://wiki.libsdl.org/moin.cgi/SDL_Init
  14. * http://wiki.libsdl.org/moin.cgi/SDL_Quit
  15. */
  16. static int main_testInitQuitJoystickHaptic (void *arg)
  17. {
  18. #if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
  19. return TEST_SKIPPED;
  20. #else
  21. int enabled_subsystems;
  22. int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
  23. SDLTest_AssertCheck( SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems." );
  24. enabled_subsystems = SDL_WasInit(initialized_subsystems);
  25. SDLTest_AssertCheck( enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems );
  26. SDL_Quit();
  27. enabled_subsystems = SDL_WasInit(initialized_subsystems);
  28. SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
  29. return TEST_COMPLETED;
  30. #endif
  31. }
  32. /* !
  33. * \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
  34. * \sa
  35. * http://wiki.libsdl.org/moin.cgi/SDL_Init
  36. * http://wiki.libsdl.org/moin.cgi/SDL_Quit
  37. */
  38. static int main_testInitQuitSubSystem (void *arg)
  39. {
  40. #if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
  41. return TEST_SKIPPED;
  42. #else
  43. int i;
  44. int subsystems[] = { SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMECONTROLLER };
  45. for (i = 0; i < SDL_arraysize(subsystems); ++i) {
  46. int initialized_system;
  47. int subsystem = subsystems[i];
  48. SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem );
  49. SDLTest_AssertCheck( SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem );
  50. initialized_system = SDL_WasInit(subsystem);
  51. SDLTest_AssertCheck( (initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system );
  52. SDL_QuitSubSystem(subsystem);
  53. SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem );
  54. }
  55. return TEST_COMPLETED;
  56. #endif
  57. }
  58. const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
  59. static int main_testImpliedJoystickInit (void *arg)
  60. {
  61. #if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
  62. return TEST_SKIPPED;
  63. #else
  64. int initialized_system;
  65. /* First initialize the controller */
  66. SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
  67. SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
  68. /* Then make sure this implicitly initialized the joystick subsystem */
  69. initialized_system = SDL_WasInit(joy_and_controller);
  70. SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
  71. /* Then quit the controller, and make sure that implicitly also quits the */
  72. /* joystick subsystem */
  73. SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
  74. initialized_system = SDL_WasInit(joy_and_controller);
  75. SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
  76. return TEST_COMPLETED;
  77. #endif
  78. }
  79. static int main_testImpliedJoystickQuit (void *arg)
  80. {
  81. #if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
  82. return TEST_SKIPPED;
  83. #else
  84. int initialized_system;
  85. /* First initialize the controller and the joystick (explicitly) */
  86. SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
  87. SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
  88. SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
  89. /* Then make sure they're both initialized properly */
  90. initialized_system = SDL_WasInit(joy_and_controller);
  91. SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
  92. /* Then quit the controller, and make sure that it does NOT quit the */
  93. /* explicitly initialized joystick subsystem. */
  94. SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
  95. initialized_system = SDL_WasInit(joy_and_controller);
  96. SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
  97. SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
  98. return TEST_COMPLETED;
  99. #endif
  100. }
  101. static const SDLTest_TestCaseReference mainTest1 =
  102. { (SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED};
  103. static const SDLTest_TestCaseReference mainTest2 =
  104. { (SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED};
  105. static const SDLTest_TestCaseReference mainTest3 =
  106. { (SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED};
  107. static const SDLTest_TestCaseReference mainTest4 =
  108. { (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
  109. /* Sequence of Main test cases */
  110. static const SDLTest_TestCaseReference *mainTests[] = {
  111. &mainTest1,
  112. &mainTest2,
  113. &mainTest3,
  114. &mainTest4,
  115. NULL
  116. };
  117. /* Main test suite (global) */
  118. SDLTest_TestSuiteReference mainTestSuite = {
  119. "Main",
  120. NULL,
  121. mainTests,
  122. NULL
  123. };
  124. /* vi: set ts=4 sw=4 expandtab: */