diff options
-rw-r--r-- | taglib/mpeg/mpegfile.cpp | 6 | ||||
-rw-r--r-- | tests/data/apetag-replaygain-lyrics3v2.mp3 | bin | 0 -> 2300 bytes | |||
-rw-r--r-- | tests/data/apetag-replaygain.mp3 | bin | 0 -> 2256 bytes | |||
-rw-r--r-- | tests/data/lyrics3v2.mp3 | bin | 0 -> 1978 bytes | |||
-rw-r--r-- | tests/test_mpeg.cpp | 75 |
5 files changed, 79 insertions, 2 deletions
diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index 985370c9..54ddecdd 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -234,8 +234,9 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version) // Dont save an APE-tag unless one has been created if((APE & tags) && APETag()) { - if(d->hasAPE) + if(d->hasAPE) { insert(APETag()->render(), d->APELocation, d->APEOriginalSize); + } else { if(d->hasID3v1) { insert(APETag()->render(), d->ID3v1Location, 0); @@ -257,8 +258,9 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version) } } } - else if(d->hasAPE && stripOthers) + else if(d->hasAPE && stripOthers) { success = strip(APE, false) && success; + } return success; } diff --git a/tests/data/apetag-replaygain-lyrics3v2.mp3 b/tests/data/apetag-replaygain-lyrics3v2.mp3 Binary files differnew file mode 100644 index 00000000..4667c447 --- /dev/null +++ b/tests/data/apetag-replaygain-lyrics3v2.mp3 diff --git a/tests/data/apetag-replaygain.mp3 b/tests/data/apetag-replaygain.mp3 Binary files differnew file mode 100644 index 00000000..bd8003ab --- /dev/null +++ b/tests/data/apetag-replaygain.mp3 diff --git a/tests/data/lyrics3v2.mp3 b/tests/data/lyrics3v2.mp3 Binary files differnew file mode 100644 index 00000000..0c3301db --- /dev/null +++ b/tests/data/lyrics3v2.mp3 diff --git a/tests/test_mpeg.cpp b/tests/test_mpeg.cpp index 973803f9..a44f8c9c 100644 --- a/tests/test_mpeg.cpp +++ b/tests/test_mpeg.cpp @@ -3,6 +3,7 @@ #include <stdio.h> #include <mpegfile.h> #include <id3v2tag.h> +#include <apetag.h> #include "utils.h" using namespace std; @@ -15,6 +16,11 @@ class TestMPEG : public CppUnit::TestFixture CPPUNIT_TEST(testSaveID3v24); CPPUNIT_TEST(testSaveID3v24WrongParam); CPPUNIT_TEST(testSaveID3v23); + CPPUNIT_TEST(testReadAPEv2); + CPPUNIT_TEST(testReadAPEv2WithLyrics3v2); + CPPUNIT_TEST(testSaveAPEv2); + CPPUNIT_TEST(testSaveAPEv2WithLyrics3v2); + CPPUNIT_TEST(testSaveAPEv2EmptyWithLyrics3v2); CPPUNIT_TEST_SUITE_END(); public: @@ -76,6 +82,75 @@ public: CPPUNIT_ASSERT_EQUAL(xxx, f2.tag()->title()); } + void testReadAPEv2() + { + ScopedFileCopy copy("apetag-replaygain", ".mp3"); + string newname = copy.fileName(); + + MPEG::File f(newname.c_str()); + String s = f.APETag()->itemListMap()["MP3GAIN_ALBUM_MINMAX"].toString(); + CPPUNIT_ASSERT_EQUAL(String("129,170"), s); + } + + void testReadAPEv2WithLyrics3v2() + { + ScopedFileCopy copy("apetag-replaygain-lyrics3v2", ".mp3"); + string newname = copy.fileName(); + + MPEG::File f(newname.c_str()); + String s = f.APETag()->itemListMap()["MP3GAIN_ALBUM_MINMAX"].toString(); + CPPUNIT_ASSERT_EQUAL(String("129,170"), s); + } + + void testSaveAPEv2() + { + ScopedFileCopy copy("apetag-replaygain", ".mp3"); + string newname = copy.fileName(); + + MPEG::File f(newname.c_str()); + f.APETag()->addValue("MP3GAIN_ALBUM_MINMAX", String("xxx")); + f.save(); + + MPEG::File f2(newname.c_str()); + String s = f2.APETag()->itemListMap()["MP3GAIN_ALBUM_MINMAX"].toString(); + CPPUNIT_ASSERT_EQUAL(String("xxx"), s); + } + + void testSaveAPEv2WithLyrics3v2() + { + ScopedFileCopy copy("apetag-replaygain-lyrics3v2", ".mp3"); + string newname = copy.fileName(); + + MPEG::File f(newname.c_str()); + f.APETag()->addValue("MP3GAIN_ALBUM_MINMAX", String("xxx")); + f.save(); + + MPEG::File f2(newname.c_str()); + String s = f2.APETag()->itemListMap()["MP3GAIN_ALBUM_MINMAX"].toString(); + CPPUNIT_ASSERT_EQUAL(String("xxx"), s); + f2.seek(-9, File::End); + CPPUNIT_ASSERT_EQUAL(ByteVector("LYRICS200"), f2.readBlock(9)); + } + + void testSaveAPEv2EmptyWithLyrics3v2() + { + ScopedFileCopy copy("lyrics3v2", ".mp3", false); + string newname = copy.fileName(); + + { + MPEG::File f(newname.c_str()); + f.APETag(true)->addValue("MP3GAIN_ALBUM_MINMAX", String("xxx")); + f.save(); + } + + MPEG::File f2(newname.c_str()); + CPPUNIT_ASSERT(f2.APETag()); + String s = f2.APETag()->itemListMap()["MP3GAIN_ALBUM_MINMAX"].toString(); + CPPUNIT_ASSERT_EQUAL(String("xxx"), s); + f2.seek(-9, File::End); + CPPUNIT_ASSERT_EQUAL(ByteVector("LYRICS200"), f2.readBlock(9)); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestMPEG); |