Browse Source

Add unit tests

Use bdd-for-c for unit tests.
master
TheoryOfNekomata 2 years ago
parent
commit
d320b66402
3 changed files with 69 additions and 9 deletions
  1. +38
    -9
      CMakeLists.txt
  2. +1
    -0
      dependencies.txt
  3. +30
    -0
      src/packages/game-test/config/IZ_config.c

+ 38
- 9
CMakeLists.txt View File

@@ -8,6 +8,7 @@ set(CMAKE_C_STANDARD 11)
include_directories(
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/include"
"${PROJECT_SOURCE_DIR}/dependencies/minIni/dev"
"${PROJECT_SOURCE_DIR}/dependencies/bdd-for-c"
)

if (WIN32)
@@ -18,18 +19,46 @@ if (WIN32)
endif ()
endif ()

link_directories("${PROJECT_SOURCE_DIR}/dependencies/SDL2/lib/${PROJECT_ARCH}")
link_directories(
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/lib/${PROJECT_ARCH}"
)

add_executable(
game
dependencies/minIni/dev/minIni.h
dependencies/minIni/dev/minIni.c
src/packages/game/config/IZ_config.h
src/packages/game/config/IZ_config.c
src/packages/game/IZ_common.h
src/packages/game/IZ_action.h
src/packages/game/IZ_app.h
src/packages/game/IZ_app.c
src/packages/game/main.c
)
target_link_libraries(
game
SDL2main
SDL2
)

add_executable(
izanagi
dependencies/minIni/dev/minIni.h
dependencies/minIni/dev/minIni.c
src/packages/game/main.c
src/packages/game/config/IZ_config.h src/packages/game/config/IZ_config.c src/packages/game/IZ_common.h src/packages/game/IZ_action.h src/packages/game/IZ_app.c src/packages/game/IZ_app.h)
target_link_libraries(izanagi SDL2main SDL2)
game-test
dependencies/minIni/dev/minIni.h
dependencies/minIni/dev/minIni.c
src/packages/game/config/IZ_config.h
src/packages/game/config/IZ_config.c
dependencies/bdd-for-c/bdd-for-c.h
src/packages/game-test/config/IZ_config.c
)
target_link_libraries(
game-test
SDL2main
SDL2
)

if (WIN32)
add_custom_command(TARGET izanagi POST_BUILD
add_custom_command(TARGET game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/lib/${PROJECT_ARCH}/SDL2.dll" # <--this is in-file
$<TARGET_FILE_DIR:izanagi>) # <--this is out-file path
$<TARGET_FILE_DIR:game>) # <--this is out-file path
endif ()

+ 1
- 0
dependencies.txt View File

@@ -1 +1,2 @@
https://github.com/compuphase/minIni
https://github.com/grassator/bdd-for-c

+ 30
- 0
src/packages/game-test/config/IZ_config.c View File

@@ -0,0 +1,30 @@
#include "bdd-for-c.h"
#include "../../game/config/IZ_config.h"

spec("config") {
describe("LoadConfig") {
static IZ_Config config;

it("should load default config values") {
IZ_LoadConfig(&config);

check(
config.video.width == 640,
"Default value for Video.Width is not loaded."
);
check(
config.video.height == 480,
"Default value for Video.Height is not loaded."
);
check(
config.video.max_fps == 30,
"Default value for Video.MaxFps is not loaded."
);

check(
config.input.gamepad_axis_threshold == 8000,
"Default value for Input.GamepadAxisThreshold is not loaded."
);
}
}
}

Loading…
Cancel
Save