#!/bin/sh

SAMPLE_FILE="outlook.pst"
SAMPLE_URL="https://github.com/libyal/testdata/blob/main/pst/${SAMPLE_FILE}?raw=true"
SAMPLE_PATH=$AUTOPKGTEST_TMP/$SAMPLE_FILE

# If available, pick sample file from debian/tests, 
if [ -r debian/tests/$SAMPLE_FILE ]; then
	echo "Picking local $SAMPLE_FILE"
	cp -a debian/tests/$SAMPLE_FILE $SAMPLE_PATH
# else, try to download it.
else
	echo "Downloading $SAMPLE_FILE"
	curl -L -k --silent --show-error -o "$SAMPLE_PATH" "$SAMPLE_URL" 2>&1
fi
# Skip test, if sample file is not available
if [ ! -r $SAMPLE_PATH ]; then
	echo "Couldn't fetch $SAMPLE_FILE"
	exit 77
fi

echo "\npffinfo:"
pffinfo $SAMPLE_PATH >$AUTOPKGTEST_TMP/pffinfo.out
cat $AUTOPKGTEST_TMP/pffinfo.out
if ! grep '^Personal Folder File information:$' $AUTOPKGTEST_TMP/pffinfo.out; then
	echo 'Missing expected pattern'
	exit 1
fi

echo "\npffexport:"
pffexport $SAMPLE_PATH >$AUTOPKGTEST_TMP/pffexport.out
cat $AUTOPKGTEST_TMP/pffexport.out
if ! grep '^Export completed.$' $AUTOPKGTEST_TMP/pffexport.out; then
	echo 'Missing expected pattern'
	exit 2
fi

echo "\nExported tree:"
tree $SAMPLE_FILE.export >$AUTOPKGTEST_TMP/tree.out
cat $AUTOPKGTEST_TMP/tree.out
if ! grep '^└── Top of Personal Folders$' $AUTOPKGTEST_TMP/tree.out; then
	echo 'Missing expected pattern'
	exit 3
fi
