2005-09-01 10:36:07 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
#
|
|
|
|
# gst-python - Python bindings for GStreamer
|
|
|
|
# Copyright (C) 2002 David I. Lehn
|
|
|
|
# Copyright (C) 2004 Johan Dahlin
|
|
|
|
# Copyright (C) 2005 Edward Hervey
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
2013-12-12 11:20:12 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-09-01 10:36:07 +00:00
|
|
|
|
2004-08-05 14:25:58 +00:00
|
|
|
import sys
|
2005-10-14 16:26:17 +00:00
|
|
|
from common import gst, unittest, TestCase
|
2004-08-05 14:25:58 +00:00
|
|
|
|
2005-10-14 16:26:17 +00:00
|
|
|
class StructureTest(TestCase):
|
2004-08-06 18:14:30 +00:00
|
|
|
def setUp(self):
|
2005-10-14 16:26:17 +00:00
|
|
|
TestCase.setUp(self)
|
2007-03-01 14:21:52 +00:00
|
|
|
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')
|
2004-08-06 18:14:30 +00:00
|
|
|
|
|
|
|
def testName(self):
|
|
|
|
assert self.struct.get_name() == 'video/x-raw-yuv'
|
|
|
|
self.struct.set_name('foobar')
|
|
|
|
assert self.struct.get_name() == 'foobar'
|
|
|
|
|
|
|
|
def testInt(self):
|
|
|
|
assert self.struct.has_key('width')
|
|
|
|
assert isinstance(self.struct['width'], int)
|
2005-09-01 15:50:46 +00:00
|
|
|
assert self.struct['width'] == 10, self.struct['width']
|
|
|
|
self.struct['width'] = 5
|
2004-08-06 18:14:30 +00:00
|
|
|
assert self.struct.has_key('width')
|
|
|
|
assert isinstance(self.struct['width'], int)
|
2005-09-01 15:50:46 +00:00
|
|
|
assert self.struct['width'] == 5, self.struct['width']
|
2004-08-06 14:18:28 +00:00
|
|
|
|
2004-08-06 18:14:30 +00:00
|
|
|
def testString(self):
|
|
|
|
assert self.struct.has_key('foo')
|
2009-06-01 17:08:47 +00:00
|
|
|
assert isinstance(self.struct['foo'], unicode)
|
2005-09-01 15:50:46 +00:00
|
|
|
assert self.struct['foo'] == 'bar', self.struct['foo']
|
|
|
|
self.struct['foo'] = 'baz'
|
2004-08-06 18:14:30 +00:00
|
|
|
assert self.struct.has_key('foo')
|
2009-06-01 17:08:47 +00:00
|
|
|
assert isinstance(self.struct['foo'], unicode)
|
2005-09-01 15:50:46 +00:00
|
|
|
assert self.struct['foo'] == 'baz', self.struct['foo']
|
2004-08-06 18:14:30 +00:00
|
|
|
|
2005-09-29 09:58:25 +00:00
|
|
|
def testBoolean(self):
|
|
|
|
assert self.struct.has_key('boolean')
|
|
|
|
assert isinstance(self.struct['boolean'], bool)
|
|
|
|
assert self.struct['boolean'] == True, self.struct['boolean']
|
|
|
|
self.struct['boolean'] = False
|
|
|
|
assert self.struct.has_key('boolean')
|
|
|
|
assert isinstance(self.struct['boolean'], bool)
|
|
|
|
assert self.struct['boolean'] == False, self.struct['boolean']
|
|
|
|
|
2004-08-06 18:14:30 +00:00
|
|
|
def testCreateInt(self):
|
2005-09-01 15:50:46 +00:00
|
|
|
self.struct['integer'] = 5
|
2004-08-06 18:14:30 +00:00
|
|
|
assert self.struct.has_key('integer')
|
|
|
|
assert isinstance(self.struct['integer'], int)
|
2005-09-01 15:50:46 +00:00
|
|
|
assert self.struct['integer'] == 5, self.struct['integer']
|
2004-08-06 18:14:30 +00:00
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
def testGstValue(self):
|
|
|
|
s = self.struct
|
|
|
|
s['fourcc'] = gst.Fourcc('XVID')
|
|
|
|
assert s['fourcc'].fourcc == 'XVID'
|
|
|
|
s['frac'] = gst.Fraction(3,4)
|
|
|
|
assert s['frac'].num == 3
|
|
|
|
assert s['frac'].denom == 4
|
2006-01-08 12:26:35 +00:00
|
|
|
s['fracrange'] = gst.FractionRange(gst.Fraction(0,1),
|
|
|
|
gst.Fraction(25,3))
|
|
|
|
assert s['fracrange'].low.num == 0
|
|
|
|
assert s['fracrange'].low.denom == 1
|
|
|
|
assert s['fracrange'].high.num == 25
|
|
|
|
assert s['fracrange'].high.denom == 3
|
2005-06-17 10:59:47 +00:00
|
|
|
s['intrange'] = gst.IntRange(5,21)
|
|
|
|
assert s['intrange'].low == 5
|
|
|
|
assert s['intrange'].high == 21
|
|
|
|
s['doublerange'] = gst.DoubleRange(6.,21.)
|
|
|
|
assert s['doublerange'].low == 6.
|
|
|
|
assert s['doublerange'].high == 21.
|
|
|
|
s['fixedlist'] = (4, 5, 6)
|
|
|
|
assert isinstance(s['fixedlist'], tuple)
|
|
|
|
assert s['fixedlist'] == (4, 5, 6)
|
|
|
|
s['list'] = [4, 5, 6]
|
|
|
|
assert isinstance(s['list'], list)
|
|
|
|
assert s['list'] == [4, 5, 6]
|
2005-09-29 09:58:25 +00:00
|
|
|
s['boolean'] = True
|
|
|
|
assert isinstance(s['boolean'], bool)
|
|
|
|
assert s['boolean'] == True
|
2004-08-30 10:42:36 +00:00
|
|
|
|
2005-06-17 10:59:47 +00:00
|
|
|
# finally, some recursive tests
|
|
|
|
s['rflist'] = ([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g'])
|
|
|
|
assert s['rflist'] == ([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g'])
|
|
|
|
s['rlist'] = [([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g']), 'h']
|
|
|
|
assert s['rlist'] == [([(['a', 'b'], ['c', 'd']),'e'], ['f', 'g']), 'h']
|
|
|
|
|
2004-08-06 18:14:30 +00:00
|
|
|
def testStructureChange(self):
|
2007-03-01 14:21:52 +00:00
|
|
|
assert self.struct['framerate'] == gst.Fraction(5, 1)
|
|
|
|
self.struct['framerate'] = gst.Fraction(10, 1)
|
|
|
|
assert self.struct['framerate'] == gst.Fraction(10, 1)
|
2005-06-17 10:59:47 +00:00
|
|
|
self.struct['pixel-aspect-ratio'] = gst.Fraction(4, 2)
|
|
|
|
assert self.struct['pixel-aspect-ratio'].num == 2
|
|
|
|
assert self.struct['pixel-aspect-ratio'].denom == 1
|
2004-08-05 14:25:58 +00:00
|
|
|
|
2005-09-20 14:50:54 +00:00
|
|
|
def testKeys(self):
|
|
|
|
k = self.struct.keys()
|
|
|
|
self.failUnless(k)
|
2005-09-29 09:58:25 +00:00
|
|
|
self.assertEquals(len(k), 5)
|
2005-09-20 14:50:54 +00:00
|
|
|
self.failUnless("width" in k)
|
|
|
|
self.failUnless("foo" in k)
|
|
|
|
self.failUnless("framerate" in k)
|
|
|
|
self.failUnless("pixel-aspect-ratio" in k)
|
2005-09-29 09:58:25 +00:00
|
|
|
self.failUnless("boolean" in k)
|
2005-09-20 14:50:54 +00:00
|
|
|
|
2004-08-05 14:25:58 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|