From 1f1fb4c3024b0d7daa7225fcfc8c18974c6de0e9 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 23 May 2017 00:52:56 +0200 Subject: [PATCH] tests: Check tag and index position --- CMakeLists.txt | 1 + tests/overall.h | 6 ++++-- tests/overallgeneral.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- tests/overallmkv.cpp | 16 +++++++++++----- tests/overallmp4.cpp | 12 ++++++++---- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 680c45c..7223986 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/tests/overall.h b/tests/overall.h index fef57fb..a44f2b5 100644 --- a/tests/overall.h +++ b/tests/overall.h @@ -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 diff --git a/tests/overallgeneral.cpp b/tests/overallgeneral.cpp index 6d0aee7..a577941 100644 --- a/tests/overallgeneral.cpp +++ b/tests/overallgeneral.cpp @@ -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()); diff --git a/tests/overallmkv.cpp b/tests/overallmkv.cpp index 9d1a241..73624be 100644 --- a/tests/overallmkv.cpp +++ b/tests/overallmkv.cpp @@ -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[] = { diff --git a/tests/overallmp4.cpp b/tests/overallmp4.cpp index 48fdf8c..79f5891 100644 --- a/tests/overallmp4.cpp +++ b/tests/overallmp4.cpp @@ -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);