elseware/tests/test_rooms.rs

119 lines
5.6 KiB
Rust
Raw Normal View History

use networking::serverstate::{ClientId, ServerState};
use entity::gateway::{EntityGateway, InMemoryGateway};
2023-11-12 00:25:00 -07:00
use elseware::ship::ship::{RecvShipPacket, SendShipPacket};
2020-10-31 23:18:25 -06:00
use libpso::packet::ship::*;
//use libpso::packet::messages::*;
2020-10-31 23:18:25 -06:00
#[path = "common.rs"]
mod common;
use common::*;
2022-02-07 03:01:29 +00:00
#[async_std::test]
async fn test_set_valid_quest_group() {
let mut entity_gateway = InMemoryGateway::default();
2023-11-12 00:46:02 -07:00
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let mut ship = standard_ship_buildable(entity_gateway.clone())
.standard_quest_builder(Box::new(quests::load_standard_quests))
.build();
2022-02-07 03:01:29 +00:00
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
2022-10-18 04:46:21 -06:00
let packets = ship.handle(ClientId(1), RecvShipPacket::RequestQuestList(RequestQuestList{flag: 0})).await.unwrap();
2022-02-07 03:01:29 +00:00
match &packets[0].1 {
SendShipPacket::QuestCategoryList(quest_cat) => {
assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Retrieval"));
},
_ => panic!("Wrong quest category"),
}
}
#[async_std::test]
async fn test_set_invalid_quest_group() {
let mut entity_gateway = InMemoryGateway::default();
2023-11-12 00:46:02 -07:00
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let mut ship = standard_ship_buildable(entity_gateway.clone())
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.build();
2022-02-07 03:01:29 +00:00
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
2022-10-18 04:46:21 -06:00
let packets = ship.handle(ClientId(1), RecvShipPacket::RequestQuestList(RequestQuestList{flag: 100})).await.unwrap();
2022-02-07 03:01:29 +00:00
match &packets[0].1 {
SendShipPacket::QuestCategoryList(quest_cat) => {
// flag > quest category length should take the highest value allowed for quest category which is 1 in multimode (for govt quests) and 0 in other modes.
// assuming we create an ep1 room in multimode, we should load the government quests in this test case
assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Government"));
},
_ => panic!("Wrong quest category"),
}
2022-07-11 03:48:21 +00:00
}
#[async_std::test]
async fn test_get_room_info() {
let mut entity_gateway = InMemoryGateway::default();
2023-11-12 00:46:02 -07:00
let (_user1, mut _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
2022-07-11 03:48:21 +00:00
_char1.name = String::from("GODmar");
entity_gateway.save_character(&_char1).await.unwrap();
2023-11-12 00:46:02 -07:00
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
let mut ship = standard_ship(entity_gateway.clone());
2022-07-11 03:48:21 +00:00
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
let _expectedmsg = String::from("1 Lv1 GODmar\nHUmar Pioneer 2\n");
2022-10-18 04:46:21 -06:00
let packets = ship.handle(ClientId(2), RecvShipPacket::MenuDetail(MenuDetail{menu: 3, item: 0})).await.unwrap();
2022-07-11 03:48:21 +00:00
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallLeftDialog(SmallLeftDialog{
padding: [17664, 1157645568],
msg: _expectedmsg,
2022-07-11 03:48:21 +00:00
}))));
}
#[async_std::test]
async fn test_cannot_get_room_info_after_room_is_closed() {
let mut entity_gateway = InMemoryGateway::default();
2023-11-12 00:46:02 -07:00
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
let mut ship = standard_ship(entity_gateway.clone());
2022-07-11 03:48:21 +00:00
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
leave_room(&mut ship, ClientId(1)).await;
let _expectedmsg = String::from("Game is no longer active!\0");
2022-10-18 04:46:21 -06:00
let packets = ship.handle(ClientId(2), RecvShipPacket::MenuDetail(MenuDetail{menu: 3, item: 0})).await.unwrap();
2022-07-11 03:48:21 +00:00
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallLeftDialog(SmallLeftDialog{
padding: [17664, 1157645568],
msg: _expectedmsg,
}))));
}
#[async_std::test]
async fn test_cannot_join_room_after_its_closed() {
let mut entity_gateway = InMemoryGateway::default();
2023-11-12 00:46:02 -07:00
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
let mut ship = standard_ship(entity_gateway.clone());
2022-07-11 03:48:21 +00:00
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).await;
create_room(&mut ship, ClientId(1), "room", "").await;
leave_room(&mut ship, ClientId(1)).await;
let _expectedmsg = String::from("This room no longer exists!\0");
2022-10-18 04:46:21 -06:00
let packets = ship.handle(ClientId(2), RecvShipPacket::MenuSelect(MenuSelect{menu: 3, item: 0})).await.unwrap();
2022-07-11 03:48:21 +00:00
assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallDialog(SmallDialog{
padding: [0,0],
msg: _expectedmsg, // wow yes cool rust is so great literally the best i can't put a String::from() directly in here.
}))));
}
2023-01-31 19:22:11 -07:00
// TODO: test joining twice errors not hangs forever