2020-04-21 10:40:25 +00:00
|
|
|
#!/bin/sh
|
2019-10-20 17:19:17 +00:00
|
|
|
|
|
|
|
PROG="$1"
|
|
|
|
TEST=testoutput
|
|
|
|
mkdir -p $TEST
|
|
|
|
|
2019-11-03 21:00:18 +00:00
|
|
|
TESTNAME="Test additional json from cmdline"
|
|
|
|
TESTRESULT="ERROR"
|
|
|
|
|
2019-10-20 17:19:17 +00:00
|
|
|
cat simulations/simulation_additional_json.txt | grep '^{' > $TEST/test_expected.txt
|
2021-08-01 21:12:52 +00:00
|
|
|
$PROG --format=json --json_floor=5 --json_address="RoodRd 42" --field_city="Stockholm" simulations/simulation_additional_json.txt \
|
2019-10-20 17:19:17 +00:00
|
|
|
MyTapWater multical21 76348799 "" \
|
2020-09-13 14:55:22 +00:00
|
|
|
> $TEST/test_output.txt 2> $TEST/test_stderr.txt
|
2019-10-20 17:19:17 +00:00
|
|
|
|
2020-04-22 06:07:19 +00:00
|
|
|
if [ "$?" = "0" ]
|
2019-10-20 17:19:17 +00:00
|
|
|
then
|
|
|
|
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
|
|
|
|
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
2020-04-22 06:07:19 +00:00
|
|
|
if [ "$?" = "0" ]
|
2019-10-20 17:19:17 +00:00
|
|
|
then
|
2019-11-03 21:00:18 +00:00
|
|
|
echo "OK: $TESTNAME"
|
|
|
|
TESTRESULT="OK"
|
2019-10-20 17:19:17 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-11-03 21:00:18 +00:00
|
|
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
|
|
|
|
|
|
|
|
2021-02-20 21:21:01 +00:00
|
|
|
|
2019-11-03 21:00:18 +00:00
|
|
|
TESTNAME="Test additional shell envs from cmdline"
|
|
|
|
TESTRESULT="ERROR"
|
2019-10-20 17:19:17 +00:00
|
|
|
|
2020-09-13 14:55:22 +00:00
|
|
|
$PROG --json_floor=5 --json_house="alfa beta" --listenvs=multical21 > $TEST/test_output.txt 2> $TEST/test_stderr.txt
|
2019-10-20 17:19:17 +00:00
|
|
|
|
|
|
|
ENVS=$(cat $TEST/test_output.txt | tr '\n' ' ')
|
|
|
|
|
|
|
|
cat > $TEST/test_expected.txt <<EOF
|
|
|
|
METER_JSON
|
|
|
|
METER_ID
|
2021-02-24 19:50:45 +00:00
|
|
|
METER_NAME
|
|
|
|
METER_MEDIA
|
|
|
|
METER_TYPE
|
|
|
|
METER_TIMESTAMP
|
2021-08-01 21:12:52 +00:00
|
|
|
METER_TIMESTAMP_UTC
|
|
|
|
METER_TIMESTAMP_UT
|
|
|
|
METER_TIMESTAMP_LT
|
2021-02-24 19:50:45 +00:00
|
|
|
METER_DEVICE
|
|
|
|
METER_RSSI_DBM
|
2019-10-20 17:19:17 +00:00
|
|
|
METER_TOTAL_M3
|
|
|
|
METER_TARGET_M3
|
|
|
|
METER_MAX_FLOW_M3H
|
|
|
|
METER_FLOW_TEMPERATURE_C
|
|
|
|
METER_EXTERNAL_TEMPERATURE_C
|
|
|
|
METER_CURRENT_STATUS
|
|
|
|
METER_TIME_DRY
|
|
|
|
METER_TIME_REVERSED
|
|
|
|
METER_TIME_LEAKING
|
|
|
|
METER_TIME_BURSTING
|
|
|
|
METER_floor
|
|
|
|
METER_house
|
|
|
|
EOF
|
|
|
|
|
|
|
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
2020-04-22 06:07:19 +00:00
|
|
|
if [ "$?" = "0" ]
|
2019-10-20 17:19:17 +00:00
|
|
|
then
|
2019-11-03 21:00:18 +00:00
|
|
|
echo "OK: $TESTNAME"
|
|
|
|
TESTRESULT="OK"
|
2019-10-20 17:19:17 +00:00
|
|
|
fi
|
|
|
|
|
2019-11-03 21:00:18 +00:00
|
|
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
|
|
|
|
|
|
|
TESTNAME="Test additional json from wmbusmeters.conf and from meter file"
|
|
|
|
TESTRESULT="ERROR"
|
|
|
|
|
2021-08-01 21:12:52 +00:00
|
|
|
$PROG --debug --useconfig=tests/config6 --device=simulations/simulation_shell.txt > $TEST/test_output.txt 2> $TEST/test_stderr.txt
|
2019-10-20 17:19:17 +00:00
|
|
|
|
2020-04-22 06:07:19 +00:00
|
|
|
if [ "$?" = "0" ]
|
2019-10-20 17:19:17 +00:00
|
|
|
then
|
|
|
|
INFO=$(cat /tmp/wmbusmeters_meter_additional_json_test | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/')
|
2021-08-01 21:12:52 +00:00
|
|
|
EXPECTED=$(echo 'METER =={"media":"warm water","meter":"supercom587","name":"Water","id":"12345678","total_m3":5.548,"timestamp":"1111-11-11T11:11:11Z","floor":"5","elevator":"ABC","address":"RoodRd 42","city":"Stockholm"}== ==RoodRd 42== ==Stockholm== ==5== ==ABC==')
|
2019-10-20 17:19:17 +00:00
|
|
|
if [ "$INFO" = "$EXPECTED" ]
|
|
|
|
then
|
2019-11-03 21:00:18 +00:00
|
|
|
echo "OK: $TESTNAME"
|
|
|
|
TESTRESULT="OK"
|
2021-08-01 21:12:52 +00:00
|
|
|
else
|
|
|
|
echo "INFO =>$INFO<"
|
|
|
|
echo "EXPECTED=>$EXPECTED<"
|
2019-10-20 17:19:17 +00:00
|
|
|
fi
|
|
|
|
fi
|
2019-11-03 21:00:18 +00:00
|
|
|
|
|
|
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|