diff options
author | David Robillard <d@drobilla.net> | 2007-03-31 01:40:11 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-03-31 01:40:11 +0000 |
commit | 423cbc959a04b6d54365b943b22936ec6b2a4b62 (patch) | |
tree | 9e349380384b0e8b5532a6507f32e21cfe20a5b9 /tests | |
parent | 9e81a81484aa0142f0c02cf066c41bd2d2c84eea (diff) | |
download | raul-423cbc959a04b6d54365b943b22936ec6b2a4b62.tar.gz raul-423cbc959a04b6d54365b943b22936ec6b2a4b62.tar.bz2 raul-423cbc959a04b6d54365b943b22936ec6b2a4b62.zip |
Added RingBuffer and MIDIRingBuffer classes/tests.
git-svn-id: http://svn.drobilla.net/lad/raul@382 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 16 | ||||
-rw-r--r-- | tests/midi_ringbuffer_test.cpp | 40 | ||||
-rw-r--r-- | tests/ringbuffer_test.cpp | 46 |
3 files changed, 101 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index cbc3582..af2b7f4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,11 +3,23 @@ if BUILD_TESTS AM_CXXFLAGS = -I.. -lpthread @RASQAL_CFLAGS@ @GLIBMM_CFLAGS@ ALL_LIBS = @RASQAL_LIBS@ @GLIBMM_LIBS@ ../src/libraul.la -bin_PROGRAMS = path_test thread_test queue_test atomic_test list_test time_test quantize_test smf_test +bin_PROGRAMS = \ + path_test \ + thread_test \ + queue_test \ + ringbuffer_test \ + midi_ringbuffer_test \ + atomic_test \ + list_test \ + time_test \ + quantize_test \ + smf_test thread_test_LDADD = $(ALL_LIBS) path_test_LDADD = $(ALL_LIBS) queue_test_LDADD = $(ALL_LIBS) +ringbuffer_test_LDADD = $(ALL_LIBS) +midi_ringbuffer_test_LDADD = $(ALL_LIBS) atomic_test_LDADD = $(ALL_LIBS) list_test_LDADD = $(ALL_LIBS) time_test_LDADD = $(ALL_LIBS) @@ -17,6 +29,8 @@ smf_test_LDADD = $(ALL_LIBS) path_test_SOURCES = path_test.cpp thread_test_SOURCES = thread_test.cpp queue_test_SOURCES = queue_test.cpp +midi_ringbuffer_test_SOURCES = midi_ringbuffer_test.cpp +ringbuffer_test_SOURCES = ringbuffer_test.cpp atomic_test_SOURCES = atomic_test.cpp list_test_SOURCES = list_test.cpp time_test_SOURCES = time_test.cpp diff --git a/tests/midi_ringbuffer_test.cpp b/tests/midi_ringbuffer_test.cpp new file mode 100644 index 0000000..c8fc508 --- /dev/null +++ b/tests/midi_ringbuffer_test.cpp @@ -0,0 +1,40 @@ +#include <iostream> +#include "raul/MIDIRingBuffer.h" + +using namespace std; +using namespace Raul; + +void +read_write_test(MIDIRingBuffer& rb, unsigned offset) +{ + TickTime t; + size_t size; + char buf[5]; + + snprintf(buf, 5, "%d", offset); + size = strlen(buf); + + size_t written = rb.write(offset, size, buf); + assert(written == size); + + for (size_t i=0; i < 4; ++i) + buf[i] = 0; + + rb.read(&t, &size, buf); + + cout << "t=" << t << ", s=" << size << ", b='" << buf << "'" << endl; + +} + + +int +main() +{ + MIDIRingBuffer rb(32); + + for (size_t i=0; i < 9999; ++i) + read_write_test(rb, i); + + return 0; +} + diff --git a/tests/ringbuffer_test.cpp b/tests/ringbuffer_test.cpp new file mode 100644 index 0000000..01f136f --- /dev/null +++ b/tests/ringbuffer_test.cpp @@ -0,0 +1,46 @@ +#include <iostream> +#include "raul/RingBuffer.h" + +using namespace std; +using namespace Raul; + +void +print_buf(size_t size, char* buf) +{ + cout << "{ "; + for (size_t i=0; i < size; ++i) { + cout << buf[i]; + if (i < size-1) + cout << ", "; + } + + cout << " }" << endl; +} + + +int +main() +{ + RingBuffer<char> rb(5); + + char ev[] = { 'a', 'b', 'c' }; + + rb.write(3, ev); + + char buf[3]; + rb.read(3, buf); + print_buf(3, buf); + + char ev2[] = { 'd', 'e', 'f' }; + rb.write(3, ev2); + + + size_t read = rb.read(3, buf); + if (read < 3) + rb.read(3 - read, buf + read); + + print_buf(3, buf); + + return 0; +} + |