Skip to content

Commit

Permalink
Adapt unit tests for DOS builds
Browse files Browse the repository at this point in the history
Rewrite each unit test as a batch file and run it in DOSBox.
  • Loading branch information
dajhorn committed Aug 29, 2024
1 parent 9de23c9 commit a2fa894
Show file tree
Hide file tree
Showing 37 changed files with 1,170 additions and 0 deletions.
1 change: 1 addition & 0 deletions cabextract/dos/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
objects/
products/
tests/
24 changes: 24 additions & 0 deletions cabextract/dos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Note that wmake intercepts `mkdir` and `rm`.
OBJECT_DIR = objects
PRODUCT_DIR = products
TEST_DIR = tests

# Watcom compiler.
CC = wcc386
Expand Down Expand Up @@ -78,6 +79,11 @@ MADE = \s\e\t +x && echo -n '\e[33mMADE \e[0m' && LS_COLORS="ex=33:fi=33" ls --c
# the output of wmake. Note that wmake for Linux is hardcoded for /bin/sh.
SHOPT = set -x;

# Use this DOS emulator for running unit tests.
DOSBOX = flatpak run com.dosbox_x.DOSBox-X
DOSOPT = -exit -fastlaunch -nolog
DOSCNF = tests.in/dosbox.cnf

# The default rule.
all: .SYMBOLIC $(TARGETS)
@%null
Expand Down Expand Up @@ -110,6 +116,9 @@ $(OBJECT_DIR):
$(PRODUCT_DIR):
mkdir -p $@

$(TEST_DIR): tests.in
mkdir -p $@

