#!/bin/sh
# Exercise the installed gtty-cli: encode a message to a WAV file, decode it
# again, and ask Hamlib for a rig model. No display or sound device is needed.
set -eu

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

gtty-cli encode "CQ CQ DE N0CALL K" "$tmp/cq.wav" >/dev/null
gtty-cli decode "$tmp/cq.wav" >"$tmp/decoded.txt"

if ! grep -q "CQ CQ DE N0CALL K" "$tmp/decoded.txt"; then
    echo "FAIL: decoded text is missing the encoded message:" >&2
    cat "$tmp/decoded.txt" >&2
    exit 1
fi

if ! gtty-cli rigs ft-710 | grep -q "FT-710"; then
    echo "FAIL: gtty-cli rigs does not list the FT-710" >&2
    exit 1
fi
