Skip to content

Commit f23a055

Browse files
committed
fn ZDICT_getDictID: test
1 parent bb25af3 commit f23a055

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/dictBuilder/zdict.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,10 +1640,38 @@ mod test {
16401640

16411641
#[test]
16421642
fn test_get_dict_header_size() {
1643+
let empty: &[u8] = &[];
1644+
let code = unsafe { ZDICT_getDictHeaderSize(empty.as_ptr().cast(), empty.len()) };
1645+
assert_eq!(
1646+
Error::from_error_code(code),
1647+
Some(Error::dictionary_corrupted)
1648+
);
1649+
1650+
let no_magic: &[u8] = &[0; 8];
1651+
let code = unsafe { ZDICT_getDictHeaderSize(no_magic.as_ptr().cast(), no_magic.len()) };
1652+
assert_eq!(
1653+
Error::from_error_code(code),
1654+
Some(Error::dictionary_corrupted)
1655+
);
1656+
16431657
let code = unsafe { ZDICT_getDictHeaderSize(DICT.as_ptr().cast(), DICT.len()) };
16441658
match Error::from_error_code(code) {
16451659
Some(err) => panic!("{:?}", err),
16461660
None => assert_eq!(code, 133),
16471661
}
16481662
}
1663+
1664+
#[test]
1665+
fn test_get_dict_id() {
1666+
let empty: &[u8] = &[];
1667+
let code = unsafe { ZDICT_getDictID(empty.as_ptr().cast(), empty.len()) };
1668+
assert_eq!(code, 0);
1669+
1670+
let no_magic: &[u8] = &[0; 8];
1671+
let code = unsafe { ZDICT_getDictID(no_magic.as_ptr().cast(), no_magic.len()) };
1672+
assert_eq!(code, 0);
1673+
1674+
let code = unsafe { ZDICT_getDictID(DICT.as_ptr().cast(), DICT.len()) };
1675+
assert_eq!(code, 1877512422);
1676+
}
16491677
}

0 commit comments

Comments
 (0)