summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/crc/cksum.test
blob: a0cf03a369b1fac8fc3160c6345c6eb5b7e56071 (plain)
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
# 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.7 2006/10/09 21:41:40 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 {
    useLocal cksum.tcl cksum ::crc
}

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

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}
testsuiteCleanup

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