diff --git a/src/dc_contact.rs b/src/dc_contact.rs index f786a3f72..1762ac468 100644 --- a/src/dc_contact.rs +++ b/src/dc_contact.rs @@ -45,7 +45,7 @@ pub unsafe fn dc_marknoticed_contact(context: &dc_context_t, contact_id: uint32_ ); } -// handle contacts +/// Returns false if addr is an invalid address, otherwise true. pub unsafe fn dc_may_be_valid_addr(addr: *const libc::c_char) -> bool { if addr.is_null() { return false; @@ -1259,3 +1259,59 @@ pub unsafe fn dc_scaleup_contact_origin( sqlite3_step(stmt); sqlite3_finalize(stmt); } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_dc_may_be_valid_addr() { + unsafe { + assert_eq!(dc_may_be_valid_addr(0 as *const libc::c_char), false); + assert_eq!( + dc_may_be_valid_addr(b"\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"user@domain.tld\x00" as *const u8 as *const libc::c_char), + true + ); + assert_eq!( + dc_may_be_valid_addr(b"uuu\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"dd.tt\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"tt.dd@uu\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"u@d\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"u@d.\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"u@d.t\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"u@d.tt\x00" as *const u8 as *const libc::c_char), + true + ); + assert_eq!( + dc_may_be_valid_addr(b"u@.tt\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_may_be_valid_addr(b"@d.tt\x00" as *const u8 as *const libc::c_char), + false + ); + } + } +} diff --git a/src/dc_mimeparser.rs b/src/dc_mimeparser.rs index 7bcefef00..a7ce75586 100644 --- a/src/dc_mimeparser.rs +++ b/src/dc_mimeparser.rs @@ -1966,3 +1966,82 @@ pub unsafe fn mailimf_find_optional_field( 0 as *mut mailimf_optional_field } + +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::CStr; + + #[test] + fn test_mailmime_parse() { + unsafe { + let txt: *const libc::c_char = + b"FieldA: ValueA\nFieldB: ValueB\n\x00" as *const u8 as *const libc::c_char; + let mut mime: *mut mailmime = 0 as *mut mailmime; + let mut dummy: size_t = 0i32 as size_t; + let res = mailmime_parse(txt, strlen(txt), &mut dummy, &mut mime); + + assert_eq!(res, MAIL_NO_ERROR as libc::c_int); + assert!(!mime.is_null()); + + let fields: *mut mailimf_fields = mailmime_find_mailimf_fields(mime); + assert!(!fields.is_null()); + + let mut of_a: *mut mailimf_optional_field = mailimf_find_optional_field( + fields, + b"fielda\x00" as *const u8 as *const libc::c_char, + ); + + assert!(!of_a.is_null()); + assert!(!(*of_a).fld_value.is_null()); + assert_eq!( + CStr::from_ptr((*of_a).fld_name as *const libc::c_char) + .to_str() + .unwrap(), + "FieldA", + ); + assert_eq!( + CStr::from_ptr((*of_a).fld_value as *const libc::c_char) + .to_str() + .unwrap(), + "ValueA", + ); + + of_a = mailimf_find_optional_field( + fields, + b"FIELDA\x00" as *const u8 as *const libc::c_char, + ); + + assert!(!of_a.is_null()); + assert!(!(*of_a).fld_value.is_null()); + assert_eq!( + CStr::from_ptr((*of_a).fld_name as *const libc::c_char) + .to_str() + .unwrap(), + "FieldA", + ); + assert_eq!( + CStr::from_ptr((*of_a).fld_value as *const libc::c_char) + .to_str() + .unwrap(), + "ValueA", + ); + + let of_b: *mut mailimf_optional_field = mailimf_find_optional_field( + fields, + b"FieldB\x00" as *const u8 as *const libc::c_char, + ); + + assert!(!of_b.is_null()); + assert!(!(*of_b).fld_value.is_null()); + assert_eq!( + CStr::from_ptr((*of_b).fld_value as *const libc::c_char) + .to_str() + .unwrap(), + "ValueB", + ); + + mailmime_free(mime); + } + } +} diff --git a/src/dc_msg.rs b/src/dc_msg.rs index 6e03e9b88..f2adeaa9e 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -1,4 +1,4 @@ -use crate::constants::Event; +use crate::constants::*; use crate::dc_chat::*; use crate::dc_contact::*; use crate::dc_context::*; @@ -388,32 +388,32 @@ pub unsafe fn dc_msg_guess_msgtype_from_suffix( suffix = dc_get_filesuffix_lc(pathNfilename); if !suffix.is_null() { if strcmp(suffix, b"mp3\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 40i32; + *ret_msgtype = DC_MSG_AUDIO as libc::c_int; *ret_mime = dc_strdup(b"audio/mpeg\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"aac\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 40i32; + *ret_msgtype = DC_MSG_AUDIO as libc::c_int; *ret_mime = dc_strdup(b"audio/aac\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"mp4\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 50i32; + *ret_msgtype = DC_MSG_VIDEO as libc::c_int; *ret_mime = dc_strdup(b"video/mp4\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"jpg\x00" as *const u8 as *const libc::c_char) == 0i32 || strcmp(suffix, b"jpeg\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 20i32; + *ret_msgtype = DC_MSG_IMAGE as libc::c_int; *ret_mime = dc_strdup(b"image/jpeg\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"png\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 20i32; + *ret_msgtype = DC_MSG_IMAGE as libc::c_int; *ret_mime = dc_strdup(b"image/png\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"webp\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 20i32; + *ret_msgtype = DC_MSG_IMAGE as libc::c_int; *ret_mime = dc_strdup(b"image/webp\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"gif\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 21i32; + *ret_msgtype = DC_MSG_GIF as libc::c_int; *ret_mime = dc_strdup(b"image/gif\x00" as *const u8 as *const libc::c_char) } else if strcmp(suffix, b"vcf\x00" as *const u8 as *const libc::c_char) == 0i32 || strcmp(suffix, b"vcard\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = 60i32; + *ret_msgtype = DC_MSG_FILE as libc::c_int; *ret_mime = dc_strdup(b"text/vcard\x00" as *const u8 as *const libc::c_char) } } @@ -1009,7 +1009,14 @@ pub unsafe fn dc_msg_get_summarytext_by_raw( b"ErrFilename\x00" as *const u8 as *const libc::c_char, ); value = dc_get_filename(pathNfilename); - label = dc_stock_str(context, if type_0 == 40i32 { 11i32 } else { 12i32 }); + label = dc_stock_str( + context, + if type_0 == DC_MSG_AUDIO as libc::c_int { + 11i32 + } else { + 12i32 + }, + ); prefix = dc_mprintf( b"%s \xe2\x80\x93 %s\x00" as *const u8 as *const libc::c_char, label, @@ -1112,18 +1119,21 @@ pub unsafe fn dc_msg_is_increation(msg: *const dc_msg_t) -> libc::c_int { return 0i32; } - (((*msg).type_0 == 20i32 - || (*msg).type_0 == 21i32 - || (*msg).type_0 == 40i32 - || (*msg).type_0 == 41i32 - || (*msg).type_0 == 50i32 - || (*msg).type_0 == 60i32) + (((*msg).type_0 == DC_MSG_IMAGE as libc::c_int + || (*msg).type_0 == DC_MSG_GIF as libc::c_int + || (*msg).type_0 == DC_MSG_AUDIO as libc::c_int + || (*msg).type_0 == DC_MSG_VOICE as libc::c_int + || (*msg).type_0 == DC_MSG_VIDEO as libc::c_int + || (*msg).type_0 == DC_MSG_FILE as libc::c_int) && (*msg).state == 18i32) as libc::c_int } // TODO should return bool /rtn pub unsafe fn dc_msg_is_setupmessage(msg: *const dc_msg_t) -> libc::c_int { - if msg.is_null() || (*msg).magic != 0x11561156i32 as libc::c_uint || (*msg).type_0 != 60i32 { + if msg.is_null() + || (*msg).magic != 0x11561156i32 as libc::c_uint + || (*msg).type_0 != DC_MSG_FILE as libc::c_int + { return 0i32; } return if dc_param_get_int((*msg).param, 'S' as i32, 0i32) == 6i32 { @@ -1616,3 +1626,143 @@ 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, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_AUDIO as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "audio/mpeg" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.aac\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_AUDIO as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "audio/aac" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.mp4\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_VIDEO as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "video/mp4" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.jpg\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_IMAGE as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "image/jpeg" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.jpeg\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_IMAGE as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "image/jpeg" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.png\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_IMAGE as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "image/png" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.webp\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_IMAGE as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "image/webp" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.gif\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_GIF as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "image/gif" + ); + free(mime_0 as *mut libc::c_void); + + dc_msg_guess_msgtype_from_suffix( + b"foo/bar-sth.vcf\x00" as *const u8 as *const libc::c_char, + &mut type_0, + &mut mime_0, + ); + assert_eq!(type_0, DC_MSG_FILE as libc::c_int); + assert_eq!( + CStr::from_ptr(mime_0 as *const libc::c_char) + .to_str() + .unwrap(), + "text/vcard" + ); + free(mime_0 as *mut libc::c_void); + } + } +} diff --git a/src/dc_simplify.rs b/src/dc_simplify.rs index eb5de28b9..9d70afe84 100644 --- a/src/dc_simplify.rs +++ b/src/dc_simplify.rs @@ -73,9 +73,9 @@ pub unsafe fn dc_simplify_simplify( out } -/* ****************************************************************************** +/** * Simplify Plain Text - ******************************************************************************/ + */ unsafe fn dc_simplify_simplify_plain_text( mut simplify: *mut dc_simplify_t, buf_terminated: *const libc::c_char, @@ -250,9 +250,9 @@ unsafe fn dc_simplify_simplify_plain_text( ret.buf } -/* ****************************************************************************** +/** * Tools - ******************************************************************************/ + */ unsafe fn is_empty_line(buf: *const libc::c_char) -> bool { /* force unsigned - otherwise the `> ' '` comparison will fail */ let mut p1: *const libc::c_uchar = buf as *const libc::c_uchar; @@ -289,3 +289,95 @@ unsafe fn is_plain_quote(buf: *const libc::c_char) -> bool { false } + +#[cfg(test)] +mod tests { + use super::*; + use std::ffi::CStr; + + #[test] + fn test_simplify_trim() { + unsafe { + let simplify: *mut dc_simplify_t = dc_simplify_new(); + let html: *const libc::c_char = + b"\r\r\nline1
\r\n\r\n\r\rline2\n\r\x00" as *const u8 as *const libc::c_char; + let plain: *mut libc::c_char = + dc_simplify_simplify(simplify, html, strlen(html) as libc::c_int, 1, 0); + + assert_eq!( + CStr::from_ptr(plain as *const libc::c_char) + .to_str() + .unwrap(), + "line1\nline2", + ); + + free(plain as *mut libc::c_void); + dc_simplify_unref(simplify); + } + } + + #[test] + fn test_simplify_parse_href() { + unsafe { + let simplify: *mut dc_simplify_t = dc_simplify_new(); + let html: *const libc::c_char = + b"text]>text bold]]>\x00" + as *const u8 as *const libc::c_char; + let plain: *mut libc::c_char = + dc_simplify_simplify(simplify, html, strlen(html) as libc::c_int, 1, 0); + + assert_eq!( + CStr::from_ptr(plain as *const libc::c_char) + .to_str() + .unwrap(), + "text *bold*<>", + ); + + free(plain as *mut libc::c_void); + dc_simplify_unref(simplify); + } + } + + #[test] + fn test_simplify_html_encoded() { + unsafe { + let simplify: *mut dc_simplify_t = dc_simplify_new(); + let html: *const libc::c_char = + b"<>"'& äÄöÖüÜß fooÆçÇ ♦&noent;‎‏‌‍\x00" + as *const u8 as *const libc::c_char; + let plain: *mut libc::c_char = + dc_simplify_simplify(simplify, html, strlen(html) as libc::c_int, 1, 0); + + assert_eq!( + strcmp(plain, + b"<>\"\'& \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), + 0, + ); + + free(plain as *mut libc::c_void); + dc_simplify_unref(simplify); + } + } +} diff --git a/src/dc_strencode.rs b/src/dc_strencode.rs index bc5ad7164..a0a73cf50 100644 --- a/src/dc_strencode.rs +++ b/src/dc_strencode.rs @@ -728,6 +728,7 @@ pub unsafe fn dc_decode_ext_header(to_decode: *const libc::c_char) -> *mut libc: #[cfg(test)] mod tests { use super::*; + use std::ffi::CStr; #[test] fn test_isalnum() { @@ -735,4 +736,159 @@ mod tests { assert_eq!(isalnum('5' as libc::c_int), 1); assert_eq!(isalnum('Q' as libc::c_int), 1); } + + #[test] + fn test_dc_decode_header_words() { + unsafe { + let mut buf1: *mut libc::c_char = dc_decode_header_words( + b"=?utf-8?B?dGVzdMOkw7bDvC50eHQ=?=\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + strcmp( + buf1, + b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char + ), + 0 + ); + free(buf1 as *mut libc::c_void); + + buf1 = + dc_decode_header_words(b"just ascii test\x00" as *const u8 as *const libc::c_char); + assert_eq!(CStr::from_ptr(buf1).to_str().unwrap(), "just ascii test"); + free(buf1 as *mut libc::c_void); + + buf1 = dc_encode_header_words(b"abcdef\x00" as *const u8 as *const libc::c_char); + assert_eq!(CStr::from_ptr(buf1).to_str().unwrap(), "abcdef"); + free(buf1 as *mut libc::c_void); + + buf1 = dc_encode_header_words( + b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + strncmp(buf1, b"=?utf-8\x00" as *const u8 as *const libc::c_char, 7), + 0 + ); + + let buf2: *mut libc::c_char = dc_decode_header_words(buf1); + assert_eq!( + strcmp( + buf2, + b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char + ), + 0 + ); + free(buf1 as *mut libc::c_void); + free(buf2 as *mut libc::c_void); + + buf1 = dc_decode_header_words( + b"=?ISO-8859-1?Q?attachment=3B=0D=0A_filename=3D?= =?ISO-8859-1?Q?=22test=E4=F6=FC=2Etxt=22=3B=0D=0A_size=3D39?=\x00" as *const u8 as *const libc::c_char + ); + assert_eq!( + strcmp( + buf1, + b"attachment;\r\n filename=\"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\";\r\n size=39\x00" as *const u8 as *const libc::c_char, + + ), + 0 + ); + free(buf1 as *mut libc::c_void); + } + } + + #[test] + fn test_dc_encode_ext_header() { + unsafe { + let mut buf1 = dc_encode_ext_header( + b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr(buf1).to_str().unwrap(), + "utf-8\'\'Bj%C3%B6rn%20Petersen" + ); + let buf2 = dc_decode_ext_header(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); + + buf1 = dc_decode_ext_header( + b"iso-8859-1\'en\'%A3%20rates\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + strcmp( + buf1, + b"\xc2\xa3 rates\x00" as *const u8 as *const libc::c_char, + ), + 0 + ); + free(buf1 as *mut libc::c_void); + + buf1 = dc_decode_ext_header(b"wrong\'format\x00" as *const u8 as *const libc::c_char); + assert_eq!( + strcmp( + buf1, + b"wrong\'format\x00" as *const u8 as *const libc::c_char, + ), + 0 + ); + free(buf1 as *mut libc::c_void); + + buf1 = dc_decode_ext_header(b"\'\'\x00" as *const u8 as *const libc::c_char); + assert_eq!( + strcmp(buf1, b"\'\'\x00" as *const u8 as *const libc::c_char), + 0 + ); + free(buf1 as *mut libc::c_void); + + buf1 = dc_decode_ext_header(b"x\'\'\x00" as *const u8 as *const libc::c_char); + assert_eq!(strcmp(buf1, b"\x00" as *const u8 as *const libc::c_char), 0); + free(buf1 as *mut libc::c_void); + + buf1 = dc_decode_ext_header(b"\'\x00" as *const u8 as *const libc::c_char); + assert_eq!( + strcmp(buf1, b"\'\x00" as *const u8 as *const libc::c_char), + 0 + ); + free(buf1 as *mut libc::c_void); + + buf1 = dc_decode_ext_header(b"\x00" as *const u8 as *const libc::c_char); + assert_eq!(strcmp(buf1, b"\x00" as *const u8 as *const libc::c_char), 0); + free(buf1 as *mut libc::c_void); + } + } + + #[test] + fn test_dc_needs_ext_header() { + unsafe { + assert_eq!( + dc_needs_ext_header(b"Bj\xc3\xb6rn\x00" as *const u8 as *const libc::c_char), + true + ); + assert_eq!( + dc_needs_ext_header(b"Bjoern\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_needs_ext_header(b"\x00" as *const u8 as *const libc::c_char), + false + ); + assert_eq!( + dc_needs_ext_header(b" \x00" as *const u8 as *const libc::c_char), + true + ); + assert_eq!( + dc_needs_ext_header(b"a b\x00" as *const u8 as *const libc::c_char), + true + ); + assert_eq!( + dc_needs_ext_header(0 as *const u8 as *const libc::c_char), + false + ); + } + } } diff --git a/src/dc_tools.rs b/src/dc_tools.rs index 9075578d9..e3a27718f 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -1704,4 +1704,258 @@ mod tests { ); } } + + #[test] + fn test_dc_atof() { + unsafe { + let f: libc::c_double = dc_atof(b"1.23\x00" as *const u8 as *const libc::c_char); + assert!(f > 1.22f64); + assert!(f < 1.24f64); + } + } + + #[test] + fn test_dc_ftoa() { + unsafe { + let s: *mut libc::c_char = dc_ftoa(1.23f64); + assert!(dc_atof(s) > 1.22f64); + assert!(dc_atof(s) < 1.24f64); + free(s as *mut libc::c_void); + } + } + + #[test] + fn test_dc_str_replace() { + unsafe { + 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, + b"a\x00" as *const u8 as *const libc::c_char, + b"ab\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "ababab" + ); + assert_eq!(replacements, 3); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_str_truncate_1() { + unsafe { + let str: *mut libc::c_char = + strdup(b"this is a little test string\x00" as *const u8 as *const libc::c_char); + dc_truncate_str(str, 16); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "this is a [...]" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_str_truncate_2() { + unsafe { + let str: *mut libc::c_char = strdup(b"1234\x00" as *const u8 as *const libc::c_char); + dc_truncate_str(str, 2); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "1234" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_str_truncate_3() { + unsafe { + let str: *mut libc::c_char = strdup(b"1234567\x00" as *const u8 as *const libc::c_char); + dc_truncate_str(str, 1); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "1[...]" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_str_truncate_4() { + unsafe { + let str: *mut libc::c_char = strdup(b"123456\x00" as *const u8 as *const libc::c_char); + dc_truncate_str(str, 4); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "123456" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_insert_breaks_1() { + unsafe { + let str: *mut libc::c_char = dc_insert_breaks( + b"just1234test\x00" as *const u8 as *const libc::c_char, + 4, + b" \x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "just 1234 test" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_insert_breaks_2() { + unsafe { + let str: *mut libc::c_char = dc_insert_breaks( + b"just1234tes\x00" as *const u8 as *const libc::c_char, + 4i32, + b"--\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "just--1234--tes" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_insert_breaks_3() { + unsafe { + let str: *mut libc::c_char = dc_insert_breaks( + b"just1234t\x00" as *const u8 as *const libc::c_char, + 4i32, + b"\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "just1234t" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_insert_breaks_4() { + unsafe { + let str: *mut libc::c_char = dc_insert_breaks( + b"\x00" as *const u8 as *const libc::c_char, + 4i32, + b"---\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_null_terminate_1() { + unsafe { + let str: *mut libc::c_char = + dc_null_terminate(b"abcxyz\x00" as *const u8 as *const libc::c_char, 3); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "abc" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_null_terminate_2() { + unsafe { + let str: *mut libc::c_char = + dc_null_terminate(b"abcxyz\x00" as *const u8 as *const libc::c_char, 0); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_null_terminate_3() { + unsafe { + let str: *mut libc::c_char = + dc_null_terminate(0 as *const u8 as *const libc::c_char, 0); + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "" + ); + free(str as *mut libc::c_void); + } + } + + #[test] + fn test_dc_str_to_clist_1() { + unsafe { + let list: *mut clist = dc_str_to_clist( + 0 as *const libc::c_char, + b" \x00" as *const u8 as *const libc::c_char, + ); + assert_eq!((*list).count, 0); + clist_free_content(list); + clist_free(list); + } + } + + #[test] + fn test_dc_str_to_clist_2() { + unsafe { + let list: *mut clist = dc_str_to_clist( + b"\x00" as *const u8 as *const libc::c_char, + b" \x00" as *const u8 as *const libc::c_char, + ); + assert_eq!((*list).count, 1); + clist_free_content(list); + clist_free(list); + } + } + + #[test] + fn test_dc_str_to_clist_3() { + unsafe { + let list: *mut clist = dc_str_to_clist( + b" \x00" as *const u8 as *const libc::c_char, + b" \x00" as *const u8 as *const libc::c_char, + ); + assert_eq!((*list).count, 2); + clist_free_content(list); + clist_free(list); + } + } + + #[test] + fn test_dc_str_to_clist_4() { + unsafe { + let list: *mut clist = dc_str_to_clist( + b"foo bar test\x00" as *const u8 as *const libc::c_char, + b" \x00" as *const u8 as *const libc::c_char, + ); + assert_eq!((*list).count, 3); + let str: *mut libc::c_char = + dc_str_from_clist(list, b" \x00" as *const u8 as *const libc::c_char); + + assert_eq!( + CStr::from_ptr(str as *const libc::c_char).to_str().unwrap(), + "foo bar test" + ); + + clist_free_content(list); + clist_free(list); + free(str as *mut libc::c_void); + } + } } diff --git a/src/x.rs b/src/x.rs index 9d74ddc11..282395516 100644 --- a/src/x.rs +++ b/src/x.rs @@ -76,3 +76,16 @@ pub use libc::atof; pub unsafe fn atof(nptr: *mut libc::c_char) -> libc::c_double { libc::strtod(nptr, std::ptr::null_mut()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_atox() { + unsafe { + assert_eq!(atol(b"\x00" as *const u8 as *const libc::c_char), 0); + assert_eq!(atoi(b"\x00" as *const u8 as *const libc::c_char), 0); + } + } +} diff --git a/tests/stress.rs b/tests/stress.rs index 09288324f..ffaa84437 100644 --- a/tests/stress.rs +++ b/tests/stress.rs @@ -3,15 +3,12 @@ use std::ffi::{CStr, CString}; use mmime::mailimf_types::*; -use mmime::mailmime_content::*; -use mmime::mailmime_types::*; use mmime::other::*; -use tempfile::tempdir; +use tempfile::{tempdir, TempDir}; use deltachat::constants::*; use deltachat::dc_array::*; use deltachat::dc_configure::*; -use deltachat::dc_contact::*; use deltachat::dc_context::*; use deltachat::dc_hash::*; use deltachat::dc_imex::*; @@ -20,13 +17,11 @@ 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::*; use deltachat::dc_saxparser::*; use deltachat::dc_securejoin::*; -use deltachat::dc_simplify::*; use deltachat::dc_strbuilder::*; use deltachat::dc_strencode::*; use deltachat::dc_tools::*; @@ -61,197 +56,6 @@ unsafe fn stress_functions(context: &dc_context_t) { b"\r\n\r\n\r\rline2\n\r\x00" as *const u8 as *const libc::c_char; - let mut plain: *mut libc::c_char = - dc_simplify_simplify(simplify, html, strlen(html) as libc::c_int, 1i32, 0i32); - - assert_eq!( - CStr::from_ptr(plain as *const libc::c_char) - .to_str() - .unwrap(), - "line1\nline2", - ); - free(plain as *mut libc::c_void); - - html = b"text(b"stress_functions\x00")) - .as_ptr(), - b"../cmdline/stress.c\x00" as *const u8 as *const libc::c_char, - 179i32, - b"strcmp(plain, \"[text](url)\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(plain as *mut libc::c_void); - html = - b"]>text bold]]>\x00" - as *const u8 as *const libc::c_char; - plain = dc_simplify_simplify(simplify, html, strlen(html) as libc::c_int, 1i32, 0i32); - if 0 != !(strcmp( - plain, - b"text *bold*<>\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, - 184i32, - b"strcmp(plain, \"text *bold*<>\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(plain as *mut libc::c_void); - html = - b"<>"'& äÄöÖüÜß fooÆçÇ ♦&noent;‎‏‌‍\x00" - as *const u8 as *const libc::c_char; - plain = dc_simplify_simplify(simplify, html, strlen(html) as libc::c_int, 1i32, 0i32); - if 0 != - !(strcmp(plain, - b"<>\"\'& \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) == 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, 189i32, - b"strcmp(plain, \"<>\\\"\'& \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;\")==0\x00" - as *const u8 as *const libc::c_char); - } else { }; - free(plain as *mut libc::c_void); - dc_simplify_unref(simplify); - let xml: *const libc::c_char = - b"\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n\x00" - as *const u8 as *const libc::c_char; - let kml: *mut dc_kml_t = dc_kml_parse(context, xml, strlen(xml)); - if 0 != !(!(*kml).addr.is_null() - && strcmp( - (*kml).addr, - b"user@example.org\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, - 205i32, - b"kml->addr && strcmp(kml->addr, \"user@example.org\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !(dc_array_get_cnt((*kml).locations) == 2) 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, - 206i32, - b"dc_array_get_cnt(kml->locations)==2\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let mut lat: libc::c_double = dc_array_get_latitude((*kml).locations, 0i32 as size_t); - if 0 != !(lat > 53.6f64 && lat < 53.8f64) 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, - 208i32, - b"lat>53.6 && lat<53.8\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let mut lng: libc::c_double = dc_array_get_longitude((*kml).locations, 0i32 as size_t); - if 0 != !(lng > 9.3f64 && lng < 9.5f64) 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, - 209i32, - b"lng> 9.3 && lng< 9.5\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let mut acc: libc::c_double = dc_array_get_accuracy((*kml).locations, 0i32 as size_t); - if 0 != !(acc > 31.9f64 && acc < 32.1f64) 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, - 210i32, - b"acc>31.9 && acc<32.1\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(dc_array_get_timestamp((*kml).locations, 0i32 as size_t) - == 1551906597i32 as libc::c_long) 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, - 211i32, - b"dc_array_get_timestamp(kml->locations, 0)==1551906597\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - lat = dc_array_get_latitude((*kml).locations, 1i32 as size_t); - if 0 != !(lat > 63.6f64 && lat < 63.8f64) 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, - 213i32, - b"lat>63.6 && lat<63.8\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - lng = dc_array_get_longitude((*kml).locations, 1i32 as size_t); - if 0 != !(lng > 19.3f64 && lng < 19.5f64) 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, - 214i32, - b"lng>19.3 && lng<19.5\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - acc = dc_array_get_accuracy((*kml).locations, 1i32 as size_t); - if 0 != !(acc > 2.4f64 && acc < 2.6f64) 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, - 215i32, - b"acc> 2.4 && acc< 2.6\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(dc_array_get_timestamp((*kml).locations, 1i32 as size_t) - == 1544739072i32 as libc::c_long) 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, - 216i32, - b"dc_array_get_timestamp(kml->locations, 1)==1544739072\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - dc_kml_unref(kml); if 0 != dc_is_open(context) { if 0 != dc_file_exist( context, @@ -609,1190 +413,7 @@ unsafe fn stress_functions(context: &dc_context_t) { free(fn0 as *mut libc::c_void); free(fn1 as *mut libc::c_void); } - let txt: *const libc::c_char = - b"FieldA: ValueA\nFieldB: ValueB\n\x00" as *const u8 as *const libc::c_char; - let mut mime: *mut mailmime = 0 as *mut mailmime; - let mut dummy: size_t = 0i32 as size_t; - if 0 != !(mailmime_parse(txt, strlen(txt), &mut dummy, &mut mime) - == MAIL_NO_ERROR as libc::c_int) 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, - 286i32, - b"mailmime_parse(txt, strlen(txt), &dummy, &mime) == MAIL_NO_ERROR\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != mime.is_null() 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, - 287i32, - b"mime != NULL\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let fields: *mut mailimf_fields = mailmime_find_mailimf_fields(mime); - if 0 != fields.is_null() 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, - 290i32, - b"fields != NULL\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let mut of_a: *mut mailimf_optional_field = - mailimf_find_optional_field(fields, b"fielda\x00" as *const u8 as *const libc::c_char); - if 0 != !(!of_a.is_null() && !(*of_a).fld_value.is_null()) 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, - 293i32, - b"of_a && of_a->fld_value\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - (*of_a).fld_name, - b"FieldA\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, - 294i32, - b"strcmp(of_a->fld_name, \"FieldA\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - (*of_a).fld_value, - b"ValueA\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, - 295i32, - b"strcmp(of_a->fld_value, \"ValueA\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - of_a = mailimf_find_optional_field(fields, b"FIELDA\x00" as *const u8 as *const libc::c_char); - if 0 != !(!of_a.is_null() && !(*of_a).fld_value.is_null()) 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, - 298i32, - b"of_a && of_a->fld_value\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - (*of_a).fld_name, - b"FieldA\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, - 299i32, - b"strcmp(of_a->fld_name, \"FieldA\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - (*of_a).fld_value, - b"ValueA\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, - 300i32, - b"strcmp(of_a->fld_value, \"ValueA\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let of_b: *mut mailimf_optional_field = - mailimf_find_optional_field(fields, b"FieldB\x00" as *const u8 as *const libc::c_char); - if 0 != !(!of_b.is_null() && !(*of_b).fld_value.is_null()) 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, - 303i32, - b"of_b && of_b->fld_value\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - (*of_b).fld_value, - b"ValueB\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, - 304i32, - b"strcmp(of_b->fld_value, \"ValueB\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - mailmime_free(mime); - let mimeparser: *mut dc_mimeparser_t = dc_mimeparser_new(context); - let raw: *const libc::c_char = - b"Content-Type: multipart/mixed; boundary=\"==break==\";\nSubject: outer-subject\nX-Special-A: special-a\nFoo: Bar\nChat-Version: 0.0\n\n--==break==\nContent-Type: text/plain; protected-headers=\"v1\";\nSubject: inner-subject\nX-Special-B: special-b\nFoo: Xy\nChat-Version: 1.0\n\ntest1\n\n--==break==--\n\n\x00" - as *const u8 as *const libc::c_char; - dc_mimeparser_parse(mimeparser, raw, strlen(raw)); - if 0 != !(strcmp( - (*mimeparser).subject, - b"inner-subject\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, - 336i32, - b"strcmp(mimeparser->subject, \"inner-subject\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - let mut of: *mut mailimf_optional_field = dc_mimeparser_lookup_optional_field( - mimeparser, - b"X-Special-A\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - (*of).fld_value, - b"special-a\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, - 339i32, - b"strcmp(of->fld_value, \"special-a\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - of = dc_mimeparser_lookup_optional_field( - mimeparser, - b"Foo\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - (*of).fld_value, - b"Bar\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, - 342i32, - b"strcmp(of->fld_value, \"Bar\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - of = dc_mimeparser_lookup_optional_field( - mimeparser, - b"Chat-Version\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - (*of).fld_value, - b"1.0\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, - 345i32, - b"strcmp(of->fld_value, \"1.0\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(carray_count((*mimeparser).parts) == 1i32 as libc::c_uint) 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, - 347i32, - b"carray_count(mimeparser->parts) == 1\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - dc_mimeparser_unref(mimeparser); - 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); - if 0 != !(atol(b"\x00" as *const u8 as *const libc::c_char) == 0i32 as libc::c_long) - 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, - 370i32, - b"atol(\"\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(atoi(b"\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, - 371i32, - b"atoi(\"\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let f: libc::c_double = dc_atof(b"1.23\x00" as *const u8 as *const libc::c_char); - if 0 != !(f > 1.22f64 && f < 1.24f64) 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, - 374i32, - b"f>1.22 && f<1.24\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - let s: *mut libc::c_char = dc_ftoa(1.23f64); - if 0 != !(dc_atof(s) > 1.22f64 && dc_atof(s) < 1.24f64) 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, - 377i32, - b"dc_atof(s)>1.22 && dc_atof(s)<1.24\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(s as *mut libc::c_void); - if 0 != (dc_may_be_valid_addr(0 as *const libc::c_char)) 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, - 380i32, - b"!dc_may_be_valid_addr(NULL)\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"\x00" as *const u8 as *const libc::c_char)) 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, - 381i32, - b"!dc_may_be_valid_addr(\"\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (!dc_may_be_valid_addr(b"user@domain.tld\x00" as *const u8 as *const libc::c_char)) - 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, - 382i32, - b"dc_may_be_valid_addr(\"user@domain.tld\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"uuu\x00" as *const u8 as *const libc::c_char)) 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, - 383i32, - b"!dc_may_be_valid_addr(\"uuu\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"dd.tt\x00" as *const u8 as *const libc::c_char)) 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, - 384i32, - b"!dc_may_be_valid_addr(\"dd.tt\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"tt.dd@uu\x00" as *const u8 as *const libc::c_char)) - 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, - 385i32, - b"!dc_may_be_valid_addr(\"tt.dd@uu\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"uu\x00" as *const u8 as *const libc::c_char)) 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, - 386i32, - b"!dc_may_be_valid_addr(\"uu\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"u@d\x00" as *const u8 as *const libc::c_char)) 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, - 387i32, - b"!dc_may_be_valid_addr(\"u@d\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"u@d.\x00" as *const u8 as *const libc::c_char)) 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, - 388i32, - b"!dc_may_be_valid_addr(\"u@d.\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"u@d.t\x00" as *const u8 as *const libc::c_char)) 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, - 389i32, - b"!dc_may_be_valid_addr(\"u@d.t\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (!dc_may_be_valid_addr(b"u@d.tt\x00" as *const u8 as *const libc::c_char)) - 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, - 390i32, - b"dc_may_be_valid_addr(\"u@d.tt\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"u@.tt\x00" as *const u8 as *const libc::c_char)) 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, - 391i32, - b"!dc_may_be_valid_addr(\"u@.tt\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_may_be_valid_addr(b"@d.tt\x00" as *const u8 as *const libc::c_char)) 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, - 392i32, - b"!dc_may_be_valid_addr(\"@d.tt\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - 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, - b"a\x00" as *const u8 as *const libc::c_char, - b"ab\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp(str, b"ababab\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, - 396i32, - b"strcmp(str, \"ababab\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(replacements == 3i32) 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, - 397i32, - b"replacements == 3\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = strdup(b"this is a little test string\x00" as *const u8 as *const libc::c_char); - dc_truncate_str(str, 16i32); - if 0 != !(strcmp( - str, - b"this is a [...]\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, - 402i32, - b"strcmp(str, \"this is a \" DC_EDITORIAL_ELLIPSE)==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = strdup(b"1234\x00" as *const u8 as *const libc::c_char); - dc_truncate_str(str, 2i32); - if 0 != !(strcmp(str, b"1234\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, - 407i32, - b"strcmp(str, \"1234\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = strdup(b"1234567\x00" as *const u8 as *const libc::c_char); - dc_truncate_str(str, 1i32); - if 0 != !(strcmp(str, b"1[...]\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, - 412i32, - b"strcmp(str, \"1[...]\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = strdup(b"123456\x00" as *const u8 as *const libc::c_char); - dc_truncate_str(str, 4i32); - if 0 != !(strcmp(str, b"123456\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, - 417i32, - b"strcmp(str, \"123456\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_insert_breaks( - b"just1234test\x00" as *const u8 as *const libc::c_char, - 4i32, - b" \x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - str, - b"just 1234 test\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, - 421i32, - b"strcmp(str, \"just 1234 test\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_insert_breaks( - b"just1234tes\x00" as *const u8 as *const libc::c_char, - 4i32, - b"--\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - str, - b"just--1234--tes\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, - 425i32, - b"strcmp(str, \"just--1234--tes\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_insert_breaks( - b"just1234t\x00" as *const u8 as *const libc::c_char, - 4i32, - b"\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp(str, b"just1234t\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, - 429i32, - b"strcmp(str, \"just1234t\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_insert_breaks( - b"\x00" as *const u8 as *const libc::c_char, - 4i32, - b"---\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp(str, b"\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, - 433i32, - b"strcmp(str, \"\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_null_terminate(b"abcxyz\x00" as *const u8 as *const libc::c_char, 3i32); - if 0 != !(strcmp(str, b"abc\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, - 437i32, - b"strcmp(str, \"abc\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_null_terminate(b"abcxyz\x00" as *const u8 as *const libc::c_char, 0i32); - if 0 != !(strcmp(str, b"\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, - 441i32, - b"strcmp(str, \"\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - str = dc_null_terminate(0 as *const libc::c_char, 0i32); - if 0 != !(strcmp(str, b"\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, - 445i32, - b"strcmp(str, \"\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(str as *mut libc::c_void); - let mut list: *mut clist = dc_str_to_clist( - 0 as *const libc::c_char, - b" \x00" as *const u8 as *const libc::c_char, - ); - if 0 != !((*list).count == 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, - 449i32, - b"clist_count(list)==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - clist_free_content(list); - clist_free(list); - list = dc_str_to_clist( - b"\x00" as *const u8 as *const libc::c_char, - b" \x00" as *const u8 as *const libc::c_char, - ); - if 0 != !((*list).count == 1i32) 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, - 454i32, - b"clist_count(list)==1\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - clist_free_content(list); - clist_free(list); - list = dc_str_to_clist( - b" \x00" as *const u8 as *const libc::c_char, - b" \x00" as *const u8 as *const libc::c_char, - ); - if 0 != !((*list).count == 2i32) 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, - 459i32, - b"clist_count(list)==2\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - clist_free_content(list); - clist_free(list); - list = dc_str_to_clist( - b"foo bar test\x00" as *const u8 as *const libc::c_char, - b" \x00" as *const u8 as *const libc::c_char, - ); - if 0 != !((*list).count == 3i32) 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, - 464i32, - b"clist_count(list)==3\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - str = dc_str_from_clist(list, b" \x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp(str, b"foo bar test\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, - 466i32, - b"strcmp(str, \"foo bar test\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - clist_free_content(list); - clist_free(list); - free(str as *mut libc::c_void); - if 0 != !(strcmp( - b"fresh=10\x00" as *const u8 as *const libc::c_char, - b"fresh=10\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, - 471i32, - b"strcmp(\"fresh=\" DC_STRINGIFY(DC_STATE_IN_FRESH), \"fresh=10\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"noticed=13\x00" as *const u8 as *const libc::c_char, - b"noticed=13\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, - 472i32, - b"strcmp(\"noticed=\" DC_STRINGIFY(DC_STATE_IN_NOTICED), \"noticed=13\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"seen=16\x00" as *const u8 as *const libc::c_char, - b"seen=16\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, - 473i32, - b"strcmp(\"seen=\" DC_STRINGIFY(DC_STATE_IN_SEEN), \"seen=16\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"pending=20\x00" as *const u8 as *const libc::c_char, - b"pending=20\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, - 474i32, - b"strcmp(\"pending=\" DC_STRINGIFY(DC_STATE_OUT_PENDING), \"pending=20\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"failed=24\x00" as *const u8 as *const libc::c_char, - b"failed=24\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, - 475i32, - b"strcmp(\"failed=\" DC_STRINGIFY(DC_STATE_OUT_FAILED), \"failed=24\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"delivered=26\x00" as *const u8 as *const libc::c_char, - b"delivered=26\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, - 476i32, - b"strcmp(\"delivered=\" DC_STRINGIFY(DC_STATE_OUT_DELIVERED), \"delivered=26\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"mdn_rcvd=28\x00" as *const u8 as *const libc::c_char, - b"mdn_rcvd=28\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, - 477i32, - b"strcmp(\"mdn_rcvd=\" DC_STRINGIFY(DC_STATE_OUT_MDN_RCVD), \"mdn_rcvd=28\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"undefined=0\x00" as *const u8 as *const libc::c_char, - b"undefined=0\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, - 479i32, - b"strcmp(\"undefined=\" DC_STRINGIFY(DC_CHAT_TYPE_UNDEFINED), \"undefined=0\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"single=100\x00" as *const u8 as *const libc::c_char, - b"single=100\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, - 480i32, - b"strcmp(\"single=\" DC_STRINGIFY(DC_CHAT_TYPE_SINGLE), \"single=100\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"group=120\x00" as *const u8 as *const libc::c_char, - b"group=120\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, - 481i32, - b"strcmp(\"group=\" DC_STRINGIFY(DC_CHAT_TYPE_GROUP), \"group=120\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"vgroup=130\x00" as *const u8 as *const libc::c_char, - b"vgroup=130\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, - 482i32, - b"strcmp(\"vgroup=\" DC_STRINGIFY(DC_CHAT_TYPE_VERIFIED_GROUP), \"vgroup=130\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"deaddrop=1\x00" as *const u8 as *const libc::c_char, - b"deaddrop=1\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, - 484i32, - b"strcmp(\"deaddrop=\" DC_STRINGIFY(DC_CHAT_ID_DEADDROP), \"deaddrop=1\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"trash=3\x00" as *const u8 as *const libc::c_char, - b"trash=3\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, - 485i32, - b"strcmp(\"trash=\" DC_STRINGIFY(DC_CHAT_ID_TRASH), \"trash=3\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"in_creation=4\x00" as *const u8 as *const libc::c_char, - b"in_creation=4\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, 486i32, - b"strcmp(\"in_creation=\" DC_STRINGIFY(DC_CHAT_ID_MSGS_IN_CREATION), \"in_creation=4\")==0\x00" - as *const u8 as *const libc::c_char); - } else { - }; - if 0 != !(strcmp( - b"starred=5\x00" as *const u8 as *const libc::c_char, - b"starred=5\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, - 487i32, - b"strcmp(\"starred=\" DC_STRINGIFY(DC_CHAT_ID_STARRED), \"starred=5\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"archivedlink=6\x00" as *const u8 as *const libc::c_char, - b"archivedlink=6\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, 488i32, - b"strcmp(\"archivedlink=\" DC_STRINGIFY(DC_CHAT_ID_ARCHIVED_LINK), \"archivedlink=6\")==0\x00" - as *const u8 as *const libc::c_char); - } else { - }; - if 0 != !(strcmp( - b"spcl_chat=9\x00" as *const u8 as *const libc::c_char, - b"spcl_chat=9\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, - 489i32, - b"strcmp(\"spcl_chat=\" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL), \"spcl_chat=9\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"self=1\x00" as *const u8 as *const libc::c_char, - b"self=1\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, - 491i32, - b"strcmp(\"self=\" DC_STRINGIFY(DC_CONTACT_ID_SELF), \"self=1\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"spcl_contact=9\x00" as *const u8 as *const libc::c_char, - b"spcl_contact=9\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, 492i32, - b"strcmp(\"spcl_contact=\" DC_STRINGIFY(DC_CONTACT_ID_LAST_SPECIAL), \"spcl_contact=9\")==0\x00" - as *const u8 as *const libc::c_char); - } else { - }; - if 0 != !(strcmp( - b"grpimg=3\x00" as *const u8 as *const libc::c_char, - b"grpimg=3\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, - 494i32, - b"strcmp(\"grpimg=\" DC_STRINGIFY(DC_CMD_GROUPIMAGE_CHANGED), \"grpimg=3\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"notverified=0\x00" as *const u8 as *const libc::c_char, - b"notverified=0\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, - 496i32, - b"strcmp(\"notverified=\" DC_STRINGIFY(DC_NOT_VERIFIED), \"notverified=0\")==0\x00" - as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"bidirectional=2\x00" as *const u8 as *const libc::c_char, - b"bidirectional=2\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, 497i32, - b"strcmp(\"bidirectional=\" DC_STRINGIFY(DC_BIDIRECT_VERIFIED), \"bidirectional=2\")==0\x00" - as *const u8 as *const libc::c_char); - } else { - }; - if 0 != !(strcmp( - b"public=0\x00" as *const u8 as *const libc::c_char, - b"public=0\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, - 499i32, - b"strcmp(\"public=\" DC_STRINGIFY(DC_KEY_PUBLIC), \"public=0\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - b"private=1\x00" as *const u8 as *const libc::c_char, - b"private=1\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, - 500i32, - b"strcmp(\"private=\" DC_STRINGIFY(DC_KEY_PRIVATE), \"private=1\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - if 0 != !('f' as i32 == 'f' as i32) 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, - 502i32, - b"DC_PARAM_FILE == \'f\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !('w' as i32 == 'w' as i32) 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, - 503i32, - b"DC_PARAM_WIDTH == \'w\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !('h' as i32 == 'h' as i32) 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, - 504i32, - b"DC_PARAM_HEIGHT == \'h\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !('d' as i32 == 'd' as i32) 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, - 505i32, - b"DC_PARAM_DURATION == \'d\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !('m' as i32 == 'm' as i32) 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, - 506i32, - b"DC_PARAM_MIMETYPE == \'m\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !('a' as i32 == 'a' as i32) 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, - 507i32, - b"DC_PARAM_FORWARDED == \'a\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !('U' as i32 == 'U' as i32) 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, - 508i32, - b"DC_PARAM_UNPROMOTED == \'U\'\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; + let mut buf1: *mut libc::c_char = 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); @@ -1889,313 +510,6 @@ unsafe fn stress_functions(context: &dc_context_t) { } else { }; free(buf1 as *mut libc::c_void); - buf1 = dc_decode_header_words( - b"=?utf-8?B?dGVzdMOkw7bDvC50eHQ=?=\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - buf1, - b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\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, - 538i32, - b"strcmp(buf1, \"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\")==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_decode_header_words(b"just ascii test\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp( - buf1, - b"just ascii test\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, - 542i32, - b"strcmp(buf1, \"just ascii test\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_encode_header_words(b"abcdef\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp(buf1, b"abcdef\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, - 546i32, - b"strcmp(buf1, \"abcdef\")==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_encode_header_words( - b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strncmp(buf1, b"=?utf-8\x00" as *const u8 as *const libc::c_char, 7) == 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, - 550i32, - b"strncmp(buf1, \"=?utf-8\", 7)==0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - buf2 = dc_decode_header_words(buf1); - if 0 != !(strcmp( - b"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\x00" as *const u8 as *const libc::c_char, - buf2, - ) == 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, - 552i32, - b"strcmp(\"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\", buf2)==0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - free(buf2 as *mut libc::c_void); - buf1 = - dc_decode_header_words(b"=?ISO-8859-1?Q?attachment=3B=0D=0A_filename=3D?= =?ISO-8859-1?Q?=22test=E4=F6=FC=2Etxt=22=3B=0D=0A_size=3D39?=\x00" - as *const u8 as *const libc::c_char); - if 0 != !(strcmp( - buf1, - b"attachment;\r\n filename=\"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\";\r\n size=39\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, 557i32, - b"strcmp(buf1, \"attachment;\\r\\n filename=\\\"test\xc3\xa4\xc3\xb6\xc3\xbc.txt\\\";\\r\\n size=39\")==0\x00" - as *const u8 as *const libc::c_char); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_encode_ext_header(b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp( - buf1, - b"utf-8\'\'Bj%C3%B6rn%20Petersen\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, - 561i32, - b"strcmp(buf1, \"utf-8\'\'Bj%C3%B6rn%20Petersen\") == 0\x00" as *const u8 - as *const libc::c_char, - ); - } else { - }; - buf2 = dc_decode_ext_header(buf1); - if 0 != !(strcmp( - buf2, - b"Bj\xc3\xb6rn Petersen\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, - 563i32, - b"strcmp(buf2, \"Bj\xc3\xb6rn Petersen\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - free(buf2 as *mut libc::c_void); - buf1 = dc_decode_ext_header( - b"iso-8859-1\'en\'%A3%20rates\x00" as *const u8 as *const libc::c_char, - ); - if 0 != !(strcmp( - buf1, - b"\xc2\xa3 rates\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, - 568i32, - b"strcmp(buf1, \"\xc2\xa3 rates\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != !(strcmp( - buf1, - b"\xc2\xa3 rates\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, - 569i32, - b"strcmp(buf1, \"\\xC2\\xA3 rates\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_decode_ext_header(b"wrong\'format\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp( - buf1, - b"wrong\'format\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, - 573i32, - b"strcmp(buf1, \"wrong\'format\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_decode_ext_header(b"\'\'\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp(buf1, b"\'\'\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, - 577i32, - b"strcmp(buf1, \"\'\'\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_decode_ext_header(b"x\'\'\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp(buf1, b"\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, - 581i32, - b"strcmp(buf1, \"\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_decode_ext_header(b"\'\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp(buf1, b"\'\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, - 585i32, - b"strcmp(buf1, \"\'\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - buf1 = dc_decode_ext_header(b"\x00" as *const u8 as *const libc::c_char); - if 0 != !(strcmp(buf1, b"\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, - 589i32, - b"strcmp(buf1, \"\") == 0\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - free(buf1 as *mut libc::c_void); - if 0 != (!dc_needs_ext_header(b"Bj\xc3\xb6rn\x00" as *const u8 as *const libc::c_char)) - 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, - 592i32, - b"dc_needs_ext_header(\"Bj\xc3\xb6rn\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_needs_ext_header(b"Bjoern\x00" as *const u8 as *const libc::c_char)) 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, - 593i32, - b"!dc_needs_ext_header(\"Bjoern\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_needs_ext_header(b"\x00" as *const u8 as *const libc::c_char)) 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, - 594i32, - b"!dc_needs_ext_header(\"\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (!dc_needs_ext_header(b" \x00" as *const u8 as *const libc::c_char)) 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, - 595i32, - b"dc_needs_ext_header(\" \")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (!dc_needs_ext_header(b"a b\x00" as *const u8 as *const libc::c_char)) 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, - 596i32, - b"dc_needs_ext_header(\"a b\")\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; - if 0 != (dc_needs_ext_header(0 as *const libc::c_char)) 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, - 597i32, - b"!dc_needs_ext_header(NULL)\x00" as *const u8 as *const libc::c_char, - ); - } else { - }; buf1 = dc_encode_modified_utf7( b"Bj\xc3\xb6rn Petersen\x00" as *const u8 as *const libc::c_char, 1i32, @@ -4476,21 +2790,130 @@ unsafe extern "C" fn cb( 0 } +#[allow(dead_code)] +struct TestContext { + ctx: dc_context_t, + dir: TempDir, +} + +unsafe fn create_test_context() -> TestContext { + let mut ctx = dc_context_new(cb, std::ptr::null_mut(), std::ptr::null_mut()); + let dir = tempdir().unwrap(); + let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap(); + assert_eq!( + dc_open(&mut ctx, dbfile.as_ptr(), std::ptr::null()), + 1, + "Failed to open {}", + CStr::from_ptr(dbfile.as_ptr() as *const libc::c_char) + .to_str() + .unwrap() + ); + + TestContext { ctx: ctx, dir: dir } +} + #[test] -fn run_stress_tests() { +fn test_dc_kml_parse() { unsafe { - let mut ctx = dc_context_new(cb, std::ptr::null_mut(), std::ptr::null_mut()); - let dir = tempdir().unwrap(); - let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap(); + let context = create_test_context(); + + let xml: *const libc::c_char = + b"\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n\x00" + as *const u8 as *const libc::c_char; + + let kml: *mut dc_kml_t = dc_kml_parse(&context.ctx, xml, strlen(xml)); + + assert!(!(*kml).addr.is_null()); assert_eq!( - dc_open(&mut ctx, dbfile.as_ptr(), std::ptr::null()), - 1, - "Failed to open {}", - CStr::from_ptr(dbfile.as_ptr() as *const libc::c_char) + CStr::from_ptr((*kml).addr as *const libc::c_char) .to_str() - .unwrap() + .unwrap(), + "user@example.org", ); - stress_functions(&ctx) + assert_eq!(dc_array_get_cnt((*kml).locations), 2); + + assert!(dc_array_get_latitude((*kml).locations, 0) > 53.6f64); + assert!(dc_array_get_latitude((*kml).locations, 0) < 53.8f64); + assert!(dc_array_get_longitude((*kml).locations, 0) > 9.3f64); + assert!(dc_array_get_longitude((*kml).locations, 0) < 9.5f64); + assert!(dc_array_get_accuracy((*kml).locations, 0) > 31.9f64); + assert!(dc_array_get_accuracy((*kml).locations, 0) < 32.1f64); + assert_eq!(dc_array_get_timestamp((*kml).locations, 0), 1551906597); + + assert!(dc_array_get_latitude((*kml).locations, 1) > 63.6f64); + assert!(dc_array_get_latitude((*kml).locations, 1) < 63.8f64); + assert!(dc_array_get_longitude((*kml).locations, 1) > 19.3f64); + assert!(dc_array_get_longitude((*kml).locations, 1) < 19.5f64); + assert!(dc_array_get_accuracy((*kml).locations, 1) > 2.4f64); + assert!(dc_array_get_accuracy((*kml).locations, 1) < 2.6f64); + + assert_eq!(dc_array_get_timestamp((*kml).locations, 1), 1544739072); + + dc_kml_unref(kml); + } +} + +#[test] +fn test_dc_mimeparser_with_context() { + unsafe { + let context = create_test_context(); + + let mimeparser: *mut dc_mimeparser_t = dc_mimeparser_new(&context.ctx); + let raw: *const libc::c_char = + b"Content-Type: multipart/mixed; boundary=\"==break==\";\nSubject: outer-subject\nX-Special-A: special-a\nFoo: Bar\nChat-Version: 0.0\n\n--==break==\nContent-Type: text/plain; protected-headers=\"v1\";\nSubject: inner-subject\nX-Special-B: special-b\nFoo: Xy\nChat-Version: 1.0\n\ntest1\n\n--==break==--\n\n\x00" + as *const u8 as *const libc::c_char; + + dc_mimeparser_parse(mimeparser, raw, strlen(raw)); + assert_eq!( + CStr::from_ptr((*mimeparser).subject as *const libc::c_char) + .to_str() + .unwrap(), + "inner-subject", + ); + + let mut of: *mut mailimf_optional_field = dc_mimeparser_lookup_optional_field( + mimeparser, + b"X-Special-A\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr((*of).fld_value as *const libc::c_char) + .to_str() + .unwrap(), + "special-a", + ); + + of = dc_mimeparser_lookup_optional_field( + mimeparser, + b"Foo\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr((*of).fld_value as *const libc::c_char) + .to_str() + .unwrap(), + "Bar", + ); + + of = dc_mimeparser_lookup_optional_field( + mimeparser, + b"Chat-Version\x00" as *const u8 as *const libc::c_char, + ); + assert_eq!( + CStr::from_ptr((*of).fld_value as *const libc::c_char) + .to_str() + .unwrap(), + "1.0", + ); + assert_eq!(carray_count((*mimeparser).parts), 1); + + dc_mimeparser_unref(mimeparser); + } +} + +#[test] +fn test_stress_tests() { + unsafe { + let context = create_test_context(); + stress_functions(&context.ctx); } }