shiny/iconvg: add testdata/blank.ivg.
Change-Id: I24c19f54fe53513f1c3e70e47339d6fabc80c06b
Reviewed-on: https://go-review.googlesource.com/30734
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/shiny/iconvg/decode_test.go b/shiny/iconvg/decode_test.go
index f8d34ba..226e71a 100644
--- a/shiny/iconvg/decode_test.go
+++ b/shiny/iconvg/decode_test.go
@@ -48,7 +48,6 @@
_ Destination = (*Rasterizer)(nil)
)
-// encodePNG is useful for manually debugging the tests.
func encodePNG(dstFilename string, src image.Image) error {
f, err := os.Create(dstFilename)
if err != nil {
@@ -124,6 +123,7 @@
var testdataTestCases = []string{
"testdata/action-info",
+ "testdata/blank",
"testdata/video-005.primitive",
}
@@ -139,7 +139,14 @@
t.Errorf("%s: disassemble: %v", tc, err)
continue
}
- want, err := ioutil.ReadFile(filepath.FromSlash(tc) + ".ivg.disassembly")
+ wantFilename := filepath.FromSlash(tc) + ".ivg.disassembly"
+ if overwriteTestdataFiles {
+ if err := ioutil.WriteFile(filepath.FromSlash(wantFilename), got, 0666); err != nil {
+ t.Errorf("%s: WriteFile: %v", tc, err)
+ }
+ continue
+ }
+ want, err := ioutil.ReadFile(wantFilename)
if err != nil {
t.Errorf("%s: ReadFile: %v", tc, err)
continue
@@ -178,6 +185,13 @@
continue
}
+ wantFilename := filepath.FromSlash(tc) + ".png"
+ if overwriteTestdataFiles {
+ if err := encodePNG(filepath.FromSlash(wantFilename), got); err != nil {
+ t.Errorf("%s: encodePNG: %v", tc, err)
+ }
+ continue
+ }
want, err := decodePNG(filepath.FromSlash(tc) + ".png")
if err != nil {
t.Errorf("%s: decodePNG: %v", tc, err)
diff --git a/shiny/iconvg/encode_test.go b/shiny/iconvg/encode_test.go
index 2c26f08..425f747 100644
--- a/shiny/iconvg/encode_test.go
+++ b/shiny/iconvg/encode_test.go
@@ -14,21 +14,34 @@
"golang.org/x/image/math/f32"
)
-func TestEncoderZeroValue(t *testing.T) {
- var e Encoder
+// overwriteTestdataFiles is set to true when adding new testdataTestCases.
+const overwriteTestdataFiles = false
+
+func testEncode(t *testing.T, e *Encoder, wantFilename string) {
got, err := e.Bytes()
if err != nil {
- t.Fatalf("Bytes: %v", err)
+ t.Fatalf("encoding: %v", err)
}
- want := []byte{
- 0x89, 0x49, 0x56, 0x47, // IconVG Magic identifier.
- 0x00, // Zero metadata chunks.
+ if overwriteTestdataFiles {
+ if err := ioutil.WriteFile(filepath.FromSlash(wantFilename), got, 0666); err != nil {
+ t.Fatalf("WriteFile: %v", err)
+ }
+ return
+ }
+ want, err := ioutil.ReadFile(filepath.FromSlash(wantFilename))
+ if err != nil {
+ t.Fatalf("ReadFile: %v", err)
}
if !bytes.Equal(got, want) {
- t.Errorf("\ngot %d bytes:\n% x\nwant %d bytes:\n% x", len(got), got, len(want), want)
+ t.Fatalf("\ngot %d bytes:\n% x\nwant %d bytes:\n% x", len(got), got, len(want), want)
}
}
+func TestEncodeBlank(t *testing.T) {
+ var e Encoder
+ testEncode(t, &e, "testdata/blank.ivg")
+}
+
func TestEncodeActionInfo(t *testing.T) {
var e Encoder
e.Reset(Metadata{
@@ -56,17 +69,7 @@
e.RelVLineTo(4)
e.ClosePathEndPath()
- got, err := e.Bytes()
- if err != nil {
- t.Fatal(err)
- }
- want, err := ioutil.ReadFile(filepath.FromSlash("testdata/action-info.ivg"))
- if err != nil {
- t.Fatal(err)
- }
- if !bytes.Equal(got, want) {
- t.Errorf("\ngot %d bytes:\n% x\nwant %d bytes:\n% x", len(got), got, len(want), want)
- }
+ testEncode(t, &e, "testdata/action-info.ivg")
}
var video005PrimitiveSVGData = []struct {
@@ -145,15 +148,5 @@
e.ClosePathEndPath()
}
- got, err := e.Bytes()
- if err != nil {
- t.Fatal(err)
- }
- want, err := ioutil.ReadFile(filepath.FromSlash("testdata/video-005.primitive.ivg"))
- if err != nil {
- t.Fatal(err)
- }
- if !bytes.Equal(got, want) {
- t.Errorf("\ngot %d bytes:\n% x\nwant %d bytes:\n% x", len(got), got, len(want), want)
- }
+ testEncode(t, &e, "testdata/video-005.primitive.ivg")
}
diff --git a/shiny/iconvg/testdata/README b/shiny/iconvg/testdata/README
index ec9e2e1..bf297de 100644
--- a/shiny/iconvg/testdata/README
+++ b/shiny/iconvg/testdata/README
@@ -10,6 +10,14 @@
+blank.ivg is a blank, square graphic.
+
+blank.ivg.disassembly is a disassembly of that IconVG file.
+
+blank.png is a rendering of that IconVG file.
+
+
+
video-005.jpeg comes from an old version of the Go repository. See
https://codereview.appspot.com/5758047/
diff --git a/shiny/iconvg/testdata/blank.ivg b/shiny/iconvg/testdata/blank.ivg
new file mode 100644
index 0000000..e5be490
--- /dev/null
+++ b/shiny/iconvg/testdata/blank.ivg
Binary files differ
diff --git a/shiny/iconvg/testdata/blank.ivg.disassembly b/shiny/iconvg/testdata/blank.ivg.disassembly
new file mode 100644
index 0000000..10d2645
--- /dev/null
+++ b/shiny/iconvg/testdata/blank.ivg.disassembly
@@ -0,0 +1,2 @@
+89 49 56 47 IconVG Magic identifier
+00 Number of metadata chunks: 0
diff --git a/shiny/iconvg/testdata/blank.png b/shiny/iconvg/testdata/blank.png
new file mode 100644
index 0000000..5bae722
--- /dev/null
+++ b/shiny/iconvg/testdata/blank.png
Binary files differ