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-2007 Purdue Research Foundation |
---|
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 {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.3.1 {Rappture::encoding::is, encoded subcommand w/ false string} { |
---|
60 | list [catch {Rappture::encoding::is encoded "hi"} msg] $msg |
---|
61 | } {0 no} |
---|
62 | |
---|
63 | test is-1.3.2 {Rappture::encoding::is, encoded b64 flag and extra string} { |
---|
64 | set h "@@RP-ENC:b64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
65 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
66 | } {0 yes} |
---|
67 | |
---|
68 | test is-1.3.3 {Rappture::encoding::is, encoded zb64 flag and extra string} { |
---|
69 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
70 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
71 | } {0 yes} |
---|
72 | |
---|
73 | test is-1.3.4 {Rappture::encoding::is, encoded z flag and extra string} { |
---|
74 | set h "@@RP-ENC:z\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
75 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
76 | } {0 yes} |
---|
77 | |
---|
78 | test is-1.3.5 {Rappture::encoding::is, encoded z flag newline no string} { |
---|
79 | set h "@@RP-ENC:z\n" |
---|
80 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
81 | } {0 yes} |
---|
82 | |
---|
83 | test is-1.3.6 {Rappture::encoding::is, encoded b64 flag newline no string} { |
---|
84 | set h "@@RP-ENC:b64\n" |
---|
85 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
86 | } {0 yes} |
---|
87 | |
---|
88 | test is-1.3.7 {Rappture::encoding::is, encoded zb64 flag newline no string} { |
---|
89 | set h "@@RP-ENC:zb64\n" |
---|
90 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
91 | } {0 yes} |
---|
92 | |
---|
93 | test is-1.3.7 {Rappture::encoding::is, encoded z flag no newline no string} { |
---|
94 | set h "@@RP-ENC:zb64" |
---|
95 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
96 | } {0 no} |
---|
97 | |
---|
98 | test is-1.3.8 {Rappture::encoding::is, encoded b64 flag no newline no string} { |
---|
99 | set h "@@RP-ENC:b64" |
---|
100 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
101 | } {0 no} |
---|
102 | |
---|
103 | test is-1.3.9 {Rappture::encoding::is, encoded zb64 flag no newline no string} { |
---|
104 | set h "@@RP-ENC:zb64" |
---|
105 | list [catch {Rappture::encoding::is encoded $h} msg] $msg |
---|
106 | } {0 no} |
---|
107 | |
---|
108 | test is-1.3.10 {Rappture::encoding::is, encoded with an embedded null} { |
---|
109 | list [catch {Rappture::encoding::is encoded "@@RP-ENC:zb64\nx\000x"} msg] $msg |
---|
110 | } {0 yes} |
---|
111 | |
---|
112 | #---------------------------------------------------------- |
---|
113 | #---------------------------------------------------------- |
---|
114 | # encode command |
---|
115 | # Rappture::encoding::encode ?-as z|b64? ?-no-header? <string> |
---|
116 | #---------------------------------------------------------- |
---|
117 | |
---|
118 | test encode-2.0.0 {Rappture::encoding::encode, 0 arguments} { |
---|
119 | list [catch {Rappture::encoding::encode} msg] $msg |
---|
120 | } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? ?-noheader? ?--? string"}} |
---|
121 | |
---|
122 | test encode-2.1.0 {Rappture::encoding::encode, ascii string argument} { |
---|
123 | list [catch {Rappture::encoding::encode "hi"} msg] $msg |
---|
124 | } {0 {@@RP-ENC:zb64 |
---|
125 | H4sIAAAAAAAAA8vIBACsKpPYAgAAAA== |
---|
126 | }} |
---|
127 | |
---|
128 | test encode-2.1.1 {Rappture::encoding::encode, binary string argument} { |
---|
129 | set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
130 | set b [Rappture::encoding::decode -as b64 $h] |
---|
131 | list [catch {Rappture::encoding::encode $b} msg] $msg |
---|
132 | } {0 {@@RP-ENC:zb64 |
---|
133 | H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA= |
---|
134 | }} |
---|
135 | |
---|
136 | test encode-2.2.0 {Rappture::encoding::encode, -as flag no value} { |
---|
137 | list [catch {Rappture::encoding::encode -as} msg] $msg |
---|
138 | } {1 {value for "-as" missing}} |
---|
139 | |
---|
140 | test encode-2.2.1 {Rappture::encoding::encode, -as flag bad value } { |
---|
141 | list [catch {Rappture::encoding::encode -as zz} msg] $msg |
---|
142 | } {1 {bad value "zz": should be b64, zb64, or z}} |
---|
143 | |
---|
144 | test encode-2.2.2 {Rappture::encoding::encode, -as flag correct value z} { |
---|
145 | list [catch {Rappture::encoding::encode -as z} msg] $msg |
---|
146 | } {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? ?-noheader? ?--? string"}} |
---|
147 | |
---|
148 | test encode-2.2.3 {Rappture::encoding::encode, -as z w/ string} { |
---|
149 | list [catch {Rappture::encoding::encode -as z "hi"} msg] $msg |
---|
150 | } [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"] |
---|
151 | |
---|
152 | test encode-2.2.4 {Rappture::encoding::encode, -as b64 w/ string} { |
---|
153 | list [catch {Rappture::encoding::encode -as b64 "hi"} msg] $msg |
---|
154 | } {0 {@@RP-ENC:b64 |
---|
155 | aGk= |
---|
156 | }} |
---|
157 | |
---|
158 | test encode-2.2.5 {Rappture::encoding::encode with --} { |
---|
159 | list [catch {Rappture::encoding::encode -hi} msg] $msg |
---|
160 | } {1 {unknown switch "-hi" |
---|
161 | following switches are available: |
---|
162 | -as z|b64|zb64 |
---|
163 | -noheader }} |
---|
164 | |
---|
165 | test encode-2.2.6 {Rappture::encoding::encode with --} { |
---|
166 | list [catch {Rappture::encoding::encode -- -hi} msg] $msg |
---|
167 | } {0 {@@RP-ENC:zb64 |
---|
168 | H4sIAAAAAAAAA9PNyAQA8jSeVgMAAAA= |
---|
169 | }} |
---|
170 | |
---|
171 | #---------------------------------------------------------- |
---|
172 | #---------------------------------------------------------- |
---|
173 | # decode command |
---|
174 | # Rappture::encooding::decode <string> |
---|
175 | #---------------------------------------------------------- |
---|
176 | |
---|
177 | test decode-3.0.0 {Rappture::encoding::decode, 0 arguments} { |
---|
178 | list [catch {Rappture::encoding::decode} msg] $msg |
---|
179 | } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? string"}} |
---|
180 | |
---|
181 | test decode-3.1.0 {Rappture::encoding::decode, 1 arg, b64 encoded} { |
---|
182 | set h "aGk=" |
---|
183 | list [catch {Rappture::encoding::decode $h} msg] $msg |
---|
184 | } {0 aGk=} |
---|
185 | |
---|
186 | test decode-3.1.1 {Rappture::encoding::decode, 1 arg, zb64 encoded} { |
---|
187 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
188 | list [catch {Rappture::encoding::decode $h} msg] $msg |
---|
189 | } {0 hi} |
---|
190 | |
---|
191 | test decode-3.1.2 {Rappture::encoding::decode, 2 args} { |
---|
192 | list [catch {Rappture::encoding::decode "hi" "bye"} msg] $msg |
---|
193 | } {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? string"}} |
---|
194 | |
---|
195 | test decode-3.2.0 {Rappture::encoding::decode, -as flag, no value} { |
---|
196 | list [catch {Rappture::encoding::decode -as} msg] $msg |
---|
197 | } {1 {value for "-as" missing}} |
---|
198 | |
---|
199 | test decode-3.2.1 {Rappture::encoding::decode, -as flag, bad value} { |
---|
200 | list [catch {Rappture::encoding::decode -as zz} msg] $msg |
---|
201 | } {1 {bad value "zz": should be b64, zb64, or z}} |
---|
202 | |
---|
203 | # This test is wrong. The -as z flag should either 1) be ignored and return |
---|
204 | # "hi" (using the header) or 2) override the header and return an error when |
---|
205 | # attempting to decompress the bogus string (see 3.2.2b) |
---|
206 | |
---|
207 | test decode-3.2.2 {Rappture::encoding::decode, -as flag, zb64 w/ string} { |
---|
208 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
209 | list [catch {Rappture::encoding::decode -as z $h} msg] $msg |
---|
210 | } {0 {@@RP-ENC:zb64 |
---|
211 | H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==}} |
---|
212 | |
---|
213 | test decode-3.2.2b {Rappture::encoding::decode, -as -noheader, zb64 w/ string} { |
---|
214 | set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA==" |
---|
215 | list [catch {Rappture::encoding::decode -as z -noheader $h} msg] $msg |
---|
216 | } {1 {Rappture::Buffer::do_decompress() |
---|
217 | : |
---|
218 | memory error while inflating data |
---|
219 | Rappture::Buffer::do_decompress() |
---|
220 | }} |
---|
221 | |
---|
222 | test decode-3.2.3 {Rappture::encoding::decode, -as flag, b64 w/ string} { |
---|
223 | set h "@@RP-ENC:b64\naGk=" |
---|
224 | list [catch {Rappture::encoding::decode -as b64 $h} msg] $msg |
---|
225 | } {0 hi} |
---|
226 | |
---|
227 | test decode-3.2.4 {encode/decode reverse each other} { |
---|
228 | set msg "This is a test" |
---|
229 | Rappture::encoding::decode [Rappture::encoding::encode $msg] |
---|
230 | } {This is a test} |
---|
231 | |
---|
232 | test encode-3.2.5 {Rappture::encoding::decode with --} { |
---|
233 | list [catch {Rappture::encoding::decode -hi} msg] $msg |
---|
234 | } {1 {unknown switch "-hi" |
---|
235 | following switches are available: |
---|
236 | -as z|b64|zb64 |
---|
237 | -noheader }} |
---|
238 | |
---|
239 | |
---|
240 | test encode-3.2.6 {Rappture::encoding::decode with --} { |
---|
241 | list [catch {Rappture::encoding::decode -- -hi} msg] $msg |
---|
242 | } {0 -hi} |
---|
243 | |
---|
244 | |
---|
245 | ::tcltest::cleanupTests |
---|
246 | return |
---|
247 | |
---|