Skip to content

Commit

Permalink
Add tests for Loader error messages, log quantized mesh errors and wa…
Browse files Browse the repository at this point in the history
…rnings
  • Loading branch information
azrogers committed Jan 23, 2025
1 parent ff1f6b9 commit 7e5019a
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 17 deletions.
18 changes: 17 additions & 1 deletion Cesium3DTilesSelection/src/LayerJsonTerrainLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ Future<QuantizedMeshLoadResult> requestTileContent(
(pResponse->statusCode() < 200 || pResponse->statusCode() >= 300)) {
QuantizedMeshLoadResult result;
result.errors.emplaceError(fmt::format(
"Receive status code {} for tile content {}",
"Received status code {} for tile content {}",
pResponse->statusCode(),
pRequest->url()));
result.pRequest = std::move(pRequest);
Expand Down Expand Up @@ -900,11 +900,19 @@ LayerJsonTerrainLoader::loadTileContent(const TileLoadInput& loadInput) {
.thenInMainThread([this,
asyncSystem,
pAssetAccessor,
pLogger,
ellipsoid,
&currentLayer,
&tile,
shouldCurrLayerLoadAvailability](
QuantizedMeshLoadResult&& loadResult) mutable {
loadResult.errors.logWarning(
pLogger,
"Warnings loading quantized mesh terrain");
loadResult.errors.logError(
pLogger,
"Errors loading quantized mesh terrain");

if (shouldCurrLayerLoadAvailability) {
const QuadtreeTileID& tileID =
std::get<QuadtreeTileID>(tile.getTileID());
Expand Down Expand Up @@ -947,11 +955,19 @@ LayerJsonTerrainLoader::loadTileContent(const TileLoadInput& loadInput) {
return std::move(futureQuantizedMesh)
.thenImmediately(
[pAssetAccessor,
pLogger,
doesTileHaveUpsampledChild,
projection = this->_projection,
tileTransform = tile.getTransform(),
tileBoundingVolume = tile.getBoundingVolume(),
ellipsoid](QuantizedMeshLoadResult&& loadResult) mutable {
loadResult.errors.logWarning(
pLogger,
"Warnings loading quantized mesh terrain");
loadResult.errors.logError(
pLogger,
"Errors loading quantized mesh terrain");

// if this tile has one of the children needs to be upsampled, we
// will need to generate its raster overlay UVs in the worker thread
// based on the projection of the loader since the upsampler needs
Expand Down
65 changes: 56 additions & 9 deletions Cesium3DTilesSelection/test/TestLayerJsonTerrainLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <doctest/doctest.h>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/ringbuffer_sink.h>

#include <cstdint>
#include <filesystem>
Expand All @@ -50,18 +51,26 @@ std::filesystem::path testDataPath = Cesium3DTilesSelection_TEST_DATA_DIR;

std::shared_ptr<SimpleAssetRequest>
createMockAssetRequest(const std::filesystem::path& requestContentPath) {
auto pMockResponse = std::make_unique<SimpleAssetResponse>(
static_cast<uint16_t>(200),
"doesn't matter",
CesiumAsync::HttpHeaders{},
readFile(requestContentPath));
auto pMockRequest = std::make_shared<SimpleAssetRequest>(
std::unique_ptr<SimpleAssetResponse> pMockCompletedResponse;
if (std::filesystem::exists(requestContentPath)) {
pMockCompletedResponse = std::make_unique<SimpleAssetResponse>(
static_cast<uint16_t>(200),
"doesn't matter",
CesiumAsync::HttpHeaders{},
readFile(requestContentPath));
} else {
pMockCompletedResponse = std::make_unique<SimpleAssetResponse>(
static_cast<uint16_t>(404),
"doesn't matter",
CesiumAsync::HttpHeaders{},
std::vector<std::byte>{});
}
auto pMockCompletedRequest = std::make_shared<SimpleAssetRequest>(
"GET",
requestContentPath.filename().string(),
CesiumAsync::HttpHeaders{},
std::move(pMockResponse));

return pMockRequest;
std::move(pMockCompletedResponse));
return pMockCompletedRequest;
}

Future<TileLoadResult> loadTile(
Expand Down Expand Up @@ -704,6 +713,44 @@ TEST_CASE("Test load layer json tile content") {
CHECK(tileLoadResult.state == TileLoadResultState::Success);
}
}

SUBCASE("Should error when fetching non-existent .terrain tiles") {
auto pLog = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(3);
spdlog::default_logger()->sinks().emplace_back(pLog);

// create loader
std::vector<LayerJsonTerrainLoader::Layer> layers;
layers.emplace_back(
"layer.json",
"1.0.0",
std::vector<std::string>{"{level}.{x}.{y}/{version}.terrain"},
std::move(contentAvailability),
maxZoom,
10);

LayerJsonTerrainLoader loader{tilingScheme, projection, std::move(layers)};

// mock tile content request
pMockedAssetAccessor->mockCompletedRequests.insert(
{"0.0.0/1.0.0.terrain",
createMockAssetRequest(
testDataPath / "CesiumTerrainTileJson" /
"nonexistent.terrain")});

// check the load result
auto tileLoadResultFuture = loadTile(
QuadtreeTileID(0, 0, 0),
loader,
asyncSystem,
pMockedAssetAccessor);
auto tileLoadResult = tileLoadResultFuture.wait();
CHECK(tileLoadResult.state == TileLoadResultState::Failed);

std::vector<std::string> logMessages = pLog->last_formatted();
REQUIRE(logMessages.size() == 1);
REQUIRE(logMessages.back().ends_with(
"Received status code 404 for tile content nonexistent.terrain\r\n"));
}
}

TEST_CASE("Test creating tile children for layer json") {
Expand Down
50 changes: 44 additions & 6 deletions Cesium3DTilesSelection/test/TestTilesetJsonLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <doctest/doctest.h>
#include <glm/ext/matrix_double3x3.hpp>
#include <glm/ext/matrix_double4x4.hpp>
#include <spdlog/sinks/ringbuffer_sink.h>
#include <spdlog/spdlog.h>

#include <array>
Expand Down Expand Up @@ -56,14 +57,23 @@ TileLoadResult loadTileContent(
const std::filesystem::path& tilePath,
TilesetContentLoader& loader,
Tile& tile) {
auto pMockCompletedResponse = std::make_unique<SimpleAssetResponse>(
static_cast<uint16_t>(200),
"doesn't matter",
CesiumAsync::HttpHeaders{},
readFile(tilePath));
std::unique_ptr<SimpleAssetResponse> pMockCompletedResponse;
if (std::filesystem::exists(tilePath)) {
pMockCompletedResponse = std::make_unique<SimpleAssetResponse>(
static_cast<uint16_t>(200),
"doesn't matter",
CesiumAsync::HttpHeaders{},
readFile(tilePath));
} else {
pMockCompletedResponse = std::make_unique<SimpleAssetResponse>(
static_cast<uint16_t>(404),
"doesn't matter",
CesiumAsync::HttpHeaders{},
std::vector<std::byte>{});
}
auto pMockCompletedRequest = std::make_shared<SimpleAssetRequest>(
"GET",
"doesn't matter",
tilePath.filename().string(),
CesiumAsync::HttpHeaders{},
std::move(pMockCompletedResponse));

Expand Down Expand Up @@ -604,6 +614,34 @@ TEST_CASE("Test loading individual tile of tileset json") {
CHECK(pLoader->getSubtreeLevels() == 2);
CHECK(pLoader->getAvailableLevels() == 2);
}

SUBCASE("Tile with missing content") {
auto pLog = std::make_shared<spdlog::sinks::ringbuffer_sink_mt>(3);
spdlog::default_logger()->sinks().emplace_back(pLog);

auto loaderResult = createTilesetJsonLoader(
testDataPath / "MultipleKindsOfTilesets" /
"ErrorMissingContentTileset.json");
REQUIRE(loaderResult.pRootTile);
REQUIRE(loaderResult.pRootTile->getChildren().size() == 1);

auto pRootTile = &loaderResult.pRootTile->getChildren()[0];

const auto& tileID = std::get<std::string>(pRootTile->getTileID());
CHECK(tileID == "nonexistent.b3dm");

// check tile content
auto tileLoadResult = loadTileContent(
testDataPath / "MultipleKindsOfTilesets" / tileID,
*loaderResult.pLoader,
*pRootTile);
CHECK(tileLoadResult.state == TileLoadResultState::Failed);

std::vector<std::string> logMessages = pLog->last_formatted();
REQUIRE(logMessages.size() == 1);
REQUIRE(logMessages.back().ends_with(
"Received status code 404 for tile content nonexistent.b3dm\r\n"));
}
}
Cesium3DTilesSelection::TilesetContentLoaderResult<TilesetJsonLoader>
Cesium3DTilesSelection::createTilesetJsonLoader(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"asset": {
"version": "1.0",
"tilesetVersion": "1.2.3"
},
"extras": {
"name": "Sample Tileset"
},
"geometricError": 240,
"root": {
"boundingVolume": {
"region": [
-1.3197209591796106,
0.6988424218,
-1.3196390408203893,
0.6989055782,
0,
88
]
},
"geometricError": 70,
"refine": "REPLACE",
"content": {
"uri": "nonexistent.b3dm",
"boundingVolume": {
"region": [
-1.3197004795898053,
0.6988582109,
-1.3196595204101946,
0.6988897891,
0,
88
]
}
}
}
}

2 changes: 1 addition & 1 deletion CesiumRasterOverlays/test/ExamplesRasterOverlays.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <CesiumRasterOverlays/RasterOverlay.h>
#include <CesiumRasterOverlays/UrlTemplateRasterOverlay.h>

#include <catch2/catch_test_macros.hpp>
#include <doctest/doctest.h>

using namespace CesiumRasterOverlays;

Expand Down

0 comments on commit 7e5019a

Please sign in to comment.