# crc32bugs.test - Copyright (C) 2002 Pat Thoyts <patthoyts@users.sf.net>
#
# Bug finding for crc32 module.
# In particular we are looking for byte order problems, and issues between
# the trf code and tcl-only code.
#
# -------------------------------------------------------------------------
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -------------------------------------------------------------------------
# RCS: @(#) $Id: crc32bugs.test 380133 2003-04-02 21:24:12Z jigen $

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

package require crc32
package require crc16

if {[catch {package present Trf}]} {
    puts "crc32bugs (pure Tcl) $::tcl_platform(byteOrder)"
} else {
    puts "crc32bugs (Trf based) $::tcl_platform(byteOrder)"
}

foreach {n msg expected} {
    1  ""                 "0"
    2  "\x00"             "d202ef8d"
    3  "\x00\x00"         "41d912ff"
    4  "\x00\x00\x00"     "ff41d912"
    5  "\x00\x00\x00\x00" "2144df1c"
    6  "\xFF"             "ff000000"
    7  "\xFF\xFF"         "ffff0000"
    8  "\xFF\xFF\xFF"     "ffffff00"
    9  "\xFF\xFF\xFF\xFF" "ffffffff"
   10  "\x00\x00\x00\x01" "5643ef8a"
   11  "\x80\x00\x00\x00" "cc1d6927"
} {
    test crc32bugs-2.$n {crc32 (Trf and and crc-32 comparison} {
	list [catch {
            list \
                [::crc::crc32 -format %x $msg] \
                [format %x [::crc::Crc32_tcl $msg]] \
                [::crc::crc-32 -format %x $msg]
        } msg] $msg
    } [list 0 [list $expected $expected $expected]]
}

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

::tcltest::cleanupTests

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