From 919f3cf7546738ebcd3ae7d053848fe1e41210cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 19 Sep 2022 15:12:41 +0200 Subject: [PATCH] room: split test_broadcast_presence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/room.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/src/room.rs b/src/room.rs index 2a78e2e..13ce443 100644 --- a/src/room.rs +++ b/src/room.rs @@ -381,7 +381,7 @@ mod tests { }; #[tokio::test] - async fn test_broadcast_presence() { + async fn test_broadcast_presence_resync() { let roomjid = BareJid::from_str("room@muc").unwrap(); let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap(); let participant1 = roomjid.clone().with_resource(String::from("nick1")); @@ -443,6 +443,29 @@ mod tests { room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Resync).await.unwrap(); component.assert(); + } + + #[tokio::test] + async fn test_broadcast_presence_update() { + let roomjid = BareJid::from_str("room@muc").unwrap(); + let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap(); + let participant1 = roomjid.clone().with_resource(String::from("nick1")); + let realjid2 = FullJid::from_str("qxx@foo/bar").unwrap(); + let participant2 = roomjid.clone().with_resource(String::from("nick2")); + let realjid3 = FullJid::from_str("bar@qxx/foo").unwrap(); + let participant3 = roomjid.clone().with_resource(String::from("nick3")); + + let mut room = Room::new(roomjid.clone()); + + room.occupants = BTreeMap::new(); + room.occupants.insert( + participant1.resource.clone(), Occupant::new(&room, realjid1.clone(), String::from("nick1")), + ); + room.occupants.insert( + participant2.resource.clone(), Occupant::new(&room, realjid2.clone(), String::from("nick2")), + ); + let occupant3 = Occupant::new(&room, realjid3.clone(), String::from("nick3")); + room.occupants.insert(participant3.resource.clone(), occupant3.clone()); // BroadcastPresence::Update let mut component = TestComponent::new(vec![]); @@ -473,6 +496,29 @@ mod tests { room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Update).await.unwrap(); component.assert(); + } + + #[tokio::test] + async fn test_broadcast_presence_join() { + let roomjid = BareJid::from_str("room@muc").unwrap(); + let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap(); + let participant1 = roomjid.clone().with_resource(String::from("nick1")); + let realjid2 = FullJid::from_str("qxx@foo/bar").unwrap(); + let participant2 = roomjid.clone().with_resource(String::from("nick2")); + let realjid3 = FullJid::from_str("bar@qxx/foo").unwrap(); + let participant3 = roomjid.clone().with_resource(String::from("nick3")); + + let mut room = Room::new(roomjid.clone()); + + room.occupants = BTreeMap::new(); + room.occupants.insert( + participant1.resource.clone(), Occupant::new(&room, realjid1.clone(), String::from("nick1")), + ); + room.occupants.insert( + participant2.resource.clone(), Occupant::new(&room, realjid2.clone(), String::from("nick2")), + ); + let occupant3 = Occupant::new(&room, realjid3.clone(), String::from("nick3")); + room.occupants.insert(participant3.resource.clone(), occupant3.clone()); // BroadcastPresence::Join let mut component = TestComponent::new(vec![]); @@ -539,6 +585,29 @@ mod tests { room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Join).await.unwrap(); component.assert(); + } + + #[tokio::test] + async fn test_broadcast_presence_leave() { + let roomjid = BareJid::from_str("room@muc").unwrap(); + let realjid1 = FullJid::from_str("foo@bar/qxx").unwrap(); + let participant1 = roomjid.clone().with_resource(String::from("nick1")); + let realjid2 = FullJid::from_str("qxx@foo/bar").unwrap(); + let participant2 = roomjid.clone().with_resource(String::from("nick2")); + let realjid3 = FullJid::from_str("bar@qxx/foo").unwrap(); + let participant3 = roomjid.clone().with_resource(String::from("nick3")); + + let mut room = Room::new(roomjid.clone()); + + room.occupants = BTreeMap::new(); + room.occupants.insert( + participant1.resource.clone(), Occupant::new(&room, realjid1.clone(), String::from("nick1")), + ); + room.occupants.insert( + participant2.resource.clone(), Occupant::new(&room, realjid2.clone(), String::from("nick2")), + ); + let occupant3 = Occupant::new(&room, realjid3.clone(), String::from("nick3")); + room.occupants.insert(participant3.resource.clone(), occupant3.clone()); // BroadcastPresence::Leave let mut component = TestComponent::new(vec![]); @@ -581,6 +650,5 @@ mod tests { room.broadcast_presence(&mut component, &occupant3, &realjid3, BroadcastPresence::Leave).await.unwrap(); component.assert(); - } }