summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim.muller@collabora.co.uk>2010-11-03 00:04:27 +0000
committerTim-Philipp Müller <tim.muller@collabora.co.uk>2010-11-05 00:23:45 +0000
commitc2504170787d4cafa557cbc887bf72881f866ffb (patch)
tree536a0519fd09a9eb7392ed067404c0a44e5b13f8
parent8402211bac1cba8e56e1f703c2f8c54d3b38bc0a (diff)
tests: add very simple zbar unit test
Not valgrind clean yet (could be zbar's fault though).
-rw-r--r--configure.ac1
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/check/Makefile.am13
-rw-r--r--tests/check/elements/.gitignore1
-rw-r--r--tests/check/elements/zbar.c111
-rw-r--r--tests/files/Makefile.am2
-rw-r--r--tests/files/barcode.pngbin0 -> 1182 bytes
7 files changed, 128 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index d5f73d6d2..991d83176 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1782,6 +1782,7 @@ sys/winks/Makefile
sys/winscreencap/Makefile
tests/Makefile
tests/check/Makefile
+tests/files/Makefile
tests/examples/Makefile
tests/examples/camerabin/Makefile
tests/examples/directfb/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 022b8d507..9e3a51fae 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,11 +10,6 @@ else
SUBDIRS_EXAMPLES =
endif
-SUBDIRS = icles \
- $(SUBDIRS_CHECK) \
- $(SUBDIRS_EXAMPLES)
-
-DIST_SUBDIRS = icles \
- check \
- examples
+SUBDIRS = $(SUBDIRS_CHECK) $(SUBDIRS_EXAMPLES) files icles
+DIST_SUBDIRS = check examples files icles
diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am
index f8ace4edd..fc0cae62a 100644
--- a/tests/check/Makefile.am
+++ b/tests/check/Makefile.am
@@ -1,6 +1,7 @@
include $(top_srcdir)/common/check.mak
CHECK_REGISTRY = $(top_builddir)/tests/check/test-registry.reg
+TEST_FILES_DIRECTORY = $(top_srcdir)/tests/files
GST_TOOLS_DIR = $(top_builddir)/tools
@@ -105,10 +106,16 @@ else
check_orc =
endif
+if USE_ZBAR
+check_zbar = elements/zbar
+else
+check_zbar =
+endif
VALGRIND_TO_FIX = \
elements/mpeg2enc \
- elements/mplex
+ elements/mplex \
+ elements/zbar
# valgrind testing
VALGRIND_TESTS_DISABLE = \
@@ -155,6 +162,7 @@ check_PROGRAMS = \
elements/rtpmux \
elements/valve \
$(check_vp8) \
+ $(check_zbar) \
$(check_orc) \
pipelines/tagschecking
@@ -162,7 +170,8 @@ noinst_HEADERS = elements/mxfdemux.h
TESTS = $(check_PROGRAMS)
-AM_CFLAGS = $(GST_CHECK_CFLAGS) $(GST_OPTION_CFLAGS)
+AM_CFLAGS = $(GST_CHECK_CFLAGS) $(GST_OPTION_CFLAGS) \
+ -DGST_TEST_FILES_PATH="\"$(TEST_FILES_DIRECTORY)\""
LDADD = $(GST_CHECK_LIBS)
elements_camerabin_CFLAGS = \
diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore
index d3c29b0b5..7c1133db4 100644
--- a/tests/check/elements/.gitignore
+++ b/tests/check/elements/.gitignore
@@ -38,3 +38,4 @@ y4menc
valve
vp8dec
vp8enc
+zbar
diff --git a/tests/check/elements/zbar.c b/tests/check/elements/zbar.c
new file mode 100644
index 000000000..e202c78c0
--- /dev/null
+++ b/tests/check/elements/zbar.c
@@ -0,0 +1,111 @@
+/* GStreamer zbar element unit test
+ *
+ * Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <gst/check/gstcheck.h>
+
+GST_START_TEST (test_still_image)
+{
+ GstMessage *zbar_msg = NULL;
+ GstElement *pipeline, *src, *dec, *csp, *zbar, *sink;
+ const gchar *type, *symbol;
+ gchar *path;
+ int qual;
+
+ pipeline = gst_pipeline_new ("pipeline");
+
+ src = gst_element_factory_make ("filesrc", NULL);
+ dec = gst_element_factory_make ("pngdec", NULL);
+ csp = gst_element_factory_make ("ffmpegcolorspace", NULL);
+ zbar = gst_element_factory_make ("zbar", NULL);
+ sink = gst_element_factory_make ("fakesink", NULL);
+
+ path = g_build_filename (GST_TEST_FILES_PATH, "barcode.png", NULL);
+ GST_LOG ("reading file '%s'", path);
+ g_object_set (src, "location", path, NULL);
+ g_free (path);
+
+ gst_bin_add_many (GST_BIN (pipeline), src, dec, csp, zbar, sink, NULL);
+ fail_unless (gst_element_link_many (src, dec, csp, zbar, sink, NULL));
+
+ fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
+ GST_STATE_CHANGE_ASYNC);
+
+ do {
+ GstMessage *msg;
+
+ msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline), -1,
+ GST_MESSAGE_ELEMENT | GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
+
+ GST_INFO ("message: %" GST_PTR_FORMAT, msg);
+
+ fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
+
+ if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
+ gst_message_unref (msg);
+ break;
+ }
+
+ if (GST_MESSAGE_SRC (msg) == GST_OBJECT_CAST (zbar) && zbar_msg == NULL) {
+ zbar_msg = msg;
+ } else {
+ gst_message_unref (msg);
+ }
+ } while (1);
+
+ fail_unless (zbar_msg != NULL);
+ fail_unless (gst_structure_has_name (zbar_msg->structure, "barcode"));
+ fail_unless (gst_structure_has_field (zbar_msg->structure, "timestamp"));
+ fail_unless (gst_structure_has_field (zbar_msg->structure, "type"));
+ fail_unless (gst_structure_has_field (zbar_msg->structure, "symbol"));
+ fail_unless (gst_structure_has_field (zbar_msg->structure, "quality"));
+ fail_unless (gst_structure_get_int (zbar_msg->structure, "quality", &qual));
+ fail_unless (qual >= 90);
+ type = gst_structure_get_string (zbar_msg->structure, "type");
+ fail_unless_equals_string (type, "EAN-13");
+ symbol = gst_structure_get_string (zbar_msg->structure, "symbol");
+ fail_unless_equals_string (symbol, "9876543210128");
+
+ fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
+ GST_STATE_CHANGE_SUCCESS);
+
+ gst_object_unref (pipeline);
+ gst_message_unref (zbar_msg);
+}
+
+GST_END_TEST;
+
+static Suite *
+zbar_suite (void)
+{
+ Suite *s = suite_create ("zbar");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+
+ if (!gst_default_registry_check_feature_version ("pngdec", 0, 10, 25)) {
+ GST_INFO ("Skipping test, pngdec either not available or too old");
+ } else {
+ tcase_add_test (tc_chain, test_still_image);
+ }
+
+ return s;
+}
+
+GST_CHECK_MAIN (zbar);
diff --git a/tests/files/Makefile.am b/tests/files/Makefile.am
new file mode 100644
index 000000000..2cf379830
--- /dev/null
+++ b/tests/files/Makefile.am
@@ -0,0 +1,2 @@
+EXTRA_DIST = \
+ barcode.png
diff --git a/tests/files/barcode.png b/tests/files/barcode.png
new file mode 100644
index 000000000..72846ce39
--- /dev/null
+++ b/tests/files/barcode.png
Binary files differ