2017-08-17 18:43:19 +02:00
|
|
|
#include "./helper.h"
|
|
|
|
|
|
|
|
#include "../abstracttrack.h"
|
2018-03-07 01:17:50 +01:00
|
|
|
#include "../mediafileinfo.h"
|
2021-02-04 23:21:50 +01:00
|
|
|
#include "../progressfeedback.h"
|
2017-08-17 18:43:19 +02:00
|
|
|
#include "../tag.h"
|
|
|
|
|
|
|
|
#include <c++utilities/tests/testutils.h>
|
2019-06-10 22:49:11 +02:00
|
|
|
using namespace CppUtilities;
|
2017-08-17 18:43:19 +02:00
|
|
|
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
using namespace std;
|
2019-06-10 22:49:11 +02:00
|
|
|
using namespace CppUtilities::Literals;
|
2018-03-06 23:09:15 +01:00
|
|
|
using namespace TagParser;
|
2017-08-17 18:43:19 +02:00
|
|
|
|
|
|
|
using namespace CPPUNIT_NS;
|
|
|
|
|
|
|
|
/*!
|
2018-06-03 21:00:49 +02:00
|
|
|
* \brief The MediaFileInfoTests tests convenience methods provided by TagParser::MediaFileInfo.
|
2017-08-17 18:43:19 +02:00
|
|
|
* \remarks It only tests parsing a simple Mkv/Mp4. Parsing different formats with different settings is tested in OverallTests.
|
|
|
|
*/
|
|
|
|
class MediaFileInfoTests : public TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(MediaFileInfoTests);
|
|
|
|
CPPUNIT_TEST(testInitialStatus);
|
|
|
|
CPPUNIT_TEST(testFileSystemMethods);
|
|
|
|
CPPUNIT_TEST(testParsingUnsupportedFile);
|
|
|
|
CPPUNIT_TEST(testFullParseAndFurtherProperties);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
2019-12-15 19:44:07 +01:00
|
|
|
void setUp() override;
|
|
|
|
void tearDown() override;
|
2017-08-17 18:43:19 +02:00
|
|
|
|
|
|
|
void testInitialStatus();
|
|
|
|
void testFileSystemMethods();
|
|
|
|
void testParsingUnsupportedFile();
|
|
|
|
void testPartialParsingAndTagCreationOfMp4File();
|
|
|
|
|
|
|
|
void testFullParseAndFurtherProperties();
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(MediaFileInfoTests);
|
|
|
|
|
|
|
|
void MediaFileInfoTests::setUp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFileInfoTests::tearDown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFileInfoTests::testInitialStatus()
|
|
|
|
{
|
|
|
|
const MediaFileInfo file;
|
|
|
|
CPPUNIT_ASSERT(!file.areTagsSupported());
|
|
|
|
CPPUNIT_ASSERT(!file.areTracksSupported());
|
|
|
|
CPPUNIT_ASSERT(!file.areChaptersSupported());
|
|
|
|
CPPUNIT_ASSERT(!file.areAttachmentsSupported());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.containerParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.tagsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.tracksParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.chaptersParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.attachmentsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ContainerFormat::Unknown, file.containerFormat());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFileInfoTests::testFileSystemMethods()
|
|
|
|
{
|
|
|
|
MediaFileInfo file("/usr/bin/unsupported.bin");
|
|
|
|
CPPUNIT_ASSERT_EQUAL("/usr/bin"s, file.containingDirectory());
|
|
|
|
CPPUNIT_ASSERT_EQUAL("unsupported.bin"s, file.fileName());
|
|
|
|
CPPUNIT_ASSERT_EQUAL("unsupported"s, file.fileName(true));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("/usr/bin/unsupported"s, file.pathWithoutExtension());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(".bin"s, file.extension());
|
2019-03-13 19:06:42 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(0), file.size());
|
2017-08-17 18:43:19 +02:00
|
|
|
file.reportPathChanged(testFilePath("unsupported.bin"));
|
|
|
|
file.open(true);
|
|
|
|
CPPUNIT_ASSERT(file.isOpen());
|
|
|
|
CPPUNIT_ASSERT(file.isReadOnly());
|
2019-03-13 19:06:42 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint64_t>(41), file.size());
|
2017-08-17 18:43:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFileInfoTests::testParsingUnsupportedFile()
|
|
|
|
{
|
2018-03-05 17:49:29 +01:00
|
|
|
Diagnostics diag;
|
2021-02-04 23:21:50 +01:00
|
|
|
AbortableProgressFeedback progress;
|
2017-08-17 18:43:19 +02:00
|
|
|
MediaFileInfo file(testFilePath("unsupported.bin"));
|
2021-02-04 23:21:50 +01:00
|
|
|
file.parseContainerFormat(diag, progress);
|
|
|
|
file.parseTags(diag, progress);
|
2017-08-17 18:43:19 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotSupported, file.containerParsingStatus());
|
2018-04-29 17:10:48 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotSupported, file.tagsParsingStatus());
|
2017-08-17 18:43:19 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.tracksParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.chaptersParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.attachmentsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ContainerFormat::Unknown, file.containerFormat());
|
|
|
|
file.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFileInfoTests::testPartialParsingAndTagCreationOfMp4File()
|
|
|
|
{
|
2018-03-05 17:49:29 +01:00
|
|
|
Diagnostics diag;
|
2021-02-04 23:21:50 +01:00
|
|
|
AbortableProgressFeedback progress;
|
2017-08-17 18:43:19 +02:00
|
|
|
MediaFileInfo file(testFilePath("mtx-test-data/aac/he-aacv2-ps.m4a"));
|
|
|
|
file.open(true);
|
2021-02-04 23:21:50 +01:00
|
|
|
file.parseContainerFormat(diag, progress);
|
|
|
|
file.parseTags(diag, progress);
|
|
|
|
file.parseAttachments(diag, progress);
|
2017-08-17 18:43:19 +02:00
|
|
|
file.close();
|
2021-02-04 23:21:50 +01:00
|
|
|
CPPUNIT_ASSERT_THROW_MESSAGE("std::ios_base::failure thrown if file closed", file.parseTracks(diag, progress), std::ios_base::failure);
|
2017-08-17 18:43:19 +02:00
|
|
|
CPPUNIT_ASSERT(file.areTagsSupported());
|
|
|
|
CPPUNIT_ASSERT(file.areTracksSupported());
|
|
|
|
CPPUNIT_ASSERT(!file.areChaptersSupported());
|
|
|
|
CPPUNIT_ASSERT(!file.areAttachmentsSupported());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.containerParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.tagsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.tracksParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotParsedYet, file.chaptersParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::NotSupported, file.attachmentsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, file.trackCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ContainerFormat::Mp4, file.containerFormat());
|
2018-03-07 01:17:50 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Diagnostics({ DiagMessage(DiagLevel::Information,
|
|
|
|
"Parsing attachments is not implemented for the container format of the file.", "parsing attachments") }),
|
|
|
|
diag);
|
2018-03-05 17:49:29 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(DiagLevel::Information, diag.level());
|
2017-08-17 18:43:19 +02:00
|
|
|
|
|
|
|
// create/remove tag
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, file.matroskaTags().size());
|
|
|
|
CPPUNIT_ASSERT(!file.id3v1Tag());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, file.id3v2Tags().size());
|
|
|
|
CPPUNIT_ASSERT(!file.vorbisComment());
|
|
|
|
CPPUNIT_ASSERT(!file.mp4Tag());
|
|
|
|
// NOTE: Maybe it should not be possible to create ID3 tags for MP4 file? It will be ignored anyways.
|
|
|
|
CPPUNIT_ASSERT(file.createId3v1Tag());
|
|
|
|
CPPUNIT_ASSERT(file.id3v1Tag());
|
|
|
|
CPPUNIT_ASSERT(file.createId3v2Tag());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1_st, file.id3v2Tags().size());
|
|
|
|
CPPUNIT_ASSERT(!file.createVorbisComment());
|
|
|
|
CPPUNIT_ASSERT(!file.vorbisComment());
|
|
|
|
CPPUNIT_ASSERT(!file.removeVorbisComment());
|
|
|
|
file.createAppropriateTags();
|
|
|
|
CPPUNIT_ASSERT(file.mp4Tag());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaFileInfoTests::testFullParseAndFurtherProperties()
|
|
|
|
{
|
2018-03-05 17:49:29 +01:00
|
|
|
Diagnostics diag;
|
2021-02-04 23:21:50 +01:00
|
|
|
AbortableProgressFeedback progress;
|
2017-08-17 18:43:19 +02:00
|
|
|
MediaFileInfo file(testFilePath("matroska_wave1/test1.mkv"));
|
|
|
|
file.open(true);
|
2021-02-04 23:21:50 +01:00
|
|
|
file.parseEverything(diag, progress);
|
2017-08-17 18:43:19 +02:00
|
|
|
// calling parse methods twice should not do anything (and hence can not fail anymore because the file has already been closed)
|
|
|
|
file.close();
|
2021-02-04 23:21:50 +01:00
|
|
|
file.parseEverything(diag, progress);
|
2017-08-17 18:43:19 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.containerParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.tagsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.tracksParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.chaptersParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ParsingStatus::Ok, file.attachmentsParsingStatus());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(ContainerFormat::Matroska, file.containerFormat());
|
|
|
|
|
|
|
|
// general info
|
|
|
|
CPPUNIT_ASSERT(file.container());
|
|
|
|
CPPUNIT_ASSERT(file.areTagsSupported());
|
|
|
|
CPPUNIT_ASSERT(file.hasAnyTag());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1_st, file.tags().size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1_st, file.matroskaTags().size());
|
|
|
|
CPPUNIT_ASSERT(!file.mp4Tag());
|
|
|
|
CPPUNIT_ASSERT(!file.vorbisComment());
|
|
|
|
CPPUNIT_ASSERT(file.areTracksSupported());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2_st, file.trackCount());
|
|
|
|
CPPUNIT_ASSERT(file.areChaptersSupported());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, file.chapters().size());
|
|
|
|
CPPUNIT_ASSERT(file.areAttachmentsSupported());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_st, file.attachments().size());
|
|
|
|
|
|
|
|
// notifications
|
2018-03-05 17:49:29 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Diagnostics(), diag);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(DiagLevel::None, diag.level());
|
|
|
|
diag.emplace_back(DiagLevel::Warning, "warning", "test");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(DiagLevel::Warning, diag.level());
|
|
|
|
diag.emplace_back(DiagLevel::Critical, "error", "test");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(DiagLevel::Critical, diag.level());
|
2017-08-17 18:43:19 +02:00
|
|
|
|
|
|
|
// track info / available languages
|
2020-12-13 18:37:15 +01:00
|
|
|
file.tracks().back()->setLocale(Locale("eng"sv, LocaleFormat::ISO_639_2_B));
|
2018-03-07 01:17:50 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL(unordered_set<string>({ "eng" }), file.availableLanguages());
|
2017-08-17 18:43:19 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(unordered_set<string>({}), file.availableLanguages(MediaType::Text));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("ID: 2422994868, type: Video"s, file.tracks()[0]->label());
|
2019-08-17 20:56:09 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL("ID: 3653291187, type: Audio, language: English"s, file.tracks()[1]->label());
|
2017-08-17 18:43:19 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL("MS-MPEG-4-480p / MP3-2ch-eng"s, file.technicalSummary());
|
|
|
|
}
|