Files
OrcaSlicer/tests/libslic3r/test_preset_setting_id.cpp
T
SoftFever ade9e77b6b Run every profile maintenance job from one tool (#15726)
* Run every profile maintenance job from one tool

orca_id_tool.py becomes orca_profile_tool.py, and orca_extra_profile_check.py
and orca_filament_lib.py fold into it as subcommands: check, generate-id, fix,
trim, update-index and update-snapshot. The three scripts already overlapped --
the checker imported half of its rules from the id tool, which in turn kept a
copy-pasted set of output helpers to avoid the resulting import cycle -- while
disagreeing on how a vendor is enumerated, how a JSON file is read and what the
exit code means. One file settles all three.

check, normalize, trim and update-index reproduce their predecessors exactly; normalize and
update-index were diffed byte-for-byte against the old scripts over a copy of
the whole tree. Deliberate changes: the compatible-printers check no longer
switches itself off when --check-materials is passed, an error exits 1 rather
than -1, update-index honours --profile-type and reports a profile it cannot
place instead of dropping it from the index, fix and update-index gained
--dry-run, trim keeps an unindexed file some surviving profile still inherits
from, and vendors are enumerated as directories with an index -- which is why
blacklist.json, a data file that an unscoped index rebuild once wrote four empty
list sections into, loses them here and will not collect them again. The dead
rename_filament_system() helper is gone.

The suite under scripts/tests now covers the maintenance commands too, and CI
runs it; nothing there ran in CI before. No shipped profile data changes apart
from those four keys.

* update vendor index files with "python3 ./scripts/orca_profile_tool.py update-index" and "python3 ./scripts/orca_profile_tool.py normalize"
2026-09-16 19:53:23 +08:00

42 lines
2.4 KiB
C++

#include <catch2/catch_all.hpp>
#include "libslic3r/Preset.hpp"
using namespace Slic3r;
// Golden vectors from the Python reference generate_preset_setting_id (defined in
// scripts/orca_profile_tool.py). The C++ generate_preset_setting_id() MUST stay byte-identical
// to it, otherwise app-side on-the-fly ids would diverge from the
// script-assigned ones in the profiles. Regenerate a vector with:
// python3 -c "import sys; sys.path.insert(0, 'scripts'); from orca_profile_tool import generate_preset_setting_id as g; print(g('Afinia','filament','Afinia ABS @Afinia H400'))"
TEST_CASE("preset setting_id matches the Python reference", "[Preset][setting_id]") {
struct Vec { const char* vendor; const char* type; const char* name; const char* expected; };
const Vec vectors[] = {
{"Afinia", "filament", "Afinia ABS @Afinia H400", "TL34qSVkppBvMvgH"},
{"Afinia", "process", "0.20mm Standard @Afinia H400", "FzmtNsy7XQvpd7w0"},
{"Afinia", "machine", "Afinia H400 0.4 nozzle", "r4FZagW0S8uoaJPd"},
{"Anycubic", "filament", "Generic PLA @Anycubic Kobra 2", "YIWGGLQ8Oepd30Fv"},
{"Creality", "process", "0.16mm Optimal @Creality Ender-3 V3", "2Nrbq8PxssUPBLza"},
{"Elegoo", "machine", "Elegoo Neptune 4 0.4 nozzle", "69QdWuRQwAZk9rFu"},
};
for (const auto& v : vectors) {
const std::string id = generate_preset_setting_id(v.vendor, v.type, v.name);
INFO(v.vendor << "/" << v.type << "/" << v.name);
CHECK(id.size() == 16);
CHECK(id == v.expected);
}
}
TEST_CASE("preset setting_id is deterministic and identity-sensitive", "[Preset][setting_id]") {
const std::string a = generate_preset_setting_id("VendorX", "filament", "My PLA");
CHECK(a == generate_preset_setting_id("VendorX", "filament", "My PLA")); // stable
CHECK(a != generate_preset_setting_id("VendorY", "filament", "My PLA")); // vendor matters
CHECK(a != generate_preset_setting_id("VendorX", "process", "My PLA")); // type matters
CHECK(a != generate_preset_setting_id("VendorX", "filament", "My PETG")); // name matters
// Empty identity yields no id (callers must not assign one).
CHECK(generate_preset_setting_id("", "filament", "My PLA").empty());
CHECK(generate_preset_setting_id("VendorX", "filament", "").empty());
}