#!/bin/sh

echo Test value returned from $t_datconv script


Nrun=0
Nfailed=0

#### 1: No parameters - should return 2 (invalid command line parameters)
Nrun=$(($Nrun+1)); failed=0

t_python $t_datconv 2>/dev/null
[ $? -ne 2 ] && failed=1

[ $failed -ne 0 ] && Nfailed=$(($Nfailed+1))
[ $failed -ne 0 ] && echo Failed test $Nrun
####

#### 2: Not existing Yaml config file - should return 2 (invalid command line parameters)
Nrun=$(($Nrun+1)); failed=0

t_python $t_datconv xxx.yaml 2>/dev/null
[ $? -ne 2 ] && failed=1

[ $failed -ne 0 ] && Nfailed=$(($Nfailed+1))
[ $failed -ne 0 ] && echo Failed test $Nrun
####

#### 3: Invalid Yaml config file (no Writer defined) - should return 2 (invalid command line parameters)
Nrun=$(($Nrun+1)); failed=0

t_python $t_datconv =invalid.yaml 2>/dev/null
[ $? -ne 2 ] && failed=1

[ $failed -ne 0 ] && Nfailed=$(($Nfailed+1))
[ $failed -ne 0 ] && echo Failed test $Nrun
####

#### 4: Invalid command line parameter - should return 2 (invalid command line parameters)
Nrun=$(($Nrun+1)); failed=0

t_python $t_datconv =xml2xml.yaml --ReaderNodule=xxx $t_outdir 2>/dev/null
[ $? -ne 2 ] && failed=1

[ $failed -ne 0 ] && Nfailed=$(($Nfailed+1))
[ $failed -ne 0 ] && echo Failed test $Nrun
####

#### 5: Error in Yaml config file (not existing input file) - should return 1 (general exception)
Nrun=$(($Nrun+1)); failed=0

t_python $t_datconv =noinpath.yaml  $t_outdir 2>/dev/null
[ $? -ne 1 ] && failed=1

[ $failed -ne 0 ] && Nfailed=$(($Nfailed+1))
[ $failed -ne 0 ] && echo Failed test $Nrun
####

#### 6: Normal run - should return 0 (success)
Nrun=$(($Nrun+1)); failed=0

t_python $t_datconv --version >/dev/null
[ $? -ne 0 ] && failed=1

[ $failed -ne 0 ] && Nfailed=$(($Nfailed+1))
[ $failed -ne 0 ] && echo Failed test $Nrun
####

#### Cleanup and Summary
rm -fR $t_outdir/*
echo Run $Nrun tests\; failed $Nfailed
echo

