1 #[cfg(test)] 2 mod tests { 3 use bt_topshim::btif::RawAddress; 4 5 #[test] from_string_invalid()6 fn from_string_invalid() { 7 assert!(RawAddress::from_string("").is_none()); 8 assert!(RawAddress::from_string("some invalid string").is_none()); 9 assert!(RawAddress::from_string("aa:bb:cc:dd:ee:ff:00").is_none()); 10 assert!(RawAddress::from_string("aa:bb:cc:dd:ee").is_none()); 11 assert!(RawAddress::from_string("aa:bb:cc:dd::ff").is_none()); 12 } 13 14 #[test] from_string_valid()15 fn from_string_valid() { 16 let addr = RawAddress::from_string("11:22:33:aa:bb:cc"); 17 assert!(addr.is_some()); 18 assert_eq!([0x11, 0x22, 0x33, 0xaa, 0xbb, 0xcc], addr.unwrap().to_byte_arr()); 19 20 // Upper/lower case should not matter. 21 let addr = RawAddress::from_string("11:22:33:AA:BB:CC"); 22 assert!(addr.is_some()); 23 assert_eq!([0x11, 0x22, 0x33, 0xaa, 0xbb, 0xcc], addr.unwrap().to_byte_arr()); 24 } 25 26 #[test] from_bytes_invalid()27 fn from_bytes_invalid() { 28 assert!(RawAddress::from_bytes(&vec![]).is_none()); 29 assert!(RawAddress::from_bytes(&vec![1, 2, 3, 4, 5]).is_none()); 30 assert!(RawAddress::from_bytes(&vec![1, 2, 3, 4, 5, 6, 7]).is_none()); 31 } 32 33 #[test] from_bytes_valid()34 fn from_bytes_valid() { 35 let addr = RawAddress::from_bytes(&vec![1, 2, 3, 4, 5, 6]); 36 assert!(addr.is_some()); 37 assert_eq!([1, 2, 3, 4, 5, 6], addr.unwrap().to_byte_arr()); 38 } 39 } 40