diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c03fbe..f27a422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ add_executable( src/packages/game/output/IZ_video.h src/packages/game/output/IZ_video.c - src/packages/game/output/IZ_video.test.c + src/packages/game/output/output.test.c ) add_executable( diff --git a/src/packages/game/input/IZ_joystick.c b/src/packages/game/input/IZ_joystick.c index f2a0149..ee00cfe 100644 --- a/src/packages/game/input/IZ_joystick.c +++ b/src/packages/game/input/IZ_joystick.c @@ -5,13 +5,14 @@ void IZ_HandleJoystickDeviceEvents(SDL_Event e, IZ_JoystickState* state) { if (SDL_NumJoysticks() <= PLAYERS && !state->joystick_instance) { state->joystick_instance = SDL_JoystickOpen(e.jdevice.which); } + return; } if (e.type == SDL_JOYDEVICEREMOVED) { if ( state->joystick_instance && SDL_JoystickInstanceID(state->joystick_instance) == e.jdevice.which - ) { + ) { state->joystick_instance = NULL; } } @@ -70,12 +71,12 @@ void IZ_HandleJoystickButtonEvents(SDL_Event e, IZ_JoystickState* state, IZ_Acti if (e.type == SDL_JOYBUTTONDOWN) { *action |= bitflag; - break; + return; } if (e.type == SDL_JOYBUTTONUP) { *action &= ~bitflag; - break; + return; } } } diff --git a/src/packages/game/input/IZ_keyboard.c b/src/packages/game/input/IZ_keyboard.c index c089d60..bfdaf33 100644 --- a/src/packages/game/input/IZ_keyboard.c +++ b/src/packages/game/input/IZ_keyboard.c @@ -6,11 +6,11 @@ void IZ_HandleKeyboardEvents(SDL_Event e, IZ_KeyboardState* state, IZ_Action* ac const uint16_t bitflag = (0x1 << i); if (e.type == SDL_KEYDOWN) { *action |= bitflag; - break; + return; } if (e.type == SDL_KEYUP) { *action &= ~bitflag; - break; + return; } } } diff --git a/src/packages/game/output/IZ_video.test.c b/src/packages/game/output/IZ_video.test.c deleted file mode 100644 index e67196c..0000000 --- a/src/packages/game/output/IZ_video.test.c +++ /dev/null @@ -1,66 +0,0 @@ -#include "../../../__mocks__/minIni.mock.h" -#include "../__mocks__/IZ_config.mock.h" -#include "IZ_video.h" - -spec("output/video") { - describe("LoadVideoConfig") { - static IZ_VideoConfig config; - - after_each() { - mock_reset(IZ_GetConfigPath); - } - - after_each() { - mock_reset(ini_getl); - } - - it("calls load method") { - mock_set_expected_calls(ini_getl, 3); - - IZ_LoadVideoConfig(&config); - - check( - mock_is_called(IZ_GetConfigPath), - "SDL_GetBasePath() not called." - ); - - check( - mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl), - "Call count mismatch for ini_getl() (expected %u, received %u).", - mock_get_expected_calls(ini_getl), - mock_get_actual_calls(ini_getl) - ); - } - } - - describe("SaveVideoConfig") { - static IZ_VideoConfig config; - - after_each() { - mock_reset(IZ_GetConfigPath); - } - - after_each() { - mock_reset(ini_putl); - } - - before_each() { - config.width = 1337; - config.height = 420; - config.max_fps = 69; - } - - it("calls save method") { - mock_set_expected_calls(ini_putl, 3); - - IZ_SaveVideoConfig(&config); - - check( - mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), - "Call count mismatch for ini_putl() (expected %u, received %u).", - mock_get_expected_calls(ini_putl), - mock_get_actual_calls(ini_putl) - ); - } - } -} diff --git a/src/packages/game/output/output.test.c b/src/packages/game/output/output.test.c new file mode 100644 index 0000000..1e44ac7 --- /dev/null +++ b/src/packages/game/output/output.test.c @@ -0,0 +1,68 @@ +#include "../../../__mocks__/minIni.mock.h" +#include "../__mocks__/IZ_config.mock.h" +#include "IZ_video.h" + +spec("output") { + describe("video") { + describe("LoadVideoConfig") { + static IZ_VideoConfig config; + + after_each() { + mock_reset(IZ_GetConfigPath); + } + + after_each() { + mock_reset(ini_getl); + } + + it("calls load method") { + mock_set_expected_calls(ini_getl, 3); + + IZ_LoadVideoConfig(&config); + + check( + mock_is_called(IZ_GetConfigPath), + "SDL_GetBasePath() not called." + ); + + check( + mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl), + "Call count mismatch for ini_getl() (expected %u, received %u).", + mock_get_expected_calls(ini_getl), + mock_get_actual_calls(ini_getl) + ); + } + } + + describe("SaveVideoConfig") { + static IZ_VideoConfig config; + + after_each() { + mock_reset(IZ_GetConfigPath); + } + + after_each() { + mock_reset(ini_putl); + } + + before_each() { + config.width = 1337; + config.height = 420; + config.max_fps = 69; + } + + it("calls save method") { + mock_set_expected_calls(ini_putl, 3); + + IZ_SaveVideoConfig(&config); + + check( + mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), + "Call count mismatch for ini_putl() (expected %u, received %u).", + mock_get_expected_calls(ini_putl), + mock_get_actual_calls(ini_putl) + ); + } + } + } +}