Skip to content

Commit f4b3539

Browse files
committed
[tests] Use helper function to make byte vectors, for brevity
1 parent 8a68b42 commit f4b3539

1 file changed

Lines changed: 44 additions & 39 deletions

File tree

tests/binary-data-test.dylan

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ author: Andreas Bogk and Hannes Mehnert
33
copyright: 2005-2011 Andreas Bogk and Hannes Mehnert. All rights reserved.
44
license: see LICENSE.txt in this distribution
55
6+
// for brevity; we do this a lot
7+
define function bv (#rest bytes)
8+
as(<byte-vector>, bytes)
9+
end;
10+
611
define function static-checker
712
(field :: <field>,
813
start :: <integer-or-unknown>,
@@ -46,14 +51,14 @@ end;
4651
define test binary-data-assemble ()
4752
let frame = make(<test-protocol>, foo: #x23, bar: #x42);
4853
let byte-vector = assemble-frame(frame);
49-
check-equal("Assembled frame is correct", as(<byte-vector>, #(#x23, #x42)), byte-vector.packet);
54+
check-equal("Assembled frame is correct", bv(#x23, #x42), byte-vector.packet);
5055
end;
5156

5257
define test binary-data-modify ()
5358
let frame = parse-frame(<test-protocol>, #(#x23, #x42));
5459
frame.bar := #x69;
5560
let byte-vector = assemble-frame(frame);
56-
check-equal("Modified frame is correct", as(<byte-vector>, #(#x23, #x69)), byte-vector.packet);
61+
check-equal("Modified frame is correct", bv(#x23, #x69), byte-vector.packet);
5762
end;
5863

5964
define binary-data <dynamic-test> (<header-frame>)
@@ -79,7 +84,7 @@ end;
7984
define test binary-data-dynamic-assemble ()
8085
let frame = make(<dynamic-test>,
8186
foobar: #x3,
82-
payload: parse-frame(<raw-frame>, as(<byte-vector>, #(#x23, #x42, #x23, #x42))));
87+
payload: parse-frame(<raw-frame>, bv(#x23, #x42, #x23, #x42)));
8388
let byte-vector = assemble-frame(frame);
8489
check-equal("Assembling dynamic frame is correct (including padding)",
8590
as(<stretchy-byte-vector-subsequence>, #(#x3, #x0, #x0, #x23, #x42, #x23, #x42)),
@@ -104,10 +109,10 @@ define test static-start-test ()
104109
end;
105110

106111
define test static-start-assemble ()
107-
let frame = make(<static-start-frame>, a: #x23, b: parse-frame(<raw-frame>, as(<byte-vector>, #(#x2, #x3, #x4, #x5))));
112+
let frame = make(<static-start-frame>, a: #x23, b: parse-frame(<raw-frame>, bv(#x2, #x3, #x4, #x5)));
108113
let byte-vector = assemble-frame(frame);
109114
check-equal("Assembling static start frame is correct (including padding)",
110-
as(<byte-vector>, #(#x23, #x0, #x0, #x2, #x3, #x4, #x5)),
115+
bv(#x23, #x0, #x0, #x2, #x3, #x4, #x5),
111116
byte-vector.packet);
112117
end;
113118

@@ -136,7 +141,7 @@ define test repeated-assemble ()
136141
after: #x44);
137142
let byte-vector = assemble-frame(frame);
138143
check-equal("Assemble frame with repeated field",
139-
as(<byte-vector>, #(#x23, #x23, #x42, #x23, #x42, #x0, #x44)),
144+
bv(#x23, #x23, #x42, #x23, #x42, #x0, #x44),
140145
byte-vector.packet);
141146
end;
142147

@@ -178,10 +183,10 @@ end;
178183
define test repeated-and-dynamic-assemble ()
179184
let frame = make(<repeated-and-dynamic-test-frame>,
180185
options: as(<stretchy-vector>, #(#x23, #x42, #x23, #x42, #x23, #x0)),
181-
payload: parse-frame(<raw-frame>, as(<byte-vector>, #(#x0, #x1, #x2, #x3, #x4))));
186+
payload: parse-frame(<raw-frame>, bv(#x0, #x1, #x2, #x3, #x4)));
182187
let byte-vector = assemble-frame(frame);
183188
check-equal("Repeated and dynamic assemble",
184-
as(<byte-vector>, #(#x8, #x23, #x23, #x42, #x23, #x42, #x23, #x0, #x0, #x1, #x2, #x3, #x4)),
189+
bv(#x8, #x23, #x23, #x42, #x23, #x42, #x23, #x0, #x0, #x1, #x2, #x3, #x4),
185190
byte-vector.packet);
186191
end;
187192

@@ -211,7 +216,7 @@ define test count-repeated-assemble ()
211216
last-field: #x23);
212217
let byte-vector = assemble-frame(frame);
213218
check-equal("Count repeated assemble",
214-
as(<byte-vector>, #(#x7, #x1, #x2, #x3, #x4, #x5, #x6, #x7, #x23)),
219+
bv(#x7, #x1, #x2, #x3, #x4, #x5, #x6, #x7, #x23),
215220
byte-vector.packet);
216221
end;
217222

@@ -243,42 +248,42 @@ end;
243248

244249
define test label-assemble ()
245250
let frames = as(<stretchy-vector>,
246-
list(make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x1, #x2, #x3)))),
247-
make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x4, #x5, #x6)))),
248-
make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x7, #x8, #x9, #x10))))));
251+
list(make(<frag>, data: parse-frame(<raw-frame>, bv(#x1, #x2, #x3))),
252+
make(<frag>, data: parse-frame(<raw-frame>, bv(#x4, #x5, #x6))),
253+
make(<frag>, data: parse-frame(<raw-frame>, bv(#x7, #x8, #x9, #x10)))));
249254
let frame = make(<labe>, a: #x23, b: frames, c: #x42);
250255
let byte-vector = assemble-frame(frame);
251256
check-equal("label assemble",
252-
as(<byte-vector>, #(#x23, #x23, #x3, #x1, #x2, #x3, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x42)),
257+
bv(#x23, #x23, #x3, #x1, #x2, #x3, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x42),
253258
byte-vector.packet);
254259
end;
255260

256261
define test label-assign1 ()
257262
let frames = as(<stretchy-vector>,
258-
list(make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x1, #x2, #x3)))),
259-
make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x4, #x5, #x6)))),
260-
make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x7, #x8, #x9, #x10))))));
263+
list(make(<frag>, data: parse-frame(<raw-frame>, bv(#x1, #x2, #x3))),
264+
make(<frag>, data: parse-frame(<raw-frame>, bv(#x4, #x5, #x6))),
265+
make(<frag>, data: parse-frame(<raw-frame>, bv(#x7, #x8, #x9, #x10)))));
261266
let frame = make(<labe>, a: #x23, b: frames, c: #x42);
262-
frame.b[1] := make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x5, #x6, #x7))));
267+
frame.b[1] := make(<frag>, data: parse-frame(<raw-frame>, bv(#x5, #x6, #x7)));
263268
let byte-vector = assemble-frame(frame);
264269
check-equal("label assign",
265-
as(<byte-vector>, #(#x23, #x23, #x3, #x1, #x2, #x3, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x42)),
270+
bv(#x23, #x23, #x3, #x1, #x2, #x3, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x42),
266271
byte-vector.packet);
267-
frames[0] := make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x6, #x7, #x8))));
272+
frames[0] := make(<frag>, data: parse-frame(<raw-frame>, bv(#x6, #x7, #x8)));
268273
byte-vector.b := frames;
269274
check-equal("label assign - 2",
270-
as(<byte-vector>, #(#x23, #x23, #x3, #x6, #x7, #x8, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x42)),
275+
bv(#x23, #x23, #x3, #x6, #x7, #x8, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x42),
271276
byte-vector.packet);
272277
let fr2 = make(<labe>, a: #x42, b: byte-vector.b, c: #x23);
273278
let bv2 = assemble-frame(fr2);
274279
check-equal("label assign - 3",
275-
as(<byte-vector>, #(#x42, #x23, #x3, #x6, #x7, #x8, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x23)),
280+
bv(#x42, #x23, #x3, #x6, #x7, #x8, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x23),
276281
bv2.packet);
277-
frames[0] := make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x10, #x11, #x12))));
282+
frames[0] := make(<frag>, data: parse-frame(<raw-frame>, bv(#x10, #x11, #x12)));
278283
bv2.b := frames;
279284
frame-field-checker(1, bv2, 8, 128, 136);
280285
check-equal("label assign - 4",
281-
as(<byte-vector>, #(#x42, #x23, #x3, #x10, #x11, #x12, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x23)),
286+
bv(#x42, #x23, #x3, #x10, #x11, #x12, #x23, #x3, #x5, #x6, #x7, #x23, #x4, #x7, #x8, #x9, #x10, #x23),
282287
bv2.packet);
283288
end;
284289

@@ -295,26 +300,26 @@ end;
295300
296301
define test label-assign2 ()
297302
let frames = as(<stretchy-vector>,
298-
list(make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x1, #x2, #x3)))),
299-
make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x4, #x5, #x6)))),
300-
make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x7, #x8, #x9, #x10))))));
303+
list(make(<frag>, data: parse-frame(<raw-frame>, bv(#x1, #x2, #x3))),
304+
make(<frag>, data: parse-frame(<raw-frame>, bv(#x4, #x5, #x6))),
305+
make(<frag>, data: parse-frame(<raw-frame>, bv(#x7, #x8, #x9, #x10)))));
301306
let frame = make(<labe>, a: #x23, b: frames, c: #x42);
302307
let byte-vector = assemble-frame(frame);
303308
let fr2 = make(<labe>, a: #x42, b: byte-vector.b, c: #x23);
304309
let bv2 = assemble-frame(fr2);
305-
frames[0] := make(<frag>, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x10, #x11))));
310+
frames[0] := make(<frag>, data: parse-frame(<raw-frame>, bv(#x10, #x11)));
306311
bv2.b := frames;
307312
frame-field-checker(1, bv2, 8, 120, 128);
308313
frame-field-checker(2, bv2, 128, 8, 136);
309314
check-equal("bv2 has correct size", 17, bv2.packet.size);
310315
check-equal("label assign2",
311-
as(<byte-vector>, #(#x42, #x23, #x2, #x10, #x11, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x23)),
316+
bv(#x42, #x23, #x2, #x10, #x11, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x23),
312317
bv2.packet);
313318
end;
314319
*/
315320

316321
define test label-assign3 ()
317-
let fr = parse-frame(<labe>, as(<byte-vector>, #(#x42, #x23, #x2, #x10, #x11, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x23, #x00, #x23)));
322+
let fr = parse-frame(<labe>, bv(#x42, #x23, #x2, #x10, #x11, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x23, #x00, #x23));
318323
frame-field-checker(0, fr, 0, 8, 8);
319324
frame-field-checker(1, fr, 8, 136, 144);
320325
frame-field-checker(2, fr, 144, 8, 152);
@@ -331,14 +336,14 @@ define test label-assign3 ()
331336
frame-field-checker(0, res, 0, 8, 8);
332337
frame-field-checker(1, res, 8, 136, 144);
333338
frame-field-checker(2, res, 144, 8, 152);
334-
let bv = assemble-frame(res);
335-
frame-field-checker(0, bv, 0, 8, 8);
336-
frame-field-checker(1, bv, 8, 136, 144);
337-
frame-field-checker(2, bv, 144, 8, 152);
338-
check-equal("size of bv is correct", 19, bv.packet.size);
339+
let bytes = assemble-frame(res);
340+
frame-field-checker(0, bytes, 0, 8, 8);
341+
frame-field-checker(1, bytes, 8, 136, 144);
342+
frame-field-checker(2, bytes, 144, 8, 152);
343+
check-equal("size of bytes is correct", 19, bytes.packet.size);
339344
check-equal("label assign3",
340-
as(<byte-vector>, #(#x42, #x23, #x2, #x10, #x11, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x23, #x00, #x23)),
341-
bv.packet);
345+
bv(#x42, #x23, #x2, #x10, #x11, #x23, #x3, #x4, #x5, #x6, #x23, #x4, #x7, #x8, #x9, #x10, #x23, #x00, #x23),
346+
bytes.packet);
342347
end;
343348

344349
define binary-data <a-super> (<container-frame>)
@@ -363,7 +368,7 @@ end;
363368
define test inheritance-assemble ()
364369
let frame = make(<a-sub>, type-code: #x42, a: #x23);
365370
let byte-vector = assemble-frame(frame);
366-
check-equal("inheritance assemble", as(<byte-vector>, #(#x42, #x23)), byte-vector.packet);
371+
check-equal("inheritance assemble", bv(#x42, #x23), byte-vector.packet);
367372
end;
368373

369374
define binary-data <b-sub> (<a-super>)
@@ -417,10 +422,10 @@ define test dynamic-length ()
417422
end;
418423

419424
define test inheritance-dynamic-length-assemble ()
420-
let frame = make(<b-sub>, type-code: #x42, data: parse-frame(<raw-frame>, as(<byte-vector>, #(#x23, #x42, #x23, #x42))));
425+
let frame = make(<b-sub>, type-code: #x42, data: parse-frame(<raw-frame>, bv(#x23, #x42, #x23, #x42)));
421426
let byte-vector = assemble-frame(frame);
422427
check-equal("Inheritance dynamic length assemble",
423-
as(<byte-vector>, #(#x42, #x4, #x23, #x42, #x23, #x42)),
428+
bv(#x42, #x4, #x23, #x42, #x23, #x42),
424429
byte-vector.packet);
425430
end;
426431

0 commit comments

Comments
 (0)