#!/usr/bin/sh

#
# Copyright (C) 2012-2020 Euclid Science Ground Segment
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3.0 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

home_dir=${PWD}


# Create unique directory
tmploc=$(mktemp -dq -t temp.XXXXXX)

# Clean and exit
local_clean_exit() {
  cd ${home_dir}
  rm -rf ${tmploc}
  exit $1
}

cd ${tmploc} || local_clean_exit 1

# regular run
CppProgramExample
if [ $? -ne 0 ]; then
  echo "Error: <CppProgramExample> failed" 1>&2
  local_clean_exit 1
fi

# regular run with known option
CppProgramExample -f
if [ $? -ne 0 ]; then
  echo "Error: <CppProgramExample -f> failed" 1>&2
  local_clean_exit 1
fi

# regular run with unknown option
CppProgramExample --toto
if [ $? -ne 64 ]; then
  echo "Error: <CppProgramExample --toto> succeeded" 1>&2
  local_clean_exit 1
fi

# regular run
PythonProgramExample
if [ $? -ne 0 ]; then
  echo "Error: <PythonProgramExample> failed" 1>&2
  local_clean_exit 1
fi

# regular run with known option
PythonProgramExample --overwrite
if [ $? -ne 0 ]; then
  echo "Error: <PythonProgramExample --overwrite> failed" 1>&2
  local_clean_exit 1
fi

# regular run with unknown option
PythonProgramExample --toto
if [ $? -eq 0 ]; then
  echo "Error: <PythonProgramExample --toto> succeeded" 1>&2
  local_clean_exit 1
fi

local_clean_exit 0
