• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * unit test for videoconvert
3  *
4  * Copyright (C) 2006-2012 Tim-Philipp Müller <tim centricular net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25 
26 #ifdef HAVE_VALGRIND
27 # include <valgrind/valgrind.h>
28 #endif
29 
30 #include <gst/check/gstcheck.h>
31 #include <gst/video/video.h>
32 
33 static guint
get_num_formats(void)34 get_num_formats (void)
35 {
36   guint i = 2;
37 
38   while (gst_video_format_to_string ((GstVideoFormat) i) != NULL)
39     ++i;
40 
41   return i;
42 }
43 
44 static void
check_pad_template(GstPadTemplate * tmpl)45 check_pad_template (GstPadTemplate * tmpl)
46 {
47   const GValue *list_val, *fmt_val;
48   GstStructure *s;
49   gboolean *formats_supported;
50   GstCaps *caps;
51   guint i, num_formats;
52 
53   num_formats = get_num_formats ();
54   formats_supported = g_new0 (gboolean, num_formats);
55 
56   caps = gst_pad_template_get_caps (tmpl);
57 
58   /* If this fails, we need to update this unit test */
59   fail_unless_equals_int (gst_caps_get_size (caps), 2);
60   /* Remove the ANY caps features structure */
61   caps = gst_caps_truncate (caps);
62   s = gst_caps_get_structure (caps, 0);
63 
64   fail_unless (gst_structure_has_name (s, "video/x-raw"));
65 
66   list_val = gst_structure_get_value (s, "format");
67   fail_unless (list_val != NULL);
68   /* If this fails, we need to update this unit test */
69   fail_unless (GST_VALUE_HOLDS_LIST (list_val));
70 
71   for (i = 0; i < gst_value_list_get_size (list_val); ++i) {
72     GstVideoFormat fmt;
73     const gchar *fmt_str;
74 
75     fmt_val = gst_value_list_get_value (list_val, i);
76     fail_unless (G_VALUE_HOLDS_STRING (fmt_val));
77     fmt_str = g_value_get_string (fmt_val);
78     GST_LOG ("format string: '%s'", fmt_str);
79     fmt = gst_video_format_from_string (fmt_str);
80     fail_unless (fmt != GST_VIDEO_FORMAT_UNKNOWN);
81     formats_supported[(guint) fmt] = TRUE;
82   }
83 
84   gst_caps_unref (caps);
85 
86   for (i = 2; i < num_formats; ++i) {
87     if (!formats_supported[i]) {
88       g_error ("videoconvert doesn't support format '%s'",
89           gst_video_format_to_string ((GstVideoFormat) i));
90     }
91   }
92 
93   g_free (formats_supported);
94 }
95 
GST_START_TEST(test_template_formats)96 GST_START_TEST (test_template_formats)
97 {
98   GstElementFactory *f;
99   GstPadTemplate *t;
100   const GList *pad_templates;
101 
102   f = gst_element_factory_find ("videoconvert");
103   fail_unless (f != NULL);
104 
105   pad_templates = gst_element_factory_get_static_pad_templates (f);
106   fail_unless_equals_int (g_list_length ((GList *) pad_templates), 2);
107 
108   t = gst_static_pad_template_get (pad_templates->data);
109   check_pad_template (GST_PAD_TEMPLATE (t));
110   gst_object_unref (t);
111   t = gst_static_pad_template_get (pad_templates->next->data);
112   check_pad_template (GST_PAD_TEMPLATE (t));
113   gst_object_unref (t);
114 
115   gst_object_unref (f);
116 }
117 
118 GST_END_TEST;
119 
120 static Suite *
videoconvert_suite(void)121 videoconvert_suite (void)
122 {
123   Suite *s = suite_create ("videoconvert");
124   TCase *tc_chain = tcase_create ("general");
125 
126   suite_add_tcase (s, tc_chain);
127 
128   tcase_add_test (tc_chain, test_template_formats);
129 
130   return s;
131 }
132 
133 GST_CHECK_MAIN (videoconvert);
134