-
Notifications
You must be signed in to change notification settings - Fork 17
/
goslice_test.go
152 lines (139 loc) · 4.07 KB
/
goslice_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package goslice
import (
"strings"
"testing"
"github.com/aligator/goslice/data"
"github.com/aligator/goslice/util/test"
)
const (
folder = "./test_stl/"
// The models are copied to the project just to avoid downloading them for each test.
// 3DBenchy is the unmodified model from here:
// https://www.thingiverse.com/thing:763622
// using the following license
// https://creativecommons.org/licenses/by-nd/4.0/
benchy = "3DBenchy.stl"
// Go Gopher mascot is the unmodified model from here:
// https://www.thingiverse.com/thing:3413597
// using the following license
// https://creativecommons.org/licenses/by/4.0/
gopher = "gopher_union.stl"
)
func TestWholeSlicer(t *testing.T) {
o := data.DefaultOptions()
// enable support so that it is tested also
o.Print.Support.Enabled = true
o.Print.BrimSkirt.BrimCount = 3
s := NewGoSlice(o)
var tests = []struct {
path string
}{
{
path: benchy,
},
{
path: gopher,
},
}
for _, testCase := range tests {
t.Log("slice " + testCase.path)
s.Options.InputFilePath = folder + testCase.path
err := s.Process()
test.Ok(t, err)
}
}
type fakeWriter struct {
finalGcode []string
}
func (w *fakeWriter) Write(gcode string, destination string) error {
w.finalGcode = strings.Split(gcode, "\n")
return nil
}
func TestStartGCode(t *testing.T) {
var tests = []struct {
Name string
StartGCode data.GCodeHunk
expected string
}{
{
Name: "basic",
StartGCode: data.NewGCodeHunk([]string{";Set Hotend", "M104 S0"}),
expected: ";Set Hotend\nM104 S0",
},
{
Name: "no startcode supplied",
StartGCode: data.DefaultOptions().Printer.StartGCode,
expected: ";SET BED TEMP\nM190 S60 ; heat and wait for bed\n;SET HOTEND TEMP\nM109 S205 ; wait for hot end temperature",
},
{
Name: "no temp setting in start code",
StartGCode: data.NewGCodeHunk([]string{"printer_start"}),
expected: ";SET BED TEMP\nM190 S60 ; heat and wait for bed\n;SET HOTEND TEMP\nM109 S205 ; wait for hot end temperature\n;START GCODE\nprinter_start",
},
}
for _, testCase := range tests {
o := data.DefaultOptions()
t.Log(testCase.Name)
o.Printer.StartGCode = testCase.StartGCode
s := NewGoSlice(o)
s.Options.InputFilePath = folder + benchy
w := fakeWriter{}
s.Writer = &w
test.Ok(t, s.Process())
gcode := w.finalGcode
test.Assert(t, strings.Contains(strings.Join(gcode, "\n"), testCase.expected),
"final gcode does not contain the expected gcode.\nexpected:"+
testCase.expected+
"\nActual: "+
strings.Join(gcode[0:10], "\n"))
}
}
func TestEndGCode(t *testing.T) {
var tests = []struct {
Name string
EndGCode data.GCodeHunk
Options data.Options
expected string
}{
{
Name: "basic",
EndGCode: data.NewGCodeHunk([]string{";Set Hotend", "M104 S0"}),
Options: data.DefaultOptions(),
expected: ";Set Hotend\nM104 S0",
},
{
Name: "no endcode supplied",
EndGCode: data.DefaultOptions().Printer.EndGCode,
Options: data.DefaultOptions(),
expected: ";END_GCODE\nM104 S0 ; Set Hot-end to 0C (off)\nM140 S0 ; Set bed to 0C (off)",
},
{
Name: "no temp setting in end code",
EndGCode: data.NewGCodeHunk([]string{"printer_stop"}),
Options: data.DefaultOptions(),
expected: ";END_GCODE\nM104 S0 ; Set Hot-end to 0C (off)\nM140 S0 ; Set bed to 0C (off)\nprinter_stop",
},
{
Name: "no heated bed",
EndGCode: data.NewGCodeHunk([]string{"printer_stop"}),
Options: data.DefaultOptions().SetHasHeatedBed(false),
expected: ";END_GCODE\nM104 S0 ; Set Hot-end to 0C (off)\nprinter_stop",
},
}
for _, testCase := range tests {
testCase.Options.Printer.EndGCode = testCase.EndGCode
t.Log(testCase.Name)
s := NewGoSlice(testCase.Options)
s.Options.InputFilePath = folder + benchy
w := fakeWriter{}
s.Writer = &w
err := s.Process()
test.Ok(t, err)
gcode := w.finalGcode
test.Assert(t, strings.Contains(strings.Join(gcode, "\n"), testCase.expected),
"final gcode does not contain the expected gcode.\nexpected:"+
testCase.expected+
"\nActual: "+
strings.Join(gcode[len(gcode)-10:], "\n"))
}
}