Tag Parser  7.1.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
overallflac.cpp
Go to the documentation of this file.
1 #include "./overall.h"
2 
3 #include "../abstracttrack.h"
4 #include "../tag.h"
5 
10 void OverallTests::checkFlacTestfile1()
11 {
12  CPPUNIT_ASSERT_EQUAL(ContainerFormat::Flac, m_fileInfo.containerFormat());
13  const auto tracks = m_fileInfo.tracks();
14  CPPUNIT_ASSERT_EQUAL(1_st, tracks.size());
15  for (const auto &track : tracks) {
16  CPPUNIT_ASSERT_EQUAL(MediaType::Audio, track->mediaType());
17  CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Flac, track->format().general);
18  CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(2), track->channelCount());
19  CPPUNIT_ASSERT_EQUAL(44100u, track->samplingFrequency());
20  CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(16), track->bitsPerSample());
21  CPPUNIT_ASSERT_EQUAL(4, track->duration().minutes());
22  }
23  const auto tags = m_fileInfo.tags();
24  switch (m_tagStatus) {
26  // ffmpeg is able to set some tags from the original file (mtx-test-data/alac/othertest-itunes.m4a)
27  CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
28  CPPUNIT_ASSERT_EQUAL("Sad Song"s, tags.front()->value(KnownField::Title).toString());
29  CPPUNIT_ASSERT_EQUAL("Oasis"s, tags.front()->value(KnownField::Artist).toString());
30  CPPUNIT_ASSERT_EQUAL("Don't Go Away (Apple Lossless)"s, tags.front()->value(KnownField::Album).toString());
31  CPPUNIT_ASSERT_EQUAL("Alternative & Punk"s, tags.front()->value(KnownField::Genre).toString());
32  CPPUNIT_ASSERT_EQUAL("Lavf57.25.100"s, tags.front()->value(KnownField::Encoder).toString());
33  CPPUNIT_ASSERT_EQUAL("1998"s, tags.front()->value(KnownField::Year).toString());
34  CPPUNIT_ASSERT(tags.front()->value(KnownField::Comment).isEmpty());
35  //CPPUNIT_ASSERT(tags.front()->value(KnownField::Cover).dataSize() == 0x58f3);
36  //CPPUNIT_ASSERT(BE::toUInt64(tags.front()->value(KnownField::Cover).dataPointer()) == 0xFFD8FFE000104A46);
37  CPPUNIT_ASSERT_EQUAL(PositionInSet(3, 4), tags.front()->value(KnownField::TrackPosition).toPositionInSet());
38  CPPUNIT_ASSERT_EQUAL(PositionInSet(1, 1), tags.front()->value(KnownField::DiskPosition).toPositionInSet());
39  break;
41  checkOggTestMetaData();
42  break;
43  case TagStatus::Removed:
44  CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
45  }
46 
47  CPPUNIT_ASSERT(m_diag.level() <= DiagLevel::Information);
48 }
49 
54 void OverallTests::checkFlacTestfile2()
55 {
56  CPPUNIT_ASSERT_EQUAL(ContainerFormat::Ogg, m_fileInfo.containerFormat());
57  const auto tracks = m_fileInfo.tracks();
58  CPPUNIT_ASSERT_EQUAL(1_st, tracks.size());
59  for (const auto &track : tracks) {
60  CPPUNIT_ASSERT_EQUAL(MediaType::Audio, track->mediaType());
61  CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Flac, track->format().general);
62  CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(2), track->channelCount());
63  CPPUNIT_ASSERT_EQUAL(44100u, track->samplingFrequency());
64  CPPUNIT_ASSERT_EQUAL(static_cast<uint16>(16), track->bitsPerSample());
65  CPPUNIT_ASSERT_EQUAL(4, track->duration().minutes());
66  }
67  const auto tags = m_fileInfo.tags();
68  switch (m_tagStatus) {
70  CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
71  break;
73  checkOggTestMetaData();
74  break;
75  case TagStatus::Removed:
76  CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
77  }
78 
79  // check for unexpected critical notifications or warnings
80  if (m_tagStatus == TagStatus::Removed) {
81  bool gotMessageAboutMissingVorbisComment = false;
82  for (const auto &msg : m_diag) {
83  if (msg.level() == DiagLevel::Critical) {
84  CPPUNIT_ASSERT_EQUAL("OGG page after FLAC-to-Ogg mapping header doesn't contain Vorbis comment."s, msg.message());
85  gotMessageAboutMissingVorbisComment = true;
86  continue;
87  }
88  CPPUNIT_ASSERT(msg.level() <= DiagLevel::Information);
89  }
90  CPPUNIT_ASSERT(gotMessageAboutMissingVorbisComment);
91  } else {
92  CPPUNIT_ASSERT(m_diag.level() <= DiagLevel::Information);
93  }
94 }
95 
100 {
101  cerr << endl << "FLAC parser" << endl;
102  m_fileInfo.setForceFullParse(false);
103  m_tagStatus = TagStatus::Original;
104  parseFile(TestUtilities::testFilePath("flac/test.flac"), &OverallTests::checkFlacTestfile1);
105  parseFile(TestUtilities::testFilePath("flac/test.ogg"), &OverallTests::checkFlacTestfile2);
106 }
107 
108 #ifdef PLATFORM_UNIX
109 
113 void OverallTests::testFlacMaking()
114 {
115  // full parse is required to determine padding
116  m_fileInfo.setForceFullParse(true);
117 
118  // do the test under different conditions
119  for (m_mode = 0; m_mode != 0x2; ++m_mode) {
120  using namespace SimpleTestFlags;
121 
122  // TODO: setup test conditions
123 
124  // print test conditions
125  list<string> testConditions;
126  if (m_mode & RemoveTag) {
127  testConditions.emplace_back("removing tag");
128  } else {
129  testConditions.emplace_back("modifying tag");
130  }
131  cerr << endl << "FLAC maker - testmode " << m_mode << ": " << joinStrings(testConditions, ", ") << endl;
132 
133  // do actual tests
134  m_tagStatus = (m_mode & RemoveTag) ? TagStatus::Removed : TagStatus::TestMetaDataPresent;
135  void (OverallTests::*modifyRoutine)(void) = (m_mode & RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaData;
136  makeFile(TestUtilities::workingCopyPath("flac/test.flac"), modifyRoutine, &OverallTests::checkFlacTestfile1);
137  makeFile(TestUtilities::workingCopyPath("flac/test.ogg"), modifyRoutine, &OverallTests::checkFlacTestfile2);
138  }
139 }
140 #endif
void testFlacParsing()
Tests the FLAC parser via MediaFileInfo.
Definition: overallflac.cpp:99
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:21
ContainerFormat containerFormat() const
Returns the container format of the current file.
DiagLevel level() const
Returns the worst diag level present in the container.
Definition: diagnostics.cpp:53
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:42
void tags(std::vector< Tag *> &tags) const
Stores all tags assigned to the current file in the specified vector.
void setForceFullParse(bool forceFullParse)
Sets whether forcing a full parse is enabled.
std::vector< AbstractTrack * > tracks() const
Returns the tracks for the current file.