aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_wav.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_wav.cpp')
-rw-r--r--tests/test_wav.cpp68
1 files changed, 66 insertions, 2 deletions
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");