1 /* GStreamer zbar element unit test
3 * Copyright (C) 2010 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
23 GST_START_TEST (test_still_image)
25 GstMessage *zbar_msg = NULL;
26 GstElement *pipeline, *src, *dec, *csp, *zbar, *sink;
27 const gchar *type, *symbol;
31 pipeline = gst_pipeline_new ("pipeline");
33 src = gst_element_factory_make ("filesrc", NULL);
34 dec = gst_element_factory_make ("pngdec", NULL);
35 csp = gst_element_factory_make ("ffmpegcolorspace", NULL);
36 zbar = gst_element_factory_make ("zbar", NULL);
37 sink = gst_element_factory_make ("fakesink", NULL);
39 path = g_build_filename (GST_TEST_FILES_PATH, "barcode.png", NULL);
40 GST_LOG ("reading file '%s'", path);
41 g_object_set (src, "location", path, NULL);
44 gst_bin_add_many (GST_BIN (pipeline), src, dec, csp, zbar, sink, NULL);
45 fail_unless (gst_element_link_many (src, dec, csp, zbar, sink, NULL));
47 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_PLAYING),
48 GST_STATE_CHANGE_ASYNC);
53 msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline), -1,
54 GST_MESSAGE_ELEMENT | GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
56 GST_INFO ("message: %" GST_PTR_FORMAT, msg);
58 fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
60 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
61 gst_message_unref (msg);
65 if (GST_MESSAGE_SRC (msg) == GST_OBJECT_CAST (zbar) && zbar_msg == NULL) {
68 gst_message_unref (msg);
72 fail_unless (zbar_msg != NULL);
73 fail_unless (gst_structure_has_name (zbar_msg->structure, "barcode"));
74 fail_unless (gst_structure_has_field (zbar_msg->structure, "timestamp"));
75 fail_unless (gst_structure_has_field (zbar_msg->structure, "type"));
76 fail_unless (gst_structure_has_field (zbar_msg->structure, "symbol"));
77 fail_unless (gst_structure_has_field (zbar_msg->structure, "quality"));
78 fail_unless (gst_structure_get_int (zbar_msg->structure, "quality", &qual));
79 fail_unless (qual >= 90);
80 type = gst_structure_get_string (zbar_msg->structure, "type");
81 fail_unless_equals_string (type, "EAN-13");
82 symbol = gst_structure_get_string (zbar_msg->structure, "symbol");
83 fail_unless_equals_string (symbol, "9876543210128");
85 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
86 GST_STATE_CHANGE_SUCCESS);
88 gst_object_unref (pipeline);
89 gst_message_unref (zbar_msg);
97 Suite *s = suite_create ("zbar");
98 TCase *tc_chain = tcase_create ("general");
100 suite_add_tcase (s, tc_chain);
102 if (!gst_default_registry_check_feature_version ("pngdec", 0, 10, 25)) {
103 GST_INFO ("Skipping test, pngdec either not available or too old");
105 tcase_add_test (tc_chain, test_still_image);
111 GST_CHECK_MAIN (zbar);