4 #include "../abstracttrack.h" 5 #include "../id3/id3v1tag.h" 6 #include "../id3/id3v2tag.h" 7 #include "../mpegaudio/mpegaudioframe.h" 23 void OverallTests::checkMp3Testfile1()
26 const auto tracks = m_fileInfo.
tracks();
27 CPPUNIT_ASSERT(tracks.size() == 1);
28 for (
const auto &track : tracks) {
32 CPPUNIT_ASSERT(track->channelCount() == 2);
33 CPPUNIT_ASSERT(track->channelConfig() ==
static_cast<byte
>(MpegChannelMode::JointStereo));
34 CPPUNIT_ASSERT(track->samplingFrequency() == 44100);
35 CPPUNIT_ASSERT(track->duration().seconds() == 3);
37 const auto tags = m_fileInfo.
tags();
38 switch (m_tagStatus) {
40 CPPUNIT_ASSERT(m_fileInfo.
id3v1Tag());
41 CPPUNIT_ASSERT(m_fileInfo.
id3v2Tags().size() == 1);
42 CPPUNIT_ASSERT(tags.size() == 2);
43 for (
const auto &tag : tags) {
46 switch (tag->type()) {
47 case TagType::Id3v1Tag:
50 CPPUNIT_ASSERT(tag->value(
KnownField::Album).toString() ==
"Double Nickels On The Dime");
54 case TagType::Id3v2Tag:
55 CPPUNIT_ASSERT(tag->value(
KnownField::Title).dataEncoding() == TagTextEncoding::Utf16LittleEndian);
60 CPPUNIT_ASSERT(tag->value(
KnownField::Album).toWString() == u
"Double Nickels On The Dime");
67 CPPUNIT_ASSERT(tag->value(KnownField::Length).toTimeSpan().isNull());
75 checkMp3TestMetaData();
78 CPPUNIT_ASSERT_EQUAL(0_st, tracks.size());
81 CPPUNIT_ASSERT(m_diag.
level() <= DiagLevel::Information);
87 void OverallTests::checkMp3TestMetaData()
95 CPPUNIT_ASSERT(id3v1Tag = m_fileInfo.id3v1Tag());
96 CPPUNIT_ASSERT(id3v2Tag = m_fileInfo.id3v2Tags().at(0).get());
98 CPPUNIT_ASSERT(id3v1Tag = m_fileInfo.id3v1Tag());
99 CPPUNIT_ASSERT(m_fileInfo.id3v2Tags().empty());
101 CPPUNIT_ASSERT(!m_fileInfo.id3v1Tag());
102 CPPUNIT_ASSERT(id3v2Tag = m_fileInfo.id3v2Tags().at(0).get());
111 m_preservedMetaData.pop();
118 CPPUNIT_ASSERT_EQUAL(m_testTitle, titleValue);
119 CPPUNIT_ASSERT_EQUAL(m_testComment, commentValue);
124 CPPUNIT_ASSERT_MESSAGE(
"not attempted to use UTF-8 in ID3v2.3", titleValue.
dataEncoding() == TagTextEncoding::Utf16LittleEndian);
126 CPPUNIT_ASSERT_MESSAGE(
"not attempted to use UTF-8 in ID3v2.3", commentValue.
dataEncoding() == TagTextEncoding::Utf16LittleEndian);
127 CPPUNIT_ASSERT_MESSAGE(
"not attempted to use UTF-8 in ID3v2.3", commentValue.
descriptionEncoding() == TagTextEncoding::Utf16LittleEndian);
129 CPPUNIT_ASSERT_EQUAL_MESSAGE(
130 "description is also converted to UTF-16",
"s\0o\0m\0e\0 \0d\0e\0s\0c\0r\0i\0p\0t\0i\0\xf3\0n\0"s, commentValue.
description());
136 m_preservedMetaData.pop();
153 void OverallTests::checkMp3PaddingConstraints()
160 CPPUNIT_ASSERT(m_fileInfo.paddingSize() == 4096);
162 CPPUNIT_ASSERT(m_fileInfo.paddingSize() >= 1024);
163 CPPUNIT_ASSERT(m_fileInfo.paddingSize() <= (4096 + 1024));
172 void OverallTests::setMp3TestMetaData()
180 id3v1Tag = m_fileInfo.createId3v1Tag();
181 id3v2Tag = m_fileInfo.createId3v2Tag();
183 id3v1Tag = m_fileInfo.createId3v1Tag();
184 m_fileInfo.removeAllId3v2Tags();
186 m_fileInfo.removeId3v1Tag();
187 id3v2Tag = m_fileInfo.createId3v2Tag();
194 for (
Tag *tag : initializer_list<Tag *>{ id3v1Tag, id3v2Tag }) {
212 cerr << endl <<
"MP3 parser" << endl;
215 parseFile(TestUtilities::testFilePath(
"mtx-test-data/mp3/id3-tag-and-xing-header.mp3"), &OverallTests::checkMp3Testfile1);
223 void OverallTests::testMp3Making()
229 for (m_mode = 0; m_mode != 0x20; ++m_mode) {
239 m_fileInfo.setTagPosition(ElementPosition::Keep);
240 m_fileInfo.setIndexPosition(ElementPosition::Keep);
243 m_fileInfo.setMaxPadding(m_mode &
PaddingConstraints ? (4096 + 1024) : numeric_limits<size_t>::max());
244 m_fileInfo.setForceTagPosition(
false);
245 m_fileInfo.setForceIndexPosition(
false);
248 list<string> testConditions;
250 testConditions.emplace_back(
"forcing rewrite");
254 testConditions.emplace_back(
"removing tag");
256 testConditions.emplace_back(
"ID3v1 and ID3v2");
259 testConditions.emplace_back(
"ID3v1 only");
261 testConditions.emplace_back(
"ID3v2 only");
264 testConditions.emplace_back(
"padding constraints");
267 testConditions.emplace_back(
"use ID3v2.4");
269 cerr << endl <<
"MP3 maker - testmode " << m_mode <<
": " << joinStrings(testConditions,
", ") << endl;
273 void (
OverallTests::*modifyRoutine)(void) = (m_mode &
RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setMp3TestMetaData;
274 makeFile(TestUtilities::workingCopyPath(
"mtx-test-data/mp3/id3-tag-and-xing-header.mp3"), modifyRoutine, &OverallTests::checkMp3Testfile1);
TagTextEncoding dataEncoding() const
Returns the data encoding.
const TagValue & value(const IdentifierType &id) const
Returns the value of the field with the specified id.
TagTextEncoding descriptionEncoding() const
Returns the description encoding.
const std::string & description() const
Returns the description.
constexpr int32 position() const
Returns the element position of the current instance.
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
PositionInSet toPositionInSet() const
Converts the value of the current TagValue object to its equivalent PositionInSet representation...
void testMp3Parsing()
Tests the MP3 parser via MediaFileInfo.
std::string toString(TagTextEncoding encoding=TagTextEncoding::Unspecified) const
Converts the value of the current TagValue object to its equivalent std::string representation.
void setVersion(byte majorVersion, byte revisionVersion)
Sets the version to the specified majorVersion and the specified revisionVersion. ...
const TagValue & value(KnownField value) const override
Returns the value of the specified field.