#!/bin/sh
# autopkgtest for libopenshot-audio
# (C) 2020 Anton Gladky

set -e

# Run the demo, filtering out expected ALSA warnings
# These warnings are normal in CI environments without audio hardware/MIDI devices
# We use 'pipefail' logic by checking the test completes properly
output=$(/usr/bin/openshot-audio-demo 2>&1)
exit_code=$?

# Filter and print output, removing ALSA warnings about missing /dev/snd/seq
echo "$output" | grep -v "ALSA lib.*open /dev/snd/seq failed" || true

# Check if the demo completed successfully
if [ $exit_code -ne 0 ]; then
    echo "ERROR: openshot-audio-demo failed with exit code $exit_code" >&2
    exit 1
fi

# Verify that the demo actually ran to completion
if ! echo "$output" | grep -q "Demo complete"; then
    echo "ERROR: Audio demo did not complete properly" >&2
    exit 1
fi

exit 0
