From 9e8e10d434cfcc819e2bead3bf019ed1cc2b50d4 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 18 Dec 2020 05:02:45 +0000 Subject: [PATCH] finally added a present test. rename item_actions to menu_actions --- tests/test_item_modifiers.rs | 101 ++++++++++++++++++ ...t_item_actions.rs => test_menu_actions.rs} | 3 + 2 files changed, 104 insertions(+) create mode 100644 tests/test_item_modifiers.rs rename tests/{test_item_actions.rs => test_menu_actions.rs} (98%) diff --git a/tests/test_item_modifiers.rs b/tests/test_item_modifiers.rs new file mode 100644 index 0000000..b6cc4ca --- /dev/null +++ b/tests/test_item_modifiers.rs @@ -0,0 +1,101 @@ +use elseware::common::serverstate::{ClientId, ServerState}; +use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; +use elseware::entity::item; +use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket}; + +use libpso::packet::ship::*; +use libpso::packet::messages::*; + +#[path = "common.rs"] +mod common; +use common::*; + +// unwrap presents +#[async_std::test] +async fn test_unwrap_weapon() { + let mut entity_gateway = InMemoryGateway::new(); + + let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; + + let wrapped_item = entity_gateway.create_item( + item::NewItemEntity { + item: item::ItemDetail::Weapon(item::weapon::Weapon { + weapon: item::weapon::WeaponType::Saber, + special: Some(item::weapon::WeaponSpecial::Burning), + grind: 5, + attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Machine, value: 20}), + Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 30}), + None], + tekked: false, + wrapping: Some(item::WrappingPaper::Red_Green), + }), + location: item::ItemLocation::Inventory{ + character_id: char1.id, + } + }).await.unwrap(); + + println!("created item: {:?}", wrapped_item); + + let mut inventory = Vec::::new(); + inventory.push(wrapped_item.into()); + entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); + + let mut ship = Box::new(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; + + ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerUseItem(PlayerUseItem { + client: 0, + target: 0, + item_id: 0x10000, + })))).await.unwrap().for_each(drop); + + let inventory_items = entity_gateway.get_character_inventory(&char1.id).await.unwrap(); + + inventory_items.items[0].with_individual(|item| { + match &item.item { + item::ItemDetail::Weapon(weapon) => { + assert!(weapon.as_bytes() == [0x00, 0x01, 0x00, 0x05, 0x9A, 0x00, 0x03, 0x14, 0x05, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); + }, + _ => panic!(), + } + }).unwrap(); +} + +#[async_std::test] +async fn test_unwrap_armor() {} + +#[async_std::test] +async fn test_unwrap_shield() {} + +#[async_std::test] +async fn test_unwrap_unit() {} + +// mag cells are covered in test_mags.rs +#[async_std::test] +async fn test_unwrap_mag() {} + +// TODO: implement wrapping packet (gallons shop quest) +// wrap presents +#[async_std::test] +async fn test_wrap_weapon() {} + +#[async_std::test] +async fn test_wrap_armor() {} + +#[async_std::test] +async fn test_wrap_shield() {} + +#[async_std::test] +async fn test_wrap_unit() {} + +// mag cells are covered in test_mags.rs +#[async_std::test] +async fn test_wrap_mag() {} + + +// item combinations? diff --git a/tests/test_item_actions.rs b/tests/test_menu_actions.rs similarity index 98% rename from tests/test_item_actions.rs rename to tests/test_menu_actions.rs index 3bc531a..b38eabb 100644 --- a/tests/test_item_actions.rs +++ b/tests/test_menu_actions.rs @@ -25,6 +25,7 @@ async fn test_equip_unit_from_equip_menu() { dfp: 0, evp: 0, slots: 4, + wrapping: None, }), location: item::ItemLocation::Inventory { character_id: char1.id, @@ -113,6 +114,7 @@ async fn test_unequip_armor_with_units() { dfp: 0, evp: 0, slots: 4, + wrapping: None, }), location: item::ItemLocation::Inventory { character_id: char1.id, @@ -192,6 +194,7 @@ async fn test_sort_items() { dfp: 0, evp: 0, slots: 4, + wrapping: None, }), location: item::ItemLocation::Inventory { character_id: char1.id,