File: pcx.test

package info (click to toggle)
libtk-img 1%3A2.0.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 47,852 kB
  • sloc: ansic: 224,696; sh: 20,589; tcl: 8,921; makefile: 2,272; cpp: 1,933; ada: 1,681; pascal: 1,139; cs: 879; awk: 794; asm: 587; python: 542; xml: 95
file content (243 lines) | stat: -rwxr-xr-x 8,169 bytes parent folder | download | duplicates (2)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# This file is a Tcl script to test PCX 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 ::pcx::test {
    namespace import ::tcltest::*

    set fmt     "pcx"
    set ext     "pcx"
    set inFile  "testimgs/img.$ext"
    set outFile "testimgs/img_out.$ext"
    set dpiFile "testimgs/dpi.$ext"

    set imgdata [readFile $inFile] 

    test pcx-0.1 {package require img::pcx} -setup {
    } -body {
        set pkgLoaded [catch {package require img::pcx}]
    } -result 0

    # Execute the follwing tests only, if the format handler could be loaded.
    if { $pkgLoaded == 0 } {
        test pcx-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 pcx-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 pcx-1.3 {Read photo from string using command \"put\"} -setup {
        } -body {
            image create photo i
            i put $imgdata
            i data -format $fmt
        } -cleanup {
            image delete i
        } -result $imgdata

        test pcx-1.4 {Read photo from string using command \"put -format\"} -setup {
        } -body {
            image create photo i
            i put $imgdata -format $fmt
            i data -format $fmt
        } -cleanup {
            image delete i
        } -result $imgdata

        test pcx-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 pcx-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 pcx-2.2 {Read photo from file with resolution information} -setup {
            catch {image delete i}
        } -body {
            image create photo i -file $dpiFile
            imageResolution i
        } -cleanup {
            image delete i
        } -constraints {
            Tk87
        } -result [refResolution]


        test pcx-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 pcx-1.X tests.


        test pcx-4.1 {Write photo to file with resolution information} -setup {
            catch {image delete i}
        } -body {
            image create photo i -file $inFile
            i write $outFile -format [list $fmt -resolution {*}[refResolution]]
            image delete i
            image create photo i -file $dpiFile
            image create photo j -file $outFile
            set res [list [imageResolution i] [imageResolution j]]
        } -cleanup {
            image delete i
            image delete j
            file delete -force $outFile
        } -constraints {
            Tk87
        } -result [list [refResolution] [refResolution]]


        test pcx-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"

        test pcx-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 pcx-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\"*" -match glob

        test pcx-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, -compression, -resolution, -xresolution, or -yresolution"

        test pcx-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 pcx-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."

        test pcx-5.7 {Write photo to file using invalid -resolution value} -setup {
            catch {image delete i}
        } -body {
            image create photo i -file $inFile
            i write $outFile -format [list $fmt -resolution -100]
        } -cleanup {
            image delete i
            file delete -force $outFile
        } -constraints {
            Tk87
        } -returnCodes {
            error
        } -result "Invalid resolution value \"-100\" specified for x resolution."

        test pcx-5.8 {Write photo to file using invalid -xresolution value} -setup {
            catch {image delete i}
        } -body {
            image create photo i -file $inFile
            i write $outFile -format [list $fmt -xresolution 12cm]
        } -cleanup {
            image delete i
            file delete -force $outFile
        } -constraints {
            Tk87
        } -returnCodes {
            error
        } -result "Invalid resolution value \"12cm\" specified for x resolution."

        test pcx-5.9 {Write photo to file using invalid -yresolution value} -setup {
            catch {image delete i}
        } -body {
            image create photo i -file $inFile
            i write $outFile -format [list $fmt -yresolution 12cm]
        } -cleanup {
            image delete i
            file delete -force $outFile
        } -constraints {
            Tk87
        } -returnCodes {
            error
        } -result "Invalid resolution value \"12cm\" specified for y resolution."
    }
}

imageFinish
tcltest::cleanupTests
namespace delete ::pcx::test