#! /bin/sh

set -e
INSTDIR="$(readlink -f $(dirname $0)/..)"

echo "XMLFLAT_HIERACHICAL_MODELLING"
cd $INSTDIR/examples/xmlflat/hierachical_modelling
$INSTDIR/bin/mbsimflatxml MBS.mbsimprj.flat.xml
echo "DONE"

echo "XML_HIERACHICAL_MODELLING"
cd $INSTDIR/examples/xml/hierachical_modelling
$INSTDIR/bin/mbsimxml MBS.mbsimprj.xml
echo "DONE"

echo "XML_TIME_DEPENDENT_KINEMATICS"
cd $INSTDIR/examples/xml/time_dependent_kinematics
$INSTDIR/bin/mbsimxml MBS.mbsimprj.xml
echo "DONE"

echo "XML_HYDRAULICS_BALLCHECKVALVE"
cd $INSTDIR/examples/xml/hydraulics_ballcheckvalve
$INSTDIR/bin/mbsimxml MBS.mbsimprj.xml
echo "DONE"


export OPENMBVCPPINTERFACE_PREFIX="$INSTDIR"

echo "OPENMBVCPPINTERFACE_SWIG_OCTAVE"
cd $INSTDIR/share/openmbvcppinterface/examples/swig
$INSTDIR/bin/octave octavetest.m
echo "DONE"

if [ "_$MBSIMENV_TEST_PYTHON" == "_1" ]; then
  echo "OPENMBVCPPINTERFACE_SWIG_PYTHON"
  cd $INSTDIR/share/openmbvcppinterface/examples/swig
  python pythontest.py
  echo "DONE"
fi

if [ "_$MBSIMENV_TEST_JAVA" == "_1" ]; then
  echo "OPENMBVCPPINTERFACE_SWIG_JAVA"
  cd $INSTDIR/share/openmbvcppinterface/examples/swig
  java -classpath .:$INSTDIR/bin/openmbv.jar javatest
  echo "DONE"
fi


echo "STARTING H5PLOTSERIE"
cd $INSTDIR/examples/xml/hierachical_modelling
$INSTDIR/bin/h5plotserie TS.mbsim.h5
echo "DONE"

echo "STARTING OPENMBV"
cd $INSTDIR/examples/xml/hierachical_modelling
$INSTDIR/bin/openmbv TS.ombv.xml
echo "DONE"

echo "STARTING MBSIMGUI"
$INSTDIR/bin/mbsimgui
echo "DONE"

echo "ALL TESTS DONE"