Tag Parser  6.2.2
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(tags.size() == 1);
37  CPPUNIT_ASSERT(tags.front()->value(KnownField::Encoder).toString() == "ffmpeg2theora 0.13");
38  // Theora tags are currently not supported and hence only the Vorbis comment is
39  // taken into account here
40  break;
42  checkOggTestMetaData();
43  break;
44  case TagStatus::Removed:
45  CPPUNIT_ASSERT(tags.size() == 0);
46  }
47 }
48 
52 void OverallTests::checkOggTestfile2()
53 {
54  CPPUNIT_ASSERT(m_fileInfo.containerFormat() == ContainerFormat::Ogg);
55  const auto tracks = m_fileInfo.tracks();
56  CPPUNIT_ASSERT(tracks.size() == 1);
57  for(const auto &track : tracks) {
58  switch(track->id()) {
59  case 1375632254:
60  CPPUNIT_ASSERT(track->mediaType() == MediaType::Audio);
61  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Opus);
62  CPPUNIT_ASSERT(track->channelCount() == 2);
63  CPPUNIT_ASSERT(track->samplingFrequency() == 48000);
64  CPPUNIT_ASSERT(track->duration().minutes() == 1);
65  break;
66  default:
67  CPPUNIT_FAIL("unknown track ID");
68  }
69  }
70  const auto tags = m_fileInfo.tags();
71  switch(m_tagStatus) {
73  CPPUNIT_ASSERT(tags.size() == 1);
74  CPPUNIT_ASSERT(tags.front()->value(KnownField::Encoder).toString() == "opusenc from opus-tools 0.1.6");
75  break;
77  checkOggTestMetaData();
78  break;
79  case TagStatus::Removed:
80  CPPUNIT_ASSERT(tags.size() == 0);
81  }
82 }
83 
87 void OverallTests::checkOggTestMetaData()
88 {
89  // check whether a tag is assigned
90  const auto tags = m_fileInfo.tags();
91  VorbisComment *tag = m_fileInfo.vorbisComment();
92  CPPUNIT_ASSERT(tags.size() == 1);
93  CPPUNIT_ASSERT(tag != nullptr);
94 
95  // check test meta data
96  CPPUNIT_ASSERT_EQUAL(m_testTitle, tag->value(KnownField::Title));
97  CPPUNIT_ASSERT_EQUAL(m_testComment.toString(), tag->value(KnownField::Comment).toString()); // loss of description is ok
98  CPPUNIT_ASSERT_EQUAL(m_testAlbum, tag->value(KnownField::Album));
99  CPPUNIT_ASSERT_EQUAL(m_preservedMetaData.front(), tag->value(KnownField::Artist));
100  CPPUNIT_ASSERT_EQUAL(m_testPosition, tag->value(KnownField::TrackPosition));
101  CPPUNIT_ASSERT_EQUAL(m_testPosition, tag->value(KnownField::DiskPosition));
102  // TODO: check more fields
103  m_preservedMetaData.pop();
104 }
105 
106 void OverallTests::setOggTestMetaData()
107 {
108  // ensure a tag exists
109  VorbisComment *tag = m_fileInfo.createVorbisComment();
110 
111  // assign test meta data
112  tag->setValue(KnownField::Title, m_testTitle);
113  tag->setValue(KnownField::Comment, m_testComment);
114  tag->setValue(KnownField::Album, m_testAlbum);
115  m_preservedMetaData.push(tag->value(KnownField::Artist));
116  tag->setValue(KnownField::TrackPosition, m_testPosition);
117  tag->setValue(KnownField::DiskPosition, m_testPosition);
118  // TODO: set more fields
119 }
120 
126 {
127  cerr << endl << "OGG parser" << endl;
128  m_fileInfo.setForceFullParse(false);
129  m_tagStatus = TagStatus::Original;
130  parseFile(TestUtilities::testFilePath("mtx-test-data/ogg/qt4dance_medium.ogg"), &OverallTests::checkOggTestfile1);
131  parseFile(TestUtilities::testFilePath("mtx-test-data/opus/v-opus.ogg"), &OverallTests::checkOggTestfile2);
132 }
133 
134 #ifdef PLATFORM_UNIX
135 
141 void OverallTests::testOggMaking()
142 {
143  // full parse is required to determine padding
144  m_fileInfo.setForceFullParse(true);
145 
146  // do the test under different conditions
147  for(m_mode = 0; m_mode != 0x2; ++m_mode) {
148  using namespace SimpleTestFlags;
149 
150  // no need to setup test conditions because the Ogg maker
151  // doesn't take those settings into account (currently)
152 
153  // print test conditions
154  list<string> testConditions;
155  if(m_mode & RemoveTag) {
156  testConditions.emplace_back("removing tag");
157  } else {
158  testConditions.emplace_back("modifying tag");
159  }
160  cerr << endl << "OGG maker - testmode " << m_mode << ": " << joinStrings(testConditions, ", ") << endl;
161 
162  // do actual tests
163  m_tagStatus = (m_mode & RemoveTag) ? TagStatus::Removed : TagStatus::TestMetaDataPresent;
164  void (OverallTests::*modifyRoutine)(void) = (m_mode & RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaData;
165  makeFile(TestUtilities::workingCopyPath("mtx-test-data/ogg/qt4dance_medium.ogg"), modifyRoutine, &OverallTests::checkOggTestfile1);
166  makeFile(TestUtilities::workingCopyPath("mtx-test-data/opus/v-opus.ogg"), modifyRoutine, &OverallTests::checkOggTestfile2);
167  }
168 }
169 #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.
const TagValue & value(KnownField field) const
Returns the value of the specified field.
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:42
void testOggParsing()
Tests the Ogg parser via MediaFileInfo.
Definition: overallogg.cpp:125
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:316