Skip to content

Commit

Permalink
Merge pull request #1 from MIERUNE/add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
ciscorn authored Mar 15, 2024
2 parents ab09179 + 853fe85 commit 5ec9c25
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/models/tileset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,33 @@ pub struct StatisticsProperty {
mod tests {
use super::*;

#[test]
fn test_default() {
let tileset = Tileset::default();
assert_eq!(tileset.asset.version, "1.1".to_string());
}

#[test]
fn test_bounding_volumes() {
// box
let bv = BoundingVolume::new_box([0., 0., 0., 1., 1., 1., 2., 2., 2., 3., 3., 3.]);
assert!(bv.box_.is_some());
assert!(bv.sphere.is_none());
assert!(bv.region.is_none());

// sphere
let bv = BoundingVolume::new_sphere([0., 0., 0., 0.]);
assert!(bv.box_.is_none());
assert!(bv.sphere.is_some());
assert!(bv.region.is_none());

// region
let bv = BoundingVolume::new_region([0., 0., 1., 1., 2., 2.]);
assert!(bv.box_.is_none());
assert!(bv.sphere.is_none());
assert!(bv.region.is_some());
}

#[test]
fn test_tile() {
let tile = Tile::default();
Expand Down
60 changes: 60 additions & 0 deletions tests/load_gltf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use serde::{Deserialize, Serialize};

use cesiumtiles::gltf_extensions::gltf;
use cesiumtiles::gltf_extensions::mesh;

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Gltf {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub meshes: Vec<Mesh>,

#[serde(skip_serializing_if = "Option::is_none")]
pub extensions: Option<GltfExtension>,
}

#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone)]
#[serde[rename_all = "camelCase"]]
pub struct Mesh {
pub primitives: Vec<MeshPrimitive>,
}

#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone)]
#[serde[rename_all = "camelCase"]]
pub struct MeshPrimitive {
#[serde(skip_serializing_if = "Option::is_none")]
pub extensions: Option<MeshPrimitiveExtension>,
}

#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Clone)]
pub struct MeshPrimitiveExtension {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "EXT_mesh_features")]
pub ext_mesh_features: Option<mesh::ext_mesh_features::ExtMeshFeatures>,

#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "EXT_structural_metadata")]
pub ext_structural_metadata: Option<mesh::ext_structural_metadata::ExtStructuralMetadata>,
}

#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
pub struct GltfExtension {
#[serde(rename = "EXT_structural_metadata")]
#[serde(skip_serializing_if = "Option::is_none")]
pub ext_structural_metadata: Option<gltf::ext_structural_metadata::ExtStructuralMetadata>,
}

#[test]
fn load_gltf_json() {
for path in glob::glob("./tests/samples/**/*.gltf").unwrap() {
let path = path.unwrap();
println!("loading {:?}", path);
let src = std::fs::read_to_string(path).unwrap();
let a: Gltf = serde_json::from_str(&src).unwrap();
let _ = format!("{:?}", a);

// 'null' should not appear in output
let a = serde_json::to_string(&a).unwrap();
assert!(!a.contains("null"));
}
}

0 comments on commit 5ec9c25

Please sign in to comment.