Tag Parser  6.2.2
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 
9 {
10  m_testTitle.assignText("some title", TagTextEncoding::Utf8);
11  m_testComment.assignText("some cómment", TagTextEncoding::Utf8);
12  m_testComment.setDescription("some descriptión", TagTextEncoding::Utf8);
13  m_testAlbum.assignText("some album", TagTextEncoding::Utf8);
14  m_testPartNumber.assignInteger(41);
15  m_testTotalParts.assignInteger(61);
16  m_testPosition.assignPosition(PositionInSet(41, 61));
17 }
18 
20 {
21  for(const string &file : {m_nestedTagsMkvPath, m_rawFlacPath, m_flacInOggPath}) {
22  if(!file.empty()) {
23  remove(file.data());
24  }
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_fileInfo.setPath(path);
37  m_fileInfo.reopen(true);
38  m_fileInfo.parseEverything();
39  // invoke testroutine to check whether parsing results are correct
40  (this->*checkRoutine)();
41  m_fileInfo.close();
42 }
43 
48 void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRoutine)(void), void (OverallTests::*checkRoutine)(void))
49 {
50  // print current file
51  cerr << "- testing " << path << endl;
52  // ensure file is open and everything is parsed
53  m_fileInfo.setPath(path);
54  m_fileInfo.reopen(true);
55  m_fileInfo.parseEverything();
56 
57  // determine expected tag and index position
58  switch(m_fileInfo.containerFormat()) {
60  CPPUNIT_ASSERT(m_fileInfo.container());
61  if(m_fileInfo.tagPosition() != ElementPosition::Keep) {
62  m_expectedTagPos = m_fileInfo.tagPosition();
63  } else {
64  m_expectedTagPos = m_fileInfo.container()->determineTagPosition();
65  if(m_expectedTagPos == ElementPosition::Keep) {
66  // if there is no tag present, the resulting tag position should equal the
67  // current index position
68  m_expectedTagPos = m_fileInfo.container()->determineIndexPosition();
69  }
70  }
71  break;
72  case ContainerFormat::Matroska:
73  CPPUNIT_ASSERT(m_fileInfo.container());
74  // since a tag is always created, it can always be expected at the specified position
75  if(m_fileInfo.tagPosition() != ElementPosition::Keep) {
76  m_expectedTagPos = m_fileInfo.tagPosition();
77  } else {
78  m_expectedTagPos = m_fileInfo.container()->determineTagPosition();
79  }
80  // an index is only present if the file had one before, hence specifying the index position
81  // might not have an effect
82  m_expectedIndexPos = m_fileInfo.container()->determineIndexPosition();
83  if(m_fileInfo.indexPosition() != ElementPosition::Keep && m_expectedIndexPos != ElementPosition::Keep) {
84  m_expectedIndexPos = m_fileInfo.indexPosition();
85  }
86  break;
87  default:
88  ;
89  }
90 
91  // invoke testroutine to do and apply changes
92  (this->*modifyRoutine)();
93  // apply changes and ensure that the previous parsing results are cleared
94  m_fileInfo.applyChanges();
95  m_fileInfo.clearParsingResults();
96  // reparse the file and invoke testroutine to check whether changings have been applied correctly
97  m_fileInfo.parseEverything();
98  (this->*checkRoutine)();
99  // invoke suitable testroutine to check padding constraints
100  switch(m_fileInfo.containerFormat()) {
101  case ContainerFormat::Matroska:
102  checkMkvConstraints();
103  break;
105  checkMp4Constraints();
106  break;
109  checkMp3PaddingConstraints();
110  break;
111  default:
112  ;
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 }
void setDescription(const std::string &value, TagTextEncoding encoding=TagTextEncoding::Latin1)
Sets the description.
Definition: tagvalue.h:396
AbstractContainer * container() const
Returns the container for the current file.
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:550
CPPUNIT_TEST_SUITE_REGISTRATION(OverallTests)
void reopen(bool readonly=false)
Opens a std::fstream for the current file.
virtual ElementPosition determineTagPosition() const
Determines the position of the tags inside the file.
void setPath(const std::string &path)
Sets the current file.
void applyChanges()
Applies assigned/changed tag information to the current file.
The PositionInSet class describes the position of an element in a set which consists of a certain num...
Definition: positioninset.h:20
void close()
A possibly opened std::fstream will be closed.
The OverallTests class tests reading and writing tags and parsing technical information for all suppo...
Definition: overall.h:42
ElementPosition indexPosition() const
Returns the position (in the output file) where the index is written when applying changes...
void assignPosition(PositionInSet value)
Assigns the given PositionInSet value.
Definition: tagvalue.h:275
void assignInteger(int value)
Assigns the given integer value.
Definition: tagvalue.cpp:601
void parseEverything()
Parses the container format, the tracks and the tag information of the current file.
void clearParsingResults()
Clears all parsing results and assigned/created/changed information such as container format...
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.
void setUp()
Creates some test meta data.
ContainerFormat containerFormat() const
Returns the container format of the current file.
virtual ElementPosition determineIndexPosition() const
Determines the position of the index.