From 22b99e7d0379d1b347ea04c27e46b83ed40d057b Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 19 Jan 2016 08:32:44 +0100 Subject: Split CacheManager into several AudioCache classes and refactored the lot of them. Unit tests added. --- test/Makefile.am | 55 +++++++++-- test/audiocacheeventhandlertest.cc | 58 ++++++++++++ test/audiocachefiletest.cc | 189 +++++++++++++++++++++++++++++++++++++ test/audiocacheidmanagertest.cc | 98 +++++++++++++++++++ test/audiocachetest.cc | 177 ++++++++++++++++++++++++++++++++++ test/cachemanagertest.cc | 149 ----------------------------- 6 files changed, 571 insertions(+), 155 deletions(-) create mode 100644 test/audiocacheeventhandlertest.cc create mode 100644 test/audiocachefiletest.cc create mode 100644 test/audiocacheidmanagertest.cc create mode 100644 test/audiocachetest.cc delete mode 100644 test/cachemanagertest.cc (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 6526f22..1f605e5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,23 +1,66 @@ # Rules for the test code (use `make check` to execute) include $(top_srcdir)/src/Makefile.am.drumgizmo -TESTS = engine gui resampler lv2 configfile cachemanager +TESTS = engine gui resampler lv2 configfile audiocache audiocachefile \ + audiocacheidmanager audiocacheeventhandler check_PROGRAMS = $(TESTS) -cachemanager_CXXFLAGS = -DOUTPUT=\"cachemanager\" $(CPPUNIT_CFLAGS) \ +audiocache_CXXFLAGS = -DOUTPUT=\"audiocache\" $(CPPUNIT_CFLAGS) \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(PTHREAD_CFLAGS) $(SNDFILE_CFLAGS) -cachemanager_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) -cachemanager_SOURCES = \ - $(top_srcdir)/src/cachemanager.cc \ +audiocache_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocache_SOURCES = \ + $(top_srcdir)/src/audiocache.cc \ + $(top_srcdir)/src/audiocacheeventhandler.cc \ + $(top_srcdir)/src/audiocachefile.cc \ + $(top_srcdir)/src/audiocacheidmanager.cc \ $(top_srcdir)/src/thread.cc \ $(top_srcdir)/src/mutex.cc \ $(top_srcdir)/src/semaphore.cc \ $(top_srcdir)/src/configuration.cc \ $(top_srcdir)/src/audiofile.cc \ test.cc \ - cachemanagertest.cc + audiocachetest.cc + +audiocachefile_CXXFLAGS = -DOUTPUT=\"audiocachefile\" $(CPPUNIT_CFLAGS) \ + -I$(top_srcdir)/src -I$(top_srcdir)/include \ + -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(PTHREAD_CFLAGS) $(SNDFILE_CFLAGS) +audiocachefile_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocachefile_SOURCES = \ + $(top_srcdir)/src/audiocachefile.cc \ + $(top_srcdir)/src/thread.cc \ + $(top_srcdir)/src/mutex.cc \ + $(top_srcdir)/src/semaphore.cc \ + $(top_srcdir)/src/configuration.cc \ + $(top_srcdir)/src/audiofile.cc \ + test.cc \ + audiocachefiletest.cc + +audiocacheidmanager_CXXFLAGS = -DOUTPUT=\"audiocacheidmanager\" \ + $(CPPUNIT_CFLAGS) \ + -I$(top_srcdir)/src -I$(top_srcdir)/include \ + -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(SNDFILE_CFLAGS) +audiocacheidmanager_LDFLAGS = $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocacheidmanager_SOURCES = \ + $(top_srcdir)/src/audiocacheidmanager.cc \ + test.cc \ + audiocacheidmanagertest.cc + +audiocacheeventhandler_CXXFLAGS = -DOUTPUT=\"audiocacheeventhandler\" \ + $(CPPUNIT_CFLAGS) \ + -I$(top_srcdir)/src -I$(top_srcdir)/include \ + -I$(top_srcdir)/hugin -DDISABLE_HUGIN $(PTHREAD_CFLAGS) $(SNDFILE_CFLAGS) +audiocacheeventhandler_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS) +audiocacheeventhandler_SOURCES = \ + $(top_srcdir)/src/audiocacheeventhandler.cc \ + $(top_srcdir)/src/audiocacheidmanager.cc \ + $(top_srcdir)/src/audiocachefile.cc \ + $(top_srcdir)/src/mutex.cc \ + $(top_srcdir)/src/thread.cc \ + $(top_srcdir)/src/semaphore.cc \ + test.cc \ + audiocacheeventhandlertest.cc engine_CXXFLAGS = -DOUTPUT=\"engine\" $(CPPUNIT_CFLAGS) \ -I$(top_srcdir)/src -I$(top_srcdir)/include \ diff --git a/test/audiocacheeventhandlertest.cc b/test/audiocacheeventhandlertest.cc new file mode 100644 index 0000000..a8c3777 --- /dev/null +++ b/test/audiocacheeventhandlertest.cc @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiocacheeventhandlertest.cc + * + * Thu Jan 7 15:44:14 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +#include + +class TestableAudioCacheEventHandler + : public AudioCacheEventHandler +{ +public: + +}; + +class AudioCacheEventHandlerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(AudioCacheEventHandlerTest); + CPPUNIT_TEST(threadedTest); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void threadedTest() + { + AudioCacheIDManager idManager; + idManager.init(10); + + AudioCacheEventHandler eventHandler(idManager); + } +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheEventHandlerTest); diff --git a/test/audiocachefiletest.cc b/test/audiocachefiletest.cc new file mode 100644 index 0000000..a70091c --- /dev/null +++ b/test/audiocachefiletest.cc @@ -0,0 +1,189 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiocachefiletest.cc + * + * Thu Jan 7 15:43:12 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +#include + +#include +#include + +class TestableAudioCacheFiles : public AudioCacheFiles +{ +public: + //CacheAudioFile& getAudioFile(const std::string& filename); + //void release(const std::string& filename); + int getRef(const std::string& filename) + { + if(audiofiles.find(filename) == audiofiles.end()) + { + return -1; + } + + return audiofiles[filename]->ref; + } +}; + +class AudioCacheFileTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(AudioCacheFileTest); + CPPUNIT_TEST(refTest); + CPPUNIT_TEST(readTest); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void refTest() + { + TestableAudioCacheFiles audiofiles; + std::string filename = "kit/ride-single-channel.wav"; + CPPUNIT_ASSERT_EQUAL(-1, audiofiles.getRef(filename)); + + audiofiles.getFile(filename); + CPPUNIT_ASSERT_EQUAL(1, audiofiles.getRef(filename)); + + audiofiles.getFile(filename); + CPPUNIT_ASSERT_EQUAL(2, audiofiles.getRef(filename)); + + audiofiles.releaseFile(filename); + CPPUNIT_ASSERT_EQUAL(1, audiofiles.getRef(filename)); + + audiofiles.releaseFile(filename); + CPPUNIT_ASSERT_EQUAL(-1, audiofiles.getRef(filename)); + } + + void readTestHelper(size_t bufferSize) + { + printf("Test buffer size: %d samples\n", bufferSize); + + std::string filename = "kit/ride-multi-channel.wav"; + AudioFile* refFile[13]; + for(size_t c = 0; c < 13; ++c) + { + refFile[c] = new AudioFile(filename, c); + refFile[c]->load(); + } + + AudioCacheFile file(filename); + CPPUNIT_ASSERT_EQUAL(filename, file.getFilename()); + CPPUNIT_ASSERT_EQUAL(13, (int)file.getChannelCount()); // Sanity check + + CacheChannels channels; + + sample_t samples[13][bufferSize]; + volatile bool ready[13]; + for(size_t c = 0; c < 13; ++c) + { + for(int c = 0; c < 13; ++c) + { + for(int i = 0; i < bufferSize; ++i) + { + samples[c][i] = 42; + } + } + + channels.push_back( + { + c, // channel + samples[c], // samples + bufferSize, // max_num_samples + &ready[c] // ready + } + ); + } + + for(size_t offset = 0; offset < file.getSize(); offset += bufferSize) + { + for(size_t c = 0; c < 13; ++c) + { + ready[c] = false; + } + + size_t readSize = file.getSize() - offset; + if(readSize > bufferSize) + { + readSize = bufferSize; + } + else + { + printf("Last read: %d samples\n", readSize); + } + + file.readChunk(channels, offset, readSize); + + for(size_t c = 0; c < 13; ++c) + { + CPPUNIT_ASSERT_EQUAL(true, ready[c]?true:false); + } + + sample_t diff[13] = {0.0}; + for(int c = 0; c < 13; ++c) + { + for(int i = 0; i < readSize; ++i) + { + diff[c] += abs(refFile[c]->data[i + offset] - samples[c][i]); + } + } + + for(int c = 0; c < 13; ++c) + { + CPPUNIT_ASSERT_EQUAL((sample_t)0.0, diff[c]); + } + } + + for(size_t c = 0; c < 13; ++c) + { + delete refFile[c]; + } + } + + void readTest() + { + // Exhaustive test for 1...64 + for(size_t bufferSize = 1; bufferSize < 64; ++bufferSize) + { + readTestHelper(bufferSize); + } + + // Binary test for 64 .. 4096 + for(size_t bufferSize = 64; bufferSize < 4096; bufferSize *= 2) + { + readTestHelper(bufferSize); + } + + // And some sporadic tests for some "wierd" sizes. + for(size_t bufferSize = 65; bufferSize < 4096; bufferSize *= 1.1) + { + readTestHelper(bufferSize); + } + } + +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheFileTest); diff --git a/test/audiocacheidmanagertest.cc b/test/audiocacheidmanagertest.cc new file mode 100644 index 0000000..58bff4e --- /dev/null +++ b/test/audiocacheidmanagertest.cc @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * audiocacheidmanagertest.cc + * + * Thu Jan 7 15:42:31 CET 2016 + * Copyright 2016 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +#include + +class TestableAudioCacheIDManager : public AudioCacheIDManager { +public: + int getAvailableIds() + { + return availableids.size(); + } +}; + +class AudioCacheIDManagerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(AudioCacheIDManagerTest); + CPPUNIT_TEST(registerReleaseTest); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void registerReleaseTest() + { + TestableAudioCacheIDManager manager; + manager.init(2); + + cache_t c1; c1.afile = (AudioCacheFile*)1; + auto id1 = manager.registerId(c1); + CPPUNIT_ASSERT(id1 != CACHE_DUMMYID); + CPPUNIT_ASSERT(id1 != CACHE_NOID); + CPPUNIT_ASSERT_EQUAL(1, manager.getAvailableIds()); + + cache_t c2; c2.afile = (AudioCacheFile*)2; + auto id2 = manager.registerId(c2); + CPPUNIT_ASSERT(id2 != CACHE_DUMMYID); + CPPUNIT_ASSERT(id2 != CACHE_NOID); + CPPUNIT_ASSERT_EQUAL(0, manager.getAvailableIds()); + + cache_t c3; c3.afile = (AudioCacheFile*)3; + auto id3 = manager.registerId(c3); + CPPUNIT_ASSERT(id3 == CACHE_DUMMYID); + CPPUNIT_ASSERT_EQUAL(0, manager.getAvailableIds()); + + cache_t& tc1 = manager.getCache(id1); + CPPUNIT_ASSERT_EQUAL(c1.afile, tc1.afile); + + cache_t& tc2 = manager.getCache(id2); + CPPUNIT_ASSERT_EQUAL(c2.afile, tc2.afile); + + manager.releaseId(id1); + CPPUNIT_ASSERT_EQUAL(1, manager.getAvailableIds()); + + cache_t c4; c4.afile = (AudioCacheFile*)4; + auto id4 = manager.registerId(c4); + CPPUNIT_ASSERT(id4 != CACHE_DUMMYID); + CPPUNIT_ASSERT(id4 != CACHE_NOID); + CPPUNIT_ASSERT_EQUAL(0, manager.getAvailableIds()); + + cache_t& tc4 = manager.getCache(id4); + CPPUNIT_ASSERT_EQUAL(c4.afile, tc4.afile); + + manager.releaseId(id2); + CPPUNIT_ASSERT_EQUAL(1, manager.getAvailableIds()); + + manager.releaseId(id4); + CPPUNIT_ASSERT_EQUAL(2, manager.getAvailableIds()); + } +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheIDManagerTest); diff --git a/test/audiocachetest.cc b/test/audiocachetest.cc new file mode 100644 index 0000000..0296490 --- /dev/null +++ b/test/audiocachetest.cc @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * cachemanagertest.cc + * + * Sun Apr 19 10:15:59 CEST 2015 + * Copyright 2015 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of DrumGizmo. + * + * DrumGizmo is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * DrumGizmo 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with DrumGizmo; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include + +#include +#include +#include + +#define FRAMESIZE 64//1024 + +class AudioCacheTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(AudioCacheTest); + CPPUNIT_TEST(singleChannelNonThreaded); + CPPUNIT_TEST(singleChannelThreaded); + CPPUNIT_TEST(multiChannelNonThreaded); + CPPUNIT_TEST(multiChannelThreaded); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + //! Test runner. + //! \param filename The name of the file to read. + //! \param channel The channel number to do comparison on. + //! \param thread Control if this test is running in threaded mode or not. + //! \param framesize The initial framesize to use. + void testHelper(const char* filename, int channel, bool threaded, + int framesize) + { + // Reference file: + AudioFile audioFileRef(filename, channel); + printf("audioFileRef.load\n"); + audioFileRef.load(ALL_SAMPLES); + + // Input file: + AudioFile audioFile(filename, channel); + printf("audioFile.load\n"); + audioFile.load(4096); + + AudioCache audioCache; + printf("audioCache.init\n"); + audioCache.init(100); + audioCache.setAsyncMode(threaded); + + // Set initial (upper limit) framesize + audioCache.setFrameSize(framesize); + + cacheid_t id; + + for(size_t initial_samples_needed = 0; + initial_samples_needed < (framesize - 1); ++initial_samples_needed) + { + + printf("open: initial_samples_needed: %d\n", initial_samples_needed); + sample_t *samples = + audioCache.open(&audioFile, initial_samples_needed, channel, id); + size_t size = initial_samples_needed; + size_t offset = 0; + + // Test pre cache: + for(size_t i = 0; i < size; ++i) + { + CPPUNIT_ASSERT_EQUAL(audioFileRef.data[offset], samples[i]); + ++offset; + } + + // Test the rest + while(offset < audioFileRef.size) + { + if(threaded) + { + // Wait until we are finished reading + int timeout = 1000; + while(!audioCache.isReady(id)) + { + usleep(1000); + if(--timeout == 0) + { + CPPUNIT_ASSERT(false); // timeout + } + } + } + + samples = audioCache.next(id, size); + + CPPUNIT_ASSERT_EQUAL(0, (int)audioCache.getNumberOfUnderruns()); + + for(size_t i = 0; (i < size) && (offset < audioFileRef.size); ++i) + { + if(audioFileRef.data[offset] != samples[i]) + { + printf("-----> offset: %d, size: %d, diff: %d," + " i: %d, size: %d, block-diff: %d\n", + offset, audioFileRef.size, audioFileRef.size - offset, + i, size, size - i); + } + CPPUNIT_ASSERT_EQUAL(audioFileRef.data[offset], samples[i]); + ++offset; + } + } + + audioCache.close(id); + } + + printf("done\n"); + } + + void singleChannelNonThreaded() + { + printf("\nsinglechannel_nonthreaded()\n"); + const char filename[] = "kit/ride-single-channel.wav"; + int channel = 0; + bool threaded = false; + testHelper(filename, channel, threaded, FRAMESIZE); + } + + void singleChannelThreaded() + { + printf("\nsinglechannel_threaded()\n"); + const char filename[] = "kit/ride-single-channel.wav"; + int channel = 0; + bool threaded = true; + testHelper(filename, channel, threaded, FRAMESIZE); + } + + void multiChannelNonThreaded() + { + printf("\nmultichannel_nonthreaded()\n"); + const char filename[] = "kit/ride-multi-channel.wav"; + int channel = 0; + bool threaded = false; + testHelper(filename, channel, threaded, FRAMESIZE); + ++channel; + testHelper(filename, channel, threaded, FRAMESIZE); + } + + void multiChannelThreaded() + { + printf("\nmultichannel_threaded()\n"); + const char filename[] = "kit/ride-multi-channel.wav"; + int channel = 0; + bool threaded = true; + testHelper(filename, channel, threaded, FRAMESIZE); + ++channel; + testHelper(filename, channel, threaded, FRAMESIZE); + } + +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(AudioCacheTest); diff --git a/test/cachemanagertest.cc b/test/cachemanagertest.cc deleted file mode 100644 index d521f83..0000000 --- a/test/cachemanagertest.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * cachemanagertest.cc - * - * Sun Apr 19 10:15:59 CEST 2015 - * Copyright 2015 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of DrumGizmo. - * - * DrumGizmo is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * DrumGizmo 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with DrumGizmo; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include - -#include -#include - -#define FRAMESIZE 1024 - -class test_cachemanager : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(test_cachemanager); - CPPUNIT_TEST(singlechannel_nonthreaded); - CPPUNIT_TEST(singlechannel_threaded); - CPPUNIT_TEST(multichannel_nonthreaded); - CPPUNIT_TEST(multichannel_threaded); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp() {} - void tearDown() {} - - void testit(const char *filename, int channel, bool threaded) - { - - // Reference file: - AudioFile afref(filename, channel); - printf("afref.load\n"); - afref.load(ALL_SAMPLES); - - // Input file: - AudioFile af(filename, channel); - printf("af.load\n"); - //af.load(ALL_SAMPLES); - af.load(4096); - - CacheManager cm; - printf("cm.init\n"); - cm.init(100, threaded); - - cm.setFrameSize(FRAMESIZE); - - cacheid_t id; - // TODO: test 0 ... FRAMESIZE - 1 - size_t initial_samples_needed = (FRAMESIZE - 1) / 2; - - printf("open: initial_samples_needed: %d\n", initial_samples_needed); - sample_t *s = cm.open(&af, initial_samples_needed, channel, id); - size_t size = initial_samples_needed; - size_t offset = 0; - - // Test pre cache: - for(size_t i = 0; i < size; i++) { - CPPUNIT_ASSERT_EQUAL(afref.data[offset], s[i]); - offset++; - } - - // Test the rest - while(offset < afref.size) { - - if(threaded) { - usleep(1000000.0 / 44100.0 * FRAMESIZE); - //sleep(1); // sleep 1 second - } - - //printf("offset: %d\t", offset); - s = cm.next(id, size); - //printf("next -> size: %d\n", size); - for(size_t i = 0; (i < size) && (offset < afref.size); i++) { - /* - if(afref.data[offset] != s[i]) { - printf("offset: %d, size: %d, diff: %d\n", offset, afref.size, afref.size - offset); - } - */ - CPPUNIT_ASSERT_EQUAL(afref.data[offset], s[i]); - offset++; - } - } - - printf("done\n"); - } - - void singlechannel_nonthreaded() - { - printf("\nsinglechannel_nonthreaded()\n"); - const char filename[] = "kit/ride-single-channel.wav"; - int channel = 0; - bool threaded = false; - testit(filename, channel, threaded); - } - - void singlechannel_threaded() - { - printf("\nsinglechannel_threaded()\n"); - const char filename[] = "kit/ride-single-channel.wav"; - int channel = 0; - bool threaded = true; - testit(filename, channel, threaded); - } - - void multichannel_nonthreaded() - { - printf("\nmultichannel_nonthreaded()\n"); - const char filename[] = "kit/ride-multi-channel.wav"; - int channel = 0; - bool threaded = false; - testit(filename, channel, threaded); - } - - void multichannel_threaded() - { - printf("\nmultichannel_threaded()\n"); - const char filename[] = "kit/ride-multi-channel.wav"; - int channel = 0; - bool threaded = true; - testit(filename, channel, threaded); - } - -}; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_cachemanager); - - - -- cgit v1.2.3