test: Add test for the plugin loader

Fix #8
This commit is contained in:
Olivier Crête 2017-05-21 17:03:48 +02:00 committed by Guillaume Desmottes
parent adca3bf8f7
commit bc3e5b1206
3 changed files with 102 additions and 0 deletions

View file

@ -3,6 +3,7 @@ runtests = files('runtests.py')
tests = [
['Test gst', 'test_gst.py'],
['Test fundamentals', 'test_types.py'],
['Test plugins', 'test_plugin.py'],
]
pluginsdirs = []
@ -25,10 +26,23 @@ if runcmd.returncode() != 0
error('Could not configure testsuite config file.' + runcmd.stderr())
endif
pluginsdirs = []
if gst_dep.type_name() == 'pkgconfig'
pbase = dependency('gstreamer-plugins-base-' + api_version, required : false)
pluginsdirs = [gst_dep.get_pkgconfig_variable('pluginsdir'),
pbase.get_pkgconfig_variable('pluginsdir')]
endif
pypluginsdir = [join_paths (meson.build_root(), 'plugin'), meson.current_source_dir()]
foreach i: tests
test_name = i.get(0)
env = environment()
env.set('GST_OVERRIDE_SRC_PATH', join_paths (meson.current_source_dir(), '..', 'gi', 'overrides'))
env.set('GST_OVERRIDE_BUILD_PATH', join_paths (meson.current_build_dir(), '..', 'gi', 'overrides'))
env.set('GST_PLUGIN_LOADING_WHITELIST', 'gstreamer',
'gst-plugins-base@' + meson.build_root(), 'gst-python@' + meson.build_root())
env.set('GST_PLUGIN_PATH_1_0', meson.build_root(), pluginsdirs + pypluginsdir)
env.set('GST_REGISTRY', join_paths(meson.current_build_dir(), '@0@.registry'.format(test_name)))
test(test_name, python, args: [runtests, i.get(1)], env: env)
endforeach

View file

@ -0,0 +1,46 @@
#!/usr/bin/env python
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
# identity.py
# 2016 Marianna S. Buschle <msb@qtec.com>
#
# Simple identity element in python
#
# You can run the example from the source doing from gst-python/:
#
# $ export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:$PWD/plugin:$PWD/examples/plugins
# $ GST_DEBUG=python:4 gst-launch-1.0 fakesrc num-buffers=10 ! identity_py ! fakesink
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstBase', '1.0')
from gi.repository import Gst, GObject, GstBase
Gst.init(None)
#
# Simple Identity element created entirely in python
#
class Identity(GstBase.BaseTransform):
__gstmetadata__ = ('Identity Python','Transform', \
'Simple identity element written in python', 'Marianna S. Buschle')
__gsttemplates__ = (Gst.PadTemplate.new("src",
Gst.PadDirection.SRC,
Gst.PadPresence.ALWAYS,
Gst.Caps.new_any()),
Gst.PadTemplate.new("sink",
Gst.PadDirection.SINK,
Gst.PadPresence.ALWAYS,
Gst.Caps.new_any()))
def __init__(self):
self.transformed = False
def do_transform_ip(self, buffer):
self.transformed = True
return Gst.FlowReturn.OK
GObject.type_register(Identity)
__gstelementfactory__ = ("test_identity_py", Gst.Rank.NONE, Identity)

42
testsuite/test_plugin.py Normal file
View file

@ -0,0 +1,42 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import overrides_hack
overrides_hack
from common import TestCase, unittest
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
class TestPlugin(TestCase):
def testLoad(self):
Gst.init(None)
p = Gst.parse_launch ("fakesrc ! test_identity_py name=id ! fakesink")
assert p.get_by_name("id").transformed == False
p.set_state(Gst.State.PLAYING)
p.get_state(Gst.CLOCK_TIME_NONE)
p.set_state(Gst.State.NULL)
assert p.get_by_name("id").transformed == True
if __name__ == "__main__":
unittest.main()