2004-05-03 16:17:38 +00:00
|
|
|
import sys
|
2004-12-14 16:53:09 +00:00
|
|
|
from common import gobject, gst, unittest
|
2004-05-03 16:17:38 +00:00
|
|
|
|
|
|
|
class BufferTest(unittest.TestCase):
|
2004-05-04 14:20:28 +00:00
|
|
|
def testBufferBuffer(self):
|
|
|
|
buf = gst.Buffer('test')
|
|
|
|
assert str(buffer(buf)) == 'test'
|
|
|
|
|
|
|
|
def testBufferStr(self):
|
|
|
|
buffer = gst.Buffer('test')
|
|
|
|
assert str(buffer) == 'test'
|
|
|
|
|
|
|
|
def testBufferBadConstructor(self):
|
|
|
|
self.assertRaises(TypeError, gst.Buffer, 'test', 0)
|
|
|
|
|
|
|
|
def testBufferStrNull(self):
|
|
|
|
test_string = 't\0e\0s\0t\0'
|
|
|
|
buffer = gst.Buffer(test_string)
|
|
|
|
assert str(buffer) == test_string
|
|
|
|
|
|
|
|
def testBufferSize(self):
|
|
|
|
test_string = 'a little string'
|
|
|
|
buffer = gst.Buffer(test_string)
|
|
|
|
assert len(buffer) == len(test_string)
|
2004-06-21 08:38:23 +00:00
|
|
|
#assert hasattr(buffer, 'size')
|
|
|
|
#assert buffer.size == len(buffer)
|
2004-05-03 16:17:38 +00:00
|
|
|
|
2004-05-04 14:20:28 +00:00
|
|
|
def testBufferMaxSize(self):
|
|
|
|
buffer = gst.Buffer(buffer_size=16)
|
|
|
|
assert hasattr(buffer, 'maxsize')
|
|
|
|
assert buffer.maxsize == 16
|
|
|
|
|
|
|
|
def testBufferCreateSub(self):
|
|
|
|
s = ''
|
|
|
|
for i in range(64):
|
|
|
|
s += '%02d' % i
|
|
|
|
|
|
|
|
buffer = gst.Buffer(s)
|
|
|
|
assert len(buffer) == 128
|
|
|
|
|
|
|
|
sub = buffer.create_sub(16, 16)
|
|
|
|
assert sub.maxsize == 16
|
|
|
|
assert sub.offset == -1, sub.offset
|
|
|
|
|
|
|
|
def testBufferMerge(self):
|
|
|
|
buffer1 = gst.Buffer('foo')
|
|
|
|
buffer2 = gst.Buffer('bar')
|
|
|
|
|
|
|
|
merged_buffer = buffer1.merge(buffer2)
|
|
|
|
assert str(merged_buffer) == 'foobar'
|
|
|
|
|
|
|
|
def testBufferJoin(self):
|
|
|
|
buffer1 = gst.Buffer('foo')
|
|
|
|
buffer2 = gst.Buffer('bar')
|
|
|
|
|
|
|
|
joined_buffer = buffer1.merge(buffer2)
|
|
|
|
assert str(joined_buffer) == 'foobar'
|
|
|
|
|
|
|
|
def testBufferSpan(self):
|
|
|
|
buffer1 = gst.Buffer('foo')
|
|
|
|
buffer2 = gst.Buffer('bar')
|
|
|
|
|
|
|
|
spaned_buffer = buffer1.span(0L, buffer2, 6L)
|
|
|
|
assert str(spaned_buffer) == 'foobar'
|
|
|
|
|
2004-06-09 13:40:27 +00:00
|
|
|
def testBufferFlagIsSet(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
# Off by default
|
|
|
|
assert not buffer.flag_is_set(gst.BUFFER_READONLY)
|
|
|
|
|
|
|
|
# Try switching on and off
|
|
|
|
buffer.flag_set(gst.BUFFER_READONLY)
|
|
|
|
assert buffer.flag_is_set(gst.BUFFER_READONLY)
|
|
|
|
buffer.flag_unset(gst.BUFFER_READONLY)
|
|
|
|
assert not buffer.flag_is_set(gst.BUFFER_READONLY)
|
|
|
|
|
|
|
|
# Try switching on and off
|
|
|
|
buffer.flag_set(gst.BUFFER_IN_CAPS)
|
|
|
|
assert buffer.flag_is_set(gst.BUFFER_IN_CAPS)
|
|
|
|
buffer.flag_unset(gst.BUFFER_IN_CAPS)
|
|
|
|
assert not buffer.flag_is_set(gst.BUFFER_IN_CAPS)
|
|
|
|
|
2004-12-14 16:53:09 +00:00
|
|
|
def testAttrType(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "data_type")
|
|
|
|
# XXX: Expose this in gobject
|
|
|
|
#assert isinstance(buffer.data_type, gobject.GType)
|
|
|
|
assert buffer.data_type == buffer.__gtype__
|
|
|
|
|
|
|
|
def testAttrFlags(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "flags")
|
|
|
|
assert isinstance(buffer.flags, int)
|
|
|
|
|
|
|
|
def testAttrTimestamp(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "timestamp")
|
|
|
|
assert isinstance(buffer.timestamp, int)
|
|
|
|
|
|
|
|
assert buffer.timestamp == -1
|
|
|
|
buffer.timestamp = 0
|
|
|
|
assert buffer.timestamp == 0
|
|
|
|
|
2004-05-03 16:17:38 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|