blob: 926a16d4d8b711057c4bb370fdb55e777788ab03 (
plain)
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
|
# Tests for the base64 module. -*- tcl -*-
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# All rights reserved.
#
# RCS: @(#) $Id: base64.test,v 1.17 2011/11/09 04:31:24 andreas_kupries Exp $
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.2
testsNeedTcltest 1.0
testing {
useLocal base64.tcl base64
}
# -------------------------------------------------------------------------
if {[catch {package present Trf}]} {
puts "> pure Tcl"
tcltest::testConstraint trf 0
} else {
puts "> Trf based"
tcltest::testConstraint trf 1
}
# -------------------------------------------------------------------------
test base64-1.1 {base64::encode} {
base64::encode "this is a test\n"
} "dGhpcyBpcyBhIHRlc3QK"
test base64-1.2 {base64::encode wraps lines at 76 characters} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
base64::encode $str
} "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3JlZW4gZmllbGQgYW5k
IGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"
test base64-1.3 {base64::encode with wrap length set to 60} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
base64::encode -maxlen 60 $str
} "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3Jl
ZW4gZmllbGQgYW5kIGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"
test base64-1.4 {base64::encode with wrap length set to 0} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
base64::encode -maxlen 0 $str
} "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3JlZW4gZmllbGQgYW5kIGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"
test base64-1.5 {base64::encode with wrap length set to 76, wrapchar to newline+space} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
base64::encode -maxlen 76 -wrapchar "\n " $str
} "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3JlZW4gZmllbGQgYW5k
IGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"
test base64-1.6 {base64::encode, errors} {
list [catch {base64::encode} msg] $msg
} [list 1 "wrong # args: should be \"base64::encode ?-maxlen maxlen? ?-wrapchar wrapchar? string\""]
test base64-1.7 {base64::encode, errors} {
list [catch {base64::encode -maxlen foo} msg] $msg
} [list 1 "value for \"-maxlen\" missing"]
test base64-1.8 {base64::encode, errors} {
list [catch {base64::encode -maxlen foo bar} msg] $msg
} [list 1 "expected integer but got \"foo\""]
test base64-1.9 {base64::encode, errors} {
list [catch {base64::encode -maxlen foo -wrapchar bar} msg] $msg
} [list 1 "value for \"-wrapchar\" missing"]
test base64-1.10 {base64::encode, errors} {
list [catch {base64::encode -foo bar} msg] $msg
} [list 1 "unknown option \"-foo\": must be -maxlen or -wrapchar"]
test base64-1.11 {base64::encode with bogus wrap length (< 0)} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
list [catch { base64::encode -maxlen -3 $str } msg] $msg
} {1 {expected positive integer but got "-3"}}
test base64-1.12 {base64::encode with bogus wrap length (non-numeric)} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
list [catch { base64::encode -maxlen foo $str } msg] $msg
} {1 {expected integer but got "foo"}}
test base64-1.13 {base64::encode with bogus wrap length (non-integer)} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
list [catch { base64::encode -maxlen 1.5 $str } msg] $msg
} {1 {expected integer but got "1.5"}}
test base64-1.14 {base64::encode with wrap length set to 20} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
base64::encode -maxlen 20 $str
} "VGhlIHNob3J0IHJlZCBm
b3ggcmFuIHF1aWNrbHkg
dGhyb3VnaCB0aGUgZ3Jl
ZW4gZmllbGQgYW5kIGp1
bXBlZCBvdmVyIHRoZSB0
YWxsIGJyb3duIGJlYXIK"
test base64-1.15 {base64::encode with wrap length set to 23 (prime)} {
set str "The short red fox ran quickly through the green field "
append str "and jumped over the tall brown bear\n"
base64::encode -maxlen 23 $str
} "VGhlIHNob3J0IHJlZCBmb3g
gcmFuIHF1aWNrbHkgdGhyb3
VnaCB0aGUgZ3JlZW4gZmllb
GQgYW5kIGp1bXBlZCBvdmVy
IHRoZSB0YWxsIGJyb3duIGJ
lYXIK"
test base64-2.1 {base64::decode} {
base64::decode "dGhpcyBpcyBhIHRlc3QK"
} "this is a test\n"
test base64-2.2 {base64::decode ignores newlines} {
set str "VGhlIHNob3J0IHJlZCBmb3ggcmFuIHF1aWNrbHkgdGhyb3VnaCB0aGUgZ3Jl\n"
append str "ZW4gZmllbGQgYW5kIGp1bXBlZCBvdmVyIHRoZSB0YWxsIGJyb3duIGJlYXIK"
base64::decode $str
} "The short red fox ran quickly through the green field and jumped over the tall brown bear\n"
test base64-2.3 {base64::decode handles equal sign padding} {
# decode the encoding of a string that will be padded in the encoding with
# one padding char
base64::decode [base64::encode "01234"]
} "01234"
test base64-2.4 {base64::decode handles equal sign padding} {
# decode the encoding of a string that will be padded in the encoding with
# two padding chars
base64::decode [base64::encode "0123"]
} "0123"
test base64-2.5 {base64::decode} {
base64::decode ""
} ""
test base64-2.6 {base64::decode} {
base64::decode " "
} ""
test base64-3.1 {base64 identity test} {
base64::decode [base64::encode "this is a test"]
} "this is a test"
test base64-3.2 {base64 identity test} {
# This test fails on version 1.5 because of the format %04x bug
# when handling the last characters
set x \f\xee
set y [base64::decode [base64::encode $x]]
string compare $x $y
} 0
# For trf a known bug.
test base64-4.0 {base64 -- sf bug 2976290} {!trf} {
list [catch {
::base64::decode s=GQMRAk5WXhsABh0NEx4RXBocBVgBHQMXHRgEFltMQENQXEFOExJVQ0RAQERUQ0dAEhYEExVIRRVVFENWKxMKABsPGBI6LRoYLhsEFhsXGFkXEwZXGQMIHg==
} msg] $msg
} {1 {Not enough data to process padding}}
testsuiteCleanup
return
|