Skip to content

Commit 2054cd0

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 1d534ff commit 2054cd0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/dc_chat.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
124124
return false;
125125
}
126126
unsafe { dc_chat_empty(chat) };
127+
dbg!("loading chat", chat_id);
127128

128129
let context = unsafe { (*chat).context };
129130

@@ -389,6 +390,7 @@ unsafe fn prepare_msg_common<'a>(
389390
let mut OK_TO_CONTINUE = true;
390391
(*msg).id = 0i32 as uint32_t;
391392
(*msg).context = context;
393+
dbg!("prepare_msg_common");
392394
if (*msg).type_0 == Viewtype::Text {
393395
/* the caller should check if the message text is empty */
394396
} else if msgtype_has_file((*msg).type_0) {
@@ -461,10 +463,13 @@ unsafe fn prepare_msg_common<'a>(
461463
);
462464
OK_TO_CONTINUE = false;
463465
}
466+
dbg!(OK_TO_CONTINUE);
464467
if OK_TO_CONTINUE {
468+
dbg!();
465469
dc_unarchive_chat(context, chat_id);
466470
let chat = dc_chat_new(context);
467471
if dc_chat_load_from_db(chat, chat_id) {
472+
dbg!("chat loaded");
468473
if (*msg).state != DC_STATE_OUT_PREPARING {
469474
(*msg).state = DC_STATE_OUT_PENDING
470475
}
@@ -712,6 +717,7 @@ unsafe fn prepare_msg_raw(
712717
}
713718

714719
// add message to the database
720+
dbg!("SQL insert");
715721

716722
if sql::execute(
717723
context,

src/dc_msg.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ pub fn dc_update_server_uid(
14411441
mod tests {
14421442
use super::*;
14431443
use std::ffi::CStr;
1444+
use crate::test_utils as test;
14441445

14451446
#[test]
14461447
fn test_dc_msg_guess_msgtype_from_suffix() {
@@ -1560,4 +1561,33 @@ mod tests {
15601561
free(mime_0 as *mut libc::c_void);
15611562
}
15621563
}
1564+
1565+
#[test]
1566+
pub fn test_prepare_message_and_send() {
1567+
use crate::config::Config;
1568+
1569+
unsafe {
1570+
let d = test::dummy_context();
1571+
let ctx = &d.ctx;
1572+
dbg!(&d.dir);
1573+
1574+
let contact = dc_create_contact(ctx, b"\x00".as_ptr().cast(), b"[email protected]\x00".as_ptr().cast());
1575+
assert!(contact != 0);
1576+
1577+
let res = ctx.set_config(Config::ConfiguredAddr, Some("[email protected]"));
1578+
assert!(res.is_ok());
1579+
1580+
let chat = dc_create_chat_by_contact_id(ctx, contact);
1581+
assert!(chat != 0);
1582+
1583+
let msg = dc_msg_new(ctx, Viewtype::Text);
1584+
assert!(!msg.is_null());
1585+
1586+
let msg_id = dc_prepare_msg(ctx, chat, msg);
1587+
assert!(msg_id != 0);
1588+
1589+
let msg2 = dc_get_msg(ctx, msg_id);
1590+
assert!(!msg2.is_null());
1591+
}
1592+
}
15631593
}

0 commit comments

Comments
 (0)