about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-09-15 01:39:06 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-09-15 01:39:06 +0000
commitd22a29c04d4cf6125ea441e37d70c83193551e11 (patch)
tree455ab8cbaad0e91e16bd577f859c12f27d8a91e0
parent360dbe6199c8607a19f8b3848826d9f721ac2a11 (diff)
downloadnetpbm-mirror-d22a29c04d4cf6125ea441e37d70c83193551e11.tar.gz
netpbm-mirror-d22a29c04d4cf6125ea441e37d70c83193551e11.tar.xz
netpbm-mirror-d22a29c04d4cf6125ea441e37d70c83193551e11.zip
color name parsing tests
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4944 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--test/Test-Order8
-rwxr-xr-xtest/infotopam.test2
-rw-r--r--test/parsecolor.ok106
-rwxr-xr-xtest/parsecolor.test146
-rw-r--r--test/ppmmake.ok40
-rwxr-xr-xtest/ppmmake.test91
-rw-r--r--test/rgbt.txt11
7 files changed, 384 insertions, 20 deletions
diff --git a/test/Test-Order b/test/Test-Order
index 3b3fc4af..b4e1f659 100644
--- a/test/Test-Order
+++ b/test/Test-Order
@@ -4,13 +4,19 @@ all-in-place.test
 legacy-names.test
 random-generator.test
 
-# Generator tests
+# Generator tests (1)
 
 pbmmake.test
 pgmmake.test
 ppmmake.test
 pamseq.test
 
+# Library test
+
+parsecolor.test
+
+# Generator tests (2)
+
 pbmpage.test
 pbmtext.test
 pbmtext-bdf.test
diff --git a/test/infotopam.test b/test/infotopam.test
index 5b849c65..feace493 100755
--- a/test/infotopam.test
+++ b/test/infotopam.test
@@ -5,7 +5,7 @@
 tmpdir=${tmpdir:-/tmp}
 test1_pam=${tmpdir}/test1.pam
 test1ch_ppm=${tmpdir}/test1ch.ppm
-RGBDEF=./rgb.test
+RGBDEF=./rgbt.txt
 
 cp "$srcdir/test1.info" "$tmpdir"
 cp "$srcdir/test2.info" "$tmpdir"
