• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * unit test for GstPlugin
4  *
5  * Copyright 2004 Thomas Vander Stichele <thomas at apestaart dot org>
6  * Copyright 2005 David Schleef <ds@schleef.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <gst/check/gstcheck.h>
28 
29 
30 static gboolean
register_check_elements(GstPlugin * plugin)31 register_check_elements (GstPlugin * plugin)
32 {
33   return TRUE;
34 }
35 
GST_START_TEST(test_register_static)36 GST_START_TEST (test_register_static)
37 {
38   GstPlugin *plugin;
39 
40   fail_unless (gst_plugin_register_static (GST_VERSION_MAJOR,
41           GST_VERSION_MINOR, "more-elements", "more-elements",
42           register_check_elements, VERSION, GST_LICENSE, PACKAGE,
43           GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN));
44 
45   plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
46 
47   gst_object_unref (plugin);
48 }
49 
50 GST_END_TEST;
51 
GST_START_TEST(test_registry)52 GST_START_TEST (test_registry)
53 {
54   GList *list, *g;
55   GstRegistry *registry;
56 
57   registry = gst_registry_get ();
58 
59   list = gst_registry_get_plugin_list (registry);
60   for (g = list; g; g = g->next) {
61     GstPlugin *plugin = GST_PLUGIN (g->data);
62 
63     /* one for the registry, one for the list */
64     GST_DEBUG ("Plugin refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (plugin),
65         gst_plugin_get_name (plugin));
66     ASSERT_OBJECT_REFCOUNT (plugin, "plugin in registry", 2);
67 
68     gst_object_unref (plugin);
69   }
70   g_list_free (list);
71 
72   list = gst_registry_feature_filter (registry, NULL, FALSE, NULL);
73   for (g = list; g; g = g->next) {
74     GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
75 
76     /* one for the registry, one for the list */
77     GST_DEBUG ("Feature refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
78         GST_OBJECT_NAME (feature));
79     gst_object_unref (feature);
80   }
81   g_list_free (list);
82 }
83 
84 GST_END_TEST;
85 
GST_START_TEST(test_load_coreelements)86 GST_START_TEST (test_load_coreelements)
87 {
88   GstPlugin *unloaded_plugin;
89   GstPlugin *loaded_plugin;
90 
91   unloaded_plugin = gst_registry_find_plugin (gst_registry_get (),
92       "coreelements");
93   fail_if (unloaded_plugin == NULL, "Failed to find coreelements plugin");
94   fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 2,
95       "Refcount of unloaded plugin in registry initially should be 2");
96   GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
97 
98   loaded_plugin = gst_plugin_load (unloaded_plugin);
99   fail_if (loaded_plugin == NULL, "Failed to load plugin");
100 
101   if (loaded_plugin != unloaded_plugin) {
102     fail_if (GST_OBJECT_REFCOUNT_VALUE (loaded_plugin) != 2,
103         "Refcount of loaded plugin in registry should be 2");
104     GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (loaded_plugin));
105     fail_if (GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin) != 1,
106         "Refcount of replaced plugin should be 1");
107     GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (unloaded_plugin));
108   }
109 
110   gst_object_unref (unloaded_plugin);
111   gst_object_unref (loaded_plugin);
112 }
113 
114 GST_END_TEST;
115 
GST_START_TEST(test_registry_get_plugin_list)116 GST_START_TEST (test_registry_get_plugin_list)
117 {
118   GList *list;
119   GstPlugin *plugin;
120 
121   plugin = gst_registry_find_plugin (gst_registry_get (), "coreelements");
122   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
123       "Refcount of plugin in registry should be 2");
124 
125   list = gst_registry_get_plugin_list (gst_registry_get ());
126 
127   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
128       "Refcount of plugin in registry+list should be 3");
129 
130   gst_plugin_list_free (list);
131 
132   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
133       "Refcount of plugin in after list free should be 2");
134 
135   gst_object_unref (plugin);
136 }
137 
138 GST_END_TEST;
139 
GST_START_TEST(test_find_plugin)140 GST_START_TEST (test_find_plugin)
141 {
142   GstPlugin *plugin;
143 
144   plugin = gst_registry_find_plugin (gst_registry_get (), "coreelements");
145   fail_if (plugin == NULL, "Failed to find coreelements plugin");
146   ASSERT_OBJECT_REFCOUNT (plugin, "plugin", 2);
147 
148   fail_unless_equals_string (gst_plugin_get_version (plugin), VERSION);
149   fail_unless_equals_string (gst_plugin_get_license (plugin), "LGPL");
150   fail_unless_equals_string (gst_plugin_get_source (plugin), "gstreamer");
151   fail_unless_equals_string (gst_plugin_get_package (plugin), GST_PACKAGE_NAME);
152   fail_unless_equals_string (gst_plugin_get_origin (plugin),
153       GST_PACKAGE_ORIGIN);
154 
155   gst_object_unref (plugin);
156 }
157 
158 GST_END_TEST;
159 
160 
GST_START_TEST(test_find_feature)161 GST_START_TEST (test_find_feature)
162 {
163   GstPluginFeature *feature;
164   GstPlugin *plugin;
165 
166   feature = gst_registry_find_feature (gst_registry_get (),
167       "identity", GST_TYPE_ELEMENT_FACTORY);
168   fail_if (feature == NULL, "Failed to find identity element factory");
169 
170   plugin = gst_plugin_feature_get_plugin (feature);
171   fail_unless (plugin != NULL);
172   fail_unless_equals_string (gst_plugin_get_name (plugin), "coreelements");
173   gst_object_unref (plugin);
174 
175   fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 2,
176       "Refcount of feature should be 2");
177   GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (feature));
178 
179   gst_object_unref (feature);
180 }
181 
182 GST_END_TEST;
183 
GST_START_TEST(test_find_element)184 GST_START_TEST (test_find_element)
185 {
186   GstElementFactory *element_factory;
187 
188   element_factory = gst_element_factory_find ("identity");
189   fail_if (element_factory == NULL, "Failed to find identity element factory");
190 
191   fail_if (GST_OBJECT_REFCOUNT_VALUE (element_factory) != 2,
192       "Refcount of plugin in registry+feature should be 2");
193 
194   gst_object_unref (element_factory);
195 }
196 
197 GST_END_TEST;
198 
199 #if 0
200 guint8 *
201 peek (gpointer data, gint64 offset, guint size)
202 {
203   return NULL;
204 }
205 
206 void
207 suggest (gpointer data, guint probability, const GstCaps * caps)
208 {
209 
210 }
211 
212 GST_START_TEST (test_typefind)
213 {
214   GstPlugin *plugin;
215   GstPluginFeature *feature;
216   GstTypeFind typefind = {
217     peek,
218     suggest,
219     NULL,
220     NULL,
221     GST_PADDING_INIT
222   };
223 
224   plugin = gst_default_registry_find_plugin ("typefindfunctions");
225   fail_if (plugin == NULL, "Failed to find typefind functions");
226   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
227       "Refcount of plugin in registry should be 2");
228   fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
229 
230   feature = gst_registry_find_feature (gst_registry_get (),
231       "audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
232   fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
233   fail_if (feature->plugin != plugin,
234       "Expected identity to be from coreelements plugin");
235 
236   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
237       "Refcount of plugin in registry+feature should be 3");
238 
239   gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
240       &typefind);
241 
242   gst_object_unref (feature->plugin);
243 
244   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 1,
245       "Refcount of plugin in after list free should be 1");
246 
247   gst_object_unref (plugin);
248 }
249 
250 GST_END_TEST;
251 #endif
252 
253 #define gst_default_registry_check_feature_version(name,a,b,c) \
254     gst_registry_check_feature_version(gst_registry_get(),(name),(a),(b),(c))
255 
GST_START_TEST(test_version_checks)256 GST_START_TEST (test_version_checks)
257 {
258   fail_if (gst_default_registry_check_feature_version ("identity",
259           GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
260       "Unexpected version check result");
261 
262   fail_if (gst_default_registry_check_feature_version ("identity",
263           GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
264       "Unexpected version check result");
265 
266   fail_if (gst_default_registry_check_feature_version ("identity",
267           GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
268       "Unexpected version check result");
269 
270   /* If the nano is set, then we expect that X.Y.Z-1.x >= X.Y.Z, so that a
271    * devel plugin is valid against an upcoming release */
272   if (GST_VERSION_NANO > 0) {
273     fail_unless (gst_default_registry_check_feature_version ("identity",
274             GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
275         TRUE, "Unexpected version check result");
276   } else {
277     fail_if (gst_default_registry_check_feature_version ("identity",
278             GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
279         TRUE, "Unexpected version check result");
280   }
281 
282   if (GST_VERSION_MAJOR > 0) {
283     fail_if (gst_default_registry_check_feature_version ("identity",
284             GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
285             GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
286   }
287 
288   if (GST_VERSION_MINOR > 0) {
289     fail_if (gst_default_registry_check_feature_version ("identity",
290             GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
291             GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
292   }
293 
294   if (GST_VERSION_MICRO > 0) {
295     fail_if (gst_default_registry_check_feature_version ("identity",
296             GST_VERSION_MAJOR, GST_VERSION_MINOR,
297             GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
298   }
299 
300   fail_if (gst_default_registry_check_feature_version ("entityid",
301           GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
302       "Unexpected version check result");
303 }
304 
305 GST_END_TEST;
306 
307 static Suite *
gst_plugin_suite(void)308 gst_plugin_suite (void)
309 {
310   Suite *s = suite_create ("GstPlugin");
311   TCase *tc_chain = tcase_create ("general");
312 
313   /* turn off timeout */
314   tcase_set_timeout (tc_chain, 60);
315 
316   suite_add_tcase (s, tc_chain);
317 #ifdef GST_GNUC_CONSTRUCTOR_DEFINED
318   tcase_add_test (tc_chain, test_old_register_static);
319 #endif
320   tcase_add_test (tc_chain, test_register_static);
321   tcase_add_test (tc_chain, test_registry);
322   tcase_add_test (tc_chain, test_load_coreelements);
323   tcase_add_test (tc_chain, test_registry_get_plugin_list);
324   tcase_add_test (tc_chain, test_find_plugin);
325   tcase_add_test (tc_chain, test_find_feature);
326   tcase_add_test (tc_chain, test_find_element);
327   tcase_add_test (tc_chain, test_version_checks);
328   //tcase_add_test (tc_chain, test_typefind);
329 
330   return s;
331 }
332 
333 GST_CHECK_MAIN (gst_plugin);
334