From bc3e5b1206e3df44f8e3a371a0486a6889e5f32e Mon Sep 17 00:00:00 2001 From: Olivier CrĂȘte Date: Sun, 21 May 2017 17:03:48 +0200 Subject: test: Add test for the plugin loader Fix #8 --- testsuite/meson.build | 14 ++++++++++++++ testsuite/python/identity.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ testsuite/test_plugin.py | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 testsuite/python/identity.py create mode 100644 testsuite/test_plugin.py diff --git a/testsuite/meson.build b/testsuite/meson.build index 4fb573b..3d0e993 100644 --- a/testsuite/meson.build +++ b/testsuite/meson.build @@ -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 diff --git a/testsuite/python/identity.py b/testsuite/python/identity.py new file mode 100644 index 0000000..a591669 --- /dev/null +++ b/testsuite/python/identity.py @@ -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 +# +# 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) diff --git a/testsuite/test_plugin.py b/testsuite/test_plugin.py new file mode 100644 index 0000000..fb513d1 --- /dev/null +++ b/testsuite/test_plugin.py @@ -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() -- cgit v1.2.3