2 # vi:si:et:sw=4:sts=4:ts=4
4 # gst-python - Python bindings for GStreamer
5 # Copyright (C) 2002 David I. Lehn
6 # Copyright (C) 2004 Johan Dahlin
7 # Copyright (C) 2005 Edward Hervey
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 from common import gst, unittest, TestCase
26 class StructureTest(TestCase):
29 self.struct = gst.structure_from_string('video/x-raw-yuv,width=10,foo="bar",pixel-aspect-ratio=1/2,framerate=5/1,boolean=(boolean)true')
32 assert self.struct.get_name() == 'video/x-raw-yuv'
33 self.struct.set_name('foobar')
34 assert self.struct.get_name() == 'foobar'
37 assert self.struct.has_key('width')
38 assert isinstance(self.struct['width'], int)
39 assert self.struct['width'] == 10, self.struct['width']
40 self.struct['width'] = 5
41 assert self.struct.has_key('width')
42 assert isinstance(self.struct['width'], int)
43 assert self.struct['width'] == 5, self.struct['width']
46 assert self.struct.has_key('foo')
47 assert isinstance(self.struct['foo'], unicode)
48 assert self.struct['foo'] == 'bar', self.struct['foo']
49 self.struct['foo'] = 'baz'
50 assert self.struct.has_key('foo')
51 assert isinstance(self.struct['foo'], unicode)
52 assert self.struct['foo'] == 'baz', self.struct['foo']
54 def testBoolean(self):
55 assert self.struct.has_key('boolean')
56 assert isinstance(self.struct['boolean'], bool)
57 assert self.struct['boolean'] == True, self.struct['boolean']
58 self.struct['boolean'] = False
59 assert self.struct.has_key('boolean')
60 assert isinstance(self.struct['boolean'], bool)
61 assert self.struct['boolean'] == False, self.struct['boolean']
63 def testCreateInt(self):
64 self.struct['integer'] = 5
65 assert self.struct.has_key('integer')
66 assert isinstance(self.struct['integer'], int)
67 assert self.struct['integer'] == 5, self.struct['integer']
69 def testGstValue(self):
71 s['fourcc'] = gst.Fourcc('XVID')
72 assert s['fourcc'].fourcc == 'XVID'
73 s['frac'] = gst.Fraction(3,4)
74 assert s['frac'].num == 3
75 assert s['frac'].denom == 4
76 s['fracrange'] = gst.FractionRange(gst.Fraction(0,1),
78 assert s['fracrange'].low.num == 0
79 assert s['fracrange'].low.denom == 1
80 assert s['fracrange'].high.num == 25
81 assert s['fracrange'].high.denom == 3
82 s['intrange'] = gst.IntRange(5,21)
83 assert s['intrange'].low == 5
84 assert s['intrange'].high == 21
85 s['doublerange'] = gst.DoubleRange(6.,21.)
86 assert s['doublerange'].low == 6.
87 assert s['doublerange'].high == 21.
88 s['fixedlist'] = (4, 5, 6)
89 assert isinstance(s['fixedlist'], tuple)
90 assert s['fixedlist'] == (4, 5, 6)
92 assert isinstance(s['list'], list)
93 assert s['list'] == [4, 5, 6]
95 assert isinstance(s['boolean'], bool)
96 assert s['boolean'] == True
98 # finally, some recursive tests
99 s['rflist'] = ([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g'])
100 assert s['rflist'] == ([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g'])
101 s['rlist'] = [([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g']), 'h']
102 assert s['rlist'] == [([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g']), 'h']
104 def testStructureChange(self):
105 assert self.struct['framerate'] == gst.Fraction(5, 1)
106 self.struct['framerate'] = gst.Fraction(10, 1)
107 assert self.struct['framerate'] == gst.Fraction(10, 1)
108 self.struct['pixel-aspect-ratio'] = gst.Fraction(4, 2)
109 assert self.struct['pixel-aspect-ratio'].num == 2
110 assert self.struct['pixel-aspect-ratio'].denom == 1
113 k = self.struct.keys()
115 self.assertEquals(len(k), 5)
116 self.failUnless("width" in k)
117 self.failUnless("foo" in k)
118 self.failUnless("framerate" in k)
119 self.failUnless("pixel-aspect-ratio" in k)
120 self.failUnless("boolean" in k)
122 if __name__ == "__main__":