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.

93 lines
1.8 KiB

package dmd
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func TestDecodeVPIN(t *testing.T) {
tests := []struct {
Name string
Coloring string
}{
{
Name: "mb_106b.vni",
},
/*
{
Name: "sprk_103.vni",
Coloring: "sprk_103.pal",
},
{
Name: "smb.ani",
Coloring: "smb.pal",
},
{
Name: "sttng.vni",
Coloring: "sttng.pal",
},
*/
}
for _, test := range tests {
t.Run(test.Name, func(it *testing.T) {
var c *Pin2DMDColoring
if test.Coloring != "" {
f, err := os.Open(filepath.Join("testdata", "vpin", test.Coloring))
if err != nil {
it.Fatal(err)
}
defer func() { _ = f.Close() }()
if c, err = DecodePin2DMDColoring(f); err != nil {
it.Fatal(err)
}
}
f, err := os.Open(filepath.Join("testdata", "vpin", test.Name))
if err != nil {
it.Fatal(err)
}
defer func() { _ = f.Close() }()
all, err := DecodeVPINWithColoring(f, c)
if err != nil {
it.Fatal(err)
}
if len(all) == 0 {
it.Fatal("no animations were decoded")
}
base := filepath.Base(test.Name)
base = base[:len(base)-len(filepath.Ext(base))]
for i, a := range all {
if a.Len() > 1 && !testing.Short() {
testEncodeGIF(it, "vpin", base, a, i)
}
}
})
}
}
func testEncodeGIF(t *testing.T, set, base string, a Animation, n int) {
t.Helper()
dir := filepath.Join(os.TempDir(), set)
if err := os.MkdirAll(dir, 0755); err != nil {
t.Error(err)
}
o, err := os.Create(filepath.Join(dir, fmt.Sprintf("%s_%s.gif", base, a.Name())))
if err != nil {
t.Fatal(err)
}
defer func() { _ = o.Close() }()
w, h := a.Size()
t.Logf("saving animation %d: %s, %dx%d, %s, %d frames to %s", n+1, a.Name(), w, h, a.Duration(), a.Len(), o.Name())
if err = EncodeToGIF(o, a, Red); err != nil {
t.Fatal(err)
}
}