77 CPPUNIT_ASSERT_THROW(binary.
toString(), ConversionException);
78 CPPUNIT_ASSERT_THROW(binary.
toInteger(), ConversionException);
87 CPPUNIT_ASSERT(!integer.isEmpty());
89 CPPUNIT_ASSERT_EQUAL(
static_cast<std::int32_t
>(42), integer.toInteger());
90 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint64_t
>(42), integer.toUnsignedInteger());
91 CPPUNIT_ASSERT_EQUAL(
"42"s, integer.toString());
92 integer.assignInteger(2);
100 integer.assignInteger(-25);
101 CPPUNIT_ASSERT_EQUAL(
"-25"s, integer.toString());
102 CPPUNIT_ASSERT_EQUAL(
PositionInSet(-25), integer.toPositionInSet());
103 CPPUNIT_ASSERT_THROW(integer.toStandardGenreIndex(), ConversionException);
106 integer.assignInteger(0);
107 CPPUNIT_ASSERT_MESSAGE(
"explicitly assigned zero not considered empty", !integer.isEmpty());
108 CPPUNIT_ASSERT_EQUAL(
"0"s, integer.toString());
109 CPPUNIT_ASSERT_EQUAL(
DateTime(), integer.toDateTime());
110 CPPUNIT_ASSERT_EQUAL(
TimeSpan(), integer.toTimeSpan());
114 CPPUNIT_ASSERT_MESSAGE(
"cleared vale considered empty", integer.isEmpty());
115 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"only date (but not type) cleared"s,
TagDataType::Integer, integer.type());
116 CPPUNIT_ASSERT_EQUAL(
static_cast<std::int32_t
>(0), integer.toInteger());
117 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint64_t
>(0), integer.toUnsignedInteger());
118 CPPUNIT_ASSERT_EQUAL(
string(), integer.toString());
119 CPPUNIT_ASSERT_EQUAL(
DateTime(), integer.toDateTime());
120 CPPUNIT_ASSERT_EQUAL(
TimeSpan(), integer.toTimeSpan());
125 auto unsignedInteger =
TagValue(
static_cast<std::uint64_t
>(42ul));
126 CPPUNIT_ASSERT(!unsignedInteger.isEmpty());
128 CPPUNIT_ASSERT_EQUAL(
static_cast<std::int32_t
>(42), unsignedInteger.toInteger());
129 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint64_t
>(42), unsignedInteger.toUnsignedInteger());
130 CPPUNIT_ASSERT_EQUAL(
"42"s, unsignedInteger.toString());
131 unsignedInteger.assignUnsignedInteger(2);
135 unsignedInteger.clearData();
139 unsignedInteger.assignInteger(0);
140 CPPUNIT_ASSERT_MESSAGE(
"explicitly assigned zero not considered empty", !unsignedInteger.isEmpty());
141 CPPUNIT_ASSERT_EQUAL(
"0"s, unsignedInteger.toString());
142 CPPUNIT_ASSERT_EQUAL(
DateTime(), unsignedInteger.toDateTime());
143 CPPUNIT_ASSERT_EQUAL(
TimeSpan(), unsignedInteger.toTimeSpan());
150 CPPUNIT_ASSERT_EQUAL(4, test.
toInteger());
152 CPPUNIT_ASSERT_EQUAL(
"4/23"s, test.
toString());
154 CPPUNIT_ASSERT_THROW(test.
toDateTime(), ConversionException);
155 CPPUNIT_ASSERT_THROW(test.
toTimeSpan(), ConversionException);
160 const TimeSpan fiveMinutes(TimeSpan::fromMinutes(5.0));
163 CPPUNIT_ASSERT_EQUAL(timeSpan,
TagValue(timeSpan));
164 CPPUNIT_ASSERT_EQUAL(fiveMinutes, timeSpan.
toTimeSpan());
165 CPPUNIT_ASSERT_EQUAL(fiveMinutes.toString(), timeSpan.
toString());
166 CPPUNIT_ASSERT_THROW(timeSpan.
toInteger(), ConversionException);
167 CPPUNIT_ASSERT_THROW(timeSpan.
toDateTime(), ConversionException);
173 const auto now = DateTime::now();
175 value.assignDateTime(now);
176 CPPUNIT_ASSERT_EQUAL(value,
TagValue(value));
177 CPPUNIT_ASSERT_EQUAL(now, value.toDateTime());
178 CPPUNIT_ASSERT_EQUAL(now.toIsoString(), value.toString());
179 CPPUNIT_ASSERT_THROW(value.toInteger(), ConversionException);
180 CPPUNIT_ASSERT_THROW(value.toTimeSpan(), ConversionException);
181 CPPUNIT_ASSERT_THROW(value.toPositionInSet(), ConversionException);
186 auto expr = DateTimeExpression::fromIsoString(
"2007");
188 value.assignDateTimeExpression(expr);
189 CPPUNIT_ASSERT_EQUAL(value,
TagValue(expr));
190 CPPUNIT_ASSERT_EQUAL(expr.value, value.toDateTime());
191 CPPUNIT_ASSERT_EQUAL(expr, value.toDateTimeExpression());
192 CPPUNIT_ASSERT_EQUAL(expr.toIsoString(), value.toString());
193 CPPUNIT_ASSERT_THROW(value.toInteger(), ConversionException);
194 CPPUNIT_ASSERT_THROW(value.toTimeSpan(), ConversionException);
195 CPPUNIT_ASSERT_THROW(value.toPositionInSet(), ConversionException);
202 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (user)",
"foo"s, popularity.user);
203 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (rating)", 40.0, popularity.rating);
204 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (play counter)", std::uint64_t(123), popularity.playCounter);
205 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (scale)",
TagType::VorbisComment, popularity.scale);
206 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to string",
"foo|40|123"s, tagValue.toString());
208 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to integer", 40, tagValue.toInteger());
209 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to unsigned integer",
static_cast<std::uint64_t
>(40), tagValue.toUnsignedInteger());
210 CPPUNIT_ASSERT_THROW_MESSAGE(
212 const auto scaledPopularity = tagValue.toScaledPopularity();
213 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"rating scaled to generic scale", 2.0, scaledPopularity.rating);
214 CPPUNIT_ASSERT_THROW_MESSAGE(
215 "failed to scale if no scaling for specified format defined", tagValue.toScaledPopularity(
TagType::Mp4Tag), ConversionException);
227 CPPUNIT_ASSERT_EQUAL_MESSAGE(
229 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"original encoding preserved",
"\0\x31\0\x35"s,
231 CPPUNIT_ASSERT_EQUAL_MESSAGE(
233 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"UTF-16 LE BOM truncated",
"\0t\0\xe4\0s\0t"s,
235 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"UTF-16 BE BOM truncated",
"t\0\xe4\0s\0t\0"s,
237 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion via c'tor",
"15\xe4"s,
243 CPPUNIT_ASSERT_EQUAL_MESSAGE(
245 CPPUNIT_ASSERT_THROW_MESSAGE(
"failing conversion pos",
TagValue(
"a4 / 15", 7,
TagTextEncoding::Utf8).toPositionInSet(), ConversionException);
246 CPPUNIT_ASSERT_EQUAL_MESSAGE(
248 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to date time expression", DateTimeExpression::fromIsoString(
"2004-04"),
250 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to date from UTF-16", DateTime::fromDate(2015, 4, 15),
253 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to time span", TimeSpan::fromHours(1.5),
TagValue(
"01:30:00", 10,
TagTextEncoding::Utf8).toTimeSpan());
254 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to time span from UTF-16", TimeSpan::fromHours(1.5),
257 CPPUNIT_ASSERT_EQUAL_MESSAGE(
260 CPPUNIT_ASSERT_THROW_MESSAGE(
263 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (user)",
"foo"s, popularity.user);
264 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (rating)", 42.0, popularity.rating);
265 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"conversion to popularity (play counter)", std::uint64_t(123), popularity.playCounter);
266 CPPUNIT_ASSERT_THROW_MESSAGE(
"failing conversion to popularity",
TagValue(
"foo|bar"sv).toPopularity(), ConversionException);
271 CPPUNIT_ASSERT_MESSAGE(
"equality requires identical types or identical string representation"s,
TagValue(0) !=
TagValue::empty());
272 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"comparison of equal types"s,
TagValue(15),
TagValue(15));
277 CPPUNIT_ASSERT_MESSAGE(
"comparison of different UTF-16 strings"s,
279 CPPUNIT_ASSERT_EQUAL_MESSAGE(
281 CPPUNIT_ASSERT_MESSAGE(
285 CPPUNIT_ASSERT_EQUAL_MESSAGE(
288 CPPUNIT_ASSERT_MESSAGE(
"string comparison case-sensitive by default"s, fooTagValue != fOoTagValue);
290 const auto popularity =
Popularity{ .user =
"some user", .rating = 200, .playCounter = 0 };
292 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"comparison of equal popularity (string and binary representation)"s,
TagValue(
"some user|200.0"sv), first);
293 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"comparison of equal popularity (only binary representation)"s, first, second);
295 CPPUNIT_ASSERT_MESSAGE(
"popularity not equal"s, first !=
TagValue(
Popularity({ .rating = 200 })));
299 withDescription.setDescription(
"test");
300 CPPUNIT_ASSERT_MESSAGE(
"meta-data must be equal"s, withDescription !=
TagValue(15));
302 TagValue withDescription2(withDescription);
303 CPPUNIT_ASSERT_EQUAL(withDescription, withDescription2);
305 CPPUNIT_ASSERT(withDescription != withDescription2);
306 withDescription.setMimeType(withDescription2.
mimeType());
307 CPPUNIT_ASSERT_EQUAL(withDescription, withDescription2);
309 CPPUNIT_ASSERT_MESSAGE(
"meta-data case must match by default"s, withDescription != withDescription2);
330 for (
const auto &rawZero : { id3zero, vorbisZero }) {
331 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"zero: raw to generic", genericZero.rating, rawZero.scaled(
TagType::Unspecified).rating);
332 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"zero: generic to raw ", rawZero.rating, genericZero.scaled(rawZero.scale).rating);
334 for (
const auto &rawMin : { id3min, vorbisMin, mkvMin }) {
335 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"min: raw to generic", genericMin.rating, rawMin.scaled(
TagType::Unspecified).rating);
336 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"min: generic to raw ", rawMin.rating, genericMin.scaled(rawMin.scale).rating);
338 for (
const auto &rawMax : { id3max, vorbisMax, mkvMax }) {
339 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"max: raw to generic", genericMax.rating, rawMax.scaled(
TagType::Unspecified).rating);
340 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"max: generic to raw ", rawMax.rating, genericMax.scaled(rawMax.scale).rating);
342 for (
const auto &rawMiddle : { id3middle, vorbisMiddle, mkvMiddle }) {
343 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"middle: raw to generic", genericMiddle.rating, rawMiddle.scaled(
TagType::Unspecified).rating);
344 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"middle: generic to raw ", rawMiddle.rating, genericMiddle.scaled(rawMiddle.scale).rating);