# cksum.test - Copyright (C) 2002 Pat Thoyts # # 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.2 2002/01/23 20:56:30 patthoyts Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import ::tcltest::* } package require cksum # ------------------------------------------------------------------------- test cksum-1.0 {cksum with no parameters } { catch {::crc::cksum} result set result } {wrong # args: should be "cksum ?-format string? -file name | data"} # ------------------------------------------------------------------------- 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: