2 # vi:si:et:sw=4:sts=4:ts=4
4 # Copyright (C) 2005 Johan Dahlin
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 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 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 from common import gst, TestCase
23 class IteratorTest(TestCase):
25 def testBinIterateElements(self):
26 pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink")
27 elements = list(pipeline.elements())
28 fakesrc = pipeline.get_by_name("src")
29 fakesink = pipeline.get_by_name("sink")
31 self.assertEqual(len(elements), 2)
32 self.failUnless(fakesrc in elements)
33 self.failUnless(fakesink in elements)
35 pipeline.remove(fakesrc)
36 elements = list(pipeline.elements())
38 self.assertEqual(len(elements), 1)
39 self.failUnless(not fakesrc in pipeline)
41 # XXX : There seems to be a problem about the GType
42 # set in gst_bin_iterated_sorted
44 def testBinIterateSorted(self):
45 pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink")
46 elements = list(pipeline.sorted())
47 fakesrc = pipeline.get_by_name("src")
48 fakesink = pipeline.get_by_name("sink")
50 self.assertEqual(elements[0], fakesink)
51 self.assertEqual(elements[1], fakesrc)
53 def testBinIterateRecurse(self):
54 pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink")
55 elements = list(pipeline.recurse())
56 fakesrc = pipeline.get_by_name("src")
57 fakesink = pipeline.get_by_name("sink")
59 self.assertEqual(elements[0], fakesink)
60 self.assertEqual(elements[1], fakesrc)
62 def testBinIterateSinks(self):
63 pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink")
64 elements = list(pipeline.sinks())
65 fakesrc = pipeline.get_by_name("src")
66 fakesink = pipeline.get_by_name("sink")
68 self.assertEqual(len(elements), 1)
69 self.failUnless(fakesink in elements)
70 self.failUnless(not fakesrc in elements)
73 def testIteratePadsFakeSrc(self):
74 fakesrc = gst.element_factory_make('fakesrc')
75 pads = list(fakesrc.pads())
76 srcpad = fakesrc.get_pad('src')
77 self.assertEqual(len(pads), 1)
78 self.assertEqual(pads[0], srcpad)
79 srcpads = list(fakesrc.src_pads())
80 self.assertEqual(len(srcpads), 1)
81 self.assertEqual(srcpads[0], srcpad)
82 sinkpads = list(fakesrc.sink_pads())
83 self.assertEqual(sinkpads, [])
85 self.assertEqual(len(list(fakesrc)), 1)
87 self.assertEqual(pad, srcpad)
92 def testIteratePadsFakeSink(self):
93 fakesink = gst.element_factory_make('fakesink')
94 pads = list(fakesink.pads())
95 sinkpad = fakesink.get_pad('sink')
96 self.assertEqual(len(pads), 1)
97 self.assertEqual(pads[0], sinkpad)
98 srcpads = list(fakesink.src_pads())
99 self.assertEqual(srcpads, [])
100 sinkpads = list(fakesink.sink_pads())
101 self.assertEqual(len(sinkpads), 1)
102 self.assertEqual(sinkpads[0], sinkpad)
104 self.assertEqual(len(list(fakesink)), 1)
106 self.assertEqual(pad, sinkpad)
111 def testInvalidIterator(self):
112 p = gst.Pad("p", gst.PAD_SRC)
113 # The C function will return NULL, we should
114 # therefore have an exception raised
115 self.assertRaises(TypeError, p.iterate_internal_links)