Fix TagValue::toStandardGenreIndex() for empty genre index

This commit is contained in:
Martchus 2019-02-14 18:18:54 +01:00
parent dbce74444a
commit 296e5d11b6
2 changed files with 5 additions and 3 deletions

View File

@ -239,7 +239,7 @@ int TagValue::toStandardGenreIndex() const
default:
throw ConversionException(argsToString("Can not convert ", tagDataTypeString(m_type), " to genre index."));
}
if (!Id3Genres::isIndexSupported(index)) {
if (!Id3Genres::isEmptyGenre(index) && !Id3Genres::isIndexSupported(index)) {
throw ConversionException("The assigned number is not a valid standard genre index.");
}
return index;

View File

@ -84,8 +84,10 @@ void TagValueTests::testInteger()
CPPUNIT_ASSERT_EQUAL("42"s, integer.toString());
integer.assignInteger(2);
CPPUNIT_ASSERT_EQUAL("Country"s, string(Id3Genres::stringFromIndex(integer.toStandardGenreIndex())));
integer.assignInteger(255);
CPPUNIT_ASSERT_EQUAL(string(), string(Id3Genres::stringFromIndex(integer.toStandardGenreIndex())));
integer.assignInteger(Id3Genres::emptyGenreIndex());
CPPUNIT_ASSERT_EQUAL(Id3Genres::emptyGenreIndex(), integer.toStandardGenreIndex());
integer.clearData();
CPPUNIT_ASSERT_EQUAL(Id3Genres::emptyGenreIndex(), integer.toStandardGenreIndex());
// negative number
integer.assignInteger(-25);