From be2902102705272efc3d2a9ebb9c5ef6761c05b4 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 1 Apr 2018 02:41:01 +0000 Subject: Add tests for pbmtext -wchar git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3189 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- test/Execute-Tests | 2 +- test/Test-Order | 3 ++ test/pbmtext-bdf.ok | 8 ++++ test/pbmtext-bdf.test | 99 ++++++++++++++++++++++++++++++++++++++++++++++ test/pbmtext-iso88591.ok | 4 ++ test/pbmtext-iso88591.test | 46 +++++++++++++++++++++ test/pbmtext-utf8.ok | 8 ++++ test/pbmtext-utf8.test | 91 ++++++++++++++++++++++++++++++++++++++++++ test/pbmtext.ok | 8 ---- test/pbmtext.test | 93 +------------------------------------------ 10 files changed, 262 insertions(+), 100 deletions(-) create mode 100644 test/pbmtext-bdf.ok create mode 100755 test/pbmtext-bdf.test create mode 100644 test/pbmtext-iso88591.ok create mode 100755 test/pbmtext-iso88591.test create mode 100644 test/pbmtext-utf8.ok create mode 100755 test/pbmtext-utf8.test (limited to 'test') diff --git a/test/Execute-Tests b/test/Execute-Tests index e69c84e7..7a65d51f 100755 --- a/test/Execute-Tests +++ b/test/Execute-Tests @@ -180,7 +180,7 @@ elif [ $VALGRIND_TESTS = "on" ] vg_command_base="valgrind --trace-children=yes"; for i in awk cat cksum cmp cp cut date dirname egrep fgrep file grep gs \ - head mkdir mktemp perl rm sed seq sh tee testrandom tr uniq \ + head iconv mkdir mktemp perl rm sed seq sh tee testrandom tr uniq \ Available-Testprog # Tell valgrind not to probe execution of the above programs. diff --git a/test/Test-Order b/test/Test-Order index 9b280d12..6abc2287 100644 --- a/test/Test-Order +++ b/test/Test-Order @@ -12,6 +12,9 @@ pamseq.test pbmpage.test pbmtext.test +pbmtext-bdf.test +pbmtext-iso88591.test +pbmtext-utf8.test pbmupc.test pgmramp.test pamgauss.test diff --git a/test/pbmtext-bdf.ok b/test/pbmtext-bdf.ok new file mode 100644 index 00000000..5ab8b4af --- /dev/null +++ b/test/pbmtext-bdf.ok @@ -0,0 +1,8 @@ +386826492 35 +1 +1 +1 +1 +1 +1 +1 diff --git a/test/pbmtext-bdf.test b/test/pbmtext-bdf.test new file mode 100755 index 00000000..1bd7c52c --- /dev/null +++ b/test/pbmtext-bdf.test @@ -0,0 +1,99 @@ +#! /bin/bash +# This script tests: pbmtext +# Also requires: + +tmpdir=${tmpdir:-/tmp} + +font_bdf=${tmpdir}/font.bdf +font_corrupt_bdf=${tmpdir}/fontcorrupt.bdf + +# Though this BDF font file defines only three letters, it is valid. + +cat > ${font_bdf} << EOF +STARTFONT 2.1 +COMMENT simple font for pbmtext test +COMMENT derived from: $XFree86: xc/fonts/bdf/misc/micro.bdf,v 1.1 1999/09/25 14:36:34 dawes Exp $ +FONT test +SIZE 4 75 75 +FONTBOUNDINGBOX 4 5 0 0 +STARTPROPERTIES 5 +FONT_DESCENT 0 +FONT_ASCENT 5 +CHARSET_REGISTRY "ISO88591" +CHARSET_ENCODING "1" +COPYRIGHT "Public domain font. Share and enjoy." +ENDPROPERTIES +CHARS 3 +STARTCHAR A +ENCODING 65 +SWIDTH 1000 0 +DWIDTH 4 0 +BBX 4 5 0 0 +BITMAP +e0 +a0 +e0 +a0 +a0 +ENDCHAR +STARTCHAR B +ENCODING 66 +SWIDTH 1000 0 +DWIDTH 4 0 +BBX 4 5 0 0 +BITMAP +e0 +a0 +c0 +a0 +e0 +ENDCHAR +STARTCHAR C +ENCODING 67 +SWIDTH 1000 0 +DWIDTH 4 0 +BBX 4 5 0 0 +BITMAP +e0 +80 +80 +80 +e0 +ENDCHAR +ENDFONT +EOF + +# Test 1 +# This should succeed and produce 386826492 35 +pbmtext -font ${font_bdf} ABC | cksum + + +# Test 2 +# The rest should all fail. Writes 1 seven times. + +echo "Test whether corrupted BDF font files are properly handled." 1>&2 +echo "Error messages will appear." 1>&2 +echo 1>&2 + +pbmtext -font ${font_bdf} BCD +echo $? + +sed 's/FONTBOUNDINGBOX 4 5 0 0/FONTBOUNDINGBOX 4 4 0 0/' \ + ${font_bdf} > ${font_corrupt_bdf} +pbmtext -font ${font_corrupt_bdf} ABC > /dev/null +echo $? +rm ${font_corrupt_bdf} + +sed 's/BBX 4 5 0 0/BBX 4 6 0 0/' \ + ${font_bdf} > ${font_corrupt_bdf} +pbmtext -font ${font_corrupt_bdf} ABC > /dev/null +echo $? +rm ${font_corrupt_bdf} + +for delete_line in 14 16 18 20 + do + sed "${delete_line}"d ${font_bdf} > ${font_corrupt_bdf} + pbmtext -font ${font_corrupt_bdf} ABC > /dev/null + echo $? + rm ${font_corrupt_bdf} + done diff --git a/test/pbmtext-iso88591.ok b/test/pbmtext-iso88591.ok new file mode 100644 index 00000000..d1516357 --- /dev/null +++ b/test/pbmtext-iso88591.ok @@ -0,0 +1,4 @@ +3491766365 5110 +3491766365 5110 +259944121 191 +259944121 191 diff --git a/test/pbmtext-iso88591.test b/test/pbmtext-iso88591.test new file mode 100755 index 00000000..34346f5c --- /dev/null +++ b/test/pbmtext-iso88591.test @@ -0,0 +1,46 @@ +#! /bin/bash +# This script tests: pbmtext +# Also requires: + +# This test requires the following locale: +# LC_ALL en_US.iso88591 +# Skip this test if it is not available + +iconv /dev/null +if [ $? -ne 0 ] + then echo "iconv command not available." 1>&2 + echo "Skipping." 1>&2 + exit 80; +fi + +echo "A" | LC_ALL=en_US.iso88591 pbmtext -wchar > /dev/null +if [ $? -ne 0 ] + then echo "LC_ALL could not be set to en_US.iso88591" 1>&2 + echo "Skipping." 1>&2 + exit 80; +fi + +# Two rows +# Should print 3491766365 5110 twice +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=160;i<=255;++i) printf("%c",i); }' | \ + pbmtext -builtin bdf | cksum + + +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=160;i<=255;++i) printf("%c",i); }' | \ + LC_ALL=en_US.iso88591 pbmtext -builtin bdf -wchar | cksum + + +# Two rows +# Should print 259944121 191 twice +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=161;i<=255;++i) printf("%c",i); print "" }' | cksum + +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=161;i<=255;++i) printf("%c",i); print ""}' | \ + LC_ALL=en_US.iso88591 pbmtext -builtin bdf -wchar -text-dump | cksum \ No newline at end of file diff --git a/test/pbmtext-utf8.ok b/test/pbmtext-utf8.ok new file mode 100644 index 00000000..864c530a --- /dev/null +++ b/test/pbmtext-utf8.ok @@ -0,0 +1,8 @@ +1240895458 5110 +1240895458 5110 +898975479 2272 +898975479 2272 +0 + !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} + !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} +1 diff --git a/test/pbmtext-utf8.test b/test/pbmtext-utf8.test new file mode 100755 index 00000000..ca1f45a2 --- /dev/null +++ b/test/pbmtext-utf8.test @@ -0,0 +1,91 @@ +#! /bin/bash +# This script tests: pbmtext +# Also requires: + +# This test requires the en_US.utf8 locale +# Skip this test if it is not available + +iconv /dev/null +if [ $? -ne 0 ] + then echo "iconv command not available." 1>&2 + echo "Skipping." 1>&2 + exit 80; +fi + +echo "A" | LC_ALL=en_US.utf8 pbmtext -wchar > /dev/null +if [ $? -ne 0 ] + then echo "LC_ALL could not be set to en_US.utf8." 1>&2 + echo "Skipping." 1>&2 + exit 80; +fi + +# Test 1. +# Two rows +# Should print 1240895458 5110 twice +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=161;i<=255;++i) printf("%c",i); }' | \ + pbmtext -builtin bdf | cksum + +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=161;i<=255;++i) printf("%c",i); }' | \ + iconv -f iso8859-1 -t utf-8 | \ + LC_ALL=en_US.utf8 pbmtext -builtin bdf -wchar | cksum + + +# Test 2. +# One row +# Should print 898975479 2272 twice +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print "" }' | \ + pbmtext -builtin bdf | cksum + +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""}' | \ + LC_ALL=en_US.utf8 pbmtext -builtin bdf -wchar | cksum + + +tmpdir=${tmpdir:-/tmp} +output=${tmpdir}/output + + +# Test 3. +# Two rows +# Output may be affected by locale. Compare with cmp. +# Should print 0 +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=161;i<=255;++i) printf("%c",i); print "" }' | \ + iconv -f iso88591 -t utf8 > ${output} + +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""; \ + for (i=161;i<=255;++i) printf("%c",i); print "" }' | \ + iconv -f iso8859-1 -t utf-8 | \ + LC_ALL=en_US.utf8 pbmtext -builtin bdf -wchar -text-dump | \ + cmp --quiet - ${output} + +echo $? +rm ${output} + + +# Test 4. +# One row +# Should print the following twice: +# !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print "" } ' + +LC_ALL=C \ +awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); print ""}' | \ + LC_ALL=en_US.utf8 pbmtext -builtin bdf -wchar -text-dump + + +# Test 5. +# Invalid utf-8 sequence +# Should print 1 +LC_ALL=C \ +awk 'BEGIN { for (i=128; i<=129;++i) printf("%c",i); print ""}' | \ + LC_ALL=en_US.utf8 pbmtext -builtin bdf -wchar -text-dump +echo $? diff --git a/test/pbmtext.ok b/test/pbmtext.ok index bd12fb94..000c0897 100644 --- a/test/pbmtext.ok +++ b/test/pbmtext.ok @@ -14,11 +14,3 @@ 1647614653 2027 3233136020 4535 1216262214 5711 -386826492 35 -1 -1 -1 -1 -1 -1 -1 diff --git a/test/pbmtext.test b/test/pbmtext.test index eeb8bf50..c92ed599 100755 --- a/test/pbmtext.test +++ b/test/pbmtext.test @@ -81,103 +81,14 @@ rm ${fontRectangle_txt} ${font_pbm} # One long row # Should print 3233136020 4535 -LC_CTYPE=C \ +LC_ALL=C \ awk 'BEGIN { for (i=32; i<=125;++i) printf("%c",i); for (i=160;i<=255;++i) printf("%c",i); }' | \ pbmtext -builtin bdf | cksum # One tall column # Should print 1216262214 5711 -LC_CTYPE=C \ +LC_ALL=C \ awk 'BEGIN { for (i=32; i<=125;++i) printf("%c\n",i); for (i=160;i<=255;++i) printf("%c\n",i); }' | \ pbmtext -nomargins -builtin bdf | cksum - - -# Test 6: -# Test corruptions in BDF font file. - -font_bdf=${tmpdir}/font.bdf -font_corrupt_bdf=${tmpdir}/fontcorrupt.bdf - -# Though this BDF font file defines only three letters, it is valid. - -cat > ${font_bdf} << EOF -STARTFONT 2.1 -COMMENT $XFree86: xc/fonts/bdf/misc/micro.bdf,v 1.1 1999/09/25 14:36:34 dawes Exp $ - Modified for test -FONT micro -SIZE 4 75 75 -FONTBOUNDINGBOX 4 5 0 0 -STARTPROPERTIES 3 -FONT_DESCENT 0 -FONT_ASCENT 5 -CHARSET_REGISTRY "ISO88591" -CHARSET_ENCODING "1" -COPYRIGHT "Public domain font. Share and enjoy." -ENDPROPERTIES -CHARS 3 -STARTCHAR A -ENCODING 65 -SWIDTH 1000 0 -DWIDTH 4 0 -BBX 4 5 0 0 -BITMAP -e0 -a0 -e0 -a0 -a0 -ENDCHAR -STARTCHAR B -ENCODING 66 -SWIDTH 1000 0 -DWIDTH 4 0 -BBX 4 5 0 0 -BITMAP -e0 -a0 -c0 -a0 -e0 -ENDCHAR -STARTCHAR C -ENCODING 67 -SWIDTH 1000 0 -DWIDTH 4 0 -BBX 4 5 0 0 -BITMAP -e0 -80 -80 -80 -e0 -ENDCHAR -ENDFONT -EOF - -# This should succeed and produce 386826492 35 -pbmtext -font ${font_bdf} ABC | cksum - -# The rest should all fail. Writes 1 seven times. -pbmtext -font ${font_bdf} BCD -echo $? - -sed 's/FONTBOUNDINGBOX 4 5 0 0/FONTBOUNDINGBOX 4 4 0 0/' \ - ${font_bdf} > ${font_corrupt_bdf} -pbmtext -font ${font_corrupt_bdf} ABC > /dev/null -echo $? -rm ${font_corrupt_bdf} - -sed 's/BBX 4 5 0 0/BBX 4 6 0 0/' \ - ${font_bdf} > ${font_corrupt_bdf} -pbmtext -font ${font_corrupt_bdf} ABC > /dev/null -echo $? -rm ${font_corrupt_bdf} - -for delete_line in 14 16 18 20 - do - sed "${delete_line}"d ${font_bdf} > ${font_corrupt_bdf} - pbmtext -font ${font_corrupt_bdf} ABC > /dev/null - echo $? - rm ${font_corrupt_bdf} - done -- cgit 1.4.1