#include "../../../__mocks__/SDL_keyboard.mock.h" #include "../../../__mocks__/minIni.mock.h" #include "../__mocks__/IZ_config.mock.h" #include "IZ_keyboard.h" spec("input/keyboard") { describe("HandleKeyboardEvents") { static SDL_Event e; static IZ_KeyboardState state; static IZ_Action action; for (uint8_t i = 0; i < CONTROLS; i += 1) { it("handles %s action activation", ACTION_NAMES[i]) { e.type = SDL_KEYDOWN; e.key.keysym.sym = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i]; state.config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i]; action = 0; IZ_HandleKeyboardEvents(e, &state, &action); check( action == (0x1 << i), "Action not set." ); } it("handles %s action deactivation", ACTION_NAMES[i]) { e.type = SDL_KEYUP; e.key.keysym.sym = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i]; state.config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i]; action = ~0; IZ_HandleKeyboardEvents(e, &state, &action); check( !(action & (0x1 << i)), "Action not unset." ); } } } describe("LoadKeyboardConfig") { static IZ_KeyboardConfig config; after_each() { mock_reset(IZ_GetConfigPath); } after_each() { mock_reset(ini_gets); } it("calls load method") { mock_set_expected_calls(ini_gets, CONTROLS); IZ_LoadKeyboardConfig(&config, 0); check( mock_is_called(IZ_GetConfigPath), "SDL_GetBasePath() not called." ); check( mock_get_expected_calls(ini_gets) == mock_get_actual_calls(ini_gets), "Call count mismatch for ini_gets() (expected %u, received %u).", mock_get_expected_calls(ini_gets), mock_get_actual_calls(ini_gets) ); } } describe("SaveKeyboardConfig") { static IZ_KeyboardConfig config; after_each() { mock_reset(IZ_GetConfigPath); } after_each() { mock_reset(ini_puts); } before_each() { for (uint8_t i = 0; i < CONTROLS; i += 1) { config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_CONTROLS[0][i]; } } it("calls save method") { mock_set_expected_calls(ini_puts, CONTROLS); IZ_SaveKeyboardConfig(&config, 0); check( mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts), "Call count mismatch for ini_puts() (expected %u, received %u).", mock_get_expected_calls(ini_puts), mock_get_actual_calls(ini_puts) ); } } }