1
0

feat: update test for bmap-rs

This commit is contained in:
2026-02-25 09:51:18 +08:00
parent 54fed7e37b
commit c9d369d2c4
3 changed files with 645 additions and 1 deletions

View File

@@ -2,13 +2,164 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "anyhow"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]
name = "bitflags"
version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
[[package]]
name = "bmap-rs"
version = "0.4.0"
dependencies = [
"tempfile",
"thiserror",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "errno"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "foldhash"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "getrandom"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
"wasip3",
]
[[package]]
name = "hashbrown"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash",
]
[[package]]
name = "hashbrown"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "id-arena"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]
name = "indexmap"
version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
dependencies = [
"equivalent",
"hashbrown 0.16.1",
"serde",
"serde_core",
]
[[package]]
name = "itoa"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]]
name = "leb128fmt"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]
name = "libc"
version = "0.2.182"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
[[package]]
name = "linux-raw-sys"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
[[package]]
name = "log"
version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
name = "memchr"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "prettyplease"
version = "0.2.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
dependencies = [
"proc-macro2",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.106"
@@ -27,6 +178,73 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rustix"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "semver"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "syn"
version = "2.0.115"
@@ -38,6 +256,19 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tempfile"
version = "3.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
dependencies = [
"fastrand",
"getrandom",
"once_cell",
"rustix",
"windows-sys",
]
[[package]]
name = "thiserror"
version = "2.0.18"
@@ -63,3 +294,170 @@ name = "unicode-ident"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537dd038a89878be9b64dd4bd1b260315c1bb94f4d784956b81e27a088d9a09e"
[[package]]
name = "unicode-xid"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "wasip2"
version = "1.0.2+wasi-0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasip3"
version = "0.4.0+wasi-0.3.0-rc-2026-01-06"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasm-encoder"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
dependencies = [
"leb128fmt",
"wasmparser",
]
[[package]]
name = "wasm-metadata"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
dependencies = [
"anyhow",
"indexmap",
"wasm-encoder",
"wasmparser",
]
[[package]]
name = "wasmparser"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
dependencies = [
"bitflags",
"hashbrown 0.15.5",
"indexmap",
"semver",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "wit-bindgen"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
dependencies = [
"wit-bindgen-rust-macro",
]
[[package]]
name = "wit-bindgen-core"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
dependencies = [
"anyhow",
"heck",
"wit-parser",
]
[[package]]
name = "wit-bindgen-rust"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
dependencies = [
"anyhow",
"heck",
"indexmap",
"prettyplease",
"syn",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
]
[[package]]
name = "wit-bindgen-rust-macro"
version = "0.51.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
dependencies = [
"anyhow",
"prettyplease",
"proc-macro2",
"quote",
"syn",
"wit-bindgen-core",
"wit-bindgen-rust",
]
[[package]]
name = "wit-component"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
dependencies = [
"anyhow",
"bitflags",
"indexmap",
"log",
"serde",
"serde_derive",
"serde_json",
"wasm-encoder",
"wasm-metadata",
"wasmparser",
"wit-parser",
]
[[package]]
name = "wit-parser"
version = "0.244.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
dependencies = [
"anyhow",
"id-arena",
"indexmap",
"log",
"semver",
"serde",
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser",
]
[[package]]
name = "zmij"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"

View File

@@ -9,3 +9,6 @@ license = "SPDX:MIT"
[dependencies]
thiserror = "2.0.12"
[dev-dependencies]
tempfile = "3.26.0"

View File

@@ -1,9 +1,252 @@
use bmap_rs::bmap_wrapper as bmap;
use std::path::PathBuf;
#[test]
fn test_complete() {
assert!(bmap::BMap::is_available());
// Parse arguments
let cliopts = cli::Cli::new();
// Check BMap status.
if !bmap::BMap::is_available() {
panic!("Fail to initialize native BMap.");
}
// Waiting debugger
println!(
"Rust PID is {}. Waiting for debugger, press any key to continue...",
std::process::id()
);
let buffer = &mut [0u8];
std::io::stdin().read_exact(buffer).unwrap();
// Start testbench
let file_name = cliopts.file_name.clone();
let temp_folder = tempfile::tempdir().unwrap();
let texture_folder = cliopts.ballance_dir.clone();
texture_folder.push("Textures");
let encodings = cliopts.encodings.clone();
bmap::BMap::with_bmap(|b| {
let r = b.create_file_reader("", "", "", std::iter::once(""));
});
drop(temp_folder);
}
mod cli {
use super::PathBuf;
pub struct Cli {
/// The path to the map for loading.
pub file_name: PathBuf,
/// The path to the Ballance directory for finding textures
pub ballance_dir: PathBuf,
/// The name of encodings used by BMap for loading map.
pub encodings: Vec<String>,
}
impl Cli {
pub fn new() -> Self {
let file_name = std::env::var("BMAP_FILE_NAME").expect(
"You must specify BMAP_FILE_NAME environment variable before running this test.",
);
let ballance_dir = std::env::var("BMAP_BALLANCE_DIR").expect(
"You must specify BMAP_BALLANCE_DIR environment variable before running this test.",
);
let encodings = std::env::var("BMAP_ENCODINGS").expect(
"You must specify BMAP_ENCODINGS environment variable before running this test.",
);
Self {
file_name: PathBuf::from(file_name),
ballance_dir: PathBuf::from(ballance_dir),
encodings: encodings.split(",").collect(),
}
}
}
}
mod testsuits {
use super::bmap;
pub use common;
pub use eq;
mod common {
use super::bmap;
pub fn test(reader: bmap::BMFileReader) {
println!("===== Groups =====");
test_group(reader);
println!("===== 3dObjects =====");
test_3dobject(reader);
println!("===== Meshes =====");
test_mesh(reader);
println!("===== Materials =====");
test_material(reader);
println!("===== Textures =====");
test_texture(reader);
println!("===== Target Lights =====");
test_target_light(reader);
println!("===== Target Cameras =====");
test_target_camera(reader);
println!("===== END =====");
}
fn test_group(reader: bmap::BMFileReader) {
for gp in reader.get_groups() {
println!("{}", gp.get_name());
for gp_item in gp.get_objects() {
println!("\t{}", gp_item.get_name());
}
}
}
fn test_3dobject(reader: bmap::BMFileReader) {
for obj in reader.get_3dobjects() {
println!("{}", obj.get_name());
let current_mesh = obj.get_current_mesh();
let mesh_name = if let Some(mesh) = current_mesh {
mesh.get_name()
} else {
"<null>".to_string()
};
println!("\tMesh: {}", mesh_name);
println!("\tVisibility: {}", obj.get_visibility());
println!("\tMatrix: {:?}", obj.get_world_matrix().to_const());
}
}
fn test_mesh(reader: bmap::BMFileReader) {
for mesh in reader.get_meshs() {
println!("{}", mesh.get_name());
println!("\tLit Mode: {}", mesh.get_lit_mode());
println!("\tVertex Count: {}", mesh.get_vertex_count());
println!("\tFace Count: {}", mesh.get_face_count());
println!("\tMaterial Slot Count: {}", mesh.get_material_slot_count());
}
}
fn test_material(reader: bmap::BMFileReader) {
for mtl in reader.get_materials() {
println!("{}", mtl.get_name());
println!("\tDiffuse: {:?}", mtl.get_diffuse().to_const_rgba());
println!("\tAmbient: {:?}", mtl.get_ambient().to_const_rgba());
println!("\tSpecular: {:?}", mtl.get_specular().to_const_rgba());
println!("\tEmissive: {:?}", mtl.get_emissive().to_const_rgba());
println!("\tSpecular Power: {}", mtl.get_specular_power());
println!(
"\tTexture Border Color: {:?}",
mtl.get_texture_border_color().to_const_rgba()
);
println!("\tTexture Blend Mode: {}", mtl.get_texture_blend_mode());
println!("\tTexture Min Mode: {}", mtl.get_texture_min_mode());
println!("\tTexture Mag Mode: {}", mtl.get_texture_mag_mode());
println!("\tSource Blend: {}", mtl.get_source_blend());
println!("\tDest Blend: {}", mtl.get_dest_blend());
println!("\tFill Mode: {}", mtl.get_fill_mode());
println!("\tShade Mode: {}", mtl.get_shade_mode());
println!("\tAlpha Test Enabled: {}", mtl.get_alpha_test_enabled());
println!("\tAlpha Blend Enabled: {}", mtl.get_alpha_blend_enabled());
println!(
"\tPerspective Correction Enabled: {}",
mtl.get_perspective_correction_enabled()
);
println!("\tZ Write Enabled: {}", mtl.get_z_write_enabled());
println!("\tTwo Sided Enabled: {}", mtl.get_two_sided_enabled());
println!("\tAlpha Ref: {}", mtl.get_alpha_ref());
println!("\tAlpha Func: {}", mtl.get_alpha_func());
println!("\tZ Func: {}", mtl.get_z_func());
}
}
fn test_texture(reader: bmap::BMFileReader) {
for tex in reader.get_textures() {
println!("{}", tex.get_name());
println!("\tFile Name: {}", tex.get_file_name());
println!("\tSave Options: {}", tex.get_save_options());
println!("\tVideo Format: {}", tex.get_video_format());
}
}
fn test_target_light(reader: bmap::BMFileReader) {
for lit in reader.get_target_lights() {
println!("{}", lit.get_name());
println!("\tVisibility: {}", lit.get_visibility());
println!("\tMatrix: {:?}", lit.get_world_matrix().to_const());
println!("\tType: {}", lit.get_type());
println!("\tColor: {:?}", lit.get_color().to_const_rgba());
println!("\tConstant Attenuation: {}", lit.get_constant_attenuation());
println!("\tLinear Attenuation: {}", lit.get_linear_attenuation());
println!(
"\tQuadratic Attenuation: {}",
lit.get_quadratic_attenuation()
);
println!("\tRange: {}", lit.get_range());
println!("\tHot Spot: {}", lit.get_hot_spot());
println!("\tFalloff: {}", lit.get_falloff());
println!("\tFalloff Shape: {}", lit.get_falloff_shape());
}
}
fn test_target_camera(reader: bmap::BMFileReader) {
for cam in reader.get_target_cameras() {
println!("{}", cam.get_name());
println!("\tVisibility: {}", cam.get_visibility());
println!("\tMatrix: {:?}", cam.get_world_matrix().to_const());
println!("\tType: {}", cam.get_projection_type());
println!("\tOrthographic Zoom: {}", cam.get_orthographic_zoom());
println!("\tFront Plane: {}", cam.get_front_plane());
println!("\tBack Plane: {}", cam.get_back_plane());
println!("\tFov: {}", cam.get_fov());
let (width, height) = cam.get_aspect_ratio();
println!("\tAspect Ratio: {}:{}", width, height);
}
}
}
mod eq {
use super::bmap;
use std::collections::{HashSet, BTreeSet};
pub fn test(reader: bmap::BMFileReader) {
// Check requirements
assert!(
reader.get_3dobject_count() >= 2,
r#"Invalid file for test Eq.
We can not perform Eq test because the length of 3dObject is too short (must greater than 2). Please choose another file to perform."#
);
// Prepare variables
let all_3dobjects = reader.get_3dobjects().collect();
let first_3dobj = &all_3dobjects[0];
let second_3dobj = &all_3dobjects[1];
let all_3dobjects_again = reader.get_3dobjects().collect();
let first_3dobj_again = &all_3dobjects_again[0];
// Test HashSet
let mut test_hashset = HashSet::new();
assert!(test_hashset.insert(first_3dobj.clone()));
assert!(!test_hashset.insert(first_3dobj_again.clone()));
assert!(test_hashset.insert(second_3dobj));
// Test BTreeSet
let mut test_btreeset = BTreeSet::new();
assert!(test_btreeset.insert(first_3dobj.clone()));
assert!(!test_btreeset.insert(first_3dobj_again.clone()));
assert!(test_btreeset.insert(second_3dobj));
}
}
}