Tag Parser  10.0.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 "../abstracttrack.h"
5 #include "../tag.h"
6 #include "../vorbis/vorbiscomment.h"
7 
11 void OverallTests::checkOggTestfile1()
12 {
13  CPPUNIT_ASSERT_EQUAL(ContainerFormat::Ogg, m_fileInfo.containerFormat());
14  const auto tracks = m_fileInfo.tracks();
15  CPPUNIT_ASSERT_EQUAL(2_st, tracks.size());
16  for (const auto &track : tracks) {
17  switch (track->id()) {
18  case 897658443:
19  CPPUNIT_ASSERT_EQUAL(MediaType::Video, track->mediaType());
20  CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Theora, track->format().general);
21  break;
22  case 1755441791:
23  CPPUNIT_ASSERT_EQUAL(MediaType::Audio, track->mediaType());
24  CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Vorbis, track->format().general);
25  CPPUNIT_ASSERT_EQUAL(static_cast<std::uint16_t>(2), track->channelCount());
26  CPPUNIT_ASSERT_EQUAL(44100u, track->samplingFrequency());
27  CPPUNIT_ASSERT_EQUAL(4, track->duration().minutes());
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_diag.level() <= DiagLevel::Information);
50 }
51 
55 void OverallTests::checkOggTestfile2()
56 {
57  CPPUNIT_ASSERT_EQUAL(ContainerFormat::Ogg, m_fileInfo.containerFormat());
58  const auto tracks = m_fileInfo.tracks();
59  CPPUNIT_ASSERT_EQUAL(1_st, tracks.size());
60  for (const auto &track : tracks) {
61  switch (track->id()) {
62  case 1375632254:
63  CPPUNIT_ASSERT_EQUAL(MediaType::Audio, track->mediaType());
64  CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Opus, track->format().general);
65  CPPUNIT_ASSERT_EQUAL(static_cast<std::uint16_t>(2), track->channelCount());
66  CPPUNIT_ASSERT_EQUAL(48000u, track->samplingFrequency());
67  CPPUNIT_ASSERT_EQUAL(1, track->duration().minutes());
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_diag.level() <= DiagLevel::Information);
88 }
89 
93 void OverallTests::checkOggTestMetaData()
94 {
95  // check whether a tag is assigned
96  const auto tags = m_fileInfo.tags();
97  const auto *const tag = m_fileInfo.vorbisComment();
98  CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
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  auto *const 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(testFilePath("mtx-test-data/ogg/qt4dance_medium.ogg"), &OverallTests::checkOggTestfile1);
137  parseFile(testFilePath("mtx-test-data/opus/v-opus.ogg"), &OverallTests::checkOggTestfile2);
138 }
139 
147 {
148  // full parse is required to determine padding
149  m_fileInfo.setForceFullParse(true);
150 
151  // do the test under different conditions
152  for (m_mode = 0; m_mode != 0x2; ++m_mode) {
153  using namespace SimpleTestFlags;
154 
155  // no need to setup test conditions because the Ogg maker
156  // doesn't take those settings into account (currently)
157 
158  // print test conditions
159  list<string> testConditions;
160  if (m_mode & RemoveTag) {
161  testConditions.emplace_back("removing tag");
162  } else {
163  testConditions.emplace_back("modifying tag");
164  }
165  cerr << endl << "OGG maker - testmode " << m_mode << ": " << joinStrings(testConditions, ", ") << endl;
166 
167  // do actual tests
168  m_tagStatus = (m_mode & RemoveTag) ? TagStatus::Removed : TagStatus::TestMetaDataPresent;
169  void (OverallTests::*modifyRoutine)(void) = (m_mode & RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaData;
170  makeFile(workingCopyPath("mtx-test-data/ogg/qt4dance_medium.ogg"), modifyRoutine, &OverallTests::checkOggTestfile1);
171  makeFile(workingCopyPath("mtx-test-data/opus/v-opus.ogg"), modifyRoutine, &OverallTests::checkOggTestfile2);
172  }
173 }
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:40
void testOggParsing()
Tests the Ogg parser via MediaFileInfo.
Definition: overallogg.cpp:131
void testOggMaking()
Tests the Ogg maker via MediaFileInfo.
Definition: overallogg.cpp:146
DiagLevel level() const
Returns the worst diag level present in the container.
Definition: diagnostics.cpp:55
std::vector< AbstractTrack * > tracks() const
Returns the tracks for the current file.
VorbisComment * createVorbisComment()
Creates a Vorbis comment for the current file.
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.
void tags(std::vector< Tag * > &tags) const
Stores all tags assigned to the current file in the specified vector.
ContainerFormat containerFormat() const
Returns the container format of the current file.
bool hasAnyTag() const
Returns an indication whether a tag of any format is assigned.
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:485
bool setValue(KnownField field, const TagValue &value) override
Assigns the given value to the specified field.
@ TestMetaDataPresent