]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
add tests for create multi pdfs
authorBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 10:17:26 +0000 (12:17 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 10:17:26 +0000 (12:17 +0200)
scanbasic.bats
scanbasic.sh

index fc5861daad88857c00200d3954874ebb3e18452e..bf75ac7dc02361265edfa1a46cfc33391ef5724d 100755 (executable)
@@ -243,3 +243,34 @@ teardown() {
        assert_success
        assert_line --index 0 "true"
 }
+
+@test "should failure createmultipdfs missing basename paramter" {
+       run createmultipdfs
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing basename"
+}
+
+@test "should failure createmultipdfs tiff2pdf fails" {
+       tiff2pdf_exit=1
+
+       run createmultipdfs "base"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: could not convert scanned*.tiff to scanned*.pdf"
+}
+
+@test "should failure createmultipdfs rm tiff fails" {
+       rm_exit=1
+
+       run createmultipdfs "base"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: could not delete scanned*.tiff"
+}
+
+@test "should success createmutlipdfs" {
+       run createmultipdfs "base"
+
+       assert_success
+}
index e20e2e5d1312fb827a405910fc5ea2ff2720b43c..4d0b7d80145bbba5630f681822a9decc2d5a1743 100644 (file)
@@ -154,28 +154,39 @@ detectsplit()
 
 createmultipdfs()
 {
-       local trenn=$1
-       local basename=$2
+       local basename=$1
        local startcount=1
        local endcount=1
-       local pdf=
 
        command -v tiff2pdf > /dev/null \
                || errlog "command tiff2pdf not found" \
                || return $?
-       for i in scanned*.tiff; do
-               pdf=${i/.tiff/.pdf}
-               tiff2pdf $i -o $pdf \
-                       || errlog "could not convert $i to $pdf" \
-                       || return 1
-               trenn=$(detectsplit $pdf)
-               rm $i
+       [ -n "$basename" ] \
+               || errlog "missing basename" \
+               || return $?
+
+       local pdf=
+       local tiff=
+       for tiff in scanned*.tiff; do
+               pdf=${tiff/.tiff/.pdf}
+               tiff2pdf $tiff -o $pdf \
+                       || errlog "could not convert $tiff to $pdf" \
+                       || return $?
+               trenn=$(detectsplit $pdf) \
+                       || return $?
+               rm $tiff \
+                       || errlog "could not delete $tiff" \
+                       || return $?
+
                if [ "$trenn" == "true" ]; then
-                       rm $pdf
+                       rm $pdf \
+                               || errlog "could not delete $pdf" \
+                               || return $?
                        createpdf $startcount $((endcount - 1)) $basename \
-                               || return 1
+                               || return $?
                        startcount=$((endcount + 1))
                fi
+
                ((endcount++))
        done
 }