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"
export -f zbarimg
zbarimg_return=
zbarimg_exit=0
+
+ export -f scanimage
+ scanimage_return=
+ scanimage_exit=0
}
teardown() {
export -n rm
export -n pdftk
export -n zbarimg
+ export -n scanimage
}
@test "should failure optimize input parameter is missing" {
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
+}
((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 $?
+}
#!/bin/bash
-@scanbasic.sh@
+# @scanbasic.sh@
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"
}
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"
}
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"
}