|
|
@@ -2,8 +2,10 @@ |
|
|
|
#include "../../../__mocks__/SDL_joystick.mock.h" |
|
|
|
#include "../../../__mocks__/SDL_stdinc.mock.h" |
|
|
|
#include "../../../__mocks__/minIni.mock.h" |
|
|
|
#include "../../../__mocks__/portmidi.mock.h" |
|
|
|
#include "IZ_keyboard.h" |
|
|
|
#include "IZ_joystick.h" |
|
|
|
#include "IZ_midi.h" |
|
|
|
|
|
|
|
i16 GenerateAxisValueWithinThreshold(u16 threshold) { |
|
|
|
return rand() % threshold; |
|
|
@@ -15,6 +17,76 @@ i16 GenerateAxisValueOutsideThreshold(u16 threshold) { |
|
|
|
|
|
|
|
spec("input") { |
|
|
|
describe("joystick") { |
|
|
|
describe("Initialize") { |
|
|
|
static IZ_JoystickState state[PLAYERS]; |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(SDL_memcpy); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(SDL_NumJoysticks); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(SDL_JoystickOpen); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_putl); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_getl); |
|
|
|
} |
|
|
|
|
|
|
|
it("sets initial state") { |
|
|
|
IZ_JoystickInitialize("config.ini", &state); |
|
|
|
|
|
|
|
check(mock_is_called(SDL_memcpy), "Initial state not loaded."); |
|
|
|
check(mock_is_called(SDL_NumJoysticks), "Connected joysticks not checked."); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls load method") { |
|
|
|
mock_set_expected_calls(ini_getl, ((CONTROLS - 4) + 2) * PLAYERS); |
|
|
|
|
|
|
|
IZ_JoystickInitialize("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls save method") { |
|
|
|
mock_set_expected_calls(ini_putl, ((CONTROLS - 4) + 2) * PLAYERS); |
|
|
|
|
|
|
|
IZ_JoystickInitialize("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
it("opens device handles") { |
|
|
|
mock_set_expected_calls(SDL_JoystickOpen, MOCK_OPEN_JOYSTICKS); |
|
|
|
|
|
|
|
IZ_JoystickInitialize("config.ini", &state); |
|
|
|
|
|
|
|
check( |
|
|
|
mock_get_expected_calls(SDL_JoystickOpen) == mock_get_actual_calls(SDL_JoystickOpen), |
|
|
|
"Call count mismatch for SDL_JoystickOpen() (expected %u, received %u).", |
|
|
|
mock_get_expected_calls(SDL_JoystickOpen), |
|
|
|
mock_get_actual_calls(SDL_JoystickOpen) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("HandleEvents") { |
|
|
|
static SDL_Event e; |
|
|
|
static IZ_JoystickState state[PLAYERS] = {}; |
|
|
@@ -289,9 +361,93 @@ spec("input") { |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("Teardown") { |
|
|
|
static SDL_Joystick device; |
|
|
|
static IZ_JoystickState state[PLAYERS] = {}; |
|
|
|
|
|
|
|
before_each() { |
|
|
|
for (u8 p = 0; p < PLAYERS; p += 1) { |
|
|
|
state[p].device = &device; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(SDL_JoystickClose); |
|
|
|
} |
|
|
|
|
|
|
|
it("closes opened devices") { |
|
|
|
mock_set_expected_calls(SDL_JoystickClose, PLAYERS); |
|
|
|
|
|
|
|
IZ_JoystickTeardown(&state); |
|
|
|
|
|
|
|
check( |
|
|
|
mock_get_expected_calls(SDL_JoystickClose) == mock_get_actual_calls(SDL_JoystickClose), |
|
|
|
"Call count mismatch for SDL_JoystickClose() (expected %u, received %u).", |
|
|
|
mock_get_expected_calls(SDL_JoystickClose), |
|
|
|
mock_get_actual_calls(SDL_JoystickClose) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("keyboard") { |
|
|
|
describe("Initialize") { |
|
|
|
static IZ_KeyboardState state[PLAYERS] = {}; |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(SDL_memcpy); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_gets); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_puts); |
|
|
|
} |
|
|
|
|
|
|
|
before_each() { |
|
|
|
for (u8 p = 0; p < PLAYERS; p += 1) { |
|
|
|
for (u8 i = 0; i < CONTROLS; i += 1) { |
|
|
|
state[p].config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_STATE[p].config.control_mapping[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
it("sets initial state") { |
|
|
|
IZ_KeyboardInitialize("config.ini", &state); |
|
|
|
|
|
|
|
check(mock_is_called(SDL_memcpy), "Initial state not loaded."); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls load method") { |
|
|
|
mock_set_expected_calls(ini_gets, CONTROLS * PLAYERS); |
|
|
|
|
|
|
|
IZ_KeyboardInitialize("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls save method") { |
|
|
|
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); |
|
|
|
|
|
|
|
IZ_KeyboardInitialize("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("HandleEvents") { |
|
|
|
static SDL_Event e; |
|
|
|
static IZ_KeyboardState state[PLAYERS] = {}; |
|
|
@@ -359,4 +515,197 @@ spec("input") { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("midi") { |
|
|
|
describe("Initialize") { |
|
|
|
static IZ_MIDIInputState state[PLAYERS]; |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(SDL_memcpy); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(Pm_CountDevices); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(Pm_OpenInput); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_puts); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_gets); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_putl); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_getl); |
|
|
|
} |
|
|
|
|
|
|
|
it("sets initial state") { |
|
|
|
IZ_MIDIInputInitialize("config.ini", &state); |
|
|
|
|
|
|
|
check(mock_is_called(SDL_memcpy), "Initial state not loaded."); |
|
|
|
check(mock_is_called(Pm_CountDevices), "Connected MIDI devices not checked."); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls load method") { |
|
|
|
mock_set_expected_calls(ini_gets, CONTROLS * PLAYERS); |
|
|
|
mock_set_expected_calls(ini_getl, 2 * PLAYERS); |
|
|
|
|
|
|
|
IZ_MIDIInputInitialize("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls save method") { |
|
|
|
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); |
|
|
|
mock_set_expected_calls(ini_putl, 2 * PLAYERS); |
|
|
|
|
|
|
|
IZ_MIDIInputInitialize("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
it("opens device handles") { |
|
|
|
mock_set_expected_calls(Pm_OpenInput, MOCK_OPEN_JOYSTICKS); |
|
|
|
|
|
|
|
IZ_MIDIInputInitialize("config.ini", &state); |
|
|
|
|
|
|
|
check( |
|
|
|
mock_get_expected_calls(Pm_OpenInput) == mock_get_actual_calls(Pm_OpenInput), |
|
|
|
"Call count mismatch for Pm_OpenInput() (expected %u, received %u).", |
|
|
|
mock_get_expected_calls(Pm_OpenInput), |
|
|
|
mock_get_actual_calls(Pm_OpenInput) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("SaveConfig") { |
|
|
|
static IZ_MIDIInputState state[PLAYERS]; |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_puts); |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(ini_putl); |
|
|
|
} |
|
|
|
|
|
|
|
it("calls save method") { |
|
|
|
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); |
|
|
|
mock_set_expected_calls(ini_putl, 2 * PLAYERS); |
|
|
|
|
|
|
|
IZ_MIDIInputSaveConfig("config.ini", &state); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
|
|
|
|
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) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("HandleEvents") { |
|
|
|
static PmEvent e; |
|
|
|
static IZ_MIDIInputState state[PLAYERS] = {}; |
|
|
|
static IZ_Action action[PLAYERS] = {}; |
|
|
|
|
|
|
|
for (u8 p = 0; p < PLAYERS; p += 1) { |
|
|
|
describe("on player %u", p) { |
|
|
|
for (u8 i = 0; i < CONTROLS; i += 1) { |
|
|
|
it("handles %s action activation", ACTION_NAMES[i]) { |
|
|
|
e.message = IZ_MIDI_NOTE_ON | (IZ_DEFAULT_MIDI_INPUT_STATE[p].config.control_mapping[i] << 8); |
|
|
|
state[p].config.control_mapping[i] = IZ_DEFAULT_MIDI_INPUT_STATE[p].config.control_mapping[i]; |
|
|
|
action[p] = 0; |
|
|
|
|
|
|
|
IZ_MIDIInputHandleEvents(e, &state, &action); |
|
|
|
check( |
|
|
|
action[p] == (0x1 << i), |
|
|
|
"Action not set." |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
it("handles %s action deactivation", ACTION_NAMES[i]) { |
|
|
|
e.message = IZ_MIDI_NOTE_OFF | (IZ_DEFAULT_MIDI_INPUT_STATE[p].config.control_mapping[i] << 8); |
|
|
|
state[p].config.control_mapping[i] = IZ_DEFAULT_MIDI_INPUT_STATE[p].config.control_mapping[i]; |
|
|
|
action[p] = ~0; |
|
|
|
|
|
|
|
IZ_MIDIInputHandleEvents(e, &state, &action); |
|
|
|
check( |
|
|
|
!(action[p] & (0x1 << i)), |
|
|
|
"Action not unset." |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
describe("Teardown") { |
|
|
|
static PmStream* stream; |
|
|
|
static IZ_MIDIInputState state[PLAYERS] = {}; |
|
|
|
|
|
|
|
before_each() { |
|
|
|
for (u8 p = 0; p < PLAYERS; p += 1) { |
|
|
|
state[p].stream = &stream; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
after_each() { |
|
|
|
mock_reset(Pm_Close); |
|
|
|
} |
|
|
|
|
|
|
|
it("closes opened devices") { |
|
|
|
mock_set_expected_calls(Pm_Close, PLAYERS); |
|
|
|
|
|
|
|
IZ_MIDIInputTeardown(&state); |
|
|
|
|
|
|
|
check( |
|
|
|
mock_get_expected_calls(Pm_Close) == mock_get_actual_calls(Pm_Close), |
|
|
|
"Call count mismatch for Pm_Close() (expected %u, received %u).", |
|
|
|
mock_get_expected_calls(Pm_Close), |
|
|
|
mock_get_actual_calls(Pm_Close) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |