Browse Source

Update tests

Ensure correct arguments are passed.
feature/data-structs
TheoryOfNekomata 2 years ago
parent
commit
627e2a8f28
3 changed files with 9 additions and 62 deletions
  1. +0
    -12
      src/packages/game/__mocks__/IZ_config.mock.h
  2. +7
    -34
      src/packages/game/input/input.test.c
  3. +2
    -16
      src/packages/game/output/output.test.c

+ 0
- 12
src/packages/game/__mocks__/IZ_config.mock.h View File

@@ -1,12 +0,0 @@
#ifndef IZ_CONFIG_MOCK_H
#define IZ_CONFIG_MOCK_H

#include "../../test/IZ_test.h"

mock(IZ_GetConfigPath) void IZ_GetConfigPath(char* config_path, size_t string_size) {
const char dummy_path[] = "test-config.ini";
memcpy_s(config_path, string_size, dummy_path, 128);
mock_return(IZ_GetConfigPath);
}

#endif

+ 7
- 34
src/packages/game/input/input.test.c View File

@@ -1,15 +1,14 @@
#include "../../../__mocks__/SDL_keyboard.mock.h" #include "../../../__mocks__/SDL_keyboard.mock.h"
#include "../../../__mocks__/SDL_joystick.mock.h" #include "../../../__mocks__/SDL_joystick.mock.h"
#include "../../../__mocks__/minIni.mock.h" #include "../../../__mocks__/minIni.mock.h"
#include "../__mocks__/IZ_config.mock.h"
#include "IZ_keyboard.h" #include "IZ_keyboard.h"
#include "IZ_joystick.h" #include "IZ_joystick.h"


short int GenerateAxisValueWithinThreshold(short int threshold) {
int16_t GenerateAxisValueWithinThreshold(uint16_t threshold) {
return rand() % threshold; return rand() % threshold;
} }


short int GenerateAxisValueOutsideThreshold(short int threshold) {
int16_t GenerateAxisValueOutsideThreshold(uint16_t threshold) {
return threshold + (rand() % (RAND_MAX - threshold - 1)) + 1; return threshold + (rand() % (RAND_MAX - threshold - 1)) + 1;
} }


