diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index fa52345..eacca14 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -25,7 +25,7 @@ jobs: make - name: Test - run: ctest + run: ctest --output-on-failure working-directory: out/${{ matrix.build-type }} build-x11: @@ -43,5 +43,5 @@ jobs: make - name: Test - run: ctest + run: ctest --output-on-failure working-directory: out diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2826769..8234f9a 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -44,5 +44,5 @@ jobs: make - name: Test - run: ctest + run: ctest --output-on-failure working-directory: out/debug diff --git a/doc/GRFMT.TXT b/doc/GRFMT.TXT index e51327d..7ff16db 100644 --- a/doc/GRFMT.TXT +++ b/doc/GRFMT.TXT @@ -27,7 +27,7 @@ Midi : MIDIデータ Data : その他データ Save : セーブデータ - Resouce : リソースファイル(マウスカーソル形状) + Resource : リソースファイル(マウスカーソル形状) Ain : DLL とその関数の情報のかかれた System39.ain BGM : BGMデータ(エスカレイヤー以降のBGMデータファイル) WAI : PCMデータの追加情報 (mixer channel 情報等) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d32d70e..3424231 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -105,6 +105,10 @@ else() # non-emscripten, non-android endif() install(TARGETS xsystem35 RUNTIME DESTINATION bin) + + add_executable(src_tests src_tests.c gameresource_test.c gameresource.c) + add_test(NAME src_tests COMMAND src_tests) + configure_file(testdata/test.gr ${CMAKE_CURRENT_BINARY_DIR}/testdata/test.gr COPYONLY) endif() # FIXME: set up dependency for xsystem35 on this diff --git a/src/gameresource.c b/src/gameresource.c index 4967f8e..f9a94fe 100644 --- a/src/gameresource.c +++ b/src/gameresource.c @@ -68,7 +68,7 @@ static boolean initFromDir(GameResource *gr) { getcwd(cwd, 255); DIR *dir = opendir("."); if(!dir) - SYSERROR("Game Resouce File open failed\n"); + SYSERROR("Game Resource File open failed\n"); struct dirent* d; while ((d = readdir(dir))) { @@ -128,6 +128,7 @@ static boolean initFromFile(GameResource *gr, FILE *fp, const char *gr_fname) { while (fgets(line, 255, fp) != NULL) { linecnt++; if (line[0] == '#') continue; + path[0] = '\0'; sscanf(line, "%s %[^\n]", key, path); if (path[0] == '\0') continue; trimRight(path); @@ -184,11 +185,11 @@ static boolean initFromFile(GameResource *gr, FILE *fp, const char *gr_fname) { return TRUE; errexit: - SYSERROR("Illigal resouce at line(%d) file<%s>\n", linecnt, gr_fname); + SYSERROR("Illigal resource at line(%d) file<%s>\n", linecnt, gr_fname); return FALSE; } -boolean initGameResorce(GameResource *gr, const char *gr_fname) { +boolean initGameResource(GameResource *gr, const char *gr_fname) { memset(gr, 0, sizeof(GameResource)); FILE *fp = fopen(gr_fname, "r"); if (!fp) diff --git a/src/gameresource.h b/src/gameresource.h index 988a096..011d0a7 100644 --- a/src/gameresource.h +++ b/src/gameresource.h @@ -40,6 +40,6 @@ typedef struct { char *alk[10]; } GameResource; -boolean initGameResorce(GameResource *gr, const char *gr_fname); +boolean initGameResource(GameResource *gr, const char *gr_fname); #endif /* !__GAMERESOURCE_H__ */ diff --git a/src/gameresource_test.c b/src/gameresource_test.c new file mode 100644 index 0000000..b5dae7c --- /dev/null +++ b/src/gameresource_test.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2020 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#undef NDEBUG +#include "gameresource.h" +#include +#include +#include +#include + +void gameresource_test(void) { +#ifdef _WIN32 + _putenv("HOME=/home/kichikuou"); +#else + setenv("HOME", "/home/kichikuou", 1); +#endif + + GameResource gr; + assert(initGameResource(&gr, "testdata/test.gr")); + + assert(gr.cnt[DRIFILE_SCO] == 1); + assert(strcmp(gr.game_fname[DRIFILE_SCO][0], "fooSA.ALD") == 0); + assert(gr.cnt[DRIFILE_CG] == 2); + assert(strcmp(gr.game_fname[DRIFILE_CG][0], "fooGA.ALD") == 0); + assert(strcmp(gr.game_fname[DRIFILE_CG][1], "fooGB.ALD") == 0); + assert(gr.cnt[DRIFILE_WAVE] == 26); + assert(strcmp(gr.game_fname[DRIFILE_WAVE][0], "fooWA.ALD") == 0); + for (int i = 1; i <= 24; i++) + assert(gr.game_fname[DRIFILE_WAVE][i] == NULL); + assert(strcmp(gr.game_fname[DRIFILE_WAVE][25], "fooWZ.ALD") == 0); + assert(gr.cnt[DRIFILE_MIDI] == 3); + assert(strcmp(gr.game_fname[DRIFILE_MIDI][2], "fooMC.ALD") == 0); + assert(strcmp(gr.game_fname[DRIFILE_DATA][0], "file name with whitespaces") == 0); + assert(strcmp(gr.game_fname[DRIFILE_RSC][0], "this line has whitespaces at end of line") == 0); + assert(strcmp(gr.game_fname[DRIFILE_BGM][0], "/path/to/fooBA.ALD") == 0); + + assert(strcmp(gr.ain, "System39.ain") == 0); + assert(strcmp(gr.wai, "foo_WA.WAI") == 0); + assert(strcmp(gr.bgi, "foo_BA.BGI") == 0); + assert(strcmp(gr.sact01, "SACTEFAM.KLD") == 0); + assert(strcmp(gr.init, "System39.ini") == 0); + assert(strcmp(gr.alk[0], "0.alk") == 0); + for (int i = 1; i <= 8; i++) + assert(gr.alk[i] == NULL); + assert(strcmp(gr.alk[9], "9.alk") == 0); + + assert(strcmp(gr.save_fname[0], "/home/kichikuou/save/foo_sa.asd") == 0); + assert(strcmp(gr.save_fname[25], "/tmp/foo_sz.asd") == 0); + // save_path is determined based on save_fname[0]. + assert(strcmp(gr.save_path, "/home/kichikuou/save") == 0); +} diff --git a/src/src_tests.c b/src/src_tests.c new file mode 100644 index 0000000..6cfc004 --- /dev/null +++ b/src/src_tests.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include +#include +#include + +void gameresource_test(void); + +void sys_error(char *format, ...) { + va_list args; + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + exit(1); +} + +int main() { + gameresource_test(); + return 0; +} diff --git a/src/testdata/test.gr b/src/testdata/test.gr new file mode 100644 index 0000000..04c7f49 --- /dev/null +++ b/src/testdata/test.gr @@ -0,0 +1,22 @@ +# This line is a comment. + +ScenarioA fooSA.ALD +GraphicsA fooGA.ALD +GraphicsB fooGB.ALD +WaveA fooWA.ALD +WaveZ fooWZ.ALD +MidiC fooMC.ALD +DataA file name with whitespaces + ResourceA this line has whitespaces at end of line +BGMA /path/to/fooBA.ALD + +Ain System39.ain +WAIA foo_WA.WAI +BGIA foo_BA.BGI +SACT01 SACTEFAM.KLD +Init System39.ini +ALK00 0.alk +ALK09 9.alk + +SaveA ~/save/foo_sa.asd +SaveZ /tmp/foo_sz.asd diff --git a/src/xsystem35.c b/src/xsystem35.c index cb4a9e5..53e83e8 100644 --- a/src/xsystem35.c +++ b/src/xsystem35.c @@ -120,7 +120,7 @@ static void sys35_usage(boolean verbose) { } puts("Usage: xsystem35 [OPTIONS]\n"); puts("OPTIONS"); - puts(" -gamefile file : set game resouce file to 'file'"); + puts(" -gamefile file : set game resource file to 'file'"); puts(" -no-shm : don't use MIT-SHM (use in another display)"); puts(" -devcd device : set cdrom device name to 'device'"); puts(" -devmidi device: set midi device name to 'device'"); @@ -626,7 +626,7 @@ int main(int argc, char **argv) { } #endif GameResource gr; - if (!initGameResorce(&gr, gameResourceFile)) + if (!initGameResource(&gr, gameResourceFile)) sys35_usage(TRUE); registerGameFiles(&gr);