summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2013-12-10 14:43:39 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2013-12-10 14:43:39 +0100
commit602b25d4af1ad51366ecc6ec5473fa6aadd0f6f0 (patch)
tree397c01bb9771ccd0abdbf2e2e5783b464ff8249d
parent49ba1d25d8c236a5455ba95b33ed26f9c7ea9c6f (diff)
downloadlibuca-602b25d4af1ad51366ecc6ec5473fa6aadd0f6f0.tar.gz
libuca-602b25d4af1ad51366ecc6ec5473fa6aadd0f6f0.tar.bz2
libuca-602b25d4af1ad51366ecc6ec5473fa6aadd0f6f0.tar.xz
libuca-602b25d4af1ad51366ecc6ec5473fa6aadd0f6f0.zip
Add ring buffer test
-rw-r--r--test/test-ring-buffer.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/test-ring-buffer.c b/test/test-ring-buffer.c
new file mode 100644
index 0000000..4872534
--- /dev/null
+++ b/test/test-ring-buffer.c
@@ -0,0 +1,75 @@
+#include <glib.h>
+#include "uca-ring-buffer.h"
+
+
+static void
+test_new_constructor (void)
+{
+ UcaRingBuffer *buffer;
+
+ buffer = g_object_new (UCA_TYPE_RING_BUFFER,
+ "block-size", 512,
+ "num-blocks", 2,
+ NULL);
+
+ g_assert (uca_ring_buffer_get_block_size (buffer) == 512);
+ g_assert (uca_ring_buffer_get_num_blocks (buffer) == 0);
+ g_assert (uca_ring_buffer_get_current_pointer (buffer) != NULL);
+
+ g_object_unref (buffer);
+}
+
+static void
+test_new_func (void)
+{
+ UcaRingBuffer *buffer;
+
+ buffer = uca_ring_buffer_new (512, 2);
+
+ g_assert (uca_ring_buffer_get_block_size (buffer) == 512);
+ g_assert (uca_ring_buffer_get_num_blocks (buffer) == 0);
+ g_assert (uca_ring_buffer_get_current_pointer (buffer) != NULL);
+
+ g_object_unref (buffer);
+}
+
+static void
+test_ring (void)
+{
+ UcaRingBuffer *buffer;
+ guint32 *data;
+
+ buffer = uca_ring_buffer_new (512, 2);
+
+ data = uca_ring_buffer_get_current_pointer (buffer);
+ data[0] = 0xBADF00D;
+ uca_ring_buffer_proceed (buffer);
+
+ data = uca_ring_buffer_get_current_pointer (buffer);
+ data[0] = 0xDEADBEEF;
+ uca_ring_buffer_proceed (buffer);
+
+ g_assert (uca_ring_buffer_get_num_blocks (buffer) == 2);
+
+ data = uca_ring_buffer_get_current_pointer (buffer);
+ g_assert (data[0] == 0xBADF00D);
+
+ data = uca_ring_buffer_get_pointer (buffer, 1);
+ g_assert (data[0] == 0xDEADBEEF);
+
+ uca_ring_buffer_reset (buffer);
+ g_assert (uca_ring_buffer_get_num_blocks (buffer) == 0);
+}
+
+int
+main (int argc, char const* argv[])
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/ringbuffer/new/constructor", test_new_constructor);
+ g_test_add_func ("/ringbuffer/new/func", test_new_func);
+ g_test_add_func ("/ringbuffer/functionality ", test_ring);
+
+ return g_test_run ();
+}