Skip to content

Commit

Permalink
feat: Add test lib_ccxr/util/mod.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
IshanGrover2004 committed Jul 17, 2024
1 parent 17355f2 commit 90def7e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/rust/lib_ccxr/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 90def7e

Please sign in to comment.