1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
# This file is a Tcl script to test ICO reading and writing.
# It is organized in the standard fashion for Tcl tests.
package require Tk
package require tcltest
tcltest::configure {*}$argv
source [file join [file dirname [info script]] constraints.tcl]
imageInit
namespace eval ::ico::test {
namespace import ::tcltest::*
set fmt "ico"
set ext "ico"
set inFile "testimgs/img.$ext"
set outFile "testimgs/img_out.$ext"
set imgdata [readFile $inFile]
test ico-0.1 {package require img::ico} -setup {
} -body {
set pkgLoaded [catch {package require img::ico}]
} -result 0
# Execute the follwing tests only, if the format handler could be loaded.
if { $pkgLoaded == 0 } {
test ico-1.1 {Read photo from file using option \"-file\"} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
i data -format $fmt
} -cleanup {
image delete i
} -result $imgdata
test ico-1.2 {Read photo from string using option \"-data\"} -setup {
catch {image delete i}
} -body {
image create photo i -data $imgdata
i data -format $fmt
} -cleanup {
image delete i
} -result $imgdata
test ico-1.3 {Read photo from string using command \"put\"} -setup {
catch {image delete i}
} -body {
image create photo i
i put $imgdata
i data -format $fmt
} -cleanup {
image delete i
} -result $imgdata
test ico-1.4 {Read photo from string using command \"put -format\"} -setup {
catch {image delete i}
} -body {
image create photo i
i put $imgdata -format $fmt
i data -format $fmt
} -cleanup {
image delete i
} -result $imgdata
test ico-1.5 {Compare 2 photos read from file and from string} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
image create photo j -data $imgdata
imageCompare i j
} -cleanup {
image delete i
image delete j
} -result 1
test ico-2.1 {Read photo from file without resolution information} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
imageResolution i
} -cleanup {
image delete i
} -constraints {
Tk87
} -result {0 0}
test ico-3.1 {Write photo to file and compare with reference photo} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
i write $outFile -format [list $fmt]
image create photo j -file $outFile
imageCompare i j
} -cleanup {
image delete i
image delete j
file delete -force $outFile
} -constraints {
Tk87
} -result 1
# Write photo to string using "i data -format" already tested in ico-1.X tests.
test ico-5.1 {Read photo from file using invalid option \"-invalidoption\"} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile -format [list $fmt -invalidoption 1]
} -returnCodes {
error
} -result "bad format option \"-invalidoption\": must be -verbose or -index"
test ico-5.2 {Read photo from file using option without value} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile -format [list $fmt -verbose]
} -returnCodes {
error
} -result "No value specified for option \"-verbose\"."
test ico-5.3 {Read photo from file using invalid -verbose value} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile -format [list $fmt -verbose "asdf"]
} -returnCodes {
error
} -result "Invalid verbose mode \"asdf\": must be 1 or 0, on or off, true or false."
test ico-5.4 {Write photo to file using invalid option \"-invalidoption\"} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
i write $outFile -format [list $fmt -invalidoption 1]
} -cleanup {
image delete i
file delete -force $outFile
} -returnCodes {
error
} -result "bad format option \"-invalidoption\": must be -verbose"
test ico-5.5 {Write photo to file using option without value} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
i write $outFile -format [list $fmt -verbose]
} -cleanup {
image delete i
file delete -force $outFile
} -returnCodes {
error
} -result "No value specified for option \"-verbose\"."
test ico-5.6 {Write photo to file using invalid -verbose value} -setup {
catch {image delete i}
} -body {
image create photo i -file $inFile
i write $outFile -format [list $fmt -verbose "asdf"]
} -cleanup {
image delete i
file delete -force $outFile
} -returnCodes {
error
} -result "Invalid verbose mode \"asdf\": must be 1 or 0, on or off, true or false."
}
}
imageFinish
tcltest::cleanupTests
namespace delete ::ico::test
|