Преглед изворни кода

Fix tests for macOS

Properly add SDL mocks for macOS.
master
TheoryOfNekomata пре 1 година
родитељ
комит
2976aa757f
4 измењених фајлова са 120 додато и 25 уклоњено
  1. +6
    -2
      CMakeLists.txt
  2. +89
    -0
      __mocks__/subprojects/ini-config/ini-config.mock.h
  3. +1
    -0
      __tests__/src/packages/game/data.test.c
  4. +24
    -23
      __tests__/src/packages/game/input.test.c

+ 6
- 2
CMakeLists.txt Прегледај датотеку

@@ -236,13 +236,18 @@ add_executable(
subprojects/bdd-for-c/bdd-for-c.h
subprojects/bdd-for-c-mocks/bdd-for-c-mocks.h

__mocks__/subprojects/minIni/minIni.mock.h
subprojects/ini-config/ini-config.h
__mocks__/subprojects/ini-config/ini-config.mock.h

__mocks__/subprojects/SDL/SDL_keyboard.mock.h
__mocks__/subprojects/SDL/SDL_events.mock.h
__mocks__/subprojects/SDL/SDL_joystick.mock.h
__mocks__/subprojects/SDL/SDL_stdinc.mock.h
__mocks__/subprojects/portmidi/portmidi.mock.h

src/packages/config/IZ_config_guid.h
src/packages/config/IZ_config_guid.c

src/packages/game/input/IZ_keyboard.h
src/packages/game/input/IZ_keyboard.c

@@ -262,7 +267,6 @@ add_executable(
__mocks__/src/packages/stdinc/IZ_stdlib.mock.h

__tests__/src/packages/game/input.test.c
__mocks__/subprojects/ini-config/ini-config.mock.h
)

target_link_libraries(


+ 89
- 0
__mocks__/subprojects/ini-config/ini-config.mock.h Прегледај датотеку

@@ -12,4 +12,93 @@ mock(INI_ConfigSave) INI_ConfigSaveResult INI_ConfigSave(INI_ConfigItem _item[],
mock_return(INI_ConfigSave) 0;
}

mock(INI_ConfigGetCommandlineOption) const char* INI_ConfigGetCommandlineOption(uint8_t _argc, const char* _argv[], const char* _val) {
mock_return(INI_ConfigGetCommandlineOption) "";
}

mock(INI_ConfigLoadU8) void INI_ConfigLoadU8(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadU8);
}

mock(INI_ConfigLoadU16) void INI_ConfigLoadU16(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadU16);
}

mock(INI_ConfigLoadU32) void INI_ConfigLoadU32(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadU32);
}

mock(INI_ConfigLoadI8) void INI_ConfigLoadI8(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadI8);
}

mock(INI_ConfigLoadI16) void INI_ConfigLoadI16(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadI16);
}

mock(INI_ConfigLoadI32) void INI_ConfigLoadI32(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadI32);
}

mock(INI_ConfigLoadString) void INI_ConfigLoadString(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigLoadString);
}

mock(INI_ConfigSaveU8) INI_ConfigSaveItemResult INI_ConfigSaveU8(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveU8) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigSaveU16) INI_ConfigSaveItemResult INI_ConfigSaveU16(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveU16) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigSaveU32) INI_ConfigSaveItemResult INI_ConfigSaveU32(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveU32) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigSaveI8) INI_ConfigSaveItemResult INI_ConfigSaveI8(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveI8) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigSaveI16) INI_ConfigSaveItemResult INI_ConfigSaveI16(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveI16) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigSaveI32) INI_ConfigSaveItemResult INI_ConfigSaveI32(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveI32) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigSaveString) INI_ConfigSaveItemResult INI_ConfigSaveString(INI_ConfigItem* _item, const char* _config_path) {
mock_return(INI_ConfigSaveString) INI_CONFIG_SAVE_ITEM_OK;
}

mock(INI_ConfigOverrideU8) void INI_ConfigOverrideU8(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideU8);
}

mock(INI_ConfigOverrideU16) void INI_ConfigOverrideU16(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideU16);
}

mock(INI_ConfigOverrideU32) void INI_ConfigOverrideU32(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideU32);
}

mock(INI_ConfigOverrideI8) void INI_ConfigOverrideI8(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideI8);
}

mock(INI_ConfigOverrideI16) void INI_ConfigOverrideI16(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideI16);
}

mock(INI_ConfigOverrideI32) void INI_ConfigOverrideI32(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideI32);
}

mock(INI_ConfigOverrideString) void INI_ConfigOverrideString(INI_ConfigItem* _item, uint8_t _argc, const char* _argv[]) {
mock_return(INI_ConfigOverrideString);
}


#endif

+ 1
- 0
__tests__/src/packages/game/data.test.c Прегледај датотеку

@@ -1,3 +1,4 @@
#include <SDL.h>
#include <bdd-for-c.h>
#include <stdinc/IZ_stdlib.mock.h>
#include <common/IZ_common.h>


+ 24
- 23
__tests__/src/packages/game/input.test.c Прегледај датотеку

@@ -1,3 +1,4 @@
#include <SDL.h>
#include <bdd-for-c.h>
#include <subprojects/SDL/SDL_keyboard.mock.h>
#include <subprojects/SDL/SDL_joystick.mock.h>
@@ -37,11 +38,11 @@ spec("input") {
}

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

