Skip to content

Commit e951a69

Browse files
committed
test: use TestContextManager in more tests
1 parent 1ebaa2a commit e951a69

File tree

4 files changed

+50
-39
lines changed

4 files changed

+50
-39
lines changed

Diff for: src/chat/chat_tests.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,9 @@ async fn test_modify_chat_lost() -> Result<()> {
674674

675675
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
676676
async fn test_leave_group() -> Result<()> {
677-
let alice = TestContext::new_alice().await;
678-
let bob = TestContext::new_bob().await;
677+
let mut tcm = TestContextManager::new();
678+
let alice = tcm.alice().await;
679+
let bob = tcm.bob().await;
679680

680681
// Create group chat with Bob.
681682
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "foo").await?;
@@ -2039,8 +2040,9 @@ async fn test_forward_quote() -> Result<()> {
20392040

20402041
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
20412042
async fn test_forward_group() -> Result<()> {
2042-
let alice = TestContext::new_alice().await;
2043-
let bob = TestContext::new_bob().await;
2043+
let mut tcm = TestContextManager::new();
2044+
let alice = tcm.alice().await;
2045+
let bob = tcm.bob().await;
20442046

20452047
let alice_chat = alice.create_chat(&bob).await;
20462048
let bob_chat = bob.create_chat(&alice).await;
@@ -2903,12 +2905,13 @@ async fn test_sync_blocked() -> Result<()> {
29032905

29042906
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
29052907
async fn test_sync_accept_before_first_msg() -> Result<()> {
2906-
let alice0 = &TestContext::new_alice().await;
2907-
let alice1 = &TestContext::new_alice().await;
2908+
let mut tcm = TestContextManager::new();
2909+
let alice0 = &tcm.alice().await;
2910+
let alice1 = &tcm.alice().await;
29082911
for a in [alice0, alice1] {
29092912
a.set_config_bool(Config::SyncMsgs, true).await?;
29102913
}
2911-
let bob = TestContext::new_bob().await;
2914+
let bob = &tcm.bob().await;
29122915

29132916
let ba_chat = bob.create_chat(alice0).await;
29142917
let sent_msg = bob.send_text(ba_chat.id, "hi").await;
@@ -2922,7 +2925,7 @@ async fn test_sync_accept_before_first_msg() -> Result<()> {
29222925
a0b_chat_id.accept(alice0).await?;
29232926
let a0b_contact = Contact::get_by_id(alice0, a0b_contact_id).await?;
29242927
assert_eq!(a0b_contact.origin, Origin::CreateChat);
2925-
assert_eq!(alice0.get_chat(&bob).await.blocked, Blocked::Not);
2928+
assert_eq!(alice0.get_chat(bob).await.blocked, Blocked::Not);
29262929

29272930
sync(alice0, alice1).await;
29282931
let alice1_contacts = Contact::get_all(alice1, 0, None).await?;
@@ -2931,7 +2934,7 @@ async fn test_sync_accept_before_first_msg() -> Result<()> {
29312934
let a1b_contact = Contact::get_by_id(alice1, a1b_contact_id).await?;
29322935
assert_eq!(a1b_contact.get_addr(), "[email protected]");
29332936
assert_eq!(a1b_contact.origin, Origin::CreateChat);
2934-
let a1b_chat = alice1.get_chat(&bob).await;
2937+
let a1b_chat = alice1.get_chat(bob).await;
29352938
assert_eq!(a1b_chat.blocked, Blocked::Not);
29362939
let chats = Chatlist::try_load(alice1, 0, None, None).await?;
29372940
assert_eq!(chats.len(), 1);
@@ -3067,8 +3070,9 @@ async fn test_sync_adhoc_grp() -> Result<()> {
30673070
/// - That sync messages don't unarchive the self-chat.
30683071
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
30693072
async fn test_sync_visibility() -> Result<()> {
3070-
let alice0 = &TestContext::new_alice().await;
3071-
let alice1 = &TestContext::new_alice().await;
3073+
let mut tcm = TestContextManager::new();
3074+
let alice0 = &tcm.alice().await;
3075+
let alice1 = &tcm.alice().await;
30723076
for a in [alice0, alice1] {
30733077
a.set_config_bool(Config::SyncMsgs, true).await?;
30743078
}
@@ -3120,8 +3124,9 @@ async fn test_sync_device_messages_visibility() -> Result<()> {
31203124

31213125
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
31223126
async fn test_sync_muted() -> Result<()> {
3123-
let alice0 = &TestContext::new_alice().await;
3124-
let alice1 = &TestContext::new_alice().await;
3127+
let mut tcm = TestContextManager::new();
3128+
let alice0 = &tcm.alice().await;
3129+
let alice1 = &tcm.alice().await;
31253130
for a in [alice0, alice1] {
31263131
a.set_config_bool(Config::SyncMsgs, true).await?;
31273132
}
@@ -3155,8 +3160,9 @@ async fn test_sync_muted() -> Result<()> {
31553160

31563161
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
31573162
async fn test_sync_broadcast() -> Result<()> {
3158-
let alice0 = &TestContext::new_alice().await;
3159-
let alice1 = &TestContext::new_alice().await;
3163+
let mut tcm = TestContextManager::new();
3164+
let alice0 = &tcm.alice().await;
3165+
let alice1 = &tcm.alice().await;
31603166
for a in [alice0, alice1] {
31613167
a.set_config_bool(Config::SyncMsgs, true).await?;
31623168
}

Diff for: src/contact/contact_tests.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,9 @@ async fn test_sync_create() -> Result<()> {
10501050

10511051
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
10521052
async fn test_make_n_import_vcard() -> Result<()> {
1053-
let alice = &TestContext::new_alice().await;
1054-
let bob = &TestContext::new_bob().await;
1053+
let mut tcm = TestContextManager::new();
1054+
let alice = &tcm.alice().await;
1055+
let bob = &tcm.bob().await;
10551056
bob.set_config(Config::Displayname, Some("Bob")).await?;
10561057
let avatar_path = bob.dir.path().join("avatar.png");
10571058
let avatar_bytes = include_bytes!("../../test-data/image/avatar64x64.png");

Diff for: src/html.rs

+23-20
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ mod tests {
285285
use crate::contact::ContactId;
286286
use crate::message::{MessengerMessage, Viewtype};
287287
use crate::receive_imf::receive_imf;
288-
use crate::test_utils::TestContext;
288+
use crate::test_utils::{TestContext, TestContextManager};
289289

290290
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
291291
async fn test_htmlparse_plain_unspecified() {
@@ -442,24 +442,25 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
442442
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
443443
async fn test_html_forwarding() {
444444
// alice receives a non-delta html-message
445-
let alice = TestContext::new_alice().await;
445+
let mut tcm = TestContextManager::new();
446+
let alice = &tcm.alice().await;
446447
let chat = alice
447448
.create_chat_with_contact("", "[email protected]")
448449
.await;
449450
let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml");
450-
receive_imf(&alice, raw, false).await.unwrap();
451+
receive_imf(alice, raw, false).await.unwrap();
451452
let msg = alice.get_last_msg_in(chat.get_id()).await;
452453
assert_ne!(msg.get_from_id(), ContactId::SELF);
453454
assert_eq!(msg.is_dc_message, MessengerMessage::No);
454455
assert!(!msg.is_forwarded());
455456
assert!(msg.get_text().contains("this is plain"));
456457
assert!(msg.has_html());
457-
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
458+
let html = msg.get_id().get_html(alice).await.unwrap().unwrap();
458459
assert!(html.contains("this is <b>html</b>"));
459460

460461
// alice: create chat with bob and forward received html-message there
461462
let chat = alice.create_chat_with_contact("", "[email protected]").await;
462-
forward_msgs(&alice, &[msg.get_id()], chat.get_id())
463+
forward_msgs(alice, &[msg.get_id()], chat.get_id())
463464
.await
464465
.unwrap();
465466
let msg = alice.get_last_msg_in(chat.get_id()).await;
@@ -468,11 +469,11 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
468469
assert!(msg.is_forwarded());
469470
assert!(msg.get_text().contains("this is plain"));
470471
assert!(msg.has_html());
471-
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
472+
let html = msg.get_id().get_html(alice).await.unwrap().unwrap();
472473
assert!(html.contains("this is <b>html</b>"));
473474

474475
// bob: check that bob also got the html-part of the forwarded message
475-
let bob = TestContext::new_bob().await;
476+
let bob = &tcm.bob().await;
476477
let chat = bob.create_chat_with_contact("", "[email protected]").await;
477478
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
478479
assert_eq!(chat.id, msg.chat_id);
@@ -481,7 +482,7 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
481482
assert!(msg.is_forwarded());
482483
assert!(msg.get_text().contains("this is plain"));
483484
assert!(msg.has_html());
484-
let html = msg.get_id().get_html(&bob).await.unwrap().unwrap();
485+
let html = msg.get_id().get_html(bob).await.unwrap().unwrap();
485486
assert!(html.contains("this is <b>html</b>"));
486487
}
487488

@@ -519,10 +520,11 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
519520

520521
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
521522
async fn test_html_forwarding_encrypted() {
523+
let mut tcm = TestContextManager::new();
522524
// Alice receives a non-delta html-message
523525
// (`ShowEmails=AcceptedContacts` lets Alice actually receive non-delta messages for known
524526
// contacts, the contact is marked as known by creating a chat using `chat_with_contact()`)
525-
let alice = TestContext::new_alice().await;
527+
let alice = &tcm.alice().await;
526528
alice
527529
.set_config(Config::ShowEmails, Some("1"))
528530
.await
@@ -531,19 +533,19 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
531533
.create_chat_with_contact("", "[email protected]")
532534
.await;
533535
let raw = include_bytes!("../test-data/message/text_alt_plain_html.eml");
534-
receive_imf(&alice, raw, false).await.unwrap();
536+
receive_imf(alice, raw, false).await.unwrap();
535537
let msg = alice.get_last_msg_in(chat.get_id()).await;
536538

537539
// forward the message to saved-messages,
538540
// this will encrypt the message as new_alice() has set up keys
539541
let chat = alice.get_self_chat().await;
540-
forward_msgs(&alice, &[msg.get_id()], chat.get_id())
542+
forward_msgs(alice, &[msg.get_id()], chat.get_id())
541543
.await
542544
.unwrap();
543545
let msg = alice.pop_sent_msg().await;
544546

545547
// receive the message on another device
546-
let alice = TestContext::new_alice().await;
548+
let alice = &tcm.alice().await;
547549
alice
548550
.set_config(Config::ShowEmails, Some("0"))
549551
.await
@@ -556,38 +558,39 @@ test some special html-characters as &lt; &gt; and &amp; but also &quot; and &#x
556558
assert!(msg.is_forwarded());
557559
assert!(msg.get_text().contains("this is plain"));
558560
assert!(msg.has_html());
559-
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
561+
let html = msg.get_id().get_html(alice).await.unwrap().unwrap();
560562
assert!(html.contains("this is <b>html</b>"));
561563
}
562564

563565
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
564566
async fn test_set_html() {
565-
let alice = TestContext::new_alice().await;
566-
let bob = TestContext::new_bob().await;
567+
let mut tcm = TestContextManager::new();
568+
let alice = &tcm.alice().await;
569+
let bob = &tcm.bob().await;
567570

568571
// alice sends a message with html-part to bob
569-
let chat_id = alice.create_chat(&bob).await.id;
572+
let chat_id = alice.create_chat(bob).await.id;
570573
let mut msg = Message::new_text("plain text".to_string());
571574
msg.set_html(Some("<b>html</b> text".to_string()));
572575
assert!(msg.mime_modified);
573-
chat::send_msg(&alice, chat_id, &mut msg).await.unwrap();
576+
chat::send_msg(alice, chat_id, &mut msg).await.unwrap();
574577

575578
// check the message is written correctly to alice's db
576579
let msg = alice.get_last_msg_in(chat_id).await;
577580
assert_eq!(msg.get_text(), "plain text");
578581
assert!(!msg.is_forwarded());
579582
assert!(msg.mime_modified);
580-
let html = msg.get_id().get_html(&alice).await.unwrap().unwrap();
583+
let html = msg.get_id().get_html(alice).await.unwrap().unwrap();
581584
assert!(html.contains("<b>html</b> text"));
582585

583586
// let bob receive the message
584-
let chat_id = bob.create_chat(&alice).await.id;
587+
let chat_id = bob.create_chat(alice).await.id;
585588
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
586589
assert_eq!(msg.chat_id, chat_id);
587590
assert_eq!(msg.get_text(), "plain text");
588591
assert!(!msg.is_forwarded());
589592
assert!(msg.mime_modified);
590-
let html = msg.get_id().get_html(&bob).await.unwrap().unwrap();
593+
let html = msg.get_id().get_html(bob).await.unwrap().unwrap();
591594
assert!(html.contains("<b>html</b> text"));
592595
}
593596

Diff for: src/reaction.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,9 @@ Here's my footer -- [email protected]"
731731

732732
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
733733
async fn test_reaction_summary() -> Result<()> {
734-
let alice = TestContext::new_alice().await;
735-
let bob = TestContext::new_bob().await;
734+
let mut tcm = TestContextManager::new();
735+
let alice = tcm.alice().await;
736+
let bob = tcm.bob().await;
736737
alice.set_config(Config::Displayname, Some("ALICE")).await?;
737738
bob.set_config(Config::Displayname, Some("BOB")).await?;
738739
let alice_bob_id = alice.add_or_lookup_contact_id(&bob).await;

0 commit comments

Comments
 (0)