mirror of
https://github.com/taglib/taglib.git
synced 2025-07-14 02:54:27 -04:00
New utility class to make sure temporary files are always deleted
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1043988 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
@ -19,12 +19,11 @@ public:
|
||||
|
||||
void testReading()
|
||||
{
|
||||
string filename = copyFile("empty", ".aiff");
|
||||
ScopedFileCopy copy("empty", ".aiff");
|
||||
string filename = copy.fileName();
|
||||
|
||||
RIFF::AIFF::File *f = new RIFF::AIFF::File(filename.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(689, f->audioProperties()->bitrate());
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -39,7 +39,8 @@ public:
|
||||
|
||||
void testSaveMultipleValues()
|
||||
{
|
||||
string newname = copyFile("silence-1", ".wma");
|
||||
ScopedFileCopy copy("silence-1", ".wma");
|
||||
string newname = copy.fileName();
|
||||
|
||||
ASF::File *f = new ASF::File(newname.c_str());
|
||||
ASF::AttributeList values;
|
||||
@ -52,13 +53,12 @@ public:
|
||||
f = new ASF::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(2, (int)f->tag()->attributeListMap()["WM/AlbumTitle"].size());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
void testSaveStream()
|
||||
{
|
||||
string newname = copyFile("silence-1", ".wma");
|
||||
ScopedFileCopy copy("silence-1", ".wma");
|
||||
string newname = copy.fileName();
|
||||
|
||||
ASF::File *f = new ASF::File(newname.c_str());
|
||||
ASF::AttributeList values;
|
||||
@ -72,13 +72,12 @@ public:
|
||||
f = new ASF::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(43, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
void testSaveLanguage()
|
||||
{
|
||||
string newname = copyFile("silence-1", ".wma");
|
||||
ScopedFileCopy copy("silence-1", ".wma");
|
||||
string newname = copy.fileName();
|
||||
|
||||
ASF::File *f = new ASF::File(newname.c_str());
|
||||
ASF::AttributeList values;
|
||||
@ -94,8 +93,6 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(32, f->tag()->attributeListMap()["WM/AlbumTitle"][0].stream());
|
||||
CPPUNIT_ASSERT_EQUAL(56, f->tag()->attributeListMap()["WM/AlbumTitle"][0].language());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
|
||||
void fileRefSave(const string &filename, const string &ext)
|
||||
{
|
||||
string newname = copyFile(filename, ext);
|
||||
ScopedFileCopy copy(filename, ext);
|
||||
string newname = copy.fileName();
|
||||
|
||||
FileRef *f = new FileRef(newname.c_str());
|
||||
CPPUNIT_ASSERT(!f->isNull());
|
||||
@ -77,8 +78,6 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
|
||||
CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
void testMusepack()
|
||||
|
@ -20,7 +20,8 @@ public:
|
||||
|
||||
void testMultipleCommentBlocks()
|
||||
{
|
||||
string newname = copyFile("multiple-vc", ".flac");
|
||||
ScopedFileCopy copy("multiple-vc", ".flac");
|
||||
string newname = copy.fileName();
|
||||
|
||||
FLAC::File *f = new FLAC::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f->tag()->artist());
|
||||
@ -31,8 +32,6 @@ public:
|
||||
f = new FLAC::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -242,7 +242,8 @@ public:
|
||||
|
||||
void testPOPMFromFile()
|
||||
{
|
||||
string newname = copyFile("xing", ".mp3");
|
||||
ScopedFileCopy copy("xing", ".mp3");
|
||||
string newname = copy.fileName();
|
||||
|
||||
ID3v2::PopularimeterFrame *f = new ID3v2::PopularimeterFrame();
|
||||
f->setEmail("email@example.com");
|
||||
@ -256,7 +257,6 @@ public:
|
||||
MPEG::File bar(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("email@example.com"), dynamic_cast<ID3v2::PopularimeterFrame *>(bar.ID3v2Tag()->frameList("POPM").front())->email());
|
||||
CPPUNIT_ASSERT_EQUAL(200, dynamic_cast<ID3v2::PopularimeterFrame *>(bar.ID3v2Tag()->frameList("POPM").front())->rating());
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
// http://bugs.kde.org/show_bug.cgi?id=150481
|
||||
@ -369,7 +369,8 @@ public:
|
||||
void testSaveUTF16Comment()
|
||||
{
|
||||
String::Type defaultEncoding = ID3v2::FrameFactory::instance()->defaultTextEncoding();
|
||||
string newname = copyFile("xing", ".mp3");
|
||||
ScopedFileCopy copy("xing", ".mp3");
|
||||
string newname = copy.fileName();
|
||||
ID3v2::FrameFactory::instance()->setDefaultTextEncoding(String::UTF16);
|
||||
MPEG::File foo(newname.c_str());
|
||||
foo.strip();
|
||||
@ -377,7 +378,6 @@ public:
|
||||
foo.save();
|
||||
MPEG::File bar(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("Test comment!"), bar.tag()->comment());
|
||||
deleteFile(newname);
|
||||
ID3v2::FrameFactory::instance()->setDefaultTextEncoding(defaultEncoding);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
|
||||
void testUpdateStco()
|
||||
{
|
||||
string filename = copyFile("no-tags", ".3g2");
|
||||
ScopedFileCopy copy("no-tags", ".3g2");
|
||||
string filename = copy.fileName();
|
||||
|
||||
MP4::File *f = new MP4::File(filename.c_str());
|
||||
f->tag()->setArtist(ByteVector(3000, 'x'));
|
||||
@ -80,13 +81,12 @@ public:
|
||||
}
|
||||
|
||||
delete f;
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
void testFreeForm()
|
||||
{
|
||||
string filename = copyFile("has-tags", ".m4a");
|
||||
ScopedFileCopy copy("has-tags", ".m4a");
|
||||
string filename = copy.fileName();
|
||||
|
||||
MP4::File *f = new MP4::File(filename.c_str());
|
||||
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("----:com.apple.iTunes:iTunNORM"));
|
||||
@ -99,13 +99,12 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(String("Bar"), f->tag()->itemListMap()["----:org.kde.TagLib:Foo"].toStringList()[0]);
|
||||
f->save();
|
||||
delete f;
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
void testSaveExisingWhenIlstIsLast()
|
||||
{
|
||||
string filename = copyFile("ilst-is-last", ".m4a");
|
||||
ScopedFileCopy copy("ilst-is-last", ".m4a");
|
||||
string filename = copy.fileName();
|
||||
|
||||
MP4::File *f = new MP4::File(filename.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("82,164"), f->tag()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]);
|
||||
@ -118,13 +117,12 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(String("82,164"), f->tag()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]);
|
||||
CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist());
|
||||
CPPUNIT_ASSERT_EQUAL(String("foo"), f->tag()->comment());
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
void test64BitAtom()
|
||||
{
|
||||
string filename = copyFile("64bit", ".mp4");
|
||||
ScopedFileCopy copy("64bit", ".mp4");
|
||||
string filename = copy.fileName();
|
||||
|
||||
MP4::File *f = new MP4::File(filename.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(true, f->tag()->itemListMap()["cpil"].toBool());
|
||||
@ -144,8 +142,6 @@ public:
|
||||
moov = atoms->atoms[0];
|
||||
// original size + 'pgap' size + padding
|
||||
CPPUNIT_ASSERT_EQUAL(long(77 + 25 + 974), moov->length);
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
void testGnre()
|
||||
@ -168,7 +164,8 @@ public:
|
||||
|
||||
void testCovrWrite()
|
||||
{
|
||||
string filename = copyFile("has-tags", ".m4a");
|
||||
ScopedFileCopy copy("has-tags", ".m4a");
|
||||
string filename = copy.fileName();
|
||||
|
||||
MP4::File *f = new MP4::File(filename.c_str());
|
||||
CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr"));
|
||||
@ -189,8 +186,6 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format());
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l[2].data().size());
|
||||
delete f;
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -23,7 +23,8 @@ public:
|
||||
|
||||
void testSimple()
|
||||
{
|
||||
string newname = copyFile("empty", ".ogg");
|
||||
ScopedFileCopy copy("empty", ".ogg");
|
||||
string newname = copy.fileName();
|
||||
|
||||
Vorbis::File *f = new Vorbis::File(newname.c_str());
|
||||
f->tag()->setArtist("The Artist");
|
||||
@ -33,13 +34,12 @@ public:
|
||||
f = new Vorbis::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
void testSplitPackets()
|
||||
{
|
||||
string newname = copyFile("empty", ".ogg");
|
||||
ScopedFileCopy copy("empty", ".ogg");
|
||||
string newname = copy.fileName();
|
||||
|
||||
Vorbis::File *f = new Vorbis::File(newname.c_str());
|
||||
f->tag()->addField("test", ByteVector(128 * 1024, 'x') + ByteVector(1, '\0'));
|
||||
@ -49,8 +49,6 @@ public:
|
||||
f = new Vorbis::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(19, f->lastPageHeader()->pageSequenceNumber());
|
||||
delete f;
|
||||
|
||||
deleteFile(newname);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -21,7 +21,8 @@ public:
|
||||
|
||||
void testFramingBit()
|
||||
{
|
||||
string newname = copyFile("empty_flac", ".oga");
|
||||
ScopedFileCopy copy("empty_flac", ".oga");
|
||||
string newname = copy.fileName();
|
||||
|
||||
Ogg::FLAC::File *f = new Ogg::FLAC::File(newname.c_str());
|
||||
f->tag()->setArtist("The Artist");
|
||||
@ -36,7 +37,6 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(9134, size);
|
||||
|
||||
delete f;
|
||||
//deleteFile(newname);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -35,7 +35,8 @@ public:
|
||||
|
||||
void testPadding()
|
||||
{
|
||||
string filename = copyFile("empty", ".aiff");
|
||||
ScopedFileCopy copy("empty", ".aiff");
|
||||
string filename = copy.fileName();
|
||||
|
||||
PublicRIFF *f = new PublicRIFF(filename.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
|
||||
@ -72,8 +73,6 @@ public:
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2));
|
||||
|
||||
deleteFile(filename);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -25,3 +25,25 @@ inline void deleteFile(const string &filename)
|
||||
{
|
||||
remove(filename.c_str());
|
||||
}
|
||||
|
||||
class ScopedFileCopy
|
||||
{
|
||||
public:
|
||||
ScopedFileCopy(const string &filename, const string &ext)
|
||||
{
|
||||
m_filename = copyFile(filename, ext);
|
||||
}
|
||||
|
||||
~ScopedFileCopy()
|
||||
{
|
||||
deleteFile(m_filename);
|
||||
}
|
||||
|
||||
string fileName()
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
private:
|
||||
string m_filename;
|
||||
};
|
||||
|
Reference in New Issue
Block a user