Tag Parser 11.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
tagvalue.cpp
Go to the documentation of this file.
1#include "./helper.h"
2
3#include "../id3/id3genres.h"
4#include "../tagvalue.h"
5
6#include <c++utilities/chrono/format.h>
7#include <c++utilities/conversion/conversionexception.h>
8
9using namespace CppUtilities;
10
11#include <cppunit/TestFixture.h>
12#include <cppunit/extensions/HelperMacros.h>
13
14using namespace std;
15using namespace CppUtilities;
16using namespace TagParser;
17using namespace CPPUNIT_NS;
18
22class TagValueTests : public TestFixture {
23 CPPUNIT_TEST_SUITE(TagValueTests);
24 CPPUNIT_TEST(testBasics);
25 CPPUNIT_TEST(testBinary);
26 CPPUNIT_TEST(testInteger);
27 CPPUNIT_TEST(testUnsignedInteger);
28 CPPUNIT_TEST(testPositionInSet);
29 CPPUNIT_TEST(testTimeSpan);
30 CPPUNIT_TEST(testDateTime);
31 CPPUNIT_TEST(testPopularity);
32 CPPUNIT_TEST(testString);
33 CPPUNIT_TEST(testEqualityOperator);
34 CPPUNIT_TEST(testPopularityScaling);
35 CPPUNIT_TEST_SUITE_END();
36
37public:
38 void setUp() override;
39 void tearDown() override;
40
41 void testBasics();
42 void testBinary();
43 void testInteger();
45 void testPositionInSet();
46 void testTimeSpan();
47 void testDateTime();
48 void testPopularity();
49 void testString();
52};
53
55
57{
58}
59
61{
62}
63
65{
66 CPPUNIT_ASSERT(TagValue::empty().isEmpty());
67 CPPUNIT_ASSERT_EQUAL(TagDataType::Undefined, TagValue().type());
68}
69
71{
72 const TagValue binary("123", 3, TagDataType::Binary);
73 CPPUNIT_ASSERT_EQUAL(TagDataType::Binary, binary.type());
74 CPPUNIT_ASSERT_EQUAL("123"s, string(binary.dataPointer(), binary.dataSize()));
75 CPPUNIT_ASSERT_THROW(binary.toString(), ConversionException);
76 CPPUNIT_ASSERT_THROW(binary.toInteger(), ConversionException);
77 CPPUNIT_ASSERT_THROW(binary.toPositionInSet(), ConversionException);
78 CPPUNIT_ASSERT_THROW(binary.toStandardGenreIndex(), ConversionException);
79}
80
82{
83 // positive number
84 auto integer = TagValue(42);
85 CPPUNIT_ASSERT(!integer.isEmpty());
86 CPPUNIT_ASSERT_EQUAL(TagDataType::Integer, integer.type());
87 CPPUNIT_ASSERT_EQUAL(static_cast<std::int32_t>(42), integer.toInteger());
88 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(42), integer.toUnsignedInteger());
89 CPPUNIT_ASSERT_EQUAL("42"s, integer.toString());
90 integer.assignInteger(2);
91 CPPUNIT_ASSERT_EQUAL("Country"s, string(Id3Genres::stringFromIndex(integer.toStandardGenreIndex())));
92 integer.assignInteger(Id3Genres::emptyGenreIndex());
93 CPPUNIT_ASSERT_EQUAL(Id3Genres::emptyGenreIndex(), integer.toStandardGenreIndex());
94 integer.clearData();
95 CPPUNIT_ASSERT_EQUAL(Id3Genres::emptyGenreIndex(), integer.toStandardGenreIndex());
96
97 // negative number
98 integer.assignInteger(-25);
99 CPPUNIT_ASSERT_EQUAL("-25"s, integer.toString());
100 CPPUNIT_ASSERT_EQUAL(PositionInSet(-25), integer.toPositionInSet());
101 CPPUNIT_ASSERT_THROW(integer.toStandardGenreIndex(), ConversionException);
102
103 // zero
104 integer.assignInteger(0);
105 CPPUNIT_ASSERT_MESSAGE("explicitly assigned zero not considered empty", !integer.isEmpty());
106 CPPUNIT_ASSERT_EQUAL("0"s, integer.toString());
107 CPPUNIT_ASSERT_EQUAL(DateTime(), integer.toDateTime());
108 CPPUNIT_ASSERT_EQUAL(TimeSpan(), integer.toTimeSpan());
109
110 // empty value treatet as zero when using to...() methods
111 integer.clearData();
112 CPPUNIT_ASSERT_MESSAGE("cleared vale considered empty", integer.isEmpty());
113 CPPUNIT_ASSERT_EQUAL_MESSAGE("only date (but not type) cleared"s, TagDataType::Integer, integer.type());
114 CPPUNIT_ASSERT_EQUAL(static_cast<std::int32_t>(0), integer.toInteger());
115 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(0), integer.toUnsignedInteger());
116 CPPUNIT_ASSERT_EQUAL(string(), integer.toString());
117 CPPUNIT_ASSERT_EQUAL(DateTime(), integer.toDateTime());
118 CPPUNIT_ASSERT_EQUAL(TimeSpan(), integer.toTimeSpan());
119}
120
122{
123 auto unsignedInteger = TagValue(static_cast<std::uint64_t>(42ul));
124 CPPUNIT_ASSERT(!unsignedInteger.isEmpty());
125 CPPUNIT_ASSERT_EQUAL(TagDataType::UnsignedInteger, unsignedInteger.type());
126 CPPUNIT_ASSERT_EQUAL(static_cast<std::int32_t>(42), unsignedInteger.toInteger());
127 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(42), unsignedInteger.toUnsignedInteger());
128 CPPUNIT_ASSERT_EQUAL("42"s, unsignedInteger.toString());
129 unsignedInteger.assignUnsignedInteger(2);
130 CPPUNIT_ASSERT_EQUAL("Country"s, string(Id3Genres::stringFromIndex(unsignedInteger.toStandardGenreIndex())));
131 unsignedInteger.assignInteger(Id3Genres::emptyGenreIndex());
132 CPPUNIT_ASSERT_EQUAL(Id3Genres::emptyGenreIndex(), unsignedInteger.toStandardGenreIndex());
133 unsignedInteger.clearData();
134 CPPUNIT_ASSERT_EQUAL(Id3Genres::emptyGenreIndex(), unsignedInteger.toStandardGenreIndex());
135
136 // zero
137 unsignedInteger.assignInteger(0);
138 CPPUNIT_ASSERT_MESSAGE("explicitly assigned zero not considered empty", !unsignedInteger.isEmpty());
139 CPPUNIT_ASSERT_EQUAL("0"s, unsignedInteger.toString());
140 CPPUNIT_ASSERT_EQUAL(DateTime(), unsignedInteger.toDateTime());
141 CPPUNIT_ASSERT_EQUAL(TimeSpan(), unsignedInteger.toTimeSpan());
142}
143
145{
146 const TagValue test(PositionInSet(4, 23));
147 CPPUNIT_ASSERT_EQUAL(PositionInSet(4, 23), test.toPositionInSet());
148 CPPUNIT_ASSERT_EQUAL(4, test.toInteger());
149 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(4), test.toUnsignedInteger());
150 CPPUNIT_ASSERT_EQUAL("4/23"s, test.toString());
151 CPPUNIT_ASSERT_THROW(test.toStandardGenreIndex(), ConversionException);
152 CPPUNIT_ASSERT_THROW(test.toDateTime(), ConversionException);
153 CPPUNIT_ASSERT_THROW(test.toTimeSpan(), ConversionException);
154}
155
157{
158 const TimeSpan fiveMinutes(TimeSpan::fromMinutes(5));
159 TagValue timeSpan;
160 timeSpan.assignTimeSpan(fiveMinutes);
161 CPPUNIT_ASSERT_EQUAL(timeSpan, TagValue(timeSpan));
162 CPPUNIT_ASSERT_EQUAL(fiveMinutes, timeSpan.toTimeSpan());
163 CPPUNIT_ASSERT_EQUAL(fiveMinutes.toString(), timeSpan.toString());
164 CPPUNIT_ASSERT_THROW(timeSpan.toInteger(), ConversionException);
165 CPPUNIT_ASSERT_THROW(timeSpan.toDateTime(), ConversionException);
166 CPPUNIT_ASSERT_THROW(timeSpan.toPositionInSet(), ConversionException);
167}
168
170{
171 const DateTime now(DateTime::now());
172 TagValue dateTime;
173 dateTime.assignDateTime(now);
174 CPPUNIT_ASSERT_EQUAL(dateTime, TagValue(dateTime));
175 CPPUNIT_ASSERT_EQUAL(now, dateTime.toDateTime());
176 CPPUNIT_ASSERT_EQUAL(now.toString(DateTimeOutputFormat::IsoOmittingDefaultComponents), dateTime.toString());
177 CPPUNIT_ASSERT_THROW(dateTime.toInteger(), ConversionException);
178 CPPUNIT_ASSERT_THROW(dateTime.toTimeSpan(), ConversionException);
179 CPPUNIT_ASSERT_THROW(dateTime.toPositionInSet(), ConversionException);
180}
181
183{
184 const auto tagValue = TagValue(Popularity{ .user = "foo", .rating = 40.0, .playCounter = 123, .scale = TagType::VorbisComment });
185 const auto popularity = tagValue.toPopularity();
186 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (user)", "foo"s, popularity.user);
187 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (rating)", 40.0, popularity.rating);
188 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (play counter)", std::uint64_t(123), popularity.playCounter);
189 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (scale)", TagType::VorbisComment, popularity.scale);
190 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to string", "foo|40|123"s, tagValue.toString());
191 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to string (only rating)", "43"s, TagValue(Popularity{ .rating = 43 }).toString());
192 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to integer", 40, tagValue.toInteger());
193 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to unsigned integer", static_cast<std::uint64_t>(40), tagValue.toUnsignedInteger());
194 CPPUNIT_ASSERT_THROW_MESSAGE(
195 "failing conversion to other type", TagValue("foo|bar"sv, TagTextEncoding::Latin1).toPopularity(), ConversionException);
196 const auto scaledPopularity = tagValue.toScaledPopularity();
197 CPPUNIT_ASSERT_EQUAL_MESSAGE("rating scaled to generic scale", 2.0, scaledPopularity.rating);
198 CPPUNIT_ASSERT_THROW_MESSAGE(
199 "failed to scale if no scaling for specified format defined", tagValue.toScaledPopularity(TagType::Mp4Tag), ConversionException);
200}
201
203{
204 CPPUNIT_ASSERT_EQUAL("15\xe4"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Latin1));
205 CPPUNIT_ASSERT_EQUAL("15\xe4"s, TagValue("15ä", TagTextEncoding::Utf8, TagTextEncoding::Latin1).toString());
206 CPPUNIT_ASSERT_EQUAL("15ä"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Utf8));
207 CPPUNIT_ASSERT_EQUAL("\x31\0\x35\0"s, TagValue(15).toString(TagTextEncoding::Utf16LittleEndian));
208 CPPUNIT_ASSERT_EQUAL("\0\x31\0\x35"s, TagValue(15).toString(TagTextEncoding::Utf16BigEndian));
209 CPPUNIT_ASSERT_EQUAL(15, TagValue("\0\x31\0\x35"s, TagTextEncoding::Utf16BigEndian).toInteger());
210 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(15), TagValue("\0\x31\0\x35"s, TagTextEncoding::Utf16BigEndian).toUnsignedInteger());
211 CPPUNIT_ASSERT_EQUAL_MESSAGE(
212 "original encoding preserved", "15ä"s, TagValue("15ä", 4, TagTextEncoding::Utf8).toString(TagTextEncoding::Unspecified));
213 CPPUNIT_ASSERT_EQUAL_MESSAGE("original encoding preserved", "\0\x31\0\x35"s,
214 TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian).toString(TagTextEncoding::Unspecified));
215 CPPUNIT_ASSERT_EQUAL_MESSAGE(
216 "UTF-8 BOM truncated", "täst"s, TagValue("\xef\xbb\xbftäst", 8, TagTextEncoding::Utf8).toString(TagTextEncoding::Unspecified));
217 CPPUNIT_ASSERT_EQUAL_MESSAGE("UTF-16 LE BOM truncated", "\0t\0\xe4\0s\0t"s,
218 TagValue("\xff\xfe\0t\0\xe4\0s\0t", 10, TagTextEncoding::Utf16LittleEndian).toString(TagTextEncoding::Unspecified));
219 CPPUNIT_ASSERT_EQUAL_MESSAGE("UTF-16 BE BOM truncated", "t\0\xe4\0s\0t\0"s,
220 TagValue("\xfe\xfft\0\xe4\0s\0t\0", 10, TagTextEncoding::Utf16BigEndian).toString(TagTextEncoding::Unspecified));
221 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion via c'tor", "15\xe4"s,
222 TagValue("\xef\xbb\xbf\x31\x35ä", 7, TagTextEncoding::Utf8, TagTextEncoding::Latin1).toString(TagTextEncoding::Unspecified));
223 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to int", -15, TagValue(" - 156", 5, TagTextEncoding::Utf8).toInteger());
224 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to int", 15, TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian).toInteger());
225 CPPUNIT_ASSERT_THROW_MESSAGE("failing conversion to int", TagValue("15ä", 4, TagTextEncoding::Utf8).toInteger(), ConversionException);
226 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to pos", PositionInSet(4, 15), TagValue("4 / 15", 6, TagTextEncoding::Utf8).toPositionInSet());
227 CPPUNIT_ASSERT_EQUAL_MESSAGE(
228 "conversion to pos", PositionInSet(15), TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian).toPositionInSet());
229 CPPUNIT_ASSERT_THROW_MESSAGE("failing conversion pos", TagValue("a4 / 15", 7, TagTextEncoding::Utf8).toPositionInSet(), ConversionException);
230 CPPUNIT_ASSERT_EQUAL_MESSAGE(
231 "conversion to date", DateTime::fromDate(2004, 4, 15), TagValue("2004-04-15", 10, TagTextEncoding::Utf8).toDateTime());
232 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to date from UTF-16", DateTime::fromDate(2015, 4, 15),
233 TagValue("\0\x32\0\x30\0\x31\0\x35\0\x2d\0\x30\0\x34\0\x2d\0\x31\0\x35", 20, TagTextEncoding::Utf16BigEndian).toDateTime());
234 CPPUNIT_ASSERT_THROW_MESSAGE("failing conversion to date", TagValue("_", 1, TagTextEncoding::Utf8).toDateTime(), ConversionException);
235 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to time span", TimeSpan::fromHours(1.5), TagValue("01:30:00", 10, TagTextEncoding::Utf8).toTimeSpan());
236 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to time span from UTF-16", TimeSpan::fromHours(1.5),
237 TagValue("\0\x31\0\x3a\0\x33\0\x30\0\x3a\0\x30\0\x30", 14, TagTextEncoding::Utf16BigEndian).toTimeSpan());
238 CPPUNIT_ASSERT_THROW_MESSAGE("failing conversion to time span", TagValue("_", 1, TagTextEncoding::Utf8).toTimeSpan(), ConversionException);
239 CPPUNIT_ASSERT_EQUAL_MESSAGE(
240 "conversion to genre from index", 15, TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian).toStandardGenreIndex());
241 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to genre from name", 2, TagValue("Country", 7, TagTextEncoding::Latin1).toStandardGenreIndex());
242 CPPUNIT_ASSERT_THROW_MESSAGE(
243 "failing conversion to genre", TagValue("Kountry", 7, TagTextEncoding::Latin1).toStandardGenreIndex(), ConversionException);
244 const auto popularity = TagValue("foo|42|123"sv).toPopularity();
245 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (user)", "foo"s, popularity.user);
246 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (rating)", 42.0, popularity.rating);
247 CPPUNIT_ASSERT_EQUAL_MESSAGE("conversion to popularity (play counter)", std::uint64_t(123), popularity.playCounter);
248 CPPUNIT_ASSERT_THROW_MESSAGE("failing conversion to popularity", TagValue("foo|bar"sv).toPopularity(), ConversionException);
249}
250
252{
253 CPPUNIT_ASSERT_MESSAGE("equality requires identical types or identical string representation"s, TagValue(0) != TagValue::empty());
254 CPPUNIT_ASSERT_EQUAL_MESSAGE("comparison of equal types"s, TagValue(15), TagValue(15));
255 CPPUNIT_ASSERT_EQUAL_MESSAGE("types might differ"s, TagValue("15", 2, TagTextEncoding::Latin1), TagValue(15));
256 CPPUNIT_ASSERT_MESSAGE("but some types shall never be considered equal"s, TagValue(DateTime(0)) != TagValue(TimeSpan(0)));
257 CPPUNIT_ASSERT_EQUAL_MESSAGE("comparison of equal UTF-16 strings"s, TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian),
258 TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian));
259 CPPUNIT_ASSERT_MESSAGE("comparison of different UTF-16 strings"s,
260 TagValue("\x31\0\x33\0", 4, TagTextEncoding::Utf16LittleEndian) != TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian));
261 CPPUNIT_ASSERT_EQUAL_MESSAGE(
262 "comparison of equal binary data"s, TagValue("\x31\0\x32\0", 4, TagDataType::Binary), TagValue("\x31\0\x32\0", 4, TagDataType::Binary));
263 CPPUNIT_ASSERT_MESSAGE(
264 "comparison of different binary data"s, TagValue("\x31\0\x33\0", 4, TagDataType::Binary) != TagValue("\x31\0\x32\0", 4, TagDataType::Binary));
265 CPPUNIT_ASSERT_EQUAL_MESSAGE("different encodings are converted if neccassary"s, TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian),
266 TagValue("15", 2, TagTextEncoding::Latin1));
267 CPPUNIT_ASSERT_EQUAL_MESSAGE(
268 "encoding is ignored when not relevant for types"s, TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian), TagValue(15));
269 const TagValue fooTagValue("foo", 3, TagDataType::Text), fOoTagValue("fOo", 3, TagDataType::Text);
270 CPPUNIT_ASSERT_MESSAGE("string comparison case-sensitive by default"s, fooTagValue != fOoTagValue);
271 CPPUNIT_ASSERT_MESSAGE("case-insensitive string comparison"s, fooTagValue.compareTo(fOoTagValue, TagValueComparisionFlags::CaseInsensitive));
272 const auto popularity = Popularity{ .user = "some user", .rating = 200, .playCounter = 0 };
273 const auto first = TagValue(popularity), second = TagValue(popularity);
274 CPPUNIT_ASSERT_EQUAL_MESSAGE("comparison of equal popularity (string and binary representation)"s, TagValue("some user|200.0"sv), first);
275 CPPUNIT_ASSERT_EQUAL_MESSAGE("comparison of equal popularity (only binary representation)"s, first, second);
276 CPPUNIT_ASSERT_MESSAGE("default-popularity not equal to empty tag value"s, TagValue(Popularity()) != TagValue());
277 CPPUNIT_ASSERT_MESSAGE("popularity not equal"s, first != TagValue(Popularity({ .rating = 200 })));
278
279 // meta-data
280 TagValue withDescription(15);
281 withDescription.setDescription("test");
282 CPPUNIT_ASSERT_MESSAGE("meta-data must be equal"s, withDescription != TagValue(15));
283 CPPUNIT_ASSERT_MESSAGE("different meta-data ignored"s, withDescription.compareTo(TagValue(15), TagValueComparisionFlags::IgnoreMetaData));
284 TagValue withDescription2(withDescription);
285 CPPUNIT_ASSERT_EQUAL(withDescription, withDescription2);
286 withDescription2.setMimeType("foo/bar");
287 CPPUNIT_ASSERT(withDescription != withDescription2);
288 withDescription.setMimeType(withDescription2.mimeType());
289 CPPUNIT_ASSERT_EQUAL(withDescription, withDescription2);
290 withDescription2.setDescription("Test");
291 CPPUNIT_ASSERT_MESSAGE("meta-data case must match by default"s, withDescription != withDescription2);
292 CPPUNIT_ASSERT_MESSAGE("meta-data case ignored"s, withDescription.compareTo(withDescription2, TagValueComparisionFlags::CaseInsensitive));
293}
294
296{
297 const auto genericZero = Popularity{ .rating = 0.0, .scale = TagType::Unspecified };
298 const auto genericMin = Popularity{ .rating = 1.0, .scale = TagType::Unspecified };
299 const auto genericMax = Popularity{ .rating = 5.0, .scale = TagType::Unspecified };
300 const auto genericMiddle = Popularity{ .rating = 3.0, .scale = TagType::Unspecified };
301 const auto id3zero = Popularity{ .rating = 0.0, .scale = TagType::Id3v2Tag };
302 const auto id3min = Popularity{ .rating = 1.0, .scale = TagType::Id3v2Tag };
303 const auto id3max = Popularity{ .rating = 255.0, .scale = TagType::Id3v2Tag };
304 const auto id3middle = Popularity{ .rating = 128.0, .scale = TagType::Id3v2Tag };
305 const auto vorbisZero = Popularity{ .rating = 0.0, .scale = TagType::VorbisComment };
306 const auto vorbisMin = Popularity{ .rating = 20.0, .scale = TagType::VorbisComment };
307 const auto vorbisMax = Popularity{ .rating = 100.0, .scale = TagType::OggVorbisComment };
308 const auto vorbisMiddle = Popularity{ .rating = 60.0, .scale = TagType::OggVorbisComment };
309 const auto mkvMin = Popularity{ .rating = 0.0, .scale = TagType::MatroskaTag };
310 const auto mkvMax = Popularity{ .rating = 5.0, .scale = TagType::MatroskaTag };
311 const auto mkvMiddle = Popularity{ .rating = 2.5, .scale = TagType::MatroskaTag };
312 for (const auto &rawZero : { id3zero, vorbisZero }) {
313 CPPUNIT_ASSERT_EQUAL_MESSAGE("zero: raw to generic", genericZero.rating, rawZero.scaled(TagType::Unspecified).rating);
314 CPPUNIT_ASSERT_EQUAL_MESSAGE("zero: generic to raw ", rawZero.rating, genericZero.scaled(rawZero.scale).rating);
315 }
316 for (const auto &rawMin : { id3min, vorbisMin, mkvMin }) {
317 CPPUNIT_ASSERT_EQUAL_MESSAGE("min: raw to generic", genericMin.rating, rawMin.scaled(TagType::Unspecified).rating);
318 CPPUNIT_ASSERT_EQUAL_MESSAGE("min: generic to raw ", rawMin.rating, genericMin.scaled(rawMin.scale).rating);
319 }
320 for (const auto &rawMax : { id3max, vorbisMax, mkvMax }) {
321 CPPUNIT_ASSERT_EQUAL_MESSAGE("max: raw to generic", genericMax.rating, rawMax.scaled(TagType::Unspecified).rating);
322 CPPUNIT_ASSERT_EQUAL_MESSAGE("max: generic to raw ", rawMax.rating, genericMax.scaled(rawMax.scale).rating);
323 }
324 for (const auto &rawMiddle : { id3middle, vorbisMiddle, mkvMiddle }) {
325 CPPUNIT_ASSERT_EQUAL_MESSAGE("middle: raw to generic", genericMiddle.rating, rawMiddle.scaled(TagType::Unspecified).rating);
326 CPPUNIT_ASSERT_EQUAL_MESSAGE("middle: generic to raw ", rawMiddle.rating, genericMiddle.scaled(rawMiddle.scale).rating);
327 }
328}
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:21
The TagValue class wraps values of different types.
Definition: tagvalue.h:142
void setMimeType(std::string_view mimeType)
Sets the MIME type.
Definition: tagvalue.h:709
const std::string & mimeType() const
Returns the MIME type.
Definition: tagvalue.h:697
bool compareTo(const TagValue &other, TagValueComparisionFlags options=TagValueComparisionFlags::None) const
Returns whether both instances are equal.
Definition: tagvalue.cpp:208
CppUtilities::DateTime toDateTime() const
Converts the value of the current TagValue object to its equivalent DateTime representation.
Definition: tagvalue.cpp:614
void setDescription(std::string_view value, TagTextEncoding encoding=TagTextEncoding::Latin1)
Sets the description.
Definition: tagvalue.h:684
std::uint64_t toUnsignedInteger() const
Definition: tagvalue.cpp:433
std::int32_t toInteger() const
Converts the value of the current TagValue object to its equivalent integer representation.
Definition: tagvalue.cpp:391
PositionInSet toPositionInSet() const
Converts the value of the current TagValue object to its equivalent PositionInSet representation.
Definition: tagvalue.cpp:526
TagDataType type() const
Returns the type of the assigned value.
Definition: tagvalue.h:540
void assignTimeSpan(CppUtilities::TimeSpan value)
Assigns the given TimeSpan value.
Definition: tagvalue.h:513
Popularity toPopularity() const
Converts the value of the current TagValue object to its equivalent Popularity representation.
Definition: tagvalue.cpp:656
void assignDateTime(CppUtilities::DateTime value)
Assigns the given DateTime value.
Definition: tagvalue.h:521
std::size_t dataSize() const
Returns the size of the assigned value in bytes.
Definition: tagvalue.h:629
std::string toString(TagTextEncoding encoding=TagTextEncoding::Unspecified) const
Converts the value of the current TagValue object to its equivalent std::string representation.
Definition: tagvalue.h:557
int toStandardGenreIndex() const
Converts the value of the current TagValue object to its equivalent standard genre index.
Definition: tagvalue.cpp:476
CppUtilities::TimeSpan toTimeSpan() const
Converts the value of the current TagValue object to its equivalent TimeSpan representation.
Definition: tagvalue.cpp:575
char * dataPointer()
Returns a pointer to the raw data assigned to the current instance.
Definition: tagvalue.h:640
The TagValueTests class tests the TagParser::TagValue class.
Definition: tagvalue.cpp:22
void testBasics()
Definition: tagvalue.cpp:64
void testTimeSpan()
Definition: tagvalue.cpp:156
void tearDown() override
Definition: tagvalue.cpp:60
void testUnsignedInteger()
Definition: tagvalue.cpp:121
void setUp() override
Definition: tagvalue.cpp:56
void testBinary()
Definition: tagvalue.cpp:70
void testInteger()
Definition: tagvalue.cpp:81
void testDateTime()
Definition: tagvalue.cpp:169
void testPositionInSet()
Definition: tagvalue.cpp:144
void testPopularityScaling()
Definition: tagvalue.cpp:295
void testEqualityOperator()
Definition: tagvalue.cpp:251
void testPopularity()
Definition: tagvalue.cpp:182
void testString()
Definition: tagvalue.cpp:202
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
std::string user
The user who gave the rating / played the file, e.g. identified by e-mail address.
Definition: tagvalue.h:74
double rating
The rating on a tag type specific scale.
Definition: tagvalue.h:76
CPPUNIT_TEST_SUITE_REGISTRATION(TagValueTests)