Files
jcl-cobol-git/test_integration.bat

114 lines
5.1 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set ROOT=D:\jcl-cobol
set COB_MAIN_DIR=D:\360安全浏览器下载\GC32-BDB-SP1-rename-7z-to-exe
set COB_CONFIG_DIR=%COB_MAIN_DIR%\config
set COB_LIBRARY_PATH=%COB_MAIN_DIR%\lib\gnucobol
set COBCPY=%ROOT%\copybooks
set PATH=%COB_MAIN_DIR%\bin;%PATH%
set DI=%ROOT%\data\input
set DW=%ROOT%\data\work
set DO=%ROOT%\data\output
set passed=0
set failed=0
:: Clean
del /q %DI%\* 2>nul
del /q %DW%\* 2>nul
del /q %DO%\* 2>nul
del /q %ROOT%\MEMOUT 2>nul
del /q %ROOT%\TXOUT 2>nul
del /q %ROOT%\RATEOUT 2>nul
echo.
echo [STEP 1] GENDATA
pushd %ROOT%
bin\GENDATA.exe
popd
if not exist %ROOT%\MEMOUT (
echo FAIL: GENDATA did not create MEMOUT
set /a failed+=1
goto :done
) else (
echo PASS: GENDATA created MEMOUT
set /a passed+=1
)
move %ROOT%\MEMOUT %DI%\member.dat >nul
move %ROOT%\TXOUT %DI%\transactions.dat >nul
move %ROOT%\RATEOUT %DI%\rate.dat >nul
:: Count lines
for /f %%i in ('find /c /v "" ^< %DI%\member.dat') do set memlines=%%i
for /f %%i in ('find /c /v "" ^< %DI%\transactions.dat') do set txlines=%%i
for /f %%i in ('find /c /v "" ^< %DI%\rate.dat') do set ratelines=%%i
if %memlines%==5 (echo PASS: members=5 & set /a passed+=1) else (echo FAIL: members expected=5 actual=%memlines% & set /a failed+=1)
if %txlines%==10 (echo PASS: transactions=10 & set /a passed+=1) else (echo FAIL: transactions expected=10 actual=%txlines% & set /a failed+=1)
if %ratelines%==2 (echo PASS: rates=2 & set /a passed+=1) else (echo FAIL: rates expected=2 actual=%ratelines% & set /a failed+=1)
echo.
echo [STEP 2] SORT
:: Sort by card(16) + date(8)
powershell -NoProfile -Command "Get-Content '%DI%\transactions.dat' | Sort-Object { $_.Substring(0,16) }, { $_.Substring(16,8) } | Set-Content '%DW%\sorted_tx.dat' -Encoding Ascii"
for /f %%i in ('find /c /v "" ^< %DW%\sorted_tx.dat') do set sortedlines=%%i
if %sortedlines%==10 (echo PASS: sorted=10 & set /a passed+=1) else (echo FAIL: sorted expected=10 actual=%sortedlines% & set /a failed+=1)
:: Check first and last card
for /f "usebackq delims=" %%a in (`powershell -NoProfile -Command "(Get-Content '%DW%\sorted_tx.dat')[0]"`) do set first=%%a
for /f "usebackq delims=" %%a in (`powershell -NoProfile -Command "(Get-Content '%DW%\sorted_tx.dat')[-1]"`) do set last=%%a
echo !first! | findstr "^6222021234567800" >nul && (echo PASS: first card=7800 & set /a passed+=1) || (echo FAIL: first card not 7800 & set /a failed+=1)
echo !last! | findstr "^9999999999999999" >nul && (echo PASS: last card=9999 & set /a passed+=1) || (echo FAIL: last card not 9999 & set /a failed+=1)
echo.
echo [STEP 3] CRDVAL
set TRANSIN=%DW%\sorted_tx.dat
set MEMBER=%DI%\member.dat
set VALIDOUT=%DW%\validated_tx.dat
set REJECT=%DO%\rejected_tx.dat
set REPORTERR=%DO%\error_report.dat
%ROOT%\bin\CRDVAL.exe
for /f %%i in ('find /c /v "" ^< %DW%\validated_tx.dat') do set validlines=%%i
for /f %%i in ('find /c /v "" ^< %DO%\rejected_tx.dat') do set rejectlines=%%i
if %validlines%==8 (echo PASS: valid=8 & set /a passed+=1) else (echo FAIL: valid expected=8 actual=%validlines% & set /a failed+=1)
if %rejectlines%==2 (echo PASS: rejects=2 & set /a passed+=1) else (echo FAIL: rejects expected=2 actual=%rejectlines% & set /a failed+=1)
findstr "FROZEN" %DO%\error_report.dat >nul && (echo PASS: error1=frozen & set /a passed+=1) || (echo FAIL: error1 not frozen & set /a failed+=1)
findstr "NOT-FOUND" %DO%\error_report.dat >nul && (echo PASS: error2=not-found & set /a passed+=1) || (echo FAIL: error2 not not-found & set /a failed+=1)
echo.
echo [STEP 4] CRDCALC
set VALIDIN=%DW%\validated_tx.dat
set RATE=%DI%\rate.dat
set CALCOUT=%DW%\billing_result.dat
%ROOT%\bin\CRDCALC.exe
for /f %%i in ('find /c /v "" ^< %DW%\billing_result.dat') do set billinglines=%%i
if %billinglines%==12 (echo PASS: billing=12 & set /a passed+=1) else (echo FAIL: billing expected=12 actual=%billinglines% & set /a failed+=1)
findstr "6480.20" %DW%\billing_result.dat >nul && (echo PASS: card7800=6480.20 & set /a passed+=1) || (echo FAIL: card7800 amount wrong & set /a failed+=1)
findstr "17200.00" %DW%\billing_result.dat >nul && (echo PASS: card7801=17200.00 & set /a passed+=1) || (echo FAIL: card7801 amount wrong & set /a failed+=1)
findstr "500.00" %DW%\billing_result.dat >nul && (echo PASS: card7802=500.00 & set /a passed+=1) || (echo FAIL: card7802 amount wrong & set /a failed+=1)
findstr "24180.20" %DW%\billing_result.dat >nul && (echo PASS: grand=24180.20 & set /a passed+=1) || (echo FAIL: grand total wrong & set /a failed+=1)
echo.
echo [STEP 5] CRDRPT
set BILLING=%DW%\billing_result.dat
set STMT=%DO%\monthly_statement.dat
set SUMMARY=%DO%\summary_report.dat
%ROOT%\bin\CRDRPT.exe
for /f %%i in ('find /c /v "" ^< %DO%\monthly_statement.dat') do set stmtlines=%%i
for /f %%i in ('find /c /v "" ^< %DO%\summary_report.dat') do set sumlines=%%i
if %stmtlines%==14 (echo PASS: statement=14 lines & set /a passed+=1) else (echo FAIL: statement expected=14 actual=%stmtlines% & set /a failed+=1)
if %sumlines%==5 (echo PASS: summary=5 lines & set /a passed+=1) else (echo FAIL: summary expected=5 actual=%sumlines% & set /a failed+=1)
:done
echo.
echo === RESULT: %passed% passed, %failed% failed ===
exit /b %failed%