# Create the version.sh file from the configure.ac file.
$(VERSION_SH): ../configure.ac $(OBJECT_DIR)
@($(SHOPT) &
Expand Down Expand Up @@ -163,3 +172,18 @@ $(PRODUCT_DIR)/CABINFO.EXE: $(PRODUCT_DIR) $(VERSION_H) $(CABINFO_OBJ)
clean: .SYMBOLIC
rm -fr $(OBJECT_DIR)
rm -fr $(PRODUCT_DIR)
rm -fr $(TEST_DIR)

$(TEST_DIR)/report.txt: .PRECIOUS $(TEST_DIR) $(DOSCNF) $(TARGETS)
$(DOSBOX) $(DOSOPT) -conf $(DOSCNF)
cat $(TEST_DIR)/*.result >$@
dos2unix $@
@( &
if grep -e ':FAIL$$' $@; &
then false; &
else echo '\e[32mALL TESTS PASS\e[0m'; &
fi; &
)

test: .SYMBOLIC $(TEST_DIR)/report.txt
@%null
159 changes: 159 additions & 0 deletions cabextract/dos/tests.in/bugs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
@ECHO OFF
REM
REM cabextract/dos/test.in/bugs.bat: Unit tests for DOS.
REM

IF "%CABDIR%"=="" GOTO ERROR_CABDIR
IF "%CABEXT%"=="" GOTO ERROR_CABEXT
IF "%TEST_IN%"=="" GOTO ERROR_TEST_IN
IF "%TEST_OUT%"=="" GOTO ERROR_TEST_OUT

SET RESULT=%TEST_OUT%\bugs.result
IF EXIST %RESULT% DEL %RESULT%

IF NOT EXIST %CABDIR%\..\BUGS\NUL GOTO END
PUSHD %CABDIR%\..\BUGS

:TEST01
SET TEST_CAB=cve-2010-2800-mszip-infinite-loop.cab
SET TEST=test01-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST02
REM Recent cabext builds can unpack this file.
REM Notice the errorlevel check for this test.
SET TEST_CAB=cve-2010-2801-qtm-flush.cab
SET TEST=test02-bugs-%TEST_CAB%
SET TEST_RESULT=PASS
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 1 SET TEST_RESULT=FAIL
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST03
SET TEST_CAB=cve-2014-9556-qtm-infinite-loop.cab
SET TEST=test03-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST04
SET TEST_CAB=cve-2014-9732-folders-segfault.cab
SET TEST=test04-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST05
SET TEST_CAB=cve-2015-4470-mszip-over-read.cab
SET TEST=test05-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST06
SET TEST_CAB=cve-2015-4471-lzx-under-read.cab
SET TEST=test06-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST07
SET TEST_CAB=filename-read-violation-1.cab
SET TEST=test07-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST08
SET TEST_CAB=filename-read-violation-2.cab
SET TEST=test08-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST09
SET TEST_CAB=filename-read-violation-3.cab
SET TEST=test09-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST10
SET TEST_CAB=filename-read-violation-4.cab
SET TEST=test10-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST11
SET TEST_CAB=lzx-main-tree-no-lengths.cab
SET TEST=test11-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST12
SET TEST_CAB=lzx-premature-matches.cab
SET TEST=test12-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST13
SET TEST_CAB=qtm-max-size-block.cab
SET TEST=test13-bugs-%TEST_CAB%
SET TEST_RESULT=FAIL
ECHO %TEST%
%CABEXT% --test %TEST_CAB%
IF ERRORLEVEL 2 SET TEST_RESULT=PASS
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

POPD
GOTO END

:ERROR_CABDIR
ECHO ERROR: %%CABDIR%% is not set.
GOTO END

:ERROR_CABEXT
ECHO ERROR: %%CABEXT%% is not set.
GOTO END

:ERROR_TEST_IN
ECHO ERROR: %%TEST_IN%% is not set.
GOTO END

:ERROR_TEST_OUT
ECHO ERROR: %%TEST_OUT%% is not set.
GOTO END

:END
SET TEST=
SET TEST_CAB=
SET TEST_RESULT=
SET RESULT=
76 changes: 76 additions & 0 deletions cabextract/dos/tests.in/case-ascii.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@ECHO OFF
REM
REM cabextract/dos/test.in/case-ascii.bat: Unit tests for DOS.
REM

IF "%CABDIR%"=="" GOTO ERROR_CABDIR
IF "%CABEXT%"=="" GOTO ERROR_CABEXT
IF "%TEST_IN%"=="" GOTO ERROR_TEST_IN
IF "%TEST_OUT%"=="" GOTO ERROR_TEST_OUT

SET TEST_CAB=case-ascii.cab
SET RESULT=%TEST_OUT%\case-ascii.result
IF EXIST %RESULT% DEL %RESULT%

PUSHD %CABDIR%

:TEST14
SET TEST=test14-case-ascii
ECHO %TEST%
%CABEXT% --list %TEST_CAB% >%TEST_OUT%\%TEST%.out
SET TEST_RESULT=PASS
FC /L %TEST_IN%\%TEST%.in %TEST_OUT%\%TEST%.out
IF ERRORLEVEL 1 SET TEST_RESULT=FAIL
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST15
SET TEST=test15-case-ascii
ECHO %TEST%
%CABEXT% --list --lowercase %TEST_CAB% >%TEST_OUT%\%TEST%.out
SET TEST_RESULT=PASS
FC /L %TEST_IN%\%TEST%.in %TEST_OUT%\%TEST%.out
IF ERRORLEVEL 1 SET TEST_RESULT=FAIL
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST16
SET TEST=test16-case-ascii
ECHO %TEST%
%CABEXT% --list --directory DIR\PATH %TEST_CAB% >%TEST_OUT%\%TEST%.out
SET TEST_RESULT=PASS
FC /L %TEST_IN%\%TEST%.in %TEST_OUT%\%TEST%.out
IF ERRORLEVEL 1 SET TEST_RESULT=FAIL
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

:TEST17
SET TEST=test17-case-ascii
ECHO %TEST%
%CABEXT% --list --lowercase --directory DIR\PATH %TEST_CAB% >%TEST_OUT%\%TEST%.out
SET TEST_RESULT=PASS
FC /L %TEST_IN%\%TEST%.in %TEST_OUT%\%TEST%.out
IF ERRORLEVEL 1 SET TEST_RESULT=FAIL
ECHO %TEST%:%TEST_RESULT% >>%RESULT%

POPD
GOTO END

:ERROR_CABDIR
ECHO ERROR: %%CABDIR%% is not set.
GOTO END

:ERROR_CABEXT
ECHO ERROR: %%CABEXT%% is not set.
GOTO END

:ERROR_TEST_IN
ECHO ERROR: %%TEST_IN%% is not set.
GOTO END

:ERROR_TEST_OUT
ECHO ERROR: %%TEST_OUT%% is not set.
GOTO END

:END
SET TEST=
SET TEST_CAB=
SET TEST_RESULT=
SET RESULT=
19 changes: 19 additions & 0 deletions cabextract/dos/tests.in/case-utf8.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@ECHO OFF
REM
REM cabextract/dos/test.in/case-utf8.bat: Unit tests for DOS.
REM

:TEST18
REM Unimplemented: Check UTF-8 LOCALE.

:TEST19
REM Unimplemented: Uppercase UTF-8 characters in file names.

:TEST20
REM Unimplemented: Lowercase UTF-8 characters in file names.

:TEST21
REM Unimplemented: Uppercase UTF-8 characters in directory names.

:TEST22
REM Unimplemented: Lowercase UTF-8 characters in directory names.
Loading

0 comments on commit a2fa894

Please sign in to comment.