From d4650ba4a984ca81333deaa8064971a361e311dc Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sun, 4 Aug 2019 13:34:42 +0000 Subject: [PATCH] Add Rust clone of python `prepare_and_send' test Previous version of patch, that changed type of `dc_msg_t.text' to String had been breaking `prepare_and_send' test in Python. This commit adds same regression test, reimplemented in Rust, since running Rust tests is simplier and faster. --- src/dc_msg.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/dc_msg.rs b/src/dc_msg.rs index 596347610..b0d8bb731 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -1426,6 +1426,7 @@ pub fn dc_update_server_uid( #[cfg(test)] mod tests { use super::*; + use crate::test_utils as test; use std::ffi::CStr; #[test] @@ -1546,4 +1547,36 @@ mod tests { free(mime_0 as *mut libc::c_void); } } + + #[test] + pub fn test_prepare_message_and_send() { + use crate::config::Config; + + unsafe { + let d = test::dummy_context(); + let ctx = &d.ctx; + + let contact = dc_create_contact( + ctx, + b"\x00".as_ptr().cast(), + b"dest@example.com\x00".as_ptr().cast(), + ); + assert!(contact != 0); + + let res = ctx.set_config(Config::ConfiguredAddr, Some("self@example.com")); + assert!(res.is_ok()); + + let chat = dc_create_chat_by_contact_id(ctx, contact); + assert!(chat != 0); + + let msg = dc_msg_new(ctx, Viewtype::Text); + assert!(!msg.is_null()); + + let msg_id = dc_prepare_msg(ctx, chat, msg); + assert!(msg_id != 0); + + let msg2 = dc_get_msg(ctx, msg_id); + assert!(!msg2.is_null()); + } + } }