mirror of
https://github.com/taglib/taglib.git
synced 2025-07-18 21:14:23 -04:00
DSDIFF support, add tests, fix formatting
This commit is contained in:
committed by
Urs Fleisch
parent
182edcd3f9
commit
19cceab211
@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/it
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/xm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/dsf
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../taglib/dsdiff
|
||||
)
|
||||
|
||||
SET(test_runner_SRCS
|
||||
@ -71,6 +72,7 @@ SET(test_runner_SRCS
|
||||
test_opus.cpp
|
||||
test_speex.cpp
|
||||
test_dsf.cpp
|
||||
test_dsdiff.cpp
|
||||
test_sizes.cpp
|
||||
test_versionnumber.cpp
|
||||
test_tag_c.cpp
|
||||
|
BIN
tests/data/empty10ms.dff
Normal file
BIN
tests/data/empty10ms.dff
Normal file
Binary file not shown.
204
tests/test_dsdiff.cpp
Normal file
204
tests/test_dsdiff.cpp
Normal file
@ -0,0 +1,204 @@
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <tag.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <dsdifffile.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestDSDIFF : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestDSDIFF);
|
||||
CPPUNIT_TEST(testProperties);
|
||||
CPPUNIT_TEST(testTags);
|
||||
CPPUNIT_TEST(testSaveID3v2);
|
||||
CPPUNIT_TEST(testSaveID3v23);
|
||||
CPPUNIT_TEST(testStrip);
|
||||
CPPUNIT_TEST(testRepeatedSave);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testProperties()
|
||||
{
|
||||
DSDIFF::File f(TEST_FILE_PATH_C("empty10ms.dff"));
|
||||
CPPUNIT_ASSERT(f.audioProperties());
|
||||
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->length());
|
||||
CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
|
||||
CPPUNIT_ASSERT_EQUAL(10, f.audioProperties()->lengthInMilliseconds());
|
||||
CPPUNIT_ASSERT_EQUAL(5644, f.audioProperties()->bitrate());
|
||||
CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
|
||||
CPPUNIT_ASSERT_EQUAL(2822400, f.audioProperties()->sampleRate());
|
||||
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->bitsPerSample());
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<long long>(28224), f.audioProperties()->sampleCount());
|
||||
}
|
||||
|
||||
void testTags()
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
string newname = copy.fileName();
|
||||
|
||||
DSDIFF::File *f = new DSDIFF::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String(""), f->tag()->artist());
|
||||
f->tag()->setArtist("The Artist");
|
||||
f->save();
|
||||
delete f;
|
||||
|
||||
f = new DSDIFF::File(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist());
|
||||
delete f;
|
||||
}
|
||||
|
||||
void testSaveID3v2()
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
string newname = copy.fileName();
|
||||
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT(!f.hasID3v2Tag());
|
||||
|
||||
f.tag()->setTitle(L"TitleXXX");
|
||||
f.save();
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT_EQUAL(String(L"TitleXXX"), f.tag()->title());
|
||||
|
||||
f.tag()->setTitle("");
|
||||
f.save();
|
||||
CPPUNIT_ASSERT(!f.hasID3v2Tag());
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT(!f.hasID3v2Tag());
|
||||
f.tag()->setTitle(L"TitleXXX");
|
||||
f.save();
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT_EQUAL(String(L"TitleXXX"), f.tag()->title());
|
||||
}
|
||||
}
|
||||
|
||||
void testSaveID3v23()
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
string newname = copy.fileName();
|
||||
|
||||
String xxx = ByteVector(254, 'X');
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(false, f.hasID3v2Tag());
|
||||
|
||||
f.tag()->setTitle(xxx);
|
||||
f.tag()->setArtist("Artist A");
|
||||
f.save(DSDIFF::File::AllTags, File::StripOthers, ID3v2::v3);
|
||||
CPPUNIT_ASSERT_EQUAL(true, f.hasID3v2Tag());
|
||||
}
|
||||
{
|
||||
DSDIFF::File f2(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL((unsigned int)3, f2.ID3v2Tag()->header()->majorVersion());
|
||||
CPPUNIT_ASSERT_EQUAL(String("Artist A"), f2.tag()->artist());
|
||||
CPPUNIT_ASSERT_EQUAL(xxx, f2.tag()->title());
|
||||
}
|
||||
}
|
||||
|
||||
void testStrip()
|
||||
{
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
f.tag()->setArtist("X");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT(f.hasDIINTag());
|
||||
f.strip();
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(!f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT(!f.hasDIINTag());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
f.ID3v2Tag(true);
|
||||
f.DIINTag(true);
|
||||
f.tag()->setArtist("X");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT(f.hasDIINTag());
|
||||
f.strip(DSDIFF::File::ID3v2);
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(!f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT(f.hasDIINTag());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
f.tag()->setArtist("X");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT(f.hasDIINTag());
|
||||
f.strip(DSDIFF::File::DIIN);
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.hasID3v2Tag());
|
||||
CPPUNIT_ASSERT(!f.hasDIINTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testRepeatedSave()
|
||||
{
|
||||
ScopedFileCopy copy("empty10ms", ".dff");
|
||||
string newname = copy.fileName();
|
||||
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String(""), f.tag()->title());
|
||||
f.tag()->setTitle("NEW TITLE");
|
||||
f.save();
|
||||
CPPUNIT_ASSERT_EQUAL(String("NEW TITLE"), f.tag()->title());
|
||||
f.tag()->setTitle("NEW TITLE 2");
|
||||
f.save();
|
||||
CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title());
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<long long>(8252), f.length());
|
||||
f.save();
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<long long>(8252), f.length());
|
||||
}
|
||||
{
|
||||
DSDIFF::File f(newname.c_str());
|
||||
CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestDSDIFF);
|
@ -46,6 +46,7 @@
|
||||
#include "opusfile.h"
|
||||
#include "xmfile.h"
|
||||
#include "dsffile.h"
|
||||
#include "dsdifffile.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "utils.h"
|
||||
|
||||
@ -101,6 +102,7 @@ class TestFileRef : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testWavPack);
|
||||
CPPUNIT_TEST(testOpus);
|
||||
CPPUNIT_TEST(testDSF);
|
||||
CPPUNIT_TEST(testDSDIFF);
|
||||
CPPUNIT_TEST(testUnsupported);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testAudioProperties);
|
||||
@ -338,6 +340,11 @@ public:
|
||||
fileRefSave<DSF::File>("empty10ms",".dsf");
|
||||
}
|
||||
|
||||
void testDSDIFF()
|
||||
{
|
||||
fileRefSave<DSDIFF::File>("empty10ms",".dff");
|
||||
}
|
||||
|
||||
void testUnsupported()
|
||||
{
|
||||
FileRef f1(TEST_FILE_PATH_C("no-extension"));
|
||||
@ -394,6 +401,8 @@ public:
|
||||
CPPUNIT_ASSERT(extensions.contains("opus"));
|
||||
CPPUNIT_ASSERT(extensions.contains("xm"));
|
||||
CPPUNIT_ASSERT(extensions.contains("dsf"));
|
||||
CPPUNIT_ASSERT(extensions.contains("dff"));
|
||||
CPPUNIT_ASSERT(extensions.contains("dsdiff"));
|
||||
}
|
||||
|
||||
void testFileResolver()
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include "commentsframe.h"
|
||||
#include "dsffile.h"
|
||||
#include "dsfproperties.h"
|
||||
#include "dsdifffile.h"
|
||||
#include "dsdiffproperties.h"
|
||||
#include "eventtimingcodesframe.h"
|
||||
#include "fileref.h"
|
||||
#include "flacfile.h"
|
||||
@ -160,6 +162,8 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(2, false), sizeof(TagLib::ByteVectorList));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::ByteVectorStream));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(0, true), sizeof(TagLib::DebugListener));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::DSDIFF::File));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::DSDIFF::Properties));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::FLAC::File));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::DSF::File));
|
||||
CPPUNIT_ASSERT_EQUAL(classSize(1, true), sizeof(TagLib::DSF::Properties));
|
||||
|
Reference in New Issue
Block a user