#!/bin/sh

set -e
at_exit() {
    set +x
    echo "info: test exiting, removing $WORKDIR"
    rm -rf $WORKDIR
}
WORKDIR=$(mktemp -d)
trap at_exit INT TERM EXIT
set -x

cd $WORKDIR

if type valgrind >/dev/null 2>&1 ; then
    VALGRIND=valgrind
fi

# This is just a simple code example to compile to verify the headers
# exist, are includable and the library is linkable.  It should be
# extended to really use the library to test a bit more of the
# package.
cat > example.c <<EOF
#include <stdio.h>
#include <fishsound/fishsound.h>
int
main (int argc, char ** argv)
{
  FishSound * fsound;

  /* quiet down compiler about unused arguments */
  if (1 < argc)
      return (strlen(argv[1]) != 0);

  fsound = fish_sound_new (FISH_SOUND_DECODE, NULL);
  fish_sound_set_interleave (fsound, 1);
  fish_sound_delete (fsound);

  printf("info: program ran as it should\n");

  exit (0);
}
EOF

gcc -o test -Wall -Wextra example.c -lfishsound

${VALGRIND} ./test