diff --git a/test/parsecolor.ok b/test/parsecolor.ok
new file mode 100644
index 00000000..3f64bded
--- /dev/null
+++ b/test/parsecolor.ok
@@ -0,0 +1,106 @@
+Sanity check: valid cases
+P3
+5 1
+255
+255 255 0  255 255 0  255 255 0  255 255 0  255 255 0
+P3
+1 2
+255
+0 0 255
+0 0 255
+P3
+3 1
+255
+255 0 0  255 0 0  255 0 0
+P3
+1 1
+255
+255 255 255
+P3
+1 1
+255
+128 128 128
+Test Invalid: general
+Expected failure 1 (no output)
+Expected failure 2 (no output)
+Expected failure 3 (no output)
+Expected failure 4 (no output)
+Test Invalid: rgb:r/g/b
+Expected failure 5 (no output)
+Expected failure 6 (no output)
+Expected failure 7 (no output)
+Expected failure 8 (no output)
+Expected failure 9 (no output)
+Expected failure 10 (no output)
+Expected failure 11 (no output)
+Expected failure 12 (no output)
+Expected failure 13 (no output)
+Expected failure 14 (no output)
+Expected failure 15 (no output)
+Expected failure 16 (no output)
+Expected failure 17 (no output)
+Expected failure 18 (no output)
+Expected failure 19 (no output)
+Expected failure 20 (no output)
+Test Invalid: rgbi:r/g/b
+Expected failure 21 (no output)
+Expected failure 22 (no output)
+Expected failure 23 (no output)
+Expected failure 24 (no output)
+Expected failure 25 (no output)
+Expected failure 26 (no output)
+Expected failure 27 (no output)
+Expected failure 28 (no output)
+Expected failure 29 (no output)
+Expected failure 30 (no output)
+Expected failure 31 (no output)
+Expected failure 32 (no output)
+Expected failure 33 (no output)
+Test Invalid: rgb-int:r/g/b
+Expected failure 34 (no output)
+Expected failure 35 (no output)
+Expected failure 36 (no output)
+Expected failure 37 (no output)
+Expected failure 38 (no output)
+Expected failure 39 (no output)
+Expected failure 40 (no output)
+Expected failure 41 (no output)
+Expected failure 42 (no output)
+Expected failure 43 (no output)
+Expected failure 44 (no output)
+Expected failure 45 (no output)
+Expected failure 46 (no output)
+Expected failure 47 (no output)
+Expected failure 48 (no output)
+Expected failure 49 (no output)
+Expected failure 50 (no output)
+Expected failure 51 (no output)
+Test Invalid: #rrggbb (Old X11 style)
+Expected failure 52 (no output)
+Expected failure 53 (no output)
+Expected failure 54 (no output)
+Expected failure 55 (no output)
+Expected failure 56 (no output)
+Expected failure 57 (no output)
+Expected failure 58 (no output)
+Expected failure 59 (no output)
+Expected failure 60 (no output)
+Expected failure 61 (no output)
+Test Invalid: r,g,b (raw floating point numbers)
+Expected failure 62 (no output)
+Expected failure 63 (no output)
+Expected failure 64 (no output)
+Expected failure 65 (no output)
+Expected failure 66 (no output)
+Expected failure 67 (no output)
+Expected failure 68 (no output)
+Expected failure 69 (no output)
+Expected failure 70 (no output)
+Expected failure 71 (no output)
+Expected failure 72 (no output)
+Test Invalid: invalid colorspec file
+Expected failure 73 (no output)
+Expected failure 74 (no output)
+Should print match, then no match
+match
+no match
diff --git a/test/parsecolor.test b/test/parsecolor.test
new file mode 100755
index 00000000..6c651fb3
--- /dev/null
+++ b/test/parsecolor.test
@@ -0,0 +1,146 @@
+#! /bin/sh
+# This script tests: ppmmake
+# Also requires:
+
+echo "Sanity check: valid cases"
+
+yellow="rgb:f/f/0"
+blue="rgbi:0/0/1.0"
+red="rgb-255:255/000/000"
+white="#FFFFFF"
+grey=".5,.5,.5"
+
+ppmmake -plain ${yellow} 5  1
+ppmmake -plain ${blue}   1  2
+ppmmake -plain ${red}    3  1
+ppmmake -plain ${white}  1  1
+ppmmake -plain ${grey}   1  1
+
+. ${srcdir}/test-invalid.inc
+
+echo "Test Invalid: general"
+
+invCmd "ppmmake RGB:ff/00/00 2 2"
+invCmd "ppmmake rgb/ff/80/90 2 2"
+invCmd "ppmmake kgb:ff/80/90 2 2"
+invCmd "ppmmake rgb:ff:80:90 2 2"
+
+echo "Test Invalid: rgb:r/g/b"
+
+invCmd "ppmmake rgb 1 1"
+invCmd "ppmmake rgb:/ 1 2"
+invCmd "ppmmake rgb: 1 3"
+invCmd "ppmmake rgb:g/0/0 1 4"
+invCmd "ppmmake rgb:ff        1 5"
+invCmd "ppmmake rgb:ff/00     1 6"
+invCmd "ppmmake rgb:ff/00/0.0 1 7"
+invCmd "ppmmake rgb:ff/00/0.0 1 8"
+invCmd "ppmmake rgb:ff/00/00/ 1 9"
+invCmd "ppmmake rgb:/ff/00/00 2 1"
+invCmd "ppmmake rgb:ff//00/00 2 2"
+invCmd "ppmmake rgb:ff/00//00 2 3"
+invCmd "ppmmake rgb:ff/00/00/00 2 4"
+
+invCmd "ppmmake rgb:10000/0000/0000 2 5"
+invCmd "ppmmake rgb:ffff/10000/0000 2 6"
+invCmd "ppmmake rgb:ffff/ffff/10000 2 7"
+
+echo "Test Invalid: rgbi:r/g/b"
+
+invCmd "ppmmake rgbi 3 1"
+invCmd "ppmmake rgbi: 3 2"
+invCmd "ppmmake rgbi:/ 3 3"
+invCmd "ppmmake rgbi:1.0     3 4"
+invCmd "ppmmake rgbi:1.0/0.0 3 5"
+invCmd "ppmmake rgbi:1.2/0/0 3 6"
+invCmd "ppmmake rgbi:1.0/0.0/-0.1 3 7"
+invCmd "ppmmake rgbi:1.0/0.0/0.0/ 3 8"
+invCmd "ppmmake rgbi:/1.0/0.0/0.0 3 9"
+invCmd "ppmmake rgbi:1.0//0.0/0.0 4 1"
+invCmd "ppmmake rgbi:1.0/0.0//0.0 4 2"
+invCmd "ppmmake rgbi:1.0/0.0/0.0/0.0 4 3"
+invCmd "ppmmake rgbi:aa/ff/aa 4 4"
+
+# This is valid
+# invCmd "ppmmake rgbi:1.0/0.0/-0.0 8 8"
+
+echo "Test Invalid: rgb-int:r/g/b"
+
+invCmd "ppmmake rgb-15 5 1"
+invCmd "ppmmake rgb-15: 5 2"
+invCmd "ppmmake rgb-15:/ 5 3"
+invCmd "ppmmake rgb-15:0 5 4"
+invCmd "ppmmake rgb-15:0/15 5 5"
+invCmd "ppmmake rgb-255:256/00/00 5 6"
+invCmd "ppmmake rgb-255:255/00/0.0 5 7"
+invCmd "ppmmake rgb-255:255/00/00/ 5 8"
+invCmd "ppmmake rgb-255:/255/00/00 5 9"
+invCmd "ppmmake rgb-255:255//00/00 6 1"
+invCmd "ppmmake rgb-255:255/00//00 6 2"
+invCmd "ppmmake rgb-255:-2/00/00 6 3"
+invCmd "ppmmake rgb-255:255/00/00/00 6 4"
+invCmd "ppmmake rgb-65536:255/00/00 6 5"
+invCmd "ppmmake rgb-0:0/0/0 6 6"
+invCmd "ppmmake rgb-:0/0/0 6 7"
+invCmd "ppmmake rgb-ff:0/0/0 6 8"
+invCmd "ppmmake rgb-255:aa/ff/aa 6 9"
+
+echo "Test Invalid: #rrggbb (Old X11 style)"
+
+invCmd "ppmmake #F 7 1"
+invCmd "ppmmake #FF 7 2"
+
+invCmd "ppmmake #AA00 7 4"
+invCmd "ppmmake #FF00F 7 5"
+
+invCmd "ppmmake #FF00FFF 7 7"
+invCmd "ppmmake #FF00FFFF 7 8"
+
+invCmd "ppmmake #FF00FFFF00 7 10"
+invCmd "ppmmake #FF00FFFF000 7 11"
+
+invCmd "ppmmake #FF00FFFF00001 7 13"
+invCmd "ppmmake #FF00FG 7 16"
+
+echo "Test Invalid: r,g,b (raw floating point numbers)"
+# This color-specification format is provided for backward compability.
+# Use rgbi:r/g/b instead.
+
+invCmd "ppmmake 0.0 8 1"
+invCmd "ppmmake ,0.0 8 2"
+invCmd "ppmmake 0.0, 8 3"
+invCmd "ppmmake 0.0,1.0 8 4"
+invCmd "ppmmake 0.0,1.0, 8 5"
+invCmd "ppmmake 0.0,1.0,1.0, 8 6"
+invCmd "ppmmake ,0.0,1.0,1.0 8 7"
+invCmd "ppmmake 0.0,,1.0,1.0 8 8"
+
+invCmd "ppmmake 2.0,0.0,1.0 8 9"
+invCmd "ppmmake -1.0,0.0,1.0 8 10"
+invCmd "ppmmake 1.0,0.0,ff 8 11"
+
+tmpdir=${tmpdir:-/tmp}
+
+rgb_garbled=${tmpdir}/rgb_garbled.txt
+rgb_dupentry1=${tmpdir}/rgb_dupentry1.txt
+rgb_dupentry2=${tmpdir}/rgb_dupentry2.txt
+brown_ppm=${tmpdir}/brown.ppm
+
+echo "Test Invalid: invalid colorspec file"
+RGBDEF=${tmpdir}/null invCmd "ppmmake red 9 1"
+
+awk '!/#/ && NF==4 {$(NR%4+1) =""; print}' ./rgbt.txt > ${rgb_garbled}
+RGBDEF=${rgb_garbled} invCmd "ppmmake red 9 2"
+
+(cat ./rgbt.txt ; echo "128  42  42 Brown" ) >  ${rgb_dupentry1}
+(echo "128  42  42 Brown"; cat ./rgbt.txt  ) >  ${rgb_dupentry2}
+
+echo "Should print match, then no match"
+RGBDEF=./rgbt.txt ppmmake Brown 9 3 > ${brown_ppm}
+RGBDEF=${rgb_dupentry1}  ppmmake Brown 9 3 | cmp -s - ${brown_ppm} \
+  && echo "match" || echo "no match"
+
+RGBDEF=${rgb_dupentry2}  ppmmake Brown 9 3 | cmp -s - ${brown_ppm} \
+  && echo "match" || echo "no match"
+
+rm ${rgb_garbled} ${rgb_dupentry1} ${rgb_dupentry2} ${brown_ppm}
diff --git a/test/ppmmake.ok b/test/ppmmake.ok
index e365bd9e..8d0e7364 100644
--- a/test/ppmmake.ok
+++ b/test/ppmmake.ok
@@ -4,12 +4,33 @@ P3
 5
 0 0 0
 P3
