diff --git a/.travis-run.sh b/.travis-run.sh
index e07b88b..03ad9d6 100755
--- a/.travis-run.sh
+++ b/.travis-run.sh
@@ -1,5 +1,19 @@
#! /bin/bash -ex
+./autogen.sh --prefix=/usr || {
+ printf "Failed to do autogen!!!\n"
+ exit -1
+}
+make clean
+make || {
+ printf "make of gst-switch failed!!!\n"
+ exit -1
+}
+sudo make install || {
+ printf "make install of gst-switch failed!!!\n"
+ exit -1
+}
+
cd python-api
case $TEST in
diff --git a/.travis-setup.sh b/.travis-setup.sh
index 729d9b2..378760e 100644
--- a/.travis-setup.sh
+++ b/.travis-setup.sh
@@ -1,153 +1,26 @@
#! /bin/bash -ex
-sudo apt-get update
+# Update / upgrade everything
+sudo apt-get -y update && sudo apt-get -y upgrade
+
+# gst-switch compile stuff
+sudo apt-get -y install build-essential dh-autoreconf
+sudo apt-get -y install libgtk-3-dev
+sudo apt-get -y install gstreamer1.0.* libgstreamer.*1.0.*
+
+# Python stuff for gst-switch API
+sudo apt-get -y install python-software-properties python-pip
+sudo apt-get -y install libglib2.0-dev gir1.2-glib-2.0 libgirepository1.0-dev libglib2.0-0 python-gi
+sudo apt-get -y install python-scipy
sudo pip install mock --upgrade
sudo pip install pytest-cov --upgrade
sudo pip install pytest-pep8 --upgrade
sudo pip install pylint --upgrade
-sudo apt-get -y install libglib2.0-dev gir1.2-glib-2.0 libgirepository1.0-dev libglib2.0-0 python-gi
-sudo apt-get -y install gstreamer0.10-plugins-good
-sudo apt-get -y install python-scipy
-sudo apt-get -y install ffmpeg || sudo apt-get -y install libav-tools
-sudo apt-get -y install libvo-aacenc-dev
-sudo apt-get -y install autoconf automake autopoint libbz2-dev libdv4-dev libfaac-dev libfaad-dev libgtk-3-dev libmjpegtools-dev libtag1-dev libasound2-dev libtool libvpx-dev libxv-dev libx11-dev libogg-dev libvorbis-dev libopencv-dev libcv-dev libhighgui-dev libv4l-dev pkg-config zlib1g-dev gtk-doc-tools yasm bison flex
-export PKG_CONFIG_PATH=/usr/lib/pkgconfig/
-export LD_LIBRARY_PATH=/usr/lib/
-export GCOV_PREFIX=$HOME/gst-switch-coverage
-cd ..
-git clone http://git.chromium.org/webm/libvpx.git
-cd libvpx
-git checkout v1.2.0
-./configure --enable-shared --enable-vp8 --prefix=/usr
-[[ -f Makefile ]] || {
- printf "Configure libvpx failed, no Makefile generated!!!\n"
- exit -1
- }
-make
-sudo make install || {
- printf "make install of libvpx failed!!!\n"
- exit -1
- }
-cd ..
-git clone git://anongit.freedesktop.org/gstreamer/gstreamer
-cd gstreamer
-git checkout 6c11da1
-./autogen.sh --prefix=/usr || {
-printf "Failed to do autogen!!!\n"
-exit -1
-}
-[[ -f Makefile ]] || {
- printf "Configure gstreamer failed, no Makefile generated!!!\n"
- exit -1
- }
-make clean
-make || {
- printf "make of $project failed!!!\n"
- exit -1
-}
-sudo make install || {
- printf "make install of gstreamer failed!!!\n"
- exit -1
- }
-cd ..
-git clone git://anongit.freedesktop.org/gstreamer/gst-plugins-base
-cd gst-plugins-base
-git checkout a8df760
-./autogen.sh --prefix=/usr || {
-printf "Failed to do autogen!!!\n"
-exit -1
-}
-[[ -f Makefile ]] || {
- printf "Configure gst-plugins-base failed, no Makefile generated!!!\n"
- exit -1
- }
-make clean
-make || {
- printf "make of gst-plugins-base failed!!!\n"
- exit -1
-}
-sudo make install || {
- printf "make install of $project failed!!!\n"
- exit -1
- }
-cd ..
-git clone git://anongit.freedesktop.org/gstreamer/gst-plugins-good
-cd gst-plugins-good
-git checkout d14d4c4
-./autogen.sh --enable-experimental --prefix=/usr || {
-printf "Failed to do autogen!!!\n"
-exit -1
-}
-[[ -f Makefile ]] || {
- printf "Configure gst-plugins-good failed, no Makefile generated!!!\n"
- exit -1
- }
-make clean
-make || {
- printf "make of gst-plugins-good failed!!!\n"
- exit -1
-}
-sudo make install || {
- printf "make install of $project failed!!!\n"
- exit -1
- }
-cd ..
-git clone git://anongit.freedesktop.org/gstreamer/gst-plugins-ugly
-cd gst-plugins-ugly
-git checkout 68985ba
-./autogen.sh --prefix=/usr || {
-printf "Failed to do autogen!!!\n"
-exit -1
-}
-[[ -f Makefile ]] || {
- printf "Configure gst-plugins-ugly failed, no Makefile generated!!!\n"
- exit -1
- }
-make clean
-make || {
- printf "make of gst-plugins-ugly failed!!!\n"
- exit -1
-}
-sudo make install || {
- printf "make install of gst-plugins-ugly failed!!!\n"
- exit -1
- }
-cd ..
-git clone https://github.com/hyades/gst-plugins-bad.git
-cd gst-plugins-bad
-./autogen.sh --prefix=/usr || {
-printf "Failed to do autogen!!!\n"
-exit -1
-}
-[[ -f Makefile ]] || {
- printf "Configure gst-plugins-bad failed, no Makefile generated!!!\n"
- exit -1
- }
-make clean
-make || {
- printf "make of gst-plugins-bad failed!!!\n"
- exit -1
-}
-sudo make install || {
- printf "make install of gst-plugins-bad failed!!!\n"
- exit -1
- }
-cd ..
-cd gst-switch
-./autogen.sh --prefix=/usr || {
-printf "Failed to do autogen!!!\n"
-exit -1
-}
-make clean
-make|| {
- printf "make of gstswitch failed!!!\n"
- exit -1
-}
-sudo make install || {
- printf "make install of gstswitch failed!!!\n"
- exit -1
- }
+# Needed for tests
+sudo apt-get -y install wget libav-tools
+
+# Needed to get coverage output
if [ $TYPE == 'c' ]; then
sudo pip install cpp-coveralls
else
diff --git a/.travis.yml b/.travis.yml
index 912edb0..2f520a4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,13 +10,14 @@ env:
- TEST=python-api TYPE=integration
- TEST=module TYPE=python
- TEST=module TYPE=c
+
install:
- - chmod +x .travis-setup.sh
- - ./.travis-setup.sh
+ - wget -q -O- https://raw.githubusercontent.com/mithro/travis-trusty/master/setup.sh | bash
+ - chmod a+rx $PWD/.travis-*.sh
+ - /trusty/run.py $PWD/.travis-setup.sh
script:
- - chmod +x .travis-run.sh
- - ./.travis-run.sh
+ - /trusty/run.py $PWD/.travis-run.sh
notifications:
email:
diff --git a/Makefile.am b/Makefile.am
index 74e55df..1dc5fb1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,8 +1,8 @@
-SUBDIRS = plugins tools tests
+SUBDIRS = plugins tools tests/unit tests
EXTRA_DIST = autogen.sh
-ACLOCAL_AMFLAGS = -I m4
+ACLOCAL_AMFLAGS = -I build
include tests/names.mk
test: update-test-suite clean-test-data $(TESTS)
diff --git a/m4/.gitignore b/build/.gitignore
similarity index 100%
rename from m4/.gitignore
rename to build/.gitignore
diff --git a/build/Makefile.am.gitignore b/build/Makefile.am.gitignore
new file mode 100644
index 0000000..42992a3
--- /dev/null
+++ b/build/Makefile.am.gitignore
@@ -0,0 +1,33 @@
+# this file should only be used in directories that generate test
+# or example binaries through noinst_PROGRAMS; it is *not* a full
+# generator of Git ignore files, and it's not meant to be used as
+# the top-level Git ignore file generator.
+
+$(srcdir)/.gitignore: Makefile.am $(top_srcdir)/build/Makefile.am.gitignore
+ $(AM_V_GEN)( \
+ echo "*.o" ; \
+ echo ".gitignore" ; \
+ echo "*.trs" ; \
+ echo "*.log" ; \
+ echo "Makefile" ; \
+ echo "Makefile.in" ; \
+ echo ".deps" ; \
+ ) > $(srcdir)/.gitignore ; \
+ for p in $(noinst_PROGRAMS); do \
+ echo "/$$p" >> $(srcdir)/.gitignore ; \
+ done ; \
+ for p in $(check_PROGRAMS); do \
+ echo "/$$p" >> $(srcdir)/.gitignore ; \
+ done
+
+
+gitignore: $(srcdir)/.gitignore
+
+gitignore-clean:
+ @rm -f $(srcdir)/.gitignore
+
+.PHONY: gitignore gitignore-clean
+
+all: gitignore
+
+maintainer-clean: gitignore-clean
diff --git a/build/README.md b/build/README.md
new file mode 100644
index 0000000..89ea825
--- /dev/null
+++ b/build/README.md
@@ -0,0 +1,6 @@
+
+ * [glib-tap.mk](https://git.gnome.org/browse/glib/tree/glib-tap.mk?id=7f2f4ab12df6ddb501900846896f496520871d16) (modified)
+ * [glibtests.m4](https://git.gnome.org/browse/glib/tree/m4macros/glibtests.m4?id=7f2f4ab12df6ddb501900846896f496520871d16)
+ * [tap-driver.sh](https://git.gnome.org/browse/glib/tree/tap-driver.sh?id=7f2f4ab12df6ddb501900846896f496520871d16)
+ * [tap-test](https://git.gnome.org/browse/glib/tree/tap-driver.sh?id=7f2f4ab12df6ddb501900846896f496520871d16)
+ * [Makefile.am.gitignore](https://git.gnome.org/browse/json-glib/tree/build/autotools/Makefile.am.gitignore?id=4ccb9ab6119b81dde81b04208b98c89fc3a7884c) (modified)
diff --git a/build/glib-tap.mk b/build/glib-tap.mk
new file mode 100644
index 0000000..11a34ab
--- /dev/null
+++ b/build/glib-tap.mk
@@ -0,0 +1,135 @@
+# GLIB - Library of useful C routines
+
+TESTS_ENVIRONMENT= \
+ G_TEST_SRCDIR="$(abs_srcdir)" \
+ G_TEST_BUILDDIR="$(abs_builddir)" \
+ G_DEBUG=gc-friendly \
+ MALLOC_CHECK_=2 \
+ MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
+LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build/tap-driver.sh
+LOG_COMPILER = $(top_srcdir)/build/tap-test
+
+NULL =
+
+# initialize variables for unconditional += appending
+BUILT_SOURCES =
+BUILT_EXTRA_DIST =
+CLEANFILES = *.log *.trs
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+EXTRA_DIST =
+TESTS =
+
+installed_test_LTLIBRARIES =
+installed_test_PROGRAMS =
+installed_test_SCRIPTS =
+nobase_installed_test_DATA =
+
+noinst_LTLIBRARIES =
+noinst_PROGRAMS =
+noinst_SCRIPTS =
+noinst_DATA =
+
+check_LTLIBRARIES =
+check_PROGRAMS =
+check_SCRIPTS =
+check_DATA =
+
+# We support a fairly large range of possible variables. It is expected that all types of files in a test suite
+# will belong in exactly one of the following variables.
+#
+# First, we support the usual automake suffixes, but in lowercase, with the customary meaning:
+#
+# test_programs, test_scripts, test_data, test_ltlibraries
+#
+# The above are used to list files that are involved in both uninstalled and installed testing. The
+# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite.
+# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data is
+# installed in the same way as it appears in the package layout.
+#
+# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled',
+# like so:
+#
+# installed_test_programs, uninstalled_test_programs
+# installed_test_scripts, uninstalled_test_scripts
+# installed_test_data, uninstalled_test_data
+# installed_test_ltlibraries, uninstalled_test_ltlibraries
+#
+# Additionally, we support 'extra' infixes for programs and scripts. This is used for support programs/scripts
+# that should not themselves be run as testcases (but exist to be used from other testcases):
+#
+# test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs
+# test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts
+#
+# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or data
+# file automatically end up in the tarball.
+#
+# dist_test_scripts, dist_test_data, dist_test_extra_scripts
+# dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts
+# dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts
+#
+# Note that no file is automatically disted unless it appears in one of the dist_ variables. This follows the
+# standard automake convention of not disting programs scripts or data by default.
+#
+# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their disted
+# variants) will be run as part of the in-tree 'make check'. These are all assumed to be runnable under
+# gtester. That's a bit strange for scripts, but it's possible.
+
+TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
+ $(dist_test_scripts) $(dist_uninstalled_test_scripts)
+
+# Note: build even the installed-only targets during 'make check' to ensure that they still work.
+# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to
+# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were
+# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'.
+all_test_programs = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(uninstalled_test_extra_programs) $(installed_test_extra_programs)
+all_test_scripts = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(uninstalled_test_extra_scripts) $(installed_test_extra_scripts)
+all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts) \
+ $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts) $(dist_installed_test_extra_scripts)
+all_test_scripts += $(all_dist_test_scripts)
+EXTRA_DIST += $(all_dist_test_scripts)
+all_test_data = $(test_data) $(uninstalled_test_data) $(installed_test_data)
+all_dist_test_data = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data)
+all_test_data += $(all_dist_test_data)
+EXTRA_DIST += $(all_dist_test_data)
+all_test_ltlibs = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries)
+
+if ENABLE_ALWAYS_BUILD_TESTS
+noinst_LTLIBRARIES += $(all_test_ltlibs)
+noinst_PROGRAMS += $(all_test_programs)
+noinst_SCRIPTS += $(all_test_scripts)
+noinst_DATA += $(all_test_data)
+else
+check_LTLIBRARIES += $(all_test_ltlibs)
+check_PROGRAMS += $(all_test_programs)
+check_SCRIPTS += $(all_test_scripts)
+check_DATA += $(all_test_data)
+endif
+
+if ENABLE_INSTALLED_TESTS
+installed_test_PROGRAMS += $(test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(installed_test_extra_programs)
+installed_test_SCRIPTS += $(test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(test_installed_extra_scripts)
+installed_test_SCRIPTS += $(dist_test_scripts) $(dist_test_extra_scripts) \
+ $(dist_installed_test_scripts) $(dist_installed_test_extra_scripts)
+nobase_installed_test_DATA += $(test_data) $(installed_test_data)
+nobase_installed_test_DATA += $(dist_test_data) $(dist_installed_test_data)
+installed_test_LTLIBRARIES += $(test_ltlibraries) $(installed_test_ltlibraries)
+installed_testcases = $(test_programs) $(installed_test_programs) \
+ $(test_scripts) $(installed_test_scripts) \
+ $(dist_test_scripts) $(dist_installed_test_scripts)
+
+installed_test_meta_DATA = $(installed_testcases:=.test)
+
+%.test: %$(EXEEXT) Makefile
+ $(AM_V_GEN) (echo '[Test]' > $@.tmp; \
+ echo 'Type=session' >> $@.tmp; \
+ echo 'Exec=$(installed_testdir)/$(notdir $<) --tap' >> $@.tmp; \
+ echo 'Output=TAP' >> $@.tmp; \
+ mv $@.tmp $@)
+
+CLEANFILES += $(installed_test_meta_DATA)
+endif
diff --git a/build/glibtests.m4 b/build/glibtests.m4
new file mode 100644
index 0000000..7d5920a
--- /dev/null
+++ b/build/glibtests.m4
@@ -0,0 +1,28 @@
+dnl GLIB_TESTS
+dnl
+
+AC_DEFUN([GLIB_TESTS],
+[
+ AC_ARG_ENABLE(installed-tests,
+ AS_HELP_STRING([--enable-installed-tests],
+ [Enable installation of some test cases]),
+ [case ${enableval} in
+ yes) ENABLE_INSTALLED_TESTS="1" ;;
+ no) ENABLE_INSTALLED_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-installed-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_INSTALLED_TESTS], test "$ENABLE_INSTALLED_TESTS" = "1")
+ AC_ARG_ENABLE(always-build-tests,
+ AS_HELP_STRING([--enable-always-build-tests],
+ [Enable always building tests during 'make all']),
+ [case ${enableval} in
+ yes) ENABLE_ALWAYS_BUILD_TESTS="1" ;;
+ no) ENABLE_ALWAYS_BUILD_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-always-build-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_ALWAYS_BUILD_TESTS], test "$ENABLE_ALWAYS_BUILD_TESTS" = "1")
+ if test "$ENABLE_INSTALLED_TESTS" = "1"; then
+ AC_SUBST(installed_test_metadir, [${datadir}/installed-tests/]AC_PACKAGE_NAME)
+ AC_SUBST(installed_testdir, [${libexecdir}/installed-tests/]AC_PACKAGE_NAME)
+ fi
+])
diff --git a/build/tap-driver.sh b/build/tap-driver.sh
new file mode 100755
index 0000000..19aa531
--- /dev/null
+++ b/build/tap-driver.sh
@@ -0,0 +1,652 @@
+#! /bin/sh
+# Copyright (C) 2011-2013 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to or send patches to
+# .
+
+scriptversion=2011-12-27.17; # UTC
+
+# Make unconditional expansion of undefined variables an error. This
+# helps a lot in preventing typo-related bugs.
+set -u
+
+me=tap-driver.sh
+
+fatal ()
+{
+ echo "$me: fatal: $*" >&2
+ exit 1
+}
+
+usage_error ()
+{
+ echo "$me: $*" >&2
+ print_usage >&2
+ exit 2
+}
+
+print_usage ()
+{
+ cat <
+ #
+ trap : 1 3 2 13 15
+ if test $merge -gt 0; then
+ exec 2>&1
+ else
+ exec 2>&3
+ fi
+ "$@"
+ echo $?
+ ) | LC_ALL=C ${AM_TAP_AWK-awk} \
+ -v me="$me" \
+ -v test_script_name="$test_name" \
+ -v log_file="$log_file" \
+ -v trs_file="$trs_file" \
+ -v expect_failure="$expect_failure" \
+ -v merge="$merge" \
+ -v ignore_exit="$ignore_exit" \
+ -v comments="$comments" \
+ -v diag_string="$diag_string" \
+'
+# FIXME: the usages of "cat >&3" below could be optimized when using
+# FIXME: GNU awk, and/on on systems that supports /dev/fd/.
+
+# Implementation note: in what follows, `result_obj` will be an
+# associative array that (partly) simulates a TAP result object
+# from the `TAP::Parser` perl module.
+
+## ----------- ##
+## FUNCTIONS ##
+## ----------- ##
+
+function fatal(msg)
+{
+ print me ": " msg | "cat >&2"
+ exit 1
+}
+
+function abort(where)
+{
+ fatal("internal error " where)
+}
+
+# Convert a boolean to a "yes"/"no" string.
+function yn(bool)
+{
+ return bool ? "yes" : "no";
+}
+
+function add_test_result(result)
+{
+ if (!test_results_index)
+ test_results_index = 0
+ test_results_list[test_results_index] = result
+ test_results_index += 1
+ test_results_seen[result] = 1;
+}
+
+# Whether the test script should be re-run by "make recheck".
+function must_recheck()
+{
+ for (k in test_results_seen)
+ if (k != "XFAIL" && k != "PASS" && k != "SKIP")
+ return 1
+ return 0
+}
+
+# Whether the content of the log file associated to this test should
+# be copied into the "global" test-suite.log.
+function copy_in_global_log()
+{
+ for (k in test_results_seen)
+ if (k != "PASS")
+ return 1
+ return 0
+}
+
+# FIXME: this can certainly be improved ...
+function get_global_test_result()
+{
+ if ("ERROR" in test_results_seen)
+ return "ERROR"
+ if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
+ return "FAIL"
+ all_skipped = 1
+ for (k in test_results_seen)
+ if (k != "SKIP")
+ all_skipped = 0
+ if (all_skipped)
+ return "SKIP"
+ return "PASS";
+}
+
+function stringify_result_obj(result_obj)
+{
+ if (result_obj["is_unplanned"] || result_obj["number"] != testno)
+ return "ERROR"
+
+ if (plan_seen == LATE_PLAN)
+ return "ERROR"
+
+ if (result_obj["directive"] == "TODO")
+ return result_obj["is_ok"] ? "XPASS" : "XFAIL"
+
+ if (result_obj["directive"] == "SKIP")
+ return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
+
+ if (length(result_obj["directive"]))
+ abort("in function stringify_result_obj()")
+
+ return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
+}
+
+function decorate_result(result)
+{
+ color_name = color_for_result[result]
+ if (color_name)
+ return color_map[color_name] "" result "" color_map["std"]
+ # If we are not using colorized output, or if we do not know how
+ # to colorize the given result, we should return it unchanged.
+ return result
+}
+
+function report(result, details)
+{
+ if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
+ {
+ msg = ": " test_script_name
+ add_test_result(result)
+ }
+ else if (result == "#")
+ {
+ msg = " " test_script_name ":"
+ }
+ else
+ {
+ abort("in function report()")
+ }
+ if (length(details))
+ msg = msg " " details
+ # Output on console might be colorized.
+ print decorate_result(result) msg
+ # Log the result in the log file too, to help debugging (this is
+ # especially true when said result is a TAP error or "Bail out!").
+ print result msg | "cat >&3";
+}
+
+function testsuite_error(error_message)
+{
+ report("ERROR", "- " error_message)
+}
+
+function handle_tap_result()
+{
+ details = result_obj["number"];
+ if (length(result_obj["description"]))
+ details = details " " result_obj["description"]
+
+ if (plan_seen == LATE_PLAN)
+ {
+ details = details " # AFTER LATE PLAN";
+ }
+ else if (result_obj["is_unplanned"])
+ {
+ details = details " # UNPLANNED";
+ }
+ else if (result_obj["number"] != testno)
+ {
+ details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
+ details, testno);
+ }
+ else if (result_obj["directive"])
+ {
+ details = details " # " result_obj["directive"];
+ if (length(result_obj["explanation"]))
+ details = details " " result_obj["explanation"]
+ }
+
+ report(stringify_result_obj(result_obj), details)
+}
+
+# `skip_reason` should be empty whenever planned > 0.
+function handle_tap_plan(planned, skip_reason)
+{
+ planned += 0 # Avoid getting confused if, say, `planned` is "00"
+ if (length(skip_reason) && planned > 0)
+ abort("in function handle_tap_plan()")
+ if (plan_seen)
+ {
+ # Error, only one plan per stream is acceptable.
+ testsuite_error("multiple test plans")
+ return;
+ }
+ planned_tests = planned
+ # The TAP plan can come before or after *all* the TAP results; we speak
+ # respectively of an "early" or a "late" plan. If we see the plan line
+ # after at least one TAP result has been seen, assume we have a late
+ # plan; in this case, any further test result seen after the plan will
+ # be flagged as an error.
+ plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
+ # If testno > 0, we have an error ("too many tests run") that will be
+ # automatically dealt with later, so do not worry about it here. If
+ # $plan_seen is true, we have an error due to a repeated plan, and that
+ # has already been dealt with above. Otherwise, we have a valid "plan
+ # with SKIP" specification, and should report it as a particular kind
+ # of SKIP result.
+ if (planned == 0 && testno == 0)
+ {
+ if (length(skip_reason))
+ skip_reason = "- " skip_reason;
+ report("SKIP", skip_reason);
+ }
+}
+
+function extract_tap_comment(line)
+{
+ if (index(line, diag_string) == 1)
+ {
+ # Strip leading `diag_string` from `line`.
+ line = substr(line, length(diag_string) + 1)
+ # And strip any leading and trailing whitespace left.
+ sub("^[ \t]*", "", line)
+ sub("[ \t]*$", "", line)
+ # Return what is left (if any).
+ return line;
+ }
+ return "";
+}
+
+# When this function is called, we know that line is a TAP result line,
+# so that it matches the (perl) RE "^(not )?ok\b".
+function setup_result_obj(line)
+{
+ # Get the result, and remove it from the line.
+ result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
+ sub("^(not )?ok[ \t]*", "", line)
+
+ # If the result has an explicit number, get it and strip it; otherwise,
+ # automatically assing the next progresive number to it.
+ if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
+ {
+ match(line, "^[0-9]+")
+ # The final `+ 0` is to normalize numbers with leading zeros.
+ result_obj["number"] = substr(line, 1, RLENGTH) + 0
+ line = substr(line, RLENGTH + 1)
+ }
+ else
+ {
+ result_obj["number"] = testno
+ }
+
+ if (plan_seen == LATE_PLAN)
+ # No further test results are acceptable after a "late" TAP plan
+ # has been seen.
+ result_obj["is_unplanned"] = 1
+ else if (plan_seen && testno > planned_tests)
+ result_obj["is_unplanned"] = 1
+ else
+ result_obj["is_unplanned"] = 0
+
+ # Strip trailing and leading whitespace.
+ sub("^[ \t]*", "", line)
+ sub("[ \t]*$", "", line)
+
+ # This will have to be corrected if we have a "TODO"/"SKIP" directive.
+ result_obj["description"] = line
+ result_obj["directive"] = ""
+ result_obj["explanation"] = ""
+
+ if (index(line, "#") == 0)
+ return # No possible directive, nothing more to do.
+
+ # Directives are case-insensitive.
+ rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
+
+ # See whether we have the directive, and if yes, where.
+ pos = match(line, rx "$")
+ if (!pos)
+ pos = match(line, rx "[^a-zA-Z0-9_]")
+
+ # If there was no TAP directive, we have nothing more to do.
+ if (!pos)
+ return
+
+ # Let`s now see if the TAP directive has been escaped. For example:
+ # escaped: ok \# SKIP
+ # not escaped: ok \\# SKIP
+ # escaped: ok \\\\\# SKIP
+ # not escaped: ok \ # SKIP
+ if (substr(line, pos, 1) == "#")
+ {
+ bslash_count = 0
+ for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
+ bslash_count += 1
+ if (bslash_count % 2)
+ return # Directive was escaped.
+ }
+
+ # Strip the directive and its explanation (if any) from the test
+ # description.
+ result_obj["description"] = substr(line, 1, pos - 1)
+ # Now remove the test description from the line, that has been dealt
+ # with already.
+ line = substr(line, pos)
+ # Strip the directive, and save its value (normalized to upper case).
+ sub("^[ \t]*#[ \t]*", "", line)
+ result_obj["directive"] = toupper(substr(line, 1, 4))
+ line = substr(line, 5)
+ # Now get the explanation for the directive (if any), with leading
+ # and trailing whitespace removed.
+ sub("^[ \t]*", "", line)
+ sub("[ \t]*$", "", line)
+ result_obj["explanation"] = line
+}
+
+function get_test_exit_message(status)
+{
+ if (status == 0)
+ return ""
+ if (status !~ /^[1-9][0-9]*$/)
+ abort("getting exit status")
+ if (status < 127)
+ exit_details = ""
+ else if (status == 127)
+ exit_details = " (command not found?)"
+ else if (status >= 128 && status <= 255)
+ exit_details = sprintf(" (terminated by signal %d?)", status - 128)
+ else if (status > 256 && status <= 384)
+ # We used to report an "abnormal termination" here, but some Korn
+ # shells, when a child process die due to signal number n, can leave
+ # in $? an exit status of 256+n instead of the more standard 128+n.
+ # Apparently, both behaviours are allowed by POSIX (2008), so be
+ # prepared to handle them both. See also Austing Group report ID
+ # 0000051
+ exit_details = sprintf(" (terminated by signal %d?)", status - 256)
+ else
+ # Never seen in practice.
+ exit_details = " (abnormal termination)"
+ return sprintf("exited with status %d%s", status, exit_details)
+}
+
+function write_test_results()
+{
+ print ":global-test-result: " get_global_test_result() > trs_file
+ print ":recheck: " yn(must_recheck()) > trs_file
+ print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
+ for (i = 0; i < test_results_index; i += 1)
+ print ":test-result: " test_results_list[i] > trs_file
+ close(trs_file);
+}
+
+BEGIN {
+
+## ------- ##
+## SETUP ##
+## ------- ##
+
+'"$init_colors"'
+
+# Properly initialized once the TAP plan is seen.
+planned_tests = 0
+
+COOKED_PASS = expect_failure ? "XPASS": "PASS";
+COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
+
+# Enumeration-like constants to remember which kind of plan (if any)
+# has been seen. It is important that NO_PLAN evaluates "false" as
+# a boolean.
+NO_PLAN = 0
+EARLY_PLAN = 1
+LATE_PLAN = 2
+
+testno = 0 # Number of test results seen so far.
+bailed_out = 0 # Whether a "Bail out!" directive has been seen.
+
+# Whether the TAP plan has been seen or not, and if yes, which kind
+# it is ("early" is seen before any test result, "late" otherwise).
+plan_seen = NO_PLAN
+
+## --------- ##
+## PARSING ##
+## --------- ##
+
+is_first_read = 1
+
+while (1)
+ {
+ # Involutions required so that we are able to read the exit status
+ # from the last input line.
+ st = getline
+ if (st < 0) # I/O error.
+ fatal("I/O error while reading from input stream")
+ else if (st == 0) # End-of-input
+ {
+ if (is_first_read)
+ abort("in input loop: only one input line")
+ break
+ }
+ if (is_first_read)
+ {
+ is_first_read = 0
+ nextline = $0
+ continue
+ }
+ else
+ {
+ curline = nextline
+ nextline = $0
+ $0 = curline
+ }
+ # Copy any input line verbatim into the log file.
+ print | "cat >&3"
+ # Parsing of TAP input should stop after a "Bail out!" directive.
+ if (bailed_out)
+ continue
+
+ # TAP test result.
+ if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
+ {
+ testno += 1
+ setup_result_obj($0)
+ handle_tap_result()
+ }
+ # TAP plan (normal or "SKIP" without explanation).
+ else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
+ {
+ # The next two lines will put the number of planned tests in $0.
+ sub("^1\\.\\.", "")
+ sub("[^0-9]*$", "")
+ handle_tap_plan($0, "")
+ continue
+ }
+ # TAP "SKIP" plan, with an explanation.
+ else if ($0 ~ /^1\.\.0+[ \t]*#/)
+ {
+ # The next lines will put the skip explanation in $0, stripping
+ # any leading and trailing whitespace. This is a little more
+ # tricky in truth, since we want to also strip a potential leading
+ # "SKIP" string from the message.
+ sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
+ sub("[ \t]*$", "");
+ handle_tap_plan(0, $0)
+ }
+ # "Bail out!" magic.
+ # Older versions of prove and TAP::Harness (e.g., 3.17) did not
+ # recognize a "Bail out!" directive when preceded by leading
+ # whitespace, but more modern versions (e.g., 3.23) do. So we
+ # emulate the latter, "more modern" behaviour.
+ else if ($0 ~ /^[ \t]*Bail out!/)
+ {
+ bailed_out = 1
+ # Get the bailout message (if any), with leading and trailing
+ # whitespace stripped. The message remains stored in `$0`.
+ sub("^[ \t]*Bail out![ \t]*", "");
+ sub("[ \t]*$", "");
+ # Format the error message for the
+ bailout_message = "Bail out!"
+ if (length($0))
+ bailout_message = bailout_message " " $0
+ testsuite_error(bailout_message)
+ }
+ # Maybe we have too look for dianogtic comments too.
+ else if (comments != 0)
+ {
+ comment = extract_tap_comment($0);
+ if (length(comment))
+ report("#", comment);
+ }
+ }
+
+## -------- ##
+## FINISH ##
+## -------- ##
+
+# A "Bail out!" directive should cause us to ignore any following TAP
+# error, as well as a non-zero exit status from the TAP producer.
+if (!bailed_out)
+ {
+ if (!plan_seen)
+ {
+ testsuite_error("missing test plan")
+ }
+ else if (planned_tests != testno)
+ {
+ bad_amount = testno > planned_tests ? "many" : "few"
+ testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
+ bad_amount, planned_tests, testno))
+ }
+ if (!ignore_exit)
+ {
+ # Fetch exit status from the last line.
+ exit_message = get_test_exit_message(nextline)
+ if (exit_message)
+ testsuite_error(exit_message)
+ }
+ }
+
+write_test_results()
+
+exit 0
+
+} # End of "BEGIN" block.
+'
+
+# TODO: document that we consume the file descriptor 3 :-(
+} 3>"$log_file"
+
+test $? -eq 0 || fatal "I/O or internal error"
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/build/tap-test b/build/tap-test
new file mode 100755
index 0000000..481e333
--- /dev/null
+++ b/build/tap-test
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+# run a GTest in tap mode. The test binary is passed as $1
+
+$1 -k --tap
diff --git a/configure.ac b/configure.ac
index 35b95c7..a5b15bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,7 +14,7 @@ AC_CONFIG_HEADERS([config.h])
dnl required version of automake
AM_INIT_AUTOMAKE([1.10])
-AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_MACRO_DIR([build])
dnl enable mainainer mode by default
AM_MAINTAINER_MODE([enable])
@@ -33,6 +33,7 @@ AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, [ ], [
AC_MSG_ERROR([You need to have pkg-config installed!])
])
+dnl === Glib + GIO ============================================================
PKG_CHECK_MODULES(GIO, [
gio-2.0 >= 2.25.0
], [
@@ -53,7 +54,7 @@ PKG_CHECK_MODULES(GLIB, [
])
])
-dnl GTK
+dnl === GTK ===================================================================
HAVE_GTK=NO
GTK2_REQ=2.14.0
GTK3_REQ=2.91.3
@@ -78,37 +79,8 @@ CPPFLAGS="$GTK_CFLAGS"
AC_CHECK_HEADER([gdk/gdkx.h], [],
[AC_MSG_ERROR([GDK X11 header (gdk/gdkx.h) is required])])
-AC_ARG_ENABLE(gcov,
- AS_HELP_STRING([--enable-gcov],[enable gcov building]),
- [
- case "${enableval}" in
- yes) BUILD_GCOV=yes ;;
- no) BUILD_GCOV=no ;;
- esac
- ],
- [BUILD_GCOV=yes])
-AC_ARG_ENABLE(gprof,
- AS_HELP_STRING([--enable-gprof],[enable gprof building]),
- [
- case "${enableval}" in
- yes) BUILD_GPROF=yes ;;
- no) BUILD_GPROF=no ;;
- esac
- ],
- [BUILD_GPROF=yes])
-AM_CONDITIONAL(GCOV_ENABLED, test "x$BUILD_GCOV" = "xyes")
-AM_CONDITIONAL(GPROF_ENABLED, test "x$BUILD_GPROF" = "xyes")
-AC_ARG_ENABLE(speakertrack,
- AS_HELP_STRING([--enable-speakertrack],[enable speakertrack]),
- [
- case "${enableval}" in
- yes) BUILD_SPEAKERTRACK=yes ;;
- no) BUILD_SPEAKERTRACK=no ;;
- esac
- ],
- [BUILD_SPEAKERTRACK=no])
- AM_CONDITIONAL(SPEAKERTRACK_ENABLED, test "x$BUILD_SPEAKERTRACK" = "xyes")
+dnl === gstreamer related options =============================================
dnl Check for the required version of GStreamer core (and gst-plugins-base)
dnl This will export GST_CFLAGS and GST_LIBS variables for use in Makefile.am
@@ -164,10 +136,56 @@ dnl set proper LDFLAGS for plugins
GST_PLUGIN_LDFLAGS='-module -avoid-version -export-symbols-regex [_]*\(gst_\|Gst\|GST_\).*'
AC_SUBST(GST_PLUGIN_LDFLAGS)
+dnl === Testing ===============================================================
+
+GLIB_TESTS
+
+dnl FIXME: Add checking for the testing requirements here.
+
+dnl === Coverage and profiling options ========================================
+AC_ARG_ENABLE(gcov,
+ AS_HELP_STRING([--enable-gcov],[enable gcov building]),
+ [
+ case "${enableval}" in
+ yes) BUILD_GCOV=yes ;;
+ no) BUILD_GCOV=no ;;
+ esac
+ ],
+ [BUILD_GCOV=yes])
+AM_CONDITIONAL(GCOV_ENABLED, test "x$BUILD_GCOV" = "xyes")
+
+AC_ARG_ENABLE(gprof,
+ AS_HELP_STRING([--enable-gprof],[enable gprof building]),
+ [
+ case "${enableval}" in
+ yes) BUILD_GPROF=yes ;;
+ no) BUILD_GPROF=no ;;
+ esac
+ ],
+ [BUILD_GPROF=yes])
+AM_CONDITIONAL(GPROF_ENABLED, test "x$BUILD_GPROF" = "xyes")
+
+dnl === Local options =========================================================
+AC_ARG_ENABLE(speakertrack,
+ AS_HELP_STRING([--enable-speakertrack],[enable speakertrack]),
+ [
+ case "${enableval}" in
+ yes) BUILD_SPEAKERTRACK=yes ;;
+ no) BUILD_SPEAKERTRACK=no ;;
+ esac
+ ],
+ [BUILD_SPEAKERTRACK=no])
+ AM_CONDITIONAL(SPEAKERTRACK_ENABLED, test "x$BUILD_SPEAKERTRACK" = "xyes")
+
+dnl FIXME: Add the Python-API as an option here
+
+dnl === Output ================================================================
+
AC_CONFIG_FILES(
Makefile
plugins/Makefile
tests/Makefile
+tests/unit/Makefile
tools/Makefile
)
diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py
index 632d4bd..b7f6d42 100644
--- a/python-api/gstswitch/server.py
+++ b/python-api/gstswitch/server.py
@@ -6,6 +6,7 @@
import os
import signal
import subprocess
+from distutils import spawn
from errno import ENOENT
from .exception import PathError, ServerProcessError
@@ -22,8 +23,9 @@ class Server(object):
"""Control all server related operations
- :param path: Path where all executables
- gst-switch-srv, gst-launch-1.0, etc are located
+ :param path: Path where the executable gst-switch-srv
+ is located. Provide the full path.
+ By default looks in the current $PATH.
:param video_port: The video port number - default = 3000
:param audio_port: The audio port number - default = 4000
:param control_port: The control port number - default = 5000
@@ -34,7 +36,7 @@ class Server(object):
def __init__(
self,
- path,
+ path=None,
video_port=3000,
audio_port=4000,
control_port=5000,
@@ -47,7 +49,7 @@ def __init__(
self._audio_port = None
self._control_port = None
self._record_file = None
- self.gst_option_string = None
+ self.gst_option_string = ''
self.path = path
self.video_port = video_port
@@ -68,10 +70,7 @@ def path(self, path):
"""Set path
:raises ValueError: Path cannot be left blank
"""
- if not path:
- raise ValueError("Path '{0}' cannot be blank".format(path))
- else:
- self._path = path
+ self._path = path
@property
def video_port(self):
@@ -197,9 +196,17 @@ def run(self, gst_option=''):
def _run_process(self):
"""Non-public method: Runs the gst-switch-srv process
"""
- cmd = self.path
- cmd += """gst-switch-srv \
- {0} \
+ cmd = ''
+ if not self.path:
+ srv_location = spawn.find_executable('gst-switch-srv')
+ if srv_location:
+ cmd = srv_location
+ else:
+ raise PathError("Cannot find gst-switch-srv in $PATH.\
+ Please specify the path.")
+ else:
+ cmd += os.path.join(self.path, 'gst-switch-srv')
+ cmd += """ {0} \
--video-input-port={1} \
--audio-input-port={2} \
--control-port={3} \
diff --git a/python-api/gstswitch/testsource.py b/python-api/gstswitch/testsource.py
index 092cd64..5f88d93 100644
--- a/python-api/gstswitch/testsource.py
+++ b/python-api/gstswitch/testsource.py
@@ -295,7 +295,6 @@ def make_xvimagesink(self):
return element
-
class VideoSrc(object):
"""A Test Video Source
diff --git a/python-api/tests/unittests/test_server_unit.py b/python-api/tests/unittests/test_server_unit.py
index 0a166a2..b938f2a 100644
--- a/python-api/tests/unittests/test_server_unit.py
+++ b/python-api/tests/unittests/test_server_unit.py
@@ -5,8 +5,9 @@
from gstswitch.server import Server
import pytest
-from gstswitch.exception import ServerProcessError, PathError
+from gstswitch.exception import ServerProcessError
import subprocess
+from distutils import spawn
from mock import Mock
@@ -18,23 +19,51 @@ class TestPath(object):
"""Test the path parameter"""
# Path Tests
- def test_invalid_path(self):
- """Test if path specified does not have executables"""
+ def test_path_provided_slash(self):
+ """Test if a path is provided"""
+ def mock_method(arg):
+ """Mocking _start_process"""
+ return arg
path = '/usr/'
serv = Server(path=path)
- with pytest.raises(PathError):
- serv.run()
+ serv._start_process = mock_method
+ assert serv._run_process().split() == "/usr/gst-switch-srv \
+--video-input-port=3000 --audio-input-port=4000 \
+--control-port=5000 --record=record.data".split()
+
+ def test_path_provided_no_slash(self):
+ """Test if a path is provided"""
+ def mock_method(arg):
+ """Mocking _start_process"""
+ return arg
+ path = '/usr'
+ serv = Server(path=path)
+ serv._start_process = mock_method
+ assert serv._run_process().split() == "/usr/gst-switch-srv \
+--video-input-port=3000 --audio-input-port=4000 \
+--control-port=5000 --record=record.data".split()
- def test_invalid_path_none(self):
+ def test_path_empty(self, monkeypatch):
"""Test if null path is given"""
- paths = [None, '', [], {}]
+
+ def mock_method(arg):
+ "Mocking _start_process"
+ return arg
+
+ def mockreturn(path):
+ "Mocking distutils.spawn.find_executable"
+ return '/usr/gst-switch-srv'
+ monkeypatch.setattr(spawn, 'find_executable', mockreturn)
+ paths = [None, '']
for path in paths:
- with pytest.raises(ValueError):
- Server(path=path)
+ serv = Server(path=path)
+ serv._start_process = mock_method
+ assert serv._run_process().split() == "/usr/gst-switch-srv \
+--video-input-port=3000 --audio-input-port=4000 \
+--control-port=5000 --record=record.data".split()
class TestVideoPort(object):
-
"""Test for video_port parameter"""
# Video Port Tests
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
new file mode 100644
index 0000000..cca148a
--- /dev/null
+++ b/tests/unit/Makefile.am
@@ -0,0 +1,13 @@
+include $(top_srcdir)/build/glib-tap.mk
+
+LDADD = \
+ $(GLIB_LIBS)
+
+dist_test_data = \
+ $(NULL)
+
+test_programs = \
+ gstswitchexample \
+ $(NULL)
+
+include $(top_srcdir)/build/Makefile.am.gitignore
diff --git a/tests/unit/gstswitchexample.c b/tests/unit/gstswitchexample.c
new file mode 100644
index 0000000..e4afed5
--- /dev/null
+++ b/tests/unit/gstswitchexample.c
@@ -0,0 +1,23 @@
+#include
+
+static void
+success (void)
+{
+ g_assert_cmpint (1234, ==, 1234);
+}
+
+static void
+fail (void)
+{
+ g_assert_cmpint (1234, ==, 1);
+}
+
+int
+main (int argc, char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_set_nonfatal_assertions ();
+ g_test_add_func ("/gstswitch/server/options/success", success);
+ g_test_add_func ("/gstswitch/server/options/fail", fail);
+ return g_test_run ();
+}
diff --git a/tools/gstswitchcontroller.c b/tools/gstswitchcontroller.c
index 1e413c5..d58f5a5 100644
--- a/tools/gstswitchcontroller.c
+++ b/tools/gstswitchcontroller.c
@@ -298,6 +298,7 @@ gst_switch_controller_emit_ui_signal (GstSwitchController * controller,
signame, parameters, &error);
if (!res) {
+ g_assert (error != NULL);
ERROR ("emit: (%d) %s", num, error->message);
} else {
++num;
@@ -325,16 +326,16 @@ gst_switch_controller_on_connection_closed (GDBusConnection * connection,
if (error) {
WARN ("close: %s", error->message);
- g_error_free (error);
}
- g_object_unref (connection);
GST_SWITCH_CONTROLLER_LOCK_UIS (controller);
controller->uis = g_list_remove (controller->uis, connection);
GST_SWITCH_CONTROLLER_UNLOCK_UIS (controller);
INFO ("closed: %p, %d (%d uis)", connection, vanished,
g_list_length (controller->uis));
+
+ g_object_unref (connection);
}
static GVariant *gst_switch_controller_call_client (GstSwitchController *
@@ -413,17 +414,18 @@ gst_switch_controller_on_new_connection (GDBusServer * server,
NULL, /* user_data_free_func */
&error);
- if (register_id <= 0 || error != NULL) {
+ if (error != NULL) {
ERROR ("failed to register controller: %s", error->message);
- return TRUE;
+ g_error_free (error);
+ return FALSE;
+ } else if (register_id <= 0) {
+ ERROR ("register_id invalid (<= 0): %d", register_id);
+ return FALSE;
+ } else {
+ INFO ("registered: %d, %s, %s", register_id,
+ SWITCH_CONTROLLER_OBJECT_PATH, introspection_data->interfaces[0]->name);
}
- /*
- INFO ("registered: %d, %s, %s", register_id,
- SWITCH_CONTROLLER_OBJECT_PATH,
- introspection_data->interfaces[0]->name);
- */
-
g_signal_connect (connection, "closed",
G_CALLBACK (gst_switch_controller_on_connection_closed), controller);
@@ -474,12 +476,13 @@ gst_switch_controller_init (GstSwitchController * controller)
auth_observer = g_dbus_auth_observer_new ();
controller->bus_server = g_dbus_server_new_sync (SWITCH_CONTROLLER_ADDRESS, flags, guid, auth_observer, NULL, /* GCancellable */
&error);
+ if (error != NULL) {
+ g_error ("failed to register controller: %s", error->message);
+ }
+ g_assert (controller->bus_server != NULL);
g_free (guid);
- if (controller->bus_server == NULL)
- goto error_new_server;
-
INFO ("Controller is listening at: %s",
g_dbus_server_get_client_address (controller->bus_server));
@@ -496,14 +499,6 @@ gst_switch_controller_init (GstSwitchController * controller)
// TODO: singleton object
return;
-
- /* Errors Handling */
-error_new_server:
- {
- if (error)
- ERROR ("%s", error->message);
- return;
- }
}
/**
@@ -580,20 +575,16 @@ gst_switch_controller_call_client (GstSwitchController * controller,
NULL /* TODO: cancellable */ ,
&error);
- if (error != NULL)
- goto error_call_sync;
-
- return value;
-
- /* ERRORS */
-error_call_sync:
- {
+ if (error != NULL) {
ERROR ("%s (%s)", error->message, method_name);
g_error_free (error);
if (value)
g_variant_unref (value);
return NULL;
}
+ g_assert (value != NULL);
+
+ return value;
}
/**