From 680188cc2a73f5f907215efed6a68f7f21c60ea4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 19 Aug 2008 18:33:12 +0000 Subject: More thread-safe ringbuffer. Add test for size/full/empty queue functions. git-svn-id: http://svn.drobilla.net/lad/raul@1446 a436a847-0d15-0410-975c-d299462d15a1 --- tests/queue_test.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/queue_test.cpp') diff --git a/tests/queue_test.cpp b/tests/queue_test.cpp index 7a1d44b..1e92104 100644 --- a/tests/queue_test.cpp +++ b/tests/queue_test.cpp @@ -120,6 +120,33 @@ int main() { unsigned long total_processed = 0; + cout << "Testing size" << endl; + for (unsigned i=0; i < queue.capacity(); ++i) { + queue.push(i); + if (i == queue.capacity()-1) { + if (!queue.full()) { + cerr << "ERROR: Should be full at " << i + << " (size " << queue.capacity() << ")" << endl; + return -1; + } + } else { + if (queue.full()) { + cerr << "ERROR: Prematurely full at " << i + << " (size " << queue.capacity() << ")" << endl; + return -1; + } + } + } + + for (unsigned i=0; i < queue.capacity(); ++i) + queue.pop(); + + if (!queue.empty()) { + cerr << "ERROR: Should be empty" << endl; + return -1; + } + + cout << "Testing concurrent reading/writing" << endl; vector writers(NUM_WRITERS, new WriteThread()); struct termios orig_term; -- cgit v1.2.1