Tag Parser  6.3.0
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(tags.size() == 0);
45  }
46 }
47 
52 void OverallTests::checkFlacTestfile2()
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  CPPUNIT_ASSERT(track->mediaType() == MediaType::Audio);
59  CPPUNIT_ASSERT(track->format() == GeneralMediaFormat::Flac);
60  CPPUNIT_ASSERT(track->channelCount() == 2);
61  CPPUNIT_ASSERT(track->samplingFrequency() == 44100);
62  CPPUNIT_ASSERT(track->bitsPerSample() == 16);
63  CPPUNIT_ASSERT(track->duration().minutes() == 4);
64  }
65  const auto tags = m_fileInfo.tags();
66  switch(m_tagStatus) {
68  CPPUNIT_ASSERT(tags.size() == 1);
69  break;
71  checkOggTestMetaData();
72  break;
73  case TagStatus::Removed:
74  CPPUNIT_ASSERT(tags.size() == 0);
75  }
76 }
77 
82 {
83  cerr << endl << "FLAC parser" << endl;
84  m_fileInfo.setForceFullParse(false);
85  m_tagStatus = TagStatus::Original;
86  parseFile(TestUtilities::testFilePath("flac/test.flac"), &OverallTests::checkFlacTestfile1);
87  parseFile(TestUtilities::testFilePath("flac/test.ogg"), &OverallTests::checkFlacTestfile2);
88 }
89 
90 #ifdef PLATFORM_UNIX
91 
95 void OverallTests::testFlacMaking()
96 {
97  // full parse is required to determine padding
98  m_fileInfo.setForceFullParse(true);
99 
100  // do the test under different conditions
101  for(m_mode = 0; m_mode != 0x2; ++m_mode) {
102  using namespace SimpleTestFlags;
103 
104  // TODO: setup test conditions
105 
106  // print test conditions
107  list<string> testConditions;
108  if(m_mode & RemoveTag) {
109  testConditions.emplace_back("removing tag");
110  } else {
111  testConditions.emplace_back("modifying tag");
112  }
113  cerr << endl << "FLAC maker - testmode " << m_mode << ": " << joinStrings(testConditions, ", ") << endl;
114 
115  // do actual tests
116  m_tagStatus = (m_mode & RemoveTag) ? TagStatus::Removed : TagStatus::TestMetaDataPresent;
117  void (OverallTests::*modifyRoutine)(void) = (m_mode & RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaData;
118  makeFile(TestUtilities::workingCopyPath("flac/test.flac"), modifyRoutine, &OverallTests::checkFlacTestfile1);
119  makeFile(TestUtilities::workingCopyPath("flac/test.ogg"), modifyRoutine, &OverallTests::checkFlacTestfile2);
120  }
121 }
122 #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:81
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:20
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:43
void setForceFullParse(bool forceFullParse)
Sets whether forcing a full parse is enabled.
ContainerFormat containerFormat() const
Returns the container format of the current file.