Skip to content

Commit 4c1ce96

Browse files
committed
Tests for buffers and queues
1 parent 7f11af0 commit 4c1ce96

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed
Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
11
#include "AudioTools.h"
22

3-
void test(BaseBuffer<int16_t> &b, const char* title){
4-
Serial.println(title);
5-
assert(b.isEmpty());
6-
for (int j=0;j<200;j++){
7-
assert(b.write(j));
8-
}
9-
assert(b.isFull());
10-
for (int j=0;j<200;j++){
11-
int16_t v = b.read();
12-
assert(v==j);
13-
}
14-
assert(b.isEmpty());
15-
int16_t array[200];
16-
for (int j=0;j<200;j++){
17-
array[j] = j;
18-
}
19-
assert(b.writeArray(array, 200)==200);
20-
assert(b.readArray(array,200)==200);
21-
for (int j=0;j<200;j++){
22-
assert(array[j]==j);
23-
}
24-
25-
Serial.println("Test OK");
3+
// test different buffer implementations
4+
5+
void test(BaseBuffer<int16_t>& b, const char* title) {
6+
Serial.println(title);
7+
assert(b.isEmpty());
8+
for (int j = 0; j < 200; j++) {
9+
assert(b.write(j));
10+
}
11+
assert(b.isFull());
12+
for (int j = 0; j < 200; j++) {
13+
int16_t v = b.read();
14+
assert(v == j);
15+
}
16+
assert(b.isEmpty());
17+
int16_t array[200];
18+
for (int j = 0; j < 200; j++) {
19+
array[j] = j;
20+
}
21+
b.clear();
22+
int len = b.writeArray(array, 200);
23+
Serial.println(len);
24+
len = b.readArray(array,200);
25+
Serial.println(len);
26+
for (int j=0;j<200;j++){
27+
assert(array[j]==j);
28+
}
29+
30+
Serial.println("Test OK");
2631
}
2732

28-
void setup(){
29-
SingleBuffer<int16_t> b1(200);
30-
RingBuffer<int16_t> b2(200);
31-
NBuffer<int16_t> b3(50,4);
33+
void setup() {
34+
Serial.begin(115200);
35+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
36+
37+
SingleBuffer<int16_t> b1(200);
38+
test(b1, "SingleBuffer");
39+
40+
RingBuffer<int16_t> b2(200);
41+
test(b2,"RingBuffer");
3242

33-
test(b1,"SingleBuffer");
34-
test(b2,"RingBuffer");
35-
test(b3,"NBuffer");
43+
NBuffer<int16_t> b3(50, 4);
44+
test(b3,"NBuffer");
3645

37-
Serial.println("Tests OK");
46+
Serial.println("Tests OK");
3847
}
3948

40-
void loop(){}
49+
void loop() {}

examples/tests/basic/test-queue/test-queue.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#include "AudioTools.h"
22
#include "Concurrency/QueueLockFree.h"
33

4-
// select the queue implementation:
5-
Queue<int> q1;
6-
QueueFromVector<int> q2{10, 0};
7-
QueueLockFree<int> q3(10);
4+
// test different queue implementations:
85

96
template <typename T>
107
void test(T &q, const char* cls){
@@ -23,13 +20,19 @@ void test(T &q, const char* cls){
2320
assert(q.size()==10-(j+1));
2421
}
2522
assert(q.empty());
26-
Serial.println("-> ok");
23+
Serial.println("ok");
2724
}
2825

2926
void setup() {
3027
Serial.begin(115200);
28+
29+
Queue<int> q1;
3130
test<Queue<int>>(q1,"Queue");
31+
32+
QueueFromVector<int> q2{10, 0};
3233
test<QueueFromVector<int>>(q2,"QueueFromVector");
34+
35+
QueueLockFree<int> q3(10);
3336
test<QueueLockFree<int>>(q3,"QueueLockFree");
3437
Serial.println("all tests passed");
3538
}

0 commit comments

Comments
 (0)