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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
# -*- tcl -*-
# Commands covered: binio
#
# This file contains a collection of tests for one or more of the trf
# commands of the TRF extension. Sourcing this file into Tcl runs the
# tests and generates output for errors. No output means no errors were
# found.
#
# Copyright (c) 1997 Andreas Kupries (andreas_kupries@users.sourceforge.net)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: binio.test,v 1.4 1997/05/31 13:51:56 aku Exp $
if {[string compare test [info procs test]] == 1} then {source defs}
if {[catch {binio} msg] && ("$msg" == "invalid command name \"binio\"")} {
puts stdout "\tSkipping 'binio' tests, as the command is not compiled into the package"
flush stdout
return ""
}
# determine endianess of machine running these tests
proc endianess {} {
set fh [open binio.test r]
set e [fconfigure $fh -byteorder]
close $fh
return $e
}
proc choose {small big} {
global endianess
switch -- $endianess {
smallendian {return $small}
bigendian {return $big}
}
}
set endianess [endianess]
test binio-1.0 {binio, errors} {
catch {binio} msg
set msg
} {wrong # args: should be "binio option channel ?arg arg...?"}
test binio-1.1 {binio, errors} {
catch {binio blubber a} msg
set msg
} {binio blubber: channel expected as 2nd argument, got "a"}
test binio-1.2 {binio, errors} {
catch {binio blubber stdin} msg
set msg
} {binio: bad option "blubber": should be one of copy, pack or unpack}
test binio-1.3 {binio, errors} {
catch {binio copy stdin} msg
set msg
} {wrong # args: should be "binio copy inChannel outChannel ?chunkSize?"}
test binio-1.4 {binio, errors} {
catch {binio pack stdout} msg
set msg
} {wrong # args: should be "binio pack outChannel format ?data1 data2 ...?"}
test binio-1.5 {binio, errors} {
catch {binio unpack stdin} msg
set msg
} {wrong # args: should be "binio unpack outChannel format ?var1 var2 ...?"}
test binio-1.6 {binio copy, errors} {
catch {binio copy stdout stdin} msg
set msg
} {channel "stdout" wasn't opened for reading}
test binio-1.7 {binio copy, errors} {
catch {binio copy stdin stdin} msg
set msg
} {channel "stdin" wasn't opened for writing}
test binio-1.8 {binio copy} {
set input [open test.binio r]
set output [memchan]
fconfigure $input -translation binary
fconfigure $output -translation binary
set n [binio copy $input $output]
close $output
close $input
set n
} {27}
test binio-1.9 {binio unpack, %c} {
set input [open test.binio r]
fconfigure $input -translation binary
set n ""
foreach i {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} {
binio unpack $input %c k
lappend n $k
}
close $input
set n
} {0 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}
test binio-1.10 {binio unpack, %X, smallendian} {
set input [open test.binio r]
fconfigure $input -translation binary -byteorder smallendian
set n ""
foreach i {1 2 3 4 5 6 7 8 9 10 11 12 13} {
binio unpack $input %X k
lappend n $k
}
close $input
set n
} {0100 0302 0504 0706 0908 0b0a 0d0c 0f0e 1110 1312 1514 1716 1918}
test binio-1.11 {binio unpack, %X, bigendian} {
set input [open test.binio r]
fconfigure $input -translation binary -byteorder bigendian
set n ""
foreach i {1 2 3 4 5 6 7 8 9 10 11 12 13} {
binio unpack $input %X k
lappend n $k
}
close $input
set n
} {0001 0203 0405 0607 0809 0a0b 0c0d 0e0f 1011 1213 1415 1617 1819}
test binio-1.12 {binio unpack, %x, smallendian order} {
set input [open test.binio r]
fconfigure $input -translation binary -byteorder smallendian
set n ""
foreach i {1 2 3 4 5 6} {
binio unpack $input %x k
lappend n $k
}
close $input
set n
} {03020100 07060504 0b0a0908 0f0e0d0c 13121110 17161514}
test binio-1.13 {binio unpack, %x, bigendian order} {
set input [open test.binio r]
fconfigure $input -translation binary -byteorder bigendian
set n ""
foreach i {1 2 3 4 5 6} {
binio unpack $input %x k
lappend n $k
}
close $input
set n
} {00010203 04050607 08090a0b 0c0d0e0f 10111213 14151617}
unset input
unset output
unset endianess
rename endianess {}
rename choose {}
|