mirror of
https://github.com/taglib/taglib.git
synced 2025-07-21 06:24:19 -04:00
Work-in-progress support for writing FLAC picture
This will enable the possibility to add support for accessing the Seektable and Cuesheet blocks, but I'm not planning on implementing that right now. CCBUG:218696 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1201717 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
@ -95,6 +95,9 @@ SET(flacs_SRCS
|
||||
flac/flacfile.cpp
|
||||
flac/flacpicture.cpp
|
||||
flac/flacproperties.cpp
|
||||
flac/flacmetadatablock.cpp
|
||||
flac/flacmetadatablocks.cpp
|
||||
flac/flacunknownmetadatablock.cpp
|
||||
)
|
||||
|
||||
SET(oggflacs_SRCS
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "flacpicture.h"
|
||||
#include "flacfile.h"
|
||||
#include "flacmetadatablock.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
|
51
taglib/flac/flacmetadatablock.cpp
Normal file
51
taglib/flac/flacmetadatablock.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/**************************************************************************
|
||||
copyright : (C) 2010 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
**************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <taglib.h>
|
||||
#include <tdebug.h>
|
||||
#include "flacmetadatablock.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class FLAC::MetadataBlock::MetadataBlockPrivate
|
||||
{
|
||||
public:
|
||||
MetadataBlockPrivate() {}
|
||||
|
||||
};
|
||||
|
||||
FLAC::MetadataBlock::MetadataBlock()
|
||||
{
|
||||
d = 0;
|
||||
}
|
||||
|
||||
FLAC::MetadataBlock::~MetadataBlock()
|
||||
{
|
||||
}
|
||||
|
75
taglib/flac/flacmetadatablock.h
Normal file
75
taglib/flac/flacmetadatablock.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**************************************************************************
|
||||
copyright : (C) 2010 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
**************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_FLACMETADATABLOCK_H
|
||||
#define TAGLIB_FLACMETADATABLOCK_H
|
||||
|
||||
#include "tlist.h"
|
||||
#include "tbytevector.h"
|
||||
#include "taglib_export.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace FLAC {
|
||||
|
||||
class TAGLIB_EXPORT MetadataBlock
|
||||
{
|
||||
public:
|
||||
MetadataBlock();
|
||||
virtual ~MetadataBlock();
|
||||
|
||||
enum BlockType {
|
||||
StreamInfo = 0,
|
||||
Padding,
|
||||
Application,
|
||||
SeekTable,
|
||||
VorbisComment,
|
||||
CueSheet,
|
||||
Picture
|
||||
};
|
||||
|
||||
/*!
|
||||
* Returns the FLAC metadata block type.
|
||||
*/
|
||||
virtual int code() const = 0;
|
||||
|
||||
/*!
|
||||
* Render the content of the block.
|
||||
*/
|
||||
virtual ByteVector render() const = 0;
|
||||
|
||||
private:
|
||||
MetadataBlock(const MetadataBlock &item);
|
||||
MetadataBlock &operator=(const MetadataBlock &item);
|
||||
|
||||
class MetadataBlockPrivate;
|
||||
MetadataBlockPrivate *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
111
taglib/flac/flacmetadatablocks.cpp
Normal file
111
taglib/flac/flacmetadatablocks.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/**************************************************************************
|
||||
copyright : (C) 2010 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
**************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <taglib.h>
|
||||
#include <tdebug.h>
|
||||
#include "flacfile.h"
|
||||
#include "flacunknownmetadatablock.h"
|
||||
#include "flacmetadatablock.h"
|
||||
#include "flacmetadatablocks.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class FLAC::MetadataBlocks::MetadataBlocksPrivate
|
||||
{
|
||||
public:
|
||||
MetadataBlocksPrivate() {}
|
||||
|
||||
List<MetadataBlock *> blocks;
|
||||
};
|
||||
|
||||
FLAC::MetadataBlocks::MetadataBlocks()
|
||||
{
|
||||
d = new MetadataBlocksPrivate();
|
||||
}
|
||||
|
||||
FLAC::MetadataBlocks::~MetadataBlocks()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
const List<FLAC::MetadataBlock *> &FLAC::MetadataBlocks::metadataBlockList() const
|
||||
{
|
||||
return d->blocks;
|
||||
}
|
||||
|
||||
bool FLAC::MetadataBlocks::read(FLAC::File *file)
|
||||
{
|
||||
bool isLastBlock = false;
|
||||
while(!isLastBlock) {
|
||||
ByteVector header = file->readBlock(4);
|
||||
if(header.size() != 4) {
|
||||
debug("FLAC::MetadataBlocks::read -- Unable to read 4 bytes long header");
|
||||
return false;
|
||||
}
|
||||
char blockType = header[0] & 0x7f;
|
||||
isLastBlock = (header[0] & 0x80) != 0;
|
||||
uint length = header.mid(1, 3).toUInt();
|
||||
ByteVector data = file->readBlock(length);
|
||||
if(data.size() != length) {
|
||||
debug("FLAC::MetadataBlocks::read -- Unable to read " + String::number(length) + " bytes long block body");
|
||||
return false;
|
||||
}
|
||||
if(blockType != FLAC::MetadataBlock::Padding) {
|
||||
FLAC::MetadataBlock *block = new FLAC::UnknownMetadataBlock(blockType, data);
|
||||
d->blocks.append(block);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ByteVector FLAC::MetadataBlocks::render(int originalLength) const
|
||||
{
|
||||
ByteVector result;
|
||||
for(uint i = 0; i < d->blocks.size(); i++) {
|
||||
FLAC::MetadataBlock *block = d->blocks[i];
|
||||
if(block->code() == FLAC::MetadataBlock::Padding)
|
||||
continue;
|
||||
ByteVector data = block->render();
|
||||
ByteVector header = ByteVector::fromUInt(data.size());
|
||||
header[0] = block->code();
|
||||
result.append(header);
|
||||
result.append(data);
|
||||
}
|
||||
int paddingLength = originalLength - result.size() - 4;
|
||||
// We have to resize the file, add some padding
|
||||
if (paddingLength < 0) {
|
||||
paddingLength = 4096;
|
||||
}
|
||||
ByteVector padding = ByteVector::fromUInt(paddingLength);
|
||||
padding.resize(paddingLength + 4);
|
||||
padding[0] = FLAC::MetadataBlock::Padding | 0x80;
|
||||
result.append(padding);
|
||||
return result;
|
||||
}
|
||||
|
69
taglib/flac/flacmetadatablocks.h
Normal file
69
taglib/flac/flacmetadatablocks.h
Normal file
@ -0,0 +1,69 @@
|
||||
/**************************************************************************
|
||||
copyright : (C) 2010 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
**************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_FLACMETADATABLOCKS_H
|
||||
#define TAGLIB_FLACMETADATABLOCKS_H
|
||||
|
||||
#include "tlist.h"
|
||||
#include "tbytevector.h"
|
||||
#include "taglib_export.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace FLAC {
|
||||
|
||||
class File;
|
||||
|
||||
class TAGLIB_EXPORT MetadataBlocks
|
||||
{
|
||||
public:
|
||||
MetadataBlocks();
|
||||
virtual ~MetadataBlocks();
|
||||
|
||||
/*!
|
||||
* Read the blocks from a file.
|
||||
*/
|
||||
bool read(File *file);
|
||||
|
||||
/*!
|
||||
* Render the blocks into a byte vector.
|
||||
*/
|
||||
ByteVector render(int originalLength) const;
|
||||
|
||||
const List<MetadataBlock *> &metadataBlockList() const;
|
||||
|
||||
private:
|
||||
MetadataBlocks(const MetadataBlocks &item);
|
||||
MetadataBlocks &operator=(const MetadataBlocks &item);
|
||||
|
||||
class MetadataBlocksPrivate;
|
||||
MetadataBlocksPrivate *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -70,6 +70,11 @@ FLAC::Picture::~Picture()
|
||||
delete d;
|
||||
}
|
||||
|
||||
int FLAC::Picture::code() const
|
||||
{
|
||||
return FLAC::MetadataBlock::Picture;
|
||||
}
|
||||
|
||||
bool FLAC::Picture::parse(const ByteVector &data)
|
||||
{
|
||||
if(data.size() < 32) {
|
||||
@ -115,6 +120,25 @@ bool FLAC::Picture::parse(const ByteVector &data)
|
||||
return true;
|
||||
}
|
||||
|
||||
ByteVector FLAC::Picture::render() const
|
||||
{
|
||||
ByteVector result;
|
||||
result.append(ByteVector::fromUInt(d->type));
|
||||
ByteVector mimeTypeData = d->mimeType.data(String::UTF8);
|
||||
result.append(ByteVector::fromUInt(mimeTypeData.size()));
|
||||
result.append(mimeTypeData);
|
||||
ByteVector descriptionData = d->description.data(String::UTF8);
|
||||
result.append(ByteVector::fromUInt(descriptionData.size()));
|
||||
result.append(descriptionData);
|
||||
result.append(ByteVector::fromUInt(d->width));
|
||||
result.append(ByteVector::fromUInt(d->height));
|
||||
result.append(ByteVector::fromUInt(d->colorDepth));
|
||||
result.append(ByteVector::fromUInt(d->numColors));
|
||||
result.append(ByteVector::fromUInt(d->data.size()));
|
||||
result.append(d->data);
|
||||
return result;
|
||||
}
|
||||
|
||||
FLAC::Picture::Type FLAC::Picture::type() const
|
||||
{
|
||||
return d->type;
|
||||
|
@ -30,12 +30,13 @@
|
||||
#include "tbytevector.h"
|
||||
#include "taglib_export.h"
|
||||
#include "attachedpictureframe.h"
|
||||
#include "flacmetadatablock.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace FLAC {
|
||||
|
||||
class TAGLIB_EXPORT Picture
|
||||
class TAGLIB_EXPORT Picture : public MetadataBlock
|
||||
{
|
||||
public:
|
||||
typedef ID3v2::AttachedPictureFrame::Type Type;
|
||||
@ -128,6 +129,16 @@ namespace TagLib {
|
||||
*/
|
||||
void setData(const ByteVector &data);
|
||||
|
||||
/*!
|
||||
* Returns the FLAC metadata block type.
|
||||
*/
|
||||
int code() const;
|
||||
|
||||
/*!
|
||||
* Render the content of the block.
|
||||
*/
|
||||
ByteVector render() const;
|
||||
|
||||
bool parse(const ByteVector &rawData);
|
||||
|
||||
private:
|
||||
|
83
taglib/flac/flacunknownmetadatablock.cpp
Normal file
83
taglib/flac/flacunknownmetadatablock.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/**************************************************************************
|
||||
copyright : (C) 2010 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
**************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <taglib.h>
|
||||
#include <tdebug.h>
|
||||
#include <tstring.h>
|
||||
#include "flacunknownmetadatablock.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class FLAC::UnknownMetadataBlock::UnknownMetadataBlockPrivate
|
||||
{
|
||||
public:
|
||||
UnknownMetadataBlockPrivate() : code(0) {}
|
||||
|
||||
int code;
|
||||
ByteVector data;
|
||||
};
|
||||
|
||||
FLAC::UnknownMetadataBlock::UnknownMetadataBlock(int code, const ByteVector &data)
|
||||
{
|
||||
d = new UnknownMetadataBlockPrivate;
|
||||
d->code = code;
|
||||
//debug(String(data.toHex()));
|
||||
d->data = data;
|
||||
}
|
||||
|
||||
FLAC::UnknownMetadataBlock::~UnknownMetadataBlock()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
int FLAC::UnknownMetadataBlock::code() const
|
||||
{
|
||||
return d->code;
|
||||
}
|
||||
|
||||
void FLAC::UnknownMetadataBlock::setCode(int code)
|
||||
{
|
||||
d->code = code;
|
||||
}
|
||||
|
||||
ByteVector FLAC::UnknownMetadataBlock::data() const
|
||||
{
|
||||
return d->data;
|
||||
}
|
||||
|
||||
void FLAC::UnknownMetadataBlock::setData(const ByteVector &data)
|
||||
{
|
||||
d->data = data;
|
||||
}
|
||||
|
||||
ByteVector FLAC::UnknownMetadataBlock::render() const
|
||||
{
|
||||
return d->data;
|
||||
}
|
||||
|
81
taglib/flac/flacunknownmetadatablock.h
Normal file
81
taglib/flac/flacunknownmetadatablock.h
Normal file
@ -0,0 +1,81 @@
|
||||
/**************************************************************************
|
||||
copyright : (C) 2010 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
**************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_FLACUNKNOWNMETADATABLOCK_H
|
||||
#define TAGLIB_FLACUNKNOWNMETADATABLOCK_H
|
||||
|
||||
#include "tlist.h"
|
||||
#include "tbytevector.h"
|
||||
#include "taglib_export.h"
|
||||
#include "flacmetadatablock.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace FLAC {
|
||||
|
||||
class TAGLIB_EXPORT UnknownMetadataBlock : public MetadataBlock
|
||||
{
|
||||
public:
|
||||
UnknownMetadataBlock(int blockType, const ByteVector &data);
|
||||
~UnknownMetadataBlock();
|
||||
|
||||
/*!
|
||||
* Returns the FLAC metadata block type.
|
||||
*/
|
||||
int code() const;
|
||||
|
||||
/*!
|
||||
* Sets the FLAC metadata block type.
|
||||
*/
|
||||
void setCode(int code);
|
||||
|
||||
/*!
|
||||
* Returns the FLAC metadata block type.
|
||||
*/
|
||||
ByteVector data() const;
|
||||
|
||||
/*!
|
||||
* Sets the FLAC metadata block type.
|
||||
*/
|
||||
void setData(const ByteVector &data);
|
||||
|
||||
/*!
|
||||
* Render the content of the block.
|
||||
*/
|
||||
ByteVector render() const;
|
||||
|
||||
private:
|
||||
UnknownMetadataBlock(const MetadataBlock &item);
|
||||
UnknownMetadataBlock &operator=(const MetadataBlock &item);
|
||||
|
||||
class UnknownMetadataBlockPrivate;
|
||||
UnknownMetadataBlockPrivate *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -386,8 +386,8 @@ namespace TagLib {
|
||||
static ByteVector null;
|
||||
|
||||
/*!
|
||||
* Returns a hex-encoded copy of the byte vector.
|
||||
*/
|
||||
* Returns a hex-encoded copy of the byte vector.
|
||||
*/
|
||||
ByteVector toHex() const;
|
||||
|
||||
protected:
|
||||
|
@ -40,6 +40,9 @@ SET(test_runner_SRCS
|
||||
test_ogg.cpp
|
||||
test_oggflac.cpp
|
||||
test_flac.cpp
|
||||
test_flacpicture.cpp
|
||||
test_flacmetadatablocks.cpp
|
||||
test_flacunknownmetadatablock.cpp
|
||||
test_ape.cpp
|
||||
test_apetag.cpp
|
||||
test_wav.cpp
|
||||
|
41
tests/test_flacmetadatablocks.cpp
Normal file
41
tests/test_flacmetadatablocks.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <tstringlist.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <flacfile.h>
|
||||
#include <flacmetadatablock.h>
|
||||
#include <flacmetadatablocks.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestFLACMetadataBlocks : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestFLACMetadataBlocks);
|
||||
CPPUNIT_TEST(testRead);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testRead()
|
||||
{
|
||||
FLAC::File f("data/silence-44-s.flac");
|
||||
FLAC::MetadataBlocks b;
|
||||
f.seek(4);
|
||||
b.read(&f);
|
||||
List<FLAC::MetadataBlock *> blocks = b.metadataBlockList();
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(5), blocks.size());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::StreamInfo, blocks[0]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::SeekTable, blocks[1]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::VorbisComment, blocks[2]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::CueSheet, blocks[3]->code());
|
||||
CPPUNIT_ASSERT_EQUAL(0 + FLAC::MetadataBlock::Picture, blocks[4]->code());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLACMetadataBlocks);
|
||||
|
49
tests/test_flacpicture.cpp
Normal file
49
tests/test_flacpicture.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <tstringlist.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <flacfile.h>
|
||||
#include <flacmetadatablock.h>
|
||||
#include <flacmetadatablocks.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestFLACPicture : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestFLACPicture);
|
||||
CPPUNIT_TEST(testParse);
|
||||
CPPUNIT_TEST(testPassThrough);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testParse()
|
||||
{
|
||||
char data[] = { 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x70, 0x6E, 0x67, 0x00, 0x00, 0x00, 0x08, 0x41, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6C, 0x2E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xDE, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0B, 0x13, 0x00, 0x00, 0x0B, 0x13, 0x01, 0x00, 0x9A, 0x9C, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4D, 0x45, 0x07, 0xD6, 0x0B, 0x1C, 0x0A, 0x36, 0x06, 0x08, 0x44, 0x3D, 0x32, 0x00, 0x00, 0x00, 0x1D, 0x74, 0x45, 0x58, 0x74, 0x43, 0x6F, 0x6D, 0x6D, 0x65, 0x6E, 0x74, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x54, 0x68, 0x65, 0x20, 0x47, 0x49, 0x4D, 0x50, 0xEF, 0x64, 0x25, 0x6E, 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x08, 0xD7, 0x63, 0xF8, 0xFF, 0xFF, 0x3F, 0x00, 0x05, 0xFE, 0x02, 0xFE, 0xDC, 0xCC, 0x59, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 };
|
||||
FLAC::Picture pic(ByteVector(data, 199));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(3, int(pic.type()));
|
||||
CPPUNIT_ASSERT_EQUAL(1, pic.width());
|
||||
CPPUNIT_ASSERT_EQUAL(1, pic.height());
|
||||
CPPUNIT_ASSERT_EQUAL(24, pic.colorDepth());
|
||||
CPPUNIT_ASSERT_EQUAL(0, pic.numColors());
|
||||
CPPUNIT_ASSERT_EQUAL(String("image/png"), pic.mimeType());
|
||||
CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic.description());
|
||||
CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic.data().size());
|
||||
}
|
||||
|
||||
void testPassThrough()
|
||||
{
|
||||
char data[] = { 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x70, 0x6E, 0x67, 0x00, 0x00, 0x00, 0x08, 0x41, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6C, 0x2E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53, 0xDE, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0B, 0x13, 0x00, 0x00, 0x0B, 0x13, 0x01, 0x00, 0x9A, 0x9C, 0x18, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4D, 0x45, 0x07, 0xD6, 0x0B, 0x1C, 0x0A, 0x36, 0x06, 0x08, 0x44, 0x3D, 0x32, 0x00, 0x00, 0x00, 0x1D, 0x74, 0x45, 0x58, 0x74, 0x43, 0x6F, 0x6D, 0x6D, 0x65, 0x6E, 0x74, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x54, 0x68, 0x65, 0x20, 0x47, 0x49, 0x4D, 0x50, 0xEF, 0x64, 0x25, 0x6E, 0x00, 0x00, 0x00, 0x0C, 0x49, 0x44, 0x41, 0x54, 0x08, 0xD7, 0x63, 0xF8, 0xFF, 0xFF, 0x3F, 0x00, 0x05, 0xFE, 0x02, 0xFE, 0xDC, 0xCC, 0x59, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 };
|
||||
FLAC::Picture pic(ByteVector(data, 199));
|
||||
CPPUNIT_ASSERT_EQUAL(ByteVector(data, 199), pic.render());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLACPicture);
|
||||
|
38
tests/test_flacunknownmetadatablock.cpp
Normal file
38
tests/test_flacunknownmetadatablock.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <tag.h>
|
||||
#include <tstringlist.h>
|
||||
#include <tbytevectorlist.h>
|
||||
#include <flacunknownmetadatablock.h>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace TagLib;
|
||||
|
||||
class TestFLACUnknownMetadataBlock : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(TestFLACUnknownMetadataBlock);
|
||||
CPPUNIT_TEST(testAccessors);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
void testAccessors()
|
||||
{
|
||||
ByteVector data("abc\x01", 4);
|
||||
FLAC::UnknownMetadataBlock block(42, data);
|
||||
CPPUNIT_ASSERT_EQUAL(42, block.code());
|
||||
CPPUNIT_ASSERT_EQUAL(data, block.data());
|
||||
CPPUNIT_ASSERT_EQUAL(data, block.render());
|
||||
ByteVector data2("xxx", 3);
|
||||
block.setCode(13);
|
||||
block.setData(data2);
|
||||
CPPUNIT_ASSERT_EQUAL(13, block.code());
|
||||
CPPUNIT_ASSERT_EQUAL(data2, block.data());
|
||||
CPPUNIT_ASSERT_EQUAL(data2, block.render());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLACUnknownMetadataBlock);
|
Reference in New Issue
Block a user