Tag Parser  6.4.1
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 "../tag.h"
4 #include "../abstracttrack.h"
5 
10 void OverallTests::checkFlacTestfile1()
11 {
12  CPPUNIT_ASSERT(m_fileInfo.containerFormat() == ContainerFormat::Flac);
13  const auto tracks = m_fileInfo.tracks();
14  CPPUNIT_ASSERT(tracks.size() == 1);
15  for(const auto &track : tracks) {
16  CPPUNIT_ASSERT(track->mediaType() == MediaType::Audio);
17  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Flac);
18  CPPUNIT_ASSERT(track->channelCount() == 2);
19  CPPUNIT_ASSERT(track->samplingFrequency() == 44100);
20  CPPUNIT_ASSERT(track->bitsPerSample() == 16);
21  CPPUNIT_ASSERT(track->duration().minutes() == 4);
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(tags.size() == 1);
28  CPPUNIT_ASSERT(tags.front()->value(KnownField::Title).toString() == "Sad Song");
29  CPPUNIT_ASSERT(tags.front()->value(KnownField::Artist).toString() == "Oasis");
30  CPPUNIT_ASSERT(tags.front()->value(KnownField::Album).toString() == "Don't Go Away (Apple Lossless)");
31  CPPUNIT_ASSERT(tags.front()->value(KnownField::Genre).toString() == "Alternative & Punk");
32  CPPUNIT_ASSERT(tags.front()->value(KnownField::Encoder).toString() == "Lavf57.25.100");
33  CPPUNIT_ASSERT(tags.front()->value(KnownField::Year).toString() == "1998");
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(tags.front()->value(KnownField::TrackPosition).toPositionInSet() == PositionInSet(3, 4));
38  CPPUNIT_ASSERT(tags.front()->value(KnownField::DiskPosition).toPositionInSet() == PositionInSet(1, 1));
39  break;
41  checkOggTestMetaData();
42  break;
43  case TagStatus::Removed:
44  CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
45  }
46 
47  CPPUNIT_ASSERT(m_fileInfo.worstNotificationTypeIncludingRelatedObjects() <= NotificationType::Information);
48 }
49 
54 void OverallTests::checkFlacTestfile2()
55 {
56  CPPUNIT_ASSERT(m_fileInfo.containerFormat() == ContainerFormat::Ogg);
57  const auto tracks = m_fileInfo.tracks();
58  CPPUNIT_ASSERT(tracks.size() == 1);
59  for(const auto &track : tracks) {
60  CPPUNIT_ASSERT(track->mediaType() == MediaType::Audio);
61  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Flac);
62  CPPUNIT_ASSERT(track->channelCount() == 2);
63  CPPUNIT_ASSERT(track->samplingFrequency() == 44100);
64  CPPUNIT_ASSERT(track->bitsPerSample() == 16);
65  CPPUNIT_ASSERT(track->duration().minutes() == 4);
66  }
67  const auto tags = m_fileInfo.tags();
68  switch(m_tagStatus) {
70  CPPUNIT_ASSERT(tags.size() == 1);
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 Notification &notification : m_fileInfo.gatherRelatedNotifications()) {
83  if(notification.type() == NotificationType::Critical) {
84  CPPUNIT_ASSERT_EQUAL("OGG page after FLAC-to-Ogg mapping header doesn't contain Vorbis comment."s, notification.message());
85  gotMessageAboutMissingVorbisComment = true;
86  continue;
87  }
88  CPPUNIT_ASSERT(notification.type() <= NotificationType::Information);
89  }
90  CPPUNIT_ASSERT(gotMessageAboutMissingVorbisComment);
91  } else {
92  CPPUNIT_ASSERT(m_fileInfo.worstNotificationTypeIncludingRelatedObjects() <= NotificationType::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 tags(std::vector< Tag *> &tags) const
Stores all tags assigned to the current file in the specified vector.
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:20
NotificationType worstNotificationTypeIncludingRelatedObjects() const
Returns the worst notification type including related objects such as track, tag and container...
std::vector< AbstractTrack * > tracks() const
Returns the tracks for the current file.
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:44
The Notification class holds a notification message of a certain notification type.
Definition: notification.h:43
void gatherRelatedNotifications(NotificationList &notifications) const
Returns the notifications of the current instance and all related objects (tracks, tags, container, ...).
void setForceFullParse(bool forceFullParse)
Sets whether forcing a full parse is enabled.
ContainerFormat containerFormat() const
Returns the container format of the current file.