#!/bin/sh

set -eu

export LC_ALL=C.UTF-8

test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT HUP INT TERM

plugin_list="$test_dir/libvisual-plugins.txt"
lv-tool-0.4 --plugin-help > "$plugin_list" 2>&1

for plugin in alsa debug jack mplayer portaudio; do
	if ! grep -Fq "($plugin)" "$plugin_list"; then
		echo "missing libvisual input plugin: $plugin" >&2
		exit 1
	fi
done

for plugin in bumpscope corona gstreamer infinite jakdaw jess lv_analyzer \
		lv_flower lv_gltest lv_scope madspin nastyfft oinksie; do
	if ! grep -Fq "($plugin)" "$plugin_list"; then
		echo "missing libvisual actor plugin: $plugin" >&2
		exit 1
	fi
done

# Force a fresh GStreamer registry so this test cannot pass using cached
# metadata from another version of the package.
export GST_REGISTRY_1_0="$test_dir/gstreamer-registry.bin"

for actor in bumpscope corona infinite jakdaw jess lv_analyzer lv_scope \
		oinksie; do
	element="libvisual_$actor"
	gst-inspect-1.0 "$element" > /dev/null
	timeout 30 gst-launch-1.0 -q \
		audiotestsrc num-buffers=16 ! audioconvert ! \
		"$element" ! fakesink sync=false
done
