2 # vi:si:et:sw=4:sts=4:ts=4
4 # gst-python - Python bindings for GStreamer
5 # Copyright (C) 2009 Edward Hervey
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.
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.
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
21 from common import gobject, gst, unittest, TestCase
23 class AdapterTest(TestCase):
27 self.adapter = gst.Adapter()
31 TestCase.tearDown(self)
33 def testAvailable(self):
35 self.assertEquals(self.adapter.available(), 0)
36 self.assertEquals(self.adapter.available_fast(), 0)
38 # let's give it 4 bytes
39 self.adapter.push(gst.Buffer("1234"))
40 self.assertEquals(self.adapter.available_fast(), 4)
42 # let's give it another 5 bytes
43 self.adapter.push(gst.Buffer("56789"))
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)
50 self.adapter.push(gst.Buffer("0123456789"))
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")
58 # it's still 10 bytes big
59 self.assertEquals(self.adapter.available(), 10)
61 # if we try to peek more than what's available, we'll have None
62 self.assertEquals(self.adapter.peek(11), None)
65 self.adapter.push(gst.Buffer("0123456789"))
66 self.assertEquals(self.adapter.available(), 10)
69 self.assertEquals(self.adapter.available(), 5)
71 # it flushed the first 5 bytes
72 self.assertEquals(self.adapter.peek(5), "56789")
75 self.assertEquals(self.adapter.available(), 0)
78 self.adapter.push(gst.Buffer("0123456789"))
79 self.assertEquals(self.adapter.available(), 10)
81 s = self.adapter.take(5)
82 self.assertEquals(s, "01234")
83 self.assertEquals(self.adapter.available(), 5)