Tag Parser  7.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
overallgeneral.cpp
Go to the documentation of this file.
1 #include "./overall.h"
2 
4 
6  : m_progress(std::function<void(AbortableProgressFeedback &)>(), std::function<void(AbortableProgressFeedback &)>())
7 {
8 }
9 
14 {
15  m_testTitle.assignText("some title", TagTextEncoding::Utf8);
16  m_testComment.assignText("some cómment", TagTextEncoding::Utf8);
17  m_testComment.setDescription("some descriptión", TagTextEncoding::Utf8);
18  m_testAlbum.assignText("some album", TagTextEncoding::Utf8);
19  m_testPartNumber.assignInteger(41);
20  m_testTotalParts.assignInteger(61);
21  m_testPosition.assignPosition(PositionInSet(41, 61));
22 }
23 
25 {
26  for (const string &file : { m_nestedTagsMkvPath, m_rawFlacPath, m_flacInOggPath }) {
27  if (!file.empty()) {
28  remove(file.data());
29  }
30  }
31 }
32 
36 void OverallTests::parseFile(const string &path, void (OverallTests::*checkRoutine)(void))
37 {
38  // print current file
39  cerr << "- testing " << path << endl;
40  // ensure file is open and everything is parsed
41  m_diag.clear();
42  m_fileInfo.setPath(path);
43  m_fileInfo.reopen(true);
44  m_fileInfo.parseEverything(m_diag);
45  // invoke testroutine to check whether parsing results are correct
46  (this->*checkRoutine)();
47  m_fileInfo.close();
48 }
49 
54 void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRoutine)(void), void (OverallTests::*checkRoutine)(void))
55 {
56  // print current file
57  cerr << "- testing " << path << endl;
58  // ensure file is open and everything is parsed
59  m_diag.clear();
60  m_fileInfo.setPath(path);
61  m_fileInfo.reopen(true);
62  m_fileInfo.parseEverything(m_diag);
63 
64  // determine expected tag and index position
65  switch (m_fileInfo.containerFormat()) {
67  CPPUNIT_ASSERT(m_fileInfo.container());
68  if (m_fileInfo.tagPosition() != ElementPosition::Keep) {
69  m_expectedTagPos = m_fileInfo.tagPosition();
70  } else {
71  m_expectedTagPos = m_fileInfo.container()->determineTagPosition(m_diag);
72  if (m_expectedTagPos == ElementPosition::Keep) {
73  // if there is no tag present, the resulting tag position should equal the
74  // current index position
75  m_expectedTagPos = m_fileInfo.container()->determineIndexPosition(m_diag);
76  }
77  }
78  break;
79  case ContainerFormat::Matroska:
80  CPPUNIT_ASSERT(m_fileInfo.container());
81  // since a tag is always created, it can always be expected at the specified position
82  if (m_fileInfo.tagPosition() != ElementPosition::Keep) {
83  m_expectedTagPos = m_fileInfo.tagPosition();
84  } else {
85  m_expectedTagPos = m_fileInfo.container()->determineTagPosition(m_diag);
86  }
87  // an index is only present if the file had one before, hence specifying the index position
88  // might not have an effect
89  m_expectedIndexPos = m_fileInfo.container()->determineIndexPosition(m_diag);
90  if (m_fileInfo.indexPosition() != ElementPosition::Keep && m_expectedIndexPos != ElementPosition::Keep) {
91  m_expectedIndexPos = m_fileInfo.indexPosition();
92  }
93  break;
94  default:;
95  }
96 
97  // invoke testroutine to do and apply changes
98  (this->*modifyRoutine)();
99  // apply changes and ensure that the previous parsing results are cleared
100  m_fileInfo.applyChanges(m_diag, m_progress);
101  m_fileInfo.clearParsingResults();
102  // reparse the file and invoke testroutine to check whether changings have been applied correctly
103  m_fileInfo.parseEverything(m_diag);
104  (this->*checkRoutine)();
105  // invoke suitable testroutine to check padding constraints
106  switch (m_fileInfo.containerFormat()) {
107  case ContainerFormat::Matroska:
108  checkMkvConstraints();
109  break;
111  checkMp4Constraints();
112  break;
115  checkMp3PaddingConstraints();
116  break;
117  default:;
118  }
119 
120  // close and remove file and backup files
121  m_fileInfo.close();
122  remove(path.c_str());
123  remove((path + ".bak").c_str());
124 }
125 
129 void OverallTests::removeAllTags()
130 {
131  m_fileInfo.removeAllTags();
132 }
133 
138 void OverallTests::noop()
139 {
140 }
141 
145 void OverallTests::removeSecondTrack()
146 {
147  CPPUNIT_ASSERT(m_fileInfo.container());
148  CPPUNIT_ASSERT(m_fileInfo.container()->trackCount() >= 2);
149  m_fileInfo.container()->removeTrack(m_fileInfo.container()->track(1));
150 }
void parseEverything(Diagnostics &diag)
Parses the container format, the tracks and the tag information of the current file.
void setPath(const std::string &path)
Sets the current file.
virtual ElementPosition determineTagPosition(Diagnostics &diag) const
Determines the position of the tags inside the file.
CPPUNIT_TEST_SUITE_REGISTRATION(OverallTests)
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const
Determines the position of the index.
void clearParsingResults()
Clears all parsing results and assigned/created/changed information such as detected container format...
STL namespace.
void applyChanges(Diagnostics &diag, AbortableProgressFeedback &progress)
Applies assigned/changed tag information to the current file.
ContainerFormat containerFormat() const
Returns the container format of the current file.
virtual std::size_t trackCount() const
Returns the number of tracks the container holds.
void assignPosition(PositionInSet value)
Assigns the given PositionInSet value.
Definition: tagvalue.h:291
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:42
void reopen(bool readonly=false)
Opens a std::fstream for the current file.
void close()
A possibly opened std::fstream will be closed.
ElementPosition tagPosition() const
Returns the position (in the output file) where the tag information is written when applying changes...
void removeAllTags()
Removes all assigned tags from the file.
AbstractContainer * container() const
Returns the container for the current file.
ElementPosition indexPosition() const
Returns the position (in the output file) where the index is written when applying changes...
void assignInteger(int value)
Assigns the given integer value.
Definition: tagvalue.cpp:603
void assignText(const char *text, std::size_t textSize, TagTextEncoding textEncoding=TagTextEncoding::Latin1, TagTextEncoding convertTo=TagTextEncoding::Unspecified)
Assigns a copy of the given text.
Definition: tagvalue.cpp:552
virtual AbstractTrack * track(std::size_t index)
Returns the track with the specified index.
void setDescription(const std::string &value, TagTextEncoding encoding=TagTextEncoding::Latin1)
Sets the description.
Definition: tagvalue.h:439
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
void setUp()
Creates some test meta data.