Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Martchus | 7690807840 | |
Martchus | 1d098c1f50 | |
Martchus | ff1eaadc88 |
|
@ -171,7 +171,7 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
|||
set(META_APP_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags")
|
||||
set(META_VERSION_MAJOR 8)
|
||||
set(META_VERSION_MINOR 3)
|
||||
set(META_VERSION_PATCH 0)
|
||||
set(META_VERSION_PATCH 1)
|
||||
set(META_PUBLIC_SHARED_LIB_DEPENDS c++utilities)
|
||||
set(META_PUBLIC_STATIC_LIB_DEPENDS c++utilities_static)
|
||||
set(META_REQUIRED_CPP_UNIT_VERSION 1.14.0)
|
||||
|
|
28
tagvalue.cpp
28
tagvalue.cpp
|
@ -117,11 +117,19 @@ bool TagValue::operator==(const TagValue &other) const
|
|||
if (m_type == other.m_type) {
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
if (m_size != other.m_size && m_encoding != other.m_encoding) {
|
||||
if (m_size != other.m_size || m_encoding != other.m_encoding) {
|
||||
// don't consider differently encoded text values equal
|
||||
return false;
|
||||
}
|
||||
return strncmp(m_ptr.get(), other.m_ptr.get(), m_size) == 0;
|
||||
if (!m_size) {
|
||||
return true;
|
||||
}
|
||||
for (auto i1 = m_ptr.get(), i2 = other.m_ptr.get(), end = m_ptr.get() + m_size; i1 != end; ++i1, ++i2) {
|
||||
if (*i1 != *i2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case TagDataType::PositionInSet:
|
||||
return toPositionInSet() == other.toPositionInSet();
|
||||
case TagDataType::Integer:
|
||||
|
@ -138,7 +146,15 @@ bool TagValue::operator==(const TagValue &other) const
|
|||
if (m_size != other.m_size) {
|
||||
return false;
|
||||
}
|
||||
return strncmp(m_ptr.get(), other.m_ptr.get(), m_size) == 0;
|
||||
if (!m_size) {
|
||||
return true;
|
||||
}
|
||||
for (auto i1 = m_ptr.get(), i2 = other.m_ptr.get(), end = m_ptr.get() + m_size; i1 != end; ++i1, ++i2) {
|
||||
if (*i1 != *i2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -192,8 +208,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());
|
||||
|
|
|
@ -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);
|
||||
|
@ -195,6 +195,14 @@ void TagValueTests::testEqualityOperator()
|
|||
CPPUNIT_ASSERT_MESSAGE("equality requires identical types or identical string representation"s, TagValue(0) != TagValue::empty());
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("types might differ"s, TagValue(15), TagValue(15));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("types might differ"s, TagValue("15", 2, TagTextEncoding::Latin1), TagValue(15));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("comparision of equal UTF-16 strings"s, TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian),
|
||||
TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian));
|
||||
CPPUNIT_ASSERT_MESSAGE("comparision of different UTF-16 strings"s,
|
||||
TagValue("\x31\0\x33\0", 4, TagTextEncoding::Utf16LittleEndian) != TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
"comparision of equal binary data"s, TagValue("\x31\0\x32\0", 4, TagDataType::Binary), TagValue("\x31\0\x32\0", 4, TagDataType::Binary));
|
||||
CPPUNIT_ASSERT_MESSAGE("comparision of different binary data"s,
|
||||
TagValue("\x31\0\x33\0", 4, TagDataType::Binary) != TagValue("\x31\0\x32\0", 4, TagDataType::Binary));
|
||||
CPPUNIT_ASSERT_MESSAGE("encoding must be equal if relevant for types"s,
|
||||
TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian) != TagValue("15", 2, TagTextEncoding::Latin1));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
|
|
Loading…
Reference in New Issue