tests: Check tag and index position

This commit is contained in:
Martchus 2017-05-23 00:52:56 +02:00
parent 9c3f596699
commit 1f1fb4c302
5 changed files with 62 additions and 13 deletions

View File

@ -173,6 +173,7 @@ set(META_PUBLIC_SHARED_LIB_DEPENDS c++utilities)
set(META_PUBLIC_STATIC_LIB_DEPENDS c++utilities_static)
set(META_PRIVATE_COMPILE_DEFINITIONS LEGACY_API)
set(META_NO_TIDY ON)
set(META_REQUIRED_CPP_UNIT_VERSION 1.14.0)
# find c++utilities
find_package(c++utilities 4.7.0 REQUIRED)

View File

@ -76,7 +76,7 @@ private:
void checkMkvTestfileHandbrakeChapters();
void checkMkvTestfileNestedTags();
void checkMkvTestMetaData();
void checkMkvPaddingConstraints();
void checkMkvConstraints();
void checkMp4Testfile1();
void checkMp4Testfile2();
@ -84,7 +84,7 @@ private:
void checkMp4Testfile4();
void checkMp4Testfile5();
void checkMp4TestMetaData();
void checkMp4PaddingConstraints();
void checkMp4Constraints();
void checkMp3Testfile1();
void checkMp3TestMetaData();
@ -136,6 +136,8 @@ private:
string m_flacInOggPath;
TagStatus m_tagStatus;
uint16 m_mode;
ElementPosition m_expectedTagPos;
ElementPosition m_expectedIndexPos;
};
#endif // TAGPARSER_OVERALL_TESTS_H

View File

