#!/bin/sh
# simple test script
# yes, I know the color scheme is painful and wrong. :)


RC=0 

#timeout 7s sh -c "ping -i 5 localhost |./xrootconsole -bw 2 -bd '#000000' -fg 'darkgreen' -bg '#660099' --wrap -geometry +100+260 $@"
#LRC=$?; if [ "$LRC" -ne 124 ]; then RC="$LRC"; echo Test failed 1>&2; fi

# testing long lines, column wrapping

timeout 7s sh -c "{ while [ 1 ] ; do sleep 1; echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; done; } |./xrootconsole -bw 2 -bd '#000000' -fg '#FF3333' -bg '#660099' --wrap -geometry +100+260 $@"
LRC=$?; if [ "$LRC" -ne 124 ]; then RC="$LRC"; echo Test failed 1>&2; fi

#extra newline bug test
timeout 7s sh -c "{ z=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; while [ 1 ] ; do sleep 1; z=x$z; echo $z; done; } |./xrootconsole -bw 2 -bd '#000000' -fg '#FF3333' -bg '#660099' --wrap -geometry +100+260 $@"
LRC=$?; if [ "$LRC" -ne 124 ]; then RC="$LRC"; echo Test failed 1>&2; fi

#bottomup test
timeout 7s sh -c "{ z=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; while [ 1 ] ; do sleep 1; z=x$z; echo $z; done; } |./xrootconsole --bottomup -bw 2 -bd '#000000' -fg '#FF3333' -bg '#660099' --wrap -geometry +100+260 $@"
LRC=$?; if [ "$LRC" -ne 124 ]; then RC="$LRC"; echo Test failed 1>&2; fi

#transparency test
timeout 7s sh -c "{ z=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; while [ 1 ] ; do sleep 1; z=x$z; echo $z; done; } |./xrootconsole --bottomup -bw 2 -bd '#000000' -fg '#FF3333' --wrap -geometry +100+260 $@"
LRC=$?; if [ "$LRC" -ne 124 ]; then RC="$LRC"; echo Test failed 1>&2; fi

#ansi color test
timeout 7s sh -c "/bin/echo -ne '\e[mNormal \e[30mBlack \e[31mRed \e[32mGreen \e[33mBrown  \e[34mBlue \e[35mMagena \e[36mCyan \e[37mWhite \e[39mNormal\n\e[1mBold   \e[30mBlack \e[31mRed \e[32mGreen \e[33mYellow \e[34mBlue \e[35mMagena \e[36mCyan \e[37mWhite \e[39mNormal\n\e[mNormal \e[40mBlack \e[41mRed \e[42mGreen \e[43mBrown  \e[44mBlue \e[45mMagena \e[46mCyan \e[47mWhite \e[49mNormal\n\e[5mBlink  \e[40mBlack \e[41mRed \e[42mGreen \e[43mYellow \e[44mBlue \e[45mMagena \e[46mCyan \e[47mWhite \e[49mNormal\n\e[7mInvert' | ./xrootconsole --ansi-color -fg '#9966FF' -geometry +100+260 $@"
LRC=$?; if [ "$LRC" -ne 124 ]; then RC="$LRC"; echo Test failed 1>&2; fi

if [ "$RC" -eq 0 ]; then
    echo "All tests succeeded."
    exit 0
else
    echo "Some tests failed."
    exit "$RC"
fi
