-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.lisp
545 lines (454 loc) · 22.6 KB
/
tests.lisp
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
(in-package :bitio)
(defun dbgval (val fmt &rest args)
;; TODO: Fix to accept the number of bits that SHOULD be printed
;; out, and zero pad with additional format args as appropriate.
;; TODO, and fix the wonky FMT usage and ordering.
(apply #'format t fmt args)
(format t ": #x~X (#b~B)~%" val val)
(finish-output))
(defun test-make-bitio/fast-io (fiobuf &key (octet-read-buffer-size 4096))
(format t " BITIO has ~A read-buffer size.~%" octet-read-buffer-size)
(make-bitio fiobuf #'fast-io:fast-read-byte
;; canonicalize fast-io's fast-read-sequence to look
;; like clhs' read-sequence. They differ in lambda
;; lists.
(lambda (vec buffer &key (start 0) (end nil))
(funcall #'fast-io:fast-read-sequence vec buffer start end))
:octet-read-buffer-size octet-read-buffer-size))
(defun test-make-bitio/clhs (fiobuf &key (octet-read-buffer-size 4096))
(make-bitio fiobuf #'read-byte #'read-sequence
:octet-read-buffer-size octet-read-buffer-size))
(defun make-octet-vector ()
(make-array 10 :element-type '(unsigned-byte 8)
:initial-contents '(#x5c
#xf6 #xee
#x79 #x9a #xde
#xff #xf2 #x88 #x02)))
(defun test-read-bits (bitio num-bits-to-read bit-endian expected-value
&optional
(expected-bits-to-have-been-read num-bits-to-read)
(eof-error-p T)
(eof-value NIL))
(multiple-value-bind (value bit-read-count)
(read-bits bitio num-bits-to-read
:bit-endian bit-endian
:eof-error-p eof-error-p
:eof-value eof-value)
(format t " -> Expecting[~D bits]: #x~X~%"
num-bits-to-read expected-value)
(format t " Actually Read[~D bits, bit ~(~S~)]: #x~X~%"
bit-read-count bit-endian value)
(if (and (not eof-error-p) (equal value eof-value))
;; In this case, expected value is known to be the eof-value!
(assert (eql expected-bits-to-have-been-read bit-read-count))
;; In this case, we either check a full value or a truncated one.
(assert (and (equalp expected-value value)
(eql expected-bits-to-have-been-read bit-read-count))))))
(defun test-read-one-byte (bitio bits-per-byte bit-endian expected-value
&optional
(expected-bits-to-have-been-read bits-per-byte)
(eof-error-p T)
(eof-value NIL))
(multiple-value-bind (value bit-read-count)
(read-one-byte bitio
:bits-per-byte bits-per-byte
:bit-endian bit-endian
:eof-error-p eof-error-p
:eof-value eof-value)
(dbgval value (format nil "~D bits ~(~S~) should be #x~X"
bits-per-byte bit-endian expected-value))
(if (and (not eof-error-p) (equal value eof-value))
;; In this case, expected value is known to be the eof-value!
(assert (eql expected-bits-to-have-been-read bit-read-count))
;; In this case, we either check a full value or a truncated one.
(assert (and (equalp expected-value value)
(eql expected-bits-to-have-been-read bit-read-count))))))
(defun test-read-integer (bitio num-bytes bits-per-byte
bit-endian byte-endian unsignedp expected-value)
(let ((value (read-integer bitio
:bit-endian bit-endian
:byte-endian byte-endian
:num-bytes num-bytes
:bits-per-byte bits-per-byte
:unsignedp unsignedp)))
(dbgval value (format nil "read-integer (num-bytes: ~A, bits-per-byte: ~A, bit-endian: ~A, byte-endian: ~A, unsignedp: ~A): [#x~X] should be #x~X"
num-bytes bits-per-byte bit-endian byte-endian unsignedp
value expected-value))
;; Currently I ignore eof-error-p and eof-value, I need to think about
;; how to add that in.
(assert (equalp expected-value value))))
;; Note "byte" doesn't necessarily mean 8 bit octets!
(defun test-read-bytes (bitio seq bit-endian bits-per-byte
expected-seq &key (start 0) end)
(let ((num-parts-read (read-bytes bitio
seq
:bit-endian bit-endian
:bits-per-byte bits-per-byte
:start start
:end end)))
(let ((*print-right-margin* 9999))
(format t "seq(bits-per-byte: ~A, bit-endian: ~A, seq ~X [start: ~A, end: ~A]) should be ~X~%"
bits-per-byte bit-endian seq start end expected-seq))
(assert (eql (length expected-seq) num-parts-read))
;; Check the sequence range we're supposed to have read is ok.
(loop :for i :from start :below (if (null end) (length seq) end)
:do (assert (eql (aref seq i) (aref expected-seq i))))))
(defmacro do-test (stream-kind octet-read-buffer-size octet-vector-sym
bitio-sym title-msg detail-msg &body body)
(let ((fiobuf (gensym)))
`(fast-io:with-fast-input (,fiobuf ,octet-vector-sym)
(format t "Test: [~A] ~A~%" , stream-kind ,title-msg)
(format t " DESC: ~A~%" ,detail-msg)
(let ((,bitio-sym
(funcall (function ,(ecase stream-kind
(:fast-io 'test-make-bitio/fast-io)
(:clhs-io 'test-make-bitio/clhs)))
,fiobuf
:octet-read-buffer-size ,octet-read-buffer-size)))
,@body
))))
(defun doit ()
(let ((octet-vector (make-octet-vector)))
(format t "Test Octet vector: ~X~%" octet-vector)
;; We test these functions:
;; make-bitio, read-bits, read-one-byte, read-integer, read-bytes,
;; octet-read-boundary-p
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all aligned 1 octet reads, octet buffer larger, no eof, bit :be"
(test-read-bits bitio 8 :be #x5C)
(test-read-bits bitio 8 :be #xF6)
(test-read-bits bitio 8 :be #xEE)
(test-read-bits bitio 8 :be #x79))
(do-test :fast-io 1 octet-vector bitio "READ-BITS"
"all aligned 1 octet reads, octet buffer size 1, no eof, bit :be"
(test-read-bits bitio 8 :be #x5C)
(test-read-bits bitio 8 :be #xF6)
(test-read-bits bitio 8 :be #xEE)
(test-read-bits bitio 8 :be #x79))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer larger, no eof, bit :be"
(test-read-bits bitio 8 :be #x5C)
(test-read-bits bitio 16 :be #xF6EE)
(test-read-bits bitio 24 :be #x799ADE)
(test-read-bits bitio 32 :be #xFFF28802))
(do-test :fast-io 3 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer smaller, no eof, bit :be"
(test-read-bits bitio 8 :be #x5C)
(test-read-bits bitio 16 :be #xF6EE)
(test-read-bits bitio 24 :be #x799ADE)
(test-read-bits bitio 32 :be #xFFF28802))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer larger, no eof, bit :le"
(test-read-bits bitio 8 :le #x3A)
(test-read-bits bitio 16 :le #x6F77)
(test-read-bits bitio 24 :le #x9E597B)
(test-read-bits bitio 32 :le #xFF4F1140))
(do-test :fast-io 11 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer larger size, no eof, bit :be"
(test-read-bits bitio 80 :be #x5CF6EE799ADEFFF28802))
(do-test :fast-io 10 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer same size, no eof, bit :be"
(test-read-bits bitio 80 :be #x5CF6EE799ADEFFF28802))
(do-test :fast-io 9 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer smaller size, no eof, bit :be"
(test-read-bits bitio 80 :be #x5CF6EE799ADEFFF28802))
(do-test :fast-io 1 octet-vector bitio "READ-BITS"
"all aligned reads, octet buffer size of 1, no eof, bit :be"
(test-read-bits bitio 80 :be #x5CF6EE799ADEFFF28802))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all unaligned reads, octet buffer larger, no eof, bit :be"
(test-read-bits bitio 1 :be #b0)
(test-read-bits bitio 1 :be #b1)
(test-read-bits bitio 1 :be #b0)
(test-read-bits bitio 1 :be #b1)
(test-read-bits bitio 1 :be #b1)
(test-read-bits bitio 1 :be #b1)
(test-read-bits bitio 1 :be #b0)
(test-read-bits bitio 1 :be #b0))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all unaligned reads, octet buffer larger, no eof, bit :le"
;; Consume 1 octet worth of information
(test-read-bits bitio 1 :le #b0)
(test-read-bits bitio 1 :le #b0)
(test-read-bits bitio 1 :le #b1)
(test-read-bits bitio 1 :le #b1)
(test-read-bits bitio 1 :le #b1)
(test-read-bits bitio 1 :le #b0)
(test-read-bits bitio 1 :le #b1)
(test-read-bits bitio 1 :le #b0))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all unaligned reads, octet buffer larger, no eof, bit :le/:be"
;; Consume 1 octet :le bits first, then :be of the remaining bits.
(test-read-bits bitio 1 :le #b0)
(test-read-bits bitio 1 :le #b0)
(test-read-bits bitio 1 :le #b1)
(test-read-bits bitio 1 :le #b1)
(test-read-bits bitio 1 :be #b0)
(test-read-bits bitio 1 :be #b1)
(test-read-bits bitio 1 :be #b0)
(test-read-bits bitio 1 :be #b1))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all unaligned reads, octet buffer larger, no eof, bit :be"
;; Consume 1 octet
(test-read-bits bitio 4 :be #b0101)
(test-read-bits bitio 4 :be #b1100)
;; Consume 1 octet
(test-read-bits bitio 3 :be #b111)
(test-read-bits bitio 5 :be #b10110)
;; Consume 1 octet
(test-read-bits bitio 2 :be #b11)
(test-read-bits bitio 6 :be #b101110)
;; Consume 1 octet
(test-read-bits bitio 1 :be #b0)
(test-read-bits bitio 7 :be #b1111001)
;; Consume 1 octet
(test-read-bits bitio 2 :be #b10)
(test-read-bits bitio 2 :be #b01)
(test-read-bits bitio 2 :be #b10)
(test-read-bits bitio 2 :be #b10)
;; Consume 3 octets hopping boundaries
(test-read-bits bitio 4 :be #xd)
(test-read-bits bitio 8 :be #xef)
(test-read-bits bitio 8 :be #xff)
(test-read-bits bitio 4 :be #x2)
;; Consume 2 octets hopping boundaries
(test-read-bits bitio 7 :be #b1000100)
(test-read-bits bitio 2 :be #b00)
(test-read-bits bitio 7 :be #b0000010))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"mixed w/inferred aligned read, octet buffer larger, no eof, bit :be"
;; Consume .5 octet
(test-read-bits bitio 4 :be #x5)
;; Consume .5 octet, 8 octets, .5 octet
;; This infers a fast read of 8 octets in the middle of the 72 bits.
(test-read-bits bitio 72 :be #xcf6ee799adefff2880)
;; Consume .5 octet
(test-read-bits bitio 4 :be #x2))
(do-test :fast-io 3 octet-vector bitio "READ-BITS"
"mixed w/inferred aligned read, octet buffer size 3, no eof, bit :be"
;; Consume .5 octet
(test-read-bits bitio 4 :be #x5)
;; Consume .5 octet, 8 octets, .5 octet
;; This infers a fast read of 8 octets in the middle of the 72 bits.
(test-read-bits bitio 72 :be #xcf6ee799adefff2880)
;; Consume .5 octet
(test-read-bits bitio 4 :be #x2))
(do-test :fast-io 4096 octet-vector bitio "READ-BITS"
"all aligned read, octet buffer size larger, eof, bit :be"
;; Consume 10 legal octets, and then one more (80 bits plus 8
;; bits) resulting in EOF. Expected value here is the
;; expected truncated return.
(test-read-bits bitio 88 :be #x5cf6ee799adefff28802 80 NIL :eof)
;; Here we blatently read an :eof again, so we expect to see an :eof
(test-read-bits bitio 80 :be :eof 0 NIL :eof))
(do-test :fast-io 7 octet-vector bitio "READ-BITS"
"all aligned read, octet buffer size smaller, eof, bit :be"
;; Consume 10 legal octets, and then one more (80 bits plus 8
;; bits) resulting in EOF. Expected value here is the
;; expected truncated return.
(test-read-bits bitio 88 :be #x5cf6ee799adefff28802 80 NIL :eof)
;; Here we blatently read an :eof again, so we expect to see an :eof
(test-read-bits bitio 80 :be :eof 0 NIL :eof))
(do-test :fast-io 1 octet-vector bitio "READ-BITS"
"all aligned read, octet buffer size 1, eof, bit :be"
;; Consume 10 legal octets, and then one more (80 bits plus 8
;; bits) resulting in EOF. Expected value here is the
;; expected truncated return.
(test-read-bits bitio 88 :be #x5cf6ee799adefff28802 80 NIL :eof)
;; Here we blatently read an :eof again, so we expect to see an :eof
(test-read-bits bitio 80 :be :eof 0 NIL :eof))
(format t "Case: read-bits, slow read path with eof, bit-endian: :be~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
;; Consume .5 octet
(test-read-bits bitio 4 :be #x5)
;; Consume .5 octet, 9 legal octets, then 1 more octet which is EOF
;; The value is the expected truncated read.
(test-read-bits bitio 84 :be #xcf6ee799adefff28802 76 NIL :eof)
;; Consume .5 octets, but get :eof
(test-read-bits bitio 4 :be :eof 0 NIL :eof)
;; Consume 1 octet, but get :eof
(test-read-bits bitio 8 :be :eof 0 NIL :eof)
;; Consume 1.5 octet, but get :eof
(test-read-bits bitio 12 :be :eof 0 NIL :eof)
))
(format t "Case: read-bits, slow read path with eof2, bit-endian: :be~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
;; Consume .5 octet, 9 legal octets. This leaves 1 for the stable.
(test-read-bits bitio 76 :be #x5cf6ee799adefff2880)
;; Consume 1 octet, but get an expected short read of 4 bits
(test-read-bits bitio 8 :be #x2 4 NIL :eof)
;; Consume .5 octet, but get eof
(test-read-bits bitio 4 :be :eof 0 NIL :eof)
))
(format t "Case: read-one-byte, bit-endian: :be, 8 bits wide~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
;; Consume 1 octet as 1 byte.
(test-read-one-byte bitio 8 :be #x5c)
))
(format t "Case: read-one-byte, bit-endian: :be, 12 bits wide~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
;; Consume 1.5 octets, as 1 byte
(test-read-one-byte bitio 12 :be #x5cf)
;; Consume 1.5 octets, as 1 byte
(test-read-one-byte bitio 12 :be #x6ee)
))
;; This one may look non-intuitive...
(format t "Case: read-one-byte, bit-endian: :le, 12 bits wide~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
;; Consume 1.5 octets, as 1 byte
(test-read-one-byte bitio 12 :le #x3a6)
;; Consume 1.5 octets, as 1 byte
(test-read-one-byte bitio 12 :le #xf77)
))
(format t "Case: read-bytes, bit-width 4, bit-endian :be~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(let ((seq (make-array (ceiling (/ (length octet-vector) .5))
:element-type '(unsigned-byte 4)
:initial-element 0)))
(test-read-bytes bitio seq :be 4
#(#x5 #xc #xf #x6 #xe #xe #x7 #x9 #x9 #xa
#xd #xe #xf #xf #xf #x2 #x8 #x8 #x0 #x2)))
))
(format t "Case: read-bytes, bit-width 4, bit-endian :le~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(let ((seq (make-array (ceiling (/ (length octet-vector) .5))
:element-type '(unsigned-byte 4)
:initial-element 0)))
(test-read-bytes bitio seq :le 4
(map 'vector
(lambda (x) (integer-reverse x 4))
#(#xc #x5 #x6 #xf #xe #xe #x9 #x7
#xa #x9 #xe #xd #xf #xf #x2 #xf
#x8 #x8 #x2 #x0))))
))
(format t "Case: read-bytes, bit-width 8, bit-endian :be~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(let ((seq (make-array (ceiling (/ (length octet-vector) 1))
:element-type '(unsigned-byte 8)
:initial-element 0)))
(test-read-bytes bitio seq :be 8
#(#x5c #xf6 #xee #x79 #x9a
#xde #xff #xf2 #x88 #x02)))
))
(format t "Case: read-bytes, bit-width 8, bit-endian :le~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(let ((seq (make-array (ceiling (/ (length octet-vector) 1))
:element-type '(unsigned-byte 8)
:initial-element 0)))
(test-read-bytes bitio seq :le 8
(map 'vector
(lambda (x) (integer-reverse x 8))
#(#x5c #xf6 #xee #x79 #x9a
#xde #xff #xf2 #x88 #x02))))
))
(format t "Case: read-bytes, bit-width 12, bit-endian :be~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(let ((seq (make-array (ceiling (/ (length octet-vector) 1.5))
:element-type '(unsigned-byte 12)
:initial-element 0)))
(test-read-bytes bitio seq :be 12
#(#x5cf #x6ee #x799 #xade #xfff #x288 #x02)))
))
(format t "Case: read-bytes, bit-width 16, bit-endian :be~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(let ((seq (make-array (ceiling (/ (length octet-vector) 2))
:element-type '(unsigned-byte 16)
:initial-element 0)))
(test-read-bytes bitio seq :be 16
#(#x5cf6 #xee79 #x9ade #xfff2 #x8802)))
))
(format t "Case: read-integer, case 1~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 1 8 :be :le T #x5c)
(test-read-integer bitio 2 8 :be :le T #xeef6)
(test-read-integer bitio 3 8 :be :le T #xde9a79)
(test-read-integer bitio 4 8 :be :le T #x0288f2ff)
))
(format t "Case: read-integer, case 2~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 1 8 :be :be T #x5c)
(test-read-integer bitio 2 8 :be :be T #xf6ee)
(test-read-integer bitio 3 8 :be :be T #x799ade)
(test-read-integer bitio 4 8 :be :be T #xfff28802)
))
(format t "Case: read-integer, case 3~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 1 4 :be :be T #x5)
(test-read-integer bitio 1 4 :le :be T #x3)
(test-read-integer bitio 1 8 :le :be T #x6f)
(test-read-integer bitio 1 8 :be :be T #xee)
(test-read-integer bitio 1 8 :le :be NIL
(sign-extend (integer-reverse #x79 8) 8))
(test-read-integer bitio 1 8 :be :be NIL
(sign-extend #x9a 8))
(test-read-integer bitio 1 4 :be :be T #xd)
;; intentional misaligned octet read...
(test-read-integer bitio 4 8 :be :be T #xefff2880)
(test-read-integer bitio 1 4 :be :be T #x2)
))
(format t "Case: read-integer, case 4~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 4 8 :be :be T #x5cf6ee79)
(test-read-integer bitio 4 8 :be :le T #xf2ffde9a)
))
(format t "Case: read-integer, case 5~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 4 12 :be :be T #x5cf6ee799ade)
))
(format t "Case: read-integer, case 6~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 4 12 :le :be T #x3a6f779e597b)
(test-read-integer bitio 4 8 :be :be T #xfff28802)
))
(format t "Case: read-integer, case 7~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 4 16 :be :be T #x5cf6ee799adefff2)
))
(format t "Case: read-integer, case 8~%")
(fast-io:with-fast-input (fiobuf octet-vector)
(let ((bitio (test-make-bitio/fast-io fiobuf)))
(test-read-integer bitio 4 16 :be :le T #xfff29adeee795cf6)
))
;; Test a non fast-io stream
(format t "Case: wrapping regular CL octet stream~%")
(with-open-file (fin (asdf:system-relative-pathname :bitio "binfile")
:direction :input
:element-type '(unsigned-byte 8)
:if-does-not-exist :error)
;; wrap fin stream with a bitio stream.
(let ((bitio (test-make-bitio/clhs fin)))
(test-read-bits bitio 88 :be #x000102030405060708090a)
))
;; Test a fast-io stream backed by a file.
(format t "Case: wrapping fast-io octet stream from a file~%")
(with-open-file (fin (asdf:system-relative-pathname :bitio "binfile")
:direction :input
:element-type '(unsigned-byte 8)
:if-does-not-exist :error)
(fast-io:with-fast-input (fin-fast
(make-array 0 :element-type '(unsigned-byte 8))
fin)
;; wrap fin stream with a bitio stream.
(let ((bitio (test-make-bitio/fast-io fin-fast)))
(test-read-bits bitio 88 :be #x000102030405060708090a)
)))
(format t "All done.~%")
))