summaryrefslogtreecommitdiff
path: root/Build/source/texk/xdvik/tests
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/xdvik/tests')
-rw-r--r--Build/source/texk/xdvik/tests/Makefile.in120
-rw-r--r--Build/source/texk/xdvik/tests/Makefile.in.orig119
-rw-r--r--Build/source/texk/xdvik/tests/README29
-rw-r--r--Build/source/texk/xdvik/tests/depend.mk245
-rw-r--r--Build/source/texk/xdvik/tests/depend.mk.orig93
-rw-r--r--Build/source/texk/xdvik/tests/run_tests.c127
-rw-r--r--Build/source/texk/xdvik/tests/run_tests.h34
-rw-r--r--Build/source/texk/xdvik/tests/test1.c14
-rw-r--r--Build/source/texk/xdvik/tests/test_dl_list.c96
-rw-r--r--Build/source/texk/xdvik/tests/test_string_list.c75
-rw-r--r--Build/source/texk/xdvik/tests/test_string_utils.c431
-rw-r--r--Build/source/texk/xdvik/tests/test_util.c45
12 files changed, 1428 insertions, 0 deletions
diff --git a/Build/source/texk/xdvik/tests/Makefile.in b/Build/source/texk/xdvik/tests/Makefile.in
new file mode 100644
index 00000000000..2d5f4d580ea
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/Makefile.in
@@ -0,0 +1,120 @@
+# @configure_input@
+# Makefile for xdvik
+#
+# - 1999/05/08: janl: Removed submakes for libwww and kpathsea. That's what
+# the top makefile is for!
+#
+
+
+### NOTE: kpse_include paths must be relative to texk/xdvik, since that
+### is from where the configure is run!
+kpse_include ../make/paths.mk
+kpse_include ../make/library.mk
+kpse_include ../make/common.mk
+kpse_include ../make/programs.mk
+kpse_include xdvi_objects.mk
+
+kpathsea_parent = ../..
+
+x_cppflags=@X_CFLAGS@ @iconv_includes@
+x_ldflags=@X_LIBS@ @x_linker_options@ @iconv_libpath@
+x_pre_libs=@X_PRE_LIBS@
+x_extra_libs=@X_EXTRA_LIBS@ @iconv_libs@
+x_tool_libs=@x_tool_libs@
+x_xmu_lib=@x_xmu_lib@
+x_xpm_libs=@x_xpm_libs@
+x_ext_lib=@x_ext_lib@
+
+x_link = $(LDLIBT1) $(x_ldflags) $(x_tool_libs) $(x_xmu_lib) -lXt $(x_pre_libs) $(x_ext_lib) $(x_xpm_libs) -lX11 $(x_extra_libs)
+
+LDLIBT1=@LDLIBT1@
+LIBT1CPPFLAGS=@LIBT1CPPFLAGS@
+LIBT1DEP=@LIBT1DEP@
+LIBT1DIR = ../../../libs/t1lib
+LIBTYPE1DIR = $(LIBT1DIR)/../type1
+LIBT1SRCDIR = $(srcdir)/$(LIBT1DIR)
+
+LIBGUI=../gui/libgui.a
+LIBGUIDEP=$(LIBGUI)
+
+CPP = @CPP@
+RANLIB = @RANLIB@
+
+# Make `#include <X11/...>' and `-lX...' work.
+# This matches web2c (needed only for Metafont).
+x_cppflags = @X_CFLAGS@
+
+# Extra xdvi-specific compiler options.
+ps_def = @PS_DEF@ -DXSERVER_INFO
+prog_cflags = @XTRA_WARN_CFLAGS@ -I.. -I$(srcdir)/.. $(x_cppflags) $(ps_def)
+
+# Note: to be able to use one depend.mk file for both Motif/Xaw (which
+# is needed since only maintainers are supposed to invoke `make depend')
+# we include *all* object files and have tests for #ifdef MOTIF/XAW inside
+# the files.
+objects = \
+ test_dl_list.o \
+ test_string_list.o \
+ test_string_utils.o \
+ test_util.o \
+ run_tests.o
+
+
+# This are the files from xdvi needed to link the tests
+xdvi_objects = \
+ ../browser.o \
+ ../dvi-draw.o \
+ ../dvi-init.o \
+ ../dvisel.o \
+ ../encodings.o \
+ ../events.o \
+ ../exit-handlers.o \
+ ../filehist.o \
+ ../font-open.o \
+ ../gf.o \
+ ../hypertex.o \
+ ../image-magick.o \
+ ../mime.o \
+ ../my-snprintf.o \
+ ../my-vsnprintf.o \
+ ../pagehist.o \
+ ../pk.o \
+ ../print-internal.o \
+ ../psdps.o \
+ ../psgs.o \
+ ../psheader.o \
+ ../psnews.o \
+ ../read-mapfile.o \
+ ../search-internal.o \
+ ../special.o \
+ ../string-utils.o \
+ ../string_list.o \
+ ../tfmload.o \
+ ../util.o \
+ ../dl_list.o \
+ ../vf.o \
+ ../xdvi.o \
+ ../xserver-info.o \
+ ../x_util.o
+
+default all: run_tests
+
+run_tests: $(objects) $(xdvi_objects) $(LIBT1DEP) $(LIBGUIDEP)
+ $(kpathsea_link) $(objects) $(xdvi_objects) $(LIBGUI) $(x_link) $(LOADLIBES)
+
+test: run_tests
+ ./run_tests
+
+test_verbose: run_tests
+ ./run_tests -v
+
+kpse_include ../make/dist.mk
+kpse_include ../make/clean.mk
+
+clean::
+ rm -f *.o *.a
+
+c_auto_h_dir = ..
+kpse_include ../make/rdepend.mk
+kpse_include ./gui/depend.mk
+kpse_include ./tests/depend.mk
diff --git a/Build/source/texk/xdvik/tests/Makefile.in.orig b/Build/source/texk/xdvik/tests/Makefile.in.orig
new file mode 100644
index 00000000000..c4a03c1ecde
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/Makefile.in.orig
@@ -0,0 +1,119 @@
+# Makefile for xdvik
+#
+# - 1999/05/08: janl: Removed submakes for libwww and kpathsea. That's what
+# the top makefile is for!
+#
+
+
+### NOTE: ac_include paths must be relative to texk/xdvik, since that
+### is from where the configure is run!
+ac_include ../make/paths.mk
+ac_include ../make/library.mk
+ac_include ../make/common.mk
+ac_include ../make/programs.mk
+ac_include xdvi_objects.mk
+
+kpathsea_parent = ../..
+
+x_cppflags=@X_CFLAGS@ @iconv_includes@
+x_ldflags=@X_LIBS@ @x_linker_options@ @iconv_libpath@
+x_pre_libs=@X_PRE_LIBS@
+x_extra_libs=@X_EXTRA_LIBS@ @iconv_libs@
+x_tool_libs=@x_tool_libs@
+x_xmu_lib=@x_xmu_lib@
+x_xpm_libs=@x_xpm_libs@
+x_ext_lib=@x_ext_lib@
+
+x_link = $(LDLIBT1) $(x_ldflags) $(x_tool_libs) $(x_xmu_lib) -lXt $(x_pre_libs) $(x_ext_lib) $(x_xpm_libs) -lX11 $(x_extra_libs)
+
+LDLIBT1=@LDLIBT1@
+LIBT1CPPFLAGS=@LIBT1CPPFLAGS@
+LIBT1DEP=@LIBT1DEP@
+LIBT1DIR = ../../../libs/t1lib
+LIBTYPE1DIR = $(LIBT1DIR)/../type1
+LIBT1SRCDIR = $(srcdir)/$(LIBT1DIR)
+
+LIBGUI=../gui/libgui.a
+LIBGUIDEP=$(LIBGUI)
+
+CPP = @CPP@
+RANLIB = @RANLIB@
+
+# Make `#include <X11/...>' and `-lX...' work.
+# This matches web2c (needed only for Metafont).
+x_cppflags = @X_CFLAGS@
+
+# Extra xdvi-specific compiler options.
+ps_def = @PS_DEF@ -DXSERVER_INFO
+prog_cflags = @XTRA_WARN_CFLAGS@ -I.. -I$(srcdir)/.. $(x_cppflags) $(ps_def)
+
+# Note: to be able to use one depend.mk file for both Motif/Xaw (which
+# is needed since only maintainers are supposed to invoke `make depend')
+# we include *all* object files and have tests for #ifdef MOTIF/XAW inside
+# the files.
+objects = \
+ test_dl_list.o \
+ test_string_list.o \
+ test_string_utils.o \
+ test_util.o \
+ run_tests.o
+
+
+# This are the files from xdvi needed to link the tests
+xdvi_objects = \
+ ../browser.o \
+ ../dvi-draw.o \
+ ../dvi-init.o \
+ ../dvisel.o \
+ ../encodings.o \
+ ../events.o \
+ ../exit-handlers.o \
+ ../filehist.o \
+ ../font-open.o \
+ ../gf.o \
+ ../hypertex.o \
+ ../image-magick.o \
+ ../mime.o \
+ ../my-snprintf.o \
+ ../my-vsnprintf.o \
+ ../pagehist.o \
+ ../pk.o \
+ ../print-internal.o \
+ ../psdps.o \
+ ../psgs.o \
+ ../psheader.o \
+ ../psnews.o \
+ ../read-mapfile.o \
+ ../search-internal.o \
+ ../special.o \
+ ../string-utils.o \
+ ../string_list.o \
+ ../tfmload.o \
+ ../util.o \
+ ../dl_list.o \
+ ../vf.o \
+ ../xdvi.o \
+ ../xserver-info.o \
+ ../x_util.o
+
+default all: run_tests
+
+run_tests: $(objects) $(xdvi_objects) $(LIBT1DEP) $(LIBGUIDEP)
+ $(kpathsea_link) $(objects) $(xdvi_objects) $(LIBGUI) $(x_link) $(LOADLIBES)
+
+test: run_tests
+ ./run_tests
+
+test_verbose: run_tests
+ ./run_tests -v
+
+ac_include ../make/dist.mk
+ac_include ../make/clean.mk
+
+clean::
+ rm -f *.o *.a
+
+c_auto_h_dir = ..
+ac_include ../make/rdepend.mk
+ac_include ./gui/depend.mk
+ac_include ./tests/depend.mk
diff --git a/Build/source/texk/xdvik/tests/README b/Build/source/texk/xdvik/tests/README
new file mode 100644
index 00000000000..f92ceca8cf3
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/README
@@ -0,0 +1,29 @@
+1. To run the tests:
+
+$ cd texk/xdvik
+$ make test
+
+or
+
+$ make test_verbose
+
+to see more details on the tests.
+
+
+
+2. To add a new test:
+
+(a) Adding a test to an existing test file:
+ - create a new function "static Boolean <test_name>(int verbosity)"
+ - add a register_test() call to the "register_all_...()" method
+ at the bottom of the file:
+ "register_test(<test_name>, "<short test description>")
+
+(b) Adding a new test file, e.g. test_foo.c:
+ - add test_foo.o to the "objects" definition in Makefile.in
+ - add a declaration for "extern void register_all_from_test_foo()" to run_tests.h
+ - add a call to "register_all_from_test_foo()" to run_tests.c
+ - define "register_all_from_test_foo(void)" at the botton of test_foo.c and
+ add register_test() methods for all test functions in the file
+ (see the existing test files for examples).
+ - rerun "make depend" as described in the toplevel file "README_maintainers".
diff --git a/Build/source/texk/xdvik/tests/depend.mk b/Build/source/texk/xdvik/tests/depend.mk
new file mode 100644
index 00000000000..36f811c632a
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/depend.mk
@@ -0,0 +1,245 @@
+run_tests.o: run_tests.c \
+ run_tests.h \
+ ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-config.h \
+ ../xdvi-debug.h \
+ ../xdvi.h \
+ ../version.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h \
+ $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h \
+ $(kpathsea_srcdir)/lib.h \
+ $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h \
+ ../hypertex.h \
+ ../dvi-init.h \
+ ../special.h \
+ ../events.h \
+ ../string-utils.h \
+ ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ ../events.h \
+ ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ $(kpathsea_srcdir)/tex-file.h
+test1.o: test1.c \
+ run_tests.h \
+ ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-config.h \
+ ../xdvi-debug.h \
+ ../xdvi.h \
+ ../version.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h \
+ $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h \
+ $(kpathsea_srcdir)/lib.h \
+ $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h \
+ ../hypertex.h \
+ ../dvi-init.h \
+ ../special.h \
+ ../events.h \
+ ../string-utils.h \
+ ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ ../events.h \
+ ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ $(kpathsea_srcdir)/tex-file.h
+test_dl_list.o: test_dl_list.c \
+ run_tests.h \
+ ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-config.h \
+ ../xdvi-debug.h \
+ ../xdvi.h \
+ ../version.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h \
+ $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h \
+ $(kpathsea_srcdir)/lib.h \
+ $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h \
+ ../hypertex.h \
+ ../dvi-init.h \
+ ../special.h \
+ ../events.h \
+ ../string-utils.h \
+ ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ ../events.h \
+ ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ ../dl_list.h
+test_string_list.o: \
+ test_string_list.c \
+ run_tests.h \
+ ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-config.h \
+ ../xdvi-debug.h \
+ ../xdvi.h \
+ ../version.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h \
+ $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h \
+ $(kpathsea_srcdir)/lib.h \
+ $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h \
+ ../hypertex.h \
+ ../dvi-init.h \
+ ../special.h \
+ ../events.h \
+ ../string-utils.h \
+ ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ ../events.h \
+ ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ ../string_list.h
+test_string_utils.o: \
+ test_string_utils.c \
+ ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-config.h \
+ ../xdvi-debug.h \
+ ../xdvi.h \
+ ../version.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h \
+ $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h \
+ $(kpathsea_srcdir)/lib.h \
+ $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ run_tests.h \
+ ../hypertex.h \
+ ../dvi-init.h \
+ ../special.h \
+ ../events.h \
+ ../string-utils.h \
+ ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ ../events.h \
+ ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ $(kpathsea_srcdir)/tex-file.h
+test_util.o: test_util.c \
+ run_tests.h \
+ ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-config.h \
+ ../xdvi-debug.h \
+ ../xdvi.h \
+ ../version.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h \
+ $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h \
+ $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h \
+ $(kpathsea_srcdir)/lib.h \
+ $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h \
+ ../hypertex.h \
+ ../dvi-init.h \
+ ../special.h \
+ ../events.h \
+ ../string-utils.h \
+ ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ ../events.h \
+ ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ $(kpathsea_srcdir)/tex-file.h
diff --git a/Build/source/texk/xdvik/tests/depend.mk.orig b/Build/source/texk/xdvik/tests/depend.mk.orig
new file mode 100644
index 00000000000..b8c28743aef
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/depend.mk.orig
@@ -0,0 +1,93 @@
+run_tests.o: run_tests.c \
+ run_tests.h ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-debug.h ../version.h $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h \
+ $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h $(kpathsea_srcdir)/lib.h $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h ../hypertex.h ../dvi-init.h ../special.h \
+ ../events.h ../string-utils.h ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h ../util.h $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h
+test_dl_list.o: test_dl_list.c run_tests.h ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-debug.h ../version.h $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h $(kpathsea_srcdir)/lib.h $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h ../hypertex.h ../dvi-init.h ../special.h \
+ ../events.h ../string-utils.h ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h ../util.h $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ ../dl_list.h
+test_string_list.o: test_string_list.c run_tests.h ../xdvi-config.h \
+ ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-debug.h ../version.h $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h $(kpathsea_srcdir)/lib.h $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h ../hypertex.h ../dvi-init.h ../special.h \
+ ../events.h ../string-utils.h ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h ../util.h $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h \
+ ../string_list.h
+test_string_utils.o: test_string_utils.c ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h ../xdvi-debug.h ../version.h $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h $(kpathsea_srcdir)/lib.h $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h $(kpathsea_srcdir)/c-fopen.h run_tests.h \
+ ../hypertex.h ../dvi-init.h ../special.h ../events.h ../string-utils.h \
+ ../my-vsnprintf.h $(kpathsea_srcdir)/tex-file.h ../util.h \
+ $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h
+test_util.o: test_util.c run_tests.h ../xdvi-config.h ../c-auto.h \
+ ../xdvi.h \
+ ../xdvi-debug.h ../version.h $(kpathsea_dir)/c-auto.h \
+ $(kpathsea_srcdir)/config.h $(kpathsea_srcdir)/c-std.h \
+ $(kpathsea_srcdir)/c-unistd.h $(kpathsea_srcdir)/systypes.h \
+ $(kpathsea_srcdir)/c-memstr.h \
+ $(kpathsea_srcdir)/c-errno.h \
+ $(kpathsea_srcdir)/c-minmax.h \
+ $(kpathsea_srcdir)/c-limits.h \
+ $(kpathsea_srcdir)/c-proto.h $(kpathsea_srcdir)/debug.h \
+ $(kpathsea_srcdir)/types.h $(kpathsea_srcdir)/lib.h $(kpathsea_srcdir)/progname.h \
+ $(kpathsea_srcdir)/c-pathmx.h \
+ $(kpathsea_srcdir)/c-dir.h \
+ $(kpathsea_srcdir)/c-vararg.h \
+ $(kpathsea_srcdir)/c-fopen.h ../hypertex.h ../dvi-init.h ../special.h \
+ ../events.h ../string-utils.h ../my-vsnprintf.h \
+ $(kpathsea_srcdir)/tex-file.h ../util.h $(kpathsea_srcdir)/c-stat.h \
+ $(kpathsea_srcdir)/hash.h
diff --git a/Build/source/texk/xdvik/tests/run_tests.c b/Build/source/texk/xdvik/tests/run_tests.c
new file mode 100644
index 00000000000..5235b9b5b2c
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/run_tests.c
@@ -0,0 +1,127 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "run_tests.h"
+#include "util.h"
+
+/* helper routines */
+Boolean test_str_equality(int verbosity, const char *str1, const char *str2)
+{
+ int res = strcmp(str1, str2);
+ if (res != 0) {
+ if (verbosity) {
+ ERROR((stderr, "|%s| != |%s|\n", str1, str2));
+ }
+ return False;
+ }
+ if (verbosity) {
+ INFO((stderr, "|%s| == |%s|\n", str1, str2));
+ }
+ return True;
+}
+
+Boolean
+test_str_list_equality(int verbosity, char **str_list1, char **str_list2)
+{
+ size_t i;
+ for (i = 0; str_list1[i] != NULL || str_list2[i] != NULL; i++)
+ {
+ int res;
+
+ if (str_list1[i] == NULL || str_list2[i] == NULL) {
+ if (verbosity) {
+ ERROR((stderr, "Items %d differ: |%s| != |%s|\n", i, str_list1[i], str_list2[i]));
+ }
+ return False;
+ }
+
+ res = strcmp(str_list1[i], str_list2[i]);
+ if (res != 0) {
+ if (verbosity) {
+ ERROR((stderr, "Items %d differ: |%s| != |%s|\n", i, str_list1[i], str_list2[i]));
+ }
+ return False;
+ }
+ else if (verbosity) {
+ INFO((stderr, "Items %d equal: |%s| == |%s|\n", i, str_list1[i], str_list2[i]));
+ }
+ }
+ return True;
+}
+
+
+
+struct test_proc {
+ const char *name;
+ testProcT proc;
+};
+
+static size_t m_test_proc_size = 0;
+static struct test_proc *m_test_proc_list = NULL;
+
+void register_test(testProcT proc, const char *name)
+{
+ size_t old_idx = m_test_proc_size;
+ m_test_proc_size++;
+ m_test_proc_list = xrealloc(m_test_proc_list, m_test_proc_size * sizeof *m_test_proc_list);
+ m_test_proc_list[old_idx].name = xstrdup(name);
+ m_test_proc_list[old_idx].proc = proc;
+}
+
+
+static Boolean
+run_all_tests(int verbosity)
+{
+ size_t i;
+
+ int tests_failed = 0;
+ int tests_ok = 0;
+
+ fprintf(stdout, "\nGoing to run %d tests ...\n", m_test_proc_size);
+
+ for (i = 0; i < m_test_proc_size; i++) {
+ Boolean retval = m_test_proc_list[i].proc(verbosity);
+ if (!retval) {
+ tests_failed++;
+ m_test_proc_list[i].proc(True);
+ }
+ else {
+ tests_ok++;
+ }
+ fprintf(stdout, "%sTest %d: %s (%s)\n",
+ retval ? "" : "*****",
+ i + 1,
+ retval ? "OK" : "FAILURE",
+ m_test_proc_list[i].name);
+ }
+
+/* fprintf(stdout, "Ran %d tests: %d OK, %d failures.\n", m_test_proc_size, tests_ok, tests_failed); */
+ if (tests_failed == 0) {
+ fprintf(stdout, "Great! All tests succeeded.\n\n");
+ return True;
+ }
+ else {
+ fprintf(stdout, "Darn, %d of %d tests failed!\n\n", tests_failed, m_test_proc_size);
+ return False;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int verbosity = 0;
+ /* fprintf(stderr, "argc: %d, argv1: %s\n", argc, argv[1]); */
+ if (argc > 1 && strcmp(argv[1], "-v") == 0) {
+ verbosity = 1;
+ }
+
+ register_all_from_test_dl_list();
+ register_all_from_test_string_utils();
+ register_all_from_test_string_list();
+ register_all_from_test_util();
+
+ if (!run_all_tests(verbosity))
+ return 1;
+ else
+ return 0;
+}
diff --git a/Build/source/texk/xdvik/tests/run_tests.h b/Build/source/texk/xdvik/tests/run_tests.h
new file mode 100644
index 00000000000..8aa1dfd109f
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/run_tests.h
@@ -0,0 +1,34 @@
+#include "xdvi-config.h"
+
+#include <sys/types.h> /* ZLB: must be before sys/socket.h for IRIX 5.3 */
+#include <sys/socket.h>
+#include <sys/file.h> /* this defines FASYNC */
+#include <sys/ioctl.h> /* this defines SIOCSPGRP and FIOASYNC */
+#include <sys/wait.h> /* this defines WIFEXITED and WEXITSTATUS */
+
+#include "xdvi.h"
+#include "hypertex.h"
+#include "dvi-init.h"
+#include "special.h"
+#include "string-utils.h"
+
+#include "kpathsea/tex-file.h"
+
+#include "events.h"
+#include "util.h"
+
+#define ERROR(X) do { fprintf(stderr, "%s:%d: Error: ", __FILE__, __LINE__); fprintf X; } while(0)
+#define INFO(X) do { fprintf(stderr, "%s:%d: Info: ", __FILE__, __LINE__); fprintf X; } while(0)
+
+typedef Boolean (*testProcT)(int verbosity);
+
+extern void register_test(testProcT testproc, const char *name);
+
+/* test helpers */
+extern Boolean test_str_equality(int verbosity, const char *str1, const char *str2);
+extern Boolean test_str_list_equality(int verbosity, char **str_list1, char **str_list2);
+
+extern void register_all_from_test_dl_list(void);
+extern void register_all_from_test_string_utils(void);
+extern void register_all_from_test_string_list(void);
+extern void register_all_from_test_util(void);
diff --git a/Build/source/texk/xdvik/tests/test1.c b/Build/source/texk/xdvik/tests/test1.c
new file mode 100644
index 00000000000..cb917e17740
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/test1.c
@@ -0,0 +1,14 @@
+#include "run_tests.h"
+
+static Boolean mytest1(void) {
+ return 1 == 1;
+}
+
+static Boolean mytest2(void) {
+ return 0 == 0;
+}
+
+void register_all_from_test1(void) {
+ register_test(mytest1, "Trivial equality");
+ register_test(mytest2, "ld_list");
+}
diff --git a/Build/source/texk/xdvik/tests/test_dl_list.c b/Build/source/texk/xdvik/tests/test_dl_list.c
new file mode 100644
index 00000000000..a929b76ef6c
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/test_dl_list.c
@@ -0,0 +1,96 @@
+#include "run_tests.h"
+#include "dl_list.h"
+
+static struct elem {
+ int i;
+ const char *name;
+} elems[] = {
+ { 1, "Hello" },
+ { 2, " " },
+ { 3, "World" },
+};
+
+static struct elem test_elems[] = {
+ { 1, "Hello" },
+ { 3, "Another" },
+ { 1, "Hello" },
+ { 2, " " },
+ { 3, "World" },
+};
+
+static void printer_func(const void *e_in) {
+ const struct elem *e = (const struct elem *)e_in;
+ INFO((stderr, "ELEM: %d, `%s'\n", e->i, e->name));
+}
+
+static Boolean test_equality(int verbose,
+ struct dl_list *list,
+ const struct elem *elems,
+ size_t list_len,
+ size_t elem_cnt)
+{
+ size_t i;
+ struct dl_list *ptr = NULL;
+
+ if (list_len != elem_cnt) {
+ if (verbose) {
+ ERROR((stderr, "List len %d != %d\n", list_len, elem_cnt));
+ }
+ return False;
+ }
+
+ for (i = 0, ptr = list; i < list_len; i++, ptr = ptr->next) {
+ const struct elem *curr = (const struct elem *)ptr->item;
+
+ if (verbose) {
+ INFO((stderr, "Checking: `%s' - `%s'\n", elems[i].name, curr->name));
+ }
+ if (strcmp(test_elems[i].name, curr->name) != 0) {
+ return False;
+ }
+ if (elems[i].i != curr->i) {
+ return False;
+ }
+ }
+ return True;
+}
+
+static Boolean dl_list_test1(int verbosity) {
+ struct dl_list *testlist = NULL;
+ size_t list_len;
+ static struct elem e1 = { 3, "Another" };
+ static struct elem e2 = { 1, "Hello" };
+
+ testlist = dl_list_insert(testlist, &elems[0]);
+ testlist = dl_list_insert(testlist, &elems[1]);
+ testlist = dl_list_insert(testlist, &elems[2]);
+ testlist = dl_list_head(testlist);
+
+ if (verbosity) {
+ testlist = dl_list_head(testlist);
+ dl_list_apply(testlist, printer_func);
+ }
+
+ list_len = dl_list_len(testlist);
+
+ test_equality(verbosity, testlist, elems, list_len, 3);
+
+ /* test pushing */
+ testlist = dl_list_push_front(testlist, &e1);
+ testlist = dl_list_push_front(testlist, &e2);
+ testlist = dl_list_head(testlist);
+ list_len = dl_list_len(testlist);
+
+ test_equality(verbosity, testlist, test_elems, list_len, 5);
+
+ /* test truncating */
+ testlist = dl_list_truncate(testlist);
+ testlist = dl_list_truncate(testlist);
+
+
+ return True;
+}
+
+void register_all_from_test_dl_list(void) {
+ register_test(dl_list_test1, "dl_list construction");
+}
diff --git a/Build/source/texk/xdvik/tests/test_string_list.c b/Build/source/texk/xdvik/tests/test_string_list.c
new file mode 100644
index 00000000000..1f23158949a
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/test_string_list.c
@@ -0,0 +1,75 @@
+#include "run_tests.h"
+#include "string_list.h"
+
+static Boolean
+string_list_test1(int verbosity)
+{
+ static char *test_str = "This\nis\na\ntest\n";
+ static char *test_str_rotated = "is\na\ntest\nThis\n";
+ static char *test_list[] = {
+ "This",
+ "is",
+ "a",
+ "test",
+ NULL
+ };
+
+ char *res_str;
+ char **test_list_orig, **test_list_rotated;
+
+ res_str = string_list_to_str(test_list, "\n");
+ if (!test_str_equality(verbosity, res_str, test_str)) {
+ return False;
+ }
+
+ test_list_rotated = string_list_rotate_down(test_list);
+ if (!test_str_equality(verbosity,
+ string_list_to_str(test_list_rotated, "\n"),
+ test_str_rotated)) {
+ return False;
+ }
+
+ test_list_orig = string_list_rotate_up(test_list_rotated);
+ if (!test_str_list_equality(verbosity,
+ test_list_orig,
+ test_list)) {
+ return False;
+ }
+ return True;
+}
+
+static Boolean
+string_list_test2(int verbosity)
+{
+ static char *test_str = "";
+ static char *test_list[] = { NULL };
+ char **res_list;
+ char *res_str = string_list_to_str(test_list, "#");
+
+ if (!test_str_equality(verbosity, res_str, test_str)) {
+ return False;
+ }
+
+ /* string_list_print(test_list); */
+
+ res_list = string_list_rotate_down(test_list);
+
+ /* string_list_print(res_list); */
+
+ if (!test_str_equality(verbosity,
+ test_str,
+ string_list_to_str(res_list, "\n")))
+ {
+ return False;
+ }
+ return True;
+}
+
+/* todo: append, prepend, reorder */
+
+void
+register_all_from_test_string_list(void)
+{
+ register_test(string_list_test1, "string lists");
+ register_test(string_list_test2, "empty string lists");
+}
diff --git a/Build/source/texk/xdvik/tests/test_string_utils.c b/Build/source/texk/xdvik/tests/test_string_utils.c
new file mode 100644
index 00000000000..c8a7dadb3bb
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/test_string_utils.c
@@ -0,0 +1,431 @@
+#include "xdvi-config.h"
+#include "xdvi.h"
+#include "kpathsea/c-vararg.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "run_tests.h"
+
+#include "string-utils.h"
+
+#define DEBUG 0
+
+static Boolean test_get_separated_list(int verbose)
+{
+ char *test_list1[] = {
+ "This is the first line",
+ "This is the second",
+ "This, is the third",
+ "The last one",
+ NULL
+ };
+ char *test_list2[] = {
+ "This",
+ "is",
+ "another",
+ "first",
+ "line",
+ NULL
+ };
+ const char *teststring1 = "This is the first line,This is the second,\"This, is the third\",The last one";
+ const char *teststring2 = "This\nis another\tfirst line";
+
+ char **res_list1 = get_separated_list(teststring1, ",", True);
+ char **res_list2 = get_separated_list(teststring2, " \t\n", True);
+ /* TODO: deallocate? */
+ return test_str_list_equality(verbose, test_list1, res_list1) && test_str_list_equality(verbose, test_list2, res_list2);
+}
+
+static Boolean test_str_is_prefix(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ char *str2;
+ Boolean case_sensitive;
+ Boolean result;
+ } tests[] = {
+ { "foo", "foobar", True, True },
+ { "foo", "Foobar", True, False },
+ { "foo", "Foobar", False, True },
+ { "foo", "FOObar", False, True },
+ { "foo", "foo", True, True },
+ { "f", "foo", True, True },
+ { "b", "foo", True, False },
+ { "foo", "b", True, False },
+ { "", "foo", True, True },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "str_is_prefix(%s,%s,%d) -> %d == %d?\n",
+ tests[i].str1,
+ tests[i].str2,
+ tests[i].case_sensitive,
+ str_is_prefix(tests[i].str1, tests[i].str2, tests[i].case_sensitive),
+ tests[i].result));
+ }
+ if (str_is_prefix(tests[i].str1, tests[i].str2, tests[i].case_sensitive) != tests[i].result) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+static Boolean test_str_is_suffix(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ char *str2;
+ Boolean case_sensitive;
+ Boolean result;
+ } tests[] = {
+ { "bar", "foobar", True, True },
+ { "bar", "FooBar", True, False },
+ { "bar", "fooBAR", False, True },
+ { "bar", "fooBaR", False, True },
+ { "bar", "bar", True, True },
+ { "r", "bar", True, True },
+ { "x", "bar", True, False },
+ { "bar", "r", True, False },
+ { "", "bar", True, True },
+ { "", "", True, True },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "str_is_suffix(%s,%s,%d) -> %d == %d?\n",
+ tests[i].str1,
+ tests[i].str2,
+ tests[i].case_sensitive,
+ str_is_suffix(tests[i].str1, tests[i].str2, tests[i].case_sensitive),
+ tests[i].result));
+ }
+ if (str_is_suffix(tests[i].str1, tests[i].str2, tests[i].case_sensitive) != tests[i].result) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+static Boolean test_is_spaces_only(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ Boolean result;
+ } tests[] = {
+ { "bar", False },
+ { " \t\n ", True },
+ { " a ", False },
+ { "", True },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "is_spaces_only(%s) -> %d == %d?\n",
+ tests[i].str1,
+ is_spaces_only(tests[i].str1),
+ tests[i].result));
+ }
+ if (is_spaces_only(tests[i].str1) != tests[i].result) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+static Boolean test_my_stristr(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ char *str2;
+ char *result;
+ } tests[] = {
+ { "paloozah", "ooz", "oozah" },
+ { "paloozah", "pa", "paloozah" },
+ { "paloozah", "par", NULL },
+ { "paloozah", "x", NULL },
+ { "PALOOZAH", "ooz", "OOZAH" },
+ { "PALOOZAH", "ah", "AH" },
+ { "PALOOZAH", "h", "H" },
+ { "h", "h", "h" },
+ { "H", "h", "H" },
+ { "", "h", NULL },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "my_stristr(%s, %s) -> %s == %s?\n",
+ tests[i].str1,
+ tests[i].str2,
+ my_stristr(tests[i].str1, tests[i].str2),
+ tests[i].result));
+ }
+ if (my_stristr(tests[i].str1, tests[i].str2) != tests[i].result) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+static Boolean test_format_arg(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ char *arg;
+ char *result;
+ } tests[] = {
+ { "netscape(%s, same-window)", "file.html", "netscape(file.html, same-window)" },
+ { "netscape(same-window)", "file.html", "netscape(same-window)" },
+ { "%s", "a", "a" },
+ { "", "", "" },
+ };
+
+ size_t i;
+ int tmpcnt = 0;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "format_arg(%s) -> %s == %s, %d\n",
+ tests[i].str1,
+ format_arg(tests[i].str1, tests[i].arg, &tmpcnt),
+ tests[i].result,
+ tmpcnt));
+ }
+ if (!test_str_equality(verbose,
+ format_arg(tests[i].str1, tests[i].arg, &tmpcnt),
+ tests[i].result)) {
+ result = False;
+ }
+ }
+ /* tempcnt shouldn't be reset to 0 by format_arg() */
+ if (tmpcnt != 1) {
+ ERROR((stderr, "tmpcnt should be 1\n"));
+ result = False;
+ }
+ return result;
+}
+
+static Boolean test_escape_format_arg(int verbose)
+{
+ static struct stringtest {
+ char *str;
+ char *result;
+ } tests[] = {
+ { "netscape(%s, same-window)", "netscape(%%s, same-window)" },
+ { "%%s", "%%%%s" },
+ { "%d%s", "%%d%%s" },
+ { "a", "a" },
+ { "", "" },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "escape_format_arg(%s) -> %s == %s\n",
+ tests[i].str,
+ escape_format_arg(tests[i].str),
+ tests[i].result));
+ }
+ if (!test_str_equality(verbose,
+ escape_format_arg(tests[i].str),
+ tests[i].result)) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+static Boolean test_filename_append_dvi(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ char *str2;
+ } tests[] = {
+ { "file:///tmp/foo.bar", "/tmp/foo.bar" },
+ { "file:///tmp/foo", "/tmp/foo.dvi" },
+ /* the following two mimick firefox behaviour with double/single slashes */
+ { "file://tmp/foo", "/foo.dvi" },
+ { "file:/tmp/foo", "/tmp/foo.dvi" },
+ { "file://localhost/tmp/foo", "/tmp/foo.dvi" },
+ { "~/tmp/foo", "~/tmp/foo.dvi" },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ char *tmp = filename_append_dvi(tests[i].str1);
+ if (verbose) {
+ INFO((stderr, "filename_append_dvi(%s) -> %s == %s?\n",
+ tests[i].str1,
+ tmp,
+ tests[i].str2));
+ }
+ if (!test_str_equality(verbose, tmp, tests[i].str2)) {
+ result = False;
+ }
+ free(tmp);
+ }
+ return result;
+}
+
+static Boolean test_canonicalize_path(int verbose)
+{
+ static struct stringtest {
+ char *str1;
+ char *str2;
+ } tests[] = {
+ { "/foo/a/bz.to/bar.dvi", "/foo/a/bz.to/bar.dvi" },
+ { "/foo/../bar.dvi", "/bar.dvi" },
+ { "/foo/../bar.dvi", "/bar.dvi" },
+ { "/foo/./roo/./bar.dvi", "/foo/roo/bar.dvi" },
+ { "/foo/./roo/../bar.dvi", "/foo/bar.dvi" },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "canonicalize_path(%s) -> %s == %s?\n",
+ tests[i].str1,
+ canonicalize_path(tests[i].str1),
+ tests[i].str2));
+ }
+ if (!test_str_equality(verbose, canonicalize_path(tests[i].str1), tests[i].str2)) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+
+
+static Boolean test_expand_filename(int verbose)
+{
+ char cwd[10240];
+ char *currpath, *testpath1, *testpath2;
+
+ currpath = xstrdup(getcwd(cwd, 10240));
+ testpath1 = expand_filename(__FILE__, USE_CWD_PATH);
+ globals.dvi_file.dirname = xstrdup(cwd);
+ globals.dvi_file.dirname = xstrcat(globals.dvi_file.dirname, "/");
+ testpath2 = expand_filename(__FILE__, USE_DVI_PATH);
+
+ currpath = xstrcat(currpath, "/");
+ currpath = xstrcat(currpath, __FILE__);
+
+ return test_str_equality(verbose, testpath1, currpath) \
+ && test_str_equality(verbose, testpath2, currpath);
+}
+
+
+static Boolean test_get_extension(int verbose)
+{
+ const char *test_strings[][2] = {
+ { "/dev/fd/3", NULL },
+ { "/home/user/file.dvi", ".dvi" },
+ { "/home/user/file.ps", ".ps" },
+ { "/home/user.bar/file.dvi", ".dvi" },
+ { "/home/user.bar/file", NULL },
+ { "/home/user/file", NULL },
+ { NULL, NULL }
+ };
+
+ size_t i;
+
+ for (i = 0; test_strings[i][0] != NULL; i++) {
+ const char *tmp = get_extension(test_strings[i][0]);
+ if (tmp == NULL && test_strings[i][1] == NULL) {
+ if (verbose)
+ INFO((stderr, "Checking extension of |%s| OK: <NULL> == <NULL>\n", test_strings[i][0]));
+ }
+ else if (tmp == NULL && test_strings[i][1] != NULL) {
+ if (verbose)
+ ERROR((stderr, "extension of |%s| gave <NULL> - should be |%s|\n",
+ test_strings[i][0], test_strings[i][1]));
+ return False;
+ }
+ else if (tmp != NULL && test_strings[i][1] == NULL) {
+ if (verbose)
+ ERROR((stderr, "extension of |%s| gave |%s| - should be <NULL>\n",
+ test_strings[i][0], tmp));
+ return False;
+ }
+ else {
+ if (strcmp(tmp, test_strings[i][1]) != 0) {
+ if (verbose)
+ ERROR((stderr, "ERROR: extension of |%s| gave |%s| - should be |%s|\n",
+ test_strings[i][0], tmp, test_strings[i][1]));
+ return False;
+ }
+ else {
+ if (verbose)
+ INFO((stderr, "Checking extension of |%s| OK: |%s| == |%s|\n",
+ test_strings[i][0], tmp, test_strings[i][1]));
+ }
+ }
+ }
+
+ return True;
+}
+
+static Boolean test_length_of_int(int verbose)
+{
+ static struct stringtest {
+ int d;
+ int len;
+ } tests[] = {
+ { 0, 1 },
+ { 1, 1 },
+ { 11, 2 },
+ { 111, 3 },
+ { 100, 3 },
+ { 100000, 6 },
+ { 999999, 6 },
+ { 1000000, 7 },
+ { 101, 3 },
+ { 001, 1 },
+ };
+
+ size_t i;
+ Boolean result = True;
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ if (verbose) {
+ INFO((stderr, "length_of_int(%d) -> %d == %d?\n",
+ tests[i].d,
+ length_of_int(tests[i].d),
+ tests[i].len));
+ }
+ if (length_of_int(tests[i].d) != tests[i].len) {
+ result = False;
+ }
+ }
+ return result;
+}
+
+void register_all_from_test_string_utils(void)
+{
+ register_test(test_str_is_prefix, "str_is_prefix()");
+ register_test(test_str_is_suffix, "str_is_suffix()");
+ register_test(test_is_spaces_only, "is_spaces_only()");
+ register_test(test_my_stristr, "my_stristr()");
+ register_test(test_filename_append_dvi, "filename_append_dvi()");
+ /* TODO: expand_filename_append_dvi */
+ register_test(test_canonicalize_path, "canonicalize_path()");
+ register_test(test_format_arg, "format_arg()");
+ register_test(test_escape_format_arg, "escape_format_arg()");
+ register_test(test_expand_filename, "expand_filename()");
+ register_test(test_get_separated_list, "get_separated_list");
+ register_test(test_length_of_int, "length_of_int()");
+ register_test(test_get_extension, "Filename extensions");
+}
diff --git a/Build/source/texk/xdvik/tests/test_util.c b/Build/source/texk/xdvik/tests/test_util.c
new file mode 100644
index 00000000000..239927190c8
--- /dev/null
+++ b/Build/source/texk/xdvik/tests/test_util.c
@@ -0,0 +1,45 @@
+#include "run_tests.h"
+#include "util.h"
+#include "string-utils.h"
+
+static Boolean
+test_src_format_arguments(int verbose)
+{
+ static struct stringtest {
+ char *str;
+ char *res[16]; /* big enuff */
+ } tests[] = {
+ { "emacsclient --no-wait +%l %f",
+ { "emacsclient", "--no-wait", "+10", "/this/is/a/filename.tex", NULL }
+ },
+ { "vim +%l:%c %f",
+ { "vim", "+10:0", "/this/is/a/filename.tex", NULL }
+ },
+ { "bazoo %f:%l:%c",
+ { "bazoo", "/this/is/a/filename.tex:10:0", NULL }
+ }
+ };
+
+ const char *filename = "/this/is/a/filename.tex";
+ int lineno = 10;
+ int colno = 0;
+ size_t i;
+ Boolean res = True;
+
+ for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) {
+ char **argv = get_separated_list(tests[i].str, " \t", True);
+ argv = src_format_arguments(argv, filename, lineno, colno);
+ if (!test_str_list_equality(verbose, argv, tests[i].res)) {
+ res = False;
+ }
+ }
+
+ return res;
+}
+
+
+void
+register_all_from_test_util(void)
+{
+ register_test(test_src_format_arguments, "src_format_arguments");
+}