Tag Parser  6.5.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
overallogg.cpp
Go to the documentation of this file.
1 #include "./helper.h"
2 #include "./overall.h"
3 
4 #include "../tag.h"
5 #include "../abstracttrack.h"
6 #include "../vorbis/vorbiscomment.h"
7 
11 void OverallTests::checkOggTestfile1()
12 {
13  CPPUNIT_ASSERT(m_fileInfo.containerFormat() == ContainerFormat::Ogg);
14  const auto tracks = m_fileInfo.tracks();
15  CPPUNIT_ASSERT(tracks.size() == 2);
16  for(const auto &track : tracks) {
17  switch(track->id()) {
18  case 897658443:
19  CPPUNIT_ASSERT(track->mediaType() == MediaType::Video);
20  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Theora);
21  break;
22  case 1755441791:
23  CPPUNIT_ASSERT(track->mediaType() == MediaType::Audio);
24  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Vorbis);
25  CPPUNIT_ASSERT(track->channelCount() == 2);
26  CPPUNIT_ASSERT(track->samplingFrequency() == 44100);
27  CPPUNIT_ASSERT(track->duration().minutes() == 4);
28  break;
29  default:
30  CPPUNIT_FAIL("unknown track ID");
31  }
32  }
33  const auto tags = m_fileInfo.tags();
34  switch(m_tagStatus) {
36  CPPUNIT_ASSERT(m_fileInfo.hasAnyTag());
37  CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
38  CPPUNIT_ASSERT_EQUAL("ffmpeg2theora 0.13"s, tags.front()->value(KnownField::Encoder).toString());
39  // Theora tags are currently not supported and hence only the Vorbis comment is
40  // taken into account here
41  break;
43  checkOggTestMetaData();
44  break;
45  case TagStatus::Removed:
46  CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
47  }
48 
49  CPPUNIT_ASSERT(m_fileInfo.worstNotificationTypeIncludingRelatedObjects() <= NotificationType::Information);
50 }
51 
55 void OverallTests::checkOggTestfile2()
56 {
57  CPPUNIT_ASSERT(m_fileInfo.containerFormat() == ContainerFormat::Ogg);
58  const auto tracks = m_fileInfo.tracks();
59  CPPUNIT_ASSERT(tracks.size() == 1);
60  for(const auto &track : tracks) {
61  switch(track->id()) {
62  case 1375632254:
63  CPPUNIT_ASSERT(track->mediaType() == MediaType::Audio);
64  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Opus);
65  CPPUNIT_ASSERT(track->channelCount() == 2);
66  CPPUNIT_ASSERT(track->samplingFrequency() == 48000);
67  CPPUNIT_ASSERT(track->duration().minutes() == 1);
68  break;
69  default:
70  CPPUNIT_FAIL("unknown track ID");
71  }
72  }
73  const auto tags = m_fileInfo.tags();
74  switch(m_tagStatus) {
76  CPPUNIT_ASSERT(m_fileInfo.hasAnyTag());
77  CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
78  CPPUNIT_ASSERT_EQUAL("opusenc from opus-tools 0.1.6"s, tags.front()->value(KnownField::Encoder).toString());
79  break;
81  checkOggTestMetaData();
82  break;
83  case TagStatus::Removed:
84  CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
85  }
86 
87  CPPUNIT_ASSERT(m_fileInfo.worstNotificationTypeIncludingRelatedObjects() <= NotificationType::Information);
88 }
89 
93 void OverallTests::checkOggTestMetaData()
94 {
95  // check whether a tag is assigned
96  const auto tags = m_fileInfo.tags();
97  VorbisComment *tag = m_fileInfo.vorbisComment();
98  CPPUNIT_ASSERT(tags.size() == 1);
99  CPPUNIT_ASSERT(tag != nullptr);
100 
101  // check test meta data
102  CPPUNIT_ASSERT_EQUAL(m_testTitle, tag->value(KnownField::Title));
103  CPPUNIT_ASSERT_EQUAL(m_testComment.toString(), tag->value(KnownField::Comment).toString()); // loss of description is ok
104  CPPUNIT_ASSERT_EQUAL(m_testAlbum, tag->value(KnownField::Album));
105  CPPUNIT_ASSERT_EQUAL(m_preservedMetaData.front(), tag->value(KnownField::Artist));
106  CPPUNIT_ASSERT_EQUAL(m_testPosition, tag->value(KnownField::TrackPosition));
107  CPPUNIT_ASSERT_EQUAL(m_testPosition, tag->value(KnownField::DiskPosition));
108  // TODO: check more fields
109  m_preservedMetaData.pop();
110 }
111 
112 void OverallTests::setOggTestMetaData()
113 {
114  // ensure a tag exists
115  VorbisComment *tag = m_fileInfo.createVorbisComment();
116 
117  // assign test meta data
118  tag->setValue(KnownField::Title, m_testTitle);
119  tag->setValue(KnownField::Comment, m_testComment);
120  tag->setValue(KnownField::Album, m_testAlbum);
121  m_preservedMetaData.push(tag->value(KnownField::Artist));
122  tag->setValue(KnownField::TrackPosition, m_testPosition);
123  tag->setValue(KnownField::DiskPosition, m_testPosition);
124  // TODO: set more fields
125 }
126 
132 {
133  cerr << endl << "OGG parser" << endl;
134  m_fileInfo.setForceFullParse(false);
135  m_tagStatus = TagStatus::Original;
136  parseFile(TestUtilities::testFilePath("mtx-test-data/ogg/qt4dance_medium.ogg"), &OverallTests::checkOggTestfile1);
137  parseFile(TestUtilities::testFilePath("mtx-test-data/opus/v-opus.ogg"), &OverallTests::checkOggTestfile2);
138 }
139 
140 #ifdef PLATFORM_UNIX
141 
147 void OverallTests::testOggMaking()
148 {
149  // full parse is required to determine padding
150  m_fileInfo.setForceFullParse(true);
151 
152  // do the test under different conditions
153  for(m_mode = 0; m_mode != 0x2; ++m_mode) {
154  using namespace SimpleTestFlags;
155 
156  // no need to setup test conditions because the Ogg maker
157  // doesn't take those settings into account (currently)
158 
159  // print test conditions
160  list<string> testConditions;
161  if(m_mode & RemoveTag) {
162  testConditions.emplace_back("removing tag");
163  } else {
164  testConditions.emplace_back("modifying tag");
165  }
166  cerr << endl << "OGG maker - testmode " << m_mode << ": " << joinStrings(testConditions, ", ") << endl;
167 
168  // do actual tests
169  m_tagStatus = (m_mode & RemoveTag) ? TagStatus::Removed : TagStatus::TestMetaDataPresent;
170  void (OverallTests::*modifyRoutine)(void) = (m_mode & RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaData;
171  makeFile(TestUtilities::workingCopyPath("mtx-test-data/ogg/qt4dance_medium.ogg"), modifyRoutine, &OverallTests::checkOggTestfile1);
172  makeFile(TestUtilities::workingCopyPath("mtx-test-data/opus/v-opus.ogg"), modifyRoutine, &OverallTests::checkOggTestfile2);
173  }
174 }
175 #endif
Implementation of Media::Tag for Vorbis comments.
Definition: vorbiscomment.h:15
void tags(std::vector< Tag *> &tags) const
Stores all tags assigned to the current file in the specified vector.
VorbisComment * createVorbisComment()
Creates a Vorbis comment for the current file.
bool hasAnyTag() const
Returns an indication whether a tag of any format is assigned.
const TagValue & value(KnownField field) const
Returns the value of the specified field.
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
void testOggParsing()
Tests the Ogg parser via MediaFileInfo.
Definition: overallogg.cpp:131
bool setValue(KnownField field, const TagValue &value)
Assigns the given value to the specified field.
VorbisComment * vorbisComment() const
Returns a pointer to the first assigned Vorbis comment or nullptr if none is assigned.
void setForceFullParse(bool forceFullParse)
Sets whether forcing a full parse is enabled.
ContainerFormat containerFormat() const
Returns the container format of the current file.
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:320