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
|
# 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.10 2005/08/26 17:13:36 andreas_kupries Exp $
# -------------------------------------------------------------------------
# Initialize the test package
#
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
# -------------------------------------------------------------------------
# Ensure we test _this_ local copy and one installed somewhere else.
#
package forget uuencode
catch {namespace delete ::uuencode}
if {[catch {source [file join [file dirname [info script]] uuencode.tcl]} msg]} {
puts "skipped [file tail [info script]]: $msg"
return
}
# -------------------------------------------------------------------------
# Setup any constraints
#
# -------------------------------------------------------------------------
# Now the package specific tests....
# -------------------------------------------------------------------------
set trf 0
if {[info command ::uuencode::CEncode] != {}} {
puts "- uuencode [package provide uuencode] (critcl based)"
} elseif {[package provide Trf] != {}} {
puts "- uuencode [package provide uuencode] (Trf based)"
set trf 1
} else {
puts "- uuencode [package provide uuencode] (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]
}
# -------------------------------------------------------------------------
file delete -force uuencode.test.data
::tcltest::cleanupTests
# Local Variables:
# mode: tcl
# indent-tabs-mode: nil
# End:
|