diff --git a/src/dc_msg.rs b/src/dc_msg.rs index 6e03e9b88..cf07ba795 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -1616,3 +1616,36 @@ pub unsafe fn dc_update_server_uid( sqlite3_step(stmt); sqlite3_finalize(stmt); } + +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::CStr; + + #[test] + fn test_dc_msg_guess_msgtype_from_suffix() { + unsafe { + let mut type_0: libc::c_int = 0; + let mut mime_0: *mut libc::c_char = 0 as *mut libc::c_char; + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.mp3\x00" as *const u8 as *const libc::c_char, + 0 as *mut libc::c_int, + &mut mime_0, + ); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "audio/mpeg" + ); + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.mp3\x00" as *const u8 as *const libc::c_char, + &mut type_0, + 0 as *mut *mut libc::c_char, + ); + assert_eq!(type_0, 40); + // TODO add more tests for different message types + free(mime_0 as *mut libc::c_void); + } + } +} diff --git a/tests/stress.rs b/tests/stress.rs index 8f250efa2..ae1eb2091 100644 --- a/tests/stress.rs +++ b/tests/stress.rs @@ -17,7 +17,6 @@ use deltachat::dc_keyring::*; use deltachat::dc_location::*; use deltachat::dc_lot::*; use deltachat::dc_mimeparser::*; -use deltachat::dc_msg::*; use deltachat::dc_param::*; use deltachat::dc_pgp::*; use deltachat::dc_qr::*; @@ -415,49 +414,6 @@ unsafe fn stress_functions(context: &dc_context_t) { free(fn1 as *mut libc::c_void); } - let mut type_0: libc::c_int = 0; - let mut mime_0: *mut libc::c_char = 0 as *mut libc::c_char; - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.mp3\x00" as *const u8 as *const libc::c_char, - 0 as *mut libc::c_int, - 0 as *mut *mut libc::c_char, - ); - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.mp3\x00" as *const u8 as *const libc::c_char, - 0 as *mut libc::c_int, - &mut mime_0, - ); - if 0 != !(strcmp( - mime_0, - b"audio/mpeg\x00" as *const u8 as *const libc::c_char, - ) == 0i32) as libc::c_int as libc::c_long - { - __assert_rtn( - (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00")) - .as_ptr(), - b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char, - 360i32, - b"strcmp(mime, \"audio/mpeg\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.mp3\x00" as *const u8 as *const libc::c_char, - &mut type_0, - 0 as *mut *mut libc::c_char, - ); - if 0 != !(type_0 == 40i32) as libc::c_int as libc::c_long { - __assert_rtn( - (*::std::mem::transmute::<&[u8; 17], &[libc::c_char; 17]>(b"stress_functions\x00")) - .as_ptr(), - b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char, - 362i32, - b"type == DC_MSG_AUDIO\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(mime_0 as *mut libc::c_void); - let mut str: *mut libc::c_char = strdup(b"aaa\x00" as *const u8 as *const libc::c_char); let replacements: libc::c_int = dc_str_replace( &mut str,