diff options
author | ziyiw <ziyiw@google.com> | 2024-04-11 22:23:32 +0000 |
---|---|---|
committer | ziyiw <ziyiw@google.com> | 2024-04-11 22:23:32 +0000 |
commit | 01a139338889a8ca62750c3472d5bb0c20d848ec (patch) | |
tree | 229b5215ac49a1731c73aedc343ae34dcb036ea7 | |
parent | 30e37396e2e82c6915e94af01db2a07d011c68fa (diff) | |
download | uwb-01a139338889a8ca62750c3472d5bb0c20d848ec.tar.gz |
[unit_test] Add unit tests for uci vendor response.
Test: atest libuwb_core_tests
Bug: 330169927
Change-Id: I4b491cf99a27bbf455dd4585484faff46eb5c81d
-rw-r--r-- | src/rust/uwb_core/src/uci/response.rs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/rust/uwb_core/src/uci/response.rs b/src/rust/uwb_core/src/uci/response.rs index 48313aa..8f5925e 100644 --- a/src/rust/uwb_core/src/uci/response.rs +++ b/src/rust/uwb_core/src/uci/response.rs @@ -296,3 +296,101 @@ fn raw_response(evt: uwb_uci_packets::UciResponse) -> Result<UciResponse> { let packet: UciControlPacket = evt.into(); Ok(UciResponse::RawUciCmd(Ok(RawUciMessage { gid, oid, payload: packet.to_raw_payload() }))) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_uci_response_casting_from_uci_vendor_response_packet() { + let mut uci_vendor_rsp_packet = uwb_uci_packets::UciResponse::try_from( + uwb_uci_packets::UciVendor_9_ResponseBuilder { + opcode: 0x00, + payload: Some(vec![0x0, 0x1, 0x2, 0x3].into()), + } + .build(), + ) + .unwrap(); + let mut uci_response = UciResponse::try_from(uci_vendor_rsp_packet.clone()).unwrap(); + assert_eq!( + uci_response, + UciResponse::RawUciCmd(Ok(RawUciMessage { + gid: 0x9, + oid: 0x0, + payload: vec![0x0, 0x1, 0x2, 0x3], + })) + ); + + uci_vendor_rsp_packet = uwb_uci_packets::UciResponse::try_from( + uwb_uci_packets::UciVendor_A_ResponseBuilder { + opcode: 0x00, + payload: Some(vec![0x0, 0x1, 0x2, 0x3].into()), + } + .build(), + ) + .unwrap(); + uci_response = UciResponse::try_from(uci_vendor_rsp_packet.clone()).unwrap(); + assert_eq!( + uci_response, + UciResponse::RawUciCmd(Ok(RawUciMessage { + gid: 0xA, + oid: 0x0, + payload: vec![0x0, 0x1, 0x2, 0x3], + })) + ); + + uci_vendor_rsp_packet = uwb_uci_packets::UciResponse::try_from( + uwb_uci_packets::UciVendor_B_ResponseBuilder { + opcode: 0x00, + payload: Some(vec![0x0, 0x1, 0x2, 0x3].into()), + } + .build(), + ) + .unwrap(); + uci_response = UciResponse::try_from(uci_vendor_rsp_packet.clone()).unwrap(); + assert_eq!( + uci_response, + UciResponse::RawUciCmd(Ok(RawUciMessage { + gid: 0xB, + oid: 0x0, + payload: vec![0x0, 0x1, 0x2, 0x3], + })) + ); + + uci_vendor_rsp_packet = uwb_uci_packets::UciResponse::try_from( + uwb_uci_packets::UciVendor_E_ResponseBuilder { + opcode: 0x00, + payload: Some(vec![0x0, 0x1, 0x2, 0x3].into()), + } + .build(), + ) + .unwrap(); + uci_response = UciResponse::try_from(uci_vendor_rsp_packet.clone()).unwrap(); + assert_eq!( + uci_response, + UciResponse::RawUciCmd(Ok(RawUciMessage { + gid: 0xE, + oid: 0x0, + payload: vec![0x0, 0x1, 0x2, 0x3], + })) + ); + + uci_vendor_rsp_packet = uwb_uci_packets::UciResponse::try_from( + uwb_uci_packets::UciVendor_F_ResponseBuilder { + opcode: 0x00, + payload: Some(vec![0x0, 0x1, 0x2, 0x3].into()), + } + .build(), + ) + .unwrap(); + uci_response = UciResponse::try_from(uci_vendor_rsp_packet.clone()).unwrap(); + assert_eq!( + uci_response, + UciResponse::RawUciCmd(Ok(RawUciMessage { + gid: 0xF, + oid: 0x0, + payload: vec![0x0, 0x1, 0x2, 0x3], + })) + ); + } +} |