Test ASCII and ISO-8859-1 output.

This commit is contained in:
John Hood
2015-10-16 12:10:31 -04:00
parent 8681199957
commit 65ced750e6
2 changed files with 103 additions and 0 deletions
+102
View File
@@ -0,0 +1,102 @@
#!/bin/sh
#
# This validates display of ASCII and ISO-8859-1 characters.
#
fail()
{
printf "$@" 2>&1
exit 99
}
PATH=$PATH:.:$srcdir
# Top-level wrapper.
if [ $# -eq 0 ]; then
e2e-test $0 baseline direct verify
exit
fi
# OK, we have arguments, we're one of the test hooks.
if [ $# -ne 1 ]; then
fail "bad arguments %s\n" "$@"
fi
sleepf()
{
(sleep .1 || sleep 1) > /dev/null 2>&1
}
seq()
{
if [ $# -lt 1 -o $# -gt 3 ]; then
echo "bad args" >&2
fi
first=$1
incr=1
last=0
case $# in
3)
incr=$2
last=$3
;;
2)
last=$2
;;
1)
;;
esac
while :; do
printf '%d\n' $first
first=$(expr $first + $incr)
if [ $first -gt $last ]; then
break
fi
done
}
chr()
{
printf "\\$(printf %03o $1)"
}
utf8cp()
{
local c=$1
if [ $c -gt $((0x10ffff)) ]; then
fail "illegal Unicode code point %x\n" $c
elif [ $c -lt $((0x80)) ]; then
chr $c
elif [ $c -lt $((0x800)) ]; then
chr $(( (($c >> 6) & 0x1f) | 0xc0 ))
chr $(( ($c & 0x3f) | 0x80 ))
elif [ $c -lt $((0x10000)) ]; then
chr $(( (($c >> 12) & 0x0f) | 0xe0 ))
chr $(( (($c >> 6) & 0x3f) | 0x80 ))
chr $(( ($c & 0x3f) | 0x80 ))
elif [ $c -lt $((0x200000)) ]; then
chr $(( (($c >> 18) & 0x03) | 0xf0 ))
chr $(( (($c >> 12) & 0x3f) | 0x80 ))
chr $(( (($c >> 6) & 0x3f) | 0x80 ))
chr $(( ($c & 0x3f) | 0x80 ))
fi
}
baseline()
{
printf '\033[H\033[J'
# ASCII, then ISO-8859-1.
for char in $(seq 32 126) $(seq 160 255) ; do
printf '%02x %s ' $char "$(utf8cp $char)"
done
printf '\n'
}
case $1 in
baseline|direct)
baseline;;
*)
fail "unknown test argument %s\n" $1;;
esac