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
RevLine 
[642]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
[1264]31} {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}}
[642]32
33test is-1.1.1 {Rappture::encoding::is, 1 incomplete subcommand} {
34    list [catch {Rappture::encoding::is binary} msg] $msg
[1264]35} {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}}
[642]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} {
[649]42    set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
43    set b [Rappture::encoding::decode -as b64 $h]
[642]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
[1264]49} {1 {bad option "binaryy": should be one of binary, encoded}}
[642]50
51test is-1.2.1 {Rappture::encoding::is, too many arguments} {
52    list [catch {Rappture::encoding::is binary binary "hi"} msg] $msg
[1264]53} {1 {wrong # args: should be "Rappture::encoding::is binary|encoded <string>"}}
[642]54
[725]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
[1264]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
[642]112#----------------------------------------------------------
113#----------------------------------------------------------
114# encode command
[655]115# Rappture::encoding::encode ?-as z|b64? ?-no-header? <string>
[642]116#----------------------------------------------------------
117
118test encode-2.0.0 {Rappture::encoding::encode, 0 arguments} {
119    list [catch {Rappture::encoding::encode} msg] $msg
[1042]120} {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? ?-no-header? ?--? <string>"}}
[642]121
122test encode-2.1.0 {Rappture::encoding::encode, ascii string argument} {
123    list [catch {Rappture::encoding::encode "hi"} msg] $msg
[652]124} {0 {@@RP-ENC:zb64
125H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==
[642]126}}
127
128test encode-2.1.1 {Rappture::encoding::encode, binary string argument}  {
[649]129    set h "H4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
130    set b [Rappture::encoding::decode -as b64 $h]
[642]131    list [catch {Rappture::encoding::encode $b} msg] $msg
[652]132} {0 {@@RP-ENC:zb64
133H4sIAAAAAAAAA5Pv5mAAA+bTJ1gY1mhNvsEE5AAAFVLsvBYAAAA=
[642]134}}
135
136test encode-2.2.0 {Rappture::encoding::encode, -as flag blank value} {
137    list [catch {Rappture::encoding::encode -as} msg] $msg
[652]138} {1 {bad value "": should be one of z, b64, zb64}}
[642]139
140test encode-2.2.1 {Rappture::encoding::encode, -as flag bad value } {
141    list [catch {Rappture::encoding::encode -as zz} msg] $msg
[652]142} {1 {bad value "zz": should be one of z, b64, zb64}}
[642]143
144test encode-2.2.2 {Rappture::encoding::encode, -as flag correct value z} {
145    list [catch {Rappture::encoding::encode -as z} msg] $msg
[1042]146} {1 {wrong # args: should be "Rappture::encoding::encode ?-as z|b64|zb64? ?-no-header? ?--? <string>"}}
[642]147
148test encode-2.2.3 {Rappture::encoding::encode, -as z w/ string} {
149    list [catch {Rappture::encoding::encode -as z "hi"} msg] $msg
[684]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"]
[642]151
152test encode-2.2.4 {Rappture::encoding::encode, -as b64 w/ string} {
153    list [catch {Rappture::encoding::encode -as b64 "hi"} msg] $msg
[652]154} {0 {@@RP-ENC:b64
155aGk=
[642]156}}
157
[1042]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
[642]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
[1042]176} {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? <string>"}}
[642]177
[649]178test decode-3.1.0 {Rappture::encoding::decode, 1 arg, b64 encoded} {
179    set h "aGk="
[642]180    list [catch {Rappture::encoding::decode $h} msg] $msg
[649]181} {0 aGk=}
[642]182
[652]183test decode-3.1.1 {Rappture::encoding::decode, 1 arg, zb64 encoded} {
184    set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
[642]185    list [catch {Rappture::encoding::decode $h} msg] $msg
186} {0 hi}
187
[649]188test decode-3.1.2 {Rappture::encoding::decode, 2 args} {
[642]189    list [catch {Rappture::encoding::decode "hi" "bye"} msg] $msg
[1042]190} {1 {wrong # args: should be "Rappture::encoding::decode ?-as z|b64|zb64? ?--? <string>"}}
[642]191
[649]192test decode-3.2.0 {Rappture::encoding::decode, -as flag, no value} {
193    list [catch {Rappture::encoding::decode -as} msg] $msg
[652]194} {1 {bad value "": should be one of z, b64, zb64}}
[642]195
[649]196test decode-3.2.1 {Rappture::encoding::decode, -as flag, bad value} {
197    list [catch {Rappture::encoding::decode -as zz} msg] $msg
[1042]198} {1 {bad value "zz": should be one of z, b64, zb64}}
[649]199
[652]200test decode-3.2.2 {Rappture::encoding::decode, -as flag, zb64 w/ string} {
201    set h "@@RP-ENC:zb64\nH4sIAAAAAAAAA8vIBACsKpPYAgAAAA=="
[649]202    list [catch {Rappture::encoding::decode -as z $h} msg] $msg
[684]203} {0 {@@RP-ENC:zb64
204H4sIAAAAAAAAA8vIBACsKpPYAgAAAA==}}
[649]205
206test decode-3.2.3 {Rappture::encoding::decode, -as flag, b64 w/ string} {
[652]207    set h "@@RP-ENC:b64\naGk="
[649]208    list [catch {Rappture::encoding::decode -as b64 $h} msg] $msg
209} {0 hi}
210
[684]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}
[649]215
[1042]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, --}}
[684]219
[1042]220test encode-3.2.6 {Rappture::encoding::decode with --} {
221    list [catch {Rappture::encoding::decode -- -hi} msg] $msg
222} {0 -hi}
223
224
[642]225::tcltest::cleanupTests
226return
227
Note: See TracBrowser for help on using the repository browser.