Browse Source

fix tests

pbs
jake 4 years ago
parent
commit
982966e679
  1. 21
      src/ship/ship.rs
  2. 104
      tests/test_bank.rs
  3. 16
      tests/test_exp_gain.rs
  4. 40
      tests/test_item_pickup.rs
  5. 20
      tests/test_item_use.rs

21
src/ship/ship.rs

@ -291,12 +291,12 @@ impl<EG: EntityGateway> ShipServerStateBuilder<EG> {
clients: HashMap::new(),
client_location: ClientLocation::new(),
level_table: CharacterLevelTable::new(),
name: self.name.unwrap(),
name: self.name.unwrap_or("NAMENOTSET".into()),
rooms: [None; MAX_ROOMS],
item_manager: items::ItemManager::new(),
quests: quests::load_quests("data/quests.toml".into()).unwrap(),
ip: self.ip.unwrap(),
port: self.port.unwrap(),
ip: self.ip.unwrap_or(Ipv4Addr::new(127,0,0,1)),
port: self.port.unwrap_or(SHIP_PORT),
}
}
}
@ -315,18 +315,9 @@ pub struct ShipServerState<EG: EntityGateway> {
}
impl<EG: EntityGateway> ShipServerState<EG> {
/*pub fn new(entity_gateway: EG) -> ShipServerState<EG> {
ShipServerState {
entity_gateway: entity_gateway,
clients: HashMap::new(),
client_location: ClientLocation::new(),
level_table: CharacterLevelTable::new(),
name: "Sona-Nyl".into(),
rooms: [None; MAX_ROOMS],
item_manager: items::ItemManager::new(),
quests: quests::load_quests("data/quests.toml".into()).unwrap(),
}
}*/
pub fn builder() -> ShipServerStateBuilder<EG> {
ShipServerStateBuilder::new()
}
async fn message(&mut self, id: ClientId, msg: &Message) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
match &msg.msg {

104
tests/test_bank.rs

@ -34,7 +34,9 @@ async fn test_bank_items_sent_in_character_login() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
let packets = ship.handle(ClientId(1), &RecvShipPacket::MenuSelect(MenuSelect {
@ -71,7 +73,9 @@ async fn test_request_bank_items() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -114,7 +118,9 @@ async fn test_request_stacked_bank_items() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -186,7 +192,9 @@ async fn test_request_bank_items_sorted() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -249,7 +257,9 @@ async fn test_deposit_individual_item() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -316,7 +326,9 @@ async fn test_deposit_stacked_item() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -383,7 +395,9 @@ async fn test_deposit_partial_stacked_item() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -476,7 +490,9 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -557,7 +573,9 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -649,7 +667,9 @@ async fn test_deposit_individual_item_in_full_bank() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -739,7 +759,9 @@ async fn test_deposit_stacked_item_in_full_bank() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -844,7 +866,9 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -899,7 +923,9 @@ async fn test_deposit_meseta() {
char1.meseta = 300;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -935,7 +961,9 @@ async fn test_deposit_too_much_meseta() {
char1.bank_meseta = 999980;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -972,7 +1000,9 @@ async fn test_deposit_meseta_when_bank_is_maxed() {
char1.bank_meseta = 999999;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1024,7 +1054,9 @@ async fn test_withdraw_individual_item() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1089,7 +1121,9 @@ async fn test_withdraw_stacked_item() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1154,7 +1188,9 @@ async fn test_withdraw_partial_stacked_item() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1245,7 +1281,9 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1325,7 +1363,9 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1417,7 +1457,9 @@ async fn test_withdraw_individual_item_in_full_inventory() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1507,7 +1549,9 @@ async fn test_withdraw_stacked_item_in_full_inventory() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1613,7 +1657,9 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1668,7 +1714,9 @@ async fn test_withdraw_meseta() {
char1.bank_meseta = 300;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1704,7 +1752,9 @@ async fn test_withdraw_too_much_meseta() {
char1.bank_meseta = 300;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -1740,7 +1790,9 @@ async fn test_withdraw_meseta_inventory_is_maxed() {
char1.bank_meseta = 300;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;

16
tests/test_exp_gain.rs

@ -17,7 +17,9 @@ async fn test_character_gains_exp() {
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -54,7 +56,9 @@ async fn test_character_levels_up() {
char1.exp = 49;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -90,7 +94,9 @@ async fn test_character_levels_up_multiple_times() {
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -133,7 +139,9 @@ async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() {
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 = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;

40
tests/test_item_pickup.rs

@ -49,7 +49,9 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() {
}
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -116,7 +118,9 @@ async fn test_pick_up_item_stack_of_items_not_already_held() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -185,7 +189,9 @@ async fn test_pick_up_meseta_when_inventory_full() {
char2.meseta = 300;
entity_gateway.save_character(&char2).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -285,7 +291,9 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -372,7 +380,9 @@ async fn test_can_not_pick_up_item_when_inventory_full() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -428,7 +438,9 @@ async fn test_can_not_drop_more_meseta_than_is_held() {
char1.meseta = 300;
entity_gateway.save_character(&char1).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
@ -496,7 +508,9 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -545,7 +559,9 @@ async fn test_can_not_pick_up_meseta_when_full() {
char2.meseta = 300;
entity_gateway.save_character(&char2).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -601,7 +617,9 @@ async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
char2.meseta = 300;
entity_gateway.save_character(&char2).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
@ -667,7 +685,9 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() {
}).await;
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
log_in_char(&mut ship, ClientId(2), "a2", "a").await;

20
tests/test_item_use.rs

@ -36,7 +36,9 @@ async fn test_use_monomate() {
}
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -90,7 +92,9 @@ async fn test_use_monomate_twice() {
}
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -149,7 +153,9 @@ async fn test_use_last_monomate() {
}
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -199,7 +205,9 @@ async fn test_use_nonstackable_tool() {
}
}).await;
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;
@ -238,7 +246,9 @@ async fn test_use_materials() {
}
}
let mut ship = ShipServerState::new(entity_gateway.clone());
let mut ship = ShipServerState::builder()
.gateway(entity_gateway.clone())
.build();
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;

Loading…
Cancel
Save