Files
OrcaSlicer/tests/fff_print/test_gcodeprocessor.cpp
T
Hanif Koh 0a30cfe6b0 Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced
Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes.

clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer.
2026-10-03 22:45:55 +08:00

81 lines
3.0 KiB
C++

#include <catch2/catch_all.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include "libslic3r/GCode/GCodeProcessor.hpp"
#include <string>
#include <vector>
using namespace Slic3r;
// Bambu firmware uses the " FEATURE: " style reserved tags, everything else the Slic3r-compatible
// "TYPE:" style, so which list applies depends on the printer kind passed in.
TEST_CASE("Reserved keyword detection follows the printer kind it is given", "[GCodeProcessor]")
{
struct Case
{
const char* name;
std::string gcode;
bool reserved_on_bbl;
bool reserved_on_non_bbl;
};
const auto test_case = GENERATE(values<Case>({
{"compatible feature tag", ";TYPE:Prime tower", false, true},
{"compatible layer tag", ";LAYER_CHANGE", false, true},
{"bbl feature tag", "; FEATURE: Outer wall", true, false},
{"tag shared by both lists", ";_GP_FIRST_LINE_M73_PLACEHOLDER", true, true},
{"bbl spells this one with a leading space", ";COLOR_CHANGE", false, true},
{"ordinary comment", "; heat the bed", false, false},
{"not a comment at all", "G1 X10 Y10 F3000", false, false},
// A tag counts only as the whole comment's prefix, so neither a tag mentioned mid-comment
// nor one trailing a real command is a reserved use.
{"tag text later in the comment", "; the TYPE:Prime tower marker", false, false},
{"tag trailing a command", "G1 X10 ;TYPE:Prime tower", false, false},
}));
DYNAMIC_SECTION(test_case.name)
{
std::vector<std::string> tags;
REQUIRE(GCodeProcessor::contains_reserved_tags(test_case.gcode, 5, tags, true) == test_case.reserved_on_bbl);
tags.clear();
REQUIRE(GCodeProcessor::contains_reserved_tags(test_case.gcode, 5, tags, false) == test_case.reserved_on_non_bbl);
}
}
TEST_CASE("Reserved keyword detection reports every offending line", "[GCodeProcessor]")
{
const std::string gcode = ";TYPE:Prime tower\nG1 X10\n;LAYER_CHANGE\n";
std::vector<std::string> tags;
REQUIRE(GCodeProcessor::contains_reserved_tags(gcode, 5, tags, false));
REQUIRE(tags.size() == 2);
// Reported in the order they appear, which is what makes the max_count cut-off meaningful.
CHECK(tags[0] == "TYPE:Prime tower");
CHECK(tags[1] == "LAYER_CHANGE");
SECTION("the reported count is capped at max_count")
{
tags.clear();
REQUIRE(GCodeProcessor::contains_reserved_tags(gcode, 1, tags, false));
CHECK(tags.size() == 1);
CHECK(tags[0] == "TYPE:Prime tower");
}
SECTION("a max_count of zero still reports the first tag")
{
tags.clear();
REQUIRE(GCodeProcessor::contains_reserved_tags(gcode, 0, tags, false));
CHECK(tags.size() == 1);
}
SECTION("g-code with nothing reserved in it reports nothing")
{
tags.clear();
CHECK_FALSE(GCodeProcessor::contains_reserved_tags("G28\n; home all axes\n", 5, tags, false));
CHECK(tags.empty());
}
}