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.

88 lines
1.9 KiB

package dmd
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestDecodeDMD1(t *testing.T) {
tests := []struct {
Name string
Width int
Height int
Len int
Duration time.Duration
}{
{
Name: "1942.dmd",
Width: 128,
Height: 32,
Len: 969,
Duration: 19*time.Second + 380*time.Millisecond,
},
{
Name: "afterburner.dmd",
Width: 128,
Height: 32,
Len: 600,
Duration: 12 * time.Second,
},
}
for i, test := range tests {
t.Run(test.Name, func(it *testing.T) {
f, err := os.Open(filepath.Join("testdata", "dmd1", test.Name))
if err != nil {
it.Fatal(err)
}
a, err := DecodeDMD1(f)
if err != nil {
_ = f.Close()
it.Fatal(err)
}
// it.Logf("animation: %s, %dx%d, %s, %d frames", a.Name(), w, h, a.Duration(), a.Len())
if v := a.Len(); v != test.Len {
it.Errorf("expected %d frames, got %d", test.Len, v)
}
if v := a.Duration(); v != test.Duration {
it.Errorf("expected %s duration, got %s", test.Duration, v)
}
w, h := a.Size()
if w != test.Width || h != test.Height {
it.Errorf("expected %dx%d size, got %dx%d", test.Width, test.Height, w, h)
}
if err = f.Close(); err != nil {
it.Fatal(err)
}
if a.Len() > 1 && !testing.Short() {
base := filepath.Base(test.Name)
base = base[:len(base)-len(filepath.Ext(base))]
testEncodeGIF(it, "dmd1", base, a, i)
/*
dir := filepath.Join(os.TempDir(), "dmd1")
if err = os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
o, err := os.Create(filepath.Join(dir, a.Name()+".gif"))
if err != nil {
it.Fatal(err)
}
it.Logf("encoding %s to %s", a.Name(), o.Name())
if err = EncodeToGIF(o, a); err != nil {
_ = o.Close()
_ = os.Remove(o.Name())
it.Fatal(err)
}
if err = o.Close(); err != nil {
_ = os.Remove(o.Name())
it.Fatal(err)
}
*/
}
})
}
}