1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-10 16:43:33 +02:00

Locate and position the current Audacity source code, and clear a variety of old junk out of the way into junk-branches

This commit is contained in:
ra
2010-01-23 19:44:49 +00:00
commit e74978ba77
1011 changed files with 781704 additions and 0 deletions

36
tests/Makefile.in Normal file
View File

@@ -0,0 +1,36 @@
CC = @CC@
CXX = @CXX@
# CFLAGS are specific to C.
override CFLAGS += @CFLAGS@
# CXXFLAGS are specific to C++.
override CXXFLAGS += @CXXFLAGS@
# CPPFLAGS are for both C and C++.
override CPPFLAGS += -I../src @CPPFLAGS@
all: run_tests
check: run_tests
LIBS = @LIBS@ ../src/libaudacity.a
TESTS = \
SimpleBlockFileTest \
SequenceTest \
$(TESTS): %: %.cpp ../src/libaudacity.a
$(CXX) -o $@ $< $(CXXFLAGS) $(CPPFLAGS) $(LIBS)
run_tests: $(TESTS)
tests='$(TESTS)'; for test in $$tests ; do \
./$$test ; \
done
clean:
rm -f $(TESTS)
distclean: clean
rm -f Makefile

174
tests/SequenceTest.cpp Normal file
View File

@@ -0,0 +1,174 @@
#include "Sequence.h"
#include "DirManager.h"
#include <wx/hash.h>
#include <vector>
#include <iostream>
class SequenceTest
{
private:
Sequence *mSequence;
DirManager *mDirManager;
std::vector<float> mMemorySequence;
public:
SequenceTest()
{
std::cout << "==> Testing Sequence\n";
srand(time(NULL));
}
void SetUp()
{
DirManager::SetTempDir("/tmp/sequence-test-dir");
mDirManager = new DirManager;
mSequence = new Sequence(mDirManager, floatSample);
mMemorySequence.clear();
}
void TearDown()
{
delete mSequence;
delete mDirManager;
mMemorySequence.clear();
}
void TestReferencing()
{
/* Thrash the Sequence through repeated appends, deletes, etc.
* Then delete the sequence and ensure that all blocks have
* been unreferenced to the point of deletion -- the dirmanager
* should be empty. */
std::cout << "\tafter thrashing the sequence and deleting it, all block files should have been deleted..." << std::flush;
int appendBufLen = (int)(mSequence->GetMaxBlockSize() * 1.4);
samplePtr appendBuf = NewSamples(appendBufLen, floatSample);
int i;
for(i = 0; i < 10; i++)
mSequence->Append(appendBuf, floatSample, appendBufLen);
for(i = 0; i < 10; i++)
{
Sequence *tmpSequence;
/* append */
mSequence->Append(appendBuf, floatSample, appendBufLen);
/* copy/paste */
int s0 = rand()%mSequence->GetNumSamples();
int len = rand()%(mSequence->GetNumSamples() - s0);
mSequence->Copy(s0, s0+len, &tmpSequence);
int dest = rand()%mSequence->GetNumSamples();
mSequence->Paste(dest, tmpSequence);
delete tmpSequence;
/* delete */
int del = rand()%mSequence->GetNumSamples();
int dellen = rand()%((mSequence->GetNumSamples()-del)/2);
mSequence->Delete(del, dellen);
}
delete mSequence;
mSequence = NULL;
assert(mDirManager->blockFileHash->GetCount() == 0);
std::cout << "ok\n";
}
void TestSetGarbageInput()
{
std::cout << "\tSequence::Set() should return false (and not crash) if given garbage input..." << std::flush;
/* Create 10 samples in the sequence so the Set requests will
* be valid */
samplePtr appendBuf = NewSamples(10, floatSample);
mSequence->Append(appendBuf, floatSample, 10);
/* should fail, "set" buffer should not be null */
assert(mSequence->Set(NULL, floatSample, 0, 10) == false);
/* should fail, -5 is not a sample format */
assert(mSequence->Set(appendBuf, (sampleFormat)-5, 0, 10) == false);
/* should fail, -1 is not a valid offset */
assert(mSequence->Set(appendBuf, floatSample, -1, 10) == false);
/* should fail, the sequence is only 10 samples long */
assert(mSequence->Set(appendBuf, floatSample, 0, 15) == false);
std::cout << "ok\n";
}
void TestGetGarbageInput()
{
std::cout << "\tSequence::Get() should return false (and not crash) if given garbage input..." << std::flush;
/* Create 10 samples in the sequence so the Set requests will
* be valid */
samplePtr appendBuf = NewSamples(10, floatSample);
mSequence->Append(appendBuf, floatSample, 10);
/* should fail, "get" buffer should not be null */
assert(mSequence->Get(NULL, floatSample, 0, 10) == false);
/* should fail, -1 is not a valid offset */
assert(mSequence->Get(appendBuf, floatSample, -1, 10) == false);
/* should fail, the sequence is only 10 samples long */
assert(mSequence->Get(appendBuf, floatSample, 0, 15) == false);
std::cout << "ok\n";
}
};
int main()
{
SequenceTest tester;
tester.SetUp();
tester.TestReferencing();
tester.TearDown();
tester.SetUp();
tester.TestSetGarbageInput();
tester.TearDown();
tester.SetUp();
tester.TestGetGarbageInput();
tester.TearDown();
return 0;
}
class wxWindow;
void ShowWarningDialog(wxWindow *parent,
wxString internalDialogName,
wxString message)
{
std::cout << "warning: " << message << std::endl;
}
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3
// arch-tag: 854b5b56-912e-4903-97f6-55314045153d

