Add unit test for gameresource.c

This commit is contained in:
kichikuou
2020-07-11 19:12:45 +09:00
parent f2fbf54c32
commit 3d70d00bce
10 changed files with 139 additions and 10 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -44,5 +44,5 @@ jobs:
make
- name: Test
run: ctest
run: ctest --output-on-failure
working-directory: out/debug
+1 -1
View File
@@ -27,7 +27,7 @@
Midi : MIDIデータ
Data : その他データ
Save : セーブデータ
Resouce : リソースファイル(マウスカーソル形状)
Resource : リソースファイル(マウスカーソル形状)
Ain : DLL とその関数の情報のかかれた System39.ain
BGM : BGMデータ(エスカレイヤー以降のBGMデータファイル)
WAI : PCMデータの追加情報 (mixer channel 情報等)
+4
View File
@@ -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
+4 -3
View File
@@ -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)
+1 -1
View File
@@ -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__ */
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2020 <KichikuouChrome@gmail.com>
*
* 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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 <KichikuouChrome@gmail.com>
*
* 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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
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;
}
+22
View File
@@ -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
+2 -2
View File
@@ -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);