Tag Parser 12.5.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
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
28
32void 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
50void 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()) {
62 case ContainerFormat::Mp4:
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;
106 case ContainerFormat::Mp4:
107 checkMp4Constraints();
108 break;
109 case ContainerFormat::MpegAudioFrames:
110 case ContainerFormat::Adts:
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
125void OverallTests::removeAllTags()
126{
127 m_fileInfo.removeAllTags();
128}
129
134void OverallTests::noop()
135{
136}
137
141void 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.
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.
CPPUNIT_TEST_SUITE_REGISTRATION(OverallTests)