View File

@@ -0,0 +1,221 @@
#include <iostream>
#include <ostream>
#include <cassert>
#include "sndfile.h"
#include "blockfile/SimpleBlockFile.h"
class SimpleBlockFileTest {
SimpleBlockFile *int16BlockFile;
SimpleBlockFile *int24BlockFile;
SimpleBlockFile *floatBlockFile;
int summaryLen;
short *int16Data;
int *int24Data;
float *floatData;
int dataLen;
public:
SimpleBlockFileTest()
{
std::cout << "==> Testing SimpleBlockFile\n";
}
void setUp() {
dataLen = 200000;
int16Data = new short[dataLen];
int24Data = new int[dataLen];
floatData = new float[dataLen];
int i;
int sign = 1;
for(i = 0; i < dataLen; i++)
{
sign *= -1;
// These have no significance, it's just random data
int16Data[i] = sign*(i*i);
int24Data[i] = sign*((i*i*i)%0x000FFFFF);
float j = (float) i;
floatData[i] = sign*j/((j*j)+1);
}
int16BlockFile = new SimpleBlockFile(wxFileName("/tmp/int16"),
(samplePtr)int16Data, dataLen,
int16Sample);
int24BlockFile = new SimpleBlockFile(wxFileName("/tmp/int24"),
(samplePtr)int24Data, dataLen,
int24Sample);
floatBlockFile = new SimpleBlockFile(wxFileName("/tmp/float"),
(samplePtr)floatData, dataLen,
floatSample);
}
void tearDown() {
delete [] int16Data;
delete [] int24Data;
delete [] floatData;
delete int16BlockFile;
delete int24BlockFile;
delete floatBlockFile;
}
void testFileValidity() {
// Use libsndfile to read the file. Make sure:
// 1. it is correctly recognized as an AU file
// 2. it has all the header information we expect
std::cout << "\tthe created files should be valid AU files with the expected number of samples...";
std::cout << std::flush;
BlockFile *theFiles[] = {int16BlockFile, int24BlockFile, floatBlockFile};
for(int i = 0; i < 3; i++)
{
BlockFile *bf = theFiles[i];
SF_INFO info;
memset(&info, 0, sizeof(info));
SNDFILE *sf = sf_open(bf->GetFileName().GetFullPath(), SFM_READ, &info);
assert(sf);
assert(info.frames == dataLen);
assert(info.channels == 1);
assert(info.format & SF_FORMAT_AU);
sf_close(sf);
}
std::cout << "OK\n";
}
template<class T> void AssertBuffersEqual(T *b1, T *b2, int len)
{
for( int i = 0; i < len; i++ )
if( b1[i] != b2[i] )
{
std::cout << b1[i] << " != " << b2[i] << " (i=" << i << ")" << std::endl;
assert(false);
}
}
void testCorrectDataWritten() {
// use libsndfile to read back the whole blockfile, make sure it matches
// the data we initially wrote
std::cout << "\tVerifying that we wrote what we think we wrote..." << std::flush;
SF_INFO info1, info2, info3;
memset(&info1, 0, sizeof(info1));
memset(&info2, 0, sizeof(info2));
memset(&info3, 0, sizeof(info3));
SNDFILE *int16sf = sf_open(int16BlockFile->GetFileName().GetFullPath(), SFM_READ, &info1);
SNDFILE *int24sf = sf_open(int24BlockFile->GetFileName().GetFullPath(), SFM_READ, &info2);
SNDFILE *floatsf = sf_open(floatBlockFile->GetFileName().GetFullPath(), SFM_READ, &info3);
// First do a read of the entire block
short int16buf[dataLen];
int int24buf[dataLen];
float floatbuf[dataLen];
sf_read_short(int16sf, int16buf, dataLen);
sf_read_int (int24sf, int24buf, dataLen);
sf_read_float(floatsf, floatbuf, dataLen);
AssertBuffersEqual(int16buf, int16Data, dataLen);
AssertBuffersEqual(floatbuf, floatData, dataLen);
// for the 24-bit buffer, libsndfile gives the 24 bits to us in the 3 most significant
// byts of a 32-bit int. So we need to shift them right 8 to get back our 24-bit data.
for( int i = 0; i < dataLen; i++ )
int24buf[i] = int24buf[i] >> 8;
AssertBuffersEqual(int24buf, int24Data, dataLen);
sf_close(int16sf);
sf_close(int24sf);
sf_close(floatsf);
std::cout << "OK\n";
}
void testReads() {
// Now use the blockfile's method to read data and compare it to what we originally wrote
std::cout << "\tVerifying that we can read back correctly..." << std::flush;
samplePtr int16buf = NewSamples(dataLen, int16Sample);
samplePtr int24buf = NewSamples(dataLen, int24Sample);
samplePtr floatbuf = NewSamples(dataLen, floatSample);
// First try a read of the entire buffer
int16BlockFile->ReadData(int16buf, int16Sample, 0, dataLen);
int24BlockFile->ReadData(int24buf, int24Sample, 0, dataLen);
floatBlockFile->ReadData(floatbuf, floatSample, 0, dataLen);
AssertBuffersEqual(int16Data, (short*)int16buf, dataLen);
AssertBuffersEqual(int24Data, (int*)int24buf, dataLen);
AssertBuffersEqual(floatData, (float*)floatbuf, dataLen);
// Now test a read that starts at the beginning but quits
// before the end
int someOffset = 537;
int16BlockFile->ReadData(int16buf, int16Sample, 0, someOffset);
int24BlockFile->ReadData(int24buf, int24Sample, 0, someOffset);
floatBlockFile->ReadData(floatbuf, floatSample, 0, someOffset);
AssertBuffersEqual(int16Data, (short*)int16buf, someOffset);
AssertBuffersEqual(int24Data, (int*)int24buf, someOffset);
AssertBuffersEqual(floatData, (float*)floatbuf, someOffset);
// Now try a read that starts in the middle and goes to the
// end
int16BlockFile->ReadData(int16buf, int16Sample, someOffset, dataLen-someOffset);
int24BlockFile->ReadData(int24buf, int24Sample, someOffset, dataLen-someOffset);
floatBlockFile->ReadData(floatbuf, floatSample, someOffset, dataLen-someOffset);
AssertBuffersEqual(int16Data+someOffset, (short*)int16buf, dataLen-someOffset);
AssertBuffersEqual(int24Data+someOffset, (int*)int24buf, dataLen-someOffset);
AssertBuffersEqual(floatData+someOffset, (float*)floatbuf, dataLen-someOffset);
std::cout << "OK\n";
}
};
int main()
{
SimpleBlockFileTest tester;
tester.setUp();
tester.testFileValidity();
tester.tearDown();
tester.setUp();
tester.testCorrectDataWritten();
tester.tearDown();
tester.setUp();
tester.testReads();
tester.tearDown();
return 0;
}
// Indentation settings for Vim and Emacs and unique identifier for Arch, a
// version control system. Please do not modify past this point.
//
// Local Variables:
// c-basic-offset: 3
// indent-tabs-mode: nil
// End:
//
// vim: et sts=3 sw=3
// arch-tag: 153d201d-e9f5-4309-b198-4633b49daa4b