]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
add tests for detectsplit
authorBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 09:59:50 +0000 (11:59 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 09:59:50 +0000 (11:59 +0200)
scanbasic.bats
scanbasic.sh

index 44cf3ef1244c98ad9a33dcf2f0bd3273bab50b11..fc5861daad88857c00200d3954874ebb3e18452e 100755 (executable)
@@ -30,6 +30,11 @@ pdftk() {
        return "$pdftk_exit"
 }
 
+zbarimg() {
+       echo "$zbarimg_return"
+       return "$zbarimg_exit"
+}
+
 setup() {
        load "/usr/lib/bats/bats-assert/load"
        load "/usr/lib/bats/bats-support/load"
@@ -59,6 +64,10 @@ setup() {
        export -f pdftk
        pdftk_return=
        pdftk_exit=0
+
+       export -f zbarimg
+       zbarimg_return=
+       zbarimg_exit=0
 }
 
 teardown() {
@@ -68,6 +77,7 @@ teardown() {
        export -n tiff2pdf
        export -n rm
        export -n pdftk
+       export -n zbarimg
 }
 
 @test "should failure optimize input parameter is missing" {
@@ -201,3 +211,35 @@ teardown() {
 
        assert_success
 }
+
+@test "should failure detectsplit missing parameter" {
+       run detectsplit
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing pdf"
+}
+
+@test "should failure detectsplit zbarimg fails" {
+       zbarimg_exit=1
+
+       run detectsplit "testfile.pdf"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: could not read cut page"
+}
+
+@test "should success and false detectsplit zbarimg nothing find" {
+       run detectsplit "testfile.pdf"
+
+       assert_success
+       assert_line --index 0 "false"
+}
+
+@test "should success and true detectsplit zbarimg find trennblatt" {
+       zbarimg_return="Trennblatt"
+
+       run detectsplit "testfile.pdf"
+
+       assert_success
+       assert_line --index 0 "true"
+}
index d78151096fa895273756aff91f68e0586856d16f..e20e2e5d1312fb827a405910fc5ea2ff2720b43c 100644 (file)
@@ -134,13 +134,20 @@ detectsplit()
        local pdf=$1
        local trenn=
 
+       command -v zbarimg > /dev/null \
+               || errlog "command zbarimg not found" \
+               || return $?
+       [ -n "$pdf" ] \
+               || errlog "missing pdf" \
+               || return $?
+
        trenn=$(zbarimg --raw --quiet $pdf) \
                || errlog "could not read cut page" \
-               || return 1
-       if [ "$trenn" == "Trennblatt" ]; then
-               echo "true"
-               return
-       fi
+               || return $?
+
+       [ "$trenn" == "Trennblatt" ] \
+               && echo "true" \
+               && return 0
 
        echo "false"
 }