File: yencode.test

package info (click to toggle)
tcllib 1.8-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 13,628 kB
  • ctags: 4,897
  • sloc: tcl: 88,012; sh: 7,856; ansic: 4,174; xml: 1,765; yacc: 753; perl: 84; f90: 84; makefile: 60; python: 33; ruby: 13; php: 11
file content (108 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download
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
# yencode.test - Copyright (C) 2002 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# Tests for the Tcllib yencode package
#
# -------------------------------------------------------------------------
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -------------------------------------------------------------------------
# RCS: @(#) $Id: yencode.test,v 1.7 2004/02/16 04:14:45 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 yencode
catch {namespace delete ::yencode}
if {[catch {source [file join [file dirname [info script]] yencode.tcl]} msg]} {
    puts "skipped [file tail [info script]]: $msg"
    return
}

# -------------------------------------------------------------------------
# Setup any constraints
#

# -------------------------------------------------------------------------
# Now the package specific tests....
# -------------------------------------------------------------------------

if {[info command ::yencode::CEncode] != {}} {
    puts "- yencode [package provide yencode] (critcl based)"
} else {
    puts "- yencode [package provide yencode] (pure tcl)"
}

proc ::yencode::loaddata {filename {translation auto}} {
    set f [open $filename r]
    fconfigure $f -translation $translation
    set data [read $f]
    close $f
    return $data
}

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

set datafile [file join $::tcltest::testsDirectory yencode.test.data]

test yencode-1.0 {yencode yEnc test file} {
    set enc [::yencode::yencode -file $datafile]
    set dec [::yencode::ydecode $enc]
    set chk [::yencode::loaddata $datafile]
    string equal $dec $chk
} {0}
    

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

foreach {n in out} {
    0 A        {k}
    1 ABC      {klm}
    2 \0\1\2   {*+,}
    3 "\r\n\t" {743}
    4 "\xd6\xe0\xe3" {=*=4=7}
} {
    test yencode-2.$n.a {check the pure tcl encode} {
        list [catch {::yencode::Encode $in} r] $r
    } [list 0 $out]
    test yencode-2.$n.b {check the pure tcl decode} {
        list [catch {::yencode::Decode $out} r] $r
    } [list 0 $in]
}

if {[info command ::yencode::CEncode] != {}} {
    foreach {n in out} {
        0 A        {k}
        1 ABC      {klm}
        2 \0\1\2   {*+,}
        3 "\r\n\t" {743}
        4 "\xd6\xe0\xe3" {=*=4=7}
    } {
        test yencode-3.$n.a {check the critcl encode} {
            list [catch {::yencode::Encode $in} r] $r
        } [list 0 $out]
        test yencode-3.$n.b {check the critcl decode} {
            list [catch {::yencode::Decode $out} r] $r
        } [list 0 $in]
    }
}

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

catch {
    unset datafile
    rename ::yencode::loaddata {}
}
::tcltest::cleanupTests

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