Skip to content

Commit 0000f0d

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 a82c2e7 commit 0000f0d

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
@@ -1445,6 +1445,7 @@ pub fn dc_update_server_uid(
14451445
#[cfg(test)]
14461446
mod tests {
14471447
use super::*;
1448+
use crate::test_utils as test;
14481449
use std::ffi::CStr;
14491450

14501451
#[test]
@@ -1565,4 +1566,36 @@ mod tests {
15651566
free(mime_0 as *mut libc::c_void);
15661567
}
15671568
}
1569+
1570+
#[test]
1571+
pub fn test_prepare_message_and_send() {
1572+
use crate::config::Config;
1573+
1574+
unsafe {
1575+
let d = test::dummy_context();
1576+
let ctx = &d.ctx;
1577+
1578+
let contact = dc_create_contact(
1579+
ctx,
1580+
b"\x00".as_ptr().cast(),
1581+
b"dest@example.com\x00".as_ptr().cast(),
1582+
);
1583+
assert!(contact != 0);
1584+
1585+
let res = ctx.set_config(Config::ConfiguredAddr, Some("self@example.com"));
1586+
assert!(res.is_ok());
1587+
1588+
let chat = dc_create_chat_by_contact_id(ctx, contact);
1589+
assert!(chat != 0);
1590+
1591+
let msg = dc_msg_new(ctx, Viewtype::Text);
1592+
assert!(!msg.is_null());
1593+
1594+
let msg_id = dc_prepare_msg(ctx, chat, msg);
1595+
assert!(msg_id != 0);
1596+
1597+
let msg2 = dc_get_msg(ctx, msg_id);
1598+
assert!(!msg2.is_null());
1599+
}
1600+
}
15681601
}

0 commit comments

Comments
 (0)