aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohannes Schickel2010-02-03 10:36:14 +0000
committerJohannes Schickel2010-02-03 10:36:14 +0000
commitbaf6b53431bbb1b5a630fd153fe3df350e3d16fd (patch)
treef9cd00669fa4a8b91f5568ecc926f828e69dad3c /test
parentd32dfa3bb3df8e1b2b4fb9d146a0affe2c2be814 (diff)
downloadscummvm-rg350-baf6b53431bbb1b5a630fd153fe3df350e3d16fd.tar.gz
scummvm-rg350-baf6b53431bbb1b5a630fd153fe3df350e3d16fd.tar.bz2
scummvm-rg350-baf6b53431bbb1b5a630fd153fe3df350e3d16fd.zip
Add some (lame) first version of RawStream unit tests. Currently all it does it, checking, whether readBuffer works for 8bit and 16bit samples.
svn-id: r47849
Diffstat (limited to 'test')
-rw-r--r--test/sound/raw.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/sound/raw.h b/test/sound/raw.h
new file mode 100644
index 0000000000..bedee869ec
--- /dev/null
+++ b/test/sound/raw.h
@@ -0,0 +1,82 @@
+#include <cxxtest/TestSuite.h>
+
+#include "sound/decoders/raw.h"
+
+#include "common/stream.h"
+#include "common/endian.h"
+
+#include <math.h>
+#include <limits>
+
+class RawStreamTestSuite : public CxxTest::TestSuite
+{
+public:
+ template<typename T>
+ T *createSine(int sampleRate, int time) {
+ T *sine = (T *)malloc(sizeof(T) * time * sampleRate);
+
+ const T maxValue = std::numeric_limits<T>::max();
+
+ for (int i = 0; i < time * sampleRate; ++i)
+ sine[i] = (T)(sin((double)i / sampleRate * 2 * PI) * maxValue);
+
+ // Convert to BE
+ if (sizeof(T) == 2) {
+ for (int i = 0; i < time * sampleRate; ++i)
+ WRITE_BE_UINT16(&sine[i], sine[i]);
+ }
+
+ return sine;
+ }
+
+ template<typename T>
+ Audio::SeekableAudioStream *createSineStream(int sampleRate, int time, const T **sineP) {
+ T *sine = createSine<T>(sampleRate, time);
+
+ Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(T) * sampleRate * time, DisposeAfterUse::YES);
+ Audio::SeekableAudioStream *s = Audio::makeRawStream(sD, sampleRate, (sizeof(T) == 2) ? Audio::FLAG_16BITS : 0);
+
+ if (sineP)
+ *sineP = sine;
+
+ return s;
+ }
+
+ void test_read_buffer_8_bit_mono() {
+ const int sampleRate = 11025;
+ const int time = 2;
+
+ const int8 *sine = 0;
+ Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine);
+
+ int16 *buffer = new int16[sampleRate * time];
+ TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
+
+ for (int i = 0; i < sampleRate * time; ++i)
+ TS_ASSERT_EQUALS(buffer[i], sine[i] << 8);
+
+ TS_ASSERT_EQUALS(s->endOfData(), true);
+
+ delete[] buffer;
+ delete s;
+ }
+
+ void test_read_buffer_16_bit_mono() {
+ const int sampleRate = 11025;
+ const int time = 2;
+
+ const int16 *sine = 0;
+ Audio::SeekableAudioStream *s = createSineStream<int16>(sampleRate, time, &sine);
+
+ int16 *buffer = new int16[sampleRate * time];
+ TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
+
+ for (int i = 0; i < sampleRate * time; ++i)
+ TS_ASSERT_EQUALS(buffer[i], (int16)READ_BE_UINT16(&sine[i]));
+
+ TS_ASSERT_EQUALS(s->endOfData(), true);
+
+ delete[] buffer;
+ delete s;
+ }
+};