From fa78047931bb73cbdad2f777705b7c2025eb9648 Mon Sep 17 00:00:00 2001 From: Gabby Getz Date: Fri, 19 May 2023 14:11:32 -0400 Subject: [PATCH] Add unit test --- .../ParentAvailability.tile.json | 36 +++++++++ .../ParentUrlAvailability.tile.json | 38 ++++++++++ .../Specs/Core/CesiumTerrainProviderSpec.js | 76 +++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 Specs/Data/CesiumTerrainTileJson/ParentAvailability.tile.json create mode 100644 Specs/Data/CesiumTerrainTileJson/ParentUrlAvailability.tile.json diff --git a/Specs/Data/CesiumTerrainTileJson/ParentAvailability.tile.json b/Specs/Data/CesiumTerrainTileJson/ParentAvailability.tile.json new file mode 100644 index 000000000000..83d7f33ce4fe --- /dev/null +++ b/Specs/Data/CesiumTerrainTileJson/ParentAvailability.tile.json @@ -0,0 +1,36 @@ +{ + "tilejson": "2.1.0", + "format" : "quantized-mesh-1.0", + "version" : "1.0.0", + "scheme" : "tms", + "attribution" : "This amazing data is courtesy The Amazing Data Source!", + "tiles" : [ + "{z}/{x}/{y}.terrain?v={version}" + ], + "extensions": [ + "watermask", + "metadata", + "octvertexnormals" + ], + "metadataAvailability": 10, + "minzoom": 0, + "maxzoom": 13, + "available" : [ + [ + { + "startX" : 0, + "startY" : 0, + "endX" : 1, + "endY" : 0 + } + ], + [ + { + "startX" : 0, + "startY" : 0, + "endX" : 3, + "endY" : 1 + } + ] + ] +} diff --git a/Specs/Data/CesiumTerrainTileJson/ParentUrlAvailability.tile.json b/Specs/Data/CesiumTerrainTileJson/ParentUrlAvailability.tile.json new file mode 100644 index 000000000000..3b1c3c0d3335 --- /dev/null +++ b/Specs/Data/CesiumTerrainTileJson/ParentUrlAvailability.tile.json @@ -0,0 +1,38 @@ +{ + "tilejson": "2.1.0", + "format" : "quantized-mesh-1.0", + "version" : "1.0.0", + "scheme" : "tms", + "attribution" : "This is a child tileset!", + "tiles" : [ + "{z}/{x}/{y}.terrain?v={version}" + ], + "extensions" : [ + "watermask", + "metadata", + "octvertexnormals" + ], + "metadataAvailability": 10, + "minzoom": 0, + "maxzoom": 13, + "available" : [ + [ + { + "startX" : 0, + "startY" : 0, + "endX" : 1, + "endY" : 0 + } + ], + [ + { + "startX" : 0, + "startY" : 0, + "endX" : 2, + "endY" : 1 + } + ] + ], + "parentUrl": "./" +} + diff --git a/packages/engine/Specs/Core/CesiumTerrainProviderSpec.js b/packages/engine/Specs/Core/CesiumTerrainProviderSpec.js index c4d6a6c5a29d..822547b1b8a2 100644 --- a/packages/engine/Specs/Core/CesiumTerrainProviderSpec.js +++ b/packages/engine/Specs/Core/CesiumTerrainProviderSpec.js @@ -133,6 +133,45 @@ describe("Core/CesiumTerrainProvider", function () { ); } + function returnParentUrlTileJsonWithMetadataAvailability() { + const paths = [ + "Data/CesiumTerrainTileJson/ParentUrlAvailability.tile.json", + "Data/CesiumTerrainTileJson/ParentAvailability.tile.json", + ]; + let i = 0; + const oldLoad = Resource._Implementations.loadWithXhr; + Resource._Implementations.loadWithXhr = function ( + url, + responseType, + method, + data, + headers, + deferred, + overrideMimeType + ) { + if (url.indexOf("layer.json") >= 0) { + Resource._DefaultImplementations.loadWithXhr( + paths[i++], + responseType, + method, + data, + headers, + deferred + ); + } else { + return oldLoad( + url, + responseType, + method, + data, + headers, + deferred, + overrideMimeType + ); + } + }; + } + async function waitForTile(level, x, y, requestNormals, requestWaterMask, f) { const terrainProvider = await CesiumTerrainProvider.fromUrl("made/up/url", { requestVertexNormals: requestNormals, @@ -899,6 +938,43 @@ describe("Core/CesiumTerrainProvider", function () { expect(terrainProvider.availability.isTileAvailable(1, 0, 0)).toBe(true); }); + it("provides QuantizedMeshTerrainData with multiple layers and with Metadata availability ", async function () { + Resource._Implementations.loadWithXhr = function ( + url, + responseType, + method, + data, + headers, + deferred, + overrideMimeType + ) { + Resource._DefaultImplementations.loadWithXhr( + "Data/CesiumTerrainTileJson/tile.metadataavailability.terrain", + responseType, + method, + data, + headers, + deferred + ); + }; + + returnParentUrlTileJsonWithMetadataAvailability(); + + const terrainProvider = await CesiumTerrainProvider.fromUrl( + "made/up/url" + ); + + expect(terrainProvider.hasMetadata).toBe(true); + const layers = terrainProvider._layers; + expect(layers.length).toBe(2); + + expect(terrainProvider.availability.isTileAvailable(1, 0, 0)).toBe(false); + + const loadedData = await terrainProvider.requestTileGeometry(0, 0, 1); + expect(loadedData).toBeInstanceOf(QuantizedMeshTerrainData); + expect(terrainProvider.availability.isTileAvailable(1, 0, 0)).toBe(true); + }); + it("returns undefined if too many requests are already in progress", async function () { const baseUrl = "made/up/url";