# 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 381286 2003-05-01 22:40:19Z jigen $

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}

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
}

package require log
log::lvSuppress notice

if {[package provide Trf] == {}} {
    puts "- uuencode [package provide uuencode] (pure Tcl)"
} else {
    puts "- uuencode [package provide uuencode] (Trf based)"
}

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

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 {[catch {package present Trf}]} {
    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."]]

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

file delete -force uuencode.test.data    
::tcltest::cleanupTests

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