|
|
@@ -434,3 +434,79 @@ func TestGoldenT1ThroughService(t *testing.T) {
|
|
|
t.Error("differs from testdata/accepted/MpckitT1.xpj")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// copyProject copies DemoFile and its data folder into dir.
|
|
|
+func copyProject(t *testing.T, dir string) string {
|
|
|
+ t.Helper()
|
|
|
+ src := filepath.Join(testdata, "device")
|
|
|
+ must(t, os.Mkdir(filepath.Join(dir, "DemoFile"+project.DataSuffix), 0o755))
|
|
|
+ b, err := os.ReadFile(filepath.Join(src, "DemoFile.xpj"))
|
|
|
+ must(t, err)
|
|
|
+ must(t, os.WriteFile(filepath.Join(dir, "DemoFile.xpj"), b, 0o644))
|
|
|
+ ents, err := os.ReadDir(filepath.Join(src, "DemoFile"+project.DataSuffix))
|
|
|
+ must(t, err)
|
|
|
+ for _, e := range ents {
|
|
|
+ b, err := os.ReadFile(filepath.Join(src, "DemoFile"+project.DataSuffix, e.Name()))
|
|
|
+ must(t, err)
|
|
|
+ must(t, os.WriteFile(filepath.Join(dir, "DemoFile"+project.DataSuffix, e.Name()), b, 0o644))
|
|
|
+ }
|
|
|
+ return filepath.Join(dir, "DemoFile.xpj")
|
|
|
+}
|
|
|
+
|
|
|
+func TestMissingFiles(t *testing.T) {
|
|
|
+ dir := t.TempDir()
|
|
|
+ path := copyProject(t, dir)
|
|
|
+ must(t, os.Remove(filepath.Join(dir, "DemoFile"+project.DataSuffix, "80s-Snr-Dreamer SA.wav")))
|
|
|
+
|
|
|
+ s, _ := newService()
|
|
|
+ res, err := s.LoadPath(path)
|
|
|
+ must(t, err)
|
|
|
+ st := res.State
|
|
|
+ if st.MissingCount != 1 {
|
|
|
+ t.Fatalf("missing count %d, want 1", st.MissingCount)
|
|
|
+ }
|
|
|
+ a2 := st.Pads[1]
|
|
|
+ if !a2.Missing || a2.Audio != "" || !strings.HasSuffix(a2.Source, "80s-Snr-Dreamer SA.wav") {
|
|
|
+ t.Errorf("A02 %+v", a2)
|
|
|
+ }
|
|
|
+ if st.Pads[0].Missing || st.Pads[0].Audio == "" {
|
|
|
+ t.Error("A01 marked missing")
|
|
|
+ }
|
|
|
+
|
|
|
+ // Export names the missing file and writes nothing.
|
|
|
+ out := t.TempDir()
|
|
|
+ if _, err := s.ExportFolder(out, false); err == nil || !strings.Contains(err.Error(), "80s-Snr-Dreamer SA.wav") {
|
|
|
+ t.Errorf("export with a missing file: %v", err)
|
|
|
+ }
|
|
|
+ if ents, _ := os.ReadDir(out); len(ents) != 0 {
|
|
|
+ t.Error("export wrote files")
|
|
|
+ }
|
|
|
+
|
|
|
+ // Replacing the pad's sample fixes it.
|
|
|
+ st, err = s.AssignSamplePath(1, filepath.Join(kickDir, "Linn 9000 kick.wav"))
|
|
|
+ must(t, err)
|
|
|
+ if st.MissingCount != 0 || st.Pads[1].Missing {
|
|
|
+ t.Error("still missing after replace")
|
|
|
+ }
|
|
|
+ if _, err := s.ExportFolder(out, false); err != nil {
|
|
|
+ t.Error(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestCloseWindow(t *testing.T) {
|
|
|
+ s, _ := newService()
|
|
|
+ s.CloseWindow() // no closer set: does nothing
|
|
|
+ closed := false
|
|
|
+ s.SetCloser(func() { closed = true })
|
|
|
+ if s.Dirty() {
|
|
|
+ t.Error("new project dirty")
|
|
|
+ }
|
|
|
+ _, _ = s.SetName("Other")
|
|
|
+ if !s.Dirty() {
|
|
|
+ t.Error("not dirty after rename")
|
|
|
+ }
|
|
|
+ s.CloseWindow()
|
|
|
+ if !closed {
|
|
|
+ t.Error("closer not called")
|
|
|
+ }
|
|
|
+}
|