|
25 | 25 | (or (= ,x* ,y*)
|
26 | 26 | (error "~S != ~S" ,x* ,y*)))))
|
27 | 27 |
|
| 28 | + (defmacro assert-eq (x y) |
| 29 | + (let ((x* (gensym "X")) |
| 30 | + (y* (gensym "Y"))) |
| 31 | + `(let ((,x* ,x) |
| 32 | + (,y* ,y)) |
| 33 | + (or (eq ,x* ,y*) |
| 34 | + (error "~S is not EQ to ~S" ,x* ,y*))))) |
| 35 | + |
28 | 36 | (defmacro assert-equal (x y)
|
29 | 37 | (let ((x* (gensym "X"))
|
30 | 38 | (y* (gensym "Y")))
|
|
319 | 327 | (read-binary 'implicit-bit-stream
|
320 | 328 | *standard-input*)))))))
|
321 | 329 |
|
| 330 | + |
| 331 | +(defbinary example (:untyped-struct t) |
| 332 | + (a 0 :type (unsigned-byte 24)) |
| 333 | + (b 0 :type (magic :actual-type (unsigned-byte 4) |
| 334 | + :value 5)) |
| 335 | + (c 0 :type (unsigned-byte 20))) |
| 336 | + |
| 337 | + |
| 338 | +(unit-test 'untyped-struct-test |
| 339 | + (flexi-streams:with-input-from-sequence (in '(0 0 0)) |
| 340 | + (handler-bind |
| 341 | + (((or end-of-file bad-magic-value) |
| 342 | + (lambda (cond) |
| 343 | + (declare (ignore cond)) |
| 344 | + (invoke-restart 'continue)))) |
| 345 | + (let ((obj (read-binary 'example in))) |
| 346 | + (assert= (slot-value obj 'a) 0) |
| 347 | + (assert= (slot-value obj 'b) 0) |
| 348 | + (assert= (slot-value obj 'c) 0))))) |
| 349 | + |
| 350 | +(defbinary example-2 (:include example) |
| 351 | + (d 0 :type (unsigned-byte 8))) |
| 352 | + |
| 353 | +(unit-test 'include-test |
| 354 | + (let ((obj (make-example-2 :a #xbedead |
| 355 | + :b 4 |
| 356 | + :c #xbefed |
| 357 | + :d #xff))) |
| 358 | + (test-round-trip ":INCLUDE test" |
| 359 | + (write-binary obj *standard-output*) |
| 360 | + (assert-equalp obj (read-binary 'example-2 *standard-input*))))) |
| 361 | + |
322 | 362 | (defun run-test ()
|
323 | 363 | (let ((test-results (do-tests)))
|
324 | 364 | (format t ">>>>>>>>>>>>>>>>>>>>>>>> TEST RESULTS: ~S~%" test-results)
|
|
0 commit comments