Fix conversion from PositionInSet to integer

Even though there was already a test verifying that it is
not possible.
This commit is contained in:
Martchus 2019-06-01 12:18:05 +02:00
parent f687618002
commit ff1eaadc88
2 changed files with 6 additions and 2 deletions

View File

@ -192,8 +192,12 @@ int32 TagValue::toInteger() const
ensureHostByteOrder(u16str, m_encoding);
return ConversionUtilities::stringToNumber<int32>(u16str);
}
case TagDataType::Integer:
case TagDataType::PositionInSet:
if (m_size == sizeof(PositionInSet)) {
return *reinterpret_cast<std::int32_t *>(m_ptr.get());
}
throw ConversionException("Can not convert assigned data to integer because the data size is not appropriate.");
case TagDataType::Integer:
case TagDataType::StandardGenreIndex:
if (m_size == sizeof(int32)) {
return *reinterpret_cast<int32 *>(m_ptr.get());

View File

@ -116,7 +116,7 @@ void TagValueTests::testPositionInSet()
{
const TagValue test(PositionInSet(4, 23));
CPPUNIT_ASSERT_EQUAL(PositionInSet(4, 23), test.toPositionInSet());
CPPUNIT_ASSERT_THROW(test.toInteger(), ConversionException);
CPPUNIT_ASSERT_EQUAL(test.toInteger(), 4);
CPPUNIT_ASSERT_EQUAL("4/23"s, test.toString());
CPPUNIT_ASSERT_THROW(test.toStandardGenreIndex(), ConversionException);
CPPUNIT_ASSERT_THROW(test.toDateTime(), ConversionException);