Skip to content

Commit 93e09cc

Browse files
KiOuigabhijit
authored andcommitted
Add test for decoding of optional extensions including open enumeration type
Signed-off-by: Lars van Rhijn <[email protected]>
1 parent 7db42d6 commit 93e09cc

File tree

1 file changed

+76
-8
lines changed

1 file changed

+76
-8
lines changed

codecs_derive/tests/09-open.rs

+76-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use asn1_codecs_derive::{AperCodec, UperCodec};
44

5-
#[derive(Debug, AperCodec, UperCodec)]
5+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
66
#[asn(type = "INTEGER", lb = "0", ub = "65535")]
77
pub struct ProtocolIE_ID(u16);
88

9-
#[derive(Debug, AperCodec, UperCodec)]
9+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
1010
#[asn(type = "ENUMERATED", lb = "0", ub = "2")]
1111
pub struct Criticality(u8);
1212
impl Criticality {
@@ -15,23 +15,31 @@ impl Criticality {
1515
const NOTIFY: u8 = 2u8;
1616
}
1717

18-
#[derive(Debug, AperCodec, UperCodec)]
18+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
1919
#[asn(type = "INTEGER", lb = "0", ub = "255")]
2020
pub struct Routing_ID(u8);
2121

22-
#[derive(Debug, AperCodec, UperCodec)]
22+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
2323
#[asn(type = "INTEGER", lb = "0", ub = "4294967295")]
2424
pub struct MME_UE_S1AP_ID(u32);
2525

26-
#[derive(Debug, AperCodec, UperCodec)]
26+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
2727
#[asn(type = "OCTET-STRING")]
2828
pub struct LPPa_PDU(Vec<u8>);
2929

30-
#[derive(Debug, AperCodec, UperCodec)]
30+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
3131
#[asn(type = "INTEGER", lb = "0", ub = "16777215")]
3232
pub struct ENB_UE_S1AP_ID(u32);
3333

34-
#[derive(Debug, AperCodec, UperCodec)]
34+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
35+
#[asn(type = "ENUMERATED", extensible = true, lb = "0", ub = "1")]
36+
pub struct GUAMIType(pub u8);
37+
impl GUAMIType {
38+
pub const NATIVE: u8 = 0u8;
39+
pub const MAPPED: u8 = 1u8;
40+
}
41+
42+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
3543
#[asn(type = "OPEN")]
3644
pub enum UplinkUEAssociatedLPPaTransportprotocolIEsItemvalue {
3745
#[asn(key = 8)]
@@ -42,9 +50,11 @@ pub enum UplinkUEAssociatedLPPaTransportprotocolIEsItemvalue {
4250
MME_UE_S1AP_ID(MME_UE_S1AP_ID),
4351
#[asn(key = 148)]
4452
Routing_ID(Routing_ID),
53+
#[asn(key = 176)]
54+
Id_GUAMIType(GUAMIType),
4555
}
4656

47-
#[derive(Debug, AperCodec, UperCodec)]
57+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
4858
#[asn(type = "SEQUENCE", extensible = false)]
4959
pub struct UplinkUEAssociatedLPPaTransportprotocolIEsItem {
5060
#[asn(key_field = true)]
@@ -53,6 +63,64 @@ pub struct UplinkUEAssociatedLPPaTransportprotocolIEsItem {
5363
pub value: UplinkUEAssociatedLPPaTransportprotocolIEsItemvalue,
5464
}
5565

66+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
67+
#[asn(
68+
type = "SEQUENCE-OF",
69+
sz_extensible = false,
70+
sz_lb = "1",
71+
sz_ub = "256"
72+
)]
73+
pub struct UplinkUEAssociatedLPPaTransportprotocolList(pub Vec<UplinkUEAssociatedLPPaTransportprotocolItem>);
74+
75+
#[derive(Debug, AperCodec, UperCodec, Eq, PartialEq)]
76+
#[asn(type = "SEQUENCE", extensible = true, optional_fields = 1)]
77+
pub struct UplinkUEAssociatedLPPaTransportprotocolItem {
78+
#[asn(optional_idx = 0)]
79+
pub ie_extensions: Option<UplinkUEAssociatedLPPaTransportprotocolIEsItem>,
80+
}
81+
5682
fn main() {
5783
eprintln!("Open");
5884
}
85+
86+
#[cfg(test)]
87+
mod tests {
88+
use asn1_codecs::aper::AperCodec;
89+
use asn1_codecs::PerCodecData;
90+
use super::*;
91+
92+
/// Test whether encoding and then decoding a list of optional extensions that include an open
93+
/// enumeration type results in the same object.
94+
///
95+
/// This function was added because of a bug that appeared in
96+
/// #[126](https://github.com/ystero-dev/hampi/issues/126).
97+
#[test]
98+
fn test_encode_decode_open_type() {
99+
let original_test_value = UplinkUEAssociatedLPPaTransportprotocolList(vec![UplinkUEAssociatedLPPaTransportprotocolItem {
100+
ie_extensions: Some(
101+
UplinkUEAssociatedLPPaTransportprotocolIEsItem {
102+
id: ProtocolIE_ID(176),
103+
criticality: Criticality(0),
104+
value: UplinkUEAssociatedLPPaTransportprotocolIEsItemvalue::Id_GUAMIType(
105+
GUAMIType(0)
106+
),
107+
}
108+
),
109+
}, UplinkUEAssociatedLPPaTransportprotocolItem {
110+
ie_extensions: Some(
111+
UplinkUEAssociatedLPPaTransportprotocolIEsItem {
112+
id: ProtocolIE_ID(176),
113+
criticality: Criticality(0),
114+
value: UplinkUEAssociatedLPPaTransportprotocolIEsItemvalue::Id_GUAMIType(
115+
GUAMIType(0)
116+
),
117+
}
118+
),
119+
}]);
120+
let mut test_value_encoded = PerCodecData::new_aper();
121+
original_test_value.aper_encode(&mut test_value_encoded).unwrap();
122+
123+
let test_value_decoded = UplinkUEAssociatedLPPaTransportprotocolList::aper_decode(&mut test_value_encoded).unwrap();
124+
assert_eq!(original_test_value, test_value_decoded);
125+
}
126+
}

0 commit comments

Comments
 (0)