File: cksum.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 (126 lines) | stat: -rw-r--r-- 3,642 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# cksum.test - Copyright (C) 2002 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# Tests for the Tcllib cksum command
#
# -------------------------------------------------------------------------
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -------------------------------------------------------------------------
# RCS: @(#) $Id: cksum.test,v 1.4 2005/03/12 21:11:01 patthoyts Exp $

# -------------------------------------------------------------------------
# Initialise 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 cksum
catch {namespace delete ::crc}
if {[catch {source [file join [file dirname [info script]] cksum.tcl]} msg]} {
    puts "skipped [file tail [info script]]: $msg"
    return
}

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

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

puts "- cksum [package provide cksum]"

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

test cksum-1.0 {cksum with no parameters } {
    catch {::crc::cksum} result
    set result
} {wrong # args: should be cksum ?-format string? -channel chan | -filename file | string}

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

foreach {n msg expected} {
    1    ""
    "4294967295"
    2    "a"
    "1220704766"
    3    "abc"
    "1219131554"
    4    "message digest"
    "3644109718"
    5    "abcdefghijklmnopqrstuvwxyz"
    "2713270184"
    6    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    "81918263"
    7    "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
    "1939911592"
    8    "\uFFFE\u0000\u0001\u0002"
    "893385333"
} {
    test cksum-2.$n {cksum and unsigned integer} {
	::crc::cksum $msg
    } $expected
}

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

foreach {n msg expected} {
    1    ""
    "0xFFFFFFFF"
    2    "a"
    "0x48C279FE"
    3    "abc"
    "0x48AA78A2"
    4    "message digest"
    "0xD934B396"
    5    "abcdefghijklmnopqrstuvwxyz"
    "0xA1B937A8"
    6    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    "0x4E1F937"
    7    "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
    "0x73A0B3A8"
    8    "\uFFFE\u0000\u0001\u0002"
    "0x353FFA75"
} {
    test cksum-3.$n {cksum as hexadecimal string} {
	::crc::cksum -format 0x%X $msg
    } $expected
}

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

set crc::testfile [info script]

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

test cksum-4.0 {cksum file option} {
    set r1 [crc::cksum -file $crc::testfile]
    set r2 [crc::cksum [crc::loaddata $crc::testfile]]
    if {$r1 != $r2} {
        set r "differing results: $r1 != $r2"
    } else {
        set r ok
    }
} {ok}
        
# -------------------------------------------------------------------------

catch {unset crc::testfile}
::tcltest::cleanupTests

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