summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziyiw <ziyiw@google.com>2024-04-10 00:20:25 +0000
committerziyiw <ziyiw@google.com>2024-04-10 00:20:25 +0000
commit44d5f96a87519679348ba953747f56bf6d237d29 (patch)
treed01da275ff53f09f1e2e870c4f663298ad091d13
parent829aad9937d90ab6fc91f757207e1c6f5c3f20bc (diff)
downloaduwb-44d5f96a87519679348ba953747f56bf6d237d29.tar.gz
[unit test] Add test coverage for uwb commands.
Bug: 330169927 Test: atest libuwb_core_tests Change-Id: I07bacba1e3e5f0ca08f125efa4a480b411e8acc0
-rw-r--r--src/rust/uwb_core/src/uci/command.rs87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/rust/uwb_core/src/uci/command.rs b/src/rust/uwb_core/src/uci/command.rs
index 9f0a70e..b15d387 100644
--- a/src/rust/uwb_core/src/uci/command.rs
+++ b/src/rust/uwb_core/src/uci/command.rs
@@ -311,6 +311,7 @@ fn build_raw_uci_cmd_packet(
#[cfg(test)]
mod tests {
use super::*;
+ use uwb_uci_packets::PhaseListShortMacAddress;
#[test]
fn test_build_raw_uci_cmd() {
@@ -493,5 +494,91 @@ mod tests {
.build()
.into()
);
+
+ cmd = UciCommand::CoreQueryTimeStamp {};
+ packet = uwb_uci_packets::UciControlPacket::try_from(cmd).unwrap();
+ assert_eq!(packet, uwb_uci_packets::CoreQueryTimeStampCmdBuilder {}.build().into());
+
+ cmd = UciCommand::RawUciCmd { mt: 1, gid: 0xa, oid: 0, payload: vec![0, 1, 2, 3] };
+ packet = uwb_uci_packets::UciControlPacket::try_from(cmd).unwrap();
+ assert_eq!(
+ packet,
+ build_raw_uci_cmd_packet(1, 0xa, 0, vec![0, 1, 2, 3])
+ .expect("Failed to build raw cmd packet.")
+ );
+
+ let phase_list_short_mac_address = PhaseListShortMacAddress {
+ session_token: 0x1324_3546,
+ start_slot_index: 0x1111,
+ end_slot_index: 0x1121,
+ phase_participation: 0x0,
+ mac_address: [0x1, 0x2],
+ };
+ cmd = UciCommand::SessionSetHybridControllerConfig {
+ session_token: 1,
+ message_control: 0,
+ number_of_phases: 0,
+ update_time: UpdateTime::new(&[1; 8]).unwrap(),
+ phase_list: PhaseList::ShortMacAddress(vec![phase_list_short_mac_address]),
+ };
+ packet = uwb_uci_packets::UciControlPacket::try_from(cmd).unwrap();
+ assert_eq!(
+ packet,
+ uwb_uci_packets::SessionSetHybridControllerConfigCmdBuilder {
+ message_control: 0,
+ number_of_phases: 0,
+ session_token: 1,
+ update_time: [1; 8],
+ payload: Some(
+ vec![
+ 0x46, 0x35, 0x24, 0x13, // session id (LE)
+ 0x11, 0x11, // start slot index (LE)
+ 0x21, 0x11, // end slot index (LE)
+ 0x00, // phase_participation
+ 0x01, 0x02
+ ]
+ .into()
+ )
+ }
+ .build()
+ .into()
+ );
+
+ cmd = UciCommand::SessionSetHybridControleeConfig {
+ session_token: 1,
+ controlee_phase_list: vec![],
+ };
+ packet = uwb_uci_packets::UciControlPacket::try_from(cmd).unwrap();
+ assert_eq!(
+ packet,
+ uwb_uci_packets::SessionSetHybridControleeConfigCmdBuilder {
+ controlee_phase_list: vec![],
+ session_token: 1,
+ }
+ .build()
+ .into()
+ );
+
+ cmd = UciCommand::SessionDataTransferPhaseConfig {
+ session_token: 1,
+ dtpcm_repetition: 0,
+ data_transfer_control: 2,
+ dtpml_size: 1,
+ mac_address: vec![0, 1],
+ slot_bitmap: vec![2, 3],
+ };
+ packet = uwb_uci_packets::UciControlPacket::try_from(cmd).unwrap();
+ assert_eq!(
+ packet,
+ uwb_uci_packets::SessionDataTransferPhaseConfigCmdBuilder {
+ session_token: 1,
+ dtpcm_repetition: 0,
+ data_transfer_control: 2,
+ dtpml_size: 1,
+ payload: Some(vec![0x00, 0x01, 0x02, 0x03].into()),
+ }
+ .build()
+ .into()
+ );
}
}