diff options
author | ziyiw <ziyiw@google.com> | 2024-04-15 22:22:45 +0000 |
---|---|---|
committer | ziyiw <ziyiw@google.com> | 2024-04-15 22:22:45 +0000 |
commit | fff148421a771915a6027a1422d40906b7e282b5 (patch) | |
tree | 62821544dfffe325b62181a4dd5a68f176acd973 | |
parent | 1bc7ee02c3e472fc526da3813aa86e6f30b01ae4 (diff) | |
download | uwb-fff148421a771915a6027a1422d40906b7e282b5.tar.gz |
[unit_test] Add more tests for uci_logger and notification.
Test: libuwb_core_tests
Bug: 330169927
Change-Id: Idb179979e6d8be5d6ae64c11341ecfcb96ec2d45
-rw-r--r-- | src/rust/uwb_core/src/uci/notification.rs | 124 | ||||
-rw-r--r-- | src/rust/uwb_core/src/uci/uci_logger.rs | 20 |
2 files changed, 142 insertions, 2 deletions
diff --git a/src/rust/uwb_core/src/uci/notification.rs b/src/rust/uwb_core/src/uci/notification.rs index e782959..41c4002 100644 --- a/src/rust/uwb_core/src/uci/notification.rs +++ b/src/rust/uwb_core/src/uci/notification.rs @@ -1045,6 +1045,66 @@ mod tests { } #[test] + fn test_cast_failed_from_session_update_controller_multicast_list_ntf_v1_packet_v2_payload() { + let controlee_status_v2 = uwb_uci_packets::ControleeStatusV2 { + mac_address: [0x0c, 0xa8], + status: uwb_uci_packets::MulticastUpdateStatusCode::StatusOkMulticastListUpdate, + }; + let another_controlee_status_v2 = uwb_uci_packets::ControleeStatusV2 { + mac_address: [0x0c, 0xa9], + status: uwb_uci_packets::MulticastUpdateStatusCode::StatusErrorKeyFetchFail, + }; + let payload = uwb_uci_packets::SessionUpdateControllerMulticastListNtfV2Payload { + controlee_status: vec![controlee_status_v2, another_controlee_status_v2], + }; + let mut buf = BytesMut::new(); + write_multicast_ntf_v2_payload(&payload, &mut buf); + let session_update_controller_multicast_list_ntf_v1 = + uwb_uci_packets::SessionUpdateControllerMulticastListNtfBuilder { + session_token: 0x32, + payload: Some(buf.freeze()), + } + .build(); + let session_notification_packet = uwb_uci_packets::SessionConfigNotification::try_from( + session_update_controller_multicast_list_ntf_v1, + ) + .unwrap(); + let uci_fira_major_version = UCIMajorVersion::V1; + let session_notification = + SessionNotification::try_from((session_notification_packet, uci_fira_major_version)); + assert_eq!(session_notification, Err(Error::BadParameters)); + } + + #[test] + fn test_cast_failed_from_session_update_controller_multicast_list_ntf_v2_packet_v1_payload() { + let controlee_status_v1 = uwb_uci_packets::ControleeStatusV1 { + mac_address: [0x0c, 0xa8], + subsession_id: 0x30, + status: uwb_uci_packets::MulticastUpdateStatusCode::StatusOkMulticastListUpdate, + }; + let payload = uwb_uci_packets::SessionUpdateControllerMulticastListNtfV1Payload { + remaining_multicast_list_size: 0x4, + controlee_status: vec![controlee_status_v1], + }; + let mut buf = BytesMut::new(); + write_multicast_ntf_v1_payload(&payload, &mut buf); + let session_update_controller_multicast_list_ntf_v1 = + uwb_uci_packets::SessionUpdateControllerMulticastListNtfBuilder { + session_token: 0x32, + payload: Some(buf.freeze()), + } + .build(); + let session_notification_packet = uwb_uci_packets::SessionConfigNotification::try_from( + session_update_controller_multicast_list_ntf_v1, + ) + .unwrap(); + let uci_fira_major_version = UCIMajorVersion::V2; + let session_notification = + SessionNotification::try_from((session_notification_packet, uci_fira_major_version)); + assert_eq!(session_notification, Err(Error::BadParameters)); + } + + #[test] fn test_session_notification_casting_from_session_update_controller_multicast_list_ntf_v2_packet( ) { let controlee_status_v2 = uwb_uci_packets::ControleeStatusV2 { @@ -1238,14 +1298,50 @@ mod tests { } .build() .into(); + let vendor_B_nonempty_notification: uwb_uci_packets::UciNotification = + uwb_uci_packets::UciVendor_B_NotificationBuilder { + opcode: 0x41, + payload: Some(bytes::Bytes::from_static(b"Placeholder notification.")), + } + .build() + .into(); + let vendor_E_nonempty_notification: uwb_uci_packets::UciNotification = + uwb_uci_packets::UciVendor_E_NotificationBuilder { + opcode: 0x41, + payload: Some(bytes::Bytes::from_static(b"Placeholder notification.")), + } + .build() + .into(); + let vendor_F_nonempty_notification: uwb_uci_packets::UciNotification = + uwb_uci_packets::UciVendor_F_NotificationBuilder { + opcode: 0x41, + payload: Some(bytes::Bytes::from_static(b"Placeholder notification.")), + } + .build() + .into(); let uci_fira_major_version = UCIMajorVersion::V1; let uci_notification_from_vendor_9 = UciNotification::try_from(( vendor_9_empty_notification, uci_fira_major_version.clone(), )) .unwrap(); - let uci_notification_from_vendor_A = - UciNotification::try_from((vendor_A_nonempty_notification, uci_fira_major_version)) + let uci_notification_from_vendor_A = UciNotification::try_from(( + vendor_A_nonempty_notification, + uci_fira_major_version.clone(), + )) + .unwrap(); + let uci_notification_from_vendor_B = UciNotification::try_from(( + vendor_B_nonempty_notification, + uci_fira_major_version.clone(), + )) + .unwrap(); + let uci_notification_from_vendor_E = UciNotification::try_from(( + vendor_E_nonempty_notification, + uci_fira_major_version.clone(), + )) + .unwrap(); + let uci_notification_from_vendor_F = + UciNotification::try_from((vendor_F_nonempty_notification, uci_fira_major_version)) .unwrap(); assert_eq!( uci_notification_from_vendor_9, @@ -1263,6 +1359,30 @@ mod tests { payload: b"Placeholder notification.".to_owned().into(), }) ); + assert_eq!( + uci_notification_from_vendor_B, + UciNotification::Vendor(RawUciMessage { + gid: 0xb, + oid: 0x41, + payload: b"Placeholder notification.".to_owned().into(), + }) + ); + assert_eq!( + uci_notification_from_vendor_E, + UciNotification::Vendor(RawUciMessage { + gid: 0xe, + oid: 0x41, + payload: b"Placeholder notification.".to_owned().into(), + }) + ); + assert_eq!( + uci_notification_from_vendor_F, + UciNotification::Vendor(RawUciMessage { + gid: 0xf, + oid: 0x41, + payload: b"Placeholder notification.".to_owned().into(), + }) + ); } #[test] diff --git a/src/rust/uwb_core/src/uci/uci_logger.rs b/src/rust/uwb_core/src/uci/uci_logger.rs index d1e8db5..381351c 100644 --- a/src/rust/uwb_core/src/uci/uci_logger.rs +++ b/src/rust/uwb_core/src/uci/uci_logger.rs @@ -213,6 +213,7 @@ mod tests { use crate::params::uci_packets::StatusCode; use crate::uci::mock_uci_logger::{MockUciLogger, UciLogEvent}; + use uwb_uci_packets::{DataPacketFormat, MessageType, UciDataPacketBuilder}; #[test] fn test_log_command_filter() -> Result<()> { @@ -265,4 +266,23 @@ mod tests { ); Ok(()) } + + #[test] + fn test_log_data_filter() -> Result<()> { + let unfiltered_data_packet: UciDataPacket = UciDataPacketBuilder { + data_packet_format: DataPacketFormat::DataSnd, + message_type: MessageType::Data, + payload: Some(vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8].into()), + } + .build(); + let (log_sender, mut log_receiver) = mpsc::unbounded_channel::<UciLogEvent>(); + let mut logger = + UciLoggerWrapper::new(MockUciLogger::new(log_sender), UciLoggerMode::Filtered); + logger.log_uci_data(&unfiltered_data_packet); + assert_eq!( + TryInto::<Vec<u8>>::try_into(log_receiver.blocking_recv().unwrap())?, + vec!(0x1, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) + ); + Ok(()) + } } |