Provide properties methods on FileRef, make FileRef non-virtual

Use of FileRef::file() is discouraged, but was necessary to access the
properties. It was also not clear whether to access the properties via
tag() or file(). With the property methods on FileRef, it should become
the "simple usage" interface it was meant to be.
As the destructor was the only virtual method on FileRef, it is now made
non-virtual. Probably, it is not useful as a virtual base class.
This commit is contained in:
Urs Fleisch
2023-10-21 14:47:34 +02:00
parent 11f94903d0
commit 8d98ebf24b
8 changed files with 177 additions and 39 deletions

View File

@ -88,8 +88,8 @@ public:
if(zlib::isAvailable()) {
FileRef f(TEST_FILE_PATH_C("compressed_id3_frame.mp3"), false);
CPPUNIT_ASSERT_EQUAL(StringList(PICTURE_KEY),
f.file()->complexPropertyKeys());
auto pictures = f.file()->complexProperties(PICTURE_KEY);
f.complexPropertyKeys());
auto pictures = f.complexProperties(PICTURE_KEY);
CPPUNIT_ASSERT_EQUAL(1U, pictures.size());
auto picture = pictures.front();
CPPUNIT_ASSERT_EQUAL(86414U,
@ -131,8 +131,8 @@ public:
FileRef f(TEST_FILE_PATH_C("has-tags.m4a"), false);
CPPUNIT_ASSERT_EQUAL(StringList(PICTURE_KEY),
f.file()->complexPropertyKeys());
auto pictures = f.file()->complexProperties(PICTURE_KEY);
f.complexPropertyKeys());
auto pictures = f.complexProperties(PICTURE_KEY);
CPPUNIT_ASSERT_EQUAL(2U, pictures.size());
auto picture = pictures.front();
CPPUNIT_ASSERT_EQUAL(expectedData1,
@ -150,8 +150,8 @@ public:
{
FileRef f(TEST_FILE_PATH_C("lowercase-fields.ogg"), false);
CPPUNIT_ASSERT_EQUAL(StringList(PICTURE_KEY),
f.file()->complexPropertyKeys());
auto pictures = f.file()->complexProperties(PICTURE_KEY);
f.complexPropertyKeys());
auto pictures = f.complexProperties(PICTURE_KEY);
CPPUNIT_ASSERT_EQUAL(1U, pictures.size());
auto picture = pictures.front();
CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"),
@ -243,19 +243,19 @@ public:
{
FileRef f(copy.fileName().c_str(), false);
CPPUNIT_ASSERT(f.file()->complexPropertyKeys().isEmpty());
f.file()->setComplexProperties(PICTURE_KEY, {TEST_PICTURE, picture2});
f.file()->setComplexProperties(GEOB_KEY, {geob1, geob2});
f.file()->save();
CPPUNIT_ASSERT(f.complexPropertyKeys().isEmpty());
f.setComplexProperties(PICTURE_KEY, {TEST_PICTURE, picture2});
f.setComplexProperties(GEOB_KEY, {geob1, geob2});
f.save();
}
{
FileRef f(copy.fileName().c_str(), false);
CPPUNIT_ASSERT_EQUAL(StringList({PICTURE_KEY, GEOB_KEY}),
f.file()->complexPropertyKeys());
f.complexPropertyKeys());
CPPUNIT_ASSERT(List<VariantMap>({TEST_PICTURE, picture2}) ==
f.file()->complexProperties(PICTURE_KEY));
f.complexProperties(PICTURE_KEY));
CPPUNIT_ASSERT(List<VariantMap>({geob1, geob2}) ==
f.file()->complexProperties(GEOB_KEY));
f.complexProperties(GEOB_KEY));
}
}

View File

@ -172,7 +172,7 @@ public:
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::FLAC::Properties));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::FLAC::UnknownMetadataBlock));
CPPUNIT_ASSERT_EQUAL(classSize(0, true), sizeof(TagLib::File));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::FileRef));
CPPUNIT_ASSERT_EQUAL(classSize(1, false), sizeof(TagLib::FileRef));
CPPUNIT_ASSERT_EQUAL(classSize(0, true), sizeof(TagLib::FileRef::FileTypeResolver));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::FileRef::StreamTypeResolver));
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::FileStream));