Replace all t.ctx with t

Not sure if that's the way to go because, you know, merge conflicts, but
we could do this now.
This commit is contained in:
Hocuri
2020-12-17 18:50:29 +01:00
parent af8a6d7722
commit 4d2c2130e8
20 changed files with 530 additions and 632 deletions

View File

@@ -525,18 +525,18 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_create() { async fn test_create() {
let t = TestContext::new().await; let t = TestContext::new().await;
let blob = BlobObject::create(&t.ctx, "foo", b"hello").await.unwrap(); let blob = BlobObject::create(&t, "foo", b"hello").await.unwrap();
let fname = t.ctx.get_blobdir().join("foo"); let fname = t.get_blobdir().join("foo");
let data = fs::read(fname).await.unwrap(); let data = fs::read(fname).await.unwrap();
assert_eq!(data, b"hello"); assert_eq!(data, b"hello");
assert_eq!(blob.as_name(), "$BLOBDIR/foo"); assert_eq!(blob.as_name(), "$BLOBDIR/foo");
assert_eq!(blob.to_abs_path(), t.ctx.get_blobdir().join("foo")); assert_eq!(blob.to_abs_path(), t.get_blobdir().join("foo"));
} }
#[async_std::test] #[async_std::test]
async fn test_lowercase_ext() { async fn test_lowercase_ext() {
let t = TestContext::new().await; let t = TestContext::new().await;
let blob = BlobObject::create(&t.ctx, "foo.TXT", b"hello") let blob = BlobObject::create(&t, "foo.TXT", b"hello")
.await .await
.unwrap(); .unwrap();
assert_eq!(blob.as_name(), "$BLOBDIR/foo.txt"); assert_eq!(blob.as_name(), "$BLOBDIR/foo.txt");
@@ -545,7 +545,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_as_file_name() { async fn test_as_file_name() {
let t = TestContext::new().await; let t = TestContext::new().await;
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello") let blob = BlobObject::create(&t, "foo.txt", b"hello")
.await .await
.unwrap(); .unwrap();
assert_eq!(blob.as_file_name(), "foo.txt"); assert_eq!(blob.as_file_name(), "foo.txt");
@@ -554,7 +554,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_as_rel_path() { async fn test_as_rel_path() {
let t = TestContext::new().await; let t = TestContext::new().await;
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello") let blob = BlobObject::create(&t, "foo.txt", b"hello")
.await .await
.unwrap(); .unwrap();
assert_eq!(blob.as_rel_path(), Path::new("foo.txt")); assert_eq!(blob.as_rel_path(), Path::new("foo.txt"));
@@ -563,26 +563,26 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_suffix() { async fn test_suffix() {
let t = TestContext::new().await; let t = TestContext::new().await;
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello") let blob = BlobObject::create(&t, "foo.txt", b"hello")
.await .await
.unwrap(); .unwrap();
assert_eq!(blob.suffix(), Some("txt")); assert_eq!(blob.suffix(), Some("txt"));
let blob = BlobObject::create(&t.ctx, "bar", b"world").await.unwrap(); let blob = BlobObject::create(&t, "bar", b"world").await.unwrap();
assert_eq!(blob.suffix(), None); assert_eq!(blob.suffix(), None);
} }
#[async_std::test] #[async_std::test]
async fn test_create_dup() { async fn test_create_dup() {
let t = TestContext::new().await; let t = TestContext::new().await;
BlobObject::create(&t.ctx, "foo.txt", b"hello") BlobObject::create(&t, "foo.txt", b"hello")
.await .await
.unwrap(); .unwrap();
let foo_path = t.ctx.get_blobdir().join("foo.txt"); let foo_path = t.get_blobdir().join("foo.txt");
assert!(foo_path.exists().await); assert!(foo_path.exists().await);
BlobObject::create(&t.ctx, "foo.txt", b"world") BlobObject::create(&t, "foo.txt", b"world")
.await .await
.unwrap(); .unwrap();
let mut dir = fs::read_dir(t.ctx.get_blobdir()).await.unwrap(); let mut dir = fs::read_dir(t.get_blobdir()).await.unwrap();
while let Some(dirent) = dir.next().await { while let Some(dirent) = dir.next().await {
let fname = dirent.unwrap().file_name(); let fname = dirent.unwrap().file_name();
if fname == foo_path.file_name().unwrap() { if fname == foo_path.file_name().unwrap() {
@@ -598,15 +598,15 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_double_ext_preserved() { async fn test_double_ext_preserved() {
let t = TestContext::new().await; let t = TestContext::new().await;
BlobObject::create(&t.ctx, "foo.tar.gz", b"hello") BlobObject::create(&t, "foo.tar.gz", b"hello")
.await .await
.unwrap(); .unwrap();
let foo_path = t.ctx.get_blobdir().join("foo.tar.gz"); let foo_path = t.get_blobdir().join("foo.tar.gz");
assert!(foo_path.exists().await); assert!(foo_path.exists().await);
BlobObject::create(&t.ctx, "foo.tar.gz", b"world") BlobObject::create(&t, "foo.tar.gz", b"world")
.await .await
.unwrap(); .unwrap();
let mut dir = fs::read_dir(t.ctx.get_blobdir()).await.unwrap(); let mut dir = fs::read_dir(t.get_blobdir()).await.unwrap();
while let Some(dirent) = dir.next().await { while let Some(dirent) = dir.next().await {
let fname = dirent.unwrap().file_name(); let fname = dirent.unwrap().file_name();
if fname == foo_path.file_name().unwrap() { if fname == foo_path.file_name().unwrap() {
@@ -624,7 +624,7 @@ mod tests {
async fn test_create_long_names() { async fn test_create_long_names() {
let t = TestContext::new().await; let t = TestContext::new().await;
let s = "1".repeat(150); let s = "1".repeat(150);
let blob = BlobObject::create(&t.ctx, &s, b"data").await.unwrap(); let blob = BlobObject::create(&t, &s, b"data").await.unwrap();
let blobname = blob.as_name().split('/').last().unwrap(); let blobname = blob.as_name().split('/').last().unwrap();
assert!(blobname.len() < 128); assert!(blobname.len() < 128);
} }
@@ -634,14 +634,14 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let src = t.dir.path().join("src"); let src = t.dir.path().join("src");
fs::write(&src, b"boo").await.unwrap(); fs::write(&src, b"boo").await.unwrap();
let blob = BlobObject::create_and_copy(&t.ctx, &src).await.unwrap(); let blob = BlobObject::create_and_copy(&t, &src).await.unwrap();
assert_eq!(blob.as_name(), "$BLOBDIR/src"); assert_eq!(blob.as_name(), "$BLOBDIR/src");
let data = fs::read(blob.to_abs_path()).await.unwrap(); let data = fs::read(blob.to_abs_path()).await.unwrap();
assert_eq!(data, b"boo"); assert_eq!(data, b"boo");
let whoops = t.dir.path().join("whoops"); let whoops = t.dir.path().join("whoops");
assert!(BlobObject::create_and_copy(&t.ctx, &whoops).await.is_err()); assert!(BlobObject::create_and_copy(&t, &whoops).await.is_err());
let whoops = t.ctx.get_blobdir().join("whoops"); let whoops = t.get_blobdir().join("whoops");
assert!(!whoops.exists().await); assert!(!whoops.exists().await);
} }
@@ -651,14 +651,14 @@ mod tests {
let src_ext = t.dir.path().join("external"); let src_ext = t.dir.path().join("external");
fs::write(&src_ext, b"boo").await.unwrap(); fs::write(&src_ext, b"boo").await.unwrap();
let blob = BlobObject::new_from_path(&t.ctx, &src_ext).await.unwrap(); let blob = BlobObject::new_from_path(&t, &src_ext).await.unwrap();
assert_eq!(blob.as_name(), "$BLOBDIR/external"); assert_eq!(blob.as_name(), "$BLOBDIR/external");
let data = fs::read(blob.to_abs_path()).await.unwrap(); let data = fs::read(blob.to_abs_path()).await.unwrap();
assert_eq!(data, b"boo"); assert_eq!(data, b"boo");
let src_int = t.ctx.get_blobdir().join("internal"); let src_int = t.get_blobdir().join("internal");
fs::write(&src_int, b"boo").await.unwrap(); fs::write(&src_int, b"boo").await.unwrap();
let blob = BlobObject::new_from_path(&t.ctx, &src_int).await.unwrap(); let blob = BlobObject::new_from_path(&t, &src_int).await.unwrap();
assert_eq!(blob.as_name(), "$BLOBDIR/internal"); assert_eq!(blob.as_name(), "$BLOBDIR/internal");
let data = fs::read(blob.to_abs_path()).await.unwrap(); let data = fs::read(blob.to_abs_path()).await.unwrap();
assert_eq!(data, b"boo"); assert_eq!(data, b"boo");
@@ -668,7 +668,7 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let src_ext = t.dir.path().join("autocrypt-setup-message-4137848473.html"); let src_ext = t.dir.path().join("autocrypt-setup-message-4137848473.html");
fs::write(&src_ext, b"boo").await.unwrap(); fs::write(&src_ext, b"boo").await.unwrap();
let blob = BlobObject::new_from_path(&t.ctx, &src_ext).await.unwrap(); let blob = BlobObject::new_from_path(&t, &src_ext).await.unwrap();
assert_eq!( assert_eq!(
blob.as_name(), blob.as_name(),
"$BLOBDIR/autocrypt-setup-message-4137848473.html" "$BLOBDIR/autocrypt-setup-message-4137848473.html"

View File

@@ -2977,7 +2977,7 @@ mod tests {
async fn test_chat_info() { async fn test_chat_info() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat = t.chat_with_contact("bob", "bob@example.com").await; let chat = t.chat_with_contact("bob", "bob@example.com").await;
let info = chat.get_info(&t.ctx).await.unwrap(); let info = chat.get_info(&t).await.unwrap();
// Ensure we can serialize this. // Ensure we can serialize this.
println!("{}", serde_json::to_string_pretty(&info).unwrap()); println!("{}", serde_json::to_string_pretty(&info).unwrap());
@@ -3008,7 +3008,7 @@ mod tests {
async fn test_get_draft_no_draft() { async fn test_get_draft_no_draft() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat = t.get_self_chat().await; let chat = t.get_self_chat().await;
let draft = chat.id.get_draft(&t.ctx).await.unwrap(); let draft = chat.id.get_draft(&t).await.unwrap();
assert!(draft.is_none()); assert!(draft.is_none());
} }
@@ -3016,7 +3016,7 @@ mod tests {
async fn test_get_draft_special_chat_id() { async fn test_get_draft_special_chat_id() {
let t = TestContext::new().await; let t = TestContext::new().await;
let draft = ChatId::new(DC_CHAT_ID_LAST_SPECIAL) let draft = ChatId::new(DC_CHAT_ID_LAST_SPECIAL)
.get_draft(&t.ctx) .get_draft(&t)
.await .await
.unwrap(); .unwrap();
assert!(draft.is_none()); assert!(draft.is_none());
@@ -3027,7 +3027,7 @@ mod tests {
// This is a weird case, maybe this should be an error but we // This is a weird case, maybe this should be an error but we
// do not get this info from the database currently. // do not get this info from the database currently.
let t = TestContext::new().await; let t = TestContext::new().await;
let draft = ChatId::new(42).get_draft(&t.ctx).await.unwrap(); let draft = ChatId::new(42).get_draft(&t).await.unwrap();
assert!(draft.is_none()); assert!(draft.is_none());
} }
@@ -3037,8 +3037,8 @@ mod tests {
let chat_id = &t.get_self_chat().await.id; let chat_id = &t.get_self_chat().await.id;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string())); msg.set_text(Some("hello".to_string()));
chat_id.set_draft(&t.ctx, Some(&mut msg)).await; chat_id.set_draft(&t, Some(&mut msg)).await;
let draft = chat_id.get_draft(&t.ctx).await.unwrap().unwrap(); let draft = chat_id.get_draft(&t).await.unwrap().unwrap();
let msg_text = msg.get_text(); let msg_text = msg.get_text();
let draft_text = draft.get_text(); let draft_text = draft.get_text();
assert_eq!(msg_text, draft_text); assert_eq!(msg_text, draft_text);
@@ -3048,10 +3048,10 @@ mod tests {
async fn test_add_contact_to_chat_ex_add_self() { async fn test_add_contact_to_chat_ex_add_self() {
// Adding self to a contact should succeed, even though it's pointless. // Adding self to a contact should succeed, even though it's pointless.
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
let added = add_contact_to_chat_ex(&t.ctx, chat_id, DC_CONTACT_ID_SELF, false) let added = add_contact_to_chat_ex(&t, chat_id, DC_CONTACT_ID_SELF, false)
.await .await
.unwrap(); .unwrap();
assert_eq!(added, false); assert_eq!(added, false);
@@ -3067,17 +3067,14 @@ mod tests {
assert!(chat.visibility == ChatVisibility::Normal); assert!(chat.visibility == ChatVisibility::Normal);
assert!(!chat.is_device_talk()); assert!(!chat.is_device_talk());
assert!(chat.can_send()); assert!(chat.can_send());
assert_eq!( assert_eq!(chat.name, t.stock_str(StockMessage::SavedMessages).await);
chat.name, assert!(chat.get_profile_image(&t).await.is_some());
t.ctx.stock_str(StockMessage::SavedMessages).await
);
assert!(chat.get_profile_image(&t.ctx).await.is_some());
} }
#[async_std::test] #[async_std::test]
async fn test_deaddrop_chat() { async fn test_deaddrop_chat() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat = Chat::load_from_db(&t.ctx, ChatId::new(DC_CHAT_ID_DEADDROP)) let chat = Chat::load_from_db(&t, ChatId::new(DC_CHAT_ID_DEADDROP))
.await .await
.unwrap(); .unwrap();
assert_eq!(DC_CHAT_ID_DEADDROP, 1); assert_eq!(DC_CHAT_ID_DEADDROP, 1);
@@ -3086,7 +3083,7 @@ mod tests {
assert!(chat.visibility == ChatVisibility::Normal); assert!(chat.visibility == ChatVisibility::Normal);
assert!(!chat.is_device_talk()); assert!(!chat.is_device_talk());
assert!(!chat.can_send()); assert!(!chat.can_send());
assert_eq!(chat.name, t.ctx.stock_str(StockMessage::DeadDrop).await); assert_eq!(chat.name, t.stock_str(StockMessage::DeadDrop).await);
} }
#[async_std::test] #[async_std::test]
@@ -3096,17 +3093,17 @@ mod tests {
// add two device-messages // add two device-messages
let mut msg1 = Message::new(Viewtype::Text); let mut msg1 = Message::new(Viewtype::Text);
msg1.text = Some("first message".to_string()); msg1.text = Some("first message".to_string());
let msg1_id = add_device_msg(&t.ctx, None, Some(&mut msg1)).await; let msg1_id = add_device_msg(&t, None, Some(&mut msg1)).await;
assert!(msg1_id.is_ok()); assert!(msg1_id.is_ok());
let mut msg2 = Message::new(Viewtype::Text); let mut msg2 = Message::new(Viewtype::Text);
msg2.text = Some("second message".to_string()); msg2.text = Some("second message".to_string());
let msg2_id = add_device_msg(&t.ctx, None, Some(&mut msg2)).await; let msg2_id = add_device_msg(&t, None, Some(&mut msg2)).await;
assert!(msg2_id.is_ok()); assert!(msg2_id.is_ok());
assert_ne!(msg1_id.as_ref().unwrap(), msg2_id.as_ref().unwrap()); assert_ne!(msg1_id.as_ref().unwrap(), msg2_id.as_ref().unwrap());
// check added messages // check added messages
let msg1 = message::Message::load_from_db(&t.ctx, msg1_id.unwrap()).await; let msg1 = message::Message::load_from_db(&t, msg1_id.unwrap()).await;
assert!(msg1.is_ok()); assert!(msg1.is_ok());
let msg1 = msg1.unwrap(); let msg1 = msg1.unwrap();
assert_eq!(msg1.text.as_ref().unwrap(), "first message"); assert_eq!(msg1.text.as_ref().unwrap(), "first message");
@@ -3115,13 +3112,13 @@ mod tests {
assert!(!msg1.is_info()); assert!(!msg1.is_info());
assert!(!msg1.is_setupmessage()); assert!(!msg1.is_setupmessage());
let msg2 = message::Message::load_from_db(&t.ctx, msg2_id.unwrap()).await; let msg2 = message::Message::load_from_db(&t, msg2_id.unwrap()).await;
assert!(msg2.is_ok()); assert!(msg2.is_ok());
let msg2 = msg2.unwrap(); let msg2 = msg2.unwrap();
assert_eq!(msg2.text.as_ref().unwrap(), "second message"); assert_eq!(msg2.text.as_ref().unwrap(), "second message");
// check device chat // check device chat
assert_eq!(msg2.chat_id.get_msg_cnt(&t.ctx).await, 2); assert_eq!(msg2.chat_id.get_msg_cnt(&t).await, 2);
} }
#[async_std::test] #[async_std::test]
@@ -3131,18 +3128,18 @@ mod tests {
// add two device-messages with the same label (second attempt is not added) // add two device-messages with the same label (second attempt is not added)
let mut msg1 = Message::new(Viewtype::Text); let mut msg1 = Message::new(Viewtype::Text);
msg1.text = Some("first message".to_string()); msg1.text = Some("first message".to_string());
let msg1_id = add_device_msg(&t.ctx, Some("any-label"), Some(&mut msg1)).await; let msg1_id = add_device_msg(&t, Some("any-label"), Some(&mut msg1)).await;
assert!(msg1_id.is_ok()); assert!(msg1_id.is_ok());
assert!(!msg1_id.as_ref().unwrap().is_unset()); assert!(!msg1_id.as_ref().unwrap().is_unset());
let mut msg2 = Message::new(Viewtype::Text); let mut msg2 = Message::new(Viewtype::Text);
msg2.text = Some("second message".to_string()); msg2.text = Some("second message".to_string());
let msg2_id = add_device_msg(&t.ctx, Some("any-label"), Some(&mut msg2)).await; let msg2_id = add_device_msg(&t, Some("any-label"), Some(&mut msg2)).await;
assert!(msg2_id.is_ok()); assert!(msg2_id.is_ok());
assert!(msg2_id.as_ref().unwrap().is_unset()); assert!(msg2_id.as_ref().unwrap().is_unset());
// check added message // check added message
let msg1 = message::Message::load_from_db(&t.ctx, *msg1_id.as_ref().unwrap()).await; let msg1 = message::Message::load_from_db(&t, *msg1_id.as_ref().unwrap()).await;
assert!(msg1.is_ok()); assert!(msg1.is_ok());
let msg1 = msg1.unwrap(); let msg1 = msg1.unwrap();
assert_eq!(msg1_id.as_ref().unwrap(), &msg1.id); assert_eq!(msg1_id.as_ref().unwrap(), &msg1.id);
@@ -3154,26 +3151,23 @@ mod tests {
// check device chat // check device chat
let chat_id = msg1.chat_id; let chat_id = msg1.chat_id;
assert_eq!(chat_id.get_msg_cnt(&t.ctx).await, 1); assert_eq!(chat_id.get_msg_cnt(&t).await, 1);
assert!(!chat_id.is_special()); assert!(!chat_id.is_special());
let chat = Chat::load_from_db(&t.ctx, chat_id).await; let chat = Chat::load_from_db(&t, chat_id).await;
assert!(chat.is_ok()); assert!(chat.is_ok());
let chat = chat.unwrap(); let chat = chat.unwrap();
assert_eq!(chat.get_type(), Chattype::Single); assert_eq!(chat.get_type(), Chattype::Single);
assert!(chat.is_device_talk()); assert!(chat.is_device_talk());
assert!(!chat.is_self_talk()); assert!(!chat.is_self_talk());
assert!(!chat.can_send()); assert!(!chat.can_send());
assert_eq!( assert_eq!(chat.name, t.stock_str(StockMessage::DeviceMessages).await);
chat.name, assert!(chat.get_profile_image(&t).await.is_some());
t.ctx.stock_str(StockMessage::DeviceMessages).await
);
assert!(chat.get_profile_image(&t.ctx).await.is_some());
// delete device message, make sure it is not added again // delete device message, make sure it is not added again
message::delete_msgs(&t.ctx, &[*msg1_id.as_ref().unwrap()]).await; message::delete_msgs(&t, &[*msg1_id.as_ref().unwrap()]).await;
let msg1 = message::Message::load_from_db(&t.ctx, *msg1_id.as_ref().unwrap()).await; let msg1 = message::Message::load_from_db(&t, *msg1_id.as_ref().unwrap()).await;
assert!(msg1.is_err() || msg1.unwrap().chat_id.is_trash()); assert!(msg1.is_err() || msg1.unwrap().chat_id.is_trash());
let msg3_id = add_device_msg(&t.ctx, Some("any-label"), Some(&mut msg2)).await; let msg3_id = add_device_msg(&t, Some("any-label"), Some(&mut msg2)).await;
assert!(msg3_id.is_ok()); assert!(msg3_id.is_ok());
assert!(msg2_id.as_ref().unwrap().is_unset()); assert!(msg2_id.as_ref().unwrap().is_unset());
} }
@@ -3181,19 +3175,19 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_add_device_msg_label_only() { async fn test_add_device_msg_label_only() {
let t = TestContext::new().await; let t = TestContext::new().await;
let res = add_device_msg(&t.ctx, Some(""), None).await; let res = add_device_msg(&t, Some(""), None).await;
assert!(res.is_err()); assert!(res.is_err());
let res = add_device_msg(&t.ctx, Some("some-label"), None).await; let res = add_device_msg(&t, Some("some-label"), None).await;
assert!(res.is_ok()); assert!(res.is_ok());
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.text = Some("message text".to_string());
let msg_id = add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)).await; let msg_id = add_device_msg(&t, Some("some-label"), Some(&mut msg)).await;
assert!(msg_id.is_ok()); assert!(msg_id.is_ok());
assert!(msg_id.as_ref().unwrap().is_unset()); assert!(msg_id.as_ref().unwrap().is_unset());
let msg_id = add_device_msg(&t.ctx, Some("unused-label"), Some(&mut msg)).await; let msg_id = add_device_msg(&t, Some("unused-label"), Some(&mut msg)).await;
assert!(msg_id.is_ok()); assert!(msg_id.is_ok());
assert!(!msg_id.as_ref().unwrap().is_unset()); assert!(!msg_id.as_ref().unwrap().is_unset());
} }
@@ -3201,25 +3195,21 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_was_device_msg_ever_added() { async fn test_was_device_msg_ever_added() {
let t = TestContext::new().await; let t = TestContext::new().await;
add_device_msg(&t.ctx, Some("some-label"), None).await.ok(); add_device_msg(&t, Some("some-label"), None).await.ok();
assert!(was_device_msg_ever_added(&t.ctx, "some-label") assert!(was_device_msg_ever_added(&t, "some-label").await.unwrap());
.await
.unwrap());
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.text = Some("message text".to_string());
add_device_msg(&t.ctx, Some("another-label"), Some(&mut msg)) add_device_msg(&t, Some("another-label"), Some(&mut msg))
.await .await
.ok(); .ok();
assert!(was_device_msg_ever_added(&t.ctx, "another-label") assert!(was_device_msg_ever_added(&t, "another-label")
.await .await
.unwrap()); .unwrap());
assert!(!was_device_msg_ever_added(&t.ctx, "unused-label") assert!(!was_device_msg_ever_added(&t, "unused-label").await.unwrap());
.await
.unwrap());
assert!(was_device_msg_ever_added(&t.ctx, "").await.is_err()); assert!(was_device_msg_ever_added(&t, "").await.is_err());
} }
#[async_std::test] #[async_std::test]
@@ -3228,38 +3218,36 @@ mod tests {
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.text = Some("message text".to_string());
add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)) add_device_msg(&t, Some("some-label"), Some(&mut msg))
.await .await
.ok(); .ok();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
// after the device-chat and all messages are deleted, a re-adding should do nothing // after the device-chat and all messages are deleted, a re-adding should do nothing
chats.get_chat_id(0).delete(&t.ctx).await.ok(); chats.get_chat_id(0).delete(&t).await.ok();
add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)) add_device_msg(&t, Some("some-label"), Some(&mut msg))
.await .await
.ok(); .ok();
assert_eq!(chatlist_len(&t.ctx, 0).await, 0) assert_eq!(chatlist_len(&t, 0).await, 0)
} }
#[async_std::test] #[async_std::test]
async fn test_device_chat_cannot_sent() { async fn test_device_chat_cannot_sent() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx.update_device_chats().await.unwrap(); t.update_device_chats().await.unwrap();
let (device_chat_id, _) = let (device_chat_id, _) =
create_or_lookup_by_contact_id(&t.ctx, DC_CONTACT_ID_DEVICE, Blocked::Not) create_or_lookup_by_contact_id(&t, DC_CONTACT_ID_DEVICE, Blocked::Not)
.await .await
.unwrap(); .unwrap();
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.text = Some("message text".to_string());
assert!(send_msg(&t.ctx, device_chat_id, &mut msg).await.is_err()); assert!(send_msg(&t, device_chat_id, &mut msg).await.is_err());
assert!(prepare_msg(&t.ctx, device_chat_id, &mut msg).await.is_err()); assert!(prepare_msg(&t, device_chat_id, &mut msg).await.is_err());
let msg_id = add_device_msg(&t.ctx, None, Some(&mut msg)).await.unwrap(); let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap();
assert!(forward_msgs(&t.ctx, &[msg_id], device_chat_id) assert!(forward_msgs(&t, &[msg_id], device_chat_id).await.is_err());
.await
.is_err());
} }
#[async_std::test] #[async_std::test]
@@ -3267,25 +3255,21 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("message text".to_string()); msg.text = Some("message text".to_string());
let msg_id1 = add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)) let msg_id1 = add_device_msg(&t, Some("some-label"), Some(&mut msg))
.await .await
.unwrap(); .unwrap();
// adding a device message with the same label won't be executed again ... // adding a device message with the same label won't be executed again ...
assert!(was_device_msg_ever_added(&t.ctx, "some-label") assert!(was_device_msg_ever_added(&t, "some-label").await.unwrap());
.await let msg_id2 = add_device_msg(&t, Some("some-label"), Some(&mut msg))
.unwrap());
let msg_id2 = add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg))
.await .await
.unwrap(); .unwrap();
assert!(msg_id2.is_unset()); assert!(msg_id2.is_unset());
// ... unless everything is deleted and resetted - as needed eg. on device switch // ... unless everything is deleted and resetted - as needed eg. on device switch
delete_and_reset_all_device_msgs(&t.ctx).await.unwrap(); delete_and_reset_all_device_msgs(&t).await.unwrap();
assert!(!was_device_msg_ever_added(&t.ctx, "some-label") assert!(!was_device_msg_ever_added(&t, "some-label").await.unwrap());
.await let msg_id3 = add_device_msg(&t, Some("some-label"), Some(&mut msg))
.unwrap());
let msg_id3 = add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg))
.await .await
.unwrap(); .unwrap();
assert_ne!(msg_id1, msg_id3); assert_ne!(msg_id1, msg_id3);
@@ -3304,100 +3288,100 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("foo".to_string()); msg.text = Some("foo".to_string());
let msg_id = add_device_msg(&t.ctx, None, Some(&mut msg)).await.unwrap(); let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap();
let chat_id1 = message::Message::load_from_db(&t.ctx, msg_id) let chat_id1 = message::Message::load_from_db(&t, msg_id)
.await .await
.unwrap() .unwrap()
.chat_id; .chat_id;
let chat_id2 = t.get_self_chat().await.id; let chat_id2 = t.get_self_chat().await.id;
assert!(!chat_id1.is_special()); assert!(!chat_id1.is_special());
assert!(!chat_id2.is_special()); assert!(!chat_id2.is_special());
assert_eq!(get_chat_cnt(&t.ctx).await, 2); assert_eq!(get_chat_cnt(&t).await, 2);
assert_eq!(chatlist_len(&t.ctx, 0).await, 2); assert_eq!(chatlist_len(&t, 0).await, 2);
assert_eq!(chatlist_len(&t.ctx, DC_GCL_NO_SPECIALS).await, 2); assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 2);
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY).await, 0); assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 0);
assert_eq!(DC_GCL_ARCHIVED_ONLY, 0x01); assert_eq!(DC_GCL_ARCHIVED_ONLY, 0x01);
assert_eq!(DC_GCL_NO_SPECIALS, 0x02); assert_eq!(DC_GCL_NO_SPECIALS, 0x02);
// archive first chat // archive first chat
assert!(chat_id1 assert!(chat_id1
.set_visibility(&t.ctx, ChatVisibility::Archived) .set_visibility(&t, ChatVisibility::Archived)
.await .await
.is_ok()); .is_ok());
assert!( assert!(
Chat::load_from_db(&t.ctx, chat_id1) Chat::load_from_db(&t, chat_id1)
.await .await
.unwrap() .unwrap()
.get_visibility() .get_visibility()
== ChatVisibility::Archived == ChatVisibility::Archived
); );
assert!( assert!(
Chat::load_from_db(&t.ctx, chat_id2) Chat::load_from_db(&t, chat_id2)
.await .await
.unwrap() .unwrap()
.get_visibility() .get_visibility()
== ChatVisibility::Normal == ChatVisibility::Normal
); );
assert_eq!(get_chat_cnt(&t.ctx).await, 2); assert_eq!(get_chat_cnt(&t).await, 2);
assert_eq!(chatlist_len(&t.ctx, 0).await, 2); // including DC_CHAT_ID_ARCHIVED_LINK now assert_eq!(chatlist_len(&t, 0).await, 2); // including DC_CHAT_ID_ARCHIVED_LINK now
assert_eq!(chatlist_len(&t.ctx, DC_GCL_NO_SPECIALS).await, 1); assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 1);
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY).await, 1); assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 1);
// archive second chat // archive second chat
assert!(chat_id2 assert!(chat_id2
.set_visibility(&t.ctx, ChatVisibility::Archived) .set_visibility(&t, ChatVisibility::Archived)
.await .await
.is_ok()); .is_ok());
assert!( assert!(
Chat::load_from_db(&t.ctx, chat_id1) Chat::load_from_db(&t, chat_id1)
.await .await
.unwrap() .unwrap()
.get_visibility() .get_visibility()
== ChatVisibility::Archived == ChatVisibility::Archived
); );
assert!( assert!(
Chat::load_from_db(&t.ctx, chat_id2) Chat::load_from_db(&t, chat_id2)
.await .await
.unwrap() .unwrap()
.get_visibility() .get_visibility()
== ChatVisibility::Archived == ChatVisibility::Archived
); );
assert_eq!(get_chat_cnt(&t.ctx).await, 2); assert_eq!(get_chat_cnt(&t).await, 2);
assert_eq!(chatlist_len(&t.ctx, 0).await, 1); // only DC_CHAT_ID_ARCHIVED_LINK now assert_eq!(chatlist_len(&t, 0).await, 1); // only DC_CHAT_ID_ARCHIVED_LINK now
assert_eq!(chatlist_len(&t.ctx, DC_GCL_NO_SPECIALS).await, 0); assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 0);
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY).await, 2); assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 2);
// archive already archived first chat, unarchive second chat two times // archive already archived first chat, unarchive second chat two times
assert!(chat_id1 assert!(chat_id1
.set_visibility(&t.ctx, ChatVisibility::Archived) .set_visibility(&t, ChatVisibility::Archived)
.await .await
.is_ok()); .is_ok());
assert!(chat_id2 assert!(chat_id2
.set_visibility(&t.ctx, ChatVisibility::Normal) .set_visibility(&t, ChatVisibility::Normal)
.await .await
.is_ok()); .is_ok());
assert!(chat_id2 assert!(chat_id2
.set_visibility(&t.ctx, ChatVisibility::Normal) .set_visibility(&t, ChatVisibility::Normal)
.await .await
.is_ok()); .is_ok());
assert!( assert!(
Chat::load_from_db(&t.ctx, chat_id1) Chat::load_from_db(&t, chat_id1)
.await .await
.unwrap() .unwrap()
.get_visibility() .get_visibility()
== ChatVisibility::Archived == ChatVisibility::Archived
); );
assert!( assert!(
Chat::load_from_db(&t.ctx, chat_id2) Chat::load_from_db(&t, chat_id2)
.await .await
.unwrap() .unwrap()
.get_visibility() .get_visibility()
== ChatVisibility::Normal == ChatVisibility::Normal
); );
assert_eq!(get_chat_cnt(&t.ctx).await, 2); assert_eq!(get_chat_cnt(&t).await, 2);
assert_eq!(chatlist_len(&t.ctx, 0).await, 2); assert_eq!(chatlist_len(&t, 0).await, 2);
assert_eq!(chatlist_len(&t.ctx, DC_GCL_NO_SPECIALS).await, 1); assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 1);
assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY).await, 1); assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 1);
} }
async fn get_chats_from_chat_list(ctx: &Context, listflags: usize) -> Vec<ChatId> { async fn get_chats_from_chat_list(ctx: &Context, listflags: usize) -> Vec<ChatId> {
@@ -3418,28 +3402,28 @@ mod tests {
// create 3 chats, wait 1 second in between to get a reliable order (we order by time) // create 3 chats, wait 1 second in between to get a reliable order (we order by time)
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.text = Some("foo".to_string()); msg.text = Some("foo".to_string());
let msg_id = add_device_msg(&t.ctx, None, Some(&mut msg)).await.unwrap(); let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap();
let chat_id1 = message::Message::load_from_db(&t.ctx, msg_id) let chat_id1 = message::Message::load_from_db(&t, msg_id)
.await .await
.unwrap() .unwrap()
.chat_id; .chat_id;
async_std::task::sleep(std::time::Duration::from_millis(1000)).await; async_std::task::sleep(std::time::Duration::from_millis(1000)).await;
let chat_id2 = t.get_self_chat().await.id; let chat_id2 = t.get_self_chat().await.id;
async_std::task::sleep(std::time::Duration::from_millis(1000)).await; async_std::task::sleep(std::time::Duration::from_millis(1000)).await;
let chat_id3 = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id3 = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
let chatlist = get_chats_from_chat_list(&t.ctx, DC_GCL_NO_SPECIALS).await; let chatlist = get_chats_from_chat_list(&t, DC_GCL_NO_SPECIALS).await;
assert_eq!(chatlist, vec![chat_id3, chat_id2, chat_id1]); assert_eq!(chatlist, vec![chat_id3, chat_id2, chat_id1]);
// pin // pin
assert!(chat_id1 assert!(chat_id1
.set_visibility(&t.ctx, ChatVisibility::Pinned) .set_visibility(&t, ChatVisibility::Pinned)
.await .await
.is_ok()); .is_ok());
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id1) Chat::load_from_db(&t, chat_id1)
.await .await
.unwrap() .unwrap()
.get_visibility(), .get_visibility(),
@@ -3447,16 +3431,16 @@ mod tests {
); );
// check if chat order changed // check if chat order changed
let chatlist = get_chats_from_chat_list(&t.ctx, DC_GCL_NO_SPECIALS).await; let chatlist = get_chats_from_chat_list(&t, DC_GCL_NO_SPECIALS).await;
assert_eq!(chatlist, vec![chat_id1, chat_id3, chat_id2]); assert_eq!(chatlist, vec![chat_id1, chat_id3, chat_id2]);
// unpin // unpin
assert!(chat_id1 assert!(chat_id1
.set_visibility(&t.ctx, ChatVisibility::Normal) .set_visibility(&t, ChatVisibility::Normal)
.await .await
.is_ok()); .is_ok());
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id1) Chat::load_from_db(&t, chat_id1)
.await .await
.unwrap() .unwrap()
.get_visibility(), .get_visibility(),
@@ -3464,30 +3448,24 @@ mod tests {
); );
// check if chat order changed back // check if chat order changed back
let chatlist = get_chats_from_chat_list(&t.ctx, DC_GCL_NO_SPECIALS).await; let chatlist = get_chats_from_chat_list(&t, DC_GCL_NO_SPECIALS).await;
assert_eq!(chatlist, vec![chat_id3, chat_id2, chat_id1]); assert_eq!(chatlist, vec![chat_id3, chat_id2, chat_id1]);
} }
#[async_std::test] #[async_std::test]
async fn test_set_chat_name() { async fn test_set_chat_name() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().get_name(),
.await
.unwrap()
.get_name(),
"foo" "foo"
); );
set_chat_name(&t.ctx, chat_id, "bar").await.unwrap(); set_chat_name(&t, chat_id, "bar").await.unwrap();
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().get_name(),
.await
.unwrap()
.get_name(),
"bar" "bar"
); );
} }
@@ -3514,91 +3492,71 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_shall_attach_selfavatar() { async fn test_shall_attach_selfavatar() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
assert!(!shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); assert!(!shall_attach_selfavatar(&t, chat_id).await.unwrap());
let (contact_id, _) = let (contact_id, _) =
Contact::add_or_lookup(&t.ctx, "", "foo@bar.org", Origin::IncomingUnknownTo) Contact::add_or_lookup(&t, "", "foo@bar.org", Origin::IncomingUnknownTo)
.await .await
.unwrap(); .unwrap();
add_contact_to_chat(&t.ctx, chat_id, contact_id).await; add_contact_to_chat(&t, chat_id, contact_id).await;
assert!(!shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); assert!(!shall_attach_selfavatar(&t, chat_id).await.unwrap());
t.ctx.set_config(Config::Selfavatar, None).await.unwrap(); // setting to None also forces re-sending t.set_config(Config::Selfavatar, None).await.unwrap(); // setting to None also forces re-sending
assert!(shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); assert!(shall_attach_selfavatar(&t, chat_id).await.unwrap());
assert!(chat_id assert!(chat_id.set_selfavatar_timestamp(&t, time()).await.is_ok());
.set_selfavatar_timestamp(&t.ctx, time()) assert!(!shall_attach_selfavatar(&t, chat_id).await.unwrap());
.await
.is_ok());
assert!(!shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap());
} }
#[async_std::test] #[async_std::test]
async fn test_set_mute_duration() { async fn test_set_mute_duration() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
// Initial // Initial
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(),
.await
.unwrap()
.is_muted(),
false false
); );
// Forever // Forever
set_muted(&t.ctx, chat_id, MuteDuration::Forever) set_muted(&t, chat_id, MuteDuration::Forever).await.unwrap();
.await
.unwrap();
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(),
.await
.unwrap()
.is_muted(),
true true
); );
// unMute // unMute
set_muted(&t.ctx, chat_id, MuteDuration::NotMuted) set_muted(&t, chat_id, MuteDuration::NotMuted)
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(),
.await
.unwrap()
.is_muted(),
false false
); );
// Timed in the future // Timed in the future
set_muted( set_muted(
&t.ctx, &t,
chat_id, chat_id,
MuteDuration::Until(SystemTime::now() + Duration::from_secs(3600)), MuteDuration::Until(SystemTime::now() + Duration::from_secs(3600)),
) )
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(),
.await
.unwrap()
.is_muted(),
true true
); );
// Time in the past // Time in the past
set_muted( set_muted(
&t.ctx, &t,
chat_id, chat_id,
MuteDuration::Until(SystemTime::now() - Duration::from_secs(3600)), MuteDuration::Until(SystemTime::now() - Duration::from_secs(3600)),
) )
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
Chat::load_from_db(&t.ctx, chat_id) Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(),
.await
.unwrap()
.is_muted(),
false false
); );
} }
@@ -3606,10 +3564,10 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_add_info_msg() { async fn test_add_info_msg() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
add_info_msg(&t.ctx, chat_id, "foo info").await; add_info_msg(&t, chat_id, "foo info").await;
let msg = t.get_last_msg(chat_id).await; let msg = t.get_last_msg(chat_id).await;
assert_eq!(msg.get_chat_id(), chat_id); assert_eq!(msg.get_chat_id(), chat_id);
@@ -3622,11 +3580,11 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_add_info_msg_with_cmd() { async fn test_add_info_msg_with_cmd() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
let msg_id = add_info_msg_with_cmd( let msg_id = add_info_msg_with_cmd(
&t.ctx, &t,
chat_id, chat_id,
"foo bar info", "foo bar info",
SystemMessage::EphemeralTimerChanged, SystemMessage::EphemeralTimerChanged,
@@ -3634,7 +3592,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&t, msg_id).await.unwrap();
assert_eq!(msg.get_chat_id(), chat_id); assert_eq!(msg.get_chat_id(), chat_id);
assert_eq!(msg.get_viewtype(), Viewtype::Text); assert_eq!(msg.get_viewtype(), Viewtype::Text);
assert_eq!(msg.get_text().unwrap(), "foo bar info"); assert_eq!(msg.get_text().unwrap(), "foo bar info");
@@ -3648,24 +3606,24 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_set_protection() { async fn test_set_protection() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let chat_id = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
assert!(!chat.is_protected()); assert!(!chat.is_protected());
assert!(chat.is_unpromoted()); assert!(chat.is_unpromoted());
// enable protection on unpromoted chat, the info-message is added via add_info_msg() // enable protection on unpromoted chat, the info-message is added via add_info_msg()
chat_id chat_id
.set_protection(&t.ctx, ProtectionStatus::Protected) .set_protection(&t, ProtectionStatus::Protected)
.await .await
.unwrap(); .unwrap();
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
assert!(chat.is_protected()); assert!(chat.is_protected());
assert!(chat.is_unpromoted()); assert!(chat.is_unpromoted());
let msgs = get_chat_msgs(&t.ctx, chat_id, 0, None).await; let msgs = get_chat_msgs(&t, chat_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
let msg = t.get_last_msg(chat_id).await; let msg = t.get_last_msg(chat_id).await;
@@ -3675,11 +3633,11 @@ mod tests {
// disable protection again, still unpromoted // disable protection again, still unpromoted
chat_id chat_id
.set_protection(&t.ctx, ProtectionStatus::Unprotected) .set_protection(&t, ProtectionStatus::Unprotected)
.await .await
.unwrap(); .unwrap();
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
assert!(!chat.is_protected()); assert!(!chat.is_protected());
assert!(chat.is_unpromoted()); assert!(chat.is_unpromoted());
@@ -3689,23 +3647,21 @@ mod tests {
assert_eq!(msg.get_state(), MessageState::InNoticed); assert_eq!(msg.get_state(), MessageState::InNoticed);
// send a message, this switches to promoted state // send a message, this switches to promoted state
send_text_msg(&t.ctx, chat_id, "hi!".to_string()) send_text_msg(&t, chat_id, "hi!".to_string()).await.unwrap();
.await
.unwrap();
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
assert!(!chat.is_protected()); assert!(!chat.is_protected());
assert!(!chat.is_unpromoted()); assert!(!chat.is_unpromoted());
let msgs = get_chat_msgs(&t.ctx, chat_id, 0, None).await; let msgs = get_chat_msgs(&t, chat_id, 0, None).await;
assert_eq!(msgs.len(), 3); assert_eq!(msgs.len(), 3);
// enable protection on promoted chat, the info-message is sent via send_msg() this time // enable protection on promoted chat, the info-message is sent via send_msg() this time
chat_id chat_id
.set_protection(&t.ctx, ProtectionStatus::Protected) .set_protection(&t, ProtectionStatus::Protected)
.await .await
.unwrap(); .unwrap();
let chat = Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = Chat::load_from_db(&t, chat_id).await.unwrap();
assert!(chat.is_protected()); assert!(chat.is_protected());
assert!(!chat.is_unpromoted()); assert!(!chat.is_unpromoted());

View File

@@ -438,18 +438,18 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_try_load() { async fn test_try_load() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id1 = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "a chat") let chat_id1 = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat")
.await .await
.unwrap(); .unwrap();
let chat_id2 = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "b chat") let chat_id2 = create_group_chat(&t, ProtectionStatus::Unprotected, "b chat")
.await .await
.unwrap(); .unwrap();
let chat_id3 = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "c chat") let chat_id3 = create_group_chat(&t, ProtectionStatus::Unprotected, "c chat")
.await .await
.unwrap(); .unwrap();
// check that the chatlist starts with the most recent message // check that the chatlist starts with the most recent message
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 3); assert_eq!(chats.len(), 3);
assert_eq!(chats.get_chat_id(0), chat_id3); assert_eq!(chats.get_chat_id(0), chat_id3);
assert_eq!(chats.get_chat_id(1), chat_id2); assert_eq!(chats.get_chat_id(1), chat_id2);
@@ -458,26 +458,26 @@ mod tests {
// drafts are sorted to the top // drafts are sorted to the top
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string())); msg.set_text(Some("hello".to_string()));
chat_id2.set_draft(&t.ctx, Some(&mut msg)).await; chat_id2.set_draft(&t, Some(&mut msg)).await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.get_chat_id(0), chat_id2); assert_eq!(chats.get_chat_id(0), chat_id2);
// check chatlist query and archive functionality // check chatlist query and archive functionality
let chats = Chatlist::try_load(&t.ctx, 0, Some("b"), None) let chats = Chatlist::try_load(&t, 0, Some("b"), None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
let chats = Chatlist::try_load(&t.ctx, DC_GCL_ARCHIVED_ONLY, None, None) let chats = Chatlist::try_load(&t, DC_GCL_ARCHIVED_ONLY, None, None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
chat_id1 chat_id1
.set_visibility(&t.ctx, ChatVisibility::Archived) .set_visibility(&t, ChatVisibility::Archived)
.await .await
.ok(); .ok();
let chats = Chatlist::try_load(&t.ctx, DC_GCL_ARCHIVED_ONLY, None, None) let chats = Chatlist::try_load(&t, DC_GCL_ARCHIVED_ONLY, None, None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
@@ -486,23 +486,23 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_sort_self_talk_up_on_forward() { async fn test_sort_self_talk_up_on_forward() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx.update_device_chats().await.unwrap(); t.update_device_chats().await.unwrap();
create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "a chat") create_group_chat(&t, ProtectionStatus::Unprotected, "a chat")
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert!(chats.len() == 3); assert!(chats.len() == 3);
assert!(!Chat::load_from_db(&t.ctx, chats.get_chat_id(0)) assert!(!Chat::load_from_db(&t, chats.get_chat_id(0))
.await .await
.unwrap() .unwrap()
.is_self_talk()); .is_self_talk());
let chats = Chatlist::try_load(&t.ctx, DC_GCL_FOR_FORWARDING, None, None) let chats = Chatlist::try_load(&t, DC_GCL_FOR_FORWARDING, None, None)
.await .await
.unwrap(); .unwrap();
assert!(chats.len() == 2); // device chat cannot be written and is skipped on forwarding assert!(chats.len() == 2); // device chat cannot be written and is skipped on forwarding
assert!(Chat::load_from_db(&t.ctx, chats.get_chat_id(0)) assert!(Chat::load_from_db(&t, chats.get_chat_id(0))
.await .await
.unwrap() .unwrap()
.is_self_talk()); .is_self_talk());
@@ -511,31 +511,31 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_search_special_chat_names() { async fn test_search_special_chat_names() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx.update_device_chats().await.unwrap(); t.update_device_chats().await.unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, Some("t-1234-s"), None) let chats = Chatlist::try_load(&t, 0, Some("t-1234-s"), None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
let chats = Chatlist::try_load(&t.ctx, 0, Some("t-5678-b"), None) let chats = Chatlist::try_load(&t, 0, Some("t-5678-b"), None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
t.ctx t
.set_stock_translation(StockMessage::SavedMessages, "test-1234-save".to_string()) .set_stock_translation(StockMessage::SavedMessages, "test-1234-save".to_string())
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, Some("t-1234-s"), None) let chats = Chatlist::try_load(&t, 0, Some("t-1234-s"), None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
t.ctx t
.set_stock_translation(StockMessage::DeviceMessages, "test-5678-babbel".to_string()) .set_stock_translation(StockMessage::DeviceMessages, "test-5678-babbel".to_string())
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, Some("t-5678-b"), None) let chats = Chatlist::try_load(&t, 0, Some("t-5678-b"), None)
.await .await
.unwrap(); .unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
@@ -544,16 +544,16 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_get_summary_unwrap() { async fn test_get_summary_unwrap() {
let t = TestContext::new().await; let t = TestContext::new().await;
let chat_id1 = create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "a chat") let chat_id1 = create_group_chat(&t, ProtectionStatus::Unprotected, "a chat")
.await .await
.unwrap(); .unwrap();
let mut msg = Message::new(Viewtype::Text); let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("foo:\nbar \r\n test".to_string())); msg.set_text(Some("foo:\nbar \r\n test".to_string()));
chat_id1.set_draft(&t.ctx, Some(&mut msg)).await; chat_id1.set_draft(&t, Some(&mut msg)).await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
let summary = chats.get_summary(&t.ctx, 0, None).await; let summary = chats.get_summary(&t, 0, None).await;
assert_eq!(summary.get_text2().unwrap(), "foo: bar test"); // the linebreak should be removed from summary assert_eq!(summary.get_text2().unwrap(), "foo: bar test"); // the linebreak should be removed from summary
} }
} }

View File

@@ -319,15 +319,15 @@ mod tests {
.unwrap() .unwrap()
.write_all(avatar_bytes) .write_all(avatar_bytes)
.unwrap(); .unwrap();
let avatar_blob = t.ctx.get_blobdir().join("avatar.jpg"); let avatar_blob = t.get_blobdir().join("avatar.jpg");
assert!(!avatar_blob.exists().await); assert!(!avatar_blob.exists().await);
t.ctx t
.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap())) .set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
.await .await
.unwrap(); .unwrap();
assert!(avatar_blob.exists().await); assert!(avatar_blob.exists().await);
assert!(std::fs::metadata(&avatar_blob).unwrap().len() < avatar_bytes.len() as u64); assert!(std::fs::metadata(&avatar_blob).unwrap().len() < avatar_bytes.len() as u64);
let avatar_cfg = t.ctx.get_config(Config::Selfavatar).await; let avatar_cfg = t.get_config(Config::Selfavatar).await;
assert_eq!(avatar_cfg, avatar_blob.to_str().map(|s| s.to_string())); assert_eq!(avatar_cfg, avatar_blob.to_str().map(|s| s.to_string()));
let img = image::open(avatar_src).unwrap(); let img = image::open(avatar_src).unwrap();
@@ -342,7 +342,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_selfavatar_in_blobdir() { async fn test_selfavatar_in_blobdir() {
let t = TestContext::new().await; let t = TestContext::new().await;
let avatar_src = t.ctx.get_blobdir().join("avatar.png"); let avatar_src = t.get_blobdir().join("avatar.png");
let avatar_bytes = include_bytes!("../test-data/image/avatar900x900.png"); let avatar_bytes = include_bytes!("../test-data/image/avatar900x900.png");
File::create(&avatar_src) File::create(&avatar_src)
.unwrap() .unwrap()
@@ -353,11 +353,11 @@ mod tests {
assert_eq!(img.width(), 900); assert_eq!(img.width(), 900);
assert_eq!(img.height(), 900); assert_eq!(img.height(), 900);
t.ctx t
.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap())) .set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
.await .await
.unwrap(); .unwrap();
let avatar_cfg = t.ctx.get_config(Config::Selfavatar).await; let avatar_cfg = t.get_config(Config::Selfavatar).await;
assert_eq!(avatar_cfg, avatar_src.to_str().map(|s| s.to_string())); assert_eq!(avatar_cfg, avatar_src.to_str().map(|s| s.to_string()));
let img = image::open(avatar_src).unwrap(); let img = image::open(avatar_src).unwrap();
@@ -374,9 +374,9 @@ mod tests {
.unwrap() .unwrap()
.write_all(avatar_bytes) .write_all(avatar_bytes)
.unwrap(); .unwrap();
let avatar_blob = t.ctx.get_blobdir().join("avatar.png"); let avatar_blob = t.get_blobdir().join("avatar.png");
assert!(!avatar_blob.exists().await); assert!(!avatar_blob.exists().await);
t.ctx t
.set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap())) .set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap()))
.await .await
.unwrap(); .unwrap();
@@ -385,24 +385,24 @@ mod tests {
std::fs::metadata(&avatar_blob).unwrap().len(), std::fs::metadata(&avatar_blob).unwrap().len(),
avatar_bytes.len() as u64 avatar_bytes.len() as u64
); );
let avatar_cfg = t.ctx.get_config(Config::Selfavatar).await; let avatar_cfg = t.get_config(Config::Selfavatar).await;
assert_eq!(avatar_cfg, avatar_blob.to_str().map(|s| s.to_string())); assert_eq!(avatar_cfg, avatar_blob.to_str().map(|s| s.to_string()));
} }
#[async_std::test] #[async_std::test]
async fn test_media_quality_config_option() { async fn test_media_quality_config_option() {
let t = TestContext::new().await; let t = TestContext::new().await;
let media_quality = t.ctx.get_config_int(Config::MediaQuality).await; let media_quality = t.get_config_int(Config::MediaQuality).await;
assert_eq!(media_quality, 0); assert_eq!(media_quality, 0);
let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default(); let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default();
assert_eq!(media_quality, constants::MediaQuality::Balanced); assert_eq!(media_quality, constants::MediaQuality::Balanced);
t.ctx t
.set_config(Config::MediaQuality, Some("1")) .set_config(Config::MediaQuality, Some("1"))
.await .await
.unwrap(); .unwrap();
let media_quality = t.ctx.get_config_int(Config::MediaQuality).await; let media_quality = t.get_config_int(Config::MediaQuality).await;
assert_eq!(media_quality, 1); assert_eq!(media_quality, 1);
assert_eq!(constants::MediaQuality::Worse as i32, 1); assert_eq!(constants::MediaQuality::Worse as i32, 1);
let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default(); let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default();

View File

@@ -616,15 +616,15 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_no_panic_on_bad_credentials() { async fn test_no_panic_on_bad_credentials() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx t
.set_config(Config::Addr, Some("probably@unexistant.addr")) .set_config(Config::Addr, Some("probably@unexistant.addr"))
.await .await
.unwrap(); .unwrap();
t.ctx t
.set_config(Config::MailPw, Some("123456")) .set_config(Config::MailPw, Some("123456"))
.await .await
.unwrap(); .unwrap();
assert!(t.ctx.configure().await.is_err()); assert!(t.configure().await.is_err());
} }
#[async_std::test] #[async_std::test]

View File

@@ -1320,11 +1320,11 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_is_self_addr() -> Result<()> { async fn test_is_self_addr() -> Result<()> {
let t = TestContext::new().await; let t = TestContext::new().await;
assert!(t.ctx.is_self_addr("me@me.org").await.is_err()); assert!(t.is_self_addr("me@me.org").await.is_err());
let addr = t.configure_alice().await; let addr = t.configure_alice().await;
assert_eq!(t.ctx.is_self_addr("me@me.org").await?, false); assert_eq!(t.is_self_addr("me@me.org").await?, false);
assert_eq!(t.ctx.is_self_addr(&addr).await?, true); assert_eq!(t.is_self_addr(&addr).await?, true);
Ok(()) Ok(())
} }
@@ -1341,16 +1341,16 @@ mod tests {
"Name two\ntwo@deux.net\n", // should not be added again "Name two\ntwo@deux.net\n", // should not be added again
"\nWonderland, Alice <alice@w.de>\n", "\nWonderland, Alice <alice@w.de>\n",
); );
assert_eq!(Contact::add_address_book(&t.ctx, book).await.unwrap(), 4); assert_eq!(Contact::add_address_book(&t, book).await.unwrap(), 4);
// check first added contact, this does not modify because of lower origin // check first added contact, this does not modify because of lower origin
let (contact_id, sth_modified) = let (contact_id, sth_modified) =
Contact::add_or_lookup(&t.ctx, "bla foo", "one@eins.org", Origin::IncomingUnknownTo) Contact::add_or_lookup(&t, "bla foo", "one@eins.org", Origin::IncomingUnknownTo)
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
assert_eq!(sth_modified, Modifier::None); assert_eq!(sth_modified, Modifier::None);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_id(), contact_id); assert_eq!(contact.get_id(), contact_id);
assert_eq!(contact.get_name(), "Name one"); assert_eq!(contact.get_name(), "Name one");
assert_eq!(contact.get_display_name(), "Name one"); assert_eq!(contact.get_display_name(), "Name one");
@@ -1358,29 +1358,25 @@ mod tests {
assert_eq!(contact.get_name_n_addr(), "Name one (one@eins.org)"); assert_eq!(contact.get_name_n_addr(), "Name one (one@eins.org)");
// modify first added contact // modify first added contact
let (contact_id_test, sth_modified) = Contact::add_or_lookup( let (contact_id_test, sth_modified) =
&t.ctx, Contact::add_or_lookup(&t, "Real one", " one@eins.org ", Origin::ManuallyCreated)
"Real one",
" one@eins.org ",
Origin::ManuallyCreated,
)
.await .await
.unwrap(); .unwrap();
assert_eq!(contact_id, contact_id_test); assert_eq!(contact_id, contact_id_test);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name(), "Real one"); assert_eq!(contact.get_name(), "Real one");
assert_eq!(contact.get_addr(), "one@eins.org"); assert_eq!(contact.get_addr(), "one@eins.org");
assert!(!contact.is_blocked()); assert!(!contact.is_blocked());
// check third added contact (contact without name) // check third added contact (contact without name)
let (contact_id, sth_modified) = let (contact_id, sth_modified) =
Contact::add_or_lookup(&t.ctx, "", "three@drei.sam", Origin::IncomingUnknownTo) Contact::add_or_lookup(&t, "", "three@drei.sam", Origin::IncomingUnknownTo)
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
assert_eq!(sth_modified, Modifier::None); assert_eq!(sth_modified, Modifier::None);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name(), ""); assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "three@drei.sam"); assert_eq!(contact.get_display_name(), "three@drei.sam");
assert_eq!(contact.get_addr(), "three@drei.sam"); assert_eq!(contact.get_addr(), "three@drei.sam");
@@ -1388,7 +1384,7 @@ mod tests {
// add name to third contact from incoming message (this becomes authorized name) // add name to third contact from incoming message (this becomes authorized name)
let (contact_id_test, sth_modified) = Contact::add_or_lookup( let (contact_id_test, sth_modified) = Contact::add_or_lookup(
&t.ctx, &t,
"m. serious", "m. serious",
"three@drei.sam", "three@drei.sam",
Origin::IncomingUnknownFrom, Origin::IncomingUnknownFrom,
@@ -1397,48 +1393,39 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!(contact_id, contact_id_test); assert_eq!(contact_id, contact_id_test);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name_n_addr(), "m. serious (three@drei.sam)"); assert_eq!(contact.get_name_n_addr(), "m. serious (three@drei.sam)");
assert!(!contact.is_blocked()); assert!(!contact.is_blocked());
// manually edit name of third contact (does not changed authorized name) // manually edit name of third contact (does not changed authorized name)
let (contact_id_test, sth_modified) = Contact::add_or_lookup( let (contact_id_test, sth_modified) =
&t.ctx, Contact::add_or_lookup(&t, "schnucki", "three@drei.sam", Origin::ManuallyCreated)
"schnucki",
"three@drei.sam",
Origin::ManuallyCreated,
)
.await .await
.unwrap(); .unwrap();
assert_eq!(contact_id, contact_id_test); assert_eq!(contact_id, contact_id_test);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "m. serious"); assert_eq!(contact.get_authname(), "m. serious");
assert_eq!(contact.get_name_n_addr(), "schnucki (three@drei.sam)"); assert_eq!(contact.get_name_n_addr(), "schnucki (three@drei.sam)");
assert!(!contact.is_blocked()); assert!(!contact.is_blocked());
// Fourth contact: // Fourth contact:
let (contact_id, sth_modified) = let (contact_id, sth_modified) =
Contact::add_or_lookup(&t.ctx, "", "alice@w.de", Origin::IncomingUnknownTo) Contact::add_or_lookup(&t, "", "alice@w.de", Origin::IncomingUnknownTo)
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
assert_eq!(sth_modified, Modifier::None); assert_eq!(sth_modified, Modifier::None);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name(), "Wonderland, Alice"); assert_eq!(contact.get_name(), "Wonderland, Alice");
assert_eq!(contact.get_display_name(), "Wonderland, Alice"); assert_eq!(contact.get_display_name(), "Wonderland, Alice");
assert_eq!(contact.get_addr(), "alice@w.de"); assert_eq!(contact.get_addr(), "alice@w.de");
assert_eq!(contact.get_name_n_addr(), "Wonderland, Alice (alice@w.de)"); assert_eq!(contact.get_name_n_addr(), "Wonderland, Alice (alice@w.de)");
// check SELF // check SELF
let contact = Contact::load_from_db(&t.ctx, DC_CONTACT_ID_SELF) let contact = Contact::load_from_db(&t, DC_CONTACT_ID_SELF).await.unwrap();
.await
.unwrap();
assert_eq!(DC_CONTACT_ID_SELF, 1); assert_eq!(DC_CONTACT_ID_SELF, 1);
assert_eq!( assert_eq!(contact.get_name(), t.stock_str(StockMessage::SelfMsg).await);
contact.get_name(),
t.ctx.stock_str(StockMessage::SelfMsg).await
);
assert_eq!(contact.get_addr(), ""); // we're not configured assert_eq!(contact.get_addr(), ""); // we're not configured
assert!(!contact.is_blocked()); assert!(!contact.is_blocked());
} }
@@ -1448,59 +1435,47 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
// incoming mail `From: bob1 <bob@example.org>` - this should init authname and name // incoming mail `From: bob1 <bob@example.org>` - this should init authname and name
let (contact_id, sth_modified) = Contact::add_or_lookup( let (contact_id, sth_modified) =
&t.ctx, Contact::add_or_lookup(&t, "bob1", "bob@example.org", Origin::IncomingUnknownFrom)
"bob1",
"bob@example.org",
Origin::IncomingUnknownFrom,
)
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
assert_eq!(sth_modified, Modifier::Created); assert_eq!(sth_modified, Modifier::Created);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "bob1"); assert_eq!(contact.get_authname(), "bob1");
assert_eq!(contact.get_name(), "bob1"); assert_eq!(contact.get_name(), "bob1");
assert_eq!(contact.get_display_name(), "bob1"); assert_eq!(contact.get_display_name(), "bob1");
// incoming mail `From: bob2 <bob@example.org>` - this should update authname and name // incoming mail `From: bob2 <bob@example.org>` - this should update authname and name
let (contact_id, sth_modified) = Contact::add_or_lookup( let (contact_id, sth_modified) =
&t.ctx, Contact::add_or_lookup(&t, "bob2", "bob@example.org", Origin::IncomingUnknownFrom)
"bob2",
"bob@example.org",
Origin::IncomingUnknownFrom,
)
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "bob2"); assert_eq!(contact.get_authname(), "bob2");
assert_eq!(contact.get_name(), "bob2"); assert_eq!(contact.get_name(), "bob2");
assert_eq!(contact.get_display_name(), "bob2"); assert_eq!(contact.get_display_name(), "bob2");
// manually edit name to "bob3" - authname should be still be "bob2" a given in `From:` above // manually edit name to "bob3" - authname should be still be "bob2" a given in `From:` above
let contact_id = Contact::create(&t.ctx, "bob3", "bob@example.org") let contact_id = Contact::create(&t, "bob3", "bob@example.org")
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "bob2"); assert_eq!(contact.get_authname(), "bob2");
assert_eq!(contact.get_name(), "bob3"); assert_eq!(contact.get_name(), "bob3");
assert_eq!(contact.get_display_name(), "bob3"); assert_eq!(contact.get_display_name(), "bob3");
// incoming mail `From: bob4 <bob@example.org>` - this should update authname, manually given name is still "bob3" // incoming mail `From: bob4 <bob@example.org>` - this should update authname, manually given name is still "bob3"
let (contact_id, sth_modified) = Contact::add_or_lookup( let (contact_id, sth_modified) =
&t.ctx, Contact::add_or_lookup(&t, "bob4", "bob@example.org", Origin::IncomingUnknownFrom)
"bob4",
"bob@example.org",
Origin::IncomingUnknownFrom,
)
.await .await
.unwrap(); .unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "bob4"); assert_eq!(contact.get_authname(), "bob4");
assert_eq!(contact.get_name(), "bob3"); assert_eq!(contact.get_name(), "bob3");
assert_eq!(contact.get_display_name(), "bob3"); assert_eq!(contact.get_display_name(), "bob3");
@@ -1511,18 +1486,16 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
// manually create "claire@example.org" without a given name // manually create "claire@example.org" without a given name
let contact_id = Contact::create(&t.ctx, "", "claire@example.org") let contact_id = Contact::create(&t, "", "claire@example.org").await.unwrap();
.await
.unwrap();
assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), ""); assert_eq!(contact.get_authname(), "");
assert_eq!(contact.get_name(), ""); assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_display_name(), "claire@example.org"); assert_eq!(contact.get_display_name(), "claire@example.org");
// incoming mail `From: claire1 <claire@example.org>` - this should update authname and name // incoming mail `From: claire1 <claire@example.org>` - this should update authname and name
let (contact_id_same, sth_modified) = Contact::add_or_lookup( let (contact_id_same, sth_modified) = Contact::add_or_lookup(
&t.ctx, &t,
"claire1", "claire1",
"claire@example.org", "claire@example.org",
Origin::IncomingUnknownFrom, Origin::IncomingUnknownFrom,
@@ -1531,14 +1504,14 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!(contact_id, contact_id_same); assert_eq!(contact_id, contact_id_same);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "claire1"); assert_eq!(contact.get_authname(), "claire1");
assert_eq!(contact.get_name(), "claire1"); assert_eq!(contact.get_name(), "claire1");
assert_eq!(contact.get_display_name(), "claire1"); assert_eq!(contact.get_display_name(), "claire1");
// incoming mail `From: claire2 <claire@example.org>` - this should update authname and name // incoming mail `From: claire2 <claire@example.org>` - this should update authname and name
let (contact_id_same, sth_modified) = Contact::add_or_lookup( let (contact_id_same, sth_modified) = Contact::add_or_lookup(
&t.ctx, &t,
"claire2", "claire2",
"claire@example.org", "claire@example.org",
Origin::IncomingUnknownFrom, Origin::IncomingUnknownFrom,
@@ -1547,7 +1520,7 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!(contact_id, contact_id_same); assert_eq!(contact_id, contact_id_same);
assert_eq!(sth_modified, Modifier::Modified); assert_eq!(sth_modified, Modifier::Modified);
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "claire2"); assert_eq!(contact.get_authname(), "claire2");
assert_eq!(contact.get_name(), "claire2"); assert_eq!(contact.get_name(), "claire2");
assert_eq!(contact.get_display_name(), "claire2"); assert_eq!(contact.get_display_name(), "claire2");
@@ -1558,33 +1531,26 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
// manually create "dave@example.org" // manually create "dave@example.org"
let contact_id = Contact::create(&t.ctx, "dave1", "dave@example.org") let contact_id = Contact::create(&t, "dave1", "dave@example.org")
.await .await
.unwrap(); .unwrap();
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), ""); assert_eq!(contact.get_authname(), "");
assert_eq!(contact.get_name(), "dave1"); assert_eq!(contact.get_name(), "dave1");
assert_eq!(contact.get_display_name(), "dave1"); assert_eq!(contact.get_display_name(), "dave1");
// incoming mail `From: dave2 <dave@example.org>` - this should update authname // incoming mail `From: dave2 <dave@example.org>` - this should update authname
Contact::add_or_lookup( Contact::add_or_lookup(&t, "dave2", "dave@example.org", Origin::IncomingUnknownFrom)
&t.ctx,
"dave2",
"dave@example.org",
Origin::IncomingUnknownFrom,
)
.await .await
.unwrap(); .unwrap();
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "dave2"); assert_eq!(contact.get_authname(), "dave2");
assert_eq!(contact.get_name(), "dave1"); assert_eq!(contact.get_name(), "dave1");
assert_eq!(contact.get_display_name(), "dave1"); assert_eq!(contact.get_display_name(), "dave1");
// manually clear the name // manually clear the name
Contact::create(&t.ctx, "", "dave@example.org") Contact::create(&t, "", "dave@example.org").await.unwrap();
.await let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
.unwrap();
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap();
assert_eq!(contact.get_authname(), "dave2"); assert_eq!(contact.get_authname(), "dave2");
assert_eq!(contact.get_name(), "dave2"); assert_eq!(contact.get_name(), "dave2");
assert_eq!(contact.get_display_name(), "dave2"); assert_eq!(contact.get_display_name(), "dave2");
@@ -1601,44 +1567,40 @@ mod tests {
async fn test_name_in_address() { async fn test_name_in_address() {
let t = TestContext::new().await; let t = TestContext::new().await;
let contact_id = Contact::create(&t.ctx, "", "<dave@example.org>") let contact_id = Contact::create(&t, "", "<dave@example.org>").await.unwrap();
.await let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
.unwrap();
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap();
assert_eq!(contact.get_name(), ""); assert_eq!(contact.get_name(), "");
assert_eq!(contact.get_addr(), "dave@example.org"); assert_eq!(contact.get_addr(), "dave@example.org");
let contact_id = Contact::create(&t.ctx, "", "Mueller, Dave <dave@example.org>") let contact_id = Contact::create(&t, "", "Mueller, Dave <dave@example.org>")
.await .await
.unwrap(); .unwrap();
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name(), "Mueller, Dave"); assert_eq!(contact.get_name(), "Mueller, Dave");
assert_eq!(contact.get_addr(), "dave@example.org"); assert_eq!(contact.get_addr(), "dave@example.org");
let contact_id = Contact::create(&t.ctx, "name1", "name2 <dave@example.org>") let contact_id = Contact::create(&t, "name1", "name2 <dave@example.org>")
.await .await
.unwrap(); .unwrap();
let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); let contact = Contact::load_from_db(&t, contact_id).await.unwrap();
assert_eq!(contact.get_name(), "name1"); assert_eq!(contact.get_name(), "name1");
assert_eq!(contact.get_addr(), "dave@example.org"); assert_eq!(contact.get_addr(), "dave@example.org");
assert!(Contact::create(&t.ctx, "", "<dskjfdslk@sadklj.dk") assert!(Contact::create(&t, "", "<dskjfdslk@sadklj.dk")
.await .await
.is_err()); .is_err());
assert!(Contact::create(&t.ctx, "", "<dskjf>dslk@sadklj.dk>") assert!(Contact::create(&t, "", "<dskjf>dslk@sadklj.dk>")
.await .await
.is_err()); .is_err());
assert!(Contact::create(&t.ctx, "", "dskjfdslksadklj.dk") assert!(Contact::create(&t, "", "dskjfdslksadklj.dk").await.is_err());
assert!(Contact::create(&t, "", "dskjfdslk@sadklj.dk>")
.await .await
.is_err()); .is_err());
assert!(Contact::create(&t.ctx, "", "dskjfdslk@sadklj.dk>") assert!(Contact::create(&t, "", "dskjf@dslk@sadkljdk")
.await .await
.is_err()); .is_err());
assert!(Contact::create(&t.ctx, "", "dskjf@dslk@sadkljdk") assert!(Contact::create(&t, "", "dskjf dslk@d.e").await.is_err());
.await assert!(Contact::create(&t, "", "<dskjf dslk@sadklj.dk")
.is_err());
assert!(Contact::create(&t.ctx, "", "dskjf dslk@d.e").await.is_err());
assert!(Contact::create(&t.ctx, "", "<dskjf dslk@sadklj.dk")
.await .await
.is_err()); .is_err());
} }

