From c119c3eeeb2578424fdaef4745cd744f6ccd5a5e Mon Sep 17 00:00:00 2001 From: upperstream Date: Sat, 9 Jul 2016 17:16:33 +0900 Subject: [PATCH] Add tests for ID3v1 and ID3v1.1. --- .gitignore | 1 + id3v1_test.go | 39 +++++++++++++++++++++++++++++ id3v1_test/NOTICE.txt | 3 +++ id3v1_test/sample_ms932_v1.1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_ms932_v1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_usascii_v1.1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_usascii_v1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_utf8_v1.1.mp3 | Bin 0 -> 344 bytes id3v1_test/sample_utf8_v1.mp3 | Bin 0 -> 344 bytes 9 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 id3v1_test.go create mode 100644 id3v1_test/NOTICE.txt create mode 100644 id3v1_test/sample_ms932_v1.1.mp3 create mode 100644 id3v1_test/sample_ms932_v1.mp3 create mode 100644 id3v1_test/sample_usascii_v1.1.mp3 create mode 100644 id3v1_test/sample_usascii_v1.mp3 create mode 100644 id3v1_test/sample_utf8_v1.1.mp3 create mode 100644 id3v1_test/sample_utf8_v1.mp3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c650540 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/id3v1_testdata.go diff --git a/id3v1_test.go b/id3v1_test.go new file mode 100644 index 0000000..f0faad4 --- /dev/null +++ b/id3v1_test.go @@ -0,0 +1,39 @@ +// This file is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication +// license. Its contents can be found at: +// http://creativecommons.org/publicdomain/zero/1.0 + +package tag + +import ( + "bytes" + "testing" +) + +//go:generate go-bindata -o id3v1_testdata.go -pkg tag -ignore .txt id3v1_test + +func TestReadID3v1Tags(t *testing.T) { + for _, name := range []string{ + "id3v1_test/sample_usascii_v1.mp3", + "id3v1_test/sample_ms932_v1.mp3", + "id3v1_test/sample_utf8_v1.mp3"} { + doTest(name, 0, 30, t) + } + for _, name := range []string{ + "id3v1_test/sample_usascii_v1.1.mp3", + "id3v1_test/sample_ms932_v1.1.mp3", + "id3v1_test/sample_utf8_v1.1.mp3"} { + doTest(name, 1, 28, t) + } +} + +func doTest(name string, track int, length int, t *testing.T) { + mp3 := MustAsset(name) + metadata, _ := ReadID3v1Tags(bytes.NewReader(mp3)) + if actual, total := metadata.Track(); actual != track || total != 0 { + t.Errorf("Track number for %s is (%d, %d) where (%d, 0) is expected.", name, actual, total, track) + } + comment := metadata.Raw()["comment"].(string) + if actual := len(comment); actual != length { + t.Errorf("Comment length for %s is %d where %d is expected", name, actual, length) + } +} diff --git a/id3v1_test/NOTICE.txt b/id3v1_test/NOTICE.txt new file mode 100644 index 0000000..f7e01d8 --- /dev/null +++ b/id3v1_test/NOTICE.txt @@ -0,0 +1,3 @@ +All files in this directory are subject to the CC0 1.0 Universal (CC0 1.0) +Public Domain Dedication license. Its contents can be found at: +http://creativecommons.org/publicdomain/zero/1.0 diff --git a/id3v1_test/sample_ms932_v1.1.mp3 b/id3v1_test/sample_ms932_v1.1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..927f4b987089ca9687bb54833602304dfa7b37ff GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA+j zLz*Wymo;}cooSA1c5Y5@?gse{29RVO8>5?3o1K~?n$xk#Hg`AYH#fj!K(wKyr9p6F hZb43}f=gmaqC$CQNrr-Nu%)q)g0YFInK=Wa3;-;OV!Z$W literal 0 HcmV?d00001 diff --git a/id3v1_test/sample_ms932_v1.mp3 b/id3v1_test/sample_ms932_v1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..13493cfb3d913ff12f34d8256d591b3d6f142815 GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA+j zLz*Wymo;}cooSA1c5Y5@?p8noNV1NN(aovNPR$X`=`aPzvd!Ji`OOV584zt~X=xCg im|KvOs^F4XlBiIgS(2gP8*FK8q+o1fYG!U>DFXmWv1cs+ literal 0 HcmV?d00001 diff --git a/id3v1_test/sample_usascii_v1.1.mp3 b/id3v1_test/sample_usascii_v1.1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..3eb86df2ad27d9b8be51392ec8beed2e5c83b46f GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA+L z6LSl4QWZinOL9^{zCs01S;wN1%;FMMDIgCfo0C+Uiy_HiXlZExRpF9YlBiIgS(2d; S8m#LW?Cj~OU}nz1C<6eN^iZRZ-5g>yBdG(KlSTz|LLA+L z6LSl4QWZinOMoN>fXX@+m1Gu|;FQftD$T`^R4}x(G=S=NNi0cJD9ZRZ-5g>yBdG(KlSTz|LLA*6 zH*I~~y!mnS^vBJsA2+Uh+_e93(~`%{9Y8M7j~KFx9yjlK+}!rKY4PKxo!DeoKW?7z sxOo9kuc4)-L2zPjK~AcIOJYf)LV0FMhC*nFn}vdrv5BdfIRm2%01cpk4gdfE literal 0 HcmV?d00001 diff --git a/id3v1_test/sample_utf8_v1.mp3 b/id3v1_test/sample_utf8_v1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d3aa4d59efc9078067aaf8aec0aa6eeccb6668e1 GIT binary patch literal 344 zcmezWSR#difq`)ekN^T^4-o0&=<8~%XKATt8cHnq4>ZRZ-5g>yBdG(KlSTz|LLA*6 zH*I~~y!mnS^vBJsA2+Uh+_e93(~`%{9YC&vf&zx@qQ}j99yhl=Zd&}fX(u+>)sLGe tJZ@e9)N5#IX%L*4Tac5g;F4I9s8F6+lA#b9;%1>>WNcz;W^Q3A0{}qyfj$5L literal 0 HcmV?d00001