From b1fa76f560100a228e5574d40e3d857c7c302a02 Mon Sep 17 00:00:00 2001 From: Lucas Silva Shepard Date: Mon, 14 Aug 2023 16:29:02 -0700 Subject: [PATCH] [fp-rs] Wrote unit tests for Fast Pair Decoder in Rust. --- fastpair/rust/demo/rust/src/decoder.rs | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fastpair/rust/demo/rust/src/decoder.rs b/fastpair/rust/demo/rust/src/decoder.rs index dd0f80d4..4865a35b 100644 --- a/fastpair/rust/demo/rust/src/decoder.rs +++ b/fastpair/rust/demo/rust/src/decoder.rs @@ -47,3 +47,38 @@ impl FpDecoder { } } } + +mod tests { + use super::*; + + #[test] + fn test_get_model_id_valid() { + // Valid scenario: Length == 3 + let uuid: u16 = 0x1234; + let data = vec![0xAA, 0xBB, 0xCC]; + let service_data = ServiceData::new(uuid, data.clone()); + let result = FpDecoder::get_model_id_from_service_data(&service_data); + assert!(result.is_ok()); + assert_eq!(result.unwrap(), data); + } + + #[test] + fn test_get_model_id_invalid() { + // Invalid scenario: Length < 3 + let uuid: u16 = 0x1234; + let data = vec![0xAA, 0xBB]; + let service_data = ServiceData::new(uuid, data); + let result = FpDecoder::get_model_id_from_service_data(&service_data); + assert!(result.is_err()); + } + + #[test] + fn test_get_model_id_unsupported() { + // Unsupported scenario: Length > 3 + let uuid: u16 = 0x1234; + let data = vec![0xAA, 0xBB, 0xCC, 0xDD]; + let service_data = ServiceData::new(uuid, data); + let result = FpDecoder::get_model_id_from_service_data(&service_data); + assert!(result.is_err()); + } +}