-1 1
+1 2
 65535
 65535 65535 65535
+65535 65535 65535
+P3
+1 3
+5
+5 3 3
+5 3 3
+5 3 3
+Test 2.1 Should print 2477651508 15012
 2477651508 15012
+Test 2.2 Should print 2135932096 23
 135932096 23
+Test 3 Should print 2378991101 7513 three times
+2378991101 7513
+2378991101 7513
 2378991101 7513
+Test 4.1
+Test 4.1 Should print 2424932605 23
+2424932605 23
+Test 4.2 Should print 925463542 22
+925463542 22
+Test 4.3 Should print 3822292470 23
+3822292470 23
+Test 4.4 Should print 630041256 21
+630041256 21
 Test Invalid
 Expected failure 1 (no output)
 Expected failure 2 (no output)
@@ -21,3 +42,20 @@ Expected failure 7 (no output)
 Expected failure 8 (no output)
 Expected failure 9 (no output)
 Expected failure 10 (no output)
+Expected failure 11 (no output)
+Expected failure 12 (no output)
+Expected failure 13 (no output)
+Expected failure 14 (no output)
+Expected failure 15 (no output)
+Expected failure 16 (no output)
+Expected failure 17 (no output)
+Expected failure 18 (no output)
+Expected failure 19 (no output)
+Expected failure 20 (no output)
+Expected failure 21 (no output)
+Expected failure 22 (no output)
+Expected failure 23 (no output)
+Expected failure 24 (no output)
+Expected failure 25 (no output)
+Expected failure 26 (no output)
+Expected failure 27 (no output)
diff --git a/test/ppmmake.test b/test/ppmmake.test
index 35275110..771a1f61 100755
--- a/test/ppmmake.test
+++ b/test/ppmmake.test
@@ -5,23 +5,84 @@
 echo "Test 1"
 
 ppmmake -maxval=5 -plain rgb:00/00/00 1 1
