File: uuencode.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (193 lines) | stat: -rw-r--r-- 5,550 bytes parent folder | download | duplicates (6)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# uuencode.test - Copyright (C) 2002 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# Tests for the Tcllib uuencode package
#
# -------------------------------------------------------------------------
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -------------------------------------------------------------------------
# RCS: @(#) $Id: uuencode.test,v 1.15 2008/12/12 04:57:46 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 {
    useTcllibC
    useLocalKeep uuencode.tcl uuencode
}

# -------------------------------------------------------------------------

set trf 0
if {[llength [info commands ::uuencode::CEncode]]} {
    puts "> critcl based"
} elseif {[package provide Trf] != {}} {
    puts "> Trf based"
    set trf 1
} else {
    puts "> pure tcl"
}

package require log
log::lvSuppress notice

# -------------------------------------------------------------------------

test uuencode-1.0 {encode string} {
    catch {::uuencode::encode ABC} result
    set result
} "04)#"

test uuencode-1.1 {decode string} {
    catch {::uuencode::decode "04)#"} result
    set result
} "ABC"

test uuencode-1.2 {encode longer string} {
    catch {::uuencode::encode [string repeat x 102]} result
    set result
} [string repeat ">'AX" 34]

test uuencode-1.3 {decode longer string} {
    catch {::uuencode::decode [string repeat ">'AX" 34]} result
    set result
} [string repeat x 102]

# Trf uses a different padding character.
if {!$trf} {
    # critcl / pure tcl based
    set testdata {begin 644 data.dat
75&AE(&-A="!S870@;VX@=&AE(&UA="X`
`
end}
} else {
    set testdata {begin 644 data.dat
75&AE(&-A="!S870@;VX@=&AE(&UA="X~
`
end}
}

test uuencode-1.4 {uuencode string} {
    catch {::uuencode::uuencode "The cat sat on the mat."} result
    set result
} $testdata

test uuencode-1.5 {uudecode string} {
    catch {::uuencode::uudecode $testdata} result
    set result
} [list [list data.dat 644 "The cat sat on the mat."]]

test uuencode-1.6 {encode dash-string} {
    catch {::uuencode::encode -BC} result
    set result
} "+4)#"

test uuencode-1.7 {decode dash-string} {
    catch {::uuencode::decode "-4)#"} result
    set result
} "5BC"

# -------------------------------------------------------------------------

set testdata [list \
        "begin 644 data.dat" \
        "75&AE(&-A=\"!S870@;VX@=&AE(&UA=\"X" \
        "`" \
        "end" ]

test uuencode-2.1 {uudecode unpadded lines} {
    catch {::uuencode::uudecode [join $testdata "\n"]} result
    set result
} [list [list data.dat 644 "The cat sat on the mat."]]

test uuencode-2.2 {uudecode DOS line endings} {
    set f [open uuencode.test.data w]
    fconfigure $f -translation binary
    puts -nonewline $f [join $testdata "\r\n"]
    close $f
    catch {::uuencode::uudecode -file uuencode.test.data} result
    set result
} [list [list data.dat 644 "The cat sat on the mat."]]

foreach {n in out} {
    0 a   {80``}
    1 abc {86)C}
    2 \0  {````}
    3 "\r\n\t" {#0H)}
    4 "hello world" {:&5L;&\@=V]R;&0`}
} {
    test uuencode-3.$n {check the pure tcl encoder} {
        list [catch {::uuencode::Encode $in} r] $r
    } [list 0 $out]
}

# -------------------------------------------------------------------------

test uuencode-4.0 {encode bad args} {
    catch {::uuencode::uuencode -bogus} result
    set result
} {bad option -bogus: must be -file, -mode, or -name}

test uuencode-4.1 {encode wrong#args} {
    catch {::uuencode::uuencode -file} result
    set result
} {wrong # args: should be "uuencode ?-name string? ?-mode octal? (-file filename | ?--? string)"}

test uuencode-4.2 {encode wrong#args} {
    catch {::uuencode::uuencode -name} result
    set result
} {wrong # args: should be "uuencode ?-name string? ?-mode octal? (-file filename | ?--? string)"}

test uuencode-4.3 {encode wrong#args} {
    catch {::uuencode::uuencode -mode} result
    set result
} {wrong # args: should be "uuencode ?-name string? ?-mode octal? (-file filename | ?--? string)"}

test uuencode-4.4 {encode wrong#args} {
    catch {::uuencode::uuencode -mode 1} result
    set result
} {wrong # args: should be "uuencode ?-name string? ?-mode octal? (-file filename | ?--? string)"}

test uuencode-4.5 {encode wrong#args} {
    catch {::uuencode::uuencode -name foo} result
    set result
} {wrong # args: should be "uuencode ?-name string? ?-mode octal? (-file filename | ?--? string)"}

test uuencode-4.6 {encode wrong#args} {
    catch {::uuencode::uuencode --} result
    set result
} {wrong # args: should be "uuencode ?-name string? ?-mode octal? (-file filename | ?--? string)"}



test uuencode-5.0 {decode bad args} {
    catch {::uuencode::uudecode -bogus} result
    set result
} {bad option -bogus: must be -file}

test uuencode-5.1 {decode wrong#args} {
    catch {::uuencode::uudecode -file} result
    set result
} {wrong # args: should be "uudecode (-file filename | ?--? string)"}

test uuencode-5.2 {decode wrong#args} {
    catch {::uuencode::uudecode --} result
    set result
} {wrong # args: should be "uudecode (-file filename | ?--? string)"}


# -------------------------------------------------------------------------

file delete -force uuencode.test.data    
testsuiteCleanup

# Local Variables:
#  mode: tcl
#  indent-tabs-mode: nil
# End: