#!/bin/sh
#
SPLITCF=$1
GREP="grep -A1"
ECM="ecm -resume -"
#
if !(test -x $SPLITCF) then
    echo "usage: ./check <splitcf_binary>";
    exit 1;
fi
#
# No result expected, just check that file is not altered:
echo -n "Test 1 "
if !($SPLITCF -p <test-1.in | cmp - test-1.in)
then
    echo "failed!";
    exit 1;
else
    echo "passed."
fi
#
# p48 of 2,1718M.c247 (split from M3436):
echo -n "Test 2 "
if !($SPLITCF -c <test-2.in | $GREP "2,1718M" | $ECM 1 8e6-1e7 >/dev/null)
then
    echo "failed!";
    exit 1;
else
    echo "passed."
fi
#
# p46 of 2,863+.c183 (split from M1726):
echo -n "Test 3 "
if !($SPLITCF -c <test-3.in | $GREP "2,863+" | $ECM 1 91e7-92e7 >/dev/null)
then
    echo "failed!";
    exit 1;
else
    echo "passed.";
fi
#
# p43 of 2,761+.c162 (split from M1522):
echo -n "Test 4 "
if !($SPLITCF -c <test-4.in | $GREP "2,761+" | $ECM 1 11e7-12e7 >/dev/null)
then
    echo "failed!";
    exit 1;
else
    echo "passed.";
fi
#
# p49 of 2,2070L.c160, originally found by Dodson (split from M4140):
echo -n "Test 5 "
if !($SPLITCF -c <test-5.in | $GREP "2,2070L" | $ECM 1 8389e7-839e8 >/dev/null)
then
    echo "failed!";
    exit 1;
else
    echo "passed.";
fi
#
# Compare with known good output.
echo -n "Test 6 "
if !($SPLITCF -c <test-6.in | cmp - test-6.out)
then
    echo "failed!";
    exit 1;
else
    echo "passed.";
fi
#
# Compare with known good output.
echo -n "Test 7 "
if !($SPLITCF -c <test-7.in | cmp - test-7.out)
then
    echo "failed!";
    exit 1;
else
    echo "passed.";
fi
#
# Compare with known good output.
echo -n "Test 8 "
if !($SPLITCF -c <test-8.in | cmp - test-8.out)
then
    echo "failed!";
    exit 1;
else
    echo "passed.";
fi
#
echo "*** All tests passed ***"
exit 0