after_each() {
mock_reset(IZ_ConfigInitialize);
mock_reset(INI_ConfigInitialize);
}

it("sets initial state") {
@@ -54,13 +55,13 @@ spec("input") {
it("calls load method") {
IZ_JoystickInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL);

check(mock_is_called(IZ_ConfigInitialize), "Config load function not called.");
check(mock_is_called(INI_ConfigInitialize), "Config load function not called.");
}

it("calls save method") {
IZ_JoystickInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL);

check(mock_is_called(IZ_ConfigSave), "Config save function not called.");
check(mock_is_called(INI_ConfigSave), "Config save function not called.");
}

it("opens device handles") {
@@ -327,7 +328,7 @@ spec("input") {
static IZ_JoystickState state[IZ_PLAYERS];

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

before_each() {
@@ -341,7 +342,7 @@ spec("input") {
it("calls save method") {
IZ_JoystickSaveConfig(&state, IZ_CONFIG_GAME_PATH);

check(mock_is_called(IZ_ConfigSave), "Config save function not called.");
check(mock_is_called(INI_ConfigSave), "Config save function not called.");
}
}

@@ -383,11 +384,11 @@ spec("input") {
}

after_each() {
mock_reset(IZ_ConfigInitialize);
mock_reset(INI_ConfigInitialize);
}

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

before_each() {
@@ -407,13 +408,13 @@ spec("input") {
it("calls load method") {
IZ_KeyboardInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL);

check(mock_is_called(IZ_ConfigInitialize), "Config load function not called.");
check(mock_is_called(INI_ConfigInitialize), "Config load function not called.");
}

it("calls save method") {
IZ_KeyboardInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL);

check(mock_is_called(IZ_ConfigSave), "Config save function not called.");
check(mock_is_called(INI_ConfigSave), "Config save function not called.");
}
}

@@ -459,7 +460,7 @@ spec("input") {
static IZ_KeyboardState state[IZ_PLAYERS] = {};

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

before_each() {
@@ -473,7 +474,7 @@ spec("input") {
it("calls save method") {
IZ_KeyboardSaveConfig(&state, IZ_CONFIG_GAME_PATH);

check(mock_is_called(IZ_ConfigSave), "Config save function not called.");
check(mock_is_called(INI_ConfigSave), "Config save function not called.");
}
}
}
@@ -495,19 +496,19 @@ spec("input") {
}

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

after_each() {
mock_reset(IZ_ConfigInitialize);
mock_reset(INI_ConfigInitialize);
}

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

after_each() {
mock_reset(IZ_ConfigInitialize);
mock_reset(INI_ConfigInitialize);
}

it("sets initial state") {
@@ -520,13 +521,13 @@ spec("input") {
it("calls load method") {
IZ_MIDIInputInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL);

check(mock_is_called(IZ_ConfigInitialize), "Config load function not called.");
check(mock_is_called(INI_ConfigInitialize), "Config load function not called.");
}

it("calls save method") {
IZ_MIDIInputInitialize(&state, IZ_CONFIG_GAME_PATH, 0, NULL);

check(mock_is_called(IZ_ConfigSave), "Config save function not called.");
check(mock_is_called(INI_ConfigSave), "Config save function not called.");
}

it("opens device handles") {
@@ -547,17 +548,17 @@ spec("input") {
static IZ_MIDIInputState state[IZ_PLAYERS];

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

after_each() {
mock_reset(IZ_ConfigSave);
mock_reset(INI_ConfigSave);
}

it("calls save method") {
IZ_MIDIInputSaveConfig(&state, IZ_CONFIG_GAME_PATH);

check(mock_is_called(IZ_ConfigSave), "Config save function not called.");
check(mock_is_called(INI_ConfigSave), "Config save function not called.");
}
}

@@ -570,7 +571,7 @@ spec("input") {
describe("on player %u", p) {
for (u8 i = 0; i < IZ_CONTROLS; i += 1) {
it("handles %s action activation", IZ_ACTION_NAMES[i]) {
e.message = IZ_MIDI_NOTE_ON | (IZ_MIDI_INPUT_DEFAULT_STATE[p].config.control_mapping[i] << 8);
e.message = MIDI_MESSAGE_NOTEON | (IZ_MIDI_INPUT_DEFAULT_STATE[p].config.control_mapping[i] << 8);
state[p].config.control_mapping[i] = IZ_MIDI_INPUT_DEFAULT_STATE[p].config.control_mapping[i];
action[p] = 0;

@@ -582,7 +583,7 @@ spec("input") {
}

it("handles %s action deactivation", IZ_ACTION_NAMES[i]) {
e.message = IZ_MIDI_NOTE_OFF | (IZ_MIDI_INPUT_DEFAULT_STATE[p].config.control_mapping[i] << 8);
e.message = MIDI_MESSAGE_NOTEOFF | (IZ_MIDI_INPUT_DEFAULT_STATE[p].config.control_mapping[i] << 8);
state[p].config.control_mapping[i] = IZ_MIDI_INPUT_DEFAULT_STATE[p].config.control_mapping[i];
action[p] = ~0;



Loading…
Откажи
Сачувај