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