TheMathemagicians/scanner/test_card_scanner_count

35 lines
923 B
Bash
Executable File

#!/bin/bash
if test -z "$1"; then
echo "usage: test_card_scanner_count <count>" >&2
exit 1
fi
STORAGE_DIR="$HOME/.local/share/sevenkeys/testimages/"
mkdir -p "$STORAGE_DIR"
starting_file_count="$(find $STORAGE_DIR/*.png | wc -l)"
echo "test_card_scanner_count: Beginning test"
while true; do
rng="$(cat /dev/random | tr -cd 'a-f0-9' | head -c 32)"
filename="$STORAGE_DIR/$rng.png"
scanimage --output-file="$filename" --source "ADF Front" --mode Color --page-width 63mm --page-height 88mm 2>/dev/null
# scanimage exits with code 7 if no documents are available in scanner
if test $? -eq 7; then
echo "test_card_scanner_count: No more cards in feeder" >&2
rm "$filename"
break
fi
done
ending_file_count="$(find $STORAGE_DIR/*.png | wc -l)"
if test $(( ending_file_count - starting_file_count )) -ne "$1"; then
echo "FAILED: Start: $starting_file_count, End: $ending_file_count"
else
echo "SUCCESS"
fi