mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-12-25 09:08:38 -07:00
* Get libslic3r tests closer to passing
I can't get geometry tests to do anything useful. I've added extra
output, but it hasn't helped me figure out why they don't work
yet. That's also probably the last broken 3mf test doesn't work.
The config tests were mostly broken because of config name changes.
The placeholder_parser tests have some things that may-or-may-not
still apply to Orca.
* Vendor a 3.x version of Catch2
Everything is surely broken at this point.
* Allow building tests separately from Orca with build_linux.sh
* Remove unnecessary log message screwing up ctest
Same solution as Prusaslicer
* Make 2 TriangleMesh methods const
Since they can be.
* Move method comment to the header where it belongsc
* Add indirectly-included header directly
Transform3d IIRC
* libslic3r tests converted to Catch2 v3
Still has 3 failing tests, but builds and runs.
* Disable 2D convex hull test and comment what I've learned
Not sure the best way to solve this yet.
* Add diff compare method for DynamicConfig
Help the unit test report errors better.
* Perl no longer used, remove comment line
* Clang-format Config.?pp
So difficult to work with ATM
* Remove cpp17 unit tests
Who gives a shit
* Don't need explicit "example" test
We have lots of tests to serve as examples.
* Leave breadcrumb to enable sla_print tests
* Fix serialization of DynamicConfig
Add comments to test, because these code paths might not be even used
anymore.
* Update run_unit_tests to run all the tests
By the time I'm done with the PR all tests will either excluded by
default or passing, so just do all.
* Update how-to-test now that build_linux.sh builds tests separately
* Update cmake regenerate instructions
Read this online; hopefully works.
* Enable slic3rutils test with Catch2 v3
* Port libnest2d and fff_print to Catch2 v3
They build. Many failing.
* Add slightly more info to Objects not fit on bed exception
* Disable failing fff_print tests from running
They're mostly failing for "objects don't fit on bed" for an
infinite-sized bed. Given infinite bed is probably only used in tests,
it probably was incidentally broken long ago.
* Must checkout tests directory in GH Actions
So we get the test data
* Missed a failing fff_print test
* Disable (most/all) broken libnest2d tests
Trying all, not checking yet though
* Fix Polygon convex/concave detection tests
Document the implementation too. Reorganize the tests to be cleaner.
* Update the test script to run tests in parallel
* Get sla_print tests to build
Probably not passing
* Don't cause full project rebuild when updating test CMakeLists.txts
* Revert "Clang-format Config.?pp"
This reverts commit 771e4c0ad2.
---------
Co-authored-by: SoftFever <softfeverever@gmail.com>
281 lines
13 KiB
C++
281 lines
13 KiB
C++
#ifdef WIN32
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
#ifndef NOMINMAX
|
|
#define NOMINMAX
|
|
#endif
|
|
#include <Windows.h>
|
|
#endif
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
#include "libslic3r/GCodeReader.hpp"
|
|
|
|
#include "test_data.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <boost/regex.hpp>
|
|
|
|
using namespace Slic3r;
|
|
using namespace Slic3r::Test;
|
|
|
|
boost::regex perimeters_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; perimeter");
|
|
boost::regex infill_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; infill");
|
|
boost::regex skirt_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; skirt");
|
|
|
|
SCENARIO( "PrintGCode basic functionality", "[PrintGCode][.]") {
|
|
GIVEN("A default configuration and a print test object") {
|
|
WHEN("the output is executed with no support material") {
|
|
Slic3r::Print print;
|
|
Slic3r::Model model;
|
|
Slic3r::Test::init_print({TestMesh::cube_20x20x20}, print, model, {
|
|
{ "layer_height", 0.2 },
|
|
{ "first_layer_height", 0.2 },
|
|
{ "first_layer_extrusion_width", 0 },
|
|
{ "gcode_comments", true },
|
|
{ "start_gcode", "" }
|
|
});
|
|
std::string gcode = Slic3r::Test::gcode(print);
|
|
THEN("Some text output is generated.") {
|
|
REQUIRE(gcode.size() > 0);
|
|
}
|
|
THEN("Exported text contains slic3r version") {
|
|
REQUIRE(gcode.find(SLIC3R_VERSION) != std::string::npos);
|
|
}
|
|
//THEN("Exported text contains git commit id") {
|
|
// REQUIRE(gcode.find("; Git Commit") != std::string::npos);
|
|
// REQUIRE(gcode.find(SLIC3R_BUILD_ID) != std::string::npos);
|
|
//}
|
|
THEN("Exported text contains extrusion statistics.") {
|
|
REQUIRE(gcode.find("; external perimeters extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; perimeters extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; solid infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; top infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; support material extrusion width") == std::string::npos);
|
|
REQUIRE(gcode.find("; first layer extrusion width") == std::string::npos);
|
|
}
|
|
THEN("Exported text does not contain cooling markers (they were consumed)") {
|
|
REQUIRE(gcode.find(";_EXTRUDE_SET_SPEED") == std::string::npos);
|
|
}
|
|
|
|
THEN("GCode preamble is emitted.") {
|
|
REQUIRE(gcode.find("G21 ; set units to millimeters") != std::string::npos);
|
|
}
|
|
|
|
THEN("Config options emitted for print config, default region config, default object config") {
|
|
REQUIRE(gcode.find("; first_layer_temperature") != std::string::npos);
|
|
REQUIRE(gcode.find("; layer_height") != std::string::npos);
|
|
REQUIRE(gcode.find("; fill_density") != std::string::npos);
|
|
}
|
|
THEN("Infill is emitted.") {
|
|
boost::smatch has_match;
|
|
REQUIRE(boost::regex_search(gcode, has_match, infill_regex));
|
|
}
|
|
THEN("Perimeters are emitted.") {
|
|
boost::smatch has_match;
|
|
REQUIRE(boost::regex_search(gcode, has_match, perimeters_regex));
|
|
}
|
|
THEN("Skirt is emitted.") {
|
|
boost::smatch has_match;
|
|
REQUIRE(boost::regex_search(gcode, has_match, skirt_regex));
|
|
}
|
|
THEN("final Z height is 20mm") {
|
|
double final_z = 0.0;
|
|
GCodeReader reader;
|
|
reader.apply_config(print.config());
|
|
reader.parse_buffer(gcode, [&final_z] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
|
final_z = std::max<double>(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
});
|
|
REQUIRE(final_z == Catch::Approx(20.));
|
|
}
|
|
}
|
|
WHEN("output is executed with complete objects and two differently-sized meshes") {
|
|
Slic3r::Print print;
|
|
Slic3r::Model model;
|
|
Slic3r::Test::init_print({TestMesh::cube_20x20x20,TestMesh::cube_20x20x20}, print, model, {
|
|
{ "first_layer_extrusion_width", 0 },
|
|
{ "first_layer_height", 0.3 },
|
|
{ "layer_height", 0.2 },
|
|
{ "support_material", false },
|
|
{ "raft_layers", 0 },
|
|
{ "complete_objects", true },
|
|
{ "gcode_comments", true },
|
|
{ "between_objects_gcode", "; between-object-gcode" }
|
|
});
|
|
std::string gcode = Slic3r::Test::gcode(print);
|
|
THEN("Some text output is generated.") {
|
|
REQUIRE(gcode.size() > 0);
|
|
}
|
|
THEN("Infill is emitted.") {
|
|
boost::smatch has_match;
|
|
REQUIRE(boost::regex_search(gcode, has_match, infill_regex));
|
|
}
|
|
THEN("Perimeters are emitted.") {
|
|
boost::smatch has_match;
|
|
REQUIRE(boost::regex_search(gcode, has_match, perimeters_regex));
|
|
}
|
|
THEN("Skirt is emitted.") {
|
|
boost::smatch has_match;
|
|
REQUIRE(boost::regex_search(gcode, has_match, skirt_regex));
|
|
}
|
|
THEN("Between-object-gcode is emitted.") {
|
|
REQUIRE(gcode.find("; between-object-gcode") != std::string::npos);
|
|
}
|
|
THEN("final Z height is 20.1mm") {
|
|
double final_z = 0.0;
|
|
GCodeReader reader;
|
|
reader.apply_config(print.config());
|
|
reader.parse_buffer(gcode, [&final_z] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
|
final_z = std::max(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
});
|
|
REQUIRE(final_z == Catch::Approx(20.1));
|
|
}
|
|
THEN("Z height resets on object change") {
|
|
double final_z = 0.0;
|
|
bool reset = false;
|
|
GCodeReader reader;
|
|
reader.apply_config(print.config());
|
|
reader.parse_buffer(gcode, [&final_z, &reset] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
|
if (final_z > 0 && std::abs(self.z() - 0.3) < 0.01 ) { // saw higher Z before this, now it's lower
|
|
reset = true;
|
|
} else {
|
|
final_z = std::max(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
}
|
|
});
|
|
REQUIRE(reset == true);
|
|
}
|
|
THEN("Shorter object is printed before taller object.") {
|
|
double final_z = 0.0;
|
|
bool reset = false;
|
|
GCodeReader reader;
|
|
reader.apply_config(print.config());
|
|
reader.parse_buffer(gcode, [&final_z, &reset] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
|
if (final_z > 0 && std::abs(self.z() - 0.3) < 0.01 ) {
|
|
reset = (final_z > 20.0);
|
|
} else {
|
|
final_z = std::max(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
}
|
|
});
|
|
REQUIRE(reset == true);
|
|
}
|
|
}
|
|
WHEN("the output is executed with support material") {
|
|
std::string gcode = ::Test::slice({TestMesh::cube_20x20x20}, {
|
|
{ "first_layer_extrusion_width", 0 },
|
|
{ "support_material", true },
|
|
{ "raft_layers", 3 },
|
|
{ "gcode_comments", true }
|
|
});
|
|
THEN("Some text output is generated.") {
|
|
REQUIRE(gcode.size() > 0);
|
|
}
|
|
THEN("Exported text contains extrusion statistics.") {
|
|
REQUIRE(gcode.find("; external perimeters extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; perimeters extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; solid infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; top infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; support material extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; first layer extrusion width") == std::string::npos);
|
|
}
|
|
THEN("Raft is emitted.") {
|
|
REQUIRE(gcode.find("; raft") != std::string::npos);
|
|
}
|
|
}
|
|
WHEN("the output is executed with a separate first layer extrusion width") {
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
{ "first_layer_extrusion_width", "0.5" }
|
|
});
|
|
THEN("Some text output is generated.") {
|
|
REQUIRE(gcode.size() > 0);
|
|
}
|
|
THEN("Exported text contains extrusion statistics.") {
|
|
REQUIRE(gcode.find("; external perimeters extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; perimeters extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; solid infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; top infill extrusion width") != std::string::npos);
|
|
REQUIRE(gcode.find("; support material extrusion width") == std::string::npos);
|
|
REQUIRE(gcode.find("; first layer extrusion width") != std::string::npos);
|
|
}
|
|
}
|
|
WHEN("Cooling is enabled and the fan is disabled.") {
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
{ "cooling", true },
|
|
{ "disable_fan_first_layers", 5 }
|
|
});
|
|
THEN("GCode to disable fan is emitted."){
|
|
REQUIRE(gcode.find("M107") != std::string::npos);
|
|
}
|
|
}
|
|
WHEN("end_gcode exists with layer_num and layer_z") {
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
{ "end_gcode", "; Layer_num [layer_num]\n; Layer_z [layer_z]" },
|
|
{ "layer_height", 0.1 },
|
|
{ "first_layer_height", 0.1 }
|
|
});
|
|
THEN("layer_num and layer_z are processed in the end gcode") {
|
|
REQUIRE(gcode.find("; Layer_num 199") != std::string::npos);
|
|
REQUIRE(gcode.find("; Layer_z 20") != std::string::npos);
|
|
}
|
|
}
|
|
WHEN("current_extruder exists in start_gcode") {
|
|
{
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
{ "start_gcode", "; Extruder [current_extruder]" }
|
|
});
|
|
THEN("current_extruder is processed in the start gcode and set for first extruder") {
|
|
REQUIRE(gcode.find("; Extruder 0") != std::string::npos);
|
|
}
|
|
}
|
|
{
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
config.set_num_extruders(4);
|
|
config.set_deserialize_strict({
|
|
{ "start_gcode", "; Extruder [current_extruder]" },
|
|
{ "infill_extruder", 2 },
|
|
{ "solid_infill_extruder", 2 },
|
|
{ "perimeter_extruder", 2 },
|
|
{ "support_material_extruder", 2 },
|
|
{ "support_material_interface_extruder", 2 }
|
|
});
|
|
std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, config);
|
|
THEN("current_extruder is processed in the start gcode and set for second extruder") {
|
|
REQUIRE(gcode.find("; Extruder 1") != std::string::npos);
|
|
}
|
|
}
|
|
}
|
|
|
|
WHEN("layer_num represents the layer's index from z=0") {
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, {
|
|
{ "complete_objects", true },
|
|
{ "gcode_comments", true },
|
|
{ "layer_gcode", ";Layer:[layer_num] ([layer_z] mm)" },
|
|
{ "layer_height", 0.1 },
|
|
{ "first_layer_height", 0.1 }
|
|
});
|
|
// End of the 1st object.
|
|
std::string token = ";Layer:199 ";
|
|
size_t pos = gcode.find(token);
|
|
THEN("First and second object last layer is emitted") {
|
|
// First object
|
|
REQUIRE(pos != std::string::npos);
|
|
pos += token.size();
|
|
REQUIRE(pos < gcode.size());
|
|
double z = 0;
|
|
REQUIRE((sscanf(gcode.data() + pos, "(%lf mm)", &z) == 1));
|
|
REQUIRE(z == Catch::Approx(20.));
|
|
// Second object
|
|
pos = gcode.find(";Layer:399 ", pos);
|
|
REQUIRE(pos != std::string::npos);
|
|
pos += token.size();
|
|
REQUIRE(pos < gcode.size());
|
|
REQUIRE((sscanf(gcode.data() + pos, "(%lf mm)", &z) == 1));
|
|
REQUIRE(z == Catch::Approx(20.));
|
|
}
|
|
}
|
|
}
|
|
}
|