layers.t 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use Test::More tests => 4;
  2. use strict;
  3. use warnings;
  4. BEGIN {
  5. use FindBin;
  6. use lib "$FindBin::Bin/../lib";
  7. }
  8. use List::Util qw(first);
  9. use Slic3r;
  10. use Slic3r::Test qw(_eq);
  11. my $config = Slic3r::Config->new_from_defaults;
  12. my $test = sub {
  13. my ($conf) = @_;
  14. $conf ||= $config;
  15. my $print = Slic3r::Test::init_print('20mm_cube', config => $conf);
  16. my @z = ();
  17. my @increments = ();
  18. Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
  19. my ($self, $cmd, $args, $info) = @_;
  20. if ($info->{dist_Z}) {
  21. push @z, 1*$args->{Z};
  22. push @increments, $info->{dist_Z};
  23. }
  24. });
  25. fail 'wrong first layer height'
  26. if $z[0] ne $config->get_value('first_layer_height') + $config->z_offset;
  27. fail 'wrong second layer height'
  28. if $z[1] ne $config->get_value('first_layer_height') + $config->get_value('layer_height') + $config->z_offset;
  29. fail 'wrong layer height'
  30. if first { !_eq($_, $config->layer_height) } @increments[1..$#increments];
  31. 1;
  32. };
  33. $config->set('start_gcode', ''); # to avoid dealing with the nozzle lift in start G-code
  34. $config->set('layer_height', 0.3);
  35. $config->set('first_layer_height', 0.2);
  36. ok $test->(), "absolute first layer height";
  37. $config->set('first_layer_height', '60%');
  38. ok $test->(), "relative first layer height";
  39. $config->set('z_offset', 0.9);
  40. ok $test->(), "positive Z offset";
  41. $config->set('z_offset', -0.8);
  42. ok $test->(), "negative Z offset";
  43. __END__