From 0d009a4e980e40dc8a9c9b5e3d25c3fafb363e95 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 7 Jan 2010 21:27:39 +0000 Subject: Move unit testing and coverage framework into autowaf. Make raul tests return 0 on success, 1 on failure. Test coverage for Raul. git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2368 a436a847-0d15-0410-975c-d299462d15a1 --- test/midi_ringbuffer_test.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/midi_ringbuffer_test.cpp (limited to 'test/midi_ringbuffer_test.cpp') diff --git a/test/midi_ringbuffer_test.cpp b/test/midi_ringbuffer_test.cpp new file mode 100644 index 0000000..f75cfd5 --- /dev/null +++ b/test/midi_ringbuffer_test.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include "raul/TimeStamp.hpp" +#include "raul/EventRingBuffer.hpp" +#include "raul/midi_names.h" + +using namespace std; +using namespace Raul; + +int +read_write_test(EventRingBuffer& rb, unsigned offset) +{ + TimeStamp t(TimeUnit(TimeUnit::FRAMES, 48000), 0, 0); + size_t size; + unsigned char write_buf[5]; + unsigned char read_buf[5]; + + snprintf((char*)write_buf, 5, "%d", offset); + size = strlen((char*)write_buf); + + const size_t written = rb.write(t, size, write_buf); + assert(written == size); + + rb.read(&t, &size, read_buf); + + return (strncmp((const char*)write_buf, (const char*)read_buf, size)); +} + + +int +main() +{ + EventRingBuffer rb(32); + + for (size_t i = 0; i < 1000000; ++i) + if (read_write_test(rb, i)) + return 1; + + return 0; +} + -- cgit v1.2.1