]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
add createpdf test
authorBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 09:42:54 +0000 (11:42 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 09:42:54 +0000 (11:42 +0200)
scanbasic.bats
scanbasic.sh

index 5e57ad11dcb120db79700b9e213600ab22014912..44cf3ef1244c98ad9a33dcf2f0bd3273bab50b11 100755 (executable)
@@ -163,3 +163,41 @@ teardown() {
 
        assert_success
 }
+
+@test "should failure createpdf missing start parameter" {
+       run createpdf
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing start"
+}
+
+@test "should failure createpdf missing end parameter" {
+       run createpdf "1"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing end"
+}
+
+@test "should failure createpdf pdftk fails" {
+       pdftk_exit=1
+
+       run createpdf "1" "2"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: could not create pdf"
+}
+
+@test "should failure pdf delete fails" {
+       rm_exit=1
+
+       run createpdf "1" "2"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: could not delete scanned001.pdf"
+}
+
+@test "should success createpdf" {
+       run createpdf "1" "2"
+
+       assert_success
+}
index 69b541a98f5f111ebce932d675a7cfb0c669b495..d78151096fa895273756aff91f68e0586856d16f 100644 (file)
@@ -66,12 +66,15 @@ createonepdf()
                || errlog "missing output" \
                || return $?
 
-       for i in scanned*.tiff; do
-               tiff2pdf $i -o ${i/.tiff/.pdf} \
+       local output_pdf=
+       local tiff=
+       for tiff in scanned*.tiff; do
+               output_pdf=${tiff/.tiff/.pdf}
+               tiff2pdf $i -o $output_pdf \
                        || errlog "could not convert tiff to pdf" \
                        || return $?
-               rm $i \
-                       || errlog "could not delete $i" \
+               rm $tiff \
+                       || errlog "could not delete $tiff" \
                        || return $?
        done
 
@@ -89,34 +92,41 @@ createonepdf()
 
 createpdf()
 {
-       local start=$1
-       local end=$2
-       local basename=$3
+       local start="$1"
+       local end="$2"
+       local basename="$3"
        local countno=
        local pdfs=()
+       basename=${basename:="out"}
 
        command -v pdftk > /dev/null \
                || errlog "command pdftk not found" \
                || return $?
+       [ -n "$start" ] \
+               || errlog "missing start" \
+               || return $?
+       [ -n "$end" ] \
+               || errlog "missing end" \
+               || return $?
 
-       if [ -z "$basename" ]; then
-               basename="out"
-       fi
-
+       local i=
        for i in $(seq $start $end); do
                countno=$(printf "%03d" $i)
                pdfs=$(echo $pdfs "scanned$countno.pdf")
        done
 
-       pdftk $pdfs output $basename$(printf "%03d" $start).pdf \
+       pdftk "$pdfs" output "$basename$(printf "%03d" $start).pdf" \
                || errlog "could not create pdf" \
                || return 1
 
-       for i in $pdfs; do
-               rm $i || errlog "could not delete $i" || return 1
+       for pdf in $pdfs; do
+               rm "$pdf" \
+                       || errlog "could not delete $pdf" \
+                       || return 1
        done
 
-       addocr $basename$(printf "%03d" $start).pdf || return 1
+       addocr "$basename$(printf "%03d" $start).pdf" \
+               || return $?
 }
 
 detectsplit()