File: raw.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 (173 lines) | stat: -rwxr-xr-x 5,991 bytes parent folder | download
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 RAW 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 ::raw::test {
    namespace import ::tcltest::*

    set fmt     "raw"
    set fmtDef  "-useheader true -nchan 3"
    set ext     "raw"
    set inFile  "testimgs/img.$ext"
    set outFile "testimgs/img_out.$ext"

    set imgdata [readFile $inFile]

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

    # Execute the follwing tests only, if the format handler could be loaded.
    if { $pkgLoaded == 0 } {
        test raw-1.1 {Read photo from file using option \"-file\"} -setup {
            catch {image delete i}
        } -body {
            image create photo i -file $inFile
            i data -format [list $fmt {*}$fmtDef]
        } -cleanup {
            image delete i
        } -result $imgdata

        test raw-1.2 {Read photo from string using option \"-data\"} -setup {
            catch {image delete i}
        } -body {
            image create photo i -data $imgdata
            i data -format [list $fmt {*}$fmtDef]
        } -cleanup {
            image delete i
        } -result $imgdata

        test raw-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 [list $fmt {*}$fmtDef]
        } -cleanup {
            image delete i
        } -result $imgdata

        test raw-1.4 {Read photo from string using command \"put -format\"} -setup {
            catch {image delete i}
        } -body {
            image create photo i
            i put $imgdata -format [list $fmt {*}$fmtDef]
            i data -format [list $fmt {*}$fmtDef]
        } -cleanup {
            image delete i
        } -result $imgdata

        test raw-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 raw-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 raw-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 {*}$fmtDef]
            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 raw-1.X tests.

        test raw-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, -useheader, -width, -height, -nchan, -byteorder, -scanorder, -pixeltype, -skipbytes, -map, -min, -max, -gamma, -saturation, -cutoff, -printagc, -uuencode, or -nomap"

        test raw-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 raw-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 raw-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, -useheader, -nchan, or scanorder"

        test raw-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 raw-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 ::raw::test