aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/audio/helper.h57
-rw-r--r--test/audio/raw.h120
-rw-r--r--test/common/fixedstack.h14
-rw-r--r--test/common/memoryreadstream.h16
-rw-r--r--test/common/pack.h2
-rw-r--r--test/common/stack.h12
-rw-r--r--test/common/subreadstream.h18
-rw-r--r--test/cxxtest/cxxtest/ValueTraits.h4
8 files changed, 85 insertions, 158 deletions
diff --git a/test/audio/helper.h b/test/audio/helper.h
index 5080c79eef..77dc63b619 100644
--- a/test/audio/helper.h
+++ b/test/audio/helper.h
@@ -24,40 +24,7 @@ static T *createSine(const int sampleRate, const int time) {
}
template<typename T>
-static Common::SeekableReadStream *createPartitionStream(T *sine, const int samples, Audio::RawStreamBlockList &blockList) {
- const int block1Len = samples / 2;
- const int block1Size = block1Len * sizeof(T);
- const int block2Len = samples - block1Len;
- const int block2Size = block2Len * sizeof(T);
-
- const int bufferLen = samples * 2;
- const int bufferSize = bufferLen * sizeof(T);
- T *partition = (T *)calloc(1, bufferSize);
-
- Audio::RawStreamBlock block;
-
- // The will layout the buffer like the following:
- // [Zero], [Part2], [Zero], [Part1]
-
- // The first part of the stream is at the end of the memory buffer
- block.pos = bufferSize - block1Size;
- block.len = block1Len;
- memcpy(partition + bufferLen - block1Len, sine, block1Size);
- blockList.push_back(block);
-
- // The second part of the stream is near the beginning of the memory buffer
- block.pos = block2Size;
- block.len = block2Len;
- memcpy(partition + block2Len, sine + block1Len, block2Size);
- blockList.push_back(block);
-
- free(sine);
-
- return new Common::MemoryReadStream((const byte *)partition, bufferSize, DisposeAfterUse::YES);
-}
-
-template<typename T>
-static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const int time, int16 **comp, bool le, bool isStereo, bool makePartition = false) {
+static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const int time, int16 **comp, bool le, bool isStereo) {
T *sine = createSine<T>(sampleRate, time * (isStereo ? 2 : 1));
const bool isUnsigned = !std::numeric_limits<T>::is_signed;
@@ -88,22 +55,12 @@ static Audio::SeekableAudioStream *createSineStream(const int sampleRate, const
}
Audio::SeekableAudioStream *s = 0;
- if (makePartition) {
- Audio::RawStreamBlockList blockList;
- Common::SeekableReadStream *sD = createPartitionStream<T>(sine, samples, blockList);
- s = Audio::makeRawStream(sD, blockList, sampleRate,
- (is16Bits ? Audio::FLAG_16BITS : 0)
- | (isUnsigned ? Audio::FLAG_UNSIGNED : 0)
- | (le ? Audio::FLAG_LITTLE_ENDIAN : 0)
- | (isStereo ? Audio::FLAG_STEREO : 0));
- } else {
- Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(T) * samples, DisposeAfterUse::YES);
- s = Audio::makeRawStream(sD, sampleRate,
- (is16Bits ? Audio::FLAG_16BITS : 0)
- | (isUnsigned ? Audio::FLAG_UNSIGNED : 0)
- | (le ? Audio::FLAG_LITTLE_ENDIAN : 0)
- | (isStereo ? Audio::FLAG_STEREO : 0));
- }
+ Common::SeekableReadStream *sD = new Common::MemoryReadStream((const byte *)sine, sizeof(T) * samples, DisposeAfterUse::YES);
+ s = Audio::makeRawStream(sD, sampleRate,
+ (is16Bits ? Audio::FLAG_16BITS : 0)
+ | (isUnsigned ? Audio::FLAG_UNSIGNED : 0)
+ | (le ? Audio::FLAG_LITTLE_ENDIAN : 0)
+ | (isStereo ? Audio::FLAG_STEREO : 0));
return s;
}
diff --git a/test/audio/raw.h b/test/audio/raw.h
index 51ec067f7e..e7cb42ac44 100644
--- a/test/audio/raw.h
+++ b/test/audio/raw.h
@@ -8,9 +8,9 @@ class RawStreamTestSuite : public CxxTest::TestSuite
{
private:
template<typename T>
- void readBufferTestTemplate(const int sampleRate, const int time, const bool le, const bool isStereo, const bool makePartition = false) {
+ void readBufferTestTemplate(const int sampleRate, const int time, const bool le, const bool isStereo) {
int16 *sine;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, le, isStereo, makePartition);
+ Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, le, isStereo);
const int totalSamples = sampleRate * time * (isStereo ? 2 : 1);
int16 *buffer = new int16[totalSamples];
@@ -68,57 +68,13 @@ public:
readBufferTestTemplate<uint16>(11025, 2, true, true);
}
- void test_read_buffer_8_bit_signed_mono_parted() {
- readBufferTestTemplate<int8>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_8_bit_signed_stereo_parted() {
- readBufferTestTemplate<int8>(11025, 2, false, true, true);
- }
-
- void test_read_buffer_8_bit_unsigned_mono_parted() {
- readBufferTestTemplate<uint8>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_16_bit_signed_be_mono_parted() {
- readBufferTestTemplate<int16>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_16_bit_signed_be_stereo_parted() {
- readBufferTestTemplate<int16>(11025, 2, false, true, true);
- }
-
- void test_read_buffer_16_bit_unsigned_be_mono_parted() {
- readBufferTestTemplate<uint16>(11025, 2, false, false, true);
- }
-
- void test_read_buffer_16_bit_unsigned_be_stereo_parted() {
- readBufferTestTemplate<uint16>(11025, 2, false, true, true);
- }
-
- void test_read_buffer_16_bit_signed_le_mono_parted() {
- readBufferTestTemplate<int16>(11025, 2, true, false, true);
- }
-
- void test_read_buffer_16_bit_signed_le_stereo_parted() {
- readBufferTestTemplate<int16>(11025, 2, true, true, true);
- }
-
- void test_read_buffer_16_bit_unsigned_le_mono_parted() {
- readBufferTestTemplate<uint16>(11025, 2, true, false, true);
- }
-
- void test_read_buffer_16_bit_unsigned_le_stereo_parted() {
- readBufferTestTemplate<uint16>(11025, 2, true, true, true);
- }
-
private:
- void partialReadTest(const bool makePartition) {
+ void partialReadTest() {
const int sampleRate = 11025;
const int time = 4;
int16 *sine;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, false, false, makePartition);
+ Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, &sine, false, false);
int16 *buffer = new int16[sampleRate * time];
TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate), sampleRate);
@@ -139,15 +95,11 @@ private:
}
public:
void test_partial_read() {
- partialReadTest(false);
- }
-
- void test_partial_read_parted() {
- partialReadTest(true);
+ partialReadTest();
}
private:
- void readAfterEndTest(const bool makePartition) {
+ void readAfterEndTest() {
const int sampleRate = 11025;
const int time = 1;
Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, 0, false, false);
@@ -165,18 +117,14 @@ private:
public:
void test_read_after_end() {
- readAfterEndTest(false);
- }
-
- void test_read_after_end_parted() {
- readAfterEndTest(true);
+ readAfterEndTest();
}
private:
- void rewindTest(const bool makePartition) {
+ void rewindTest() {
const int sampleRate = 11025;
const int time = 2;
- Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
+ Audio::SeekableAudioStream *s = createSineStream<int8>(sampleRate, time, 0, false, false);
int16 *buffer = new int16[sampleRate * time];
TS_ASSERT_EQUALS(s->readBuffer(buffer, sampleRate * time), sampleRate * time);
@@ -193,15 +141,11 @@ private:
}
public:
void test_rewind() {
- rewindTest(false);
- }
-
- void test_rewind_parted() {
- rewindTest(true);
+ rewindTest();
}
private:
- void lengthTest(const bool makePartition) {
+ void lengthTest() {
int sampleRate = 0;
const int time = 4;
@@ -209,66 +153,62 @@ private:
// 11025 Hz tests
sampleRate = 11025;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<int8>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
- s = createSineStream<uint16>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<uint16>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
// 48000 Hz tests
sampleRate = 48000;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<int8>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
- s = createSineStream<uint16>(sampleRate, time, 0, true, false, makePartition);
+ s = createSineStream<uint16>(sampleRate, time, 0, true, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
// 11840 Hz tests
sampleRate = 11840;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<int8>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
- s = createSineStream<uint16>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<uint16>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
// 11111 Hz tests
sampleRate = 11111;
- s = createSineStream<int8>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<int8>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
- s = createSineStream<uint16>(sampleRate, time, 0, false, false, makePartition);
+ s = createSineStream<uint16>(sampleRate, time, 0, false, false);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
// 22050 Hz stereo test
sampleRate = 22050;
- s = createSineStream<int8>(sampleRate, time, 0, false, true, makePartition);
+ s = createSineStream<int8>(sampleRate, time, 0, false, true);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
- s = createSineStream<uint16>(sampleRate, time, 0, true, true, makePartition);
+ s = createSineStream<uint16>(sampleRate, time, 0, true, true);
TS_ASSERT_EQUALS(s->getLength().totalNumberOfFrames(), sampleRate * time);
delete s;
}
public:
void test_length() {
- lengthTest(false);
- }
-
- void test_length_parted() {
- lengthTest(true);
+ lengthTest();
}
private:
- void seekTest(const int sampleRate, const int time, const bool isStereo, const bool makePartition) {
+ void seekTest(const int sampleRate, const int time, const bool isStereo) {
const int totalFrames = sampleRate * time * (isStereo ? 2 : 1);
int readData = 0, offset = 0;
@@ -276,7 +216,7 @@ private:
Audio::SeekableAudioStream *s = 0;
int16 *sine = 0;
- s = createSineStream<int8>(sampleRate, time, &sine, false, isStereo, makePartition);
+ s = createSineStream<int8>(sampleRate, time, &sine, false, isStereo);
// Seek to 500ms
const Audio::Timestamp a(0, 1, 2);
@@ -341,18 +281,10 @@ private:
public:
void test_seek_mono() {
- seekTest(11025, 2, false, false);
+ seekTest(11025, 2, false);
}
void test_seek_stereo() {
- seekTest(11025, 2, true, false);
- }
-
- void test_seek_mono_parted() {
- seekTest(11025, 2, false, true);
- }
-
- void test_seek_stereo_parted() {
- seekTest(11025, 2, true, true);
+ seekTest(11025, 2, true);
}
};
diff --git a/test/common/fixedstack.h b/test/common/fixedstack.h
index 9aa00b4680..9d4cceb2e6 100644
--- a/test/common/fixedstack.h
+++ b/test/common/fixedstack.h
@@ -18,18 +18,20 @@ public:
}
void test_size() {
- Common::FixedStack<int> stack;
- TS_ASSERT_EQUALS(stack.size(), 0);
+ typedef Common::FixedStack<int> Stack;
+
+ Stack stack;
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)0);
stack.push(5);
- TS_ASSERT_EQUALS(stack.size(), 1);
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)1);
stack.push(9);
stack.push(0);
- TS_ASSERT_EQUALS(stack.size(), 3);
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)3);
stack.pop();
- TS_ASSERT_EQUALS(stack.size(), 2);
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)2);
}
void test_top_pop() {
@@ -44,7 +46,7 @@ public:
stack[0] = -23;
stack.top() = 42;
TS_ASSERT_EQUALS(stack[0], -23);
- TS_ASSERT_EQUALS(stack.top(), 42);
+ TS_ASSERT_EQUALS(stack.top(), 42);
stack.pop();
TS_ASSERT_EQUALS(stack[0], -23);
diff --git a/test/common/memoryreadstream.h b/test/common/memoryreadstream.h
index a476f12a2f..adef861a5e 100644
--- a/test/common/memoryreadstream.h
+++ b/test/common/memoryreadstream.h
@@ -84,4 +84,20 @@ class MemoryReadStreamTestSuite : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(ms.pos(), 7);
TS_ASSERT(!ms.eos());
}
+
+ void test_eos() {
+ byte contents[] = { 1, 2, 3, 4, 5, 6, 7 };
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ // Read after the end of the stream
+ for (int32 i = 0; i <= ms.size(); ++i)
+ ms.readByte();
+
+ // The eos flag should be set here
+ TS_ASSERT(ms.eos());
+
+ // Seeking should reset the eos flag
+ ms.seek(0, SEEK_SET);
+ TS_ASSERT(!ms.eos());
+ }
};
diff --git a/test/common/pack.h b/test/common/pack.h
index 724457f838..f62b31e9dc 100644
--- a/test/common/pack.h
+++ b/test/common/pack.h
@@ -15,7 +15,7 @@ struct TestStruct {
#include <common/pack-end.h> // END STRUCT PACKING
-#define OFFS(type,item) (((ptrdiff_t)(&((type*)42)->type::item))-42)
+#define OFFS(type,item) (((ptrdiff_t)(&((type *)42)->type::item))-42)
class PackTestSuite : public CxxTest::TestSuite
{
diff --git a/test/common/stack.h b/test/common/stack.h
index 0b1bcee350..ed32ec6496 100644
--- a/test/common/stack.h
+++ b/test/common/stack.h
@@ -18,18 +18,20 @@ public:
}
void test_size() {
- Common::Stack<int> stack;
- TS_ASSERT_EQUALS(stack.size(), 0);
+ typedef Common::Stack<int> Stack;
+
+ Stack stack;
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)0);
stack.push(5);
- TS_ASSERT_EQUALS(stack.size(), 1);
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)1);
stack.push(9);
stack.push(0);
- TS_ASSERT_EQUALS(stack.size(), 3);
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)3);
stack.pop();
- TS_ASSERT_EQUALS(stack.size(), 2);
+ TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)2);
}
void test_top_pop() {
diff --git a/test/common/subreadstream.h b/test/common/subreadstream.h
index 463f49e929..32e6f938d2 100644
--- a/test/common/subreadstream.h
+++ b/test/common/subreadstream.h
@@ -26,4 +26,22 @@ class SubReadStreamTestSuite : public CxxTest::TestSuite {
b = srs.readByte();
TS_ASSERT(srs.eos());
}
+
+ void test_safe_eos() {
+ byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ Common::MemoryReadStream ms(contents, sizeof(contents));
+
+ Common::SafeSeekableSubReadStream ssrs1(&ms, 0, sizeof(contents));
+ Common::SafeSeekableSubReadStream ssrs2(&ms, 0, sizeof(contents));
+
+ // Read after the end of the stream of the first sub stream
+ for (int32 i = 0; i <= ssrs1.size(); ++i)
+ ssrs1.readByte();
+
+ // eos should be set for the first sub stream
+ TS_ASSERT(ssrs1.eos());
+
+ // eos should not be set for the second sub stream
+ TS_ASSERT(!ssrs2.eos());
+ }
};
diff --git a/test/cxxtest/cxxtest/ValueTraits.h b/test/cxxtest/cxxtest/ValueTraits.h
index 339a345029..45b2ea39c1 100644
--- a/test/cxxtest/cxxtest/ValueTraits.h
+++ b/test/cxxtest/cxxtest/ValueTraits.h
@@ -70,7 +70,7 @@ namespace CxxTest
//
// The default ValueTraits class dumps up to 8 bytes as hex values
//
- template <class T>
+ template<class T>
class ValueTraits
{
enum { MAX_BYTES = 8 };
@@ -85,7 +85,7 @@ namespace CxxTest
// traits( T t )
// Creates an object of type ValueTraits<T>
//
- template <class T>
+ template<class T>
inline ValueTraits<T> traits( T t )
{
return ValueTraits<T>( t );