[aravis] buffer: add unit tests.



commit 89e7b9154ca63084b6468861f8d7624b46b7598d
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed Feb 16 21:53:53 2011 +0100

    buffer: add unit tests.

 tests/.gitignore  |    1 +
 tests/Makefile.am |    5 ++-
 tests/buffer.c    |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 1 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index 2c99942..501e18d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,6 @@
 evaluator
 genicam
+buffer
 fake
 arv-test
 arv-genicam-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b1f82d3..deca643 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,13 +23,16 @@ arv_zip_test_LDADD = $(test_progs_ldadd)
 arv_camera_test_SOURCES = arvcameratest.c
 arv_camera_test_LDADD = $(test_progs_ldadd)
 
-TEST_PROGS += evaluator fake
+TEST_PROGS += evaluator buffer fake
 
 noinst_PROGRAMS += $(TEST_PROGS)
 
 evaluator_SOURCES = evaluator.c
 evaluator_LDADD = $(test_progs_ldadd)
 
+buffer_SOURCES = buffer.c
+buffer_LDADD = $(test_progs_ldadd)
+
 fake_SOURCES = fake.c
 fake_CFLAGS = -DGENICAM_FILENAME="\"$(top_srcdir)/src/arv-fake-camera.xml\""
 fake_LDADD = $(test_progs_ldadd)
diff --git a/tests/buffer.c b/tests/buffer.c
new file mode 100644
index 0000000..3a419fb
--- /dev/null
+++ b/tests/buffer.c
@@ -0,0 +1,85 @@
+#include <glib.h>
+#include <arv.h>
+
+static void
+simple_buffer_test (void)
+{
+	ArvBuffer *buffer;
+
+	buffer = arv_buffer_new (1024, NULL);
+
+	g_assert (ARV_IS_BUFFER (buffer));
+	g_assert (buffer->data != NULL);
+	g_assert (buffer->size == 1024);
+
+	g_assert (buffer->user_data == NULL);
+	g_assert (buffer->user_data_destroy_func == NULL);
+
+	g_assert (buffer->status == ARV_BUFFER_STATUS_CLEARED);
+
+	g_object_unref (buffer);
+}
+
+static void
+preallocated_buffer_test (void)
+{
+	ArvBuffer *buffer;
+	void *data = g_malloc (1024);
+
+	buffer = arv_buffer_new (1024, data);
+	g_assert (ARV_IS_BUFFER (buffer));
+	g_assert (buffer->data == data);
+
+	g_assert (buffer->user_data == NULL);
+	g_assert (buffer->user_data_destroy_func == NULL);
+
+	g_assert (buffer->status == ARV_BUFFER_STATUS_CLEARED);
+
+	g_object_unref (buffer);
+}
+
+static void
+full_buffer_destroy_func (void *data)
+{
+	*((int *) data) = 4321;
+}
+
+static void
+full_buffer_test (void)
+{
+	ArvBuffer *buffer;
+	int value = 1234;
+
+
+	buffer = arv_buffer_new_full (1024, NULL, &value, full_buffer_destroy_func);
+
+	g_assert (ARV_IS_BUFFER (buffer));
+	g_assert (buffer->data != NULL);
+	g_assert (buffer->size == 1024);
+
+	g_assert (buffer->user_data == &value);
+	g_assert (buffer->user_data_destroy_func == full_buffer_destroy_func);
+
+	g_assert (buffer->status == ARV_BUFFER_STATUS_CLEARED);
+
+	g_object_unref (buffer);
+
+	g_assert (value == 4321);
+}
+
+int
+main (int argc, char *argv[])
+{
+	int i;
+
+	g_test_init (&argc, &argv, NULL);
+
+	g_type_init ();
+
+	g_test_add_func ("/buffer/simple-buffer", simple_buffer_test);
+	g_test_add_func ("/buffer/preallocated-buffer", preallocated_buffer_test);
+	g_test_add_func ("/buffer/full-buffer", full_buffer_test);
+
+	return g_test_run();
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]