mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
Add some tests
Original commit message from CVS: Add some tests
This commit is contained in:
parent
da7eb714c3
commit
8a810ece62
6 changed files with 168 additions and 54 deletions
12
testsuite/common.py
Normal file
12
testsuite/common.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, '..')
|
||||
|
||||
# Load GST and make sure we load it from the current build
|
||||
import gst
|
||||
assert sys.modules.has_key('_gst')
|
||||
assert os.path.basename(sys.modules['_gst'].__file__), \
|
||||
os.path.join('..', 'gst', 'libs')
|
|
@ -2,35 +2,54 @@
|
|||
#
|
||||
# testsuite for gstreamer.Element
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, '..')
|
||||
from common import gst, unittest
|
||||
|
||||
import gst
|
||||
class ElementTest(unittest.TestCase):
|
||||
name = 'fakesink'
|
||||
alias = 'sink'
|
||||
|
||||
def testBadConstruct(self):
|
||||
self.assertRaises(TypeError, gst.Element)
|
||||
self.assertRaises(TypeError, gst.Element, None)
|
||||
|
||||
def fail(message):
|
||||
'print reason for failing and leave'
|
||||
print "FAILED: %s" % message
|
||||
sys.exit(-1)
|
||||
def testGoodConstructor(self):
|
||||
element = gst.Element(self.name, self.alias)
|
||||
assert element
|
||||
assert element.get_name() == self.alias
|
||||
|
||||
class FakeSinkTest(ElementTest):
|
||||
FAKESINK_STATE_ERROR_NONE = "0"
|
||||
FAKESINK_STATE_ERROR_NULL_READY, = "1"
|
||||
FAKESINK_STATE_ERROR_READY_PAUSED, = "2"
|
||||
FAKESINK_STATE_ERROR_PAUSED_PLAYING = "3"
|
||||
FAKESINK_STATE_ERROR_PLAYING_PAUSED = "4"
|
||||
FAKESINK_STATE_ERROR_PAUSED_READY = "5"
|
||||
FAKESINK_STATE_ERROR_READY_NULL = "6"
|
||||
|
||||
# create an element we know exists
|
||||
src = gst.Element("fakesrc", "source")
|
||||
if not src:
|
||||
fail("Can't create fakesrc Element")
|
||||
name = 'fakesink'
|
||||
alias = 'sink'
|
||||
def setUp(self):
|
||||
self.element = gst.Element('fakesink', 'sink')
|
||||
|
||||
# create an element we know doesn't exist
|
||||
nope = None
|
||||
result = 0
|
||||
try:
|
||||
nope = gst.Element("idontexist", "none")
|
||||
except RuntimeError: result = 1
|
||||
if result == 0:
|
||||
fail("creating an unexistant element didn't generate a RuntimeError")
|
||||
def testStateError(self):
|
||||
self.element.set_property('state-error',
|
||||
self.FAKESINK_STATE_ERROR_NULL_READY)
|
||||
def error_cb(element, source, pointer, None):
|
||||
assert isinstance(element, gst.Element)
|
||||
assert element == self.element
|
||||
assert isinstance(source, gst.Element)
|
||||
assert source == self.element
|
||||
return False
|
||||
|
||||
self.element.connect('error', error_cb)
|
||||
self.element.set_state(gst.STATE_READY)
|
||||
|
||||
# create a sink
|
||||
sink = gst.Element("fakesink", "sink")
|
||||
|
||||
# link
|
||||
if not src.link(sink):
|
||||
fail("could not link")
|
||||
|
||||
sys.exit(0)
|
||||
class NonExistentTest(ElementTest):
|
||||
name = 'this-element-does-not-exist'
|
||||
alias = 'no-alias'
|
||||
|
||||
def testGoodConstructor(self):
|
||||
self.assertRaises(RuntimeError, gst.Element, self.name, self.alias)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
26
testsuite/pipeline.py
Normal file
26
testsuite/pipeline.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from common import gst, unittest
|
||||
|
||||
class PipelineTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.pipeline = gst.Pipeline('test-pipeline')
|
||||
|
||||
source = gst.Element('fakesrc', 'source')
|
||||
source.set_property('num-buffers', 5)
|
||||
sink = gst.Element('fakesink', 'sink')
|
||||
self.pipeline.add_many(source, sink)
|
||||
gst.element_link_many(source, sink)
|
||||
|
||||
def testRun(self):
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_NULL)
|
||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_PLAYING)
|
||||
|
||||
while self.pipeline.iterate():
|
||||
pass
|
||||
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_PAUSED)
|
||||
self.pipeline.set_state(gst.STATE_NULL)
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_NULL)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
12
testsuite/runtests.py
Normal file
12
testsuite/runtests.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
from unittest import TestLoader, TextTestRunner
|
||||
from types import ClassType
|
||||
|
||||
loader = TestLoader()
|
||||
testRunner = TextTestRunner()
|
||||
|
||||
for name in ('element', 'pipeline'):
|
||||
print 'Testing', name
|
||||
tests = loader.loadTestsFromName(name)
|
||||
testRunner.run(tests)
|
|
@ -2,35 +2,54 @@
|
|||
#
|
||||
# testsuite for gstreamer.Element
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, '..')
|
||||
from common import gst, unittest
|
||||
|
||||
import gst
|
||||
class ElementTest(unittest.TestCase):
|
||||
name = 'fakesink'
|
||||
alias = 'sink'
|
||||
|
||||
def testBadConstruct(self):
|
||||
self.assertRaises(TypeError, gst.Element)
|
||||
self.assertRaises(TypeError, gst.Element, None)
|
||||
|
||||
def fail(message):
|
||||
'print reason for failing and leave'
|
||||
print "FAILED: %s" % message
|
||||
sys.exit(-1)
|
||||
def testGoodConstructor(self):
|
||||
element = gst.Element(self.name, self.alias)
|
||||
assert element
|
||||
assert element.get_name() == self.alias
|
||||
|
||||
class FakeSinkTest(ElementTest):
|
||||
FAKESINK_STATE_ERROR_NONE = "0"
|
||||
FAKESINK_STATE_ERROR_NULL_READY, = "1"
|
||||
FAKESINK_STATE_ERROR_READY_PAUSED, = "2"
|
||||
FAKESINK_STATE_ERROR_PAUSED_PLAYING = "3"
|
||||
FAKESINK_STATE_ERROR_PLAYING_PAUSED = "4"
|
||||
FAKESINK_STATE_ERROR_PAUSED_READY = "5"
|
||||
FAKESINK_STATE_ERROR_READY_NULL = "6"
|
||||
|
||||
# create an element we know exists
|
||||
src = gst.Element("fakesrc", "source")
|
||||
if not src:
|
||||
fail("Can't create fakesrc Element")
|
||||
name = 'fakesink'
|
||||
alias = 'sink'
|
||||
def setUp(self):
|
||||
self.element = gst.Element('fakesink', 'sink')
|
||||
|
||||
# create an element we know doesn't exist
|
||||
nope = None
|
||||
result = 0
|
||||
try:
|
||||
nope = gst.Element("idontexist", "none")
|
||||
except RuntimeError: result = 1
|
||||
if result == 0:
|
||||
fail("creating an unexistant element didn't generate a RuntimeError")
|
||||
def testStateError(self):
|
||||
self.element.set_property('state-error',
|
||||
self.FAKESINK_STATE_ERROR_NULL_READY)
|
||||
def error_cb(element, source, pointer, None):
|
||||
assert isinstance(element, gst.Element)
|
||||
assert element == self.element
|
||||
assert isinstance(source, gst.Element)
|
||||
assert source == self.element
|
||||
return False
|
||||
|
||||
self.element.connect('error', error_cb)
|
||||
self.element.set_state(gst.STATE_READY)
|
||||
|
||||
# create a sink
|
||||
sink = gst.Element("fakesink", "sink")
|
||||
|
||||
# link
|
||||
if not src.link(sink):
|
||||
fail("could not link")
|
||||
|
||||
sys.exit(0)
|
||||
class NonExistentTest(ElementTest):
|
||||
name = 'this-element-does-not-exist'
|
||||
alias = 'no-alias'
|
||||
|
||||
def testGoodConstructor(self):
|
||||
self.assertRaises(RuntimeError, gst.Element, self.name, self.alias)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
26
testsuite/test_pipeline.py
Normal file
26
testsuite/test_pipeline.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from common import gst, unittest
|
||||
|
||||
class PipelineTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.pipeline = gst.Pipeline('test-pipeline')
|
||||
|
||||
source = gst.Element('fakesrc', 'source')
|
||||
source.set_property('num-buffers', 5)
|
||||
sink = gst.Element('fakesink', 'sink')
|
||||
self.pipeline.add_many(source, sink)
|
||||
gst.element_link_many(source, sink)
|
||||
|
||||
def testRun(self):
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_NULL)
|
||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_PLAYING)
|
||||
|
||||
while self.pipeline.iterate():
|
||||
pass
|
||||
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_PAUSED)
|
||||
self.pipeline.set_state(gst.STATE_NULL)
|
||||
self.assertEqual(self.pipeline.get_state(), gst.STATE_NULL)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in a new issue