mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
Unit testing for QFS_CompressPath
This commit is contained in:
parent
05c57f219d
commit
550b094b93
2 changed files with 54 additions and 0 deletions
|
@ -41,4 +41,11 @@ libQFutil_la_SOURCES= \
|
|||
qfplist.c quakefs.c quakeio.c riff.c script.c sizebuf.c string.c sys.c \
|
||||
va.c ver_check.c wad.c wadfile.c zone.c $(fnmatch) $(getopt)
|
||||
|
||||
check_PROGRAMS=test-qfs
|
||||
|
||||
test_qfs_SOURCES=test-qfs.c
|
||||
test_qfs_LDADD=$(builddir)/libQFutil.la
|
||||
test_qfs_DEPENDENCIES=$(builddir)/libQFutil.la
|
||||
|
||||
EXTRA_DIST= $(fnmatch_src) $(getopt_src)
|
||||
TESTS=$(check_PROGRAMS)
|
||||
|
|
47
libs/util/test-qfs.c
Normal file
47
libs/util/test-qfs.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include "QF/quakefs.h"
|
||||
|
||||
struct {
|
||||
const char *path;
|
||||
const char *expect;
|
||||
} path_tests [] = {
|
||||
{"", ""},
|
||||
{"/", "/"},
|
||||
{"\\", "/"},
|
||||
{".", ""},
|
||||
{"./", ""},
|
||||
{"/.", "/"},
|
||||
{"..", ".."},
|
||||
{"/..", "/"},
|
||||
{"foo/..", ""},
|
||||
{"foo/bar/..", "foo"},
|
||||
{"../foo/..", ".."},
|
||||
{"\\blah\\../foo/..\\baz/.\\x", "/baz/x"},
|
||||
};
|
||||
#define num_path_tests (sizeof (path_tests) / sizeof (path_tests[0]))
|
||||
|
||||
int
|
||||
main (int argc, const char **argv)
|
||||
{
|
||||
size_t i;
|
||||
int res = 0;
|
||||
|
||||
for (i = 0; i < num_path_tests; i++) {
|
||||
char *cpath = QFS_CompressPath (path_tests[i].path);
|
||||
if (strcmp (cpath, path_tests[i].expect)) {
|
||||
fprintf (stderr, "FAIL: (%zd) \"%s\" -> \"%s\", got \"%s\"\n", i,
|
||||
path_tests[i].path, path_tests[i].expect, cpath);
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
Loading…
Reference in a new issue