1 | # Commands covered: |
---|
2 | # Rappture::encoding::is |
---|
3 | # Rappture::encoding::encode |
---|
4 | # Rappture::encoding::decode |
---|
5 | # |
---|
6 | # This file contains a collection of tests for one of the Rappture Tcl |
---|
7 | # commands. Sourcing this file into Tcl runs the tests and |
---|
8 | # generates output for errors. No output means no errors were found. |
---|
9 | # |
---|
10 | # ====================================================================== |
---|
11 | # AUTHOR: Derrick Kearney, Purdue University |
---|
12 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
13 | # |
---|
14 | # See the file "license.terms" for information on usage and redistribution |
---|
15 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
16 | |
---|
17 | |
---|
18 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
19 | package require tcltest |
---|
20 | package require Rappture |
---|
21 | namespace import -force ::tcltest::* |
---|
22 | } |
---|
23 | |
---|
24 | #---------------------------------------------------------- |
---|
25 | #---------------------------------------------------------- |
---|
26 | # is command |
---|
27 | # Rappture::encoding::is binary <string> |
---|
28 | #---------------------------------------------------------- |
---|
29 | test is-1.0.1 {Rappture::encoding::is, 0 arguments} { |
---|
30 | list [catch {Rappture::encoding::is} msg] $msg |
---|
31 | } {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}} |
---|
32 | |
---|
33 | test is-1.1.1 {Rappture::encoding::is, 1 incomplete subcommand} { |
---|
34 | list [catch {Rappture::encoding::is binary} msg] $msg |
---|
35 | } {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}} |
---|
36 | |
---|
37 | test is-1.1.2 {Rappture::encoding::is, 1 subcommand w/ string} { |
---|
38 | list [catch {Rappture::encoding::is binary "hi"} msg] $msg |
---|
39 | } {0 no} |
---|
40 | |
---|
41 | test is-1.1.3 {Rappture::encoding::is, 1 subcommand w/ string} { |
---|
42 | set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
43 | set b [Rappture::encoding::decode -as b64 $h] |
---|
44 | list [catch {Rappture::encoding::is binary $b} msg] $msg |
---|
45 | } {0 yes} |
---|
46 | |
---|
47 | test is-1.2.0 {Rappture::encoding::is, 1 invalid subcommand} { |
---|
48 | list [catch {Rappture::encoding::is binaryy "hi"} msg] $msg |
---|
49 | } {1 {bad option "binaryy": should be binary or encoded}} |
---|
50 | |
---|
51 | test is-1.2.1 {Rappture::encoding::is, too many arguments} { |
---|
52 | list [catch {Rappture::encoding::is binary binary "hi"} msg] $msg |
---|
53 | } {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}} |
---|
54 | |
---|
55 | test is-1.2.2.0 {Rappture::encoding::is, with an embedded null} { |
---|
56 | list [catch {Rappture::encoding::is binary "x\000x"} msg] $msg |
---|
57 | } {0 yes} |
---|
58 | |
---|
59 | test is-1.2.2.1 {Rappture::encoding::is, with an embedded start of heading} { |
---|
60 | list [catch {Rappture::encoding::is binary "x\001x"} msg] $msg |
---|
61 | } {0 yes} |
---|
62 | |
---|
63 | test is-1.2.2.2 {Rappture::encoding::is, with an embedded start of text} { |
---|
64 | list [catch {Rappture::encoding::is binary "x\002x"} msg] $msg |
---|
65 | } {0 yes} |
---|
66 | |
---|
67 | test is-1.2.2.3 {Rappture::encoding::is, with an embedded end of text} { |
---|
68 | list [catch {Rappture::encoding::is binary "x\003x"} msg] $msg |
---|
69 | } {0 yes} |
---|
70 | |
---|
71 | test is-1.2.2.4 {Rappture::encoding::is, with an embedded end of transmission} { |
---|
72 | list [catch {Rappture::encoding::is binary "x\004x"} msg] $msg |
---|
73 | } {0 yes} |
---|
74 | |
---|
75 | test is-1.2.2.5 {Rappture::encoding::is, with an embedded enquiry} { |
---|
76 | list [catch {Rappture::encoding::is binary "x\005x"} msg] $msg |
---|
77 | } {0 yes} |
---|
78 | |
---|
79 | test is-1.2.2.6 {Rappture::encoding::is, with an embedded acknowledge} { |
---|
80 | list [catch {Rappture::encoding::is binary "x\006x"} msg] $msg |
---|
81 | } {0 yes} |
---|
82 | |
---|
83 | test is-1.2.2.7 {Rappture::encoding::is, with an embedded bell} { |
---|
84 | list [catch {Rappture::encoding::is binary "x\007x"} msg] $msg |
---|
85 | } {0 yes} |
---|
86 | |
---|
87 | test is-1.2.2.8 {Rappture::encoding::is, with an embedded backspace} { |
---|
88 | list [catch {Rappture::encoding::is binary "x\010x"} msg] $msg |
---|
89 | } {0 yes} |
---|
90 | |
---|
91 | test is-1.2.2.9 {Rappture::encoding::is, with an embedded horizontal tab} { |
---|
92 | list [catch {Rappture::encoding::is binary "x\011x"} msg] $msg |
---|
93 | } {0 no} |
---|
94 | |
---|
95 | test is-1.2.2.10 {Rappture::encoding::is, with an embedded newlines} { |
---|
96 | list [catch {Rappture::encoding::is binary "x\012x"} msg] $msg |
---|
97 | } {0 no} |
---|
98 | |
---|
99 | test is-1.2.2.11 {Rappture::encoding::is, with an embedded vertical tab} { |
---|
100 | list [catch {Rappture::encoding::is binary "x\013x"} msg] $msg |
---|
101 | } {0 yes} |
---|
102 | |
---|
103 | test is-1.2.2.12 {Rappture::encoding::is, with an embedded form feed} { |
---|
104 | # this is encountered in spice, maybe abinit? |
---|
105 | list [catch {Rappture::encoding::is binary "x\014x"} msg] $msg |
---|
106 | } {0 yes} |
---|
107 | |
---|
108 | test is-1.2.2.13 {Rappture::encoding::is, with an embedded carriage return} { |
---|
109 | list [catch {Rappture::encoding::is binary "x\015x"} msg] $msg |
---|
110 | } {0 no} |
---|
111 | |
---|
112 | test is-1.2.2.14 {Rappture::encoding::is, with an embedded shift out} { |
---|
113 | list [catch {Rappture::encoding::is binary "x\016x"} msg] $msg |
---|
114 | } {0 yes} |
---|
115 | |
---|
116 | test is-1.2.2.15 {Rappture::encoding::is, with an embedded space} { |
---|
117 | list [catch {Rappture::encoding::is binary "x\040x"} msg] $msg |
---|
118 | } {0 no} |
---|
119 | |
---|
120 | #test is-1.2.2.16 {Rappture::encoding::is, with an embedded 8bit ascii char } { |
---|
121 | # list [catch {Rappture::encoding::is binary "x\200x"} msg] $msg |
---|
122 | #} {0 yes} |
---|
123 | |
---|
124 | |
---|
125 | test is-1.3.1 {Rappture::encoding::is, encoded subcommand w/ false string} { |
---|
126 | list [catch {Rappture::encoding::is encoded "hi"} msg] $msg |
---|
127 | } {0 no} |
---|
128 | |
---|
129 | test is-1.3.2 {Rappture::encoding::is, encoded b64 flag and extra string} { |
---|
130 | set h "@@RP-ENC:b64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
131 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
132 | } {0 yes} |
---|
133 | |
---|
134 | test is-1.3.3 {Rappture::encoding::is, encoded zb64 flag and extra string} { |
---|
135 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
136 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
137 | } {0 yes} |
---|
138 | |
---|
139 | test is-1.3.4 {Rappture::encoding::is, encoded z flag and extra string} { |
---|
140 | set h "@@RP-ENC:z\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
141 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
142 | } {0 yes} |
---|
143 | |
---|
144 | test is-1.3.5 {Rappture::encoding::is, encoded z flag newline no string} { |
---|
145 | set h "@@RP-ENC:z\n" |
---|
146 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
147 | } {0 yes} |
---|
148 | |
---|
149 | test is-1.3.6 {Rappture::encoding::is, encoded b64 flag newline no string} { |
---|
150 | set h "@@RP-ENC:b64\n" |
---|
151 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
152 | } {0 yes} |
---|
153 | |
---|
154 | test is-1.3.7 {Rappture::encoding::is, encoded zb64 flag newline no string} { |
---|
155 | set h "@@RP-ENC:zb64\n" |
---|
156 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
157 | } {0 yes} |
---|
158 | |
---|
159 | test is-1.3.7 {Rappture::encoding::is, encoded z flag no newline no string} { |
---|
160 | set h "@@RP-ENC:zb64" |
---|
161 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
162 | } {0 no} |
---|
163 | |
---|
164 | test is-1.3.8 {Rappture::encoding::is, encoded b64 flag no newline no string} { |
---|
165 | set h "@@RP-ENC:b64" |
---|
166 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
167 | } {0 no} |
---|
168 | |
---|
169 | test is-1.3.9 {Rappture::encoding::is, encoded zb64 flag no newline no string} { |
---|
170 | set h "@@RP-ENC:zb64" |
---|
171 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
172 | } {0 no} |
---|
173 | |
---|
174 | test is-1.3.10 {Rappture::encoding::is, encoded with an embedded null} { |
---|
175 | list [catch {Rappture::encoding::is encoded "@@RP-ENC:zb64\nx\000x"} msg] $msg |
---|
176 | } {0 yes} |
---|
177 | |
---|
178 | #---------------------------------------------------------- |
---|
179 | #---------------------------------------------------------- |
---|
180 | # encode command |
---|
181 | # Rappture::encoding::encode ?-as z|b64? ?-no-header? <string> |
---|
182 | #---------------------------------------------------------- |
---|
183 | |
---|
184 | test encode-2.0.0 {Rappture::encoding::encode, 0 arguments} { |
---|
185 | list [catch {Rappture::encoding::encode} msg] $msg |
---|
186 | } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? ?-noheader? ?--? string"}} |
---|
187 | |
---|
188 | test encode-2.1.0 {Rappture::encoding::encode, ascii string argument} { |
---|
189 | list [catch {Rappture::encoding::encode "hi"} msg] $msg |
---|
190 | } {0 {@@RP-ENC:zb64 |
---|
191 | H4sIAAAAAAAAA8vIBACsKpPYAgAAAA== |
---|
192 | }} |
---|
193 | |
---|
194 | test encode-2.1.1 {Rappture::encoding::encode, binary string argument} { |
---|
195 | set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
196 | set b [Rappture::encoding::decode -as b64 $h] |
---|
197 | list [catch {Rappture::encoding::encode $b} msg] $msg |
---|
198 | } {0 {@@RP-ENC:zb64 |
---|
199 | H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA= |
---|
200 | }} |
---|
201 | |
---|
202 | test encode-2.2.0 {Rappture::encoding::encode, -as flag no value} { |
---|
203 | list [catch {Rappture::encoding::encode -as} msg] $msg |
---|
204 | } {1 {value for "-as" missing}} |
---|
205 | |
---|
206 | test encode-2.2.1 {Rappture::encoding::encode, -as flag bad value } { |
---|
207 | list [catch {Rappture::encoding::encode -as zz} msg] $msg |
---|
208 | } {1 {bad value "zz": should be b64, zb64, or z}} |
---|
209 | |
---|
210 | test encode-2.2.2 {Rappture::encoding::encode, -as flag correct value z} { |
---|
211 | list [catch {Rappture::encoding::encode -as z} msg] $msg |
---|
212 | } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? ?-noheader? ?--? string"}} |
---|
213 | |
---|
214 | test encode-2.2.3 {Rappture::encoding::encode, -as z w/ string} { |
---|
215 | list [catch {Rappture::encoding::encode -as z "hi"} msg] $msg |
---|
216 | } [list 0 "@@RP-ENC:z\n\037\213\010\000\000\000\000\000\000\003\313\310\004\000\254\052\223\330\002\000\000\000"] |
---|
217 | |
---|
218 | test encode-2.2.4 {Rappture::encoding::encode, -as b64 w/ string} { |
---|
219 | list [catch {Rappture::encoding::encode -as b64 "hi"} msg] $msg |
---|
220 | } {0 {@@RP-ENC:b64 |
---|
221 | aGk= |
---|
222 | }} |
---|
223 | |
---|
224 | test encode-2.2.5 {Rappture::encoding::encode with --} { |
---|
225 | list [catch {Rappture::encoding::encode -hi} msg] $msg |
---|
226 | } {1 {unknown switch "-hi" |
---|
227 | following switches are available: |
---|
228 | -as z|b64|zb64 |
---|
229 | -noheader }} |
---|
230 | |
---|
231 | test encode-2.2.6 {Rappture::encoding::encode with --} { |
---|
232 | list [catch {Rappture::encoding::encode -- -hi} msg] $msg |
---|
233 | } {0 {@@RP-ENC:zb64 |
---|
234 | H4sIAAAAAAAAA9PNyAQA8jSeVgMAAAA= |
---|
235 | }} |
---|
236 | |
---|
237 | #---------------------------------------------------------- |
---|
238 | #---------------------------------------------------------- |
---|
239 | # decode command |
---|
240 | # Rappture::encooding::decode <string> |
---|
241 | #---------------------------------------------------------- |
---|
242 | |
---|
243 | test decode-3.0.0 {Rappture::encoding::decode, 0 arguments} { |
---|
244 | list [catch {Rappture::encoding::decode} msg] $msg |
---|
245 | } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? string"}} |
---|
246 | |
---|
247 | test decode-3.1.0 {Rappture::encoding::decode, 1 arg, b64 encoded} { |
---|
248 | set h "aGk=" |
---|
249 | list [catch {Rappture::encoding::decode $h} msg] $msg |
---|
250 | } {0 aGk=} |
---|
251 | |
---|
252 | test decode-3.1.1 {Rappture::encoding::decode, 1 arg, zb64 encoded} { |
---|
253 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
254 | list [catch {Rappture::encoding::decode $h} msg] $msg |
---|
255 | } {0 hi} |
---|
256 | |
---|
257 | test decode-3.1.2 {Rappture::encoding::decode, 2 args} { |
---|
258 | list [catch {Rappture::encoding::decode "hi" "bye"} msg] $msg |
---|
259 | } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? string"}} |
---|
260 | |
---|
261 | test decode-3.2.0 {Rappture::encoding::decode, -as flag, no value} { |
---|
262 | list [catch {Rappture::encoding::decode -as} msg] $msg |
---|
263 | } {1 {value for "-as" missing}} |
---|
264 | |
---|
265 | test decode-3.2.1 {Rappture::encoding::decode, -as flag, bad value} { |
---|
266 | list [catch {Rappture::encoding::decode -as zz} msg] $msg |
---|
267 | } {1 {bad value "zz": should be b64, zb64, or z}} |
---|
268 | |
---|
269 | # This test is wrong. The -as z flag should either 1) be ignored and return |
---|
270 | # "hi" (using the header) or 2) override the header and return an error when |
---|
271 | # attempting to decompress the bogus string (see 3.2.2b) |
---|
272 | |
---|
273 | test decode-3.2.2 {Rappture::encoding::decode, -as flag, zb64 w/ string} { |
---|
274 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
275 | list [catch {Rappture::encoding::decode -as z $h} msg] $msg |
---|
276 | } {1 {: |
---|
277 | decode flags don't match the header |
---|
278 | }} |
---|
279 | |
---|
280 | test decode-3.2.2b {Rappture::encoding::decode, -as -noheader, zb64 w/ string} { |
---|
281 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
282 | list [catch {Rappture::encoding::decode -as z -noheader $h} msg] $msg |
---|
283 | } {1 {Rappture::Buffer::do_decompress() |
---|
284 | : |
---|
285 | memory error while inflating data |
---|
286 | Rappture::Buffer::do_decompress() |
---|
287 | }} |
---|
288 | |
---|
289 | test decode-3.2.3 {Rappture::encoding::decode, -as flag, b64 w/ string} { |
---|
290 | set h "@@RP-ENC:b64\naGk=" |
---|
291 | list [catch {Rappture::encoding::decode -as b64 $h} msg] $msg |
---|
292 | } {0 hi} |
---|
293 | |
---|
294 | test decode-3.2.4 {encode/decode reverse each other} { |
---|
295 | set msg "This is a test" |
---|
296 | Rappture::encoding::decode [Rappture::encoding::encode $msg] |
---|
297 | } {This is a test} |
---|
298 | |
---|
299 | test encode-3.2.5 {Rappture::encoding::decode with --} { |
---|
300 | list [catch {Rappture::encoding::decode -hi} msg] $msg |
---|
301 | } {1 {unknown switch "-hi" |
---|
302 | following switches are available: |
---|
303 | -as z|b64|zb64 |
---|
304 | -noheader }} |
---|
305 | |
---|
306 | |
---|
307 | test encode-3.2.6 {Rappture::encoding::decode with --} { |
---|
308 | list [catch {Rappture::encoding::decode -- -hi} msg] $msg |
---|
309 | } {0 -hi} |
---|
310 | |
---|
311 | test encode-4.0 {is binary (isxml) test with invalid XML characters} { |
---|
312 | list [catch {Rappture::encoding::is binary "formfeed \f"} msg] $msg |
---|
313 | } {0 yes} |
---|
314 | test encode-4.1 {is binary (isxml) test with invalid XML characters} { |
---|
315 | list [catch {Rappture::encoding::is binary "backspace \b"} msg] $msg |
---|
316 | } {0 yes} |
---|
317 | test encode-4.2 {is binary (isxml) test with invalid XML characters} { |
---|
318 | list [catch {Rappture::encoding::is binary "vertical tab \v"} msg] $msg |
---|
319 | } {0 yes} |
---|
320 | test encode-4.3 {is binary (isxml) test with invalid XML characters} { |
---|
321 | list [catch {Rappture::encoding::is binary "high-order bit \x80"} msg] $msg |
---|
322 | } {0 yes} |
---|
323 | test encode-4.4 {is binary (isxml) test with invalid XML characters} { |
---|
324 | list [catch {Rappture::encoding::is binary "high-order bit \xFF"} msg] $msg |
---|
325 | } {0 yes} |
---|
326 | test encode-4.5 {is binary (isxml) test with invalid XML characters} { |
---|
327 | list [catch {Rappture::encoding::is binary "NUL \0"} msg] $msg |
---|
328 | } {0 yes} |
---|
329 | test encode-4.6 {is binary (isxml) test with invalid XML characters} { |
---|
330 | list [catch {Rappture::encoding::is binary "BEL \a"} msg] $msg |
---|
331 | } {0 yes} |
---|
332 | test encode-4.7 {is binary (isxml) test with valid XML characters} { |
---|
333 | list [catch {Rappture::encoding::is binary "tab/cr/nl \t\r\n "} msg] $msg |
---|
334 | } {0 no} |
---|
335 | test encode-4.8 {is binary (isxml) test with valid XML characters} { |
---|
336 | list [catch { |
---|
337 | set string "\t\r\n" |
---|
338 | for { set i 0x20 } { $i <= 0x7F } { incr i } { |
---|
339 | append string [format %c $i] |
---|
340 | } |
---|
341 | Rappture::encoding::is binary $string |
---|
342 | } msg] $msg |
---|
343 | } {0 no} |
---|
344 | |
---|
345 | test encode-4.8 {is binary (isxml) test with all characters} { |
---|
346 | list [catch { |
---|
347 | set result {} |
---|
348 | for { set i 0 } { $i <= 0xFF } { incr i } { |
---|
349 | set string [format %c $i] |
---|
350 | if { ![Rappture::encoding::is binary $string] } { |
---|
351 | lappend result $i |
---|
352 | } |
---|
353 | } |
---|
354 | set result |
---|
355 | } msg] $msg |
---|
356 | } {0 {9 10 13 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}} |
---|
357 | |
---|
358 | |
---|
359 | ::tcltest::cleanupTests |
---|
360 | return |
---|
361 | |
---|