From eb4e727f74ff01025a1b8e9c54051e8457097204 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Thu, 26 Jul 2018 22:58:21 -0500 Subject: [PATCH] Added test to check for two-object systems. --- src/test/libslic3r/test_printgcode.cpp | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/libslic3r/test_printgcode.cpp b/src/test/libslic3r/test_printgcode.cpp index f02922481..8b5e571cf 100644 --- a/src/test/libslic3r/test_printgcode.cpp +++ b/src/test/libslic3r/test_printgcode.cpp @@ -3,8 +3,10 @@ #include #include "test_data.hpp" #include "libslic3r.h" +#include "GCodeReader.hpp" using namespace Slic3r::Test; +using namespace Slic3r; std::regex perimeters_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; perimeter"); std::regex infill_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; infill"); @@ -18,6 +20,7 @@ SCENARIO( "PrintGCode basic functionality", "[!mayfail]") { WHEN("the output is executed with no support material") { config->set("first_layer_extrusion_width", 0); config->set("gcode_comments", true); + config->set("start_gcode", ""); Slic3r::Model model; auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)}; print->process(); @@ -64,6 +67,47 @@ SCENARIO( "PrintGCode basic functionality", "[!mayfail]") { std::smatch has_match; REQUIRE(std::regex_search(exported, has_match, skirt_regex)); } + THEN("final Z height is ~20mm") { + double final_z {0.0}; + auto reader {GCodeReader()}; + reader.apply_config(print->config); + reader.parse(exported, [&final_z] (GCodeReader& self, const GCodeReader::GCodeLine& line) + { + final_z = std::max(final_z, static_cast(self.Z)); // record the highest Z point we reach + }); + REQUIRE(final_z == Approx(20.15)); + std::cerr << exported << "\n"; + } + } + WHEN("output is executed with complete objects and two differently-sized meshes") { + Slic3r::Model model; + config->set("first_layer_extrusion_width", 0); + config->set("support_material", false); + config->set("raft_layers", 0); + config->set("complete_objects", true); + config->set("gcode_comments", true); + config->set("between_objects_gcode", "; between-object-gcode"); + auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20, TestMesh::overhang}, model, config)}; + Slic3r::Test::gcode(gcode, print); + auto exported {gcode.str()}; + THEN("Some text output is generated.") { + REQUIRE(exported.size() > 0); + } + THEN("Infill is emitted.") { + std::smatch has_match; + REQUIRE(std::regex_search(exported, has_match, infill_regex)); + } + THEN("Perimeters are emitted.") { + std::smatch has_match; + REQUIRE(std::regex_search(exported, has_match, perimeters_regex)); + } + THEN("Skirt is emitted.") { + std::smatch has_match; + REQUIRE(std::regex_search(exported, has_match, skirt_regex)); + } + THEN("Between-object-gcode is emitted.") { + REQUIRE(exported.find("; between-object-gcode") != std::string::npos); + } } WHEN("the output is executed with support material") { Slic3r::Model model;