#! /bin/bash
###############################################################################
#
# $Id$ $Name$
#
# The contents of this file are subject to the AAF SDK Public Source
# License Agreement Version 2.0 (the "License"); You may not use this
# file except in compliance with the License.  The License is available
# in AAFSDKPSL.TXT, or you may obtain a copy of the License from the
# Advanced Media Workflow Association, Inc., or its successor.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
# the License for the specific language governing rights and limitations
# under the License.  Refer to Section 3.3 of the License for proper use
# of this Exhibit.
#
# WARNING:  Please contact the Advanced Media Workflow Association,
# Inc., for more information about any additional licenses to
# intellectual property covering the AAF Standard that may be required
# to create and distribute AAF compliant products.
# (http://www.amwa.tv/policies).
#
# Copyright Notices:
# The Original Code of this file is Copyright 1998-2009, licensor of the
# Advanced Media Workflow Association.  All rights reserved.
#
###############################################################################

short_usage()
{
	echo `basename $0` [-basedir directory] [-release]
}

usage()
{
	short_usage;
	echo "-basedir directory"
	echo "  Set the directory where the AAF directory resides."
	echo "-release"
	echo "	Test the release build.  The default is debug."
	echo
	echo "Run the ComModAAF program for this platform and the specified build type."
	echo "The AAFTARGET environment variable may be used as an alternative to the"
	echo "-release option."
	exit 1;
}

BASE_DIR=.
AAFTARGET=${AAFTARGET:=Debug}

until [ $# == 0 ]
do

	case $1 in
		-basedir  ) BASE_DIR=$2 ; shift ;;
		-release  ) AAFTARGET=Release ;;
		-h        ) usage ;;
		-help     ) usage ;;
		*	  ) echo Unrecognized option $1 ; short_usage; exit 1 ;;
	esac

	shift
done

cd ${BASE_DIR}/AAF
if [ $? -ne 0 ]; then
    echo Failed to change to AAF directory: ${BASE_DIR}/AAF
    exit 1
fi

BUILD_DIR=`make builddir AAFTARGET=${AAFTARGET}`
cd $BUILD_DIR
if [ $? -ne 0 ]; then
    echo Failed to change to build directory: $BUILD_DIRECTORY
    exit 1
fi

case $AAFTARGET in 
	Debug   ) BIN_DIR=bin/debug ;;
	Release ) BIN_DIR=bin ;;
	* ) echo Unrecognized AAFTARGET value: $AAFTARGET; exit 1 ;; 
esac

cd $BIN_DIR
if [ $? -ne 0 ]; then
    echo Failed to change to binary directory: $BIN_DIR
    exit 1
fi

# Get the required Laser.wav file.
cp ${BASE_DIR}/AAF/AAFWinSDK/examples/com-api/ComEssenceDataTest/Laser.wav .
if [ $? -ne 0 ]; then
	echo Failed to copy Laser.wav.
	exit 1
fi

#
# Run the regression tests.
#
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:. ./ComModAAF 

exit $?
