forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_boolean.rs
82 lines (72 loc) · 1.62 KB
/
default_boolean.rs
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
mod test_utils;
use test_utils::*;
asn_to_rust!(
r#"DefaultString DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
theValue BOOLEAN ::= FALSE
MyCleverSeq ::= SEQUENCE {
secret-flag BOOLEAN DEFAULT TRUE,
flag-secret BOOLEAN DEFAULT theValue
}
END"#
);
#[test]
pub fn does_it_compile() {
let seq = MyCleverSeq {
secret_flag: true,
flag_secret: true,
};
let mut writer = PrintlnWriter::default();
writer.write(&seq).unwrap();
// Writing sequence MyCleverSeq, tag=Universal(16)
// Writing DEFAULT (default: true)
// None
// Writing DEFAULT (default: false)
// Some
// WRITING Boolean, tag=Universal(1)
// true
}
#[test]
pub fn test_seq_with_non_default_value_00() {
serialize_and_deserialize_uper(
8 * 0 + 3,
&[0x80],
&MyCleverSeq {
secret_flag: false,
flag_secret: false,
},
);
}
#[test]
pub fn test_seq_with_non_default_value_01() {
serialize_and_deserialize_uper(
8 * 0 + 4,
&[0xD0],
&MyCleverSeq {
secret_flag: false,
flag_secret: true,
},
);
}
#[test]
pub fn test_seq_with_default_value_10() {
serialize_and_deserialize_uper(
8 * 0 + 2,
&[0x00],
&MyCleverSeq {
secret_flag: true,
flag_secret: false,
},
);
}
#[test]
pub fn test_seq_with_non_default_value_11() {
serialize_and_deserialize_uper(
8 * 0 + 3,
&[0x60],
&MyCleverSeq {
secret_flag: true,
flag_secret: true,
},
);
}