Tag Parser  8.2.0
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 }
27 
31 void OverallTests::parseFile(const string &path, void (OverallTests::*checkRoutine)(void))
32 {
33  // print current file
34  cerr << "- testing " << path << endl;
35  // ensure file is open and everything is parsed
36  m_diag.clear();
37  m_fileInfo.setPath(path);
38  m_fileInfo.reopen(true);
39  m_fileInfo.parseEverything(m_diag);
40  // invoke testroutine to check whether parsing results are correct
41  (this->*checkRoutine)();
42  m_fileInfo.close();
43 }
44 
49 void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRoutine)(void), void (OverallTests::*checkRoutine)(void))
50 {
51  // print current file
52  cerr << "- testing " << path << endl;
53  // ensure file is open and everything is parsed
54  m_diag.clear();
55  m_fileInfo.setPath(path);
56  m_fileInfo.reopen(true);
57  m_fileInfo.parseEverything(m_diag);
58 
59  // determine expected tag and index position
60  switch (m_fileInfo.containerFormat()) {
62  CPPUNIT_ASSERT(m_fileInfo.container());
63  if (m_fileInfo.tagPosition() != ElementPosition::Keep) {
64  m_expectedTagPos = m_fileInfo.tagPosition();
65  } else {
66  m_expectedTagPos = m_fileInfo.container()->determineTagPosition(m_diag);
67  if (m_expectedTagPos == ElementPosition::Keep) {
68  // if there is no tag present, the resulting tag position should equal the
69  // current index position
70  m_expectedTagPos = m_fileInfo.container()->determineIndexPosition(m_diag);
71  }
72  }
73  break;
74  case ContainerFormat::Matroska:
75  CPPUNIT_ASSERT(m_fileInfo.container());
76  // since a tag is always created, it can always be expected at the specified position
77  if (m_fileInfo.tagPosition() != ElementPosition::Keep) {
78  m_expectedTagPos = m_fileInfo.tagPosition();
79  } else {
80  m_expectedTagPos = m_fileInfo.container()->determineTagPosition(m_diag);
81  }
82  // an index is only present if the file had one before, hence specifying the index position
83  // might not have an effect
84  m_expectedIndexPos = m_fileInfo.container()->determineIndexPosition(m_diag);
85  if (m_fileInfo.indexPosition() != ElementPosition::Keep && m_expectedIndexPos != ElementPosition::Keep) {
86  m_expectedIndexPos = m_fileInfo.indexPosition();
87  }
88  break;
89  default:;
90  }
91 
92  // invoke testroutine to do and apply changes
93  (this->*modifyRoutine)();
94  // apply changes and ensure that the previous parsing results are cleared
95  m_fileInfo.applyChanges(m_diag, m_progress);
96  m_fileInfo.clearParsingResults();
97  // reparse the file and invoke testroutine to check whether changings have been applied correctly
98  m_fileInfo.parseEverything(m_diag);
99  (this->*checkRoutine)();
100  // invoke suitable testroutine to check padding constraints
101  switch (m_fileInfo.containerFormat()) {
102  case ContainerFormat::Matroska:
103  checkMkvConstraints();
104  break;
106  checkMp4Constraints();
107  break;
110  checkMp3PaddingConstraints();
111  break;
112  default:;
113  }
114 
115  // close and remove file and backup files
116  m_fileInfo.close();
117  remove(path.c_str());
118  remove((path + ".bak").c_str());
119 }
120 
124 void OverallTests::removeAllTags()
125 {
126  m_fileInfo.removeAllTags();
127 }
128 
133 void OverallTests::noop()
134 {
135 }
136 
140 void OverallTests::removeSecondTrack()
141 {
142  CPPUNIT_ASSERT(m_fileInfo.container());
143  CPPUNIT_ASSERT(m_fileInfo.container()->trackCount() >= 2);
144  m_fileInfo.container()->removeTrack(m_fileInfo.container()->track(1));
145 }
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...
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:21
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:313
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:44
void reopen(bool readonly=false)
Opens a std::fstream for the current file.
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
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:639
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:588
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:461
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
void setUp()
Creates some test meta data.