#!/bin/sh

PROG="$1"
TEST=testoutput
mkdir -p $TEST

TESTNAME="Test auto removal of dll crcs in frame b long telegrams"
TESTRESULT="ERROR"

OUTPUT=$($PROG --format=fields --selectfields=total_kwh,total_water_m3 C244C5140443054300048C200E900F002C25895E02003B0877D31DA840B17A0E009007100F8FAD4C4E61400DA4F3B1F7E273CC4C5C07F93CD20B237345DB39F9A98F8415E1C4B7A25C86E4C22D05C3352FA7E2E5627031F14643063F1DC8FE2C32459B6F02E4234B447B18E4BFDA8C4DA9B1EDE6CF29D0B2122A3E8B9DEEBEE3E6DBE6617B4E709EC6B595179CB01C2C0BDE6723A345B708652880C114A58DA07C73AD9EB8ACB17FA0A88F19BC84CB1FC56672DE8A9603FD0C05010002FD0B2111F60B Senso sensostar 43054304 622b9656991ff0c1574c0950cf9278d1 2>&1)

if [ "$?" = "0" ]
then
    if [ "$OUTPUT" = "9341;1348.631" ]
    then
        echo OK: $TESTNAME
        TESTRESULT="OK"
    else
        echo ERROR: $TESTNAME
        echo "Expected 9341;1348.631 but got $OUTPUT"
        exit 1
    fi
else
    echo "wmbusmeters returned error code: $?"
    cat $TEST/test_output.txt
fi
