From 73adf26401ac3fc62ea2439f452be66644cdb397 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 1 Jun 2019 12:18:05 +0200 Subject: [PATCH] Fix conversion from PositionInSet to integer Even though there was already a test verifying that it is not possible. --- tagvalue.cpp | 6 +++++- tests/tagvalue.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tagvalue.cpp b/tagvalue.cpp index 573114f..d2dce7c 100644 --- a/tagvalue.cpp +++ b/tagvalue.cpp @@ -192,8 +192,12 @@ std::int32_t TagValue::toInteger() const ensureHostByteOrder(u16str, m_encoding); return ConversionUtilities::stringToNumber(u16str); } - case TagDataType::Integer: case TagDataType::PositionInSet: + if (m_size == sizeof(PositionInSet)) { + return *reinterpret_cast(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(std::int32_t)) { return *reinterpret_cast(m_ptr.get()); diff --git a/tests/tagvalue.cpp b/tests/tagvalue.cpp index 24f9e2a..6db967f 100644 --- a/tests/tagvalue.cpp +++ b/tests/tagvalue.cpp @@ -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);