diff --git a/src/blob.rs b/src/blob.rs index f164be5e8..fc345f86d 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -525,18 +525,18 @@ mod tests { #[async_std::test] async fn test_create() { let t = TestContext::new().await; - let blob = BlobObject::create(&t.ctx, "foo", b"hello").await.unwrap(); - let fname = t.ctx.get_blobdir().join("foo"); + let blob = BlobObject::create(&t, "foo", b"hello").await.unwrap(); + let fname = t.get_blobdir().join("foo"); let data = fs::read(fname).await.unwrap(); assert_eq!(data, b"hello"); 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 fn test_lowercase_ext() { 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 .unwrap(); assert_eq!(blob.as_name(), "$BLOBDIR/foo.txt"); @@ -545,7 +545,7 @@ mod tests { #[async_std::test] async fn test_as_file_name() { 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 .unwrap(); assert_eq!(blob.as_file_name(), "foo.txt"); @@ -554,7 +554,7 @@ mod tests { #[async_std::test] async fn test_as_rel_path() { 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 .unwrap(); assert_eq!(blob.as_rel_path(), Path::new("foo.txt")); @@ -563,26 +563,26 @@ mod tests { #[async_std::test] async fn test_suffix() { 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 .unwrap(); 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); } #[async_std::test] async fn test_create_dup() { let t = TestContext::new().await; - BlobObject::create(&t.ctx, "foo.txt", b"hello") + BlobObject::create(&t, "foo.txt", b"hello") .await .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); - BlobObject::create(&t.ctx, "foo.txt", b"world") + BlobObject::create(&t, "foo.txt", b"world") .await .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 { let fname = dirent.unwrap().file_name(); if fname == foo_path.file_name().unwrap() { @@ -598,15 +598,15 @@ mod tests { #[async_std::test] async fn test_double_ext_preserved() { let t = TestContext::new().await; - BlobObject::create(&t.ctx, "foo.tar.gz", b"hello") + BlobObject::create(&t, "foo.tar.gz", b"hello") .await .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); - BlobObject::create(&t.ctx, "foo.tar.gz", b"world") + BlobObject::create(&t, "foo.tar.gz", b"world") .await .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 { let fname = dirent.unwrap().file_name(); if fname == foo_path.file_name().unwrap() { @@ -624,7 +624,7 @@ mod tests { async fn test_create_long_names() { let t = TestContext::new().await; 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(); assert!(blobname.len() < 128); } @@ -634,14 +634,14 @@ mod tests { let t = TestContext::new().await; let src = t.dir.path().join("src"); 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"); let data = fs::read(blob.to_abs_path()).await.unwrap(); assert_eq!(data, b"boo"); let whoops = t.dir.path().join("whoops"); - assert!(BlobObject::create_and_copy(&t.ctx, &whoops).await.is_err()); - let whoops = t.ctx.get_blobdir().join("whoops"); + assert!(BlobObject::create_and_copy(&t, &whoops).await.is_err()); + let whoops = t.get_blobdir().join("whoops"); assert!(!whoops.exists().await); } @@ -651,14 +651,14 @@ mod tests { let src_ext = t.dir.path().join("external"); 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"); let data = fs::read(blob.to_abs_path()).await.unwrap(); 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(); - 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"); let data = fs::read(blob.to_abs_path()).await.unwrap(); assert_eq!(data, b"boo"); @@ -668,7 +668,7 @@ mod tests { let t = TestContext::new().await; let src_ext = t.dir.path().join("autocrypt-setup-message-4137848473.html"); 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/autocrypt-setup-message-4137848473.html" diff --git a/src/chat.rs b/src/chat.rs index 085be53c7..975d19751 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -2977,7 +2977,7 @@ mod tests { async fn test_chat_info() { let t = TestContext::new().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. println!("{}", serde_json::to_string_pretty(&info).unwrap()); @@ -3008,7 +3008,7 @@ mod tests { async fn test_get_draft_no_draft() { let t = TestContext::new().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()); } @@ -3016,7 +3016,7 @@ mod tests { async fn test_get_draft_special_chat_id() { let t = TestContext::new().await; let draft = ChatId::new(DC_CHAT_ID_LAST_SPECIAL) - .get_draft(&t.ctx) + .get_draft(&t) .await .unwrap(); assert!(draft.is_none()); @@ -3027,7 +3027,7 @@ mod tests { // This is a weird case, maybe this should be an error but we // do not get this info from the database currently. 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()); } @@ -3037,8 +3037,8 @@ mod tests { let chat_id = &t.get_self_chat().await.id; let mut msg = Message::new(Viewtype::Text); msg.set_text(Some("hello".to_string())); - chat_id.set_draft(&t.ctx, Some(&mut msg)).await; - let draft = chat_id.get_draft(&t.ctx).await.unwrap().unwrap(); + chat_id.set_draft(&t, Some(&mut msg)).await; + let draft = chat_id.get_draft(&t).await.unwrap().unwrap(); let msg_text = msg.get_text(); let draft_text = draft.get_text(); assert_eq!(msg_text, draft_text); @@ -3048,10 +3048,10 @@ mod tests { async fn test_add_contact_to_chat_ex_add_self() { // Adding self to a contact should succeed, even though it's pointless. 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 .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 .unwrap(); assert_eq!(added, false); @@ -3067,17 +3067,14 @@ mod tests { assert!(chat.visibility == ChatVisibility::Normal); assert!(!chat.is_device_talk()); assert!(chat.can_send()); - assert_eq!( - chat.name, - t.ctx.stock_str(StockMessage::SavedMessages).await - ); - assert!(chat.get_profile_image(&t.ctx).await.is_some()); + assert_eq!(chat.name, t.stock_str(StockMessage::SavedMessages).await); + assert!(chat.get_profile_image(&t).await.is_some()); } #[async_std::test] async fn test_deaddrop_chat() { 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 .unwrap(); assert_eq!(DC_CHAT_ID_DEADDROP, 1); @@ -3086,7 +3083,7 @@ mod tests { assert!(chat.visibility == ChatVisibility::Normal); assert!(!chat.is_device_talk()); 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] @@ -3096,17 +3093,17 @@ mod tests { // add two device-messages let mut msg1 = Message::new(Viewtype::Text); 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()); let mut msg2 = Message::new(Viewtype::Text); 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_ne!(msg1_id.as_ref().unwrap(), msg2_id.as_ref().unwrap()); // 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()); let msg1 = msg1.unwrap(); assert_eq!(msg1.text.as_ref().unwrap(), "first message"); @@ -3115,13 +3112,13 @@ mod tests { assert!(!msg1.is_info()); 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()); let msg2 = msg2.unwrap(); assert_eq!(msg2.text.as_ref().unwrap(), "second message"); // 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] @@ -3131,18 +3128,18 @@ mod tests { // add two device-messages with the same label (second attempt is not added) let mut msg1 = Message::new(Viewtype::Text); 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.as_ref().unwrap().is_unset()); let mut msg2 = Message::new(Viewtype::Text); 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.as_ref().unwrap().is_unset()); // 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()); let msg1 = msg1.unwrap(); assert_eq!(msg1_id.as_ref().unwrap(), &msg1.id); @@ -3154,26 +3151,23 @@ mod tests { // check device chat 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()); - 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()); let chat = chat.unwrap(); assert_eq!(chat.get_type(), Chattype::Single); assert!(chat.is_device_talk()); assert!(!chat.is_self_talk()); assert!(!chat.can_send()); - assert_eq!( - chat.name, - t.ctx.stock_str(StockMessage::DeviceMessages).await - ); - assert!(chat.get_profile_image(&t.ctx).await.is_some()); + assert_eq!(chat.name, t.stock_str(StockMessage::DeviceMessages).await); + assert!(chat.get_profile_image(&t).await.is_some()); // delete device message, make sure it is not added again - message::delete_msgs(&t.ctx, &[*msg1_id.as_ref().unwrap()]).await; - let msg1 = message::Message::load_from_db(&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, *msg1_id.as_ref().unwrap()).await; 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!(msg2_id.as_ref().unwrap().is_unset()); } @@ -3181,19 +3175,19 @@ mod tests { #[async_std::test] async fn test_add_device_msg_label_only() { 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()); - 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()); let mut msg = Message::new(Viewtype::Text); 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.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.as_ref().unwrap().is_unset()); } @@ -3201,25 +3195,21 @@ mod tests { #[async_std::test] async fn test_was_device_msg_ever_added() { let t = TestContext::new().await; - add_device_msg(&t.ctx, Some("some-label"), None).await.ok(); - assert!(was_device_msg_ever_added(&t.ctx, "some-label") - .await - .unwrap()); + add_device_msg(&t, Some("some-label"), None).await.ok(); + assert!(was_device_msg_ever_added(&t, "some-label").await.unwrap()); let mut msg = Message::new(Viewtype::Text); 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 .ok(); - assert!(was_device_msg_ever_added(&t.ctx, "another-label") + assert!(was_device_msg_ever_added(&t, "another-label") .await .unwrap()); - assert!(!was_device_msg_ever_added(&t.ctx, "unused-label") - .await - .unwrap()); + assert!(!was_device_msg_ever_added(&t, "unused-label").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] @@ -3228,38 +3218,36 @@ mod tests { let mut msg = Message::new(Viewtype::Text); 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 .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); // 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(); - add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)) + chats.get_chat_id(0).delete(&t).await.ok(); + add_device_msg(&t, Some("some-label"), Some(&mut msg)) .await .ok(); - assert_eq!(chatlist_len(&t.ctx, 0).await, 0) + assert_eq!(chatlist_len(&t, 0).await, 0) } #[async_std::test] async fn test_device_chat_cannot_sent() { let t = TestContext::new().await; - t.ctx.update_device_chats().await.unwrap(); + t.update_device_chats().await.unwrap(); 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 .unwrap(); let mut msg = Message::new(Viewtype::Text); msg.text = Some("message text".to_string()); - assert!(send_msg(&t.ctx, device_chat_id, &mut msg).await.is_err()); - assert!(prepare_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, device_chat_id, &mut msg).await.is_err()); - let msg_id = add_device_msg(&t.ctx, None, Some(&mut msg)).await.unwrap(); - assert!(forward_msgs(&t.ctx, &[msg_id], device_chat_id) - .await - .is_err()); + let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap(); + assert!(forward_msgs(&t, &[msg_id], device_chat_id).await.is_err()); } #[async_std::test] @@ -3267,25 +3255,21 @@ mod tests { let t = TestContext::new().await; let mut msg = Message::new(Viewtype::Text); 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 .unwrap(); // adding a device message with the same label won't be executed again ... - assert!(was_device_msg_ever_added(&t.ctx, "some-label") - .await - .unwrap()); - let msg_id2 = add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)) + assert!(was_device_msg_ever_added(&t, "some-label").await.unwrap()); + let msg_id2 = add_device_msg(&t, Some("some-label"), Some(&mut msg)) .await .unwrap(); assert!(msg_id2.is_unset()); // ... unless everything is deleted and resetted - as needed eg. on device switch - delete_and_reset_all_device_msgs(&t.ctx).await.unwrap(); - assert!(!was_device_msg_ever_added(&t.ctx, "some-label") - .await - .unwrap()); - let msg_id3 = add_device_msg(&t.ctx, Some("some-label"), Some(&mut msg)) + delete_and_reset_all_device_msgs(&t).await.unwrap(); + assert!(!was_device_msg_ever_added(&t, "some-label").await.unwrap()); + let msg_id3 = add_device_msg(&t, Some("some-label"), Some(&mut msg)) .await .unwrap(); assert_ne!(msg_id1, msg_id3); @@ -3304,100 +3288,100 @@ mod tests { let t = TestContext::new().await; let mut msg = Message::new(Viewtype::Text); msg.text = Some("foo".to_string()); - let msg_id = add_device_msg(&t.ctx, None, Some(&mut msg)).await.unwrap(); - let chat_id1 = message::Message::load_from_db(&t.ctx, msg_id) + let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap(); + let chat_id1 = message::Message::load_from_db(&t, msg_id) .await .unwrap() .chat_id; let chat_id2 = t.get_self_chat().await.id; assert!(!chat_id1.is_special()); assert!(!chat_id2.is_special()); - assert_eq!(get_chat_cnt(&t.ctx).await, 2); - assert_eq!(chatlist_len(&t.ctx, 0).await, 2); - assert_eq!(chatlist_len(&t.ctx, DC_GCL_NO_SPECIALS).await, 2); - assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY).await, 0); + assert_eq!(get_chat_cnt(&t).await, 2); + assert_eq!(chatlist_len(&t, 0).await, 2); + assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 2); + assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 0); assert_eq!(DC_GCL_ARCHIVED_ONLY, 0x01); assert_eq!(DC_GCL_NO_SPECIALS, 0x02); // archive first chat assert!(chat_id1 - .set_visibility(&t.ctx, ChatVisibility::Archived) + .set_visibility(&t, ChatVisibility::Archived) .await .is_ok()); assert!( - Chat::load_from_db(&t.ctx, chat_id1) + Chat::load_from_db(&t, chat_id1) .await .unwrap() .get_visibility() == ChatVisibility::Archived ); assert!( - Chat::load_from_db(&t.ctx, chat_id2) + Chat::load_from_db(&t, chat_id2) .await .unwrap() .get_visibility() == ChatVisibility::Normal ); - assert_eq!(get_chat_cnt(&t.ctx).await, 2); - assert_eq!(chatlist_len(&t.ctx, 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.ctx, DC_GCL_ARCHIVED_ONLY).await, 1); + assert_eq!(get_chat_cnt(&t).await, 2); + assert_eq!(chatlist_len(&t, 0).await, 2); // including DC_CHAT_ID_ARCHIVED_LINK now + assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 1); + assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 1); // archive second chat assert!(chat_id2 - .set_visibility(&t.ctx, ChatVisibility::Archived) + .set_visibility(&t, ChatVisibility::Archived) .await .is_ok()); assert!( - Chat::load_from_db(&t.ctx, chat_id1) + Chat::load_from_db(&t, chat_id1) .await .unwrap() .get_visibility() == ChatVisibility::Archived ); assert!( - Chat::load_from_db(&t.ctx, chat_id2) + Chat::load_from_db(&t, chat_id2) .await .unwrap() .get_visibility() == ChatVisibility::Archived ); - assert_eq!(get_chat_cnt(&t.ctx).await, 2); - assert_eq!(chatlist_len(&t.ctx, 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.ctx, DC_GCL_ARCHIVED_ONLY).await, 2); + assert_eq!(get_chat_cnt(&t).await, 2); + assert_eq!(chatlist_len(&t, 0).await, 1); // only DC_CHAT_ID_ARCHIVED_LINK now + assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).await, 0); + assert_eq!(chatlist_len(&t, DC_GCL_ARCHIVED_ONLY).await, 2); // archive already archived first chat, unarchive second chat two times assert!(chat_id1 - .set_visibility(&t.ctx, ChatVisibility::Archived) + .set_visibility(&t, ChatVisibility::Archived) .await .is_ok()); assert!(chat_id2 - .set_visibility(&t.ctx, ChatVisibility::Normal) + .set_visibility(&t, ChatVisibility::Normal) .await .is_ok()); assert!(chat_id2 - .set_visibility(&t.ctx, ChatVisibility::Normal) + .set_visibility(&t, ChatVisibility::Normal) .await .is_ok()); assert!( - Chat::load_from_db(&t.ctx, chat_id1) + Chat::load_from_db(&t, chat_id1) .await .unwrap() .get_visibility() == ChatVisibility::Archived ); assert!( - Chat::load_from_db(&t.ctx, chat_id2) + Chat::load_from_db(&t, chat_id2) .await .unwrap() .get_visibility() == ChatVisibility::Normal ); - assert_eq!(get_chat_cnt(&t.ctx).await, 2); - assert_eq!(chatlist_len(&t.ctx, 0).await, 2); - assert_eq!(chatlist_len(&t.ctx, DC_GCL_NO_SPECIALS).await, 1); - assert_eq!(chatlist_len(&t.ctx, DC_GCL_ARCHIVED_ONLY).await, 1); + assert_eq!(get_chat_cnt(&t).await, 2); + assert_eq!(chatlist_len(&t, 0).await, 2); + assert_eq!(chatlist_len(&t, DC_GCL_NO_SPECIALS).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 { @@ -3418,28 +3402,28 @@ mod tests { // create 3 chats, wait 1 second in between to get a reliable order (we order by time) let mut msg = Message::new(Viewtype::Text); msg.text = Some("foo".to_string()); - let msg_id = add_device_msg(&t.ctx, None, Some(&mut msg)).await.unwrap(); - let chat_id1 = message::Message::load_from_db(&t.ctx, msg_id) + let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap(); + let chat_id1 = message::Message::load_from_db(&t, msg_id) .await .unwrap() .chat_id; async_std::task::sleep(std::time::Duration::from_millis(1000)).await; let chat_id2 = t.get_self_chat().await.id; 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 .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]); // pin assert!(chat_id1 - .set_visibility(&t.ctx, ChatVisibility::Pinned) + .set_visibility(&t, ChatVisibility::Pinned) .await .is_ok()); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id1) + Chat::load_from_db(&t, chat_id1) .await .unwrap() .get_visibility(), @@ -3447,16 +3431,16 @@ mod tests { ); // 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]); // unpin assert!(chat_id1 - .set_visibility(&t.ctx, ChatVisibility::Normal) + .set_visibility(&t, ChatVisibility::Normal) .await .is_ok()); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id1) + Chat::load_from_db(&t, chat_id1) .await .unwrap() .get_visibility(), @@ -3464,30 +3448,24 @@ mod tests { ); // 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]); } #[async_std::test] async fn test_set_chat_name() { 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 .unwrap(); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .get_name(), + Chat::load_from_db(&t, chat_id).await.unwrap().get_name(), "foo" ); - set_chat_name(&t.ctx, chat_id, "bar").await.unwrap(); + set_chat_name(&t, chat_id, "bar").await.unwrap(); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .get_name(), + Chat::load_from_db(&t, chat_id).await.unwrap().get_name(), "bar" ); } @@ -3514,91 +3492,71 @@ mod tests { #[async_std::test] async fn test_shall_attach_selfavatar() { 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 .unwrap(); - assert!(!shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); + assert!(!shall_attach_selfavatar(&t, chat_id).await.unwrap()); 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 .unwrap(); - add_contact_to_chat(&t.ctx, chat_id, contact_id).await; - assert!(!shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); - t.ctx.set_config(Config::Selfavatar, None).await.unwrap(); // setting to None also forces re-sending - assert!(shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); + add_contact_to_chat(&t, chat_id, contact_id).await; + assert!(!shall_attach_selfavatar(&t, chat_id).await.unwrap()); + t.set_config(Config::Selfavatar, None).await.unwrap(); // setting to None also forces re-sending + assert!(shall_attach_selfavatar(&t, chat_id).await.unwrap()); - assert!(chat_id - .set_selfavatar_timestamp(&t.ctx, time()) - .await - .is_ok()); - assert!(!shall_attach_selfavatar(&t.ctx, chat_id).await.unwrap()); + assert!(chat_id.set_selfavatar_timestamp(&t, time()).await.is_ok()); + assert!(!shall_attach_selfavatar(&t, chat_id).await.unwrap()); } #[async_std::test] async fn test_set_mute_duration() { 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 .unwrap(); // Initial assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .is_muted(), + Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(), false ); // Forever - set_muted(&t.ctx, chat_id, MuteDuration::Forever) - .await - .unwrap(); + set_muted(&t, chat_id, MuteDuration::Forever).await.unwrap(); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .is_muted(), + Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(), true ); // unMute - set_muted(&t.ctx, chat_id, MuteDuration::NotMuted) + set_muted(&t, chat_id, MuteDuration::NotMuted) .await .unwrap(); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .is_muted(), + Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(), false ); // Timed in the future set_muted( - &t.ctx, + &t, chat_id, MuteDuration::Until(SystemTime::now() + Duration::from_secs(3600)), ) .await .unwrap(); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .is_muted(), + Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(), true ); // Time in the past set_muted( - &t.ctx, + &t, chat_id, MuteDuration::Until(SystemTime::now() - Duration::from_secs(3600)), ) .await .unwrap(); assert_eq!( - Chat::load_from_db(&t.ctx, chat_id) - .await - .unwrap() - .is_muted(), + Chat::load_from_db(&t, chat_id).await.unwrap().is_muted(), false ); } @@ -3606,10 +3564,10 @@ mod tests { #[async_std::test] async fn test_add_info_msg() { 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 .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; assert_eq!(msg.get_chat_id(), chat_id); @@ -3622,11 +3580,11 @@ mod tests { #[async_std::test] async fn test_add_info_msg_with_cmd() { 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 .unwrap(); let msg_id = add_info_msg_with_cmd( - &t.ctx, + &t, chat_id, "foo bar info", SystemMessage::EphemeralTimerChanged, @@ -3634,7 +3592,7 @@ mod tests { .await .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_viewtype(), Viewtype::Text); assert_eq!(msg.get_text().unwrap(), "foo bar info"); @@ -3648,24 +3606,24 @@ mod tests { #[async_std::test] async fn test_set_protection() { 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 .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_unpromoted()); // enable protection on unpromoted chat, the info-message is added via add_info_msg() chat_id - .set_protection(&t.ctx, ProtectionStatus::Protected) + .set_protection(&t, ProtectionStatus::Protected) .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_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); let msg = t.get_last_msg(chat_id).await; @@ -3675,11 +3633,11 @@ mod tests { // disable protection again, still unpromoted chat_id - .set_protection(&t.ctx, ProtectionStatus::Unprotected) + .set_protection(&t, ProtectionStatus::Unprotected) .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_unpromoted()); @@ -3689,23 +3647,21 @@ mod tests { assert_eq!(msg.get_state(), MessageState::InNoticed); // send a message, this switches to promoted state - send_text_msg(&t.ctx, chat_id, "hi!".to_string()) - .await - .unwrap(); + send_text_msg(&t, chat_id, "hi!".to_string()).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_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); // enable protection on promoted chat, the info-message is sent via send_msg() this time chat_id - .set_protection(&t.ctx, ProtectionStatus::Protected) + .set_protection(&t, ProtectionStatus::Protected) .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_unpromoted()); diff --git a/src/chatlist.rs b/src/chatlist.rs index 7b05169a1..caf5378bd 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -438,18 +438,18 @@ mod tests { #[async_std::test] async fn test_try_load() { 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 .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 .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 .unwrap(); // 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.get_chat_id(0), chat_id3); assert_eq!(chats.get_chat_id(1), chat_id2); @@ -458,26 +458,26 @@ mod tests { // drafts are sorted to the top let mut msg = Message::new(Viewtype::Text); msg.set_text(Some("hello".to_string())); - chat_id2.set_draft(&t.ctx, Some(&mut msg)).await; - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); + chat_id2.set_draft(&t, Some(&mut msg)).await; + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); assert_eq!(chats.get_chat_id(0), chat_id2); // 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 .unwrap(); 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 .unwrap(); assert_eq!(chats.len(), 0); chat_id1 - .set_visibility(&t.ctx, ChatVisibility::Archived) + .set_visibility(&t, ChatVisibility::Archived) .await .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 .unwrap(); assert_eq!(chats.len(), 1); @@ -486,23 +486,23 @@ mod tests { #[async_std::test] async fn test_sort_self_talk_up_on_forward() { let t = TestContext::new().await; - t.ctx.update_device_chats().await.unwrap(); - create_group_chat(&t.ctx, ProtectionStatus::Unprotected, "a chat") + t.update_device_chats().await.unwrap(); + create_group_chat(&t, ProtectionStatus::Unprotected, "a chat") .await .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!(!Chat::load_from_db(&t.ctx, chats.get_chat_id(0)) + assert!(!Chat::load_from_db(&t, chats.get_chat_id(0)) .await .unwrap() .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 .unwrap(); 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 .unwrap() .is_self_talk()); @@ -511,31 +511,31 @@ mod tests { #[async_std::test] async fn test_search_special_chat_names() { 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 .unwrap(); 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 .unwrap(); assert_eq!(chats.len(), 0); - t.ctx + t .set_stock_translation(StockMessage::SavedMessages, "test-1234-save".to_string()) .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 .unwrap(); assert_eq!(chats.len(), 1); - t.ctx + t .set_stock_translation(StockMessage::DeviceMessages, "test-5678-babbel".to_string()) .await .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 .unwrap(); assert_eq!(chats.len(), 1); @@ -544,16 +544,16 @@ mod tests { #[async_std::test] async fn test_get_summary_unwrap() { 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 .unwrap(); let mut msg = Message::new(Viewtype::Text); 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 summary = chats.get_summary(&t.ctx, 0, None).await; + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); + 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 } } diff --git a/src/config.rs b/src/config.rs index 3f8c5a20e..3da720c80 100644 --- a/src/config.rs +++ b/src/config.rs @@ -319,15 +319,15 @@ mod tests { .unwrap() .write_all(avatar_bytes) .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); - t.ctx + t .set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap())) .await .unwrap(); assert!(avatar_blob.exists().await); 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())); let img = image::open(avatar_src).unwrap(); @@ -342,7 +342,7 @@ mod tests { #[async_std::test] async fn test_selfavatar_in_blobdir() { 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"); File::create(&avatar_src) .unwrap() @@ -353,11 +353,11 @@ mod tests { assert_eq!(img.width(), 900); assert_eq!(img.height(), 900); - t.ctx + t .set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap())) .await .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())); let img = image::open(avatar_src).unwrap(); @@ -374,9 +374,9 @@ mod tests { .unwrap() .write_all(avatar_bytes) .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); - t.ctx + t .set_config(Config::Selfavatar, Some(&avatar_src.to_str().unwrap())) .await .unwrap(); @@ -385,24 +385,24 @@ mod tests { 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())); } #[async_std::test] async fn test_media_quality_config_option() { 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); let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default(); assert_eq!(media_quality, constants::MediaQuality::Balanced); - t.ctx + t .set_config(Config::MediaQuality, Some("1")) .await .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!(constants::MediaQuality::Worse as i32, 1); let media_quality = constants::MediaQuality::from_i32(media_quality).unwrap_or_default(); diff --git a/src/configure/mod.rs b/src/configure/mod.rs index bea7d85bf..d9605e93b 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -616,15 +616,15 @@ mod tests { #[async_std::test] async fn test_no_panic_on_bad_credentials() { let t = TestContext::new().await; - t.ctx + t .set_config(Config::Addr, Some("probably@unexistant.addr")) .await .unwrap(); - t.ctx + t .set_config(Config::MailPw, Some("123456")) .await .unwrap(); - assert!(t.ctx.configure().await.is_err()); + assert!(t.configure().await.is_err()); } #[async_std::test] diff --git a/src/contact.rs b/src/contact.rs index a06c039ed..c2374e853 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -1320,11 +1320,11 @@ mod tests { #[async_std::test] async fn test_is_self_addr() -> Result<()> { 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; - assert_eq!(t.ctx.is_self_addr("me@me.org").await?, false); - assert_eq!(t.ctx.is_self_addr(&addr).await?, true); + assert_eq!(t.is_self_addr("me@me.org").await?, false); + assert_eq!(t.is_self_addr(&addr).await?, true); Ok(()) } @@ -1341,16 +1341,16 @@ mod tests { "Name two\ntwo@deux.net\n", // should not be added again "\nWonderland, Alice \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 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 .unwrap(); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); 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_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)"); // modify first added contact - let (contact_id_test, sth_modified) = Contact::add_or_lookup( - &t.ctx, - "Real one", - " one@eins.org ", - Origin::ManuallyCreated, - ) - .await - .unwrap(); + let (contact_id_test, sth_modified) = + Contact::add_or_lookup(&t, "Real one", " one@eins.org ", Origin::ManuallyCreated) + .await + .unwrap(); assert_eq!(contact_id, contact_id_test); 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_addr(), "one@eins.org"); assert!(!contact.is_blocked()); // check third added contact (contact without name) 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 .unwrap(); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); 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_display_name(), "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) let (contact_id_test, sth_modified) = Contact::add_or_lookup( - &t.ctx, + &t, "m. serious", "three@drei.sam", Origin::IncomingUnknownFrom, @@ -1397,48 +1393,39 @@ mod tests { .unwrap(); assert_eq!(contact_id, contact_id_test); 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!(!contact.is_blocked()); // manually edit name of third contact (does not changed authorized name) - let (contact_id_test, sth_modified) = Contact::add_or_lookup( - &t.ctx, - "schnucki", - "three@drei.sam", - Origin::ManuallyCreated, - ) - .await - .unwrap(); + let (contact_id_test, sth_modified) = + Contact::add_or_lookup(&t, "schnucki", "three@drei.sam", Origin::ManuallyCreated) + .await + .unwrap(); assert_eq!(contact_id, contact_id_test); 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_name_n_addr(), "schnucki (three@drei.sam)"); assert!(!contact.is_blocked()); // Fourth contact: 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 .unwrap(); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); 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_display_name(), "Wonderland, Alice"); assert_eq!(contact.get_addr(), "alice@w.de"); assert_eq!(contact.get_name_n_addr(), "Wonderland, Alice (alice@w.de)"); // check SELF - let contact = Contact::load_from_db(&t.ctx, DC_CONTACT_ID_SELF) - .await - .unwrap(); + let contact = Contact::load_from_db(&t, DC_CONTACT_ID_SELF).await.unwrap(); assert_eq!(DC_CONTACT_ID_SELF, 1); - assert_eq!( - contact.get_name(), - t.ctx.stock_str(StockMessage::SelfMsg).await - ); + assert_eq!(contact.get_name(), t.stock_str(StockMessage::SelfMsg).await); assert_eq!(contact.get_addr(), ""); // we're not configured assert!(!contact.is_blocked()); } @@ -1448,59 +1435,47 @@ mod tests { let t = TestContext::new().await; // incoming mail `From: bob1 ` - this should init authname and name - let (contact_id, sth_modified) = Contact::add_or_lookup( - &t.ctx, - "bob1", - "bob@example.org", - Origin::IncomingUnknownFrom, - ) - .await - .unwrap(); + let (contact_id, sth_modified) = + Contact::add_or_lookup(&t, "bob1", "bob@example.org", Origin::IncomingUnknownFrom) + .await + .unwrap(); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); 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_name(), "bob1"); assert_eq!(contact.get_display_name(), "bob1"); // incoming mail `From: bob2 ` - this should update authname and name - let (contact_id, sth_modified) = Contact::add_or_lookup( - &t.ctx, - "bob2", - "bob@example.org", - Origin::IncomingUnknownFrom, - ) - .await - .unwrap(); + let (contact_id, sth_modified) = + Contact::add_or_lookup(&t, "bob2", "bob@example.org", Origin::IncomingUnknownFrom) + .await + .unwrap(); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); 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_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 - let contact_id = Contact::create(&t.ctx, "bob3", "bob@example.org") + let contact_id = Contact::create(&t, "bob3", "bob@example.org") .await .unwrap(); 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_name(), "bob3"); assert_eq!(contact.get_display_name(), "bob3"); // incoming mail `From: bob4 ` - this should update authname, manually given name is still "bob3" - let (contact_id, sth_modified) = Contact::add_or_lookup( - &t.ctx, - "bob4", - "bob@example.org", - Origin::IncomingUnknownFrom, - ) - .await - .unwrap(); + let (contact_id, sth_modified) = + Contact::add_or_lookup(&t, "bob4", "bob@example.org", Origin::IncomingUnknownFrom) + .await + .unwrap(); assert!(contact_id > DC_CONTACT_ID_LAST_SPECIAL); 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_name(), "bob3"); assert_eq!(contact.get_display_name(), "bob3"); @@ -1511,18 +1486,16 @@ mod tests { let t = TestContext::new().await; // manually create "claire@example.org" without a given name - let contact_id = Contact::create(&t.ctx, "", "claire@example.org") - .await - .unwrap(); + let contact_id = Contact::create(&t, "", "claire@example.org").await.unwrap(); 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_name(), ""); assert_eq!(contact.get_display_name(), "claire@example.org"); // incoming mail `From: claire1 ` - this should update authname and name let (contact_id_same, sth_modified) = Contact::add_or_lookup( - &t.ctx, + &t, "claire1", "claire@example.org", Origin::IncomingUnknownFrom, @@ -1531,14 +1504,14 @@ mod tests { .unwrap(); assert_eq!(contact_id, contact_id_same); 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_name(), "claire1"); assert_eq!(contact.get_display_name(), "claire1"); // incoming mail `From: claire2 ` - this should update authname and name let (contact_id_same, sth_modified) = Contact::add_or_lookup( - &t.ctx, + &t, "claire2", "claire@example.org", Origin::IncomingUnknownFrom, @@ -1547,7 +1520,7 @@ mod tests { .unwrap(); assert_eq!(contact_id, contact_id_same); 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_name(), "claire2"); assert_eq!(contact.get_display_name(), "claire2"); @@ -1558,33 +1531,26 @@ mod tests { let t = TestContext::new().await; // 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 .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_name(), "dave1"); assert_eq!(contact.get_display_name(), "dave1"); // incoming mail `From: dave2 ` - this should update authname - Contact::add_or_lookup( - &t.ctx, - "dave2", - "dave@example.org", - Origin::IncomingUnknownFrom, - ) - .await - .unwrap(); - let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); + Contact::add_or_lookup(&t, "dave2", "dave@example.org", Origin::IncomingUnknownFrom) + .await + .unwrap(); + let contact = Contact::load_from_db(&t, contact_id).await.unwrap(); assert_eq!(contact.get_authname(), "dave2"); assert_eq!(contact.get_name(), "dave1"); assert_eq!(contact.get_display_name(), "dave1"); // manually clear the name - Contact::create(&t.ctx, "", "dave@example.org") - .await - .unwrap(); - let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); + Contact::create(&t, "", "dave@example.org").await.unwrap(); + let contact = Contact::load_from_db(&t, contact_id).await.unwrap(); assert_eq!(contact.get_authname(), "dave2"); assert_eq!(contact.get_name(), "dave2"); assert_eq!(contact.get_display_name(), "dave2"); @@ -1601,44 +1567,40 @@ mod tests { async fn test_name_in_address() { let t = TestContext::new().await; - let contact_id = Contact::create(&t.ctx, "", "") - .await - .unwrap(); - let contact = Contact::load_from_db(&t.ctx, contact_id).await.unwrap(); + let contact_id = Contact::create(&t, "", "").await.unwrap(); + let contact = Contact::load_from_db(&t, contact_id).await.unwrap(); assert_eq!(contact.get_name(), ""); assert_eq!(contact.get_addr(), "dave@example.org"); - let contact_id = Contact::create(&t.ctx, "", "Mueller, Dave ") + let contact_id = Contact::create(&t, "", "Mueller, Dave ") .await .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_addr(), "dave@example.org"); - let contact_id = Contact::create(&t.ctx, "name1", "name2 ") + let contact_id = Contact::create(&t, "name1", "name2 ") .await .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_addr(), "dave@example.org"); - assert!(Contact::create(&t.ctx, "", "dslk@sadklj.dk>") + assert!(Contact::create(&t, "", "dslk@sadklj.dk>") .await .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 .is_err()); - assert!(Contact::create(&t.ctx, "", "dskjfdslk@sadklj.dk>") + assert!(Contact::create(&t, "", "dskjf@dslk@sadkljdk") .await .is_err()); - assert!(Contact::create(&t.ctx, "", "dskjf@dslk@sadkljdk") - .await - .is_err()); - assert!(Contact::create(&t.ctx, "", "dskjf dslk@d.e").await.is_err()); - assert!(Contact::create(&t.ctx, "", "\n\ To: alice@example.com\n\ Subject: foo\n\ @@ -2357,20 +2357,20 @@ mod tests { false, ).await.unwrap(); assert_eq!( - Contact::load_from_db(&t.ctx, contact_id) + Contact::load_from_db(&t, contact_id) .await .unwrap() .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); let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() { msg_id } else { 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 .unwrap(); assert_eq!(msg.is_dc_message, MessengerMessage::Yes); @@ -2381,18 +2381,18 @@ mod tests { #[async_std::test] async fn test_escaped_recipients() { let t = TestContext::new_alice().await; - Contact::create(&t.ctx, "foobar", "foobar@example.com") + Contact::create(&t, "foobar", "foobar@example.com") .await .unwrap(); 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 .unwrap() .0; dc_receive_imf( - &t.ctx, + &t, b"From: Foobar \n\ To: =?UTF-8?B?0JjQvNGPLCDQpNCw0LzQuNC70LjRjw==?= alice@example.com\n\ Cc: =?utf-8?q?=3Ch2=3E?= \n\ @@ -2410,15 +2410,15 @@ mod tests { .await .unwrap(); assert_eq!( - Contact::load_from_db(&t.ctx, carl_contact_id) + Contact::load_from_db(&t, carl_contact_id) .await .unwrap() .get_name(), "h2" ); - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); - let msg = Message::load_from_db(&t.ctx, chats.get_msg_id(0).unwrap()) + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); + let msg = Message::load_from_db(&t, chats.get_msg_id(0).unwrap()) .await .unwrap(); assert_eq!(msg.is_dc_message, MessengerMessage::Yes); @@ -2429,12 +2429,12 @@ mod tests { #[async_std::test] async fn test_cc_to_contact() { let t = TestContext::new_alice().await; - Contact::create(&t.ctx, "foobar", "foobar@example.com") + Contact::create(&t, "foobar", "foobar@example.com") .await .unwrap(); let carl_contact_id = Contact::add_or_lookup( - &t.ctx, + &t, "garabage", "carl@host.tld", Origin::IncomingUnknownFrom, @@ -2444,7 +2444,7 @@ mod tests { .0; dc_receive_imf( - &t.ctx, + &t, b"From: Foobar \n\ To: alice@example.com\n\ Cc: Carl \n\ @@ -2462,7 +2462,7 @@ mod tests { .await .unwrap(); assert_eq!( - Contact::load_from_db(&t.ctx, carl_contact_id) + Contact::load_from_db(&t, carl_contact_id) .await .unwrap() .get_name(), @@ -2554,7 +2554,7 @@ mod tests { t.configure_addr(self_addr).await; dc_receive_imf( - &t.ctx, + &t, format!( "From: {}\n\ To: {}\n\ @@ -2574,21 +2574,21 @@ mod tests { .await .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(); // Check that the ndn would be downloaded: let headers = mailparse::parse_mail(raw_ndn).unwrap().headers; assert!( - crate::imap::prefetch_should_download(&t.ctx, &headers, ShowEmails::Off) + crate::imap::prefetch_should_download(&t, &headers, ShowEmails::Off) .await .unwrap() ); - dc_receive_imf(&t.ctx, raw_ndn, "INBOX", 1, false) + dc_receive_imf(&t, raw_ndn, "INBOX", 1, false) .await .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); @@ -2601,7 +2601,7 @@ mod tests { t.configure_addr("alice@gmail.com").await; dc_receive_imf( - &t.ctx, + &t, b"From: alice@gmail.com\n\ To: bob@example.com, assidhfaaspocwaeofi@gmail.com\n\ Subject: foo\n\ @@ -2620,30 +2620,30 @@ mod tests { .await .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 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 .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); - 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() { msg_id } else { 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!( last_msg.text, Some( - t.ctx + t .stock_string_repl_str( StockMessage::FailedSendingTo, "assidhfaaspocwaeofi@gmail.com", @@ -2671,7 +2671,7 @@ mod tests { async fn test_html_only_mail() { let t = TestContext::new_alice().await; let msg = load_imf_email( - &t.ctx, + &t, include_bytes!("../test-data/message/wrong-html.eml"), ) .await; @@ -2682,7 +2682,7 @@ mod tests { async fn test_pdf_filename_simple() { let t = TestContext::new_alice().await; let msg = load_imf_email( - &t.ctx, + &t, include_bytes!("../test-data/message/pdf_filename_simple.eml"), ) .await; @@ -2696,7 +2696,7 @@ mod tests { // test filenames split across multiple header lines, see rfc 2231 let t = TestContext::new_alice().await; let msg = load_imf_email( - &t.ctx, + &t, include_bytes!("../test-data/message/pdf_filename_continuation.eml"), ) .await; diff --git a/src/dc_tools.rs b/src/dc_tools.rs index 7af4a00f7..7649ecec8 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -898,7 +898,7 @@ mod tests { #[async_std::test] async fn test_file_handling() { let t = TestContext::new().await; - let context = &t.ctx; + let context = &t; macro_rules! dc_file_exist { ($ctx:expr, $fname:expr) => { $ctx.get_blobdir() @@ -978,11 +978,11 @@ mod tests { async fn test_create_smeared_timestamp() { let t = TestContext::new().await; assert_ne!( - dc_create_smeared_timestamp(&t.ctx).await, - dc_create_smeared_timestamp(&t.ctx).await + dc_create_smeared_timestamp(&t).await, + dc_create_smeared_timestamp(&t).await ); assert!( - dc_create_smeared_timestamp(&t.ctx).await + dc_create_smeared_timestamp(&t).await >= SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() @@ -994,13 +994,13 @@ mod tests { async fn test_create_smeared_timestamps() { let t = TestContext::new().await; let count = MAX_SECONDS_TO_LEND_FROM_FUTURE - 1; - let start = dc_create_smeared_timestamps(&t.ctx, count as usize).await; - let next = dc_smeared_time(&t.ctx).await; + let start = dc_create_smeared_timestamps(&t, count as usize).await; + let next = dc_smeared_time(&t).await; assert!((start + count - 1) < next); let count = MAX_SECONDS_TO_LEND_FROM_FUTURE + 30; - let start = dc_create_smeared_timestamps(&t.ctx, count as usize).await; - let next = dc_smeared_time(&t.ctx).await; + let start = dc_create_smeared_timestamps(&t, count as usize).await; + let next = dc_smeared_time(&t).await; assert!((start + count - 1) < next); } @@ -1074,53 +1074,53 @@ mod tests { / 1_000; // a correct time must not add a device message - maybe_warn_on_bad_time(&t.ctx, timestamp_now, get_provider_update_timestamp()).await; - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); + maybe_warn_on_bad_time(&t, timestamp_now, get_provider_update_timestamp()).await; + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 0); // 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; - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); + maybe_warn_on_bad_time(&t, timestamp_future, get_provider_update_timestamp()).await; + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 0); // a date in the past must add a device message - maybe_warn_on_bad_time(&t.ctx, timestamp_past, get_provider_update_timestamp()).await; - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); + maybe_warn_on_bad_time(&t, timestamp_past, get_provider_update_timestamp()).await; + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 1); 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); // the message should be added only once a day - test that an hour later and nearly a day later maybe_warn_on_bad_time( - &t.ctx, + &t, timestamp_past + 60 * 60, get_provider_update_timestamp(), ) .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); maybe_warn_on_bad_time( - &t.ctx, + &t, timestamp_past + 60 * 60 * 24 - 1, get_provider_update_timestamp(), ) .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); // next day, there should be another device message maybe_warn_on_bad_time( - &t.ctx, + &t, timestamp_past + 60 * 60 * 24, 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!(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); } @@ -1132,60 +1132,60 @@ mod tests { // in about 6 months, the app should not be outdated // (if this fails, provider-db is not updated since 6 months) maybe_warn_on_outdated( - &t.ctx, + &t, timestamp_now + 180 * 24 * 60 * 60, 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); // in 1 year, the app should be considered as outdated maybe_warn_on_outdated( - &t.ctx, + &t, timestamp_now + 365 * 24 * 60 * 60, 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); 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); // 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) maybe_warn_on_outdated( - &t.ctx, + &t, timestamp_now + (365 + 1) * 24 * 60 * 60, get_provider_update_timestamp(), ) .await; maybe_warn_on_outdated( - &t.ctx, + &t, timestamp_now + (365 + 2) * 24 * 60 * 60, 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); 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(); assert!(test_len == 1 || test_len == 2); // ... but every month // (forward generous 33 days to avoid being in the same month as in the previous check) maybe_warn_on_outdated( - &t.ctx, + &t, timestamp_now + (365 + 33) * 24 * 60 * 60, 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); 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); } } diff --git a/src/e2ee.rs b/src/e2ee.rs index 0b1f02553..266fb41f5 100644 --- a/src/e2ee.rs +++ b/src/e2ee.rs @@ -357,13 +357,13 @@ mod tests { async fn test_prexisting() { let t = TestContext::new().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 fn test_not_configured() { 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 fn test_should_encrypt() { 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: // 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); - assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).unwrap()); - assert!(!encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); + let ps = new_peerstates(&t, EncryptPreference::NoPreference); + assert!(encrypt_helper.should_encrypt(&t, true, &ps).unwrap()); + assert!(!encrypt_helper.should_encrypt(&t, false, &ps).unwrap()); // test with EncryptPreference::Reset - let ps = new_peerstates(&t.ctx, EncryptPreference::Reset); - assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).unwrap()); - assert!(!encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); + let ps = new_peerstates(&t, EncryptPreference::Reset); + assert!(encrypt_helper.should_encrypt(&t, true, &ps).unwrap()); + assert!(!encrypt_helper.should_encrypt(&t, false, &ps).unwrap()); // test with EncryptPreference::Mutual (self is also Mutual) - let ps = new_peerstates(&t.ctx, EncryptPreference::Mutual); - assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).unwrap()); - assert!(encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); + let ps = new_peerstates(&t, EncryptPreference::Mutual); + assert!(encrypt_helper.should_encrypt(&t, true, &ps).unwrap()); + assert!(encrypt_helper.should_encrypt(&t, false, &ps).unwrap()); // test with missing peerstate let mut ps = Vec::new(); ps.push((None, "bob@foo.bar")); - assert!(encrypt_helper.should_encrypt(&t.ctx, true, &ps).is_err()); - assert!(!encrypt_helper.should_encrypt(&t.ctx, false, &ps).unwrap()); + assert!(encrypt_helper.should_encrypt(&t, true, &ps).is_err()); + assert!(!encrypt_helper.should_encrypt(&t, false, &ps).unwrap()); } } diff --git a/src/imex.rs b/src/imex.rs index a978388df..b787308da 100644 --- a/src/imex.rs +++ b/src/imex.rs @@ -909,7 +909,7 @@ mod tests { let t = TestContext::new().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); // Check some substrings, indicating things got substituted. // In particular note the mixing of `\r\n` and `\n` depending @@ -926,12 +926,11 @@ mod tests { #[async_std::test] async fn test_render_setup_file_newline_replace() { let t = TestContext::new().await; - t.ctx - .set_stock_translation(StockMessage::AcSetupMsgBody, "hello\r\nthere".to_string()) + t.set_stock_translation(StockMessage::AcSetupMsgBody, "hello\r\nthere".to_string()) .await .unwrap(); 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); assert!(msg.contains("

hello
there

")); } @@ -939,7 +938,7 @@ mod tests { #[async_std::test] async fn test_create_setup_code() { 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.chars().nth(4).unwrap(), '-'); assert_eq!(setupcode.chars().nth(9).unwrap(), '-'); diff --git a/src/job.rs b/src/job.rs index 6e72384a3..1151d9f8d 100644 --- a/src/job.rs +++ b/src/job.rs @@ -1372,18 +1372,18 @@ mod tests { // fails to load from the database instead of failing to load // all jobs. 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( - &t.ctx, + &t, Thread::from(Action::MoveMsg), &InterruptInfo::new(false, None), ) .await; assert!(jobs.is_none()); - insert_job(&t.ctx, 1).await; + insert_job(&t, 1).await; let jobs = load_next( - &t.ctx, + &t, Thread::from(Action::MoveMsg), &InterruptInfo::new(false, None), ) @@ -1395,10 +1395,10 @@ mod tests { async fn test_load_next_job_one() { let t = TestContext::new().await; - insert_job(&t.ctx, 1).await; + insert_job(&t, 1).await; let jobs = load_next( - &t.ctx, + &t, Thread::from(Action::MoveMsg), &InterruptInfo::new(false, None), ) diff --git a/src/key.rs b/src/key.rs index c9fdff018..d6dfbba49 100644 --- a/src/key.rs +++ b/src/key.rs @@ -558,31 +558,31 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD let alice = alice_keypair(); let t = TestContext::new().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); - let seckey = SignedSecretKey::load_self(&t.ctx).await.unwrap(); + let seckey = SignedSecretKey::load_self(&t).await.unwrap(); assert_eq!(alice.secret, seckey); } #[async_std::test] async fn test_load_self_generate_public() { let t = TestContext::new().await; - t.ctx + t .set_config(Config::ConfiguredAddr, Some("alice@example.com")) .await .unwrap(); - let key = SignedPublicKey::load_self(&t.ctx).await; + let key = SignedPublicKey::load_self(&t).await; assert!(key.is_ok()); } #[async_std::test] async fn test_load_self_generate_secret() { let t = TestContext::new().await; - t.ctx + t .set_config(Config::ConfiguredAddr, Some("alice@example.com")) .await .unwrap(); - let key = SignedSecretKey::load_self(&t.ctx).await; + let key = SignedSecretKey::load_self(&t).await; assert!(key.is_ok()); } @@ -591,11 +591,11 @@ i8pcjGO+IZffvyZJVRWfVooBJmWWbPB1pueo3tx8w3+fcuzpxz+RLFKaPyqXO+dD use std::thread; let t = TestContext::new().await; - t.ctx + t .set_config(Config::ConfiguredAddr, Some("alice@example.com")) .await .unwrap(); - let ctx = t.ctx.clone(); + let ctx = t.clone(); let ctx0 = ctx.clone(); let thr0 = 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 // the keypairs table. let t = TestContext::new().await; - let ctx = Arc::new(t.ctx); + let ctx = Arc::new(t); let ctx1 = ctx.clone(); let nrows = || async { diff --git a/src/keyring.rs b/src/keyring.rs index 142672867..d0314ddb3 100644 --- a/src/keyring.rs +++ b/src/keyring.rs @@ -83,10 +83,10 @@ mod tests { t.configure_alice().await; let alice = alice_keypair(); - let pub_ring: Keyring = Keyring::new_self(&t.ctx).await.unwrap(); + let pub_ring: Keyring = Keyring::new_self(&t).await.unwrap(); assert_eq!(pub_ring.keys(), [alice.public]); - let sec_ring: Keyring = Keyring::new_self(&t.ctx).await.unwrap(); + let sec_ring: Keyring = Keyring::new_self(&t).await.unwrap(); assert_eq!(sec_ring.keys(), [alice.secret]); } } diff --git a/src/message.rs b/src/message.rs index 01398aa8c..2c2c7b790 100644 --- a/src/message.rs +++ b/src/message.rs @@ -2057,17 +2057,17 @@ mod tests { // test that get_width() and get_height() are returning some dimensions for images; // (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, _) = - 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 .unwrap(); 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 { 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 { has_image = true; // just check that width/height are inside some reasonable ranges diff --git a/src/mimefactory.rs b/src/mimefactory.rs index e653a7511..c7dc21425 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1417,7 +1417,7 @@ mod tests { assert_eq!(first_subject_str(t).await, "Message from alice@example.com"); let t = TestContext::new_alice().await; - t.ctx + t .set_config(Config::Displayname, Some("Alice")) .await .unwrap(); @@ -1453,7 +1453,7 @@ mod tests { // 5. Receive an mdn (read receipt) and make sure the mdn's subject is not used let t = TestContext::new_alice().await; dc_receive_imf( - &t.ctx, + &t, b"From: alice@example.com\n\ To: Charlie \n\ Subject: Hello, Charlie\n\ @@ -1491,8 +1491,8 @@ mod tests { Final-Recipient: rfc822;charlie@example.com\n\ Original-Message-ID: <2893@example.com>\n\ Disposition: manual-action/MDN-sent-automatically; displayed\n\ - \n", &t.ctx).await; - let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) + \n", &t).await; + let mf = MimeFactory::from_msg(&t, &new_msg, false) .await .unwrap(); // The subject string should not be "Re: message opened" @@ -1501,23 +1501,23 @@ mod tests { async fn first_subject_str(t: TestContext) -> String { 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 .unwrap() .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 .unwrap(); let mut new_msg = Message::new(Viewtype::Text); new_msg.set_text(Some("Hi".to_string())); 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 .unwrap(); - let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) + let mf = MimeFactory::from_msg(&t, &new_msg, false) .await .unwrap(); @@ -1526,8 +1526,8 @@ mod tests { async fn msg_to_subject_str(imf_raw: &[u8]) -> String { let t = TestContext::new_alice().await; - let new_msg = incoming_msg_to_reply_msg(imf_raw, &t.ctx).await; - let mf = MimeFactory::from_msg(&t.ctx, &new_msg, false) + let new_msg = incoming_msg_to_reply_msg(imf_raw, &t).await; + let mf = MimeFactory::from_msg(&t, &new_msg, false) .await .unwrap(); mf.subject_str().await @@ -1564,7 +1564,7 @@ mod tests { // This test could still be extended async fn test_render_reply() { let t = TestContext::new_alice().await; - let context = &t.ctx; + let context = &t; let msg = incoming_msg_to_reply_msg( b"From: Charlie \n\ @@ -1579,7 +1579,7 @@ mod tests { ) .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(); assert_eq!(recipients, vec!["charlie@example.com"]); diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 6a7767d8c..028ff9a6d 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -1493,8 +1493,8 @@ mod tests { fn load_mail_with_attachment<'a>(t: &'a TestContext, raw: &'a [u8]) -> ParsedMail<'a> { let mail = mailparse::parse_mail(raw).unwrap(); - assert!(get_attachment_filename(&t.ctx, &mail).unwrap().is_none()); - assert!(get_attachment_filename(&t.ctx, &mail.subparts[0]) + assert!(get_attachment_filename(&t, &mail).unwrap().is_none()); + assert!(get_attachment_filename(&t, &mail.subparts[0]) .unwrap() .is_none()); mail @@ -1507,7 +1507,7 @@ mod tests { &t, 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())) } @@ -1518,7 +1518,7 @@ mod tests { &t, 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())) } @@ -1529,7 +1529,7 @@ mod tests { &t, 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())) } @@ -1540,7 +1540,7 @@ mod tests { &t, 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())) } @@ -1552,7 +1552,7 @@ mod tests { &t, 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())) } @@ -1563,7 +1563,7 @@ mod tests { &t, 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 assert_eq!(filename, Some("=?utf-8?q?foo?=.bar".to_string())) } @@ -1575,7 +1575,7 @@ mod tests { &t, 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())) } @@ -1586,7 +1586,7 @@ mod tests { &t, 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())) } @@ -1597,7 +1597,7 @@ mod tests { &t, 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())) } @@ -1608,7 +1608,7 @@ mod tests { &t, 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())) } @@ -1619,7 +1619,7 @@ mod tests { &t, 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())) } @@ -1631,7 +1631,7 @@ mod tests { &t, 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())) } @@ -1764,26 +1764,26 @@ mod tests { let t = TestContext::new().await; 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.group_avatar, None); 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[0].typ, Viewtype::Text); assert!(mimeparser.user_avatar.unwrap().is_change()); assert_eq!(mimeparser.group_avatar, None); 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[0].typ, Viewtype::Text); assert_eq!(mimeparser.user_avatar, Some(AvatarAction::Delete)); assert_eq!(mimeparser.group_avatar, None); 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[0].typ, Viewtype::Text); 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 = String::from_utf8_lossy(raw).to_string(); 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 .unwrap(); assert_eq!(mimeparser.parts.len(), 1); @@ -1807,7 +1807,7 @@ mod tests { let t = TestContext::new().await; 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[0].typ, Viewtype::VideochatInvitation); assert_eq!( @@ -2121,7 +2121,7 @@ MDYyMDYxNTE1RTlDOEE4Cj4+CnN0YXJ0eHJlZgo4Mjc4CiUlRU9GCg== ------=_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[0].typ, Viewtype::File); @@ -2130,7 +2130,7 @@ MDYyMDYxNTE1RTlDOEE4Cj4+CnN0YXJ0eHJlZgo4Mjc4CiUlRU9GCg== // Make sure the file is there even though the html is wrong: let param = &message.parts[0].param; let blob: BlobObject = param - .get_blob(Param::File, &t.ctx, false) + .get_blob(Param::File, &t, false) .await .unwrap() .unwrap(); @@ -2518,7 +2518,7 @@ On 2020-10-25, Bob wrote: async fn test_quote_div() { let t = TestContext::new().await; 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].param.get(Param::Quote).unwrap(), "Now?"); } diff --git a/src/param.rs b/src/param.rs index ef452774e..a1f06a0aa 100644 --- a/src/param.rs +++ b/src/param.rs @@ -436,7 +436,7 @@ mod tests { #[async_std::test] async fn test_params_file_fs_path() { 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")); } else { panic!("Wrong enum variant"); @@ -446,7 +446,7 @@ mod tests { #[async_std::test] async fn test_params_file_blob() { 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"); } else { panic!("Wrong enum variant"); @@ -461,15 +461,15 @@ mod tests { let mut p = Params::new(); 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())); - 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(); assert_eq!(path, fname); // 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 { BlobError::WrongBlobdir { .. } => (), _ => panic!("wrong error type/variant: {:?}", err), @@ -477,33 +477,33 @@ mod tests { fs::write(fname, b"boo").await.unwrap(); let blob = p - .get_blob(Param::File, &t.ctx, true) + .get_blob(Param::File, &t, true) .await .unwrap() .unwrap(); assert_eq!( blob, - BlobObject::from_name(&t.ctx, "foo".to_string()).unwrap() + BlobObject::from_name(&t, "foo".to_string()).unwrap() ); // 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()); let blob = p - .get_blob(Param::File, &t.ctx, false) + .get_blob(Param::File, &t, false) .await .unwrap() .unwrap(); assert_eq!( blob, - BlobObject::from_name(&t.ctx, "bar".to_string()).unwrap() + BlobObject::from_name(&t, "bar".to_string()).unwrap() ); p.remove(Param::File); - assert!(p.get_file(Param::File, &t.ctx).unwrap().is_none()); - assert!(p.get_path(Param::File, &t.ctx).unwrap().is_none()); + assert!(p.get_file(Param::File, &t).unwrap().is_none()); + assert!(p.get_path(Param::File, &t).unwrap().is_none()); assert!(p - .get_blob(Param::File, &t.ctx, false) + .get_blob(Param::File, &t, false) .await .unwrap() .is_none()); diff --git a/src/stock.rs b/src/stock.rs index 77b2bdb3c..41078031f 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -485,11 +485,10 @@ mod tests { #[async_std::test] async fn test_set_stock_translation() { let t = TestContext::new().await; - t.ctx - .set_stock_translation(StockMessage::NoMessages, "xyz".to_string()) + t.set_stock_translation(StockMessage::NoMessages, "xyz".to_string()) .await .unwrap(); - assert_eq!(t.ctx.stock_str(StockMessage::NoMessages).await, "xyz") + assert_eq!(t.stock_str(StockMessage::NoMessages).await, "xyz") } #[async_std::test] @@ -510,10 +509,7 @@ mod tests { #[async_std::test] async fn test_stock_str() { let t = TestContext::new().await; - assert_eq!( - t.ctx.stock_str(StockMessage::NoMessages).await, - "No messages." - ); + assert_eq!(t.stock_str(StockMessage::NoMessages).await, "No messages."); } #[async_std::test] @@ -521,8 +517,7 @@ mod tests { let t = TestContext::new().await; // uses %1$s substitution assert_eq!( - t.ctx - .stock_string_repl_str(StockMessage::MsgAddMember, "Foo") + t.stock_string_repl_str(StockMessage::MsgAddMember, "Foo") .await, "Member Foo added." ); @@ -533,8 +528,7 @@ mod tests { async fn test_stock_string_repl_int() { let t = TestContext::new().await; assert_eq!( - t.ctx - .stock_string_repl_int(StockMessage::MsgAddMember, 42) + t.stock_string_repl_int(StockMessage::MsgAddMember, 42) .await, "Member 42 added." ); @@ -544,8 +538,7 @@ mod tests { async fn test_stock_string_repl_str2() { let t = TestContext::new().await; assert_eq!( - t.ctx - .stock_string_repl_str2(StockMessage::ServerResponse, "foo", "bar") + t.stock_string_repl_str2(StockMessage::ServerResponse, "foo", "bar") .await, "Could not connect to foo: bar" ); @@ -555,8 +548,7 @@ mod tests { async fn test_stock_system_msg_simple() { let t = TestContext::new().await; assert_eq!( - t.ctx - .stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0) + t.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0) .await, "Location streaming enabled." ) @@ -566,14 +558,13 @@ mod tests { async fn test_stock_system_msg_add_member_by_me() { let t = TestContext::new().await; assert_eq!( - t.ctx - .stock_system_msg( - StockMessage::MsgAddMember, - "alice@example.com", - "", - DC_CONTACT_ID_SELF - ) - .await, + t.stock_system_msg( + StockMessage::MsgAddMember, + "alice@example.com", + "", + DC_CONTACT_ID_SELF + ) + .await, "Member alice@example.com added by me." ) } @@ -581,18 +572,17 @@ mod tests { #[async_std::test] async fn test_stock_system_msg_add_member_by_me_with_displayname() { let t = TestContext::new().await; - Contact::create(&t.ctx, "Alice", "alice@example.com") + Contact::create(&t, "Alice", "alice@example.com") .await .expect("failed to create contact"); assert_eq!( - t.ctx - .stock_system_msg( - StockMessage::MsgAddMember, - "alice@example.com", - "", - DC_CONTACT_ID_SELF - ) - .await, + t.stock_system_msg( + StockMessage::MsgAddMember, + "alice@example.com", + "", + DC_CONTACT_ID_SELF + ) + .await, "Member Alice (alice@example.com) added by me." ); } @@ -601,22 +591,21 @@ mod tests { async fn test_stock_system_msg_add_member_by_other_with_displayname() { let t = TestContext::new().await; let contact_id = { - Contact::create(&t.ctx, "Alice", "alice@example.com") + Contact::create(&t, "Alice", "alice@example.com") .await .expect("Failed to create contact Alice"); - Contact::create(&t.ctx, "Bob", "bob@example.com") + Contact::create(&t, "Bob", "bob@example.com") .await .expect("failed to create bob") }; assert_eq!( - t.ctx - .stock_system_msg( - StockMessage::MsgAddMember, - "alice@example.com", - "", - contact_id, - ) - .await, + t.stock_system_msg( + StockMessage::MsgAddMember, + "alice@example.com", + "", + contact_id, + ) + .await, "Member Alice (alice@example.com) added by Bob (bob@example.com)." ); } @@ -625,14 +614,13 @@ mod tests { async fn test_stock_system_msg_grp_name() { let t = TestContext::new().await; assert_eq!( - t.ctx - .stock_system_msg( - StockMessage::MsgGrpName, - "Some chat", - "Other chat", - DC_CONTACT_ID_SELF - ) - .await, + t.stock_system_msg( + StockMessage::MsgGrpName, + "Some chat", + "Other chat", + DC_CONTACT_ID_SELF + ) + .await, "Group name changed from \"Some chat\" to \"Other chat\" by me." ) } @@ -640,13 +628,12 @@ mod tests { #[async_std::test] async fn test_stock_system_msg_grp_name_other() { 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 .expect("failed to create contact"); assert_eq!( - t.ctx - .stock_system_msg(StockMessage::MsgGrpName, "Some chat", "Other chat", id) + t.stock_system_msg(StockMessage::MsgGrpName, "Some chat", "Other chat", id) .await, "Group name changed from \"Some chat\" to \"Other chat\" by Alice (alice@example.com)." ) @@ -655,13 +642,11 @@ mod tests { #[async_std::test] async fn test_update_device_chats() { let t = TestContext::new().await; - t.ctx.update_device_chats().await.ok(); - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); + t.update_device_chats().await.ok(); + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 2); - let chat0 = Chat::load_from_db(&t.ctx, chats.get_chat_id(0)) - .await - .unwrap(); + let chat0 = Chat::load_from_db(&t, chats.get_chat_id(0)).await.unwrap(); let (self_talk_id, device_chat_id) = if chat0.is_self_talk() { (chats.get_chat_id(0), chats.get_chat_id(1)) } 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 - let device_chat_msgs_before = chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None) - .await - .len(); - self_talk_id.delete(&t.ctx).await.ok(); + let device_chat_msgs_before = chat::get_chat_msgs(&t, device_chat_id, 0, None).await.len(); + self_talk_id.delete(&t).await.ok(); assert_eq!( - chat::get_chat_msgs(&t.ctx, device_chat_id, 0, None) - .await - .len(), + chat::get_chat_msgs(&t, device_chat_id, 0, None).await.len(), device_chat_msgs_before + 1 ); // delete device chat - device_chat_id.delete(&t.ctx).await.ok(); + device_chat_id.delete(&t).await.ok(); // 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); // a subsequent call to update_device_chats() must not re-add manally deleted messages or chats - t.ctx.update_device_chats().await.ok(); - let chats = Chatlist::try_load(&t.ctx, 0, None, None).await.unwrap(); + t.update_device_chats().await.ok(); + let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); assert_eq!(chats.len(), 0); } } diff --git a/src/test_utils.rs b/src/test_utils.rs index a9029c667..6948ea7d0 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -77,7 +77,7 @@ impl TestContext { let t = Self::new().await; let keypair = bob_keypair(); 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 .expect("Failed to save Bob's key"); t