;; Test bokbok-packet (use bokbok-packet) (use test) (use utf8) (use crypto-tools) (use numbers) (define (check-binary input wanted-output) (let* ((actual-output (join-packet input)) (decoded-output (split-packet actual-output))) (test (sprintf "~S bytes" input) (blob->hexstring (string->blob wanted-output)) (blob->hexstring (string->blob actual-output))) (if (and (real? input) (not (= input input))) (test (sprintf "~S decoded (nan)" input) #f (= decoded-output decoded-output)) (test (sprintf "~S decoded" input) input decoded-output)))) ;; Simple things (check-binary #t "\x01\x01\xff") (check-binary #f "\x01\x01\x00") ;; Stringy things (check-binary 'fish "\xdd\x04fish") (check-binary "FISH" "\x0c\x04FISH") (check-binary "Ÿ" "\x0c\x02Ÿ") ;; Integer things ; Explore +/- around various powers of two (check-binary 0 "\x02\x00") (check-binary 1 "\x02\x01\x01") (check-binary -1 "\x02\x01\xff") (check-binary 127 "\x02\x01\x7f") (check-binary 128 "\x02\x02\x00\x80") (check-binary -127 "\x02\x01\x81") (check-binary -128 "\x02\x01\x80") (check-binary -129 "\x02\x02\xff\x7f") (check-binary 255 "\x02\x02\x00\xff") (check-binary 256 "\x02\x02\x01\x00") (check-binary -255 "\x02\x02\xff\x01") (check-binary -256 "\x02\x02\xff\x00") (check-binary 32767 "\x02\x02\x7f\xff") (check-binary 32768 "\x02\x04\x00\x00\x80\x00") (check-binary -32767 "\x02\x02\x80\x01") (check-binary -32768 "\x02\x02\x80\x00") (check-binary -32769 "\x02\x04\xff\xff\x7f\xff") (check-binary 65535 "\x02\x04\x00\x00\xff\xff") (check-binary 65536 "\x02\x04\x00\x01\x00\x00") (check-binary -65535 "\x02\x04\xff\xff\x00\x01") (check-binary -65536 "\x02\x04\xff\xff\x00\x00") (check-binary -65537 "\x02\x04\xff\xfe\xff\xff") (check-binary 8388607 "\x02\x04\x00\x7f\xff\xff") (check-binary 8388608 "\x02\x04\x00\x80\x00\x00") (check-binary -8388607 "\x02\x04\xff\x80\x00\x01") (check-binary -8388608 "\x02\x04\xff\x80\x00\x00") (check-binary -8388609 "\x02\x04\xff\x7f\xff\xff") (check-binary 16777215 "\x02\x04\x00\xff\xff\xff") (check-binary 16777216 "\x02\x04\x01\x00\x00\x00") (check-binary -16777215 "\x02\x04\xff\x00\x00\x01") (check-binary -16777216 "\x02\x04\xff\x00\x00\x00") (check-binary -16777217 "\x02\x04\xfe\xff\xff\xff") (check-binary 2147483647 "\x02\x04\x7f\xff\xff\xff") (check-binary 2147483648 "\x02\x08\x00\x00\x00\x00\x80\x00\x00\x00") (check-binary -2147483647 "\x02\x04\x80\x00\x00\x01") (check-binary -2147483648 "\x02\x04\x80\x00\x00\x00") (check-binary -2147483649 "\x02\x08\xff\xff\xff\xff\x7f\xff\xff\xff") (check-binary 4294967295 "\x02\x08\x00\x00\x00\x00\xff\xff\xff\xff") (check-binary 4294967296 "\x02\x08\x00\x00\x00\x01\x00\x00\x00\x00") (check-binary -4294967295 "\x02\x08\xff\xff\xff\xff\x00\x00\x00\x01") (check-binary -4294967296 "\x02\x08\xff\xff\xff\xff\x00\x00\x00\x00") (check-binary -4294967297 "\x02\x08\xff\xff\xff\xfe\xff\xff\xff\xff") (check-binary (- (expt 2 63) 1) "\x02\x08\x7f\xff\xff\xff\xff\xff\xff\xff") (check-binary (- (expt 2 63) 0) "\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00") (check-binary (- 0 (expt 2 63) -1) "\x02\x08\x80\x00\x00\x00\x00\x00\x00\x01") (check-binary (- 0 (expt 2 63)) "\x02\x08\x80\x00\x00\x00\x00\x00\x00\x00") (check-binary (- 0 (expt 2 63) 1) "\x02\x10\xff\xff\xff\xff\xff\xff\xff\xff\x7f\xff\xff\xff\xff\xff\xff\xff") (check-binary (- (expt 2 64) 1) "\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff") (check-binary (- (expt 2 64) 0) "\x02\x10\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00") (check-binary (- 0 (expt 2 64) -1) "\x02\x10\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x01") (check-binary (- 0 (expt 2 64)) "\x02\x10\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") (check-binary (- 0 (expt 2 64) 1) "\x02\x10\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xff") (check-binary (- 0 (expt 2 64) 2) "\x02\x10\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\xfe") ;; Floaty things (check-binary 0.0 "\xfe\x030.0") (check-binary 1.0 "\xfe\x031.0") (check-binary +inf.0 "\xfe\x06+inf.0") (check-binary -inf.0 "\xfe\x06-inf.0") (check-binary +nan.0 "\xfe\x06+nan.0") (check-binary 2+1i "\xfe\x042+1i") (check-binary 1/3 "\xfe\x031/3") ;; Listy things (check-binary '() "\xe0\x80\x00\x00") (check-binary '("hello") "\xe0\x80\x0c\x05hello\x00\x00") (check-binary '("hello" world) "\xe0\x80\x0c\x05hello\xdd\x05world\x00\x00") ;; Vectory things (check-binary #() "\x30\x80\x00\x00") (check-binary #("hello") "\x30\x80\x0c\x05hello\x00\x00") (check-binary #("hello" world) "\x30\x80\x0c\x05hello\xdd\x05world\x00\x00") ;; Core objects (check-binary (make-core-object #x11 "Hello") "\x11\x80\x0c\x05Hello\x00\x00") (check-binary (make-core-object 'fap "Hello") "\xff\x80\xdd\x03fap\x0c\x05Hello\x00\x00")