61f948d283cd3370072fe547ceff28dd7e5eb9b0
[platform/upstream/gstreamer.git] / testsuite / bins / interface.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/gst.h>
21
22 /* tests if gst_bin_get_(all_)by_interface works */
23
24 gint 
25 main (gint argc, gchar *argv[])
26 {
27   GstBin *bin, *bin2;
28   GList *list;
29   GstElement *filesrc;
30   
31   gst_init (&argc, &argv);
32
33   bin = GST_BIN (gst_bin_new (NULL));
34   g_assert (bin);
35
36   filesrc = gst_element_factory_make ("filesrc", NULL);
37   g_assert (filesrc);
38   g_assert (GST_IS_URI_HANDLER (filesrc));
39   gst_bin_add (bin, filesrc);
40   
41   g_assert (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
42   list = gst_bin_get_all_by_interface (bin, GST_TYPE_URI_HANDLER);
43   g_assert (g_list_length (list) == 1);
44   g_assert (list->data == (gpointer) filesrc);
45   g_list_free (list);
46   
47   gst_bin_add_many (bin, 
48       gst_element_factory_make ("identity", NULL),
49       gst_element_factory_make ("identity", NULL), 
50       gst_element_factory_make ("identity", NULL),
51       NULL);
52   g_assert (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
53   list = gst_bin_get_all_by_interface (bin, GST_TYPE_URI_HANDLER);
54   g_assert (g_list_length (list) == 1);
55   g_assert (list->data == (gpointer) filesrc);
56   g_list_free (list);
57
58   bin2 = bin;
59   bin = GST_BIN (gst_bin_new (NULL));
60   g_assert (bin);
61   gst_bin_add_many (bin,
62       gst_element_factory_make ("identity", NULL),
63       gst_element_factory_make ("identity", NULL),
64       GST_ELEMENT (bin2),
65       gst_element_factory_make ("identity", NULL),
66       NULL);
67   g_assert (gst_bin_get_by_interface (bin, GST_TYPE_URI_HANDLER) == filesrc);
68   list = gst_bin_get_all_by_interface (bin, GST_TYPE_URI_HANDLER);
69   g_assert (g_list_length (list) == 1);
70   g_assert (list->data == (gpointer) filesrc);
71   g_list_free (list);
72
73   gst_bin_add (bin, gst_element_factory_make ("filesrc", NULL));
74   gst_bin_add (bin2, gst_element_factory_make ("filesrc", NULL));
75   list = gst_bin_get_all_by_interface (bin, GST_TYPE_URI_HANDLER);
76   g_assert (g_list_length (list) == 3);
77   g_list_free (list);
78
79   g_object_unref (bin);
80   return 0;
81 }