From 36d9c94f1f499f22dbedd8a485e39716381a8c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Thu, 14 Jul 2011 14:13:24 +0200 Subject: Add unit tests --- taglib/mpeg/mpegfile.cpp | 6 ++- tests/data/apetag-replaygain-lyrics3v2.mp3 | Bin 0 -> 2300 bytes tests/data/apetag-replaygain.mp3 | Bin 0 -> 2256 bytes tests/data/lyrics3v2.mp3 | Bin 0 -> 1978 bytes tests/test_mpeg.cpp | 75 +++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/data/apetag-replaygain-lyrics3v2.mp3 create mode 100644 tests/data/apetag-replaygain.mp3 create mode 100644 tests/data/lyrics3v2.mp3 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 new file mode 100644 index 00000000..4667c447 Binary files /dev/null and b/tests/data/apetag-replaygain-lyrics3v2.mp3 differ diff --git a/tests/data/apetag-replaygain.mp3 b/tests/data/apetag-replaygain.mp3 new file mode 100644 index 00000000..bd8003ab Binary files /dev/null and b/tests/data/apetag-replaygain.mp3 differ diff --git a/tests/data/lyrics3v2.mp3 b/tests/data/lyrics3v2.mp3 new file mode 100644 index 00000000..0c3301db Binary files /dev/null and b/tests/data/lyrics3v2.mp3 differ 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 #include #include +#include #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); -- cgit v1.2.3