Tag Parser  10.0.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"sv, TagTextEncoding::Utf8);
16  m_testComment.assignText("some cómment"sv, TagTextEncoding::Utf8);
17  m_testComment.setDescription("some descriptión"sv, TagTextEncoding::Utf8);
18  m_testCommentWithoutDescription.assignText("some cómment"sv, TagTextEncoding::Utf8);
19  m_testAlbum.assignText("some album"sv, TagTextEncoding::Utf8);
20  m_testPartNumber.assignInteger(41);
21  m_testTotalParts.assignInteger(61);
22  m_testPosition.assignPosition(PositionInSet(41, 61));
23 }
24 
26 {
27 }
28 
32 void OverallTests::parseFile(const string &path, void (OverallTests::*checkRoutine)(void))
33 {
34  // print current file
35  cerr << "- testing " << path << endl;
36  // ensure file is open and everything is parsed
37  m_diag.clear();
38  m_fileInfo.setPath(path);
39  m_fileInfo.reopen(true);
40  m_fileInfo.parseEverything(m_diag, m_progress);
41  // invoke testroutine to check whether parsing results are correct
42  (this->*checkRoutine)();
43  m_fileInfo.close();
44 }
45 
50 void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRoutine)(void), void (OverallTests::*checkRoutine)(void))
51 {
52  // print current file
53  cerr << "- testing " << path << endl;
54  // ensure file is open and everything is parsed
55  m_diag.clear();
56  m_fileInfo.setPath(path);
57  m_fileInfo.reopen(true);
58  m_fileInfo.parseEverything(m_diag, m_progress);
59 
60  // determine expected tag and index position
61  switch (m_fileInfo.containerFormat()) {
63  CPPUNIT_ASSERT(m_fileInfo.container());
64  if (m_fileInfo.tagPosition() != ElementPosition::Keep) {
65  m_expectedTagPos = m_fileInfo.tagPosition();
66  } else {
67  m_expectedTagPos = m_fileInfo.container()->determineTagPosition(m_diag);
68  if (m_expectedTagPos == ElementPosition::Keep) {
69  // if there is no tag present, the resulting tag position should equal the
70  // current index position
71  m_expectedTagPos = m_fileInfo.container()->determineIndexPosition(m_diag);
72  }
73  }
74  break;
75  case ContainerFormat::Matroska:
76  CPPUNIT_ASSERT(m_fileInfo.container());
77  // since a tag is always created, it can always be expected at the specified position
78  if (m_fileInfo.tagPosition() != ElementPosition::Keep) {
79  m_expectedTagPos = m_fileInfo.tagPosition();
80  } else {
81  m_expectedTagPos = m_fileInfo.container()->determineTagPosition(m_diag);
82  }
83  // an index is only present if the file had one before, hence specifying the index position
84  // might not have an effect
85  m_expectedIndexPos = m_fileInfo.container()->determineIndexPosition(m_diag);
86  if (m_fileInfo.indexPosition() != ElementPosition::Keep && m_expectedIndexPos != ElementPosition::Keep) {
87  m_expectedIndexPos = m_fileInfo.indexPosition();
88  }
89  break;
90  default:;
91  }
92 
93  // invoke testroutine to do and apply changes
94  (this->*modifyRoutine)();
95  // apply changes and ensure that the previous parsing results are cleared
96  m_fileInfo.applyChanges(m_diag, m_progress);
97  m_fileInfo.clearParsingResults();
98  // reparse the file and invoke testroutine to check whether changings have been applied correctly
99  m_fileInfo.parseEverything(m_diag, m_progress);
100  (this->*checkRoutine)();
101  // invoke suitable testroutine to check padding constraints
102  switch (m_fileInfo.containerFormat()) {
103  case ContainerFormat::Matroska:
104  checkMkvConstraints();
105  break;
107  checkMp4Constraints();
108  break;
111  checkMp3PaddingConstraints();
112  break;
113  default:;
114  }
115 
116  // close and remove file and backup files
117  m_fileInfo.close();
118  remove(path.c_str());
119  remove((path + ".bak").c_str());
120 }
121 
125 void OverallTests::removeAllTags()
126 {
127  m_fileInfo.removeAllTags();
128 }
129 
134 void OverallTests::noop()
135 {
136 }
137 
141 void OverallTests::removeSecondTrack()
142 {
143  CPPUNIT_ASSERT(m_fileInfo.container());
144  CPPUNIT_ASSERT(m_fileInfo.container()->trackCount() >= 2);
145  m_fileInfo.container()->removeTrack(m_fileInfo.container()->track(1));
146 }
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:40
void setUp() override
Creates some test meta data.
void tearDown() override
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
virtual ElementPosition determineTagPosition(Diagnostics &diag) const
Determines the position of the tags inside the file.
virtual AbstractTrack * track(std::size_t index)
Returns the track with the specified index.
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const
Determines the position of the index.
virtual std::size_t trackCount() const
Returns the number of tracks the container holds.
void reopen(bool readOnly=false)
Opens a std::fstream for the current file.
void close()
A possibly opened std::fstream will be closed.
void setPath(std::string_view path)
Sets the current file.
void parseEverything(Diagnostics &diag, AbortableProgressFeedback &progress)
Parses the container format, the tracks and the tag information of the current file.
void removeAllTags()
Removes all assigned tags from the file.
void clearParsingResults()
Clears all parsing results and assigned/created/changed information such as detected container format...
ElementPosition tagPosition() const
Returns the position (in the output file) where the tag information is written when applying changes.
AbstractContainer * container() const
Returns the container for the current file.
ContainerFormat containerFormat() const
Returns the container format of the current file.
void applyChanges(Diagnostics &diag, AbortableProgressFeedback &progress)
Applies assigned/changed tag information to the current file.
ElementPosition indexPosition() const
Returns the position (in the output file) where the index is written when applying changes.
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:21
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:770
void assignInteger(int value)
Assigns the given integer value.
Definition: tagvalue.cpp:821
void assignPosition(PositionInSet value)
Assigns the given PositionInSet value.
Definition: tagvalue.h:428
void setDescription(std::string_view value, TagTextEncoding encoding=TagTextEncoding::Latin1)
Sets the description.
Definition: tagvalue.h:614
@ MpegAudioFrames
Definition: signature.cpp:91
CPPUNIT_TEST_SUITE_REGISTRATION(OverallTests)