Skip to content

Commit 3c00ed7

Browse files
Dmitry BogatovDmitry Bogatov
authored andcommitted
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.
1 parent 5811248 commit 3c00ed7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/dc_msg.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,7 @@ pub fn dc_update_server_uid(
14261426
#[cfg(test)]
14271427
mod tests {
14281428
use super::*;
1429+
use crate::test_utils as test;
14291430
use std::ffi::CStr;
14301431

14311432
#[test]
@@ -1546,4 +1547,36 @@ mod tests {
15461547
free(mime_0 as *mut libc::c_void);
15471548
}
15481549
}
1550+
1551+
#[test]
1552+
pub fn test_prepare_message_and_send() {
1553+
use crate::config::Config;
1554+
1555+
unsafe {
1556+
let d = test::dummy_context();
1557+
let ctx = &d.ctx;
1558+
1559+
let contact = dc_create_contact(
1560+
ctx,
1561+
b"\x00".as_ptr().cast(),
1562+
b"[email protected]\x00".as_ptr().cast(),
1563+
);
1564+
assert!(contact != 0);
1565+
1566+
let res = ctx.set_config(Config::ConfiguredAddr, Some("[email protected]"));
1567+
assert!(res.is_ok());
1568+
1569+
let chat = dc_create_chat_by_contact_id(ctx, contact);
1570+
assert!(chat != 0);
1571+
1572+
let msg = dc_msg_new(ctx, Viewtype::Text);
1573+
assert!(!msg.is_null());
1574+
1575+
let msg_id = dc_prepare_msg(ctx, chat, msg);
1576+
assert!(msg_id != 0);
1577+
1578+
let msg2 = dc_get_msg(ctx, msg_id);
1579+
assert!(!msg2.is_null());
1580+
}
1581+
}
15491582
}

0 commit comments

Comments
 (0)