# This file is a Tcl script to test out the default image data format # ("list format") implementend in the file tkImgListFormat.c. # It is organized in the standard fashion for Tcl tests. # # Copyright (c) ??? # All rights reserved. # # Author: Simon Bachmann (simonbachmann@bluewin.ch) package require tcltest 2.2 namespace import ::tcltest::* tcltest::configure {*}$argv tcltest::loadTestedCommands imageInit # find the teapot.ppm file for use in these tests set teapotPhotoFile [file join [file dirname [info script]] teapot.ppm] testConstraint hasTeapotPhoto [file exists $teapotPhotoFile] # let's see if we have the semi-transparent one as well set transpTeapotPhotoFile [file join [file dirname [info script]] teapotTransparent.png] testConstraint hasTranspTeapotPhoto [file exists $transpTeapotPhotoFile] # --------------------------------------------------------------------- test imgListFormat-1.1 {ParseFormatOptions: default values} -setup { image create photo photo1 } -body { photo1 put {{red green} {blue black}} lindex [photo1 data] 1 1 } -cleanup { imageCleanup } -result {#000000} test imgListFormat-1.2 {ParseFormatOptions: format name as first arg} -setup { image create photo photo1 } -body { photo1 put #1256ef -format {default} -to 0 0 10 10 } -cleanup { imageCleanup } -result {} test imgListFormat-1.3 {ParseFormatOptions: unknown option} -setup { image create photo photo1 } -body { photo1 data -format {default -bogus} } -cleanup { imageCleanup } -returnCodes error -result {bad format option "-bogus": must be -colorformat} test imgListFormat-1.4 {ParseFormatOptions: option not allowed} -setup { image create photo photo1 } -body { photo1 put yellow -format {default -colorformat rgb} } -cleanup { imageCleanup } -returnCodes error -result \ {bad format option "-colorformat": no options allowed} test imgListFormat-1.5 {ParseFormatOptions: bad -colorformat val #1} -setup { image create photo photo1 } -body { photo1 put yellow photo1 data -format {default -colorformat bogus} } -cleanup { imageCleanup } -returnCodes error -result \ {bad color format "bogus": must be rgb, argb, or list} test imgListFormat-1.6 {ParseFormatOptions: bad -colorformat val #2} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat tkcolor} } -returnCodes error -result \ {bad color format "tkcolor": must be rgb, argb, or list} test imgListFormat-1.7 {ParseFormatOptions: bad -colorformat #3} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat emptystring} } -returnCodes error -result \ {bad color format "emptystring": must be rgb, argb, or list} test imgListFormat-1.8 {ParseFormatOptions: bad -colorformat #4} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat rgb-short} } -cleanup { imageCleanup } -returnCodes error -result \ {bad color format "rgb-short": must be rgb, argb, or list} test imgListFormat-1.9 {ParseFormatOptions: bad -colorformat #5} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat argb-short} } -returnCodes error -result \ {bad color format "argb-short": must be rgb, argb, or list} test imgListFormat-1.10 {valid colorformats} -setup { image create photo photo1 } -body { photo1 put white#78 set result {} lappend result [photo1 data -format {default -colorformat rgb}] lappend result [photo1 data -format {default -colorformat argb}] lappend result [photo1 data -format {default -colorformat list}] set result } -cleanup { imageCleanup unset result } -result {{{#ffffff}} {{#78ffffff}} {{{255 255 255 120}}}} # GetBadOptMsg: only use case already tested with imgListFormat-1.4 test imgListFormat-3.1 {StringMatchDef: data is not a list} -body { testphotostringmatch {not a " proper list} # " (this comment is here only for editor highlighting) } -returnCodes error -result {unmatched open quote in list} # empty data case tested with imgPhoto-4.95 (imgPhoto.test) test imgListFormat-3.2 {StringMatchDef: \ list element not a proper list} -body { testphotostringmatch {{red white} {not "} {blue green}} # " } -returnCodes error -result {unmatched open quote in list} test imgListFormat-3.3 {StringMatchDef: \ sublists with differen lengths} -body { testphotostringmatch {{#001122 #334455 #667788} {#99AABB #CCDDEE} {#FF0011 #223344 #556677}} } -returnCodes error -result \ {invalid row # 1: all rows must have the same number of elements} test imgListFormat-3.4 {StringMatchDef: base64 data is not parsed as valid \ } -setup { image create photo photo1 } -body { photo1 put { iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCA YAAAEFsT2yAAAABGdBTUEAAYagMeiWXwAA ABdJREFUCJkFwQEBAAAAgiD6P9pACRoqDk fUBvt1wUFKAAAAAElFTkSuQmCC } -format default } -cleanup { imageCleanup } -returnCodes error -result {couldn't recognize image data} test imgListFormat-3.5 {StringMatchDef: valid data} -setup { image create photo photo1 } -body { photo1 put {{blue green} {yellow magenta} {#000000 #FFFFFFFF}} list [image width photo1] [image height photo1] \ [photo1 get 0 2 -withalpha] } -cleanup { imageCleanup } -result {2 3 {0 0 0 255}} # ImgStringRead: most of the error cases cannot be tested with current code, # as the errors are detected by StringMatchDef test imgListFormat-4.1 {StringReadDef: use with -format opt} -setup { image create photo photo1 } -body { photo1 put white -format "default" photo1 get 0 0 } -cleanup { imageCleanup } -result {255 255 255} test imgListFormat-4.2 {StringReadDef: suboptions to format} -setup { image create photo photo1 } -body { photo1 put white -format {default -bogus} } -cleanup { imageCleanup } -returnCodes error -result \ {bad format option "-bogus": no options allowed} test imgListFormat-4.3 {StringReadDef: erroneous non-option argument} -setup { image create photo photo1 } -body { photo1 put orange -format {default bogus} } -returnCodes error -result {bad format option "bogus": no options allowed} test imgListFormat-4.4 {StringReadDef: normal use case} -constraints { hasTeapotPhoto } -setup { image create photo photo1 -file $teapotPhotoFile image create photo photo2 } -body { set imgData [photo1 data] photo2 put $imgData string equal [photo1 data] [photo2 data] } -cleanup { imageCleanup unset imgData } -result {1} test imgListFormat-4.5 {StringReadDef: correct compositing rule} -constraints { hasTranspTeapotPhoto } -setup { image create photo photo1 -file $transpTeapotPhotoFile image create photo photo2 } -body { photo2 put #FF0000 -to 0 0 50 50 photo2 put [photo1 data -format {default -colorformat argb}] -to 10 10 40 40 list [photo2 get 0 0 -withalpha] [photo2 get 20 25 -withalpha] \ [photo2 get 49 49 -withalpha] } -cleanup { imageCleanup } -result {{255 0 0 255} {0 78 185 225} {255 0 0 255}} test imgListFormat-5.1 {StringWriteDef: format options not a list} -setup { image create photo photo1 } -body { photo1 data -format {default " bogus} # " } -cleanup { imageCleanup } -returnCodes error -result {unmatched open quote in list} test imgListFormat-5.2 {StringWriteDef: invalid format option} -setup { image create photo photo1 } -body { photo1 data -format {default -bogus} } -cleanup { imageCleanup } -returnCodes error -result {bad format option "-bogus": must be -colorformat} test imgListFormat-5.3 {StringWriteDef: non-option arg in format} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat list bogus} } -cleanup { imageCleanup } -returnCodes error -result {bad format option "bogus": must be -colorformat} test imgListFormat-5.4 {StringWriteDef: empty image} -setup { image create photo photo1 } -body { photo1 data -format {default -colorformat argb} } -cleanup { imageCleanup } -result {} test imgListFormat-5.5 {StirngWriteDef: size of data} -setup { image create photo photo1 } -body { photo1 put blue -to 0 0 35 64 set imgData [photo1 data] list [llength [lindex $imgData 0]] [llength $imgData] } -cleanup { unset imgData imageCleanup } -result {35 64} test imgListFormat-5.6 {StringWriteDef: test some pixels #1} -constraints { hasTeapotPhoto } -setup { set result {} image create photo photo1 -file $teapotPhotoFile } -body { set imgData [photo1 data] # note: with [lindex], the coords are inverted (y x) lappend result [lindex $imgData 0 0] lappend result [lindex $imgData 3 2] lappend result [lindex $imgData 107 53] lappend result [lindex $imgData 203 157] lappend result [lindex $imgData 255 255] set result } -cleanup { unset result unset imgData imageCleanup } -result {{#135cc0} #135cc0 #a06d52 #e1c8ba #135cc0} test imgListFormat-5.7 {StringWriteDef: test some pixels #2} -constraints { hasTeapotPhoto } -setup { set result {} image create photo photo1 -file $teapotPhotoFile } -body { set imgData [photo1 data -format {default -colorformat argb}] # note: with [lindex], the coords are inverted (y x) lappend result [lindex $imgData 0 0] lappend result [lindex $imgData 3 2] lappend result [lindex $imgData 107 53] lappend result [lindex $imgData 203 157] lappend result [lindex $imgData 255 255] set result } -cleanup { unset result unset imgData imageCleanup } -result {{#ff135cc0} #ff135cc0 #ffa06d52 #ffe1c8ba #ff135cc0} test imgListFormat-5.8 {StringWriteDef: test some pixels #3} -constraints { hasTranspTeapotPhoto } -setup { image create photo photo1 -file $transpTeapotPhotoFile } -body { set imgData [photo1 data -format {default -colorformat rgb}] set result {} lappend result [lindex $imgData 3 2] lappend result [lindex $imgData 107 53] lappend result [lindex $imgData 203 157] set result } -cleanup { unset result unset imgData imageCleanup } -result {{#004eb9} #a14100 #ffca9f} test imgListFormat-5.9 {StringWriteDef: test some pixels #4} -constraints { hasTranspTeapotPhoto } -setup { image create photo photo1 -file $transpTeapotPhotoFile } -body { set imgData [photo1 data -format {default -colorformat argb}] set result [lindex $imgData 3 2] lappend result [lindex $imgData 107 53] lappend result [lindex $imgData 203 157] set result } -cleanup { unset result unset imgData imageCleanup } -result {{#e1004eb9} #aaa14100 #afffca9f} test imgListFormat-5.10 {StringWriteDef: test some pixels #5} -constraints { hasTranspTeapotPhoto } -setup { image create photo photo1 -file $transpTeapotPhotoFile } -body { set imgData [photo1 data -format {default -colorformat list}] set result {} lappend result [lindex $imgData 3 2] lappend result [lindex $imgData 107 53] lappend result [lindex $imgData 203 157] set result } -cleanup { unset imgData unset result imageCleanup } -result {{0 78 185 225} {161 65 0 170} {255 202 159 175}} test imgListFormat-6.1 {ParseColor: list format} -setup { image create photo photo1 } -body { photo1 put [list [list [list 255 255 255]]] photo1 get 0 0 -withalpha } -cleanup { imageCleanup } -result {255 255 255 255} test imgListFormat-6.2 {ParseColor: string format in list rep} -setup { image create photo photo1 } -body { photo1 put [list [list [list white]]] photo1 get 0 0 -withalpha } -cleanup { imageCleanup } -result {255 255 255 255} test imgListFormat-6.3 {ParseColor: empty string} -setup { image create photo photo1 set result {} } -body { photo1 put {{"" ""} {"" ""}} lappend result [image width photo1] lappend result [image height photo1] lappend result [photo1 get 1 1 -withalpha] set result } -cleanup { unset result imageCleanup } -result {2 2 {0 0 0 0}} test imgListFormat-6.4 {ImgPhotoParsecolor: empty string, mixed} -setup { image create photo photo1 } -body { photo1 put {{black white} {{} white}} list [photo1 get 0 0 -withalpha] [photo1 get 0 1 -withalpha] } -cleanup { imageCleanup } -result {{0 0 0 255} {0 0 0 0}} test imgListFormat-6.5 {ParseColor: invalid hex digit} -setup { image create photo photo1 } -body { photo1 put {#ABCD #ABCZ} } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "#ABCZ"} test imgListFormat-6.6 {ParseColor: valid #ARGB color} -setup { image create photo photo1 } -body { photo1 put {{#0d9bd502 #F7ac}} list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha] } -cleanup { imageCleanup } -result {{155 213 2 13} {119 170 204 255}} test imgListFormat-6.7 {ParseColor: Tk color, valid suffixes} -setup { image create photo photo1 set result {} } -body { photo1 put {{blue@0.711 #114433#C} {#8D4#1A magenta}} lappend result [photo1 get 0 0 -withalpha] lappend result [photo1 get 1 0 -withalpha] lappend result [photo1 get 0 1 -withalpha] lappend result [photo1 get 1 1 -withalpha] set result } -cleanup { unset result imageCleanup } -result {{0 0 255 181} {17 68 51 204} {136 221 68 26} {255 0 255 255}} test imgListFormat-6.8 {ParseColor: Tk color with and w/o suffixes} -setup { image create photo photo1 set result {} } -body { photo1 put {{#52D8a0 #2B5} {#E47@0.01 maroon#4}} lappend result [photo1 get 0 0 -withalpha] lappend result [photo1 get 1 0 -withalpha] lappend result [photo1 get 0 1 -withalpha] lappend result [photo1 get 1 1 -withalpha] set result } -cleanup { unset result imageCleanup } -result {{82 216 160 255} {34 187 85 255} {238 68 119 3} {128 0 0 68}} test imgListFormat-6.9 {ParseColor: @A suffix, not a float} -setup { image create photo photo1 } -body { photo1 put {{blue@0.5 blue@bogus}} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid alpha suffix "@bogus": expected floating-point value} test imgListFormat-6.10 {ParseColor: @A, value too low} -setup { image create photo photo1 } -body { photo1 put {green@.1 green@-0.1} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid alpha suffix "@-0.1": value must be in the range from 0 to 1} test imgListFormat-6.11 {ParseColor: @A, value too high} -setup { image create photo photo1 } -body { photo1 put {#000000@0 #000000@1.0001} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid alpha suffix "@1.0001": value must be in the range from 0 to 1} test imgListFormat-6.12 {ParseColor: @A suffix, edge values} -setup { imageCleanup image create photo photo1 } -body { photo1 put {{yellow@1e-22 yellow@0.12352941 yellow@0.12352942 \ yellow@0.9999999}} list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha] \ [photo1 get 2 0 -withalpha] [photo1 get 3 0 -withalpha] } -cleanup { imageCleanup } -result {{255 255 0 0} {255 255 0 31} {255 255 0 32} {255 255 0 255}} test imgListFormat-6.13 {ParseColor: # suffix, no hex digits} -setup { image create photo photo1 } -body { photo1 put {{black#f} {black#}} } -cleanup { imageCleanup } -returnCodes error -result {invalid alpha suffix "#"} test imgListFormat-6.14 {ParseColor: # suffix, too many digits} -setup { image create photo photo1 } -body { photo1 put {{#ABC#12 #ABC#123}} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid alpha suffix "#123"} test imgListFormat-6.15 {ParseColor: invalid digit in #X suffix} -setup { image create photo photo1 } -body { photo1 put {#000#a #000#g} } -cleanup { imageCleanup } -returnCodes error -result {invalid alpha suffix "#g": expected hex digit} test imgListFormat-6.16 {ParseColor: invalid digit in #XX suffix} -setup { image create photo photo1 } -body { photo1 put {green#2 green#2W} } -cleanup { imageCleanup } -returnCodes error -result {invalid alpha suffix "#2W": expected hex digit} test imgListFormat-6.17 {ParseColor: list format, string rep} -setup { image create photo photo1 } -body { photo1 put {{"111 222 33 44"}} photo1 get 0 0 -withalpha } -cleanup { imageCleanup } -result {111 222 33 44} test imgListFormat-6.18 {ParseColor: invalid color: wrong digit #} -setup { image create photo photo1 } -body { photo1 put {{#000 #00}} } -returnCodes error -result {invalid color name "#00"} test imgListFormat-6.19 {ParseColor: invalid color: not a hex digit} -setup { image create photo photo1 } -body { photo1 put {#ABCDEF@.99 #ABCDEG@.99} } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "#ABCDEG@.99"} test imgListFormat-6.20 {ParseColor: suffix not allowed #1} -setup { image create photo photo1 } -body { photo1 put {#ABC@.5 #ABCD@0.5} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid color name "#ABCD@0.5"} test imgListFormat-6.21 {ParseColor: suffix not allowed #2} -setup { image create photo photo1 } -body { photo1 put {{{100 100 100} {100 100 100#FE}}} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid color name "100 100 100#FE"} test imgListFormat-6.22 {ParseColor: suffix not allowed #3} -setup { image create photo photo1 } -body { photo1 put {#1111 #1111#1} } -cleanup { imageCleanup } -returnCodes error -result \ {invalid color name "#1111#1"} test imgListFormat-6.23 {ParseColor: overall test} -setup { image create photo photo1 set result {} } -body { photo1 put { {snow@0.5 snow#80 snow#8 #fffffafafafa@0.5 #fffffabbfacc#8} {#fffffafffaff#80 #ffffaafaa@.5 #ffffaafaa#8 #ffffaafaa#80 #fee#8} {#fee#80 #fee@0.5 #fffafa@0.5 #fffafa#8 #fffafa#80} {{0xff 250 0xfa 128} {255 250 250} #8fee #80fffafa snow}} for {set y 0} {$y < 4} {incr y} { for {set x 0} {$x < 5} {incr x} { lappend result [photo1 get $x $y -withalpha] } } set result } -cleanup { imageCleanup unset result } -result \ {{255 250 250 128} {255 250 250 128} {255 250 250 136} {255 250 250 128}\ {255 250 250 136} {255 250 250 128} {255 250 250 128} {255 250 250 136}\ {255 250 250 128} {255 238 238 136} {255 238 238 128} {255 238 238 128}\ {255 250 250 128} {255 250 250 136} {255 250 250 128} {255 250 250 128}\ {255 250 250 255} {255 238 238 136} {255 250 250 128} {255 250 250 255}} # Note: the error messages from ParseColorAsList are currently discarded. All # we'll ever get is a "invalid color mame xx" message. test imgListFormat-7.1 {ParseColorAsListAsList: invalid list} -setup { image create photo photo1 } -body { photo1 put {{{123 45 67 89} {123 45 " 67}}} #" } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "123 45 " 67"} #" test imgListFormat-7.2 {ParseColorAsList: too few elements in list} -setup { image create photo photo1 } -body { photo1 put {{{0 255 0 255} {0 255}}} } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "0 255"} test imgListFormat-7.3 {ParseColorAsList: too many elements in list} -setup { image create photo photo1 } -body { photo1 put {{{0 100 200 255} {0 100 200 255 0}}} } -returnCodes error -result {invalid color name "0 100 200 255 0"} test imgListFormat-7.4 {ParseColorAsList: not an integer value} -setup { image create photo photo1 } -body { photo1 put {{{9 0xf3 87 65} {43 21 10 1.0}}} } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "43 21 10 1.0"} test imgListFormat-7.5 {ParseColorAsList: negative value in list} -setup { image create photo photo1 } -body { photo1 put {{{121 121 121} {121 121 -1}}} } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "121 121 -1"} test imgListFormat-7.6 {ParseColorAsList: value in list too large} -setup { image create photo photo1 } -body { photo1 put {{{0 1 2 3} {254 255 256}}} } -cleanup { imageCleanup } -returnCodes error -result {invalid color name "254 255 256"} test imgListFormat-7.7 {ParseColorAsList: valid list form} -setup { image create photo photo1 } -body { photo1 put {{{0x0 0x10 0xfe 0xff} {0 100 254}} {{30 30 30 0} {1 1 254 1}}} list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha] \ [photo1 get 0 1 -withalpha] [photo1 get 1 1 -withalpha] } -cleanup { imageCleanup } -result {{0 16 254 255} {0 100 254 255} {30 30 30 0} {1 1 254 1}} # --------------------------------------------------------------------- imageFinish # cleanup cleanupTests return