Merging gst-python
[platform/upstream/gstreamer.git] / subprojects / gst-python / testsuite / old / test_adapter.py
1 # -*- Mode: Python -*-
2 # vi:si:et:sw=4:sts=4:ts=4
3 #
4 # gst-python - Python bindings for GStreamer
5 # Copyright (C) 2009 Edward Hervey
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
20
21 from common import gobject, gst, unittest, TestCase
22
23 class AdapterTest(TestCase):
24
25     def setUp(self):
26         TestCase.setUp(self)
27         self.adapter = gst.Adapter()
28
29     def tearDown(self):
30         self.adapter = None
31         TestCase.tearDown(self)
32
33     def testAvailable(self):
34         # starts empty
35         self.assertEquals(self.adapter.available(), 0)
36         self.assertEquals(self.adapter.available_fast(), 0)
37
38         # let's give it 4 bytes
39         self.adapter.push(gst.Buffer("1234"))
40         self.assertEquals(self.adapter.available_fast(), 4)
41
42         # let's give it another 5 bytes
43         self.adapter.push(gst.Buffer("56789"))
44         # we now have 9 bytes
45         self.assertEquals(self.adapter.available(), 9)
46         # but can only do a fast take of 4 bytes (the first buffer)
47         self.assertEquals(self.adapter.available_fast(), 4)
48
49     def testPeek(self):
50         self.adapter.push(gst.Buffer("0123456789"))
51
52         # let's peek at 5 bytes
53         b = self.adapter.peek(5)
54         # it can return more than 5 bytes
55         self.assert_(len(b) >= 5)
56         self.assertEquals(b, "01234")
57
58         # it's still 10 bytes big
59         self.assertEquals(self.adapter.available(), 10)
60
61         # if we try to peek more than what's available, we'll have None
62         self.assertEquals(self.adapter.peek(11), None)
63
64     def testFlush(self):
65         self.adapter.push(gst.Buffer("0123456789"))
66         self.assertEquals(self.adapter.available(), 10)
67
68         self.adapter.flush(5)
69         self.assertEquals(self.adapter.available(), 5)
70
71         # it flushed the first 5 bytes
72         self.assertEquals(self.adapter.peek(5), "56789")
73
74         self.adapter.flush(5)
75         self.assertEquals(self.adapter.available(), 0)
76
77     def testTake(self):
78         self.adapter.push(gst.Buffer("0123456789"))
79         self.assertEquals(self.adapter.available(), 10)
80
81         s = self.adapter.take(5)
82         self.assertEquals(s, "01234")
83         self.assertEquals(self.adapter.available(), 5)