aboutsummaryrefslogtreecommitdiff
path: root/test/sound
diff options
context:
space:
mode:
authorJohannes Schickel2010-02-06 16:41:53 +0000
committerJohannes Schickel2010-02-06 16:41:53 +0000
commite3d4d5e3793041a189370521d11bc24727da4d31 (patch)
treed393ea62c9ccbc3fafc837fc93ab7b49ec0ab58b /test/sound
parent4fca64d1b049d5d94b0ca844c7dad301ddaf8718 (diff)
downloadscummvm-rg350-e3d4d5e3793041a189370521d11bc24727da4d31.tar.gz
scummvm-rg350-e3d4d5e3793041a189370521d11bc24727da4d31.tar.bz2
scummvm-rg350-e3d4d5e3793041a189370521d11bc24727da4d31.zip
Add (currently failing :-/) unit tests for LoopingAudioStream.
svn-id: r47934
Diffstat (limited to 'test/sound')
-rw-r--r--test/sound/audiostream.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/sound/audiostream.h b/test/sound/audiostream.h
index 4efbdba7cb..869598a7ac 100644
--- a/test/sound/audiostream.h
+++ b/test/sound/audiostream.h
@@ -2,6 +2,8 @@
#include "sound/audiostream.h"
+#include "helper.h"
+
class AudioStreamTestSuite : public CxxTest::TestSuite
{
public:
@@ -31,5 +33,62 @@ public:
const Audio::Timestamp e = Audio::convertTimeToStreamPos(Audio::Timestamp(1, 1, 4), 11025, false);
TS_ASSERT_EQUALS(e.totalNumberOfFrames(), 5 * 11025 / 4);
}
+
+private:
+ void testLoopingAudioStreamFixedIter(const int sampleRate, const bool isStereo) {
+ const int secondLength = sampleRate * (isStereo ? 2 : 1);
+
+ int16 *sine = 0;
+ Audio::SeekableAudioStream *s = createSineStream<int16>(sampleRate, 1, &sine, false, isStereo);
+ Audio::LoopingAudioStream *loop = new Audio::LoopingAudioStream(s, 4);
+
+ int16 *buffer = new int16[secondLength * 2];
+
+ // Check parameters
+ TS_ASSERT_EQUALS(loop->isStereo(), isStereo);
+ TS_ASSERT_EQUALS(loop->getRate(), sampleRate);
+ TS_ASSERT_EQUALS(loop->endOfData(), false);
+ TS_ASSERT_EQUALS(loop->getCompleteIterations(), (uint)0);
+
+ // Read one second
+ TS_ASSERT_EQUALS(loop->readBuffer(buffer, secondLength), secondLength);
+ TS_ASSERT_EQUALS(memcmp(buffer, sine, secondLength * sizeof(int16)), 0);
+
+ TS_ASSERT_EQUALS(loop->getCompleteIterations(), (uint)1);
+ TS_ASSERT_EQUALS(loop->endOfData(), false);
+
+ // Read two seconds
+ TS_ASSERT_EQUALS(loop->readBuffer(buffer, secondLength * 2), secondLength * 2);
+ TS_ASSERT_EQUALS(memcmp(buffer, sine, secondLength * sizeof(int16)), 0);
+ TS_ASSERT_EQUALS(memcmp(buffer + secondLength, sine, secondLength * sizeof(int16)), 0);
+
+ TS_ASSERT_EQUALS(loop->getCompleteIterations(), (uint)3);
+ TS_ASSERT_EQUALS(loop->endOfData(), false);
+
+ // Read the last second
+ TS_ASSERT_EQUALS(loop->readBuffer(buffer, secondLength), secondLength);
+ TS_ASSERT_EQUALS(memcmp(buffer, sine, secondLength * sizeof(int16)), 0);
+
+ TS_ASSERT_EQUALS(loop->getCompleteIterations(), (uint)4);
+ TS_ASSERT_EQUALS(loop->endOfData(), true);
+
+ // Try to read beyond the end of the stream
+ TS_ASSERT_EQUALS(loop->readBuffer(buffer, secondLength), 0);
+ TS_ASSERT_EQUALS(loop->getCompleteIterations(), (uint)4);
+ TS_ASSERT_EQUALS(loop->endOfData(), true);
+
+ delete[] buffer;
+ delete loop;
+ delete[] sine;
+ }
+
+public:
+ void test_looping_audio_stream_mono_fixed_iter() {
+ testLoopingAudioStreamFixedIter(22050, false);
+ }
+
+ void test_looping_audio_stream_stereo_fixed_iter() {
+ testLoopingAudioStreamFixedIter(22050, true);
+ }
};