def testSubtract(self): self.doSubtract( gst.Caps ("some/mime, _int = [ 1, 2 ], list = { \"A\", \"B\", \"C\" }"), gst.Caps ("some/mime, _int = 1, list = \"A\"")) self.doSubtract( gst.Caps ("some/mime, _double = (double) 1.0; other/mime, _int = { 1, 2 }"), gst.Caps ("some/mime, _double = (double) 1.0"))
def setUp(self): TestCase.setUp(self) self.caps = gst.caps_from_string('video/x-raw-yuv,width=10,framerate=5/1;video/x-raw-rgb,width=15,framerate=10/1') self.assertEquals(self.caps.__refcount__, 1) self.structure = self.caps[0] self.any = gst.Caps("ANY") self.assertEquals(self.any.__refcount__, 1) self.empty = gst.Caps() self.assertEquals(self.empty.__refcount__, 1)
def testCapsConstructFromString(self): caps = gst.Caps('video/x-raw-yuv,width=10') assert isinstance(caps, gst.Caps) assert len(caps) == 1 assert isinstance(caps[0], gst.Structure) assert caps[0].get_name() == 'video/x-raw-yuv' assert isinstance(caps[0]['width'], int) assert caps[0]['width'] == 10
def testCapsConstructFromStructure(self): struct = gst.structure_from_string('video/x-raw-yuv,width=10,framerate=[0/1, 25/3]') caps = gst.Caps(struct) assert isinstance(caps, gst.Caps) assert len(caps) == 1 assert isinstance(caps[0], gst.Structure) assert caps[0].get_name() == 'video/x-raw-yuv' assert isinstance(caps[0]['width'], int) assert caps[0]['width'] == 10 assert isinstance(caps[0]['framerate'], gst.FractionRange)
def testNoneValue(self): caps = gst.Caps("foo") def invalid_assignment(): caps[0]["bar"] = None self.assertRaises(TypeError, invalid_assignment) def invalid_set_value(): caps[0].set_value("bar", None) self.assertRaises(TypeError, invalid_set_value)
def testCapsContainingMiniObjects(self): # buffer contains hex encoding of ascii 'abcd' caps = gst.Caps("video/x-raw-yuv, buf=(buffer)61626364") buf = caps[0]['buf'] assert isinstance(buf, gst.Buffer) assert buf.data == "abcd" buf = gst.Buffer("1234") caps[0]['buf2'] = buf buf2 = caps[0]['buf2'] assert buf2 == buf
def testCapsConstructFromStructures(self): struct1 = gst.structure_from_string('video/x-raw-yuv,width=10') struct2 = gst.structure_from_string('video/x-raw-rgb,height=20.0') caps = gst.Caps(struct1, struct2) assert isinstance(caps, gst.Caps) assert len(caps) == 2 struct = caps[0] assert isinstance(struct, gst.Structure), struct assert struct.get_name() == 'video/x-raw-yuv', struct.get_name() assert struct.has_key('width') assert isinstance(struct['width'], int) assert struct['width'] == 10 struct = caps[1] assert isinstance(struct, gst.Structure), struct assert struct.get_name() == 'video/x-raw-rgb', struct.get_name() assert struct.has_key('height') assert isinstance(struct['height'], float) assert struct['height'] == 20.0
def application_awesome_type_find(typefind, arg1, arg2): self.failUnlessEqual(arg1, 'arg1') self.failUnlessEqual(arg2, 'arg2') data = typefind.peek(0, 5) self.failUnless(data == '', 'peek out of length??') data = typefind.peek(0, 0) self.failUnless(data == '', '0 peek??') data = typefind.peek(3, 1) self.failUnless(data == 'M') data = typefind.peek(0, 4) self.failUnless(data == 'AWSM') typefind.suggest(gst.TYPE_FIND_MAXIMUM, gst.Caps('application/awesome'))
def testTypeFind(self): def application_awesome_type_find(typefind, arg1, arg2): self.failUnlessEqual(arg1, 'arg1') self.failUnlessEqual(arg2, 'arg2') data = typefind.peek(0, 5) self.failUnless(data == '', 'peek out of length??') data = typefind.peek(0, 0) self.failUnless(data == '', '0 peek??') data = typefind.peek(3, 1) self.failUnless(data == 'M') data = typefind.peek(0, 4) self.failUnless(data == 'AWSM') typefind.suggest(gst.TYPE_FIND_MAXIMUM, gst.Caps('application/awesome')) res = gst.type_find_register('application/awesome', gst.RANK_PRIMARY, application_awesome_type_find, ['.twi'], gst.Caps('application/awesome'), 'arg1', 'arg2') self.failUnless(res, 'type_find_register failed') factory = None factories = gst.type_find_factory_get_list() for typefind_factory in factories: if typefind_factory.get_name() == 'application/awesome': factory = typefind_factory break self.failUnless(factory is not None) obj = gst.Pad('src', gst.PAD_SRC) buffer = gst.Buffer('AWSM') caps, probability = gst.type_find_helper_for_buffer(obj, buffer) self.failUnlessEqual(str(caps), 'application/awesome') self.failUnlessEqual(probability, gst.TYPE_FIND_MAXIMUM)
def testCapsConstructEmpty(self): caps = gst.Caps() assert isinstance(caps, gst.Caps)
def testFilters(self): name = 'video/x-raw-yuv' filtercaps = gst.Caps(*[struct for struct in self.caps if struct.get_name() == name]) intersection = self.caps & 'video/x-raw-yuv' assert filtercaps == intersection
def testTrueFalse(self): 'test that comparisons using caps work the intended way' assert self.any # not empty even though it has no structures assert not self.empty assert not gst.Caps('EMPTY') # also empty assert gst.Caps('your/mom')
def testCapsReferenceStructs(self): 'test that shows why it\'s not a good idea to use structures by reference' caps = gst.Caps('hi/mom,width=0') structure = caps[0] del caps assert structure['width'] == 0