4#include "../abstracttrack.h"
6#include "../vorbis/vorbiscomment.h"
8#include <c++utilities/io/misc.h>
17void OverallTests::checkOggTestfile1()
20 const auto tracks = m_fileInfo.
tracks();
21 CPPUNIT_ASSERT_EQUAL(2_st, tracks.size());
22 for (
const auto &track : tracks) {
23 switch (track->id()) {
26 CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Theora, track->format().general);
30 CPPUNIT_ASSERT_EQUAL(GeneralMediaFormat::Vorbis, track->format().general);
31 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint16_t
>(2), track->channelCount());
32 CPPUNIT_ASSERT_EQUAL(44100u, track->samplingFrequency());
33 CPPUNIT_ASSERT_EQUAL(4, track->duration().minutes());
36 CPPUNIT_FAIL(
"unknown track ID");
39 const auto tags = m_fileInfo.
tags();
40 switch (m_tagStatus) {
43 CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
44 CPPUNIT_ASSERT_EQUAL(
"ffmpeg2theora 0.13"s, tags.front()->value(
KnownField::Encoder).toString());
49 checkOggTestMetaData();
52 CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
55 CPPUNIT_ASSERT(m_diag.
level() <= DiagLevel::Information);
61void OverallTests::checkOggTestfile2()
64 const auto tracks = m_fileInfo.
tracks();
65 CPPUNIT_ASSERT_EQUAL(1_st, tracks.size());
66 for (
const auto &track : tracks) {
67 switch (track->id()) {
71 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint16_t
>(2), track->channelCount());
72 CPPUNIT_ASSERT_EQUAL(48000u, track->samplingFrequency());
73 CPPUNIT_ASSERT_EQUAL(1, track->duration().minutes());
76 CPPUNIT_FAIL(
"unknown track ID");
79 const auto tags = m_fileInfo.
tags();
80 switch (m_tagStatus) {
83 CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
84 CPPUNIT_ASSERT_EQUAL(
"opusenc from opus-tools 0.1.6"s, tags.front()->value(
KnownField::Encoder).toString());
87 checkOggTestMetaData();
90 CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
93 CPPUNIT_ASSERT(m_diag.
level() <= DiagLevel::Information);
99void OverallTests::checkOggTestfile3()
102 const auto tracks = m_fileInfo.
tracks();
103 CPPUNIT_ASSERT_EQUAL(1_st, tracks.size());
104 for (
const auto &track : tracks) {
105 switch (track->id()) {
109 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint16_t
>(2), track->channelCount());
110 CPPUNIT_ASSERT_EQUAL(48000u, track->samplingFrequency());
111 CPPUNIT_ASSERT_EQUAL(TimeSpan::fromSeconds(19.461), track->duration());
114 CPPUNIT_FAIL(
"unknown track ID");
117 const auto tags = m_fileInfo.
tags();
118 switch (m_tagStatus) {
121 CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
122 CPPUNIT_ASSERT_EQUAL(
"Lavf58.76.100"s, tags.front()->value(
KnownField::Encoder).toString());
123 CPPUNIT_ASSERT_EQUAL(
"eng"s, tags.front()->value(KnownField::Language).toString());
126 checkOggTestMetaDataCover();
129 CPPUNIT_ASSERT_EQUAL(0_st, tags.size());
133 CPPUNIT_ASSERT_MESSAGE(
"no warnings for non-broken file", m_diag.
level() <= DiagLevel::Information);
136 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"warning present", DiagLevel::Warning, m_diag.
level());
137 for (
const auto &msg : m_diag) {
138 if (msg.level() == DiagLevel::Warning) {
139 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"warning due to broken segment termination",
"3 bytes left in last segment."s, msg.message());
140 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"warning relates to Vorbis comment",
"parsing Vorbis comment"s, msg.context());
149void OverallTests::checkOggTestMetaData()
152 const auto tags = m_fileInfo.
tags();
154 CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
155 CPPUNIT_ASSERT(tag !=
nullptr);
165 m_preservedMetaData.pop();
168void OverallTests::checkOggTestMetaDataCover()
171 const auto tags = m_fileInfo.
tags();
173 CPPUNIT_ASSERT_EQUAL(1_st, tags.size());
174 CPPUNIT_ASSERT(tag !=
nullptr);
176 const auto expectedCoverData = readFile(testFilePath(
"ogg/example-cover.png"));
177 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"expected cover assigned", std::string_view(expectedCoverData), tag->value(
KnownField::Cover).data());
180void OverallTests::setOggTestMetaData()
195void OverallTests::setOggTestMetaDataCover()
198 const auto cover = readFile(testFilePath(
"ogg/example-cover.png"));
208 cerr << endl <<
"OGG parser" << endl;
211 parseFile(testFilePath(
"mtx-test-data/ogg/qt4dance_medium.ogg"), &OverallTests::checkOggTestfile1);
212 parseFile(testFilePath(
"mtx-test-data/opus/v-opus.ogg"), &OverallTests::checkOggTestfile2);
213 parseFile(testFilePath(
"ogg/noise-broken-segment-termination.opus"), &OverallTests::checkOggTestfile3);
228 for (m_mode = 0; m_mode != 0x2; ++m_mode) {
235 list<string> testConditions;
237 testConditions.emplace_back(
"removing tag");
239 testConditions.emplace_back(
"modifying tag");
241 cerr << endl <<
"OGG maker - testmode " << m_mode <<
": " << joinStrings(testConditions,
", ") << endl;
245 const auto modifyRoutine = (m_mode &
RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaData;
246 const auto modifyRoutineCover = (m_mode &
RemoveTag) ? &OverallTests::removeAllTags : &OverallTests::setOggTestMetaDataCover;
247 makeFile(workingCopyPath(
"mtx-test-data/ogg/qt4dance_medium.ogg"), modifyRoutine, &OverallTests::checkOggTestfile1);
248 makeFile(workingCopyPath(
"mtx-test-data/opus/v-opus.ogg"), modifyRoutine, &OverallTests::checkOggTestfile2);
249 makeFile(workingCopyPath(
"ogg/noise-without-cover.opus"), modifyRoutineCover, &OverallTests::checkOggTestfile3);
void testOggParsing()
Tests the Ogg parser via MediaFileInfo.
void testOggMaking()
Tests the Ogg maker via MediaFileInfo.
DiagLevel level() const
Returns the worst diag level present in the container.
The TagValue class wraps values of different types.
std::string toString(TagTextEncoding encoding=TagTextEncoding::Unspecified) const
Converts the value of the current TagValue object to its equivalent std::string representation.