registry: get rid of gst_default_registry_*() convenience macros
[platform/upstream/gstreamer.git] / tests / check / gst / gstplugin.c
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., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include "config.h"
25
26 #include <gst/check/gstcheck.h>
27
28
29 static gboolean
30 register_check_elements (GstPlugin * plugin)
31 {
32   return TRUE;
33 }
34
35 GST_START_TEST (test_register_static)
36 {
37   GstPlugin *plugin;
38
39   fail_unless (gst_plugin_register_static (GST_VERSION_MAJOR,
40           GST_VERSION_MINOR, "more-elements", "more-elements",
41           register_check_elements, VERSION, GST_LICENSE, PACKAGE,
42           GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN));
43
44   plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
45
46   gst_object_unref (plugin);
47 }
48
49 GST_END_TEST;
50
51 GST_START_TEST (test_registry)
52 {
53   GList *list, *g;
54   GstRegistry *registry;
55
56   registry = gst_registry_get ();
57
58   list = gst_registry_get_plugin_list (registry);
59   for (g = list; g; g = g->next) {
60     GstPlugin *plugin = GST_PLUGIN (g->data);
61
62     /* one for the registry, one for the list */
63     GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (plugin),
64         plugin->desc.name);
65     ASSERT_OBJECT_REFCOUNT (plugin, "plugin in registry", 2);
66
67     gst_object_unref (plugin);
68   }
69   g_list_free (list);
70
71   list = gst_registry_feature_filter (registry, NULL, FALSE, NULL);
72   for (g = list; g; g = g->next) {
73     GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
74
75     /* one for the registry, one for the list */
76     GST_DEBUG ("refcount %d %s", GST_OBJECT_REFCOUNT_VALUE (feature),
77         GST_OBJECT_NAME (feature));
78     ASSERT_OBJECT_REFCOUNT (feature, "feature in registry", 2);
79     gst_object_unref (feature);
80   }
81   g_list_free (list);
82 }
83
84 GST_END_TEST;
85
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
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
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 (plugin->desc.version, VERSION);
149   fail_unless_equals_string (plugin->desc.license, "LGPL");
150   fail_unless_equals_string (plugin->desc.source, "gstreamer");
151   fail_unless_equals_string (plugin->desc.package, GST_PACKAGE_NAME);
152   fail_unless_equals_string (plugin->desc.origin, GST_PACKAGE_ORIGIN);
153
154   gst_object_unref (plugin);
155 }
156
157 GST_END_TEST;
158
159
160 GST_START_TEST (test_find_feature)
161 {
162   GstPluginFeature *feature;
163
164   feature = gst_registry_find_feature (gst_registry_get (),
165       "identity", GST_TYPE_ELEMENT_FACTORY);
166   fail_if (feature == NULL, "Failed to find identity element factory");
167   fail_if (strcmp (feature->plugin_name, "coreelements"),
168       "Expected identity to be from coreelements plugin");
169
170   fail_if (GST_OBJECT_REFCOUNT_VALUE (feature) != 2,
171       "Refcount of feature should be 2");
172   GST_DEBUG ("refcount %d", GST_OBJECT_REFCOUNT_VALUE (feature));
173
174   gst_object_unref (feature);
175 }
176
177 GST_END_TEST;
178
179 GST_START_TEST (test_find_element)
180 {
181   GstElementFactory *element_factory;
182
183   element_factory = gst_element_factory_find ("identity");
184   fail_if (element_factory == NULL, "Failed to find identity element factory");
185
186   fail_if (GST_OBJECT_REFCOUNT_VALUE (element_factory) != 2,
187       "Refcount of plugin in registry+feature should be 2");
188
189   gst_object_unref (element_factory);
190 }
191
192 GST_END_TEST;
193
194 #if 0
195 guint8 *
196 peek (gpointer data, gint64 offset, guint size)
197 {
198   return NULL;
199 }
200
201 void
202 suggest (gpointer data, guint probability, const GstCaps * caps)
203 {
204
205 }
206
207 GST_START_TEST (test_typefind)
208 {
209   GstPlugin *plugin;
210   GstPluginFeature *feature;
211   GstTypeFind typefind = {
212     peek,
213     suggest,
214     NULL,
215     NULL,
216     GST_PADDING_INIT
217   };
218
219   plugin = gst_default_registry_find_plugin ("typefindfunctions");
220   fail_if (plugin == NULL, "Failed to find typefind functions");
221   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 2,
222       "Refcount of plugin in registry should be 2");
223   fail_if (gst_plugin_is_loaded (plugin), "Expected plugin to be unloaded");
224
225   feature = gst_registry_find_feature (gst_registry_get (),
226       "audio/x-au", GST_TYPE_TYPE_FIND_FACTORY);
227   fail_if (feature == NULL, "Failed to find audio/x-aw typefind factory");
228   fail_if (feature->plugin != plugin,
229       "Expected identity to be from coreelements plugin");
230
231   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 3,
232       "Refcount of plugin in registry+feature should be 3");
233
234   gst_type_find_factory_call_function (GST_TYPE_FIND_FACTORY (feature),
235       &typefind);
236
237   gst_object_unref (feature->plugin);
238
239   fail_if (GST_OBJECT_REFCOUNT_VALUE (plugin) != 1,
240       "Refcount of plugin in after list free should be 1");
241
242   gst_object_unref (plugin);
243 }
244
245 GST_END_TEST;
246 #endif
247
248 #define gst_default_registry_check_feature_version(name,a,b,c) \
249     gst_registry_check_feature_version(gst_registry_get(),(name),(a),(b),(c))
250
251 GST_START_TEST (test_version_checks)
252 {
253   fail_if (gst_default_registry_check_feature_version ("identity",
254           GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == FALSE,
255       "Unexpected version check result");
256
257   fail_if (gst_default_registry_check_feature_version ("identity",
258           GST_VERSION_MAJOR + 1, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
259       "Unexpected version check result");
260
261   fail_if (gst_default_registry_check_feature_version ("identity",
262           GST_VERSION_MAJOR, GST_VERSION_MINOR + 1, GST_VERSION_MICRO) == TRUE,
263       "Unexpected version check result");
264
265   /* If the nano is set, then we expect that X.Y.Z-1.x >= X.Y.Z, so that a
266    * devel plugin is valid against an upcoming release */
267   if (GST_VERSION_NANO > 0) {
268     fail_unless (gst_default_registry_check_feature_version ("identity",
269             GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
270         TRUE, "Unexpected version check result");
271   } else {
272     fail_if (gst_default_registry_check_feature_version ("identity",
273             GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO + 1) ==
274         TRUE, "Unexpected version check result");
275   }
276
277   if (GST_VERSION_MAJOR > 0) {
278     fail_if (gst_default_registry_check_feature_version ("identity",
279             GST_VERSION_MAJOR - 1, GST_VERSION_MINOR,
280             GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
281   }
282
283   if (GST_VERSION_MINOR > 0) {
284     fail_if (gst_default_registry_check_feature_version ("identity",
285             GST_VERSION_MAJOR, GST_VERSION_MINOR - 1,
286             GST_VERSION_MICRO) == FALSE, "Unexpected version check result");
287   }
288
289   if (GST_VERSION_MICRO > 0) {
290     fail_if (gst_default_registry_check_feature_version ("identity",
291             GST_VERSION_MAJOR, GST_VERSION_MINOR,
292             GST_VERSION_MICRO - 1) == FALSE, "Unexpected version check result");
293   }
294
295   fail_if (gst_default_registry_check_feature_version ("entityid",
296           GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO) == TRUE,
297       "Unexpected version check result");
298 }
299
300 GST_END_TEST;
301
302 static Suite *
303 gst_plugin_suite (void)
304 {
305   Suite *s = suite_create ("GstPlugin");
306   TCase *tc_chain = tcase_create ("general");
307
308   /* turn off timeout */
309   tcase_set_timeout (tc_chain, 60);
310
311   suite_add_tcase (s, tc_chain);
312 #ifdef GST_GNUC_CONSTRUCTOR_DEFINED
313   tcase_add_test (tc_chain, test_old_register_static);
314 #endif
315   tcase_add_test (tc_chain, test_register_static);
316   tcase_add_test (tc_chain, test_registry);
317   tcase_add_test (tc_chain, test_load_coreelements);
318   tcase_add_test (tc_chain, test_registry_get_plugin_list);
319   tcase_add_test (tc_chain, test_find_plugin);
320   tcase_add_test (tc_chain, test_find_feature);
321   tcase_add_test (tc_chain, test_find_element);
322   tcase_add_test (tc_chain, test_version_checks);
323   //tcase_add_test (tc_chain, test_typefind);
324
325   return s;
326 }
327
328 GST_CHECK_MAIN (gst_plugin);