PrusaSlicer-NonPlainar/t/retraction.t

86 lines
2.8 KiB
Perl
Raw Normal View History

use Test::More tests => 9;
2012-11-21 19:41:14 +00:00
use strict;
use warnings;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
use Slic3r;
use Slic3r::Test;
2012-12-04 23:39:40 +00:00
my $config = Slic3r::Config->new_from_defaults;
my $test = sub {
2012-12-05 10:52:52 +00:00
my ($conf) = @_;
$conf ||= $config;
2012-12-05 11:01:48 +00:00
my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
2012-11-21 19:41:14 +00:00
my $retracted = 1; # ignore the first travel move from home to first point
2012-12-05 00:27:21 +00:00
my $lifted = 0;
2012-11-21 19:41:14 +00:00
Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
my ($self, $cmd, $args, $info) = @_;
2012-12-05 00:27:21 +00:00
if ($info->{dist_Z}) {
# lift move or lift + change layer
2012-12-05 11:01:48 +00:00
if (Slic3r::Test::compare($info->{dist_Z}, $conf->retract_lift->[0])
|| (Slic3r::Test::compare($info->{dist_Z}, $conf->layer_height + $conf->retract_lift->[0]) && $conf->retract_lift->[0] > 0)) {
fail 'only lifting while retracted' if !$retracted && !($conf->g0 && $info->{retracting});
2012-12-05 00:27:21 +00:00
$lifted = 1;
}
if ($info->{dist_Z} < 0) {
fail 'going down only after lifting' if !$lifted;
fail 'going down by the same amount of the lift'
2012-12-05 11:01:48 +00:00
if !Slic3r::Test::compare($info->{dist_Z}, -$conf->retract_lift->[0]);
2012-12-05 00:27:21 +00:00
$lifted = 0;
}
}
2012-11-21 19:41:14 +00:00
if ($info->{retracting}) {
2012-12-04 23:39:40 +00:00
fail 'retracted by the correct amount'
2012-12-05 11:01:48 +00:00
if !Slic3r::Test::compare(-$info->{dist_E}, $conf->retract_length->[0]);
2012-12-05 10:52:52 +00:00
fail 'combining retraction and travel with G0'
2012-12-05 11:01:48 +00:00
if $cmd ne 'G0' && $conf->g0 && ($info->{dist_Z} || $info->{dist_XY});
2012-11-21 19:41:14 +00:00
$retracted = 1;
}
if ($info->{extruding}) {
2012-12-05 00:27:21 +00:00
fail 'only extruding while not lifted' if $lifted;
2012-12-04 23:39:40 +00:00
if ($retracted) {
fail 'unretracted by the correct amount'
2012-12-05 11:01:48 +00:00
if !Slic3r::Test::compare($info->{dist_E}, $conf->retract_length->[0] + $conf->retract_restart_extra->[0]);
2012-12-04 23:39:40 +00:00
$retracted = 0;
}
2012-11-21 19:41:14 +00:00
}
2012-12-05 11:01:48 +00:00
if ($info->{travel} && $info->{dist_XY} >= $conf->retract_before_travel->[0]) {
2012-12-04 23:39:40 +00:00
fail 'retracted before long travel move' if !$retracted;
2012-11-21 19:41:14 +00:00
}
});
2012-12-04 23:39:40 +00:00
1;
};
$config->set('retract_length', [1.5]);
$config->set('retract_before_travel', [3]);
2012-11-21 19:41:14 +00:00
2012-12-05 10:52:52 +00:00
my $retract_tests = sub {
my ($descr) = @_;
ok $test->(), "retraction$descr";
my $conf = $config->clone;
$conf->set('retract_restart_extra', [1]);
ok $test->($conf), "restart extra length$descr";
$conf->set('retract_lift', [1]);
ok $test->($conf), "lift$descr";
};
2012-11-21 19:41:14 +00:00
2012-12-05 10:52:52 +00:00
$retract_tests->('');
$config->set('duplicate', 2);
$retract_tests->(' (duplicate)');
2012-12-05 10:52:52 +00:00
$config->set('g0', 1);
$retract_tests->(' (G0 and duplicate)');
2012-12-05 00:27:21 +00:00
2012-11-21 19:41:14 +00:00
__END__