Package dmd implements well-known formats for dot-matrix display (DMD) art.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.4 KiB

package dmd
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestDecodeRunDMD(t *testing.T) {
image := os.Getenv("RUNDMD_IMAGE")
if image == "" {
t.Skip("RUNDMD_IMAGE not defined")
}
f, err := os.Open(image)
if err != nil {
if os.IsNotExist(err) {
t.Skip(err)
}
t.Fatal(err)
}
defer func() { _ = f.Close() }()
all, err := DecodeRunDMD(f)
if err != nil {
t.Fatal(err)
}
if len(all) == 0 {
t.Fatal("no animations were decoded")
}
for i, a := range all {
if !strings.Contains(a.Name(), "24_") {
continue
}
w, h := a.Size()
t.Logf("animation %d: %s, %dx%d, %s, %d frames", i+1, a.Name(), w, h, a.Duration(), a.Len())
}
if !testing.Short() {
dir := filepath.Join(os.TempDir(), "rundmd")
if err = os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
for _, a := range all {
if !strings.Contains(a.Name(), "24_") {
continue
}
o, err := os.Create(filepath.Join(dir, a.Name()+".gif"))
if err != nil {
t.Error(err)
} else {
t.Logf("encoding %s to %s", a.Name(), o.Name())
if a.IsMask() {
err = EncodeToGIF(o, a, Amber)
} else {
err = EncodeToGIF(o, a, Red)
}
if err != nil {
_ = o.Close()
_ = os.Remove(o.Name())
t.Fatalf("failed to encode %s: %v", a.Name(), err)
} else if err = o.Close(); err != nil {
_ = os.Remove(o.Name())
t.Fatalf("failed to close %s: %v", a.Name(), err)
}
}
}
}
}