summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2014-02-14 14:28:59 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2014-02-14 14:34:47 +0100
commitf15d21389a81f8df36b00113aed5c81d27143861 (patch)
treec7a6247afd73254c202a8ccbb1e93bb43287b315 /test
parentdf1ae54168a7dda396050077f14fed33c4882c47 (diff)
downloadlibuca-f15d21389a81f8df36b00113aed5c81d27143861.tar.gz
libuca-f15d21389a81f8df36b00113aed5c81d27143861.tar.bz2
libuca-f15d21389a81f8df36b00113aed5c81d27143861.tar.xz
libuca-f15d21389a81f8df36b00113aed5c81d27143861.zip
Use read-write ring buffer
Diffstat (limited to 'test')
-rw-r--r--test/test-ring-buffer.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/test/test-ring-buffer.c b/test/test-ring-buffer.c
index 2026408..02bf1eb 100644
--- a/test/test-ring-buffer.c
+++ b/test/test-ring-buffer.c
@@ -14,7 +14,7 @@ test_new_constructor (void)
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_assert (uca_ring_buffer_get_write_pointer (buffer) != NULL);
g_object_unref (buffer);
}
@@ -28,7 +28,7 @@ test_new_func (void)
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_assert (uca_ring_buffer_get_write_pointer (buffer) != NULL);
g_object_unref (buffer);
}
@@ -41,26 +41,47 @@ test_ring (void)
buffer = uca_ring_buffer_new (512, 2);
- data = uca_ring_buffer_get_current_pointer (buffer);
+ data = uca_ring_buffer_get_write_pointer (buffer);
data[0] = 0xBADF00D;
- uca_ring_buffer_proceed (buffer);
- data = uca_ring_buffer_get_current_pointer (buffer);
+ g_assert (uca_ring_buffer_available (buffer));
+ g_assert (uca_ring_buffer_get_num_blocks (buffer) == 1);
+
+ data = uca_ring_buffer_get_write_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);
+ data = uca_ring_buffer_get_read_pointer (buffer);
g_assert (data[0] == 0xBADF00D);
- data = uca_ring_buffer_get_pointer (buffer, 1);
+ data = uca_ring_buffer_get_read_pointer (buffer);
g_assert (data[0] == 0xDEADBEEF);
+ g_assert (!uca_ring_buffer_available (buffer));
+
uca_ring_buffer_reset (buffer);
g_assert (uca_ring_buffer_get_num_blocks (buffer) == 0);
}
+static void
+test_overwrite (void)
+{
+ UcaRingBuffer *buffer;
+ guint32 *data;
+
+ buffer = uca_ring_buffer_new (512, 1);
+
+ data = uca_ring_buffer_get_write_pointer (buffer);
+ data[0] = 0xBADF00D;
+
+ data = uca_ring_buffer_get_write_pointer (buffer);
+ data[0] = 0xDEADBEEF;
+
+ data = uca_ring_buffer_get_read_pointer (buffer);
+ g_assert (data[0] == 0xDEADBEEF);
+}
+
int
main (int argc, char *argv[])
{
@@ -70,6 +91,7 @@ main (int argc, char *argv[])
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);
+ g_test_add_func ("/ringbuffer/overwrite ", test_overwrite);
return g_test_run ();
}