-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MIERUNE/add-tests
Add tests
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |