Browse Source

Organize tests

Ensure one type of test can only be handled at a time.
master
TheoryOfNekomata 2 years ago
parent
commit
0ae822976a
5 changed files with 75 additions and 72 deletions
  1. +1
    -1
      CMakeLists.txt
  2. +4
    -3
      src/packages/game/input/IZ_joystick.c
  3. +2
    -2
      src/packages/game/input/IZ_keyboard.c
  4. +0
    -66
      src/packages/game/output/IZ_video.test.c
  5. +68
    -0
      src/packages/game/output/output.test.c

+ 1
- 1
CMakeLists.txt View File

@@ -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(


+ 4
- 3
src/packages/game/input/IZ_joystick.c View File

@@ -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;
}
}
}


+ 2
- 2
src/packages/game/input/IZ_keyboard.c View File

@@ -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;
}
}
}


+ 0
- 66
src/packages/game/output/IZ_video.test.c View File

@@ -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)
);
}
}
}

+ 68
- 0
src/packages/game/output/output.test.c View File

@@ -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)
);
}
}
}
}

Loading…
Cancel
Save