mirror of
https://github.com/taglib/taglib.git
synced 2026-10-23 16:38:49 -04:00
ASF: Return excess values from setProperties (#1464)
This commit is contained in:
+14
-4
@@ -477,6 +477,16 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props)
|
||||
}
|
||||
|
||||
PropertyMap ignoredProps;
|
||||
const auto setSingleValue = [&ignoredProps](const String &prop,
|
||||
const StringList &values, String &target) {
|
||||
target = values.isEmpty() ? String() : values.front();
|
||||
if(values.size() > 1) {
|
||||
StringList ignoredValues = values;
|
||||
ignoredValues.erase(ignoredValues.begin());
|
||||
ignoredProps.insert(prop, ignoredValues);
|
||||
}
|
||||
};
|
||||
|
||||
for(const auto &[prop, attributes] : props) {
|
||||
if(reverseKeyMap.contains(prop)) {
|
||||
const auto &[name, type] = reverseKeyMap[prop];
|
||||
@@ -542,16 +552,16 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props)
|
||||
}
|
||||
}
|
||||
else if(prop == "TITLE") {
|
||||
d->title = attributes.toString();
|
||||
setSingleValue(prop, attributes, d->title);
|
||||
}
|
||||
else if(prop == "ARTIST") {
|
||||
d->artist = attributes.toString();
|
||||
setSingleValue(prop, attributes, d->artist);
|
||||
}
|
||||
else if(prop == "COMMENT") {
|
||||
d->comment = attributes.toString();
|
||||
setSingleValue(prop, attributes, d->comment);
|
||||
}
|
||||
else if(prop == "COPYRIGHT") {
|
||||
d->copyright = attributes.toString();
|
||||
setSingleValue(prop, attributes, d->copyright);
|
||||
}
|
||||
else {
|
||||
ignoredProps.insert(prop, attributes);
|
||||
|
||||
@@ -51,6 +51,7 @@ class TestASF : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testSavePicture);
|
||||
CPPUNIT_TEST(testSaveMultiplePictures);
|
||||
CPPUNIT_TEST(testProperties);
|
||||
CPPUNIT_TEST(testPropertiesMultipleValues);
|
||||
CPPUNIT_TEST(testPropertiesAllSupported);
|
||||
CPPUNIT_TEST(testPropertiesRealFile);
|
||||
CPPUNIT_TEST(testRating);
|
||||
@@ -309,6 +310,48 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("3"), tags["DISCNUMBER"]);
|
||||
}
|
||||
|
||||
void testPropertiesMultipleValues()
|
||||
{
|
||||
for(const auto &key : {"TITLE", "ARTIST", "COMMENT", "COPYRIGHT"}) {
|
||||
ScopedFileCopy copy("silence-1", ".wma");
|
||||
{
|
||||
ASF::File f(copy.fileName().c_str());
|
||||
PropertyMap props;
|
||||
props[key] = StringList("Alice").append("Bob").append("Carol");
|
||||
props["ALBUM"] = StringList("First").append("Second");
|
||||
|
||||
const PropertyMap ignored = f.setProperties(props);
|
||||
CPPUNIT_ASSERT_EQUAL(1u, ignored.size());
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Bob").append("Carol"), ignored.value(key));
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Alice"), f.properties().value(key));
|
||||
CPPUNIT_ASSERT_EQUAL(props.value("ALBUM"), f.properties().value("ALBUM"));
|
||||
CPPUNIT_ASSERT(f.save());
|
||||
}
|
||||
{
|
||||
ASF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Alice"), f.properties().value(key));
|
||||
const StringList albums = f.properties().value("ALBUM");
|
||||
CPPUNIT_ASSERT_EQUAL(2u, albums.size());
|
||||
CPPUNIT_ASSERT(albums.contains("First"));
|
||||
CPPUNIT_ASSERT(albums.contains("Second"));
|
||||
|
||||
PropertyMap props;
|
||||
props[key] = StringList("Solo");
|
||||
CPPUNIT_ASSERT(f.setProperties(props).isEmpty());
|
||||
CPPUNIT_ASSERT_EQUAL(StringList("Solo"), f.properties().value(key));
|
||||
|
||||
props[key].clear();
|
||||
CPPUNIT_ASSERT(f.setProperties(props).isEmpty());
|
||||
CPPUNIT_ASSERT(!f.properties().contains(key));
|
||||
|
||||
props[key] = StringList("Solo");
|
||||
CPPUNIT_ASSERT(f.setProperties(props).isEmpty());
|
||||
CPPUNIT_ASSERT(f.setProperties(PropertyMap()).isEmpty());
|
||||
CPPUNIT_ASSERT(!f.properties().contains(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testPropertiesAllSupported()
|
||||
{
|
||||
PropertyMap tags;
|
||||
|
||||
Reference in New Issue
Block a user