diff --git a/src/rust/lib_ccxr/src/util/mod.rs b/src/rust/lib_ccxr/src/util/mod.rs index ff414cb78..fa0fbbe64 100644 --- a/src/rust/lib_ccxr/src/util/mod.rs +++ b/src/rust/lib_ccxr/src/util/mod.rs @@ -17,3 +17,20 @@ pub fn write_string_into_pointer(buffer: *mut c_char, string: &str) { buffer[..string.len()].copy_from_slice(string.as_bytes()); buffer[string.len()] = b'\0'; } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_write_string_into_pointer() { + let test_string = "CCExtractor is the best"; + let mut buffer = vec![0u8; test_string.len() + 1]; + let buffer_ptr = buffer.as_mut_ptr() as *mut c_char; + + write_string_into_pointer(buffer_ptr, test_string); + + assert_eq!(&buffer[..test_string.len()], test_string.as_bytes()); + assert_eq!(buffer[test_string.len()], 0); // Check null terminator + } +}