From: Bastian Dehn Date: Sat, 5 Jul 2025 10:54:44 +0000 (+0200) Subject: change scantopdf to basic X-Git-Tag: v1.0.7^2~11 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=84a3e6e17d114d03d109931097f41cd8fe487e1d;p=scantopdf.git change scantopdf to basic --- diff --git a/scanbasic.bats b/scanbasic.bats index bf75ac7..b2c6dec 100755 --- a/scanbasic.bats +++ b/scanbasic.bats @@ -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 +} diff --git a/scanbasic.sh b/scanbasic.sh index 4d0b7d8..378c634 100644 --- a/scanbasic.sh +++ b/scanbasic.sh @@ -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 $? +} diff --git a/scantopdf b/scantopdf index 0606468..8c22b8a 100755 --- 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" } diff --git a/scantopdfbw b/scantopdfbw index 2007c6a..977aa97 100755 --- a/scantopdfbw +++ b/scantopdfbw @@ -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" } diff --git a/scantopdfgray b/scantopdfgray index 0d28506..6a39c30 100755 --- a/scantopdfgray +++ b/scantopdfgray @@ -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" }