diff --git a/.github/workflows/build_ubuntu.yml b/.github/workflows/build_ubuntu.yml index 97fecba..aaf8ef3 100644 --- a/.github/workflows/build_ubuntu.yml +++ b/.github/workflows/build_ubuntu.yml @@ -27,6 +27,7 @@ jobs: sudo apt-get install -y libdbus-1-dev - run: | cd ./core_lib + cargo test cargo build build-tauri: diff --git a/core_lib/Cargo.lock b/core_lib/Cargo.lock index c031805..bf1a8fb 100644 --- a/core_lib/Cargo.lock +++ b/core_lib/Cargo.lock @@ -1661,7 +1661,7 @@ dependencies = [ [[package]] name = "rqs_lib" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "base64", diff --git a/core_lib/src/utils.rs b/core_lib/src/utils.rs index e86d2c6..36c2d16 100644 --- a/core_lib/src/utils.rs +++ b/core_lib/src/utils.rs @@ -16,7 +16,7 @@ use tokio::io::AsyncReadExt; use tokio::net::TcpStream; use ts_rs::TS; -#[derive(Debug, Clone, Deserialize, Serialize, TS)] +#[derive(Debug, Clone, Deserialize, PartialEq, Serialize, TS)] #[ts(export)] #[allow(dead_code)] pub enum DeviceType { @@ -107,8 +107,7 @@ pub fn parse_mdns_endpoint_info(encoded_str: &str) -> Result<(DeviceType, String return Err(anyhow!("Invalid data length")); } - let device_type_byte = decoded_bytes[0]; - let device_type = (device_type_byte & 0b0111) >> 4; + let device_type = (decoded_bytes[0] >> 1) & 0x7; let name_length = decoded_bytes[17] as usize; if 18 + name_length > decoded_bytes.len() { return Err(anyhow!("Invalid name length")); @@ -165,9 +164,7 @@ pub fn to_four_digit_string(bytes: &Vec) -> String { let mut hash = 0; let mut multiplier = 1; for &byte in bytes { - // Cast u8 to i8 (assuming that's what's intended by static_cast(byte)) - // Rust by default treats i8 as signed, matching the C++ behavior here - let byte = byte as i8 as i32; // `as i32` to perform calculation correctly + let byte = byte as i8 as i32; hash = (hash + byte * multiplier) % k_hash_modulo; multiplier = (multiplier * k_hash_base_multiplier) % k_hash_modulo; } @@ -205,3 +202,23 @@ pub fn is_not_self_ip(ip_address: &Ipv4Addr) -> bool { true } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_gen_and_parse_mdns_info() { + let device_name = "a_device_name"; + let device_type = DeviceType::Laptop; + + dbg!(&device_type); + dbg!(device_type.clone() as u8); + + let info = gen_mdns_endpoint_info(device_type.clone() as u8, device_name); + let parse_info = parse_mdns_endpoint_info(&info).unwrap(); + + assert_eq!(parse_info.1, device_name); + assert_eq!(parse_info.0, device_type); + } +} diff --git a/frontend/src-tauri/Cargo.lock b/frontend/src-tauri/Cargo.lock index 3952d0a..adc6b14 100644 --- a/frontend/src-tauri/Cargo.lock +++ b/frontend/src-tauri/Cargo.lock @@ -3923,7 +3923,7 @@ dependencies = [ [[package]] name = "rqs_lib" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "base64", @@ -3959,7 +3959,7 @@ dependencies = [ [[package]] name = "rquickshare" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "log",