DSDIFF: Fix adding and removing DIIN chunks

Also modernize and simplify code, fix formatting, support
ID3v2FrameFactory, fix updating the internal chunk bookkeeping
after file modifications, stripping ID3 and DIIN tags.
This commit is contained in:
Urs Fleisch
2023-10-14 06:50:59 +02:00
parent 19cceab211
commit 6b5f28d56d
7 changed files with 228 additions and 225 deletions

View File

@ -1,8 +1,31 @@
#include <string>
#include <cstdio>
#include <tag.h>
#include <tbytevectorlist.h>
#include <dsdifffile.h>
/***************************************************************************
copyright : (C) 2013-2023 Stephen F. Booth
email : me@sbooth.org
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "tbytevectorlist.h"
#include "dsdifffile.h"
#include "plainfile.h"
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -26,7 +49,6 @@ public:
{
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());
@ -41,15 +63,16 @@ public:
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;
{
DSDIFF::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String(""), f.tag()->artist());
f.tag()->setArtist("The Artist");
f.save();
}
{
DSDIFF::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("The Artist"), f.tag()->artist());
}
}
void testSaveID3v2()
@ -77,7 +100,7 @@ public:
{
DSDIFF::File f(newname.c_str());
CPPUNIT_ASSERT(!f.hasID3v2Tag());
f.tag()->setTitle(L"TitleXXX");
f.ID3v2Tag(true)->setTitle(L"TitleXXX");
f.save();
CPPUNIT_ASSERT(f.hasID3v2Tag());
}
@ -117,7 +140,8 @@ public:
ScopedFileCopy copy("empty10ms", ".dff");
{
DSDIFF::File f(copy.fileName().c_str());
f.tag()->setArtist("X");
f.ID3v2Tag(true)->setArtist("X");
f.DIINTag(true)->setArtist("Y");
f.save();
}
{
@ -183,6 +207,7 @@ public:
{
DSDIFF::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(7186), f.length());
CPPUNIT_ASSERT_EQUAL(String(""), f.tag()->title());
f.tag()->setTitle("NEW TITLE");
f.save();
@ -190,14 +215,21 @@ public:
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());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(8292), f.length());
f.save();
CPPUNIT_ASSERT_EQUAL(static_cast<long long>(8252), f.length());
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(8292), f.length());
}
{
DSDIFF::File f(newname.c_str());
CPPUNIT_ASSERT_EQUAL(String("NEW TITLE 2"), f.tag()->title());
f.strip();
CPPUNIT_ASSERT_EQUAL(static_cast<offset_t>(7186), f.length());
}
// Check if file without tags is same as original empty file
const ByteVector dsfData = PlainFile(TEST_FILE_PATH_C("empty10ms.dff")).readAll();
const ByteVector fileData = PlainFile(newname.c_str()).readAll();
CPPUNIT_ASSERT(dsfData == fileData);
}
};