2 * Copyright (C) 2011 Stefan Kost <ensonic@users.sf.net>
4 * gstelementfactory.c: Unit test for GstElementFactory
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.
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.
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <gst/check/gstcheck.h>
24 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
27 GST_STATIC_CAPS ("audio/x-raw-int, " "channels = (int) [ 1, 6 ]")
29 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
32 GST_STATIC_CAPS ("audio/x-raw-int, " "channels = (int) [ 1, 6 ]")
36 setup_pad_template (GstElementFactory * factory, GstStaticPadTemplate * tmpl)
38 GstStaticPadTemplate *template;
40 template = g_slice_dup (GstStaticPadTemplate, tmpl);
41 factory->staticpadtemplates = g_list_append (factory->staticpadtemplates,
43 factory->numpadtemplates++;
46 static GstElementFactory *
49 GstPluginFeature *feature;
50 GstElementFactory *factory;
52 feature = g_object_newv (GST_TYPE_ELEMENT_FACTORY, 0, NULL);
53 gst_plugin_feature_set_name (feature, "test");
55 factory = GST_ELEMENT_FACTORY_CAST (feature);
56 factory->details.longname = g_strdup ("test");
57 factory->details.klass = g_strdup ("test");
58 factory->details.description = g_strdup ("test");
59 factory->details.author = g_strdup ("test");
61 setup_pad_template (factory, &sink_template);
62 setup_pad_template (factory, &src_template);
67 /* create a basic factory */
68 GST_START_TEST (test_create)
70 GstElementFactory *factory;
72 factory = setup_factory ();
73 fail_if (factory == NULL);
75 g_object_unref (factory);
80 /* test if the factory can accept some caps */
81 GST_START_TEST (test_can_sink_any_caps)
83 GstElementFactory *factory;
87 factory = setup_factory ();
88 fail_if (factory == NULL);
90 caps = gst_caps_new_simple ("audio/x-raw-int", NULL);
91 fail_if (caps == NULL);
92 res = gst_element_factory_can_sink_any_caps (factory, caps);
94 gst_caps_unref (caps);
96 g_object_unref (factory);
101 /* test if the factory is compabible with some caps */
102 GST_START_TEST (test_can_sink_all_caps)
104 GstElementFactory *factory;
108 factory = setup_factory ();
109 fail_if (factory == NULL);
111 caps = gst_caps_new_simple ("audio/x-raw-int", NULL);
112 fail_if (caps == NULL);
113 res = gst_element_factory_can_sink_all_caps (factory, caps);
115 gst_caps_unref (caps);
117 g_object_unref (factory);
122 /* check if the elementfactory of a class is filled (see #131079) */
123 GST_START_TEST (test_class)
125 GstElementClass *klass;
126 GstElementFactory *factory, *tmp;
129 GST_DEBUG ("finding factory for queue");
130 factory = gst_element_factory_find ("queue");
131 fail_if (factory == NULL);
133 /* it may already be loaded if check is being run with CK_FORK=no */
134 if (!GST_PLUGIN_FEATURE (factory)->loaded) {
135 GST_DEBUG ("getting the type");
136 /* feature is not loaded, should return 0 as the type */
137 type = gst_element_factory_get_element_type (factory);
141 GST_DEBUG ("now loading the plugin");
143 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
145 fail_if (tmp == NULL);
147 gst_object_unref (factory);
150 /* feature is now loaded */
151 type = gst_element_factory_get_element_type (factory);
154 klass = g_type_class_ref (factory->type);
155 fail_if (klass == NULL);
157 GST_DEBUG ("checking the element factory class field");
158 /* and elementfactory is filled in */
159 fail_if (klass->elementfactory == NULL);
160 fail_if (klass->elementfactory != factory);
168 gst_element_factory_suite (void)
170 Suite *s = suite_create ("GstElementFactory");
171 TCase *tc_chain = tcase_create ("element-factory tests");
173 suite_add_tcase (s, tc_chain);
174 tcase_add_test (tc_chain, test_class);
175 tcase_add_test (tc_chain, test_create);
176 tcase_add_test (tc_chain, test_can_sink_any_caps);
177 tcase_add_test (tc_chain, test_can_sink_all_caps);
182 GST_CHECK_MAIN (gst_element_factory);