aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/dsd_stereo.wvbin0 -> 52595 bytes
-rw-r--r--tests/data/non_standard_rate.wvbin0 -> 132 bytes
-rw-r--r--tests/plainfile.h50
-rw-r--r--tests/test_aiff.cpp4
-rw-r--r--tests/test_file.cpp11
-rw-r--r--tests/test_flac.cpp79
-rw-r--r--tests/test_id3v1.cpp13
-rw-r--r--tests/test_mp4.cpp107
-rw-r--r--tests/test_wav.cpp68
-rw-r--r--tests/test_wavpack.cpp32
10 files changed, 350 insertions, 14 deletions
diff --git a/tests/data/dsd_stereo.wv b/tests/data/dsd_stereo.wv
new file mode 100644
index 00000000..80619270
--- /dev/null
+++ b/tests/data/dsd_stereo.wv
Binary files differ
diff --git a/tests/data/non_standard_rate.wv b/tests/data/non_standard_rate.wv
new file mode 100644
index 00000000..ccc90277
--- /dev/null
+++ b/tests/data/non_standard_rate.wv
Binary files differ
diff --git a/tests/plainfile.h b/tests/plainfile.h
new file mode 100644
index 00000000..6147b56b
--- /dev/null
+++ b/tests/plainfile.h
@@ -0,0 +1,50 @@
+/***************************************************************************
+ copyright : (C) 2015 by Tsuda Kageyu
+ email : tsuda.kageyu@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., 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/ *
+ ***************************************************************************/
+
+#ifndef TAGLIB_PLAINFILE_H
+#define TAGLIB_PLAINFILE_H
+
+#include <tfile.h>
+
+using namespace TagLib;
+
+//! File subclass that gives tests access to filesystem operations
+class PlainFile : public File {
+public:
+ explicit PlainFile(FileName name) : File(name) { }
+ Tag *tag() const { return NULL; }
+ AudioProperties *audioProperties() const { return NULL; }
+ bool save() { return false; }
+ void truncate(long length) { File::truncate(length); }
+
+ ByteVector readAll() {
+ seek(0, End);
+ long end = tell();
+ seek(0);
+ return readBlock(end);
+ }
+};
+
+#endif
diff --git a/tests/test_aiff.cpp b/tests/test_aiff.cpp
index 116c13a6..0337729f 100644
--- a/tests/test_aiff.cpp
+++ b/tests/test_aiff.cpp
@@ -148,13 +148,13 @@ public:
void testFuzzedFile1()
{
RIFF::AIFF::File f(TEST_FILE_PATH_C("segfault.aif"));
- CPPUNIT_ASSERT(!f.isValid());
+ CPPUNIT_ASSERT(f.isValid());
}
void testFuzzedFile2()
{
RIFF::AIFF::File f(TEST_FILE_PATH_C("excessive_alloc.aif"));
- CPPUNIT_ASSERT(!f.isValid());
+ CPPUNIT_ASSERT(f.isValid());
}
};
diff --git a/tests/test_file.cpp b/tests/test_file.cpp
index 9aae07fe..ef8c1b10 100644
--- a/tests/test_file.cpp
+++ b/tests/test_file.cpp
@@ -25,20 +25,11 @@
#include <tfile.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "plainfile.h"
#include "utils.h"
using namespace TagLib;
-// File subclass that gives tests access to filesystem operations
-class PlainFile : public File {
-public:
- PlainFile(FileName name) : File(name) { }
- Tag *tag() const { return NULL; }
- AudioProperties *audioProperties() const { return NULL; }
- bool save(){ return false; }
- void truncate(long length) { File::truncate(length); }
-};
-
class TestFile : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestFile);
diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp
index 0cc2b7ec..7c25a83b 100644
--- a/tests/test_flac.cpp
+++ b/tests/test_flac.cpp
@@ -34,6 +34,7 @@
#include <id3v1tag.h>
#include <id3v2tag.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "plainfile.h"
#include "utils.h"
using namespace std;
@@ -64,6 +65,7 @@ class TestFLAC : public CppUnit::TestFixture
CPPUNIT_TEST(testStripTags);
CPPUNIT_TEST(testRemoveXiphField);
CPPUNIT_TEST(testEmptySeekTable);
+ CPPUNIT_TEST(testPictureStoredAfterComment);
CPPUNIT_TEST_SUITE_END();
public:
@@ -533,6 +535,83 @@ public:
}
}
+ void testPictureStoredAfterComment()
+ {
+ // Blank.png from https://commons.wikimedia.org/wiki/File:Blank.png
+ const unsigned char blankPngData[] = {
+ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
+ 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02,
+ 0x08, 0x06, 0x00, 0x00, 0x00, 0x9d, 0x74, 0x66, 0x1a, 0x00, 0x00, 0x00,
+ 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00,
+ 0x00, 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc,
+ 0x61, 0x05, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73, 0x00, 0x00,
+ 0x0e, 0xc3, 0x00, 0x00, 0x0e, 0xc3, 0x01, 0xc7, 0x6f, 0xa8, 0x64, 0x00,
+ 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41, 0x54, 0x18, 0x57, 0x63, 0xc0, 0x01,
+ 0x18, 0x18, 0x00, 0x00, 0x1a, 0x00, 0x01, 0x82, 0x92, 0x4d, 0x60, 0x00,
+ 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
+ };
+ const ByteVector picData(reinterpret_cast<const char *>(blankPngData),
+ sizeof(blankPngData));
+
+ ScopedFileCopy copy("no-tags", ".flac");
+ {
+ FLAC::File f(copy.fileName().c_str());
+ CPPUNIT_ASSERT(!f.hasID3v1Tag());
+ CPPUNIT_ASSERT(!f.hasID3v2Tag());
+ CPPUNIT_ASSERT(!f.hasXiphComment());
+ CPPUNIT_ASSERT(f.pictureList().isEmpty());
+
+ FLAC::Picture *pic = new FLAC::Picture;
+ pic->setData(picData);
+ pic->setType(FLAC::Picture::FrontCover);
+ pic->setMimeType("image/png");
+ pic->setDescription("blank.png");
+ pic->setWidth(3);
+ pic->setHeight(2);
+ pic->setColorDepth(32);
+ pic->setNumColors(0);
+ f.addPicture(pic);
+ f.xiphComment(true)->setTitle("Title");
+ f.save();
+ }
+ {
+ FLAC::File f(copy.fileName().c_str());
+ CPPUNIT_ASSERT(!f.hasID3v1Tag());
+ CPPUNIT_ASSERT(!f.hasID3v2Tag());
+ CPPUNIT_ASSERT(f.hasXiphComment());
+ const List<FLAC::Picture *> pictures = f.pictureList();
+ CPPUNIT_ASSERT_EQUAL(1U, pictures.size());
+ CPPUNIT_ASSERT_EQUAL(picData, pictures[0]->data());
+ CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pictures[0]->type());
+ CPPUNIT_ASSERT_EQUAL(String("image/png"), pictures[0]->mimeType());
+ CPPUNIT_ASSERT_EQUAL(String("blank.png"), pictures[0]->description());
+ CPPUNIT_ASSERT_EQUAL(3, pictures[0]->width());
+ CPPUNIT_ASSERT_EQUAL(2, pictures[0]->height());
+ CPPUNIT_ASSERT_EQUAL(32, pictures[0]->colorDepth());
+ CPPUNIT_ASSERT_EQUAL(0, pictures[0]->numColors());
+ CPPUNIT_ASSERT_EQUAL(String("Title"), f.xiphComment(false)->title());
+ }
+
+ const unsigned char expectedHeadData[] = {
+ 'f', 'L', 'a', 'C', 0x00, 0x00, 0x00, 0x22, 0x12, 0x00, 0x12, 0x00,
+ 0x00, 0x00, 0x0e, 0x00, 0x00, 0x10, 0x0a, 0xc4, 0x42, 0xf0, 0x00, 0x02,
+ 0x7a, 0xc0, 0xa1, 0xb1, 0x41, 0xf7, 0x66, 0xe9, 0x84, 0x9a, 0xc3, 0xdb,
+ 0x10, 0x30, 0xa2, 0x0a, 0x3c, 0x77, 0x04, 0x00, 0x00, 0x17, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 'T', 'I',
+ 'T', 'L', 'E', '=', 'T', 'i', 't', 'l', 'e', 0x06, 0x00, 0x00,
+ 0xa9, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 'i', 'm', 'a',
+ 'g', 'e', '/', 'p', 'n', 'g', 0x00, 0x00, 0x00, 0x09, 'b', 'l',
+ 'a', 'n', 'k', '.', 'p', 'n', 'g', 0x00, 0x00, 0x00, 0x03, 0x00,
+ 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x77
+ };
+ ByteVector expectedData(reinterpret_cast<const char *>(expectedHeadData),
+ sizeof(expectedHeadData));
+ expectedData.append(picData);
+ const ByteVector fileData = PlainFile(copy.fileName().c_str()).readAll();
+ CPPUNIT_ASSERT(fileData.startsWith(expectedData));
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);
diff --git a/tests/test_id3v1.cpp b/tests/test_id3v1.cpp
index 3358aead..c50c3428 100644
--- a/tests/test_id3v1.cpp
+++ b/tests/test_id3v1.cpp
@@ -40,6 +40,7 @@ class TestID3v1 : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(TestID3v1);
CPPUNIT_TEST(testStripWhiteSpace);
CPPUNIT_TEST(testGenres);
+ CPPUNIT_TEST(testRenamedGenres);
CPPUNIT_TEST_SUITE_END();
public:
@@ -68,6 +69,18 @@ public:
CPPUNIT_ASSERT_EQUAL(100, ID3v1::genreIndex("Humour"));
}
+ void testRenamedGenres()
+ {
+ CPPUNIT_ASSERT_EQUAL(String("Bebop"), ID3v1::genre(85));
+ CPPUNIT_ASSERT_EQUAL(85, ID3v1::genreIndex("Bebop"));
+ CPPUNIT_ASSERT_EQUAL(85, ID3v1::genreIndex("Bebob"));
+
+ ID3v1::Tag tag;
+ tag.setGenre("Hardcore");
+ CPPUNIT_ASSERT_EQUAL(String("Hardcore Techno"), tag.genre());
+ CPPUNIT_ASSERT_EQUAL(129U, tag.genreNumber());
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v1);
diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp
index 05bf6bd3..ba38c0f0 100644
--- a/tests/test_mp4.cpp
+++ b/tests/test_mp4.cpp
@@ -28,10 +28,12 @@
#include <tag.h>
#include <mp4tag.h>
#include <tbytevectorlist.h>
+#include <tbytevectorstream.h>
#include <tpropertymap.h>
#include <mp4atom.h>
#include <mp4file.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "plainfile.h"
#include "utils.h"
using namespace std;
@@ -41,7 +43,9 @@ class TestMP4 : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestMP4);
CPPUNIT_TEST(testPropertiesAAC);
+ CPPUNIT_TEST(testPropertiesAACWithoutBitrate);
CPPUNIT_TEST(testPropertiesALAC);
+ CPPUNIT_TEST(testPropertiesALACWithoutBitrate);
CPPUNIT_TEST(testPropertiesM4V);
CPPUNIT_TEST(testFreeForm);
CPPUNIT_TEST(testCheckValid);
@@ -59,6 +63,7 @@ class TestMP4 : public CppUnit::TestFixture
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testRepeatedSave);
CPPUNIT_TEST(testWithZeroLengthAtom);
+ CPPUNIT_TEST(testEmptyValuesRemoveItems);
CPPUNIT_TEST_SUITE_END();
public:
@@ -77,6 +82,28 @@ public:
CPPUNIT_ASSERT_EQUAL(MP4::Properties::AAC, f.audioProperties()->codec());
}
+ void testPropertiesAACWithoutBitrate()
+ {
+ ByteVector aacData = PlainFile(TEST_FILE_PATH_C("has-tags.m4a")).readAll();
+ CPPUNIT_ASSERT_GREATER(1960U, aacData.size());
+ CPPUNIT_ASSERT_EQUAL(ByteVector("mp4a"), aacData.mid(1890, 4));
+ // Set the bitrate to zero
+ for (int offset = 1956; offset < 1960; ++offset) {
+ aacData[offset] = 0;
+ }
+ ByteVectorStream aacStream(aacData);
+ MP4::File f(&aacStream);
+ CPPUNIT_ASSERT(f.audioProperties());
+ CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
+ CPPUNIT_ASSERT_EQUAL(3708, f.audioProperties()->lengthInMilliseconds());
+ CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+ CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
+ CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
+ CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isEncrypted());
+ CPPUNIT_ASSERT_EQUAL(MP4::Properties::AAC, f.audioProperties()->codec());
+ }
+
void testPropertiesALAC()
{
MP4::File f(TEST_FILE_PATH_C("empty_alac.m4a"));
@@ -91,6 +118,28 @@ public:
CPPUNIT_ASSERT_EQUAL(MP4::Properties::ALAC, f.audioProperties()->codec());
}
+ void testPropertiesALACWithoutBitrate()
+ {
+ ByteVector alacData = PlainFile(TEST_FILE_PATH_C("empty_alac.m4a")).readAll();
+ CPPUNIT_ASSERT_GREATER(474U, alacData.size());
+ CPPUNIT_ASSERT_EQUAL(ByteVector("alac"), alacData.mid(446, 4));
+ // Set the bitrate to zero
+ for (int offset = 470; offset < 474; ++offset) {
+ alacData[offset] = 0;
+ }
+ ByteVectorStream alacStream(alacData);
+ MP4::File f(&alacStream);
+ CPPUNIT_ASSERT(f.audioProperties());
+ CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
+ CPPUNIT_ASSERT_EQUAL(3705, f.audioProperties()->lengthInMilliseconds());
+ CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+ CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
+ CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
+ CPPUNIT_ASSERT_EQUAL(false, f.audioProperties()->isEncrypted());
+ CPPUNIT_ASSERT_EQUAL(MP4::Properties::ALAC, f.audioProperties()->codec());
+ }
+
void testPropertiesM4V()
{
MP4::File f(TEST_FILE_PATH_C("blank_video.m4v"));
@@ -455,6 +504,64 @@ public:
CPPUNIT_ASSERT_EQUAL(22050, f.audioProperties()->sampleRate());
}
+ void testEmptyValuesRemoveItems()
+ {
+ const MP4::File f(TEST_FILE_PATH_C("has-tags.m4a"));
+ MP4::Tag *tag = f.tag();
+ const String testTitle("Title");
+ const String testArtist("Artist");
+ const String testAlbum("Album");
+ const String testComment("Comment");
+ const String testGenre("Genre");
+ const String nullString;
+ const unsigned int testYear = 2020;
+ const unsigned int testTrack = 1;
+ const unsigned int zeroUInt = 0;
+
+ tag->setTitle(testTitle);
+ CPPUNIT_ASSERT_EQUAL(testTitle, tag->title());
+ CPPUNIT_ASSERT(tag->contains("\251nam"));
+ tag->setArtist(testArtist);
+ CPPUNIT_ASSERT_EQUAL(testArtist, tag->artist());
+ CPPUNIT_ASSERT(tag->contains("\251ART"));
+ tag->setAlbum(testAlbum);
+ CPPUNIT_ASSERT_EQUAL(testAlbum, tag->album());
+ CPPUNIT_ASSERT(tag->contains("\251alb"));
+ tag->setComment(testComment);
+ CPPUNIT_ASSERT_EQUAL(testComment, tag->comment());
+ CPPUNIT_ASSERT(tag->contains("\251cmt"));
+ tag->setGenre(testGenre);
+ CPPUNIT_ASSERT_EQUAL(testGenre, tag->genre());
+ CPPUNIT_ASSERT(tag->contains("\251gen"));
+ tag->setYear(testYear);
+ CPPUNIT_ASSERT_EQUAL(testYear, tag->year());
+ CPPUNIT_ASSERT(tag->contains("\251day"));
+ tag->setTrack(testTrack);
+ CPPUNIT_ASSERT_EQUAL(testTrack, tag->track());
+ CPPUNIT_ASSERT(tag->contains("trkn"));
+
+ tag->setTitle(nullString);
+ CPPUNIT_ASSERT_EQUAL(nullString, tag->title());
+ CPPUNIT_ASSERT(!tag->contains("\251nam"));
+ tag->setArtist(nullString);
+ CPPUNIT_ASSERT_EQUAL(nullString, tag->artist());
+ CPPUNIT_ASSERT(!tag->contains("\251ART"));
+ tag->setAlbum(nullString);
+ CPPUNIT_ASSERT_EQUAL(nullString, tag->album());
+ CPPUNIT_ASSERT(!tag->contains("\251alb"));
+ tag->setComment(nullString);
+ CPPUNIT_ASSERT_EQUAL(nullString, tag->comment());
+ CPPUNIT_ASSERT(!tag->contains("\251cmt"));
+ tag->setGenre(nullString);
+ CPPUNIT_ASSERT_EQUAL(nullString, tag->genre());
+ CPPUNIT_ASSERT(!tag->contains("\251gen"));
+ tag->setYear(zeroUInt);
+ CPPUNIT_ASSERT_EQUAL(zeroUInt, tag->year());
+ CPPUNIT_ASSERT(!tag->contains("\251day"));
+ tag->setTrack(zeroUInt);
+ CPPUNIT_ASSERT_EQUAL(zeroUInt, tag->track());
+ CPPUNIT_ASSERT(!tag->contains("trkn"));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);
diff --git a/tests/test_wav.cpp b/tests/test_wav.cpp
index e94864ba..61081393 100644
--- a/tests/test_wav.cpp
+++ b/tests/test_wav.cpp
@@ -28,9 +28,12 @@
#include <id3v2tag.h>
#include <infotag.h>
#include <tbytevectorlist.h>
+#include <tbytevectorstream.h>
+#include <tfilestream.h>
#include <tpropertymap.h>
#include <wavfile.h>
#include <cppunit/extensions/HelperMacros.h>
+#include "plainfile.h"
#include "utils.h"
using namespace std;
@@ -42,6 +45,7 @@ class TestWAV : public CppUnit::TestFixture
CPPUNIT_TEST(testPCMProperties);
CPPUNIT_TEST(testALAWProperties);
CPPUNIT_TEST(testFloatProperties);
+ CPPUNIT_TEST(testFloatWithoutFactChunkProperties);
CPPUNIT_TEST(testZeroSizeDataChunk);
CPPUNIT_TEST(testID3v2Tag);
CPPUNIT_TEST(testSaveID3v23);
@@ -50,6 +54,7 @@ class TestWAV : public CppUnit::TestFixture
CPPUNIT_TEST(testDuplicateTags);
CPPUNIT_TEST(testFuzzedFile1);
CPPUNIT_TEST(testFuzzedFile2);
+ CPPUNIT_TEST(testFileWithGarbageAppended);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST(testPCMWithFactChunk);
CPPUNIT_TEST(testWaveFormatExtensible);
@@ -99,10 +104,29 @@ public:
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->format());
}
+ void testFloatWithoutFactChunkProperties()
+ {
+ ByteVector wavData = PlainFile(TEST_FILE_PATH_C("float64.wav")).readAll();
+ CPPUNIT_ASSERT_EQUAL(ByteVector("fact"), wavData.mid(36, 4));
+ // Remove the fact chunk by renaming it to fakt
+ wavData[38] = 'k';
+ ByteVectorStream wavStream(wavData);
+ RIFF::WAV::File f(&wavStream);
+ CPPUNIT_ASSERT(f.audioProperties());
+ CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
+ CPPUNIT_ASSERT_EQUAL(97, f.audioProperties()->lengthInMilliseconds());
+ CPPUNIT_ASSERT_EQUAL(5645, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+ CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
+ CPPUNIT_ASSERT_EQUAL(64, f.audioProperties()->bitsPerSample());
+ CPPUNIT_ASSERT_EQUAL(4281U, f.audioProperties()->sampleFrames());
+ CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->format());
+ }
+
void testZeroSizeDataChunk()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("zero-size-chunk.wav"));
- CPPUNIT_ASSERT(!f.isValid());
+ CPPUNIT_ASSERT(f.isValid());
}
void testID3v2Tag()
@@ -263,7 +287,17 @@ public:
void testFuzzedFile1()
{
RIFF::WAV::File f1(TEST_FILE_PATH_C("infloop.wav"));
- CPPUNIT_ASSERT(!f1.isValid());
+ CPPUNIT_ASSERT(f1.isValid());
+ // The file has problems:
+ // Chunk 'ISTt' has invalid size (larger than the file size).
+ // Its properties can nevertheless be read.
+ RIFF::WAV::Properties* properties = f1.audioProperties();
+ CPPUNIT_ASSERT_EQUAL(1, properties->channels());
+ CPPUNIT_ASSERT_EQUAL(88, properties->bitrate());
+ CPPUNIT_ASSERT_EQUAL(8, properties->bitsPerSample());
+ CPPUNIT_ASSERT_EQUAL(11025, properties->sampleRate());
+ CPPUNIT_ASSERT(!f1.hasInfoTag());
+ CPPUNIT_ASSERT(!f1.hasID3v2Tag());
}
void testFuzzedFile2()
@@ -272,6 +306,36 @@ public:
CPPUNIT_ASSERT(f2.isValid());
}
+ void testFileWithGarbageAppended()
+ {
+ ScopedFileCopy copy("empty", ".wav");
+ ByteVector contentsBeforeModification;
+ {
+ FileStream stream(copy.fileName().c_str());
+ stream.seek(0, IOStream::End);
+ const char garbage[] = "12345678";
+ stream.writeBlock(ByteVector(garbage, sizeof(garbage) - 1));
+ stream.seek(0);
+ contentsBeforeModification = stream.readBlock(stream.length());
+ }
+ {
+ RIFF::WAV::File f(copy.fileName().c_str());
+ CPPUNIT_ASSERT(f.isValid());
+ f.ID3v2Tag()->setTitle("ID3v2 Title");
+ f.InfoTag()->setTitle("INFO Title");
+ CPPUNIT_ASSERT(f.save());
+ }
+ {
+ RIFF::WAV::File f(copy.fileName().c_str());
+ f.strip();
+ }
+ {
+ FileStream stream(copy.fileName().c_str());
+ ByteVector contentsAfterModification = stream.readBlock(stream.length());
+ CPPUNIT_ASSERT_EQUAL(contentsBeforeModification, contentsAfterModification);
+ }
+ }
+
void testStripAndProperties()
{
ScopedFileCopy copy("empty", ".wav");
diff --git a/tests/test_wavpack.cpp b/tests/test_wavpack.cpp
index 6c64f08d..591529fb 100644
--- a/tests/test_wavpack.cpp
+++ b/tests/test_wavpack.cpp
@@ -41,6 +41,8 @@ class TestWavPack : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(TestWavPack);
CPPUNIT_TEST(testNoLengthProperties);
CPPUNIT_TEST(testMultiChannelProperties);
+ CPPUNIT_TEST(testDsdStereoProperties);
+ CPPUNIT_TEST(testNonStandardRateProperties);
CPPUNIT_TEST(testTaggedProperties);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testStripAndProperties);
@@ -79,6 +81,36 @@ public:
CPPUNIT_ASSERT_EQUAL(1031, f.audioProperties()->version());
}
+ void testDsdStereoProperties()
+ {
+ WavPack::File f(TEST_FILE_PATH_C("dsd_stereo.wv"));
+ CPPUNIT_ASSERT(f.audioProperties());
+ CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->lengthInSeconds());
+ CPPUNIT_ASSERT_EQUAL(200, f.audioProperties()->lengthInMilliseconds());
+ CPPUNIT_ASSERT_EQUAL(2096, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+ CPPUNIT_ASSERT_EQUAL(8, f.audioProperties()->bitsPerSample());
+ CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isLossless());
+ CPPUNIT_ASSERT_EQUAL(352800, f.audioProperties()->sampleRate());
+ CPPUNIT_ASSERT_EQUAL(70560U, f.audioProperties()->sampleFrames());
+ CPPUNIT_ASSERT_EQUAL(1040, f.audioProperties()->version());
+ }
+
+ void testNonStandardRateProperties()
+ {
+ WavPack::File f(TEST_FILE_PATH_C("non_standard_rate.wv"));
+ CPPUNIT_ASSERT(f.audioProperties());
+ CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->lengthInSeconds());
+ CPPUNIT_ASSERT_EQUAL(3675, f.audioProperties()->lengthInMilliseconds());
+ CPPUNIT_ASSERT_EQUAL(0, f.audioProperties()->bitrate());
+ CPPUNIT_ASSERT_EQUAL(2, f.audioProperties()->channels());
+ CPPUNIT_ASSERT_EQUAL(16, f.audioProperties()->bitsPerSample());
+ CPPUNIT_ASSERT_EQUAL(true, f.audioProperties()->isLossless());
+ CPPUNIT_ASSERT_EQUAL(1000, f.audioProperties()->sampleRate());
+ CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames());
+ CPPUNIT_ASSERT_EQUAL(1040, f.audioProperties()->version());
+ }
+
void testTaggedProperties()
{
WavPack::File f(TEST_FILE_PATH_C("tagged.wv"));