summaryrefslogtreecommitdiffstats
path: root/test/ringbuffer_test.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-14 04:47:15 +0000
committerDavid Robillard <d@drobilla.net>2012-08-14 04:47:15 +0000
commit37223c88b3c34833bf23136d1b884044bc7feaaa (patch)
treebdf5bb3079950153dbfb1a3df9ce8b4e1a9b3473 /test/ringbuffer_test.cpp
parent7014fc38dafb9a31cb6ab71b66ee9f64f3eb3c65 (diff)
downloadraul-37223c88b3c34833bf23136d1b884044bc7feaaa.tar.gz
raul-37223c88b3c34833bf23136d1b884044bc7feaaa.tar.bz2
raul-37223c88b3c34833bf23136d1b884044bc7feaaa.zip
100% test coverage for RingBuffer.
Improve test coverage for Semaphore (as much as is feasibly possible). git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4689 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'test/ringbuffer_test.cpp')
-rw-r--r--test/ringbuffer_test.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/ringbuffer_test.cpp b/test/ringbuffer_test.cpp
index 48f5431..302f918 100644
--- a/test/ringbuffer_test.cpp
+++ b/test/ringbuffer_test.cpp
@@ -131,6 +131,61 @@ main(int argc, char** argv)
n_writes, MSG_SIZE, size);
ring = new Raul::RingBuffer(size);
+ if (ring->capacity() < (unsigned)size - 1) {
+ fprintf(stderr, "Ring capacity is smaller than expected\n");
+ return 1;
+ }
+
+ if (ring->skip(1)) {
+ fprintf(stderr, "Successfully skipped in empty RingBuffer\n");
+ return 1;
+ }
+
+ char buf[6] = { 'h', 'e', 'l', 'l', '0', '\0' };
+ if (ring->read(1, buf)) {
+ fprintf(stderr, "Successfully read from empty RingBuffer\n");
+ return 1;
+ }
+
+ ring->write(sizeof(buf), buf);
+ ring->skip(1);
+ char buf2[sizeof(buf) - 1];
+ ring->read(sizeof(buf2), buf2);
+ if (strcmp(buf2, buf + 1)) {
+ fprintf(stderr, "Skip failed\n");
+ return 1;
+ }
+
+ ring->reset();
+ if (ring->read_space() != 0) {
+ fprintf(stderr, "Reset RingBuffer is not empty\n");
+ return 1;
+ }
+
+ for (uint32_t i = 0; i < ring->capacity(); ++i) {
+ const char c = 'X';
+ if (ring->write(1, &c) != 1) {
+ fprintf(stderr, "Write failed\n");
+ return 1;
+ }
+ }
+
+ if (ring->write_space() != 0) {
+ fprintf(stderr, "Ring is not full as expected\n");
+ return 1;
+ }
+
+ if (ring->write(1, buf) != 0) {
+ fprintf(stderr, "Successfully wrote to full RingBuffer\n");
+ return 1;
+ }
+
+ if (ring->peek(1, buf2) != 1 || buf2[0] != 'X') {
+ fprintf(stderr, "Failed to read from full RingBuffer\n");
+ return 1;
+ }
+
+ ring->reset();
pthread_t reader_thread;
if (pthread_create(&reader_thread, NULL, reader, NULL)) {