rust/bitbox02: unit test strlen_ptr
@@ -104,6 +104,14 @@ mod tests {
assert_eq!(truncate_str("test", 6), "test");
}
+ #[test]
+ fn test_strlen_ptr() {
+ assert_eq!(unsafe { strlen_ptr(b"\0".as_ptr()) }, 0);
+ assert_eq!(unsafe { strlen_ptr(b"a\0".as_ptr()) }, 1);
+ assert_eq!(unsafe { strlen_ptr(b"abcdef\0".as_ptr()) }, 6);
+ assert_eq!(unsafe { strlen_ptr(b"abcdef\0defghji".as_ptr()) }, 6);
+ }
+
#[test]
fn test_str_from_null_terminated() {
assert_eq!(str_from_null_terminated(b"\0"), Ok(""));
