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);
}
};
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;
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;
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;
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);
}
};
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());
CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
delete f;
-
- deleteFile(newname);
}
void testMusepack()
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());
f = new FLAC::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
delete f;
-
- deleteFile(newname);
}
};
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");
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
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();
foo.save();
MPEG::File bar(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("Test comment!"), bar.tag()->comment());
- deleteFile(newname);
ID3v2::FrameFactory::instance()->setDefaultTextEncoding(defaultEncoding);
}
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'));
}
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"));
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]);
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());
moov = atoms->atoms[0];
// original size + 'pgap' size + padding
CPPUNIT_ASSERT_EQUAL(long(77 + 25 + 974), moov->length);
-
- deleteFile(filename);
}
void testGnre()
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"));
CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l[2].data().size());
delete f;
-
- deleteFile(filename);
}
};
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");
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'));
f = new Vorbis::File(newname.c_str());
CPPUNIT_ASSERT_EQUAL(19, f->lastPageHeader()->pageSequenceNumber());
delete f;
-
- deleteFile(newname);
}
};
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");
CPPUNIT_ASSERT_EQUAL(9134, size);
delete f;
- //deleteFile(newname);
}
};
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));
CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2));
CPPUNIT_ASSERT_EQUAL(ByteVector("foo"), f->chunkData(2));
-
- deleteFile(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;
+};