]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
change scantopdf to basic
authorBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 10:54:44 +0000 (12:54 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 5 Jul 2025 10:54:44 +0000 (12:54 +0200)
scanbasic.bats
scanbasic.sh
scantopdf
scantopdfbw
scantopdfgray

index bf75ac7dc02361265edfa1a46cfc33391ef5724d..b2c6dec015edd21a1ea166dd98f1313c03b52fdc 100755 (executable)
@@ -35,6 +35,11 @@ zbarimg() {
        return "$zbarimg_exit"
 }
 
+scanimage() {
+       echo "$scanimage_return"
+       return "$scanimage_exit"
+}
+
 setup() {
        load "/usr/lib/bats/bats-assert/load"
        load "/usr/lib/bats/bats-support/load"
@@ -68,6 +73,10 @@ setup() {
        export -f zbarimg
        zbarimg_return=
        zbarimg_exit=0
+
+       export -f scanimage
+       scanimage_return=
+       scanimage_exit=0
 }
 
 teardown() {
@@ -78,6 +87,7 @@ teardown() {
        export -n rm
        export -n pdftk
        export -n zbarimg
+       export -n scanimage
 }
 
 @test "should failure optimize input parameter is missing" {
@@ -274,3 +284,39 @@ teardown() {
 
        assert_success
 }
+
+@test "should failure scantopdf missing mode parameter" {
+       run scantopdf
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing mode"
+}
+
+@test "should failure scantopdf missing pagecount parameter" {
+       run scantopdf "Color"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing pagecount"
+}
+
+@test "should failure scantopdf missing output parameter" {
+       run scantopdf "Color" "5"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: missing output"
+}
+
+@test "should failure scantopdf scanimage fails" {
+       scanimage_exit=1
+
+       run scantopdf "Color" "1" "test.pdf"
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: scan error"
+}
+
+@test "should success scantopdf" {
+       run scantopdf "Color" "1" "test.pdf"
+
+       assert_success
+}
index 4d0b7d80145bbba5630f681822a9decc2d5a1743..378c6347be82b2227dcaa1de53cc1609a2b4e09a 100644 (file)
@@ -190,3 +190,43 @@ createmultipdfs()
                ((endcount++))
        done
 }
+
+scantopdf() {
+       local mode="$1"
+       local pagecount="$2"
+       local output="$3"
+
+       command -v scanimage > /dev/null \
+               || errlog "command scanimage not found" \
+               || return $?
+       [ -n "$mode" ] \
+               || errlog "missing mode" \
+               || return $?
+       [ -n "$pagecount" ] \
+               || errlog "missing pagecount" \
+               || return $?
+       [ -n "$output" ] \
+               || errlog "missing output" \
+               || return $?
+
+       scanimage --source=DocumentFeeder \
+               --mode=$mode \
+               --resolution=300 \
+               --scanside=Duplex \
+               --skip-blank-pages=yes \
+               --format=tiff \
+               --batch-count=$pagecount \
+               --batch-increment=1 \
+               --batch=scanned%03d.tiff \
+               || errlog "scan error" \
+               || return $?
+
+       if [ "$output" == "multi" ]; then
+               createmultipdfs $pagecount \
+                       || return $?
+               return
+       fi
+
+       createonepdf $output \
+               || return $?
+}
index 06064688a1456b93f8062f63f60818fd1d36773e..8c22b8a9082bcf78c69c22e3c4d1e2aadb31da5e 100755 (executable)
--- a/scantopdf
+++ b/scantopdf
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-@scanbasic.sh@
+@scanbasic.sh@
 
 main()
 {
@@ -9,30 +9,10 @@ main()
        local basename=$3
 
        echo "⭐ START: scantopdf"
-       command -v scanimage > /dev/null \
-               || errlog "command scanimage not found" \
-               || return $?
-       [ -n "$pagecount" ] || errlog "missing page count" || return $?
-       [ -n "$output" ] || errlog "missing output name" || return $?
 
-       scanimage --source=DocumentFeeder \
-               --mode=Color \
-               --resolution=300 \
-               --scanside=Duplex \
-               --skip-blank-pages=yes \
-               --format=tiff \
-               --batch-count=$pagecount \
-               --batch-increment=1 \
-               --batch=scanned%03d.tiff \
-               || errlog "scan error" \
+       scantopdf "Color" "$pagecount" "$basename" \
                || return $?
 
-       if [ "$output" == "multi" ]; then
-               createmultipdfs $pagecount $basename || return $?
-               return
-       fi
-
-       createonepdf $output || return $?
        echo "✅ SUCCESS: scantopdf"
 }
 
index 2007c6a81fcb75baa62dae4740a4f1821f3ff7a0..977aa97029192d4f8cc50170d0f5e8d545bff2c2 100755 (executable)
@@ -9,30 +9,10 @@ main()
        local basename=$3
 
        echo "⭐ START: scantopdfbw"
-       command -v scanimage > /dev/null \
-               || errlog "command scanimage not found" \
-               || return $?
-       [ -n "$pagecount" ] || errlog "missing page count" || return $?
-       [ -n "$output" ] || errlog "missing output name" || return $?
 
-       scanimage --source=DocumentFeeder \
-               --mode=BW \
-               --resolution=300 \
-               --scanside=Duplex \
-               --skip-blank-pages=yes \
-               --format=tiff \
-               --batch-count=$pagecount \
-               --batch-increment=1 \
-               --batch=scanned%03d.tiff \
-               || errlog "scan error" \
+       scantopdf "BW" "$pagecount" "$basename" \
                || return $?
 
-       if [ "$output" == "multi" ]; then
-               createmultipdfs $pagecount $basename || return 1
-               return
-       fi
-
-       createonepdf $output || return $?
        echo "✅ SUCCESS: scantopdfbw"
 }
 
index 0d28506f51069cdddb8e880620b5749e9230895a..6a39c3040f4a36cd3562579675f0bd873dc4eabd 100755 (executable)
@@ -9,30 +9,10 @@ main()
        local basename=$3
 
        echo "⭐ START: scantopdfgray"
-       command -v scanimage > /dev/null \
-               || errlog "command scanimage not found" \
-               || return $?
-       [ -n "$pagecount" ] || errlog "missing page count" || return $?
-       [ -n "$output" ] || errlog "missing output name" || return $?
 
-       scanimage --source=DocumentFeeder \
-               --mode=Gray \
-               --resolution=300 \
-               --scanside=Duplex \
-               --skip-blank-pages=yes \
-               --format=tiff \
-               --batch-count=$pagecount \
-               --batch-increment=1 \
-               --batch=scanned%03d.tiff \
-               || errlog "scan error" \
+       scantopdf "Gray" "$pagecount" "$basename" \
                || return $?
 
-       if [ "$output" == "multi" ]; then
-               createmultipdfs $pagecount $basename || return 1
-               return
-       fi
-
-       createonepdf $output || return $?
        echo "✅ SUCCESS: scantopdfgray"
 }