?? binary.test
字號:
# This file tests the tclBinary.c file and the "binary" Tcl command. ## This file contains a collection of tests for one or more of the Tcl# built-in commands. Sourcing this file into Tcl runs the tests and# generates output for errors. No output means no errors were found.## Copyright (c) 1997 by Sun Microsystems, Inc.# Copyright (c) 1998-1999 by Scriptics Corporation.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## RCS: @(#) $Id: binary.test,v 1.11 2003/02/21 21:54:11 dkf Exp $if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest namespace import -force ::tcltest::*}test binary-0.1 {DupByteArrayInternalRep} { set hdr [binary format cc 0 0316] set buf hellomatt set data $hdr append data $buf string length $data} 11test binary-1.1 {Tcl_BinaryObjCmd: bad args} { list [catch {binary} msg] $msg} {1 {wrong # args: should be "binary option ?arg arg ...?"}}test binary-1.2 {Tcl_BinaryObjCmd: bad args} { list [catch {binary foo} msg] $msg} {1 {bad option "foo": must be format or scan}}test binary-1.3 {Tcl_BinaryObjCmd: format error} { list [catch {binary f} msg] $msg} {1 {wrong # args: should be "binary format formatString ?arg arg ...?"}}test binary-1.4 {Tcl_BinaryObjCmd: format} { binary format ""} {}test binary-2.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format a } msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-2.2 {Tcl_BinaryObjCmd: format} { binary format a0 foo} {}test binary-2.3 {Tcl_BinaryObjCmd: format} { binary format a f} {f}test binary-2.4 {Tcl_BinaryObjCmd: format} { binary format a foo} {f}test binary-2.5 {Tcl_BinaryObjCmd: format} { binary format a3 foo} {foo}test binary-2.6 {Tcl_BinaryObjCmd: format} { binary format a5 foo} foo\x00\x00test binary-2.7 {Tcl_BinaryObjCmd: format} { binary format a*a3 foobarbaz blat} foobarbazblatest binary-2.8 {Tcl_BinaryObjCmd: format} { binary format a*X3a2 foobar x} foox\x00rtest binary-3.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format A} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-3.2 {Tcl_BinaryObjCmd: format} { binary format A0 f} {}test binary-3.3 {Tcl_BinaryObjCmd: format} { binary format A f} {f}test binary-3.4 {Tcl_BinaryObjCmd: format} { binary format A foo} {f}test binary-3.5 {Tcl_BinaryObjCmd: format} { binary format A3 foo} {foo}test binary-3.6 {Tcl_BinaryObjCmd: format} { binary format A5 foo} {foo }test binary-3.7 {Tcl_BinaryObjCmd: format} { binary format A*A3 foobarbaz blat} foobarbazblatest binary-3.8 {Tcl_BinaryObjCmd: format} { binary format A*X3A2 foobar x} {foox r}test binary-4.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format B} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-4.2 {Tcl_BinaryObjCmd: format} { binary format B0 1} {}test binary-4.3 {Tcl_BinaryObjCmd: format} { binary format B 1} \x80test binary-4.4 {Tcl_BinaryObjCmd: format} { binary format B* 010011} \x4ctest binary-4.5 {Tcl_BinaryObjCmd: format} { binary format B8 01001101} \x4dtest binary-4.6 {Tcl_BinaryObjCmd: format} { binary format A2X2B9 oo 01001101} \x4d\x00test binary-4.7 {Tcl_BinaryObjCmd: format} { binary format B9 010011011010} \x4d\x80test binary-4.8 {Tcl_BinaryObjCmd: format} { binary format B2B3 10 010} \x80\x40test binary-4.9 {Tcl_BinaryObjCmd: format} { list [catch {binary format B1B5 1 foo} msg] $msg} {1 {expected binary string but got "foo" instead}}test binary-5.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format b} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-5.2 {Tcl_BinaryObjCmd: format} { binary format b0 1} {}test binary-5.3 {Tcl_BinaryObjCmd: format} { binary format b 1} \x01test binary-5.4 {Tcl_BinaryObjCmd: format} { binary format b* 010011} 2test binary-5.5 {Tcl_BinaryObjCmd: format} { binary format b8 01001101} \xb2test binary-5.6 {Tcl_BinaryObjCmd: format} { binary format A2X2b9 oo 01001101} \xb2\x00test binary-5.7 {Tcl_BinaryObjCmd: format} { binary format b9 010011011010} \xb2\x01test binary-5.8 {Tcl_BinaryObjCmd: format} { binary format b17 1} \x01\00\00test binary-5.9 {Tcl_BinaryObjCmd: format} { binary format b2b3 10 010} \x01\x02test binary-5.10 {Tcl_BinaryObjCmd: format} { list [catch {binary format b1b5 1 foo} msg] $msg} {1 {expected binary string but got "foo" instead}}test binary-6.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format h} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-6.2 {Tcl_BinaryObjCmd: format} { binary format h0 1} {}test binary-6.3 {Tcl_BinaryObjCmd: format} { binary format h 1} \x01test binary-6.4 {Tcl_BinaryObjCmd: format} { binary format h c} \x0ctest binary-6.5 {Tcl_BinaryObjCmd: format} { binary format h* baadf00d} \xab\xda\x0f\xd0test binary-6.6 {Tcl_BinaryObjCmd: format} { binary format h4 c410} \x4c\x01test binary-6.7 {Tcl_BinaryObjCmd: format} { binary format h6 c4102} \x4c\x01\x02test binary-6.8 {Tcl_BinaryObjCmd: format} { binary format h5 c41020304} \x4c\x01\x02test binary-6.9 {Tcl_BinaryObjCmd: format} { binary format a3X3h5 foo 2} \x02\x00\x00test binary-6.10 {Tcl_BinaryObjCmd: format} { binary format h2h3 23 456} \x32\x54\x06test binary-6.11 {Tcl_BinaryObjCmd: format} { list [catch {binary format h2 foo} msg] $msg} {1 {expected hexadecimal string but got "foo" instead}}test binary-7.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format H} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-7.2 {Tcl_BinaryObjCmd: format} { binary format H0 1} {}test binary-7.3 {Tcl_BinaryObjCmd: format} { binary format H 1} \x10test binary-7.4 {Tcl_BinaryObjCmd: format} { binary format H c} \xc0test binary-7.5 {Tcl_BinaryObjCmd: format} { binary format H* baadf00d} \xba\xad\xf0\x0dtest binary-7.6 {Tcl_BinaryObjCmd: format} { binary format H4 c410} \xc4\x10test binary-7.7 {Tcl_BinaryObjCmd: format} { binary format H6 c4102} \xc4\x10\x20test binary-7.8 {Tcl_BinaryObjCmd: format} { binary format H5 c41023304} \xc4\x10\x20test binary-7.9 {Tcl_BinaryObjCmd: format} { binary format a3X3H5 foo 2} \x20\x00\x00test binary-7.10 {Tcl_BinaryObjCmd: format} { binary format H2H3 23 456} \x23\x45\x60test binary-7.11 {Tcl_BinaryObjCmd: format} { list [catch {binary format H2 foo} msg] $msg} {1 {expected hexadecimal string but got "foo" instead}}test binary-8.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format c} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-8.2 {Tcl_BinaryObjCmd: format} { list [catch {binary format c blat} msg] $msg} {1 {expected integer but got "blat"}}test binary-8.3 {Tcl_BinaryObjCmd: format} { binary format c0 0x50} {}test binary-8.4 {Tcl_BinaryObjCmd: format} { binary format c 0x50} Ptest binary-8.5 {Tcl_BinaryObjCmd: format} { binary format c 0x5052} Rtest binary-8.6 {Tcl_BinaryObjCmd: format} { binary format c2 {0x50 0x52}} PRtest binary-8.7 {Tcl_BinaryObjCmd: format} { binary format c2 {0x50 0x52 0x53}} PRtest binary-8.8 {Tcl_BinaryObjCmd: format} { binary format c* {0x50 0x52}} PRtest binary-8.9 {Tcl_BinaryObjCmd: format} { list [catch {binary format c2 {0x50}} msg] $msg} {1 {number of elements in list does not match count}}test binary-8.10 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} list [catch {binary format c $a} msg] $msg} [list 1 "expected integer but got \"0x50 0x51\""]test binary-8.11 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format c1 $a} Ptest binary-9.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format s} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-9.2 {Tcl_BinaryObjCmd: format} { list [catch {binary format s blat} msg] $msg} {1 {expected integer but got "blat"}}test binary-9.3 {Tcl_BinaryObjCmd: format} { binary format s0 0x50} {}test binary-9.4 {Tcl_BinaryObjCmd: format} { binary format s 0x50} P\x00test binary-9.5 {Tcl_BinaryObjCmd: format} { binary format s 0x5052} RPtest binary-9.6 {Tcl_BinaryObjCmd: format} { binary format s 0x505251 0x53} QRtest binary-9.7 {Tcl_BinaryObjCmd: format} { binary format s2 {0x50 0x52}} P\x00R\x00test binary-9.8 {Tcl_BinaryObjCmd: format} { binary format s* {0x5051 0x52}} QPR\x00test binary-9.9 {Tcl_BinaryObjCmd: format} { binary format s2 {0x50 0x52 0x53} 0x54} P\x00R\x00test binary-9.10 {Tcl_BinaryObjCmd: format} { list [catch {binary format s2 {0x50}} msg] $msg} {1 {number of elements in list does not match count}}test binary-9.11 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} list [catch {binary format s $a} msg] $msg} [list 1 "expected integer but got \"0x50 0x51\""]test binary-9.12 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format s1 $a} P\x00test binary-10.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format S} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-10.2 {Tcl_BinaryObjCmd: format} { list [catch {binary format S blat} msg] $msg} {1 {expected integer but got "blat"}}test binary-10.3 {Tcl_BinaryObjCmd: format} { binary format S0 0x50} {}test binary-10.4 {Tcl_BinaryObjCmd: format} { binary format S 0x50} \x00Ptest binary-10.5 {Tcl_BinaryObjCmd: format} { binary format S 0x5052} PRtest binary-10.6 {Tcl_BinaryObjCmd: format} { binary format S 0x505251 0x53} RQtest binary-10.7 {Tcl_BinaryObjCmd: format} { binary format S2 {0x50 0x52}} \x00P\x00Rtest binary-10.8 {Tcl_BinaryObjCmd: format} { binary format S* {0x5051 0x52}} PQ\x00Rtest binary-10.9 {Tcl_BinaryObjCmd: format} { binary format S2 {0x50 0x52 0x53} 0x54} \x00P\x00Rtest binary-10.10 {Tcl_BinaryObjCmd: format} { list [catch {binary format S2 {0x50}} msg] $msg} {1 {number of elements in list does not match count}}test binary-10.11 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} list [catch {binary format S $a} msg] $msg} [list 1 "expected integer but got \"0x50 0x51\""]test binary-10.12 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format S1 $a} \x00Ptest binary-11.1 {Tcl_BinaryObjCmd: format} { list [catch {binary format i} msg] $msg} {1 {not enough arguments for all format specifiers}}test binary-11.2 {Tcl_BinaryObjCmd: format} { list [catch {binary format i blat} msg] $msg} {1 {expected integer but got "blat"}}test binary-11.3 {Tcl_BinaryObjCmd: format} { binary format i0 0x50} {}test binary-11.4 {Tcl_BinaryObjCmd: format} { binary format i 0x50} P\x00\x00\x00test binary-11.5 {Tcl_BinaryObjCmd: format} { binary format i 0x5052} RP\x00\x00test binary-11.6 {Tcl_BinaryObjCmd: format} { binary format i 0x505251 0x53} QRP\x00test binary-11.7 {Tcl_BinaryObjCmd: format} { binary format i1 {0x505251 0x53}} QRP\x00test binary-11.8 {Tcl_BinaryObjCmd: format} { binary format i 0x53525150} PQRStest binary-11.9 {Tcl_BinaryObjCmd: format} { binary format i2 {0x50 0x52}} P\x00\x00\x00R\x00\x00\x00test binary-11.10 {Tcl_BinaryObjCmd: format} { binary format i* {0x50515253 0x52}} SRQPR\x00\x00\x00test binary-11.11 {Tcl_BinaryObjCmd: format} { list [catch {binary format i2 {0x50}} msg] $msg} {1 {number of elements in list does not match count}}test binary-11.12 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} list [catch {binary format i $a} msg] $msg} [list 1 "expected integer but got \"0x50 0x51\""]test binary-11.13 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format i1 $a
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -