#!/bin/sh

### Redirect standard error into standard output
exec 2>&1

### Exit immediately if a command exits with a non-zero status
set -e

### Get the directory of this script (for access to configure.ac and
### contacts.vcf)
VIEWER_DIR=$(dirname $0)/../../viewer

### Rolo command.  Can be set as an environment variable when
### launching this script.  Defaults to the compiled version in ../src.
VIBES_VIEWER=${VIBES_VIEWER:-VIBes-viewer}

### Test whether the server launches and consumes the commands
TMPDIR=/tmp
CHANNEL=$TMPDIR/.vibes.json
HOME=$TMPDIR $VIBES_VIEWER &
PID=$!
cat $VIEWER_DIR/tests/all_commands.json > $CHANNEL
sleep 10
[ -n "$PID" ] && kill -9 $PID
SIZE=$(wc -c $CHANNEL | cut -d\  -f1)
[ $SIZE = 0 ] && exit 0 || exit 1
