Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Mar 15, 2024
1 parent 297e0b1 commit 853fe85
Show file tree
Hide file tree
Showing 107 changed files with 2,161 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"));
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
103 changes: 103 additions & 0 deletions tests/samples/gltf/CESIUM_primitive_outline/BoxPrimitiveOutline.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"extensionsUsed" : [ "CESIUM_primitive_outline" ],
"accessors" : [ {
"bufferView" : 0,
"byteOffset" : 0,
"componentType" : 5125,
"count" : 36,
"type" : "SCALAR",
"max" : [ 23 ],
"min" : [ 0 ]
}, {
"bufferView" : 1,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 24,
"type" : "VEC3",
"max" : [ 1.0, 1.0, 1.0 ],
"min" : [ 0.0, 0.0, 0.0 ]
}, {
"bufferView" : 2,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 24,
"type" : "VEC3",
"max" : [ 1.0, 1.0, 1.0 ],
"min" : [ -1.0, -1.0, -1.0 ]
}, {
"bufferView" : 3,
"byteOffset" : 0,
"componentType" : 5122,
"count" : 24,
"type" : "SCALAR",
"max" : [ 15 ],
"min" : [ 0 ]
} ],
"asset" : {
"generator" : "JglTF from https://github.com/javagl/JglTF",
"version" : "2.0"
},
"buffers" : [ {
"uri" : "data:application/gltf-buffer;base64,AAAAAAIAAAABAAAAAAAAAAMAAAACAAAABAAAAAYAAAAFAAAABAAAAAcAAAAGAAAACAAAAAoAAAAJAAAACAAAAAsAAAAKAAAADAAAAA4AAAANAAAADAAAAA8AAAAOAAAAEAAAABIAAAARAAAAEAAAABMAAAASAAAAFAAAABYAAAAVAAAAFAAAABcAAAAWAAAAAAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAgD8AAAAAAAAAAAAAgD8AAAAAAACAPwAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAgD8AAIA/AACAPwAAgD8AAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAIA/AACAPwAAgD8AAIA/AACAPwAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAIA/AAAAAAAAgD8AAAAAAACAPwAAgD8AAAAAAACAPwAAgD8AAIA/AAAAAAAAgD8AAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAIA/AACAPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAA",
"byteLength" : 720
}, {
"uri" : "data:application/gltf-buffer;base64,AAABAAEAAgACAAMAAwAAAAQABQAFAAYABgAHAAcABAAMAA0ACAAJAAsACgAOAA8A",
"byteLength" : 48
} ],
"bufferViews" : [ {
"name" : "indices",
"buffer" : 0,
"byteOffset" : 0,
"byteLength" : 144,
"target" : 34963
}, {
"name" : "attribute",
"buffer" : 0,
"byteOffset" : 144,
"byteLength" : 288,
"target" : 34962
}, {
"name" : "attribute",
"buffer" : 0,
"byteOffset" : 432,
"byteLength" : 288,
"target" : 34962
}, {
"name" : "outlineIndices",
"buffer" : 1,
"byteOffset" : 0,
"byteLength" : 48
} ],
"materials" : [ {
"pbrMetallicRoughness" : {
"baseColorFactor" : [ 0.0, 1.0, 0.0, 1.0 ],
"metallicFactor" : 1.0,
"roughnessFactor" : 1.0
},
"alphaMode" : "OPAQUE",
"doubleSided" : true
} ],
"meshes" : [ {
"primitives" : [ {
"extensions" : {
"CESIUM_primitive_outline" : {
"indices" : 3
}
},
"attributes" : {
"POSITION" : 1,
"NORMAL" : 2
},
"indices" : 0,
"material" : 0,
"mode" : 4
} ]
} ],
"nodes" : [ {
"mesh" : 0
} ],
"scene" : 0,
"scenes" : [ {
"nodes" : [ 0 ]
} ]
}
102 changes: 102 additions & 0 deletions tests/samples/gltf/EXT_mesh_features/FeatureIdAttribute.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"extensionsUsed" : [ "EXT_mesh_features" ],
"accessors" : [ {
"bufferView" : 0,
"byteOffset" : 0,
"componentType" : 5123,
"count" : 24,
"type" : "SCALAR",
"max" : [ 15 ],
"min" : [ 0 ]
}, {
"bufferView" : 1,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 16,
"type" : "VEC3",
"max" : [ 1.0, 1.0, 0.0 ],
"min" : [ 0.0, 0.0, 0.0 ]
}, {
"bufferView" : 2,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 16,
"type" : "VEC3",
"max" : [ 0.0, 0.0, 1.0 ],
"min" : [ 0.0, 0.0, 1.0 ]
}, {
"bufferView" : 3,
"byteOffset" : 0,
"componentType" : 5121,
"count" : 16,
"type" : "SCALAR",
"max" : [ 3 ],
"min" : [ 0 ]
} ],
"asset" : {
"generator" : "JglTF from https://github.com/javagl/JglTF",
"version" : "2.0"
},
"buffers" : [ {
"uri" : "data:application/gltf-buffer;base64,AAABAAIAAQADAAIABAAFAAYABQAHAAYACAAJAAoACQALAAoADAANAA4ADQAPAA4AAAAAAAAAAAAAAAAAZmbmPgAAAAAAAAAAAAAAAGZm5j4AAAAAZmbmPmZm5j4AAAAAzcwMPwAAAAAAAAAAAACAPwAAAAAAAAAAzcwMP2Zm5j4AAAAAAACAP2Zm5j4AAAAAAAAAAM3MDD8AAAAAZmbmPs3MDD8AAAAAAAAAAAAAgD8AAAAAZmbmPgAAgD8AAAAAzcwMP83MDD8AAAAAAACAP83MDD8AAAAAzcwMPwAAgD8AAAAAAACAPwAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAQAAAAEAAAACAAAAAgAAAAIAAAACAAAAAwAAAAMAAAADAAAAAwAAAA==",
"byteLength" : 496
} ],
"bufferViews" : [ {
"buffer" : 0,
"byteOffset" : 0,
"byteLength" : 48,
"target" : 34963
}, {
"buffer" : 0,
"byteOffset" : 48,
"byteLength" : 192,
"target" : 34962
}, {
"buffer" : 0,
"byteOffset" : 240,
"byteLength" : 192,
"target" : 34962
}, {
"buffer" : 0,
"byteOffset" : 432,
"byteLength" : 64,
"byteStride" : 4,
"target" : 34962
} ],
"materials" : [ {
"pbrMetallicRoughness" : {
"baseColorFactor" : [ 0.5, 1.0, 0.5, 1.0 ],
"metallicFactor" : 0.0,
"roughnessFactor" : 1.0
},
"alphaMode" : "OPAQUE",
"doubleSided" : true
} ],
"meshes" : [ {
"primitives" : [ {
"extensions" : {
"EXT_mesh_features" : {
"featureIds" : [ {
"featureCount" : 4,
"attribute" : 0
} ]
}
},
"attributes" : {
"POSITION" : 1,
"NORMAL" : 2,
"_FEATURE_ID_0" : 3
},
"indices" : 0,
"material" : 0,
"mode" : 4
} ]
} ],
"nodes" : [ {
"mesh" : 0
} ],
"scene" : 0,
"scenes" : [ {
"nodes" : [ 0 ]
} ]
}
Loading

0 comments on commit 853fe85

Please sign in to comment.