Skip to content

Commit

Permalink
Add some deserialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vswarte committed Aug 11, 2024
1 parent cd554b1 commit 93e80da
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/message/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ edition = "2021"

[dependencies.serde]
workspace = true

[dependencies.waygate-wire]
workspace = true
52 changes: 52 additions & 0 deletions crates/message/src/bloodmessage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,55 @@ pub struct ResponseReentryBloodMessageParams {
pub struct RequestRemoveBloodMessageParams {
pub identifier: ObjectIdentifier,
}

#[cfg(test)]
mod test {
use waygate_wire::deserialize;
use crate::RequestGetBloodMessageListParams;
use crate::RequestCreateBloodMessageParams;

#[test]
fn deserialize_create_bloodmessage() {
let deserialized: RequestCreateBloodMessageParams = deserialize(
include_bytes!("../test/data/RequestCreateBloodMessage.bin"),
).unwrap();

assert_eq!(deserialized.area.play_region, 1400001);
assert_eq!(deserialized.area.area, 1400001);
assert_eq!(deserialized.character_id, 21);
assert_eq!(deserialized.data.len(), 520);
assert_eq!(deserialized.group_passwords.len(), 1);
assert_eq!(deserialized.group_passwords[0], "schlong");
assert_eq!(deserialized.unk, 0);
}

#[test]
fn deserialize_get_bloodmessage_list() {
let deserialized: RequestGetBloodMessageListParams = deserialize(
include_bytes!("../test/data/RequestGetBloodMessageList.bin"),
).unwrap();

assert_eq!(deserialized.search_areas.len(), 8);
assert_eq!(deserialized.search_areas[0].play_region, 6043340);
assert_eq!(deserialized.search_areas[0].area, 6102002);
assert_eq!(deserialized.search_areas[1].play_region, 6042340);
assert_eq!(deserialized.search_areas[1].area, 6102002);
assert_eq!(deserialized.search_areas[2].play_region, 6043350);
assert_eq!(deserialized.search_areas[2].area, 6102002);
assert_eq!(deserialized.search_areas[3].play_region, 6042350);
assert_eq!(deserialized.search_areas[3].area, 6102002);
assert_eq!(deserialized.search_areas[4].play_region, 6043340);
assert_eq!(deserialized.search_areas[4].area, 6102000);
assert_eq!(deserialized.search_areas[5].play_region, 6042340);
assert_eq!(deserialized.search_areas[5].area, 600000);
assert_eq!(deserialized.search_areas[6].play_region, 6041340);
assert_eq!(deserialized.search_areas[6].area, 6102002);
assert_eq!(deserialized.search_areas[7].play_region, 6041340);
assert_eq!(deserialized.search_areas[7].area, 600000);
assert_eq!(deserialized.group_passwords.len(), 4);
assert_eq!(deserialized.group_passwords[0], "group1");
assert_eq!(deserialized.group_passwords[1], "group2");
assert_eq!(deserialized.group_passwords[2], "group3");
assert_eq!(deserialized.group_passwords[3], "group4");
}
}
56 changes: 55 additions & 1 deletion crates/message/src/bloodstain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};

use super::*;

Expand Down Expand Up @@ -44,3 +44,57 @@ pub struct ResponseGetDeadingGhostParams {
pub identifier: ObjectIdentifier,
pub replay_data: Vec<u8>,
}

#[cfg(test)]
mod test {
use waygate_wire::deserialize;
use crate::{RequestCreateBloodstainParams, RequestGetBloodstainListParams};

#[test]
fn deserialize_create_bloodstain() {
let deserialized: RequestCreateBloodstainParams = deserialize(
include_bytes!("../test/data/RequestCreateBloodstain.bin"),
).unwrap();

assert_eq!(deserialized.area.play_region, 1400001);
assert_eq!(deserialized.area.area, 1400001);
assert_eq!(deserialized.advertisement_data.len(), 128);
assert_eq!(deserialized.replay_data.len(), 1165);
assert_eq!(deserialized.group_passwords.len(), 1);
assert_eq!(deserialized.group_passwords[0], "schlong");
}

#[test]
fn deserialize_get_bloodstain_list() {
let deserialized: RequestGetBloodstainListParams = deserialize(
include_bytes!("../test/data/RequestGetBloodstainList.bin"),
).unwrap();

assert_eq!(deserialized.search_areas.len(), 10);
assert_eq!(deserialized.search_areas[0].play_region, 3000001);
assert_eq!(deserialized.search_areas[0].area, 3000001);
assert_eq!(deserialized.search_areas[1].play_region, 6043330);
assert_eq!(deserialized.search_areas[1].area, 6102002);
assert_eq!(deserialized.search_areas[2].play_region, 6042330);
assert_eq!(deserialized.search_areas[2].area, 6102002);
assert_eq!(deserialized.search_areas[3].play_region, 3000000);
assert_eq!(deserialized.search_areas[3].area, 3000000);
assert_eq!(deserialized.search_areas[4].play_region, 6043330);
assert_eq!(deserialized.search_areas[4].area, 6102000);
assert_eq!(deserialized.search_areas[5].play_region, 6043340);
assert_eq!(deserialized.search_areas[5].area, 6102002);
assert_eq!(deserialized.search_areas[6].play_region, 6043340);
assert_eq!(deserialized.search_areas[6].area, 6102000);
assert_eq!(deserialized.search_areas[7].play_region, 6043320);
assert_eq!(deserialized.search_areas[7].area, 6102002);
assert_eq!(deserialized.search_areas[8].play_region, 6042340);
assert_eq!(deserialized.search_areas[8].area, 6102002);
assert_eq!(deserialized.search_areas[9].play_region, 6042320);
assert_eq!(deserialized.search_areas[9].area, 6102002);
assert_eq!(deserialized.group_passwords.len(), 4);
assert_eq!(deserialized.group_passwords[0], "group1");
assert_eq!(deserialized.group_passwords[1], "group2");
assert_eq!(deserialized.group_passwords[2], "group3");
assert_eq!(deserialized.group_passwords[3], "group4");
}
}
22 changes: 22 additions & 0 deletions crates/message/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,25 @@ pub struct RequestJoinMultiplayParams {
pub unk5: u32,
pub unk6: u32,
}

#[cfg(test)]
mod test {
use waygate_wire::deserialize;
use crate::{ObjectIdentifier, RequestUpdateSignParams, RequestUseItemLogParams};

#[test]
fn deserialize_use_item_log() {
let deserialized: RequestUseItemLogParams = deserialize(
include_bytes!("../test/data/RequestUseItemLog.bin"),
).unwrap();

assert_eq!(deserialized.used_items.len(), 1);
assert_eq!(deserialized.used_items[0].item_id, 101);
assert_eq!(deserialized.used_items[0].times_used, 1);
assert_eq!(deserialized.used_items[0].unk3, 1);
assert_eq!(deserialized.location.map, 60423600);
assert_eq!(deserialized.location.x, -45.939575);
assert_eq!(deserialized.location.y, 92.36392);
assert_eq!(deserialized.location.z, 79.65545);
}
}
46 changes: 46 additions & 0 deletions crates/message/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,49 @@ pub struct RequestCreateMatchAreaSignParams {
pub struct ResponseCreateMatchAreaSignParams {
pub identifier: ObjectIdentifier,
}

#[cfg(test)]
mod test {
use waygate_wire::deserialize;
use crate::{ObjectIdentifier, RequestGetSignListParams, RequestUpdateSignParams};

#[test]
fn deserialize_update_sign() {
let deserialized: RequestUpdateSignParams = deserialize(
include_bytes!("../test/data/RequestUpdateSign.bin"),
).unwrap();

assert_eq!(
deserialized.identifier,
ObjectIdentifier { object_id: -1198167463, secondary_id: 328094526 }
);
assert_eq!(deserialized.unk0, 0);
}

#[test]
fn deserialize_get_sign_list() {
let deserialized: RequestGetSignListParams = deserialize(
include_bytes!("../test/data/RequestGetSignList.bin"),
).unwrap();

// TODO: add example with known signs
assert_eq!(deserialized.known_signs.len(), 0);
assert_eq!(deserialized.search_areas.len(), 2);
assert_eq!(deserialized.search_areas[0].play_region, 1100000);
assert_eq!(deserialized.search_areas[0].area, 1100000);
assert_eq!(deserialized.search_areas[1].play_region, 1100001);
assert_eq!(deserialized.search_areas[1].area, 1100001);
assert_eq!(deserialized.matching_parameters.game_version, 11001000);
assert_eq!(deserialized.matching_parameters.unk1, 5);
assert_eq!(deserialized.matching_parameters.region_flags, 256);
assert_eq!(deserialized.matching_parameters.unk2, 0);
assert_eq!(deserialized.matching_parameters.soul_level, 99);
assert_eq!(deserialized.matching_parameters.unk3, 0);
assert_eq!(deserialized.matching_parameters.unk4, 0);
assert_eq!(deserialized.matching_parameters.clear_count, 0);
assert_eq!(deserialized.matching_parameters.password, "");
assert_eq!(deserialized.matching_parameters.unk5, 0);
assert_eq!(deserialized.matching_parameters.max_reinforce, 22);
assert_eq!(deserialized.matching_parameters.unk6, 5);
}
}
Binary file not shown.
Binary file modified crates/message/test/data/RequestCreateBloodstain.bin
100755 → 100644
Binary file not shown.
Binary file modified crates/message/test/data/RequestGetBloodMessageList.bin
Binary file not shown.
Binary file added crates/message/test/data/RequestGetSignList.bin
Binary file not shown.
Binary file added crates/message/test/data/RequestUpdateSign.bin
Binary file not shown.
Binary file added crates/message/test/data/RequestUseItemLog.bin
Binary file not shown.
Binary file not shown.
Binary file removed crates/message/test/data/ResponseCreateSession.bin
Binary file not shown.
Binary file not shown.

0 comments on commit 93e80da

Please sign in to comment.