From 4080cff31640a11d82a78b09b6f06ce8486a1261 Mon Sep 17 00:00:00 2001 From: Marco Hutter Date: Fri, 12 Jul 2024 14:19:03 +0200 Subject: [PATCH] Update specs for TilesetMerger --- .../tilesetProcessing/TilesetMergerSpec.ts | 165 +++++++++++++++--- 1 file changed, 145 insertions(+), 20 deletions(-) diff --git a/specs/tools/tilesetProcessing/TilesetMergerSpec.ts b/specs/tools/tilesetProcessing/TilesetMergerSpec.ts index bd7467e..fb1f459 100644 --- a/specs/tools/tilesetProcessing/TilesetMergerSpec.ts +++ b/specs/tools/tilesetProcessing/TilesetMergerSpec.ts @@ -7,31 +7,39 @@ import { TilesetOperations } from "../../../src/tools"; import { SpecHelpers } from "../../SpecHelpers"; const SPECS_DATA_BASE_DIRECTORY = SpecHelpers.getSpecsDataBaseDirectory(); - -const basicInputs = [ - SPECS_DATA_BASE_DIRECTORY + "/mergeTilesets/basicMerge/TilesetA", - SPECS_DATA_BASE_DIRECTORY + "/mergeTilesets/basicMerge/sub/TilesetA", -]; -const basicOutput = - SPECS_DATA_BASE_DIRECTORY + "/output/mergeTilesets/basicMerge"; const overwrite = true; describe("TilesetMerger", function () { afterEach(function () { SpecHelpers.forceDeleteDirectory( - SPECS_DATA_BASE_DIRECTORY + "/output/mergeTilesets" + Paths.join(SPECS_DATA_BASE_DIRECTORY, "output/mergeTilesets") ); }); + it("merges tilesets from directories into a single tileset directory", async function () { + const inputDirectories = [ + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/TilesetA" + ), + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/sub/TilesetA" + ), + ]; + const outputDirectory = Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "output/mergeTilesets/basicMerge" + ); + const outputFile = Paths.join(outputDirectory, "tileset.json"); - it("merges tilesets into a single tileset", async function () { - await TilesetOperations.merge(basicInputs, basicOutput, overwrite); + await TilesetOperations.merge(inputDirectories, outputDirectory, overwrite); // Ensure that the output directory contains the expected files: // All files of the input, disambiguated for the same base name // (i.e. "TilesetA" and "TilesetA-0" - this is not specified, // but has to be assumed here) const actualRelativeFiles = - SpecHelpers.collectRelativeFileNames(basicOutput); + SpecHelpers.collectRelativeFileNames(outputDirectory); actualRelativeFiles.sort(); const expectedRelativeFiles = [ "TilesetA-0/ll.b3dm", @@ -52,9 +60,66 @@ describe("TilesetMerger", function () { // Ensure that the single 'tileset.json' contains the // proper content URIs for the external tilesets: - const tilesetJsonBuffer = fs.readFileSync( - Paths.join(basicOutput, "tileset.json") + const tilesetJsonBuffer = fs.readFileSync(outputFile); + const tileset = JSON.parse(tilesetJsonBuffer.toString()); + const actualContentUris = await SpecHelpers.collectExplicitContentUris( + tileset.root + ); + actualContentUris.sort(); + + const expectedContentUris = [ + "TilesetA-0/tileset.json", + "TilesetA/tileset.json", + ]; + expect(actualContentUris).toEqual(expectedContentUris); + }); + + it("merges tilesets from files into a single tileset file", async function () { + const inputFiles = [ + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/TilesetA/tileset.json" + ), + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/sub/TilesetA/tileset.json" + ), + ]; + const outputDirectory = Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "output/mergeTilesets/basicMerge" ); + const outputFile = Paths.join(outputDirectory, "tileset.json"); + + await TilesetOperations.merge(inputFiles, outputFile, overwrite); + + // Ensure that the output directory contains the expected files: + // All files of the input, disambiguated for the same base name + // (i.e. "TilesetA" and "TilesetA-0" - this is not specified, + // but has to be assumed here) + const actualRelativeFiles = + SpecHelpers.collectRelativeFileNames(outputDirectory); + actualRelativeFiles.sort(); + const expectedRelativeFiles = [ + "TilesetA-0/ll.b3dm", + "TilesetA-0/lr.b3dm", + "TilesetA-0/parent.b3dm", + "TilesetA-0/tileset.json", + "TilesetA-0/ul.b3dm", + "TilesetA-0/ur.b3dm", + "TilesetA/ll.b3dm", + "TilesetA/lr.b3dm", + "TilesetA/parent.b3dm", + "TilesetA/tileset.json", + "TilesetA/ul.b3dm", + "TilesetA/ur.b3dm", + "tileset.json", + ]; + expect(actualRelativeFiles).toEqual(expectedRelativeFiles); + + // Ensure that the single 'tileset.json' contains the + // proper content URIs for the external tilesets: + const tilesetJsonBuffer = fs.readFileSync(outputFile); const tileset = JSON.parse(tilesetJsonBuffer.toString()); const actualContentUris = await SpecHelpers.collectExplicitContentUris( tileset.root @@ -68,21 +133,81 @@ describe("TilesetMerger", function () { expect(actualContentUris).toEqual(expectedContentUris); }); - it("merges tilesets into a single tileset for mergeJson", async function () { - await TilesetOperations.mergeJson(basicInputs, basicOutput, overwrite); + it("merges tilesets from directories into a single tileset in a directory for mergeJson", async function () { + const inputDirectories = [ + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/TilesetA" + ), + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/sub/TilesetA" + ), + ]; + const outputDirectory = Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "output/mergeTilesets/basicMerge" + ); + const outputFile = Paths.join(outputDirectory, "tileset.json"); + + await TilesetOperations.mergeJson( + inputDirectories, + outputDirectory, + overwrite + ); // Ensure that the output directory contains the expected files: const actualRelativeFiles = - SpecHelpers.collectRelativeFileNames(basicOutput); + SpecHelpers.collectRelativeFileNames(outputDirectory); actualRelativeFiles.sort(); const expectedRelativeFiles = ["tileset.json"]; expect(actualRelativeFiles).toEqual(expectedRelativeFiles); // Ensure that the single 'tileset.json' contains the // proper content URIs for the external tilesets: - const tilesetJsonBuffer = fs.readFileSync( - Paths.join(basicOutput, "tileset.json") + const tilesetJsonBuffer = fs.readFileSync(outputFile); + const tileset = JSON.parse(tilesetJsonBuffer.toString()); + const actualContentUris = await SpecHelpers.collectExplicitContentUris( + tileset.root ); + actualContentUris.sort(); + + const expectedContentUris = [ + "../../../mergeTilesets/basicMerge/TilesetA/tileset.json", + "../../../mergeTilesets/basicMerge/sub/TilesetA/tileset.json", + ]; + expect(actualContentUris).toEqual(expectedContentUris); + }); + + it("merges tilesets from files into a single tileset file for mergeJson", async function () { + const inputFiles = [ + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/TilesetA/tileset.json" + ), + Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "mergeTilesets/basicMerge/sub/TilesetA/tileset.json" + ), + ]; + const outputDirectory = Paths.join( + SPECS_DATA_BASE_DIRECTORY, + "output/mergeTilesets/basicMerge" + ); + const outputFile = Paths.join(outputDirectory, "tileset.json"); + + await TilesetOperations.mergeJson(inputFiles, outputFile, overwrite); + + // Ensure that the output directory contains the expected files: + const actualRelativeFiles = + SpecHelpers.collectRelativeFileNames(outputDirectory); + actualRelativeFiles.sort(); + const expectedRelativeFiles = ["tileset.json"]; + expect(actualRelativeFiles).toEqual(expectedRelativeFiles); + + // Ensure that the single 'tileset.json' contains the + // proper content URIs for the external tilesets: + const tilesetJsonBuffer = fs.readFileSync(outputFile); const tileset = JSON.parse(tilesetJsonBuffer.toString()); const actualContentUris = await SpecHelpers.collectExplicitContentUris( tileset.root @@ -90,8 +215,8 @@ describe("TilesetMerger", function () { actualContentUris.sort(); const expectedContentUris = [ - "specs/data/mergeTilesets/basicMerge/TilesetA/tileset.json", - "specs/data/mergeTilesets/basicMerge/sub/TilesetA/tileset.json", + "../../../mergeTilesets/basicMerge/TilesetA/tileset.json", + "../../../mergeTilesets/basicMerge/sub/TilesetA/tileset.json", ]; expect(actualContentUris).toEqual(expectedContentUris); });