Starter project for SDL2.
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.

102 lines
2.3 KiB

  1. #include "../../../__mocks__/SDL_keyboard.mock.h"
  2. #include "../../../__mocks__/minIni.mock.h"
  3. #include "../__mocks__/IZ_config.mock.h"
  4. #include "IZ_keyboard.h"
  5. spec("input/keyboard") {
  6. describe("HandleKeyboardEvents") {
  7. static SDL_Event e;
  8. static IZ_KeyboardState state;
  9. static IZ_Action action;
  10. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  11. it("handles %s action activation", ACTION_NAMES[i]) {
  12. e.type = SDL_KEYDOWN;
  13. e.key.keysym.sym = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i];
  14. state.config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i];
  15. action = 0;
  16. IZ_HandleKeyboardEvents(e, &state, &action);
  17. check(
  18. action == (0x1 << i),
  19. "Action not set."
  20. );
  21. }
  22. it("handles %s action deactivation", ACTION_NAMES[i]) {
  23. e.type = SDL_KEYUP;
  24. e.key.keysym.sym = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i];
  25. state.config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i];
  26. action = ~0;
  27. IZ_HandleKeyboardEvents(e, &state, &action);
  28. check(
  29. !(action & (0x1 << i)),
  30. "Action not unset."
  31. );
  32. }
  33. }
  34. }
  35. describe("LoadKeyboardConfig") {
  36. static IZ_KeyboardConfig config;
  37. after_each() {
  38. mock_reset(IZ_GetConfigPath);
  39. }
  40. after_each() {
  41. mock_reset(ini_gets);
  42. }
  43. it("calls load method") {
  44. mock_set_expected_calls(ini_gets, CONTROLS);
  45. IZ_LoadKeyboardConfig(&config, 0);
  46. check(
  47. mock_is_called(IZ_GetConfigPath),
  48. "SDL_GetBasePath() not called."
  49. );
  50. check(
  51. mock_get_expected_calls(ini_gets) == mock_get_actual_calls(ini_gets),
  52. "Call count mismatch for ini_gets() (expected %u, received %u).",
  53. mock_get_expected_calls(ini_gets),
  54. mock_get_actual_calls(ini_gets)
  55. );
  56. }
  57. }
  58. describe("SaveKeyboardConfig") {
  59. static IZ_KeyboardConfig config;
  60. after_each() {
  61. mock_reset(IZ_GetConfigPath);
  62. }
  63. after_each() {
  64. mock_reset(ini_puts);
  65. }
  66. before_each() {
  67. for (uint8_t i = 0; i < CONTROLS; i += 1) {
  68. config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i];
  69. }
  70. }
  71. it("calls save method") {
  72. mock_set_expected_calls(ini_puts, CONTROLS);
  73. IZ_SaveKeyboardConfig(&config, 0);
  74. check(
  75. mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts),
  76. "Call count mismatch for ini_puts() (expected %u, received %u).",
  77. mock_get_expected_calls(ini_puts),
  78. mock_get_actual_calls(ini_puts)
  79. );
  80. }
  81. }
  82. }