-ppmmake -maxval=65535 -plain rgb:ff/ff/ff 1 1
+ppmmake -maxval=65535 -plain rgb:ff/ff/ff 1 2
+ppmmake -maxval=5 -plain rgb:ff/80/80 1 3
+
+echo "Test 2.1 Should print 2477651508 15012"
 ppmmake -maxval=5 rgb:ff/80/80 50 100 | cksum
+
+echo "Test 2.2 Should print 2135932096 23"
 ppmmake rgbi:0.5/1.0/0 2 2 | cksum
-ppmmake red 50 50  | cksum
+
+echo "Test 3 Should print 2378991101 7513 three times"
+
+ppmmake "#FFFF00000000" 50 50 | cksum
+ppmmake 1.0,0.0,0.0 50 50 | cksum
+RGBDEF=./rgbt.txt ppmmake red 50 50 | cksum
+
+echo "Test 4.1"
+
+yellow="rgb:f/f/0"
+blue="rgbi:0/0/1.0"
+
+echo "Test 4.1 Should print 2424932605 23"
+ppmmake ${yellow} 2 2 | cksum
+
+echo "Test 4.2 Should print 925463542 22"
+ppmmake -maxval=15 ${yellow} 2 2 | cksum
+
+echo "Test 4.3 Should print 3822292470 23"
+ppmmake ${blue}   2 2 | cksum
+
+echo "Test 4.4 Should print 630041256 21"
+ppmmake -maxval=1  ${blue}   2 2 | cksum 
 
 echo "Test Invalid"
 
