Skip to content

Commit e8658cc

Browse files
authored
Bring over tests from encoded_length PR (#548)
1 parent c453b96 commit e8658cc

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/derive_test.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,64 @@ fn test_default_bool() {
328328
]);
329329
}
330330

331+
#[test]
332+
fn test_struct_field_types() {
333+
// This test covers encoding a variety of different field types. Mostly to
334+
// cover their encoded_length implementations.
335+
336+
#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Debug, Eq)]
337+
struct TlvField<'a> {
338+
t: asn1::Tlv<'a>,
339+
}
340+
assert_roundtrips(&[
341+
(
342+
Ok(TlvField {
343+
t: asn1::parse_single(b"\x05\x00").unwrap(),
344+
}),
345+
b"\x30\x02\x05\x00",
346+
),
347+
(
348+
Ok(TlvField {
349+
t: asn1::parse_single(b"\x1f\x81\x80\x01\x00").unwrap(),
350+
}),
351+
b"\x30\x05\x1f\x81\x80\x01\x00",
352+
),
353+
]);
354+
355+
#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Debug, Eq)]
356+
struct ChoiceFields<'a> {
357+
c1: asn1::Choice1<&'a [u8]>,
358+
c2: asn1::Choice2<bool, u64>,
359+
}
360+
assert_roundtrips(&[
361+
(
362+
Ok(ChoiceFields {
363+
c1: asn1::Choice1::ChoiceA(b""),
364+
c2: asn1::Choice2::ChoiceA(true),
365+
}),
366+
b"\x30\x05\x04\x00\x01\x01\xff",
367+
),
368+
(
369+
Ok(ChoiceFields {
370+
c1: asn1::Choice1::ChoiceA(b""),
371+
c2: asn1::Choice2::ChoiceB(12),
372+
}),
373+
b"\x30\x05\x04\x00\x02\x01\x0c",
374+
),
375+
]);
376+
377+
#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Debug, Eq)]
378+
struct LongField<'a> {
379+
f: &'a [u8],
380+
}
381+
assert_roundtrips(&[
382+
(
383+
Ok(LongField{f: b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}),
384+
b"\x30\x81\x84\x04\x81\x81aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
385+
)
386+
]);
387+
}
388+
331389
#[test]
332390
fn test_enum() {
333391
#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Debug, Eq)]

0 commit comments

Comments
 (0)