source: trunk/lang/tcl/tests/encode.test @ 1264

Last change on this file since 1264 was 1264, checked in by dkearney, 16 years ago

fixing rp library's get() function for retrieving encoded data. if the data is encoded there is no need to do xml entity translation. adding a function rappture's encode class for checking to see if a string has a proper header encode header. adding corresponding tcl functions and tests. also adjusting some of the int declarations to size_t.

File size: 8.8 KB
Line 
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
18if {[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#----------------------------------------------------------
29test 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
33test 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
37test 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
41test 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
47test 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 one of binary, encoded}}
50
51test 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
55test 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
59test 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
63test 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
68test 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
73test 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
78test 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
83test 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
88test 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
93test 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
98test 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
103test 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
108test 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
118test 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? ?-no-header? ?--? <string>"}}
121
122test encode-2.1.0 {Rappture::encoding::encode, ascii string argument} {
123    list [catch {Rappture::encoding::encode "hi"} msg] $msg
124} {0 {@@RP-ENC:zb64
125H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==
126}}
127
128test 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
133H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA=
134}}
135
136test encode-2.2.0 {Rappture::encoding::encode, -as flag blank value} {
137    list [catch {Rappture::encoding::encode -as} msg] $msg
138} {1 {bad value "": should be one of z, b64, zb64}}
139
140test 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 one of z, b64, zb64}}
143
144test 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? ?-no-header? ?--? <string>"}}
147
148test 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
152test 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
155aGk=
156}}
157
158test encode-2.2.5 {Rappture::encoding::encode with --} {
159    list [catch {Rappture::encoding::encode -hi} msg] $msg
160} {1 {bad option "-hi": should be -as, -no-header, --}}
161
162test encode-2.2.6 {Rappture::encoding::encode with --} {
163    list [catch {Rappture::encoding::encode -- -hi} msg] $msg
164} {0 {@@RP-ENC:zb64
165H4sIAAAAAAAAA9PNyAQA8jSeVgMAAAA=
166}}
167
168#----------------------------------------------------------
169#----------------------------------------------------------
170# decode command
171# Rappture::encooding::decode <string>
172#----------------------------------------------------------
173
174test decode-3.0.0 {Rappture::encoding::decode, 0 arguments} {
175    list [catch {Rappture::encoding::decode} msg] $msg
176} {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? <string>"}}
177
178test decode-3.1.0 {Rappture::encoding::decode, 1 arg, b64 encoded} {
179    set h "aGk="
180    list [catch {Rappture::encoding::decode $h} msg] $msg
181} {0 aGk=}
182
183test decode-3.1.1 {Rappture::encoding::decode, 1 arg, zb64 encoded} {
184    set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
185    list [catch {Rappture::encoding::decode $h} msg] $msg
186} {0 hi}
187
188test decode-3.1.2 {Rappture::encoding::decode, 2 args} {
189    list [catch {Rappture::encoding::decode "hi" "bye"} msg] $msg
190} {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? <string>"}}
191
192test decode-3.2.0 {Rappture::encoding::decode, -as flag, no value} {
193    list [catch {Rappture::encoding::decode -as} msg] $msg
194} {1 {bad value "": should be one of z, b64, zb64}}
195
196test decode-3.2.1 {Rappture::encoding::decode, -as flag, bad value} {
197    list [catch {Rappture::encoding::decode -as zz} msg] $msg
198} {1 {bad value "zz": should be one of z, b64, zb64}}
199
200test decode-3.2.2 {Rappture::encoding::decode, -as flag, zb64 w/ string} {
201    set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
202    list [catch {Rappture::encoding::decode -as z $h} msg] $msg
203} {0 {@@RP-ENC:zb64
204H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==}}
205
206test decode-3.2.3 {Rappture::encoding::decode, -as flag, b64 w/ string} {
207    set h "@@RP-ENC:b64\naGk="
208    list [catch {Rappture::encoding::decode -as b64 $h} msg] $msg
209} {0 hi}
210
211test decode-3.2.4 {encode/decode reverse each other} {
212    set msg "This is a test"
213    Rappture::encoding::decode [Rappture::encoding::encode $msg]
214} {This is a test}
215
216test encode-3.2.5 {Rappture::encoding::decode with --} {
217    list [catch {Rappture::encoding::decode -hi} msg] $msg
218} {1 {bad option "-hi": should be -as, --}}
219
220test encode-3.2.6 {Rappture::encoding::decode with --} {
221    list [catch {Rappture::encoding::decode -- -hi} msg] $msg
222} {0 -hi}
223
224
225::tcltest::cleanupTests
226return
227
Note: See TracBrowser for help on using the repository browser.