-. ./test-invalid.inc
-
-invCmd "ppmmake rgb:gg/00/00  2 2"
-invCmd "ppmmake rgb:ff/ff/00  2"
-invCmd "ppmmake rgbi:1.1/0/0  2 2"
-invCmd "ppmmake rgbi:1.0/.5   2 2"
-invCmd "ppmmake rainbow       2 2"
-invCmd "ppmmake               2 2"
-invCmd "ppmmake blue -maxval=0 2 2"
-invCmd "ppmmake blue -maxval=-1 2 2"
-invCmd "ppmmake blue -maxval=65536 2 2"
-export  RGBDEF=/dev/null
-invCmd "ppmmake red 2 2"
+. ${srcdir}/test-invalid.inc
+
+# No color specified
+
+invCmd "ppmmake 199 199"
+
+# Invalid or missing width height
+
+invCmd "ppmmake ${yellow}"
+invCmd "ppmmake ${yellow} 200"
+invCmd "ppmmake ${yellow} 0 200"
+invCmd "ppmmake ${yellow} 120 0"
+invCmd "ppmmake ${yellow} -2 1"
+invCmd "ppmmake ${yellow} 1 -1"
+invCmd "ppmmake ${yellow} 100 99.9"
+invCmd "ppmmake ${yellow} 99.9 100"
+
+# Invalid maxval
+
+invCmd "ppmmake ${blue} -maxval=0     ${blue} 20 1"
+invCmd "ppmmake ${blue} -maxval=-1    ${blue} 20 2"
+invCmd "ppmmake ${blue} -maxval=65536 ${blue} 20 3"
+invCmd "ppmmake ${blue} -maxval=max ${blue} 20 4"
+invCmd "ppmmake ${blue} -maxval=0.9 ${blue} 20 5"
+
+# Invalid colorname file
+
+RGBDEF=/dev/null  invCmd "ppmmake red 32 12"
+
+# Invalid color
+
+RGBDEF=./rgbt.txt invCmd "ppmmake rainbow 43 2"
+
+# Multiple colors
+
+invCmd "ppmmake ${blue} ${yellow} 50 1"
+invCmd "ppmmake #FFFFFF ${yellow} 50 2"
+invCmd "ppmmake #ffffff #FFFFFF 50 3"
+invCmd "ppmmake #ffffff rgb:00/00/0F 50 4"
+invCmd "ppmmake rgb:00/00/0F rgb:FF/00/0F 50 5"
+invCmd "ppmmake rgbi:0.0/0.0/0.0 rgbi:1.0/0.0/0.0 50 6"
+invCmd "ppmmake rgb:0/0/0  rgbi:1.0/0.0/0.0 50 7"
+invCmd "ppmmake rgb-255:255/00/00 rgb-65535:0/1024/0 50 8"
+invCmd "ppmmake rgb-ff:00/00/00 rgb-f:0/0/0 50 9"
+
+RGBDEF=./rgbt.txt invCmd "ppmmake red ${blue} 50 10"
+RGBDEF=./rgbt.txt invCmd "ppmmake black white 50 11"
diff --git a/test/rgbt.txt b/test/rgbt.txt
index 96145e00..73978710 100644
--- a/test/rgbt.txt
+++ b/test/rgbt.txt
@@ -6,11 +6,18 @@
   0 255   0 Green
   0   0 255 Blue
   0 255 255 Cyan
-255   0 255 Magenta  
+255   0 255 Magenta
 255 255   0 Yellow
 255 138   0 Orange
 160  32 240 Purple
 103  67   0 Brown
 128 128 128 Gray
-
+#
+# There are two "Brown" colors defined in lib/rgb.txt .  Whenever
+# there are multiple entries by the same color name, the first one
+# in the file is effective and is the one given above.
+#
+# Any string which does not appear in the 4th field above may be
+# used to induce failure.  The following values are recommended:
+# "NoColor" "Rainbow"