Commit 8a810ece authored by Johan Dahlin's avatar Johan Dahlin

Add some tests

Original commit message from CVS:
Add some tests
parent da7eb714
#
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, '..')
import gst
def fail(message):
'print reason for failing and leave'
print "FAILED: %s" % message
sys.exit(-1)
# create an element we know exists
src = gst.Element("fakesrc", "source")
if not src:
fail("Can't create fakesrc Element")
# 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")
# create a sink
sink = gst.Element("fakesink", "sink")
# link
if not src.link(sink):
fail("could not link")
sys.exit(0)
from common import gst, unittest
class ElementTest(unittest.TestCase):
name = 'fakesink'
alias = 'sink'
def testBadConstruct(self):
self.assertRaises(TypeError, gst.Element)
self.assertRaises(TypeError, gst.Element, None)
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"
name = 'fakesink'
alias = 'sink'
def setUp(self):
self.element = gst.Element('fakesink', 'sink')
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)
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()
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()
#!/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, '..')
import gst
def fail(message):
'print reason for failing and leave'
print "FAILED: %s" % message
sys.exit(-1)
# create an element we know exists
src = gst.Element("fakesrc", "source")
if not src:
fail("Can't create fakesrc Element")
# 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")
# create a sink
sink = gst.Element("fakesink", "sink")
# link
if not src.link(sink):
fail("could not link")
sys.exit(0)
from common import gst, unittest
class ElementTest(unittest.TestCase):
name = 'fakesink'
alias = 'sink'
def testBadConstruct(self):
self.assertRaises(TypeError, gst.Element)
self.assertRaises(TypeError, gst.Element, None)
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"
name = 'fakesink'
alias = 'sink'
def setUp(self):
self.element = gst.Element('fakesink', 'sink')
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)
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()
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment