Skip to content

Commit

Permalink
Update specs for TilesetMerger
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Jul 12, 2024
1 parent e839c5d commit 4080cff
Showing 1 changed file with 145 additions and 20 deletions.
165 changes: 145 additions & 20 deletions specs/tools/tilesetProcessing/TilesetMergerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -68,30 +133,90 @@ 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
);
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);
});
Expand Down

0 comments on commit 4080cff

Please sign in to comment.