@@ -23,7 +22,7 @@ spec("input") {
describe("on axis motion events") { describe("on axis motion events") {
before_each() { before_each() {
e.type = SDL_JOYAXISMOTION; e.type = SDL_JOYAXISMOTION;
state.config.axis_threshold = 8000;
state.config.axis_threshold = 8000u;
} }


describe("on primary horizontal direction") { describe("on primary horizontal direction") {
@@ -259,10 +258,6 @@ spec("input") {
describe("LoadJoystickConfig") { describe("LoadJoystickConfig") {
static IZ_JoystickConfig config; static IZ_JoystickConfig config;


after_each() {
mock_reset(IZ_GetConfigPath);
}

after_each() { after_each() {
mock_reset(ini_getl); mock_reset(ini_getl);
} }
@@ -270,12 +265,7 @@ spec("input") {
it("calls load method") { it("calls load method") {
mock_set_expected_calls(ini_getl, CONTROLS - 4 + 1); mock_set_expected_calls(ini_getl, CONTROLS - 4 + 1);


IZ_LoadJoystickConfig(&config, 0);

check(
mock_is_called(IZ_GetConfigPath),
"SDL_GetBasePath() not called."
);
IZ_LoadJoystickConfig("config.ini", &config, 0);


check( check(
mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl), mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl),
@@ -289,10 +279,6 @@ spec("input") {
describe("SaveJoystickConfig") { describe("SaveJoystickConfig") {
static IZ_JoystickConfig config; static IZ_JoystickConfig config;


after_each() {
mock_reset(IZ_GetConfigPath);
}

after_each() { after_each() {
mock_reset(ini_putl); mock_reset(ini_putl);
} }
@@ -306,7 +292,7 @@ spec("input") {
it("calls save method") { it("calls save method") {
mock_set_expected_calls(ini_putl, CONTROLS - 4 + 1); mock_set_expected_calls(ini_putl, CONTROLS - 4 + 1);


IZ_SaveJoystickConfig(&config, 0);
IZ_SaveJoystickConfig("config.ini", &config, 0);


check( check(
mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl),
@@ -356,10 +342,6 @@ spec("input") {
describe("LoadKeyboardConfig") { describe("LoadKeyboardConfig") {
static IZ_KeyboardConfig config; static IZ_KeyboardConfig config;


after_each() {
mock_reset(IZ_GetConfigPath);
}

after_each() { after_each() {
mock_reset(ini_gets); mock_reset(ini_gets);
} }
@@ -367,12 +349,7 @@ spec("input") {
it("calls load method") { it("calls load method") {
mock_set_expected_calls(ini_gets, CONTROLS); mock_set_expected_calls(ini_gets, CONTROLS);


IZ_LoadKeyboardConfig(&config, 0);

check(
mock_is_called(IZ_GetConfigPath),
"SDL_GetBasePath() not called."
);
IZ_LoadKeyboardConfig("config.ini", &config, 0);


check( check(
mock_get_expected_calls(ini_gets) == mock_get_actual_calls(ini_gets), mock_get_expected_calls(ini_gets) == mock_get_actual_calls(ini_gets),
@@ -386,10 +363,6 @@ spec("input") {
describe("SaveKeyboardConfig") { describe("SaveKeyboardConfig") {
static IZ_KeyboardConfig config; static IZ_KeyboardConfig config;


after_each() {
mock_reset(IZ_GetConfigPath);
}

after_each() { after_each() {
mock_reset(ini_puts); mock_reset(ini_puts);
} }
@@ -403,7 +376,7 @@ spec("input") {
it("calls save method") { it("calls save method") {
mock_set_expected_calls(ini_puts, CONTROLS); mock_set_expected_calls(ini_puts, CONTROLS);


IZ_SaveKeyboardConfig(&config, 0);
IZ_SaveKeyboardConfig("config.ini", &config, 0);


check( check(
mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts), mock_get_expected_calls(ini_puts) == mock_get_actual_calls(ini_puts),


+ 2
- 16
src/packages/game/output/output.test.c View File

@@ -1,5 +1,4 @@
#include "../../../__mocks__/minIni.mock.h" #include "../../../__mocks__/minIni.mock.h"
#include "../__mocks__/IZ_config.mock.h"
#include "IZ_video.h" #include "IZ_video.h"


spec("output") { spec("output") {
@@ -7,10 +6,6 @@ spec("output") {
describe("LoadVideoConfig") { describe("LoadVideoConfig") {
static IZ_VideoConfig config; static IZ_VideoConfig config;


after_each() {
mock_reset(IZ_GetConfigPath);
}

after_each() { after_each() {
mock_reset(ini_getl); mock_reset(ini_getl);
} }
@@ -18,12 +13,7 @@ spec("output") {
it("calls load method") { it("calls load method") {
mock_set_expected_calls(ini_getl, 3); mock_set_expected_calls(ini_getl, 3);


IZ_LoadVideoConfig(&config);

check(
mock_is_called(IZ_GetConfigPath),
"SDL_GetBasePath() not called."
);
IZ_LoadVideoConfig("config.ini", &config);


check( check(
mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl), mock_get_expected_calls(ini_getl) == mock_get_actual_calls(ini_getl),
@@ -37,10 +27,6 @@ spec("output") {
describe("SaveVideoConfig") { describe("SaveVideoConfig") {
static IZ_VideoConfig config; static IZ_VideoConfig config;


after_each() {
mock_reset(IZ_GetConfigPath);
}

after_each() { after_each() {
mock_reset(ini_putl); mock_reset(ini_putl);
} }
@@ -54,7 +40,7 @@ spec("output") {
it("calls save method") { it("calls save method") {
mock_set_expected_calls(ini_putl, 3); mock_set_expected_calls(ini_putl, 3);


IZ_SaveVideoConfig(&config);
IZ_SaveVideoConfig("config.ini", &config);


check( check(
mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl), mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl),


Loading…
Cancel
Save