Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed May 19, 2023
1 parent 0b16196 commit fa78047
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Specs/Data/CesiumTerrainTileJson/ParentAvailability.tile.json
Original file line number Diff line number Diff line change
@@ -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
}
]
]
}
38 changes: 38 additions & 0 deletions Specs/Data/CesiumTerrainTileJson/ParentUrlAvailability.tile.json
Original file line number Diff line number Diff line change
@@ -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": "./"
}

76 changes: 76 additions & 0 deletions packages/engine/Specs/Core/CesiumTerrainProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";

Expand Down

0 comments on commit fa78047

Please sign in to comment.