View File

@@ -528,7 +528,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_get_fresh_msgs() { async fn test_get_fresh_msgs() {
let t = TestContext::new().await; let t = TestContext::new().await;
let fresh = t.ctx.get_fresh_msgs().await; let fresh = t.get_fresh_msgs().await;
assert!(fresh.is_empty()) assert!(fresh.is_empty())
} }
@@ -587,14 +587,14 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn no_crashes_on_context_deref() { async fn no_crashes_on_context_deref() {
let t = TestContext::new().await; let t = TestContext::new().await;
std::mem::drop(t.ctx); std::mem::drop(t);
} }
#[async_std::test] #[async_std::test]
async fn test_get_info() { async fn test_get_info() {
let t = TestContext::new().await; let t = TestContext::new().await;
let info = t.ctx.get_info().await; let info = t.get_info().await;
assert!(info.get("database_dir").is_some()); assert!(info.get("database_dir").is_some());
} }

View File

@@ -2029,134 +2029,134 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_adhoc_group_show_chats_only() { async fn test_adhoc_group_show_chats_only() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
assert_eq!(t.ctx.get_config_int(Config::ShowEmails).await, 0); assert_eq!(t.get_config_int(Config::ShowEmails).await, 0);
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
dc_receive_imf(&t.ctx, MSGRMSG, "INBOX", 1, false) dc_receive_imf(&t, MSGRMSG, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
dc_receive_imf(&t.ctx, ONETOONE_NOREPLY_MAIL, "INBOX", 1, false) dc_receive_imf(&t, ONETOONE_NOREPLY_MAIL, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
dc_receive_imf(&t.ctx, GRP_MAIL, "INBOX", 1, false) dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
} }
#[async_std::test] #[async_std::test]
async fn test_adhoc_group_show_accepted_contact_unknown() { async fn test_adhoc_group_show_accepted_contact_unknown() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
t.ctx t
.set_config(Config::ShowEmails, Some("1")) .set_config(Config::ShowEmails, Some("1"))
.await .await
.unwrap(); .unwrap();
dc_receive_imf(&t.ctx, GRP_MAIL, "INBOX", 1, false) dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
// adhoc-group with unknown contacts with show_emails=accepted is ignored for unknown contacts // adhoc-group with unknown contacts with show_emails=accepted is ignored for unknown contacts
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
} }
#[async_std::test] #[async_std::test]
async fn test_adhoc_group_show_accepted_contact_known() { async fn test_adhoc_group_show_accepted_contact_known() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
t.ctx t
.set_config(Config::ShowEmails, Some("1")) .set_config(Config::ShowEmails, Some("1"))
.await .await
.unwrap(); .unwrap();
Contact::create(&t.ctx, "Bob", "bob@example.com") Contact::create(&t, "Bob", "bob@example.com")
.await .await
.unwrap(); .unwrap();
dc_receive_imf(&t.ctx, GRP_MAIL, "INBOX", 1, false) dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
// adhoc-group with known contacts with show_emails=accepted is still ignored for known contacts // adhoc-group with known contacts with show_emails=accepted is still ignored for known contacts
// (and existent chat is required) // (and existent chat is required)
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
} }
#[async_std::test] #[async_std::test]
async fn test_adhoc_group_show_accepted_contact_accepted() { async fn test_adhoc_group_show_accepted_contact_accepted() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
t.ctx t
.set_config(Config::ShowEmails, Some("1")) .set_config(Config::ShowEmails, Some("1"))
.await .await
.unwrap(); .unwrap();
// accept Bob by accepting a delta-message from Bob // accept Bob by accepting a delta-message from Bob
dc_receive_imf(&t.ctx, MSGRMSG, "INBOX", 1, false) dc_receive_imf(&t, MSGRMSG, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
assert!(chats.get_chat_id(0).is_deaddrop()); assert!(chats.get_chat_id(0).is_deaddrop());
let chat_id = chat::create_by_msg_id(&t.ctx, chats.get_msg_id(0).unwrap()) let chat_id = chat::create_by_msg_id(&t, chats.get_msg_id(0).unwrap())
.await .await
.unwrap(); .unwrap();
assert!(!chat_id.is_special()); assert!(!chat_id.is_special());
let chat = chat::Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = chat::Chat::load_from_db(&t, chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Single); assert_eq!(chat.typ, Chattype::Single);
assert_eq!(chat.name, "Bob"); assert_eq!(chat.name, "Bob");
assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await.len(), 1); assert_eq!(chat::get_chat_contacts(&t, chat_id).await.len(), 1);
assert_eq!(chat::get_chat_msgs(&t.ctx, chat_id, 0, None).await.len(), 1); assert_eq!(chat::get_chat_msgs(&t, chat_id, 0, None).await.len(), 1);
// receive a non-delta-message from Bob, shows up because of the show_emails setting // receive a non-delta-message from Bob, shows up because of the show_emails setting
dc_receive_imf(&t.ctx, ONETOONE_NOREPLY_MAIL, "INBOX", 2, false) dc_receive_imf(&t, ONETOONE_NOREPLY_MAIL, "INBOX", 2, false)
.await .await
.unwrap(); .unwrap();
assert_eq!(chat::get_chat_msgs(&t.ctx, chat_id, 0, None).await.len(), 2); assert_eq!(chat::get_chat_msgs(&t, chat_id, 0, None).await.len(), 2);
// let Bob create an adhoc-group by a non-delta-message, shows up because of the show_emails setting // let Bob create an adhoc-group by a non-delta-message, shows up because of the show_emails setting
dc_receive_imf(&t.ctx, GRP_MAIL, "INBOX", 3, false) dc_receive_imf(&t, GRP_MAIL, "INBOX", 3, false)
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 2); assert_eq!(chats.len(), 2);
let chat_id = chat::create_by_msg_id(&t.ctx, chats.get_msg_id(0).unwrap()) let chat_id = chat::create_by_msg_id(&t, chats.get_msg_id(0).unwrap())
.await .await
.unwrap(); .unwrap();
let chat = chat::Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = chat::Chat::load_from_db(&t, chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
assert_eq!(chat.name, "group with Alice, Bob and Claire"); assert_eq!(chat.name, "group with Alice, Bob and Claire");
assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await.len(), 3); assert_eq!(chat::get_chat_contacts(&t, chat_id).await.len(), 3);
} }
#[async_std::test] #[async_std::test]
async fn test_adhoc_group_show_all() { async fn test_adhoc_group_show_all() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
t.ctx t
.set_config(Config::ShowEmails, Some("2")) .set_config(Config::ShowEmails, Some("2"))
.await .await
.unwrap(); .unwrap();
dc_receive_imf(&t.ctx, GRP_MAIL, "INBOX", 1, false) dc_receive_imf(&t, GRP_MAIL, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
// adhoc-group with unknown contacts with show_emails=all will show up in the deaddrop // adhoc-group with unknown contacts with show_emails=all will show up in the deaddrop
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
assert!(chats.get_chat_id(0).is_deaddrop()); assert!(chats.get_chat_id(0).is_deaddrop());
let chat_id = chat::create_by_msg_id(&t.ctx, chats.get_msg_id(0).unwrap()) let chat_id = chat::create_by_msg_id(&t, chats.get_msg_id(0).unwrap())
.await .await
.unwrap(); .unwrap();
let chat = chat::Chat::load_from_db(&t.ctx, chat_id).await.unwrap(); let chat = chat::Chat::load_from_db(&t, chat_id).await.unwrap();
assert_eq!(chat.typ, Chattype::Group); assert_eq!(chat.typ, Chattype::Group);
assert_eq!(chat.name, "group with Alice, Bob and Claire"); assert_eq!(chat.name, "group with Alice, Bob and Claire");
assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await.len(), 3); assert_eq!(chat::get_chat_contacts(&t, chat_id).await.len(), 3);
} }
#[async_std::test] #[async_std::test]
@@ -2164,36 +2164,36 @@ mod tests {
// create alice's account // create alice's account
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let bob_id = Contact::create(&t.ctx, "bob", "bob@example.com") let bob_id = Contact::create(&t, "bob", "bob@example.com")
.await .await
.unwrap(); .unwrap();
let one2one_id = chat::create_by_contact_id(&t.ctx, bob_id).await.unwrap(); let one2one_id = chat::create_by_contact_id(&t, bob_id).await.unwrap();
one2one_id one2one_id
.set_visibility(&t.ctx, ChatVisibility::Archived) .set_visibility(&t, ChatVisibility::Archived)
.await .await
.unwrap(); .unwrap();
let one2one = Chat::load_from_db(&t.ctx, one2one_id).await.unwrap(); let one2one = Chat::load_from_db(&t, one2one_id).await.unwrap();
assert!(one2one.get_visibility() == ChatVisibility::Archived); assert!(one2one.get_visibility() == ChatVisibility::Archived);
// create a group with bob, archive group // create a group with bob, archive group
let group_id = chat::create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "foo") let group_id = chat::create_group_chat(&t, ProtectionStatus::Unprotected, "foo")
.await .await
.unwrap(); .unwrap();
chat::add_contact_to_chat(&t.ctx, group_id, bob_id).await; chat::add_contact_to_chat(&t, group_id, bob_id).await;
assert_eq!( assert_eq!(
chat::get_chat_msgs(&t.ctx, group_id, 0, None).await.len(), chat::get_chat_msgs(&t, group_id, 0, None).await.len(),
0 0
); );
group_id group_id
.set_visibility(&t.ctx, ChatVisibility::Archived) .set_visibility(&t, ChatVisibility::Archived)
.await .await
.unwrap(); .unwrap();
let group = Chat::load_from_db(&t.ctx, group_id).await.unwrap(); let group = Chat::load_from_db(&t, group_id).await.unwrap();
assert!(group.get_visibility() == ChatVisibility::Archived); assert!(group.get_visibility() == ChatVisibility::Archived);
// everything archived, chatlist should be empty // everything archived, chatlist should be empty
assert_eq!( assert_eq!(
Chatlist::try_load(&t.ctx, DC_GCL_NO_SPECIALS, None, None) Chatlist::try_load(&t, DC_GCL_NO_SPECIALS, None, None)
.await .await
.unwrap() .unwrap()
.len(), .len(),
@@ -2202,7 +2202,7 @@ mod tests {
// send a message to group with bob // send a message to group with bob
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
format!( format!(
"From: alice@example.com\n\ "From: alice@example.com\n\
To: bob@example.com\n\ To: bob@example.com\n\
@@ -2224,25 +2224,25 @@ mod tests {
) )
.await .await
.unwrap(); .unwrap();
let msgs = chat::get_chat_msgs(&t.ctx, group_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, group_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() { let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() {
msg_id msg_id
} else { } else {
panic!("Wrong item type"); panic!("Wrong item type");
}; };
let msg = message::Message::load_from_db(&t.ctx, *msg_id) let msg = message::Message::load_from_db(&t, *msg_id)
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
assert_eq!(msg.text.unwrap(), "hello"); assert_eq!(msg.text.unwrap(), "hello");
assert_eq!(msg.state, MessageState::OutDelivered); assert_eq!(msg.state, MessageState::OutDelivered);
let group = Chat::load_from_db(&t.ctx, group_id).await.unwrap(); let group = Chat::load_from_db(&t, group_id).await.unwrap();
assert!(group.get_visibility() == ChatVisibility::Normal); assert!(group.get_visibility() == ChatVisibility::Normal);
// bob sends a read receipt to the group // bob sends a read receipt to the group
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
format!( format!(
"From: bob@example.com\n\ "From: bob@example.com\n\
To: alice@example.com\n\ To: alice@example.com\n\
@@ -2279,23 +2279,23 @@ mod tests {
) )
.await.unwrap(); .await.unwrap();
assert_eq!( assert_eq!(
chat::get_chat_msgs(&t.ctx, group_id, 0, None).await.len(), chat::get_chat_msgs(&t, group_id, 0, None).await.len(),
1 1
); );
let msg = message::Message::load_from_db(&t.ctx, *msg_id) let msg = message::Message::load_from_db(&t, *msg_id)
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.state, MessageState::OutMdnRcvd); assert_eq!(msg.state, MessageState::OutMdnRcvd);
// check, the read-receipt has not unarchived the one2one // check, the read-receipt has not unarchived the one2one
assert_eq!( assert_eq!(
Chatlist::try_load(&t.ctx, DC_GCL_NO_SPECIALS, None, None) Chatlist::try_load(&t, DC_GCL_NO_SPECIALS, None, None)
.await .await
.unwrap() .unwrap()
.len(), .len(),
1 1
); );
let one2one = Chat::load_from_db(&t.ctx, one2one_id).await.unwrap(); let one2one = Chat::load_from_db(&t, one2one_id).await.unwrap();
assert!(one2one.get_visibility() == ChatVisibility::Archived); assert!(one2one.get_visibility() == ChatVisibility::Archived);
} }
@@ -2306,9 +2306,9 @@ mod tests {
// "deaddrop" chat) to avoid a re-download from the server. See also [**] // "deaddrop" chat) to avoid a re-download from the server. See also [**]
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let context = &t.ctx; let context = &t;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert!(chats.get_msg_id(0).is_err()); assert!(chats.get_msg_id(0).is_err());
dc_receive_imf( dc_receive_imf(
@@ -2327,7 +2327,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
// Check that the message was added to the database: // Check that the message was added to the database:
assert!(chats.get_msg_id(0).is_ok()); assert!(chats.get_msg_id(0).is_ok());
} }
@@ -2335,14 +2335,14 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_escaped_from() { async fn test_escaped_from() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let contact_id = Contact::create(&t.ctx, "foobar", "foobar@example.com") let contact_id = Contact::create(&t, "foobar", "foobar@example.com")
.await .await
.unwrap(); .unwrap();
let chat_id = chat::create_by_contact_id(&t.ctx, contact_id) let chat_id = chat::create_by_contact_id(&t, contact_id)
.await .await
.unwrap(); .unwrap();
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
b"From: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= <foobar@example.com>\n\ b"From: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= <foobar@example.com>\n\
To: alice@example.com\n\ To: alice@example.com\n\
Subject: foo\n\ Subject: foo\n\
@@ -2357,20 +2357,20 @@ mod tests {
false, false,
).await.unwrap(); ).await.unwrap();
assert_eq!( assert_eq!(
Contact::load_from_db(&t.ctx, contact_id) Contact::load_from_db(&t, contact_id)
.await .await
.unwrap() .unwrap()
.get_authname(), .get_authname(),
"Имя, Фамилия", "Имя, Фамилия",
); );
let msgs = chat::get_chat_msgs(&t.ctx, chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, chat_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() { let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() {
msg_id msg_id
} else { } else {
panic!("Wrong item type"); panic!("Wrong item type");
}; };
let msg = message::Message::load_from_db(&t.ctx, *msg_id) let msg = message::Message::load_from_db(&t, *msg_id)
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
@@ -2381,18 +2381,18 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_escaped_recipients() { async fn test_escaped_recipients() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
Contact::create(&t.ctx, "foobar", "foobar@example.com") Contact::create(&t, "foobar", "foobar@example.com")
.await .await
.unwrap(); .unwrap();
let carl_contact_id = let carl_contact_id =
Contact::add_or_lookup(&t.ctx, "Carl", "carl@host.tld", Origin::IncomingUnknownFrom) Contact::add_or_lookup(&t, "Carl", "carl@host.tld", Origin::IncomingUnknownFrom)
.await .await
.unwrap() .unwrap()
.0; .0;
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
b"From: Foobar <foobar@example.com>\n\ b"From: Foobar <foobar@example.com>\n\
To: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= alice@example.com\n\ To: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= alice@example.com\n\
Cc: =?utf-8?q?=3Ch2=3E?= <carl@host.tld>\n\ Cc: =?utf-8?q?=3Ch2=3E?= <carl@host.tld>\n\
@@ -2410,15 +2410,15 @@ mod tests {
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
Contact::load_from_db(&t.ctx, carl_contact_id) Contact::load_from_db(&t, carl_contact_id)
.await .await
.unwrap() .unwrap()
.get_name(), .get_name(),
"h2" "h2"
); );
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
let msg = Message::load_from_db(&t.ctx, chats.get_msg_id(0).unwrap()) let msg = Message::load_from_db(&t, chats.get_msg_id(0).unwrap())
.await .await
.unwrap(); .unwrap();
assert_eq!(msg.is_dc_message, MessengerMessage::Yes); assert_eq!(msg.is_dc_message, MessengerMessage::Yes);
@@ -2429,12 +2429,12 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_cc_to_contact() { async fn test_cc_to_contact() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
Contact::create(&t.ctx, "foobar", "foobar@example.com") Contact::create(&t, "foobar", "foobar@example.com")
.await .await
.unwrap(); .unwrap();
let carl_contact_id = Contact::add_or_lookup( let carl_contact_id = Contact::add_or_lookup(
&t.ctx, &t,
"garabage", "garabage",
"carl@host.tld", "carl@host.tld",
Origin::IncomingUnknownFrom, Origin::IncomingUnknownFrom,
@@ -2444,7 +2444,7 @@ mod tests {
.0; .0;
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
b"From: Foobar <foobar@example.com>\n\ b"From: Foobar <foobar@example.com>\n\
To: alice@example.com\n\ To: alice@example.com\n\
Cc: Carl <carl@host.tld>\n\ Cc: Carl <carl@host.tld>\n\
@@ -2462,7 +2462,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
Contact::load_from_db(&t.ctx, carl_contact_id) Contact::load_from_db(&t, carl_contact_id)
.await .await
.unwrap() .unwrap()
.get_name(), .get_name(),
@@ -2554,7 +2554,7 @@ mod tests {
t.configure_addr(self_addr).await; t.configure_addr(self_addr).await;
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
format!( format!(
"From: {}\n\ "From: {}\n\
To: {}\n\ To: {}\n\
@@ -2574,21 +2574,21 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
let msg_id = chats.get_msg_id(0).unwrap(); let msg_id = chats.get_msg_id(0).unwrap();
// Check that the ndn would be downloaded: // Check that the ndn would be downloaded:
let headers = mailparse::parse_mail(raw_ndn).unwrap().headers; let headers = mailparse::parse_mail(raw_ndn).unwrap().headers;
assert!( assert!(
crate::imap::prefetch_should_download(&t.ctx, &headers, ShowEmails::Off) crate::imap::prefetch_should_download(&t, &headers, ShowEmails::Off)
.await .await
.unwrap() .unwrap()
); );
dc_receive_imf(&t.ctx, raw_ndn, "INBOX", 1, false) dc_receive_imf(&t, raw_ndn, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&t, msg_id).await.unwrap();
assert_eq!(msg.state, MessageState::OutFailed); assert_eq!(msg.state, MessageState::OutFailed);
@@ -2601,7 +2601,7 @@ mod tests {
t.configure_addr("alice@gmail.com").await; t.configure_addr("alice@gmail.com").await;
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
b"From: alice@gmail.com\n\ b"From: alice@gmail.com\n\
To: bob@example.com, assidhfaaspocwaeofi@gmail.com\n\ To: bob@example.com, assidhfaaspocwaeofi@gmail.com\n\
Subject: foo\n\ Subject: foo\n\
@@ -2620,30 +2620,30 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
let msg_id = chats.get_msg_id(0).unwrap(); let msg_id = chats.get_msg_id(0).unwrap();
let raw = include_bytes!("../test-data/message/gmail_ndn_group.eml"); let raw = include_bytes!("../test-data/message/gmail_ndn_group.eml");
dc_receive_imf(&t.ctx, raw, "INBOX", 1, false) dc_receive_imf(&t, raw, "INBOX", 1, false)
.await .await
.unwrap(); .unwrap();
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap(); let msg = Message::load_from_db(&t, msg_id).await.unwrap();
assert_eq!(msg.state, MessageState::OutFailed); assert_eq!(msg.state, MessageState::OutFailed);
let msgs = chat::get_chat_msgs(&t.ctx, msg.chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, msg.chat_id, 0, None).await;
let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() { let msg_id = if let ChatItem::Message { msg_id } = msgs.last().unwrap() {
msg_id msg_id
} else { } else {
panic!("Wrong item type"); panic!("Wrong item type");
}; };
let last_msg = Message::load_from_db(&t.ctx, *msg_id).await.unwrap(); let last_msg = Message::load_from_db(&t, *msg_id).await.unwrap();
assert_eq!( assert_eq!(
last_msg.text, last_msg.text,
Some( Some(
t.ctx t
.stock_string_repl_str( .stock_string_repl_str(
StockMessage::FailedSendingTo, StockMessage::FailedSendingTo,
"assidhfaaspocwaeofi@gmail.com", "assidhfaaspocwaeofi@gmail.com",
@@ -2671,7 +2671,7 @@ mod tests {
async fn test_html_only_mail() { async fn test_html_only_mail() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let msg = load_imf_email( let msg = load_imf_email(
&t.ctx, &t,
include_bytes!("../test-data/message/wrong-html.eml"), include_bytes!("../test-data/message/wrong-html.eml"),
) )
.await; .await;
@@ -2682,7 +2682,7 @@ mod tests {
async fn test_pdf_filename_simple() { async fn test_pdf_filename_simple() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let msg = load_imf_email( let msg = load_imf_email(
&t.ctx, &t,
include_bytes!("../test-data/message/pdf_filename_simple.eml"), include_bytes!("../test-data/message/pdf_filename_simple.eml"),
) )
.await; .await;
@@ -2696,7 +2696,7 @@ mod tests {
// test filenames split across multiple header lines, see rfc 2231 // test filenames split across multiple header lines, see rfc 2231
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let msg = load_imf_email( let msg = load_imf_email(
&t.ctx, &t,
include_bytes!("../test-data/message/pdf_filename_continuation.eml"), include_bytes!("../test-data/message/pdf_filename_continuation.eml"),
) )
.await; .await;

View File

@@ -898,7 +898,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_file_handling() { async fn test_file_handling() {
let t = TestContext::new().await; let t = TestContext::new().await;
let context = &t.ctx; let context = &t;
macro_rules! dc_file_exist { macro_rules! dc_file_exist {
($ctx:expr, $fname:expr) => { ($ctx:expr, $fname:expr) => {
$ctx.get_blobdir() $ctx.get_blobdir()
@@ -978,11 +978,11 @@ mod tests {
async fn test_create_smeared_timestamp() { async fn test_create_smeared_timestamp() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_ne!( assert_ne!(
dc_create_smeared_timestamp(&t.ctx).await, dc_create_smeared_timestamp(&t).await,
dc_create_smeared_timestamp(&t.ctx).await dc_create_smeared_timestamp(&t).await
); );
assert!( assert!(
dc_create_smeared_timestamp(&t.ctx).await dc_create_smeared_timestamp(&t).await
>= SystemTime::now() >= SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH) .duration_since(SystemTime::UNIX_EPOCH)
.unwrap() .unwrap()
@@ -994,13 +994,13 @@ mod tests {
async fn test_create_smeared_timestamps() { async fn test_create_smeared_timestamps() {
let t = TestContext::new().await; let t = TestContext::new().await;
let count = MAX_SECONDS_TO_LEND_FROM_FUTURE - 1; let count = MAX_SECONDS_TO_LEND_FROM_FUTURE - 1;
let start = dc_create_smeared_timestamps(&t.ctx, count as usize).await; let start = dc_create_smeared_timestamps(&t, count as usize).await;
let next = dc_smeared_time(&t.ctx).await; let next = dc_smeared_time(&t).await;
assert!((start + count - 1) < next); assert!((start + count - 1) < next);
let count = MAX_SECONDS_TO_LEND_FROM_FUTURE + 30; let count = MAX_SECONDS_TO_LEND_FROM_FUTURE + 30;
let start = dc_create_smeared_timestamps(&t.ctx, count as usize).await; let start = dc_create_smeared_timestamps(&t, count as usize).await;
let next = dc_smeared_time(&t.ctx).await; let next = dc_smeared_time(&t).await;
assert!((start + count - 1) < next); assert!((start + count - 1) < next);
} }
@@ -1074,53 +1074,53 @@ mod tests {
/ 1_000; / 1_000;
// a correct time must not add a device message // a correct time must not add a device message
maybe_warn_on_bad_time(&t.ctx, timestamp_now, get_provider_update_timestamp()).await; maybe_warn_on_bad_time(&t, timestamp_now, get_provider_update_timestamp()).await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
// we cannot find out if a date in the future is wrong - a device message is not added // we cannot find out if a date in the future is wrong - a device message is not added
maybe_warn_on_bad_time(&t.ctx, timestamp_future, get_provider_update_timestamp()).await; maybe_warn_on_bad_time(&t, timestamp_future, get_provider_update_timestamp()).await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
// a date in the past must add a device message // a date in the past must add a device message
maybe_warn_on_bad_time(&t.ctx, timestamp_past, get_provider_update_timestamp()).await; maybe_warn_on_bad_time(&t, timestamp_past, get_provider_update_timestamp()).await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
let device_chat_id = chats.get_chat_id(0); let device_chat_id = chats.get_chat_id(0);
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
// the message should be added only once a day - test that an hour later and nearly a day later // the message should be added only once a day - test that an hour later and nearly a day later
maybe_warn_on_bad_time( maybe_warn_on_bad_time(
&t.ctx, &t,
timestamp_past + 60 * 60, timestamp_past + 60 * 60,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
maybe_warn_on_bad_time( maybe_warn_on_bad_time(
&t.ctx, &t,
timestamp_past + 60 * 60 * 24 - 1, timestamp_past + 60 * 60 * 24 - 1,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
// next day, there should be another device message // next day, there should be another device message
maybe_warn_on_bad_time( maybe_warn_on_bad_time(
&t.ctx, &t,
timestamp_past + 60 * 60 * 24, timestamp_past + 60 * 60 * 24,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
assert_eq!(device_chat_id, chats.get_chat_id(0)); assert_eq!(device_chat_id, chats.get_chat_id(0));
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
assert_eq!(msgs.len(), 2); assert_eq!(msgs.len(), 2);
} }
@@ -1132,60 +1132,60 @@ mod tests {
// in about 6 months, the app should not be outdated // in about 6 months, the app should not be outdated
// (if this fails, provider-db is not updated since 6 months) // (if this fails, provider-db is not updated since 6 months)
maybe_warn_on_outdated( maybe_warn_on_outdated(
&t.ctx, &t,
timestamp_now + 180 * 24 * 60 * 60, timestamp_now + 180 * 24 * 60 * 60,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
// in 1 year, the app should be considered as outdated // in 1 year, the app should be considered as outdated
maybe_warn_on_outdated( maybe_warn_on_outdated(
&t.ctx, &t,
timestamp_now + 365 * 24 * 60 * 60, timestamp_now + 365 * 24 * 60 * 60,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
let device_chat_id = chats.get_chat_id(0); let device_chat_id = chats.get_chat_id(0);
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
// do not repeat the warning every day ... // do not repeat the warning every day ...
// (we test that for the 2 subsequent days, this may be the next month, so the result should be 1 or 2 device message) // (we test that for the 2 subsequent days, this may be the next month, so the result should be 1 or 2 device message)
maybe_warn_on_outdated( maybe_warn_on_outdated(
&t.ctx, &t,
timestamp_now + (365 + 1) * 24 * 60 * 60, timestamp_now + (365 + 1) * 24 * 60 * 60,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
maybe_warn_on_outdated( maybe_warn_on_outdated(
&t.ctx, &t,
timestamp_now + (365 + 2) * 24 * 60 * 60, timestamp_now + (365 + 2) * 24 * 60 * 60,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
let device_chat_id = chats.get_chat_id(0); let device_chat_id = chats.get_chat_id(0);
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
let test_len = msgs.len(); let test_len = msgs.len();
assert!(test_len == 1 || test_len == 2); assert!(test_len == 1 || test_len == 2);
// ... but every month // ... but every month
// (forward generous 33 days to avoid being in the same month as in the previous check) // (forward generous 33 days to avoid being in the same month as in the previous check)
maybe_warn_on_outdated( maybe_warn_on_outdated(
&t.ctx, &t,
timestamp_now + (365 + 33) * 24 * 60 * 60, timestamp_now + (365 + 33) * 24 * 60 * 60,
get_provider_update_timestamp(), get_provider_update_timestamp(),
) )
.await; .await;
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 1); assert_eq!(chats.len(), 1);
let device_chat_id = chats.get_chat_id(0); let device_chat_id = chats.get_chat_id(0);
let msgs = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
assert_eq!(msgs.len(), test_len + 1); assert_eq!(msgs.len(), test_len + 1);
} }
} }

View File

@@ -357,13 +357,13 @@ mod tests {
async fn test_prexisting() { async fn test_prexisting() {
let t = TestContext::new().await; let t = TestContext::new().await;
let test_addr = t.configure_alice().await; let test_addr = t.configure_alice().await;
assert_eq!(ensure_secret_key_exists(&t.ctx).await.unwrap(), test_addr); assert_eq!(ensure_secret_key_exists(&t).await.unwrap(), test_addr);
} }
#[async_std::test] #[async_std::test]
async fn test_not_configured() { async fn test_not_configured() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert!(ensure_secret_key_exists(&t.ctx).await.is_err()); assert!(ensure_secret_key_exists(&t).await.is_err());
} }
} }
@@ -526,28 +526,28 @@ Sent with my Delta Chat Messenger: https://delta.chat";
#[async_std::test] #[async_std::test]
async fn test_should_encrypt() { async fn test_should_encrypt() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let encrypt_helper = EncryptHelper::new(&t.ctx).await.unwrap(); let encrypt_helper = EncryptHelper::new(&t).await.unwrap();
// test with EncryptPreference::NoPreference: // test with EncryptPreference::NoPreference:
// if e2ee_eguaranteed is unset, there is no encryption as not more than half of peers want encryption // if e2ee_eguaranteed is unset, there is no encryption as not more than half of peers want encryption
let ps = new_peerstates(&t.ctx, EncryptPreference::NoPreference); let ps = new_peerstates(&t, EncryptPreference::NoPreference);
assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).unwrap()); assert!(encrypt_helper.should_encrypt(&t, true, &ps).unwrap());
assert!(!encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); assert!(!encrypt_helper.should_encrypt(&t, false, &ps).unwrap());
// test with EncryptPreference::Reset // test with EncryptPreference::Reset
let ps = new_peerstates(&t.ctx, EncryptPreference::Reset); let ps = new_peerstates(&t, EncryptPreference::Reset);
assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).unwrap()); assert!(encrypt_helper.should_encrypt(&t, true, &ps).unwrap());
assert!(!encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); assert!(!encrypt_helper.should_encrypt(&t, false, &ps).unwrap());
// test with EncryptPreference::Mutual (self is also Mutual) // test with EncryptPreference::Mutual (self is also Mutual)
let ps = new_peerstates(&t.ctx, EncryptPreference::Mutual); let ps = new_peerstates(&t, EncryptPreference::Mutual);
assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).unwrap()); assert!(encrypt_helper.should_encrypt(&t, true, &ps).unwrap());
assert!(encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); assert!(encrypt_helper.should_encrypt(&t, false, &ps).unwrap());
// test with missing peerstate // test with missing peerstate
let mut ps = Vec::new(); let mut ps = Vec::new();
ps.push((None, "bob@foo.bar")); ps.push((None, "bob@foo.bar"));
assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).is_err()); assert!(encrypt_helper.should_encrypt(&t, true, &ps).is_err());
assert!(!encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); assert!(!encrypt_helper.should_encrypt(&t, false, &ps).unwrap());
} }
} }

View File

@@ -909,7 +909,7 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
t.configure_alice().await; t.configure_alice().await;
let msg = render_setup_file(&t.ctx, "hello").await.unwrap(); let msg = render_setup_file(&t, "hello").await.unwrap();
println!("{}", &msg); println!("{}", &msg);
// Check some substrings, indicating things got substituted. // Check some substrings, indicating things got substituted.
// In particular note the mixing of `\r\n` and `\n` depending // In particular note the mixing of `\r\n` and `\n` depending
@@ -926,12 +926,11 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_render_setup_file_newline_replace() { async fn test_render_setup_file_newline_replace() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx t.set_stock_translation(StockMessage::AcSetupMsgBody, "hello\r\nthere".to_string())
.set_stock_translation(StockMessage::AcSetupMsgBody, "hello\r\nthere".to_string())
.await .await
.unwrap(); .unwrap();
t.configure_alice().await; t.configure_alice().await;
let msg = render_setup_file(&t.ctx, "pw").await.unwrap(); let msg = render_setup_file(&t, "pw").await.unwrap();
println!("{}", &msg); println!("{}", &msg);
assert!(msg.contains("<p>hello<br>there</p>")); assert!(msg.contains("<p>hello<br>there</p>"));
} }
@@ -939,7 +938,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_create_setup_code() { async fn test_create_setup_code() {
let t = TestContext::new().await; let t = TestContext::new().await;
let setupcode = create_setup_code(&t.ctx); let setupcode = create_setup_code(&t);
assert_eq!(setupcode.len(), 44); assert_eq!(setupcode.len(), 44);
assert_eq!(setupcode.chars().nth(4).unwrap(), '-'); assert_eq!(setupcode.chars().nth(4).unwrap(), '-');
assert_eq!(setupcode.chars().nth(9).unwrap(), '-'); assert_eq!(setupcode.chars().nth(9).unwrap(), '-');

View File

@@ -1372,18 +1372,18 @@ mod tests {
// fails to load from the database instead of failing to load // fails to load from the database instead of failing to load
// all jobs. // all jobs.
let t = TestContext::new().await; let t = TestContext::new().await;
insert_job(&t.ctx, -1).await; // This can not be loaded into Job struct. insert_job(&t, -1).await; // This can not be loaded into Job struct.
let jobs = load_next( let jobs = load_next(
&t.ctx, &t,
Thread::from(Action::MoveMsg), Thread::from(Action::MoveMsg),
&InterruptInfo::new(false, None), &InterruptInfo::new(false, None),
) )
.await; .await;
assert!(jobs.is_none()); assert!(jobs.is_none());
insert_job(&t.ctx, 1).await; insert_job(&t, 1).await;
let jobs = load_next( let jobs = load_next(
&t.ctx, &t,
Thread::from(Action::MoveMsg), Thread::from(Action::MoveMsg),
&InterruptInfo::new(false, None), &InterruptInfo::new(false, None),
) )
@@ -1395,10 +1395,10 @@ mod tests {
async fn test_load_next_job_one() { async fn test_load_next_job_one() {
let t = TestContext::new().await; let t = TestContext::new().await;
insert_job(&t.ctx, 1).await; insert_job(&t, 1).await;
let jobs = load_next( let jobs = load_next(
&t.ctx, &t,
Thread::from(Action::MoveMsg), Thread::from(Action::MoveMsg),
&InterruptInfo::new(false, None), &InterruptInfo::new(false, None),
) )

View File

@@ -558,31 +558,31 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
let alice = alice_keypair(); let alice = alice_keypair();
let t = TestContext::new().await; let t = TestContext::new().await;
t.configure_alice().await; t.configure_alice().await;
let pubkey = SignedPublicKey::load_self(&t.ctx).await.unwrap(); let pubkey = SignedPublicKey::load_self(&t).await.unwrap();
assert_eq!(alice.public, pubkey); assert_eq!(alice.public, pubkey);
let seckey = SignedSecretKey::load_self(&t.ctx).await.unwrap(); let seckey = SignedSecretKey::load_self(&t).await.unwrap();
assert_eq!(alice.secret, seckey); assert_eq!(alice.secret, seckey);
} }
#[async_std::test] #[async_std::test]
async fn test_load_self_generate_public() { async fn test_load_self_generate_public() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx t
.set_config(Config::ConfiguredAddr, Some("alice@example.com")) .set_config(Config::ConfiguredAddr, Some("alice@example.com"))
.await .await
.unwrap(); .unwrap();
let key = SignedPublicKey::load_self(&t.ctx).await; let key = SignedPublicKey::load_self(&t).await;
assert!(key.is_ok()); assert!(key.is_ok());
} }
#[async_std::test] #[async_std::test]
async fn test_load_self_generate_secret() { async fn test_load_self_generate_secret() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx t
.set_config(Config::ConfiguredAddr, Some("alice@example.com")) .set_config(Config::ConfiguredAddr, Some("alice@example.com"))
.await .await
.unwrap(); .unwrap();
let key = SignedSecretKey::load_self(&t.ctx).await; let key = SignedSecretKey::load_self(&t).await;
assert!(key.is_ok()); assert!(key.is_ok());
} }
@@ -591,11 +591,11 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
use std::thread; use std::thread;
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx t
.set_config(Config::ConfiguredAddr, Some("alice@example.com")) .set_config(Config::ConfiguredAddr, Some("alice@example.com"))
.await .await
.unwrap(); .unwrap();
let ctx = t.ctx.clone(); let ctx = t.clone();
let ctx0 = ctx.clone(); let ctx0 = ctx.clone();
let thr0 = let thr0 =
thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx0))); thread::spawn(move || async_std::task::block_on(SignedPublicKey::load_self(&ctx0)));
@@ -618,7 +618,7 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD
// Saving the same key twice should result in only one row in // Saving the same key twice should result in only one row in
// the keypairs table. // the keypairs table.
let t = TestContext::new().await; let t = TestContext::new().await;
let ctx = Arc::new(t.ctx); let ctx = Arc::new(t);
let ctx1 = ctx.clone(); let ctx1 = ctx.clone();
let nrows = || async { let nrows = || async {

View File

@@ -83,10 +83,10 @@ mod tests {
t.configure_alice().await; t.configure_alice().await;
let alice = alice_keypair(); let alice = alice_keypair();
let pub_ring: Keyring<SignedPublicKey> = Keyring::new_self(&t.ctx).await.unwrap(); let pub_ring: Keyring<SignedPublicKey> = Keyring::new_self(&t).await.unwrap();
assert_eq!(pub_ring.keys(), [alice.public]); assert_eq!(pub_ring.keys(), [alice.public]);
let sec_ring: Keyring<SignedSecretKey> = Keyring::new_self(&t.ctx).await.unwrap(); let sec_ring: Keyring<SignedSecretKey> = Keyring::new_self(&t).await.unwrap();
assert_eq!(sec_ring.keys(), [alice.secret]); assert_eq!(sec_ring.keys(), [alice.secret]);
} }
} }

View File

@@ -2057,17 +2057,17 @@ mod tests {
// test that get_width() and get_height() are returning some dimensions for images; // test that get_width() and get_height() are returning some dimensions for images;
// (as the device-chat contains a welcome-images, we check that) // (as the device-chat contains a welcome-images, we check that)
t.ctx.update_device_chats().await.ok(); t.update_device_chats().await.ok();
let (device_chat_id, _) = let (device_chat_id, _) =
chat::create_or_lookup_by_contact_id(&t.ctx, DC_CONTACT_ID_DEVICE, Blocked::Not) chat::create_or_lookup_by_contact_id(&t, DC_CONTACT_ID_DEVICE, Blocked::Not)
.await .await
.unwrap(); .unwrap();
let mut has_image = false; let mut has_image = false;
let chatitems = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None).await; let chatitems = chat::get_chat_msgs(&t, device_chat_id, 0, None).await;
for chatitem in chatitems { for chatitem in chatitems {
if let ChatItem::Message { msg_id } = chatitem { if let ChatItem::Message { msg_id } = chatitem {
if let Ok(msg) = Message::load_from_db(&t.ctx, msg_id).await { if let Ok(msg) = Message::load_from_db(&t, msg_id).await {
if msg.get_viewtype() == Viewtype::Image { if msg.get_viewtype() == Viewtype::Image {
has_image = true; has_image = true;
// just check that width/height are inside some reasonable ranges // just check that width/height are inside some reasonable ranges

View File

@@ -1417,7 +1417,7 @@ mod tests {
assert_eq!(first_subject_str(t).await, "Message from alice@example.com"); assert_eq!(first_subject_str(t).await, "Message from alice@example.com");
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
t.ctx t
.set_config(Config::Displayname, Some("Alice")) .set_config(Config::Displayname, Some("Alice"))
.await .await
.unwrap(); .unwrap();
@@ -1453,7 +1453,7 @@ mod tests {
// 5. Receive an mdn (read receipt) and make sure the mdn's subject is not used // 5. Receive an mdn (read receipt) and make sure the mdn's subject is not used
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
dc_receive_imf( dc_receive_imf(
&t.ctx, &t,
b"From: alice@example.com\n\ b"From: alice@example.com\n\
To: Charlie <charlie@example.com>\n\ To: Charlie <charlie@example.com>\n\
Subject: Hello, Charlie\n\ Subject: Hello, Charlie\n\
@@ -1491,8 +1491,8 @@ mod tests {
Final-Recipient: rfc822;charlie@example.com\n\ Final-Recipient: rfc822;charlie@example.com\n\
Original-Message-ID: <2893@example.com>\n\ Original-Message-ID: <2893@example.com>\n\
Disposition: manual-action/MDN-sent-automatically; displayed\n\ Disposition: manual-action/MDN-sent-automatically; displayed\n\
\n", &t.ctx).await; \n", &t).await;
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) let mf = MimeFactory::from_msg(&t, &new_msg, false)
.await .await
.unwrap(); .unwrap();
// The subject string should not be "Re: message opened" // The subject string should not be "Re: message opened"
@@ -1501,23 +1501,23 @@ mod tests {
async fn first_subject_str(t: TestContext) -> String { async fn first_subject_str(t: TestContext) -> String {
let contact_id = let contact_id =
Contact::add_or_lookup(&t.ctx, "Dave", "dave@example.com", Origin::ManuallyCreated) Contact::add_or_lookup(&t, "Dave", "dave@example.com", Origin::ManuallyCreated)
.await .await
.unwrap() .unwrap()
.0; .0;
let chat_id = chat::create_by_contact_id(&t.ctx, contact_id) let chat_id = chat::create_by_contact_id(&t, contact_id)
.await .await
.unwrap(); .unwrap();
let mut new_msg = Message::new(Viewtype::Text); let mut new_msg = Message::new(Viewtype::Text);
new_msg.set_text(Some("Hi".to_string())); new_msg.set_text(Some("Hi".to_string()));
new_msg.chat_id = chat_id; new_msg.chat_id = chat_id;
chat::prepare_msg(&t.ctx, chat_id, &mut new_msg) chat::prepare_msg(&t, chat_id, &mut new_msg)
.await .await
.unwrap(); .unwrap();
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) let mf = MimeFactory::from_msg(&t, &new_msg, false)
.await .await
.unwrap(); .unwrap();
@@ -1526,8 +1526,8 @@ mod tests {
async fn msg_to_subject_str(imf_raw: &[u8]) -> String { async fn msg_to_subject_str(imf_raw: &[u8]) -> String {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let new_msg = incoming_msg_to_reply_msg(imf_raw, &t.ctx).await; let new_msg = incoming_msg_to_reply_msg(imf_raw, &t).await;
let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) let mf = MimeFactory::from_msg(&t, &new_msg, false)
.await .await
.unwrap(); .unwrap();
mf.subject_str().await mf.subject_str().await
@@ -1564,7 +1564,7 @@ mod tests {
// This test could still be extended // This test could still be extended
async fn test_render_reply() { async fn test_render_reply() {
let t = TestContext::new_alice().await; let t = TestContext::new_alice().await;
let context = &t.ctx; let context = &t;
let msg = incoming_msg_to_reply_msg( let msg = incoming_msg_to_reply_msg(
b"From: Charlie <charlie@example.com>\n\ b"From: Charlie <charlie@example.com>\n\
@@ -1579,7 +1579,7 @@ mod tests {
) )
.await; .await;
let mimefactory = MimeFactory::from_msg(&t.ctx, &msg, false).await.unwrap(); let mimefactory = MimeFactory::from_msg(&t, &msg, false).await.unwrap();
let recipients = mimefactory.recipients(); let recipients = mimefactory.recipients();
assert_eq!(recipients, vec!["charlie@example.com"]); assert_eq!(recipients, vec!["charlie@example.com"]);

View File

@@ -1493,8 +1493,8 @@ mod tests {
fn load_mail_with_attachment<'a>(t: &'a TestContext, raw: &'a [u8]) -> ParsedMail<'a> { fn load_mail_with_attachment<'a>(t: &'a TestContext, raw: &'a [u8]) -> ParsedMail<'a> {
let mail = mailparse::parse_mail(raw).unwrap(); let mail = mailparse::parse_mail(raw).unwrap();
assert!(get_attachment_filename(&t.ctx, &mail).unwrap().is_none()); assert!(get_attachment_filename(&t, &mail).unwrap().is_none());
assert!(get_attachment_filename(&t.ctx, &mail.subparts[0]) assert!(get_attachment_filename(&t, &mail.subparts[0])
.unwrap() .unwrap()
.is_none()); .is_none());
mail mail
@@ -1507,7 +1507,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_simple.eml"), include_bytes!("../test-data/message/attach_filename_simple.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("test.html".to_string())) assert_eq!(filename, Some("test.html".to_string()))
} }
@@ -1518,7 +1518,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_encoded_words.eml"), include_bytes!("../test-data/message/attach_filename_encoded_words.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string())) assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string()))
} }
@@ -1529,7 +1529,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_encoded_words_binary.eml"), include_bytes!("../test-data/message/attach_filename_encoded_words_binary.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some(" § 165 Abs".to_string())) assert_eq!(filename, Some(" § 165 Abs".to_string()))
} }
@@ -1540,7 +1540,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_encoded_words_windows1251.eml"), include_bytes!("../test-data/message/attach_filename_encoded_words_windows1251.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("file Что нового 2020.pdf".to_string())) assert_eq!(filename, Some("file Что нового 2020.pdf".to_string()))
} }
@@ -1552,7 +1552,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_encoded_words_cont.eml"), include_bytes!("../test-data/message/attach_filename_encoded_words_cont.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("Maßn'ah'men Okt. 2020.html".to_string())) assert_eq!(filename, Some("Maßn'ah'men Okt. 2020.html".to_string()))
} }
@@ -1563,7 +1563,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_encoded_words_bad_delimiter.eml"), include_bytes!("../test-data/message/attach_filename_encoded_words_bad_delimiter.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
// not decoded as a space is missing after encoded-words part // not decoded as a space is missing after encoded-words part
assert_eq!(filename, Some("=?utf-8?q?foo?=.bar".to_string())) assert_eq!(filename, Some("=?utf-8?q?foo?=.bar".to_string()))
} }
@@ -1575,7 +1575,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_apostrophed.eml"), include_bytes!("../test-data/message/attach_filename_apostrophed.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("Maßnahmen Okt. 2021.html".to_string())) assert_eq!(filename, Some("Maßnahmen Okt. 2021.html".to_string()))
} }
@@ -1586,7 +1586,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_apostrophed_cont.eml"), include_bytes!("../test-data/message/attach_filename_apostrophed_cont.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("Maßnahmen März 2022.html".to_string())) assert_eq!(filename, Some("Maßnahmen März 2022.html".to_string()))
} }
@@ -1597,7 +1597,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_apostrophed_windows1251.eml"), include_bytes!("../test-data/message/attach_filename_apostrophed_windows1251.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("программирование.HTM".to_string())) assert_eq!(filename, Some("программирование.HTM".to_string()))
} }
@@ -1608,7 +1608,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_apostrophed_cp1252.eml"), include_bytes!("../test-data/message/attach_filename_apostrophed_cp1252.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("Auftragsbestätigung.pdf".to_string())) assert_eq!(filename, Some("Auftragsbestätigung.pdf".to_string()))
} }
@@ -1619,7 +1619,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_apostrophed_invalid.eml"), include_bytes!("../test-data/message/attach_filename_apostrophed_invalid.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("somedäüta.html.zip".to_string())) assert_eq!(filename, Some("somedäüta.html.zip".to_string()))
} }
@@ -1631,7 +1631,7 @@ mod tests {
&t, &t,
include_bytes!("../test-data/message/attach_filename_combined.eml"), include_bytes!("../test-data/message/attach_filename_combined.eml"),
); );
let filename = get_attachment_filename(&t.ctx, &mail.subparts[1]).unwrap(); let filename = get_attachment_filename(&t, &mail.subparts[1]).unwrap();
assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string())) assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string()))
} }
@@ -1764,26 +1764,26 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let raw = include_bytes!("../test-data/message/mail_attach_txt.eml"); let raw = include_bytes!("../test-data/message/mail_attach_txt.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap();
assert_eq!(mimeparser.user_avatar, None); assert_eq!(mimeparser.user_avatar, None);
assert_eq!(mimeparser.group_avatar, None); assert_eq!(mimeparser.group_avatar, None);
let raw = include_bytes!("../test-data/message/mail_with_user_avatar.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_avatar.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Text); assert_eq!(mimeparser.parts[0].typ, Viewtype::Text);
assert!(mimeparser.user_avatar.unwrap().is_change()); assert!(mimeparser.user_avatar.unwrap().is_change());
assert_eq!(mimeparser.group_avatar, None); assert_eq!(mimeparser.group_avatar, None);
let raw = include_bytes!("../test-data/message/mail_with_user_avatar_deleted.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_avatar_deleted.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Text); assert_eq!(mimeparser.parts[0].typ, Viewtype::Text);
assert_eq!(mimeparser.user_avatar, Some(AvatarAction::Delete)); assert_eq!(mimeparser.user_avatar, Some(AvatarAction::Delete));
assert_eq!(mimeparser.group_avatar, None); assert_eq!(mimeparser.group_avatar, None);
let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::Text); assert_eq!(mimeparser.parts[0].typ, Viewtype::Text);
assert!(mimeparser.user_avatar.unwrap().is_change()); assert!(mimeparser.user_avatar.unwrap().is_change());
@@ -1793,7 +1793,7 @@ mod tests {
let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml"); let raw = include_bytes!("../test-data/message/mail_with_user_and_group_avatars.eml");
let raw = String::from_utf8_lossy(raw).to_string(); let raw = String::from_utf8_lossy(raw).to_string();
let raw = raw.replace("Chat-User-Avatar:", "Xhat-Xser-Xvatar:"); let raw = raw.replace("Chat-User-Avatar:", "Xhat-Xser-Xvatar:");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw.as_bytes()) let mimeparser = MimeMessage::from_bytes(&t, raw.as_bytes())
.await .await
.unwrap(); .unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
@@ -1807,7 +1807,7 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
let raw = include_bytes!("../test-data/message/videochat_invitation.eml"); let raw = include_bytes!("../test-data/message/videochat_invitation.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap();
assert_eq!(mimeparser.parts.len(), 1); assert_eq!(mimeparser.parts.len(), 1);
assert_eq!(mimeparser.parts[0].typ, Viewtype::VideochatInvitation); assert_eq!(mimeparser.parts[0].typ, Viewtype::VideochatInvitation);
assert_eq!( assert_eq!(
@@ -2121,7 +2121,7 @@ MDYyMDYxNTE1RTlDOEE4Cj4+CnN0YXJ0eHJlZgo4Mjc4CiUlRU9GCg==
------=_Part_25_46172632.1581201680436-- ------=_Part_25_46172632.1581201680436--
"#; "#;
let message = MimeMessage::from_bytes(&t.ctx, &raw[..]).await.unwrap(); let message = MimeMessage::from_bytes(&t, &raw[..]).await.unwrap();
assert_eq!(message.parts.len(), 1); assert_eq!(message.parts.len(), 1);
assert_eq!(message.parts[0].typ, Viewtype::File); assert_eq!(message.parts[0].typ, Viewtype::File);
@@ -2130,7 +2130,7 @@ MDYyMDYxNTE1RTlDOEE4Cj4+CnN0YXJ0eHJlZgo4Mjc4CiUlRU9GCg==
// Make sure the file is there even though the html is wrong: // Make sure the file is there even though the html is wrong:
let param = &message.parts[0].param; let param = &message.parts[0].param;
let blob: BlobObject = param let blob: BlobObject = param
.get_blob(Param::File, &t.ctx, false) .get_blob(Param::File, &t, false)
.await .await
.unwrap() .unwrap()
.unwrap(); .unwrap();
@@ -2518,7 +2518,7 @@ On 2020-10-25, Bob wrote:
async fn test_quote_div() { async fn test_quote_div() {
let t = TestContext::new().await; let t = TestContext::new().await;
let raw = include_bytes!("../test-data/message/gmx-quote.eml"); let raw = include_bytes!("../test-data/message/gmx-quote.eml");
let mimeparser = MimeMessage::from_bytes(&t.ctx, raw).await.unwrap(); let mimeparser = MimeMessage::from_bytes(&t, raw).await.unwrap();
assert_eq!(mimeparser.parts[0].msg, "YIPPEEEEEE\n\nMulti-line"); assert_eq!(mimeparser.parts[0].msg, "YIPPEEEEEE\n\nMulti-line");
assert_eq!(mimeparser.parts[0].param.get(Param::Quote).unwrap(), "Now?"); assert_eq!(mimeparser.parts[0].param.get(Param::Quote).unwrap(), "Now?");
} }

View File

@@ -436,7 +436,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_params_file_fs_path() { async fn test_params_file_fs_path() {
let t = TestContext::new().await; let t = TestContext::new().await;
if let ParamsFile::FsPath(p) = ParamsFile::from_param(&t.ctx, "/foo/bar/baz").unwrap() { if let ParamsFile::FsPath(p) = ParamsFile::from_param(&t, "/foo/bar/baz").unwrap() {
assert_eq!(p, Path::new("/foo/bar/baz")); assert_eq!(p, Path::new("/foo/bar/baz"));
} else { } else {
panic!("Wrong enum variant"); panic!("Wrong enum variant");
@@ -446,7 +446,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_params_file_blob() { async fn test_params_file_blob() {
let t = TestContext::new().await; let t = TestContext::new().await;
if let ParamsFile::Blob(b) = ParamsFile::from_param(&t.ctx, "$BLOBDIR/foo").unwrap() { if let ParamsFile::Blob(b) = ParamsFile::from_param(&t, "$BLOBDIR/foo").unwrap() {
assert_eq!(b.as_name(), "$BLOBDIR/foo"); assert_eq!(b.as_name(), "$BLOBDIR/foo");
} else { } else {
panic!("Wrong enum variant"); panic!("Wrong enum variant");
@@ -461,15 +461,15 @@ mod tests {
let mut p = Params::new(); let mut p = Params::new();
p.set(Param::File, fname.to_str().unwrap()); p.set(Param::File, fname.to_str().unwrap());
let file = p.get_file(Param::File, &t.ctx).unwrap().unwrap(); let file = p.get_file(Param::File, &t).unwrap().unwrap();
assert_eq!(file, ParamsFile::FsPath(fname.clone().into())); assert_eq!(file, ParamsFile::FsPath(fname.clone().into()));
let path: PathBuf = p.get_path(Param::File, &t.ctx).unwrap().unwrap(); let path: PathBuf = p.get_path(Param::File, &t).unwrap().unwrap();
let fname: PathBuf = fname.into(); let fname: PathBuf = fname.into();
assert_eq!(path, fname); assert_eq!(path, fname);
// Blob does not exist yet, expect BlobError. // Blob does not exist yet, expect BlobError.
let err = p.get_blob(Param::File, &t.ctx, false).await.unwrap_err(); let err = p.get_blob(Param::File, &t, false).await.unwrap_err();
match err { match err {
BlobError::WrongBlobdir { .. } => (), BlobError::WrongBlobdir { .. } => (),
_ => panic!("wrong error type/variant: {:?}", err), _ => panic!("wrong error type/variant: {:?}", err),
@@ -477,33 +477,33 @@ mod tests {
fs::write(fname, b"boo").await.unwrap(); fs::write(fname, b"boo").await.unwrap();
let blob = p let blob = p
.get_blob(Param::File, &t.ctx, true) .get_blob(Param::File, &t, true)
.await .await
.unwrap() .unwrap()
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
blob, blob,
BlobObject::from_name(&t.ctx, "foo".to_string()).unwrap() BlobObject::from_name(&t, "foo".to_string()).unwrap()
); );
// Blob in blobdir, expect blob. // Blob in blobdir, expect blob.
let bar_path = t.ctx.get_blobdir().join("bar"); let bar_path = t.get_blobdir().join("bar");
p.set(Param::File, bar_path.to_str().unwrap()); p.set(Param::File, bar_path.to_str().unwrap());
let blob = p let blob = p
.get_blob(Param::File, &t.ctx, false) .get_blob(Param::File, &t, false)
.await .await
.unwrap() .unwrap()
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
blob, blob,
BlobObject::from_name(&t.ctx, "bar".to_string()).unwrap() BlobObject::from_name(&t, "bar".to_string()).unwrap()
); );
p.remove(Param::File); p.remove(Param::File);
assert!(p.get_file(Param::File, &t.ctx).unwrap().is_none()); assert!(p.get_file(Param::File, &t).unwrap().is_none());
assert!(p.get_path(Param::File, &t.ctx).unwrap().is_none()); assert!(p.get_path(Param::File, &t).unwrap().is_none());
assert!(p assert!(p
.get_blob(Param::File, &t.ctx, false) .get_blob(Param::File, &t, false)
.await .await
.unwrap() .unwrap()
.is_none()); .is_none());

View File

@@ -485,11 +485,10 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_set_stock_translation() { async fn test_set_stock_translation() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx t.set_stock_translation(StockMessage::NoMessages, "xyz".to_string())
.set_stock_translation(StockMessage::NoMessages, "xyz".to_string())
.await .await
.unwrap(); .unwrap();
assert_eq!(t.ctx.stock_str(StockMessage::NoMessages).await, "xyz") assert_eq!(t.stock_str(StockMessage::NoMessages).await, "xyz")
} }
#[async_std::test] #[async_std::test]
@@ -510,10 +509,7 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_stock_str() { async fn test_stock_str() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_eq!( assert_eq!(t.stock_str(StockMessage::NoMessages).await, "No messages.");
t.ctx.stock_str(StockMessage::NoMessages).await,
"No messages."
);
} }
#[async_std::test] #[async_std::test]
@@ -521,8 +517,7 @@ mod tests {
let t = TestContext::new().await; let t = TestContext::new().await;
// uses %1$s substitution // uses %1$s substitution
assert_eq!( assert_eq!(
t.ctx t.stock_string_repl_str(StockMessage::MsgAddMember, "Foo")
.stock_string_repl_str(StockMessage::MsgAddMember, "Foo")
.await, .await,
"Member Foo added." "Member Foo added."
); );
@@ -533,8 +528,7 @@ mod tests {
async fn test_stock_string_repl_int() { async fn test_stock_string_repl_int() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_eq!( assert_eq!(
t.ctx t.stock_string_repl_int(StockMessage::MsgAddMember, 42)
.stock_string_repl_int(StockMessage::MsgAddMember, 42)
.await, .await,
"Member 42 added." "Member 42 added."
); );
@@ -544,8 +538,7 @@ mod tests {
async fn test_stock_string_repl_str2() { async fn test_stock_string_repl_str2() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_eq!( assert_eq!(
t.ctx t.stock_string_repl_str2(StockMessage::ServerResponse, "foo", "bar")
.stock_string_repl_str2(StockMessage::ServerResponse, "foo", "bar")
.await, .await,
"Could not connect to foo: bar" "Could not connect to foo: bar"
); );
@@ -555,8 +548,7 @@ mod tests {
async fn test_stock_system_msg_simple() { async fn test_stock_system_msg_simple() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_eq!( assert_eq!(
t.ctx t.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0)
.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0)
.await, .await,
"Location streaming enabled." "Location streaming enabled."
) )
@@ -566,8 +558,7 @@ mod tests {
async fn test_stock_system_msg_add_member_by_me() { async fn test_stock_system_msg_add_member_by_me() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_eq!( assert_eq!(
t.ctx t.stock_system_msg(
.stock_system_msg(
StockMessage::MsgAddMember, StockMessage::MsgAddMember,
"alice@example.com", "alice@example.com",
"", "",
@@ -581,12 +572,11 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_stock_system_msg_add_member_by_me_with_displayname() { async fn test_stock_system_msg_add_member_by_me_with_displayname() {
let t = TestContext::new().await; let t = TestContext::new().await;
Contact::create(&t.ctx, "Alice", "alice@example.com") Contact::create(&t, "Alice", "alice@example.com")
.await .await
.expect("failed to create contact"); .expect("failed to create contact");
assert_eq!( assert_eq!(
t.ctx t.stock_system_msg(
.stock_system_msg(
StockMessage::MsgAddMember, StockMessage::MsgAddMember,
"alice@example.com", "alice@example.com",
"", "",
@@ -601,16 +591,15 @@ mod tests {
async fn test_stock_system_msg_add_member_by_other_with_displayname() { async fn test_stock_system_msg_add_member_by_other_with_displayname() {
let t = TestContext::new().await; let t = TestContext::new().await;
let contact_id = { let contact_id = {
Contact::create(&t.ctx, "Alice", "alice@example.com") Contact::create(&t, "Alice", "alice@example.com")
.await .await
.expect("Failed to create contact Alice"); .expect("Failed to create contact Alice");
Contact::create(&t.ctx, "Bob", "bob@example.com") Contact::create(&t, "Bob", "bob@example.com")
.await .await
.expect("failed to create bob") .expect("failed to create bob")
}; };
assert_eq!( assert_eq!(
t.ctx t.stock_system_msg(
.stock_system_msg(
StockMessage::MsgAddMember, StockMessage::MsgAddMember,
"alice@example.com", "alice@example.com",
"", "",
@@ -625,8 +614,7 @@ mod tests {
async fn test_stock_system_msg_grp_name() { async fn test_stock_system_msg_grp_name() {
let t = TestContext::new().await; let t = TestContext::new().await;
assert_eq!( assert_eq!(
t.ctx t.stock_system_msg(
.stock_system_msg(
StockMessage::MsgGrpName, StockMessage::MsgGrpName,
"Some chat", "Some chat",
"Other chat", "Other chat",
@@ -640,13 +628,12 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_stock_system_msg_grp_name_other() { async fn test_stock_system_msg_grp_name_other() {
let t = TestContext::new().await; let t = TestContext::new().await;
let id = Contact::create(&t.ctx, "Alice", "alice@example.com") let id = Contact::create(&t, "Alice", "alice@example.com")
.await .await
.expect("failed to create contact"); .expect("failed to create contact");
assert_eq!( assert_eq!(
t.ctx t.stock_system_msg(StockMessage::MsgGrpName, "Some chat", "Other chat", id)
.stock_system_msg(StockMessage::MsgGrpName, "Some chat", "Other chat", id)
.await, .await,
"Group name changed from \"Some chat\" to \"Other chat\" by Alice (alice@example.com)." "Group name changed from \"Some chat\" to \"Other chat\" by Alice (alice@example.com)."
) )
@@ -655,13 +642,11 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_update_device_chats() { async fn test_update_device_chats() {
let t = TestContext::new().await; let t = TestContext::new().await;
t.ctx.update_device_chats().await.ok(); t.update_device_chats().await.ok();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 2); assert_eq!(chats.len(), 2);
let chat0 = Chat::load_from_db(&t.ctx, chats.get_chat_id(0)) let chat0 = Chat::load_from_db(&t, chats.get_chat_id(0)).await.unwrap();
.await
.unwrap();
let (self_talk_id, device_chat_id) = if chat0.is_self_talk() { let (self_talk_id, device_chat_id) = if chat0.is_self_talk() {
(chats.get_chat_id(0), chats.get_chat_id(1)) (chats.get_chat_id(0), chats.get_chat_id(1))
} else { } else {
@@ -669,27 +654,23 @@ mod tests {
}; };
// delete self-talk first; this adds a message to device-chat about how self-talk can be restored // delete self-talk first; this adds a message to device-chat about how self-talk can be restored
let device_chat_msgs_before = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None) let device_chat_msgs_before = chat::get_chat_msgs(&t, device_chat_id, 0, None).await.len();
.await self_talk_id.delete(&t).await.ok();
.len();
self_talk_id.delete(&t.ctx).await.ok();
assert_eq!( assert_eq!(
chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None) chat::get_chat_msgs(&t, device_chat_id, 0, None).await.len(),
.await
.len(),
device_chat_msgs_before + 1 device_chat_msgs_before + 1
); );
// delete device chat // delete device chat
device_chat_id.delete(&t.ctx).await.ok(); device_chat_id.delete(&t).await.ok();
// check, that the chatlist is empty // check, that the chatlist is empty
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
// a subsequent call to update_device_chats() must not re-add manally deleted messages or chats // a subsequent call to update_device_chats() must not re-add manally deleted messages or chats
t.ctx.update_device_chats().await.ok(); t.update_device_chats().await.ok();
let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.len(), 0); assert_eq!(chats.len(), 0);
} }
} }

View File

@@ -77,7 +77,7 @@ impl TestContext {
let t = Self::new().await; let t = Self::new().await;
let keypair = bob_keypair(); let keypair = bob_keypair();
t.configure_addr(&keypair.addr.to_string()).await; t.configure_addr(&keypair.addr.to_string()).await;
key::store_self_keypair(&t.ctx, &keypair, key::KeyPairUse::Default) key::store_self_keypair(&t, &keypair, key::KeyPairUse::Default)
.await .await
.expect("Failed to save Bob's key"); .expect("Failed to save Bob's key");
t t