summaryrefslogtreecommitdiff
path: root/testsuite/test_typefind.py
blob: f3a5e93872efbb92991c4ff79f02dab195e970b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2008 Alessandro Decina
#
# 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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA

from common import gst, unittest, TestCase, pygobject_2_13

import sys
import time

class TypeFindTest(TestCase):
    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)