Tag Parser  9.1.3
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_testCommentWithoutDescription.assignText("some cómment", TagTextEncoding::Utf8);
19  m_testAlbum.assignText("some album", 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);
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);
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);
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 }
TagParser::RawDataType::Utf8
@ Utf8
Definition: mp4tagfield.h:21
TagParser::AbstractContainer::determineTagPosition
virtual ElementPosition determineTagPosition(Diagnostics &diag) const
Determines the position of the tags inside the file.
Definition: abstractcontainer.cpp:352
TagParser::AbortableProgressFeedback
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks....
Definition: progressfeedback.h:186
TagParser::BasicFileInfo::reopen
void reopen(bool readOnly=false)
Opens a std::fstream for the current file.
Definition: basicfileinfo.cpp:59
TagParser::TagValue::assignPosition
void assignPosition(PositionInSet value)
Assigns the given PositionInSet value.
Definition: tagvalue.h:355
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(OverallTests)
TagParser::BasicFileInfo::setPath
void setPath(const std::string &path)
Sets the current file.
Definition: basicfileinfo.cpp:94
OverallTests::tearDown
void tearDown() override
Definition: overallgeneral.cpp:25
TagParser::AbstractContainer::track
virtual AbstractTrack * track(std::size_t index)
Returns the track with the specified index.
Definition: abstractcontainer.cpp:363
TagParser::TagValue::assignText
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:767
TagParser::TagValue::assignInteger
void assignInteger(int value)
Assigns the given integer value.
Definition: tagvalue.cpp:818
overall.h
OverallTests::setUp
void setUp() override
Creates some test meta data.
Definition: overallgeneral.cpp:13
TagParser::AbstractContainer::trackCount
virtual std::size_t trackCount() const
Returns the number of tracks the container holds.
Definition: abstractcontainer.cpp:372
TagParser::MediaFileInfo::tagPosition
ElementPosition tagPosition() const
Returns the position (in the output file) where the tag information is written when applying changes.
Definition: mediafileinfo.h:557
TagParser::MediaFileInfo::container
AbstractContainer * container() const
Returns the container for the current file.
Definition: mediafileinfo.h:432
TagParser::MediaFileInfo::clearParsingResults
void clearParsingResults()
Clears all parsing results and assigned/created/changed information such as detected container format...
Definition: mediafileinfo.cpp:1289
TagParser::MediaFileInfo::parseEverything
void parseEverything(Diagnostics &diag)
Parses the container format, the tracks and the tag information of the current file.
Definition: mediafileinfo.cpp:513
TagParser::Adts
@ Adts
Definition: signature.cpp:86
TagParser::MpegAudioFrames
@ MpegAudioFrames
Definition: signature.cpp:91
TagParser::MediaFileInfo::removeAllTags
void removeAllTags()
Removes all assigned tags from the file.
Definition: mediafileinfo.cpp:1109
TagParser::TagValue::setDescription
void setDescription(const std::string &value, TagTextEncoding encoding=TagTextEncoding::Latin1)
Sets the description.
Definition: tagvalue.h:526
TagParser::PositionInSet
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:21
OverallTests
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:40
OverallTests::OverallTests
OverallTests()
Definition: overallgeneral.cpp:5
TagParser::BasicFileInfo::close
void close()
A possibly opened std::fstream will be closed.
Definition: basicfileinfo.cpp:71
TagParser::AbstractContainer::removeTrack
virtual bool removeTrack(AbstractTrack *track)
Removes the specified track to the container.
Definition: abstractcontainer.cpp:391
TagParser::MediaFileInfo::applyChanges
void applyChanges(Diagnostics &diag, AbortableProgressFeedback &progress)
Applies assigned/changed tag information to the current file.
Definition: mediafileinfo.cpp:659
TagParser::MediaFileInfo::indexPosition
ElementPosition indexPosition() const
Returns the position (in the output file) where the index is written when applying changes.
Definition: mediafileinfo.h:602
TagParser::MediaFileInfo::containerFormat
ContainerFormat containerFormat() const
Returns the container format of the current file.
Definition: mediafileinfo.h:211
TagParser::AbstractContainer::determineIndexPosition
virtual ElementPosition determineIndexPosition(Diagnostics &diag) const
Determines the position of the index.
Definition: abstractcontainer.cpp:183
TagParser::Mp4
@ Mp4
Definition: signature.cpp:53