Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
153 lines
7.7 KiB
JavaScript
153 lines
7.7 KiB
JavaScript
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { pathToFileURL } = require("url");
|
|
|
|
const buildDirectory = path.resolve(process.argv[2] || "build-web/configure/bin");
|
|
|
|
async function main()
|
|
{
|
|
globalThis.__dirname = `${buildDirectory}${path.sep}`;
|
|
globalThis.require = require;
|
|
const probeModule = await import(pathToFileURL(path.join(buildDirectory, "FreeCADWebDocumentProbe.js")).href);
|
|
const probe = await probeModule.default({
|
|
wasmBinary: fs.readFileSync(path.join(buildDirectory, "FreeCADWebDocumentProbe.wasm")),
|
|
});
|
|
const run = probe.ccall("fc_web_document_create_and_enumerate", "number", [], []);
|
|
const result = {
|
|
run,
|
|
error: probe.ccall("fc_web_document_last_error", "string", [], []),
|
|
documentName: probe.ccall("fc_web_document_name", "string", [], []),
|
|
objectName: probe.ccall("fc_web_document_object_name", "string", [], []),
|
|
objectType: probe.ccall("fc_web_document_object_type", "string", [], []),
|
|
documentCount: probe.ccall("fc_web_document_count", "number", [], []),
|
|
objectCount: probe.ccall("fc_web_document_object_count", "number", [], []),
|
|
};
|
|
if (result.run !== 1
|
|
|| result.documentCount !== 1
|
|
|| result.objectCount !== 1
|
|
|| result.objectName !== "Box"
|
|
|| result.objectType !== "Part::Box"
|
|
|| !/^WebDocument\d*$/.test(result.documentName)
|
|
|| result.error !== "") {
|
|
throw new Error(JSON.stringify(result));
|
|
}
|
|
const recomputeRun = probe.ccall("fc_web_document_recompute_box", "number", [], []);
|
|
const recompute = {
|
|
run: recomputeRun,
|
|
error: probe.ccall("fc_web_document_last_error", "string", [], []),
|
|
count: probe.ccall("fc_web_document_recompute_count", "number", [], []),
|
|
volume: probe.ccall("fc_web_document_recompute_volume", "number", [], []),
|
|
hasError: probe.ccall("fc_web_document_recompute_has_error", "number", [], []),
|
|
};
|
|
if (recompute.run !== 1
|
|
|| recompute.count !== 1
|
|
|| recompute.hasError !== 0
|
|
|| Math.abs(recompute.volume - 24) > 1e-9
|
|
|| recompute.error !== "") {
|
|
throw new Error(JSON.stringify({ result, recompute }));
|
|
}
|
|
const recoveryRun = probe.ccall("fc_web_document_invalid_dimension_recovery", "number", [], []);
|
|
const recovery = {
|
|
run: recoveryRun,
|
|
error: probe.ccall("fc_web_document_last_error", "string", [], []),
|
|
invalidError: probe.ccall("fc_web_document_invalid_dimension_error", "string", [], []),
|
|
invalidVolume: probe.ccall("fc_web_document_invalid_shape_volume", "number", [], []),
|
|
recoveredVolume: probe.ccall("fc_web_document_recovered_shape_volume", "number", [], []),
|
|
hasError: probe.ccall("fc_web_document_recovery_has_error", "number", [], []),
|
|
};
|
|
if (recovery.run !== 1
|
|
|| recovery.invalidError !== "Length of box too small"
|
|
|| Math.abs(recovery.invalidVolume - 24) > 1e-9
|
|
|| Math.abs(recovery.recoveredVolume - 24) > 1e-9
|
|
|| recovery.hasError !== 0
|
|
|| recovery.error !== "") {
|
|
throw new Error(JSON.stringify({ result, recompute, recovery }));
|
|
}
|
|
const saveRun = probe.ccall("fc_web_document_save_fcstd", "number", [], []);
|
|
const save = {
|
|
run: saveRun,
|
|
error: probe.ccall("fc_web_document_last_error", "string", [], []),
|
|
path: probe.ccall("fc_web_document_fcstd_path", "string", [], []),
|
|
size: probe.ccall("fc_web_document_fcstd_size", "number", [], []),
|
|
volume: probe.ccall("fc_web_document_fcstd_volume", "number", [], []),
|
|
};
|
|
if (save.run !== 1
|
|
|| save.path !== "/tmp/WebBox.FCStd"
|
|
|| save.size <= 22
|
|
|| Math.abs(save.volume - 24) > 1e-9
|
|
|| save.error !== "") {
|
|
throw new Error(JSON.stringify({ result, recompute, recovery, save }));
|
|
}
|
|
fs.writeFileSync(
|
|
path.join(buildDirectory, "WebBox.FCStd"),
|
|
probe.FS.readFile(save.path),
|
|
);
|
|
const openRun = probe.ccall("fc_web_document_open_fcstd", "number", [], []);
|
|
const opened = {
|
|
run: openRun,
|
|
error: probe.ccall("fc_web_document_last_error", "string", [], []),
|
|
documentCount: probe.ccall("fc_web_document_opened_document_count", "number", [], []),
|
|
objectCount: probe.ccall("fc_web_document_opened_object_count", "number", [], []),
|
|
objectType: probe.ccall("fc_web_document_opened_object_type", "string", [], []),
|
|
length: probe.ccall("fc_web_document_opened_length", "number", [], []),
|
|
width: probe.ccall("fc_web_document_opened_width", "number", [], []),
|
|
height: probe.ccall("fc_web_document_opened_height", "number", [], []),
|
|
volume: probe.ccall("fc_web_document_opened_volume", "number", [], []),
|
|
};
|
|
if (opened.run !== 1
|
|
|| opened.documentCount !== 1
|
|
|| opened.objectCount !== 1
|
|
|| opened.objectType !== "Part::Box"
|
|
|| Math.abs(opened.length - 2) > 1e-9
|
|
|| Math.abs(opened.width - 3) > 1e-9
|
|
|| Math.abs(opened.height - 4) > 1e-9
|
|
|| Math.abs(opened.volume - 24) > 1e-9
|
|
|| opened.error !== "") {
|
|
throw new Error(JSON.stringify({ result, recompute, recovery, save, opened }));
|
|
}
|
|
const transactionRun = probe.ccall("fc_web_document_commit_resize_transaction", "number", [], []);
|
|
const transaction = {
|
|
run: transactionRun,
|
|
error: probe.ccall("fc_web_document_last_error", "string", [], []),
|
|
id: probe.ccall("fc_web_document_transaction_id", "number", [], []),
|
|
beforeUndo: probe.ccall("fc_web_document_transaction_before_undo", "number", [], []),
|
|
afterUndo: probe.ccall("fc_web_document_transaction_after_undo", "number", [], []),
|
|
pendingBeforeCommit: probe.ccall("fc_web_document_transaction_pending_before_commit", "number", [], []),
|
|
pendingAfterCommit: probe.ccall("fc_web_document_transaction_pending_after_commit", "number", [], []),
|
|
beforeVolume: probe.ccall("fc_web_document_transaction_before_volume", "number", [], []),
|
|
afterVolume: probe.ccall("fc_web_document_transaction_after_volume", "number", [], []),
|
|
undoResult: probe.ccall("fc_web_document_transaction_undo_result", "number", [], []),
|
|
afterUndoCount: probe.ccall("fc_web_document_transaction_after_undo_count", "number", [], []),
|
|
undoVolume: probe.ccall("fc_web_document_transaction_undo_volume", "number", [], []),
|
|
redoResult: probe.ccall("fc_web_document_transaction_redo_result", "number", [], []),
|
|
redoVolume: probe.ccall("fc_web_document_transaction_redo_volume", "number", [], []),
|
|
abortPending: probe.ccall("fc_web_document_transaction_abort_pending", "number", [], []),
|
|
abortVolume: probe.ccall("fc_web_document_transaction_abort_volume", "number", [], []),
|
|
};
|
|
if (transaction.run !== 1
|
|
|| transaction.error !== ""
|
|
|| transaction.id === 0
|
|
|| transaction.pendingBeforeCommit !== 1
|
|
|| transaction.pendingAfterCommit !== 0
|
|
|| transaction.afterUndo <= transaction.beforeUndo
|
|
|| Math.abs(transaction.beforeVolume - 24) > 1e-9
|
|
|| Math.abs(transaction.afterVolume - 48) > 1e-9
|
|
|| transaction.undoResult !== 1
|
|
|| transaction.afterUndoCount <= 0
|
|
|| Math.abs(transaction.undoVolume - 24) > 1e-9
|
|
|| transaction.redoResult !== 1
|
|
|| Math.abs(transaction.redoVolume - 48) > 1e-9
|
|
|| transaction.abortPending !== 0
|
|
|| Math.abs(transaction.abortVolume - 48) > 1e-9) {
|
|
throw new Error(JSON.stringify({ result, recompute, recovery, save, opened, transaction }));
|
|
}
|
|
console.log(JSON.stringify({ result, recompute, recovery, save, opened, transaction }));
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|