@ -53,6 +53,41 @@ void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRouti
m_fileInfo.setPath(path);
m_fileInfo.reopen(true);
m_fileInfo.parseEverything();
// determine expected tag and index position
switch(m_fileInfo.containerFormat()) {
case ContainerFormat::Mp4:
CPPUNIT_ASSERT(m_fileInfo.container());
if(m_fileInfo.tagPosition() != ElementPosition::Keep) {
m_expectedTagPos = m_fileInfo.tagPosition();
} else {
m_expectedTagPos = m_fileInfo.container()->determineTagPosition();
if(m_expectedTagPos == ElementPosition::Keep) {
// if there is no tag present, the resulting tag position should equal the
// current index position
m_expectedTagPos = m_fileInfo.container()->determineIndexPosition();
}
}
break;
case ContainerFormat::Matroska:
CPPUNIT_ASSERT(m_fileInfo.container());
// since a tag is always created, it can always be expected at the specified position
if(m_fileInfo.tagPosition() != ElementPosition::Keep) {
m_expectedTagPos = m_fileInfo.tagPosition();
} else {
m_expectedTagPos = m_fileInfo.container()->determineTagPosition();
}
// an index is only present if the file had one before, hence specifying the index position
// might not have an effect
m_expectedIndexPos = m_fileInfo.container()->determineIndexPosition();
if(m_fileInfo.indexPosition() != ElementPosition::Keep && m_expectedIndexPos != ElementPosition::Keep) {
m_expectedIndexPos = m_fileInfo.indexPosition();
}
break;
default:
;
}
// invoke testroutine to do and apply changes
(this->*modifyRoutine)();
// apply changes and ensure that the previous parsing results are cleared
@ -64,10 +99,10 @@ void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRouti
// invoke suitable testroutine to check padding constraints
switch(m_fileInfo.containerFormat()) {
case ContainerFormat::Matroska:
checkMkvPaddingConstraints();
checkMkvConstraints();
break;
case ContainerFormat::Mp4:
checkMp4PaddingConstraints();
checkMp4Constraints();
break;
case ContainerFormat::MpegAudioFrames:
case ContainerFormat::Adts:
@ -76,6 +111,7 @@ void OverallTests::makeFile(const string &path, void (OverallTests::*modifyRouti
default:
;
}
// close and remove file and backup files
m_fileInfo.close();
remove(path.c_str());

View File

@ -492,19 +492,25 @@ void OverallTests::checkMkvTestMetaData()
}
/*!
* \brief Checks whether padding constraints are met.
* \brief Checks whether padding and element position constraints are met.
*/
void OverallTests::checkMkvPaddingConstraints()
void OverallTests::checkMkvConstraints()
{
using namespace MkvTestFlags;
CPPUNIT_ASSERT(m_fileInfo.container());
if(m_mode & PaddingConstraints) {
if(m_mode & ForceRewring) {
CPPUNIT_ASSERT(m_fileInfo.paddingSize() == 4096);
CPPUNIT_ASSERT_EQUAL(4096ul, m_fileInfo.paddingSize());
} else {
CPPUNIT_ASSERT(m_fileInfo.paddingSize() >= 1024);
CPPUNIT_ASSERT(m_fileInfo.paddingSize() <= (4096 + 1024));
// TODO: check tag/index position and rewriting behaviour
}
if(!(m_mode & RemoveTag) && (m_expectedTagPos != ElementPosition::Keep) && ((m_mode & ForceRewring) || (m_mode & ForceTagPos))) {
CPPUNIT_ASSERT_EQUAL(m_expectedTagPos, m_fileInfo.container()->determineTagPosition());
}
if((m_expectedIndexPos != ElementPosition::Keep) && ((m_mode & ForceRewring) || (m_mode & ForceIndexPos))) {
CPPUNIT_ASSERT_EQUAL(m_expectedIndexPos, m_fileInfo.container()->determineIndexPosition());
}
}
}
@ -557,7 +563,7 @@ void OverallTests::createMkvWithNestedTags()
m_nestedTagsMkvPath = workingCopyPathMode("mtx-test-data/mkv/nested-tags.mkv", WorkingCopyMode::NoCopy);
remove(m_nestedTagsMkvPath.data());
cerr << "\n- creating testfile \"" << m_nestedTagsMkvPath << "\" with mkvmerge" << endl;
cerr << "\n\n- Create testfile \"" << m_nestedTagsMkvPath << "\" with mkvmerge" << endl;
const string tagsMkvPath(testFilePath("mtx-test-data/mkv/tags.mkv"));
const string tagsXmlPath(testFilePath("mkv/nested-tags.xml"));
const char *const mkvmergeArgs[] = {

View File

@ -268,19 +268,22 @@ void OverallTests::checkMp4TestMetaData()
}
/*!
* \brief Checks whether padding constraints are met.
* \brief Checks whether padding and element position constraints are met.
*/
void OverallTests::checkMp4PaddingConstraints()
void OverallTests::checkMp4Constraints()
{
using namespace Mp4TestFlags;
CPPUNIT_ASSERT(m_fileInfo.container());
if(m_mode & PaddingConstraints) {
if(m_mode & ForceRewring) {
CPPUNIT_ASSERT(m_fileInfo.paddingSize() == 4096);
CPPUNIT_ASSERT_EQUAL(4096ul, m_fileInfo.paddingSize());
} else {
CPPUNIT_ASSERT(m_fileInfo.paddingSize() >= 1024);
CPPUNIT_ASSERT(m_fileInfo.paddingSize() <= (4096 + 1024));
// TODO: check tag position and rewriting behaviour
}
if(!(m_mode & RemoveTag) && (m_fileInfo.container()->documentType() != "dash") && ((m_mode & ForceRewring) || (m_mode & ForceTagPos))) {
CPPUNIT_ASSERT_EQUAL(m_expectedTagPos, m_fileInfo.container()->determineTagPosition());
}
}
}
@ -330,6 +333,7 @@ void OverallTests::testMp4Making()
using namespace Mp4TestFlags;
// setup test conditions
m_fileInfo.setForceRewrite(m_mode & ForceRewring);
if(m_mode & KeepTagPos) {
m_fileInfo.setTagPosition(ElementPosition::Keep);