mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
test: move stress tests to dc_strencode and dc_tools
This commit is contained in:
@@ -898,4 +898,62 @@ mod tests {
|
||||
unsafe { print_hex(hex.as_mut_ptr(), cur) };
|
||||
assert_eq!(to_string(hex.as_ptr() as *const _), "=3A");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_urlencode_urldecode() {
|
||||
unsafe {
|
||||
let buf1 =
|
||||
dc_urlencode(b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char);
|
||||
|
||||
assert_eq!(
|
||||
CStr::from_ptr(buf1 as *const libc::c_char)
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Bj%C3%B6rn+Petersen"
|
||||
);
|
||||
|
||||
let buf2 = dc_urldecode(buf1);
|
||||
|
||||
assert_eq!(
|
||||
strcmp(
|
||||
buf2,
|
||||
b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
free(buf1 as *mut libc::c_void);
|
||||
free(buf2 as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_encode_decode_modified_utf7() {
|
||||
unsafe {
|
||||
let buf1 = dc_encode_modified_utf7(
|
||||
b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char,
|
||||
1,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
CStr::from_ptr(buf1 as *const libc::c_char)
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"Bj&APY-rn_Petersen"
|
||||
);
|
||||
|
||||
let buf2 = dc_decode_modified_utf7(buf1, 1);
|
||||
|
||||
assert_eq!(
|
||||
strcmp(
|
||||
buf2,
|
||||
b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
free(buf1 as *mut libc::c_void);
|
||||
free(buf2 as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1816,4 +1816,70 @@ mod tests {
|
||||
|
||||
unsafe { free(raw as *mut _) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_replace_bad_utf8_chars_1() {
|
||||
unsafe {
|
||||
let buf1 = strdup(b"ol\xc3\xa1 mundo <>\"\'& \xc3\xa4\xc3\x84\xc3\xb6\xc3\x96\xc3\xbc\xc3\x9c\xc3\x9f foo\xc3\x86\xc3\xa7\xc3\x87 \xe2\x99\xa6&noent;\x00" as *const u8 as *const libc::c_char);
|
||||
let buf2 = strdup(buf1);
|
||||
|
||||
dc_replace_bad_utf8_chars(buf2);
|
||||
|
||||
assert_eq!(strcmp(buf1, buf2), 0);
|
||||
|
||||
free(buf1 as *mut libc::c_void);
|
||||
free(buf2 as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_replace_bad_utf8_chars_2() {
|
||||
unsafe {
|
||||
let buf1 = strdup(b"ISO-String with Ae: \xc4\x00" as *const u8 as *const libc::c_char);
|
||||
let buf2 = strdup(buf1);
|
||||
|
||||
dc_replace_bad_utf8_chars(buf2);
|
||||
|
||||
assert_eq!(
|
||||
CStr::from_ptr(buf2 as *const libc::c_char)
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
"ISO-String with Ae: _"
|
||||
);
|
||||
|
||||
free(buf1 as *mut libc::c_void);
|
||||
free(buf2 as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_replace_bad_utf8_chars_3() {
|
||||
unsafe {
|
||||
let buf1 = strdup(b"\x00" as *const u8 as *const libc::c_char);
|
||||
let buf2 = strdup(buf1);
|
||||
|
||||
dc_replace_bad_utf8_chars(buf2);
|
||||
|
||||
assert_eq!(*buf2.offset(0), 0);
|
||||
|
||||
free(buf1 as *mut libc::c_void);
|
||||
free(buf2 as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_replace_bad_utf8_chars_4() {
|
||||
unsafe {
|
||||
dc_replace_bad_utf8_chars(0 as *mut libc::c_char);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_create_id() {
|
||||
unsafe {
|
||||
let buf = dc_create_id();
|
||||
assert_eq!(strlen(buf), 11);
|
||||
free(buf as *mut libc::c_void);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user